From: Ralph Corderoy Date: Wed, 9 Aug 2017 23:08:55 +0000 (+0100) Subject: m_getfld.c: Alter Peek() to call Getc() and Ungetc(). X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/4ff236a53b9caf73f0583c41e8be49a77546dd20?ds=sidebyside 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. --- 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,