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