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

  1. From: istvan@hhb.UUCP (Istvan Mohos)
  2. Newsgroups: alt.sources
  3. Subject: Subject: ILIB Unix Toolkit in C
  4. Message-ID: <548@hhb.UUCP>
  5. Date: 8 Jun 90 20:51:23 GMT
  6.  
  7.  
  8. ---- Cut Here and unpack ----
  9. #!/bin/sh
  10. # This is part 02 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/ilower.c ==============
  16. echo "x - extracting i/ilower.c (Text)"
  17. sed 's/^X//' << 'SHAR_EOF' > i/ilower.c &&
  18. X/* ilower.c */
  19. X/********************************************
  20. X* fast tolower string in buffer
  21. X* Istvan Mohos, 1987 --- in the Public Domain
  22. X*********************************************/
  23. X
  24. X#include "i.h"
  25. X#include "idowncas.h"
  26. X
  27. Xint
  28. Xilower (start, end)
  29. Xregister char *start;
  30. Xchar *end;
  31. X{
  32. X    register char *lo, *off;
  33. X
  34. X    if (NULCHARP (start))
  35. X        return (ierror ("ilower: null buffer"));
  36. X    ITOEND;
  37. X
  38. X    off = end;
  39. X
  40. X    for (lo = downcas; --off >= start;)
  41. X        *off = *(lo + *off);
  42. X    return(end - start);
  43. X}
  44. SHAR_EOF
  45. $TOUCH -am 0605074590 i/ilower.c &&
  46. chmod 0644 i/ilower.c ||
  47. echo "restore of i/ilower.c failed"
  48. set `wc -c i/ilower.c`;Wc_c=$1
  49. if test "$Wc_c" != "484"; then
  50.     echo original size 484, current size $Wc_c
  51. fi
  52. # ============= i/imatch.c ==============
  53. echo "x - extracting i/imatch.c (Text)"
  54. sed 's/^X//' << 'SHAR_EOF' > i/imatch.c &&
  55. X/* imatch.c */
  56. X/********************************************
  57. X* find word in buffer
  58. X* Istvan Mohos, 1987 --- in the Public Domain
  59. X*********************************************/
  60. X
  61. X#include "i.h"
  62. X
  63. Xchar *
  64. Ximatch (start, end, word)
  65. Xregister char *start;
  66. Xchar *end, *word;
  67. X{
  68. X    register char *off;
  69. X    register char *tail;
  70. X    char *sc, *tc;
  71. X    char *pp, *wp;
  72. X    int length;
  73. X
  74. X    if (NULCHARP (start) || BADCHARP (word)) {
  75. X        ierror("imatch: invalid parameters");
  76. X        return(NULL);
  77. X    }
  78. X    ITOEND;
  79. X
  80. X    for (sc = off = word; *off++;);
  81. X    length = --off - word;
  82. X    tc = --off;
  83. X
  84. X    off = end;
  85. X
  86. X    for (off -= --length; start < off;) {
  87. X
  88. X        /* proceed to first black character */
  89. X        for (;WHITE(*start);)
  90. X            if (++start == off)
  91. X                return(NULL);
  92. X
  93. X        tail = start + length;
  94. X        if (*start++ == *sc && *tail == *tc)
  95. X            if (length > 1) {
  96. X                for (wp = tc, pp = tail; *--wp == *--pp;)
  97. X                    if (pp == start)
  98. X                        return(--start);
  99. X            }
  100. X            else
  101. X                return(--start);
  102. X
  103. X        /* proceed to next white character */
  104. X        for (;BLACK(*start);)
  105. X            if (++start >= off)
  106. X                return(NULL);
  107. X    }
  108. X    return(NULL);
  109. X}
  110. SHAR_EOF
  111. $TOUCH -am 0605074590 i/imatch.c &&
  112. chmod 0644 i/imatch.c ||
  113. echo "restore of i/imatch.c failed"
  114. set `wc -c i/imatch.c`;Wc_c=$1
  115. if test "$Wc_c" != "1037"; then
  116.     echo original size 1037, current size $Wc_c
  117. fi
  118. # ============= i/imode.c ==============
  119. echo "x - extracting i/imode.c (Text)"
  120. sed 's/^X//' << 'SHAR_EOF' > i/imode.c &&
  121. X/* imode.c */
  122. X/****************************************************
  123. X* give file name and permission; return true or false
  124. X* Istvan Mohos, 1987 --- in the Public Domain
  125. X*****************************************************/
  126. X
  127. X#include "i.h"
  128. X
  129. Xint
  130. Ximode (fname, perm)
  131. Xchar *fname;
  132. Xint perm;
  133. X{
  134. X    struct stat sbuf;
  135. X
  136. X    if (BADCHARP(fname))
  137. X        return (ierror("imode: invalid file name"));
  138. X
  139. X    if (stat(fname, &sbuf) == -1)
  140. X        return (ierror("imode: stat"));
  141. X
  142. X    if (perm == 0)
  143. X        return ((int)sbuf.st_mode);
  144. X
  145. X    if (perm >= 010000 && perm <= 077777 && sbuf.st_mode >= 0100000)
  146. X        return (0); /* file type mismatch */
  147. X
  148. X    if (perm >= 020000 && perm <= 047777 && sbuf.st_mode >= 060000)
  149. X        return (0); /* block special mismatch against dir or chr */
  150. X
  151. X    if (((int)sbuf.st_mode & perm) == perm)
  152. X        return (1);  /* perm OK */
  153. X
  154. X    return(0) ; /* perm mismatch */
  155. X}
  156. SHAR_EOF
  157. $TOUCH -am 0605074590 i/imode.c &&
  158. chmod 0644 i/imode.c ||
  159. echo "restore of i/imode.c failed"
  160. set `wc -c i/imode.c`;Wc_c=$1
  161. if test "$Wc_c" != "832"; then
  162.     echo original size 832, current size $Wc_c
  163. fi
  164. # ============= i/imonth.c ==============
  165. echo "x - extracting i/imonth.c (Text)"
  166. sed 's/^X//' << 'SHAR_EOF' > i/imonth.c &&
  167. X/* imonth.c */
  168. X/***********************************************
  169. X* return int 0-12 for current month (0 == error)
  170. X* Istvan Mohos, 1987 --- in the Public Domain
  171. X***********************************************/
  172. X
  173. X#include "i.h"
  174. X
  175. Xint
  176. Ximonth (ptr)
  177. Xchar *ptr;
  178. X{
  179. X    register int hv = 0;
  180. X    register char *hp;
  181. X    static char hashbuf[] = {
  182. X        12, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 8, 0, 0,
  183. X        3, 0, 0, 4, 0, 0,10, 5, 9, 0, 0, 7, 0, 6, 0, 0, 0, 0, 0,11, };
  184. X
  185. X    hp = ptr;
  186. X    if (BADCHARP(hp))
  187. X        return (ierror ("imonth: invalid pointer"));
  188. X    if (*hp > 64) {
  189. X        hv += (*hp++ & 95);
  190. X        if (*hp) {
  191. X            hv += (*hp++ & 95);
  192. X            if (*hp)
  193. X                hv += (*hp & 95);
  194. X        }
  195. X        hv -= 204;
  196. X        if (hv < 0 || hv > 39)
  197. X            return (0);
  198. X        return (hashbuf[hv]);
  199. X    }
  200. X    if ((hv = atoi(hp)) > 12 || hv < 1)
  201. X        return (0);
  202. X    return (hv);
  203. X}
  204. SHAR_EOF
  205. $TOUCH -am 0605074590 i/imonth.c &&
  206. chmod 0644 i/imonth.c ||
  207. echo "restore of i/imonth.c failed"
  208. set `wc -c i/imonth.c`;Wc_c=$1
  209. if test "$Wc_c" != "790"; then
  210.     echo original size 790, current size $Wc_c
  211. fi
  212. # ============= i/inest.c ==============
  213. echo "x - extracting i/inest.c (Text)"
  214. sed 's/^X//' << 'SHAR_EOF' > i/inest.c &&
  215. X/* inest.c */
  216. X/**********************************************************
  217. X* create offset:nestlevel list for tracking delimiter pairs
  218. X* Istvan Mohos, 1987 --- in the Public Domain
  219. X***********************************************************/
  220. X
  221. X#include "i.h"
  222. X
  223. Xint
  224. Xinest (start, end, ldelim, rdelim, infopairs)
  225. Xchar *start, *end, *ldelim, *rdelim;
  226. Xint **infopairs;
  227. X{
  228. X    unsigned int cnt = 0; /* count of delimiters */
  229. X    int lsiz;          /* length of left delimiter */
  230. X    int rsiz;          /* length of right delimiter */
  231. X    int nestlev = 0;   /* level of nesting */
  232. X    int morechars = 1; /* flag that there are more bytes in buf */
  233. X    int morelines = 1; /* flag that there are more lines in buf */
  234. X    register char *pp;
  235. X    register char *mark;
  236. X    register char ld;  /* first char of ldelim */
  237. X    register char rd;  /* first char of rdelim */
  238. X    char *lstop;       /* last point from which to compare ldelim */
  239. X    char *rstop;       /* last point from which to compare rdelim */
  240. X    char *nl;          /* point to nl char at end of line */
  241. X    char *levp;        /* to base of malloc'd int list */
  242. X    int  *lpt;         /* to access successive int's in list */
  243. X
  244. X    if (NULCHARP (start))
  245. X        return (ierror ("inest: null buffer"));
  246. X    ITOEND;
  247. X
  248. X    if (BADCHARP(ldelim) || BADCHARP(rdelim))
  249. X        return(ierror("inest: bad delimiters"));
  250. X    ld = *ldelim;
  251. X    rd = *rdelim;
  252. X
  253. X    /* fast special case if ldelim and rdelim are single chars */
  254. X    lsiz = strlen(ldelim);
  255. X    if ((rsiz = strlen(rdelim)) == 1 && lsiz == 1) {
  256. X        if (ld == '\n' || rd == '\n')
  257. X                return(ierror("inest: nl delimiter"));
  258. X        if (ld == rd)
  259. X            return (ierror ("inest: identical delimiters"));
  260. X
  261. X        /* count delimiters */
  262. X        for (pp = end; --pp >= start;)
  263. X            if (*pp == ld || *pp == rd)
  264. X                cnt++;
  265. X
  266. X        if (NULCHARP (levp = calloc((cnt+1)*2, sizeof(int))))
  267. X            return (ierror ("inest: can't allocate int array"));
  268. X        lpt = (int *)levp;
  269. X        *infopairs = (int *)levp;
  270. X
  271. X        if (!cnt)
  272. X            return (0);
  273. X
  274. X        /* write offset and nestlevel into successive cells of list;
  275. X           using positive int for ldelim nestlevel values,
  276. X           using negative int for rdelim nestlevel values
  277. X        */
  278. X        pp = start;
  279. X        morelines = 1;
  280. X        while (morelines) {
  281. X            /* find next nl */
  282. X            for (mark = pp; pp < end && *pp != '\n'; pp++);
  283. X            if (pp == end) {
  284. X                morelines = 0;
  285. X                if (pp == mark)
  286. X                    continue;
  287. X                /* else unterminated line still must be processed */
  288. X            }
  289. X            nl = pp, pp = mark;
  290. X
  291. X            for (; pp < nl; pp++) {
  292. X                if (*pp == ld) {
  293. X                    *lpt++ = pp-start;
  294. X                    *lpt++ = ++nestlev;
  295. X                }
  296. X                else if (*pp == rd) {
  297. X                    *lpt++ = pp-start;
  298. X                    if (nestlev)
  299. X                        *lpt++ = -(nestlev--);
  300. X                    else
  301. X                        *lpt++ = 0;
  302. X                }
  303. X            }
  304. X            if (pp != end)
  305. X                pp++; /* get it past nl */
  306. X        }
  307. X        return (cnt);
  308. X    }
  309. X
  310. X    for (pp = ldelim + lsiz; --pp >= ldelim;)
  311. X        if (*pp == '\n')
  312. X            return(ierror("inest: nl in ldelim"));
  313. X    for (pp = rdelim + rsiz; --pp >= rdelim;)
  314. X        if (*pp == '\n')
  315. X            return(ierror("inest: nl in rdelim"));
  316. X
  317. X    /* if  --- endif : good
  318. X       if  --- ifend : bad
  319. X       foo --- oo    : good
  320. X       foo --- fo    : bad
  321. X    */
  322. X    if (strncmp (ldelim, rdelim, ((lsiz > rsiz) ? rsiz : lsiz)) == 0)
  323. X        return (ierror ("inest: overlapping delimiters"));
  324. X
  325. X    /* count delimiters */
  326. X    pp = start;
  327. X    lstop = end - lsiz;
  328. X    rstop = end - rsiz;
  329. X    morechars = 1;
  330. X    while (morechars) {
  331. X        for (; pp < end && *pp != ld && *pp != rd; pp++);
  332. X        if (pp == end) {
  333. X            morechars = 0;
  334. X            continue;
  335. X        }
  336. X        if (pp <= lstop && strncmp (pp, ldelim, lsiz) == 0)
  337. X            pp += lsiz, cnt++;
  338. X        else if (pp <= rstop && strncmp (pp, rdelim, rsiz) == 0)
  339. X            pp += rsiz, cnt++;
  340. X        else /* first char of delim did match, but no strcmp */
  341. X            pp++;
  342. X    }
  343. X
  344. X    if (NULCHARP (levp = calloc((unsigned)(cnt+1)*2, sizeof(int))))
  345. X        return (ierror ("inest: can't allocate int array"));
  346. X    lpt = (int *)levp;
  347. X    *infopairs = (int *)levp;
  348. X
  349. X    if (!cnt)
  350. X        return (0);
  351. X
  352. X    /* write offset and nestlevel into successive cells of list;
  353. X       using positive int for ldelim nestlevel values,
  354. X       using negative int for rdelim nestlevel values
  355. X    */
  356. X    pp = start;
  357. X    morelines = 1;
  358. X    while (morelines) {
  359. X        /* find next nl */
  360. X        for (mark = pp; pp < end && *pp != '\n'; pp++);
  361. X        if (pp == end) {
  362. X            morelines = 0;
  363. X            if (pp == mark)
  364. X                continue;
  365. X            /* else unterminated line still must be processed */
  366. X        }
  367. X        nl = pp, pp = mark;
  368. X        lstop = nl - lsiz;
  369. X        rstop = nl - rsiz;
  370. X
  371. X        morechars = 1;
  372. X        while (morechars) {
  373. X            for (; pp < nl && *pp != ld && *pp != rd; pp++);
  374. X            if (pp == nl) {
  375. X                morechars = 0;
  376. X                continue;
  377. X            }
  378. X            if (pp <= lstop && strncmp (pp, ldelim, lsiz) == 0) {
  379. X                *lpt++ = pp-start;
  380. X                *lpt++ = ++nestlev;
  381. X                pp += lsiz;
  382. X            }
  383. X            else if (pp <= rstop && strncmp (pp, rdelim, rsiz) == 0) {
  384. X                *lpt++ = pp-start;
  385. X                if (nestlev)
  386. X                    *lpt++ = -(nestlev--);
  387. X                else
  388. X                    *lpt++ = 0;
  389. X                pp += rsiz;
  390. X            }
  391. X            else /* matched first char of a delimiter, but no strcmp */
  392. X                pp++;
  393. X        }
  394. X        if (pp != end)
  395. X            pp++; /* get it past nl */
  396. X    }
  397. X    return (cnt);
  398. X}
  399. SHAR_EOF
  400. $TOUCH -am 0605074590 i/inest.c &&
  401. chmod 0644 i/inest.c ||
  402. echo "restore of i/inest.c failed"
  403. set `wc -c i/inest.c`;Wc_c=$1
  404. if test "$Wc_c" != "4820"; then
  405.     echo original size 4820, current size $Wc_c
  406. fi
  407. # ============= i/inextl.c ==============
  408. echo "x - extracting i/inextl.c (Text)"
  409. sed 's/^X//' << 'SHAR_EOF' > i/inextl.c &&
  410. X/* inextl.c */
  411. X/********************************************
  412. X* return location of first token in next line
  413. X* Istvan Mohos, 1987 --- in the Public Domain
  414. X********************************************/
  415. X
  416. X#include "i.h"
  417. X
  418. Xchar *
  419. Xinextl (start, end, skiptok)
  420. Xregister char *start;
  421. Xregister char *end;
  422. Xregister char *skiptok;
  423. X{
  424. X    if (NULCHARP (start)) {
  425. X        ierror ("inextl: null buffer");
  426. X        return (NULL);
  427. X    }
  428. X    ITOEND;
  429. X
  430. Xagain:
  431. X    /* jump over newline */
  432. X    for (;start < end && *start != '\n'; ++start);
  433. X    if (start >= end)
  434. X        return(NULL);
  435. X
  436. X    /* find first non-space */
  437. X    for (;start < end && WHITE(*start); ++start);
  438. X    if (start == end)
  439. X        return (start);
  440. X
  441. X    if (skiptok && (strncmp (skiptok, start, strlen (skiptok)) == 0))
  442. X        goto again;
  443. X
  444. X    return (start);
  445. X}
  446. SHAR_EOF
  447. $TOUCH -am 0605074590 i/inextl.c &&
  448. chmod 0644 i/inextl.c ||
  449. echo "restore of i/inextl.c failed"
  450. set `wc -c i/inextl.c`;Wc_c=$1
  451. if test "$Wc_c" != "739"; then
  452.     echo original size 739, current size $Wc_c
  453. fi
  454. # ============= i/inl.c ==============
  455. echo "x - extracting i/inl.c (Text)"
  456. sed 's/^X//' << 'SHAR_EOF' > i/inl.c &&
  457. X/* inl.c */
  458. X/********************************************
  459. X* return pointer to next newline or null byte
  460. X* Istvan Mohos, 1987 --- in the Public Domain
  461. X*********************************************/
  462. X
  463. X#include "i.h"
  464. X
  465. Xchar *
  466. Xinl (start)
  467. Xregister char *start;
  468. X{
  469. X    if (*start == '\n' || *start == '\0')
  470. X        return(start);
  471. X
  472. X    /* do not go past newline or null */
  473. X    for(start++; *start; start++)
  474. X        if (*start == '\n' && *(start-1) != '\\')
  475. X            return(start);
  476. X
  477. X    return(start);
  478. X}
  479. X
  480. Xchar *
  481. Xinull (start)
  482. Xregister char *start;
  483. X{
  484. X    for(; *start; start++);
  485. X    return(start);
  486. X}
  487. SHAR_EOF
  488. $TOUCH -am 0605074590 i/inl.c &&
  489. chmod 0644 i/inl.c ||
  490. echo "restore of i/inl.c failed"
  491. set `wc -c i/inl.c`;Wc_c=$1
  492. if test "$Wc_c" != "553"; then
  493.     echo original size 553, current size $Wc_c
  494. fi
  495. # ============= i/inumsearch.c ==============
  496. echo "x - extracting i/inumsearch.c (Text)"
  497. sed 's/^X//' << 'SHAR_EOF' > i/inumsearch.c &&
  498. X/* inumsearch.c */
  499. X/***********************************************
  500. X* alphanum search in array of character pointers
  501. X* Istvan Mohos, 1987 --- in the Public Domain
  502. X************************************************/
  503. X
  504. X#include "i.h"
  505. X
  506. Xint
  507. Xinumsearch (comparee, wordlist, listcount)
  508. Xchar *comparee;
  509. Xchar *wordlist[];
  510. Xint listcount;
  511. X{
  512. X    register int lo, hi;
  513. X    register int m, mid;
  514. X
  515. X    if (BADCHARP (comparee))
  516. X        return(ierror("inumsearch: invalid comparee"));
  517. X    if (listcount < 1)
  518. X        return (-1);
  519. X
  520. X    for (lo = 0, hi = listcount -1; lo <= hi;) {
  521. X        mid = (lo + hi) >> 1;
  522. X        if ((m = inumstrcmp(comparee, wordlist[mid])) < 0)
  523. X            hi = mid -1;
  524. X        else if (m > 0)
  525. X            lo = mid +1;
  526. X        else
  527. X            return(mid);
  528. X    }
  529. X    return (-1);
  530. X}
  531. SHAR_EOF
  532. $TOUCH -am 0605074590 i/inumsearch.c &&
  533. chmod 0644 i/inumsearch.c ||
  534. echo "restore of i/inumsearch.c failed"
  535. set `wc -c i/inumsearch.c`;Wc_c=$1
  536. if test "$Wc_c" != "700"; then
  537.     echo original size 700, current size $Wc_c
  538. fi
  539. # ============= i/inumsort.c ==============
  540. echo "x - extracting i/inumsort.c (Text)"
  541. sed 's/^X//' << 'SHAR_EOF' > i/inumsort.c &&
  542. X/* inumsort.c */
  543. X/********************************************
  544. X* alphanum ptr sort
  545. X* Istvan Mohos, 1987 --- in the Public Domain
  546. X*********************************************/
  547. X
  548. X#include "i.h"
  549. X
  550. Xvoid
  551. Xinumsort (ptr, itemcount)
  552. Xchar *ptr[];
  553. Xint itemcount;
  554. X{
  555. X    int ri, rj;
  556. X    register char *tp, **mp, **np;
  557. X
  558. X    if (itemcount < 2)
  559. X        return; /* already sorted */
  560. X    mp = np = ptr;
  561. X    if (itemcount == 2) { /* just exchange if not in order */
  562. X        if (inumstrcmp(*++np, *mp) < 0) {
  563. X            tp = *mp;
  564. X            *mp = *np;
  565. X            *np = tp;
  566. X        }
  567. X    }
  568. X    else {
  569. X        part(mp, itemcount, &ri, &rj);
  570. X        inumsort(mp, rj+1);
  571. X        inumsort(mp+ri, itemcount-ri);
  572. X    }
  573. X}
  574. X
  575. Xstatic
  576. Xpart (ptr, itemcount, pi, pj)
  577. Xchar *ptr[];
  578. Xint itemcount;
  579. Xint *pi, *pj;
  580. X{
  581. X    char *ref, *tp;
  582. X    register char **mp;
  583. X    register int mi, mj;
  584. X
  585. X    mi = 0;
  586. X    mj = itemcount-1;
  587. X    mp = ptr;
  588. X    for (ref = *(mp + mj/2); mi <= mj;) {
  589. X        for (;inumstrcmp(*(mp+mi), ref) < 0; mi++);
  590. X        for (;inumstrcmp(*(mp+mj), ref) > 0; mj--);
  591. X        if (mi <= mj) {
  592. X            tp = *(mp+mi);
  593. X            *(mp+mi++) = *(mp+mj);
  594. X            *(mp+mj--) = tp;
  595. X        }
  596. X    }
  597. X    *pi = mi;
  598. X    *pj = mj;
  599. X}
  600. SHAR_EOF
  601. $TOUCH -am 0605074590 i/inumsort.c &&
  602. chmod 0644 i/inumsort.c ||
  603. echo "restore of i/inumsort.c failed"
  604. set `wc -c i/inumsort.c`;Wc_c=$1
  605. if test "$Wc_c" != "1036"; then
  606.     echo original size 1036, current size $Wc_c
  607. fi
  608. # ============= i/inumstrcmp.c ==============
  609. echo "x - extracting i/inumstrcmp.c (Text)"
  610. sed 's/^X//' << 'SHAR_EOF' > i/inumstrcmp.c &&
  611. X/* inumstrcmp.c */
  612. X/********************************************
  613. X* alphanumeric comparison of two strings
  614. X* Istvan Mohos, 1987 --- in the Public Domain
  615. X********************************************/
  616. X
  617. X#include "i.h"
  618. X
  619. X#define PTR1GREATER   1
  620. X#define PTR1PTR2EQUAL 0
  621. X#define PTR2GREATER  -1
  622. X
  623. Xint
  624. Xinumstrcmp (ptr1, ptr2)
  625. Xregister char *ptr1, *ptr2;
  626. X{
  627. X    register int num1, num2;
  628. X
  629. X    if (NULCHARP (ptr1) || NULCHARP (ptr2))
  630. X        return (ierror ("inumstrcmp: NULL parameter"));
  631. X
  632. X    for (;;) {
  633. X        if (*ptr1 == '\0')               /* if ptr1 is null */
  634. X            if (*ptr2 == '\0')
  635. X                return (PTR1PTR2EQUAL);
  636. X            else
  637. X                return (PTR2GREATER);
  638. X
  639. X        if (*ptr2 == '\0')               /* if ptr2 is null */
  640. X            return (PTR1GREATER);
  641. X
  642. X        if (*ptr1 < '0' || *ptr1 > '9') {/* if ptr1 is alphabetic */
  643. X            if (*ptr1 > *ptr2)
  644. X                return (PTR1GREATER);
  645. X            if (*ptr1 < *ptr2)
  646. X                return (PTR2GREATER);
  647. X            ptr1++, ptr2++;
  648. X            continue;                    /* ptr1,ptr2 identical alpha */
  649. X        }
  650. X
  651. X        if (*ptr2 < '0' || *ptr2 > '9') {/* ptr1 numeral, ptr2 alpha */
  652. X            if (*ptr1 > *ptr2)
  653. X                return (PTR1GREATER);
  654. X            return (PTR2GREATER);
  655. X        }
  656. X
  657. X        if ((num1 = atoi(ptr1)) > (num2 = atoi(ptr2)))
  658. X            return (PTR1GREATER);
  659. X        if (num1 < num2)
  660. X            return (PTR2GREATER);
  661. X
  662. X        /* identical numbers still could be weird: '0012' vs '12' */
  663. X        for (++ptr1; *ptr1 >= '0' && *ptr1 <= '9'; ptr1++);
  664. X        for (++ptr2; *ptr2 >= '0' && *ptr2 <= '9'; ptr2++);
  665. X    }
  666. X}
  667. X
  668. SHAR_EOF
  669. $TOUCH -am 0605074590 i/inumstrcmp.c &&
  670. chmod 0644 i/inumstrcmp.c ||
  671. echo "restore of i/inumstrcmp.c failed"
  672. set `wc -c i/inumstrcmp.c`;Wc_c=$1
  673. if test "$Wc_c" != "1389"; then
  674.     echo original size 1389, current size $Wc_c
  675. fi
  676. # ============= i/ioctal.c ==============
  677. echo "x - extracting i/ioctal.c (Text)"
  678. sed 's/^X//' << 'SHAR_EOF' > i/ioctal.c &&
  679. X/* ioctal.c */
  680. X/********************************************
  681. X* convert octal digit string to int
  682. X* Istvan Mohos, 1990 --- in the Public Domain
  683. X*********************************************/
  684. X
  685. X#include "i.h"
  686. X
  687. Xint
  688. Xioctal (ptr)
  689. Xregister char *ptr;
  690. X{
  691. X    register int val = 0;
  692. X
  693. X    if (NULCHARP(ptr))
  694. X        return (ierror ("ioctal: invalid pointer"));
  695. X
  696. X    for (--ptr; *++ptr && ((*ptr>='0' && *ptr<='7') || WHITE(*ptr));)
  697. X        if (!WHITE(*ptr))
  698. X            val <<= 3, val += *ptr - '0';
  699. X    return (val);
  700. X}
  701. SHAR_EOF
  702. $TOUCH -am 0605074590 i/ioctal.c &&
  703. chmod 0644 i/ioctal.c ||
  704. echo "restore of i/ioctal.c failed"
  705. set `wc -c i/ioctal.c`;Wc_c=$1
  706. if test "$Wc_c" != "475"; then
  707.     echo original size 475, current size $Wc_c
  708. fi
  709. # ============= i/iopt.c ==============
  710. echo "x - extracting i/iopt.c (Text)"
  711. sed 's/^X//' << 'SHAR_EOF' > i/iopt.c &&
  712. X/* iopt.c */
  713. X/*********************************************
  714. X* command line option manager
  715. X* Istvan Mohos, 1987 --- in the Public Domain
  716. X*********************************************/
  717. X
  718. X#include "i.h"
  719. X
  720. Xint
  721. Xiopt (ptr)
  722. Xchar ***ptr;
  723. X{
  724. X    register char *rp;
  725. X    static char **olist;
  726. X    static int first = 1;
  727. X    int optlen;
  728. X
  729. X    if (first) {
  730. X        olist = *ptr;
  731. X        first = 0;
  732. X    }
  733. X
  734. X    rp = *olist;
  735. X    if (rp == NULL || *rp != '-') { /* no more options */
  736. X        *ptr = olist;               /* set to first non-option */
  737. X        first = 1;                  /* automatically re-init */
  738. X        return (0);
  739. X    }
  740. X
  741. X    optlen = strlen (rp);
  742. X    if (optlen > 2) {               /* flag, value combined */
  743. X        rp += 2;
  744. X        *olist = rp;                /* right past '-c' flag */
  745. X        *ptr = olist;
  746. X        ++olist;                    /* pre-increment for next time */
  747. X        return (*--rp);
  748. X    }
  749. X
  750. X    if (optlen == 1) {              /* '-' by itself */
  751. X        *ptr = olist;
  752. X        ++olist;                    /* pre-increment for next time */
  753. X        return (*rp);
  754. X    }
  755. X
  756. X    /* else (optlen == 2): normal '-c' flag */
  757. X    ++rp;
  758. X    ++olist;
  759. X    if (*olist == NULL || **olist == 0) { /* no option value */
  760. X        --olist;
  761. X        *ptr = olist;               /* cough up entire option flag */
  762. X        first = 1;                  /* automatically re-init */
  763. X        return (0);
  764. X    }
  765. X
  766. X    *ptr = olist;
  767. X    ++olist;                        /* pre-increment for next time */
  768. X    return (*rp);
  769. X}
  770. SHAR_EOF
  771. $TOUCH -am 0605074590 i/iopt.c &&
  772. chmod 0644 i/iopt.c ||
  773. echo "restore of i/iopt.c failed"
  774. set `wc -c i/iopt.c`;Wc_c=$1
  775. if test "$Wc_c" != "1339"; then
  776.     echo original size 1339, current size $Wc_c
  777. fi
  778. # ============= i/iread.c ==============
  779. echo "x - extracting i/iread.c (Text)"
  780. sed 's/^X//' << 'SHAR_EOF' > i/iread.c &&
  781. X/* iread.c */
  782. X/*************************************************
  783. X* read file into malloc'd buffer, return file size
  784. X* Istvan Mohos, 1987 --- in the Public Domain
  785. X**************************************************/
  786. X
  787. X#include "i.h"
  788. X
  789. Xint
  790. Xiread (fname, mallocp)
  791. Xchar *fname;
  792. Xchar **mallocp;
  793. X{
  794. X    struct stat sbuf;
  795. X    int checkval, fd;
  796. X    int count;
  797. X
  798. X    if (BADCHARP (fname))
  799. X        return (ierror ("iread: invalid file name"));
  800. X
  801. X    if (mallocp == (char **) NULL) {
  802. X        if (access (fname, R_OK) == -1)
  803. X            return (-1); /* can't read it */
  804. X        return (0);
  805. X    }
  806. X
  807. X    if ((fd = open (fname, 0)) == -1)
  808. X        return (ierror ("iread: no file access"));
  809. X
  810. X    if ((checkval = fstat (fd, &sbuf)) == -1)
  811. X        return (ierror ("iread: fstat read error"));
  812. X
  813. X    if ((count = (int)sbuf.st_size) == 0)
  814. X        return (ierror ("iread: zero length file"));
  815. X
  816. X    if (NULCHARP (*mallocp = malloc ((unsigned int) count+1)))
  817. X        return (ierror ("iread: can't allocate read buffer"));
  818. X
  819. X    if ((checkval = read (fd, *mallocp, count)) != count) {
  820. X        sprintf (ierbuf+200,
  821. X            "iread: expected: %d, read: %d", count, checkval);
  822. X        return (ierror (ierbuf+200));
  823. X    }
  824. X    close (fd);
  825. X    *(*mallocp + count) = 0;
  826. X    return (checkval);
  827. X}
  828. SHAR_EOF
  829. $TOUCH -am 0605074590 i/iread.c &&
  830. chmod 0644 i/iread.c ||
  831. echo "restore of i/iread.c failed"
  832. set `wc -c i/iread.c`;Wc_c=$1
  833. if test "$Wc_c" != "1141"; then
  834.     echo original size 1141, current size $Wc_c
  835. fi
  836. # ============= i/irotate.c ==============
  837. echo "x - extracting i/irotate.c (Text)"
  838. sed 's/^X//' << 'SHAR_EOF' > i/irotate.c &&
  839. X/* irotate.c */
  840. X/********************************************
  841. X* rotate passed text in new buffer
  842. X* Istvan Mohos, 1987 --- in the Public Domain
  843. X*********************************************/
  844. X
  845. X#include "i.h"
  846. X
  847. X#define IROTR       1 /* rotate 90 deg. to right */
  848. X#define IROTL      -1 /* rotate 90 deg. to left */
  849. X#define IROTOR      3 /* rotate 180 deg. over and 90 deg. to right */
  850. X#define IROTOL     -3 /* rotate 180 deg. over and 90 deg. to left */
  851. X
  852. Xint
  853. Xirotate (start, llength, lcount, mallocp, type)
  854. Xchar *start, **mallocp;
  855. Xint llength, lcount;
  856. Xint type;
  857. X{
  858. X    register char *from, *to;
  859. X    int rotsiz;
  860. X    register int ri, rj;
  861. X
  862. X    if (NULCHARP (start))
  863. X        return (ierror ("irotate: null buffer"));
  864. X
  865. X    if (llength < 1 || lcount < 1)
  866. X        return(ierror("rotate: bad dimensions"));
  867. X
  868. X    rotsiz = (lcount + 1) * llength;
  869. X    if (NULCHARP(*mallocp = malloc((unsigned int)rotsiz + 1)))
  870. X        return(ierror("irotate: can't allocate rotor buffer"));
  871. X    to = *mallocp;
  872. X    *(*mallocp + rotsiz) = 0;
  873. X
  874. X    switch (type) {
  875. X        case IROTR:
  876. X        default:
  877. X            for (rj = 0; rj < llength; rj++) {
  878. X                from = start + ((lcount-1) * llength) + rj;
  879. X                for (ri = 0; ri++ < lcount; from -= llength)
  880. X                    *to++ = *from;
  881. X                *to++ = '\n';
  882. X            }
  883. X            break;
  884. X
  885. X        case IROTOR:
  886. X            for (rj = 0; rj < llength; rj++) {
  887. X                from = start + rj;
  888. X                for (ri = 0; ri++ < lcount; from += llength)
  889. X                    *to++ = *from;
  890. X                *to++ = '\n';
  891. X            }
  892. X            break;
  893. X
  894. X        case IROTOL:
  895. X            for (rj = llength; --rj >= 0; ) {
  896. X                from = start + ((lcount -1) * llength) + rj;
  897. X                for (ri = 0; ri++ < lcount; from -= llength)
  898. X                    *to++ = *from;
  899. X                *to++ = '\n';
  900. X            }
  901. X            break;
  902. X
  903. X        case IROTL:
  904. X            for (rj = llength; --rj >= 0; ) {
  905. X                from = start + rj;
  906. X                for (ri = 0; ri++ < lcount; from += llength)
  907. X                    *to++ = *from;
  908. X                *to++ = '\n';
  909. X            }
  910. X            break;
  911. X
  912. X    }
  913. X
  914. X    return (rotsiz);
  915. X}
  916. SHAR_EOF
  917. $TOUCH -am 0605074590 i/irotate.c &&
  918. chmod 0644 i/irotate.c ||
  919. echo "restore of i/irotate.c failed"
  920. set `wc -c i/irotate.c`;Wc_c=$1
  921. if test "$Wc_c" != "1778"; then
  922.     echo original size 1778, current size $Wc_c
  923. fi
  924. # ============= i/iround.c ==============
  925. echo "x - extracting i/iround.c (Text)"
  926. sed 's/^X//' << 'SHAR_EOF' > i/iround.c &&
  927. X/* iround.c */
  928. X/****************************************************************
  929. X* suppress trailing zeros or round to a given digit of a fraction
  930. X* Istvan Mohos, 1987 --- in the Public Domain
  931. X*****************************************************************/
  932. X
  933. X#include "i.h"
  934. X
  935. Xint
  936. Xiround (start, end, maxfrac)
  937. Xchar *start;
  938. Xchar *end;
  939. Xint maxfrac;
  940. X{
  941. X    register char *jp;      /* scratch pointer */
  942. X    register char *dp;      /* pointing to decimal point */
  943. X    register char *hp;      /* pointing to first digit of string */
  944. X    register char *mf;      /* pointing to specified fraction end */
  945. X    register char *fin;     /* last digit of fraction */
  946. X    int carry;
  947. X    int intsiz;
  948. X
  949. X    if (NULCHARP (start))
  950. X        return (ierror ("iround: null buffer"));
  951. X    ITOEND;
  952. X    if (end == start)
  953. X        return (ierror ("iround: zero-size buffer"));
  954. X
  955. X    /* Move from start, over any white spaces, a single + or - sign,
  956. X       more white spaces, to the leftmost digit, then to decimal point,
  957. X       then to the last digit of the decimal fraction.
  958. X    */
  959. X    for (hp = start-1; ++hp < end && WHITE(*hp););
  960. X    if (hp == end)
  961. X        return (0);
  962. X    if (*hp == '+' || *hp == '-') {
  963. X        for (; ++hp < end && WHITE(*hp););
  964. X        if (hp == end)
  965. X            return (0);
  966. X    }
  967. X    if (*hp != '.' && (*hp < '0' || *hp > '9'))
  968. X        return (0);
  969. X    for (dp = hp-1; ++dp<end && *dp!='.' && *dp>='0' && *dp<='9';);
  970. X    if (dp == end || *dp != '.')
  971. X        return (0);
  972. X    intsiz = dp - hp;
  973. X    for (fin = dp; ++fin<end && *fin>='0' && *fin<='9';);
  974. X
  975. X    /* Stopped on the byte past the last digit of the string;
  976. X       null it if there is enough space, then move back to last digit.
  977. X    */
  978. X    if (fin < end)
  979. X        *fin = NUL;
  980. X    --fin;
  981. X
  982. X    /* any negative int passed to null-out trailing '0' digits */
  983. X    if (maxfrac < 0) {
  984. X        for (++fin; *--fin == '0'; *fin = NUL);
  985. X        if (fin == dp)
  986. X            (intsiz) ? (*fin-- = NUL) : (*fin = '0');
  987. X        return (fin+1 - start);
  988. X    }
  989. X
  990. X    if ((mf = dp+maxfrac) >= fin) { /* nothing to do */
  991. X        if (fin == dp)
  992. X            (intsiz) ? (*fin-- = NUL) : (*fin = '0');
  993. X        return (fin+1 - start);
  994. X    }
  995. X
  996. X    /* generate a carry, then null out the byte past maxfrac */
  997. X    (*++mf >= '5') ? (carry = 1) : (carry = 0);
  998. X    if (end > mf+1)  /* need next byte too if string expands */
  999. X        *(mf+1) = NUL;
  1000. X    *mf-- = NUL;
  1001. X
  1002. X    /* If "round to int" was specified, loose the decimal point.
  1003. X       But if there were no int digits given, a number has to be
  1004. X       created by substituting a '0' in place of the dp.
  1005. X    */
  1006. X    if (!maxfrac)
  1007. X        (intsiz) ? (*mf-- = NUL) : (*mf = '0');
  1008. X
  1009. X    if (!carry)       /* truncated string otherwise unchanged */
  1010. X        return (mf+1 - start);
  1011. X
  1012. X    if (*mf < '9') {  /* last digit of truncated string incremented */
  1013. X        ++(*mf);
  1014. X        return (mf+1 - start);
  1015. X    }
  1016. X
  1017. X    /* By this time, we have a carry from the lost fractional digits,
  1018. X       and the last digit of the existing string is a '9'.
  1019. X       The potential combination of (maxfrac == 0, intsiz == 0) is
  1020. X       no longer a possibility (the remaining string is at worst a
  1021. X       fraction without original int digits, or an original int
  1022. X       without a fraction).  In the more general "int.fraction" case,
  1023. X       homogenize the string by shifting the "int" part right 1 byte.
  1024. X    */
  1025. X    if (intsiz)
  1026. X        ibcopy (hp+1, hp, intsiz);
  1027. X    ++hp;
  1028. X    if (!maxfrac)
  1029. X        ++mf;
  1030. X
  1031. X    /*_______________ generic: ______ !intsiz: _____ !maxfrac:
  1032. X    |                    mf              mf            mf
  1033. X    |                 hp |            hp |           hp|
  1034. X    |                 |  |            |  |           | |
  1035. X    |                 v  v            v  v           v v
  1036. X    |  before ibcopy  7.49            .749           749$
  1037. X    |  after ibcopy   7749            .749           7749
  1038. X    |  after           ^ ^             ^ ^            ^ ^
  1039. X    |   ++hp,++mf      | |             | |            | |
  1040. X    |                 hp mf           hp mf          hp mf
  1041. X    |________________________________________________________*/
  1042. X
  1043. X    /* bubble up nines backward from last digit */
  1044. X    for (jp = mf, *mf = '0'; --jp >= hp; ) {
  1045. X        if (*jp == '9')
  1046. X            *jp = '0';
  1047. X        else {
  1048. X            ++(*jp);
  1049. X            break;
  1050. X        }
  1051. X    }
  1052. X
  1053. X    /* if new '1' digit at front, shift fractional part to right */
  1054. X    if (jp < hp) {
  1055. X        *jp = '1';
  1056. X        if (maxfrac) {
  1057. X            ibcopy (dp+2, dp+1, mf++ -dp);
  1058. X            *(dp+1) = '.';
  1059. X        }
  1060. X    /*
  1061. X    |  original       9.99            .999           999$
  1062. X    |  at int shift   9999            .999           9999
  1063. X    |  after bubble   1000            1000           1000
  1064. X    |  at frac shift  10.00           1.000          1000
  1065. X    |                  ^  ^            ^  ^           ^ ^
  1066. X    |                  |  |            |  |           | |
  1067. X    |                 hp  mf          hp  mf         hp mf
  1068. X    |________________________________________________________*/
  1069. X        return (mf+1 - start);
  1070. X    }
  1071. X
  1072. X    /* didn't add new digit, shift integer part back to left */
  1073. X    ibcopy (hp-1, hp, intsiz);
  1074. X    (maxfrac) ? (*dp = '.') : (*mf-- = NUL);
  1075. X
  1076. X    /*
  1077. X    |  original       7.49            .749           749$
  1078. X    |  at int shift   7749            .749           7749
  1079. X    |  after bubble   7750            .750           7750
  1080. X    |  at left shift  7750            .750           7500
  1081. X    |  restore dp     7.50            .750           750$
  1082. X    |                  ^ ^             ^ ^            ^^^
  1083. X    |                  | |             | |            |||
  1084. X    |                 hp mf           hp mf          hp|mf
  1085. X    |                                                  mf
  1086. X    |________________________________________________________*/
  1087. X
  1088. X    return (mf+1 - start);
  1089. X}
  1090. SHAR_EOF
  1091. $TOUCH -am 0605074590 i/iround.c &&
  1092. chmod 0644 i/iround.c ||
  1093. echo "restore of i/iround.c failed"
  1094. set `wc -c i/iround.c`;Wc_c=$1
  1095. if test "$Wc_c" != "5257"; then
  1096.     echo original size 5257, current size $Wc_c
  1097. fi
  1098. # ============= i/isearch.c ==============
  1099. echo "x - extracting i/isearch.c (Text)"
  1100. sed 's/^X//' << 'SHAR_EOF' > i/isearch.c &&
  1101. X/* isearch.c */
  1102. X/*********************************************
  1103. X* binary search in array of character pointers
  1104. X* Istvan Mohos, 1987 --- in the Public Domain
  1105. X**********************************************/
  1106. X
  1107. X#include "i.h"
  1108. X
  1109. Xint
  1110. Xisearch (comparee, wordlist, listcount)
  1111. Xchar *comparee;
  1112. Xchar *wordlist[];
  1113. Xint listcount;
  1114. X{
  1115. X    register int lo, hi;
  1116. X    register int m, mid;
  1117. X    int signific;
  1118. X
  1119. X    if (BADCHARP (comparee))
  1120. X        return(ierror("isearch: invalid comparee"));
  1121. X    if (listcount < 1)
  1122. X        return (-1);
  1123. X
  1124. X    signific = strlen(comparee);
  1125. X    for (lo = 0, hi = listcount -1; lo <= hi;) {
  1126. X        mid = (lo + hi) >> 1;
  1127. X        if ((m = strncmp(comparee, wordlist[mid], signific)) < 0)
  1128. X            hi = mid -1;
  1129. X        else if (m > 0)
  1130. X            lo = mid +1;
  1131. X        else
  1132. X            return(mid);
  1133. X    }
  1134. X    return (-1);
  1135. X}
  1136. SHAR_EOF
  1137. $TOUCH -am 0605074590 i/isearch.c &&
  1138. chmod 0644 i/isearch.c ||
  1139. echo "restore of i/isearch.c failed"
  1140. set `wc -c i/isearch.c`;Wc_c=$1
  1141. if test "$Wc_c" != "737"; then
  1142.     echo original size 737, current size $Wc_c
  1143. fi
  1144. # ============= i/isort.c ==============
  1145. echo "x - extracting i/isort.c (Text)"
  1146. sed 's/^X//' << 'SHAR_EOF' > i/isort.c &&
  1147. X/* isort.c */
  1148. X/********************************************
  1149. X* easier-to-use str ptr sort
  1150. X* Istvan Mohos, 1987 --- in the Public Domain
  1151. X*********************************************/
  1152. X
  1153. X#include "i.h"
  1154. X
  1155. Xvoid
  1156. Xisort (ptr, itemcount)
  1157. Xchar *ptr[];
  1158. Xint itemcount;
  1159. X{
  1160. X    int ri, rj;
  1161. X    register char *tp, **mp, **np;
  1162. X
  1163. X    if (itemcount < 2)
  1164. X        return; /* already sorted */
  1165. X    mp = np = ptr;
  1166. X    if (itemcount == 2) { /* just exchange if not in order */
  1167. X        if (strcmp(*++np, *mp) < 0) {
  1168. X            tp = *mp;
  1169. X            *mp = *np;
  1170. X            *np = tp;
  1171. X        }
  1172. X    }
  1173. X    else {
  1174. X        part(mp, itemcount, &ri, &rj);
  1175. X        isort(mp, rj+1);
  1176. X        isort(mp+ri, itemcount-ri);
  1177. X    }
  1178. X}
  1179. X
  1180. Xstatic
  1181. Xpart (ptr, itemcount, pi, pj)
  1182. Xchar *ptr[];
  1183. Xint itemcount;
  1184. Xint *pi, *pj;
  1185. X{
  1186. X    char *ref, *tp;
  1187. X    register char **mp;
  1188. X    register int mi, mj;
  1189. X
  1190. X    mi = 0;
  1191. X    mj = itemcount-1;
  1192. X    mp = ptr;
  1193. X    for (ref = *(mp + mj/2); mi <= mj;) {
  1194. X        for (;strcmp(*(mp+mi), ref) < 0; mi++);
  1195. X        for (;strcmp(*(mp+mj), ref) > 0; mj--);
  1196. X        if (mi <= mj) {
  1197. X            tp = *(mp+mi);
  1198. X            *(mp+mi++) = *(mp+mj);
  1199. X            *(mp+mj--) = tp;
  1200. X        }
  1201. X    }
  1202. X    *pi = mi;
  1203. X    *pj = mj;
  1204. X}
  1205. SHAR_EOF
  1206. $TOUCH -am 0605074590 i/isort.c &&
  1207. chmod 0644 i/isort.c ||
  1208. echo "restore of i/isort.c failed"
  1209. set `wc -c i/isort.c`;Wc_c=$1
  1210. if test "$Wc_c" != "1021"; then
  1211.     echo original size 1021, current size $Wc_c
  1212. fi
  1213. # ============= i/istartl.c ==============
  1214. echo "x - extracting i/istartl.c (Text)"
  1215. sed 's/^X//' << 'SHAR_EOF' > i/istartl.c &&
  1216. X/* istartl.c */
  1217. X/******************************************************
  1218. X* match word to first non-white word of lines in buffer
  1219. X* Istvan Mohos, 1987 --- in the Public Domain
  1220. X******************************************************/
  1221. X
  1222. X#include "i.h"
  1223. X
  1224. Xchar *
  1225. Xistartl (start, end, word)
  1226. Xregister char *start;
  1227. Xchar *end, *word;
  1228. X{
  1229. X    register char *off, c;
  1230. X    int length;
  1231. X
  1232. X    if (NULCHARP (start)) {
  1233. X        ierror ("istartl: null buffer");
  1234. X        return (NULL);
  1235. X    }
  1236. X    ITOEND;
  1237. X
  1238. X    if (BADCHARP(word)) {
  1239. X        ierror ("istartl: invalid word");
  1240. X        return (NULL);
  1241. X    }
  1242. X
  1243. X    for (off = word; *off++;);
  1244. X    length = --off - word;
  1245. X    c = *word;
  1246. X    off = end;
  1247. X
  1248. X    for (; start < off;) {
  1249. X        /* stop at first non-white character */
  1250. X        for (;WHITE(*start);)
  1251. X            if (++start == off)
  1252. X                return (NULL);
  1253. X
  1254. X        if ((*start == c) && (start+length <= off) &&
  1255. X            (strncmp(start, word, length) == 0))
  1256. X            return (start);        /* found word searched for */
  1257. X
  1258. X        /* proceed to next newline */
  1259. X        for (;*start != '\n';)
  1260. X            if (++start == off)
  1261. X                return (NULL);
  1262. X    }
  1263. X    return (NULL);
  1264. X}
  1265. SHAR_EOF
  1266. $TOUCH -am 0605074590 i/istartl.c &&
  1267. chmod 0644 i/istartl.c ||
  1268. echo "restore of i/istartl.c failed"
  1269. set `wc -c i/istartl.c`;Wc_c=$1
  1270. if test "$Wc_c" != "1006"; then
  1271.     echo original size 1006, current size $Wc_c
  1272. fi
  1273. # ============= i/istripcom.c ==============
  1274. echo "x - extracting i/istripcom.c (Text)"
  1275. sed 's/^X//' << 'SHAR_EOF' > i/istripcom.c &&
  1276. X/* istripcom.c */
  1277. X/**************************************************
  1278. X: substitute spaces for comments, delimiters in buf
  1279. X: Istvan Mohos, 1987 --- in the Public Domain
  1280. X**************************************************/
  1281. X
  1282. X#include "i.h"
  1283. X
  1284. Xint
  1285. Xistripcom (start, end, lcom, rcom)
  1286. Xregister char *start;
  1287. Xregister char *end;
  1288. Xchar *lcom, *rcom;
  1289. X{
  1290. X    register char *rp;
  1291. X    int lc, rc;
  1292. X    int ri, miss;
  1293. X    int llen, rlen;
  1294. X    int select = 0;
  1295. X    int count = 0;
  1296. X    int nest = 1;
  1297. X
  1298. X    if (NULCHARP(start))
  1299. X        return(ierror("istripcom: invalid buffer"));
  1300. X    ITOEND;
  1301. X    if (BADCHARP(lcom))
  1302. X        return(ierror("istripcom: zero length start comment"));
  1303. X    if (BADCHARP(rcom))
  1304. X        return(ierror("istripcom: zero length end comment"));
  1305. X    if (*lcom < 32)
  1306. X        return(ierror("istripcom: invalid start comment"));
  1307. X
  1308. X    if ((llen = strlen(lcom)) == 1) {
  1309. X        lc = *lcom;
  1310. X        select = 10;
  1311. X    }
  1312. X    else
  1313. X        select = 20;
  1314. X
  1315. X    switch(*rcom) {
  1316. X        case '\n':
  1317. X            break;
  1318. X        default:
  1319. X            if ((rlen = strlen(rcom)) == 1) {
  1320. X                rc = *rcom;
  1321. X                select += 1;
  1322. X            }
  1323. X            else
  1324. X                select += 2;
  1325. X            /* C comments receive special handling */
  1326. X            if (!(strcmp (lcom, "/*") || strcmp (rcom, "*/")))
  1327. X                ++select;
  1328. X            else if (strcmp(lcom, rcom) == 0)
  1329. X                nest = 0;
  1330. X            break;
  1331. X    }
  1332. X
  1333. X    rp = start;
  1334. X    switch (select) {
  1335. X        default:
  1336. X            return(ierror("istripcom: invalid comment specs"));
  1337. X
  1338. X        case 10: /* lcom is single letter, rcom \n */
  1339. X            for (; rp < end; rp++) {
  1340. X                if (*rp == lc) {
  1341. X                    ++count;
  1342. X                    for (*rp++ = ' ';rp<end && *rp != '\n';*rp++ = ' ');
  1343. X                }
  1344. X            }
  1345. X            break;
  1346. X
  1347. X        case 11: /* lcom and rcom are single letters */
  1348. X            for (; rp < end; rp++) {
  1349. X                if (*rp == lc) {
  1350. X                    ++count;
  1351. X                    for (*rp++ = ' ';rp<end && *rp != rc;) {
  1352. X                        if (nest && *rp == lc)
  1353. X                            count += istripcom(rp, end, lcom, rcom);
  1354. X                        *rp++ = ' ';
  1355. X                    }
  1356. X                    if (*rp == rc && rc != '\n')
  1357. X                        *rp = ' '; /* erase right delimiter */
  1358. X                }
  1359. X            }
  1360. X            break;
  1361. X
  1362. X        case 12: /* lcom single letter, rcom is string */
  1363. X            for (; rp < end; rp++) {
  1364. X                if (*rp == lc) {
  1365. X                    ++count;
  1366. X                    *rp++ = ' ';
  1367. X
  1368. X                    for (; end-rp >= rlen &&
  1369. X                    (miss = strncmp (rp, rcom, rlen)); *rp++ = ' ')
  1370. X                        if (nest && *rp == lc)
  1371. X                            count += istripcom (rp, end, lcom, rcom);
  1372. X
  1373. X                    if (!miss) {
  1374. X                        for (ri = rlen; --ri; *rp++ = ' ');
  1375. X                        *rp = ' '; /* erase bytes of delimiter */
  1376. X                    }
  1377. X                    else { /* not enough space for delimiter */
  1378. X                        for (ri = rlen; --ri; *rp++ = ' ');
  1379. X                        --rp;
  1380. X                    }
  1381. X                }
  1382. X            }
  1383. X            break;
  1384. X
  1385. X        case 20: /* lcom is string, rcom is \n */
  1386. X            for (; rp < end; rp++) {
  1387. X                if (end-rp >= llen &&
  1388. X                (miss = strncmp (rp, lcom, llen)) == 0) {
  1389. X                    ++count;
  1390. X                    for (ri = llen; --ri >= 0; *rp++ = ' ');
  1391. X                    for (;rp < end && *rp != '\n'; *rp++ = ' ');
  1392. X                }
  1393. X            }
  1394. X            break;
  1395. X
  1396. X        case 21: /* lcom is string, rcom single char */
  1397. X            for (; rp < end; rp++) {
  1398. X                if (end-rp >= llen &&
  1399. X                (miss = strncmp (rp, lcom, llen)) == 0) {
  1400. X                    ++count;
  1401. X                    for (ri = llen; --ri >= 0; *rp++ = ' ');
  1402. X
  1403. X                    for (;rp < end && *rp != rc; *rp++ = ' ')
  1404. X                        if (nest && end-rp >= llen &&
  1405. X                        strncmp (rp, lcom, llen) == 0)
  1406. X                            count += istripcom( rp, end, lcom, rcom);
  1407. X
  1408. X                    if (*rp == rc && rc != '\n')
  1409. X                        *rp = ' '; /* erase right delimiter */
  1410. X                }
  1411. X            }
  1412. X            break;
  1413. X
  1414. X        case 22: /* lcom is string, rcom is string */
  1415. X            for (; rp < end; rp++) {
  1416. X                if (end-rp >= llen &&
  1417. X                (miss = strncmp (rp, lcom, llen)) == 0) {
  1418. X                    ++count;
  1419. X                    for (ri = llen; --ri >= 0; *rp++ = ' ');
  1420. X
  1421. X                    for (; end-rp >= rlen &&
  1422. X                    (miss = strncmp (rp, rcom, rlen)); *rp++ = ' ')
  1423. X                        if (nest && end-rp >= llen &&
  1424. X                        strncmp (rp, lcom, llen) == 0)
  1425. X                            count += istripcom(rp, end, lcom, rcom);
  1426. X
  1427. X                    if (!miss) {
  1428. X                        for (ri = rlen; --ri; *rp++ = ' ');
  1429. X                        *rp = ' '; /* erase last bytes of delim */
  1430. X                    }
  1431. X                    else { /* not enough space for delimiter */
  1432. X                        for (ri = rlen; --ri; *rp++ = ' ');
  1433. X                        --rp;
  1434. X                    }
  1435. X                }
  1436. X            }
  1437. X            break;
  1438. X
  1439. X        case 23: /* C comments */
  1440. X            for (; rp < end; rp++) {
  1441. X
  1442. X                /* skip character constants */
  1443. X                if (*rp == '\\') { /* skip next byte */
  1444. X                    if (++rp < end)
  1445. X                        ++rp;
  1446. X                    continue;
  1447. X                }
  1448. X
  1449. X                /* skip string constants */
  1450. X                if (*rp == '\'') {
  1451. X                    escape1:
  1452. X                    while (++rp != end && *rp != '\'');
  1453. X                    if (rp == end)
  1454. X                        continue;
  1455. X                    if (*(rp-1) == '\\') /* escaped quote */
  1456. X                        goto escape1;
  1457. X                    ++rp;
  1458. X                    continue;
  1459. X                }
  1460. X                if (*rp == '"') {
  1461. X                    escape2:
  1462. X                    while (++rp != end && *rp != '"');
  1463. X                    if (rp == end)
  1464. X                        continue;
  1465. X                    if (*(rp-1) == '\\') /* escaped quote */
  1466. X                        goto escape2;
  1467. X                    ++rp;
  1468. X                    continue;
  1469. X                }
  1470. X
  1471. X                if (end-rp >= llen &&
  1472. X                (miss = strncmp (rp, lcom, llen)) == 0) {
  1473. X                    ++count;
  1474. X                    *rp++ = ' ';
  1475. X                    *rp++ = ' ';
  1476. X                    for (; end-rp >= rlen &&
  1477. X                    (miss = strncmp (rp, rcom, rlen)); *rp++ = ' ');
  1478. X                    if (!miss) {
  1479. X                        *rp++ = ' ';
  1480. X                        *rp = ' ';
  1481. X                    }
  1482. X                    else
  1483. X                        *rp = ' '; /* no delimiter at end */
  1484. X                }
  1485. X            }
  1486. X            break;
  1487. X    }
  1488. X    return(count);
  1489. X }
  1490. SHAR_EOF
  1491. $TOUCH -am 0605074590 i/istripcom.c &&
  1492. chmod 0644 i/istripcom.c ||
  1493. echo "restore of i/istripcom.c failed"
  1494. set `wc -c i/istripcom.c`;Wc_c=$1
  1495. if test "$Wc_c" != "4802"; then
  1496.     echo original size 4802, current size $Wc_c
  1497. fi
  1498. # ============= i/istripdq.c ==============
  1499. echo "x - extracting i/istripdq.c (Text)"
  1500. sed 's/^X//' << 'SHAR_EOF' > i/istripdq.c &&
  1501. X/* istripdq.c */
  1502. X/********************************************
  1503. X: substitute spaces for quoted strings in buf
  1504. X: Istvan Mohos, 1987 --- in the Public Domain
  1505. X********************************************/
  1506. X
  1507. X#include "i.h"
  1508. X
  1509. Xint
  1510. Xistripdq (start, end)
  1511. Xregister char *start;
  1512. Xregister char *end;
  1513. X{
  1514. X    register char *rp;
  1515. X    int count = 0;
  1516. X
  1517. X    if (NULCHARP (start))
  1518. X        return (ierror ("istripdq: null buffer"));
  1519. X    ITOEND;
  1520. X
  1521. X    for (rp = start; rp < end; rp++) {
  1522. X        if ((rp > start) &&
  1523. X           ((*rp == '"' && *(rp-1) == '\\') ||
  1524. X            (*rp == '"' && *(rp-1) == '\'' && *(rp+1) == '\'')))
  1525. X            continue;
  1526. X
  1527. X        if (*rp == '"') { /* found left delimiter */
  1528. X            ++count;
  1529. X            for (rp++; rp < end; rp++) { /* blank escaped dqs, etc. */
  1530. X                if ((*rp == '"' && *(rp-1) == '\\') ||
  1531. X                    (*rp == '"' && *(rp-1) == '\'' && *(rp+1) == '\''))
  1532. X                    *rp = ' ';
  1533. X                if (*rp == '"')
  1534. X                    break; /* found right delimiter */
  1535. X                *rp = ' ';
  1536. X            }
  1537. X        }
  1538. X    }
  1539. X
  1540. X    return(count);
  1541. X }
  1542. SHAR_EOF
  1543. $TOUCH -am 0605074590 i/istripdq.c &&
  1544. chmod 0644 i/istripdq.c ||
  1545. echo "restore of i/istripdq.c failed"
  1546. set `wc -c i/istripdq.c`;Wc_c=$1
  1547. if test "$Wc_c" != "916"; then
  1548.     echo original size 916, current size $Wc_c
  1549. fi
  1550. # ============= i/istripsq.c ==============
  1551. echo "x - extracting i/istripsq.c (Text)"
  1552. sed 's/^X//' << 'SHAR_EOF' > i/istripsq.c &&
  1553. X/* istripsq.c */
  1554. X/********************************************
  1555. X: substitute spaces for single quoted strings
  1556. X: Istvan Mohos, 1987 --- in the Public Domain
  1557. X********************************************/
  1558. X
  1559. X#include "i.h"
  1560. X
  1561. Xint
  1562. Xistripsq (start, end)
  1563. Xregister char *start;
  1564. Xregister char *end;
  1565. X{
  1566. X    register char *rp;
  1567. X    int count = 0;
  1568. X
  1569. X    if (NULCHARP (start))
  1570. X        return (ierror ("istripsq: null buffer"));
  1571. X    ITOEND;
  1572. X
  1573. X    for (rp = start; rp < end; rp++) {
  1574. X        if ((rp > start) &&
  1575. X           ((*rp == '\'' && *(rp-1) == '\\')))
  1576. X            continue;
  1577. X
  1578. X        if (*rp == '\'') { /* found left delimiter */
  1579. X            ++count;
  1580. X            for (rp++; rp < end; rp++) { /* blank escaped sqes, etc. */
  1581. X                if ((*rp == '\'' && *(rp-1) == '\\'))
  1582. X                    *rp = ' ';
  1583. X                if (*rp == '\'')
  1584. X                    break; /* found right delimiter */
  1585. X                *rp = ' ';
  1586. X            }
  1587. X        }
  1588. X    }
  1589. X
  1590. X    return(count);
  1591. X }
  1592. SHAR_EOF
  1593. $TOUCH -am 0605074590 i/istripsq.c &&
  1594. chmod 0644 i/istripsq.c ||
  1595. echo "restore of i/istripsq.c failed"
  1596. set `wc -c i/istripsq.c`;Wc_c=$1
  1597. if test "$Wc_c" != "805"; then
  1598.     echo original size 805, current size $Wc_c
  1599. fi
  1600. # ============= i/istripstr.c ==============
  1601. echo "x - extracting i/istripstr.c (Text)"
  1602. sed 's/^X//' << 'SHAR_EOF' > i/istripstr.c &&
  1603. X/* istripstr.c */
  1604. X/**************************************************
  1605. X: blank occurrences of string in buffer with spaces
  1606. X: Istvan Mohos, 1987 --- in the Public Domain
  1607. X**************************************************/
  1608. X
  1609. X#include "i.h"
  1610. X
  1611. Xint
  1612. Xistripstr (start, end, string)
  1613. Xregister char *start;
  1614. Xchar *end, *string;
  1615. X{
  1616. X    register char *off, c;
  1617. X    char *anchor;
  1618. X    int count = 0;
  1619. X    int length;
  1620. X
  1621. X    if (NULCHARP (start))
  1622. X        return (ierror ("istripstr: null buffer"));
  1623. X    ITOEND;
  1624. X
  1625. X    if (BADCHARP(string))
  1626. X        return(ierror("istripstr: invalid string"));
  1627. X
  1628. X    for (off = string; *off++;);
  1629. X    length = --off - string;
  1630. X    c = *string;
  1631. X    off = end;
  1632. X
  1633. X    for(; start < off; start++) {
  1634. X        if ((*start == c) && ((anchor = start+length) <= off) &&
  1635. X            (strncmp(start, string, length) == 0)) {
  1636. X            ++count;
  1637. X            for(; start < anchor; *start++ = ' ');
  1638. X        }
  1639. X    }
  1640. X    return(count);
  1641. X}
  1642. SHAR_EOF
  1643. $TOUCH -am 0605074590 i/istripstr.c &&
  1644. chmod 0644 i/istripstr.c ||
  1645. echo "restore of i/istripstr.c failed"
  1646. set `wc -c i/istripstr.c`;Wc_c=$1
  1647. if test "$Wc_c" != "831"; then
  1648.     echo original size 831, current size $Wc_c
  1649. fi
  1650. # ============= i/iswap.c ==============
  1651. echo "x - extracting i/iswap.c (Text)"
  1652. sed 's/^X//' << 'SHAR_EOF' > i/iswap.c &&
  1653. X/* iswap.c */
  1654. X/********************************************
  1655. X* change one string to another in buffer
  1656. X* Istvan Mohos, 1987 --- in the Public Domain
  1657. X*********************************************/
  1658. X
  1659. X#include "i.h"
  1660. X
  1661. Xint
  1662. Xiswap (start, end, from, to)
  1663. Xchar *start, *end, *from, *to;
  1664. X{
  1665. X    register char *inp, *off;
  1666. X    char *mark, ch;
  1667. X    int frsiz, tosiz;
  1668. X    int count = 0;
  1669. X
  1670. X    if (NULCHARP (start))
  1671. X        return (ierror ("iswap: null buffer"));
  1672. X    ITOEND;
  1673. X
  1674. X    if (BADCHARP(from))
  1675. X        return(ierror("iswap: bad source pattern"));
  1676. X    if (BADCHARP(to))
  1677. X        return(ierror("iswap: bad target pattern"));
  1678. X
  1679. X    for (off = from; *off++;);
  1680. X    frsiz = --off - from;
  1681. X
  1682. X    for (off = to; *off++;);
  1683. X    tosiz = --off - to;
  1684. X
  1685. X    off = end;
  1686. X    if ((off -= frsiz) <= start)
  1687. X        return(0);
  1688. X    for (inp = start; inp < off; inp++) {
  1689. X        if (*inp == *from && ibcmp(inp, from, frsiz) == 0) {
  1690. X            mark = inp;
  1691. X            inp += tosiz;
  1692. X            ch = *inp;
  1693. X            strcpy (mark, to);
  1694. X            *inp-- = ch;
  1695. X            ++count;
  1696. X        }
  1697. X    }
  1698. X    return(count);
  1699. X}
  1700. SHAR_EOF
  1701. $TOUCH -am 0605074590 i/iswap.c &&
  1702. chmod 0644 i/iswap.c ||
  1703. echo "restore of i/iswap.c failed"
  1704. set `wc -c i/iswap.c`;Wc_c=$1
  1705. if test "$Wc_c" != "937"; then
  1706.     echo original size 937, current size $Wc_c
  1707. fi
  1708. # ============= i/itexrect.c ==============
  1709. echo "x - extracting i/itexrect.c (Text)"
  1710. sed 's/^X//' << 'SHAR_EOF' > i/itexrect.c &&
  1711. X/* itexrect.c */
  1712. X/**********************************
  1713. X* make rectangular array from lines
  1714. X* Istvan Mohos, 1987 --- in the Public Domain
  1715. X**********************************/
  1716. X
  1717. X#include "i.h"
  1718. X
  1719. Xint
  1720. Xitexrect (start, end, mallocp, lcount)
  1721. Xregister char *start, *end;
  1722. Xchar **mallocp;
  1723. Xint *lcount;
  1724. X{
  1725. X    int linecount, longest;
  1726. X    char *to, *behind;
  1727. X    int length;
  1728. X    register int ri;
  1729. X
  1730. X    if (NULCHARP (start))
  1731. X        return (ierror ("itexrect: null buffer"));
  1732. X    ITOEND;
  1733. X
  1734. X    if (end - start < 1)
  1735. X        return(ierror("itexrect: empty source buffer"));
  1736. X
  1737. X    longest = ilongest (start, end, &linecount);
  1738. X    if (longest == 0 || linecount == 0) {
  1739. X        *mallocp = NULL;
  1740. X        *lcount = 0;
  1741. X        return (0);
  1742. X    }
  1743. X
  1744. X    if (NULCHARP(*mallocp = malloc((unsigned int)linecount * longest)))
  1745. X        return(ierror("itexrect: can't allocate *mallocp buffer"));
  1746. X
  1747. X    /* space fill to max line length in *mallocp */
  1748. X    for (behind = start, to = *mallocp; start < end; start++) {
  1749. X        if (*start == '\n' || *start == '\0') {
  1750. X            length = start - behind;
  1751. X            behind = start + 1;
  1752. X            for (ri = longest - length; --ri >= 0; *to++ = ' ');
  1753. X        }
  1754. X        else
  1755. X            *to++ = *start;
  1756. X    }
  1757. X    *lcount = linecount;
  1758. X    return (longest);
  1759. X}
  1760. SHAR_EOF
  1761. $TOUCH -am 0605074590 i/itexrect.c &&
  1762. chmod 0644 i/itexrect.c ||
  1763. echo "restore of i/itexrect.c failed"
  1764. set `wc -c i/itexrect.c`;Wc_c=$1
  1765. if test "$Wc_c" != "1123"; then
  1766.     echo original size 1123, current size $Wc_c
  1767. fi
  1768. # ============= i/itoday.c ==============
  1769. echo "x - extracting i/itoday.c (Text)"
  1770. sed 's/^X//' << 'SHAR_EOF' > i/itoday.c &&
  1771. X/* itoday.c */
  1772. X/*************************************************
  1773. X* return integer value of current day, month, year
  1774. X* Istvan Mohos, 1987 --- in the Public Domain
  1775. X*************************************************/
  1776. X
  1777. X#include "i.h"
  1778. X
  1779. Xint
  1780. Xitosec()
  1781. X{
  1782. X    struct tm *ptr;
  1783. X
  1784. X    ptr = _igetdate();
  1785. X    return (ptr->tm_sec);
  1786. X}
  1787. X
  1788. Xint
  1789. Xitomin()
  1790. X{
  1791. X    struct tm *ptr;
  1792. X
  1793. X    ptr = _igetdate();
  1794. X    return (ptr->tm_min);
  1795. X}
  1796. X
  1797. Xint
  1798. Xitohour()
  1799. X{
  1800. X    struct tm *ptr;
  1801. X
  1802. X    ptr = _igetdate();
  1803. X    return (ptr->tm_hour);
  1804. X}
  1805. X
  1806. Xint
  1807. Xitoday()
  1808. X{
  1809. X    struct tm *ptr;
  1810. X
  1811. X    ptr = _igetdate();
  1812. X    return (ptr->tm_mday);
  1813. X}
  1814. X
  1815. Xint
  1816. Xitomonth()
  1817. X{
  1818. X    struct tm *ptr;
  1819. X
  1820. X    ptr = _igetdate();
  1821. X    return (ptr->tm_mon + 1);
  1822. X}
  1823. X
  1824. Xint
  1825. Xitoyear()
  1826. X{
  1827. X    struct tm *ptr;
  1828. X
  1829. X    ptr = _igetdate();
  1830. X    return (ptr->tm_year + 1900);
  1831. X}
  1832. SHAR_EOF
  1833. $TOUCH -am 0605074590 i/itoday.c &&
  1834. chmod 0644 i/itoday.c ||
  1835. echo "restore of i/itoday.c failed"
  1836. set `wc -c i/itoday.c`;Wc_c=$1
  1837. if test "$Wc_c" != "722"; then
  1838.     echo original size 722, current size $Wc_c
  1839. fi
  1840. # ============= i/itok.c ==============
  1841. echo "x - extracting i/itok.c (Text)"
  1842. sed 's/^X//' << 'SHAR_EOF' > i/itok.c &&
  1843. X/* itok.c */
  1844. X/**********************************************
  1845. X* bidir token recognizer, can handle null bytes
  1846. X* Istvan Mohos, 1987 --- in the Public offomain
  1847. X***********************************************/
  1848. X
  1849. X#include "i.h"
  1850. X
  1851. X#define ISETEND      if (end == (char *)NULL)\
  1852. X                         for(off = start; *off; off++);\
  1853. X                     else if (start > end) {\
  1854. X                         for(off = start; *off; off++)\
  1855. X                             if (*off == '\n') { ++off; break; }\
  1856. X                     } else off = end;\
  1857. X                     end = off
  1858. X
  1859. Xint
  1860. Xitok (context, start, end, result)
  1861. Xint context;
  1862. Xregister char *start;
  1863. Xchar *end, **result;
  1864. X{
  1865. X    register char *off, *past_dlm;
  1866. X    int dlmflag, tokflag;
  1867. X    static char *anchor, *P;
  1868. X    static char *pre, *buflim;
  1869. X
  1870. X    if (NULCHARP (start))
  1871. X        return (ierror ("itok: null 'start' buffer"));
  1872. X
  1873. X    switch (context) {
  1874. X        case INITOKF: /* first call, forward */
  1875. X        case INITOKR: /* first call, backwards */
  1876. X            ISETEND;
  1877. X            buflim = off;
  1878. X            (context == INITOKF) ? (P = start) : (P = off -1);
  1879. X            pre = start -1;
  1880. X            return(off - start);
  1881. X
  1882. X        case ITOKF: /* subsequent calls, forward */
  1883. X        default:
  1884. X            if (P == pre)
  1885. X                 ++P;
  1886. X            ISETEND;
  1887. X            past_dlm = off;
  1888. X
  1889. X            /* move to 1st non-delimiter byte */
  1890. X            for (tokflag = 0; P < buflim;) {
  1891. X                for (dlmflag = 0, off = start; off < past_dlm;)
  1892. X                    if (dlmflag = (*off++ == *P)) {
  1893. X                        P++;
  1894. X                        break;   /* do not test other separators */
  1895. X                    }
  1896. X                if (tokflag = !dlmflag)  /* found first byte of token */
  1897. X                    break;
  1898. X            }
  1899. X
  1900. X            if (!tokflag) {
  1901. X                *result = NULL;
  1902. X                return(0);
  1903. X            }
  1904. X
  1905. X            /* move past token */
  1906. X            for (anchor = P; P < buflim; P++)
  1907. X                for (off = start; off < past_dlm;)
  1908. X                    if (*off++ == *P) {
  1909. X                        *result = anchor;
  1910. X                        return(P - anchor); /* most return from here */
  1911. X                    }
  1912. X
  1913. X            *result = anchor; /* but no space for delimiter */
  1914. X            return(buflim - anchor);
  1915. X
  1916. X        case ITOKR: /* subsequent calls, backwards */
  1917. X            if (P == buflim)
  1918. X                 --P;
  1919. X            ISETEND;
  1920. X            past_dlm = off;
  1921. X
  1922. X            /* move backwards to 1st non-delimiter */
  1923. X            for (tokflag = 0; P > pre;) {
  1924. X                for (dlmflag = 0, off = start; off < past_dlm;)
  1925. X                    if (dlmflag = (*off++ == *P)) {
  1926. X                        P--;
  1927. X                        break;   /* do not test other separators */
  1928. X                    }
  1929. X                if (tokflag = !dlmflag)  /* rightmost byte of token */
  1930. X                    break;
  1931. X            }
  1932. X
  1933. X            if (!tokflag) {
  1934. X                *result = NULL;
  1935. X                return(0);
  1936. X            }
  1937. X
  1938. X            /* move to left of token */
  1939. X            for (anchor = P; P > pre; P--)
  1940. X                for (off = start; off < past_dlm;)
  1941. X                    if (*off++ == *P) {
  1942. X                        *result = P +1;
  1943. X                        return(anchor - P); /* most return from here */
  1944. X                    }
  1945. X
  1946. X            *result = P + 1; /* but no delimiter at the beginning */
  1947. X            return(anchor - pre);
  1948. X    }
  1949. X}
  1950. SHAR_EOF
  1951. $TOUCH -am 0605074590 i/itok.c &&
  1952. chmod 0644 i/itok.c ||
  1953. echo "restore of i/itok.c failed"
  1954. set `wc -c i/itok.c`;Wc_c=$1
  1955. if test "$Wc_c" != "2546"; then
  1956.     echo original size 2546, current size $Wc_c
  1957. fi
  1958. # ============= i/itran.c ==============
  1959. echo "x - extracting i/itran.c (Text)"
  1960. sed 's/^X//' << 'SHAR_EOF' > i/itran.c &&
  1961. X/* itran.c */
  1962. X/********************************************
  1963. X* change one char to another in buffer
  1964. X* Istvan Mohos, 1987 --- in the Public Domain
  1965. X********************************************/
  1966. X
  1967. X#include "i.h"
  1968. X
  1969. Xint
  1970. Xitran (start, end, fromc, toc)
  1971. Xregister char *start, *end, fromc, toc;
  1972. X{
  1973. X    int count = 0;
  1974. X
  1975. X    if (NULCHARP (start))
  1976. X        return (ierror ("itran: null buffer"));
  1977. X    ITOEND;
  1978. X
  1979. X    for (; start < end; start++)
  1980. X        if (*start == fromc)
  1981. X            *start = toc, ++count;
  1982. X    return (count);
  1983. X}
  1984. SHAR_EOF
  1985. $TOUCH -am 0605074590 i/itran.c &&
  1986. chmod 0644 i/itran.c ||
  1987. echo "restore of i/itran.c failed"
  1988. set `wc -c i/itran.c`;Wc_c=$1
  1989. if test "$Wc_c" != "475"; then
  1990.     echo original size 475, current size $Wc_c
  1991. fi
  1992. # ============= i/iuniq.c ==============
  1993. echo "x - extracting i/iuniq.c (Text)"
  1994. sed 's/^X//' << 'SHAR_EOF' > i/iuniq.c &&
  1995. X/* iuniq.c */
  1996. X/*************************************************
  1997. X* return 1 if parameter is used for the first time
  1998. X* Istvan Mohos, 1987 --- in the Public Domain
  1999. X**************************************************/
  2000. X
  2001. X#include "i.h"
  2002. X
  2003. Xint
  2004. Xiuniq (item)
  2005. Xint item;
  2006. X{
  2007. X    static int within = 0;
  2008. X    static char *mp = NULL;
  2009. X
  2010. X    if (item < 0) {
  2011. X        if (mp != NULL) {
  2012. X            free(mp);
  2013. X            mp = NULL;
  2014. X        }
  2015. X        within = 0;
  2016. X        return(0);
  2017. X    }
  2018. X    if (item >= within) {
  2019. X        if (within)
  2020. X            return(-sys_nerr);
  2021. X        if ((mp = calloc((unsigned)item, sizeof(char))) == NULL) {
  2022. X            ierror("iuniq: calloc error");
  2023. X            return(-sys_nerr);
  2024. X        }
  2025. X        within = item;
  2026. X        return(0);
  2027. X    }
  2028. X    if (*(mp+item))
  2029. X        return(0);
  2030. X    *(mp+item) = 1;
  2031. X        return(1);
  2032. X}
  2033. SHAR_EOF
  2034. $TOUCH -am 0605074590 i/iuniq.c &&
  2035. chmod 0644 i/iuniq.c ||
  2036. echo "restore of i/iuniq.c failed"
  2037. set `wc -c i/iuniq.c`;Wc_c=$1
  2038. if test "$Wc_c" != "683"; then
  2039.     echo original size 683, current size $Wc_c
  2040. fi
  2041. # ============= i/iuniqa.c ==============
  2042. echo "x - extracting i/iuniqa.c (Text)"
  2043. sed 's/^X//' << 'SHAR_EOF' > i/iuniqa.c &&
  2044. X/* iuniqa.c */
  2045. X/*************************************************
  2046. X* return 1 if parameter is used for the first time
  2047. X* Istvan Mohos, 1987 --- in the Public Domain
  2048. X**************************************************/
  2049. X
  2050. X#include "i.h"
  2051. X
  2052. Xint
  2053. Xiuniqa (item)
  2054. Xint item;
  2055. X{
  2056. X    static int within = 0;
  2057. X    static char *mp = NULL;
  2058. X
  2059. X    if (item < 0) {
  2060. X        if (mp != NULL) {
  2061. X            free(mp);
  2062. X            mp = NULL;
  2063. X        }
  2064. X        within = 0;
  2065. X        return(0);
  2066. X    }
  2067. X    if (item >= within) {
  2068. X        if (within)
  2069. X            return(-sys_nerr);
  2070. X        if ((mp = calloc((unsigned)item, sizeof(char))) == NULL) {
  2071. X            ierror("iuniqa: calloc error");
  2072. X            return(-sys_nerr);
  2073. X        }
  2074. X        within = item;
  2075. X        return(0);
  2076. X    }
  2077. X    if (*(mp+item))
  2078. X        return(0);
  2079. X    *(mp+item) = 1;
  2080. X        return(1);
  2081. X}
  2082. SHAR_EOF
  2083. $TOUCH -am 0605074590 i/iuniqa.c &&
  2084. chmod 0644 i/iuniqa.c ||
  2085. echo "restore of i/iuniqa.c failed"
  2086. set `wc -c i/iuniqa.c`;Wc_c=$1
  2087. if test "$Wc_c" != "686"; then
  2088.     echo original size 686, current size $Wc_c
  2089. fi
  2090. # ============= i/iupper.c ==============
  2091. echo "x - extracting i/iupper.c (Text)"
  2092. sed 's/^X//' << 'SHAR_EOF' > i/iupper.c &&
  2093. X/* iupper.c */
  2094. X/********************************************
  2095. X* fast toupper string in buffer
  2096. X* Istvan Mohos, 1987 --- in the Public Domain
  2097. X*********************************************/
  2098. X
  2099. X#include "i.h"
  2100. X#include "iupcas.h"
  2101. X
  2102. Xint
  2103. Xiupper (start, end)
  2104. Xregister char *start;
  2105. Xchar *end;
  2106. X{
  2107. X    register char *up, *off;
  2108. X
  2109. X    if (NULCHARP (start))
  2110. X        return (ierror ("iupper: null buffer"));
  2111. X    ITOEND;
  2112. X
  2113. X    off = end;
  2114. X
  2115. X    for (up = upcas; --off >= start;)
  2116. X        *off = *(up + *off);
  2117. X    return(end - start);
  2118. X}
  2119. SHAR_EOF
  2120. $TOUCH -am 0605074590 i/iupper.c &&
  2121. chmod 0644 i/iupper.c ||
  2122. echo "restore of i/iupper.c failed"
  2123. set `wc -c i/iupper.c`;Wc_c=$1
  2124. if test "$Wc_c" != "480"; then
  2125.     echo original size 480, current size $Wc_c
  2126. fi
  2127. # ============= i/iwhich.c ==============
  2128. echo "x - extracting i/iwhich.c (Text)"
  2129. sed 's/^X//' << 'SHAR_EOF' > i/iwhich.c &&
  2130. X/* iwhich.c */
  2131. X/********************************************
  2132. X* faster "which"
  2133. X* Istvan Mohos, 1987 --- in the Public Domain
  2134. X*********************************************/
  2135. X
  2136. X#include "i.h"
  2137. X
  2138. Xchar *
  2139. Xiwhich (item, perm)
  2140. Xchar *item;
  2141. Xint perm;
  2142. X{
  2143. X    char *nextptr, *path;
  2144. X    static char segment[256];
  2145. X    char *delim = " :";
  2146. X    register int siz;
  2147. X
  2148. X    if (BADCHARP(item)) {
  2149. X        ierror("iwhich: invalid pointer");
  2150. X        return(NULL);
  2151. X    }
  2152. X    if (NULCHARP(ilast(item, '/'))) {              /* path not given */
  2153. X        if ((path = getenv("PATH")) != NULL) {     /* PATH exists */
  2154. X            ftok(INITOKF, path, inull (path));
  2155. X            for(;siz = ftok(ITOKF, delim, delim+2, &nextptr);) {
  2156. X                sprintf(segment, "%*.*s/%s",siz, siz, nextptr, item);
  2157. X                if (access(segment, perm) != -1)
  2158. X                    return(segment);
  2159. X            }
  2160. X        }
  2161. X        return(NULL);
  2162. X    }
  2163. X    if (access(item, perm) != -1)    /* else verify given path */
  2164. X        return(item);
  2165. X    return(NULL);
  2166. X}
  2167. X
  2168. Xstatic
  2169. Xint
  2170. Xftok (context, head, Z, result)
  2171. Xint context;
  2172. Xchar *head, *Z, **result;
  2173. X{
  2174. X    register char *rp, *past_dlm;
  2175. X    int dlmflag, tokflag;
  2176. X    static char *anchor, *P;
  2177. X    static char *pre, *off;
  2178. X
  2179. X    switch (context) {
  2180. X        case INITOKF: /* first call, forward */
  2181. X            off = Z;
  2182. X            P = head;
  2183. X            pre = head -1;
  2184. X            return(off - head);
  2185. X
  2186. X        case ITOKF: /* subsequent calls, forward */
  2187. X        default:
  2188. X            if (P == pre)
  2189. X                 ++P;
  2190. X            past_dlm = Z;
  2191. X
  2192. X            /* move to 1st non-delimiter byte */
  2193. X            for (tokflag = 0; P < off;) {
  2194. X                for (dlmflag = 0, rp = head; rp < past_dlm;)
  2195. X                    if (dlmflag = (*rp++ == *P)) {
  2196. X                        P++;
  2197. X                        break;   /* do not test other separators */
  2198. X                    }
  2199. X                if (tokflag = !dlmflag)  /* found first byte of token */
  2200. X                    break;
  2201. X            }
  2202. X
  2203. X            if (!tokflag) {
  2204. X                *result = NULL;
  2205. X                return(0);
  2206. X            }
  2207. X
  2208. X            /* move past token */
  2209. X            for (anchor = P; P < off; P++)
  2210. X                for (rp = head; rp < past_dlm;)
  2211. X                    if (*rp++ == *P) {
  2212. X                        *result = anchor;
  2213. X                        return(P - anchor); /* most return from here */
  2214. X                    }
  2215. X
  2216. X            *result = anchor; /* but no delimiter at the end */
  2217. X            return(off - anchor);
  2218. X    }
  2219. X}
  2220. SHAR_EOF
  2221. $TOUCH -am 0605074590 i/iwhich.c &&
  2222. chmod 0644 i/iwhich.c ||
  2223. echo "restore of i/iwhich.c failed"
  2224. set `wc -c i/iwhich.c`;Wc_c=$1
  2225. if test "$Wc_c" != "1953"; then
  2226.     echo original size 1953, current size $Wc_c
  2227. fi
  2228. echo "End of part 2, continue with part 3"
  2229. exit 0
  2230. -- 
  2231.         Istvan Mohos
  2232.         ...uunet!pyrdc!pyrnj!hhb!istvan
  2233.         RACAL-REDAC/HHB 1000 Wyckoff Ave. Mahwah NJ 07430 201-848-8000
  2234. ======================================================================
  2235.