From 4ff236a53b9caf73f0583c41e8be49a77546dd20 Mon Sep 17 00:00:00 2001 From: Ralph Corderoy Date: Thu, 10 Aug 2017 00:08:55 +0100 Subject: [PATCH] m_getfld.c: Alter Peek() to call Getc() and Ungetc(). Functionally equivalent, not called too often, and it gets rid of another copy of the logic to decide if we've enough, should read some more, etc. --- sbr/m_getfld.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/sbr/m_getfld.c b/sbr/m_getfld.c index 6804e58e..67e9de82 100644 --- a/sbr/m_getfld.c +++ b/sbr/m_getfld.c @@ -201,6 +201,7 @@ /* * static prototypes */ +static void Ungetc(m_getfld_state_t s); static int m_Eom (m_getfld_state_t); #define eom(c,s) (s->msg_style != MS_DEFAULT && \ @@ -515,16 +516,17 @@ Getc (m_getfld_state_t s) { return (unsigned char)*s->readpos++; } -/* Return the next character that would be read by Getc() without - * consuming it, fetching more of the input for the buffer if required, - * or EOF on end of file. */ +/* Return the next character that Getc() would return, which may be EOF. */ static int -Peek (m_getfld_state_t s) { - if ((s->end - s->readpos < 1 && read_more (s) == 0) || - s->readpos >= s->end) - return EOF; +Peek (m_getfld_state_t s) +{ + int c; + + c = Getc(s); + if (c != EOF) + Ungetc(s); - return (unsigned char)*s->readpos; + return c; } /* If there's room, undo the consumption of one character from msg_buf, -- 2.56.0