/* * Read patterns from file. */ void patfile(char *fn) { struct stat st; struct expr *e = NULL; char *cp; struct iblok *ip; size_t sz, len; int nl; if ((ip = ib_open(fn, 0)) == NULL || fstat(ip->ib_fd, &st) < 0) { fprintf(stderr, "%s: can't open %s\n", progname, fn); exit(2); } if (e0) { if (sus) for (e = e0; e->e_nxt; e = e->e_nxt); else e0 = NULL; } while (cp = NULL, sz = 0, (len = ib_getlin(ip, &cp, &sz, srealloc)) > 0) { if ((nl = cp[len - 1] == '\n') != 0) cp[len - 1] = '\0'; addpat(&e, cp, len - nl, nl); } ib_close(ip); }
static int input(int n) /* get input line and split into fields */ { register int i; wint_t wc; int m; char *bp; size_t length; long pc; if ((length = ib_getlin(f[n], &buf[n], &bufsize[n], srealloc)) == 0) return(-1); bp = buf[n]; pc = 0; for (i = 0; ; i++) { if (sep1 == ' ') /* strip multiples */ while (next(wc, bp, m), wc == sep1 || wc == sep2) bp += m; /* skip blanks */ else next(wc, bp, m); if (wc == '\n' || wc == '\0') break; setppi(n, pc++, bp); /* record beginning */ while (next(wc, bp, m), wc != sep1 && wc != '\n' && wc != sep2 && wc != '\0') bp += m; *bp++ = '\0'; /* mark end by overwriting blank */ /* fails badly if string doesn't have \n at end */ } if (pc == 0) setppi(n, pc++, ""); setppi(n, pc, 0); return(i); }