home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume13 / perl / part09 < prev    next >
Encoding:
Internet Message Format  |  1988-01-30  |  49.1 KB

  1. Subject:  v13i009:  Perl, a "replacement" for awk and sed, Part09/10
  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 13, Issue 9
  8. Archive-name: perl/part09
  9.  
  10.  
  11.  
  12. #! /bin/sh
  13.  
  14. # Make a new directory for the perl sources, cd to it, and run kits 1
  15. # thru 10 through sh.  When all 10 kits have been run, read README.
  16.  
  17. echo "This is perl 1.0 kit 9 (of 10).  If kit 9 is complete, the line"
  18. echo '"'"End of kit 9 (of 10)"'" will echo at the end.'
  19. echo ""
  20. export PATH || (echo "You didn't use sh, you clunch." ; kill $$)
  21. mkdir t 2>/dev/null
  22. mkdir x2p 2>/dev/null
  23. echo Extracting x2p/util.c
  24. sed >x2p/util.c <<'!STUFFY!FUNK!' -e 's/X//'
  25. X/* $Header: util.c,v 1.0 87/12/18 13:07:34 root Exp $
  26. X *
  27. X * $Log:    util.c,v $
  28. X * Revision 1.0  87/12/18  13:07:34  root
  29. X * Initial revision
  30. X * 
  31. X */
  32. X
  33. X#include <stdio.h>
  34. X
  35. X#include "handy.h"
  36. X#include "EXTERN.h"
  37. X#include "a2p.h"
  38. X#include "INTERN.h"
  39. X#include "util.h"
  40. X
  41. X#define FLUSH
  42. X#define MEM_SIZE unsigned int
  43. X
  44. Xstatic char nomem[] = "Out of memory!\n";
  45. X
  46. X/* paranoid version of malloc */
  47. X
  48. Xstatic int an = 0;
  49. X
  50. Xchar *
  51. Xsafemalloc(size)
  52. XMEM_SIZE size;
  53. X{
  54. X    char *ptr;
  55. X    char *malloc();
  56. X
  57. X    ptr = malloc(size?size:1);    /* malloc(0) is NASTY on our system */
  58. X#ifdef DEBUGGING
  59. X    if (debug & 128)
  60. X    fprintf(stderr,"0x%x: (%05d) malloc %d bytes\n",ptr,an++,size);
  61. X#endif
  62. X    if (ptr != Nullch)
  63. X    return ptr;
  64. X    else {
  65. X    fputs(nomem,stdout) FLUSH;
  66. X    exit(1);
  67. X    }
  68. X    /*NOTREACHED*/
  69. X}
  70. X
  71. X/* paranoid version of realloc */
  72. X
  73. Xchar *
  74. Xsaferealloc(where,size)
  75. Xchar *where;
  76. XMEM_SIZE size;
  77. X{
  78. X    char *ptr;
  79. X    char *realloc();
  80. X
  81. X    ptr = realloc(where,size?size:1);    /* realloc(0) is NASTY on our system */
  82. X#ifdef DEBUGGING
  83. X    if (debug & 128) {
  84. X    fprintf(stderr,"0x%x: (%05d) rfree\n",where,an++);
  85. X    fprintf(stderr,"0x%x: (%05d) realloc %d bytes\n",ptr,an++,size);
  86. X    }
  87. X#endif
  88. X    if (ptr != Nullch)
  89. X    return ptr;
  90. X    else {
  91. X    fputs(nomem,stdout) FLUSH;
  92. X    exit(1);
  93. X    }
  94. X    /*NOTREACHED*/
  95. X}
  96. X
  97. X/* safe version of free */
  98. X
  99. Xsafefree(where)
  100. Xchar *where;
  101. X{
  102. X#ifdef DEBUGGING
  103. X    if (debug & 128)
  104. X    fprintf(stderr,"0x%x: (%05d) free\n",where,an++);
  105. X#endif
  106. X    free(where);
  107. X}
  108. X
  109. X/* safe version of string copy */
  110. X
  111. Xchar *
  112. Xsafecpy(to,from,len)
  113. Xchar *to;
  114. Xregister char *from;
  115. Xregister int len;
  116. X{
  117. X    register char *dest = to;
  118. X
  119. X    if (from != Nullch) 
  120. X    for (len--; len && (*dest++ = *from++); len--) ;
  121. X    *dest = '\0';
  122. X    return to;
  123. X}
  124. X
  125. X#ifdef undef
  126. X/* safe version of string concatenate, with \n deletion and space padding */
  127. X
  128. Xchar *
  129. Xsafecat(to,from,len)
  130. Xchar *to;
  131. Xregister char *from;
  132. Xregister int len;
  133. X{
  134. X    register char *dest = to;
  135. X
  136. X    len--;                /* leave room for null */
  137. X    if (*dest) {
  138. X    while (len && *dest++) len--;
  139. X    if (len) {
  140. X        len--;
  141. X        *(dest-1) = ' ';
  142. X    }
  143. X    }
  144. X    if (from != Nullch)
  145. X    while (len && (*dest++ = *from++)) len--;
  146. X    if (len)
  147. X    dest--;
  148. X    if (*(dest-1) == '\n')
  149. X    dest--;
  150. X    *dest = '\0';
  151. X    return to;
  152. X}
  153. X#endif
  154. X
  155. X/* copy a string up to some (non-backslashed) delimiter, if any */
  156. X
  157. Xchar *
  158. Xcpytill(to,from,delim)
  159. Xregister char *to, *from;
  160. Xregister int delim;
  161. X{
  162. X    for (; *from; from++,to++) {
  163. X    if (*from == '\\' && from[1] == delim)
  164. X        *to++ = *from++;
  165. X    else if (*from == delim)
  166. X        break;
  167. X    *to = *from;
  168. X    }
  169. X    *to = '\0';
  170. X    return from;
  171. X}
  172. X
  173. Xchar *
  174. Xcpy2(to,from,delim)
  175. Xregister char *to, *from;
  176. Xregister int delim;
  177. X{
  178. X    for (; *from; from++,to++) {
  179. X    if (*from == '\\' && from[1] == delim)
  180. X        *to++ = *from++;
  181. X    else if (*from == '$')
  182. X        *to++ = '\\';
  183. X    else if (*from == delim)
  184. X        break;
  185. X    *to = *from;
  186. X    }
  187. X    *to = '\0';
  188. X    return from;
  189. X}
  190. X
  191. X/* return ptr to little string in big string, NULL if not found */
  192. X
  193. Xchar *
  194. Xinstr(big, little)
  195. Xchar *big, *little;
  196. X
  197. X{
  198. X    register char *t, *s, *x;
  199. X
  200. X    for (t = big; *t; t++) {
  201. X    for (x=t,s=little; *s; x++,s++) {
  202. X        if (!*x)
  203. X        return Nullch;
  204. X        if (*s != *x)
  205. X        break;
  206. X    }
  207. X    if (!*s)
  208. X        return t;
  209. X    }
  210. X    return Nullch;
  211. X}
  212. X
  213. X/* copy a string to a safe spot */
  214. X
  215. Xchar *
  216. Xsavestr(str)
  217. Xchar *str;
  218. X{
  219. X    register char *newaddr = safemalloc((MEM_SIZE)(strlen(str)+1));
  220. X
  221. X    (void)strcpy(newaddr,str);
  222. X    return newaddr;
  223. X}
  224. X
  225. X/* grow a static string to at least a certain length */
  226. X
  227. Xvoid
  228. Xgrowstr(strptr,curlen,newlen)
  229. Xchar **strptr;
  230. Xint *curlen;
  231. Xint newlen;
  232. X{
  233. X    if (newlen > *curlen) {        /* need more room? */
  234. X    if (*curlen)
  235. X        *strptr = saferealloc(*strptr,(MEM_SIZE)newlen);
  236. X    else
  237. X        *strptr = safemalloc((MEM_SIZE)newlen);
  238. X    *curlen = newlen;
  239. X    }
  240. X}
  241. X
  242. X/*VARARGS1*/
  243. Xfatal(pat,a1,a2,a3,a4)
  244. Xchar *pat;
  245. X{
  246. X    fprintf(stderr,pat,a1,a2,a3,a4);
  247. X    exit(1);
  248. X}
  249. X
  250. Xstatic bool firstsetenv = TRUE;
  251. Xextern char **environ;
  252. X
  253. Xvoid
  254. Xsetenv(nam,val)
  255. Xchar *nam, *val;
  256. X{
  257. X    register int i=envix(nam);        /* where does it go? */
  258. X
  259. X    if (!environ[i]) {            /* does not exist yet */
  260. X    if (firstsetenv) {        /* need we copy environment? */
  261. X        int j;
  262. X#ifndef lint
  263. X        char **tmpenv = (char**)    /* point our wand at memory */
  264. X        safemalloc((i+2) * sizeof(char*));
  265. X#else
  266. X        char **tmpenv = Null(char **);
  267. X#endif /* lint */
  268. X    
  269. X        firstsetenv = FALSE;
  270. X        for (j=0; j<i; j++)        /* copy environment */
  271. X        tmpenv[j] = environ[j];
  272. X        environ = tmpenv;        /* tell exec where it is now */
  273. X    }
  274. X#ifndef lint
  275. X    else
  276. X        environ = (char**) saferealloc((char*) environ,
  277. X        (i+2) * sizeof(char*));
  278. X                    /* just expand it a bit */
  279. X#endif /* lint */
  280. X    environ[i+1] = Nullch;    /* make sure it's null terminated */
  281. X    }
  282. X    environ[i] = safemalloc(strlen(nam) + strlen(val) + 2);
  283. X                    /* this may or may not be in */
  284. X                    /* the old environ structure */
  285. X    sprintf(environ[i],"%s=%s",nam,val);/* all that work just for this */
  286. X}
  287. X
  288. Xint
  289. Xenvix(nam)
  290. Xchar *nam;
  291. X{
  292. X    register int i, len = strlen(nam);
  293. X
  294. X    for (i = 0; environ[i]; i++) {
  295. X    if (strnEQ(environ[i],nam,len) && environ[i][len] == '=')
  296. X        break;            /* strnEQ must come first to avoid */
  297. X    }                    /* potential SEGV's */
  298. X    return i;
  299. X}
  300. !STUFFY!FUNK!
  301. echo Extracting util.c
  302. sed >util.c <<'!STUFFY!FUNK!' -e 's/X//'
  303. X/* $Header: util.c,v 1.0 87/12/18 13:06:30 root Exp $
  304. X *
  305. X * $Log:    util.c,v $
  306. X * Revision 1.0  87/12/18  13:06:30  root
  307. X * Initial revision
  308. X * 
  309. X */
  310. X
  311. X#include <stdio.h>
  312. X
  313. X#include "handy.h"
  314. X#include "EXTERN.h"
  315. X#include "search.h"
  316. X#include "perl.h"
  317. X#include "INTERN.h"
  318. X#include "util.h"
  319. X
  320. X#define FLUSH
  321. X#define MEM_SIZE unsigned int
  322. X
  323. Xstatic char nomem[] = "Out of memory!\n";
  324. X
  325. X/* paranoid version of malloc */
  326. X
  327. Xstatic int an = 0;
  328. X
  329. Xchar *
  330. Xsafemalloc(size)
  331. XMEM_SIZE size;
  332. X{
  333. X    char *ptr;
  334. X    char *malloc();
  335. X
  336. X    ptr = malloc(size?size:1);    /* malloc(0) is NASTY on our system */
  337. X#ifdef DEBUGGING
  338. X    if (debug & 128)
  339. X    fprintf(stderr,"0x%x: (%05d) malloc %d bytes\n",ptr,an++,size);
  340. X#endif
  341. X    if (ptr != Nullch)
  342. X    return ptr;
  343. X    else {
  344. X    fputs(nomem,stdout) FLUSH;
  345. X    exit(1);
  346. X    }
  347. X    /*NOTREACHED*/
  348. X}
  349. X
  350. X/* paranoid version of realloc */
  351. X
  352. Xchar *
  353. Xsaferealloc(where,size)
  354. Xchar *where;
  355. XMEM_SIZE size;
  356. X{
  357. X    char *ptr;
  358. X    char *realloc();
  359. X
  360. X    ptr = realloc(where,size?size:1);    /* realloc(0) is NASTY on our system */
  361. X#ifdef DEBUGGING
  362. X    if (debug & 128) {
  363. X    fprintf(stderr,"0x%x: (%05d) rfree\n",where,an++);
  364. X    fprintf(stderr,"0x%x: (%05d) realloc %d bytes\n",ptr,an++,size);
  365. X    }
  366. X#endif
  367. X    if (ptr != Nullch)
  368. X    return ptr;
  369. X    else {
  370. X    fputs(nomem,stdout) FLUSH;
  371. X    exit(1);
  372. X    }
  373. X    /*NOTREACHED*/
  374. X}
  375. X
  376. X/* safe version of free */
  377. X
  378. Xsafefree(where)
  379. Xchar *where;
  380. X{
  381. X#ifdef DEBUGGING
  382. X    if (debug & 128)
  383. X    fprintf(stderr,"0x%x: (%05d) free\n",where,an++);
  384. X#endif
  385. X    free(where);
  386. X}
  387. X
  388. X/* safe version of string copy */
  389. X
  390. Xchar *
  391. Xsafecpy(to,from,len)
  392. Xchar *to;
  393. Xregister char *from;
  394. Xregister int len;
  395. X{
  396. X    register char *dest = to;
  397. X
  398. X    if (from != Nullch) 
  399. X    for (len--; len && (*dest++ = *from++); len--) ;
  400. X    *dest = '\0';
  401. X    return to;
  402. X}
  403. X
  404. X#ifdef undef
  405. X/* safe version of string concatenate, with \n deletion and space padding */
  406. X
  407. Xchar *
  408. Xsafecat(to,from,len)
  409. Xchar *to;
  410. Xregister char *from;
  411. Xregister int len;
  412. X{
  413. X    register char *dest = to;
  414. X
  415. X    len--;                /* leave room for null */
  416. X    if (*dest) {
  417. X    while (len && *dest++) len--;
  418. X    if (len) {
  419. X        len--;
  420. X        *(dest-1) = ' ';
  421. X    }
  422. X    }
  423. X    if (from != Nullch)
  424. X    while (len && (*dest++ = *from++)) len--;
  425. X    if (len)
  426. X    dest--;
  427. X    if (*(dest-1) == '\n')
  428. X    dest--;
  429. X    *dest = '\0';
  430. X    return to;
  431. X}
  432. X#endif
  433. X
  434. X/* copy a string up to some (non-backslashed) delimiter, if any */
  435. X
  436. Xchar *
  437. Xcpytill(to,from,delim)
  438. Xregister char *to, *from;
  439. Xregister int delim;
  440. X{
  441. X    for (; *from; from++,to++) {
  442. X    if (*from == '\\' && from[1] == delim)
  443. X        from++;
  444. X    else if (*from == delim)
  445. X        break;
  446. X    *to = *from;
  447. X    }
  448. X    *to = '\0';
  449. X    return from;
  450. X}
  451. X
  452. X/* return ptr to little string in big string, NULL if not found */
  453. X
  454. Xchar *
  455. Xinstr(big, little)
  456. Xchar *big, *little;
  457. X
  458. X{
  459. X    register char *t, *s, *x;
  460. X
  461. X    for (t = big; *t; t++) {
  462. X    for (x=t,s=little; *s; x++,s++) {
  463. X        if (!*x)
  464. X        return Nullch;
  465. X        if (*s != *x)
  466. X        break;
  467. X    }
  468. X    if (!*s)
  469. X        return t;
  470. X    }
  471. X    return Nullch;
  472. X}
  473. X
  474. X/* copy a string to a safe spot */
  475. X
  476. Xchar *
  477. Xsavestr(str)
  478. Xchar *str;
  479. X{
  480. X    register char *newaddr = safemalloc((MEM_SIZE)(strlen(str)+1));
  481. X
  482. X    (void)strcpy(newaddr,str);
  483. X    return newaddr;
  484. X}
  485. X
  486. X/* grow a static string to at least a certain length */
  487. X
  488. Xvoid
  489. Xgrowstr(strptr,curlen,newlen)
  490. Xchar **strptr;
  491. Xint *curlen;
  492. Xint newlen;
  493. X{
  494. X    if (newlen > *curlen) {        /* need more room? */
  495. X    if (*curlen)
  496. X        *strptr = saferealloc(*strptr,(MEM_SIZE)newlen);
  497. X    else
  498. X        *strptr = safemalloc((MEM_SIZE)newlen);
  499. X    *curlen = newlen;
  500. X    }
  501. X}
  502. X
  503. X/*VARARGS1*/
  504. Xfatal(pat,a1,a2,a3,a4)
  505. Xchar *pat;
  506. X{
  507. X    extern FILE *e_fp;
  508. X    extern char *e_tmpname;
  509. X
  510. X    fprintf(stderr,pat,a1,a2,a3,a4);
  511. X    if (e_fp)
  512. X    UNLINK(e_tmpname);
  513. X    exit(1);
  514. X}
  515. X
  516. Xstatic bool firstsetenv = TRUE;
  517. Xextern char **environ;
  518. X
  519. Xvoid
  520. Xsetenv(nam,val)
  521. Xchar *nam, *val;
  522. X{
  523. X    register int i=envix(nam);        /* where does it go? */
  524. X
  525. X    if (!environ[i]) {            /* does not exist yet */
  526. X    if (firstsetenv) {        /* need we copy environment? */
  527. X        int j;
  528. X#ifndef lint
  529. X        char **tmpenv = (char**)    /* point our wand at memory */
  530. X        safemalloc((i+2) * sizeof(char*));
  531. X#else
  532. X        char **tmpenv = Null(char **);
  533. X#endif /* lint */
  534. X    
  535. X        firstsetenv = FALSE;
  536. X        for (j=0; j<i; j++)        /* copy environment */
  537. X        tmpenv[j] = environ[j];
  538. X        environ = tmpenv;        /* tell exec where it is now */
  539. X    }
  540. X#ifndef lint
  541. X    else
  542. X        environ = (char**) saferealloc((char*) environ,
  543. X        (i+2) * sizeof(char*));
  544. X                    /* just expand it a bit */
  545. X#endif /* lint */
  546. X    environ[i+1] = Nullch;    /* make sure it's null terminated */
  547. X    }
  548. X    environ[i] = safemalloc(strlen(nam) + strlen(val) + 2);
  549. X                    /* this may or may not be in */
  550. X                    /* the old environ structure */
  551. X    sprintf(environ[i],"%s=%s",nam,val);/* all that work just for this */
  552. X}
  553. X
  554. Xint
  555. Xenvix(nam)
  556. Xchar *nam;
  557. X{
  558. X    register int i, len = strlen(nam);
  559. X
  560. X    for (i = 0; environ[i]; i++) {
  561. X    if (strnEQ(environ[i],nam,len) && environ[i][len] == '=')
  562. X        break;            /* strnEQ must come first to avoid */
  563. X    }                    /* potential SEGV's */
  564. X    return i;
  565. X}
  566. !STUFFY!FUNK!
  567. echo Extracting hash.c
  568. sed >hash.c <<'!STUFFY!FUNK!' -e 's/X//'
  569. X/* $Header: hash.c,v 1.0 87/12/18 13:05:17 root Exp $
  570. X *
  571. X * $Log:    hash.c,v $
  572. X * Revision 1.0  87/12/18  13:05:17  root
  573. X * Initial revision
  574. X * 
  575. X */
  576. X
  577. X#include <stdio.h>
  578. X#include "EXTERN.h"
  579. X#include "handy.h"
  580. X#include "util.h"
  581. X#include "search.h"
  582. X#include "perl.h"
  583. X
  584. XSTR *
  585. Xhfetch(tb,key)
  586. Xregister HASH *tb;
  587. Xchar *key;
  588. X{
  589. X    register char *s;
  590. X    register int i;
  591. X    register int hash;
  592. X    register HENT *entry;
  593. X
  594. X    if (!tb)
  595. X    return Nullstr;
  596. X    for (s=key,        i=0,    hash = 0;
  597. X      /* while */ *s;
  598. X     s++,        i++,    hash *= 5) {
  599. X    hash += *s * coeff[i];
  600. X    }
  601. X    entry = tb->tbl_array[hash & tb->tbl_max];
  602. X    for (; entry; entry = entry->hent_next) {
  603. X    if (entry->hent_hash != hash)        /* strings can't be equal */
  604. X        continue;
  605. X    if (strNE(entry->hent_key,key))    /* is this it? */
  606. X        continue;
  607. X    return entry->hent_val;
  608. X    }
  609. X    return Nullstr;
  610. X}
  611. X
  612. Xbool
  613. Xhstore(tb,key,val)
  614. Xregister HASH *tb;
  615. Xchar *key;
  616. XSTR *val;
  617. X{
  618. X    register char *s;
  619. X    register int i;
  620. X    register int hash;
  621. X    register HENT *entry;
  622. X    register HENT **oentry;
  623. X
  624. X    if (!tb)
  625. X    return FALSE;
  626. X    for (s=key,        i=0,    hash = 0;
  627. X      /* while */ *s;
  628. X     s++,        i++,    hash *= 5) {
  629. X    hash += *s * coeff[i];
  630. X    }
  631. X
  632. X    oentry = &(tb->tbl_array[hash & tb->tbl_max]);
  633. X    i = 1;
  634. X
  635. X    for (entry = *oentry; entry; i=0, entry = entry->hent_next) {
  636. X    if (entry->hent_hash != hash)        /* strings can't be equal */
  637. X        continue;
  638. X    if (strNE(entry->hent_key,key))    /* is this it? */
  639. X        continue;
  640. X    safefree((char*)entry->hent_val);
  641. X    entry->hent_val = val;
  642. X    return TRUE;
  643. X    }
  644. X    entry = (HENT*) safemalloc(sizeof(HENT));
  645. X
  646. X    entry->hent_key = savestr(key);
  647. X    entry->hent_val = val;
  648. X    entry->hent_hash = hash;
  649. X    entry->hent_next = *oentry;
  650. X    *oentry = entry;
  651. X
  652. X    if (i) {                /* initial entry? */
  653. X    tb->tbl_fill++;
  654. X    if ((tb->tbl_fill * 100 / (tb->tbl_max + 1)) > FILLPCT)
  655. X        hsplit(tb);
  656. X    }
  657. X
  658. X    return FALSE;
  659. X}
  660. X
  661. X#ifdef NOTUSED
  662. Xbool
  663. Xhdelete(tb,key)
  664. Xregister HASH *tb;
  665. Xchar *key;
  666. X{
  667. X    register char *s;
  668. X    register int i;
  669. X    register int hash;
  670. X    register HENT *entry;
  671. X    register HENT **oentry;
  672. X
  673. X    if (!tb)
  674. X    return FALSE;
  675. X    for (s=key,        i=0,    hash = 0;
  676. X      /* while */ *s;
  677. X     s++,        i++,    hash *= 5) {
  678. X    hash += *s * coeff[i];
  679. X    }
  680. X
  681. X    oentry = &(tb->tbl_array[hash & tb->tbl_max]);
  682. X    entry = *oentry;
  683. X    i = 1;
  684. X    for (; entry; i=0, oentry = &entry->hent_next, entry = entry->hent_next) {
  685. X    if (entry->hent_hash != hash)        /* strings can't be equal */
  686. X        continue;
  687. X    if (strNE(entry->hent_key,key))    /* is this it? */
  688. X        continue;
  689. X    safefree((char*)entry->hent_val);
  690. X    safefree(entry->hent_key);
  691. X    *oentry = entry->hent_next;
  692. X    safefree((char*)entry);
  693. X    if (i)
  694. X        tb->tbl_fill--;
  695. X    return TRUE;
  696. X    }
  697. X    return FALSE;
  698. X}
  699. X#endif
  700. X
  701. Xhsplit(tb)
  702. XHASH *tb;
  703. X{
  704. X    int oldsize = tb->tbl_max + 1;
  705. X    register int newsize = oldsize * 2;
  706. X    register int i;
  707. X    register HENT **a;
  708. X    register HENT **b;
  709. X    register HENT *entry;
  710. X    register HENT **oentry;
  711. X
  712. X    a = (HENT**) saferealloc((char*)tb->tbl_array, newsize * sizeof(HENT*));
  713. X    bzero((char*)&a[oldsize], oldsize * sizeof(HENT*)); /* zero second half */
  714. X    tb->tbl_max = --newsize;
  715. X    tb->tbl_array = a;
  716. X
  717. X    for (i=0; i<oldsize; i++,a++) {
  718. X    if (!*a)                /* non-existent */
  719. X        continue;
  720. X    b = a+oldsize;
  721. X    for (oentry = a, entry = *a; entry; entry = *oentry) {
  722. X        if ((entry->hent_hash & newsize) != i) {
  723. X        *oentry = entry->hent_next;
  724. X        entry->hent_next = *b;
  725. X        if (!*b)
  726. X            tb->tbl_fill++;
  727. X        *b = entry;
  728. X        continue;
  729. X        }
  730. X        else
  731. X        oentry = &entry->hent_next;
  732. X    }
  733. X    if (!*a)                /* everything moved */
  734. X        tb->tbl_fill--;
  735. X    }
  736. X}
  737. X
  738. XHASH *
  739. Xhnew()
  740. X{
  741. X    register HASH *tb = (HASH*)safemalloc(sizeof(HASH));
  742. X
  743. X    tb->tbl_array = (HENT**) safemalloc(8 * sizeof(HENT*));
  744. X    tb->tbl_fill = 0;
  745. X    tb->tbl_max = 7;
  746. X    hiterinit(tb);    /* so each() will start off right */
  747. X    bzero((char*)tb->tbl_array, 8 * sizeof(HENT*));
  748. X    return tb;
  749. X}
  750. X
  751. X#ifdef NOTUSED
  752. Xhshow(tb)
  753. Xregister HASH *tb;
  754. X{
  755. X    fprintf(stderr,"%5d %4d (%2d%%)\n",
  756. X    tb->tbl_max+1,
  757. X    tb->tbl_fill,
  758. X    tb->tbl_fill * 100 / (tb->tbl_max+1));
  759. X}
  760. X#endif
  761. X
  762. Xhiterinit(tb)
  763. Xregister HASH *tb;
  764. X{
  765. X    tb->tbl_riter = -1;
  766. X    tb->tbl_eiter = Null(HENT*);
  767. X    return tb->tbl_fill;
  768. X}
  769. X
  770. XHENT *
  771. Xhiternext(tb)
  772. Xregister HASH *tb;
  773. X{
  774. X    register HENT *entry;
  775. X
  776. X    entry = tb->tbl_eiter;
  777. X    do {
  778. X    if (entry)
  779. X        entry = entry->hent_next;
  780. X    if (!entry) {
  781. X        tb->tbl_riter++;
  782. X        if (tb->tbl_riter > tb->tbl_max) {
  783. X        tb->tbl_riter = -1;
  784. X        break;
  785. X        }
  786. X        entry = tb->tbl_array[tb->tbl_riter];
  787. X    }
  788. X    } while (!entry);
  789. X
  790. X    tb->tbl_eiter = entry;
  791. X    return entry;
  792. X}
  793. X
  794. Xchar *
  795. Xhiterkey(entry)
  796. Xregister HENT *entry;
  797. X{
  798. X    return entry->hent_key;
  799. X}
  800. X
  801. XSTR *
  802. Xhiterval(entry)
  803. Xregister HENT *entry;
  804. X{
  805. X    return entry->hent_val;
  806. X}
  807. !STUFFY!FUNK!
  808. echo Extracting x2p/hash.c
  809. sed >x2p/hash.c <<'!STUFFY!FUNK!' -e 's/X//'
  810. X/* $Header: hash.c,v 1.0 87/12/18 13:07:18 root Exp $
  811. X *
  812. X * $Log:    hash.c,v $
  813. X * Revision 1.0  87/12/18  13:07:18  root
  814. X * Initial revision
  815. X * 
  816. X */
  817. X
  818. X#include <stdio.h>
  819. X#include "EXTERN.h"
  820. X#include "handy.h"
  821. X#include "util.h"
  822. X#include "a2p.h"
  823. X
  824. XSTR *
  825. Xhfetch(tb,key)
  826. Xregister HASH *tb;
  827. Xchar *key;
  828. X{
  829. X    register char *s;
  830. X    register int i;
  831. X    register int hash;
  832. X    register HENT *entry;
  833. X
  834. X    if (!tb)
  835. X    return Nullstr;
  836. X    for (s=key,        i=0,    hash = 0;
  837. X      /* while */ *s;
  838. X     s++,        i++,    hash *= 5) {
  839. X    hash += *s * coeff[i];
  840. X    }
  841. X    entry = tb->tbl_array[hash & tb->tbl_max];
  842. X    for (; entry; entry = entry->hent_next) {
  843. X    if (entry->hent_hash != hash)        /* strings can't be equal */
  844. X        continue;
  845. X    if (strNE(entry->hent_key,key))    /* is this it? */
  846. X        continue;
  847. X    return entry->hent_val;
  848. X    }
  849. X    return Nullstr;
  850. X}
  851. X
  852. Xbool
  853. Xhstore(tb,key,val)
  854. Xregister HASH *tb;
  855. Xchar *key;
  856. XSTR *val;
  857. X{
  858. X    register char *s;
  859. X    register int i;
  860. X    register int hash;
  861. X    register HENT *entry;
  862. X    register HENT **oentry;
  863. X
  864. X    if (!tb)
  865. X    return FALSE;
  866. X    for (s=key,        i=0,    hash = 0;
  867. X      /* while */ *s;
  868. X     s++,        i++,    hash *= 5) {
  869. X    hash += *s * coeff[i];
  870. X    }
  871. X
  872. X    oentry = &(tb->tbl_array[hash & tb->tbl_max]);
  873. X    i = 1;
  874. X
  875. X    for (entry = *oentry; entry; i=0, entry = entry->hent_next) {
  876. X    if (entry->hent_hash != hash)        /* strings can't be equal */
  877. X        continue;
  878. X    if (strNE(entry->hent_key,key))    /* is this it? */
  879. X        continue;
  880. X    safefree((char*)entry->hent_val);
  881. X    entry->hent_val = val;
  882. X    return TRUE;
  883. X    }
  884. X    entry = (HENT*) safemalloc(sizeof(HENT));
  885. X
  886. X    entry->hent_key = savestr(key);
  887. X    entry->hent_val = val;
  888. X    entry->hent_hash = hash;
  889. X    entry->hent_next = *oentry;
  890. X    *oentry = entry;
  891. X
  892. X    if (i) {                /* initial entry? */
  893. X    tb->tbl_fill++;
  894. X    if ((tb->tbl_fill * 100 / (tb->tbl_max + 1)) > FILLPCT)
  895. X        hsplit(tb);
  896. X    }
  897. X
  898. X    return FALSE;
  899. X}
  900. X
  901. X#ifdef NOTUSED
  902. Xbool
  903. Xhdelete(tb,key)
  904. Xregister HASH *tb;
  905. Xchar *key;
  906. X{
  907. X    register char *s;
  908. X    register int i;
  909. X    register int hash;
  910. X    register HENT *entry;
  911. X    register HENT **oentry;
  912. X
  913. X    if (!tb)
  914. X    return FALSE;
  915. X    for (s=key,        i=0,    hash = 0;
  916. X      /* while */ *s;
  917. X     s++,        i++,    hash *= 5) {
  918. X    hash += *s * coeff[i];
  919. X    }
  920. X
  921. X    oentry = &(tb->tbl_array[hash & tb->tbl_max]);
  922. X    entry = *oentry;
  923. X    i = 1;
  924. X    for (; entry; i=0, oentry = &entry->hent_next, entry = entry->hent_next) {
  925. X    if (entry->hent_hash != hash)        /* strings can't be equal */
  926. X        continue;
  927. X    if (strNE(entry->hent_key,key))    /* is this it? */
  928. X        continue;
  929. X    safefree((char*)entry->hent_val);
  930. X    safefree(entry->hent_key);
  931. X    *oentry = entry->hent_next;
  932. X    safefree((char*)entry);
  933. X    if (i)
  934. X        tb->tbl_fill--;
  935. X    return TRUE;
  936. X    }
  937. X    return FALSE;
  938. X}
  939. X#endif
  940. X
  941. Xhsplit(tb)
  942. XHASH *tb;
  943. X{
  944. X    int oldsize = tb->tbl_max + 1;
  945. X    register int newsize = oldsize * 2;
  946. X    register int i;
  947. X    register HENT **a;
  948. X    register HENT **b;
  949. X    register HENT *entry;
  950. X    register HENT **oentry;
  951. X
  952. X    a = (HENT**) saferealloc((char*)tb->tbl_array, newsize * sizeof(HENT*));
  953. X    bzero((char*)&a[oldsize], oldsize * sizeof(HENT*)); /* zero second half */
  954. X    tb->tbl_max = --newsize;
  955. X    tb->tbl_array = a;
  956. X
  957. X    for (i=0; i<oldsize; i++,a++) {
  958. X    if (!*a)                /* non-existent */
  959. X        continue;
  960. X    b = a+oldsize;
  961. X    for (oentry = a, entry = *a; entry; entry = *oentry) {
  962. X        if ((entry->hent_hash & newsize) != i) {
  963. X        *oentry = entry->hent_next;
  964. X        entry->hent_next = *b;
  965. X        if (!*b)
  966. X            tb->tbl_fill++;
  967. X        *b = entry;
  968. X        continue;
  969. X        }
  970. X        else
  971. X        oentry = &entry->hent_next;
  972. X    }
  973. X    if (!*a)                /* everything moved */
  974. X        tb->tbl_fill--;
  975. X    }
  976. X}
  977. X
  978. XHASH *
  979. Xhnew()
  980. X{
  981. X    register HASH *tb = (HASH*)safemalloc(sizeof(HASH));
  982. X
  983. X    tb->tbl_array = (HENT**) safemalloc(8 * sizeof(HENT*));
  984. X    tb->tbl_fill = 0;
  985. X    tb->tbl_max = 7;
  986. X    hiterinit(tb);    /* so each() will start off right */
  987. X    bzero((char*)tb->tbl_array, 8 * sizeof(HENT*));
  988. X    return tb;
  989. X}
  990. X
  991. X#ifdef NOTUSED
  992. Xhshow(tb)
  993. Xregister HASH *tb;
  994. X{
  995. X    fprintf(stderr,"%5d %4d (%2d%%)\n",
  996. X    tb->tbl_max+1,
  997. X    tb->tbl_fill,
  998. X    tb->tbl_fill * 100 / (tb->tbl_max+1));
  999. X}
  1000. X#endif
  1001. X
  1002. Xhiterinit(tb)
  1003. Xregister HASH *tb;
  1004. X{
  1005. X    tb->tbl_riter = -1;
  1006. X    tb->tbl_eiter = Null(HENT*);
  1007. X    return tb->tbl_fill;
  1008. X}
  1009. X
  1010. XHENT *
  1011. Xhiternext(tb)
  1012. Xregister HASH *tb;
  1013. X{
  1014. X    register HENT *entry;
  1015. X
  1016. X    entry = tb->tbl_eiter;
  1017. X    do {
  1018. X    if (entry)
  1019. X        entry = entry->hent_next;
  1020. X    if (!entry) {
  1021. X        tb->tbl_riter++;
  1022. X        if (tb->tbl_riter > tb->tbl_max) {
  1023. X        tb->tbl_riter = -1;
  1024. X        break;
  1025. X        }
  1026. X        entry = tb->tbl_array[tb->tbl_riter];
  1027. X    }
  1028. X    } while (!entry);
  1029. X
  1030. X    tb->tbl_eiter = entry;
  1031. X    return entry;
  1032. X}
  1033. X
  1034. Xchar *
  1035. Xhiterkey(entry)
  1036. Xregister HENT *entry;
  1037. X{
  1038. X    return entry->hent_key;
  1039. X}
  1040. X
  1041. XSTR *
  1042. Xhiterval(entry)
  1043. Xregister HENT *entry;
  1044. X{
  1045. X    return entry->hent_val;
  1046. X}
  1047. !STUFFY!FUNK!
  1048. echo Extracting makedepend.SH
  1049. sed >makedepend.SH <<'!STUFFY!FUNK!' -e 's/X//'
  1050. Xcase $CONFIG in
  1051. X'')
  1052. X    if test ! -f config.sh; then
  1053. X    ln ../config.sh . || \
  1054. X    ln ../../config.sh . || \
  1055. X    ln ../../../config.sh . || \
  1056. X    (echo "Can't find config.sh."; exit 1)
  1057. X    fi
  1058. X    . config.sh
  1059. X    ;;
  1060. Xesac
  1061. Xcase "$0" in
  1062. X*/*) cd `expr X$0 : 'X\(.*\)/'` ;;
  1063. Xesac
  1064. Xecho "Extracting makedepend (with variable substitutions)"
  1065. X$spitshell >makedepend <<!GROK!THIS!
  1066. X$startsh
  1067. X# $Header: makedepend.SH,v 1.0 87/12/18 17:54:32 root Exp $
  1068. X#
  1069. X# $Log:    makedepend.SH,v $
  1070. X# Revision 1.0  87/12/18  17:54:32  root
  1071. X# Initial revision
  1072. X# 
  1073. X# 
  1074. X
  1075. Xexport PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh \$0; kill \$\$)
  1076. X
  1077. Xcat='$cat'
  1078. Xcp='$cp'
  1079. Xcpp='$cpp'
  1080. Xecho='$echo'
  1081. Xegrep='$egrep'
  1082. Xexpr='$expr'
  1083. Xmv='$mv'
  1084. Xrm='$rm'
  1085. Xsed='$sed'
  1086. Xsort='$sort'
  1087. Xtest='$test'
  1088. Xtr='$tr'
  1089. Xuniq='$uniq'
  1090. X!GROK!THIS!
  1091. X
  1092. X$spitshell >>makedepend <<'!NO!SUBS!'
  1093. X
  1094. X$cat /dev/null >.deptmp
  1095. X$rm -f *.c.c c/*.c.c
  1096. Xif test -f Makefile; then
  1097. X    mf=Makefile
  1098. Xelse
  1099. X    mf=makefile
  1100. Xfi
  1101. Xif test -f $mf; then
  1102. X    defrule=`<$mf sed -n        \
  1103. X    -e '/^\.c\.o:.*;/{'        \
  1104. X    -e    's/\$\*\.c//'        \
  1105. X    -e    's/^[^;]*;[     ]*//p'    \
  1106. X    -e    q                \
  1107. X    -e '}'                \
  1108. X    -e '/^\.c\.o: *$/{'        \
  1109. X    -e    N                \
  1110. X    -e    's/\$\*\.c//'        \
  1111. X    -e    's/^.*\n[     ]*//p'        \
  1112. X    -e    q                \
  1113. X    -e '}'`
  1114. Xfi
  1115. Xcase "$defrule" in
  1116. X'') defrule='$(CC) -c $(CFLAGS)' ;;
  1117. Xesac
  1118. X
  1119. Xmake clist || ($echo "Searching for .c files..."; \
  1120. X    $echo *.c */*.c | $tr ' ' '\012' | $egrep -v '\*' >.clist)
  1121. Xfor file in `$cat .clist`; do
  1122. X# for file in `cat /dev/null`; do
  1123. X    case "$file" in
  1124. X    *.c) filebase=`basename $file .c` ;;
  1125. X    *.y) filebase=`basename $file .c` ;;
  1126. X    esac
  1127. X    $echo "Finding dependencies for $filebase.o."
  1128. X    $sed -n <$file >$file.c \
  1129. X    -e "/^${filebase}_init(/q" \
  1130. X    -e '/^#/{' \
  1131. X    -e 's|/\*.*$||' \
  1132. X    -e 's|\\$||' \
  1133. X    -e p \
  1134. X    -e '}'
  1135. X    $cpp -I/usr/local/include -I. -I./h $file.c | \
  1136. X    $sed \
  1137. X    -e '/^# *[0-9]/!d' \
  1138. X    -e 's/^.*"\(.*\)".*$/'$filebase'.o: \1/' \
  1139. X    -e 's|: \./|: |' \
  1140. X    -e 's|\.c\.c|.c|' | \
  1141. X    $uniq | $sort | $uniq >> .deptmp
  1142. Xdone
  1143. X
  1144. X$sed <Makefile >Makefile.new -e '1,/^# AUTOMATICALLY/!d'
  1145. X
  1146. Xmake shlist || ($echo "Searching for .SH files..."; \
  1147. X    $echo *.SH */*.SH | $tr ' ' '\012' | $egrep -v '\*' >.shlist)
  1148. Xif $test -s .deptmp; then
  1149. X    for file in `cat .shlist`; do
  1150. X    $echo `$expr X$file : 'X\(.*\).SH`: $file config.sh \; \
  1151. X        /bin/sh $file >> .deptmp
  1152. X    done
  1153. X    $echo "Updating Makefile..."
  1154. X    $echo "# If this runs make out of memory, delete /usr/include lines." \
  1155. X    >> Makefile.new
  1156. X    $sed 's|^\(.*\.o:\) *\(.*/.*\.c\) *$|\1 \2; '"$defrule \2|" .deptmp \
  1157. X       >>Makefile.new
  1158. Xelse
  1159. X    make hlist || ($echo "Searching for .h files..."; \
  1160. X    $echo *.h */*.h | $tr ' ' '\012' | $egrep -v '\*' >.hlist)
  1161. X    $echo "You don't seem to have a proper C preprocessor.  Using grep instead."
  1162. X    $egrep '^#include ' `cat .clist` `cat .hlist`  >.deptmp
  1163. X    $echo "Updating Makefile..."
  1164. X    <.clist $sed -n                            \
  1165. X    -e '/\//{'                            \
  1166. X    -e   's|^\(.*\)/\(.*\)\.c|\2.o: \1/\2.c; '"$defrule \1/\2.c|p"    \
  1167. X    -e   d                                \
  1168. X    -e '}'                                \
  1169. X    -e 's|^\(.*\)\.c|\1.o: \1.c|p' >> Makefile.new
  1170. X    <.hlist $sed -n 's|\(.*/\)\(.*\)|s= \2= \1\2=|p' >.hsed
  1171. X    <.deptmp $sed -n 's|c:#include "\(.*\)".*$|o: \1|p' | \
  1172. X       $sed 's|^[^;]*/||' | \
  1173. X       $sed -f .hsed >> Makefile.new
  1174. X    <.deptmp $sed -n 's|c:#include <\(.*\)>.*$|o: /usr/include/\1|p' \
  1175. X       >> Makefile.new
  1176. X    <.deptmp $sed -n 's|h:#include "\(.*\)".*$|h: \1|p' | \
  1177. X       $sed -f .hsed >> Makefile.new
  1178. X    <.deptmp $sed -n 's|h:#include <\(.*\)>.*$|h: /usr/include/\1|p' \
  1179. X       >> Makefile.new
  1180. X    for file in `$cat .shlist`; do
  1181. X    $echo `$expr X$file : 'X\(.*\).SH`: $file config.sh \; \
  1182. X        /bin/sh $file >> Makefile.new
  1183. X    done
  1184. Xfi
  1185. X$rm -f Makefile.old
  1186. X$cp Makefile Makefile.old
  1187. X$cp Makefile.new Makefile
  1188. X$rm Makefile.new
  1189. X$echo "# WARNING: Put nothing here or make depend will gobble it up!" >> Makefile
  1190. X$rm -f .deptmp `sed 's/\.c/.c.c/' .clist` .shlist .clist .hlist .hsed
  1191. X
  1192. X!NO!SUBS!
  1193. X$eunicefix makedepend
  1194. Xchmod 755 makedepend
  1195. Xcase `pwd` in
  1196. X*SH)
  1197. X    $rm -f ../makedepend
  1198. X    ln makedepend ../makedepend
  1199. X    ;;
  1200. Xesac
  1201. !STUFFY!FUNK!
  1202. echo Extracting perl.h
  1203. sed >perl.h <<'!STUFFY!FUNK!' -e 's/X//'
  1204. X/* $Header: perl.h,v 1.0 87/12/18 13:05:38 root Exp $
  1205. X *
  1206. X * $Log:    perl.h,v $
  1207. X * Revision 1.0  87/12/18  13:05:38  root
  1208. X * Initial revision
  1209. X * 
  1210. X */
  1211. X
  1212. X#define DEBUGGING
  1213. X#define STDSTDIO    /* eventually should be in config.h */
  1214. X
  1215. X#define VOIDUSED 1
  1216. X#include "config.h"
  1217. X
  1218. X#ifndef BCOPY
  1219. X#   define bcopy(s1,s2,l) memcpy(s2,s1,l);
  1220. X#   define bzero(s,l) memset(s,0,l);
  1221. X#endif
  1222. X
  1223. X#include <stdio.h>
  1224. X#include <ctype.h>
  1225. X#include <setjmp.h>
  1226. X#include <sys/types.h>
  1227. X#include <sys/stat.h>
  1228. X#include <time.h>
  1229. X#include <sys/times.h>
  1230. X
  1231. Xtypedef struct arg ARG;
  1232. Xtypedef struct cmd CMD;
  1233. Xtypedef struct formcmd FCMD;
  1234. Xtypedef struct scanpat SPAT;
  1235. Xtypedef struct stab STAB;
  1236. Xtypedef struct stio STIO;
  1237. Xtypedef struct string STR;
  1238. Xtypedef struct atbl ARRAY;
  1239. Xtypedef struct htbl HASH;
  1240. X
  1241. X#include "str.h"
  1242. X#include "form.h"
  1243. X#include "stab.h"
  1244. X#include "spat.h"
  1245. X#include "arg.h"
  1246. X#include "cmd.h"
  1247. X#include "array.h"
  1248. X#include "hash.h"
  1249. X
  1250. X/* A string is TRUE if not "" or "0". */
  1251. X#define True(val) (tmps = (val), (*tmps && !(*tmps == '0' && !tmps[1])))
  1252. XEXT char *Yes INIT("1");
  1253. XEXT char *No INIT("");
  1254. X
  1255. X#define str_true(str) (Str = (str), (Str->str_pok ? True(Str->str_ptr) : (Str->str_nok ? (Str->str_nval != 0.0) : 0 )))
  1256. X
  1257. X#define str_peek(str) (Str = (str), (Str->str_pok ? Str->str_ptr : (Str->str_nok ? (sprintf(buf,"num(%g)",Str->str_nval),buf) : "" )))
  1258. X#define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
  1259. X#define str_gnum(str) (Str = (str), (Str->str_nok ? Str->str_nval : str_2num(Str)))
  1260. XEXT STR *Str;
  1261. X
  1262. X#define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
  1263. X
  1264. XCMD *add_label();
  1265. XCMD *block_head();
  1266. XCMD *append_line();
  1267. XCMD *make_acmd();
  1268. XCMD *make_ccmd();
  1269. XCMD *invert();
  1270. XCMD *addcond();
  1271. XCMD *addloop();
  1272. XCMD *wopt();
  1273. X
  1274. XSPAT *stab_to_spat();
  1275. X
  1276. XSTAB *stabent();
  1277. X
  1278. XARG *stab_to_arg();
  1279. XARG *op_new();
  1280. XARG *make_op();
  1281. XARG *make_lval();
  1282. XARG *make_match();
  1283. XARG *make_split();
  1284. XARG *flipflip();
  1285. X
  1286. XSTR *arg_to_str();
  1287. XSTR *str_new();
  1288. XSTR *stab_str();
  1289. XSTR *eval();
  1290. X
  1291. XFCMD *load_format();
  1292. X
  1293. Xchar *scanpat();
  1294. Xchar *scansubst();
  1295. Xchar *scantrans();
  1296. Xchar *scanstr();
  1297. Xchar *scanreg();
  1298. Xchar *reg_get();
  1299. Xchar *str_append_till();
  1300. Xchar *str_gets();
  1301. X
  1302. Xbool do_match();
  1303. Xbool do_open();
  1304. Xbool do_close();
  1305. Xbool do_print();
  1306. X
  1307. Xint do_subst();
  1308. X
  1309. Xvoid str_free();
  1310. Xvoid freearg();
  1311. X
  1312. XEXT int line INIT(0);
  1313. XEXT int arybase INIT(0);
  1314. X
  1315. Xstruct outrec {
  1316. X    int o_lines;
  1317. X    char *o_str;
  1318. X    int o_len;
  1319. X};
  1320. X
  1321. XEXT struct outrec outrec;
  1322. XEXT struct outrec toprec;
  1323. X
  1324. XEXT STAB *last_in_stab INIT(Nullstab);
  1325. XEXT STAB *defstab INIT(Nullstab);
  1326. XEXT STAB *argvstab INIT(Nullstab);
  1327. XEXT STAB *envstab INIT(Nullstab);
  1328. XEXT STAB *sigstab INIT(Nullstab);
  1329. XEXT STAB *defoutstab INIT(Nullstab);
  1330. XEXT STAB *curoutstab INIT(Nullstab);
  1331. XEXT STAB *argvoutstab INIT(Nullstab);
  1332. X
  1333. XEXT STR *freestrroot INIT(Nullstr);
  1334. X
  1335. XEXT FILE *rsfp;
  1336. XEXT char buf[1024];
  1337. XEXT char *bufptr INIT(buf);
  1338. X
  1339. XEXT STR *linestr INIT(Nullstr);
  1340. X
  1341. XEXT char record_separator INIT('\n');
  1342. XEXT char *ofs INIT(Nullch);
  1343. XEXT char *ors INIT(Nullch);
  1344. XEXT char *ofmt INIT(Nullch);
  1345. XEXT char *inplace INIT(Nullch);
  1346. X
  1347. XEXT char tokenbuf[256];
  1348. XEXT int expectterm INIT(TRUE);
  1349. XEXT int lex_newlines INIT(FALSE);
  1350. X
  1351. XFILE *popen();
  1352. X/* char *str_get(); */
  1353. XSTR *interp();
  1354. Xvoid free_arg();
  1355. XSTIO *stio_new();
  1356. X
  1357. XEXT struct stat statbuf;
  1358. XEXT struct tms timesbuf;
  1359. X
  1360. X#ifdef DEBUGGING
  1361. XEXT int debug INIT(0);
  1362. XEXT int dlevel INIT(0);
  1363. XEXT char debname[40];
  1364. XEXT char debdelim[40];
  1365. X#define YYDEBUG;
  1366. Xextern int yydebug;
  1367. X#endif
  1368. X
  1369. XEXT STR str_no;
  1370. XEXT STR str_yes;
  1371. X
  1372. X/* runtime control stuff */
  1373. X
  1374. XEXT struct loop {
  1375. X    char *loop_label;
  1376. X    jmp_buf loop_env;
  1377. X} loop_stack[32];
  1378. X
  1379. XEXT int loop_ptr INIT(-1);
  1380. X
  1381. XEXT jmp_buf top_env;
  1382. X
  1383. XEXT char *goto_targ INIT(Nullch);    /* cmd_exec gets strange when set */
  1384. X
  1385. Xdouble atof();
  1386. Xlong time();
  1387. Xstruct tm *gmtime(), *localtime();
  1388. X
  1389. X#ifdef CHARSPRINTF
  1390. X    char *sprintf();
  1391. X#else
  1392. X    int sprintf();
  1393. X#endif
  1394. X
  1395. X#ifdef EUNICE
  1396. X#define UNLINK(f) while (unlink(f) >= 0)
  1397. X#else
  1398. X#define UNLINK unlink
  1399. X#endif
  1400. !STUFFY!FUNK!
  1401. echo Extracting config.h.SH
  1402. sed >config.h.SH <<'!STUFFY!FUNK!' -e 's/X//'
  1403. Xcase $CONFIG in
  1404. X'')
  1405. X    if test ! -f config.sh; then
  1406. X    ln ../config.sh . || \
  1407. X    ln ../../config.sh . || \
  1408. X    ln ../../../config.sh . || \
  1409. X    (echo "Can't find config.sh."; exit 1)
  1410. X    echo "Using config.sh from above..."
  1411. X    fi
  1412. X    . config.sh
  1413. X    ;;
  1414. Xesac
  1415. Xecho "Extracting config.h (with variable substitutions)"
  1416. Xcat <<!GROK!THIS! >config.h
  1417. X/* config.h
  1418. X * This file was produced by running the config.h.SH script, which
  1419. X * gets its values from config.sh, which is generally produced by
  1420. X * running Configure.
  1421. X *
  1422. X * Feel free to modify any of this as the need arises.  Note, however,
  1423. X * that running config.h.SH again will wipe out any changes you've made.
  1424. X * For a more permanent change edit config.sh and rerun config.h.SH.
  1425. X */
  1426. X
  1427. X
  1428. X/* EUNICE:
  1429. X *    This symbol, if defined, indicates that the program is being compiled
  1430. X *    under the EUNICE package under VMS.  The program will need to handle
  1431. X *    things like files that don't go away the first time you unlink them,
  1432. X *    due to version numbering.  It will also need to compensate for lack
  1433. X *    of a respectable link() command.
  1434. X */
  1435. X/* VMS:
  1436. X *    This symbol, if defined, indicates that the program is running under
  1437. X *    VMS.  It is currently only set in conjunction with the EUNICE symbol.
  1438. X */
  1439. X#$d_eunice    EUNICE        /**/
  1440. X#$d_eunice    VMS        /**/
  1441. X
  1442. X/* CHARSPRINTF:
  1443. X *    This symbol is defined if this system declares "char *sprintf()" in
  1444. X *    stdio.h.  The trend seems to be to declare it as "int sprintf()".  It
  1445. X *    is up to the package author to declare sprintf correctly based on the
  1446. X *    symbol.
  1447. X */
  1448. X#$d_charsprf    CHARSPRINTF     /**/
  1449. X
  1450. X/* index:
  1451. X *    This preprocessor symbol is defined, along with rindex, if the system
  1452. X *    uses the strchr and strrchr routines instead.
  1453. X */
  1454. X/* rindex:
  1455. X *    This preprocessor symbol is defined, along with index, if the system
  1456. X *    uses the strchr and strrchr routines instead.
  1457. X */
  1458. X#$d_index    index strchr    /* cultural */
  1459. X#$d_index    rindex strrchr    /*  differences? */
  1460. X
  1461. X/* STRUCTCOPY:
  1462. X *    This symbol, if defined, indicates that this C compiler knows how
  1463. X *    to copy structures.  If undefined, you'll need to use a block copy
  1464. X *    routine of some sort instead.
  1465. X */
  1466. X#$d_strctcpy    STRUCTCOPY    /**/
  1467. X
  1468. X/* vfork:
  1469. X *    This symbol, if defined, remaps the vfork routine to fork if the
  1470. X *    vfork() routine isn't supported here.
  1471. X */
  1472. X#$d_vfork    vfork fork    /**/
  1473. X
  1474. X/* VOIDFLAGS:
  1475. X *    This symbol indicates how much support of the void type is given by this
  1476. X *    compiler.  What various bits mean:
  1477. X *
  1478. X *        1 = supports declaration of void
  1479. X *        2 = supports arrays of pointers to functions returning void
  1480. X *        4 = supports comparisons between pointers to void functions and
  1481. X *            addresses of void functions
  1482. X *
  1483. X *    The package designer should define VOIDUSED to indicate the requirements
  1484. X *    of the package.  This can be done either by #defining VOIDUSED before
  1485. X *    including config.h, or by defining defvoidused in Myinit.U.  If the
  1486. X *    level of void support necessary is not present, defines void to int.
  1487. X */
  1488. X#ifndef VOIDUSED
  1489. X#define VOIDUSED $defvoidused
  1490. X#endif
  1491. X#define VOIDFLAGS $voidflags
  1492. X#if (VOIDFLAGS & VOIDUSED) != VOIDUSED
  1493. X#$define void int        /* is void to be avoided? */
  1494. X#$define M_VOID        /* Xenix strikes again */
  1495. X#endif
  1496. X
  1497. X!GROK!THIS!
  1498. !STUFFY!FUNK!
  1499. echo Extracting cmd.h
  1500. sed >cmd.h <<'!STUFFY!FUNK!' -e 's/X//'
  1501. X/* $Header: cmd.h,v 1.0 87/12/18 13:04:59 root Exp $
  1502. X *
  1503. X * $Log:    cmd.h,v $
  1504. X * Revision 1.0  87/12/18  13:04:59  root
  1505. X * Initial revision
  1506. X * 
  1507. X */
  1508. X
  1509. X#define C_NULL 0
  1510. X#define C_IF 1
  1511. X#define C_WHILE 2
  1512. X#define C_EXPR 3
  1513. X#define C_BLOCK 4
  1514. X
  1515. X#ifndef DOINIT
  1516. Xextern char *cmdname[];
  1517. X#else
  1518. Xchar *cmdname[] = {
  1519. X    "NULL",
  1520. X    "IF",
  1521. X    "WHILE",
  1522. X    "EXPR",
  1523. X    "BLOCK",
  1524. X    "5",
  1525. X    "6",
  1526. X    "7",
  1527. X    "8",
  1528. X    "9",
  1529. X    "10",
  1530. X    "11",
  1531. X    "12",
  1532. X    "13",
  1533. X    "14",
  1534. X    "15",
  1535. X    "16"
  1536. X};
  1537. X#endif
  1538. X
  1539. X#define CF_OPTIMIZE 077    /* type of optimization */
  1540. X#define CF_FIRSTNEG 0100/* conditional is ($register NE 'string') */
  1541. X#define CF_NESURE 0200    /* if first doesn't match we're sure */
  1542. X#define CF_EQSURE 0400    /* if first does match we're sure */
  1543. X#define CF_COND    01000    /* test c_expr as conditional first, if not null. */
  1544. X            /* Set for everything except do {} while currently */
  1545. X#define CF_LOOP 02000    /* loop on the c_expr conditional (loop modifiers) */
  1546. X#define CF_INVERT 04000    /* it's an "unless" or an "until" */
  1547. X#define CF_ONCE 010000    /* we've already pushed the label on the stack */
  1548. X#define CF_FLIP 020000    /* on a match do flipflop */
  1549. X
  1550. X#define CFT_FALSE 0    /* c_expr is always false */
  1551. X#define CFT_TRUE 1    /* c_expr is always true */
  1552. X#define CFT_REG 2    /* c_expr is a simple register */
  1553. X#define CFT_ANCHOR 3    /* c_expr is an anchored search /^.../ */
  1554. X#define CFT_STROP 4    /* c_expr is a string comparison */
  1555. X#define CFT_SCAN 5    /* c_expr is an unanchored search /.../ */
  1556. X#define CFT_GETS 6    /* c_expr is $reg = <filehandle> */
  1557. X#define CFT_EVAL 7    /* c_expr is not optimized, so call eval() */
  1558. X#define CFT_UNFLIP 8    /* 2nd half of range not optimized */
  1559. X#define CFT_CHOP 9    /* c_expr is a chop on a register */
  1560. X
  1561. X#ifndef DOINIT
  1562. Xextern char *cmdopt[];
  1563. X#else
  1564. Xchar *cmdopt[] = {
  1565. X    "FALSE",
  1566. X    "TRUE",
  1567. X    "REG",
  1568. X    "ANCHOR",
  1569. X    "STROP",
  1570. X    "SCAN",
  1571. X    "GETS",
  1572. X    "EVAL",
  1573. X    "UNFLIP",
  1574. X    "CHOP",
  1575. X    "10"
  1576. X};
  1577. X#endif
  1578. X
  1579. Xstruct acmd {
  1580. X    STAB    *ac_stab;    /* a symbol table entry */
  1581. X    ARG        *ac_expr;    /* any associated expression */
  1582. X};
  1583. X
  1584. Xstruct ccmd {
  1585. X    CMD        *cc_true;    /* normal code to do on if and while */
  1586. X    CMD        *cc_alt;    /* else code or continue code */
  1587. X};
  1588. X
  1589. Xstruct cmd {
  1590. X    CMD        *c_next;    /* the next command at this level */
  1591. X    ARG        *c_expr;    /* conditional expression */
  1592. X    CMD        *c_head;    /* head of this command list */
  1593. X    STR        *c_first;    /* head of string to match as shortcut */
  1594. X    STAB    *c_stab;    /* a symbol table entry, mostly for fp */
  1595. X    SPAT    *c_spat;    /* pattern used by optimization */
  1596. X    char    *c_label;    /* label for this construct */
  1597. X    union ucmd {
  1598. X    struct acmd acmd;    /* normal command */
  1599. X    struct ccmd ccmd;    /* compound command */
  1600. X    } ucmd;
  1601. X    short    c_flen;        /* len of c_first, if not null */
  1602. X    short    c_flags;    /* optimization flags--see above */
  1603. X    char    c_type;        /* what this command does */
  1604. X};
  1605. X
  1606. X#define Nullcmd Null(CMD*)
  1607. X
  1608. XEXT CMD *main_root INIT(Nullcmd);
  1609. X
  1610. XEXT struct compcmd {
  1611. X    CMD *comp_true;
  1612. X    CMD *comp_alt;
  1613. X};
  1614. X
  1615. X#ifndef DOINIT
  1616. Xextern struct compcmd Nullccmd;
  1617. X#else
  1618. Xstruct compcmd Nullccmd = {Nullcmd, Nullcmd};
  1619. X#endif
  1620. Xvoid opt_arg();
  1621. Xvoid evalstatic();
  1622. XSTR *cmd_exec();
  1623. !STUFFY!FUNK!
  1624. echo Extracting x2p/Makefile.SH
  1625. sed >x2p/Makefile.SH <<'!STUFFY!FUNK!' -e 's/X//'
  1626. Xcase $CONFIG in
  1627. X'')
  1628. X    if test ! -f config.sh; then
  1629. X    ln ../config.sh . || \
  1630. X    ln ../../config.sh . || \
  1631. X    ln ../../../config.sh . || \
  1632. X    (echo "Can't find config.sh."; exit 1)
  1633. X    fi
  1634. X    . config.sh
  1635. X    ;;
  1636. Xesac
  1637. Xcase "$0" in
  1638. X*/*) cd `expr X$0 : 'X\(.*\)/'` ;;
  1639. Xesac
  1640. Xecho "Extracting x2p/Makefile (with variable substitutions)"
  1641. Xcat >Makefile <<!GROK!THIS!
  1642. X# $Header: Makefile.SH,v 1.0 87/12/18 17:50:17 root Exp $
  1643. X#
  1644. X# $Log:    Makefile.SH,v $
  1645. X# Revision 1.0  87/12/18  17:50:17  root
  1646. X# Initial revision
  1647. X# 
  1648. X# 
  1649. X
  1650. XCC = $cc
  1651. Xbin = $bin
  1652. Xlib = $lib
  1653. Xmansrc = $mansrc
  1654. Xmanext = $manext
  1655. XCFLAGS = $ccflags -O
  1656. XLDFLAGS = $ldflags
  1657. XSMALL = $small
  1658. XLARGE = $large $split
  1659. X
  1660. Xlibs = $libnm -lm
  1661. X!GROK!THIS!
  1662. X
  1663. Xcat >>Makefile <<'!NO!SUBS!'
  1664. X
  1665. Xpublic = a2p s2p
  1666. X
  1667. Xprivate = 
  1668. X
  1669. Xmanpages = a2p.man s2p.man
  1670. X
  1671. Xutil =
  1672. X
  1673. Xsh = Makefile.SH makedepend.SH
  1674. X
  1675. Xh = EXTERN.h INTERN.h config.h handy.h hash.h a2p.h str.h util.h
  1676. X
  1677. Xc = hash.c ../malloc.c str.c util.c walk.c
  1678. X
  1679. Xobj = hash.o malloc.o str.o util.o walk.o
  1680. X
  1681. Xlintflags = -phbvxac
  1682. X
  1683. Xaddedbyconf = Makefile.old bsd eunice filexp loc pdp11 usg v7
  1684. X
  1685. X# grrr
  1686. XSHELL = /bin/sh
  1687. X
  1688. X.c.o:
  1689. X    $(CC) -c $(CFLAGS) $(LARGE) $*.c
  1690. X
  1691. Xall: $(public) $(private) $(util)
  1692. X    touch all
  1693. X
  1694. Xa2p: $(obj) a2p.o
  1695. X    $(CC) $(LDFLAGS) $(LARGE) $(obj) a2p.o $(libs) -o a2p
  1696. X
  1697. Xa2p.c: a2p.y
  1698. X    @ echo Expect 107 shift/reduce errors...
  1699. X    yacc a2p.y
  1700. X    mv y.tab.c a2p.c
  1701. X
  1702. Xa2p.o: a2p.c a2py.c a2p.h EXTERN.h util.h INTERN.h handy.h
  1703. X    $(CC) -c $(CFLAGS) $(LARGE) a2p.c
  1704. X
  1705. X# if a .h file depends on another .h file...
  1706. X$(h):
  1707. X    touch $@
  1708. Xinstall: a2p s2p
  1709. X# won't work with csh
  1710. X    export PATH || exit 1
  1711. X    - mv $(bin)/a2p $(bin)/a2p.old
  1712. X    - mv $(bin)/s2p $(bin)/s2p.old
  1713. X    - if test `pwd` != $(bin); then cp $(public) $(bin); fi
  1714. X    cd $(bin); \
  1715. Xfor pub in $(public); do \
  1716. Xchmod 755 `basename $$pub`; \
  1717. Xdone
  1718. X    - test $(bin) = /bin || rm -f /bin/a2p
  1719. X#    chmod 755 makedir
  1720. X#    - makedir `filexp $(lib)`
  1721. X#    - \
  1722. X#if test `pwd` != `filexp $(lib)`; then \
  1723. X#cp $(private) `filexp $(lib)`; \
  1724. X#fi
  1725. X#    cd `filexp $(lib)`; \
  1726. X#for priv in $(private); do \
  1727. X#chmod 755 `basename $$priv`; \
  1728. X#done
  1729. X    - if test `pwd` != $(mansrc); then \
  1730. Xfor page in $(manpages); do \
  1731. Xcp $$page $(mansrc)/`basename $$page .man`.$(manext); \
  1732. Xdone; \
  1733. Xfi
  1734. X
  1735. Xclean:
  1736. X    rm -f *.o
  1737. X
  1738. Xrealclean:
  1739. X    rm -f a2p *.orig */*.orig *.o core $(addedbyconf)
  1740. X
  1741. X# The following lint has practically everything turned on.  Unfortunately,
  1742. X# you have to wade through a lot of mumbo jumbo that can't be suppressed.
  1743. X# If the source file has a /*NOSTRICT*/ somewhere, ignore the lint message
  1744. X# for that spot.
  1745. X
  1746. Xlint:
  1747. X    lint $(lintflags) $(defs) $(c) > a2p.fuzz
  1748. X
  1749. Xdepend: ../makedepend
  1750. X    ../makedepend
  1751. X
  1752. Xclist:
  1753. X    echo $(c) | tr ' ' '\012' >.clist
  1754. X
  1755. Xhlist:
  1756. X    echo $(h) | tr ' ' '\012' >.hlist
  1757. X
  1758. Xshlist:
  1759. X    echo $(sh) | tr ' ' '\012' >.shlist
  1760. X
  1761. X# AUTOMATICALLY GENERATED MAKE DEPENDENCIES--PUT NOTHING BELOW THIS LINE
  1762. X$(obj):
  1763. X    @ echo "You haven't done a "'"make depend" yet!'; exit 1
  1764. Xmakedepend: makedepend.SH
  1765. X    /bin/sh makedepend.SH
  1766. X!NO!SUBS!
  1767. X$eunicefix Makefile
  1768. Xcase `pwd` in
  1769. X*SH)
  1770. X    $rm -f ../Makefile
  1771. X    ln Makefile ../Makefile
  1772. X    ;;
  1773. Xesac
  1774. !STUFFY!FUNK!
  1775. echo Extracting t/comp.cmdopt
  1776. sed >t/comp.cmdopt <<'!STUFFY!FUNK!' -e 's/X//'
  1777. X#!./perl
  1778. X
  1779. X# $Header: comp.cmdopt,v 1.0 87/12/18 13:12:19 root Exp $
  1780. X
  1781. Xprint "1..40\n";
  1782. X
  1783. X# test the optimization of constants
  1784. X
  1785. Xif (1) { print "ok 1\n";} else { print "not ok 1\n";}
  1786. Xunless (0) { print "ok 2\n";} else { print "not ok 2\n";}
  1787. X
  1788. Xif (0) { print "not ok 3\n";} else { print "ok 3\n";}
  1789. Xunless (1) { print "not ok 4\n";} else { print "ok 4\n";}
  1790. X
  1791. Xunless (!1) { print "ok 5\n";} else { print "not ok 5\n";}
  1792. Xif (!0) { print "ok 6\n";} else { print "not ok 6\n";}
  1793. X
  1794. Xunless (!0) { print "not ok 7\n";} else { print "ok 7\n";}
  1795. Xif (!1) { print "not ok 8\n";} else { print "ok 8\n";}
  1796. X
  1797. X$x = 1;
  1798. Xif (1 && $x) { print "ok 9\n";} else { print "not ok 9\n";}
  1799. Xif (0 && $x) { print "not ok 10\n";} else { print "ok 10\n";}
  1800. X$x = '';
  1801. Xif (1 && $x) { print "not ok 11\n";} else { print "ok 11\n";}
  1802. Xif (0 && $x) { print "not ok 12\n";} else { print "ok 12\n";}
  1803. X
  1804. X$x = 1;
  1805. Xif (1 || $x) { print "ok 13\n";} else { print "not ok 13\n";}
  1806. Xif (0 || $x) { print "ok 14\n";} else { print "not ok 14\n";}
  1807. X$x = '';
  1808. Xif (1 || $x) { print "ok 15\n";} else { print "not ok 15\n";}
  1809. Xif (0 || $x) { print "not ok 16\n";} else { print "ok 16\n";}
  1810. X
  1811. X
  1812. X# test the optimization of registers
  1813. X
  1814. X$x = 1;
  1815. Xif ($x) { print "ok 17\n";} else { print "not ok 17\n";}
  1816. Xunless ($x) { print "not ok 18\n";} else { print "ok 18\n";}
  1817. X
  1818. X$x = '';
  1819. Xif ($x) { print "not ok 19\n";} else { print "ok 19\n";}
  1820. Xunless ($x) { print "ok 20\n";} else { print "not ok 20\n";}
  1821. X
  1822. X# test optimization of string operations
  1823. X
  1824. X$a = 'a';
  1825. Xif ($a eq 'a') { print "ok 21\n";} else { print "not ok 21\n";}
  1826. Xif ($a ne 'a') { print "not ok 22\n";} else { print "ok 22\n";}
  1827. X
  1828. Xif ($a =~ /a/) { print "ok 23\n";} else { print "not ok 23\n";}
  1829. Xif ($a !~ /a/) { print "not ok 24\n";} else { print "ok 24\n";}
  1830. X# test interaction of logicals and other operations
  1831. X
  1832. X$a = 'a';
  1833. X$x = 1;
  1834. Xif ($a eq 'a' && $x) { print "ok 25\n";} else { print "not ok 25\n";}
  1835. Xif ($a ne 'a' && $x) { print "not ok 26\n";} else { print "ok 26\n";}
  1836. X$x = '';
  1837. Xif ($a eq 'a' && $x) { print "not ok 27\n";} else { print "ok 27\n";}
  1838. Xif ($a ne 'a' && $x) { print "not ok 28\n";} else { print "ok 28\n";}
  1839. X
  1840. X$x = 1;
  1841. Xif ($a eq 'a' || $x) { print "ok 29\n";} else { print "not ok 29\n";}
  1842. Xif ($a ne 'a' || $x) { print "ok 30\n";} else { print "not ok 30\n";}
  1843. X$x = '';
  1844. Xif ($a eq 'a' || $x) { print "ok 31\n";} else { print "not ok 31\n";}
  1845. Xif ($a ne 'a' || $x) { print "not ok 32\n";} else { print "ok 32\n";}
  1846. X
  1847. X$x = 1;
  1848. Xif ($a =~ /a/ && $x) { print "ok 33\n";} else { print "not ok 33\n";}
  1849. Xif ($a !~ /a/ && $x) { print "not ok 34\n";} else { print "ok 34\n";}
  1850. X$x = '';
  1851. Xif ($a =~ /a/ && $x) { print "not ok 35\n";} else { print "ok 35\n";}
  1852. X    if ($a !~ /a/ && $x) { print "not ok 36\n";} else { print "ok 36\n";}
  1853. X
  1854. X$x = 1;
  1855. Xif ($a =~ /a/ || $x) { print "ok 37\n";} else { print "not ok 37\n";}
  1856. Xif ($a !~ /a/ || $x) { print "ok 38\n";} else { print "not ok 38\n";}
  1857. X$x = '';
  1858. Xif ($a =~ /a/ || $x) { print "ok 39\n";} else { print "not ok 39\n";}
  1859. Xif ($a !~ /a/ || $x) { print "not ok 40\n";} else { print "ok 40\n";}
  1860. !STUFFY!FUNK!
  1861. echo Extracting config.H
  1862. sed >config.H <<'!STUFFY!FUNK!' -e 's/X//'
  1863. X/* config.h
  1864. X * This file was produced by running the config.h.SH script, which
  1865. X * gets its values from config.sh, which is generally produced by
  1866. X * running Configure.
  1867. X *
  1868. X * Feel free to modify any of this as the need arises.  Note, however,
  1869. X * that running config.h.SH again will wipe out any changes you've made.
  1870. X * For a more permanent change edit config.sh and rerun config.h.SH.
  1871. X */
  1872. X
  1873. X
  1874. X/* EUNICE:
  1875. X *    This symbol, if defined, indicates that the program is being compiled
  1876. X *    under the EUNICE package under VMS.  The program will need to handle
  1877. X *    things like files that don't go away the first time you unlink them,
  1878. X *    due to version numbering.  It will also need to compensate for lack
  1879. X *    of a respectable link() command.
  1880. X */
  1881. X/* VMS:
  1882. X *    This symbol, if defined, indicates that the program is running under
  1883. X *    VMS.  It is currently only set in conjunction with the EUNICE symbol.
  1884. X */
  1885. X#/*undef    EUNICE        /**/
  1886. X#/*undef    VMS        /**/
  1887. X
  1888. X/* CHARSPRINTF:
  1889. X *    This symbol is defined if this system declares "char *sprintf()" in
  1890. X *    stdio.h.  The trend seems to be to declare it as "int sprintf()".  It
  1891. X *    is up to the package author to declare sprintf correctly based on the
  1892. X *    symbol.
  1893. X */
  1894. X#define    CHARSPRINTF     /**/
  1895. X
  1896. X/* index:
  1897. X *    This preprocessor symbol is defined, along with rindex, if the system
  1898. X *    uses the strchr and strrchr routines instead.
  1899. X */
  1900. X/* rindex:
  1901. X *    This preprocessor symbol is defined, along with index, if the system
  1902. X *    uses the strchr and strrchr routines instead.
  1903. X */
  1904. X#/*undef    index strchr    /* cultural */
  1905. X#/*undef    rindex strrchr    /*  differences? */
  1906. X
  1907. X/* STRUCTCOPY:
  1908. X *    This symbol, if defined, indicates that this C compiler knows how
  1909. X *    to copy structures.  If undefined, you'll need to use a block copy
  1910. X *    routine of some sort instead.
  1911. X */
  1912. X#define    STRUCTCOPY    /**/
  1913. X
  1914. X/* vfork:
  1915. X *    This symbol, if defined, remaps the vfork routine to fork if the
  1916. X *    vfork() routine isn't supported here.
  1917. X */
  1918. X#/*undef    vfork fork    /**/
  1919. X
  1920. X/* VOIDFLAGS:
  1921. X *    This symbol indicates how much support of the void type is given by this
  1922. X *    compiler.  What various bits mean:
  1923. X *
  1924. X *        1 = supports declaration of void
  1925. X *        2 = supports arrays of pointers to functions returning void
  1926. X *        4 = supports comparisons between pointers to void functions and
  1927. X *            addresses of void functions
  1928. X *
  1929. X *    The package designer should define VOIDUSED to indicate the requirements
  1930. X *    of the package.  This can be done either by #defining VOIDUSED before
  1931. X *    including config.h, or by defining defvoidused in Myinit.U.  If the
  1932. X *    level of void support necessary is not present, defines void to int.
  1933. X */
  1934. X#ifndef VOIDUSED
  1935. X#define VOIDUSED 7
  1936. X#endif
  1937. X#define VOIDFLAGS 7
  1938. X#if (VOIDFLAGS & VOIDUSED) != VOIDUSED
  1939. X#define void int        /* is void to be avoided? */
  1940. X#define M_VOID        /* Xenix strikes again */
  1941. X#endif
  1942. X
  1943. !STUFFY!FUNK!
  1944. echo Extracting t/op.auto
  1945. sed >t/op.auto <<'!STUFFY!FUNK!' -e 's/X//'
  1946. X#!./perl
  1947. X
  1948. X# $Header: op.auto,v 1.0 87/12/18 13:13:08 root Exp $
  1949. X
  1950. Xprint "1..30\n";
  1951. X
  1952. X$x = 10000;
  1953. Xif (0 + ++$x - 1 == 10000) { print "ok 1\n";} else {print "not ok 1\n";}
  1954. Xif (0 + $x-- - 1 == 10000) { print "ok 2\n";} else {print "not ok 2\n";}
  1955. Xif (1 * $x == 10000) { print "ok 3\n";} else {print "not ok 3\n";}
  1956. Xif (0 + $x-- - 0 == 10000) { print "ok 4\n";} else {print "not ok 4\n";}
  1957. Xif (1 + $x == 10000) { print "ok 5\n";} else {print "not ok 5\n";}
  1958. Xif (1 + $x++ == 10000) { print "ok 6\n";} else {print "not ok 6\n";}
  1959. Xif (0 + $x == 10000) { print "ok 7\n";} else {print "not ok 7\n";}
  1960. Xif (0 + --$x + 1 == 10000) { print "ok 8\n";} else {print "not ok 8\n";}
  1961. Xif (0 + ++$x + 0 == 10000) { print "ok 9\n";} else {print "not ok 9\n";}
  1962. Xif ($x == 10000) { print "ok 10\n";} else {print "not ok 10\n";}
  1963. X
  1964. X$x[0] = 10000;
  1965. Xif (0 + ++$x[0] - 1 == 10000) { print "ok 11\n";} else {print "not ok 11\n";}
  1966. Xif (0 + $x[0]-- - 1 == 10000) { print "ok 12\n";} else {print "not ok 12\n";}
  1967. Xif (1 * $x[0] == 10000) { print "ok 13\n";} else {print "not ok 13\n";}
  1968. Xif (0 + $x[0]-- - 0 == 10000) { print "ok 14\n";} else {print "not ok 14\n";}
  1969. Xif (1 + $x[0] == 10000) { print "ok 15\n";} else {print "not ok 15\n";}
  1970. Xif (1 + $x[0]++ == 10000) { print "ok 16\n";} else {print "not ok 16\n";}
  1971. Xif (0 + $x[0] == 10000) { print "ok 17\n";} else {print "not ok 17\n";}
  1972. Xif (0 + --$x[0] + 1 == 10000) { print "ok 18\n";} else {print "not ok 18\n";}
  1973. Xif (0 + ++$x[0] + 0 == 10000) { print "ok 19\n";} else {print "not ok 19\n";}
  1974. Xif ($x[0] == 10000) { print "ok 20\n";} else {print "not ok 20\n";}
  1975. X
  1976. X$x{0} = 10000;
  1977. Xif (0 + ++$x{0} - 1 == 10000) { print "ok 21\n";} else {print "not ok 21\n";}
  1978. Xif (0 + $x{0}-- - 1 == 10000) { print "ok 22\n";} else {print "not ok 22\n";}
  1979. Xif (1 * $x{0} == 10000) { print "ok 23\n";} else {print "not ok 23\n";}
  1980. Xif (0 + $x{0}-- - 0 == 10000) { print "ok 24\n";} else {print "not ok 24\n";}
  1981. Xif (1 + $x{0} == 10000) { print "ok 25\n";} else {print "not ok 25\n";}
  1982. Xif (1 + $x{0}++ == 10000) { print "ok 26\n";} else {print "not ok 26\n";}
  1983. Xif (0 + $x{0} == 10000) { print "ok 27\n";} else {print "not ok 27\n";}
  1984. Xif (0 + --$x{0} + 1 == 10000) { print "ok 28\n";} else {print "not ok 28\n";}
  1985. Xif (0 + ++$x{0} + 0 == 10000) { print "ok 29\n";} else {print "not ok 29\n";}
  1986. Xif ($x{0} == 10000) { print "ok 30\n";} else {print "not ok 30\n";}
  1987. !STUFFY!FUNK!
  1988. echo Extracting t/op.pat
  1989. sed >t/op.pat <<'!STUFFY!FUNK!' -e 's/X//'
  1990. X#!./perl
  1991. X
  1992. X# $Header: op.pat,v 1.0 87/12/18 13:14:07 root Exp $
  1993. Xprint "1..22\n";
  1994. X
  1995. X$x = "abc\ndef\n";
  1996. X
  1997. Xif ($x =~ /^abc/) {print "ok 1\n";} else {print "not ok 1\n";}
  1998. Xif ($x !~ /^def/) {print "ok 2\n";} else {print "not ok 2\n";}
  1999. X
  2000. X$* = 1;
  2001. Xif ($x =~ /^def/) {print "ok 3\n";} else {print "not ok 3\n";}
  2002. X$* = 0;
  2003. X
  2004. X$_ = '123';
  2005. Xif (/^([0-9][0-9]*)/) {print "ok 4\n";} else {print "not ok 4\n";}
  2006. X
  2007. Xif ($x =~ /^xxx/) {print "not ok 5\n";} else {print "ok 5\n";}
  2008. Xif ($x !~ /^abc/) {print "not ok 6\n";} else {print "ok 6\n";}
  2009. X
  2010. Xif ($x =~ /def/) {print "ok 7\n";} else {print "not ok 7\n";}
  2011. Xif ($x !~ /def/) {print "not ok 8\n";} else {print "ok 8\n";}
  2012. X
  2013. Xif ($x !~ /.def/) {print "ok 9\n";} else {print "not ok 9\n";}
  2014. Xif ($x =~ /.def/) {print "not ok 10\n";} else {print "ok 10\n";}
  2015. X
  2016. Xif ($x =~ /\ndef/) {print "ok 11\n";} else {print "not ok 11\n";}
  2017. Xif ($x !~ /\ndef/) {print "not ok 12\n";} else {print "ok 12\n";}
  2018. X
  2019. X$_ = 'aaabbbccc';
  2020. Xif (/(a*b*)(c*)/ && $1 eq 'aaabbb' && $2 eq 'ccc') {
  2021. X    print "ok 13\n";
  2022. X} else {
  2023. X    print "not ok 13\n";
  2024. X}
  2025. Xif (/(a+b+c+)/ && $1 eq 'aaabbbccc') {
  2026. X    print "ok 14\n";
  2027. X} else {
  2028. X    print "not ok 14\n";
  2029. X}
  2030. X
  2031. Xif (/a+b?c+/) {print "not ok 15\n";} else {print "ok 15\n";}
  2032. X
  2033. X$_ = 'aaabccc';
  2034. Xif (/a+b?c+/) {print "ok 16\n";} else {print "not ok 16\n";}
  2035. Xif (/a*b+c*/) {print "ok 17\n";} else {print "not ok 17\n";}
  2036. X
  2037. X$_ = 'aaaccc';
  2038. Xif (/a*b?c*/) {print "ok 18\n";} else {print "not ok 18\n";}
  2039. Xif (/a*b+c*/) {print "not ok 19\n";} else {print "ok 19\n";}
  2040. X
  2041. X$_ = 'abcdef';
  2042. Xif (/bcd|xyz/) {print "ok 20\n";} else {print "not ok 20\n";}
  2043. Xif (/xyz|bcd/) {print "ok 21\n";} else {print "not ok 21\n";}
  2044. X
  2045. Xif (m|bc/*d|) {print "ok 22\n";} else {print "not ok 22\n";}
  2046. !STUFFY!FUNK!
  2047. echo ""
  2048. echo "End of kit 9 (of 10)"
  2049. cat /dev/null >kit9isdone
  2050. config=true
  2051. for iskit in 1 2 3 4 5 6 7 8 9 10; do
  2052.     if test -f kit${iskit}isdone; then
  2053.     echo "You have run kit ${iskit}."
  2054.     else
  2055.     echo "You still need to run kit ${iskit}."
  2056.     config=false
  2057.     fi
  2058. done
  2059. case $config in
  2060.     true)
  2061.     echo "You have run all your kits.  Please read README and then type Configure."
  2062.     chmod 755 Configure
  2063.     ;;
  2064. esac
  2065. : Someone might mail this, so...
  2066. exit
  2067.