shithub: riscv

Download patch

ref: b8986a889d7e3a445c0265c5cfb3b1db385db756
parent: 85824350b5f65053053245d141aaf7d668089d28
author: ben <ben@rana>
date: Wed Apr 27 04:09:16 EDT 2016

use Beof for awk port

--- a/sys/src/cmd/awk/awk.h
+++ b/sys/src/cmd/awk/awk.h
@@ -18,8 +18,6 @@
 
 #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 */
--- a/sys/src/cmd/awk/lex.c
+++ b/sys/src/cmd/awk/lex.c
@@ -541,7 +541,7 @@
 		c = pgetc();
 	if (c == '\n')
 		lineno++;
-	else if (c == EOF)
+	else if (c == Beof)
 		c = 0;
 	if (ep >= ebuf + sizeof ebuf)
 		ep = ebuf;
--- a/sys/src/cmd/awk/lib.c
+++ b/sys/src/cmd/awk/lib.c
@@ -154,7 +154,7 @@
 			*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 @@
 	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 @@
 	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 @@
 
 	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 @@
 			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);
 		}
--- a/sys/src/cmd/awk/main.c
+++ b/sys/src/cmd/awk/main.c
@@ -177,7 +177,7 @@
 	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)
@@ -184,7 +184,7 @@
 				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);
--- a/sys/src/cmd/awk/run.c
+++ b/sys/src/cmd/awk/run.c
@@ -1618,7 +1618,7 @@
 			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 @@
 				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);