PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/IronPython_Main/Runtime/Tests/LinqDlrTests/testenv/perl/bin/find2perl.bat

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