diff mbox series

[v5,09/13] input: Add pgetc_eoa

Message ID 67b4b988d3bb9d6b8ec564d908c8339fd78660c7.1717291579.git.herbert@gondor.apana.org.au (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series Add multi-byte supportAdd multi-byte support | expand

Commit Message

Herbert Xu June 2, 2024, 1:29 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 *);