]> diplodocus.org Git - nmh/commitdiff
m_getfld.c: Alter Peek() to call Getc() and Ungetc().
authorRalph Corderoy <ralph@inputplus.co.uk>
Wed, 9 Aug 2017 23:08:55 +0000 (00:08 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Wed, 9 Aug 2017 23:08:55 +0000 (00:08 +0100)
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

index 6804e58..67e9de8 100644 (file)
 /*
  * 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,