3 if test ! -f config.sh; then
5 ln ../../config.sh . || \
6 ln ../../../config.sh . || \
7 (echo "Can't find config.sh."; exit 1)
12 : This forces SH files to create target in same directory as SH file.
13 : This is so that make depend always knows where to find SH derivatives.
15 */*) cd `expr X$0 : 'X\(.*\)/'` ;;
17 echo "Extracting find2perl (with variable substitutions)"
18 : This section of the file will have variable substitutions done on it.
19 : Move anything that needs config subs from !NO!SUBS! section to !GROK!THIS!.
20 : Protect any dollar signs and backticks that you do not want interpreted
21 : by putting a backslash in front. You may delete these comments.
23 $spitshell >find2perl <<!GROK!THIS!
26 # Modified September 26, 1993 to provide proper handling of years after 1999
27 # Tom Link <tml+@pitt.edu>
28 # University of Pittsburgh
30 eval 'exec $bin/perl -S \$0 \${1+"\$@"}'
31 if \$running_under_some_shell;
37 : In the following dollars and backticks do not need the extra backslash.
38 $spitshell >>find2perl <<'!NO!SUBS!'
40 while ($ARGV[0] =~ /^[^-!(]/) {
43 @roots = ('.') unless @roots;
44 for (@roots) { $_ = "e($_); }
45 $roots = join(',', @roots);
51 s/^-// || /^[()!]/ || die "Unrecognized switch: $_\n";
65 elsif ($_ eq 'name') {
67 $pat = &fileglob_to_re(shift);
68 $out .= '/' . $pat . "/";
70 elsif ($_ eq 'perm') {
72 die "Malformed -perm argument: $onum\n" unless $onum =~ /^-?[0-7]+$/;
73 if ($onum =~ s/^-//) {
74 $onum = '0' . sprintf("%o", oct($onum) & 017777); # s/b 07777 ?
75 $out .= &tab . "((\$mode & $onum) == $onum)";
78 $onum = '0' . $onum unless $onum =~ /^0/;
79 $out .= &tab . "((\$mode & 0777) == $onum)";
82 elsif ($_ eq 'type') {
83 ($filetest = shift) =~ tr/s/S/;
84 $out .= &tab . "-$filetest _";
86 elsif ($_ eq 'print') {
87 $out .= &tab . 'print("$name\n")';
89 elsif ($_ eq 'print0') {
90 $out .= &tab . 'print("$name\0")';
92 elsif ($_ eq 'fstype') {
96 { $out .= '($dev < 0)'; }
98 { $out .= '($dev >= 0)'; }
100 elsif ($_ eq 'user') {
102 $out .= &tab . "(\$uid == \$uid{'$uname'})";
105 elsif ($_ eq 'group') {
107 $out .= &tab . "(\$gid == \$gid{'$gname'})";
110 elsif ($_ eq 'nouser') {
111 $out .= &tab . '!defined $uid{$uid}';
114 elsif ($_ eq 'nogroup') {
115 $out .= &tab . '!defined $gid{$gid}';
118 elsif ($_ eq 'links') {
119 $out .= &tab . '($nlink ' . &n(shift);
121 elsif ($_ eq 'inum') {
122 $out .= &tab . '($ino ' . &n(shift);
124 elsif ($_ eq 'size') {
125 $out .= &tab . '(int((-s _ + 511) / 512) ' . &n(shift);
127 elsif ($_ eq 'atime') {
128 $out .= &tab . '(int(-A _) ' . &n(shift);
130 elsif ($_ eq 'mtime') {
131 $out .= &tab . '(int(-M _) ' . &n(shift);
133 elsif ($_ eq 'ctime') {
134 $out .= &tab . '(int(-C _) ' . &n(shift);
136 elsif ($_ eq 'exec') {
137 for (@cmd = (); @ARGV && $ARGV[0] ne ';'; push(@cmd,shift)) { }
140 if (m#^(/bin/)?rm -f {}$#) {
142 $out .= &tab . 'unlink($_)';
145 $out .= &tab . '(unlink($_) || 1)';
148 elsif (m#^(/bin/)?rm {}$#) {
149 $out .= &tab . '(unlink($_) || warn "$name: $!\n")';
152 for (@cmd) { s/'/\\'/g; }
154 $out .= &tab . "&exec(0, '@cmd')";
160 for (@cmd = (); @ARGV && $ARGV[0] ne ';'; push(@cmd,shift)) { }
162 for (@cmd) { s/'/\\'/g; }
164 $out .= &tab . "&exec(1, '@cmd')";
168 elsif ($_ eq 'prune') {
169 $out .= &tab . '($prune = 1)';
171 elsif ($_ eq 'xdev') {
172 $out .= &tab . '(($prune |= ($dev != $topdev)),1)';
174 elsif ($_ eq 'newer') {
177 $newername = 'AGE_OF' . $file;
178 $newername =~ s/[^\w]/_/g;
179 $newername = '$' . $newername;
180 $out .= "(-M _ < $newername)";
181 $initnewer .= "$newername = -M " . "e($file) . ";\n";
183 elsif ($_ eq 'eval') {
184 $prog = "e(shift);
185 $out .= &tab . "eval $prog";
187 elsif ($_ eq 'depth') {
192 $out .= &tab . "&ls";
195 elsif ($_ eq 'tar') {
197 die "-tar must have a filename argument\n" unless @ARGV;
203 $initfile .= "open($fh, " . "e($file) .
204 qq{) || die "Can't open $fh: \$!\\n";\n};
206 $flushall = "\n&tflushall;\n";
211 die "-$_ must have a filename argument\n" unless @ARGV;
215 $out .= "&cpio('" . substr($_,0,1) . "', $fh)";
217 $initfile .= "open($fh, " . "e($file) .
218 qq{) || die "Can't open $fh: \$!\\n";\n};
220 $flushall = "\n&flushall;\n";
223 die "Unrecognized switch: -$_\n";
226 if ($ARGV[0] eq '-o') {
227 { local($statdone) = 1; $out .= "\n" . &tab . "||\n"; }
228 $statdone = 0 if $indent == 1 && $delayedstat;
233 $out .= " &&" unless $ARGV[0] eq ')';
235 shift if $ARGV[0] eq '-a';
243 eval 'exec $bin/perl -S \$0 \${1+"\$@"}'
244 if \$running_under_some_shell;
250 @rwx = ('---','--x','-w-','-wx','r--','r-x','rw-','rwx');
251 @moname = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
256 if ($inituser || $initls) {
257 print 'while (($name, $pw, $uid) = getpwent) {', "\n";
258 print ' $uid{$name} = $uid{$uid} = $uid;', "\n" if $inituser;
259 print ' $user{$uid} = $name unless $user{$uid};', "\n" if $initls;
263 if ($initgroup || $initls) {
264 print 'while (($name, $pw, $gid) = getgrent) {', "\n";
265 print ' $gid{$name} = $gid{$gid} = $gid;', "\n" if $initgroup;
266 print ' $group{$gid} = $name unless $group{$gid};', "\n" if $initls;
270 print $initnewer, "\n" if $initnewer;
272 print $initfile, "\n" if $initfile;
274 $find = $depth ? "finddepth" : "find";
278 # Traverse desired filesystems
293 local($ok, @cmd) = @_;
294 foreach $word (@cmd) {
295 $word =~ s#{}#$name#g;
298 local($old) = select(STDOUT);
302 return 0 unless <STDIN> =~ /^y/;
316 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$sizemm,
317 $atime,$mtime,$ctime,$blksize,$blocks) = lstat(_);
321 if (defined $blocks) {
322 $blocks = int(($blocks + 1) / 2);
325 $blocks = int(($size + 1023) / 1024);
328 if (-f _) { $perms = '-'; }
329 elsif (-d _) { $perms = 'd'; }
330 elsif (-c _) { $perms = 'c'; $sizemm = &sizemm; }
331 elsif (-b _) { $perms = 'b'; $sizemm = &sizemm; }
332 elsif (-p _) { $perms = 'p'; }
333 elsif (-S _) { $perms = 's'; }
334 else { $perms = 'l'; $pname .= ' -> ' . readlink($_); }
337 $tmp = $rwx[$tmpmode & 7];
339 $tmp = $rwx[$tmpmode & 7] . $tmp;
341 $tmp = $rwx[$tmpmode & 7] . $tmp;
342 substr($tmp,2,1) =~ tr/-x/Ss/ if -u _;
343 substr($tmp,5,1) =~ tr/-x/Ss/ if -g _;
344 substr($tmp,8,1) =~ tr/-x/Tt/ if -k _;
347 $user = $user{$uid} || $uid;
348 $group = $group{$gid} || $gid;
350 ($sec,$min,$hour,$mday,$mon,$year) = localtime($mtime);
351 $moname = $moname[$mon];
352 if (-M _ > 365.25 / 2) {
353 $timeyear = $year + 1900;
356 $timeyear = sprintf("%02d:%02d", $hour, $min);
359 printf "%5lu %4ld %-10s %2d %-8s %-8s %8s %s %2d %5s %s\n",
375 sprintf("%3d, %3d", ($rdev >> 8) & 255, $rdev & 255);
387 if ($name eq 'TRAILER!!!') {
392 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
393 $atime,$mtime,$ctime,$blksize,$blocks) = lstat(_);
395 open(IN, "./$_\0") || do {
396 warn "Couldn't open $name: $!\n";
401 $text = readlink($_);
402 $size = 0 unless defined $text;
406 ($nm = $name) =~ s#^\./##;
410 sprintf("%06o%06o%06o%06o%06o%06o%06o%06o%011lo%06o%011lo%s\0",
425 $cpout{$fh} .= "\0" if length($cpout{$fh}) & 1;
426 $cpout{$fh} .= pack("SSSSSSSSLSLa*",
427 070707, $dev, $ino, $mode, $uid, $gid, $nlink, $rdev, $mtime,
428 length($nm)+1, $size, $nm . (length($nm) & 1 ? "\0" : "\0\0"));
431 $cpout{$fh} .= $text;
434 &flush($fh) while ($l = length($cpout{$fh})) >= 5120;
435 while (sysread(IN, $cpout{$fh}, 5120 - $l, $l)) {
437 $l = length($cpout{$fh});
446 while (length($cpout{$fh}) >= 5120) {
447 syswrite($fh,$cpout{$fh},5120);
449 substr($cpout{$fh}, 0, 5120) = '';
454 $name = 'TRAILER!!!';
455 foreach $fh (keys %cpout) {
457 $cpout{$fh} .= "0" x (5120 - length($cpout{$fh}));
459 print $blocks{$fh} * 10, " blocks\n";
470 local($linkname,$header,$l,$slop);
471 local($linkflag) = "\0";
473 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
474 $atime,$mtime,$ctime,$blksize,$blocks) = lstat(_);
477 if ($linkname = $linkseen{$fh,$dev,$ino}) {
481 $linkseen{$fh,$dev,$ino} = $nm;
485 open(IN, "./$_\0") || do {
486 warn "Couldn't open $name: $!\n";
489 $size = 0 if $linkflag ne "\0";
492 $linkname = readlink($_);
493 $linkflag = 2 if defined $linkname;
498 $header = pack("a100a8a8a8a12a12a8a1a100",
500 sprintf("%6o ", $mode & 0777),
501 sprintf("%6o ", $uid & 0777777),
502 sprintf("%6o ", $gid & 0777777),
503 sprintf("%11o ", $size),
504 sprintf("%11o ", $mtime),
508 $l = length($header) % 512;
509 substr($header, 148, 6) = sprintf("%6o", unpack("%16C*", $header));
510 substr($header, 154, 1) = "\0"; # blech
511 $tarout{$fh} .= $header;
512 $tarout{$fh} .= "\0" x (512 - $l) if $l;
514 &tflush($fh) while ($l = length($tarout{$fh})) >= 10240;
515 while (sysread(IN, $tarout{$fh}, 10240 - $l, $l)) {
516 $slop = length($tarout{$fh}) % 512;
517 $tarout{$fh} .= "\0" x (512 - $slop) if $slop;
519 $l = length($tarout{$fh});
528 while (length($tarout{$fh}) >= 10240) {
529 syswrite($fh,$tarout{$fh},10240);
531 substr($tarout{$fh}, 0, 10240) = '';
538 foreach $fh (keys %tarout) {
539 $len = 10240 - length($tarout{$fh});
540 $len += 10240 if $len < 1024;
541 $tarout{$fh} .= "\0" x $len;
551 ############################################################################
556 $tabstring = "\t" x ($indent / 2) . ' ' x ($indent % 2 * 4);
558 if ($_ =~ /^(name|print|prune|exec|ok|\(|\))/) {
563 $tabstring .= <<'ENDOFSTAT' . $tabstring;
564 ($nlink || (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_))) &&
568 $tabstring .= <<'ENDOFSTAT' . $tabstring;
569 (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
575 $tabstring =~ s/^\s+/ / if $out =~ /!$/;
582 $tmp =~ s#([./^\$()])#\\$1#g;
583 $tmp =~ s/([?*])/.$1/g;
590 $n =~ s/^-/< / || $n =~ s/^\+/> / || $n =~ s/^/== /;
591 $n =~ s/ 0*(\d)/ $1/;