| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
system("grep 'define NETSNMP_DS_' ../../include/net-snmp/library/default_store.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::default_store -O default_store.h"); |
| 6 |
|
| 7 |
open(ORIG,"default_store.xs"); |
| 8 |
open(NEW1,"NetSNMP-default_store/fallback/const-c.inc"); |
| 9 |
open(NEW2,"NetSNMP-default_store/fallback/const-xs.inc"); |
| 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\/library\/default_store.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::default_store PACKAGE = NetSNMP::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 |
# skip past the constant portion of the old file |
| 30 |
while (<ORIG>) { |
| 31 |
last if (/netsnmp_ds_get_bool/); |
| 32 |
$last = $_; |
| 33 |
} |
| 34 |
|
| 35 |
# We need the last two lines |
| 36 |
print OUT $last; |
| 37 |
print OUT $_; |
| 38 |
|
| 39 |
# and the rest |
| 40 |
print OUT <ORIG>; |
| 41 |
|
| 42 |
close(OUT); |
| 43 |
|
| 44 |
# |
| 45 |
# generate test |
| 46 |
# |
| 47 |
open(H,"default_store.h"); |
| 48 |
open(ORIG,"test.pl"); |
| 49 |
open(OUT,">test.pl.new"); |
| 50 |
|
| 51 |
while(<ORIG>) { |
| 52 |
print OUT; |
| 53 |
last if (/\%tests =/); |
| 54 |
} |
| 55 |
|
| 56 |
while(<H>) { |
| 57 |
if (/define\s+(\w+)\s+(\d+)/) { |
| 58 |
printf OUT (" %-40s => %d,\n", "\"$1\"", $2); |
| 59 |
$tokenlist .= " $1\n"; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
while(<ORIG>) { |
| 64 |
last if (/\);/); |
| 65 |
} |
| 66 |
print OUT; |
| 67 |
print OUT <ORIG>; |
| 68 |
close(OUT); |
| 69 |
|
| 70 |
# |
| 71 |
# modify the perl module itself |
| 72 |
# |
| 73 |
open(H,"default_store.h"); |
| 74 |
open(ORIG,"default_store.pm"); |
| 75 |
open(OUT,">default_store_new.pm"); |
| 76 |
|
| 77 |
# first list |
| 78 |
while(<ORIG>) { |
| 79 |
print OUT; |
| 80 |
last if (/\%EXPORT_TAGS =/); |
| 81 |
} |
| 82 |
print OUT $tokenlist; |
| 83 |
while(<ORIG>) { |
| 84 |
last if (/netsnmp_ds_get_boolean/); |
| 85 |
} |
| 86 |
print OUT; |
| 87 |
|
| 88 |
# second list |
| 89 |
while(<ORIG>) { |
| 90 |
print OUT; |
| 91 |
last if (/\@EXPORT =/); |
| 92 |
} |
| 93 |
print OUT $tokenlist; |
| 94 |
while(<ORIG>) { |
| 95 |
last if (/\);/); |
| 96 |
} |
| 97 |
print OUT; |
| 98 |
|
| 99 |
# last section |
| 100 |
while(<ORIG>) { |
| 101 |
print OUT; |
| 102 |
last if (/head2 Exportable constants/); |
| 103 |
} |
| 104 |
print OUT "\n"; |
| 105 |
print OUT $tokenlist; |
| 106 |
while(<ORIG>) { |
| 107 |
last if (/head2 Exportable functions/); |
| 108 |
} |
| 109 |
print OUT "\n"; |
| 110 |
print OUT; |
| 111 |
|
| 112 |
# tail end |
| 113 |
print OUT <ORIG>; |
| 114 |
close(OUT); |
| 115 |
|
| 116 |
# |
| 117 |
# install new files |
| 118 |
# |
| 119 |
print "updated test.pl\n"; |
| 120 |
rename("test.pl.new","test.pl"); |
| 121 |
rename("default_store_new.pm", "default_store.pm"); |
| 122 |
print "updated default_store.pm\n"; |
| 123 |
rename("default_store_new.xs", "default_store.xs"); |
| 124 |
print "updated default_store.xs\n"; |
| 125 |
|
| 126 |
# |
| 127 |
# remove the temp files. |
| 128 |
# |
| 129 |
system("rm -rf NetSNMP-default_store"); |
| 130 |
unlink("default_store.h"); |
| 131 |
|