Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

602 lines
13 KiB

  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. goto endofperl
  11. @rem ';
  12. #!perl
  13. #line 14
  14. eval 'exec P:\Apps\ActivePerl\temp\bin\MSWin32-x86-object\perl.exe -S $0 ${1+"$@"}'
  15. if $running_under_some_shell;
  16. $startperl = "#!perl";
  17. $perlpath = "P:\Apps\ActivePerl\temp\bin\MSWin32-x86-object\perl.exe";
  18. #
  19. # Modified September 26, 1993 to provide proper handling of years after 1999
  20. # Tom Link <[email protected]>
  21. # University of Pittsburgh
  22. #
  23. # Modified April 7, 1998 with nasty hacks to implement the troublesome -follow
  24. # Billy Constantine <[email protected]> <[email protected]>
  25. # University of Adelaide, Adelaide, South Australia
  26. #
  27. while ($ARGV[0] =~ /^[^-!(]/) {
  28. push(@roots, shift);
  29. }
  30. @roots = ('.') unless @roots;
  31. for (@roots) { $_ = &quote($_); }
  32. $roots = join(',', @roots);
  33. $indent = 1;
  34. $stat = 'lstat';
  35. $decl = '';
  36. while (@ARGV) {
  37. $_ = shift;
  38. s/^-// || /^[()!]/ || die "Unrecognized switch: $_\n";
  39. if ($_ eq '(') {
  40. $out .= &tab . "(\n";
  41. $indent++;
  42. next;
  43. }
  44. elsif ($_ eq ')') {
  45. $indent--;
  46. $out .= &tab . ")";
  47. }
  48. elsif ($_ eq 'follow') {
  49. $stat = 'stat';
  50. $decl = '%already_seen = ();';
  51. $out .= &tab . '(not $already_seen{"$dev,$ino"}) &&';
  52. $out .= "\n" . &tab . '(($already_seen{"$dev,$ino"} = !(-d _)) || 1)';
  53. }
  54. elsif ($_ eq '!') {
  55. $out .= &tab . "!";
  56. next;
  57. }
  58. elsif ($_ eq 'name') {
  59. $out .= &tab;
  60. $pat = &fileglob_to_re(shift);
  61. $out .= '/' . $pat . "/";
  62. }
  63. elsif ($_ eq 'perm') {
  64. $onum = shift;
  65. die "Malformed -perm argument: $onum\n" unless $onum =~ /^-?[0-7]+$/;
  66. if ($onum =~ s/^-//) {
  67. $onum = '0' . sprintf("%o", oct($onum) & 017777); # s/b 07777 ?
  68. $out .= &tab . "((\$mode & $onum) == $onum)";
  69. }
  70. else {
  71. $onum = '0' . $onum unless $onum =~ /^0/;
  72. $out .= &tab . "((\$mode & 0777) == $onum)";
  73. }
  74. }
  75. elsif ($_ eq 'type') {
  76. ($filetest = shift) =~ tr/s/S/;
  77. $out .= &tab . "-$filetest _";
  78. }
  79. elsif ($_ eq 'print') {
  80. $out .= &tab . 'print("$name\n")';
  81. }
  82. elsif ($_ eq 'print0') {
  83. $out .= &tab . 'print("$name\0")';
  84. }
  85. elsif ($_ eq 'fstype') {
  86. $out .= &tab;
  87. $type = shift;
  88. if ($type eq 'nfs')
  89. { $out .= '($dev < 0)'; }
  90. else
  91. { $out .= '($dev >= 0)'; }
  92. }
  93. elsif ($_ eq 'user') {
  94. $uname = shift;
  95. $out .= &tab . "(\$uid == \$uid{'$uname'})";
  96. $inituser++;
  97. }
  98. elsif ($_ eq 'group') {
  99. $gname = shift;
  100. $out .= &tab . "(\$gid == \$gid{'$gname'})";
  101. $initgroup++;
  102. }
  103. elsif ($_ eq 'nouser') {
  104. $out .= &tab . '!defined $uid{$uid}';
  105. $inituser++;
  106. }
  107. elsif ($_ eq 'nogroup') {
  108. $out .= &tab . '!defined $gid{$gid}';
  109. $initgroup++;
  110. }
  111. elsif ($_ eq 'links') {
  112. $out .= &tab . '($nlink ' . &n(shift);
  113. }
  114. elsif ($_ eq 'inum') {
  115. $out .= &tab . '($ino ' . &n(shift);
  116. }
  117. elsif ($_ eq 'size') {
  118. $out .= &tab . '(int(((-s _) + 511) / 512) ' . &n(shift);
  119. }
  120. elsif ($_ eq 'atime') {
  121. $out .= &tab . '(int(-A _) ' . &n(shift);
  122. }
  123. elsif ($_ eq 'mtime') {
  124. $out .= &tab . '(int(-M _) ' . &n(shift);
  125. }
  126. elsif ($_ eq 'ctime') {
  127. $out .= &tab . '(int(-C _) ' . &n(shift);
  128. }
  129. elsif ($_ eq 'exec') {
  130. for (@cmd = (); @ARGV && $ARGV[0] ne ';'; push(@cmd,shift)) { }
  131. shift;
  132. $_ = "@cmd";
  133. if (m#^(/bin/)?rm -f {}$#) {
  134. if (!@ARGV) {
  135. $out .= &tab . 'unlink($_)';
  136. }
  137. else {
  138. $out .= &tab . '(unlink($_) || 1)';
  139. }
  140. }
  141. elsif (m#^(/bin/)?rm {}$#) {
  142. $out .= &tab . '(unlink($_) || warn "$name: $!\n")';
  143. }
  144. else {
  145. for (@cmd) { s/'/\\'/g; }
  146. $" = "','";
  147. $out .= &tab . "&exec(0, '@cmd')";
  148. $" = ' ';
  149. $initexec++;
  150. }
  151. }
  152. elsif ($_ eq 'ok') {
  153. for (@cmd = (); @ARGV && $ARGV[0] ne ';'; push(@cmd,shift)) { }
  154. shift;
  155. for (@cmd) { s/'/\\'/g; }
  156. $" = "','";
  157. $out .= &tab . "&exec(1, '@cmd')";
  158. $" = ' ';
  159. $initexec++;
  160. }
  161. elsif ($_ eq 'prune') {
  162. $out .= &tab . '($prune = 1)';
  163. }
  164. elsif ($_ eq 'xdev') {
  165. $out .= &tab . '!($prune |= ($dev != $topdev))';
  166. }
  167. elsif ($_ eq 'newer') {
  168. $out .= &tab;
  169. $file = shift;
  170. $newername = 'AGE_OF' . $file;
  171. $newername =~ s/[^\w]/_/g;
  172. $newername = "\$$newername";
  173. $out .= "(-M _ < $newername)";
  174. $initnewer .= "$newername = -M " . &quote($file) . ";\n";
  175. }
  176. elsif ($_ eq 'eval') {
  177. $prog = &quote(shift);
  178. $out .= &tab . "eval $prog";
  179. }
  180. elsif ($_ eq 'depth') {
  181. $depth++;
  182. next;
  183. }
  184. elsif ($_ eq 'ls') {
  185. $out .= &tab . "&ls";
  186. $initls++;
  187. }
  188. elsif ($_ eq 'tar') {
  189. $out .= &tab;
  190. die "-tar must have a filename argument\n" unless @ARGV;
  191. $file = shift;
  192. $fh = 'FH' . $file;
  193. $fh =~ s/[^\w]/_/g;
  194. $out .= "&tar($fh)";
  195. $file = '>' . $file;
  196. $initfile .= "open($fh, " . &quote($file) .
  197. qq{) || die "Can't open $fh: \$!\\n";\n};
  198. $inittar++;
  199. $flushall = "\n&tflushall;\n";
  200. }
  201. elsif (/^n?cpio$/) {
  202. $depth++;
  203. $out .= &tab;
  204. die "-$_ must have a filename argument\n" unless @ARGV;
  205. $file = shift;
  206. $fh = 'FH' . $file;
  207. $fh =~ s/[^\w]/_/g;
  208. $out .= "&cpio('" . substr($_,0,1) . "', $fh)";
  209. $file = '>' . $file;
  210. $initfile .= "open($fh, " . &quote($file) .
  211. qq{) || die "Can't open $fh: \$!\\n";\n};
  212. $initcpio++;
  213. $flushall = "\n&flushall;\n";
  214. }
  215. else {
  216. die "Unrecognized switch: -$_\n";
  217. }
  218. if (@ARGV) {
  219. if ($ARGV[0] eq '-o') {
  220. { local($statdone) = 1; $out .= "\n" . &tab . "||\n"; }
  221. $statdone = 0 if $indent == 1 && $delayedstat;
  222. $saw_or++;
  223. shift;
  224. }
  225. else {
  226. $out .= " &&" unless $ARGV[0] eq ')';
  227. $out .= "\n";
  228. shift if $ARGV[0] eq '-a';
  229. }
  230. }
  231. }
  232. print <<"END";
  233. $startperl
  234. eval 'exec $perlpath -S \$0 \${1+"\$@"}'
  235. if \$running_under_some_shell;
  236. END
  237. if ($initls) {
  238. print <<'END';
  239. @rwx = ('---','--x','-w-','-wx','r--','r-x','rw-','rwx');
  240. @moname = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
  241. END
  242. }
  243. if ($inituser || $initls) {
  244. print 'while (($name, $pw, $uid) = getpwent) {', "\n";
  245. print ' $uid{$name} = $uid{$uid} = $uid;', "\n" if $inituser;
  246. print ' $user{$uid} = $name unless $user{$uid};', "\n" if $initls;
  247. print "}\n\n";
  248. }
  249. if ($initgroup || $initls) {
  250. print 'while (($name, $pw, $gid) = getgrent) {', "\n";
  251. print ' $gid{$name} = $gid{$gid} = $gid;', "\n" if $initgroup;
  252. print ' $group{$gid} = $name unless $group{$gid};', "\n" if $initls;
  253. print "}\n\n";
  254. }
  255. print $initnewer, "\n" if $initnewer;
  256. print $initfile, "\n" if $initfile;
  257. $find = $depth ? "finddepth" : "find";
  258. print <<"END";
  259. require "$find.pl";
  260. # Traverse desired filesystems
  261. $decl
  262. &$find($roots);
  263. $flushall
  264. exit;
  265. sub wanted {
  266. $out;
  267. }
  268. END
  269. if ($initexec) {
  270. print <<'END';
  271. sub exec {
  272. local($ok, @cmd) = @_;
  273. foreach $word (@cmd) {
  274. $word =~ s#{}#$name#g;
  275. }
  276. if ($ok) {
  277. local($old) = select(STDOUT);
  278. $| = 1;
  279. print "@cmd";
  280. select($old);
  281. return 0 unless <STDIN> =~ /^y/;
  282. }
  283. chdir $cwd; # sigh
  284. system @cmd;
  285. chdir $dir;
  286. return !$?;
  287. }
  288. END
  289. }
  290. if ($initls) {
  291. print <<"INTERP", <<'END';
  292. sub ls {
  293. (\$dev,\$ino,\$mode,\$nlink,\$uid,\$gid,\$rdev,\$sizemm,
  294. \$atime,\$mtime,\$ctime,\$blksize,\$blocks) = $stat\(_\);
  295. INTERP
  296. $pname = $name;
  297. if (defined $blocks) {
  298. $blocks = int(($blocks + 1) / 2);
  299. }
  300. else {
  301. $blocks = int(($size + 1023) / 1024);
  302. }
  303. if (-f _) { $perms = '-'; }
  304. elsif (-d _) { $perms = 'd'; }
  305. elsif (-c _) { $perms = 'c'; $sizemm = &sizemm; }
  306. elsif (-b _) { $perms = 'b'; $sizemm = &sizemm; }
  307. elsif (-p _) { $perms = 'p'; }
  308. elsif (-S _) { $perms = 's'; }
  309. else { $perms = 'l'; $pname .= ' -> ' . readlink($_); }
  310. $tmpmode = $mode;
  311. $tmp = $rwx[$tmpmode & 7];
  312. $tmpmode >>= 3;
  313. $tmp = $rwx[$tmpmode & 7] . $tmp;
  314. $tmpmode >>= 3;
  315. $tmp = $rwx[$tmpmode & 7] . $tmp;
  316. substr($tmp,2,1) =~ tr/-x/Ss/ if -u _;
  317. substr($tmp,5,1) =~ tr/-x/Ss/ if -g _;
  318. substr($tmp,8,1) =~ tr/-x/Tt/ if -k _;
  319. $perms .= $tmp;
  320. $user = $user{$uid} || $uid;
  321. $group = $group{$gid} || $gid;
  322. ($sec,$min,$hour,$mday,$mon,$year) = localtime($mtime);
  323. $moname = $moname[$mon];
  324. if (-M _ > 365.25 / 2) {
  325. $timeyear = $year + 1900;
  326. }
  327. else {
  328. $timeyear = sprintf("%02d:%02d", $hour, $min);
  329. }
  330. printf "%5lu %4ld %-10s %2d %-8s %-8s %8s %s %2d %5s %s\n",
  331. $ino,
  332. $blocks,
  333. $perms,
  334. $nlink,
  335. $user,
  336. $group,
  337. $sizemm,
  338. $moname,
  339. $mday,
  340. $timeyear,
  341. $pname;
  342. 1;
  343. }
  344. sub sizemm {
  345. sprintf("%3d, %3d", ($rdev >> 8) & 255, $rdev & 255);
  346. }
  347. END
  348. }
  349. if ($initcpio) {
  350. print <<'START', <<"INTERP", <<'END';
  351. sub cpio {
  352. local($nc,$fh) = @_;
  353. local($text);
  354. if ($name eq 'TRAILER!!!') {
  355. $text = '';
  356. $size = 0;
  357. }
  358. else {
  359. START
  360. (\$dev,\$ino,\$mode,\$nlink,\$uid,\$gid,\$rdev,\$size,
  361. \$atime,\$mtime,\$ctime,\$blksize,\$blocks) = $stat\(_\);
  362. INTERP
  363. if (-f _) {
  364. open(IN, "./$_\0") || do {
  365. warn "Couldn't open $name: $!\n";
  366. return;
  367. };
  368. }
  369. else {
  370. $text = readlink($_);
  371. $size = 0 unless defined $text;
  372. }
  373. }
  374. ($nm = $name) =~ s#^\./##;
  375. $nc{$fh} = $nc;
  376. if ($nc eq 'n') {
  377. $cpout{$fh} .=
  378. sprintf("%06o%06o%06o%06o%06o%06o%06o%06o%011lo%06o%011lo%s\0",
  379. 070707,
  380. $dev & 0777777,
  381. $ino & 0777777,
  382. $mode & 0777777,
  383. $uid & 0777777,
  384. $gid & 0777777,
  385. $nlink & 0777777,
  386. $rdev & 0177777,
  387. $mtime,
  388. length($nm)+1,
  389. $size,
  390. $nm);
  391. }
  392. else {
  393. $cpout{$fh} .= "\0" if length($cpout{$fh}) & 1;
  394. $cpout{$fh} .= pack("SSSSSSSSLSLa*",
  395. 070707, $dev, $ino, $mode, $uid, $gid, $nlink, $rdev, $mtime,
  396. length($nm)+1, $size, $nm . (length($nm) & 1 ? "\0" : "\0\0"));
  397. }
  398. if ($text ne '') {
  399. $cpout{$fh} .= $text;
  400. }
  401. elsif ($size) {
  402. &flush($fh) while ($l = length($cpout{$fh})) >= 5120;
  403. while (sysread(IN, $cpout{$fh}, 5120 - $l, $l)) {
  404. &flush($fh);
  405. $l = length($cpout{$fh});
  406. }
  407. }
  408. close IN;
  409. }
  410. sub flush {
  411. local($fh) = @_;
  412. while (length($cpout{$fh}) >= 5120) {
  413. syswrite($fh,$cpout{$fh},5120);
  414. ++$blocks{$fh};
  415. substr($cpout{$fh}, 0, 5120) = '';
  416. }
  417. }
  418. sub flushall {
  419. $name = 'TRAILER!!!';
  420. foreach $fh (keys %cpout) {
  421. &cpio($nc{$fh},$fh);
  422. $cpout{$fh} .= "0" x (5120 - length($cpout{$fh}));
  423. &flush($fh);
  424. print $blocks{$fh} * 10, " blocks\n";
  425. }
  426. }
  427. END
  428. }
  429. if ($inittar) {
  430. print <<'START', <<"INTERP", <<'END';
  431. sub tar {
  432. local($fh) = @_;
  433. local($linkname,$header,$l,$slop);
  434. local($linkflag) = "\0";
  435. START
  436. (\$dev,\$ino,\$mode,\$nlink,\$uid,\$gid,\$rdev,\$size,
  437. \$atime,\$mtime,\$ctime,\$blksize,\$blocks) = $stat\(_\);
  438. INTERP
  439. $nm = $name;
  440. if ($nlink > 1) {
  441. if ($linkname = $linkseen{$fh,$dev,$ino}) {
  442. $linkflag = 1;
  443. }
  444. else {
  445. $linkseen{$fh,$dev,$ino} = $nm;
  446. }
  447. }
  448. if (-f _) {
  449. open(IN, "./$_\0") || do {
  450. warn "Couldn't open $name: $!\n";
  451. return;
  452. };
  453. $size = 0 if $linkflag ne "\0";
  454. }
  455. else {
  456. $linkname = readlink($_);
  457. $linkflag = 2 if defined $linkname;
  458. $nm .= '/' if -d _;
  459. $size = 0;
  460. }
  461. $header = pack("a100a8a8a8a12a12a8a1a100",
  462. $nm,
  463. sprintf("%6o ", $mode & 0777),
  464. sprintf("%6o ", $uid & 0777777),
  465. sprintf("%6o ", $gid & 0777777),
  466. sprintf("%11o ", $size),
  467. sprintf("%11o ", $mtime),
  468. " ",
  469. $linkflag,
  470. $linkname);
  471. $l = length($header) % 512;
  472. substr($header, 148, 6) = sprintf("%6o", unpack("%16C*", $header));
  473. substr($header, 154, 1) = "\0"; # blech
  474. $tarout{$fh} .= $header;
  475. $tarout{$fh} .= "\0" x (512 - $l) if $l;
  476. if ($size) {
  477. &tflush($fh) while ($l = length($tarout{$fh})) >= 10240;
  478. while (sysread(IN, $tarout{$fh}, 10240 - $l, $l)) {
  479. $slop = length($tarout{$fh}) % 512;
  480. $tarout{$fh} .= "\0" x (512 - $slop) if $slop;
  481. &tflush($fh);
  482. $l = length($tarout{$fh});
  483. }
  484. }
  485. close IN;
  486. }
  487. sub tflush {
  488. local($fh) = @_;
  489. while (length($tarout{$fh}) >= 10240) {
  490. syswrite($fh,$tarout{$fh},10240);
  491. ++$blocks{$fh};
  492. substr($tarout{$fh}, 0, 10240) = '';
  493. }
  494. }
  495. sub tflushall {
  496. local($len);
  497. foreach $fh (keys %tarout) {
  498. $len = 10240 - length($tarout{$fh});
  499. $len += 10240 if $len < 1024;
  500. $tarout{$fh} .= "\0" x $len;
  501. &tflush($fh);
  502. }
  503. }
  504. END
  505. }
  506. exit;
  507. ############################################################################
  508. sub tab {
  509. local($tabstring);
  510. $tabstring = "\t" x ($indent / 2) . ' ' x ($indent % 2 * 4);
  511. if (!$statdone) {
  512. if ($_ =~ /^(name|print|prune|exec|ok|\(|\))/) {
  513. $delayedstat++;
  514. }
  515. else {
  516. if ($saw_or) {
  517. $tabstring .= <<"ENDOFSTAT" . $tabstring;
  518. (\$nlink || ((\$dev,\$ino,\$mode,\$nlink,\$uid,\$gid) = $stat\(\$_\))) &&
  519. ENDOFSTAT
  520. }
  521. else {
  522. $tabstring .= <<"ENDOFSTAT" . $tabstring;
  523. ((\$dev,\$ino,\$mode,\$nlink,\$uid,\$gid) = $stat\(\$_\)) &&
  524. ENDOFSTAT
  525. }
  526. $statdone = 1;
  527. }
  528. }
  529. $tabstring =~ s/^\s+/ / if $out =~ /!$/;
  530. $tabstring;
  531. }
  532. sub fileglob_to_re {
  533. local($tmp) = @_;
  534. $tmp =~ s#([./^\$()])#\\$1#g;
  535. $tmp =~ s/([?*])/.$1/g;
  536. "^$tmp\$";
  537. }
  538. sub n {
  539. local($n) = @_;
  540. $n =~ s/^-/< / || $n =~ s/^\+/> / || $n =~ s/^/== /;
  541. $n =~ s/ 0*(\d)/ $1/;
  542. $n . ')';
  543. }
  544. sub quote {
  545. local($string) = @_;
  546. $string =~ s/'/\\'/;
  547. "'$string'";
  548. }
  549. __END__
  550. :endofperl