diff mbox series

[v3,08/13] input: Add pgetc_eoa

Message ID 91d6bef13f4cca0029d879ba44650dc2b15199d1.1714900377.git.herbert@gondor.apana.org.au (mailing list archive)
State Changes Requested
Delegated to: Herbert Xu
Headers show
Series Add multi-byte support | expand

Commit Message

Herbert Xu May 5, 2024, 9:14 a.m. UTC
This reintroduces PEOA in a limited way.  Instead of allowing pgetc
to return it, limit it to a new function pgetc_eoa so only specific
callers need to deal with PEOA.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
 src/input.c | 8 +++++++-
 src/input.h | 3 ++-
 2 files changed, 9 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/src/input.c b/src/input.c
index e17e067..bedc581 100644
--- a/src/input.c
+++ b/src/input.c
@@ -157,7 +157,7 @@  static int __pgetc(void)
  * Nul characters in the input are silently discarded.
  */
 
-int pgetc(void)
+int __attribute__((noinline)) pgetc(void)
 {
 	struct strpush *sp = parsefile->spfree;
 
@@ -167,6 +167,12 @@  int pgetc(void)
 	return __pgetc();
 }
 
+int pgetc_eoa(void)
+{
+	return parsefile->strpush && parsefile->nleft == -1 &&
+	       parsefile->strpush->ap ? PEOA : pgetc();
+}
+
 static int stdin_clear_nonblock(void)
 {
 	int flags = fcntl(0, F_GETFL, 0);
diff --git a/src/input.h b/src/input.h
index 5b4a045..151b1c6 100644
--- a/src/input.h
+++ b/src/input.h
@@ -45,6 +45,7 @@ 
 #define PUNGETC_MAX (MB_LEN_MAX > 16 ? MB_LEN_MAX : 16)
 
 /* PEOF (the end of file marker) is defined in syntax.h */
+#define PEOA ((PEOF) - 1)
 
 enum {
 	INPUT_PUSH_FILE = 1,
@@ -102,7 +103,7 @@  extern struct parsefile *parsefile;
 #define plinno (parsefile->linno)
 
 int pgetc(void);
-int pgetc2(void);
+int pgetc_eoa(void);
 void pungetc(void);
 void pungetn(int);
 void pushstring(char *, void *);