added files
[bcm963xx.git] / userapps / opensource / net-snmp / perl / default_store / gen
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 -n NetSNMP::default_store -O default_store.h");
6
7 open(ORIG,"default_store.xs");
8 open(NEW,"NetSNMP/default_store/default_store.xs");
9 open(OUT,">default_store_new.xs");
10
11 # get up to the include from the original file
12 while(<ORIG>) {
13     print OUT;
14     last if (/include <net-snmp\/library\/default_store.h/);
15 }
16
17 # skip up to the include from the original file
18 while(<NEW>) {
19     last if (/include <default_store.h>/);
20 }
21
22 # include the entire new file
23 print OUT <NEW>;
24
25 # skip past the constant portion of the old file
26 while (<ORIG>) {
27     last if (/netsnmp_ds_get_bool/);
28     $last = $_;
29 }
30
31 # We need the last two lines
32 print OUT $last;
33 print OUT $_;
34
35 # and the rest
36 print OUT <ORIG>;
37
38 close(OUT);
39
40 #
41 # generate test
42 #
43 open(H,"default_store.h");
44 open(ORIG,"test.pl");
45 open(OUT,">test.pl.new");
46
47 while(<ORIG>) {
48     print OUT;
49     last if (/\%tests =/);
50 }
51
52 while(<H>) {
53     if (/define\s+(\w+)\s+(\d+)/) {
54         printf OUT ("                  %-40s => %d,\n", "\"$1\"", $2);
55         $tokenlist .= "                            $1\n";
56     }
57 }
58
59 while(<ORIG>) {
60     last if (/\);/);
61 }
62 print OUT;
63 print OUT <ORIG>;
64 close(OUT);
65
66 #
67 # modify the perl module itself
68 #
69 open(H,"default_store.h");
70 open(ORIG,"default_store.pm");
71 open(OUT,">default_store_new.pm");
72
73 # first list
74 while(<ORIG>) {
75     print OUT;
76     last if (/\%EXPORT_TAGS =/);
77 }
78 print OUT $tokenlist;
79 while(<ORIG>) {
80     last if (/netsnmp_ds_get_boolean/);
81 }
82 print OUT;
83
84 # second list
85 while(<ORIG>) {
86     print OUT;
87     last if (/\@EXPORT =/);
88 }
89 print OUT $tokenlist;
90 while(<ORIG>) {
91     last if (/\);/);
92 }
93 print OUT;
94
95 # last section
96 while(<ORIG>) {
97     print OUT;
98     last if (/head2 Exportable constants/);
99 }
100 print OUT "\n";
101 print OUT $tokenlist;
102 while(<ORIG>) {
103     last if (/head2 Exportable functions/);
104 }
105 print OUT "\n";
106 print OUT;
107
108 # tail end
109 print OUT <ORIG>;
110 close(OUT);
111
112 #
113 # install new files
114 #
115 print "updated test.pl\n";
116 rename("test.pl.new","test.pl");
117 rename("default_store_new.pm", "default_store.pm");
118 print "updated default_store.pm\n";
119 rename("default_store_new.xs", "default_store.xs");
120 print "updated default_store.xs\n";
121
122 #
123 # remove the temp files.
124 #
125 system("rm -rf NetSNMP");
126 unlink("default_store.h");
127