version 1.29, 2020/06/10 21:02:33 |
version 1.30, 2020/06/10 21:02:53 |
|
|
|
|
int readrec(char **pbuf, int *pbufsize, FILE *inf) /* read one record into buf */ |
int readrec(char **pbuf, int *pbufsize, FILE *inf) /* read one record into buf */ |
{ |
{ |
int sep, c; |
int sep, c, isrec; |
char *rr, *buf = *pbuf; |
char *rr, *buf = *pbuf; |
int bufsize = *pbufsize; |
int bufsize = *pbufsize; |
char *rs = getsval(rsloc); |
char *rs = getsval(rsloc); |
|
|
if ((sep = *rs) == 0) { |
if (*rs && rs[1]) { |
sep = '\n'; |
int found; |
while ((c=getc(inf)) == '\n' && c != EOF) /* skip leading \n's */ |
|
; |
fa *pfa = makedfa(rs, 1); |
if (c != EOF) |
found = fnematch(pfa, inf, &buf, &bufsize, recsize); |
ungetc(c, inf); |
if (found) |
} |
*patbeg = 0; |
for (rr = buf; ; ) { |
} else { |
for (; (c=getc(inf)) != sep && c != EOF; ) { |
if ((sep = *rs) == 0) { |
if (rr-buf+1 > bufsize) |
sep = '\n'; |
if (!adjbuf(&buf, &bufsize, 1+rr-buf, recsize, &rr, "readrec 1")) |
while ((c=getc(inf)) == '\n' && c != EOF) /* skip leading \n's */ |
FATAL("input record `%.30s...' too long", buf); |
; |
|
if (c != EOF) |
|
ungetc(c, inf); |
|
} |
|
for (rr = buf; ; ) { |
|
for (; (c=getc(inf)) != sep && c != EOF; ) { |
|
if (rr-buf+1 > bufsize) |
|
if (!adjbuf(&buf, &bufsize, 1+rr-buf, |
|
recsize, &rr, "readrec 1")) |
|
FATAL("input record `%.30s...' too long", buf); |
|
*rr++ = c; |
|
} |
|
if (*rs == sep || c == EOF) |
|
break; |
|
if ((c = getc(inf)) == '\n' || c == EOF) /* 2 in a row */ |
|
break; |
|
if (!adjbuf(&buf, &bufsize, 2+rr-buf, recsize, &rr, |
|
"readrec 2")) |
|
FATAL("input record `%.30s...' too long", buf); |
|
*rr++ = '\n'; |
*rr++ = c; |
*rr++ = c; |
} |
} |
if (*rs == sep || c == EOF) |
if (!adjbuf(&buf, &bufsize, 1+rr-buf, recsize, &rr, "readrec 3")) |
break; |
|
if ((c = getc(inf)) == '\n' || c == EOF) /* 2 in a row */ |
|
break; |
|
if (!adjbuf(&buf, &bufsize, 2+rr-buf, recsize, &rr, "readrec 2")) |
|
FATAL("input record `%.30s...' too long", buf); |
FATAL("input record `%.30s...' too long", buf); |
*rr++ = '\n'; |
*rr = 0; |
*rr++ = c; |
|
} |
} |
if (!adjbuf(&buf, &bufsize, 1+rr-buf, recsize, &rr, "readrec 3")) |
|
FATAL("input record `%.30s...' too long", buf); |
|
*rr = 0; |
|
DPRINTF( ("readrec saw <%s>, returns %d\n", buf, c == EOF && rr == buf ? 0 : 1) ); |
|
*pbuf = buf; |
*pbuf = buf; |
*pbufsize = bufsize; |
*pbufsize = bufsize; |
return c == EOF && rr == buf ? 0 : 1; |
isrec = *buf || !feof(inf); |
|
DPRINTF( ("readrec saw <%s>, returns %d\n", buf, isrec) ); |
|
return isrec; |
} |
} |
|
|
char *getargv(int n) /* get ARGV[n] */ |
char *getargv(int n) /* get ARGV[n] */ |