home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2004 July / APC0407D2.iso / workshop / apache / files / ActivePerl-5.8.3.809-MSWin32-x86.msi / _27931c6b74ed0d7d384415553f770f63 < prev    next >
Encoding:
Text File  |  2004-02-02  |  24.4 KB  |  888 lines

  1. @rem = '--*-Perl-*--
  2. @echo off
  3. if "%OS%" == "Windows_NT" goto WinNT
  4. perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. goto endofperl
  6. :WinNT
  7. perl -x -S %0 %*
  8. if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
  9. if %errorlevel% == 9009 echo You do not have Perl in your PATH.
  10. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
  11. goto endofperl
  12. @rem ';
  13. #!perl
  14. #line 15
  15.     eval 'exec C:\p4view\Apps\Gecko\MSI\data\ActivePerl\Perl\bin\perl.exe -S $0 ${1+"$@"}'
  16.       if $running_under_some_shell;
  17. (my $perlpath = <<'/../') =~ s/\s*\z//;
  18. C:\p4view\Apps\Gecko\MSI\data\ActivePerl\Perl\bin\perl.exe
  19. /../
  20. use strict;
  21. use vars qw/$statdone/;
  22. use File::Spec::Functions 'curdir';
  23. my $startperl = "#! $perlpath -w";
  24.  
  25. #
  26. # Modified September 26, 1993 to provide proper handling of years after 1999
  27. #   Tom Link <tml+@pitt.edu>
  28. #   University of Pittsburgh
  29. #
  30. # Modified April 7, 1998 with nasty hacks to implement the troublesome -follow
  31. #  Billy Constantine <wdconsta@cs.adelaide.edu.au> <billy@smug.adelaide.edu.au>
  32. #  University of Adelaide, Adelaide, South Australia
  33. #
  34. # Modified 1999-06-10, 1999-07-07 to migrate to cleaner perl5 usage
  35. #   Ken Pizzini <ken@halcyon.com>
  36. #
  37. # Modified 2000-01-28 to use the 'follow' option of File::Find
  38.  
  39. sub tab ();
  40. sub n ($$);
  41. sub fileglob_to_re ($);
  42. sub quote ($);
  43.  
  44. my @roots = ();
  45. while ($ARGV[0] =~ /^[^-!(]/) {
  46.     push(@roots, shift);
  47. }
  48. @roots = (curdir()) unless @roots;
  49. for (@roots) { $_ = quote($_) }
  50. my $roots = join(', ', @roots);
  51.  
  52. my $find = "find";
  53. my $indent_depth = 1;
  54. my $stat = 'lstat';
  55. my $decl = '';
  56. my $flushall = '';
  57. my $initfile = '';
  58. my $initnewer = '';
  59. my $out = '';
  60. my $declaresubs = "sub wanted;\n";
  61. my %init = ();
  62. my ($follow_in_effect,$Skip_And) = (0,0);
  63. my $print_needed = 1;
  64.  
  65. while (@ARGV) {
  66.     $_ = shift;
  67.     s/^-// || /^[()!]/ || die "Unrecognized switch: $_\n";
  68.     if ($_ eq '(') {
  69.         $out .= tab . "(\n";
  70.         $indent_depth++;
  71.         next;
  72.     } elsif ($_ eq ')') {
  73.         --$indent_depth;
  74.         $out .= tab . ")";
  75.     } elsif ($_ eq 'follow') {
  76.         $follow_in_effect= 1;
  77.         $stat = 'stat';
  78.         $Skip_And= 1;
  79.     } elsif ($_ eq '!') {
  80.         $out .= tab . "!";
  81.         next;
  82.     } elsif ($_ eq 'name') {
  83.         $out .= tab . '/' . fileglob_to_re(shift) . "/s";
  84.     } elsif ($_ eq 'perm') {
  85.         my $onum = shift;
  86.         $onum =~ /^-?[0-7]+$/
  87.             || die "Malformed -perm argument: $onum\n";
  88.         $out .= tab;
  89.         if ($onum =~ s/^-//) {
  90.             $onum = sprintf("0%o", oct($onum) & 07777);
  91.             $out .= "((\$mode & $onum) == $onum)";
  92.         } else {
  93.             $onum =~ s/^0*/0/;
  94.             $out .= "((\$mode & 0777) == $onum)";
  95.         }
  96.     } elsif ($_ eq 'type') {
  97.         (my $filetest = shift) =~ tr/s/S/;
  98.         $out .= tab . "-$filetest _";
  99.     } elsif ($_ eq 'print') {
  100.         $out .= tab . 'print("$name\n")';
  101.     $print_needed = 0;
  102.     } elsif ($_ eq 'print0') {
  103.         $out .= tab . 'print("$name\0")';
  104.     $print_needed = 0;
  105.     } elsif ($_ eq 'fstype') {
  106.         my $type = shift;
  107.         $out .= tab;
  108.         if ($type eq 'nfs') {
  109.             $out .= '($dev < 0)';
  110.         } else {
  111.             $out .= '($dev >= 0)'; #XXX
  112.         }
  113.     } elsif ($_ eq 'user') {
  114.         my $uname = shift;
  115.         $out .= tab . "(\$uid == \$uid{'$uname'})";
  116.         $init{user} = 1;
  117.     } elsif ($_ eq 'group') {
  118.         my $gname = shift;
  119.         $out .= tab . "(\$gid == \$gid{'$gname'})";
  120.         $init{group} = 1;
  121.     } elsif ($_ eq 'nouser') {
  122.         $out .= tab . '!exists $uid{$uid}';
  123.         $init{user} = 1;
  124.     } elsif ($_ eq 'nogroup') {
  125.         $out .= tab . '!exists $gid{$gid}';
  126.         $init{group} = 1;
  127.     } elsif ($_ eq 'links') {
  128.         $out .= tab . n('$nlink', shift);
  129.     } elsif ($_ eq 'inum') {
  130.         $out .= tab . n('$ino', shift);
  131.     } elsif ($_ eq 'size') {
  132.         $_ = shift;
  133.         my $n = 'int(((-s _) + 511) / 512)';
  134.         if (s/c\z//) {
  135.             $n = 'int(-s _)';
  136.         } elsif (s/k\z//) {
  137.             $n = 'int(((-s _) + 1023) / 1024)';
  138.         }
  139.         $out .= tab . n($n, $_);
  140.     } elsif ($_ eq 'atime') {
  141.         $out .= tab . n('int(-A _)', shift);
  142.     } elsif ($_ eq 'mtime') {
  143.         $out .= tab . n('int(-M _)', shift);
  144.     } elsif ($_ eq 'ctime') {
  145.         $out .= tab . n('int(-C _)', shift);
  146.     } elsif ($_ eq 'exec') {
  147.         my @cmd = ();
  148.         while (@ARGV && $ARGV[0] ne ';')
  149.             { push(@cmd, shift) }
  150.         shift;
  151.         $out .= tab;
  152.         if ($cmd[0] =~m#^(?:(?:/usr)?/bin/)?rm$#
  153.                 && $cmd[$#cmd] eq '{}'
  154.                 && (@cmd == 2 || (@cmd == 3 && $cmd[1] eq '-f'))) {
  155.             if (@cmd == 2) {
  156.                 $out .= '(unlink($_) || warn "$name: $!\n")';
  157.             } elsif (!@ARGV) {
  158.                 $out .= 'unlink($_)';
  159.             } else {
  160.                 $out .= '(unlink($_) || 1)';
  161.             }
  162.         } else {
  163.             for (@cmd)
  164.                 { s/'/\\'/g }
  165.             { local $" = "','"; $out .= "doexec(0, '@cmd')"; }
  166.             $declaresubs .= "sub doexec (\$\@);\n";
  167.             $init{doexec} = 1;
  168.         }
  169.     $print_needed = 0;
  170.     } elsif ($_ eq 'ok') {
  171.         my @cmd = ();
  172.         while (@ARGV && $ARGV[0] ne ';')
  173.             { push(@cmd, shift) }
  174.         shift;
  175.         $out .= tab;
  176.         for (@cmd)
  177.             { s/'/\\'/g }
  178.         { local $" = "','"; $out .= "doexec(1, '@cmd')"; }
  179.         $declaresubs .= "sub doexec (\$\@);\n";
  180.         $init{doexec} = 1;
  181.     $print_needed = 0;
  182.     } elsif ($_ eq 'prune') {
  183.         $out .= tab . '($File::Find::prune = 1)';
  184.     } elsif ($_ eq 'xdev') {
  185.         $out .= tab . '!($File::Find::prune |= ($dev != $File::Find::topdev))'
  186. ;
  187.     } elsif ($_ eq 'newer') {
  188.         my $file = shift;
  189.         my $newername = 'AGE_OF' . $file;
  190.         $newername =~ s/\W/_/g;
  191.         $newername = '$' . $newername;
  192.         $out .= tab . "(-M _ < $newername)";
  193.         $initnewer .= "my $newername = -M " . quote($file) . ";\n";
  194.     } elsif ($_ eq 'eval') {
  195.         my $prog = shift;
  196.         $prog =~ s/'/\\'/g;
  197.         $out .= tab . "eval {$prog}";
  198.     } elsif ($_ eq 'depth') {
  199.         $find = 'finddepth';
  200.         next;
  201.     } elsif ($_ eq 'ls') {
  202.         $out .= tab . "ls";
  203.         $declaresubs .= "sub ls ();\n";
  204.         $init{ls} = 1;
  205.     $print_needed = 0;
  206.     } elsif ($_ eq 'tar') {
  207.         die "-tar must have a filename argument\n" unless @ARGV;
  208.         my $file = shift;
  209.         my $fh = 'FH' . $file;
  210.         $fh =~ s/\W/_/g;
  211.         $out .= tab . "tar(*$fh, \$name)";
  212.         $flushall .= "tflushall;\n";
  213.         $declaresubs .= "sub tar;\nsub tflushall ();\n";
  214.         $initfile .= "open($fh, " . quote('> ' . $file) .
  215.                      qq{) || die "Can't open $fh: \$!\\n";\n};
  216.         $init{tar} = 1;
  217.     } elsif (/^(n?)cpio\z/) {
  218.         die "-$_ must have a filename argument\n" unless @ARGV;
  219.         my $file = shift;
  220.         my $fh = 'FH' . $file;
  221.         $fh =~ s/\W/_/g;
  222.         $out .= tab . "cpio(*$fh, \$name, '$1')";
  223.         $find = 'finddepth';
  224.         $flushall .= "cflushall;\n";
  225.         $declaresubs .= "sub cpio;\nsub cflushall ();\n";
  226.         $initfile .= "open($fh, " . quote('> ' . $file) .
  227.                      qq{) || die "Can't open $fh: \$!\\n";\n};
  228.         $init{cpio} = 1;
  229.     } else {
  230.         die "Unrecognized switch: -$_\n";
  231.     }
  232.  
  233.     if (@ARGV) {
  234.         if ($ARGV[0] eq '-o') {
  235.             { local($statdone) = 1; $out .= "\n" . tab . "||\n"; }
  236.             $statdone = 0 if $indent_depth == 1 && exists $init{delayedstat};
  237.             $init{saw_or} = 1;
  238.             shift;
  239.         } else {
  240.             $out .= " &&" unless $Skip_And || $ARGV[0] eq ')';
  241.             $out .= "\n";
  242.             shift if $ARGV[0] eq '-a';
  243.         }
  244.     }
  245. }
  246.  
  247. if ($print_needed) {
  248.     $out .= "\n" . tab . '&& print("$name\n")';
  249. }
  250.  
  251.  
  252. print <<"END";
  253. $startperl
  254.     eval 'exec $perlpath -S \$0 \${1+"\$@"}'
  255.         if 0; #\$running_under_some_shell
  256.  
  257. use strict;
  258. use File::Find ();
  259.  
  260. # Set the variable \$File::Find::dont_use_nlink if you're using AFS,
  261. # since AFS cheats.
  262.  
  263. # for the convenience of &wanted calls, including -eval statements:
  264. use vars qw/*name *dir *prune/;
  265. *name   = *File::Find::name;
  266. *dir    = *File::Find::dir;
  267. *prune  = *File::Find::prune;
  268.  
  269. $declaresubs
  270.  
  271. END
  272.  
  273. if (exists $init{ls}) {
  274.     print <<'END';
  275. my @rwx = qw(--- --x -w- -wx r-- r-x rw- rwx);
  276. my @moname = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
  277.  
  278. END
  279. }
  280.  
  281. if (exists $init{user} || exists $init{ls} || exists $init{tar}) {
  282.     print "my (%uid, %user);\n";
  283.     print "while (my (\$name, \$pw, \$uid) = getpwent) {\n";
  284.     print '    $uid{$name} = $uid{$uid} = $uid;', "\n"
  285.         if exists $init{user};
  286.     print '    $user{$uid} = $name unless exists $user{$uid};', "\n"
  287.         if exists $init{ls} || exists $init{tar};
  288.     print "}\n\n";
  289. }
  290.  
  291. if (exists $init{group} || exists $init{ls} || exists $init{tar}) {
  292.     print "my (%gid, %group);\n";
  293.     print "while (my (\$name, \$pw, \$gid) = getgrent) {\n";
  294.     print '    $gid{$name} = $gid{$gid} = $gid;', "\n"
  295.         if exists $init{group};
  296.     print '    $group{$gid} = $name unless exists $group{$gid};', "\n"
  297.         if exists $init{ls} || exists $init{tar};
  298.     print "}\n\n";
  299. }
  300.  
  301. print $initnewer, "\n" if $initnewer ne '';
  302. print $initfile, "\n" if $initfile ne '';
  303. $flushall .= "exit;\n";
  304. if (exists $init{declarestat}) {
  305.     $out = <<'END' . $out;
  306.     my ($dev,$ino,$mode,$nlink,$uid,$gid);
  307.  
  308. END
  309. }
  310.  
  311. if ( $follow_in_effect ) {
  312. $out =~ s/lstat\(\$_\)/lstat(_)/;
  313. print <<"END";
  314. $decl
  315. # Traverse desired filesystems
  316. File::Find::$find( {wanted => \\&wanted, follow => 1}, $roots);
  317. $flushall
  318.  
  319. sub wanted {
  320. $out;
  321. }
  322.  
  323. END
  324. } else {
  325. print <<"END";
  326. $decl
  327. # Traverse desired filesystems
  328. File::Find::$find({wanted => \\&wanted}, $roots);
  329. $flushall
  330.  
  331. sub wanted {
  332. $out;
  333. }
  334.  
  335. END
  336. }
  337.  
  338. if (exists $init{doexec}) {
  339.     print <<'END';
  340.  
  341. use Cwd ();
  342. my $cwd = Cwd::cwd();
  343.  
  344. sub doexec ($@) {
  345.     my $ok = shift;
  346.     my @command = @_; # copy so we don't try to s/// aliases to constants
  347.     for my $word (@command)
  348.         { $word =~ s#{}#$name#g }
  349.     if ($ok) {
  350.         my $old = select(STDOUT);
  351.         $| = 1;
  352.         print "@command";
  353.         select($old);
  354.         return 0 unless <STDIN> =~ /^y/;
  355.     }
  356.     chdir $cwd; #sigh
  357.     system @command;
  358.     chdir $File::Find::dir;
  359.     return !$?;
  360. }
  361.  
  362. END
  363. }
  364.  
  365. if (exists $init{ls}) {
  366.     print <<'INTRO', <<"SUB", <<'END';
  367.  
  368. sub sizemm {
  369.     my $rdev = shift;
  370.     sprintf("%3d, %3d", ($rdev >> 8) & 0xff, $rdev & 0xff);
  371. }
  372.  
  373. sub ls () {
  374.     my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  375. INTRO
  376.         \$atime,\$mtime,\$ctime,\$blksize,\$blocks) = $stat(_);
  377. SUB
  378.     my $pname = $name;
  379.  
  380.     $blocks
  381.         or $blocks = int(($size + 1023) / 1024);
  382.  
  383.     my $perms = $rwx[$mode & 7];
  384.     $mode >>= 3;
  385.     $perms = $rwx[$mode & 7] . $perms;
  386.     $mode >>= 3;
  387.     $perms = $rwx[$mode & 7] . $perms;
  388.     substr($perms, 2, 1) =~ tr/-x/Ss/ if -u _;
  389.     substr($perms, 5, 1) =~ tr/-x/Ss/ if -g _;
  390.     substr($perms, 8, 1) =~ tr/-x/Tt/ if -k _;
  391.     if    (-f _) { $perms = '-' . $perms; }
  392.     elsif (-d _) { $perms = 'd' . $perms; }
  393.     elsif (-l _) { $perms = 'l' . $perms; $pname .= ' -> ' . readlink($_); }
  394.     elsif (-c _) { $perms = 'c' . $perms; $size = sizemm($rdev); }
  395.     elsif (-b _) { $perms = 'b' . $perms; $size = sizemm($rdev); }
  396.     elsif (-p _) { $perms = 'p' . $perms; }
  397.     elsif (-S _) { $perms = 's' . $perms; }
  398.     else         { $perms = '?' . $perms; }
  399.  
  400.     my $user = $user{$uid} || $uid;
  401.     my $group = $group{$gid} || $gid;
  402.  
  403.     my ($sec,$min,$hour,$mday,$mon,$timeyear) = localtime($mtime);
  404.     if (-M _ > 365.25 / 2) {
  405.         $timeyear += 1900;
  406.     } else {
  407.         $timeyear = sprintf("%02d:%02d", $hour, $min);
  408.     }
  409.  
  410.     printf "%5lu %4ld %-10s %3d %-8s %-8s %8s %s %2d %5s %s\n",
  411.             $ino,
  412.                  $blocks,
  413.                       $perms,
  414.                             $nlink,
  415.                                 $user,
  416.                                      $group,
  417.                                           $size,
  418.                                               $moname[$mon],
  419.                                                  $mday,
  420.                                                      $timeyear,
  421.                                                          $pname;
  422.     1;
  423. }
  424.  
  425. END
  426. }
  427.  
  428.  
  429. if (exists $init{cpio} || exists $init{tar}) {
  430. print <<'END';
  431.  
  432. my %blocks = ();
  433.  
  434. sub flush {
  435.     my ($fh, $varref, $blksz) = @_;
  436.  
  437.     while (length($$varref) >= $blksz) {
  438.         no strict qw/refs/;
  439.         syswrite($fh, $$varref, $blksz);
  440.         substr($$varref, 0, $blksz) = '';
  441.         ++$blocks{$fh};
  442.     }
  443. }
  444.  
  445. END
  446. }
  447.  
  448.  
  449. if (exists $init{cpio}) {
  450.     print <<'INTRO', <<"SUB", <<'END';
  451.  
  452. my %cpout = ();
  453. my %nc = ();
  454.  
  455. sub cpio {
  456.     my ($fh, $fname, $nc) = @_;
  457.     my $text = '';
  458.     my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  459.         $atime,$mtime,$ctime,$blksize,$blocks);
  460.     local (*IN);
  461.  
  462.     if ( ! defined $fname ) {
  463.         $fname = 'TRAILER!!!';
  464.         ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  465.           $atime,$mtime,$ctime,$blksize,$blocks) = (0) x 13;
  466.     } else {
  467.         ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  468. INTRO
  469.           \$atime,\$mtime,\$ctime,\$blksize,\$blocks) = $stat(_);
  470. SUB
  471.         if (-f _) {
  472.             open(IN, "./$_\0") || do {
  473.                 warn "Couldn't open $fname: $!\n";
  474.                 return;
  475.             }
  476.         } else {
  477.             $text = readlink($_);
  478.             $size = 0 unless defined $text;
  479.         }
  480.     }
  481.  
  482.     $fname =~ s#^\./##;
  483.     $nc{$fh} = $nc;
  484.     if ($nc eq 'n') {
  485.         $cpout{$fh} .=
  486.           sprintf("%06o%06o%06o%06o%06o%06o%06o%06o%011lo%06o%011lo%s\0",
  487.             070707,
  488.             $dev & 0777777,
  489.             $ino & 0777777,
  490.             $mode & 0777777,
  491.             $uid & 0777777,
  492.             $gid & 0777777,
  493.             $nlink & 0777777,
  494.             $rdev & 0177777,
  495.             $mtime,
  496.             length($fname)+1,
  497.             $size,
  498.             $fname);
  499.     } else {
  500.         $cpout{$fh} .= "\0" if length($cpout{$fh}) & 1;
  501.         $cpout{$fh} .= pack("SSSSSSSSLSLa*",
  502.             070707, $dev, $ino, $mode, $uid, $gid, $nlink, $rdev, $mtime,
  503.             length($fname)+1, $size,
  504.             $fname . (length($fname) & 1 ? "\0" : "\0\0"));
  505.     }
  506.  
  507.     if ($text ne '') {
  508.         $cpout{$fh} .= $text;
  509.     } elsif ($size) {
  510.         my $l;
  511.         flush($fh, \$cpout{$fh}, 5120)
  512.             while ($l = length($cpout{$fh})) >= 5120;
  513.         while (sysread(IN, $cpout{$fh}, 5120 - $l, $l)) {
  514.             flush($fh, \$cpout{$fh}, 5120);
  515.             $l = length($cpout{$fh});
  516.         }
  517.         close IN;
  518.     }
  519. }
  520.  
  521. sub cflushall () {
  522.     for my $fh (keys %cpout) {
  523.         cpio($fh, undef, $nc{$fh});
  524.         $cpout{$fh} .= "0" x (5120 - length($cpout{$fh}));
  525.         flush($fh, \$cpout{$fh}, 5120);
  526.         print $blocks{$fh} * 10, " blocks\n";
  527.     }
  528. }
  529.  
  530. END
  531. }
  532.  
  533. if (exists $init{tar}) {
  534.     print <<'INTRO', <<"SUB", <<'END';
  535.  
  536. my %tarout = ();
  537. my %linkseen = ();
  538.  
  539. sub tar {
  540.     my ($fh, $fname) = @_;
  541.     my $prefix = '';
  542.     my $typeflag = '0';
  543.     my $linkname;
  544.     my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  545. INTRO
  546.         \$atime,\$mtime,\$ctime,\$blksize,\$blocks) = $stat(_);
  547. SUB
  548.     local (*IN);
  549.  
  550.     if ($nlink > 1) {
  551.         if ($linkname = $linkseen{$fh, $dev, $ino}) {
  552.             if (length($linkname) > 100) {
  553.                 warn "$0: omitting file with linkname ",
  554.                      "too long for tar output: $linkname\n";
  555.                 return;
  556.             }
  557.             $typeflag = '1';
  558.             $size = 0;
  559.         } else {
  560.             $linkseen{$fh, $dev, $ino} = $fname;
  561.         }
  562.     }
  563.     if ($typeflag eq '0') {
  564.         if (-f _) {
  565.             open(IN, "./$_\0") || do {
  566.                 warn "Couldn't open $fname: $!\n";
  567.                 return;
  568.             }
  569.         } else {
  570.             $linkname = readlink($_);
  571.             if (defined $linkname) { $typeflag = '2' }
  572.             elsif (-c _) { $typeflag = '3' }
  573.             elsif (-b _) { $typeflag = '4' }
  574.             elsif (-d _) { $typeflag = '5' }
  575.             elsif (-p _) { $typeflag = '6' }
  576.         }
  577.     }
  578.  
  579.     if (length($fname) > 100) {
  580.         ($prefix, $fname) = ($fname =~ m#\A(.*?)/(.{,100})\Z(?!\n)#);
  581.         if (!defined($fname) || length($prefix) > 155) {
  582.             warn "$0: omitting file with name too long for tar output: ",
  583.                  $fname, "\n";
  584.             return;
  585.         }
  586.     }
  587.  
  588.     $size = 0 if $typeflag ne '0';
  589.     my $header = pack("a100a8a8a8a12a12a8a1a100a6a2a32a32a8a8a155",
  590.                         $fname,
  591.                         sprintf("%7o ", $mode &    0777),
  592.                         sprintf("%7o ", $uid  & 0777777),
  593.                         sprintf("%7o ", $gid  & 0777777),
  594.                         sprintf("%11o ", $size),
  595.                         sprintf("%11o ", $mtime),
  596.                         ' 'x8,
  597.                         $typeflag,
  598.                         defined $linkname ? $linkname : '',
  599.                         "ustar\0",
  600.                         "00",
  601.                         $user{$uid},
  602.                         $group{$gid},
  603.                         ($rdev >> 8) & 0xff,
  604.                         $rdev & 0xff,
  605.                         $prefix,
  606.                      );
  607.     substr($header, 148, 8) = sprintf("%7o ", unpack("%16C*", $header));
  608.     my $l = length($header) % 512;
  609.     $tarout{$fh} .= $header;
  610.     $tarout{$fh} .= "\0" x (512 - $l) if $l;
  611.  
  612.     if ($size) {
  613.         flush($fh, \$tarout{$fh}, 10240)
  614.             while ($l = length($tarout{$fh})) >= 10240;
  615.         while (sysread(IN, $tarout{$fh}, 10240 - $l, $l)) {
  616.             my $slop = length($tarout{$fh}) % 512;
  617.             $tarout{$fh} .= "\0" x (512 - $slop) if $slop;
  618.             flush($fh, \$tarout{$fh}, 10240);
  619.             $l = length($tarout{$fh});
  620.         }
  621.         close IN;
  622.     }
  623. }
  624.  
  625. sub tflushall () {
  626.     my $len;
  627.     for my $fh (keys %tarout) {
  628.         $len = 10240 - length($tarout{$fh});
  629.         $len += 10240 if $len < 1024;
  630.         $tarout{$fh} .= "\0" x $len;
  631.         flush($fh, \$tarout{$fh}, 10240);
  632.     }
  633. }
  634.  
  635. END
  636. }
  637.  
  638. exit;
  639.  
  640. ############################################################################
  641.  
  642. sub tab () {
  643.     my $tabstring;
  644.  
  645.     $tabstring = "\t" x ($indent_depth/2) . ' ' x ($indent_depth%2 * 4);
  646.     if (!$statdone) {
  647.         if ($_ =~ /^(?:name|print|prune|exec|ok|\(|\))/) {
  648.             $init{delayedstat} = 1;
  649.         } else {
  650.             my $statcall = '(($dev,$ino,$mode,$nlink,$uid,$gid) = '
  651.                          . $stat . '($_))';
  652.             if (exists $init{saw_or}) {
  653.                 $tabstring .= "(\$nlink || $statcall) &&\n" . $tabstring;
  654.             } else {
  655.                 $tabstring .= "$statcall &&\n" . $tabstring;
  656.             }
  657.             $statdone = 1;
  658.             $init{declarestat} = 1;
  659.         }
  660.     }
  661.     $tabstring =~ s/^\s+/ / if $out =~ /!$/;
  662.     $tabstring;
  663. }
  664.  
  665. sub fileglob_to_re ($) {
  666.     my $x = shift;
  667.     $x =~ s#([./^\$()+])#\\$1#g;
  668.     $x =~ s#([?*])#.$1#g;
  669.     "^$x\\z";
  670. }
  671.  
  672. sub n ($$) {
  673.     my ($pre, $n) = @_;
  674.     $n =~ s/^-/< / || $n =~ s/^\+/> / || $n =~ s/^/== /;
  675.     $n =~ s/ 0*(\d)/ $1/;
  676.     "($pre $n)";
  677. }
  678.  
  679. sub quote ($) {
  680.     my $string = shift;
  681.     $string =~ s/\\/\\\\/g;
  682.     $string =~ s/'/\\'/g;
  683.     "'$string'";
  684. }
  685.  
  686. __END__
  687.  
  688. =head1 NAME
  689.  
  690. find2perl - translate find command lines to Perl code
  691.  
  692. =head1 SYNOPSIS
  693.  
  694.     find2perl [paths] [predicates] | perl
  695.  
  696. =head1 DESCRIPTION
  697.  
  698. find2perl is a little translator to convert find command lines to
  699. equivalent Perl code.  The resulting code is typically faster than
  700. running find itself.
  701.  
  702. "paths" are a set of paths where find2perl will start its searches and
  703. "predicates" are taken from the following list.
  704.  
  705. =over 4
  706.  
  707. =item C<! PREDICATE>
  708.  
  709. Negate the sense of the following predicate.  The C<!> must be passed as
  710. a distinct argument, so it may need to be surrounded by whitespace and/or
  711. quoted from interpretation by the shell using a backslash (just as with
  712. using C<find(1)>).
  713.  
  714. =item C<( PREDICATES )>
  715.  
  716. Group the given PREDICATES.  The parentheses must be passed as distinct
  717. arguments, so they may need to be surrounded by whitespace and/or
  718. quoted from interpretation by the shell using a backslash (just as with
  719. using C<find(1)>).
  720.  
  721. =item C<PREDICATE1 PREDICATE2>
  722.  
  723. True if _both_ PREDICATE1 and PREDICATE2 are true; PREDICATE2 is not
  724. evaluated if PREDICATE1 is false.
  725.  
  726. =item C<PREDICATE1 -o PREDICATE2>
  727.  
  728. True if either one of PREDICATE1 or PREDICATE2 is true; PREDICATE2 is
  729. not evaluated if PREDICATE1 is true.
  730.  
  731. =item C<-follow>
  732.  
  733. Follow (dereference) symlinks.  The checking of file attributes depends
  734. on the position of the C<-follow> option. If it precedes the file
  735. check option, an C<stat> is done which means the file check applies to the
  736. file the symbolic link is pointing to. If C<-follow> option follows the
  737. file check option, this now applies to the symbolic link itself, i.e.
  738. an C<lstat> is done.
  739.  
  740. =item C<-depth>
  741.  
  742. Change directory traversal algorithm from breadth-first to depth-first.
  743.  
  744. =item C<-prune>
  745.  
  746. Do not descend into the directory currently matched.
  747.  
  748. =item C<-xdev>
  749.  
  750. Do not traverse mount points (prunes search at mount-point directories).
  751.  
  752. =item C<-name GLOB>
  753.  
  754. File name matches specified GLOB wildcard pattern.  GLOB may need to be
  755. quoted to avoid interpretation by the shell (just as with using
  756. C<find(1)>).
  757.  
  758. =item C<-perm PERM>
  759.  
  760. Low-order 9 bits of permission match octal value PERM.
  761.  
  762. =item C<-perm -PERM>
  763.  
  764. The bits specified in PERM are all set in file's permissions.
  765.  
  766. =item C<-type X>
  767.  
  768. The file's type matches perl's C<-X> operator.
  769.  
  770. =item C<-fstype TYPE>
  771.  
  772. Filesystem of current path is of type TYPE (only NFS/non-NFS distinction
  773. is implemented).
  774.  
  775. =item C<-user USER>
  776.  
  777. True if USER is owner of file.
  778.  
  779. =item C<-group GROUP>
  780.  
  781. True if file's group is GROUP.
  782.  
  783. =item C<-nouser>
  784.  
  785. True if file's owner is not in password database.
  786.  
  787. =item C<-nogroup>
  788.  
  789. True if file's group is not in group database.
  790.  
  791. =item C<-inum INUM>
  792.  
  793. True file's inode number is INUM.
  794.  
  795. =item C<-links N>
  796.  
  797. True if (hard) link count of file matches N (see below).
  798.  
  799. =item C<-size N>
  800.  
  801. True if file's size matches N (see below) N is normally counted in
  802. 512-byte blocks, but a suffix of "c" specifies that size should be
  803. counted in characters (bytes) and a suffix of "k" specifes that
  804. size should be counted in 1024-byte blocks.
  805.  
  806. =item C<-atime N>
  807.  
  808. True if last-access time of file matches N (measured in days) (see
  809. below).
  810.  
  811. =item C<-ctime N>
  812.  
  813. True if last-changed time of file's inode matches N (measured in days,
  814. see below).
  815.  
  816. =item C<-mtime N>
  817.  
  818. True if last-modified time of file matches N (measured in days, see below).
  819.  
  820. =item C<-newer FILE>
  821.  
  822. True if last-modified time of file matches N.
  823.  
  824. =item C<-print>
  825.  
  826. Print out path of file (always true). If none of C<-exec>, C<-ls>,
  827. C<-print0>, or C<-ok> is specified, then C<-print> will be added
  828. implicitly.
  829.  
  830. =item C<-print0>
  831.  
  832. Like -print, but terminates with \0 instead of \n.
  833.  
  834. =item C<-exec OPTIONS ;>
  835.  
  836. exec() the arguments in OPTIONS in a subprocess; any occurrence of {} in
  837. OPTIONS will first be substituted with the path of the current
  838. file.  Note that the command "rm" has been special-cased to use perl's
  839. unlink() function instead (as an optimization).  The C<;> must be passed as
  840. a distinct argument, so it may need to be surrounded by whitespace and/or
  841. quoted from interpretation by the shell using a backslash (just as with
  842. using C<find(1)>).
  843.  
  844. =item C<-ok OPTIONS ;>
  845.  
  846. Like -exec, but first prompts user; if user's response does not begin
  847. with a y, skip the exec.  The C<;> must be passed as
  848. a distinct argument, so it may need to be surrounded by whitespace and/or
  849. quoted from interpretation by the shell using a backslash (just as with
  850. using C<find(1)>).
  851.  
  852. =item C<-eval EXPR>
  853.  
  854. Has the perl script eval() the EXPR.  
  855.  
  856. =item C<-ls>
  857.  
  858. Simulates C<-exec ls -dils {} ;>
  859.  
  860. =item C<-tar FILE>
  861.  
  862. Adds current output to tar-format FILE.
  863.  
  864. =item C<-cpio FILE>
  865.  
  866. Adds current output to old-style cpio-format FILE.
  867.  
  868. =item C<-ncpio FILE>
  869.  
  870. Adds current output to "new"-style cpio-format FILE.
  871.  
  872. =back
  873.  
  874. Predicates which take a numeric argument N can come in three forms:
  875.  
  876.    * N is prefixed with a +: match values greater than N
  877.    * N is prefixed with a -: match values less than N
  878.    * N is not prefixed with either + or -: match only values equal to N
  879.  
  880. =head1 SEE ALSO
  881.  
  882. find
  883.  
  884. =cut
  885.  
  886. __END__
  887. :endofperl
  888.