home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume18 / perl / part31 < prev    next >
Internet Message Format  |  1991-04-17  |  51KB

  1. From: lwall@netlabs.com (Larry Wall)
  2. Newsgroups: comp.sources.misc
  3. Subject: v18i049:  perl - The perl programming language, Part31/36
  4. Message-ID: <1991Apr17.185846.2891@sparky.IMD.Sterling.COM>
  5. Date: 17 Apr 91 18:58:46 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Checksum-Snefru: 197883e2 db2142ff 6a702370 8691e194
  8.  
  9. Submitted-by: Larry Wall <lwall@netlabs.com>
  10. Posting-number: Volume 18, Issue 49
  11. Archive-name: perl/part31
  12.  
  13. [There are 36 kits for perl version 4.0.]
  14.  
  15. #! /bin/sh
  16.  
  17. # Make a new directory for the perl sources, cd to it, and run kits 1
  18. # thru 36 through sh.  When all 36 kits have been run, read README.
  19.  
  20. echo "This is perl 4.0 kit 31 (of 36).  If kit 31 is complete, the line"
  21. echo '"'"End of kit 31 (of 36)"'" will echo at the end.'
  22. echo ""
  23. export PATH || (echo "You didn't use sh, you clunch." ; kill $$)
  24. mkdir h2pl h2pl/eg h2pl/eg/sys lib os2 t t/lib t/op x2p 2>/dev/null
  25. echo Extracting x2p/hash.c
  26. sed >x2p/hash.c <<'!STUFFY!FUNK!' -e 's/X//'
  27. X/* $Header: hash.c,v 4.0 91/03/20 01:57:49 lwall Locked $
  28. X *
  29. X *    Copyright (c) 1989, Larry Wall
  30. X *
  31. X *    You may distribute under the terms of the GNU General Public License
  32. X *    as specified in the README file that comes with the perl 3.0 kit.
  33. X *
  34. X * $Log:    hash.c,v $
  35. X * Revision 4.0  91/03/20  01:57:49  lwall
  36. X * 4.0 baseline.
  37. X * 
  38. X */
  39. X
  40. X#include <stdio.h>
  41. X#include "EXTERN.h"
  42. X#include "handy.h"
  43. X#include "util.h"
  44. X#include "a2p.h"
  45. X
  46. XSTR *
  47. Xhfetch(tb,key)
  48. Xregister HASH *tb;
  49. Xchar *key;
  50. X{
  51. X    register char *s;
  52. X    register int i;
  53. X    register int hash;
  54. X    register HENT *entry;
  55. X
  56. X    if (!tb)
  57. X    return Nullstr;
  58. X    for (s=key,        i=0,    hash = 0;
  59. X      /* while */ *s;
  60. X     s++,        i++,    hash *= 5) {
  61. X    hash += *s * coeff[i];
  62. X    }
  63. X    entry = tb->tbl_array[hash & tb->tbl_max];
  64. X    for (; entry; entry = entry->hent_next) {
  65. X    if (entry->hent_hash != hash)        /* strings can't be equal */
  66. X        continue;
  67. X    if (strNE(entry->hent_key,key))    /* is this it? */
  68. X        continue;
  69. X    return entry->hent_val;
  70. X    }
  71. X    return Nullstr;
  72. X}
  73. X
  74. Xbool
  75. Xhstore(tb,key,val)
  76. Xregister HASH *tb;
  77. Xchar *key;
  78. XSTR *val;
  79. X{
  80. X    register char *s;
  81. X    register int i;
  82. X    register int hash;
  83. X    register HENT *entry;
  84. X    register HENT **oentry;
  85. X
  86. X    if (!tb)
  87. X    return FALSE;
  88. X    for (s=key,        i=0,    hash = 0;
  89. X      /* while */ *s;
  90. X     s++,        i++,    hash *= 5) {
  91. X    hash += *s * coeff[i];
  92. X    }
  93. X
  94. X    oentry = &(tb->tbl_array[hash & tb->tbl_max]);
  95. X    i = 1;
  96. X
  97. X    for (entry = *oentry; entry; i=0, entry = entry->hent_next) {
  98. X    if (entry->hent_hash != hash)        /* strings can't be equal */
  99. X        continue;
  100. X    if (strNE(entry->hent_key,key))    /* is this it? */
  101. X        continue;
  102. X    /*NOSTRICT*/
  103. X    safefree((char*)entry->hent_val);
  104. X    entry->hent_val = val;
  105. X    return TRUE;
  106. X    }
  107. X    /*NOSTRICT*/
  108. X    entry = (HENT*) safemalloc(sizeof(HENT));
  109. X
  110. X    entry->hent_key = savestr(key);
  111. X    entry->hent_val = val;
  112. X    entry->hent_hash = hash;
  113. X    entry->hent_next = *oentry;
  114. X    *oentry = entry;
  115. X
  116. X    if (i) {                /* initial entry? */
  117. X    tb->tbl_fill++;
  118. X    if ((tb->tbl_fill * 100 / (tb->tbl_max + 1)) > FILLPCT)
  119. X        hsplit(tb);
  120. X    }
  121. X
  122. X    return FALSE;
  123. X}
  124. X
  125. X#ifdef NOTUSED
  126. Xbool
  127. Xhdelete(tb,key)
  128. Xregister HASH *tb;
  129. Xchar *key;
  130. X{
  131. X    register char *s;
  132. X    register int i;
  133. X    register int hash;
  134. X    register HENT *entry;
  135. X    register HENT **oentry;
  136. X
  137. X    if (!tb)
  138. X    return FALSE;
  139. X    for (s=key,        i=0,    hash = 0;
  140. X      /* while */ *s;
  141. X     s++,        i++,    hash *= 5) {
  142. X    hash += *s * coeff[i];
  143. X    }
  144. X
  145. X    oentry = &(tb->tbl_array[hash & tb->tbl_max]);
  146. X    entry = *oentry;
  147. X    i = 1;
  148. X    for (; entry; i=0, oentry = &entry->hent_next, entry = entry->hent_next) {
  149. X    if (entry->hent_hash != hash)        /* strings can't be equal */
  150. X        continue;
  151. X    if (strNE(entry->hent_key,key))    /* is this it? */
  152. X        continue;
  153. X    safefree((char*)entry->hent_val);
  154. X    safefree(entry->hent_key);
  155. X    *oentry = entry->hent_next;
  156. X    safefree((char*)entry);
  157. X    if (i)
  158. X        tb->tbl_fill--;
  159. X    return TRUE;
  160. X    }
  161. X    return FALSE;
  162. X}
  163. X#endif
  164. X
  165. Xhsplit(tb)
  166. XHASH *tb;
  167. X{
  168. X    int oldsize = tb->tbl_max + 1;
  169. X    register int newsize = oldsize * 2;
  170. X    register int i;
  171. X    register HENT **a;
  172. X    register HENT **b;
  173. X    register HENT *entry;
  174. X    register HENT **oentry;
  175. X
  176. X    a = (HENT**) saferealloc((char*)tb->tbl_array, newsize * sizeof(HENT*));
  177. X    bzero((char*)&a[oldsize], oldsize * sizeof(HENT*)); /* zero second half */
  178. X    tb->tbl_max = --newsize;
  179. X    tb->tbl_array = a;
  180. X
  181. X    for (i=0; i<oldsize; i++,a++) {
  182. X    if (!*a)                /* non-existent */
  183. X        continue;
  184. X    b = a+oldsize;
  185. X    for (oentry = a, entry = *a; entry; entry = *oentry) {
  186. X        if ((entry->hent_hash & newsize) != i) {
  187. X        *oentry = entry->hent_next;
  188. X        entry->hent_next = *b;
  189. X        if (!*b)
  190. X            tb->tbl_fill++;
  191. X        *b = entry;
  192. X        continue;
  193. X        }
  194. X        else
  195. X        oentry = &entry->hent_next;
  196. X    }
  197. X    if (!*a)                /* everything moved */
  198. X        tb->tbl_fill--;
  199. X    }
  200. X}
  201. X
  202. XHASH *
  203. Xhnew()
  204. X{
  205. X    register HASH *tb = (HASH*)safemalloc(sizeof(HASH));
  206. X
  207. X    tb->tbl_array = (HENT**) safemalloc(8 * sizeof(HENT*));
  208. X    tb->tbl_fill = 0;
  209. X    tb->tbl_max = 7;
  210. X    hiterinit(tb);    /* so each() will start off right */
  211. X    bzero((char*)tb->tbl_array, 8 * sizeof(HENT*));
  212. X    return tb;
  213. X}
  214. X
  215. X#ifdef NOTUSED
  216. Xhshow(tb)
  217. Xregister HASH *tb;
  218. X{
  219. X    fprintf(stderr,"%5d %4d (%2d%%)\n",
  220. X    tb->tbl_max+1,
  221. X    tb->tbl_fill,
  222. X    tb->tbl_fill * 100 / (tb->tbl_max+1));
  223. X}
  224. X#endif
  225. X
  226. Xhiterinit(tb)
  227. Xregister HASH *tb;
  228. X{
  229. X    tb->tbl_riter = -1;
  230. X    tb->tbl_eiter = Null(HENT*);
  231. X    return tb->tbl_fill;
  232. X}
  233. X
  234. XHENT *
  235. Xhiternext(tb)
  236. Xregister HASH *tb;
  237. X{
  238. X    register HENT *entry;
  239. X
  240. X    entry = tb->tbl_eiter;
  241. X    do {
  242. X    if (entry)
  243. X        entry = entry->hent_next;
  244. X    if (!entry) {
  245. X        tb->tbl_riter++;
  246. X        if (tb->tbl_riter > tb->tbl_max) {
  247. X        tb->tbl_riter = -1;
  248. X        break;
  249. X        }
  250. X        entry = tb->tbl_array[tb->tbl_riter];
  251. X    }
  252. X    } while (!entry);
  253. X
  254. X    tb->tbl_eiter = entry;
  255. X    return entry;
  256. X}
  257. X
  258. Xchar *
  259. Xhiterkey(entry)
  260. Xregister HENT *entry;
  261. X{
  262. X    return entry->hent_key;
  263. X}
  264. X
  265. XSTR *
  266. Xhiterval(entry)
  267. Xregister HENT *entry;
  268. X{
  269. X    return entry->hent_val;
  270. X}
  271. !STUFFY!FUNK!
  272. echo Extracting str.h
  273. sed >str.h <<'!STUFFY!FUNK!' -e 's/X//'
  274. X/* $RCSfile: str.h,v $$Revision: 4.0.1.1 $$Date: 91/04/12 09:16:12 $
  275. X *
  276. X *    Copyright (c) 1989, Larry Wall
  277. X *
  278. X *    You may distribute under the terms of the GNU General Public License
  279. X *    as specified in the README file that comes with the perl 3.0 kit.
  280. X *
  281. X * $Log:    str.h,v $
  282. X * Revision 4.0.1.1  91/04/12  09:16:12  lwall
  283. X * patch1: you may now use "die" and "caller" in a signal handler
  284. X * 
  285. X * Revision 4.0  91/03/20  01:40:04  lwall
  286. X * 4.0 baseline.
  287. X * 
  288. X */
  289. X
  290. Xstruct string {
  291. X    char *    str_ptr;    /* pointer to malloced string */
  292. X    STRLEN    str_len;    /* allocated size */
  293. X    union {
  294. X    double    str_nval;    /* numeric value, if any */
  295. X    STAB    *str_stab;    /* magic stab for magic "key" string */
  296. X    long    str_useful;    /* is this search optimization effective? */
  297. X    ARG    *str_args;    /* list of args for interpreted string */
  298. X    HASH    *str_hash;    /* string represents an assoc array (stab?) */
  299. X    ARRAY    *str_array;    /* string represents an array */
  300. X    CMD    *str_cmd;    /* command for this source line */
  301. X    } str_u;
  302. X    STRLEN    str_cur;    /* length of str_ptr as a C string */
  303. X    STR        *str_magic;    /* while free, link to next free str */
  304. X                /* while in use, ptr to "key" for magic items */
  305. X    char    str_pok;    /* state of str_ptr */
  306. X    char    str_nok;    /* state of str_nval */
  307. X    unsigned char str_rare;    /* used by search strings */
  308. X    unsigned char str_state;    /* one of SS_* below */
  309. X                /* also used by search strings for backoff */
  310. X#ifdef TAINT
  311. X    bool    str_tainted;    /* 1 if possibly under control of $< */
  312. X#endif
  313. X};
  314. X
  315. Xstruct stab {    /* should be identical, except for str_ptr */
  316. X    STBP *    str_ptr;    /* pointer to malloced string */
  317. X    STRLEN    str_len;    /* allocated size */
  318. X    union {
  319. X    double    str_nval;    /* numeric value, if any */
  320. X    STAB    *str_stab;    /* magic stab for magic "key" string */
  321. X    long    str_useful;    /* is this search optimization effective? */
  322. X    ARG    *str_args;    /* list of args for interpreted string */
  323. X    HASH    *str_hash;    /* string represents an assoc array (stab?) */
  324. X    ARRAY    *str_array;    /* string represents an array */
  325. X    CMD    *str_cmd;    /* command for this source line */
  326. X    } str_u;
  327. X    STRLEN    str_cur;    /* length of str_ptr as a C string */
  328. X    STR        *str_magic;    /* while free, link to next free str */
  329. X                /* while in use, ptr to "key" for magic items */
  330. X    char    str_pok;    /* state of str_ptr */
  331. X    char    str_nok;    /* state of str_nval */
  332. X    unsigned char str_rare;    /* used by search strings */
  333. X    unsigned char str_state;    /* one of SS_* below */
  334. X                /* also used by search strings for backoff */
  335. X#ifdef TAINT
  336. X    bool    str_tainted;    /* 1 if possibly under control of $< */
  337. X#endif
  338. X};
  339. X
  340. X/* some extra info tacked to some lvalue strings */
  341. X
  342. Xstruct lstring {
  343. X    struct string lstr;
  344. X    STRLEN    lstr_offset;
  345. X    STRLEN    lstr_len;
  346. X};
  347. X
  348. X/* These are the values of str_pok:        */
  349. X#define SP_VALID    1    /* str_ptr is valid */
  350. X#define SP_FBM        2    /* string was compiled for fbm search */
  351. X#define SP_STUDIED    4    /* string was studied */
  352. X#define SP_CASEFOLD    8    /* case insensitive fbm search */
  353. X#define SP_INTRP    16    /* string was compiled for interping */
  354. X#define SP_TAIL        32    /* fbm string is tail anchored: /foo$/  */
  355. X#define SP_MULTI    64    /* symbol table entry probably isn't a typo */
  356. X#define SP_TEMP        128    /* string slated to die, so can be plundered */
  357. X
  358. X#define Nullstr Null(STR*)
  359. X
  360. X/* These are the values of str_state:        */
  361. X#define SS_NORM        0    /* normal string */
  362. X#define SS_INCR        1    /* normal string, incremented ptr */
  363. X#define SS_SARY        2    /* array on save stack */
  364. X#define SS_SHASH    3    /* associative array on save stack */
  365. X#define SS_SINT        4    /* integer on save stack */
  366. X#define SS_SLONG    5    /* long on save stack */
  367. X#define SS_SSTRP    6    /* STR* on save stack */
  368. X#define SS_SHPTR    7    /* HASH* on save stack */
  369. X#define SS_SNSTAB    8    /* non-stab on save stack */
  370. X#define SS_SCSV        9    /* callsave structure on save stack */
  371. X#define SS_SAPTR    10    /* ARRAY* on save stack */
  372. X#define SS_HASH        253    /* carrying an hash */
  373. X#define SS_ARY        254    /* carrying an array */
  374. X#define SS_FREE        255    /* in free list */
  375. X/* str_state may have any value 0-255 when used to hold fbm pattern, in which */
  376. X/* case it indicates offset to rarest character in screaminstr key */
  377. X
  378. X/* the following macro updates any magic values this str is associated with */
  379. X
  380. X#ifdef TAINT
  381. X#define STABSET(x) \
  382. X    (x)->str_tainted |= tainted; \
  383. X    if ((x)->str_magic) \
  384. X    stabset((x)->str_magic,(x))
  385. X#else
  386. X#define STABSET(x) \
  387. X    if ((x)->str_magic) \
  388. X    stabset((x)->str_magic,(x))
  389. X#endif
  390. X
  391. X#define STR_SSET(dst,src) if (dst != src) str_sset(dst,src)
  392. X
  393. XEXT STR **tmps_list;
  394. XEXT int tmps_max INIT(-1);
  395. XEXT int tmps_base INIT(-1);
  396. X
  397. Xchar *str_2ptr();
  398. Xdouble str_2num();
  399. XSTR *str_mortal();
  400. XSTR *str_2mortal();
  401. XSTR *str_make();
  402. XSTR *str_nmake();
  403. XSTR *str_smake();
  404. Xint str_cmp();
  405. Xint str_eq();
  406. Xvoid str_magic();
  407. Xvoid str_insert();
  408. XSTRLEN str_len();
  409. !STUFFY!FUNK!
  410. echo Extracting cmd.h
  411. sed >cmd.h <<'!STUFFY!FUNK!' -e 's/X//'
  412. X/* $Header: cmd.h,v 4.0 91/03/20 01:04:34 lwall Locked $
  413. X *
  414. X *    Copyright (c) 1989, Larry Wall
  415. X *
  416. X *    You may distribute under the terms of the GNU General Public License
  417. X *    as specified in the README file that comes with the perl 3.0 kit.
  418. X *
  419. X * $Log:    cmd.h,v $
  420. X * Revision 4.0  91/03/20  01:04:34  lwall
  421. X * 4.0 baseline.
  422. X * 
  423. X */
  424. X
  425. X#define C_NULL 0
  426. X#define C_IF 1
  427. X#define C_ELSE 2
  428. X#define C_WHILE 3
  429. X#define C_BLOCK 4
  430. X#define C_EXPR 5
  431. X#define C_NEXT 6
  432. X#define C_ELSIF 7    /* temporary--turns into an IF + ELSE */
  433. X#define C_CSWITCH 8    /* created by switch optimization in block_head() */
  434. X#define C_NSWITCH 9    /* likewise */
  435. X
  436. X#ifdef DEBUGGING
  437. X#ifndef DOINIT
  438. Xextern char *cmdname[];
  439. X#else
  440. Xchar *cmdname[] = {
  441. X    "NULL",
  442. X    "IF",
  443. X    "ELSE",
  444. X    "WHILE",
  445. X    "BLOCK",
  446. X    "EXPR",
  447. X    "NEXT",
  448. X    "ELSIF",
  449. X    "CSWITCH",
  450. X    "NSWITCH",
  451. X    "10"
  452. X};
  453. X#endif
  454. X#endif /* DEBUGGING */
  455. X
  456. X#define CF_OPTIMIZE 077    /* type of optimization */
  457. X#define CF_FIRSTNEG 0100/* conditional is ($register NE 'string') */
  458. X#define CF_NESURE 0200    /* if short doesn't match we're sure */
  459. X#define CF_EQSURE 0400    /* if short does match we're sure */
  460. X#define CF_COND    01000    /* test c_expr as conditional first, if not null. */
  461. X            /* Set for everything except do {} while currently */
  462. X#define CF_LOOP 02000    /* loop on the c_expr conditional (loop modifiers) */
  463. X#define CF_INVERT 04000    /* it's an "unless" or an "until" */
  464. X#define CF_ONCE 010000    /* we've already pushed the label on the stack */
  465. X#define CF_FLIP 020000    /* on a match do flipflop */
  466. X#define CF_TERM 040000    /* value of this cmd might be returned */
  467. X#define CF_DBSUB 0100000 /* this is an inserted cmd for debugging */
  468. X
  469. X#define CFT_FALSE 0    /* c_expr is always false */
  470. X#define CFT_TRUE 1    /* c_expr is always true */
  471. X#define CFT_REG 2    /* c_expr is a simple register */
  472. X#define CFT_ANCHOR 3    /* c_expr is an anchored search /^.../ */
  473. X#define CFT_STROP 4    /* c_expr is a string comparison */
  474. X#define CFT_SCAN 5    /* c_expr is an unanchored search /.../ */
  475. X#define CFT_GETS 6    /* c_expr is <filehandle> */
  476. X#define CFT_EVAL 7    /* c_expr is not optimized, so call eval() */
  477. X#define CFT_UNFLIP 8    /* 2nd half of range not optimized */
  478. X#define CFT_CHOP 9    /* c_expr is a chop on a register */
  479. X#define CFT_ARRAY 10    /* this is a foreach loop */
  480. X#define CFT_INDGETS 11    /* c_expr is <$variable> */
  481. X#define CFT_NUMOP 12    /* c_expr is a numeric comparison */
  482. X#define CFT_CCLASS 13    /* c_expr must start with one of these characters */
  483. X#define CFT_D0 14    /* no special breakpoint at this line */
  484. X#define CFT_D1 15    /* possible special breakpoint at this line */
  485. X
  486. X#ifdef DEBUGGING
  487. X#ifndef DOINIT
  488. Xextern char *cmdopt[];
  489. X#else
  490. Xchar *cmdopt[] = {
  491. X    "FALSE",
  492. X    "TRUE",
  493. X    "REG",
  494. X    "ANCHOR",
  495. X    "STROP",
  496. X    "SCAN",
  497. X    "GETS",
  498. X    "EVAL",
  499. X    "UNFLIP",
  500. X    "CHOP",
  501. X    "ARRAY",
  502. X    "INDGETS",
  503. X    "NUMOP",
  504. X    "CCLASS",
  505. X    "14"
  506. X};
  507. X#endif
  508. X#endif /* DEBUGGING */
  509. X
  510. Xstruct acmd {
  511. X    STAB    *ac_stab;    /* a symbol table entry */
  512. X    ARG        *ac_expr;    /* any associated expression */
  513. X};
  514. X
  515. Xstruct ccmd {
  516. X    CMD        *cc_true;    /* normal code to do on if and while */
  517. X    CMD        *cc_alt;    /* else cmd ptr or continue code */
  518. X};
  519. X
  520. Xstruct scmd {
  521. X    CMD        **sc_next;    /* array of pointers to commands */
  522. X    short    sc_offset;    /* first value - 1 */
  523. X    short    sc_max;        /* last value + 1 */
  524. X};
  525. X
  526. Xstruct cmd {
  527. X    CMD        *c_next;    /* the next command at this level */
  528. X    ARG        *c_expr;    /* conditional expression */
  529. X    CMD        *c_head;    /* head of this command list */
  530. X    STR        *c_short;    /* string to match as shortcut */
  531. X    STAB    *c_stab;    /* a symbol table entry, mostly for fp */
  532. X    SPAT    *c_spat;    /* pattern used by optimization */
  533. X    char    *c_label;    /* label for this construct */
  534. X    union ucmd {
  535. X    struct acmd acmd;    /* normal command */
  536. X    struct ccmd ccmd;    /* compound command */
  537. X    struct scmd scmd;    /* switch command */
  538. X    } ucmd;
  539. X    short    c_slen;        /* len of c_short, if not null */
  540. X    VOLATILE short c_flags;    /* optimization flags--see above */
  541. X    HASH    *c_stash;    /* package line was compiled in */
  542. X    STAB    *c_filestab;    /* file the following line # is from */
  543. X    line_t      c_line;         /* line # of this command */
  544. X    char    c_type;        /* what this command does */
  545. X};
  546. X
  547. X#define Nullcmd Null(CMD*)
  548. X#define Nullcsv Null(CSV*)
  549. X
  550. XEXT CMD * VOLATILE main_root INIT(Nullcmd);
  551. XEXT CMD * VOLATILE eval_root INIT(Nullcmd);
  552. X
  553. XEXT CMD compiling;
  554. XEXT CMD * VOLATILE curcmd INIT(&compiling);
  555. XEXT CSV * VOLATILE curcsv INIT(Nullcsv);
  556. X
  557. Xstruct callsave {
  558. X    SUBR *sub;
  559. X    STAB *stab;
  560. X    CSV *curcsv;
  561. X    CMD *curcmd;
  562. X    ARRAY *savearray;
  563. X    ARRAY *argarray;
  564. X    long depth;
  565. X    int wantarray;
  566. X    char hasargs;
  567. X};
  568. X
  569. Xstruct compcmd {
  570. X    CMD *comp_true;
  571. X    CMD *comp_alt;
  572. X};
  573. X
  574. Xvoid opt_arg();
  575. Xvoid evalstatic();
  576. Xint cmd_exec();
  577. !STUFFY!FUNK!
  578. echo Extracting t/op/s.t
  579. sed >t/op/s.t <<'!STUFFY!FUNK!' -e 's/X//'
  580. X#!./perl
  581. X
  582. X# $Header: s.t,v 4.0 91/03/20 01:54:30 lwall Locked $
  583. X
  584. Xprint "1..51\n";
  585. X
  586. X$x = 'foo';
  587. X$_ = "x";
  588. Xs/x/\$x/;
  589. Xprint "#1\t:$_: eq :\$x:\n";
  590. Xif ($_ eq '$x') {print "ok 1\n";} else {print "not ok 1\n";}
  591. X
  592. X$_ = "x";
  593. Xs/x/$x/;
  594. Xprint "#2\t:$_: eq :foo:\n";
  595. Xif ($_ eq 'foo') {print "ok 2\n";} else {print "not ok 2\n";}
  596. X
  597. X$_ = "x";
  598. Xs/x/\$x $x/;
  599. Xprint "#3\t:$_: eq :\$x foo:\n";
  600. Xif ($_ eq '$x foo') {print "ok 3\n";} else {print "not ok 3\n";}
  601. X
  602. X$b = 'cd';
  603. X($a = 'abcdef') =~ s'(b${b}e)'\n$1';
  604. Xprint "#4\t:$1: eq :bcde:\n";
  605. Xprint "#4\t:$a: eq :a\\n\$1f:\n";
  606. Xif ($1 eq 'bcde' && $a eq 'a\n$1f') {print "ok 4\n";} else {print "not ok 4\n";}
  607. X
  608. X$a = 'abacada';
  609. Xif (($a =~ s/a/x/g) == 4 && $a eq 'xbxcxdx')
  610. X    {print "ok 5\n";} else {print "not ok 5\n";}
  611. X
  612. Xif (($a =~ s/a/y/g) == 0 && $a eq 'xbxcxdx')
  613. X    {print "ok 6\n";} else {print "not ok 6 $a\n";}
  614. X
  615. Xif (($a =~ s/b/y/g) == 1 && $a eq 'xyxcxdx')
  616. X    {print "ok 7\n";} else {print "not ok 7 $a\n";}
  617. X
  618. X$_ = 'ABACADA';
  619. Xif (/a/i && s///gi && $_ eq 'BCD') {print "ok 8\n";} else {print "not ok 8 $_\n";}
  620. X
  621. X$_ = '\\' x 4;
  622. Xif (length($_) == 4) {print "ok 9\n";} else {print "not ok 9\n";}
  623. Xs/\\/\\\\/g;
  624. Xif ($_ eq '\\' x 8) {print "ok 10\n";} else {print "not ok 10 $_\n";}
  625. X
  626. X$_ = '\/' x 4;
  627. Xif (length($_) == 8) {print "ok 11\n";} else {print "not ok 11\n";}
  628. Xs/\//\/\//g;
  629. Xif ($_ eq '\\//' x 4) {print "ok 12\n";} else {print "not ok 12\n";}
  630. Xif (length($_) == 12) {print "ok 13\n";} else {print "not ok 13\n";}
  631. X
  632. X$_ = 'aaaXXXXbbb';
  633. Xs/^a//;
  634. Xprint $_ eq 'aaXXXXbbb' ? "ok 14\n" : "not ok 14\n";
  635. X
  636. X$_ = 'aaaXXXXbbb';
  637. Xs/a//;
  638. Xprint $_ eq 'aaXXXXbbb' ? "ok 15\n" : "not ok 15\n";
  639. X
  640. X$_ = 'aaaXXXXbbb';
  641. Xs/^a/b/;
  642. Xprint $_ eq 'baaXXXXbbb' ? "ok 16\n" : "not ok 16\n";
  643. X
  644. X$_ = 'aaaXXXXbbb';
  645. Xs/a/b/;
  646. Xprint $_ eq 'baaXXXXbbb' ? "ok 17\n" : "not ok 17\n";
  647. X
  648. X$_ = 'aaaXXXXbbb';
  649. Xs/aa//;
  650. Xprint $_ eq 'aXXXXbbb' ? "ok 18\n" : "not ok 18\n";
  651. X
  652. X$_ = 'aaaXXXXbbb';
  653. Xs/aa/b/;
  654. Xprint $_ eq 'baXXXXbbb' ? "ok 19\n" : "not ok 19\n";
  655. X
  656. X$_ = 'aaaXXXXbbb';
  657. Xs/b$//;
  658. Xprint $_ eq 'aaaXXXXbb' ? "ok 20\n" : "not ok 20\n";
  659. X
  660. X$_ = 'aaaXXXXbbb';
  661. Xs/b//;
  662. Xprint $_ eq 'aaaXXXXbb' ? "ok 21\n" : "not ok 21\n";
  663. X
  664. X$_ = 'aaaXXXXbbb';
  665. Xs/bb//;
  666. Xprint $_ eq 'aaaXXXXb' ? "ok 22\n" : "not ok 22\n";
  667. X
  668. X$_ = 'aaaXXXXbbb';
  669. Xs/aX/y/;
  670. Xprint $_ eq 'aayXXXbbb' ? "ok 23\n" : "not ok 23\n";
  671. X
  672. X$_ = 'aaaXXXXbbb';
  673. Xs/Xb/z/;
  674. Xprint $_ eq 'aaaXXXzbb' ? "ok 24\n" : "not ok 24\n";
  675. X
  676. X$_ = 'aaaXXXXbbb';
  677. Xs/aaX.*Xbb//;
  678. Xprint $_ eq 'ab' ? "ok 25\n" : "not ok 25\n";
  679. X
  680. X$_ = 'aaaXXXXbbb';
  681. Xs/bb/x/;
  682. Xprint $_ eq 'aaaXXXXxb' ? "ok 26\n" : "not ok 26\n";
  683. X
  684. X# now for some unoptimized versions of the same.
  685. X
  686. X$_ = 'aaaXXXXbbb';
  687. X$x ne $x || s/^a//;
  688. Xprint $_ eq 'aaXXXXbbb' ? "ok 27\n" : "not ok 27\n";
  689. X
  690. X$_ = 'aaaXXXXbbb';
  691. X$x ne $x || s/a//;
  692. Xprint $_ eq 'aaXXXXbbb' ? "ok 28\n" : "not ok 28\n";
  693. X
  694. X$_ = 'aaaXXXXbbb';
  695. X$x ne $x || s/^a/b/;
  696. Xprint $_ eq 'baaXXXXbbb' ? "ok 29\n" : "not ok 29\n";
  697. X
  698. X$_ = 'aaaXXXXbbb';
  699. X$x ne $x || s/a/b/;
  700. Xprint $_ eq 'baaXXXXbbb' ? "ok 30\n" : "not ok 30\n";
  701. X
  702. X$_ = 'aaaXXXXbbb';
  703. X$x ne $x || s/aa//;
  704. Xprint $_ eq 'aXXXXbbb' ? "ok 31\n" : "not ok 31\n";
  705. X
  706. X$_ = 'aaaXXXXbbb';
  707. X$x ne $x || s/aa/b/;
  708. Xprint $_ eq 'baXXXXbbb' ? "ok 32\n" : "not ok 32\n";
  709. X
  710. X$_ = 'aaaXXXXbbb';
  711. X$x ne $x || s/b$//;
  712. Xprint $_ eq 'aaaXXXXbb' ? "ok 33\n" : "not ok 33\n";
  713. X
  714. X$_ = 'aaaXXXXbbb';
  715. X$x ne $x || s/b//;
  716. Xprint $_ eq 'aaaXXXXbb' ? "ok 34\n" : "not ok 34\n";
  717. X
  718. X$_ = 'aaaXXXXbbb';
  719. X$x ne $x || s/bb//;
  720. Xprint $_ eq 'aaaXXXXb' ? "ok 35\n" : "not ok 35\n";
  721. X
  722. X$_ = 'aaaXXXXbbb';
  723. X$x ne $x || s/aX/y/;
  724. Xprint $_ eq 'aayXXXbbb' ? "ok 36\n" : "not ok 36\n";
  725. X
  726. X$_ = 'aaaXXXXbbb';
  727. X$x ne $x || s/Xb/z/;
  728. Xprint $_ eq 'aaaXXXzbb' ? "ok 37\n" : "not ok 37\n";
  729. X
  730. X$_ = 'aaaXXXXbbb';
  731. X$x ne $x || s/aaX.*Xbb//;
  732. Xprint $_ eq 'ab' ? "ok 38\n" : "not ok 38\n";
  733. X
  734. X$_ = 'aaaXXXXbbb';
  735. X$x ne $x || s/bb/x/;
  736. Xprint $_ eq 'aaaXXXXxb' ? "ok 39\n" : "not ok 39\n";
  737. X
  738. X$_ = 'abc123xyz';
  739. Xs/\d+/$&*2/e;              # yields 'abc246xyz'
  740. Xprint $_ eq 'abc246xyz' ? "ok 40\n" : "not ok 40\n";
  741. Xs/\d+/sprintf("%5d",$&)/e; # yields 'abc  246xyz'
  742. Xprint $_ eq 'abc  246xyz' ? "ok 41\n" : "not ok 41\n";
  743. Xs/\w/$& x 2/eg;            # yields 'aabbcc  224466xxyyzz'
  744. Xprint $_ eq 'aabbcc  224466xxyyzz' ? "ok 42\n" : "not ok 42\n";
  745. X
  746. X$_ = "aaaaa";
  747. Xprint y/a/b/ == 5 ? "ok 43\n" : "not ok 43\n";
  748. Xprint y/a/b/ == 0 ? "ok 44\n" : "not ok 44\n";
  749. Xprint y/b// == 5 ? "ok 45\n" : "not ok 45\n";
  750. Xprint y/b/c/s == 5 ? "ok 46\n" : "not ok 46\n";
  751. Xprint y/c// == 1 ? "ok 47\n" : "not ok 47\n";
  752. Xprint y/c//d == 1 ? "ok 48\n" : "not ok 48\n";
  753. Xprint $_ eq "" ? "ok 49\n" : "not ok 49\n";
  754. X
  755. X$_ = "Now is the %#*! time for all good men...";
  756. Xprint (($x=(y/a-zA-Z //cd)) == 7 ? "ok 50\n" : "not ok 50\n");
  757. Xprint y/ / /s == 8 ? "ok 51\n" : "not ok 51\n";
  758. X
  759. !STUFFY!FUNK!
  760. echo Extracting t/lib/big.t
  761. sed >t/lib/big.t <<'!STUFFY!FUNK!' -e 's/X//'
  762. X#!./perl
  763. Xrequire "../lib/bigint.pl";
  764. X
  765. X$test = 0;
  766. X$| = 1;
  767. Xprint "1..246\n";
  768. Xwhile (<DATA>) {
  769. X    chop;
  770. X    if (/^&/) {
  771. X        $f = $_;
  772. X    } else {
  773. X        ++$test;
  774. X        @args = split(/:/,$_,99);
  775. X        $ans = pop(@args);
  776. X        $try = "$f('" . join("','", @args) . "');";
  777. X        if (($ans1 = eval($try)) eq $ans) {
  778. X            print "ok $test\n";
  779. X        } else {
  780. X            print "not ok $test\n";
  781. X            print "# '$try' expected: '$ans' got: '$ans1'\n";
  782. X        }
  783. X    }
  784. X} 
  785. X__END__
  786. X&bnorm
  787. Xabc:NaN
  788. X   1 a:NaN
  789. X1bcd2:NaN
  790. X11111b:NaN
  791. X+1z:NaN
  792. X-1z:NaN
  793. X0:+0
  794. X+0:+0
  795. X+00:+0
  796. X+0 0 0:+0
  797. X000000  0000000   00000:+0
  798. X-0:+0
  799. X-0000:+0
  800. X+1:+1
  801. X+01:+1
  802. X+001:+1
  803. X+00000100000:+100000
  804. X123456789:+123456789
  805. X-1:-1
  806. X-01:-1
  807. X-001:-1
  808. X-123456789:-123456789
  809. X-00000100000:-100000
  810. X&bneg
  811. Xabd:NaN
  812. X+0:+0
  813. X+1:-1
  814. X-1:+1
  815. X+123456789:-123456789
  816. X-123456789:+123456789
  817. X&babs
  818. Xabc:NaN
  819. X+0:+0
  820. X+1:+1
  821. X-1:+1
  822. X+123456789:+123456789
  823. X-123456789:+123456789
  824. X&bcmp
  825. Xabc:abc:
  826. Xabc:+0:
  827. X+0:abc:
  828. X+0:+0:0
  829. X-1:+0:-1
  830. X+0:-1:1
  831. X+1:+0:1
  832. X+0:+1:-1
  833. X-1:+1:-1
  834. X+1:-1:1
  835. X-1:-1:0
  836. X+1:+1:0
  837. X+123:+123:0
  838. X+123:+12:1
  839. X+12:+123:-1
  840. X-123:-123:0
  841. X-123:-12:-1
  842. X-12:-123:1
  843. X+123:+124:-1
  844. X+124:+123:1
  845. X-123:-124:1
  846. X-124:-123:-1
  847. X&badd
  848. Xabc:abc:NaN
  849. Xabc:+0:NaN
  850. X+0:abc:NaN
  851. X+0:+0:+0
  852. X+1:+0:+1
  853. X+0:+1:+1
  854. X+1:+1:+2
  855. X-1:+0:-1
  856. X+0:-1:-1
  857. X-1:-1:-2
  858. X-1:+1:+0
  859. X+1:-1:+0
  860. X+9:+1:+10
  861. X+99:+1:+100
  862. X+999:+1:+1000
  863. X+9999:+1:+10000
  864. X+99999:+1:+100000
  865. X+999999:+1:+1000000
  866. X+9999999:+1:+10000000
  867. X+99999999:+1:+100000000
  868. X+999999999:+1:+1000000000
  869. X+9999999999:+1:+10000000000
  870. X+99999999999:+1:+100000000000
  871. X+10:-1:+9
  872. X+100:-1:+99
  873. X+1000:-1:+999
  874. X+10000:-1:+9999
  875. X+100000:-1:+99999
  876. X+1000000:-1:+999999
  877. X+10000000:-1:+9999999
  878. X+100000000:-1:+99999999
  879. X+1000000000:-1:+999999999
  880. X+10000000000:-1:+9999999999
  881. X+123456789:+987654321:+1111111110
  882. X-123456789:+987654321:+864197532
  883. X-123456789:-987654321:-1111111110
  884. X+123456789:-987654321:-864197532
  885. X&bsub
  886. Xabc:abc:NaN
  887. Xabc:+0:NaN
  888. X+0:abc:NaN
  889. X+0:+0:+0
  890. X+1:+0:+1
  891. X+0:+1:-1
  892. X+1:+1:+0
  893. X-1:+0:-1
  894. X+0:-1:+1
  895. X-1:-1:+0
  896. X-1:+1:-2
  897. X+1:-1:+2
  898. X+9:+1:+8
  899. X+99:+1:+98
  900. X+999:+1:+998
  901. X+9999:+1:+9998
  902. X+99999:+1:+99998
  903. X+999999:+1:+999998
  904. X+9999999:+1:+9999998
  905. X+99999999:+1:+99999998
  906. X+999999999:+1:+999999998
  907. X+9999999999:+1:+9999999998
  908. X+99999999999:+1:+99999999998
  909. X+10:-1:+11
  910. X+100:-1:+101
  911. X+1000:-1:+1001
  912. X+10000:-1:+10001
  913. X+100000:-1:+100001
  914. X+1000000:-1:+1000001
  915. X+10000000:-1:+10000001
  916. X+100000000:-1:+100000001
  917. X+1000000000:-1:+1000000001
  918. X+10000000000:-1:+10000000001
  919. X+123456789:+987654321:-864197532
  920. X-123456789:+987654321:-1111111110
  921. X-123456789:-987654321:+864197532
  922. X+123456789:-987654321:+1111111110
  923. X&bmul
  924. Xabc:abc:NaN
  925. Xabc:+0:NaN
  926. X+0:abc:NaN
  927. X+0:+0:+0
  928. X+0:+1:+0
  929. X+1:+0:+0
  930. X+0:-1:+0
  931. X-1:+0:+0
  932. X+123456789123456789:+0:+0
  933. X+0:+123456789123456789:+0
  934. X-1:-1:+1
  935. X-1:+1:-1
  936. X+1:-1:-1
  937. X+1:+1:+1
  938. X+2:+3:+6
  939. X-2:+3:-6
  940. X+2:-3:-6
  941. X-2:-3:+6
  942. X+111:+111:+12321
  943. X+10101:+10101:+102030201
  944. X+1001001:+1001001:+1002003002001
  945. X+100010001:+100010001:+10002000300020001
  946. X+10000100001:+10000100001:+100002000030000200001
  947. X+11111111111:+9:+99999999999
  948. X+22222222222:+9:+199999999998
  949. X+33333333333:+9:+299999999997
  950. X+44444444444:+9:+399999999996
  951. X+55555555555:+9:+499999999995
  952. X+66666666666:+9:+599999999994
  953. X+77777777777:+9:+699999999993
  954. X+88888888888:+9:+799999999992
  955. X+99999999999:+9:+899999999991
  956. X&bdiv
  957. Xabc:abc:NaN
  958. Xabc:+1:abc:NaN
  959. X+1:abc:NaN
  960. X+0:+0:NaN
  961. X+0:+1:+0
  962. X+1:+0:NaN
  963. X+0:-1:+0
  964. X-1:+0:NaN
  965. X+1:+1:+1
  966. X-1:-1:+1
  967. X+1:-1:-1
  968. X-1:+1:-1
  969. X+1:+2:+0
  970. X+2:+1:+2
  971. X+1000000000:+9:+111111111
  972. X+2000000000:+9:+222222222
  973. X+3000000000:+9:+333333333
  974. X+4000000000:+9:+444444444
  975. X+5000000000:+9:+555555555
  976. X+6000000000:+9:+666666666
  977. X+7000000000:+9:+777777777
  978. X+8000000000:+9:+888888888
  979. X+9000000000:+9:+1000000000
  980. X+35500000:+113:+314159
  981. X+71000000:+226:+314159
  982. X+106500000:+339:+314159
  983. X+1000000000:+3:+333333333
  984. X+10:+5:+2
  985. X+100:+4:+25
  986. X+1000:+8:+125
  987. X+10000:+16:+625
  988. X+999999999999:+9:+111111111111
  989. X+999999999999:+99:+10101010101
  990. X+999999999999:+999:+1001001001
  991. X+999999999999:+9999:+100010001
  992. X+999999999999999:+99999:+10000100001
  993. X&bmod
  994. Xabc:abc:NaN
  995. Xabc:+1:abc:NaN
  996. X+1:abc:NaN
  997. X+0:+0:NaN
  998. X+0:+1:+0
  999. X+1:+0:NaN
  1000. X+0:-1:+0
  1001. X-1:+0:NaN
  1002. X+1:+1:+0
  1003. X-1:-1:+0
  1004. X+1:-1:+0
  1005. X-1:+1:+0
  1006. X+1:+2:+1
  1007. X+2:+1:+0
  1008. X+1000000000:+9:+1
  1009. X+2000000000:+9:+2
  1010. X+3000000000:+9:+3
  1011. X+4000000000:+9:+4
  1012. X+5000000000:+9:+5
  1013. X+6000000000:+9:+6
  1014. X+7000000000:+9:+7
  1015. X+8000000000:+9:+8
  1016. X+9000000000:+9:+0
  1017. X+35500000:+113:+33
  1018. X+71000000:+226:+66
  1019. X+106500000:+339:+99
  1020. X+1000000000:+3:+1
  1021. X+10:+5:+0
  1022. X+100:+4:+0
  1023. X+1000:+8:+0
  1024. X+10000:+16:+0
  1025. X+999999999999:+9:+0
  1026. X+999999999999:+99:+0
  1027. X+999999999999:+999:+0
  1028. X+999999999999:+9999:+0
  1029. X+999999999999999:+99999:+0
  1030. X&bgcd
  1031. Xabc:abc:NaN
  1032. Xabc:+0:NaN
  1033. X+0:abc:NaN
  1034. X+0:+0:+0
  1035. X+0:+1:+1
  1036. X+1:+0:+1
  1037. X+1:+1:+1
  1038. X+2:+3:+1
  1039. X+3:+2:+1
  1040. X+100:+625:+25
  1041. X+4096:+81:+1
  1042. !STUFFY!FUNK!
  1043. echo Extracting installperl
  1044. sed >installperl <<'!STUFFY!FUNK!' -e 's/X//'
  1045. X#!./perl
  1046. X
  1047. Xwhile (@ARGV) {
  1048. X    $nonono = 1 if $ARGV[0] eq '-n';
  1049. X    $versiononly = 1 if $ARGV[0] eq '-v';
  1050. X    shift;
  1051. X}
  1052. X
  1053. X@scripts = 'h2ph';
  1054. X@manpages = ('perl.man', 'h2ph.man');
  1055. X
  1056. X$version = sprintf("%5.3f", $]);
  1057. X$release = substr($version,0,3);
  1058. X$patchlevel = substr($version,3,2);
  1059. X
  1060. X# Read in the config file.
  1061. X
  1062. Xopen(CONFIG, "config.sh") || die "You haven't run Configure yet!\n";
  1063. Xwhile (<CONFIG>) {
  1064. X    if (s/^(\w+=)/\$$1/) {
  1065. X    $accum =~ s/'undef'/undef/g;
  1066. X    eval $accum;
  1067. X    $accum = '';
  1068. X    }
  1069. X    $accum .= $_;
  1070. X}
  1071. X
  1072. X# Do some quick sanity checks.
  1073. X
  1074. Xif ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; }
  1075. X
  1076. X   $installbin        || die "No installbin directory in config.sh\n";
  1077. X-d $installbin        || die "$installbin is not a directory\n";
  1078. X-w $installbin        || die "$installbin is not writable by you\n"
  1079. X    unless $installbin =~ m#^/afs/#;
  1080. X
  1081. X-x 'perl'        || die "perl isn't executable!\n";
  1082. X-x 'taintperl'        || die "taintperl isn't executable!\n";
  1083. X-x 'suidperl'        || die "suidperl isn't executable!\n" if $d_dosuid;
  1084. X
  1085. X-x 't/TEST'        || warn "WARNING: You've never run 'make test'!!!",
  1086. X    "  (Installing anyway.)\n";
  1087. X
  1088. X# First we install the version-numbered executables.
  1089. X
  1090. X$ver = sprintf("%5.3f", $]);
  1091. X
  1092. X&unlink("$installbin/perl$ver");
  1093. X&cmd("cp perl $installbin/perl$ver");
  1094. X
  1095. X&unlink("$installbin/tperl$ver");
  1096. X&cmd("cp taintperl $installbin/tperl$ver");
  1097. X&chmod(0755, "$installbin/tperl$ver");        # force non-suid for security
  1098. X
  1099. X&unlink("$installbin/sperl$ver");
  1100. Xif ($d_dosuid) {
  1101. X    &cmd("cp suidperl $installbin/sperl$ver");
  1102. X    &chmod(04711, "$installbin/sperl$ver");
  1103. X}
  1104. X
  1105. Xexit 0 if $versiononly;
  1106. X
  1107. X# Make links to ordinary names if installbin directory isn't current directory.
  1108. X
  1109. X($bdev,$bino) = stat($installbin);
  1110. X($ddev,$dino) = stat('.');
  1111. X
  1112. Xif ($bdev != $ddev || $bino != $dino) {
  1113. X    &unlink("$installbin/perl", "$installbin/taintperl", "$installbin/suidperl");
  1114. X    &link("$installbin/perl$ver", "$installbin/perl");
  1115. X    &link("$installbin/tperl$ver", "$installbin/taintperl");
  1116. X    &link("$installbin/sperl$ver", "$installbin/suidperl") if $d_dosuid;
  1117. X}
  1118. X
  1119. X# Make some enemies in the name of standardization.   :-)
  1120. X
  1121. X($udev,$uino) = stat("/usr/bin");
  1122. X
  1123. Xif (-w _ && ($udev != $ddev || $uino != $dino) && !$nonono) {
  1124. X    unlink "/usr/bin/perl";
  1125. X    eval 'symlink("$installbin/perl", "/usr/bin/perl")' ||
  1126. X    eval 'link("$installbin/perl", "/usr/bin/perl")' ||
  1127. X    &cmd("cp $installbin/perl /usr/bin");
  1128. X}
  1129. X
  1130. X# Install scripts.
  1131. X
  1132. X&makedir($scriptdir);
  1133. X
  1134. Xfor (@scripts) {
  1135. X    &cmd("cp $_ $scriptdir");
  1136. X    &chmod(0755, "$scriptdir/$_");
  1137. X}
  1138. X
  1139. X# Install library files.
  1140. X
  1141. X&makedir($installprivlib);
  1142. X
  1143. X($pdev,$pino) = stat($installprivlib);
  1144. X
  1145. Xif ($pdev != $ddev || $pino != $dino) {
  1146. X    &cmd("cd lib && cp *.pl $installprivlib");
  1147. X}
  1148. X
  1149. X# Install man pages.
  1150. X
  1151. Xif ($mansrc ne '') {
  1152. X    &makedir($mansrc);
  1153. X
  1154. X    ($mdev,$mino) = stat($mansrc);
  1155. X    if ($mdev != $ddev || $mino != $dino) {
  1156. X    for (@manpages) {
  1157. X        ($new = $_) =~ s/man$/$manext/;
  1158. X        print STDERR "  Installing $mansrc/$new\n";
  1159. X        next if $nonono;
  1160. X        open(MI,$_);
  1161. X        open(MO,">$mansrc/$new");
  1162. X        print MO ".ds RP Release $release Patchlevel $patchlevel\n";
  1163. X        while (<MI>) {
  1164. X        print MO;
  1165. X        }
  1166. X        close MI;
  1167. X        close MO;
  1168. X    }
  1169. X    }
  1170. X}
  1171. X
  1172. Xprint STDERR "  Installation complete\n";
  1173. X
  1174. Xexit 0;
  1175. X
  1176. X###############################################################################
  1177. X
  1178. Xsub unlink {
  1179. X    local(@names) = @_;
  1180. X
  1181. X    foreach $name (@names) {
  1182. X    next unless -e $name;
  1183. X    print STDERR "  unlink $name\n";
  1184. X    unlink($name) || warn "Couldn't unlink $name: $!\n" unless $nonono;
  1185. X    }
  1186. X}
  1187. X
  1188. Xsub cmd {
  1189. X    local($cmd) = @_;
  1190. X    print STDERR "  $cmd\n";
  1191. X    unless ($nonono) {
  1192. X    system $cmd;
  1193. X    warn "Command failed!!!\n" if $?;
  1194. X    }
  1195. X}
  1196. X
  1197. Xsub link {
  1198. X    local($from,$to) = @_;
  1199. X
  1200. X    print STDERR "  ln $from $to\n";
  1201. X    link($from,$to) || warn "Couldn't link $from to $to: $!\n" unless $nonono;
  1202. X}
  1203. X
  1204. Xsub chmod {
  1205. X    local($mode,$name) = @_;
  1206. X
  1207. X    printf STDERR "  chmod %o %s\n", $mode, $name;
  1208. X    chmod($mode,$name) || warn "Couldn't chmod $mode $name: $!\n"
  1209. X    unless $nonono;
  1210. X}
  1211. X
  1212. Xsub makedir {
  1213. X    local($dir) = @_;
  1214. X    unless (-d $dir) {
  1215. X    local($shortdir) = $dir;
  1216. X
  1217. X    $shortdir =~ s#(.*)/.*#$1#;
  1218. X    &makedir($shortdir);
  1219. X
  1220. X    print STDERR "  mkdir $dir\n";
  1221. X    mkdir($dir, 0777) || warn "Couldn't create $dir: $!\n" unless $nonono;
  1222. X    }
  1223. X}
  1224. !STUFFY!FUNK!
  1225. echo Extracting lib/bigrat.pl
  1226. sed >lib/bigrat.pl <<'!STUFFY!FUNK!' -e 's/X//'
  1227. Xpackage bigrat;
  1228. Xrequire "bigint.pl";
  1229. X
  1230. X# Arbitrary size rational math package
  1231. X#
  1232. X# Input values to these routines consist of strings of the form 
  1233. X#   m|^\s*[+-]?[\d\s]+(/[\d\s]+)?$|.
  1234. X# Examples:
  1235. X#   "+0/1"                          canonical zero value
  1236. X#   "3"                             canonical value "+3/1"
  1237. X#   "   -123/123 123"               canonical value "-1/1001"
  1238. X#   "123 456/7890"                  canonical value "+20576/1315"
  1239. X# Output values always include a sign and no leading zeros or
  1240. X#   white space.
  1241. X# This package makes use of the bigint package.
  1242. X# The string 'NaN' is used to represent the result when input arguments 
  1243. X#   that are not numbers, as well as the result of dividing by zero and
  1244. X#       the sqrt of a negative number.
  1245. X# Extreamly naive algorthims are used.
  1246. X#
  1247. X# Routines provided are:
  1248. X#
  1249. X#   rneg(RAT) return RAT                negation
  1250. X#   rabs(RAT) return RAT                absolute value
  1251. X#   rcmp(RAT,RAT) return CODE           compare numbers (undef,<0,=0,>0)
  1252. X#   radd(RAT,RAT) return RAT            addition
  1253. X#   rsub(RAT,RAT) return RAT            subtraction
  1254. X#   rmul(RAT,RAT) return RAT            multiplication
  1255. X#   rdiv(RAT,RAT) return RAT            division
  1256. X#   rmod(RAT) return (RAT,RAT)          integer and fractional parts
  1257. X#   rnorm(RAT) return RAT               normalization
  1258. X#   rsqrt(RAT, cycles) return RAT       square root
  1259. X
  1260. X# Convert a number to the canonical string form m|^[+-]\d+/\d+|.
  1261. Xsub main'rnorm { #(string) return rat_num
  1262. X    local($_) = @_;
  1263. X    s/\s+//g;
  1264. X    if (m#^([+-]?\d+)(/(\d*[1-9]0*))?$#) {
  1265. X    &norm($1, $3 ? $3 : '+1');
  1266. X    } else {
  1267. X    'NaN';
  1268. X    }
  1269. X}
  1270. X
  1271. X# Normalize by reducing to lowest terms
  1272. Xsub norm { #(bint, bint) return rat_num
  1273. X    local($num,$dom) = @_;
  1274. X    if ($num eq 'NaN') {
  1275. X    'NaN';
  1276. X    } elsif ($dom eq 'NaN') {
  1277. X    'NaN';
  1278. X    } elsif ($dom =~ /^[+-]?0+$/) {
  1279. X    'NaN';
  1280. X    } else {
  1281. X    local($gcd) = &'bgcd($num,$dom);
  1282. X    if ($gcd ne '+1') { 
  1283. X        $num = &'bdiv($num,$gcd);
  1284. X        $dom = &'bdiv($dom,$gcd);
  1285. X    } else {
  1286. X        $num = &'bnorm($num);
  1287. X        $dom = &'bnorm($dom);
  1288. X    }
  1289. X    substr($dom,0,1) = '';
  1290. X    "$num/$dom";
  1291. X    }
  1292. X}
  1293. X
  1294. X# negation
  1295. Xsub main'rneg { #(rat_num) return rat_num
  1296. X    local($_) = &'rnorm($_[0]);
  1297. X    tr/-+/+-/ if ($_ ne '+0/1');
  1298. X    $_;
  1299. X}
  1300. X
  1301. X# absolute value
  1302. Xsub main'rabs { #(rat_num) return $rat_num
  1303. X    local($_) = &'rnorm($_[0]);
  1304. X    substr($_,0,1) = '+' unless $_ eq 'NaN';
  1305. X    $_;
  1306. X}
  1307. X
  1308. X# multipication
  1309. Xsub main'rmul { #(rat_num, rat_num) return rat_num
  1310. X    local($xn,$xd) = split('/',&'rnorm($_[0]));
  1311. X    local($yn,$yd) = split('/',&'rnorm($_[1]));
  1312. X    &norm(&'bmul($xn,$yn),&'bmul($xd,$yd));
  1313. X}
  1314. X
  1315. X# division
  1316. Xsub main'rdiv { #(rat_num, rat_num) return rat_num
  1317. X    local($xn,$xd) = split('/',&'rnorm($_[0]));
  1318. X    local($yn,$yd) = split('/',&'rnorm($_[1]));
  1319. X    &norm(&'bmul($xn,$yd),&'bmul($xd,$yn));
  1320. X}
  1321. X
  1322. X# addition
  1323. Xsub main'radd { #(rat_num, rat_num) return rat_num
  1324. X    local($xn,$xd) = split('/',&'rnorm($_[0]));
  1325. X    local($yn,$yd) = split('/',&'rnorm($_[1]));
  1326. X    &norm(&'badd(&'bmul($xn,$yd),&'bmul($yn,$xd)),&'bmul($xd,$yd));
  1327. X}
  1328. X
  1329. X# subtraction
  1330. Xsub main'rsub { #(rat_num, rat_num) return rat_num
  1331. X    local($xn,$xd) = split('/',&'rnorm($_[0]));
  1332. X    local($yn,$yd) = split('/',&'rnorm($_[1]));
  1333. X    &norm(&'bsub(&'bmul($xn,$yd),&'bmul($yn,$xd)),&'bmul($xd,$yd));
  1334. X}
  1335. X
  1336. X# comparison
  1337. Xsub main'rcmp { #(rat_num, rat_num) return cond_code
  1338. X    local($xn,$xd) = split('/',&'rnorm($_[0]));
  1339. X    local($yn,$yd) = split('/',&'rnorm($_[1]));
  1340. X    &bigint'cmp(&'bmul($xn,$yd),&'bmul($yn,$xd));
  1341. X}
  1342. X
  1343. X# int and frac parts
  1344. Xsub main'rmod { #(rat_num) return (rat_num,rat_num)
  1345. X    local($xn,$xd) = split('/',&'rnorm($_[0]));
  1346. X    local($i,$f) = &'bdiv($xn,$xd);
  1347. X    if (wantarray) {
  1348. X    ("$i/1", "$f/$xd");
  1349. X    } else {
  1350. X    "$i/1";
  1351. X    }   
  1352. X}
  1353. X
  1354. X# square root by Newtons method.
  1355. X#   cycles specifies the number of iterations default: 5
  1356. Xsub main'rsqrt { #(fnum_str[, cycles]) return fnum_str
  1357. X    local($x, $scale) = (&'rnorm($_[0]), $_[1]);
  1358. X    if ($x eq 'NaN') {
  1359. X    'NaN';
  1360. X    } elsif ($x =~ /^-/) {
  1361. X    'NaN';
  1362. X    } else {
  1363. X    local($gscale, $guess) = (0, '+1/1');
  1364. X    $scale = 5 if (!$scale);
  1365. X    while ($gscale++ < $scale) {
  1366. X        $guess = &'rmul(&'radd($guess,&'rdiv($x,$guess)),"+1/2");
  1367. X    }
  1368. X    "$guess";          # quotes necessary due to perl bug
  1369. X    }
  1370. X}
  1371. X
  1372. X1;
  1373. !STUFFY!FUNK!
  1374. echo Extracting h2pl/eg/sys/ioctl.pl
  1375. sed >h2pl/eg/sys/ioctl.pl <<'!STUFFY!FUNK!' -e 's/X//'
  1376. X$_IOCTL_ = 0x1;
  1377. X$TIOCGSIZE = 0x40087468;
  1378. X$TIOCSSIZE = 0x80087467;
  1379. X$IOCPARM_MASK = 0x7F;
  1380. X$IOC_VOID = 0x20000000;
  1381. X$IOC_OUT = 0x40000000;
  1382. X$IOC_IN = 0x80000000;
  1383. X$IOC_INOUT = 0xC0000000;
  1384. X$TIOCGETD = 0x40047400;
  1385. X$TIOCSETD = 0x80047401;
  1386. X$TIOCHPCL = 0x20007402;
  1387. X$TIOCMODG = 0x40047403;
  1388. X$TIOCMODS = 0x80047404;
  1389. X$TIOCM_LE = 0x1;
  1390. X$TIOCM_DTR = 0x2;
  1391. X$TIOCM_RTS = 0x4;
  1392. X$TIOCM_ST = 0x8;
  1393. X$TIOCM_SR = 0x10;
  1394. X$TIOCM_CTS = 0x20;
  1395. X$TIOCM_CAR = 0x40;
  1396. X$TIOCM_CD = 0x40;
  1397. X$TIOCM_RNG = 0x80;
  1398. X$TIOCM_RI = 0x80;
  1399. X$TIOCM_DSR = 0x100;
  1400. X$TIOCGETP = 0x40067408;
  1401. X$TIOCSETP = 0x80067409;
  1402. X$TIOCSETN = 0x8006740A;
  1403. X$TIOCEXCL = 0x2000740D;
  1404. X$TIOCNXCL = 0x2000740E;
  1405. X$TIOCFLUSH = 0x80047410;
  1406. X$TIOCSETC = 0x80067411;
  1407. X$TIOCGETC = 0x40067412;
  1408. X$TIOCSET = 0x80047413;
  1409. X$TIOCBIS = 0x80047414;
  1410. X$TIOCBIC = 0x80047415;
  1411. X$TIOCGET = 0x40047416;
  1412. X$TANDEM = 0x1;
  1413. X$CBREAK = 0x2;
  1414. X$LCASE = 0x4;
  1415. X$ECHO = 0x8;
  1416. X$CRMOD = 0x10;
  1417. X$RAW = 0x20;
  1418. X$ODDP = 0x40;
  1419. X$EVENP = 0x80;
  1420. X$ANYP = 0xC0;
  1421. X$NLDELAY = 0x300;
  1422. X$NL0 = 0x0;
  1423. X$NL1 = 0x100;
  1424. X$NL2 = 0x200;
  1425. X$NL3 = 0x300;
  1426. X$TBDELAY = 0xC00;
  1427. X$TAB0 = 0x0;
  1428. X$TAB1 = 0x400;
  1429. X$TAB2 = 0x800;
  1430. X$XTABS = 0xC00;
  1431. X$CRDELAY = 0x3000;
  1432. X$CR0 = 0x0;
  1433. X$CR1 = 0x1000;
  1434. X$CR2 = 0x2000;
  1435. X$CR3 = 0x3000;
  1436. X$VTDELAY = 0x4000;
  1437. X$FF0 = 0x0;
  1438. X$FF1 = 0x4000;
  1439. X$BSDELAY = 0x8000;
  1440. X$BS0 = 0x0;
  1441. X$BS1 = 0x8000;
  1442. X$ALLDELAY = 0xFF00;
  1443. X$CRTBS = 0x10000;
  1444. X$PRTERA = 0x20000;
  1445. X$CRTERA = 0x40000;
  1446. X$TILDE = 0x80000;
  1447. X$MDMBUF = 0x100000;
  1448. X$LITOUT = 0x200000;
  1449. X$TOSTOP = 0x400000;
  1450. X$FLUSHO = 0x800000;
  1451. X$NOHANG = 0x1000000;
  1452. X$L001000 = 0x2000000;
  1453. X$CRTKIL = 0x4000000;
  1454. X$L004000 = 0x8000000;
  1455. X$CTLECH = 0x10000000;
  1456. X$PENDIN = 0x20000000;
  1457. X$DECCTQ = 0x40000000;
  1458. X$NOFLSH = 0x80000000;
  1459. X$TIOCCSET = 0x800E7417;
  1460. X$TIOCCGET = 0x400E7418;
  1461. X$TIOCLBIS = 0x8004747F;
  1462. X$TIOCLBIC = 0x8004747E;
  1463. X$TIOCLSET = 0x8004747D;
  1464. X$TIOCLGET = 0x4004747C;
  1465. X$LCRTBS = 0x1;
  1466. X$LPRTERA = 0x2;
  1467. X$LCRTERA = 0x4;
  1468. X$LTILDE = 0x8;
  1469. X$LMDMBUF = 0x10;
  1470. X$LLITOUT = 0x20;
  1471. X$LTOSTOP = 0x40;
  1472. X$LFLUSHO = 0x80;
  1473. X$LNOHANG = 0x100;
  1474. X$LCRTKIL = 0x400;
  1475. X$LCTLECH = 0x1000;
  1476. X$LPENDIN = 0x2000;
  1477. X$LDECCTQ = 0x4000;
  1478. X$LNOFLSH = 0x8000;
  1479. X$TIOCSBRK = 0x2000747B;
  1480. X$TIOCCBRK = 0x2000747A;
  1481. X$TIOCSDTR = 0x20007479;
  1482. X$TIOCCDTR = 0x20007478;
  1483. X$TIOCGPGRP = 0x40047477;
  1484. X$TIOCSPGRP = 0x80047476;
  1485. X$TIOCSLTC = 0x80067475;
  1486. X$TIOCGLTC = 0x40067474;
  1487. X$TIOCOUTQ = 0x40047473;
  1488. X$TIOCSTI = 0x80017472;
  1489. X$TIOCNOTTY = 0x20007471;
  1490. X$TIOCPKT = 0x80047470;
  1491. X$TIOCPKT_DATA = 0x0;
  1492. X$TIOCPKT_FLUSHREAD = 0x1;
  1493. X$TIOCPKT_FLUSHWRITE = 0x2;
  1494. X$TIOCPKT_STOP = 0x4;
  1495. X$TIOCPKT_START = 0x8;
  1496. X$TIOCPKT_NOSTOP = 0x10;
  1497. X$TIOCPKT_DOSTOP = 0x20;
  1498. X$TIOCSTOP = 0x2000746F;
  1499. X$TIOCSTART = 0x2000746E;
  1500. X$TIOCREMOTE = 0x20007469;
  1501. X$TIOCGWINSZ = 0x40087468;
  1502. X$TIOCSWINSZ = 0x80087467;
  1503. X$TIOCRESET = 0x20007466;
  1504. X$OTTYDISC = 0x0;
  1505. X$NETLDISC = 0x1;
  1506. X$NTTYDISC = 0x2;
  1507. X$FIOCLEX = 0x20006601;
  1508. X$FIONCLEX = 0x20006602;
  1509. X$FIONREAD = 0x4004667F;
  1510. X$FIONBIO = 0x8004667E;
  1511. X$FIOASYNC = 0x8004667D;
  1512. X$FIOSETOWN = 0x8004667C;
  1513. X$FIOGETOWN = 0x4004667B;
  1514. X$STPUTTABLE = 0x8004667A;
  1515. X$STGETTABLE = 0x80046679;
  1516. X$SIOCSHIWAT = 0x80047300;
  1517. X$SIOCGHIWAT = 0x40047301;
  1518. X$SIOCSLOWAT = 0x80047302;
  1519. X$SIOCGLOWAT = 0x40047303;
  1520. X$SIOCATMARK = 0x40047307;
  1521. X$SIOCSPGRP = 0x80047308;
  1522. X$SIOCGPGRP = 0x40047309;
  1523. X$SIOCADDRT = 0x8034720A;
  1524. X$SIOCDELRT = 0x8034720B;
  1525. X$SIOCSIFADDR = 0x8020690C;
  1526. X$SIOCGIFADDR = 0xC020690D;
  1527. X$SIOCSIFDSTADDR = 0x8020690E;
  1528. X$SIOCGIFDSTADDR = 0xC020690F;
  1529. X$SIOCSIFFLAGS = 0x80206910;
  1530. X$SIOCGIFFLAGS = 0xC0206911;
  1531. X$SIOCGIFBRDADDR = 0xC0206912;
  1532. X$SIOCSIFBRDADDR = 0x80206913;
  1533. X$SIOCGIFCONF = 0xC0086914;
  1534. X$SIOCGIFNETMASK = 0xC0206915;
  1535. X$SIOCSIFNETMASK = 0x80206916;
  1536. X$SIOCGIFMETRIC = 0xC0206917;
  1537. X$SIOCSIFMETRIC = 0x80206918;
  1538. X$SIOCSARP = 0x8024691E;
  1539. X$SIOCGARP = 0xC024691F;
  1540. X$SIOCDARP = 0x80246920;
  1541. X$PIXCONTINUE = 0x80747000;
  1542. X$PIXSTEP = 0x80747001;
  1543. X$PIXTERMINATE = 0x20007002;
  1544. X$PIGETFLAGS = 0x40747003;
  1545. X$PIXINHERIT = 0x80747004;
  1546. X$PIXDETACH = 0x20007005;
  1547. X$PIXGETSUBCODE = 0xC0747006;
  1548. X$PIXRDREGS = 0xC0747007;
  1549. X$PIXWRREGS = 0xC0747008;
  1550. X$PIXRDVREGS = 0xC0747009;
  1551. X$PIXWRVREGS = 0xC074700A;
  1552. X$PIXRDVSTATE = 0xC074700B;
  1553. X$PIXWRVSTATE = 0xC074700C;
  1554. X$PIXRDCREGS = 0xC074700D;
  1555. X$PIXWRCREGS = 0xC074700E;
  1556. X$PIRDSDRS = 0xC074700F;
  1557. X$PIXGETSIGACTION = 0xC0747010;
  1558. X$PIGETU = 0xC0747011;
  1559. X$PISETRWTID = 0xC0747012;
  1560. X$PIXGETTHCOUNT = 0xC0747013;
  1561. X$PIXRUN = 0x20007014;
  1562. !STUFFY!FUNK!
  1563. echo Extracting os2/alarm.c
  1564. sed >os2/alarm.c <<'!STUFFY!FUNK!' -e 's/X//'
  1565. X/*
  1566. X * This software is Copyright 1989 by Jack Hudler.
  1567. X *
  1568. X * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  1569. X * use this software as long as: there is no monetary profit gained
  1570. X * specifically from the use or reproduction or this software, it is not
  1571. X * sold, rented, traded or otherwise marketed, and this copyright notice is
  1572. X * included prominently in any copy made.
  1573. X *
  1574. X * The author make no claims as to the fitness or correctness of this software
  1575. X * for any use whatsoever, and it is provided as is. Any use of this software
  1576. X * is at the user's own risk.
  1577. X *
  1578. X */
  1579. X
  1580. X/****************************** Module Header ******************************\
  1581. X* Module Name: alarm.c
  1582. X* Created    : 11-08-89
  1583. X* Author     : Jack Hudler  [jack@csccat.lonestar.org]
  1584. X* Copyright  : 1988 Jack Hudler.
  1585. X* Function   : Unix like alarm signal simulator.
  1586. X\***************************************************************************/
  1587. X
  1588. X/* Tested using OS2 1.2 with Microsoft C 5.1 and 6.0. */
  1589. X
  1590. X#define INCL_DOSPROCESS
  1591. X#define INCL_DOSSIGNALS
  1592. X#define INCL_DOS
  1593. X#include <os2.h>
  1594. X
  1595. X#include <stdlib.h>
  1596. X#include <stdio.h>
  1597. X#include <signal.h>
  1598. X
  1599. X#include "alarm.h"
  1600. X
  1601. X#define ALARM_STACK 4096    /* This maybe over kill, but the page size is 4K */
  1602. X
  1603. Xstatic  PBYTE     pbAlarmStack;
  1604. Xstatic  SEL       selAlarmStack;
  1605. Xstatic  TID       tidAlarm;
  1606. Xstatic  PID       pidMain;
  1607. Xstatic  BOOL      bAlarmInit=FALSE;
  1608. Xstatic  BOOL      bAlarmRunning=FALSE;
  1609. Xstatic  USHORT    uTime;
  1610. X
  1611. Xstatic VOID FAR alarm_thread ( VOID )
  1612. X{
  1613. X    while(1)
  1614. X    {
  1615. X      if (bAlarmRunning)
  1616. X      {
  1617. X        DosSleep(1000L);
  1618. X        uTime--;
  1619. X        if (uTime==0L)
  1620. X        {
  1621. X          // send signal to the main process.. I could have put raise() here
  1622. X          // however that would require the use of the multithreaded library,
  1623. X          // and it does not contain raise()!
  1624. X          // I tried it with the standard library, this signaled ok, but a
  1625. X          // test printf in the signal would not work and even caused SEGV.
  1626. X          // So I signal the process through OS/2 and then the process
  1627. X          // signals itself.
  1628. X          if (bAlarmRunning)
  1629. X            DosFlagProcess(pidMain,FLGP_PID, PFLG_A,1);
  1630. X          bAlarmRunning=FALSE;
  1631. X        }
  1632. X      }
  1633. X      else
  1634. X        DosSleep(500L);
  1635. X    }
  1636. X}
  1637. X
  1638. Xstatic VOID PASCAL FAR AlarmSignal(USHORT usSigArg,USHORT usSigNum)
  1639. X{
  1640. X    /*
  1641. X     * this is not executed from the thread. The thread triggers Process
  1642. X     * flag A which is in the main processes scope, this inturn triggers
  1643. X     * (via the raise) SIGUSR1 which is defined to SIGALRM.
  1644. X     */
  1645. X    raise(SIGUSR1);
  1646. X}
  1647. X
  1648. Xstatic void alarm_init(void)
  1649. X{
  1650. X    PFNSIGHANDLER pfnPrev;
  1651. X    USHORT       pfAction;
  1652. X    PIDINFO      pid;
  1653. X
  1654. X    bAlarmInit = TRUE;
  1655. X
  1656. X    if (!DosAllocSeg( ALARM_STACK, (PSEL) &selAlarmStack, SEG_NONSHARED ))
  1657. X    {
  1658. X      OFFSETOF(pbAlarmStack) = ALARM_STACK - 2;
  1659. X      SELECTOROF(pbAlarmStack) = selAlarmStack;
  1660. X      /* Create the thread */
  1661. X      if (DosCreateThread( alarm_thread, &tidAlarm, pbAlarmStack ))
  1662. X      {
  1663. X        fprintf(stderr,"Alarm thread failed to start.\n");
  1664. X        exit(1);
  1665. X      }
  1666. X      /* Setup the signal handler for Process Flag A */
  1667. X      if (DosSetSigHandler(AlarmSignal,&pfnPrev,&pfAction,SIGA_ACCEPT,SIG_PFLG_A))
  1668. X      {
  1669. X        fprintf(stderr,"SigHandler Failed to install.\n");
  1670. X        exit(1);
  1671. X      }
  1672. X      /* Save main process ID, we'll need it for triggering the signal */
  1673. X      DosGetPID(&pid);
  1674. X      pidMain = pid.pid;
  1675. X    }
  1676. X    else
  1677. X      exit(1);
  1678. X}
  1679. X
  1680. Xunsigned alarm(unsigned sec)
  1681. X{
  1682. X    if (!bAlarmInit) alarm_init();
  1683. X
  1684. X    if (sec)
  1685. X    {
  1686. X      uTime = sec;
  1687. X      bAlarmRunning = TRUE;
  1688. X    }
  1689. X    else
  1690. X      bAlarmRunning = FALSE;
  1691. X
  1692. X    return 0;
  1693. X}
  1694. X
  1695. X#ifdef TESTING
  1696. X/* A simple test to see if it works */
  1697. XBOOL  x;
  1698. X
  1699. Xvoid timeout(void)
  1700. X{
  1701. X    fprintf(stderr,"ALARM TRIGGERED!!\n");
  1702. X    DosBeep(1000,500);
  1703. X    x++;
  1704. X}
  1705. X
  1706. Xvoid main(void)
  1707. X{
  1708. X    (void) signal(SIGALRM, timeout);
  1709. X    (void) alarm(1L);
  1710. X    printf("ALARM RUNNING!!\n");
  1711. X    while(!x);
  1712. X}
  1713. X#endif
  1714. !STUFFY!FUNK!
  1715. echo Extracting t/op/array.t
  1716. sed >t/op/array.t <<'!STUFFY!FUNK!' -e 's/X//'
  1717. X#!./perl
  1718. X
  1719. X# $Header: array.t,v 4.0 91/03/20 01:51:31 lwall Locked $
  1720. X
  1721. Xprint "1..36\n";
  1722. X
  1723. X@ary = (1,2,3,4,5);
  1724. Xif (join('',@ary) eq '12345') {print "ok 1\n";} else {print "not ok 1\n";}
  1725. X
  1726. X$tmp = $ary[$#ary]; --$#ary;
  1727. Xif ($tmp == 5) {print "ok 2\n";} else {print "not ok 2\n";}
  1728. Xif ($#ary == 3) {print "ok 3\n";} else {print "not ok 3\n";}
  1729. Xif (join('',@ary) eq '1234') {print "ok 4\n";} else {print "not ok 4\n";}
  1730. X
  1731. X$[ = 1;
  1732. X@ary = (1,2,3,4,5);
  1733. Xif (join('',@ary) eq '12345') {print "ok 5\n";} else {print "not ok 5\n";}
  1734. X
  1735. X$tmp = $ary[$#ary]; --$#ary;
  1736. Xif ($tmp == 5) {print "ok 6\n";} else {print "not ok 6\n";}
  1737. Xif ($#ary == 4) {print "ok 7\n";} else {print "not ok 7\n";}
  1738. Xif (join('',@ary) eq '1234') {print "ok 8\n";} else {print "not ok 8\n";}
  1739. X
  1740. Xif ($ary[5] eq '') {print "ok 9\n";} else {print "not ok 9\n";}
  1741. X
  1742. X$#ary += 1;    # see if we can recover element 5
  1743. Xif ($#ary == 5) {print "ok 10\n";} else {print "not ok 10\n";}
  1744. Xif ($ary[5] == 5) {print "ok 11\n";} else {print "not ok 11\n";}
  1745. X
  1746. X$[ = 0;
  1747. X@foo = ();
  1748. X$r = join(',', $#foo, @foo);
  1749. Xif ($r eq "-1") {print "ok 12\n";} else {print "not ok 12 $r\n";}
  1750. X$foo[0] = '0';
  1751. X$r = join(',', $#foo, @foo);
  1752. Xif ($r eq "0,0") {print "ok 13\n";} else {print "not ok 13 $r\n";}
  1753. X$foo[2] = '2';
  1754. X$r = join(',', $#foo, @foo);
  1755. Xif ($r eq "2,0,,2") {print "ok 14\n";} else {print "not ok 14 $r\n";}
  1756. X@bar = ();
  1757. X$bar[0] = '0';
  1758. X$bar[1] = '1';
  1759. X$r = join(',', $#bar, @bar);
  1760. Xif ($r eq "1,0,1") {print "ok 15\n";} else {print "not ok 15 $r\n";}
  1761. X@bar = ();
  1762. X$r = join(',', $#bar, @bar);
  1763. Xif ($r eq "-1") {print "ok 16\n";} else {print "not ok 16 $r\n";}
  1764. X$bar[0] = '0';
  1765. X$r = join(',', $#bar, @bar);
  1766. Xif ($r eq "0,0") {print "ok 17\n";} else {print "not ok 17 $r\n";}
  1767. X$bar[2] = '2';
  1768. X$r = join(',', $#bar, @bar);
  1769. Xif ($r eq "2,0,,2") {print "ok 18\n";} else {print "not ok 18 $r\n";}
  1770. Xreset 'b';
  1771. X@bar = ();
  1772. X$bar[0] = '0';
  1773. X$r = join(',', $#bar, @bar);
  1774. Xif ($r eq "0,0") {print "ok 19\n";} else {print "not ok 19 $r\n";}
  1775. X$bar[2] = '2';
  1776. X$r = join(',', $#bar, @bar);
  1777. Xif ($r eq "2,0,,2") {print "ok 20\n";} else {print "not ok 20 $r\n";}
  1778. X
  1779. X$foo = 'now is the time';
  1780. Xif (($F1,$F2,$Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/)) {
  1781. X    if ($F1 eq 'now' && $F2 eq 'is' && $Etc eq 'the time') {
  1782. X    print "ok 21\n";
  1783. X    }
  1784. X    else {
  1785. X    print "not ok 21\n";
  1786. X    }
  1787. X}
  1788. Xelse {
  1789. X    print "not ok 21\n";
  1790. X}
  1791. X
  1792. X$foo = 'lskjdf';
  1793. Xif ($cnt = (($F1,$F2,$Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/))) {
  1794. X    print "not ok 22 $cnt $F1:$F2:$Etc\n";
  1795. X}
  1796. Xelse {
  1797. X    print "ok 22\n";
  1798. X}
  1799. X
  1800. X%foo = ('blurfl','dyick','foo','bar','etc.','etc.');
  1801. X%bar = %foo;
  1802. Xprint $bar{'foo'} eq 'bar' ? "ok 23\n" : "not ok 23\n";
  1803. X%bar = ();
  1804. Xprint $bar{'foo'} eq '' ? "ok 24\n" : "not ok 24\n";
  1805. X(%bar,$a,$b) = (%foo,'how','now');
  1806. Xprint $bar{'foo'} eq 'bar' ? "ok 25\n" : "not ok 25\n";
  1807. Xprint $bar{'how'} eq 'now' ? "ok 26\n" : "not ok 26\n";
  1808. X@bar{keys %foo} = values %foo;
  1809. Xprint $bar{'foo'} eq 'bar' ? "ok 27\n" : "not ok 27\n";
  1810. Xprint $bar{'how'} eq 'now' ? "ok 28\n" : "not ok 28\n";
  1811. X
  1812. X@foo = grep(/e/,split(' ','now is the time for all good men to come to'));
  1813. Xprint join(' ',@foo) eq 'the time men come' ? "ok 29\n" : "not ok 29\n";
  1814. X
  1815. X@foo = grep(!/e/,split(' ','now is the time for all good men to come to'));
  1816. Xprint join(' ',@foo) eq 'now is for all good to to' ? "ok 30\n" : "not ok 30\n";
  1817. X
  1818. X$foo = join('',('a','b','c','d','e','f')[0..5]);
  1819. Xprint $foo eq 'abcdef' ? "ok 31\n" : "not ok 31\n";
  1820. X
  1821. X$foo = join('',('a','b','c','d','e','f')[0..1]);
  1822. Xprint $foo eq 'ab' ? "ok 32\n" : "not ok 32\n";
  1823. X
  1824. X$foo = join('',('a','b','c','d','e','f')[6]);
  1825. Xprint $foo eq '' ? "ok 33\n" : "not ok 33\n";
  1826. X
  1827. X@foo = ('a','b','c','d','e','f')[0,2,4];
  1828. X@bar = ('a','b','c','d','e','f')[1,3,5];
  1829. X$foo = join('',(@foo,@bar)[0..5]);
  1830. Xprint $foo eq 'acebdf' ? "ok 34\n" : "not ok 34\n";
  1831. X
  1832. X$foo = ('a','b','c','d','e','f')[0,2,4];
  1833. Xprint $foo eq 'e' ? "ok 35\n" : "not ok 35\n";
  1834. X
  1835. X$foo = ('a','b','c','d','e','f')[1];
  1836. Xprint $foo eq 'b' ? "ok 36\n" : "not ok 36\n";
  1837. !STUFFY!FUNK!
  1838. echo Extracting lib/timelocal.pl
  1839. sed >lib/timelocal.pl <<'!STUFFY!FUNK!' -e 's/X//'
  1840. X;# timelocal.pl
  1841. X;#
  1842. X;# Usage:
  1843. X;#    $time = timelocal($sec,$min,$hours,$mday,$mon,$year,$junk,$junk,$isdst);
  1844. X;#    $time = timegm($sec,$min,$hours,$mday,$mon,$year);
  1845. X
  1846. X;# These routines are quite efficient and yet are always guaranteed to agree
  1847. X;# with localtime() and gmtime().  We manage this by caching the start times
  1848. X;# of any months we've seen before.  If we know the start time of the month,
  1849. X;# we can always calculate any time within the month.  The start times
  1850. X;# themselves are guessed by successive approximation starting at the
  1851. X;# current time, since most dates seen in practice are close to the
  1852. X;# current date.  Unlike algorithms that do a binary search (calling gmtime
  1853. X;# once for each bit of the time value, resulting in 32 calls), this algorithm
  1854. X;# calls it at most 6 times, and usually only once or twice.  If you hit
  1855. X;# the month cache, of course, it doesn't call it at all.
  1856. X
  1857. X;# timelocal is implemented using the same cache.  We just assume that we're
  1858. X;# translating a GMT time, and then fudge it when we're done for the timezone
  1859. X;# and daylight savings arguments.  The timezone is determined by examining
  1860. X;# the result of localtime(0) when the package is initialized.  The daylight
  1861. X;# savings offset is currently assumed to be one hour.
  1862. X
  1863. XCONFIG: {
  1864. X    package timelocal;
  1865. X    
  1866. X    @epoch = localtime(0);
  1867. X    $tzmin = $epoch[2] * 60 + $epoch[1];    # minutes east of GMT
  1868. X    if ($tzmin > 0) {
  1869. X    $tzmin = 24 * 60 - $tzmin;        # minutes west of GMT
  1870. X    $tzmin -= 24 * 60 if $epoch[5] == 70;    # account for the date line
  1871. X    }
  1872. X
  1873. X    $SEC = 1;
  1874. X    $MIN = 60 * $SEC;
  1875. X    $HR = 60 * $MIN;
  1876. X    $DAYS = 24 * $HR;
  1877. X}
  1878. X
  1879. Xsub timegm {
  1880. X    package timelocal;
  1881. X
  1882. X    $ym = pack(C2, @_[5,4]);
  1883. X    $cheat = $cheat{$ym} || &cheat;
  1884. X    $cheat + $_[0] * $SEC + $_[1] * $MIN + $_[2] * $HR + ($_[3]-1) * $DAYS;
  1885. X}
  1886. X
  1887. Xsub timelocal {
  1888. X    package timelocal;
  1889. X
  1890. X    $ym = pack(C2, @_[5,4]);
  1891. X    $cheat = $cheat{$ym} || &cheat;
  1892. X    $cheat + $_[0] * $SEC + $_[1] * $MIN + $_[2] * $HR + ($_[3]-1) * $DAYS
  1893. X    + $tzmin * $MIN - 60 * 60 * ($_[8] != 0);
  1894. X}
  1895. X
  1896. Xpackage timelocal;
  1897. X
  1898. Xsub cheat {
  1899. X    $year = $_[5];
  1900. X    $month = $_[4];
  1901. X    $guess = $^T;
  1902. X    @g = gmtime($guess);
  1903. X    while ($diff = $year - $g[5]) {
  1904. X    $guess += $diff * (364 * $DAYS);
  1905. X    @g = gmtime($guess);
  1906. X    }
  1907. X    while ($diff = $month - $g[4]) {
  1908. X    $guess += $diff * (28 * $DAYS);
  1909. X    @g = gmtime($guess);
  1910. X    }
  1911. X    $g[3]--;
  1912. X    $guess -= $g[0] * $SEC + $g[1] * $MIN + $g[2] * $HR + $g[3] * $DAYS;
  1913. X    $cheat{$ym} = $guess;
  1914. X}
  1915. !STUFFY!FUNK!
  1916. echo " "
  1917. echo "End of kit 31 (of 36)"
  1918. cat /dev/null >kit31isdone
  1919. run=''
  1920. config=''
  1921. 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 25 26 27 28 29 30 31 32 33 34 35 36; do
  1922.     if test -f kit${iskit}isdone; then
  1923.     run="$run $iskit"
  1924.     else
  1925.     todo="$todo $iskit"
  1926.     fi
  1927. done
  1928. case $todo in
  1929.     '')
  1930.     echo "You have run all your kits.  Please read README and then type Configure."
  1931.     for combo in *:AA; do
  1932.         if test -f "$combo"; then
  1933.         realfile=`basename $combo :AA`
  1934.         cat $realfile:[A-Z][A-Z] >$realfile
  1935.         rm -rf $realfile:[A-Z][A-Z]
  1936.         fi
  1937.     done
  1938.     rm -rf kit*isdone
  1939.     chmod 755 Configure
  1940.     ;;
  1941.     *)  echo "You have run$run."
  1942.     echo "You still need to run$todo."
  1943.     ;;
  1944. esac
  1945. : Someone might mail this, so...
  1946. exit
  1947.  
  1948. exit 0 # Just in case...
  1949. -- 
  1950. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1951. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1952. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1953. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1954.