home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1433 < prev    next >
Internet Message Format  |  1990-12-28  |  56KB

  1. From: istvan@hhb.UUCP (Istvan Mohos)
  2. Newsgroups: alt.sources
  3. Subject: Subject: ILIB Unix Toolkit in C
  4. Message-ID: <549@hhb.UUCP>
  5. Date: 8 Jun 90 20:52:44 GMT
  6.  
  7.  
  8. ---- Cut Here and unpack ----
  9. #!/bin/sh
  10. # This is part 03 of a multipart archive
  11. if touch 2>&1 | fgrep '[-amc]' > /dev/null
  12.  then TOUCH=touch
  13.  else TOUCH=true
  14. fi
  15. # ============= i/iwrite.c ==============
  16. echo "x - extracting i/iwrite.c (Text)"
  17. sed 's/^X//' << 'SHAR_EOF' > i/iwrite.c &&
  18. X/* iwrite.c */
  19. X/********************************************
  20. X* write file from buffer, return size written
  21. X* Istvan Mohos, 1987 --- in the Public Domain
  22. X*********************************************/
  23. X
  24. X#include "i.h"
  25. X
  26. Xint
  27. Xiwrite (fname, start, end)
  28. Xchar *fname;
  29. Xregister char *start;
  30. Xregister char *end;
  31. X{
  32. X    struct stat sbuf;
  33. X    int checkval, descr;
  34. X    int perm = 0644;
  35. X
  36. X    if (BADCHARP(fname))
  37. X        return(ierror("iwrite: invalid file name"));
  38. X
  39. X    if ((checkval = stat(fname, &sbuf)) != -1)
  40. X        perm = (int)sbuf.st_mode;
  41. X
  42. X    if (NULCHARP(start)) {
  43. X        if ((descr = open(fname, O_RDWR | O_CREAT, perm)) == -1)
  44. X            return(-1); /* no access */
  45. X        if (checkval != -1) {
  46. X            close(descr);
  47. X            return(1); /* it was there, it's OK, didn't touch it */
  48. X        }
  49. X        unlink(fname);
  50. X        return(0); /* wasn't there, not there now, looks OK */
  51. X    }
  52. X
  53. X    if ((descr = open(fname, O_WRONLY | O_CREAT | O_TRUNC, perm)) == -1)
  54. X        return(ierror("iwrite: can't write to"));
  55. X
  56. X    ITOEND;
  57. X
  58. X    if ((checkval = write(descr, start, end-start)) != end-start) {
  59. X        sprintf(ierbuf+200, "iwrite: tried: %d, wrote: %d",
  60. X            end-start, checkval);
  61. X        return(ierror(ierbuf+200));
  62. X    }
  63. X
  64. X    close(descr);
  65. X    return(checkval);
  66. X}
  67. SHAR_EOF
  68. $TOUCH -am 0605074590 i/iwrite.c &&
  69. chmod 0644 i/iwrite.c ||
  70. echo "restore of i/iwrite.c failed"
  71. set `wc -c i/iwrite.c`;Wc_c=$1
  72. if test "$Wc_c" != "1143"; then
  73.     echo original size 1143, current size $Wc_c
  74. fi
  75. # ============= i/iwritopn.c ==============
  76. echo "x - extracting i/iwritopn.c (Text)"
  77. sed 's/^X//' << 'SHAR_EOF' > i/iwritopn.c &&
  78. X/* iwritopn.c */
  79. X/**********************************************
  80. X* write file from buffer, leave open, return fd
  81. X* Istvan Mohos, 1987 --- in the Public Domain
  82. X***********************************************/
  83. X
  84. X#include "i.h"
  85. X
  86. Xint
  87. Xiwritopn (fname, start, end)
  88. Xregister char *fname;
  89. Xregister char *start;
  90. Xchar *end;
  91. X{
  92. X    struct stat sbuf;
  93. X    int checkval, descr;
  94. X    int perm = 0644;
  95. X
  96. X    if (BADCHARP(fname))
  97. X        return(ierror("iwritopn: invalid file name"));
  98. X
  99. X    if ((checkval = stat(fname, &sbuf)) != -1)
  100. X        perm = (int)sbuf.st_mode;
  101. X
  102. X    if ((descr = open(fname, O_WRONLY | O_CREAT | O_TRUNC, perm)) == -1)
  103. X        return(ierror("iwritopn: can't write to"));
  104. X
  105. X    if (NULCHARP (start))
  106. X        return (ierror ("iwritopn: invalid buffer"));
  107. X    ITOEND;
  108. X
  109. X    if ((checkval = write(descr, start, end-start)) != end-start) {
  110. X        sprintf(ierbuf+200, "iwritopn: tried: %d, wrote: %d",
  111. X            end-start, checkval);
  112. X        return(ierror(ierbuf+200));
  113. X    }
  114. X
  115. X    return(descr);
  116. X}
  117. SHAR_EOF
  118. $TOUCH -am 0605074590 i/iwritopn.c &&
  119. chmod 0644 i/iwritopn.c ||
  120. echo "restore of i/iwritopn.c failed"
  121. set `wc -c i/iwritopn.c`;Wc_c=$1
  122. if test "$Wc_c" != "916"; then
  123.     echo original size 916, current size $Wc_c
  124. fi
  125. # ============= i/ixmatch.c ==============
  126. echo "x - extracting i/ixmatch.c (Text)"
  127. sed 's/^X//' << 'SHAR_EOF' > i/ixmatch.c &&
  128. X/* ixmatch.c */
  129. X/********************************************
  130. X* find word in buffer
  131. X* Istvan Mohos, 1987 --- in the Public Domain
  132. X*********************************************/
  133. X
  134. X#include "i.h"
  135. X
  136. Xchar *
  137. Xixmatch (start, end, word)
  138. Xregister char *start;
  139. Xchar *end, *word;
  140. X{
  141. X    register char *off;
  142. X    register char *tail;
  143. X    char *sc, *tc;
  144. X    char *pp, *wp;
  145. X    int length;
  146. X
  147. X    if (NULCHARP (start) || BADCHARP (word)) {
  148. X        ierror("ixmatch: invalid word");
  149. X        return(NULL);
  150. X    }
  151. X    ITOEND;
  152. X
  153. X    for (sc = off = word; *off++;);
  154. X    length = --off - word;
  155. X    tc = --off;
  156. X
  157. X    off = end;
  158. X
  159. X    for (off -= --length; start < off;) {
  160. X
  161. X        /* proceed to first black character */
  162. X        for (;WHITE(*start);)
  163. X            if (++start == off)
  164. X                return(NULL);
  165. X
  166. X        tail = start + length;
  167. X        if (*start++ == *sc && *tail == *tc)
  168. X            if (length > 1) {
  169. X                for (wp = tc, pp = tail; *--wp == *--pp;)
  170. X                    if (pp == start)
  171. X                        if (start == off || WHITE(*++tail))
  172. X                            return(--start);
  173. X            }
  174. X            else if (start == off || WHITE(*++tail))
  175. X                return(--start);
  176. X
  177. X        /* proceed to next white character */
  178. X        for (;BLACK(*start);)
  179. X            if (++start >= off)
  180. X                return(NULL);
  181. X    }
  182. X    return(NULL);
  183. X}
  184. SHAR_EOF
  185. $TOUCH -am 0605074590 i/ixmatch.c &&
  186. chmod 0644 i/ixmatch.c ||
  187. echo "restore of i/ixmatch.c failed"
  188. set `wc -c i/ixmatch.c`;Wc_c=$1
  189. if test "$Wc_c" != "1113"; then
  190.     echo original size 1113, current size $Wc_c
  191. fi
  192. # ============= i/ixsearch.c ==============
  193. echo "x - extracting i/ixsearch.c (Text)"
  194. sed 's/^X//' << 'SHAR_EOF' > i/ixsearch.c &&
  195. X/* ixsearch.c */
  196. X/*********************************************
  197. X* binary search in array of character pointers
  198. X* Istvan Mohos, 1987 --- in the Public Domain
  199. X**********************************************/
  200. X
  201. X#include "i.h"
  202. X
  203. Xint
  204. Xixsearch (comparee, wordlist, listcount)
  205. Xchar *comparee;
  206. Xchar *wordlist[];
  207. Xint listcount;
  208. X{
  209. X    register int lo, hi;
  210. X    register int m, mid;
  211. X
  212. X    if (BADCHARP (comparee))
  213. X        return(ierror("ixsearch: invalid comparee"));
  214. X    if (listcount < 1)
  215. X        return (-1);
  216. X
  217. X    for (lo = 0, hi = listcount -1; lo <= hi;) {
  218. X        mid = (lo + hi) >> 1;
  219. X        if ((m = strcmp(comparee, wordlist[mid])) < 0)
  220. X            hi = mid -1;
  221. X        else if (m > 0)
  222. X            lo = mid +1;
  223. X        else
  224. X            return(mid);
  225. X    }
  226. X    return (-1);
  227. X}
  228. SHAR_EOF
  229. $TOUCH -am 0605074590 i/ixsearch.c &&
  230. chmod 0644 i/ixsearch.c ||
  231. echo "restore of i/ixsearch.c failed"
  232. set `wc -c i/ixsearch.c`;Wc_c=$1
  233. if test "$Wc_c" != "684"; then
  234.     echo original size 684, current size $Wc_c
  235. fi
  236. # ============= i/ixswap.c ==============
  237. echo "x - extracting i/ixswap.c (Text)"
  238. sed 's/^X//' << 'SHAR_EOF' > i/ixswap.c &&
  239. X/* ixswap.c */
  240. X/********************************************
  241. X* change one word to another in buffer
  242. X* Istvan Mohos, 1987 --- in the Public Domain
  243. X*********************************************/
  244. X
  245. X#include "i.h"
  246. X
  247. Xint
  248. Xixswap (start, end, from, to)
  249. Xchar *start, *end, *from, *to;
  250. X{
  251. X    register char *off;
  252. X    register char *inp, *we;
  253. X    register char ch;
  254. X    char *mark;
  255. X    char tok[SHORTSTR];
  256. X    int frsiz, tosiz;
  257. X    int count = 0;
  258. X
  259. X    if (NULCHARP (start))
  260. X        return (ierror ("ixswap: null buffer"));
  261. X    ITOEND;
  262. X
  263. X    if (BADCHARP(from))
  264. X        return(ierror("ixswap: bad source pattern"));
  265. X    if (BADCHARP(to))
  266. X        return(ierror("ixswap: bad target pattern"));
  267. X
  268. X    for (off = from; *off++;);
  269. X    frsiz = --off - from;
  270. X
  271. X    for (off = to; *off++;);
  272. X    tosiz = --off - to;
  273. X
  274. X    off = end;
  275. X    inp = start;
  276. X
  277. X    /* get alphanumeric word only */
  278. X    for (;(we = ialntok(inp, off, tok)) != (char *)NULL;) {
  279. X       if (strcmp (from, tok) == 0) {
  280. X           mark = we - frsiz;
  281. X           inp = mark + tosiz;
  282. X           ch = *inp;
  283. X           strcpy (mark, to);
  284. X           *inp = ch;
  285. X           ++count;
  286. X       }
  287. X       else
  288. X           inp = we;
  289. X    }
  290. X    return(count);
  291. X}
  292. SHAR_EOF
  293. $TOUCH -am 0605074590 i/ixswap.c &&
  294. chmod 0644 i/ixswap.c ||
  295. echo "restore of i/ixswap.c failed"
  296. set `wc -c i/ixswap.c`;Wc_c=$1
  297. if test "$Wc_c" != "1049"; then
  298.     echo original size 1049, current size $Wc_c
  299. fi
  300. # ============= i/i.h ==============
  301. echo "x - extracting i/i.h (Text)"
  302. sed 's/^X//' << 'SHAR_EOF' > i/i.h &&
  303. X/* i.h */
  304. X/**************************************
  305. X* local include file for ilib functions
  306. X* Istvan Mohos, 1987
  307. X***************************************/
  308. X
  309. X#ifdef pyr
  310. X#include <sys/time.h>
  311. X#else
  312. X#include <time.h>
  313. X#endif
  314. X
  315. X#include <stdio.h>
  316. X#include <signal.h>
  317. X#include <sys/types.h>
  318. X#include <sys/stat.h>
  319. X
  320. X#ifndef X_OK
  321. X#    ifdef REALUNIX
  322. X#        define F_OK 0
  323. X#        define X_OK 1
  324. X#        define W_OK 2
  325. X#        define R_OK 4
  326. X#        include <fcntl.h>
  327. X#    else
  328. X#        include <sys/file.h>
  329. X#    endif
  330. X#endif
  331. X
  332. X#ifdef REALUNIX
  333. X   void memcpy(); /* in truth, char* */
  334. X#  define ibcopy(a,b,c) memcpy((a),(b),(c))
  335. X
  336. X   int memcmp();
  337. X#  define ibcmp(a,b,c)  memcmp((a),(b),(c))
  338. X#else
  339. X   void bcpy();
  340. X#  define ibcopy(a,b,c) bcopy((b),(a),(c))
  341. X
  342. X   int bcmp();
  343. X#  define ibcmp(a,b,c)  bcmp((a),(b),(c))
  344. X#endif
  345. X
  346. X#define ITOEND if (end == (char *)NULL) for (end = start; *end; end++)
  347. X
  348. X#define NUL          0    /* the ASCII 0 byte */
  349. X#define MAXSTR       1892
  350. X#define BIGBUFSIZ    4096
  351. X#define SHORTSTR     256
  352. X#define IFOURK       4096
  353. X#define ITWOK        2048
  354. X#define IONEK        1024
  355. X#define IHALFK       512
  356. X#define IQUARTK      256
  357. X#define BADCHARP(p)  ((p) == (char *)NULL || *(p) == '\0')
  358. X#define NULCHARP(p)  ((p) == (char *)NULL)
  359. X#define WHITE(c)     ((c) < 33)
  360. X#define BLACK(c)     ((c) > 32)
  361. X#define SMALL(c)     ((c) < 32)
  362. X
  363. X#define INITOKF      1    /* setup forward parsing */
  364. X#define INITOKR     -1    /* setup reverse parsing */
  365. X#define ITOKF        2    /* forward parse */
  366. X#define ITOKR       -2    /* reverse parse */
  367. X
  368. Xint  fstat();
  369. Xint  stat();
  370. Xchar *calloc();
  371. Xchar *ctime();
  372. Xchar *getenv();
  373. Xchar *malloc();
  374. Xlong lseek();
  375. Xlong time();
  376. Xstruct tm *_igetdate();
  377. X
  378. Xchar *ialntok();
  379. Xchar *ianytok();
  380. Xchar *ictok();
  381. Xchar *ilast();
  382. Xchar *inull();
  383. Xchar *iwhich();
  384. Xint  ierror();
  385. Xint  ifamily();
  386. Xint  ilongest();
  387. Xint  iread();
  388. Xint  itexrect();
  389. X
  390. Xextern int errno, sys_nerr;
  391. Xextern char *sys_errlist[];
  392. X
  393. X#ifndef IAMIERROR
  394. Xextern char ierbuf[];
  395. Xextern int  ierflag;
  396. X#endif
  397. SHAR_EOF
  398. $TOUCH -am 0601073090 i/i.h &&
  399. chmod 0644 i/i.h ||
  400. echo "restore of i/i.h failed"
  401. set `wc -c i/i.h`;Wc_c=$1
  402. if test "$Wc_c" != "1975"; then
  403.     echo original size 1975, current size $Wc_c
  404. fi
  405. # ============= i/icmapalnum.h ==============
  406. echo "x - extracting i/icmapalnum.h (Text)"
  407. sed 's/^X//' << 'SHAR_EOF' > i/icmapalnum.h &&
  408. X/* icmapalnum.h */
  409. X/********************************************
  410. X* character map array used by ictok.c
  411. X* Istvan Mohos, 1987 --- in the Public Domain
  412. X*********************************************/
  413. X
  414. Xstatic char cmapalnum[] = {
  415. X  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  416. X  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  417. X  0,  0,  0,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  418. X  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,
  419. X  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
  420. X  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  1,
  421. X  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
  422. X  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,
  423. X};
  424. SHAR_EOF
  425. $TOUCH -am 0425094890 i/icmapalnum.h &&
  426. chmod 0644 i/icmapalnum.h ||
  427. echo "restore of i/icmapalnum.h failed"
  428. set `wc -c i/icmapalnum.h`;Wc_c=$1
  429. if test "$Wc_c" != "748"; then
  430.     echo original size 748, current size $Wc_c
  431. fi
  432. # ============= i/idowncas.h ==============
  433. echo "x - extracting i/idowncas.h (Text)"
  434. sed 's/^X//' << 'SHAR_EOF' > i/idowncas.h &&
  435. X/* idowncas.h */
  436. X/********************************************
  437. X* character map array used by ilower.c
  438. X* Istvan Mohos, 1987 --- in the Public Domain
  439. X*********************************************/
  440. X
  441. Xstatic char downcas[] = {
  442. X  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
  443. X 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  444. X 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  445. X 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
  446. X 64, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
  447. X112,113,114,115,116,117,118,119,120,121,122, 91, 92, 93, 94, 95,
  448. X 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
  449. X112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
  450. X};
  451. SHAR_EOF
  452. $TOUCH -am 0425094890 i/idowncas.h &&
  453. chmod 0644 i/idowncas.h ||
  454. echo "restore of i/idowncas.h failed"
  455. set `wc -c i/idowncas.h`;Wc_c=$1
  456. if test "$Wc_c" != "745"; then
  457.     echo original size 745, current size $Wc_c
  458. fi
  459. # ============= i/ifonetic.h ==============
  460. echo "x - extracting i/ifonetic.h (Text)"
  461. sed 's/^X//' << 'SHAR_EOF' > i/ifonetic.h &&
  462. X/* ifonetic.h */
  463. X/********************************************
  464. X* name list and map array used by ifonetic.c
  465. X* Istvan Mohos, 1990 --- in the Public Domain
  466. X*********************************************/
  467. X
  468. X#define IFONCNT 106
  469. X
  470. Xstatic char *listfonet[] = {
  471. X  "ack","amp","apo","ast","ats","ban","bar","bel","bqu","bsl","bsp","can","car",
  472. X  "cca","ccb","ccc","ccd","cce","ccf","ccg","cch","cci","ccj",
  473. X  "cck","ccl","ccm","ccn","cco","ccp","ccq","ccr","ccs","cct",
  474. X  "ccu","ccv","ccw","ccx","ccy","ccz",
  475. X  "cir","col","com","das","dc1","dc2","dc3","dc4","del","dle","dol","dot","eks",
  476. X  "eme","enq","eot","equ","esc","etb","etx","exc","exx","fil","gra","gre","gro",
  477. X  "has","lan","lcu","les","lpa","lsq","min","nak","new","nul","pag",
  478. X  "per","pip","plu","poi","pou","que","quo","ran","rcu","rec","ret","rpa","rsq",
  479. X  "sem","sha","sin","sla","soh","sou","spa","sta","stx","sub",
  480. X  "syn","tab","tic","til","und","uni","ver",};
  481. X
  482. Xstatic char mapfonet[] = {
  483. X      6,   38,   39,   42,   64,   33,  124,    7,   96,   92,    8,   24,   94,
  484. X      1,    2,    3,    4,    5,    6,    7,    8,    9,   10,
  485. X     11,   12,   13,   14,   15,   16,   17,   18,   19,   20,
  486. X     21,   22,   23,   24,   25,   26,
  487. X     94,   58,   44,   45,   17,   18,   19,   20,  127,   16,   36,   46,   88,
  488. X     25,    5,    4,   61,   27,   23,    3,   33,   88,   28,   96,   62,   29,
  489. X     35,   60,  123,   60,   40,   91,   45,   21,   10,    0,   12,
  490. X     37,  124,   43,   46,   35,   63,   34,   62,  125,   30,   13,   41,   93,
  491. X     59,   35,   15,   47,    1,   14,   32,   42,    2,   26,
  492. X     22,    9,   39,  126,   95,   31,   11, };
  493. SHAR_EOF
  494. $TOUCH -am 0601070590 i/ifonetic.h &&
  495. chmod 0644 i/ifonetic.h ||
  496. echo "restore of i/ifonetic.h failed"
  497. set `wc -c i/ifonetic.h`;Wc_c=$1
  498. if test "$Wc_c" != "1617"; then
  499.     echo original size 1617, current size $Wc_c
  500. fi
  501. # ============= i/ilib.h ==============
  502. echo "x - extracting i/ilib.h (Text)"
  503. sed 's/^X//' << 'SHAR_EOF' > i/ilib.h &&
  504. X/* ilib.h */
  505. X/*********************************************************************
  506. X* This is the client's #include file for accessing functions in ilib.a
  507. X* Istvan Mohos, 1987 --- in the Public Domain
  508. X**********************************************************************/
  509. X
  510. X/* functions archived in ilib.a: */
  511. Xchar * ialntok();
  512. Xchar * ianymatch();
  513. Xchar * ianytok();
  514. Xvoid   iblank();
  515. Xint    ibreakl();
  516. Xchar * ictok();
  517. Xchar * icopy();
  518. Xint    icount();
  519. Xvoid   icue();
  520. Xint    idamage();
  521. Xchar * idate();
  522. Xvoid   idump();
  523. Xint    iego();
  524. Xint    ierror();
  525. Xint    iexpect();
  526. Xint    ifamily();
  527. Xint    ifilter();
  528. Xint    ifonetic();
  529. Xint    ifrombit();
  530. Xint    igroup();
  531. Xint    ihash();
  532. Xint    ihasharg();
  533. Xchar * ihms();
  534. Xint    iinput();
  535. Xint    iline();
  536. Xint    ilist();
  537. Xint    ilistn();
  538. Xint    illistn();
  539. Xint    ilongest();
  540. Xint    ilower();
  541. Xchar * imatch();
  542. Xint    imode();
  543. Xint    imonth();
  544. Xint    inest();
  545. Xchar * inl();
  546. Xchar * inull();
  547. Xint    inumsearch();
  548. Xvoid   inumsort();
  549. Xint    inumstrcmp();
  550. Xchar * inextl();
  551. Xint    ioctal();
  552. Xint    iopt();
  553. Xint    iread();
  554. Xint    irotate();
  555. Xint    iround();
  556. Xint    isearch();
  557. Xvoid   isort();
  558. Xchar * istartl();
  559. Xint    istripcom();
  560. Xint    istripdq();
  561. Xint    istripsq();
  562. Xint    istripstr();
  563. Xint    iswap();
  564. Xint    itexrect();
  565. Xchar * itobit();
  566. Xint    itoday();
  567. Xint    itohour();
  568. Xint    itok();
  569. Xint    itomin();
  570. Xint    itomonth();
  571. Xint    itosec();
  572. Xint    itoyear();
  573. Xint    itran();
  574. Xvoid   itwin();
  575. Xint    iuniq();
  576. Xint    iuniqa();
  577. Xint    iupper();
  578. Xchar * iwhich();
  579. Xint    iwrite();
  580. Xint    iwritopn();
  581. Xchar * ixmatch();
  582. Xint    ixsearch();
  583. Xint    ixswap();
  584. X
  585. Xchar * malloc();
  586. Xchar * calloc();
  587. Xchar * gets();
  588. Xlong   lseek();
  589. X
  590. X#include <stdio.h>
  591. X#ifndef X_OK
  592. X#    ifdef REALUNIX
  593. X#        define F_OK 0
  594. X#        define X_OK 1
  595. X#        define W_OK 2
  596. X#        define R_OK 4
  597. X#        include <fcntl.h>
  598. X#    else
  599. X#        include <sys/file.h>
  600. X#    endif
  601. X#endif
  602. X
  603. X#ifdef REALUNIX
  604. X   void memcpy(); /* in truth, char* */
  605. X#  define ibcopy(a,b,c) memcpy((a),(b),(c))
  606. X
  607. X   int memcmp();
  608. X#  define ibcmp(a,b,c)  memcmp((a),(b),(c))
  609. X#else
  610. X   void bcpy();
  611. X#  define ibcopy(a,b,c) bcopy((b),(a),(c))
  612. X
  613. X   int bcmp();
  614. X#  define ibcmp(a,b,c)  bcmp((a),(b),(c))
  615. X#endif
  616. X
  617. Xextern char ierbuf[];
  618. Xextern int  ierflag;
  619. X
  620. X/* imode symbolic constants, modeled after stat.h list */
  621. X#define ISSOCK   0140000   /* socket */
  622. X#define ISLNK    0120000   /* symbolic link */
  623. X#define ISREG    0100000   /* regular */
  624. X#define ISBLK    0060000   /* block special */
  625. X#define ISDIR    0040000   /* directory */
  626. X#define ISCHR    0020000   /* character special */
  627. X#define ISFIFO   0010000   /* named pipe */
  628. X#define ISUID    0004000   /* set uid on execution */
  629. X#define ISGID    0002000   /* set gid on execution */
  630. X#define ISSTICK  0001000   /* keep text in memory (sticky bit) */
  631. X#define ISROWN   0000400   /* read, owner */
  632. X#define ISWOWN   0000200   /* write, owner */
  633. X#define ISXOWN   0000100   /* execute/search, owner */
  634. X#define ISRGRP   0000040   /* read, group */
  635. X#define ISWGRP   0000020   /* write, group */
  636. X#define ISXGRP   0000010   /* execute/search, group */
  637. X#define ISRALL   0000004   /* read, others */
  638. X#define ISWALL   0000002   /* write, others */
  639. X#define ISXALL   0000001   /* execute/search, others */
  640. X
  641. X#define INITOKF       1    /* setup forward parsing */
  642. X#define INITOKR      -1    /* setup reverse parsing */
  643. X#define ITOKF         2    /* forward parse */
  644. X#define ITOKR        -2    /* reverse parse */
  645. X
  646. X#define DOUNCOUN(x,y) (y) = (x); --(y) >= 0
  647. X#define BADCHARP(p)   ((p) == (char *)NULL || *(p) == '\0')
  648. X#define NULCHARP(p)   ((p) == (char *)NULL)
  649. X#define ZPT           (char *)NULL
  650. X
  651. X#define IANYTOK       0
  652. X#define IALNTOK       1
  653. X#define ICTOK         2
  654. X
  655. X#define SPACE_LINE   -1
  656. X#define LINE_ONLY     0
  657. X#define LINE_SPACE    1
  658. X
  659. X#define IROTR         1 /* rotate 90 deg. to right */
  660. X#define IROTL        -1 /* rotate 90 deg. to left */
  661. X#define IROTOR        3 /* rotate 180 deg. over and 90 deg. to right */
  662. X#define IROTOL       -3 /* rotate 180 deg. over and 90 deg. to left */
  663. X
  664. X#define SHORTMO       0 /* idate format: Jun 23 1988 */
  665. X#define SHORTUPMO     1 /* idate format: JUN 23 1988 */
  666. X#define LONGMO        2 /* idate format: June 23, 1988 */
  667. X#define LONGUPMO      3 /* idate format: JUNE 23, 1988 */
  668. X
  669. X#define WHITE(c)      ((c) < 33)
  670. X#define BLACK(c)      ((c) > 32)
  671. X#define TONEXWHITE(p) while (*(p) && (*(p)>32)) (p)++
  672. X#define TONEXBLACK(p) while (*(p) && (*(p)<33)) (p)++
  673. X
  674. X#define IFOURK        4096
  675. X#define ITWOK         2048
  676. X#define IONEK         1024
  677. X#define IHALFK        512
  678. X#define IQUARTK       256
  679. X
  680. X/* man page macro converts line-starting Q into right arrow */
  681. X#ifdef  IMANFMT
  682. X#define Q
  683. X#endif
  684. SHAR_EOF
  685. $TOUCH -am 0601073090 i/ilib.h &&
  686. chmod 0644 i/ilib.h ||
  687. echo "restore of i/ilib.h failed"
  688. set `wc -c i/ilib.h`;Wc_c=$1
  689. if test "$Wc_c" != "4616"; then
  690.     echo original size 4616, current size $Wc_c
  691. fi
  692. # ============= i/imapalnum.h ==============
  693. echo "x - extracting i/imapalnum.h (Text)"
  694. sed 's/^X//' << 'SHAR_EOF' > i/imapalnum.h &&
  695. X/* imapalnum.h */
  696. X/********************************************
  697. X* character map array used by ialntok.c
  698. X* Istvan Mohos, 1987 --- in the Public Domain
  699. X*********************************************/
  700. X
  701. Xstatic char mapalnum[] = {
  702. X  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  703. X  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  704. X  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  705. X  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,
  706. X  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
  707. X  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,
  708. X  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
  709. X  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,
  710. X};
  711. SHAR_EOF
  712. $TOUCH -am 0425094990 i/imapalnum.h &&
  713. chmod 0644 i/imapalnum.h ||
  714. echo "restore of i/imapalnum.h failed"
  715. set `wc -c i/imapalnum.h`;Wc_c=$1
  716. if test "$Wc_c" != "748"; then
  717.     echo original size 748, current size $Wc_c
  718. fi
  719. # ============= i/iupcas.h ==============
  720. echo "x - extracting i/iupcas.h (Text)"
  721. sed 's/^X//' << 'SHAR_EOF' > i/iupcas.h &&
  722. X/* iupcas.h */
  723. X/********************************************
  724. X* character map array used by iupper.c
  725. X* Istvan Mohos, 1987 --- in the Public Domain
  726. X*********************************************/
  727. X
  728. Xstatic char upcas[] = {
  729. X  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
  730. X 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  731. X 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  732. X 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
  733. X 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
  734. X 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
  735. X 96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
  736. X 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,123,124,125,126,127,
  737. X};
  738. SHAR_EOF
  739. $TOUCH -am 0425095090 i/iupcas.h &&
  740. chmod 0644 i/iupcas.h ||
  741. echo "restore of i/iupcas.h failed"
  742. set `wc -c i/iupcas.h`;Wc_c=$1
  743. if test "$Wc_c" != "741"; then
  744.     echo original size 741, current size $Wc_c
  745. fi
  746. # ============= i/makefile ==============
  747. echo "x - extracting i/makefile (Text)"
  748. sed 's/^X//' << 'SHAR_EOF' > i/makefile &&
  749. X#
  750. XCC=/bin/cc
  751. XCFLAGS=-O
  752. X
  753. X# SYSV:  comment out 'ranlib ilib.a'
  754. X#        CFLAGS=-O -DREALUNIX
  755. X# 6300+: -DPLUS6300
  756. X
  757. X#.SILENT:
  758. X
  759. XCOMPLEX=ialntok.o ictok.o ifonetic.o ilower.o iupper.o
  760. X
  761. XPLAIN=ianymatch.o ianytok.o iblank.o ibreakl.o \
  762. X    icopy.o icount.o \
  763. X    icue.o idamage.o idate.o idump.o iego.o ierror.o \
  764. X    iexpect.o ifamily.o ifilter.o ifrombit.o \
  765. X    igroup.o ihash.o ihasharg.o ihms.o \
  766. X    ilast.o iline.o ilist.o ilistn.o illistn.o \
  767. X    ilongest.o imatch.o imode.o imonth.o \
  768. X    iinput.o inest.o inl.o inumstrcmp.o inumsearch.o \
  769. X    inumsort.o inextl.o ioctal.o iopt.o iread.o irotate.o \
  770. X    iround.o isearch.o isort.o istartl.o istripcom.o \
  771. X    istripdq.o istripsq.o istripstr.o iswap.o ixswap.o \
  772. X    itexrect.o itoday.o \
  773. X    itok.o itran.o iuniq.o iuniqa.o iwhich.o iwrite.o \
  774. X    iwritopn.o ixmatch.o ixsearch.o
  775. X
  776. Xilib.a:    ${PLAIN} ${COMPLEX}
  777. X    ar rul ilib.a ${PLAIN} ${COMPLEX}
  778. X    ranlib ilib.a
  779. X
  780. X${PLAIN}:   i.h
  781. Xialntok.o:  i.h imapalnum.h  ialntok.c
  782. Xictok.o:    i.h icmapalnum.h ictok.c
  783. Xifonetic.o: i.h ifonetic.h   ifonetic.c
  784. Xilower.o:   i.h idowncas.h   ilower.c
  785. Xiupper.o:   i.h iupcas.h     iupper.c
  786. SHAR_EOF
  787. $TOUCH -am 0605074590 i/makefile &&
  788. chmod 0644 i/makefile ||
  789. echo "restore of i/makefile failed"
  790. set `wc -c i/makefile`;Wc_c=$1
  791. if test "$Wc_c" != "1080"; then
  792.     echo original size 1080, current size $Wc_c
  793. fi
  794. # ============= iex/add.c ==============
  795. if test ! -d 'iex'; then
  796.     echo "x - creating directory iex"
  797.     mkdir 'iex'
  798. fi
  799. echo "x - extracting iex/add.c (Text)"
  800. sed 's/^X//' << 'SHAR_EOF' > iex/add.c &&
  801. X#ifdef NEVER
  802. X/bin/cc -O -DIMANFMT -I../i $0 ../i/ilib.a -lm -o $BIN/add
  803. Xexit 0
  804. X#endif
  805. X
  806. X/* add leading number on each line of input, print total */
  807. X#include "ilib.h"
  808. Xdouble atof();
  809. X
  810. Xmain (argc, argv)
  811. Xint argc;
  812. Xchar *argv[];
  813. X{
  814. X    char number[32];
  815. X    char **opt = &argv[1];
  816. X    char *buf;
  817. X    char *list;
  818. X    char **lp;
  819. X    int bufsiz;
  820. X    int lines;
  821. X    int frac = 0;
  822. X    double total = 0.;
  823. X
  824. XQ   if (iopt (&opt) == 'r')
  825. X        frac = atoi (*opt++);
  826. X    if ((bufsiz = ifilter (*opt, &buf)) < 0)
  827. X        puts (ierbuf), exit (1);
  828. X    if ((lines = illistn (buf, buf + bufsiz, &list)) < 0)
  829. X        puts (ierbuf), exit (1);
  830. X
  831. XQ   for (lp = (char **)list; --lines >= 0; total += atof (*lp++));
  832. X    sprintf (number, "%.8f", total);
  833. XQ   iround (number, inull(number), frac);
  834. X    puts (number);
  835. X    exit(0);
  836. X}
  837. SHAR_EOF
  838. $TOUCH -am 0605075390 iex/add.c &&
  839. chmod 0755 iex/add.c ||
  840. echo "restore of iex/add.c failed"
  841. set `wc -c iex/add.c`;Wc_c=$1
  842. if test "$Wc_c" != "740"; then
  843.     echo original size 740, current size $Wc_c
  844. fi
  845. # ============= iex/area.c ==============
  846. echo "x - extracting iex/area.c (Text)"
  847. sed 's/^X//' << 'SHAR_EOF' > iex/area.c &&
  848. X#ifdef NEVER
  849. X/bin/cc -O -DIMANFMT -DAREAF=\"$HOME/.area\" -DNOWF=\"$HOME/.now\" \
  850. X-I../i $0 ../i/ilib.a -o $BIN/area
  851. X(/bin/rm -f $BIN/now)
  852. X/bin/ln $BIN/area $BIN/now
  853. Xexit 0
  854. X#endif
  855. X
  856. X/* data base lookup */
  857. X#include "ilib.h"
  858. X#define  NOW  244
  859. X
  860. Xmain (argc, argv)
  861. Xint argc;
  862. Xchar *argv[];
  863. X{
  864. X    static char cmdstr[IONEK]; /* concatenate disjoint argv strings */
  865. X    static char space[] = {32};/* space, to separate argv strings */
  866. X    char **word = &argv[1];    /* ptr to argv strings */
  867. X    char *db;                  /* pointer to file name */
  868. X    char *buffer;              /* for storing data base */
  869. X    char *list;                /* pointer list to lines of data base */
  870. X    int bytes;                 /* byte count of data base */
  871. X    int lines;                 /* count of ptrs to lines of data base */
  872. X    int context;               /* which command to execute */
  873. X    int indx;                  /* of matching record in data base */
  874. X    int offset;                /* from Greenwich Mean, in record */
  875. X    int hours;                 /* in GMT time stamp */
  876. X
  877. X    if ((context = ihasharg(argv[0],'/')) == NOW)
  878. X        db = NOWF;
  879. X    else
  880. X        db = AREAF;
  881. X
  882. X    /* unify individual command line arguments like: New York City */
  883. X    for (; !NULCHARP (*word); word++)
  884. X        strcat (cmdstr, *word), strcat (cmdstr, space);
  885. X    cmdstr[strlen (cmdstr) -1] = 0; /* loose trailing space */
  886. X
  887. X    /* read data base, create pointer list, sort pointers */
  888. X    if ((bytes = iread (db, &buffer)) < 0)
  889. X        fprintf (stderr, "%s\n", ierbuf), exit (1);
  890. XQ   if ((lines = illistn (buffer, buffer + bytes, &list)) < 0)
  891. X        fprintf (stderr, "%s\n", ierbuf), exit (1);
  892. XQ   isort ((char **)list, lines);
  893. X
  894. X    /* find the matching string in the data base */
  895. XQ   if ((indx = isearch (cmdstr, (char **)list, lines)) < 0)
  896. X        fprintf (stderr, "No record of %s in %s\n", cmdstr, db),
  897. X        exit (1);
  898. X
  899. X    if (context == NOW) {
  900. X        offset = atoi (*((char **)list + indx) + strlen (cmdstr));
  901. X        strcpy (cmdstr, ihms (0));
  902. X        if ((hours = atoi (cmdstr)) + offset > 24)
  903. X            sprintf (cmdstr, "%.2d", hours + offset - 24);
  904. X        else if (hours + offset < 0)
  905. X            sprintf (cmdstr, "%.2d", hours + offset + 24);
  906. X        else
  907. X            sprintf (cmdstr, "%.2d", hours + offset);
  908. X        cmdstr[2] = ':';
  909. X        puts (cmdstr);
  910. X    }
  911. X    else
  912. X        puts (*((char **)list + indx));
  913. X
  914. X    exit(0);
  915. X}
  916. SHAR_EOF
  917. $TOUCH -am 0605075390 iex/area.c &&
  918. chmod 0755 iex/area.c ||
  919. echo "restore of iex/area.c failed"
  920. set `wc -c iex/area.c`;Wc_c=$1
  921. if test "$Wc_c" != "2221"; then
  922.     echo original size 2221, current size $Wc_c
  923. fi
  924. # ============= iex/banner.c ==============
  925. echo "x - extracting iex/banner.c (Text)"
  926. sed 's/^X//' << 'SHAR_EOF' > iex/banner.c &&
  927. X#ifdef NEVER
  928. X/bin/cc -O -DIMANFMT -I../i $0 ../i/ilib.a -o $BIN/banner
  929. Xexit 0
  930. X#endif
  931. X
  932. X/* output command line strings in large letters */
  933. X#include "ilib.h"
  934. X
  935. Xstatic char banchars[96][7] = {
  936. X{  0,  0,  0,  0,  0,  0,  0},      { 28, 28, 28,  8,  0, 28,  8},
  937. X{119,119, 34, 68,  0,  0,  0},      { 20, 20,127, 20,127, 20, 20},
  938. X{ 62, 73, 72, 62,  9, 73, 62},      {113, 82,116,  8, 23, 37, 71},
  939. X{ 24, 36, 24, 56, 69, 66, 57},      { 28, 28,  8, 16,  0,  0,  0},
  940. X{ 12, 16, 32, 32, 32, 16, 12},      { 24,  4,  2,  2,  2,  4, 24},
  941. X{  0, 34, 20,127, 20, 34,  0},      {  0,  8,  8, 62,  8,  8,  0},
  942. X{  0,  0,  0, 28, 28,  8, 16},      {  0,  0,  0, 62,  0,  0,  0},
  943. X{  0,  0,  0,  0, 28, 28, 28},      {  1,  2,  4,  8, 16, 32, 64},
  944. X{ 28, 34, 65, 65, 65, 34, 28},      {  8, 24, 40,  8,  8,  8, 62},
  945. X{ 62, 65,  1, 62, 64, 64,127},      { 62, 65,  1, 62,  1, 65, 62},
  946. X{ 64, 66, 66, 66,127,  2,  2},      {127, 64, 64,126,  1, 65, 62},
  947. X{ 62, 65, 64,126, 65, 65, 62},      {127, 66,  4,  8, 16, 16, 16},
  948. X{ 62, 65, 65, 62, 65, 65, 62},      { 62, 65, 65, 63,  1, 65, 62},
  949. X{  8, 28,  8,  0,  8, 28,  8},      { 28, 28,  0, 28, 28,  8, 16},
  950. X{  4,  8, 16, 32, 16,  8,  4},      {  0,  0, 62,  0, 62,  0,  0},
  951. X{ 16,  8,  4,  2,  4,  8, 16},      { 62, 65,  1, 14,  8,  0,  8},
  952. X{ 62, 65, 93, 93, 94, 64, 62},      {  8, 20, 34, 65,127, 65, 65},
  953. X{126, 65, 65,126, 65, 65,126},      { 62, 65, 64, 64, 64, 65, 62},
  954. X{126, 65, 65, 65, 65, 65,126},      {127, 64, 64,124, 64, 64,127},
  955. X{127, 64, 64,124, 64, 64, 64},      { 62, 65, 64, 79, 65, 65, 62},
  956. X{ 65, 65, 65,127, 65, 65, 65},      { 28,  8,  8,  8,  8,  8, 28},
  957. X{  1,  1,  1,  1, 65, 65, 62},      { 66, 68, 72,112, 72, 68, 66},
  958. X{ 64, 64, 64, 64, 64, 64,127},      { 65, 99, 85, 73, 65, 65, 65},
  959. X{ 65, 97, 81, 73, 69, 67, 65},      { 62, 65, 65, 65, 65, 65, 62},
  960. X{126, 65, 65,126, 64, 64, 64},      { 62, 65, 65, 65, 69, 66, 61},
  961. X{126, 65, 65,126, 68, 66, 65},      { 62, 65, 64, 62,  1, 65, 62},
  962. X{127,  8,  8,  8,  8,  8,  8},      { 65, 65, 65, 65, 65, 65, 62},
  963. X{ 65, 65, 65, 65, 34, 20,  8},      { 65, 73, 73, 73, 73, 73, 54},
  964. X{ 65, 34, 20,  8, 20, 34, 65},      { 65, 34, 20,  8,  8,  8,  8},
  965. X{127,  2,  4,  8, 16, 32,127},      { 62, 32, 32, 32, 32, 32, 62},
  966. X{ 64, 32, 16,  8,  4,  2,  1},      { 62,  2,  2,  2,  2,  2, 62},
  967. X{  8, 20, 34,  0,  0,  0,  0},      {  0,  0,  0,  0,  0,  0,127},
  968. X{ 28, 28,  8,  4,  0,  0,  0},      {  0, 12, 18, 33, 63, 33, 33},
  969. X{  0, 62, 33, 62, 33, 33, 62},      {  0, 30, 33, 32, 32, 33, 30},
  970. X{  0, 62, 33, 33, 33, 33, 62},      {  0, 63, 32, 62, 32, 32, 63},
  971. X{  0, 63, 32, 62, 32, 32, 32},      {  0, 30, 33, 32, 39, 33, 30},
  972. X{  0, 33, 33, 63, 33, 33, 33},      {  0,  4,  4,  4,  4,  4,  4},
  973. X{  0,  1,  1,  1,  1, 33, 30},      {  0, 33, 34, 60, 36, 34, 33},
  974. X{  0, 32, 32, 32, 32, 32, 63},      {  0, 33, 51, 45, 33, 33, 33},
  975. X{  0, 33, 49, 41, 37, 35, 33},      {  0, 30, 33, 33, 33, 33, 30},
  976. X{  0, 62, 33, 33, 62, 32, 32},      {  0, 30, 33, 33, 37, 34, 29},
  977. X{  0, 62, 33, 33, 62, 34, 33},      {  0, 30, 32, 30,  1, 33, 30},
  978. X{  0, 31,  4,  4,  4,  4,  4},      {  0, 33, 33, 33, 33, 33, 30},
  979. X{  0, 33, 33, 33, 33, 18, 12},      {  0, 33, 33, 33, 45, 51, 33},
  980. X{  0, 33, 18, 12, 12, 18, 33},      {  0, 17, 10,  4,  4,  4,  4},
  981. X{  0, 63,  2,  4,  8, 16, 63},      { 28, 32, 16,112, 16, 32, 28},
  982. X{  8,  8,  8,  0,  8,  8,  8},      { 28,  2,  4,  7,  4,  2, 28},
  983. X{ 48, 73,  6,  0,  0,  0,  0},      {  0,  0,  0,  0,  0,  0,  0}
  984. X};
  985. X
  986. X#define SPACE 32
  987. X
  988. Xmain (argc, argv)
  989. Xint argc;
  990. Xchar *argv[];
  991. X{
  992. X    char **word;         /* pointer to argv list */
  993. X    char line[ITWOK];    /* 2K buffer to hold single line of 'pixels' */
  994. X    char *cp;            /* point to individual chars of 'word' */
  995. X    char *ip;            /* pointer in 'line' buffer */
  996. X    int  ri;             /* loop counter of pixel height (7) */
  997. X    int  wlen;           /* string length of a given word */
  998. X
  999. X    if (argc < 2)
  1000. X        fprintf(stderr,
  1001. X"Usage: %s word ...\n%s", argv[0],
  1002. X"\toutput each 'word' in large characters, on a line by itself\n"),
  1003. X        exit(1);
  1004. X
  1005. X    for (word = argv+1; !NULCHARP (*word); word++) {
  1006. X        wlen = ifonetic (*word);
  1007. X        if (wlen > 256) /* horizontal pixel string would overrun line */
  1008. X            fprintf(stderr, "Word too long: %s (max. 256 bytes)\n",
  1009. X            *word), exit (1);
  1010. X    }
  1011. X
  1012. X    for (word = argv+1; !NULCHARP (*word); word++) {
  1013. X        for (ri = 0; ri < 7; ri++) {
  1014. X            for (ip = line, cp = *word; *cp; cp++) {
  1015. X                if (*cp < SPACE)
  1016. X                    continue;
  1017. X                sprintf (ip, "%s%c",
  1018. XQ               itobit (banchars[*cp-SPACE][ri],7,SPACE,'#'), SPACE);
  1019. X                icue (&ip);
  1020. X            }
  1021. X            *--ip = '\0'; /* erase last space */
  1022. X            puts (line);
  1023. X        }
  1024. X        puts (""); /* extra line at bottom of banner text */
  1025. X    }
  1026. X
  1027. X    exit(0);
  1028. X}
  1029. SHAR_EOF
  1030. $TOUCH -am 0605075390 iex/banner.c &&
  1031. chmod 0755 iex/banner.c ||
  1032. echo "restore of iex/banner.c failed"
  1033. set `wc -c iex/banner.c`;Wc_c=$1
  1034. if test "$Wc_c" != "4609"; then
  1035.     echo original size 4609, current size $Wc_c
  1036. fi
  1037. # ============= iex/behead.c ==============
  1038. echo "x - extracting iex/behead.c (Text)"
  1039. sed 's/^X//' << 'SHAR_EOF' > iex/behead.c &&
  1040. X#ifdef NEVER
  1041. X/bin/cc -O -DIMANFMT -I../i $0 ../i/ilib.a -o $BIN/behead
  1042. Xexit 0
  1043. X#endif
  1044. X
  1045. X/* in place, delete leading lines of files */
  1046. X#include "ilib.h"
  1047. X
  1048. Xmain (argc,argv)
  1049. Xint argc;
  1050. Xchar *argv[];
  1051. X{
  1052. X    char **file = argv;
  1053. X    char *buf;             /* point to buffer malloc'd by iread() */
  1054. X    char *end;             /* point to one byte past buffer */
  1055. X    char *ptr;             /* working pointer */
  1056. X    int filesize;          /* size of malloc'd buffer */
  1057. X    int string = 0;        /* assume number option on command line */
  1058. X    int delcount;          /* number of lines to delete */
  1059. X    int linesize;          /* byte count of current line */
  1060. X    int cnt;               /* working counter */
  1061. X
  1062. X    if (argc < 3)
  1063. X        fprintf (stderr,
  1064. X"Usage: %s number|string file ...\n\%s%s%s", *file,
  1065. X"\tdelete first <number> lines of each file or\n",
  1066. X"\tall leading lines until a line begins with <string>\n",
  1067. X"\t(nothing is deleted if no line begins with <string>)\n\n"), exit(1);
  1068. X
  1069. X    if ((delcount = atoi(*++file)) < 1)  /* look for a string */
  1070. X        string = 1, ifonetic (*file);
  1071. X
  1072. X    for (++file; !NULCHARP (*file); file++) {
  1073. X        if ((filesize = iread (*file, &buf)) < 1) {
  1074. X            fprintf (stderr, "%s %s\n", ierbuf, *file);
  1075. X            continue;
  1076. X        }
  1077. X        ptr = buf;
  1078. X        end = buf + filesize;
  1079. X
  1080. X        if (string) {
  1081. XQ           if ((ptr = istartl (buf, end, argv[1])) == NULL) {
  1082. X                free (buf);
  1083. X                fprintf (stderr, "No line starts with '%s' in %s\n",
  1084. X                    argv[1], *file);
  1085. X                continue;
  1086. X            }
  1087. X            while (ptr > buf && WHITE (*(ptr-1)) && *(ptr-1) != '\n')
  1088. X                --ptr;           /* back up to beginning of line */
  1089. X        }
  1090. X        else {
  1091. X            for (DOUNCOUN (delcount, cnt);) {
  1092. X                if ((linesize = iline (ptr, end)) < 1)
  1093. X                    break;       /* not enough lines in file */
  1094. X                ptr += linesize;
  1095. X            }
  1096. X        }
  1097. X
  1098. X        /* write remainder over original file */
  1099. X        if (iwrite (*file, ptr, end) < 0)
  1100. X            fprintf (stderr, "%s %s\n", ierbuf, *file);
  1101. X        free (buf);
  1102. X    }
  1103. X    exit (0);
  1104. X}
  1105. SHAR_EOF
  1106. $TOUCH -am 0605075390 iex/behead.c &&
  1107. chmod 0755 iex/behead.c ||
  1108. echo "restore of iex/behead.c failed"
  1109. set `wc -c iex/behead.c`;Wc_c=$1
  1110. if test "$Wc_c" != "1862"; then
  1111.     echo original size 1862, current size $Wc_c
  1112. fi
  1113. # ============= iex/char.c ==============
  1114. echo "x - extracting iex/char.c (Text)"
  1115. sed 's/^X//' << 'SHAR_EOF' > iex/char.c &&
  1116. X#ifdef NEVER
  1117. X/bin/cc -O -DIMANFMT -I../i $0 ../i/ilib.a -o $BIN/char
  1118. Xexit 0
  1119. X#endif
  1120. X
  1121. X/* output space separated character lists */
  1122. X#include "ilib.h"
  1123. X#define SPACE 32
  1124. X
  1125. Xmain (argc, argv)
  1126. Xint argc;
  1127. Xchar *argv[];
  1128. X{
  1129. X    char **range;        /* defines range of ASCII values to output */
  1130. X    char *first, *last;  /* limit pointers */
  1131. X    int  begin = 1;      /* flag to suppress first (leading) space */
  1132. X    int  ri;             /* scratch counter */
  1133. X
  1134. X    if (argc < 2)
  1135. X        fprintf(stderr, "Usage: %s range [range ...]\n%s", argv[0],
  1136. X"\toutput space-separated ASCII byte sequence delimited by 'range'\n"),
  1137. X        exit(1);
  1138. X
  1139. X    /* in each range, output character list */
  1140. X    for (range = argv+1; !NULCHARP (*range); range++) {
  1141. XQ       if (ifonetic (*range) < 2)
  1142. X            first = last = *range;
  1143. X        else
  1144. X            first = *range, last = first+1;
  1145. X
  1146. X        if (*first < *last) {
  1147. X            for (ri = *first; ri <= *last; ri++)
  1148. X                if (begin)
  1149. X                    putchar (ri), begin = 0;
  1150. X                else
  1151. X                    putchar (SPACE), putchar (ri);
  1152. X        }
  1153. X        else {
  1154. X            for (ri = *first; ri >= *last; ri--)
  1155. X                if (begin)
  1156. X                    putchar (ri), begin = 0;
  1157. X                else
  1158. X                    putchar (SPACE), putchar (ri);
  1159. X        }
  1160. X    }
  1161. X    puts (""); /* final newline */
  1162. X
  1163. X    exit(0);
  1164. X}
  1165. SHAR_EOF
  1166. $TOUCH -am 0605075390 iex/char.c &&
  1167. chmod 0755 iex/char.c ||
  1168. echo "restore of iex/char.c failed"
  1169. set `wc -c iex/char.c`;Wc_c=$1
  1170. if test "$Wc_c" != "1143"; then
  1171.     echo original size 1143, current size $Wc_c
  1172. fi
  1173. # ============= iex/cnum.c ==============
  1174. echo "x - extracting iex/cnum.c (Text)"
  1175. sed 's/^X//' << 'SHAR_EOF' > iex/cnum.c &&
  1176. X#ifdef NEVER
  1177. X/bin/cc -O -DIMANFMT -I../i $0 ../i/ilib.a -o $BIN/cnum
  1178. Xexit 0
  1179. X#endif
  1180. X
  1181. X/* custom line numbering via command line options */
  1182. X#include "ilib.h"
  1183. X
  1184. Xmain (argc,argv)
  1185. Xint argc;
  1186. Xchar *argv[];
  1187. X{
  1188. X    char line[IHALFK];
  1189. X    char build[IHALFK*4];
  1190. X    char format[32];
  1191. X    char *prepend;
  1192. X    char *append;
  1193. X    char *tail;
  1194. XQ   char **optval;
  1195. XQ   int  optchar;
  1196. X    int  linecount = 100;
  1197. X    int  thisnum = 1;
  1198. X    int  increment = 1;
  1199. X    int  justify = 1;
  1200. X    int  new = 0;
  1201. X    int  aftertext = 0;
  1202. X    int  zerofill = 0;
  1203. X    char base = 'd';
  1204. X
  1205. X    if (argc == 1)
  1206. X        printusage (argv[0]), exit (1);
  1207. X
  1208. X    /* command line args, subject file, or both */
  1209. XQ   optval = &(argv[1]);
  1210. XQ   while (optchar = iopt (&optval)) {
  1211. XQ       switch (optchar) {
  1212. X        case 'c':
  1213. XQ           linecount = abs (atoi (*optval));
  1214. X            new = 1;
  1215. X            break;
  1216. X        case 'f':
  1217. X            aftertext = 1;
  1218. X            break;
  1219. X        case 's':
  1220. X            thisnum = atoi (*optval);
  1221. X            break;
  1222. X        case 'i':
  1223. X            increment = atoi (*optval);
  1224. X            break;
  1225. X        case 'j':
  1226. X            justify = atoi (*optval);
  1227. X            break;
  1228. X        case '-':
  1229. X            zerofill = 1;
  1230. X            break;
  1231. X        case 'b':
  1232. X            base = **optval;
  1233. X            if (base != 'x' && base != 'X' && base != 'o')
  1234. X                base = 'd';
  1235. X            break;
  1236. X        case 'p':
  1237. X            prepend = *optval;
  1238. X            break;
  1239. X        case 'a':
  1240. X            append = *optval;
  1241. X            break;
  1242. X        case 't':
  1243. X            tail = *optval;
  1244. X            break;
  1245. X        default:
  1246. X            printusage (argv[0]);
  1247. X            exit (1);
  1248. X        }
  1249. X    }
  1250. X
  1251. XQ   if (!new && !NULCHARP (*optval))  /* rename file to stdin */
  1252. X        if (freopen (*optval, "r", stdin) == NULL)
  1253. X            fprintf (stderr, "Open failed on %s\n", *optval), exit (1);
  1254. X
  1255. X    if (justify > 1 && zerofill)
  1256. X        sprintf(format, "%cs%c.%d%c%cs", '%', '%', justify, base, '%');
  1257. X    else
  1258. X        sprintf(format, "%cs%c%d%c%cs", '%', '%', justify, base, '%');
  1259. X
  1260. X    if (new)
  1261. X        for (strcat (format, "\n"); linecount--; thisnum += increment)
  1262. X            printf(format, prepend, thisnum, append);
  1263. X    else {
  1264. X        while (gets (line) != NULL) {
  1265. X            sprintf (build, format, prepend, thisnum, append);
  1266. X            if (aftertext)
  1267. X               printf ("%s%s%s\n",line, build, tail);
  1268. X            else
  1269. X               printf ("%s%s%s\n", build, line, tail);
  1270. X            thisnum += increment;
  1271. X        }
  1272. X    }
  1273. X
  1274. X    exit (0);
  1275. X}
  1276. X
  1277. Xprintusage (objname)
  1278. Xchar *objname;
  1279. X{
  1280. X    fprintf(stderr, "Usage: %s options [infile]\n%s", objname,
  1281. X"Options: (flag and value may be combined into a single token)\n");
  1282. X
  1283. X    fprintf(stderr, "%s%s%s%s%s%s%s%s%s%s\n",
  1284. X"\t-      ......... print leading zeros in conjunction with -jN\n",
  1285. X"\t-c N   CREATE... N new lines instead of numbering input\n",
  1286. X"\t-s N   START.... the first line with N (may be negative)\n",
  1287. X"\t-i N   INCREMENT or decrement to next line number by N\n",
  1288. X"\t-j N   JUSTIFY.. right to N bytes (-N for left justify)\n",
  1289. X"\t-f *   FOLLOWING instead of leading the line (* is any char)\n",
  1290. X"\t-b B   BASE..... (number base) d=decimal, o=octal, x/X=hex\n",
  1291. X"\t-p S   PREPEND.. string S before sequence numbers\n",
  1292. X"\t-a S   APPEND... string S after sequence numbers\n",
  1293. X"\t-t S   TAIL..... string S past source lines\n");
  1294. X}
  1295. SHAR_EOF
  1296. $TOUCH -am 0605075390 iex/cnum.c &&
  1297. chmod 0755 iex/cnum.c ||
  1298. echo "restore of iex/cnum.c failed"
  1299. set `wc -c iex/cnum.c`;Wc_c=$1
  1300. if test "$Wc_c" != "2846"; then
  1301.     echo original size 2846, current size $Wc_c
  1302. fi
  1303. # ============= iex/cweed.c ==============
  1304. echo "x - extracting iex/cweed.c (Text)"
  1305. sed 's/^X//' << 'SHAR_EOF' > iex/cweed.c &&
  1306. X#ifdef NEVER
  1307. X/bin/cc -O -DIMANFMT -I../i $0 ../i/ilib.a -o $BIN/cweed
  1308. Xexit 0
  1309. X#endif
  1310. X
  1311. X/* list tokens of input with comments removed */
  1312. X#include "ilib.h"
  1313. X#include "../i/icmapalnum.h"
  1314. X
  1315. X#define  SPACE    32
  1316. X
  1317. Xmain (argc,argv)
  1318. Xint argc;
  1319. Xchar *argv[];
  1320. X{
  1321. X    char token[IHALFK];     /* buffer for token */
  1322. X    char *inp;              /* malloc pointer to buffer */
  1323. X    char *endp;             /* end of input text */
  1324. X    char *anchor;           /* save place in buffer */
  1325. X    char *wp;               /* word pointer in line of input text */
  1326. X    int  strsiz;            /* size of input text */
  1327. X    int  firsttok = 1;      /* first token in line */
  1328. X    int  toktype;           /* TRUE if token begins with ALNUM */
  1329. X
  1330. X    if (argc > 2)
  1331. X        fprintf (stderr, "Usage:  %s [file]\n%s%s%s", argv[0],
  1332. X        "\tCopy C tokens of input to stdout (excluding comments),\n",
  1333. X        "\tseparate consecutive non-alphanumeric tokens by a space,\n",
  1334. X        "\tseparate consecutive alphanumeric tokens by a space.\n"),
  1335. X        exit(1);
  1336. X
  1337. X    /* read file into buffer at inp */
  1338. XQ   if ((strsiz = ifilter (argv[1], &inp)) < 1)
  1339. X        fprintf (stderr, "%s at: %s\n", ierbuf, argv[1]), exit(1);
  1340. X    endp = inp + strsiz;
  1341. X
  1342. X    /* remove comments and comment delimiters */
  1343. XQ   istripcom (inp, endp, "/*", "*/");
  1344. X
  1345. X    /* side with the Lilliputian hordes who believe that '{' should
  1346. X       go on the test line; blow away intervening newlines
  1347. X    */
  1348. X    for (anchor = inp;;) {
  1349. X        while (anchor < endp && *anchor++ != '{');
  1350. X        if (anchor == endp)          /* no further '{' in file */
  1351. X            break;
  1352. X        if ((wp = anchor - 3) < inp) /* back from byte past '{' */
  1353. X            continue;
  1354. X        while (WHITE (*wp))
  1355. X            *wp-- = SPACE;           /* brute force */
  1356. X    }
  1357. X
  1358. X    /* print tokens to stdout */
  1359. XQ   for (; strsiz = iline (inp, endp); firsttok = 1) {
  1360. X        anchor = inp;
  1361. X        inp += strsiz;
  1362. XQ       for (wp = anchor; (wp = ictok (wp, inp, token)) != NULL;)
  1363. X            if (firsttok) {
  1364. X                printf ("%s", token), firsttok = 0;
  1365. XQ               toktype = cmapalnum[*token];
  1366. X            }
  1367. X            else {
  1368. X                if (toktype == cmapalnum[*token])
  1369. X                    printf (" %s", token);
  1370. X                else
  1371. X                    printf ("%s", token);
  1372. X                toktype = cmapalnum[*token];
  1373. X            }
  1374. X        if (!firsttok)
  1375. X            puts ("");
  1376. X    }
  1377. X
  1378. X    exit(0);
  1379. X}
  1380. SHAR_EOF
  1381. $TOUCH -am 0605075390 iex/cweed.c &&
  1382. chmod 0755 iex/cweed.c ||
  1383. echo "restore of iex/cweed.c failed"
  1384. set `wc -c iex/cweed.c`;Wc_c=$1
  1385. if test "$Wc_c" != "2114"; then
  1386.     echo original size 2114, current size $Wc_c
  1387. fi
  1388. # ============= iex/defilter.c ==============
  1389. echo "x - extracting iex/defilter.c (Text)"
  1390. sed 's/^X//' << 'SHAR_EOF' > iex/defilter.c &&
  1391. X#ifdef NEVER
  1392. X/bin/cc -O -DIMANFMT -I../i $0 ../i/ilib.a -o $BIN/defilter
  1393. Xexit 0
  1394. X#endif
  1395. X
  1396. X/* replace input file text of filter commands with their output */
  1397. X#include "ilib.h"
  1398. X
  1399. Xmain (argc, argv)
  1400. Xint argc;
  1401. Xchar *argv[];
  1402. X{
  1403. X    char *mktemp(), *realloc();
  1404. X    static char delims[3] = {32, 9, 0}; /* SPACE, TAB */
  1405. X    char outfname[32];     /* collect output in /tmp file */
  1406. X    char line[IFOURK];     /* buffer for line of input */
  1407. X    char **file;           /* pointer to file list in command line */
  1408. X    char **argp;           /* pointer to new arg vector */
  1409. X    char *newargv;         /* dynamically allocated new arg vector */
  1410. X    int  newargc;          /* new arg vector count */
  1411. X    int  childstat;        /* termination status of child process */
  1412. X
  1413. X    if (argc < 3)
  1414. X        fprintf(stderr,
  1415. X"\nUsage: %s 'command' file ...\n%s%s%s%s%s\n", argv[0],
  1416. X"\tsupply input to 'command' from each 'file' in turn;\n",
  1417. X"\treplace text of input 'file' with the output of 'command'.\n",
  1418. X"\t'command' should be an executable object or the name of an\n",
  1419. X"\texecutable script, with or without option flags and options,\n",
  1420. X"\twithout pipes or redirection, quoted to form a single token.\n"),
  1421. X        exit(1);
  1422. X
  1423. X    sprintf (outfname, "/tmp/%s", mktemp ("defil.XXXXXX"));
  1424. X
  1425. X    /* create a NULL terminated, new argv list from 'command' */
  1426. XQ   if ((newargc = ilist (argv[1],inull(argv[1]),delims, &newargv)) < 1)
  1427. X        fprintf (stderr, "'command' argument error\n"), exit (1);
  1428. X
  1429. X    /* ilist allocated an unreported NULL pointer at the end of
  1430. X       newargv, but we still need another pointer for the 'file' arg.
  1431. X    */
  1432. X    if ((newargv = realloc
  1433. X    (newargv, (unsigned int)(newargc+2)*sizeof(char*))) == NULL)
  1434. X        fprintf (stderr, "%s: realloc error\n", argv[0]), exit (1);
  1435. X    *((char **)newargv + newargc + 1) = NULL; /* new sentinel NULL */
  1436. X
  1437. X    for (argp = (char**)newargv; !NULCHARP(*argp); argp++)
  1438. XQ       ifonetic (*argp);
  1439. X    /* argp now points to the next-to-last cell of newargv */
  1440. X
  1441. X    for (file = argv + 2; !NULCHARP (*file); file++) {
  1442. X        /* complete the new command with the name of the next file */
  1443. XQ       *argp = *file;
  1444. X
  1445. X        /* rename input file to stdin, create output file as stdout */
  1446. X        if (freopen (*file, "r", stdin) == NULL)
  1447. X            fprintf (stderr, "Open failed on %s\n", *file), exit (1);
  1448. X        if (freopen (outfname, "w", stdout) == NULL)
  1449. X            fprintf (stderr, "Can't write to %s\n", outfname), exit (1);
  1450. X
  1451. X        switch (fork()) {
  1452. X        case -1:                 /* fork failed */
  1453. X            fprintf (stderr, "Can't create new process\n"), exit (1);
  1454. X        case 0:                  /* child process */
  1455. XQ           execvp (*((char **)newargv), (char **)newargv);
  1456. X            /* exec failed; use ierror to get system error message */
  1457. X            ierror ("");
  1458. X            fprintf(stderr, "%sduring execvp of %s ... %s\n", ierbuf,
  1459. X                *((char **)newargv), *argp), exit (1);
  1460. X        default:                 /* parent process */
  1461. X            wait(&childstat);     /* for child to die */
  1462. X            if (childstat == 0) { /* terminated normally */
  1463. X                sprintf (line, "/bin/mv %s %s", outfname, *file);
  1464. X                if (system (line))
  1465. X                    fprintf (stderr,
  1466. X                    "Can't mv %s to %s\n",outfname, *file), exit (1);
  1467. X            }
  1468. X            else /* leave source intact if command error occurred */
  1469. X                unlink (outfname);
  1470. X            break;
  1471. X        }
  1472. X    }
  1473. X
  1474. X    exit (0);
  1475. X}
  1476. SHAR_EOF
  1477. $TOUCH -am 0605075390 iex/defilter.c &&
  1478. chmod 0755 iex/defilter.c ||
  1479. echo "restore of iex/defilter.c failed"
  1480. set `wc -c iex/defilter.c`;Wc_c=$1
  1481. if test "$Wc_c" != "3151"; then
  1482.     echo original size 3151, current size $Wc_c
  1483. fi
  1484. # ============= iex/distrib.c ==============
  1485. echo "x - extracting iex/distrib.c (Text)"
  1486. sed 's/^X//' << 'SHAR_EOF' > iex/distrib.c &&
  1487. X#ifdef NEVER
  1488. X/bin/cc -O -DIMANFMT -I../i $0 ../i/ilib.a -o $BIN/distrib
  1489. Xexit 0
  1490. X#endif
  1491. X
  1492. X/* count strings in lines */
  1493. X#include "ilib.h"
  1494. X
  1495. Xmain (argc, argv)
  1496. Xint argc;
  1497. Xchar *argv[];
  1498. X{
  1499. X    char **pat;          /* 'pattern' --- pointer to argv list */
  1500. X    char inline[IONEK];  /* 1K buffer to hold line of input */
  1501. X    char *rp;            /* pointer; let optimizer make it 'register' */
  1502. X    int  item;           /* counter of patterns in argv list */
  1503. X    int  plen;           /* string length of a given pattern */
  1504. X
  1505. X    if (argc < 2)
  1506. X        fprintf(stderr, "Usage: %s pattern1 [pattern2 ...]\n%s", argv[0],
  1507. X        "(count occurrence of each pattern in lines of input)\n"), exit(1);
  1508. X
  1509. X    for (pat = argv+1; !NULCHARP (*pat); pat++)
  1510. X        ifonetic (*pat);
  1511. X    /* initialize icount(); non-zero return indicates malloc fail */
  1512. XQ   if (icount (argc-1))
  1513. X        fprintf(stderr, "%s\n", ierbuf), exit(1);
  1514. X
  1515. X    /* in each line read, count occurrence of patterns */
  1516. X    while (fgets (inline, IONEK, stdin) != NULL) {
  1517. X
  1518. X        /* replay line for each pattern, avoid strncmp if possible */
  1519. X        for (item = 0, pat = argv+1; !NULCHARP(*pat); item++, pat++) {
  1520. X            if ((plen = strlen (*pat)) == 1) {
  1521. X                for (rp = inline; *rp; rp++)
  1522. X                     if (*rp == **pat)
  1523. XQ                        icount (item);
  1524. X            }
  1525. X            else {
  1526. X                for (rp = inline; *rp; rp++)
  1527. X                     if (*rp == **pat)
  1528. X                         if (strncmp (rp, *pat, plen) == 0)
  1529. XQ                            icount (item);
  1530. X            }
  1531. X        }
  1532. X    }
  1533. X
  1534. X    /* dummy recall for each pattern, to capture the returned count */
  1535. X    for (item = 0, pat = argv+1; !NULCHARP(*pat); item++, pat++)
  1536. XQ       printf ("%s: %d\n", *pat, icount (item));
  1537. X
  1538. X    /* reset call necessary only if icount() was to be used again:
  1539. XQ   icount (-1);
  1540. X    */
  1541. X
  1542. X    exit(0);
  1543. X}
  1544. SHAR_EOF
  1545. $TOUCH -am 0605075390 iex/distrib.c &&
  1546. chmod 0755 iex/distrib.c ||
  1547. echo "restore of iex/distrib.c failed"
  1548. set `wc -c iex/distrib.c`;Wc_c=$1
  1549. if test "$Wc_c" != "1667"; then
  1550.     echo original size 1667, current size $Wc_c
  1551. fi
  1552. # ============= iex/ego.c ==============
  1553. echo "x - extracting iex/ego.c (Text)"
  1554. sed 's/^X//' << 'SHAR_EOF' > iex/ego.c &&
  1555. X#ifdef NEVER
  1556. X/bin/cc -O -DIMANFMT -I../i $0 ../i/ilib.a -o $BIN/ego
  1557. X(/bin/rm -f $BIN/ext $BIN/path $BIN/egoext)
  1558. X/bin/ln $BIN/ego $BIN/ext
  1559. X/bin/ln $BIN/ego $BIN/path
  1560. X/bin/ln $BIN/ego $BIN/egoext
  1561. Xexit 0
  1562. X#endif
  1563. X
  1564. X/* Get path/, extension, basename, basename.extension from file names */
  1565. X#include "ilib.h"
  1566. X#define EGO       219
  1567. X#define EXT       241
  1568. X#define PATH      301
  1569. X#define EGOEXT    460
  1570. X
  1571. Xmain (argc,argv)
  1572. Xint argc;
  1573. Xchar *argv[];
  1574. X{
  1575. X    char buf[IONEK];
  1576. X    char **file = argv;
  1577. X    int cmd, pathlen, baselen;
  1578. X
  1579. X    if (argc < 2)
  1580. X        fprintf (stderr, "Usage: ego|ext|path|egoext file ...\n%s%s%s%s",
  1581. X        "\tego    --- print name without path/ and .ext to stdout\n",
  1582. X        "\text    --- print ext without path/name.\n",
  1583. X        "\tpath   --- print path/ component only, without name.ext\n",
  1584. X        "\tegoext --- print name.ext without leading path\n\n", *file),
  1585. X        exit (0);
  1586. XQ   cmd = ihasharg (*file++, '/');
  1587. X    for (; !NULCHARP (*file); file++) {
  1588. X        switch (cmd) {
  1589. X            default:
  1590. X            case EGO:
  1591. XQ               iego (*file, buf, '/', '.');
  1592. X                break;
  1593. X            case EXT:
  1594. XQ               pathlen = iego (*file, buf, '/', 0);
  1595. XQ               baselen = iego (*file, buf, '/', '.');
  1596. X                *buf = 0;
  1597. X                if (*(*file+pathlen+baselen) == '.')
  1598. X                    strcpy (buf, *file+pathlen+baselen+1);
  1599. X                break;
  1600. X            case PATH:
  1601. XQ               iego (*file, buf, '/', 0);
  1602. X                break;
  1603. X            case EGOEXT:
  1604. XQ               iego (*file, buf, '/', '/');
  1605. X                break;
  1606. X        }
  1607. X        puts(buf);
  1608. X    }
  1609. X    exit(0);
  1610. X}
  1611. SHAR_EOF
  1612. $TOUCH -am 0605075390 iex/ego.c &&
  1613. chmod 0755 iex/ego.c ||
  1614. echo "restore of iex/ego.c failed"
  1615. set `wc -c iex/ego.c`;Wc_c=$1
  1616. if test "$Wc_c" != "1412"; then
  1617.     echo original size 1412, current size $Wc_c
  1618. fi
  1619. # ============= iex/excise.c ==============
  1620. echo "x - extracting iex/excise.c (Text)"
  1621. sed 's/^X//' << 'SHAR_EOF' > iex/excise.c &&
  1622. X#ifdef NEVER
  1623. X/bin/cc -O -DIMANFMT -I../i $0 ../i/ilib.a -o $BIN/excise
  1624. Xexit 0
  1625. X#endif
  1626. X
  1627. X/* delete line(s) of files that contain a specified string */
  1628. X#include "ilib.h"
  1629. X#define FIRSTONLY 0
  1630. X
  1631. Xmain (argc,argv)
  1632. Xint argc;
  1633. Xchar *argv[];
  1634. X{
  1635. X    char *mktemp();
  1636. X    char outfname[32];     /* collect output in /tmp file */
  1637. X    char line[IFOURK];     /* buffer for line of input */
  1638. X    char **opt = &argv[1]; /* command line arguments */
  1639. X    char **file;
  1640. X    register char *str;
  1641. X    register char *byt;    /* parser in input buffer */
  1642. X    register char *end;    /* pointing to end of input buffer */
  1643. X    int optval;            /* FIRSTONLY unless '-' option was given */
  1644. X    int len;               /* lenght of 'string' */
  1645. X    int lcount;            /* lenght of 'string' */
  1646. X
  1647. X    if (argc < 3)
  1648. X        fprintf(stderr, "\nUsage: %s [-] string files\n%s%s\n", argv[0],
  1649. X"\tdelete from each <file> the first line that contains <string>,\n",
  1650. X"\tor delete every such line from each <file> with the - option\n"),
  1651. X        exit(1);
  1652. X
  1653. X    if ((optval = iopt (&opt)) == '-')
  1654. X        str = argv[2], file = &argv[3];
  1655. X    else
  1656. X        str = argv[1], file = &argv[2], optval = FIRSTONLY;
  1657. X    if ((len = ifonetic (str)) < 1)
  1658. X        fprintf (stderr, "Null 'string' in command line\n"), exit (1);
  1659. X    sprintf (outfname, "/tmp/%s", mktemp ("excise.XXXXXX"));
  1660. X
  1661. X    for (; !NULCHARP (*file); file++) {
  1662. X        /* rename input file to stdin, create output file as stdout */
  1663. XQ       if (freopen (*file, "r", stdin) == NULL)
  1664. X            fprintf (stderr, "Open failed on %s\n", *file), exit (1);
  1665. XQ       if (freopen (outfname, "w", stdout) == NULL)
  1666. X            fprintf (stderr, "Can't write to %s\n", outfname), exit (1);
  1667. X
  1668. X        /* withhold input line from output if it contains 'string' */
  1669. X        for (lcount = 1; gets (line) != NULL; lcount++) {
  1670. XQ           end = inl (line); /* set 'end' to terminating NUL byte */
  1671. X            /* set 'end' to last possible point of match in line */
  1672. X            if ((end -= len-1) < line) { /* too small for match */
  1673. X                puts (line);
  1674. X                continue;
  1675. X            }
  1676. X            for (byt = line; byt < end; byt++) {
  1677. X                /* strcmp only if first bytes match */
  1678. X                if (*byt == *str && strncmp (byt, str, len) == 0) {
  1679. X                    fprintf (stderr, "%s: line %d\n", *file, lcount);
  1680. X                    break;
  1681. X                }
  1682. X            }
  1683. X            if (byt == end) /* no string match */
  1684. X                puts (line);
  1685. X            else if (optval == FIRSTONLY) /* string did match */
  1686. X                while (gets (line) != NULL)
  1687. X                    puts (line);
  1688. X        }
  1689. X
  1690. XQ       fflush (stdout);
  1691. X        sprintf (line, "/bin/mv %s %s", outfname, *file);
  1692. X        if (system (line))
  1693. X            fprintf (stderr, "Can't move %s to %s\n", outfname, *file),
  1694. X            exit (1);
  1695. X    }
  1696. X    exit (0);
  1697. X}
  1698. SHAR_EOF
  1699. $TOUCH -am 0605075390 iex/excise.c &&
  1700. chmod 0755 iex/excise.c ||
  1701. echo "restore of iex/excise.c failed"
  1702. set `wc -c iex/excise.c`;Wc_c=$1
  1703. if test "$Wc_c" != "2495"; then
  1704.     echo original size 2495, current size $Wc_c
  1705. fi
  1706. # ============= iex/fcat.c ==============
  1707. echo "x - extracting iex/fcat.c (Text)"
  1708. sed 's/^X//' << 'SHAR_EOF' > iex/fcat.c &&
  1709. X#ifdef NEVER
  1710. X/bin/cc -O -DIMANFMT -I../i $0 ../i/ilib.a -o $BIN/fcat
  1711. Xexit 0
  1712. X#endif
  1713. X
  1714. X/* print fields from lines of input, concatenated by spaces */
  1715. X#include "ilib.h"
  1716. X
  1717. Xmain (argc,argv)
  1718. Xint argc;
  1719. Xchar *argv[];
  1720. X{
  1721. X    static char defdel[] = {32,9,0}; /* SPACE, TAB, NUL */
  1722. X    char *dp = defdel;       /* to default delimiters */
  1723. X    char line[IONEK];        /* to hold single input line */
  1724. X    char *mp = argv[1];      /* fieldmask of command line */
  1725. X    char **argp;
  1726. X    char *toklist[16], **tl; /* pointers to tokens in line */
  1727. X    int masksiz;             /* byte width of fieldmask */
  1728. X    int *masklist, *ml;      /* int list of field ids to output */
  1729. X    int ri;                  /* loop index (of last token in line) */
  1730. X    int fwd = 1;             /* field numbering starts at left */
  1731. X    int delsiz = 3;
  1732. X    int toksiz;
  1733. X    int firsttok;            /* do not output preceding SPACE */
  1734. X    int optchar;
  1735. X
  1736. X    if (argc < 2)
  1737. X        fprintf (stderr,
  1738. X"Usage: %s fieldmask [-] [-d delimiters] [file]\n\%s%s%s%s\n", argv[0],
  1739. X"\t<fieldmask> is from the set '123456789abcdefg', each byte causes\n",
  1740. X"\tthe output of the 1st,2nd,...16th field of the lines of input.\n",
  1741. X"\t'Solo minus' option reverses field numbering (last field = 1). \n",
  1742. X"\tField delimiters are SPACE and TAB, or each byte of <delimiters>\n"),
  1743. X        exit(0);
  1744. X
  1745. X    masksiz = strlen (mp);
  1746. X    if ((masklist = (int *)malloc ((unsigned int)(masksiz + 1) *
  1747. X    sizeof (int))) == NULL) /* one extra for the sentinel */
  1748. X        fprintf (stderr, "No memory for mask\n"), exit (1);
  1749. X    *(masklist + masksiz) = 16; /* sentinel value */
  1750. X
  1751. X    /* convert mask bytes to indices 0 through 15, in masklist */
  1752. X    for (ml = masklist; *mp; mp++)
  1753. X        if (*mp >= '1' && *mp <= '9')
  1754. X            *ml++ = *mp - '1';
  1755. X        else if (*mp >= 'a' && *mp <= 'g')
  1756. X            *ml++ = *mp - 'X'; /* ASCII X = 88, ASCII a = 97 */
  1757. X        else
  1758. X            fprintf (stderr, "Mask character set: 123456789abcdefg\n"),
  1759. X            exit (1);
  1760. X
  1761. X    for (argp = argv + 2; optchar = iopt (&argp); argp++) {
  1762. X        if (optchar == 'd') {
  1763. X            dp = *argp;
  1764. X            delsiz = ifonetic (dp);
  1765. X            delsiz++; /* include terminating NUL */
  1766. X        }
  1767. X        else if (optchar == '-')
  1768. X            fwd = 0;
  1769. X        else
  1770. X            fprintf (stderr, "Option error: -%c%s\n", optchar, *argp),
  1771. X            exit (1);
  1772. X    }
  1773. X
  1774. X    /* rename file on command line (if any) to stdin */
  1775. X    if (!NULCHARP(*argp) && freopen (*argp, "r", stdin) == NULL)
  1776. X        fprintf (stderr, "Can't read %s\n", *argp), exit (1);
  1777. X
  1778. X    while (gets (line) != NULL) {
  1779. X        /* Set pointers to the first (last) 16 tokens in 'line', max.;
  1780. X           after recognizing a token, terminate it with NUL.
  1781. X           Because the internal itok() text marker will find that
  1782. X           its dereferenced byte was changed from a normal ASCII
  1783. X           SPACE, TAB, etc. to NUL; the NUL character also gets
  1784. X           included in the delimiter set, letting the internal
  1785. X           pointer skip over it during the search for the next token.
  1786. X        */
  1787. XQ       itok (fwd?INITOKF:INITOKR, line, (char *)NULL);
  1788. X        for (ri = 0, tl = toklist;
  1789. XQ       (toksiz = itok(fwd?ITOKF:ITOKR, dp, dp+delsiz, &(*tl)))
  1790. X        && ri < 16; tl++, ri++)
  1791. X                *(*tl + toksiz) = '\0'; /* NUL terminate token */
  1792. X
  1793. X        /* output fields indexed by successive elements of mask list */
  1794. X        for (firsttok = 1, ml = masklist; *ml < 16; ml++)
  1795. X            if (*ml < ri)
  1796. X                if (firsttok)
  1797. X                    fputs (*(toklist + *ml), stdout), firsttok = 0;
  1798. X                else /* use leading space */
  1799. X                    fprintf (stdout, " %s", *(toklist + *ml));
  1800. X        puts (""); /* print newline even if no tokens */
  1801. X    }
  1802. X
  1803. X    exit (0);
  1804. X}
  1805. SHAR_EOF
  1806. $TOUCH -am 0605075390 iex/fcat.c &&
  1807. chmod 0755 iex/fcat.c ||
  1808. echo "restore of iex/fcat.c failed"
  1809. set `wc -c iex/fcat.c`;Wc_c=$1
  1810. if test "$Wc_c" != "3349"; then
  1811.     echo original size 3349, current size $Wc_c
  1812. fi
  1813. echo "End of part 3, continue with part 4"
  1814. exit 0
  1815. -- 
  1816.         Istvan Mohos
  1817.         ...uunet!pyrdc!pyrnj!hhb!istvan
  1818.         RACAL-REDAC/HHB 1000 Wyckoff Ave. Mahwah NJ 07430 201-848-8000
  1819. ======================================================================
  1820.