summaryrefslogtreecommitdiff
path: root/perl/default_store/gen
blob: 76912964efdc6cce3fe61726791d13ed2957fec7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/perl

system("grep 'define NETSNMP_DS_' ../../include/net-snmp/library/default_store.h > default_store.h");
#gcc -E ../../include/net-snmp/library/default_store.h | grep -v default_store.h >> default_store.h
system("h2xs -b 5.5.0 -n NetSNMP::default_store -O default_store.h");

open(ORIG,"default_store.xs");
open(NEW1,"NetSNMP-default_store/fallback/const-c.inc");
open(NEW2,"NetSNMP-default_store/fallback/const-xs.inc");
open(OUT,">default_store_new.xs");

# get up to the include from the original file
while(<ORIG>) {
    print OUT;
    last if (/include <net-snmp\/library\/default_store.h/);
}

# include the entire new file
print OUT "\n\n/* autogenerated by \"gen\" from const-c.inc */\n\n";
print OUT <NEW1>;
print OUT "\n\n/* autogenerated by \"gen\" from const-xs.inc */\n\n";
print OUT "MODULE = NetSNMP::default_store         PACKAGE = NetSNMP::default_store\n\n";

print OUT <NEW2>;

#print OUT "\n\n/* autogenerated by \"gen\" from tail of old .xs file */\n\n";
print OUT "\n\n\n";

# skip past the constant portion of the old file
while (<ORIG>) {
    last if (/netsnmp_ds_get_bool/);
    $last = $_;
}

# We need the last two lines
print OUT $last;
print OUT $_;

# and the rest
print OUT <ORIG>;

close(OUT);

#
# generate test
#
open(H,"default_store.h");
open(ORIG,"test.pl");
open(OUT,">test.pl.new");

while(<ORIG>) {
    print OUT;
    last if (/\%tests =/);
}

while(<H>) {
    if (/define\s+(\w+)\s+(\d+)/) {
	printf OUT ("                  %-40s => %d,\n", "\"$1\"", $2);
	$tokenlist .= "				   $1\n";
    }
}

while(<ORIG>) {
    last if (/\);/);
}
print OUT;
print OUT <ORIG>;
close(OUT);

#
# modify the perl module itself
#
open(H,"default_store.h");
open(ORIG,"default_store.pm");
open(OUT,">default_store_new.pm");

# first list
while(<ORIG>) {
    print OUT;
    last if (/\%EXPORT_TAGS =/);
}
print OUT $tokenlist;
while(<ORIG>) {
    last if (/netsnmp_ds_get_boolean/);
}
print OUT;

# second list
while(<ORIG>) {
    print OUT;
    last if (/\@EXPORT =/);
}
print OUT $tokenlist;
while(<ORIG>) {
    last if (/\);/);
}
print OUT;

# last section
while(<ORIG>) {
    print OUT;
    last if (/head2 Exportable constants/);
}
print OUT "\n";
print OUT $tokenlist;
while(<ORIG>) {
    last if (/head2 Exportable functions/);
}
print OUT "\n";
print OUT;

# tail end
print OUT <ORIG>;
close(OUT);

#
# install new files
#
print "updated test.pl\n";
rename("test.pl.new","test.pl");
rename("default_store_new.pm", "default_store.pm");
print "updated default_store.pm\n";
rename("default_store_new.xs", "default_store.xs");
print "updated default_store.xs\n";

#
# remove the temp files.
#
system("rm -rf NetSNMP-default_store");
unlink("default_store.h");