home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume20 / perl3.0 / part24 < prev    next >
Encoding:
Internet Message Format  |  1989-11-01  |  44.6 KB

  1. Subject:  v20i107:  Perl, a language with features of C/sed/awk/shell/etc, Part24/24
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Larry Wall <lwall@jpl-devvax.jpl.nasa.gov>
  7. Posting-number: Volume 20, Issue 107
  8. Archive-name: perl3.0/part24
  9.  
  10. #! /bin/sh
  11.  
  12. # Make a new directory for the perl sources, cd to it, and run kits 1
  13. # thru 24 through sh.  When all 24 kits have been run, read README.
  14.  
  15. echo "This is perl 3.0 kit 24 (of 24).  If kit 24 is complete, the line"
  16. echo '"'"End of kit 24 (of 24)"'" will echo at the end.'
  17. echo ""
  18. export PATH || (echo "You didn't use sh, you clunch." ; kill $$)
  19. mkdir eg eg/g eg/scan eg/van lib t x2p 2>/dev/null
  20. echo Extracting t/op.regexp
  21. sed >t/op.regexp <<'!STUFFY!FUNK!' -e 's/X//'
  22. X#!./perl
  23. X
  24. X# $Header: op.regexp,v 3.0 89/10/18 15:31:02 lwall Locked $
  25. X
  26. Xopen(TESTS,'re_tests') || open(TESTS,'t/re_tests') || die "Can't open re_tests";
  27. Xwhile (<TESTS>) { }
  28. X$numtests = $.;
  29. Xclose(TESTS);
  30. X
  31. Xprint "1..$numtests\n";
  32. Xopen(TESTS,'re_tests') || open(TESTS,'t/re_tests') || die "Can't open re_tests";
  33. Xwhile (<TESTS>) {
  34. X    ($pat, $subject, $result, $repl, $expect) = split(/[\t\n]/,$_);
  35. X    $input = join(':',$pat,$subject,$result,$repl,$expect);
  36. X    eval "\$match = (\$subject =~ \$pat); \$got = \"$repl\";";
  37. X    if ($result eq 'c') {
  38. X    if ($@ ne '') {print "ok $.\n";} else {print "not ok $.\n";}
  39. X    }
  40. X    elsif ($result eq 'n') {
  41. X    if (!$match) {print "ok $.\n";} else {print "not ok $. $input => $got\n";}
  42. X    }
  43. X    else {
  44. X    if ($match && $got eq $expect) {
  45. X        print "ok $.\n";
  46. X    }
  47. X    else {
  48. X        print "not ok $. $input => $got\n";
  49. X    }
  50. X    }
  51. X}
  52. Xclose(TESTS);
  53. !STUFFY!FUNK!
  54. echo Extracting t/op.vec
  55. sed >t/op.vec <<'!STUFFY!FUNK!' -e 's/X//'
  56. X#!./perl
  57. X
  58. X# $Header: op.vec,v 3.0 89/10/18 15:32:11 lwall Locked $
  59. X
  60. Xprint "1..13\n";
  61. X
  62. Xprint vec($foo,0,1) == 0 ? "ok 1\n" : "not ok 1\n";
  63. Xprint length($foo) == 0 ? "ok 2\n" : "not ok 2\n";
  64. Xvec($foo,0,1) = 1;
  65. Xprint length($foo) == 1 ? "ok 3\n" : "not ok 3\n";
  66. Xprint ord($foo) == 1 ? "ok 4\n" : "not ok 4\n";
  67. Xprint vec($foo,0,1) == 1 ? "ok 5\n" : "not ok 5\n";
  68. X
  69. Xprint vec($foo,20,1) == 0 ? "ok 6\n" : "not ok 6\n";
  70. Xvec($foo,20,1) = 1;
  71. Xprint vec($foo,20,1) == 1 ? "ok 7\n" : "not ok 7\n";
  72. Xprint length($foo) == 3 ? "ok 8\n" : "not ok 8\n";
  73. Xprint vec($foo,1,8) == 0 ? "ok 9\n" : "not ok 9\n";
  74. Xvec($foo,1,8) = 0xf1;
  75. Xprint vec($foo,1,8) == 0xf1 ? "ok 10\n" : "not ok 10\n";
  76. Xprint ((ord(substr($foo,1,1)) & 255) == 0xf1 ? "ok 11\n" : "not ok 11\n");
  77. Xprint vec($foo,2,4) == 1 ? "ok 12\n" : "not ok 12\n";
  78. Xprint vec($foo,3,4) == 15 ? "ok 13\n" : "not ok 13\n";
  79. X
  80. !STUFFY!FUNK!
  81. echo Extracting x2p/handy.h
  82. sed >x2p/handy.h <<'!STUFFY!FUNK!' -e 's/X//'
  83. X/* $Header: handy.h,v 3.0 89/10/18 15:34:44 lwall Locked $
  84. X *
  85. X *    Copyright (c) 1989, Larry Wall
  86. X *
  87. X *    You may distribute under the terms of the GNU General Public License
  88. X *    as specified in the README file that comes with the perl 3.0 kit.
  89. X *
  90. X * $Log:    handy.h,v $
  91. X * Revision 3.0  89/10/18  15:34:44  lwall
  92. X * 3.0 baseline
  93. X * 
  94. X */
  95. X
  96. X#define Null(type) ((type)0)
  97. X#define Nullch Null(char*)
  98. X#define Nullfp Null(FILE*)
  99. X
  100. X#define bool char
  101. X#define TRUE (1)
  102. X#define FALSE (0)
  103. X
  104. X#define Ctl(ch) (ch & 037)
  105. X
  106. X#define strNE(s1,s2) (strcmp(s1,s2))
  107. X#define strEQ(s1,s2) (!strcmp(s1,s2))
  108. X#define strLT(s1,s2) (strcmp(s1,s2) < 0)
  109. X#define strLE(s1,s2) (strcmp(s1,s2) <= 0)
  110. X#define strGT(s1,s2) (strcmp(s1,s2) > 0)
  111. X#define strGE(s1,s2) (strcmp(s1,s2) >= 0)
  112. X#define strnNE(s1,s2,l) (strncmp(s1,s2,l))
  113. X#define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
  114. !STUFFY!FUNK!
  115. echo Extracting x2p/util.h
  116. sed >x2p/util.h <<'!STUFFY!FUNK!' -e 's/X//'
  117. X/* $Header: util.h,v 3.0 89/10/18 15:35:41 lwall Locked $
  118. X *
  119. X *    Copyright (c) 1989, Larry Wall
  120. X *
  121. X *    You may distribute under the terms of the GNU General Public License
  122. X *    as specified in the README file that comes with the perl 3.0 kit.
  123. X *
  124. X * $Log:    util.h,v $
  125. X * Revision 3.0  89/10/18  15:35:41  lwall
  126. X * 3.0 baseline
  127. X * 
  128. X */
  129. X
  130. X/* is the string for makedir a directory name or a filename? */
  131. X
  132. X#define MD_DIR 0
  133. X#define MD_FILE 1
  134. X
  135. Xvoid    util_init();
  136. Xint    doshell();
  137. Xchar    *safemalloc();
  138. Xchar    *saferealloc();
  139. Xchar    *safecpy();
  140. Xchar    *safecat();
  141. Xchar    *cpytill();
  142. Xchar    *cpy2();
  143. Xchar    *instr();
  144. X#ifdef SETUIDGID
  145. X    int        eaccess();
  146. X#endif
  147. Xchar    *getwd();
  148. Xvoid    cat();
  149. Xvoid    prexit();
  150. Xchar    *get_a_line();
  151. Xchar    *savestr();
  152. Xint    makedir();
  153. Xvoid    setenv();
  154. Xint    envix();
  155. Xvoid    notincl();
  156. Xchar    *getval();
  157. Xvoid    growstr();
  158. Xvoid    setdef();
  159. !STUFFY!FUNK!
  160. echo Extracting lib/getopts.pl
  161. sed >lib/getopts.pl <<'!STUFFY!FUNK!' -e 's/X//'
  162. X;# getopts.pl - a better getopt.pl
  163. X
  164. X;# Usage:
  165. X;#      do Getopts('a:bc');  # -a takes arg. -b & -c not. Sets opt_* as a
  166. X;#                           #  side effect.
  167. X
  168. Xsub Getopts {
  169. X    local($argumentative) = @_;
  170. X    local(@args,$_,$first,$rest);
  171. X
  172. X    @args = split( / */, $argumentative );
  173. X    while(($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
  174. X    ($first,$rest) = ($1,$2);
  175. X    $pos = index($argumentative,$first);
  176. X    if($pos >= $[) {
  177. X        if($args[$pos+1] eq ':') {
  178. X        shift;
  179. X        if($rest eq '') {
  180. X            $rest = shift;
  181. X        }
  182. X        eval "\$opt_$first = \$rest;";
  183. X        }
  184. X        else {
  185. X        eval "\$opt_$first = 1";
  186. X        if($rest eq '') {
  187. X            shift;
  188. X        }
  189. X        else {
  190. X            $ARGV[0] = "-$rest";
  191. X        }
  192. X        }
  193. X    }
  194. X    else {
  195. X        print stderr "Unknown option: $first\n";
  196. X        if($rest ne '') {
  197. X        $ARGV[0] = "-$rest";
  198. X        }
  199. X        else {
  200. X        shift;
  201. X        }
  202. X    }
  203. X    }
  204. X}
  205. X
  206. X1;
  207. !STUFFY!FUNK!
  208. echo Extracting t/base.term
  209. sed >t/base.term <<'!STUFFY!FUNK!' -e 's/X//'
  210. X#!./perl
  211. X
  212. X# $Header: base.term,v 3.0 89/10/18 15:24:34 lwall Locked $
  213. X
  214. Xprint "1..6\n";
  215. X
  216. X# check "" interpretation
  217. X
  218. X$x = "\n";
  219. Xif ($x lt ' ') {print "ok 1\n";} else {print "not ok 1\n";}
  220. X
  221. X# check `` processing
  222. X
  223. X$x = `echo hi there`;
  224. Xif ($x eq "hi there\n") {print "ok 2\n";} else {print "not ok 2\n";}
  225. X
  226. X# check $#array
  227. X
  228. X$x[0] = 'foo';
  229. X$x[1] = 'foo';
  230. X$tmp = $#x;
  231. Xprint "#3\t:$tmp: == :1:\n";
  232. Xif ($#x == '1') {print "ok 3\n";} else {print "not ok 3\n";}
  233. X
  234. X# check numeric literal
  235. X
  236. X$x = 1;
  237. Xif ($x == '1') {print "ok 4\n";} else {print "not ok 4\n";}
  238. X
  239. X# check <> pseudoliteral
  240. X
  241. Xopen(try, "/dev/null") || (die "Can't open /dev/null.");
  242. Xif (<try> eq '') {print "ok 5\n";} else {print "not ok 5\n";}
  243. X
  244. Xopen(try, "../Makefile") || (die "Can't open ../Makefile.");
  245. Xif (<try> ne '') {print "ok 6\n";} else {print "not ok 6\n";}
  246. !STUFFY!FUNK!
  247. echo Extracting t/comp.multiline
  248. sed >t/comp.multiline <<'!STUFFY!FUNK!' -e 's/X//'
  249. X#!./perl
  250. X
  251. X# $Header: comp.multiline,v 3.0 89/10/18 15:25:39 lwall Locked $
  252. X
  253. Xprint "1..5\n";
  254. X
  255. Xopen(try,'>Comp.try') || (die "Can't open temp file.");
  256. X
  257. X$x = 'now is the time
  258. Xfor all good men
  259. Xto come to.
  260. X';
  261. X
  262. X$y = 'now is the time' . "\n" .
  263. X'for all good men' . "\n" .
  264. X'to come to.' . "\n";
  265. X
  266. Xif ($x eq $y) {print "ok 1\n";} else {print "not ok 1\n";}
  267. X
  268. Xprint try $x;
  269. Xclose try;
  270. X
  271. Xopen(try,'Comp.try') || (die "Can't reopen temp file.");
  272. X$count = 0;
  273. X$z = '';
  274. Xwhile (<try>) {
  275. X    $z .= $_;
  276. X    $count = $count + 1;
  277. X}
  278. X
  279. Xif ($z eq $y) {print "ok 2\n";} else {print "not ok 2\n";}
  280. X
  281. Xif ($count == 3) {print "ok 3\n";} else {print "not ok 3\n";}
  282. X
  283. X$_ = `cat Comp.try`;
  284. X
  285. Xif (/.*\n.*\n.*\n$/) {print "ok 4\n";} else {print "not ok 4\n";}
  286. X`/bin/rm -f Comp.try`;
  287. X
  288. Xif ($_ eq $y) {print "ok 5\n";} else {print "not ok 5\n";}
  289. !STUFFY!FUNK!
  290. echo Extracting t/op.local
  291. sed >t/op.local <<'!STUFFY!FUNK!' -e 's/X//'
  292. X#!./perl
  293. X
  294. X# $Header: op.local,v 3.0 89/10/18 15:29:49 lwall Locked $
  295. X
  296. Xprint "1..20\n";
  297. X
  298. Xsub foo {
  299. X    local($a, $b) = @_;
  300. X    local($c, $d);
  301. X    $c = "ok 3\n";
  302. X    $d = "ok 4\n";
  303. X    { local($a,$c) = ("ok 9\n", "ok 10\n"); ($x, $y) = ($a, $c); }
  304. X    print $a, $b;
  305. X    $c . $d;
  306. X}
  307. X
  308. X$a = "ok 5\n";
  309. X$b = "ok 6\n";
  310. X$c = "ok 7\n";
  311. X$d = "ok 8\n";
  312. X
  313. Xprint do foo("ok 1\n","ok 2\n");
  314. X
  315. Xprint $a,$b,$c,$d,$x,$y;
  316. X
  317. X# same thing, only with arrays and associative arrays
  318. X
  319. Xsub foo2 {
  320. X    local($a, @b) = @_;
  321. X    local(@c, %d);
  322. X    @c = "ok 13\n";
  323. X    $d{''} = "ok 14\n";
  324. X    { local($a,@c) = ("ok 19\n", "ok 20\n"); ($x, $y) = ($a, @c); }
  325. X    print $a, @b;
  326. X    $c[0] . $d{''};
  327. X}
  328. X
  329. X$a = "ok 15\n";
  330. X@b = "ok 16\n";
  331. X@c = "ok 17\n";
  332. X$d{''} = "ok 18\n";
  333. X
  334. Xprint do foo2("ok 11\n","ok 12\n");
  335. X
  336. Xprint $a,@b,@c,%d,$x,$y;
  337. !STUFFY!FUNK!
  338. echo Extracting eg/van/empty
  339. sed >eg/van/empty <<'!STUFFY!FUNK!' -e 's/X//'
  340. X#!/usr/bin/perl
  341. X
  342. X# $Header: empty,v 3.0 89/10/18 15:16:28 lwall Locked $
  343. X
  344. X# This script empties a trashcan.
  345. X
  346. X$recursive = shift if $ARGV[0] eq '-r';
  347. X
  348. X@ARGV = '.' if $#ARGV < 0;
  349. X
  350. Xchop($pwd = `pwd`);
  351. X
  352. Xdir: foreach $dir (@ARGV) {
  353. X    unless (chdir $dir) {
  354. X    print stderr "Can't find directory $dir: $!\n";
  355. X    next dir;
  356. X    }
  357. X    if ($recursive) {
  358. X    do cmd('find . -name .deleted -exec /bin/rm -rf {} ;');
  359. X    }
  360. X    else {
  361. X    if (-d '.deleted') {
  362. X        do cmd('rm -rf .deleted');
  363. X    }
  364. X    else {
  365. X        if ($dir eq '.' && $pwd =~ m|/\.deleted$|) {
  366. X        chdir '..';
  367. X        do cmd('rm -rf .deleted');
  368. X        }
  369. X        else {
  370. X        print stderr "No trashcan found in directory $dir\n";
  371. X        }
  372. X    }
  373. X    }
  374. X}
  375. Xcontinue {
  376. X    chdir $pwd;
  377. X}
  378. X
  379. X# force direct execution with no shell
  380. X
  381. Xsub cmd {
  382. X    system split(' ',join(' ',@_));
  383. X}
  384. X
  385. !STUFFY!FUNK!
  386. echo Extracting t/comp.cpp
  387. sed >t/comp.cpp <<'!STUFFY!FUNK!' -e 's/X//'
  388. X#!./perl -P
  389. X
  390. X# $Header: comp.cpp,v 3.0 89/10/18 15:25:19 lwall Locked $
  391. X
  392. Xprint "1..3\n";
  393. X
  394. X#this is a comment
  395. X#define MESS "ok 1\n"
  396. Xprint MESS;
  397. X
  398. X#If you capitalize, it's a comment.
  399. X#ifdef MESS
  400. X    print "ok 2\n";
  401. X#else
  402. X    print "not ok 2\n";
  403. X#endif
  404. X
  405. Xopen(try,">Comp.cpp.tmp") || die "Can't open temp perl file.";
  406. Xprint try '$ok = "not ok 3\n";'; print try "\n";
  407. Xprint try "#include <Comp.cpp.inc>\n";
  408. Xprint try "#ifdef OK\n";
  409. Xprint try '$ok = OK;'; print try "\n";
  410. Xprint try "#endif\n";
  411. Xprint try 'print $ok;'; print try "\n";
  412. Xclose try;
  413. X
  414. Xopen(try,">Comp.cpp.inc") || (die "Can't open temp include file.");
  415. Xprint try '#define OK "ok 3\n"'; print try "\n";
  416. Xclose try;
  417. X
  418. X$pwd=`pwd`;
  419. X$pwd =~ s/\n//;
  420. X$x = `./perl -P -I$pwd Comp.cpp.tmp`;
  421. Xprint $x;
  422. X`/bin/rm -f Comp.cpp.tmp Comp.cpp.inc`;
  423. !STUFFY!FUNK!
  424. echo Extracting form.h
  425. sed >form.h <<'!STUFFY!FUNK!' -e 's/X//'
  426. X/* $Header: form.h,v 3.0 89/10/18 15:17:39 lwall Locked $
  427. X *
  428. X *    Copyright (c) 1989, Larry Wall
  429. X *
  430. X *    You may distribute under the terms of the GNU General Public License
  431. X *    as specified in the README file that comes with the perl 3.0 kit.
  432. X *
  433. X * $Log:    form.h,v $
  434. X * Revision 3.0  89/10/18  15:17:39  lwall
  435. X * 3.0 baseline
  436. X * 
  437. X */
  438. X
  439. X#define F_NULL 0
  440. X#define F_LEFT 1
  441. X#define F_RIGHT 2
  442. X#define F_CENTER 3
  443. X#define F_LINES 4
  444. X
  445. Xstruct formcmd {
  446. X    struct formcmd *f_next;
  447. X    ARG *f_expr;
  448. X    STR *f_unparsed;
  449. X    line_t f_line;
  450. X    char *f_pre;
  451. X    short f_presize;
  452. X    short f_size;
  453. X    char f_type;
  454. X    char f_flags;
  455. X};
  456. X
  457. X#define FC_CHOP 1
  458. X#define FC_NOBLANK 2
  459. X#define FC_MORE 4
  460. X#define FC_REPEAT 8
  461. X
  462. X#define Nullfcmd Null(FCMD*)
  463. X
  464. XEXT char *chopset INIT(" \n-");
  465. !STUFFY!FUNK!
  466. echo Extracting eg/scan/scan_ps
  467. sed >eg/scan/scan_ps <<'!STUFFY!FUNK!' -e 's/X//'
  468. X#!/usr/bin/perl -P
  469. X
  470. X# $Header: scan_ps,v 3.0 89/10/18 15:15:47 lwall Locked $
  471. X
  472. X# This looks for looping processes.
  473. X
  474. X#if defined(mc300) || defined(mc500) || defined(mc700)
  475. Xopen(Ps, '/bin/ps -el|') || die "scan_ps: can't run ps";
  476. X
  477. Xwhile (<Ps>) {
  478. X    next if /rwhod/;
  479. X    print if index(' T', substr($_,62,1)) < 0;
  480. X}
  481. X#else
  482. Xopen(Ps, '/bin/ps auxww|') || die "scan_ps: can't run ps";
  483. X
  484. Xwhile (<Ps>) {
  485. X    next if /dataserver/;
  486. X    next if /nfsd/;
  487. X    next if /update/;
  488. X    next if /ypserv/;
  489. X    next if /rwhod/;
  490. X    next if /routed/;
  491. X    next if /pagedaemon/;
  492. X#ifdef vax
  493. X    ($user,$pid,$cpu,$mem,$sz,$rss,$tt,$stat,$start,$time) = split;
  494. X#else
  495. X    ($user,$pid,$cpu,$mem,$sz,$rss,$tt,$stat,$time) = split;
  496. X#endif
  497. X    print if length($time) > 4;
  498. X}
  499. X#endif
  500. !STUFFY!FUNK!
  501. echo Extracting t/op.index
  502. sed >t/op.index <<'!STUFFY!FUNK!' -e 's/X//'
  503. X#!./perl
  504. X
  505. X# $Header: op.index,v 3.0 89/10/18 15:29:29 lwall Locked $
  506. X
  507. Xprint "1..6\n";
  508. X
  509. X
  510. X$foo = 'Now is the time for all good men to come to the aid of their country.';
  511. X
  512. X$first = substr($foo,0,index($foo,'the'));
  513. Xprint ($first eq "Now is " ? "ok 1\n" : "not ok 1\n");
  514. X
  515. X$last = substr($foo,rindex($foo,'the'),100);
  516. Xprint ($last eq "their country." ? "ok 2\n" : "not ok 2\n");
  517. X
  518. X$last = substr($foo,index($foo,'Now'),2);
  519. Xprint ($last eq "No" ? "ok 3\n" : "not ok 3\n");
  520. X
  521. X$last = substr($foo,rindex($foo,'Now'),2);
  522. Xprint ($last eq "No" ? "ok 4\n" : "not ok 4\n");
  523. X
  524. X$last = substr($foo,index($foo,'.'),100);
  525. Xprint ($last eq "." ? "ok 5\n" : "not ok 5\n");
  526. X
  527. X$last = substr($foo,rindex($foo,'.'),100);
  528. Xprint ($last eq "." ? "ok 6\n" : "not ok 6\n");
  529. !STUFFY!FUNK!
  530. echo Extracting t/op.delete
  531. sed >t/op.delete <<'!STUFFY!FUNK!' -e 's/X//'
  532. X#!./perl
  533. X
  534. X# $Header: op.delete,v 3.0 89/10/18 15:28:36 lwall Locked $
  535. X
  536. Xprint "1..6\n";
  537. X
  538. X$foo{1} = 'a';
  539. X$foo{2} = 'b';
  540. X$foo{3} = 'c';
  541. X
  542. X$foo = delete $foo{2};
  543. X
  544. Xif ($foo eq 'b') {print "ok 1\n";} else {print "not ok 1 $foo\n";}
  545. Xif ($foo{2} eq '') {print "ok 2\n";} else {print "not ok 2 $foo{2}\n";}
  546. Xif ($foo{1} eq 'a') {print "ok 3\n";} else {print "not ok 3\n";}
  547. Xif ($foo{3} eq 'c') {print "ok 4\n";} else {print "not ok 4\n";}
  548. X
  549. X$foo = join('',values(foo));
  550. Xif ($foo eq 'ac' || $foo eq 'ca') {print "ok 5\n";} else {print "not ok 5\n";}
  551. X
  552. Xforeach $key (keys foo) {
  553. X    delete $foo{$key};
  554. X}
  555. X
  556. X$foo{'foo'} = 'x';
  557. X$foo{'bar'} = 'y';
  558. X
  559. X$foo = join('',values(foo));
  560. Xif ($foo eq 'xy' || $foo eq 'yx') {print "ok 6\n";} else {print "not ok 6\n";}
  561. !STUFFY!FUNK!
  562. echo Extracting util.h
  563. sed >util.h <<'!STUFFY!FUNK!' -e 's/X//'
  564. X/* $Header: util.h,v 3.0 89/10/18 15:33:18 lwall Locked $
  565. X *
  566. X *    Copyright (c) 1989, Larry Wall
  567. X *
  568. X *    You may distribute under the terms of the GNU General Public License
  569. X *    as specified in the README file that comes with the perl 3.0 kit.
  570. X *
  571. X * $Log:    util.h,v $
  572. X * Revision 3.0  89/10/18  15:33:18  lwall
  573. X * 3.0 baseline
  574. X * 
  575. X */
  576. X
  577. XEXT int *screamfirst INIT(Null(int*));
  578. XEXT int *screamnext INIT(Null(int*));
  579. X
  580. Xchar    *safemalloc();
  581. Xchar    *saferealloc();
  582. Xchar    *cpytill();
  583. Xchar    *instr();
  584. Xchar    *fbminstr();
  585. Xchar    *screaminstr();
  586. Xvoid    fbmcompile();
  587. Xchar    *savestr();
  588. Xvoid    setenv();
  589. Xint    envix();
  590. Xvoid    growstr();
  591. Xchar    *ninstr();
  592. Xchar    *rninstr();
  593. Xchar    *nsavestr();
  594. XFILE    *mypopen();
  595. Xint    mypclose();
  596. !STUFFY!FUNK!
  597. echo Extracting array.h
  598. sed >array.h <<'!STUFFY!FUNK!' -e 's/X//'
  599. X/* $Header: array.h,v 3.0 89/10/18 15:08:41 lwall Locked $
  600. X *
  601. X *    Copyright (c) 1989, Larry Wall
  602. X *
  603. X *    You may distribute under the terms of the GNU General Public License
  604. X *    as specified in the README file that comes with the perl 3.0 kit.
  605. X *
  606. X * $Log:    array.h,v $
  607. X * Revision 3.0  89/10/18  15:08:41  lwall
  608. X * 3.0 baseline
  609. X * 
  610. X */
  611. X
  612. Xstruct atbl {
  613. X    STR    **ary_array;
  614. X    STR **ary_alloc;
  615. X    STR *ary_magic;
  616. X    int ary_max;
  617. X    int ary_fill;
  618. X    int ary_index;
  619. X    char ary_flags;
  620. X};
  621. X
  622. X#define ARF_REAL 1    /* free old entries */
  623. X
  624. XSTR *afetch();
  625. Xbool astore();
  626. XSTR *apop();
  627. XSTR *ashift();
  628. Xvoid afree();
  629. Xvoid aclear();
  630. Xbool apush();
  631. Xint alen();
  632. XARRAY *anew();
  633. XARRAY *afake();
  634. !STUFFY!FUNK!
  635. echo Extracting t/comp.package
  636. sed >t/comp.package <<'!STUFFY!FUNK!' -e 's/X//'
  637. X#!./perl
  638. X
  639. Xprint "1..7\n";
  640. X
  641. X$blurfl = 123;
  642. X$foo = 3;
  643. X
  644. Xpackage XYZ;
  645. X
  646. X$bar = 4;
  647. X
  648. X{
  649. X    package ABC;
  650. X    $blurfl = 5;
  651. X    $main'a = $'b;
  652. X}
  653. X
  654. X$ABC'dyick = 6;
  655. X
  656. X$xyz = 2;
  657. X
  658. X$main = join(':', sort(keys _main));
  659. X$XYZ = join(':', sort(keys _XYZ));
  660. X$ABC = join(':', sort(keys _ABC));
  661. X
  662. Xprint $XYZ eq 'ABC:XYZ:bar:main:xyz' ? "ok 1\n" : "not ok 1 '$XYZ'\n";
  663. Xprint $ABC eq 'blurfl:dyick' ? "ok 2\n" : "not ok 2\n";
  664. Xprint $main'blurfl == 123 ? "ok 3\n" : "not ok 3\n";
  665. Xpackage ABC;
  666. Xprint $blurfl == 5 ? "ok 4\n" : "not ok 4\n";
  667. Xeval 'print $blurfl == 5 ? "ok 5\n" : "not ok 5\n";';
  668. Xeval 'package main; print $blurfl == 123 ? "ok 6\n" : "not ok 6\n";';
  669. Xprint $blurfl == 5 ? "ok 7\n" : "not ok 7\n";
  670. !STUFFY!FUNK!
  671. echo Extracting t/op.range
  672. sed >t/op.range <<'!STUFFY!FUNK!' -e 's/X//'
  673. X#!./perl
  674. X
  675. X# $Header: op.range,v 3.0 89/10/18 15:30:53 lwall Locked $
  676. X
  677. Xprint "1..6\n";
  678. X
  679. Xprint join(':',1..5) eq '1:2:3:4:5' ? "ok 1\n" : "not ok 1\n";
  680. X
  681. X@foo = (1,2,3,4,5,6,7,8,9);
  682. X@foo[2..4] = ('c','d','e');
  683. X
  684. Xprint join(':',@foo[$foo[0]..5]) eq '2:c:d:e:6' ? "ok 2\n" : "not ok 2\n";
  685. X
  686. X@bar[2..4] = ('c','d','e');
  687. Xprint join(':',@bar[1..5]) eq ':c:d:e:' ? "ok 3\n" : "not ok 3\n";
  688. X
  689. X($a,@bcd[0..2],$e) = ('a','b','c','d','e');
  690. Xprint join(':',$a,@bcd[0..2],$e) eq 'a:b:c:d:e' ? "ok 4\n" : "not ok 4\n";
  691. X
  692. X$x = 0;
  693. Xfor (1..100) {
  694. X    $x += $_;
  695. X}
  696. Xprint $x == 5050 ? "ok 5\n" : "not ok 5 $x\n";
  697. X
  698. X$x = 0;
  699. Xfor ((100,2..99,1)) {
  700. X    $x += $_;
  701. X}
  702. Xprint $x == 5050 ? "ok 6\n" : "not ok 6 $x\n";
  703. !STUFFY!FUNK!
  704. echo Extracting t/cmd.mod
  705. sed >t/cmd.mod <<'!STUFFY!FUNK!' -e 's/X//'
  706. X#!./perl
  707. X
  708. X# $Header: cmd.mod,v 3.0 89/10/18 15:24:48 lwall Locked $
  709. X
  710. Xprint "1..7\n";
  711. X
  712. Xprint "ok 1\n" if 1;
  713. Xprint "not ok 1\n" unless 1;
  714. X
  715. Xprint "ok 2\n" unless 0;
  716. Xprint "not ok 2\n" if 0;
  717. X
  718. X1 && (print "not ok 3\n") if 0;
  719. X1 && (print "ok 3\n") if 1;
  720. X0 || (print "not ok 4\n") if 0;
  721. X0 || (print "ok 4\n") if 1;
  722. X
  723. X$x = 0;
  724. Xdo {$x[$x] = $x;} while ($x++) < 10;
  725. Xif (join(' ',@x) eq '0 1 2 3 4 5 6 7 8 9 10') {
  726. X    print "ok 5\n";
  727. X} else {
  728. X    print "not ok 5\n";
  729. X}
  730. X
  731. X$x = 15;
  732. X$x = 10 while $x < 10;
  733. Xif ($x == 15) {print "ok 6\n";} else {print "not ok 6\n";}
  734. X
  735. Xopen(foo,'TEST') || open(foo,'t/TEST');
  736. X$x = 0;
  737. X$x++ while <foo>;
  738. Xprint $x > 50 && $x < 1000 ? "ok 7\n" : "not ok 7\n";
  739. !STUFFY!FUNK!
  740. echo Extracting t/op.exec
  741. sed >t/op.exec <<'!STUFFY!FUNK!' -e 's/X//'
  742. X#!./perl
  743. X
  744. X# $Header: op.exec,v 3.0 89/10/18 15:28:57 lwall Locked $
  745. X
  746. X$| = 1;                # flush stdout
  747. Xprint "1..8\n";
  748. X
  749. Xprint "not ok 1\n" if system "echo ok \\1";    # shell interpreted
  750. Xprint "not ok 2\n" if system "echo ok 2";    # split and directly called
  751. Xprint "not ok 3\n" if system "echo", "ok", "3"; # directly called
  752. X
  753. Xif (system "true") {print "not ok 4\n";} else {print "ok 4\n";}
  754. X
  755. Xif ((system "/bin/sh -c 'exit 1'") != 256) { print "not "; }
  756. Xprint "ok 5\n";
  757. X
  758. Xif ((system "lskdfj") == 255 << 8) {print "ok 6\n";} else {print "not ok 6\n";}
  759. X
  760. Xunless (exec "lskdjfalksdjfdjfkls") {print "ok 7\n";} else {print "not ok 7\n";}
  761. X
  762. Xexec "echo","ok","8";
  763. !STUFFY!FUNK!
  764. echo Extracting lib/stat.pl
  765. sed >lib/stat.pl <<'!STUFFY!FUNK!' -e 's/X//'
  766. X;# $Header: stat.pl,v 3.0 89/10/18 15:19:53 lwall Locked $
  767. X
  768. X;# Usage:
  769. X;#    @ary = stat(foo);
  770. X;#    $st_dev = @ary[$ST_DEV];
  771. X;#
  772. X$ST_DEV =    0 + $[;
  773. X$ST_INO =    1 + $[;
  774. X$ST_MODE =    2 + $[;
  775. X$ST_NLINK =    3 + $[;
  776. X$ST_UID =    4 + $[;
  777. X$ST_GID =    5 + $[;
  778. X$ST_RDEV =    6 + $[;
  779. X$ST_SIZE =    7 + $[;
  780. X$ST_ATIME =    8 + $[;
  781. X$ST_MTIME =    9 + $[;
  782. X$ST_CTIME =    10 + $[;
  783. X$ST_BLKSIZE =    11 + $[;
  784. X$ST_BLOCKS =    12 + $[;
  785. X
  786. X;# Usage:
  787. X;#    do Stat('foo');        # sets st_* as a side effect
  788. X;#
  789. Xsub Stat {
  790. X    ($st_dev,$st_ino,$st_mode,$st_nlink,$st_uid,$st_gid,$st_rdev,$st_size,
  791. X    $st_atime,$st_mtime,$st_ctime,$st_blksize,$st_blocks) = stat(shift(@_));
  792. X}
  793. X
  794. X1;
  795. !STUFFY!FUNK!
  796. echo Extracting t/op.goto
  797. sed >t/op.goto <<'!STUFFY!FUNK!' -e 's/X//'
  798. X#!./perl
  799. X
  800. X# $Header: op.goto,v 3.0 89/10/18 15:29:24 lwall Locked $
  801. X
  802. Xprint "1..3\n";
  803. X
  804. Xwhile (0) {
  805. X    $foo = 1;
  806. X  label1:
  807. X    $foo = 2;
  808. X    goto label2;
  809. X} continue {
  810. X    $foo = 0;
  811. X    goto label4;
  812. X  label3:
  813. X    $foo = 4;
  814. X    goto label4;
  815. X}
  816. Xgoto label1;
  817. X
  818. X$foo = 3;
  819. X
  820. Xlabel2:
  821. Xprint "#1\t:$foo: == 2\n";
  822. Xif ($foo == 2) {print "ok 1\n";} else {print "not ok 1\n";}
  823. Xgoto label3;
  824. X
  825. Xlabel4:
  826. Xprint "#2\t:$foo: == 4\n";
  827. Xif ($foo == 4) {print "ok 2\n";} else {print "not ok 2\n";}
  828. X
  829. X$x = `./perl -e 'goto foo;' 2>&1`;
  830. Xprint "#3\t/label/ in :$x";
  831. Xif ($x =~ /label/) {print "ok 3\n";} else {print "not ok 3\n";}
  832. !STUFFY!FUNK!
  833. echo Extracting client
  834. sed >client <<'!STUFFY!FUNK!' -e 's/X//'
  835. X#!./perl
  836. X
  837. X$pat = 'S n C4 x8';
  838. X$inet = 2;
  839. X$echo = 7;
  840. X$smtp = 25;
  841. X$nntp = 119;
  842. X$test = 2345;
  843. X
  844. X$SIG{'INT'} = 'dokill';
  845. X
  846. X$this = pack($pat,$inet,0,   128,149,13,43);
  847. X$that = pack($pat,$inet,$test,127,0,0,1);
  848. X
  849. Xif (socket(S,2,1,6)) { print "socket ok\n"; } else { die $!; }
  850. Xif (bind(S,$this)) { print "bind ok\n"; } else { die $!; }
  851. Xif (connect(S,$that)) { print "connect ok\n"; } else { die $!; }
  852. X
  853. Xselect(S); $| = 1; select(stdout);
  854. X
  855. Xif ($child = fork) {
  856. X    while (<>) {
  857. X    print S;
  858. X    }
  859. X    sleep 3;
  860. X    do dokill();
  861. X}
  862. Xelse {
  863. X    while (<S>) {
  864. X    print;
  865. X    }
  866. X}
  867. X
  868. Xsub dokill { kill 9,$child if $child; }
  869. !STUFFY!FUNK!
  870. echo Extracting eg/muck.man
  871. sed >eg/muck.man <<'!STUFFY!FUNK!' -e 's/X//'
  872. X.\" $Header: muck.man,v 3.0 89/10/18 15:14:55 lwall Locked $
  873. X.TH MUCK 1 "10 Jan 1989"
  874. X.SH NAME
  875. Xmuck \- make usage checker
  876. X.SH SYNOPSIS
  877. X.B muck
  878. X[options]
  879. X.SH DESCRIPTION
  880. X.I muck
  881. Xlooks at your current makefile and complains if you've left out any dependencies
  882. Xbetween .o and .h files.
  883. XIt also complains about extraneous dependencies.
  884. X.PP
  885. XYou can use the -f FILENAME option to specify an alternate name for your
  886. Xmakefile.
  887. XThe -v option is a little more verbose about what muck is mucking around
  888. Xwith at the moment.
  889. X.SH SEE ALSO
  890. Xmake(1)
  891. X.SH BUGS
  892. XOnly knows about .h, .c and .o files.
  893. !STUFFY!FUNK!
  894. echo Extracting lib/dumpvar.pl
  895. sed >lib/dumpvar.pl <<'!STUFFY!FUNK!' -e 's/X//'
  896. Xpackage dumpvar;
  897. X
  898. Xsub main'dumpvar {
  899. X    ($package) = @_;
  900. X    local(*stab) = eval("*_$package");
  901. X    while (($key,$val) = each(%stab)) {
  902. X    {
  903. X        local(*entry) = $val;
  904. X        if (defined $entry) {
  905. X        print "\$$key = '$entry'\n";
  906. X        }
  907. X        if (defined @entry) {
  908. X        print "\@$key = (\n";
  909. X        foreach $num ($[ .. $#entry) {
  910. X            print "  $num\t'",$entry[$num],"'\n";
  911. X        }
  912. X        print ")\n";
  913. X        }
  914. X        if ($key ne "_$package" && defined %entry) {
  915. X        print "\%$key = (\n";
  916. X        foreach $key (sort keys(%entry)) {
  917. X            print "  $key\t'",$entry{$key},"'\n";
  918. X        }
  919. X        print ")\n";
  920. X        }
  921. X    }
  922. X    }
  923. X}
  924. !STUFFY!FUNK!
  925. echo Extracting server
  926. sed >server <<'!STUFFY!FUNK!' -e 's/X//'
  927. X#!./perl
  928. X
  929. X$pat = 'S n C4 x8';
  930. X$inet = 2;
  931. X$echo = 7;
  932. X$smtp = 25;
  933. X$nntp = 119;
  934. X
  935. X$this = pack($pat,$inet,2345, 0,0,0,0);
  936. Xselect(NS); $| = 1; select(stdout);
  937. X
  938. Xif (socket(S,2,1,6)) { print "socket ok\n"; } else { die $!; }
  939. Xif (bind(S,$this)) { print "bind ok\n"; } else { die $!; }
  940. Xif (listen(S,5)) { print "listen ok\n"; } else { die $!; }
  941. Xfor (;;) {
  942. X    print "Listening again\n";
  943. X    if ($addr = accept(NS,S)) { print "accept ok\n"; } else { die $!; }
  944. X
  945. X    @ary = unpack($pat,$addr);
  946. X    $, = ' ';
  947. X    print @ary; print "\n";
  948. X
  949. X    while (<NS>) {
  950. X    print;
  951. X    print NS;
  952. X    }
  953. X}
  954. !STUFFY!FUNK!
  955. echo Extracting t/op.flip
  956. sed >t/op.flip <<'!STUFFY!FUNK!' -e 's/X//'
  957. X#!./perl
  958. X
  959. X# $Header: op.flip,v 3.0 89/10/18 15:29:07 lwall Locked $
  960. X
  961. Xprint "1..8\n";
  962. X
  963. X@a = (1,2,3,4,5,6,7,8,9,10,11,12);
  964. X
  965. Xwhile ($_ = shift(a)) {
  966. X    if ($x = /4/../8/) { $z = $x; print "ok ", $x + 0, "\n"; }
  967. X    $y .= /1/../2/;
  968. X}
  969. X
  970. Xif ($z eq '5E0') {print "ok 6\n";} else {print "not ok 6\n";}
  971. X
  972. Xif ($y eq '12E0123E0') {print "ok 7\n";} else {print "not ok 7\n";}
  973. X
  974. X@a = ('a','b','c','d','e','f','g');
  975. X
  976. Xopen(of,'../Makefile');
  977. Xwhile (<of>) {
  978. X    (3 .. 5) && $foo .= $_;
  979. X}
  980. X$x = ($foo =~ y/\n/\n/);
  981. X
  982. Xif ($x eq 3) {print "ok 8\n";} else {print "not ok 8 $x:$foo:\n";}
  983. !STUFFY!FUNK!
  984. echo Extracting eg/dus
  985. sed >eg/dus <<'!STUFFY!FUNK!' -e 's/X//'
  986. X#!/usr/bin/perl
  987. X
  988. X# $Header: dus,v 3.0 89/10/18 15:13:43 lwall Locked $
  989. X
  990. X# This script does a du -s on any directories in the current directory that
  991. X# are not mount points for another filesystem.
  992. X
  993. X($mydev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
  994. X   $blksize,$blocks) = stat('.');
  995. X
  996. Xopen(ls,'ls -F1|');
  997. X
  998. Xwhile (<ls>) {
  999. X    chop;
  1000. X    next unless s|/$||;
  1001. X    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
  1002. X       $blksize,$blocks) = stat($_);
  1003. X    next unless $dev == $mydev;
  1004. X    push(@ary,$_);
  1005. X}
  1006. X
  1007. Xexec 'du', '-s', @ary;
  1008. !STUFFY!FUNK!
  1009. echo Extracting t/op.chop
  1010. sed >t/op.chop <<'!STUFFY!FUNK!' -e 's/X//'
  1011. X#!./perl
  1012. X
  1013. X# $Header: op.chop,v 3.0 89/10/18 15:28:19 lwall Locked $
  1014. X
  1015. Xprint "1..4\n";
  1016. X
  1017. X# optimized
  1018. X
  1019. X$_ = 'abc';
  1020. X$c = do foo();
  1021. Xif ($c . $_ eq 'cab') {print "ok 1\n";} else {print "not ok 1 $c$_\n";}
  1022. X
  1023. X# unoptimized
  1024. X
  1025. X$_ = 'abc';
  1026. X$c = chop($_);
  1027. Xif ($c . $_ eq 'cab') {print "ok 2\n";} else {print "not ok 2\n";}
  1028. X
  1029. Xsub foo {
  1030. X    chop;
  1031. X}
  1032. X
  1033. X@foo = ("hi \n","there\n","!\n");
  1034. X@bar = @foo;
  1035. Xchop(@bar);
  1036. Xprint join('',@bar) eq 'hi there!' ? "ok 3\n" : "not ok 3\n";
  1037. X
  1038. X$foo = "\n";
  1039. Xchop($foo,@foo);
  1040. Xprint join('',$foo,@foo) eq 'hi there!' ? "ok 4\n" : "not ok 4\n";
  1041. !STUFFY!FUNK!
  1042. echo Extracting gettest
  1043. sed >gettest <<'!STUFFY!FUNK!' -e 's/X//'
  1044. X#!./perl
  1045. X
  1046. X    while (($name,$aliases,$addrtype,$length,@addrs) = gethostent) {
  1047. X    print $name,' ',$aliases,
  1048. X      sprintf(" %d.%d.%d.%d\n",unpack('CCCC',$addrs[0]));
  1049. X    last if $i++ > 50;
  1050. X    }
  1051. X    <stdin>;
  1052. X    while (($name,$aliases,$addrtype,$net) = getnetent) {
  1053. X    print "$name $aliases $addrtype ",sprintf("%08lx",$net),"\n";
  1054. X    }
  1055. X    <stdin>;
  1056. X    while (($name,$aliases,$proto) = getprotoent) {
  1057. X    print "$name $aliases $proto\n";
  1058. X    }
  1059. X    <stdin>;
  1060. X    while (($name,$aliases,$port,$proto) = getservent) {
  1061. X    print "$name $aliases $port $proto\n";
  1062. X    }
  1063. X
  1064. !STUFFY!FUNK!
  1065. echo Extracting t/io.dup
  1066. sed >t/io.dup <<'!STUFFY!FUNK!' -e 's/X//'
  1067. X#!./perl
  1068. X
  1069. X# $Header: io.dup,v 3.0 89/10/18 15:26:15 lwall Locked $
  1070. X
  1071. Xprint "1..6\n";
  1072. X
  1073. Xprint "ok 1\n";
  1074. X
  1075. Xopen(dupout,">&STDOUT");
  1076. Xopen(duperr,">&STDERR");
  1077. X
  1078. Xopen(STDOUT,">Io.dup") || die "Can't open stdout";
  1079. Xopen(STDERR,">&STDOUT") || die "Can't open stderr";
  1080. X
  1081. Xselect(STDERR); $| = 1;
  1082. Xselect(STDOUT); $| = 1;
  1083. X
  1084. Xprint STDOUT "ok 2\n";
  1085. Xprint STDERR "ok 3\n";
  1086. Xsystem 'echo ok 4';
  1087. Xsystem 'echo ok 5 1>&2';
  1088. X
  1089. Xclose(STDOUT);
  1090. Xclose(STDERR);
  1091. X
  1092. Xopen(STDOUT,">&dupout");
  1093. Xopen(STDERR,">&duperr");
  1094. X
  1095. Xsystem 'cat Io.dup';
  1096. Xunlink 'Io.dup';
  1097. X
  1098. Xprint STDOUT "ok 6\n";
  1099. !STUFFY!FUNK!
  1100. echo Extracting t/op.sort
  1101. sed >t/op.sort <<'!STUFFY!FUNK!' -e 's/X//'
  1102. X#!./perl
  1103. X
  1104. X# $Header: op.sort,v 3.0 89/10/18 15:31:19 lwall Locked $
  1105. X
  1106. Xprint "1..3\n";
  1107. X
  1108. Xsub reverse { $a lt $b ? 1 : $a gt $b ? -1 : 0; }
  1109. X
  1110. X@harry = ('dog','cat','x','Cain','Abel');
  1111. X@george = ('gone','chased','yz','Punished','Axed');
  1112. X
  1113. X$x = join('', sort @harry);
  1114. Xprint ($x eq 'AbelCaincatdogx' ? "ok 1\n" : "not ok 1\n");
  1115. X
  1116. X$x = join('', sort reverse @harry);
  1117. Xprint ($x eq 'xdogcatCainAbel' ? "ok 2\n" : "not ok 2\n");
  1118. X
  1119. X$x = join('', sort @george, 'to', @harry);
  1120. Xprint ($x eq 'AbelAxedCainPunishedcatchaseddoggonetoxyz'?"ok 3\n":"not ok 3\n");
  1121. !STUFFY!FUNK!
  1122. echo Extracting lib/abbrev.pl
  1123. sed >lib/abbrev.pl <<'!STUFFY!FUNK!' -e 's/X//'
  1124. X;# Usage:
  1125. X;#    %foo = ();
  1126. X;#    &abbrev(*foo,LIST);
  1127. X;#    ...
  1128. X;#    $long = $foo{$short};
  1129. X
  1130. Xpackage abbrev;
  1131. X
  1132. Xsub main'abbrev {
  1133. X    local(*domain) = @_;
  1134. X    shift(@_);
  1135. X    @cmp = @_;
  1136. X    foreach $name (@_) {
  1137. X    @extra = split(//,$name);
  1138. X    $abbrev = shift(@extra);
  1139. X    $len = 1;
  1140. X    foreach $cmp (@cmp) {
  1141. X        next if $cmp eq $name;
  1142. X        while (substr($cmp,0,$len) eq $abbrev) {
  1143. X        $abbrev .= shift(@extra);
  1144. X        ++$len;
  1145. X        }
  1146. X    }
  1147. X    $domain{$abbrev} = $name;
  1148. X    while ($#extra >= 0) {
  1149. X        $abbrev .= shift(@extra);
  1150. X        $domain{$abbrev} = $name;
  1151. X    }
  1152. X    }
  1153. X}
  1154. X
  1155. X1;
  1156. !STUFFY!FUNK!
  1157. echo Extracting t/cmd.elsif
  1158. sed >t/cmd.elsif <<'!STUFFY!FUNK!' -e 's/X//'
  1159. X#!./perl
  1160. X
  1161. X# $Header: cmd.elsif,v 3.0 89/10/18 15:24:38 lwall Locked $
  1162. X
  1163. Xsub foo {
  1164. X    if ($_[0] == 1) {
  1165. X    1;
  1166. X    }
  1167. X    elsif ($_[0] == 2) {
  1168. X    2;
  1169. X    }
  1170. X    elsif ($_[0] == 3) {
  1171. X    3;
  1172. X    }
  1173. X    else {
  1174. X    4;
  1175. X    }
  1176. X}
  1177. X
  1178. Xprint "1..4\n";
  1179. X
  1180. Xif (($x = do foo(1)) == 1) {print "ok 1\n";} else {print "not ok 1 '$x'\n";}
  1181. Xif (($x = do foo(2)) == 2) {print "ok 2\n";} else {print "not ok 2 '$x'\n";}
  1182. Xif (($x = do foo(3)) == 3) {print "ok 3\n";} else {print "not ok 3 '$x'\n";}
  1183. Xif (($x = do foo(4)) == 4) {print "ok 4\n";} else {print "not ok 4 '$x'\n";}
  1184. !STUFFY!FUNK!
  1185. echo Extracting t/comp.script
  1186. sed >t/comp.script <<'!STUFFY!FUNK!' -e 's/X//'
  1187. X#!./perl
  1188. X
  1189. X# $Header: comp.script,v 3.0 89/10/18 15:25:55 lwall Locked $
  1190. X
  1191. Xprint "1..3\n";
  1192. X
  1193. X$x = `./perl -e 'print "ok\n";'`;
  1194. X
  1195. Xif ($x eq "ok\n") {print "ok 1\n";} else {print "not ok 1\n";}
  1196. X
  1197. Xopen(try,">Comp.script") || (die "Can't open temp file.");
  1198. Xprint try 'print "ok\n";'; print try "\n";
  1199. Xclose try;
  1200. X
  1201. X$x = `./perl Comp.script`;
  1202. X
  1203. Xif ($x eq "ok\n") {print "ok 2\n";} else {print "not ok 2\n";}
  1204. X
  1205. X$x = `./perl <Comp.script`;
  1206. X
  1207. Xif ($x eq "ok\n") {print "ok 3\n";} else {print "not ok 3\n";}
  1208. X
  1209. X`/bin/rm -f Comp.script`;
  1210. !STUFFY!FUNK!
  1211. echo Extracting eg/findtar
  1212. sed >eg/findtar <<'!STUFFY!FUNK!' -e 's/X//'
  1213. X#!/usr/bin/perl
  1214. X
  1215. X# $Header: findtar,v 3.0 89/10/18 15:13:52 lwall Locked $
  1216. X
  1217. X# findtar takes find-style arguments and spits out a tarfile on stdout.
  1218. X# It won't work unless your find supports -ls and your tar the I flag.
  1219. X
  1220. X$args = join(' ',@ARGV);
  1221. Xopen(find,"/usr/bin/find $args -ls |") || die "Can't run find for you.";
  1222. X
  1223. Xopen(tar,"| /bin/tar cIf - -") || die "Can't run tar for you: $!";
  1224. X
  1225. Xwhile (<find>) {
  1226. X    @x = split(' ');
  1227. X    if ($x[2] =~ /^d/) { print tar '-d ';}
  1228. X    print tar $x[10],"\n";
  1229. X}
  1230. !STUFFY!FUNK!
  1231. echo Extracting t/comp.decl
  1232. sed >t/comp.decl <<'!STUFFY!FUNK!' -e 's/X//'
  1233. X#!./perl
  1234. X
  1235. X# $Header: comp.decl,v 3.0 89/10/18 15:25:25 lwall Locked $
  1236. X
  1237. X# check to see if subroutine declarations work everwhere
  1238. X
  1239. Xsub one {
  1240. X    print "ok 1\n";
  1241. X}
  1242. Xformat one =
  1243. Xok 5
  1244. X.
  1245. X
  1246. Xprint "1..7\n";
  1247. X
  1248. Xdo one();
  1249. Xdo two();
  1250. X
  1251. Xsub two {
  1252. X    print "ok 2\n";
  1253. X}
  1254. Xformat two =
  1255. X@<<<
  1256. X$foo
  1257. X.
  1258. X
  1259. Xif ($x eq $x) {
  1260. X    sub three {
  1261. X    print "ok 3\n";
  1262. X    }
  1263. X    do three();
  1264. X}
  1265. X
  1266. Xdo four();
  1267. X$~ = 'one';
  1268. Xwrite;
  1269. X$~ = 'two';
  1270. X$foo = "ok 6";
  1271. Xwrite;
  1272. X$~ = 'three';
  1273. Xwrite;
  1274. X
  1275. Xformat three =
  1276. Xok 7
  1277. X.
  1278. X
  1279. Xsub four {
  1280. X    print "ok 4\n";
  1281. X}
  1282. !STUFFY!FUNK!
  1283. echo Extracting t/op.append
  1284. sed >t/op.append <<'!STUFFY!FUNK!' -e 's/X//'
  1285. X#!./perl
  1286. X
  1287. X# $Header: op.append,v 3.0 89/10/18 15:26:51 lwall Locked $
  1288. X
  1289. Xprint "1..3\n";
  1290. X
  1291. X$a = 'ab' . 'c';    # compile time
  1292. X$b = 'def';
  1293. X
  1294. X$c = $a . $b;
  1295. Xprint "#1\t:$c: eq :abcdef:\n";
  1296. Xif ($c eq 'abcdef') {print "ok 1\n";} else {print "not ok 1\n";}
  1297. X
  1298. X$c .= 'xyz';
  1299. Xprint "#2\t:$c: eq :abcdefxyz:\n";
  1300. Xif ($c eq 'abcdefxyz') {print "ok 2\n";} else {print "not ok 2\n";}
  1301. X
  1302. X$_ = $a;
  1303. X$_ .= $b;
  1304. Xprint "#3\t:$_: eq :abcdef:\n";
  1305. Xif ($_ eq 'abcdef') {print "ok 3\n";} else {print "not ok 3\n";}
  1306. !STUFFY!FUNK!
  1307. echo Extracting eg/down
  1308. sed >eg/down <<'!STUFFY!FUNK!' -e 's/X//'
  1309. X#!/usr/bin/perl
  1310. X
  1311. X$| = 1;
  1312. Xif ($#ARGV >= 0) {
  1313. X    $cmd = join(' ',@ARGV);
  1314. X}
  1315. Xelse {
  1316. X    print "Command: ";
  1317. X    $cmd = <stdin>;
  1318. X    chop($cmd);
  1319. X    while ($cmd =~ s/\\$//) {
  1320. X    print "+ ";
  1321. X    $cmd .= <stdin>;
  1322. X    chop($cmd);
  1323. X    }
  1324. X}
  1325. X$cwd = `pwd`; chop($cwd);
  1326. X
  1327. Xopen(FIND,'find . -type d -print|') || die "Can't run find";
  1328. X
  1329. Xwhile (<FIND>) {
  1330. X    chop;
  1331. X    unless (chdir $_) {
  1332. X    print stderr "Can't cd to $_\n";
  1333. X    next;
  1334. X    }
  1335. X    print "\t--> ",$_,"\n";
  1336. X    system $cmd;
  1337. X    chdir $cwd;
  1338. X}
  1339. !STUFFY!FUNK!
  1340. echo Extracting t/op.glob
  1341. sed >t/op.glob <<'!STUFFY!FUNK!' -e 's/X//'
  1342. X#!./perl
  1343. X
  1344. X# $Header: op.glob,v 3.0 89/10/18 15:29:19 lwall Locked $
  1345. X
  1346. Xprint "1..4\n";
  1347. X
  1348. X@ops = <op.*>;
  1349. X$list = join(' ',@ops);
  1350. X
  1351. Xchop($otherway = `echo op.*`);
  1352. X
  1353. Xprint $list eq $otherway ? "ok 1\n" : "not ok 1\n$list\n$otherway\n";
  1354. X
  1355. Xprint $/ eq "\n" ? "ok 2\n" : "not ok 2\n";
  1356. X
  1357. Xwhile (<jskdfjskdfj* op.* jskdjfjkosvk*>) {
  1358. X    $not = "not " unless $_ eq shift @ops;
  1359. X    $not = "not at all " if $/ eq "\0";
  1360. X}
  1361. Xprint "${not}ok 3\n";
  1362. X
  1363. Xprint $/ eq "\n" ? "ok 4\n" : "not ok 4\n";
  1364. !STUFFY!FUNK!
  1365. echo Extracting eg/who
  1366. sed >eg/who <<'!STUFFY!FUNK!' -e 's/X//'
  1367. X#!/usr/bin/perl
  1368. X# This assumes your /etc/utmp file looks like ours
  1369. Xopen(utmp,'/etc/utmp');
  1370. X@mo = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
  1371. Xwhile (read(utmp,$utmp,36)) {
  1372. X    ($line,$name,$host,$time) = unpack('A8A8A16l',$utmp);
  1373. X    if ($name) {
  1374. X    $host = "($host)" if $host;
  1375. X    ($sec,$min,$hour,$mday,$mon) = localtime($time);
  1376. X    printf "%-9s%-8s%s %2d %02d:%02d   %s\n",
  1377. X      $name,$line,$mo[$mon],$mday,$hour,$min,$host;
  1378. X    }
  1379. X}   
  1380. !STUFFY!FUNK!
  1381. echo Extracting t/op.mkdir
  1382. sed >t/op.mkdir <<'!STUFFY!FUNK!' -e 's/X//'
  1383. X#!./perl
  1384. X
  1385. X# $Header: op.mkdir,v 3.0 89/10/18 15:30:05 lwall Locked $
  1386. X
  1387. Xprint "1..7\n";
  1388. X
  1389. X`rm -rf blurfl`;
  1390. X
  1391. Xprint (mkdir('blurfl',0666) ? "ok 1\n" : "not ok 1\n");
  1392. Xprint (mkdir('blurfl',0666) ? "not ok 2\n" : "ok 2\n");
  1393. Xprint ($! == 17 ? "ok 3\n" : "not ok 3\n");
  1394. Xprint (-d 'blurfl' ? "ok 4\n" : "not ok 4\n");
  1395. Xprint (rmdir('blurfl') ? "ok 5\n" : "not ok 5\n");
  1396. Xprint (rmdir('blurfl') ? "not ok 6\n" : "ok 6\n");
  1397. Xprint ($! == 2 ? "ok 7\n" : "not ok 7\n");
  1398. !STUFFY!FUNK!
  1399. echo Extracting t/io.print
  1400. sed >t/io.print <<'!STUFFY!FUNK!' -e 's/X//'
  1401. X#!./perl
  1402. X
  1403. X# $Header: io.print,v 3.0 89/10/18 15:26:36 lwall Locked $
  1404. X
  1405. Xprint "1..16\n";
  1406. X
  1407. X$foo = 'STDOUT';
  1408. Xprint $foo "ok 1\n";
  1409. X
  1410. Xprint "ok 2\n","ok 3\n","ok 4\n";
  1411. Xprint STDOUT "ok 5\n";
  1412. X
  1413. Xopen(foo,">-");
  1414. Xprint foo "ok 6\n";
  1415. X
  1416. Xprintf "ok %d\n",7;
  1417. Xprintf("ok %d\n",8);
  1418. X
  1419. X@a = ("ok %d%c",9,ord("\n"));
  1420. Xprintf @a;
  1421. X
  1422. X$a[1] = 10;
  1423. Xprintf STDOUT @a;
  1424. X
  1425. X$, = ' ';
  1426. X$\ = "\n";
  1427. X
  1428. Xprint "ok","11";
  1429. X
  1430. X@x = ("ok","12\nok","13\nok");
  1431. X@y = ("15\nok","16");
  1432. Xprint @x,"14\nok",@y;
  1433. !STUFFY!FUNK!
  1434. echo Extracting t/io.inplace
  1435. sed >t/io.inplace <<'!STUFFY!FUNK!' -e 's/X//'
  1436. X#!./perl -i.bak
  1437. X
  1438. X# $Header: io.inplace,v 3.0 89/10/18 15:26:25 lwall Locked $
  1439. X
  1440. Xprint "1..2\n";
  1441. X
  1442. X@ARGV = ('.a','.b','.c');
  1443. X`echo foo | tee .a .b .c`;
  1444. Xwhile (<>) {
  1445. X    s/foo/bar/;
  1446. X}
  1447. Xcontinue {
  1448. X    print;
  1449. X}
  1450. X
  1451. Xif (`cat .a .b .c` eq "bar\nbar\nbar\n") {print "ok 1\n";} else {print "not ok 1\n";}
  1452. Xif (`cat .a.bak .b.bak .c.bak` eq "foo\nfoo\nfoo\n") {print "ok 2\n";} else {print "not ok 2\n";}
  1453. X
  1454. Xunlink '.a', '.b', '.c', '.a.bak', '.b.bak', '.c.bak';
  1455. !STUFFY!FUNK!
  1456. echo Extracting eg/van/vanexp
  1457. sed >eg/van/vanexp <<'!STUFFY!FUNK!' -e 's/X//'
  1458. X#!/usr/bin/perl
  1459. X
  1460. X# $Header: vanexp,v 3.0 89/10/18 15:16:41 lwall Locked $
  1461. X
  1462. X# This is for running from a find at night to expire old .deleteds
  1463. X
  1464. X$can = $ARGV[0];
  1465. X
  1466. Xexit 1 unless $can =~ /.deleted$/;
  1467. X
  1468. X($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
  1469. X   $blksize,$blocks) = stat($can);
  1470. X
  1471. Xexit 0 unless $size;
  1472. X
  1473. Xif (time - $mtime > 2 * 24 * 60 * 60) {
  1474. X    `/bin/rm -rf $can`;
  1475. X}
  1476. Xelse {
  1477. X    `find $can -ctime +2 -exec rm -f {} \;`;
  1478. X}
  1479. !STUFFY!FUNK!
  1480. echo Extracting t/op.read
  1481. sed >t/op.read <<'!STUFFY!FUNK!' -e 's/X//'
  1482. X#!./perl
  1483. X
  1484. X# $Header: op.read,v 3.0 89/10/18 15:30:58 lwall Locked $
  1485. X
  1486. Xprint "1..4\n";
  1487. X
  1488. X
  1489. Xopen(FOO,'op.read') || open(FOO,'t/op.read') || die "Can't open op.read";
  1490. Xseek(FOO,4,0);
  1491. X$got = read(FOO,$buf,4);
  1492. X
  1493. Xprint ($got == 4 ? "ok 1\n" : "not ok 1\n");
  1494. Xprint ($buf eq "perl" ? "ok 2\n" : "not ok 2 :$buf:\n");
  1495. X
  1496. Xseek(FOO,20000,0);
  1497. X$got = read(FOO,$buf,4);
  1498. X
  1499. Xprint ($got == 0 ? "ok 3\n" : "not ok 3\n");
  1500. Xprint ($buf eq "" ? "ok 4\n" : "not ok 4\n");
  1501. !STUFFY!FUNK!
  1502. echo Extracting t/op.pack
  1503. sed >t/op.pack <<'!STUFFY!FUNK!' -e 's/X//'
  1504. X#!./perl
  1505. X
  1506. X# $Header: op.pack,v 3.0 89/10/18 15:30:39 lwall Locked $
  1507. X
  1508. Xprint "1..3\n";
  1509. X
  1510. X$format = "c2x5CCxsila6";
  1511. X@ary = (1,-100,127,128,32767,12345,123456,"abcdef");
  1512. X$foo = pack($format,@ary);
  1513. X@ary2 = unpack($format,$foo);
  1514. X
  1515. Xprint ($#ary == $#ary2 ? "ok 1\n" : "not ok 1\n");
  1516. X
  1517. X$out1=join(':',@ary);
  1518. X$out2=join(':',@ary2);
  1519. Xprint ($out1 eq $out2 ? "ok 2\n" : "not ok 2\n");
  1520. X
  1521. Xprint ($foo =~ /def/ ? "ok 3\n" : "not ok 3\n");
  1522. !STUFFY!FUNK!
  1523. echo Extracting eg/g/ged
  1524. sed >eg/g/ged <<'!STUFFY!FUNK!' -e 's/X//'
  1525. X#!/usr/bin/perl
  1526. X
  1527. X# $Header: ged,v 3.0 89/10/18 15:14:22 lwall Locked $
  1528. X
  1529. X# Does inplace edits on a set of files on a set of machines.
  1530. X#
  1531. X# Typical invokation:
  1532. X#
  1533. X#    ged vax+sun /etc/passwd
  1534. X#    s/Freddy/Freddie/;
  1535. X#    ^D
  1536. X#
  1537. X
  1538. X$class = shift;
  1539. X$files = join(' ',@ARGV);
  1540. X
  1541. Xdie "Usage: ged class files <perlcmds\n" unless $files;
  1542. X
  1543. Xexec "gsh", $class, "-d", "perl -pi.bak - $files";
  1544. X
  1545. Xdie "Couldn't execute gsh for some reason, stopped";
  1546. !STUFFY!FUNK!
  1547. echo Extracting x2p/EXTERN.h
  1548. sed >x2p/EXTERN.h <<'!STUFFY!FUNK!' -e 's/X//'
  1549. X/* $Header: EXTERN.h,v 3.0 89/10/18 15:33:37 lwall Locked $
  1550. X *
  1551. X *    Copyright (c) 1989, Larry Wall
  1552. X *
  1553. X *    You may distribute under the terms of the GNU General Public License
  1554. X *    as specified in the README file that comes with the perl 3.0 kit.
  1555. X *
  1556. X * $Log:    EXTERN.h,v $
  1557. X * Revision 3.0  89/10/18  15:33:37  lwall
  1558. X * 3.0 baseline
  1559. X * 
  1560. X */
  1561. X
  1562. X#undef EXT
  1563. X#define EXT extern
  1564. X
  1565. X#undef INIT
  1566. X#define INIT(x)
  1567. X
  1568. X#undef DOINIT
  1569. !STUFFY!FUNK!
  1570. echo Extracting EXTERN.h
  1571. sed >EXTERN.h <<'!STUFFY!FUNK!' -e 's/X//'
  1572. X/* $Header: EXTERN.h,v 3.0 89/10/18 15:06:03 lwall Locked $
  1573. X *
  1574. X *    Copyright (c) 1989, Larry Wall
  1575. X *
  1576. X *    You may distribute under the terms of the GNU General Public License
  1577. X *    as specified in the README file that comes with the perl 3.0 kit.
  1578. X *
  1579. X * $Log:    EXTERN.h,v $
  1580. X * Revision 3.0  89/10/18  15:06:03  lwall
  1581. X * 3.0 baseline
  1582. X * 
  1583. X */
  1584. X
  1585. X#undef EXT
  1586. X#define EXT extern
  1587. X
  1588. X#undef INIT
  1589. X#define INIT(x)
  1590. X
  1591. X#undef DOINIT
  1592. !STUFFY!FUNK!
  1593. echo Extracting x2p/INTERN.h
  1594. sed >x2p/INTERN.h <<'!STUFFY!FUNK!' -e 's/X//'
  1595. X/* $Header: INTERN.h,v 3.0 89/10/18 15:33:45 lwall Locked $
  1596. X *
  1597. X *    Copyright (c) 1989, Larry Wall
  1598. X *
  1599. X *    You may distribute under the terms of the GNU General Public License
  1600. X *    as specified in the README file that comes with the perl 3.0 kit.
  1601. X *
  1602. X * $Log:    INTERN.h,v $
  1603. X * Revision 3.0  89/10/18  15:33:45  lwall
  1604. X * 3.0 baseline
  1605. X * 
  1606. X */
  1607. X
  1608. X#undef EXT
  1609. X#define EXT
  1610. X
  1611. X#undef INIT
  1612. X#define INIT(x) = x
  1613. X
  1614. X#define DOINIT
  1615. !STUFFY!FUNK!
  1616. echo Extracting INTERN.h
  1617. sed >INTERN.h <<'!STUFFY!FUNK!' -e 's/X//'
  1618. X/* $Header: INTERN.h,v 3.0 89/10/18 15:06:25 lwall Locked $
  1619. X *
  1620. X *    Copyright (c) 1989, Larry Wall
  1621. X *
  1622. X *    You may distribute under the terms of the GNU General Public License
  1623. X *    as specified in the README file that comes with the perl 3.0 kit.
  1624. X *
  1625. X * $Log:    INTERN.h,v $
  1626. X * Revision 3.0  89/10/18  15:06:25  lwall
  1627. X * 3.0 baseline
  1628. X * 
  1629. X */
  1630. X
  1631. X#undef EXT
  1632. X#define EXT
  1633. X
  1634. X#undef INIT
  1635. X#define INIT(x) = x
  1636. X
  1637. X#define DOINIT
  1638. !STUFFY!FUNK!
  1639. echo Extracting t/op.int
  1640. sed >t/op.int <<'!STUFFY!FUNK!' -e 's/X//'
  1641. X#!./perl
  1642. X
  1643. X# $Header: op.int,v 3.0 89/10/18 15:29:33 lwall Locked $
  1644. X
  1645. Xprint "1..4\n";
  1646. X
  1647. X# compile time evaluation
  1648. X
  1649. Xif (int(1.234) == 1) {print "ok 1\n";} else {print "not ok 1\n";}
  1650. X
  1651. Xif (int(-1.234) == -1) {print "ok 2\n";} else {print "not ok 2\n";}
  1652. X
  1653. X# run time evaluation
  1654. X
  1655. X$x = 1.234;
  1656. Xif (int($x) == 1) {print "ok 3\n";} else {print "not ok 3\n";}
  1657. Xif (int(-$x) == -1) {print "ok 4\n";} else {print "not ok 4\n";}
  1658. !STUFFY!FUNK!
  1659. echo Extracting t/base.cond
  1660. sed >t/base.cond <<'!STUFFY!FUNK!' -e 's/X//'
  1661. X#!./perl
  1662. X
  1663. X# $Header: base.cond,v 3.0 89/10/18 15:24:11 lwall Locked $
  1664. X
  1665. X# make sure conditional operators work
  1666. X
  1667. Xprint "1..4\n";
  1668. X
  1669. X$x = '0';
  1670. X
  1671. X$x eq $x && (print "ok 1\n");
  1672. X$x ne $x && (print "not ok 1\n");
  1673. X$x eq $x || (print "not ok 2\n");
  1674. X$x ne $x || (print "ok 2\n");
  1675. X
  1676. X$x == $x && (print "ok 3\n");
  1677. X$x != $x && (print "not ok 3\n");
  1678. X$x == $x || (print "not ok 4\n");
  1679. X$x != $x || (print "ok 4\n");
  1680. !STUFFY!FUNK!
  1681. echo Extracting perlsh
  1682. sed >perlsh <<'!STUFFY!FUNK!' -e 's/X//'
  1683. X#!/usr/bin/perl
  1684. X
  1685. X# Poor man's perl shell.
  1686. X
  1687. X# Simply type two carriage returns every time you want to evaluate.
  1688. X# Note that it must be a complete perl statement--don't type double
  1689. X#  carriage return in the middle of a loop.
  1690. X
  1691. X$/ = '';    # set paragraph mode
  1692. X$SHlinesep = "\n";
  1693. Xwhile ($SHcmd = <>) {
  1694. X    $/ = $SHlinesep;
  1695. X    eval $SHcmd; print $@ || "\n";
  1696. X    $SHlinesep = $/; $/ = '';
  1697. X}
  1698. !STUFFY!FUNK!
  1699. echo Extracting eg/nih
  1700. sed >eg/nih <<'!STUFFY!FUNK!' -e 's/X//'
  1701. Xeval "exec /usr/bin/perl -Spi.bak $0 $*"
  1702. X    if $running_under_some_shell;
  1703. X
  1704. X# $Header: nih,v 3.0 89/10/18 15:15:12 lwall Locked $
  1705. X
  1706. X# This script makes #! scripts directly executable on machines that don't
  1707. X# support #!.  It edits in place any scripts mentioned on the command line.
  1708. X
  1709. Xs|^#!(.*)|#!$1\neval "exec $1 -S \$0 \$*"\n\tif \$running_under_some_shell;|
  1710. X    if $. == 1;
  1711. !STUFFY!FUNK!
  1712. echo Extracting lib/importenv.pl
  1713. sed >lib/importenv.pl <<'!STUFFY!FUNK!' -e 's/X//'
  1714. X;# $Header: importenv.pl,v 3.0 89/10/18 15:19:39 lwall Locked $
  1715. X
  1716. X;# This file, when interpreted, pulls the environment into normal variables.
  1717. X;# Usage:
  1718. X;#    do 'importenv.pl';
  1719. X;# or
  1720. X;#    #include <importenv.pl>
  1721. X
  1722. Xlocal($tmp,$key) = '';
  1723. X
  1724. Xforeach $key (keys(ENV)) {
  1725. X    $tmp .= "\$$key = \$ENV{'$key'};" if $key =~ /^[A-Za-z]\w*$/;
  1726. X}
  1727. Xeval $tmp;
  1728. X
  1729. X1;
  1730. !STUFFY!FUNK!
  1731. echo Extracting t/op.join
  1732. sed >t/op.join <<'!STUFFY!FUNK!' -e 's/X//'
  1733. X#!./perl
  1734. X
  1735. X# $Header: op.join,v 3.0 89/10/18 15:29:38 lwall Locked $
  1736. X
  1737. Xprint "1..3\n";
  1738. X
  1739. X@x = (1, 2, 3);
  1740. Xif (join(':',@x) eq '1:2:3') {print "ok 1\n";} else {print "not ok 1\n";}
  1741. X
  1742. Xif (join('',1,2,3) eq '123') {print "ok 2\n";} else {print "not ok 2\n";}
  1743. X
  1744. Xif (join(':',split(/ /,"1 2 3")) eq '1:2:3') {print "ok 3\n";} else {print "not ok 3\n";}
  1745. !STUFFY!FUNK!
  1746. echo Extracting t/io.pipe
  1747. sed >t/io.pipe <<'!STUFFY!FUNK!' -e 's/X//'
  1748. X#!./perl
  1749. X
  1750. X# $Header: io.pipe,v 3.0 89/10/18 15:26:30 lwall Locked $
  1751. X
  1752. X$| = 1;
  1753. Xprint "1..4\n";
  1754. X
  1755. Xopen(PIPE, "|-") || (exec 'tr', '[A-Z]', '[a-z]');
  1756. Xprint PIPE "OK 1\n";
  1757. Xprint PIPE "ok 2\n";
  1758. Xclose PIPE;
  1759. X
  1760. Xif (open(PIPE, "-|")) {
  1761. X    while(<PIPE>) {
  1762. X    print;
  1763. X    }
  1764. X}
  1765. Xelse {
  1766. X    print STDOUT "ok 3\n";
  1767. X    exec 'echo', 'ok 4';
  1768. X}
  1769. !STUFFY!FUNK!
  1770. echo Extracting t/op.unshift
  1771. sed >t/op.unshift <<'!STUFFY!FUNK!' -e 's/X//'
  1772. X#!./perl
  1773. X
  1774. X# $Header: op.unshift,v 3.0 89/10/18 15:32:06 lwall Locked $
  1775. X
  1776. Xprint "1..2\n";
  1777. X
  1778. X@a = (1,2,3);
  1779. X$cnt1 = unshift(a,0);
  1780. X
  1781. Xif (join(' ',@a) eq '0 1 2 3') {print "ok 1\n";} else {print "not ok 1\n";}
  1782. X$cnt2 = unshift(a,3,2,1);
  1783. Xif (join(' ',@a) eq '3 2 1 0 1 2 3') {print "ok 2\n";} else {print "not ok 2\n";}
  1784. X
  1785. X
  1786. !STUFFY!FUNK!
  1787. echo Extracting t/op.oct
  1788. sed >t/op.oct <<'!STUFFY!FUNK!' -e 's/X//'
  1789. X#!./perl
  1790. X
  1791. X# $Header: op.oct,v 3.0 89/10/18 15:30:15 lwall Locked $
  1792. X
  1793. Xprint "1..3\n";
  1794. X
  1795. Xif (oct('01234') == 01234) {print "ok 1\n";} else {print "not ok 1\n";}
  1796. Xif (oct('0x1234') == 0x1234) {print "ok 2\n";} else {print "not ok 2\n";}
  1797. Xif (hex('01234') == 0x1234) {print "ok 3\n";} else {print "not ok 3\n";}
  1798. !STUFFY!FUNK!
  1799. echo Extracting t/op.ord
  1800. sed >t/op.ord <<'!STUFFY!FUNK!' -e 's/X//'
  1801. X#!./perl
  1802. X
  1803. X# $Header: op.ord,v 3.0 89/10/18 15:30:29 lwall Locked $
  1804. X
  1805. Xprint "1..2\n";
  1806. X
  1807. X# compile time evaluation
  1808. X
  1809. Xif (ord('A') == 65) {print "ok 1\n";} else {print "not ok 1\n";}
  1810. X
  1811. X# run time evaluation
  1812. X
  1813. X$x = 'ABC';
  1814. Xif (ord($x) == 65) {print "ok 2\n";} else {print "not ok 2\n";}
  1815. !STUFFY!FUNK!
  1816. echo Extracting t/op.fork
  1817. sed >t/op.fork <<'!STUFFY!FUNK!' -e 's/X//'
  1818. X#!./perl
  1819. X
  1820. X# $Header: op.fork,v 3.0 89/10/18 15:29:12 lwall Locked $
  1821. X
  1822. X$| = 1;
  1823. Xprint "1..2\n";
  1824. X
  1825. Xif ($cid = fork) {
  1826. X    sleep 2;
  1827. X    if ($result = (kill 9, $cid)) {print "ok 2\n";} else {print "not ok 2 $result\n";}
  1828. X}
  1829. Xelse {
  1830. X    $| = 1;
  1831. X    print "ok 1\n";
  1832. X    sleep 10;
  1833. X}
  1834. !STUFFY!FUNK!
  1835. echo Extracting t/base.if
  1836. sed >t/base.if <<'!STUFFY!FUNK!' -e 's/X//'
  1837. X#!./perl
  1838. X
  1839. X# $Header: base.if,v 3.0 89/10/18 15:24:17 lwall Locked $
  1840. X
  1841. Xprint "1..2\n";
  1842. X
  1843. X# first test to see if we can run the tests.
  1844. X
  1845. X$x = 'test';
  1846. Xif ($x eq $x) { print "ok 1\n"; } else { print "not ok 1\n";}
  1847. Xif ($x ne $x) { print "not ok 2\n"; } else { print "ok 2\n";}
  1848. !STUFFY!FUNK!
  1849. echo Extracting t/base.pat
  1850. sed >t/base.pat <<'!STUFFY!FUNK!' -e 's/X//'
  1851. X#!./perl
  1852. X
  1853. X# $Header: base.pat,v 3.0 89/10/18 15:24:30 lwall Locked $
  1854. X
  1855. Xprint "1..2\n";
  1856. X
  1857. X# first test to see if we can run the tests.
  1858. X
  1859. X$_ = 'test';
  1860. Xif (/^test/) { print "ok 1\n"; } else { print "not ok 1\n";}
  1861. Xif (/^foo/) { print "not ok 2\n"; } else { print "ok 2\n";}
  1862. !STUFFY!FUNK!
  1863. echo Extracting t/op.cond
  1864. sed >t/op.cond <<'!STUFFY!FUNK!' -e 's/X//'
  1865. X#!./perl
  1866. X
  1867. X# $Header: op.cond,v 3.0 89/10/18 15:28:26 lwall Locked $
  1868. X
  1869. Xprint "1..4\n";
  1870. X
  1871. Xprint 1 ? "ok 1\n" : "not ok 1\n";    # compile time
  1872. Xprint 0 ? "not ok 2\n" : "ok 2\n";
  1873. X
  1874. X$x = 1;
  1875. Xprint $x ? "ok 3\n" : "not ok 3\n";    # run time
  1876. Xprint !$x ? "not ok 4\n" : "ok 4\n";
  1877. !STUFFY!FUNK!
  1878. echo Extracting t/op.sprintf
  1879. sed >t/op.sprintf <<'!STUFFY!FUNK!' -e 's/X//'
  1880. X#!./perl
  1881. X
  1882. X# $Header: op.sprintf,v 3.0 89/10/18 15:31:28 lwall Locked $
  1883. X
  1884. Xprint "1..1\n";
  1885. X
  1886. X$x = sprintf("%3s %-4s%%foo %5d%c%3.1f","hi",123,456,65,3.0999);
  1887. Xif ($x eq ' hi 123 %foo   456A3.1') {print "ok 1\n";} else {print "not ok 1 '$x'\n";}
  1888. !STUFFY!FUNK!
  1889. echo Extracting eg/rename
  1890. sed >eg/rename <<'!STUFFY!FUNK!' -e 's/X//'
  1891. X#!/usr/bin/perl
  1892. X
  1893. X($op = shift) || die "Usage: rename perlexpr [filenames]\n";
  1894. Xif ($#ARGV < 0) {
  1895. X    @ARGV = <stdin>;
  1896. X    chop(@ARGV);
  1897. X}
  1898. Xfor (@ARGV) {
  1899. X    $was = $_;
  1900. X    eval $op;
  1901. X    die $@ if $@;
  1902. X    rename($was,$_) unless $was eq $_;
  1903. X}
  1904. !STUFFY!FUNK!
  1905. echo Extracting eg/ADB
  1906. sed >eg/ADB <<'!STUFFY!FUNK!' -e 's/X//'
  1907. X#!/usr/bin/perl
  1908. X
  1909. X# $Header: ADB,v 3.0 89/10/18 15:13:04 lwall Locked $
  1910. X
  1911. X# This script is only useful when used in your crash directory.
  1912. X
  1913. X$num = shift;
  1914. Xexec 'adb', '-k', "vmunix.$num", "vmcore.$num";
  1915. !STUFFY!FUNK!
  1916. echo Extracting eg/rmfrom
  1917. sed >eg/rmfrom <<'!STUFFY!FUNK!' -e 's/X//'
  1918. X#!/usr/bin/perl -n
  1919. X
  1920. X# $Header: rmfrom,v 3.0 89/10/18 15:15:20 lwall Locked $
  1921. X
  1922. X# A handy (but dangerous) script to put after a find ... -print.
  1923. X
  1924. Xchop; unlink;
  1925. !STUFFY!FUNK!
  1926. echo Extracting Wishlist
  1927. sed >Wishlist <<'!STUFFY!FUNK!' -e 's/X//'
  1928. Xctime to time support
  1929. Xbetter format pictures
  1930. Xpager?
  1931. Xbuilt-in cpp
  1932. Xperl to C translator
  1933. Xmulti-threading
  1934. !STUFFY!FUNK!
  1935. echo ""
  1936. echo "End of kit 24 (of 24)"
  1937. cat /dev/null >kit24isdone
  1938. run=''
  1939. config=''
  1940. for iskit in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24; do
  1941.     if test -f kit${iskit}isdone; then
  1942.     run="$run $iskit"
  1943.     else
  1944.     todo="$todo $iskit"
  1945.     fi
  1946. done
  1947. case $todo in
  1948.     '')
  1949.     echo "You have run all your kits.  Please read README and then type Configure."
  1950.     chmod 755 Configure
  1951.     ;;
  1952.     *)  echo "You have run$run."
  1953.     echo "You still need to run$todo."
  1954.     ;;
  1955. esac
  1956. : Someone might mail this, so...
  1957. exit
  1958.  
  1959.