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