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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
#!/usr/local/bin/perl
#
# $NetBSD: trrt2netbsd,v 1.4 1999/06/16 20:47:57 is Exp $
#
# Perl script to convert a standard distribution directory for traceroute into
# a NetBSD source tree.
#
# This is done as a script so that as each distribution is released,
# only changes from the previous one need to be dealt with as
# modifications to this script and related files. This should
# reduce the cost of updating from a new release of traceroute by an
# order of magnitude (or more?)
#
# This script requires two environment variables set:
# SRCDIR - traceroute source directory
# TARGETDIR - name of the high level directory to make
#
# Written by Christos Zoulas Oct 2nd, 1997 for traceroute-1.4a5
#
$version = "1.4a5";
# definitions ...
@subdirs = ("usr.sbin/traceroute");
@trrtf = ("ifaddrlist.c", "savestr.c", "traceroute.c");
@trrthf = ("gnuc.h", "ifaddrlist.h", "savestr.h");
@trrtmf = ("traceroute.8");
@trrtdf = ("CHANGES", "README");
@trrtaf = ("mean.awk", "median.awk");
# sed edit list: file, sed-program
%sedlist = ();
#
# Utility Subroutines
#
sub makedir {
system("mkdir -p @_");
}
# &fixrcs (fromfile, tofile);
sub fixrcs
{
my ($f, $t) = @_;
my @keywords = ("Author", "Date", "Header", "Id", "Locker", "Log",
"Name", "RCSfile", "Revision", "Source", "State");
my $state = 0;
my $hdr = 0;
open(IFILE, "<$f") || die "Cannot open $f";
open(OFILE, ">$t") || die "Cannot create $t";
if ($t =~ /.*\.[0-9]/) {
print OFILE '.\\" $', 'NetBSD', '$', "\n.\\\"", "\n";
}
elsif ($t =~ /.*\.[ch]/) {
print OFILE "/*\t", '$', 'NetBSD', '$', "\t*/\n\n";
}
elsif ($t =~ /.*\.[yl]/) {
$hdr = 1;
}
else {
print OFILE '$', 'NetBSD', '$', "\n";
}
while (<IFILE>) {
if ($hdr == 1) {
if (/%{/) {
print OFILE "%{\n/*\t", '$', 'NetBSD', '$', "\t*/\n\n";
$hdr = 0;
next;
}
}
if ($state == 2) {
if (/#endif/) {
print OFILE "#else\n__RCSID(", '"$', 'NetBSD', '$"',
");\n#endif\n";
$state = 0;
}
}
if ($state == 1) {
print OFILE "#if 0\n";
$state = 2;
}
if (/#ifndef lint/) {
print OFILE "#include <sys/cdefs.h>\n";
$state = 1;
}
foreach $key (@keywords) {
s/\$$key\$/$key/g;
s/\$$key:(.*)\$/$key:$1/g;
}
print OFILE $_;
}
close(IFILE) || die "closing input file";
close(OFILE) || die "closing output file";
}
# ©files (fromdir, todir, list of files);
sub copyfiles {
local ($fdir, $tdir, @list) = @_;
local ($f);
foreach $f (@list) {
print " $fdir/$f --> $tdir/$f\n";
&fixrcs("$fdir/$f", "$tdir/$f");
}
}
# ©file (fromfile, tofile);
sub copyfile {
local ($f, $t) = @_;
print " $f --> $t\n";
system ("cp $f $t");
}
sub uniq {
local (@inlist) = @_;
local (@outlist);
@outlist = ($inlist[0]);
for ( $i=1; $i < @inlist; $i++ ) {
if ($inlist[$i] ne $inlist[$i-1]) {
push (@outlist, $inlist[$i]);
}
}
@outlist;
}
sub dumpsrcs {
local (@names) = @_;
local ($count);
$count = 0;
while ($f = pop(@names)) {
print ODATA "$f ";
if ($count == 5 && @names > 0) {
print ODATA "\\\n";
$count = 0;
} else {
$count += 1;
}
}
if ($count != 0) {
print ODATA "\n";
}
}
#
# Main program.
#
$srcdir = $ENV{'SRCDIR'};
$targetdir = $ENV{'TARGETDIR'};
$incdirs = "-I. -I$srcdir/config -I$srcdir";
if (!$srcdir | !targetdir) {
die "You must define the environment variables SRCDIR and TARGETDIR.\n"
}
print "Making the NetBSD directory tree.\n";
foreach $f (@subdirs) {
print " -->$f\n";
makedir ("$targetdir/$f");
}
print "Populating the usr.sbin/traceroute directory.\n";
©files ("$srcdir", "$targetdir/usr.sbin/traceroute", @trrtf, @trrthf, @trrtdf,
@trrtmf, @trrtaf);
#
# Build makefiles
#
$first = "True";
while ($line = <DATA>) {
chop ($line);
if (substr($line,0,2) eq "%%") {
@cmd = split (/ /,$line);
if ($cmd[1] eq "file") {
print "Building $targetdir/$cmd[2]\n";
if ($first eq "") {
close (ODATA);
} else {
$first = "";
}
open (ODATA, ">$targetdir/$cmd[2]") ||
die "Could not create $targetdir/$cmd[2]";
} elsif ($cmd[1] eq "awks") {
print " Defining AWKS\n";
if ($first) {
die "Data file must start with a %% file!";
}
print ODATA "AWKS=\t";
&dumpsrcs (@trrtaf);
} elsif ($cmd[1] eq "srcs") {
print " Defining SRCS\n";
if ($first) {
die "Data file must start with a %% file!";
}
print ODATA "SRCS=\t";
&dumpsrcs (@trrtf);
} elsif ($cmd[1] eq "man") {
print " Defining MAN\n";
if ($first) {
die "Data file must start with a %% file!";
}
print ODATA "MAN=\t";
&dumpsrcs (@trrtmf);
} elsif ($cmd[1] eq "version") {
print " Defining VERSION\n";
print ODATA "char version[] = \"$version\";";
} elsif ($cmd[1] eq "NetBSD") {
if ($first) {
die "Data section must start with a %% file!";
}
print ODATA "$cmd[2] \$"."NetBSD".": \$ $cmd[3]\n";
}
} else {
if ($first) {
die "Data file must start with a %% file!";
}
print ODATA "$line\n";
}
}
close (ODATA);
#
# Sed transformations of files
#
foreach $n (keys(%sedlist)) {
print "Modifying $n\n";
system ("cd $targetdir; sed $sedlist{$n} $n > tmp; mv -f tmp $n");
}
#
# end of the script
#
# what follows is the data for makefiles and other special files
# that need to be created.
__END__
%% file usr.sbin/traceroute/Makefile
%% NetBSD #
WARNS?= 1
PROG= traceroute
%% man
CPPFLAGS+=-DHAVE_MALLOC_H=1 -DHAVE_SYS_SELECT_H=1 -DHAVE_SYS_SOCKIO_H=1
CPPFLAGS+=-DHAVE_STRERROR=1 -DHAVE_SETLINEBUF=1 -DHAVE_SOCKADDR_SA_LEN=1
CPPFLAGS+=-DHAVE_RAW_OPTIONS=1
BINOWN= root
BINMODE=4555
%% srcs
SRCS+= version.c
%% awks
.include <bsd.prog.mk>
%% file usr.sbin/traceroute/version.c
%% NetBSD /* */
%% version
|