Skip to contentSkip to conversation

input: Remove special case for unget EOF

PATCH New Ron Yorston 1 participant 1 message Sep 5, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 input: Remove special case for unget EOF

Commit 17db43b5841504b694203952fb0e82246c06a97f (input: Allow two consecutive calls to pungetc) ensures that EOF is handled like any other character with respect to unget. As a result it's possible to remove the special case for unget of EOF in preadbuffer.

---
 src/input.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
src/input.c +4 -7
index d7c101b..ec075f5 100644
@@ -58,7 +58,6 @@
 #include "myhistedit.h"
 #endif
 
-#define EOF_NLEFT -99		/* value of parsenleft when EOF pushed back */
 #define IBUFSIZ (BUFSIZ + 1)
 
 
@@ -220,9 +219,8 @@ retry:
  * Refill the input buffer and return the next input character:
  *
  * 1) If a string was pushed back on the input, pop it;
- * 2) If an EOF was pushed back (parsenleft == EOF_NLEFT) or we are reading
- *    from a string so we can't refill the buffer, return EOF.
- * 3) If the is more stuff in this buffer, use it else call read to fill it.
+ * 2) If we are reading from a string we can't refill the buffer, return EOF.
+ * 3) If there is more stuff in this buffer, use it else call read to fill it.
  * 4) Process input up to the next newline, deleting nul characters.
  */
 
@@ -239,8 +237,7 @@ static int preadbuffer(void)
 		popstring();
 		return __pgetc();
 	}
-	if (unlikely(parsefile->nleft == EOF_NLEFT ||
-		     parsefile->buf == NULL))
+	if (parsefile->buf == NULL)
 		return PEOF;
 	flushall();
 
@@ -248,7 +245,7 @@ static int preadbuffer(void)
 	if (more <= 0) {
 again:
 		if ((more = preadfd()) <= 0) {
-			parsefile->lleft = parsefile->nleft = EOF_NLEFT;
+			parsefile->lleft = parsefile->nleft = 0;
 			return PEOF;
 		}
 	}
Signature · 1 line
2.31.1