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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
|
#!/usr/local/bin/perl
use Config;
use File::Basename qw(&basename &dirname);
# List explicitly here the variables you want Configure to
# generate. Metaconfig only looks for shell variables, so you
# have to mention them as if they were shell variables, not
# %Config entries. Thus you write
# $startperl
# to ensure Configure will look for $Config{startperl}.
# This forces PL files to create target in same directory as PL file.
# This is so that make depend always knows where to find PL derivatives.
chdir(dirname($0));
($file = basename($0)) =~ s/\.PL$//;
$file =~ s/\.pl$//
if ($^O eq 'VMS' or $^O eq 'os2'); # "case-forgiving"
open OUT,">$file" or die "Can't create $file: $!";
print "Extracting $file (with variable substitutions)\n";
# In this section, perl variables will be expanded during extraction.
# You can use $Config{...} to use Configure variables.
print OUT <<"!GROK!THIS!";
$Config{startperl}
eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
if \$running_under_some_shell;
\$startperl = "$Config{startperl}";
\$perlpath = "$Config{perlpath}";
!GROK!THIS!
# In the following, perl variables are not expanded during extraction.
print OUT <<'!NO!SUBS!';
#
# Modified September 26, 1993 to provide proper handling of years after 1999
# Tom Link <tml+@pitt.edu>
# University of Pittsburgh
while ($ARGV[0] =~ /^[^-!(]/) {
push(@roots, shift);
}
@roots = ('.') unless @roots;
for (@roots) { $_ = "e($_); }
$roots = join(',', @roots);
$indent = 1;
while (@ARGV) {
$_ = shift;
s/^-// || /^[()!]/ || die "Unrecognized switch: $_\n";
if ($_ eq '(') {
$out .= &tab . "(\n";
$indent++;
next;
}
elsif ($_ eq ')') {
$indent--;
$out .= &tab . ")";
}
elsif ($_ eq '!') {
$out .= &tab . "!";
next;
}
elsif ($_ eq 'name') {
$out .= &tab;
$pat = &fileglob_to_re(shift);
$out .= '/' . $pat . "/";
}
elsif ($_ eq 'perm') {
$onum = shift;
die "Malformed -perm argument: $onum\n" unless $onum =~ /^-?[0-7]+$/;
if ($onum =~ s/^-//) {
$onum = '0' . sprintf("%o", oct($onum) & 017777); # s/b 07777 ?
$out .= &tab . "((\$mode & $onum) == $onum)";
}
else {
$onum = '0' . $onum unless $onum =~ /^0/;
$out .= &tab . "((\$mode & 0777) == $onum)";
}
}
elsif ($_ eq 'type') {
($filetest = shift) =~ tr/s/S/;
$out .= &tab . "-$filetest _";
}
elsif ($_ eq 'print') {
$out .= &tab . 'print("$name\n")';
}
elsif ($_ eq 'print0') {
$out .= &tab . 'print("$name\0")';
}
elsif ($_ eq 'fstype') {
$out .= &tab;
$type = shift;
if ($type eq 'nfs')
{ $out .= '($dev < 0)'; }
else
{ $out .= '($dev >= 0)'; }
}
elsif ($_ eq 'user') {
$uname = shift;
$out .= &tab . "(\$uid == \$uid{'$uname'})";
$inituser++;
}
elsif ($_ eq 'group') {
$gname = shift;
$out .= &tab . "(\$gid == \$gid{'$gname'})";
$initgroup++;
}
elsif ($_ eq 'nouser') {
$out .= &tab . '!defined $uid{$uid}';
$inituser++;
}
elsif ($_ eq 'nogroup') {
$out .= &tab . '!defined $gid{$gid}';
$initgroup++;
}
elsif ($_ eq 'links') {
$out .= &tab . '($nlink ' . &n(shift);
}
elsif ($_ eq 'inum') {
$out .= &tab . '($ino ' . &n(shift);
}
elsif ($_ eq 'size') {
$out .= &tab . '(int(((-s _) + 511) / 512) ' . &n(shift);
}
elsif ($_ eq 'atime') {
$out .= &tab . '(int(-A _) ' . &n(shift);
}
elsif ($_ eq 'mtime') {
$out .= &tab . '(int(-M _) ' . &n(shift);
}
elsif ($_ eq 'ctime') {
$out .= &tab . '(int(-C _) ' . &n(shift);
}
elsif ($_ eq 'exec') {
for (@cmd = (); @ARGV && $ARGV[0] ne ';'; push(@cmd,shift)) { }
shift;
$_ = "@cmd";
if (m#^(/bin/)?rm -f {}$#) {
if (!@ARGV) {
$out .= &tab . 'unlink($_)';
}
else {
$out .= &tab . '(unlink($_) || 1)';
}
}
elsif (m#^(/bin/)?rm {}$#) {
$out .= &tab . '(unlink($_) || warn "$name: $!\n")';
}
else {
for (@cmd) { s/'/\\'/g; }
$" = "','";
$out .= &tab . "&exec(0, '@cmd')";
$" = ' ';
$initexec++;
}
}
elsif ($_ eq 'ok') {
for (@cmd = (); @ARGV && $ARGV[0] ne ';'; push(@cmd,shift)) { }
shift;
for (@cmd) { s/'/\\'/g; }
$" = "','";
$out .= &tab . "&exec(1, '@cmd')";
$" = ' ';
$initexec++;
}
elsif ($_ eq 'prune') {
$out .= &tab . '($prune = 1)';
}
elsif ($_ eq 'xdev') {
$out .= &tab . '!($prune |= ($dev != $topdev))';
}
elsif ($_ eq 'newer') {
$out .= &tab;
$file = shift;
$newername = 'AGE_OF' . $file;
$newername =~ s/[^\w]/_/g;
$newername = '$' . $newername;
$out .= "(-M _ < $newername)";
$initnewer .= "$newername = -M " . "e($file) . ";\n";
}
elsif ($_ eq 'eval') {
$prog = "e(shift);
$out .= &tab . "eval $prog";
}
elsif ($_ eq 'depth') {
$depth++;
next;
}
elsif ($_ eq 'ls') {
$out .= &tab . "&ls";
$initls++;
}
elsif ($_ eq 'tar') {
$out .= &tab;
die "-tar must have a filename argument\n" unless @ARGV;
$file = shift;
$fh = 'FH' . $file;
$fh =~ s/[^\w]/_/g;
$out .= "&tar($fh)";
$file = '>' . $file;
$initfile .= "open($fh, " . "e($file) .
qq{) || die "Can't open $fh: \$!\\n";\n};
$inittar++;
$flushall = "\n&tflushall;\n";
}
elsif (/^n?cpio$/) {
$depth++;
$out .= &tab;
die "-$_ must have a filename argument\n" unless @ARGV;
$file = shift;
$fh = 'FH' . $file;
$fh =~ s/[^\w]/_/g;
$out .= "&cpio('" . substr($_,0,1) . "', $fh)";
$file = '>' . $file;
$initfile .= "open($fh, " . "e($file) .
qq{) || die "Can't open $fh: \$!\\n";\n};
$initcpio++;
$flushall = "\n&flushall;\n";
}
else {
die "Unrecognized switch: -$_\n";
}
if (@ARGV) {
if ($ARGV[0] eq '-o') {
{ local($statdone) = 1; $out .= "\n" . &tab . "||\n"; }
$statdone = 0 if $indent == 1 && $delayedstat;
$saw_or++;
shift;
}
else {
$out .= " &&" unless $ARGV[0] eq ')';
$out .= "\n";
shift if $ARGV[0] eq '-a';
}
}
}
print <<"END";
$startperl
eval 'exec $perlpath -S \$0 \${1+"\$@"}'
if \$running_under_some_shell;
END
if ($initls) {
print <<'END';
@rwx = ('---','--x','-w-','-wx','r--','r-x','rw-','rwx');
@moname = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
END
}
if ($inituser || $initls) {
print 'while (($name, $pw, $uid) = getpwent) {', "\n";
print ' $uid{$name} = $uid{$uid} = $uid;', "\n" if $inituser;
print ' $user{$uid} = $name unless $user{$uid};', "\n" if $initls;
print "}\n\n";
}
if ($initgroup || $initls) {
print 'while (($name, $pw, $gid) = getgrent) {', "\n";
print ' $gid{$name} = $gid{$gid} = $gid;', "\n" if $initgroup;
print ' $group{$gid} = $name unless $group{$gid};', "\n" if $initls;
print "}\n\n";
}
print $initnewer, "\n" if $initnewer;
print $initfile, "\n" if $initfile;
$find = $depth ? "finddepth" : "find";
print <<"END";
require "$find.pl";
# Traverse desired filesystems
&$find($roots);
$flushall
exit;
sub wanted {
$out;
}
END
if ($initexec) {
print <<'END';
sub exec {
local($ok, @cmd) = @_;
foreach $word (@cmd) {
$word =~ s#{}#$name#g;
}
if ($ok) {
local($old) = select(STDOUT);
$| = 1;
print "@cmd";
select($old);
return 0 unless <STDIN> =~ /^y/;
}
chdir $cwd; # sigh
system @cmd;
chdir $dir;
return !$?;
}
END
}
if ($initls) {
print <<'END';
sub ls {
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$sizemm,
$atime,$mtime,$ctime,$blksize,$blocks) = lstat(_);
$pname = $name;
if (defined $blocks) {
$blocks = int(($blocks + 1) / 2);
}
else {
$blocks = int(($size + 1023) / 1024);
}
if (-f _) { $perms = '-'; }
elsif (-d _) { $perms = 'd'; }
elsif (-c _) { $perms = 'c'; $sizemm = &sizemm; }
elsif (-b _) { $perms = 'b'; $sizemm = &sizemm; }
elsif (-p _) { $perms = 'p'; }
elsif (-S _) { $perms = 's'; }
else { $perms = 'l'; $pname .= ' -> ' . readlink($_); }
$tmpmode = $mode;
$tmp = $rwx[$tmpmode & 7];
$tmpmode >>= 3;
$tmp = $rwx[$tmpmode & 7] . $tmp;
$tmpmode >>= 3;
$tmp = $rwx[$tmpmode & 7] . $tmp;
substr($tmp,2,1) =~ tr/-x/Ss/ if -u _;
substr($tmp,5,1) =~ tr/-x/Ss/ if -g _;
substr($tmp,8,1) =~ tr/-x/Tt/ if -k _;
$perms .= $tmp;
$user = $user{$uid} || $uid;
$group = $group{$gid} || $gid;
($sec,$min,$hour,$mday,$mon,$year) = localtime($mtime);
$moname = $moname[$mon];
if (-M _ > 365.25 / 2) {
$timeyear = $year + 1900;
}
else {
$timeyear = sprintf("%02d:%02d", $hour, $min);
}
printf "%5lu %4ld %-10s %2d %-8s %-8s %8s %s %2d %5s %s\n",
$ino,
$blocks,
$perms,
$nlink,
$user,
$group,
$sizemm,
$moname,
$mday,
$timeyear,
$pname;
1;
}
sub sizemm {
sprintf("%3d, %3d", ($rdev >> 8) & 255, $rdev & 255);
}
END
}
if ($initcpio) {
print <<'END';
sub cpio {
local($nc,$fh) = @_;
local($text);
if ($name eq 'TRAILER!!!') {
$text = '';
$size = 0;
}
else {
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks) = lstat(_);
if (-f _) {
open(IN, "./$_\0") || do {
warn "Couldn't open $name: $!\n";
return;
};
}
else {
$text = readlink($_);
$size = 0 unless defined $text;
}
}
($nm = $name) =~ s#^\./##;
$nc{$fh} = $nc;
if ($nc eq 'n') {
$cpout{$fh} .=
sprintf("%06o%06o%06o%06o%06o%06o%06o%06o%011lo%06o%011lo%s\0",
070707,
$dev & 0777777,
$ino & 0777777,
$mode & 0777777,
$uid & 0777777,
$gid & 0777777,
$nlink & 0777777,
$rdev & 0177777,
$mtime,
length($nm)+1,
$size,
$nm);
}
else {
$cpout{$fh} .= "\0" if length($cpout{$fh}) & 1;
$cpout{$fh} .= pack("SSSSSSSSLSLa*",
070707, $dev, $ino, $mode, $uid, $gid, $nlink, $rdev, $mtime,
length($nm)+1, $size, $nm . (length($nm) & 1 ? "\0" : "\0\0"));
}
if ($text ne '') {
$cpout{$fh} .= $text;
}
elsif ($size) {
&flush($fh) while ($l = length($cpout{$fh})) >= 5120;
while (sysread(IN, $cpout{$fh}, 5120 - $l, $l)) {
&flush($fh);
$l = length($cpout{$fh});
}
}
close IN;
}
sub flush {
local($fh) = @_;
while (length($cpout{$fh}) >= 5120) {
syswrite($fh,$cpout{$fh},5120);
++$blocks{$fh};
substr($cpout{$fh}, 0, 5120) = '';
}
}
sub flushall {
$name = 'TRAILER!!!';
foreach $fh (keys %cpout) {
&cpio($nc{$fh},$fh);
$cpout{$fh} .= "0" x (5120 - length($cpout{$fh}));
&flush($fh);
print $blocks{$fh} * 10, " blocks\n";
}
}
END
}
if ($inittar) {
print <<'END';
sub tar {
local($fh) = @_;
local($linkname,$header,$l,$slop);
local($linkflag) = "\0";
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks) = lstat(_);
$nm = $name;
if ($nlink > 1) {
if ($linkname = $linkseen{$fh,$dev,$ino}) {
$linkflag = 1;
}
else {
$linkseen{$fh,$dev,$ino} = $nm;
}
}
if (-f _) {
open(IN, "./$_\0") || do {
warn "Couldn't open $name: $!\n";
return;
};
$size = 0 if $linkflag ne "\0";
}
else {
$linkname = readlink($_);
$linkflag = 2 if defined $linkname;
$nm .= '/' if -d _;
$size = 0;
}
$header = pack("a100a8a8a8a12a12a8a1a100",
$nm,
sprintf("%6o ", $mode & 0777),
sprintf("%6o ", $uid & 0777777),
sprintf("%6o ", $gid & 0777777),
sprintf("%11o ", $size),
sprintf("%11o ", $mtime),
" ",
$linkflag,
$linkname);
$l = length($header) % 512;
substr($header, 148, 6) = sprintf("%6o", unpack("%16C*", $header));
substr($header, 154, 1) = "\0"; # blech
$tarout{$fh} .= $header;
$tarout{$fh} .= "\0" x (512 - $l) if $l;
if ($size) {
&tflush($fh) while ($l = length($tarout{$fh})) >= 10240;
while (sysread(IN, $tarout{$fh}, 10240 - $l, $l)) {
$slop = length($tarout{$fh}) % 512;
$tarout{$fh} .= "\0" x (512 - $slop) if $slop;
&tflush($fh);
$l = length($tarout{$fh});
}
}
close IN;
}
sub tflush {
local($fh) = @_;
while (length($tarout{$fh}) >= 10240) {
syswrite($fh,$tarout{$fh},10240);
++$blocks{$fh};
substr($tarout{$fh}, 0, 10240) = '';
}
}
sub tflushall {
local($len);
foreach $fh (keys %tarout) {
$len = 10240 - length($tarout{$fh});
$len += 10240 if $len < 1024;
$tarout{$fh} .= "\0" x $len;
&tflush($fh);
}
}
END
}
exit;
############################################################################
sub tab {
local($tabstring);
$tabstring = "\t" x ($indent / 2) . ' ' x ($indent % 2 * 4);
if (!$statdone) {
if ($_ =~ /^(name|print|prune|exec|ok|\(|\))/) {
$delayedstat++;
}
else {
if ($saw_or) {
$tabstring .= <<'ENDOFSTAT' . $tabstring;
($nlink || (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_))) &&
ENDOFSTAT
}
else {
$tabstring .= <<'ENDOFSTAT' . $tabstring;
(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
ENDOFSTAT
}
$statdone = 1;
}
}
$tabstring =~ s/^\s+/ / if $out =~ /!$/;
$tabstring;
}
sub fileglob_to_re {
local($tmp) = @_;
$tmp =~ s#([./^\$()])#\\$1#g;
$tmp =~ s/([?*])/.$1/g;
"^$tmp\$";
}
sub n {
local($n) = @_;
$n =~ s/^-/< / || $n =~ s/^\+/> / || $n =~ s/^/== /;
$n =~ s/ 0*(\d)/ $1/;
$n . ')';
}
sub quote {
local($string) = @_;
$string =~ s/'/\\'/;
"'$string'";
}
!NO!SUBS!
close OUT or die "Can't close $file: $!";
chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
|