Dave Shield | 00ef569 | 2011-02-22 08:55:48 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl |
| 2 | |
| 3 | system("grep 'define NETSNMP_DS_' ../../../include/net-snmp/agent/ds_agent.h > default_store.h"); |
| 4 | #gcc -E ../../include/net-snmp/library/default_store.h | grep -v default_store.h >> default_store.h |
| 5 | system("h2xs -b 5.5.0 -n NetSNMP::agent::default_store -O default_store.h"); |
| 6 | |
| 7 | open(ORIG,"default_store.xs"); |
| 8 | open(NEW1,"NetSNMP-agent-default_store/fallback/const-c.inc") || die "can't open inc file 1"; |
| 9 | open(NEW2,"NetSNMP-agent-default_store/fallback/const-xs.inc") || die "can't open inc file 2"; |
| 10 | open(OUT,">default_store_new.xs"); |
| 11 | |
| 12 | # get up to the include from the original file |
| 13 | while(<ORIG>) { |
| 14 | print OUT; |
| 15 | last if (/include <net-snmp\/agent\/ds_agent.h/); |
| 16 | } |
| 17 | |
| 18 | # include the entire new file |
| 19 | print OUT "\n\n/* autogenerated by \"gen\" from const-c.inc */\n\n"; |
| 20 | print OUT <NEW1>; |
| 21 | print OUT "\n\n/* autogenerated by \"gen\" from const-xs.inc */\n\n"; |
| 22 | print OUT "MODULE = NetSNMP::agent::default_store PACKAGE = NetSNMP::agent::default_store\n\n"; |
| 23 | |
| 24 | print OUT <NEW2>; |
| 25 | |
| 26 | #print OUT "\n\n/* autogenerated by \"gen\" from tail of old .xs file */\n\n"; |
| 27 | print OUT "\n\n\n"; |
| 28 | |
| 29 | close(OUT); |
| 30 | |
| 31 | # |
| 32 | # generate test |
| 33 | # |
| 34 | open(H,"default_store.h"); |
| 35 | open(ORIG,"test.pl"); |
| 36 | open(OUT,">test.pl.new"); |
| 37 | |
| 38 | while(<ORIG>) { |
| 39 | print OUT; |
| 40 | last if (/\%tests =/); |
| 41 | } |
| 42 | |
| 43 | while(<H>) { |
| 44 | if (/define\s+(\w+)\s+(\d+)/) { |
| 45 | printf OUT (" %-40s => %d,\n", "\"$1\"", $2); |
| 46 | $tokenlist .= " $1\n"; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | while(<ORIG>) { |
| 51 | last if (/\);/); |
| 52 | } |
| 53 | print OUT; |
| 54 | print OUT <ORIG>; |
| 55 | close(OUT); |
| 56 | |
| 57 | # |
| 58 | # modify the perl module itself |
| 59 | # |
| 60 | open(H,"default_store.h"); |
| 61 | open(ORIG,"default_store.pm"); |
| 62 | open(OUT,">default_store_new.pm"); |
| 63 | |
| 64 | # first list |
| 65 | while(<ORIG>) { |
| 66 | print OUT; |
| 67 | last if (/\%EXPORT_TAGS =/); |
| 68 | } |
| 69 | print OUT $tokenlist; |
| 70 | while(<ORIG>) { |
| 71 | last if (/\) \] \);/); |
| 72 | } |
| 73 | print OUT; |
| 74 | |
| 75 | # second list |
| 76 | while(<ORIG>) { |
| 77 | print OUT; |
| 78 | last if (/\@EXPORT =/); |
| 79 | } |
| 80 | print OUT $tokenlist; |
| 81 | while(<ORIG>) { |
| 82 | last if (/\);/); |
| 83 | } |
| 84 | print OUT; |
| 85 | |
| 86 | # last section |
| 87 | while(<ORIG>) { |
| 88 | print OUT; |
| 89 | last if (/head2 Exportable constants/); |
| 90 | } |
| 91 | print OUT "\n"; |
| 92 | print OUT $tokenlist; |
| 93 | while(<ORIG>) { |
| 94 | last if (/^\s*$/); |
| 95 | } |
| 96 | print OUT "\n"; |
| 97 | print OUT; |
| 98 | |
| 99 | # tail end |
| 100 | print OUT <ORIG>; |
| 101 | close(OUT); |
| 102 | |
| 103 | # |
| 104 | # install new files |
| 105 | # |
| 106 | print "updated test.pl\n"; |
| 107 | rename("test.pl.new","test.pl"); |
| 108 | rename("default_store_new.pm", "default_store.pm"); |
| 109 | print "updated default_store.pm\n"; |
| 110 | rename("default_store_new.xs", "default_store.xs"); |
| 111 | print "updated default_store.xs\n"; |
| 112 | |
| 113 | # |
| 114 | # remove the temp files. |
| 115 | # |
| 116 | system("rm -rf NetSNMP-agent-default_store"); |
| 117 | unlink("default_store.h"); |
| 118 | |