home *** CD-ROM | disk | FTP | other *** search
- From: istvan@hhb.UUCP (Istvan Mohos)
- Newsgroups: alt.sources
- Subject: Subject: ILIB Unix Toolkit in C
- Message-ID: <548@hhb.UUCP>
- Date: 8 Jun 90 20:51:23 GMT
-
-
- ---- Cut Here and unpack ----
- #!/bin/sh
- # This is part 02 of a multipart archive
- if touch 2>&1 | fgrep '[-amc]' > /dev/null
- then TOUCH=touch
- else TOUCH=true
- fi
- # ============= i/ilower.c ==============
- echo "x - extracting i/ilower.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/ilower.c &&
- X/* ilower.c */
- X/********************************************
- X* fast tolower string in buffer
- X* Istvan Mohos, 1987 --- in the Public Domain
- X*********************************************/
- X
- X#include "i.h"
- X#include "idowncas.h"
- X
- Xint
- Xilower (start, end)
- Xregister char *start;
- Xchar *end;
- X{
- X register char *lo, *off;
- X
- X if (NULCHARP (start))
- X return (ierror ("ilower: null buffer"));
- X ITOEND;
- X
- X off = end;
- X
- X for (lo = downcas; --off >= start;)
- X *off = *(lo + *off);
- X return(end - start);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/ilower.c &&
- chmod 0644 i/ilower.c ||
- echo "restore of i/ilower.c failed"
- set `wc -c i/ilower.c`;Wc_c=$1
- if test "$Wc_c" != "484"; then
- echo original size 484, current size $Wc_c
- fi
- # ============= i/imatch.c ==============
- echo "x - extracting i/imatch.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/imatch.c &&
- X/* imatch.c */
- X/********************************************
- X* find word in buffer
- X* Istvan Mohos, 1987 --- in the Public Domain
- X*********************************************/
- X
- X#include "i.h"
- X
- Xchar *
- Ximatch (start, end, word)
- Xregister char *start;
- Xchar *end, *word;
- X{
- X register char *off;
- X register char *tail;
- X char *sc, *tc;
- X char *pp, *wp;
- X int length;
- X
- X if (NULCHARP (start) || BADCHARP (word)) {
- X ierror("imatch: invalid parameters");
- X return(NULL);
- X }
- X ITOEND;
- X
- X for (sc = off = word; *off++;);
- X length = --off - word;
- X tc = --off;
- X
- X off = end;
- X
- X for (off -= --length; start < off;) {
- X
- X /* proceed to first black character */
- X for (;WHITE(*start);)
- X if (++start == off)
- X return(NULL);
- X
- X tail = start + length;
- X if (*start++ == *sc && *tail == *tc)
- X if (length > 1) {
- X for (wp = tc, pp = tail; *--wp == *--pp;)
- X if (pp == start)
- X return(--start);
- X }
- X else
- X return(--start);
- X
- X /* proceed to next white character */
- X for (;BLACK(*start);)
- X if (++start >= off)
- X return(NULL);
- X }
- X return(NULL);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/imatch.c &&
- chmod 0644 i/imatch.c ||
- echo "restore of i/imatch.c failed"
- set `wc -c i/imatch.c`;Wc_c=$1
- if test "$Wc_c" != "1037"; then
- echo original size 1037, current size $Wc_c
- fi
- # ============= i/imode.c ==============
- echo "x - extracting i/imode.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/imode.c &&
- X/* imode.c */
- X/****************************************************
- X* give file name and permission; return true or false
- X* Istvan Mohos, 1987 --- in the Public Domain
- X*****************************************************/
- X
- X#include "i.h"
- X
- Xint
- Ximode (fname, perm)
- Xchar *fname;
- Xint perm;
- X{
- X struct stat sbuf;
- X
- X if (BADCHARP(fname))
- X return (ierror("imode: invalid file name"));
- X
- X if (stat(fname, &sbuf) == -1)
- X return (ierror("imode: stat"));
- X
- X if (perm == 0)
- X return ((int)sbuf.st_mode);
- X
- X if (perm >= 010000 && perm <= 077777 && sbuf.st_mode >= 0100000)
- X return (0); /* file type mismatch */
- X
- X if (perm >= 020000 && perm <= 047777 && sbuf.st_mode >= 060000)
- X return (0); /* block special mismatch against dir or chr */
- X
- X if (((int)sbuf.st_mode & perm) == perm)
- X return (1); /* perm OK */
- X
- X return(0) ; /* perm mismatch */
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/imode.c &&
- chmod 0644 i/imode.c ||
- echo "restore of i/imode.c failed"
- set `wc -c i/imode.c`;Wc_c=$1
- if test "$Wc_c" != "832"; then
- echo original size 832, current size $Wc_c
- fi
- # ============= i/imonth.c ==============
- echo "x - extracting i/imonth.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/imonth.c &&
- X/* imonth.c */
- X/***********************************************
- X* return int 0-12 for current month (0 == error)
- X* Istvan Mohos, 1987 --- in the Public Domain
- X***********************************************/
- X
- X#include "i.h"
- X
- Xint
- Ximonth (ptr)
- Xchar *ptr;
- X{
- X register int hv = 0;
- X register char *hp;
- X static char hashbuf[] = {
- X 12, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 8, 0, 0,
- X 3, 0, 0, 4, 0, 0,10, 5, 9, 0, 0, 7, 0, 6, 0, 0, 0, 0, 0,11, };
- X
- X hp = ptr;
- X if (BADCHARP(hp))
- X return (ierror ("imonth: invalid pointer"));
- X if (*hp > 64) {
- X hv += (*hp++ & 95);
- X if (*hp) {
- X hv += (*hp++ & 95);
- X if (*hp)
- X hv += (*hp & 95);
- X }
- X hv -= 204;
- X if (hv < 0 || hv > 39)
- X return (0);
- X return (hashbuf[hv]);
- X }
- X if ((hv = atoi(hp)) > 12 || hv < 1)
- X return (0);
- X return (hv);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/imonth.c &&
- chmod 0644 i/imonth.c ||
- echo "restore of i/imonth.c failed"
- set `wc -c i/imonth.c`;Wc_c=$1
- if test "$Wc_c" != "790"; then
- echo original size 790, current size $Wc_c
- fi
- # ============= i/inest.c ==============
- echo "x - extracting i/inest.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/inest.c &&
- X/* inest.c */
- X/**********************************************************
- X* create offset:nestlevel list for tracking delimiter pairs
- X* Istvan Mohos, 1987 --- in the Public Domain
- X***********************************************************/
- X
- X#include "i.h"
- X
- Xint
- Xinest (start, end, ldelim, rdelim, infopairs)
- Xchar *start, *end, *ldelim, *rdelim;
- Xint **infopairs;
- X{
- X unsigned int cnt = 0; /* count of delimiters */
- X int lsiz; /* length of left delimiter */
- X int rsiz; /* length of right delimiter */
- X int nestlev = 0; /* level of nesting */
- X int morechars = 1; /* flag that there are more bytes in buf */
- X int morelines = 1; /* flag that there are more lines in buf */
- X register char *pp;
- X register char *mark;
- X register char ld; /* first char of ldelim */
- X register char rd; /* first char of rdelim */
- X char *lstop; /* last point from which to compare ldelim */
- X char *rstop; /* last point from which to compare rdelim */
- X char *nl; /* point to nl char at end of line */
- X char *levp; /* to base of malloc'd int list */
- X int *lpt; /* to access successive int's in list */
- X
- X if (NULCHARP (start))
- X return (ierror ("inest: null buffer"));
- X ITOEND;
- X
- X if (BADCHARP(ldelim) || BADCHARP(rdelim))
- X return(ierror("inest: bad delimiters"));
- X ld = *ldelim;
- X rd = *rdelim;
- X
- X /* fast special case if ldelim and rdelim are single chars */
- X lsiz = strlen(ldelim);
- X if ((rsiz = strlen(rdelim)) == 1 && lsiz == 1) {
- X if (ld == '\n' || rd == '\n')
- X return(ierror("inest: nl delimiter"));
- X if (ld == rd)
- X return (ierror ("inest: identical delimiters"));
- X
- X /* count delimiters */
- X for (pp = end; --pp >= start;)
- X if (*pp == ld || *pp == rd)
- X cnt++;
- X
- X if (NULCHARP (levp = calloc((cnt+1)*2, sizeof(int))))
- X return (ierror ("inest: can't allocate int array"));
- X lpt = (int *)levp;
- X *infopairs = (int *)levp;
- X
- X if (!cnt)
- X return (0);
- X
- X /* write offset and nestlevel into successive cells of list;
- X using positive int for ldelim nestlevel values,
- X using negative int for rdelim nestlevel values
- X */
- X pp = start;
- X morelines = 1;
- X while (morelines) {
- X /* find next nl */
- X for (mark = pp; pp < end && *pp != '\n'; pp++);
- X if (pp == end) {
- X morelines = 0;
- X if (pp == mark)
- X continue;
- X /* else unterminated line still must be processed */
- X }
- X nl = pp, pp = mark;
- X
- X for (; pp < nl; pp++) {
- X if (*pp == ld) {
- X *lpt++ = pp-start;
- X *lpt++ = ++nestlev;
- X }
- X else if (*pp == rd) {
- X *lpt++ = pp-start;
- X if (nestlev)
- X *lpt++ = -(nestlev--);
- X else
- X *lpt++ = 0;
- X }
- X }
- X if (pp != end)
- X pp++; /* get it past nl */
- X }
- X return (cnt);
- X }
- X
- X for (pp = ldelim + lsiz; --pp >= ldelim;)
- X if (*pp == '\n')
- X return(ierror("inest: nl in ldelim"));
- X for (pp = rdelim + rsiz; --pp >= rdelim;)
- X if (*pp == '\n')
- X return(ierror("inest: nl in rdelim"));
- X
- X /* if --- endif : good
- X if --- ifend : bad
- X foo --- oo : good
- X foo --- fo : bad
- X */
- X if (strncmp (ldelim, rdelim, ((lsiz > rsiz) ? rsiz : lsiz)) == 0)
- X return (ierror ("inest: overlapping delimiters"));
- X
- X /* count delimiters */
- X pp = start;
- X lstop = end - lsiz;
- X rstop = end - rsiz;
- X morechars = 1;
- X while (morechars) {
- X for (; pp < end && *pp != ld && *pp != rd; pp++);
- X if (pp == end) {
- X morechars = 0;
- X continue;
- X }
- X if (pp <= lstop && strncmp (pp, ldelim, lsiz) == 0)
- X pp += lsiz, cnt++;
- X else if (pp <= rstop && strncmp (pp, rdelim, rsiz) == 0)
- X pp += rsiz, cnt++;
- X else /* first char of delim did match, but no strcmp */
- X pp++;
- X }
- X
- X if (NULCHARP (levp = calloc((unsigned)(cnt+1)*2, sizeof(int))))
- X return (ierror ("inest: can't allocate int array"));
- X lpt = (int *)levp;
- X *infopairs = (int *)levp;
- X
- X if (!cnt)
- X return (0);
- X
- X /* write offset and nestlevel into successive cells of list;
- X using positive int for ldelim nestlevel values,
- X using negative int for rdelim nestlevel values
- X */
- X pp = start;
- X morelines = 1;
- X while (morelines) {
- X /* find next nl */
- X for (mark = pp; pp < end && *pp != '\n'; pp++);
- X if (pp == end) {
- X morelines = 0;
- X if (pp == mark)
- X continue;
- X /* else unterminated line still must be processed */
- X }
- X nl = pp, pp = mark;
- X lstop = nl - lsiz;
- X rstop = nl - rsiz;
- X
- X morechars = 1;
- X while (morechars) {
- X for (; pp < nl && *pp != ld && *pp != rd; pp++);
- X if (pp == nl) {
- X morechars = 0;
- X continue;
- X }
- X if (pp <= lstop && strncmp (pp, ldelim, lsiz) == 0) {
- X *lpt++ = pp-start;
- X *lpt++ = ++nestlev;
- X pp += lsiz;
- X }
- X else if (pp <= rstop && strncmp (pp, rdelim, rsiz) == 0) {
- X *lpt++ = pp-start;
- X if (nestlev)
- X *lpt++ = -(nestlev--);
- X else
- X *lpt++ = 0;
- X pp += rsiz;
- X }
- X else /* matched first char of a delimiter, but no strcmp */
- X pp++;
- X }
- X if (pp != end)
- X pp++; /* get it past nl */
- X }
- X return (cnt);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/inest.c &&
- chmod 0644 i/inest.c ||
- echo "restore of i/inest.c failed"
- set `wc -c i/inest.c`;Wc_c=$1
- if test "$Wc_c" != "4820"; then
- echo original size 4820, current size $Wc_c
- fi
- # ============= i/inextl.c ==============
- echo "x - extracting i/inextl.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/inextl.c &&
- X/* inextl.c */
- X/********************************************
- X* return location of first token in next line
- X* Istvan Mohos, 1987 --- in the Public Domain
- X********************************************/
- X
- X#include "i.h"
- X
- Xchar *
- Xinextl (start, end, skiptok)
- Xregister char *start;
- Xregister char *end;
- Xregister char *skiptok;
- X{
- X if (NULCHARP (start)) {
- X ierror ("inextl: null buffer");
- X return (NULL);
- X }
- X ITOEND;
- X
- Xagain:
- X /* jump over newline */
- X for (;start < end && *start != '\n'; ++start);
- X if (start >= end)
- X return(NULL);
- X
- X /* find first non-space */
- X for (;start < end && WHITE(*start); ++start);
- X if (start == end)
- X return (start);
- X
- X if (skiptok && (strncmp (skiptok, start, strlen (skiptok)) == 0))
- X goto again;
- X
- X return (start);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/inextl.c &&
- chmod 0644 i/inextl.c ||
- echo "restore of i/inextl.c failed"
- set `wc -c i/inextl.c`;Wc_c=$1
- if test "$Wc_c" != "739"; then
- echo original size 739, current size $Wc_c
- fi
- # ============= i/inl.c ==============
- echo "x - extracting i/inl.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/inl.c &&
- X/* inl.c */
- X/********************************************
- X* return pointer to next newline or null byte
- X* Istvan Mohos, 1987 --- in the Public Domain
- X*********************************************/
- X
- X#include "i.h"
- X
- Xchar *
- Xinl (start)
- Xregister char *start;
- X{
- X if (*start == '\n' || *start == '\0')
- X return(start);
- X
- X /* do not go past newline or null */
- X for(start++; *start; start++)
- X if (*start == '\n' && *(start-1) != '\\')
- X return(start);
- X
- X return(start);
- X}
- X
- Xchar *
- Xinull (start)
- Xregister char *start;
- X{
- X for(; *start; start++);
- X return(start);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/inl.c &&
- chmod 0644 i/inl.c ||
- echo "restore of i/inl.c failed"
- set `wc -c i/inl.c`;Wc_c=$1
- if test "$Wc_c" != "553"; then
- echo original size 553, current size $Wc_c
- fi
- # ============= i/inumsearch.c ==============
- echo "x - extracting i/inumsearch.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/inumsearch.c &&
- X/* inumsearch.c */
- X/***********************************************
- X* alphanum search in array of character pointers
- X* Istvan Mohos, 1987 --- in the Public Domain
- X************************************************/
- X
- X#include "i.h"
- X
- Xint
- Xinumsearch (comparee, wordlist, listcount)
- Xchar *comparee;
- Xchar *wordlist[];
- Xint listcount;
- X{
- X register int lo, hi;
- X register int m, mid;
- X
- X if (BADCHARP (comparee))
- X return(ierror("inumsearch: invalid comparee"));
- X if (listcount < 1)
- X return (-1);
- X
- X for (lo = 0, hi = listcount -1; lo <= hi;) {
- X mid = (lo + hi) >> 1;
- X if ((m = inumstrcmp(comparee, wordlist[mid])) < 0)
- X hi = mid -1;
- X else if (m > 0)
- X lo = mid +1;
- X else
- X return(mid);
- X }
- X return (-1);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/inumsearch.c &&
- chmod 0644 i/inumsearch.c ||
- echo "restore of i/inumsearch.c failed"
- set `wc -c i/inumsearch.c`;Wc_c=$1
- if test "$Wc_c" != "700"; then
- echo original size 700, current size $Wc_c
- fi
- # ============= i/inumsort.c ==============
- echo "x - extracting i/inumsort.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/inumsort.c &&
- X/* inumsort.c */
- X/********************************************
- X* alphanum ptr sort
- X* Istvan Mohos, 1987 --- in the Public Domain
- X*********************************************/
- X
- X#include "i.h"
- X
- Xvoid
- Xinumsort (ptr, itemcount)
- Xchar *ptr[];
- Xint itemcount;
- X{
- X int ri, rj;
- X register char *tp, **mp, **np;
- X
- X if (itemcount < 2)
- X return; /* already sorted */
- X mp = np = ptr;
- X if (itemcount == 2) { /* just exchange if not in order */
- X if (inumstrcmp(*++np, *mp) < 0) {
- X tp = *mp;
- X *mp = *np;
- X *np = tp;
- X }
- X }
- X else {
- X part(mp, itemcount, &ri, &rj);
- X inumsort(mp, rj+1);
- X inumsort(mp+ri, itemcount-ri);
- X }
- X}
- X
- Xstatic
- Xpart (ptr, itemcount, pi, pj)
- Xchar *ptr[];
- Xint itemcount;
- Xint *pi, *pj;
- X{
- X char *ref, *tp;
- X register char **mp;
- X register int mi, mj;
- X
- X mi = 0;
- X mj = itemcount-1;
- X mp = ptr;
- X for (ref = *(mp + mj/2); mi <= mj;) {
- X for (;inumstrcmp(*(mp+mi), ref) < 0; mi++);
- X for (;inumstrcmp(*(mp+mj), ref) > 0; mj--);
- X if (mi <= mj) {
- X tp = *(mp+mi);
- X *(mp+mi++) = *(mp+mj);
- X *(mp+mj--) = tp;
- X }
- X }
- X *pi = mi;
- X *pj = mj;
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/inumsort.c &&
- chmod 0644 i/inumsort.c ||
- echo "restore of i/inumsort.c failed"
- set `wc -c i/inumsort.c`;Wc_c=$1
- if test "$Wc_c" != "1036"; then
- echo original size 1036, current size $Wc_c
- fi
- # ============= i/inumstrcmp.c ==============
- echo "x - extracting i/inumstrcmp.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/inumstrcmp.c &&
- X/* inumstrcmp.c */
- X/********************************************
- X* alphanumeric comparison of two strings
- X* Istvan Mohos, 1987 --- in the Public Domain
- X********************************************/
- X
- X#include "i.h"
- X
- X#define PTR1GREATER 1
- X#define PTR1PTR2EQUAL 0
- X#define PTR2GREATER -1
- X
- Xint
- Xinumstrcmp (ptr1, ptr2)
- Xregister char *ptr1, *ptr2;
- X{
- X register int num1, num2;
- X
- X if (NULCHARP (ptr1) || NULCHARP (ptr2))
- X return (ierror ("inumstrcmp: NULL parameter"));
- X
- X for (;;) {
- X if (*ptr1 == '\0') /* if ptr1 is null */
- X if (*ptr2 == '\0')
- X return (PTR1PTR2EQUAL);
- X else
- X return (PTR2GREATER);
- X
- X if (*ptr2 == '\0') /* if ptr2 is null */
- X return (PTR1GREATER);
- X
- X if (*ptr1 < '0' || *ptr1 > '9') {/* if ptr1 is alphabetic */
- X if (*ptr1 > *ptr2)
- X return (PTR1GREATER);
- X if (*ptr1 < *ptr2)
- X return (PTR2GREATER);
- X ptr1++, ptr2++;
- X continue; /* ptr1,ptr2 identical alpha */
- X }
- X
- X if (*ptr2 < '0' || *ptr2 > '9') {/* ptr1 numeral, ptr2 alpha */
- X if (*ptr1 > *ptr2)
- X return (PTR1GREATER);
- X return (PTR2GREATER);
- X }
- X
- X if ((num1 = atoi(ptr1)) > (num2 = atoi(ptr2)))
- X return (PTR1GREATER);
- X if (num1 < num2)
- X return (PTR2GREATER);
- X
- X /* identical numbers still could be weird: '0012' vs '12' */
- X for (++ptr1; *ptr1 >= '0' && *ptr1 <= '9'; ptr1++);
- X for (++ptr2; *ptr2 >= '0' && *ptr2 <= '9'; ptr2++);
- X }
- X}
- X
- SHAR_EOF
- $TOUCH -am 0605074590 i/inumstrcmp.c &&
- chmod 0644 i/inumstrcmp.c ||
- echo "restore of i/inumstrcmp.c failed"
- set `wc -c i/inumstrcmp.c`;Wc_c=$1
- if test "$Wc_c" != "1389"; then
- echo original size 1389, current size $Wc_c
- fi
- # ============= i/ioctal.c ==============
- echo "x - extracting i/ioctal.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/ioctal.c &&
- X/* ioctal.c */
- X/********************************************
- X* convert octal digit string to int
- X* Istvan Mohos, 1990 --- in the Public Domain
- X*********************************************/
- X
- X#include "i.h"
- X
- Xint
- Xioctal (ptr)
- Xregister char *ptr;
- X{
- X register int val = 0;
- X
- X if (NULCHARP(ptr))
- X return (ierror ("ioctal: invalid pointer"));
- X
- X for (--ptr; *++ptr && ((*ptr>='0' && *ptr<='7') || WHITE(*ptr));)
- X if (!WHITE(*ptr))
- X val <<= 3, val += *ptr - '0';
- X return (val);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/ioctal.c &&
- chmod 0644 i/ioctal.c ||
- echo "restore of i/ioctal.c failed"
- set `wc -c i/ioctal.c`;Wc_c=$1
- if test "$Wc_c" != "475"; then
- echo original size 475, current size $Wc_c
- fi
- # ============= i/iopt.c ==============
- echo "x - extracting i/iopt.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/iopt.c &&
- X/* iopt.c */
- X/*********************************************
- X* command line option manager
- X* Istvan Mohos, 1987 --- in the Public Domain
- X*********************************************/
- X
- X#include "i.h"
- X
- Xint
- Xiopt (ptr)
- Xchar ***ptr;
- X{
- X register char *rp;
- X static char **olist;
- X static int first = 1;
- X int optlen;
- X
- X if (first) {
- X olist = *ptr;
- X first = 0;
- X }
- X
- X rp = *olist;
- X if (rp == NULL || *rp != '-') { /* no more options */
- X *ptr = olist; /* set to first non-option */
- X first = 1; /* automatically re-init */
- X return (0);
- X }
- X
- X optlen = strlen (rp);
- X if (optlen > 2) { /* flag, value combined */
- X rp += 2;
- X *olist = rp; /* right past '-c' flag */
- X *ptr = olist;
- X ++olist; /* pre-increment for next time */
- X return (*--rp);
- X }
- X
- X if (optlen == 1) { /* '-' by itself */
- X *ptr = olist;
- X ++olist; /* pre-increment for next time */
- X return (*rp);
- X }
- X
- X /* else (optlen == 2): normal '-c' flag */
- X ++rp;
- X ++olist;
- X if (*olist == NULL || **olist == 0) { /* no option value */
- X --olist;
- X *ptr = olist; /* cough up entire option flag */
- X first = 1; /* automatically re-init */
- X return (0);
- X }
- X
- X *ptr = olist;
- X ++olist; /* pre-increment for next time */
- X return (*rp);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/iopt.c &&
- chmod 0644 i/iopt.c ||
- echo "restore of i/iopt.c failed"
- set `wc -c i/iopt.c`;Wc_c=$1
- if test "$Wc_c" != "1339"; then
- echo original size 1339, current size $Wc_c
- fi
- # ============= i/iread.c ==============
- echo "x - extracting i/iread.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/iread.c &&
- X/* iread.c */
- X/*************************************************
- X* read file into malloc'd buffer, return file size
- X* Istvan Mohos, 1987 --- in the Public Domain
- X**************************************************/
- X
- X#include "i.h"
- X
- Xint
- Xiread (fname, mallocp)
- Xchar *fname;
- Xchar **mallocp;
- X{
- X struct stat sbuf;
- X int checkval, fd;
- X int count;
- X
- X if (BADCHARP (fname))
- X return (ierror ("iread: invalid file name"));
- X
- X if (mallocp == (char **) NULL) {
- X if (access (fname, R_OK) == -1)
- X return (-1); /* can't read it */
- X return (0);
- X }
- X
- X if ((fd = open (fname, 0)) == -1)
- X return (ierror ("iread: no file access"));
- X
- X if ((checkval = fstat (fd, &sbuf)) == -1)
- X return (ierror ("iread: fstat read error"));
- X
- X if ((count = (int)sbuf.st_size) == 0)
- X return (ierror ("iread: zero length file"));
- X
- X if (NULCHARP (*mallocp = malloc ((unsigned int) count+1)))
- X return (ierror ("iread: can't allocate read buffer"));
- X
- X if ((checkval = read (fd, *mallocp, count)) != count) {
- X sprintf (ierbuf+200,
- X "iread: expected: %d, read: %d", count, checkval);
- X return (ierror (ierbuf+200));
- X }
- X close (fd);
- X *(*mallocp + count) = 0;
- X return (checkval);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/iread.c &&
- chmod 0644 i/iread.c ||
- echo "restore of i/iread.c failed"
- set `wc -c i/iread.c`;Wc_c=$1
- if test "$Wc_c" != "1141"; then
- echo original size 1141, current size $Wc_c
- fi
- # ============= i/irotate.c ==============
- echo "x - extracting i/irotate.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/irotate.c &&
- X/* irotate.c */
- X/********************************************
- X* rotate passed text in new buffer
- X* Istvan Mohos, 1987 --- in the Public Domain
- X*********************************************/
- X
- X#include "i.h"
- X
- X#define IROTR 1 /* rotate 90 deg. to right */
- X#define IROTL -1 /* rotate 90 deg. to left */
- X#define IROTOR 3 /* rotate 180 deg. over and 90 deg. to right */
- X#define IROTOL -3 /* rotate 180 deg. over and 90 deg. to left */
- X
- Xint
- Xirotate (start, llength, lcount, mallocp, type)
- Xchar *start, **mallocp;
- Xint llength, lcount;
- Xint type;
- X{
- X register char *from, *to;
- X int rotsiz;
- X register int ri, rj;
- X
- X if (NULCHARP (start))
- X return (ierror ("irotate: null buffer"));
- X
- X if (llength < 1 || lcount < 1)
- X return(ierror("rotate: bad dimensions"));
- X
- X rotsiz = (lcount + 1) * llength;
- X if (NULCHARP(*mallocp = malloc((unsigned int)rotsiz + 1)))
- X return(ierror("irotate: can't allocate rotor buffer"));
- X to = *mallocp;
- X *(*mallocp + rotsiz) = 0;
- X
- X switch (type) {
- X case IROTR:
- X default:
- X for (rj = 0; rj < llength; rj++) {
- X from = start + ((lcount-1) * llength) + rj;
- X for (ri = 0; ri++ < lcount; from -= llength)
- X *to++ = *from;
- X *to++ = '\n';
- X }
- X break;
- X
- X case IROTOR:
- X for (rj = 0; rj < llength; rj++) {
- X from = start + rj;
- X for (ri = 0; ri++ < lcount; from += llength)
- X *to++ = *from;
- X *to++ = '\n';
- X }
- X break;
- X
- X case IROTOL:
- X for (rj = llength; --rj >= 0; ) {
- X from = start + ((lcount -1) * llength) + rj;
- X for (ri = 0; ri++ < lcount; from -= llength)
- X *to++ = *from;
- X *to++ = '\n';
- X }
- X break;
- X
- X case IROTL:
- X for (rj = llength; --rj >= 0; ) {
- X from = start + rj;
- X for (ri = 0; ri++ < lcount; from += llength)
- X *to++ = *from;
- X *to++ = '\n';
- X }
- X break;
- X
- X }
- X
- X return (rotsiz);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/irotate.c &&
- chmod 0644 i/irotate.c ||
- echo "restore of i/irotate.c failed"
- set `wc -c i/irotate.c`;Wc_c=$1
- if test "$Wc_c" != "1778"; then
- echo original size 1778, current size $Wc_c
- fi
- # ============= i/iround.c ==============
- echo "x - extracting i/iround.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/iround.c &&
- X/* iround.c */
- X/****************************************************************
- X* suppress trailing zeros or round to a given digit of a fraction
- X* Istvan Mohos, 1987 --- in the Public Domain
- X*****************************************************************/
- X
- X#include "i.h"
- X
- Xint
- Xiround (start, end, maxfrac)
- Xchar *start;
- Xchar *end;
- Xint maxfrac;
- X{
- X register char *jp; /* scratch pointer */
- X register char *dp; /* pointing to decimal point */
- X register char *hp; /* pointing to first digit of string */
- X register char *mf; /* pointing to specified fraction end */
- X register char *fin; /* last digit of fraction */
- X int carry;
- X int intsiz;
- X
- X if (NULCHARP (start))
- X return (ierror ("iround: null buffer"));
- X ITOEND;
- X if (end == start)
- X return (ierror ("iround: zero-size buffer"));
- X
- X /* Move from start, over any white spaces, a single + or - sign,
- X more white spaces, to the leftmost digit, then to decimal point,
- X then to the last digit of the decimal fraction.
- X */
- X for (hp = start-1; ++hp < end && WHITE(*hp););
- X if (hp == end)
- X return (0);
- X if (*hp == '+' || *hp == '-') {
- X for (; ++hp < end && WHITE(*hp););
- X if (hp == end)
- X return (0);
- X }
- X if (*hp != '.' && (*hp < '0' || *hp > '9'))
- X return (0);
- X for (dp = hp-1; ++dp<end && *dp!='.' && *dp>='0' && *dp<='9';);
- X if (dp == end || *dp != '.')
- X return (0);
- X intsiz = dp - hp;
- X for (fin = dp; ++fin<end && *fin>='0' && *fin<='9';);
- X
- X /* Stopped on the byte past the last digit of the string;
- X null it if there is enough space, then move back to last digit.
- X */
- X if (fin < end)
- X *fin = NUL;
- X --fin;
- X
- X /* any negative int passed to null-out trailing '0' digits */
- X if (maxfrac < 0) {
- X for (++fin; *--fin == '0'; *fin = NUL);
- X if (fin == dp)
- X (intsiz) ? (*fin-- = NUL) : (*fin = '0');
- X return (fin+1 - start);
- X }
- X
- X if ((mf = dp+maxfrac) >= fin) { /* nothing to do */
- X if (fin == dp)
- X (intsiz) ? (*fin-- = NUL) : (*fin = '0');
- X return (fin+1 - start);
- X }
- X
- X /* generate a carry, then null out the byte past maxfrac */
- X (*++mf >= '5') ? (carry = 1) : (carry = 0);
- X if (end > mf+1) /* need next byte too if string expands */
- X *(mf+1) = NUL;
- X *mf-- = NUL;
- X
- X /* If "round to int" was specified, loose the decimal point.
- X But if there were no int digits given, a number has to be
- X created by substituting a '0' in place of the dp.
- X */
- X if (!maxfrac)
- X (intsiz) ? (*mf-- = NUL) : (*mf = '0');
- X
- X if (!carry) /* truncated string otherwise unchanged */
- X return (mf+1 - start);
- X
- X if (*mf < '9') { /* last digit of truncated string incremented */
- X ++(*mf);
- X return (mf+1 - start);
- X }
- X
- X /* By this time, we have a carry from the lost fractional digits,
- X and the last digit of the existing string is a '9'.
- X The potential combination of (maxfrac == 0, intsiz == 0) is
- X no longer a possibility (the remaining string is at worst a
- X fraction without original int digits, or an original int
- X without a fraction). In the more general "int.fraction" case,
- X homogenize the string by shifting the "int" part right 1 byte.
- X */
- X if (intsiz)
- X ibcopy (hp+1, hp, intsiz);
- X ++hp;
- X if (!maxfrac)
- X ++mf;
- X
- X /*_______________ generic: ______ !intsiz: _____ !maxfrac:
- X | mf mf mf
- X | hp | hp | hp|
- X | | | | | | |
- X | v v v v v v
- X | before ibcopy 7.49 .749 749$
- X | after ibcopy 7749 .749 7749
- X | after ^ ^ ^ ^ ^ ^
- X | ++hp,++mf | | | | | |
- X | hp mf hp mf hp mf
- X |________________________________________________________*/
- X
- X /* bubble up nines backward from last digit */
- X for (jp = mf, *mf = '0'; --jp >= hp; ) {
- X if (*jp == '9')
- X *jp = '0';
- X else {
- X ++(*jp);
- X break;
- X }
- X }
- X
- X /* if new '1' digit at front, shift fractional part to right */
- X if (jp < hp) {
- X *jp = '1';
- X if (maxfrac) {
- X ibcopy (dp+2, dp+1, mf++ -dp);
- X *(dp+1) = '.';
- X }
- X /*
- X | original 9.99 .999 999$
- X | at int shift 9999 .999 9999
- X | after bubble 1000 1000 1000
- X | at frac shift 10.00 1.000 1000
- X | ^ ^ ^ ^ ^ ^
- X | | | | | | |
- X | hp mf hp mf hp mf
- X |________________________________________________________*/
- X return (mf+1 - start);
- X }
- X
- X /* didn't add new digit, shift integer part back to left */
- X ibcopy (hp-1, hp, intsiz);
- X (maxfrac) ? (*dp = '.') : (*mf-- = NUL);
- X
- X /*
- X | original 7.49 .749 749$
- X | at int shift 7749 .749 7749
- X | after bubble 7750 .750 7750
- X | at left shift 7750 .750 7500
- X | restore dp 7.50 .750 750$
- X | ^ ^ ^ ^ ^^^
- X | | | | | |||
- X | hp mf hp mf hp|mf
- X | mf
- X |________________________________________________________*/
- X
- X return (mf+1 - start);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/iround.c &&
- chmod 0644 i/iround.c ||
- echo "restore of i/iround.c failed"
- set `wc -c i/iround.c`;Wc_c=$1
- if test "$Wc_c" != "5257"; then
- echo original size 5257, current size $Wc_c
- fi
- # ============= i/isearch.c ==============
- echo "x - extracting i/isearch.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/isearch.c &&
- X/* isearch.c */
- X/*********************************************
- X* binary search in array of character pointers
- X* Istvan Mohos, 1987 --- in the Public Domain
- X**********************************************/
- X
- X#include "i.h"
- X
- Xint
- Xisearch (comparee, wordlist, listcount)
- Xchar *comparee;
- Xchar *wordlist[];
- Xint listcount;
- X{
- X register int lo, hi;
- X register int m, mid;
- X int signific;
- X
- X if (BADCHARP (comparee))
- X return(ierror("isearch: invalid comparee"));
- X if (listcount < 1)
- X return (-1);
- X
- X signific = strlen(comparee);
- X for (lo = 0, hi = listcount -1; lo <= hi;) {
- X mid = (lo + hi) >> 1;
- X if ((m = strncmp(comparee, wordlist[mid], signific)) < 0)
- X hi = mid -1;
- X else if (m > 0)
- X lo = mid +1;
- X else
- X return(mid);
- X }
- X return (-1);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/isearch.c &&
- chmod 0644 i/isearch.c ||
- echo "restore of i/isearch.c failed"
- set `wc -c i/isearch.c`;Wc_c=$1
- if test "$Wc_c" != "737"; then
- echo original size 737, current size $Wc_c
- fi
- # ============= i/isort.c ==============
- echo "x - extracting i/isort.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/isort.c &&
- X/* isort.c */
- X/********************************************
- X* easier-to-use str ptr sort
- X* Istvan Mohos, 1987 --- in the Public Domain
- X*********************************************/
- X
- X#include "i.h"
- X
- Xvoid
- Xisort (ptr, itemcount)
- Xchar *ptr[];
- Xint itemcount;
- X{
- X int ri, rj;
- X register char *tp, **mp, **np;
- X
- X if (itemcount < 2)
- X return; /* already sorted */
- X mp = np = ptr;
- X if (itemcount == 2) { /* just exchange if not in order */
- X if (strcmp(*++np, *mp) < 0) {
- X tp = *mp;
- X *mp = *np;
- X *np = tp;
- X }
- X }
- X else {
- X part(mp, itemcount, &ri, &rj);
- X isort(mp, rj+1);
- X isort(mp+ri, itemcount-ri);
- X }
- X}
- X
- Xstatic
- Xpart (ptr, itemcount, pi, pj)
- Xchar *ptr[];
- Xint itemcount;
- Xint *pi, *pj;
- X{
- X char *ref, *tp;
- X register char **mp;
- X register int mi, mj;
- X
- X mi = 0;
- X mj = itemcount-1;
- X mp = ptr;
- X for (ref = *(mp + mj/2); mi <= mj;) {
- X for (;strcmp(*(mp+mi), ref) < 0; mi++);
- X for (;strcmp(*(mp+mj), ref) > 0; mj--);
- X if (mi <= mj) {
- X tp = *(mp+mi);
- X *(mp+mi++) = *(mp+mj);
- X *(mp+mj--) = tp;
- X }
- X }
- X *pi = mi;
- X *pj = mj;
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/isort.c &&
- chmod 0644 i/isort.c ||
- echo "restore of i/isort.c failed"
- set `wc -c i/isort.c`;Wc_c=$1
- if test "$Wc_c" != "1021"; then
- echo original size 1021, current size $Wc_c
- fi
- # ============= i/istartl.c ==============
- echo "x - extracting i/istartl.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/istartl.c &&
- X/* istartl.c */
- X/******************************************************
- X* match word to first non-white word of lines in buffer
- X* Istvan Mohos, 1987 --- in the Public Domain
- X******************************************************/
- X
- X#include "i.h"
- X
- Xchar *
- Xistartl (start, end, word)
- Xregister char *start;
- Xchar *end, *word;
- X{
- X register char *off, c;
- X int length;
- X
- X if (NULCHARP (start)) {
- X ierror ("istartl: null buffer");
- X return (NULL);
- X }
- X ITOEND;
- X
- X if (BADCHARP(word)) {
- X ierror ("istartl: invalid word");
- X return (NULL);
- X }
- X
- X for (off = word; *off++;);
- X length = --off - word;
- X c = *word;
- X off = end;
- X
- X for (; start < off;) {
- X /* stop at first non-white character */
- X for (;WHITE(*start);)
- X if (++start == off)
- X return (NULL);
- X
- X if ((*start == c) && (start+length <= off) &&
- X (strncmp(start, word, length) == 0))
- X return (start); /* found word searched for */
- X
- X /* proceed to next newline */
- X for (;*start != '\n';)
- X if (++start == off)
- X return (NULL);
- X }
- X return (NULL);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/istartl.c &&
- chmod 0644 i/istartl.c ||
- echo "restore of i/istartl.c failed"
- set `wc -c i/istartl.c`;Wc_c=$1
- if test "$Wc_c" != "1006"; then
- echo original size 1006, current size $Wc_c
- fi
- # ============= i/istripcom.c ==============
- echo "x - extracting i/istripcom.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/istripcom.c &&
- X/* istripcom.c */
- X/**************************************************
- X: substitute spaces for comments, delimiters in buf
- X: Istvan Mohos, 1987 --- in the Public Domain
- X**************************************************/
- X
- X#include "i.h"
- X
- Xint
- Xistripcom (start, end, lcom, rcom)
- Xregister char *start;
- Xregister char *end;
- Xchar *lcom, *rcom;
- X{
- X register char *rp;
- X int lc, rc;
- X int ri, miss;
- X int llen, rlen;
- X int select = 0;
- X int count = 0;
- X int nest = 1;
- X
- X if (NULCHARP(start))
- X return(ierror("istripcom: invalid buffer"));
- X ITOEND;
- X if (BADCHARP(lcom))
- X return(ierror("istripcom: zero length start comment"));
- X if (BADCHARP(rcom))
- X return(ierror("istripcom: zero length end comment"));
- X if (*lcom < 32)
- X return(ierror("istripcom: invalid start comment"));
- X
- X if ((llen = strlen(lcom)) == 1) {
- X lc = *lcom;
- X select = 10;
- X }
- X else
- X select = 20;
- X
- X switch(*rcom) {
- X case '\n':
- X break;
- X default:
- X if ((rlen = strlen(rcom)) == 1) {
- X rc = *rcom;
- X select += 1;
- X }
- X else
- X select += 2;
- X /* C comments receive special handling */
- X if (!(strcmp (lcom, "/*") || strcmp (rcom, "*/")))
- X ++select;
- X else if (strcmp(lcom, rcom) == 0)
- X nest = 0;
- X break;
- X }
- X
- X rp = start;
- X switch (select) {
- X default:
- X return(ierror("istripcom: invalid comment specs"));
- X
- X case 10: /* lcom is single letter, rcom \n */
- X for (; rp < end; rp++) {
- X if (*rp == lc) {
- X ++count;
- X for (*rp++ = ' ';rp<end && *rp != '\n';*rp++ = ' ');
- X }
- X }
- X break;
- X
- X case 11: /* lcom and rcom are single letters */
- X for (; rp < end; rp++) {
- X if (*rp == lc) {
- X ++count;
- X for (*rp++ = ' ';rp<end && *rp != rc;) {
- X if (nest && *rp == lc)
- X count += istripcom(rp, end, lcom, rcom);
- X *rp++ = ' ';
- X }
- X if (*rp == rc && rc != '\n')
- X *rp = ' '; /* erase right delimiter */
- X }
- X }
- X break;
- X
- X case 12: /* lcom single letter, rcom is string */
- X for (; rp < end; rp++) {
- X if (*rp == lc) {
- X ++count;
- X *rp++ = ' ';
- X
- X for (; end-rp >= rlen &&
- X (miss = strncmp (rp, rcom, rlen)); *rp++ = ' ')
- X if (nest && *rp == lc)
- X count += istripcom (rp, end, lcom, rcom);
- X
- X if (!miss) {
- X for (ri = rlen; --ri; *rp++ = ' ');
- X *rp = ' '; /* erase bytes of delimiter */
- X }
- X else { /* not enough space for delimiter */
- X for (ri = rlen; --ri; *rp++ = ' ');
- X --rp;
- X }
- X }
- X }
- X break;
- X
- X case 20: /* lcom is string, rcom is \n */
- X for (; rp < end; rp++) {
- X if (end-rp >= llen &&
- X (miss = strncmp (rp, lcom, llen)) == 0) {
- X ++count;
- X for (ri = llen; --ri >= 0; *rp++ = ' ');
- X for (;rp < end && *rp != '\n'; *rp++ = ' ');
- X }
- X }
- X break;
- X
- X case 21: /* lcom is string, rcom single char */
- X for (; rp < end; rp++) {
- X if (end-rp >= llen &&
- X (miss = strncmp (rp, lcom, llen)) == 0) {
- X ++count;
- X for (ri = llen; --ri >= 0; *rp++ = ' ');
- X
- X for (;rp < end && *rp != rc; *rp++ = ' ')
- X if (nest && end-rp >= llen &&
- X strncmp (rp, lcom, llen) == 0)
- X count += istripcom( rp, end, lcom, rcom);
- X
- X if (*rp == rc && rc != '\n')
- X *rp = ' '; /* erase right delimiter */
- X }
- X }
- X break;
- X
- X case 22: /* lcom is string, rcom is string */
- X for (; rp < end; rp++) {
- X if (end-rp >= llen &&
- X (miss = strncmp (rp, lcom, llen)) == 0) {
- X ++count;
- X for (ri = llen; --ri >= 0; *rp++ = ' ');
- X
- X for (; end-rp >= rlen &&
- X (miss = strncmp (rp, rcom, rlen)); *rp++ = ' ')
- X if (nest && end-rp >= llen &&
- X strncmp (rp, lcom, llen) == 0)
- X count += istripcom(rp, end, lcom, rcom);
- X
- X if (!miss) {
- X for (ri = rlen; --ri; *rp++ = ' ');
- X *rp = ' '; /* erase last bytes of delim */
- X }
- X else { /* not enough space for delimiter */
- X for (ri = rlen; --ri; *rp++ = ' ');
- X --rp;
- X }
- X }
- X }
- X break;
- X
- X case 23: /* C comments */
- X for (; rp < end; rp++) {
- X
- X /* skip character constants */
- X if (*rp == '\\') { /* skip next byte */
- X if (++rp < end)
- X ++rp;
- X continue;
- X }
- X
- X /* skip string constants */
- X if (*rp == '\'') {
- X escape1:
- X while (++rp != end && *rp != '\'');
- X if (rp == end)
- X continue;
- X if (*(rp-1) == '\\') /* escaped quote */
- X goto escape1;
- X ++rp;
- X continue;
- X }
- X if (*rp == '"') {
- X escape2:
- X while (++rp != end && *rp != '"');
- X if (rp == end)
- X continue;
- X if (*(rp-1) == '\\') /* escaped quote */
- X goto escape2;
- X ++rp;
- X continue;
- X }
- X
- X if (end-rp >= llen &&
- X (miss = strncmp (rp, lcom, llen)) == 0) {
- X ++count;
- X *rp++ = ' ';
- X *rp++ = ' ';
- X for (; end-rp >= rlen &&
- X (miss = strncmp (rp, rcom, rlen)); *rp++ = ' ');
- X if (!miss) {
- X *rp++ = ' ';
- X *rp = ' ';
- X }
- X else
- X *rp = ' '; /* no delimiter at end */
- X }
- X }
- X break;
- X }
- X return(count);
- X }
- SHAR_EOF
- $TOUCH -am 0605074590 i/istripcom.c &&
- chmod 0644 i/istripcom.c ||
- echo "restore of i/istripcom.c failed"
- set `wc -c i/istripcom.c`;Wc_c=$1
- if test "$Wc_c" != "4802"; then
- echo original size 4802, current size $Wc_c
- fi
- # ============= i/istripdq.c ==============
- echo "x - extracting i/istripdq.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/istripdq.c &&
- X/* istripdq.c */
- X/********************************************
- X: substitute spaces for quoted strings in buf
- X: Istvan Mohos, 1987 --- in the Public Domain
- X********************************************/
- X
- X#include "i.h"
- X
- Xint
- Xistripdq (start, end)
- Xregister char *start;
- Xregister char *end;
- X{
- X register char *rp;
- X int count = 0;
- X
- X if (NULCHARP (start))
- X return (ierror ("istripdq: null buffer"));
- X ITOEND;
- X
- X for (rp = start; rp < end; rp++) {
- X if ((rp > start) &&
- X ((*rp == '"' && *(rp-1) == '\\') ||
- X (*rp == '"' && *(rp-1) == '\'' && *(rp+1) == '\'')))
- X continue;
- X
- X if (*rp == '"') { /* found left delimiter */
- X ++count;
- X for (rp++; rp < end; rp++) { /* blank escaped dqs, etc. */
- X if ((*rp == '"' && *(rp-1) == '\\') ||
- X (*rp == '"' && *(rp-1) == '\'' && *(rp+1) == '\''))
- X *rp = ' ';
- X if (*rp == '"')
- X break; /* found right delimiter */
- X *rp = ' ';
- X }
- X }
- X }
- X
- X return(count);
- X }
- SHAR_EOF
- $TOUCH -am 0605074590 i/istripdq.c &&
- chmod 0644 i/istripdq.c ||
- echo "restore of i/istripdq.c failed"
- set `wc -c i/istripdq.c`;Wc_c=$1
- if test "$Wc_c" != "916"; then
- echo original size 916, current size $Wc_c
- fi
- # ============= i/istripsq.c ==============
- echo "x - extracting i/istripsq.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/istripsq.c &&
- X/* istripsq.c */
- X/********************************************
- X: substitute spaces for single quoted strings
- X: Istvan Mohos, 1987 --- in the Public Domain
- X********************************************/
- X
- X#include "i.h"
- X
- Xint
- Xistripsq (start, end)
- Xregister char *start;
- Xregister char *end;
- X{
- X register char *rp;
- X int count = 0;
- X
- X if (NULCHARP (start))
- X return (ierror ("istripsq: null buffer"));
- X ITOEND;
- X
- X for (rp = start; rp < end; rp++) {
- X if ((rp > start) &&
- X ((*rp == '\'' && *(rp-1) == '\\')))
- X continue;
- X
- X if (*rp == '\'') { /* found left delimiter */
- X ++count;
- X for (rp++; rp < end; rp++) { /* blank escaped sqes, etc. */
- X if ((*rp == '\'' && *(rp-1) == '\\'))
- X *rp = ' ';
- X if (*rp == '\'')
- X break; /* found right delimiter */
- X *rp = ' ';
- X }
- X }
- X }
- X
- X return(count);
- X }
- SHAR_EOF
- $TOUCH -am 0605074590 i/istripsq.c &&
- chmod 0644 i/istripsq.c ||
- echo "restore of i/istripsq.c failed"
- set `wc -c i/istripsq.c`;Wc_c=$1
- if test "$Wc_c" != "805"; then
- echo original size 805, current size $Wc_c
- fi
- # ============= i/istripstr.c ==============
- echo "x - extracting i/istripstr.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/istripstr.c &&
- X/* istripstr.c */
- X/**************************************************
- X: blank occurrences of string in buffer with spaces
- X: Istvan Mohos, 1987 --- in the Public Domain
- X**************************************************/
- X
- X#include "i.h"
- X
- Xint
- Xistripstr (start, end, string)
- Xregister char *start;
- Xchar *end, *string;
- X{
- X register char *off, c;
- X char *anchor;
- X int count = 0;
- X int length;
- X
- X if (NULCHARP (start))
- X return (ierror ("istripstr: null buffer"));
- X ITOEND;
- X
- X if (BADCHARP(string))
- X return(ierror("istripstr: invalid string"));
- X
- X for (off = string; *off++;);
- X length = --off - string;
- X c = *string;
- X off = end;
- X
- X for(; start < off; start++) {
- X if ((*start == c) && ((anchor = start+length) <= off) &&
- X (strncmp(start, string, length) == 0)) {
- X ++count;
- X for(; start < anchor; *start++ = ' ');
- X }
- X }
- X return(count);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/istripstr.c &&
- chmod 0644 i/istripstr.c ||
- echo "restore of i/istripstr.c failed"
- set `wc -c i/istripstr.c`;Wc_c=$1
- if test "$Wc_c" != "831"; then
- echo original size 831, current size $Wc_c
- fi
- # ============= i/iswap.c ==============
- echo "x - extracting i/iswap.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/iswap.c &&
- X/* iswap.c */
- X/********************************************
- X* change one string to another in buffer
- X* Istvan Mohos, 1987 --- in the Public Domain
- X*********************************************/
- X
- X#include "i.h"
- X
- Xint
- Xiswap (start, end, from, to)
- Xchar *start, *end, *from, *to;
- X{
- X register char *inp, *off;
- X char *mark, ch;
- X int frsiz, tosiz;
- X int count = 0;
- X
- X if (NULCHARP (start))
- X return (ierror ("iswap: null buffer"));
- X ITOEND;
- X
- X if (BADCHARP(from))
- X return(ierror("iswap: bad source pattern"));
- X if (BADCHARP(to))
- X return(ierror("iswap: bad target pattern"));
- X
- X for (off = from; *off++;);
- X frsiz = --off - from;
- X
- X for (off = to; *off++;);
- X tosiz = --off - to;
- X
- X off = end;
- X if ((off -= frsiz) <= start)
- X return(0);
- X for (inp = start; inp < off; inp++) {
- X if (*inp == *from && ibcmp(inp, from, frsiz) == 0) {
- X mark = inp;
- X inp += tosiz;
- X ch = *inp;
- X strcpy (mark, to);
- X *inp-- = ch;
- X ++count;
- X }
- X }
- X return(count);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/iswap.c &&
- chmod 0644 i/iswap.c ||
- echo "restore of i/iswap.c failed"
- set `wc -c i/iswap.c`;Wc_c=$1
- if test "$Wc_c" != "937"; then
- echo original size 937, current size $Wc_c
- fi
- # ============= i/itexrect.c ==============
- echo "x - extracting i/itexrect.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/itexrect.c &&
- X/* itexrect.c */
- X/**********************************
- X* make rectangular array from lines
- X* Istvan Mohos, 1987 --- in the Public Domain
- X**********************************/
- X
- X#include "i.h"
- X
- Xint
- Xitexrect (start, end, mallocp, lcount)
- Xregister char *start, *end;
- Xchar **mallocp;
- Xint *lcount;
- X{
- X int linecount, longest;
- X char *to, *behind;
- X int length;
- X register int ri;
- X
- X if (NULCHARP (start))
- X return (ierror ("itexrect: null buffer"));
- X ITOEND;
- X
- X if (end - start < 1)
- X return(ierror("itexrect: empty source buffer"));
- X
- X longest = ilongest (start, end, &linecount);
- X if (longest == 0 || linecount == 0) {
- X *mallocp = NULL;
- X *lcount = 0;
- X return (0);
- X }
- X
- X if (NULCHARP(*mallocp = malloc((unsigned int)linecount * longest)))
- X return(ierror("itexrect: can't allocate *mallocp buffer"));
- X
- X /* space fill to max line length in *mallocp */
- X for (behind = start, to = *mallocp; start < end; start++) {
- X if (*start == '\n' || *start == '\0') {
- X length = start - behind;
- X behind = start + 1;
- X for (ri = longest - length; --ri >= 0; *to++ = ' ');
- X }
- X else
- X *to++ = *start;
- X }
- X *lcount = linecount;
- X return (longest);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/itexrect.c &&
- chmod 0644 i/itexrect.c ||
- echo "restore of i/itexrect.c failed"
- set `wc -c i/itexrect.c`;Wc_c=$1
- if test "$Wc_c" != "1123"; then
- echo original size 1123, current size $Wc_c
- fi
- # ============= i/itoday.c ==============
- echo "x - extracting i/itoday.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/itoday.c &&
- X/* itoday.c */
- X/*************************************************
- X* return integer value of current day, month, year
- X* Istvan Mohos, 1987 --- in the Public Domain
- X*************************************************/
- X
- X#include "i.h"
- X
- Xint
- Xitosec()
- X{
- X struct tm *ptr;
- X
- X ptr = _igetdate();
- X return (ptr->tm_sec);
- X}
- X
- Xint
- Xitomin()
- X{
- X struct tm *ptr;
- X
- X ptr = _igetdate();
- X return (ptr->tm_min);
- X}
- X
- Xint
- Xitohour()
- X{
- X struct tm *ptr;
- X
- X ptr = _igetdate();
- X return (ptr->tm_hour);
- X}
- X
- Xint
- Xitoday()
- X{
- X struct tm *ptr;
- X
- X ptr = _igetdate();
- X return (ptr->tm_mday);
- X}
- X
- Xint
- Xitomonth()
- X{
- X struct tm *ptr;
- X
- X ptr = _igetdate();
- X return (ptr->tm_mon + 1);
- X}
- X
- Xint
- Xitoyear()
- X{
- X struct tm *ptr;
- X
- X ptr = _igetdate();
- X return (ptr->tm_year + 1900);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/itoday.c &&
- chmod 0644 i/itoday.c ||
- echo "restore of i/itoday.c failed"
- set `wc -c i/itoday.c`;Wc_c=$1
- if test "$Wc_c" != "722"; then
- echo original size 722, current size $Wc_c
- fi
- # ============= i/itok.c ==============
- echo "x - extracting i/itok.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/itok.c &&
- X/* itok.c */
- X/**********************************************
- X* bidir token recognizer, can handle null bytes
- X* Istvan Mohos, 1987 --- in the Public offomain
- X***********************************************/
- X
- X#include "i.h"
- X
- X#define ISETEND if (end == (char *)NULL)\
- X for(off = start; *off; off++);\
- X else if (start > end) {\
- X for(off = start; *off; off++)\
- X if (*off == '\n') { ++off; break; }\
- X } else off = end;\
- X end = off
- X
- Xint
- Xitok (context, start, end, result)
- Xint context;
- Xregister char *start;
- Xchar *end, **result;
- X{
- X register char *off, *past_dlm;
- X int dlmflag, tokflag;
- X static char *anchor, *P;
- X static char *pre, *buflim;
- X
- X if (NULCHARP (start))
- X return (ierror ("itok: null 'start' buffer"));
- X
- X switch (context) {
- X case INITOKF: /* first call, forward */
- X case INITOKR: /* first call, backwards */
- X ISETEND;
- X buflim = off;
- X (context == INITOKF) ? (P = start) : (P = off -1);
- X pre = start -1;
- X return(off - start);
- X
- X case ITOKF: /* subsequent calls, forward */
- X default:
- X if (P == pre)
- X ++P;
- X ISETEND;
- X past_dlm = off;
- X
- X /* move to 1st non-delimiter byte */
- X for (tokflag = 0; P < buflim;) {
- X for (dlmflag = 0, off = start; off < past_dlm;)
- X if (dlmflag = (*off++ == *P)) {
- X P++;
- X break; /* do not test other separators */
- X }
- X if (tokflag = !dlmflag) /* found first byte of token */
- X break;
- X }
- X
- X if (!tokflag) {
- X *result = NULL;
- X return(0);
- X }
- X
- X /* move past token */
- X for (anchor = P; P < buflim; P++)
- X for (off = start; off < past_dlm;)
- X if (*off++ == *P) {
- X *result = anchor;
- X return(P - anchor); /* most return from here */
- X }
- X
- X *result = anchor; /* but no space for delimiter */
- X return(buflim - anchor);
- X
- X case ITOKR: /* subsequent calls, backwards */
- X if (P == buflim)
- X --P;
- X ISETEND;
- X past_dlm = off;
- X
- X /* move backwards to 1st non-delimiter */
- X for (tokflag = 0; P > pre;) {
- X for (dlmflag = 0, off = start; off < past_dlm;)
- X if (dlmflag = (*off++ == *P)) {
- X P--;
- X break; /* do not test other separators */
- X }
- X if (tokflag = !dlmflag) /* rightmost byte of token */
- X break;
- X }
- X
- X if (!tokflag) {
- X *result = NULL;
- X return(0);
- X }
- X
- X /* move to left of token */
- X for (anchor = P; P > pre; P--)
- X for (off = start; off < past_dlm;)
- X if (*off++ == *P) {
- X *result = P +1;
- X return(anchor - P); /* most return from here */
- X }
- X
- X *result = P + 1; /* but no delimiter at the beginning */
- X return(anchor - pre);
- X }
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/itok.c &&
- chmod 0644 i/itok.c ||
- echo "restore of i/itok.c failed"
- set `wc -c i/itok.c`;Wc_c=$1
- if test "$Wc_c" != "2546"; then
- echo original size 2546, current size $Wc_c
- fi
- # ============= i/itran.c ==============
- echo "x - extracting i/itran.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/itran.c &&
- X/* itran.c */
- X/********************************************
- X* change one char to another in buffer
- X* Istvan Mohos, 1987 --- in the Public Domain
- X********************************************/
- X
- X#include "i.h"
- X
- Xint
- Xitran (start, end, fromc, toc)
- Xregister char *start, *end, fromc, toc;
- X{
- X int count = 0;
- X
- X if (NULCHARP (start))
- X return (ierror ("itran: null buffer"));
- X ITOEND;
- X
- X for (; start < end; start++)
- X if (*start == fromc)
- X *start = toc, ++count;
- X return (count);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/itran.c &&
- chmod 0644 i/itran.c ||
- echo "restore of i/itran.c failed"
- set `wc -c i/itran.c`;Wc_c=$1
- if test "$Wc_c" != "475"; then
- echo original size 475, current size $Wc_c
- fi
- # ============= i/iuniq.c ==============
- echo "x - extracting i/iuniq.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/iuniq.c &&
- X/* iuniq.c */
- X/*************************************************
- X* return 1 if parameter is used for the first time
- X* Istvan Mohos, 1987 --- in the Public Domain
- X**************************************************/
- X
- X#include "i.h"
- X
- Xint
- Xiuniq (item)
- Xint item;
- X{
- X static int within = 0;
- X static char *mp = NULL;
- X
- X if (item < 0) {
- X if (mp != NULL) {
- X free(mp);
- X mp = NULL;
- X }
- X within = 0;
- X return(0);
- X }
- X if (item >= within) {
- X if (within)
- X return(-sys_nerr);
- X if ((mp = calloc((unsigned)item, sizeof(char))) == NULL) {
- X ierror("iuniq: calloc error");
- X return(-sys_nerr);
- X }
- X within = item;
- X return(0);
- X }
- X if (*(mp+item))
- X return(0);
- X *(mp+item) = 1;
- X return(1);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/iuniq.c &&
- chmod 0644 i/iuniq.c ||
- echo "restore of i/iuniq.c failed"
- set `wc -c i/iuniq.c`;Wc_c=$1
- if test "$Wc_c" != "683"; then
- echo original size 683, current size $Wc_c
- fi
- # ============= i/iuniqa.c ==============
- echo "x - extracting i/iuniqa.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/iuniqa.c &&
- X/* iuniqa.c */
- X/*************************************************
- X* return 1 if parameter is used for the first time
- X* Istvan Mohos, 1987 --- in the Public Domain
- X**************************************************/
- X
- X#include "i.h"
- X
- Xint
- Xiuniqa (item)
- Xint item;
- X{
- X static int within = 0;
- X static char *mp = NULL;
- X
- X if (item < 0) {
- X if (mp != NULL) {
- X free(mp);
- X mp = NULL;
- X }
- X within = 0;
- X return(0);
- X }
- X if (item >= within) {
- X if (within)
- X return(-sys_nerr);
- X if ((mp = calloc((unsigned)item, sizeof(char))) == NULL) {
- X ierror("iuniqa: calloc error");
- X return(-sys_nerr);
- X }
- X within = item;
- X return(0);
- X }
- X if (*(mp+item))
- X return(0);
- X *(mp+item) = 1;
- X return(1);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/iuniqa.c &&
- chmod 0644 i/iuniqa.c ||
- echo "restore of i/iuniqa.c failed"
- set `wc -c i/iuniqa.c`;Wc_c=$1
- if test "$Wc_c" != "686"; then
- echo original size 686, current size $Wc_c
- fi
- # ============= i/iupper.c ==============
- echo "x - extracting i/iupper.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/iupper.c &&
- X/* iupper.c */
- X/********************************************
- X* fast toupper string in buffer
- X* Istvan Mohos, 1987 --- in the Public Domain
- X*********************************************/
- X
- X#include "i.h"
- X#include "iupcas.h"
- X
- Xint
- Xiupper (start, end)
- Xregister char *start;
- Xchar *end;
- X{
- X register char *up, *off;
- X
- X if (NULCHARP (start))
- X return (ierror ("iupper: null buffer"));
- X ITOEND;
- X
- X off = end;
- X
- X for (up = upcas; --off >= start;)
- X *off = *(up + *off);
- X return(end - start);
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/iupper.c &&
- chmod 0644 i/iupper.c ||
- echo "restore of i/iupper.c failed"
- set `wc -c i/iupper.c`;Wc_c=$1
- if test "$Wc_c" != "480"; then
- echo original size 480, current size $Wc_c
- fi
- # ============= i/iwhich.c ==============
- echo "x - extracting i/iwhich.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > i/iwhich.c &&
- X/* iwhich.c */
- X/********************************************
- X* faster "which"
- X* Istvan Mohos, 1987 --- in the Public Domain
- X*********************************************/
- X
- X#include "i.h"
- X
- Xchar *
- Xiwhich (item, perm)
- Xchar *item;
- Xint perm;
- X{
- X char *nextptr, *path;
- X static char segment[256];
- X char *delim = " :";
- X register int siz;
- X
- X if (BADCHARP(item)) {
- X ierror("iwhich: invalid pointer");
- X return(NULL);
- X }
- X if (NULCHARP(ilast(item, '/'))) { /* path not given */
- X if ((path = getenv("PATH")) != NULL) { /* PATH exists */
- X ftok(INITOKF, path, inull (path));
- X for(;siz = ftok(ITOKF, delim, delim+2, &nextptr);) {
- X sprintf(segment, "%*.*s/%s",siz, siz, nextptr, item);
- X if (access(segment, perm) != -1)
- X return(segment);
- X }
- X }
- X return(NULL);
- X }
- X if (access(item, perm) != -1) /* else verify given path */
- X return(item);
- X return(NULL);
- X}
- X
- Xstatic
- Xint
- Xftok (context, head, Z, result)
- Xint context;
- Xchar *head, *Z, **result;
- X{
- X register char *rp, *past_dlm;
- X int dlmflag, tokflag;
- X static char *anchor, *P;
- X static char *pre, *off;
- X
- X switch (context) {
- X case INITOKF: /* first call, forward */
- X off = Z;
- X P = head;
- X pre = head -1;
- X return(off - head);
- X
- X case ITOKF: /* subsequent calls, forward */
- X default:
- X if (P == pre)
- X ++P;
- X past_dlm = Z;
- X
- X /* move to 1st non-delimiter byte */
- X for (tokflag = 0; P < off;) {
- X for (dlmflag = 0, rp = head; rp < past_dlm;)
- X if (dlmflag = (*rp++ == *P)) {
- X P++;
- X break; /* do not test other separators */
- X }
- X if (tokflag = !dlmflag) /* found first byte of token */
- X break;
- X }
- X
- X if (!tokflag) {
- X *result = NULL;
- X return(0);
- X }
- X
- X /* move past token */
- X for (anchor = P; P < off; P++)
- X for (rp = head; rp < past_dlm;)
- X if (*rp++ == *P) {
- X *result = anchor;
- X return(P - anchor); /* most return from here */
- X }
- X
- X *result = anchor; /* but no delimiter at the end */
- X return(off - anchor);
- X }
- X}
- SHAR_EOF
- $TOUCH -am 0605074590 i/iwhich.c &&
- chmod 0644 i/iwhich.c ||
- echo "restore of i/iwhich.c failed"
- set `wc -c i/iwhich.c`;Wc_c=$1
- if test "$Wc_c" != "1953"; then
- echo original size 1953, current size $Wc_c
- fi
- echo "End of part 2, continue with part 3"
- exit 0
- --
- Istvan Mohos
- ...uunet!pyrdc!pyrnj!hhb!istvan
- RACAL-REDAC/HHB 1000 Wyckoff Ave. Mahwah NJ 07430 201-848-8000
- ======================================================================
-