use Beof for awk port
This commit is contained in:
parent
85824350b5
commit
b8986a889d
5 changed files with 15 additions and 17 deletions
|
@ -18,8 +18,6 @@ typedef double Awkfloat;
|
|||
|
||||
#define FOPEN_MAX 40 /* max number of open files */
|
||||
|
||||
#define EOF -1
|
||||
|
||||
extern char errbuf[];
|
||||
|
||||
extern int compile_time; /* 1 if compiling, 0 if running */
|
||||
|
|
|
@ -541,7 +541,7 @@ int input(void) /* get next lexical input character */
|
|||
c = pgetc();
|
||||
if (c == '\n')
|
||||
lineno++;
|
||||
else if (c == EOF)
|
||||
else if (c == Beof)
|
||||
c = 0;
|
||||
if (ep >= ebuf + sizeof ebuf)
|
||||
ep = ebuf;
|
||||
|
|
|
@ -154,7 +154,7 @@ int getrec(char **pbuf, int *pbufsize, int isrecord) /* get next input record */
|
|||
*pbufsize = bufsize;
|
||||
return 1;
|
||||
}
|
||||
/* EOF arrived on this file; set up next */
|
||||
/* Beof arrived on this file; set up next */
|
||||
if (infile != &stdin)
|
||||
Bterm(infile);
|
||||
infile = nil;
|
||||
|
@ -184,21 +184,21 @@ int readrec(char **pbuf, int *pbufsize, Biobuf *inf) /* read one record into buf
|
|||
strcpy(inputFS, *FS); /* for subsequent field splitting */
|
||||
if ((sep = **RS) == 0) {
|
||||
sep = '\n';
|
||||
while ((c=Bgetc(inf)) == '\n' && c != EOF) /* skip leading \n's */
|
||||
while ((c=Bgetc(inf)) == '\n' && c != Beof) /* skip leading \n's */
|
||||
;
|
||||
if (c != EOF)
|
||||
if (c != Beof)
|
||||
Bungetc(inf);
|
||||
}
|
||||
for (rr = buf; ; ) {
|
||||
for (; (c=Bgetc(inf)) != sep && c != EOF; ) {
|
||||
for (; (c=Bgetc(inf)) != sep && c != Beof; ) {
|
||||
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)
|
||||
if (**RS == sep || c == Beof)
|
||||
break;
|
||||
if ((c = Bgetc(inf)) == '\n' || c == EOF) /* 2 in a row */
|
||||
if ((c = Bgetc(inf)) == '\n' || c == Beof) /* 2 in a row */
|
||||
break;
|
||||
if (!adjbuf(&buf, &bufsize, 2+rr-buf, recsize, &rr, "readrec 2"))
|
||||
FATAL("input record `%.30s...' too long", buf);
|
||||
|
@ -208,10 +208,10 @@ int readrec(char **pbuf, int *pbufsize, Biobuf *inf) /* read one record into buf
|
|||
if (!adjbuf(&buf, &bufsize, 1+rr-buf, recsize, &rr, "readrec 3"))
|
||||
FATAL("input record `%.30s...' too long", buf);
|
||||
*rr = 0;
|
||||
dprint( ("readrec saw <%s>, returns %d\n", buf, c == EOF && rr == buf ? 0 : 1) );
|
||||
dprint( ("readrec saw <%s>, returns %d\n", buf, c == Beof && rr == buf ? 0 : 1) );
|
||||
*pbuf = buf;
|
||||
*pbufsize = bufsize;
|
||||
return c == EOF && rr == buf ? 0 : 1;
|
||||
return c == Beof && rr == buf ? 0 : 1;
|
||||
}
|
||||
|
||||
char *getargv(int n) /* get ARGV[n] */
|
||||
|
@ -512,7 +512,7 @@ void bracecheck(void)
|
|||
|
||||
if (beenhere++)
|
||||
return;
|
||||
while ((c = input()) != EOF && c != '\0')
|
||||
while ((c = input()) != Beof && c != '\0')
|
||||
bclass(c);
|
||||
bcheck2(bracecnt, '{', '}');
|
||||
bcheck2(brackcnt, '[', ']');
|
||||
|
@ -618,7 +618,7 @@ void eprint(void) /* try to print context around error */
|
|||
Bputc(&stderr, *p);
|
||||
Bprint(&stderr, " <<< ");
|
||||
if (*ep)
|
||||
while ((c = input()) != '\n' && c != '\0' && c != EOF) {
|
||||
while ((c = input()) != '\n' && c != '\0' && c != Beof) {
|
||||
Bputc(&stderr, c);
|
||||
bclass(c);
|
||||
}
|
||||
|
|
|
@ -177,14 +177,14 @@ int pgetc(void) /* get 1 character from awk program */
|
|||
for (;;) {
|
||||
if (yyin == nil) {
|
||||
if (curpfile >= npfile)
|
||||
return EOF;
|
||||
return Beof;
|
||||
if (strcmp(pfile[curpfile], "-") == 0)
|
||||
yyin = &stdin;
|
||||
else if ((yyin = Bopen(pfile[curpfile], OREAD)) == nil)
|
||||
FATAL("can't open file %s", pfile[curpfile]);
|
||||
lineno = 1;
|
||||
}
|
||||
if ((c = Bgetc(yyin)) != EOF)
|
||||
if ((c = Bgetc(yyin)) != Beof)
|
||||
return c;
|
||||
if (yyin != &stdin)
|
||||
Bterm(yyin);
|
||||
|
|
|
@ -1618,7 +1618,7 @@ Cell *bltin(Node **a, int) /* builtin functions. a[0] is type, a[1] is arg list
|
|||
flush_all(); /* fflush() or fflush("") -> all */
|
||||
u = 0;
|
||||
} else if ((fp = openfile(FFLUSH, getsval(x))) == nil)
|
||||
u = EOF;
|
||||
u = Beof;
|
||||
else
|
||||
u = Bflush(fp);
|
||||
break;
|
||||
|
@ -1783,7 +1783,7 @@ Cell *closefile(Node **a, int)
|
|||
stat = pclose(files[i].fp);
|
||||
else
|
||||
stat = Bterm(files[i].fp);
|
||||
if (stat == EOF)
|
||||
if (stat == Beof)
|
||||
WARNING( "i/o error occurred closing %s", files[i].fname );
|
||||
if (i > 2) /* don't do /dev/std... */
|
||||
xfree(files[i].fname);
|
||||
|
|
Loading…
Reference in a new issue