home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / perl / scripts-osu / find2perl.shar < prev    next >
Encoding:
Internet Message Format  |  1991-03-06  |  15.3 KB

  1. Path: tut.cis.ohio-state.edu!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!elroy.jpl.nasa.gov!jpl-devvax!lwall
  2. From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: find2perl
  5. Message-ID: <11709@jpl-devvax.JPL.NASA.GOV>
  6. Date: 7 Mar 91 02:27:36 GMT
  7. References: <11674@jpl-devvax.JPL.NASA.GOV> <40887@genrad.UUCP>
  8. Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall)
  9. Organization: Jet Propulsion Laboratory, Pasadena, CA
  10. Lines: 675
  11.  
  12. In article <40887@genrad.UUCP> rep@thor.genrad.COM (Pete Peterson) writes:
  13. : In article <11674@jpl-devvax.JPL.NASA.GOV> lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes:
  14. :  >This is an alpha version of find2perl.  It spits out a perl script that
  15. :  >does the same thing (hopefully) as the corresponding find command.
  16. :  >
  17. :  >Usage:
  18. :  >
  19. :  >    find2perl . -name '*.bak' -print | perl
  20. :  >
  21. :  >This isn't thoroughly tested.  It does do -print0 and -eval.  It doesn't
  22. :  >do -ls or -cpio (yet).  It does try pretty hard to avoid unnecessary
  23. :  >stats.
  24. : OK, I give up.  I'll ask the dumb question.  Why does it do:
  25. :             $pat = "*$pat*" unless $pat =~ tr/?*[//;
  26. : thus changing "find2perl . -name 'core'" into "find2perl . -name '*core*'"? 
  27.  
  28. Not a dumb question at all.  I misread the man page, and got confused by
  29. a feature that only applies to "fast find".
  30.  
  31. I've fixed that, and added -depth, -ls, -cpio, -ncpio and -tar.  So you
  32. can call this a beta.
  33.  
  34. I didn't realize till now just how much random crap tar and cpio leave sitting
  35. around in their output files...
  36.  
  37. BTW, Sun's find -cpio sets the inode number of a directory wrong, though
  38. it's probable that no one actually looks at it.
  39.  
  40. Larry
  41.  
  42. #!/bin/sh
  43. : make a subdirectory, cd to it, and run this through sh.
  44. echo 'If this kit is complete, "End of kit" will echo at the end'
  45. echo Extracting find2perl
  46. sed >find2perl <<'!STUFFY!FUNK!' -e 's/X//'
  47. X#!/usr/bin/perl
  48. X
  49. Xwhile ($ARGV[0] =~ /^[^-(]/) {
  50. X    push(@roots, shift);
  51. X}
  52. X@roots = ('.') unless @roots;
  53. Xfor (@roots) { $_ = "e($_); }
  54. X$roots = join(',', @roots);
  55. X
  56. X$indent = 1;
  57. X
  58. Xwhile (@ARGV) {
  59. X    $_ = shift;
  60. X    if ($_ eq '(') {
  61. X    $out .= &tab . "(\n";
  62. X    $indent++;
  63. X    next;
  64. X    }
  65. X    elsif ($_ eq ')') {
  66. X    $indent--;
  67. X    $out .= &tab . ")";
  68. X    }
  69. X    elsif ($_ eq '!') {
  70. X    $out .= &tab . "!";
  71. X    next;
  72. X    }
  73. X    else {
  74. X    s/^-// || die "Unrecognized switch: $_\n";
  75. X    }
  76. X    if ($_ eq 'name') {
  77. X    $out .= &tab;
  78. X    $pat = &fileglob_to_re(shift);
  79. X    $out .= '/' . $pat . "/";
  80. X    }
  81. X    elsif ($_ eq 'perm') {
  82. X    $onum = shift;
  83. X    die "Malformed -perm argument: $onum\n" unless $onum =~ /^-?[0-7]+$/;
  84. X    if ($onum =~ s/^-//) {
  85. X        $onum = '0' . sprintf("%o", oct($onum) & 017777);    # s/b 07777 ?
  86. X        $out .= &tab . "(\$mode & $onum) == $onum";
  87. X    }
  88. X    else {
  89. X        $onum = '0' . $onum unless $onum =~ /^0/;
  90. X        $out .= &tab . "(\$mode & 0777) == $onum";
  91. X    }
  92. X    }
  93. X    elsif ($_ eq 'type') {
  94. X    ($filetest = shift) =~ tr/s/S/;
  95. X    $out .= &tab . "-$filetest _";
  96. X    }
  97. X    elsif ($_ eq 'print') {
  98. X    $out .= &tab . 'print("$name\n")';
  99. X    }
  100. X    elsif ($_ eq 'print0') {
  101. X    $out .= &tab . 'print("$name\0")';
  102. X    }
  103. X    elsif ($_ eq 'fstype') {
  104. X    $out .= &tab;
  105. X    $type = shift;
  106. X    if ($type eq 'nfs')
  107. X        { $out .= '$dev < 0'; }
  108. X    else
  109. X        { $out .= '$dev >= 0'; }
  110. X    }
  111. X    elsif ($_ eq 'user') {
  112. X    $uname = shift;
  113. X    $out .= &tab . "\$uid == \$uid{'$uname'}";
  114. X    $inituser++;
  115. X    }
  116. X    elsif ($_ eq 'group') {
  117. X    $gname = shift;
  118. X    $out .= &tab . "\$gid == \$gid('$gname')";
  119. X    $initgroup++;
  120. X    }
  121. X    elsif ($_ eq 'nouser') {
  122. X    $out .= &tab . '!defined $uid{$uid}';
  123. X    $inituser++;
  124. X    }
  125. X    elsif ($_ eq 'nogroup') {
  126. X    $out .= &tab . '!defined $gid{$gid}';
  127. X    $initgroup++;
  128. X    }
  129. X    elsif ($_ eq 'links') {
  130. X    $out .= &tab . '$nlink ' . &n(shift);
  131. X    }
  132. X    elsif ($_ eq 'inum') {
  133. X    $out .= &tab . '$ino ' . &n(shift);
  134. X    }
  135. X    elsif ($_ eq 'size') {
  136. X    $out .= &tab . 'int((-s _ + 511) / 512) ' . &n(shift);
  137. X    }
  138. X    elsif ($_ eq 'atime') {
  139. X    $out .= &tab . 'int(-A _) ' . &n(shift);
  140. X    }
  141. X    elsif ($_ eq 'mtime') {
  142. X    $out .= &tab . 'int(-M _) ' . &n(shift);
  143. X    }
  144. X    elsif ($_ eq 'ctime') {
  145. X    $out .= &tab . 'int(-C _) ' . &n(shift);
  146. X    }
  147. X    elsif ($_ eq 'exec') {
  148. X    for (@cmd = (); @ARGV && $ARGV[0] ne ';'; push(@cmd,shift)) { }
  149. X    shift;
  150. X    for (@cmd) { s/'/\\'/g; }
  151. X    $" = "','";
  152. X    $out .= &tab . "&exec(0, '@cmd')";
  153. X    $" = ' ';
  154. X    $initexec++;
  155. X    }
  156. X    elsif ($_ eq 'ok') {
  157. X    for (@cmd = (); @ARGV && $ARGV[0] ne ';'; push(@cmd,shift)) { }
  158. X    shift;
  159. X    for (@cmd) { s/'/\\'/g; }
  160. X    $" = "','";
  161. X    $out .= &tab . "&exec(1, '@cmd')";
  162. X    $" = ' ';
  163. X    $initexec++;
  164. X    }
  165. X    elsif ($_ eq 'prune') {
  166. X    $out .= &tab . '($prune = 1)';
  167. X    }
  168. X    elsif ($_ eq 'xdev') {
  169. X    $out .= &tab . '(($prune |= ($dev != $topdev)),1)';
  170. X    }
  171. X    elsif ($_ eq 'newer') {
  172. X    $out .= &tab;
  173. X    $file = shift;
  174. X    $newername = 'AGE_OF' . $file;
  175. X    $newername =~ s/[^\w]/_/g;
  176. X    $newername = '$' . $newername;
  177. X    $out .= "-M _ < $newername";
  178. X    $initnewer .= "$newername = -M " . "e($file) . ";\n";
  179. X    }
  180. X    elsif ($_ eq 'eval') {
  181. X    $prog = "e(shift);
  182. X    $out .= &tab . "eval $prog";
  183. X    }
  184. X    elsif ($_ eq 'depth') {
  185. X    $depth++;
  186. X    next;
  187. X    }
  188. X    elsif ($_ eq 'ls') {
  189. X    $out .= &tab . "&ls";
  190. X    $initls++;
  191. X    }
  192. X    elsif ($_ eq 'tar') {
  193. X    $out .= &tab;
  194. X    die "-tar must have a filename argument\n" unless @ARGV;
  195. X    $file = shift;
  196. X    $fh = 'FH' . $file;
  197. X    $fh =~ s/[^\w]/_/g;
  198. X    $out .= "&tar($fh)";
  199. X    $file = '>' . $file;
  200. X    $initfile .= "open($fh, " . "e($file) .
  201. X      qq{) || die "Can't open $fh: \$!\\n";\n};
  202. X    $inittar++;
  203. X    $flushall = "\n&tflushall;\n";
  204. X    }
  205. X    elsif (/^n?cpio$/) {
  206. X    $depth++;
  207. X    $out .= &tab;
  208. X    die "-$_ must have a filename argument\n" unless @ARGV;
  209. X    $file = shift;
  210. X    $fh = 'FH' . $file;
  211. X    $fh =~ s/[^\w]/_/g;
  212. X    $out .= "&cpio('" . substr($_,0,1) . "', $fh)";
  213. X    $file = '>' . $file;
  214. X    $initfile .= "open($fh, " . "e($file) .
  215. X      qq{) || die "Can't open $fh: \$!\\n";\n};
  216. X    $initcpio++;
  217. X    $flushall = "\n&flushall;\n";
  218. X    }
  219. X    else {
  220. X    die "Unrecognized switch: -$_\n";
  221. X    }
  222. X    if (@ARGV) {
  223. X    if ($ARGV[0] eq '-o') {
  224. X        $out .= " ||\n";
  225. X        shift;
  226. X    }
  227. X    else {
  228. X        $out .= " &&" unless $ARGV[0] eq ')';
  229. X        $out .= "\n";
  230. X        shift if $ARGV[0] eq '-a';
  231. X    }
  232. X    }
  233. X}
  234. X
  235. Xprint <<'END';
  236. X#!/usr/bin/perl
  237. X
  238. XEND
  239. X
  240. Xif ($initls) {
  241. X    print <<'END';
  242. X@rwx = ('---','--x','-w-','-wx','r--','r-x','rw-','rwx');
  243. X@moname = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
  244. X
  245. XEND
  246. X}
  247. X
  248. Xif ($inituser || $initls) {
  249. X    print 'while (($name, $pw, $uid) = getpwent) {', "\n";
  250. X    print '    $uid{$name} = $uid{$uid} = $uid;', "\n" if $inituser;
  251. X    print '    $user{$uid} = $name unless $user{$uid};', "\n" if $initls;
  252. X    print "}\n\n";
  253. X}
  254. X
  255. Xif ($initgroup || $initls) {
  256. X    print 'while (($name, $pw, $gid) = getgrent) {', "\n";
  257. X    print '    $gid{$name} = $gid{$gid} = $gid;', "\n" if $initgroup;
  258. X    print '    $group{$gid} = $name unless $group{$gid};', "\n" if $initls;
  259. X    print "}\n\n";
  260. X}
  261. X
  262. Xprint $initnewer, "\n" if $initnewer;
  263. X
  264. Xprint $initfile, "\n" if $initfile;
  265. X
  266. Xprint <<"END";
  267. X# Traverse desired filesystems
  268. X
  269. X&dodirs($roots);
  270. X$flushall
  271. Xexit;
  272. X
  273. Xsub wanted {
  274. X$out;
  275. X}
  276. X
  277. XEND
  278. X
  279. Xprint <<'END';
  280. Xsub dodirs {
  281. X    chop($cwd = `pwd`);
  282. X    foreach $topdir (@_) {
  283. X    (($topdev,$topino,$topmode,$topnlink) = stat($topdir))
  284. X      || (warn("Can't stat $topdir: $!\n"), next);
  285. X    if (-d _) {
  286. X        if (chdir($topdir)) {
  287. XEND
  288. Xif ($depth) {
  289. X    print <<'END';
  290. X        $topdir = '' if $topdir eq '/';
  291. X        &dodir($topdir,$topnlink);
  292. X        ($dir,$_) = ($topdir,'.');
  293. X        $name = $topdir;
  294. X        &wanted;
  295. XEND
  296. X}
  297. Xelse {
  298. X    print <<'END';
  299. X        ($dir,$_) = ($topdir,'.');
  300. X        $name = $topdir;
  301. X        &wanted;
  302. X        $topdir = '' if $topdir eq '/';
  303. X        &dodir($topdir,$topnlink);
  304. XEND
  305. X}
  306. Xprint <<'END';
  307. X        }
  308. X        else {
  309. X        warn "Can't cd to $topdir: $!\n";
  310. X        }
  311. X    }
  312. X    else {
  313. X        unless (($dir,$_) = $topdir =~ m#^(.*/)(.*)$#) {
  314. X        ($dir,$_) = ('.', $topdir);
  315. X        }
  316. X        chdir $dir && &wanted;
  317. X    }
  318. X    chdir $cwd;
  319. X    }
  320. X}
  321. X
  322. Xsub dodir {
  323. X    local($dir,$nlink) = @_;
  324. X    local($dev,$ino,$mode,$subcount);
  325. X    local($name);
  326. X
  327. X    # Get the list of files in the current directory.
  328. X
  329. X    opendir(DIR,'.') || warn "Can't open $dir: $!\n";
  330. X    local(@filenames) = readdir(DIR);
  331. X    closedir(DIR);
  332. X
  333. X    if ($nlink == 2) {        # This dir has no subdirectories.
  334. X    for (@filenames) {
  335. X        next if $_ eq '.';
  336. X        next if $_ eq '..';
  337. X        $name = "$dir/$_";
  338. X        &wanted;
  339. X    }
  340. X    }
  341. X    else {                    # This dir has subdirectories.
  342. X    $subcount = $nlink - 2;
  343. X    for (@filenames) {
  344. X        next if $_ eq '.';
  345. X        next if $_ eq '..';
  346. X        $nlink = $prune = 0;
  347. X        $name = "$dir/$_";
  348. XEND
  349. Xprint <<'END' unless $depth;
  350. X        &wanted;
  351. XEND
  352. Xprint <<'END';
  353. X        if ($subcount > 0) {    # Seen all the subdirs?
  354. X
  355. X        # Get link count and check for directoriness.
  356. X
  357. X        ($dev,$ino,$mode,$nlink) = lstat($_) unless $nlink;
  358. X        
  359. X        if (-d _) {
  360. X
  361. X            # It really is a directory, so do it recursively.
  362. X
  363. X            if (!$prune && chdir $_) {
  364. X            &dodir($name,$nlink);
  365. X            chdir '..';
  366. X            }
  367. X            --$subcount;
  368. X        }
  369. X        }
  370. XEND
  371. Xprint <<'END' if $depth;
  372. X        &wanted;
  373. XEND
  374. Xprint <<'END';
  375. X    }
  376. X    }
  377. X}
  378. X
  379. XEND
  380. X
  381. Xif ($initexec) {
  382. X    print <<'END';
  383. Xsub exec {
  384. X    local($ok, @cmd) = @_;
  385. X    foreach $word (@cmd) {
  386. X    $word =~ s#{}#$name#g;
  387. X    }
  388. X    if ($ok) {
  389. X    local($old) = select(STDOUT);
  390. X    $| = 1;
  391. X    print "@cmd";
  392. X    select($old);
  393. X    return 0 unless <STDIN> =~ /^y/;
  394. X    }
  395. X    chdir $cwd;        # sigh
  396. X    system @cmd;
  397. X    chdir $dir;
  398. X    return !$?;
  399. X}
  400. X
  401. XEND
  402. X}
  403. X
  404. Xif ($initls) {
  405. X    print <<'END';
  406. Xsub ls {
  407. X    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$sizemm,
  408. X      $atime,$mtime,$ctime,$blksize,$blocks) = lstat(_);
  409. X
  410. X    $pname = $name;
  411. X
  412. X    if (defined $blocks) {
  413. X    $blocks = int(($blocks + 1) / 2);
  414. X    }
  415. X    else {
  416. X    $blocks = int(($size + 1023) / 1024);
  417. X    }
  418. X
  419. X    if    (-f _) { $perms = '-'; }
  420. X    elsif (-d _) { $perms = 'd'; }
  421. X    elsif (-c _) { $perms = 'c'; $sizemm = &sizemm; }
  422. X    elsif (-b _) { $perms = 'b'; $sizemm = &sizemm; }
  423. X    elsif (-p _) { $perms = 'p'; }
  424. X    elsif (-S _) { $perms = 's'; }
  425. X    else         { $perms = 'l'; $pname .= ' -> ' . readlink($_); }
  426. X
  427. X    $tmpmode = $mode;
  428. X    $tmp = $rwx[$tmpmode & 7];
  429. X    $tmpmode >>= 3;
  430. X    $tmp = $rwx[$tmpmode & 7] . $tmp;
  431. X    $tmpmode >>= 3;
  432. X    $tmp = $rwx[$tmpmode & 7] . $tmp;
  433. X    substr($tmp,2,1) =~ tr/-x/Ss/ if -u _;
  434. X    substr($tmp,5,1) =~ tr/-x/Ss/ if -g _;
  435. X    substr($tmp,8,1) =~ tr/-x/Tt/ if -k _;
  436. X    $perms .= $tmp;
  437. X
  438. X    $user = $user{$uid} || $uid;
  439. X    $group = $group{$gid} || $gid;
  440. X
  441. X    ($sec,$min,$hour,$mday,$mon,$year) = localtime($mtime);
  442. X    $moname = $moname[$mon];
  443. X    if (-M _ > 365.25 / 2) {
  444. X    $timeyear = '19' . $year;
  445. X    }
  446. X    else {
  447. X    $timeyear = sprintf("%02d:%02d", $hour, $min);
  448. X    }
  449. X
  450. X    printf "%5lu %4ld %-10s %2d %-8s %-8s %8s %s %2d %5s %s\n",
  451. X        $ino,
  452. X         $blocks,
  453. X              $perms,
  454. X                $nlink,
  455. X                $user,
  456. X                     $group,
  457. X                      $sizemm,
  458. X                          $moname,
  459. X                         $mday,
  460. X                             $timeyear,
  461. X                             $pname;
  462. X    1;
  463. X}
  464. X
  465. Xsub sizemm {
  466. X    sprintf("%3d, %3d", ($rdev >> 8) & 255, $rdev & 255);
  467. X}
  468. X
  469. XEND
  470. X}
  471. X
  472. Xif ($initcpio) {
  473. Xprint <<'END';
  474. Xsub cpio {
  475. X    local($nc,$fh) = @_;
  476. X    local($text);
  477. X
  478. X    if ($name eq 'TRAILER!!!') {
  479. X    $text = '';
  480. X    $size = 0;
  481. X    }
  482. X    else {
  483. X    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  484. X      $atime,$mtime,$ctime,$blksize,$blocks) = lstat(_);
  485. X    if (-f _) {
  486. X        open(IN, $_) || do {
  487. X        warn "Couldn't open $name: $!\n";
  488. X        return;
  489. X        };
  490. X    }
  491. X    else {
  492. X        $text = readlink($_);
  493. X        $size = 0 unless defined $text;
  494. X    }
  495. X    }
  496. X
  497. X    ($nm = $name) =~ s#^\./##;
  498. X    $nc{$fh} = $nc;
  499. X    if ($nc eq 'n') {
  500. X    $cpout{$fh} .=
  501. X      sprintf("%06o%06o%06o%06o%06o%06o%06o%06o%011lo%06o%011lo%s\0",
  502. X        070707,
  503. X        $dev & 0777777,
  504. X        $ino & 0777777,
  505. X        $mode & 0777777,
  506. X        $uid & 0777777,
  507. X        $gid & 0777777,
  508. X        $nlink & 0777777,
  509. X        $rdev & 0177777,
  510. X        $mtime,
  511. X        length($nm)+1,
  512. X        $size,
  513. X        $nm);
  514. X    }
  515. X    else {
  516. X    $cpout{$fh} .= "\0" if length($cpout{$fh}) & 1;
  517. X    $cpout{$fh} .= pack("SSSSSSSSLSLa*",
  518. X        070707, $dev, $ino, $mode, $uid, $gid, $nlink, $rdev, $mtime,
  519. X        length($nm)+1, $size, $nm . (length($nm) & 1 ? "\0" : "\0\0"));
  520. X    }
  521. X    if ($text ne '') {
  522. X    $cpout{$fh} .= $text;
  523. X    }
  524. X    elsif ($size) {
  525. X    &flush($fh) while ($l = length($cpout{$fh})) >= 5120;
  526. X    while (sysread(IN, $cpout{$fh}, 5120 - $l, $l)) {
  527. X        &flush($fh);
  528. X        $l = length($cpout{$fh});
  529. X    }
  530. X    }
  531. X    close IN;
  532. X}
  533. X
  534. Xsub flush {
  535. X    local($fh) = @_;
  536. X
  537. X    while (length($cpout{$fh}) >= 5120) {
  538. X    syswrite($fh,$cpout{$fh},5120);
  539. X    ++$blocks{$fh};
  540. X    substr($cpout{$fh}, 0, 5120) = '';
  541. X    }
  542. X}
  543. X
  544. Xsub flushall {
  545. X    $name = 'TRAILER!!!';
  546. X    foreach $fh (keys %cpout) {
  547. X    &cpio($nc{$fh},$fh);
  548. X    $cpout{$fh} .= "0" x (5120 - length($cpout{$fh}));
  549. X    &flush($fh);
  550. X    print $blocks{$fh} * 10, " blocks\n";
  551. X    }
  552. X}
  553. X
  554. XEND
  555. X}
  556. X
  557. Xif ($inittar) {
  558. Xprint <<'END';
  559. Xsub tar {
  560. X    local($fh) = @_;
  561. X    local($linkname,$header,$l,$slop);
  562. X    local($linkflag) = "\0";
  563. X
  564. X    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  565. X      $atime,$mtime,$ctime,$blksize,$blocks) = lstat(_);
  566. X    $nm = $name;
  567. X    if ($nlink > 1) {
  568. X    if ($linkname = $linkseen{$fh,$dev,$ino}) {
  569. X        $linkflag = 1;
  570. X    }
  571. X    else {
  572. X        $linkseen{$fh,$dev,$ino} = $nm;
  573. X    }
  574. X    }
  575. X    if (-f _) {
  576. X    open(IN, $_) || do {
  577. X        warn "Couldn't open $name: $!\n";
  578. X        return;
  579. X    };
  580. X    $size = 0 if $linkflag ne "\0";
  581. X    }
  582. X    else {
  583. X    $linkname = readlink($_);
  584. X    $linkflag = 2 if defined $linkname;
  585. X    $nm .= '/' if -d _;
  586. X    $size = 0;
  587. X    }
  588. X
  589. X    $header = pack("a100a8a8a8a12a12a8a1a100",
  590. X    $nm,
  591. X    sprintf("%6o ", $mode & 0777),
  592. X    sprintf("%6o ", $uid & 0777777),
  593. X    sprintf("%6o ", $gid & 0777777),
  594. X    sprintf("%11o ", $size),
  595. X    sprintf("%11o ", $mtime),
  596. X    "        ",
  597. X    $linkflag,
  598. X    $linkname);
  599. X    $l = length($header) % 512;
  600. X    substr($header, 148, 6) = sprintf("%6o", unpack("%16C*", $header));
  601. X    substr($header, 154, 1) = "\0";  # blech
  602. X    $tarout{$fh} .= $header;
  603. X    $tarout{$fh} .= "\0" x (512 - $l) if $l;
  604. X    if ($size) {
  605. X    &tflush($fh) while ($l = length($tarout{$fh})) >= 10240;
  606. X    while (sysread(IN, $tarout{$fh}, 10240 - $l, $l)) {
  607. X        $slop = length($tarout{$fh}) % 512;
  608. X        $tarout{$fh} .= "\0" x (512 - $slop) if $slop;
  609. X        &tflush($fh);
  610. X        $l = length($tarout{$fh});
  611. X    }
  612. X    }
  613. X    close IN;
  614. X}
  615. X
  616. Xsub tflush {
  617. X    local($fh) = @_;
  618. X
  619. X    while (length($tarout{$fh}) >= 10240) {
  620. X    syswrite($fh,$tarout{$fh},10240);
  621. X    ++$blocks{$fh};
  622. X    substr($tarout{$fh}, 0, 10240) = '';
  623. X    }
  624. X}
  625. X
  626. Xsub tflushall {
  627. X    local($len);
  628. X
  629. X    foreach $fh (keys %tarout) {
  630. X    $len = 10240 - length($tarout{$fh});
  631. X    $len += 10240 if $len < 1024;
  632. X    $tarout{$fh} .= "\0" x $len;
  633. X    &tflush($fh);
  634. X    }
  635. X}
  636. X
  637. XEND
  638. X}
  639. X
  640. Xexit;
  641. X
  642. X############################################################################
  643. X
  644. Xsub tab {
  645. X    local($tabstring);
  646. X
  647. X    $tabstring = "\t" x ($indent / 2) . ' ' x ($indent % 2 * 4);
  648. X    if ($_ !~ /^(name|print)/) {
  649. X    if (!$statdone) {
  650. X        $tabstring .= <<'ENDOFSTAT' . $tabstring;
  651. X(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
  652. XENDOFSTAT
  653. X        $statdone = 1;
  654. X    }
  655. X    }
  656. X    $tabstring =~ s/^\s+/ / if $out =~ /!$/;
  657. X    $tabstring;
  658. X}
  659. X
  660. Xsub fileglob_to_re {
  661. X    local($tmp) = @_;
  662. X
  663. X    $tmp =~ s/([.^\$()])/\\$1/g;
  664. X    $tmp =~ s/([?*])/.$1/g;
  665. X    "^$tmp$";
  666. X}
  667. X
  668. Xsub n {
  669. X    local($n) = @_;
  670. X
  671. X    $n =~ s/^-0*/< / || $n =~ s/^\+0*/> / || $n =~ s/^0*/== /;
  672. X    $n;
  673. X}
  674. X
  675. Xsub quote {
  676. X    local($string) = @_;
  677. X    $string =~ s/'/\\'/;
  678. X    "'$string'";
  679. X}
  680. !STUFFY!FUNK!
  681. echo ""
  682. echo "End of kit"
  683. : I do not append .signature, but someone might mail this.
  684. exit
  685.  
  686.