unsigned char msg_buf[2 * MSG_INPUT_SIZE + MAX_DELIMITER_SIZE];
unsigned char *readpos;
unsigned char *end; /* One past, like C++, the last character read in. */
+ size_t bytes_read; /* To support old msg_count. */
} m;
static void
/* A new file stream, so reset the buffer state. */
m->readpos = m->end = m->msg_buf;
}
+
+ m->bytes_read = 0;
}
static size_t
memmove (m->msg_buf, m->readpos - retain, retain);
m->readpos = m->msg_buf + retain;
-
num_read = fread (m->readpos, 1, MSG_INPUT_SIZE, iob);
-
m->end = m->readpos + num_read;
return num_read;
if (read_more (&m, iob) == 0) {
/* Pretend that we read a character. That's what stdio does. */
++m.readpos;
+ /* Don't seem to need the following but maybe because no
+ caller of m_getfld () looks at it. */
+ ++m.bytes_read;
return EOF;
}
}
+ ++m.bytes_read;
return m.readpos < m.end ? *m.readpos++ : EOF;
}
Peek (FILE *iob) {
int next_char = Getc (iob);
--m.readpos;
+ --m.bytes_read;
return next_char;
}
Ungetc (int c, FILE *iob) {
NMH_UNUSED (iob);
- return m.readpos == m.msg_buf ? EOF : (*--m.readpos = c);
+ if (m.readpos == m.msg_buf) {
+ return EOF;
+ } else {
+ --m.bytes_read;
+ return *--m.readpos = c;
+ }
}
{
register unsigned char *bp, *cp, *ep, *sp;
register int cnt, c, i, j;
- long bytes_read = 0;
setup_buffer (iob, &m);
case FLD:
if (c == '\n' || c == '-') {
/* we hit the header/body separator */
- while (c != '\n' && (c = Getc(iob)) >= 0) {
- ++bytes_read;
- }
+ while (c != '\n' && (c = Getc(iob)) >= 0) continue;
if (c < 0 || (c = Getc(iob)) < 0 || eom (c, iob)) {
if (! eom_action) {
j to 1 to account for that. */
for (j = 1;
c != ':' && c != '\n' && c != EOF && j <= i;
- ++j, ++bytes_read, c = Getc (iob)) {
+ ++j, c = Getc (iob)) {
*cp++ = c;
}
memcpy (buf, name, j - 1);
buf[j - 1] = '\n';
buf[j] = '\0';
- *bufsz = bytes_read;
+ *bufsz = m.bytes_read - 1;
return BODY;
}
if ((i -= j) <= 0) {
}
finish:
*cp = 0;
- *bufsz = cp - buf + bytes_read + 1;
+ *bufsz = m.bytes_read + (state == BODY ? cp - buf - 1 : 0);
return (state);
}
char text[MAX_DELIMITER_SIZE];
register char *cp;
register char *delimstr;
- size_t bytes_read = 0;
setup_buffer (iob, &m);
msg_style = MS_UNKNOWN;
for (c = 0, cp = text; c < 5; ++c, ++cp) {
- ++bytes_read;
if ((*cp = Getc (iob)) == EOF) {
break;
}
if (c == 5 && strncmp (text, "From ", 5) == 0) {
msg_style = MS_MBOX;
delimstr = "\nFrom ";
- while (++bytes_read, (c = Getc (iob)) != '\n' && c >= 0)
- ;
+ while ((c = Getc (iob)) != '\n' && c >= 0) continue;
/* m_unknown is only called on maildrop files, and they are only
read using m_getfld (). The caller musn't try to read from
the stream directly because the file position indicator was
was read into the message buffer. */
} else {
/* not a Unix style maildrop */
- m.readpos -= bytes_read; /* fseek (iob, pos, SEEK_SET), but relative. */
+ m.readpos -= m.bytes_read;
if (mmdlm2 == NULL || *mmdlm2 == 0)
mmdlm2 = "\001\001\001\001\n";
delimstr = mmdlm2;
m_Eom (int c, FILE *iob)
{
register int i;
- size_t bytes_read = 0;
char text[MAX_DELIMITER_SIZE];
char *cp;
for (i = 0, cp = text; i < edelimlen; ++i, ++cp) {
- ++bytes_read;
if ((*cp = Getc (iob)) == EOF) {
break;
}
/* Did not find delimiter, so restore the read position.
Note that on input, a character had already been read
with Getc(). It will be unget by m_getfld () on return. */
- m.readpos -= bytes_read;
+ m.readpos -= m.bytes_read - 1;
return 0;
}