*/
struct m_getfld_state;
static int m_Eom (m_getfld_state_t);
-static char *matchc(int, char *, int, char *);
#define eom(c,s) (s->msg_style != MS_DEFAULT && \
((c) == *s->msg_delim && m_Eom(s)))
ssize_t retain = s->edelimlen;
size_t num_read;
- if (retain < s->end - s->readpos) retain = s->end - s->readpos;
+ if (retain < s->end - s->readpos)
+ retain = s->end - s->readpos;
assert (retain <= s->readpos - s->msg_buf);
/* Move what we want to retain at end of the buffer to the beginning. */
while (isspace ((unsigned char) *--cp) && cp >= name) continue;
*++cp = 0;
/* readpos points to the first character of the field body. */
- /* fall through */
+ /* FALLTHRU */
case FLDPLUS: {
/*
n = 0;
for (finished = 0; ! finished; ) {
while (c != '\n' && c != EOF && n++ < max) {
- if ((c = Getc (s)) != EOF) { *cp++ = c; }
+ if ((c = Getc (s)) != EOF)
+ *cp++ = c;
}
- if (c != EOF) c = Peek (s);
+ if (c != EOF)
+ c = Peek (s);
if (max < n) {
/* The dest buffer is full. Need to back the read
pointer up by one because when m_getfld() is
*/
char *ep;
- if ((ep = matchc( s->fdelimlen, s->fdelim, c, bp )))
+ if ((ep = memmem(bp, c, s->fdelim, s->fdelimlen)))
c = ep - bp + 1;
else {
/*
delimstr = mmdlm2;
s->msg_style = MS_MMDF;
}
+
c = strlen (delimstr);
- s->fdelim = mh_xmalloc (c + 3);
+ s->fdelim = mh_xmalloc (c + 3); /* \0, \n, delimstr, \0 */
*s->fdelim++ = '\0';
*s->fdelim = '\n';
+ s->fdelimlen = c + 1;
s->msg_delim = s->fdelim+1;
- s->edelim = s->msg_delim+1;
- s->fdelimlen = c;
- s->edelimlen = c - 1; /* == strlen (delimstr) */
strcpy (s->msg_delim, delimstr);
+ s->edelim = s->msg_delim+1;
+ s->edelimlen = c - 1;
s->delimend = s->msg_delim + s->edelimlen;
if (s->edelimlen <= 1)
adios (NULL, "maildrop delimiter must be at least 2 bytes");
+
+ /* Now malloc'd memory at s->fdelim-1 referenced several times:
+ *
+ * delimstr "\nFrom " "\001\001\001\001\n"
+ * c 6 5
+ * s->fdelim \0"\n\nFrom " \0"\n\001\001\001\001\n"
+ * s->fdelimlen 6 5
+ * s->msg_delim "\nFrom " "\001\001\001\001\n"
+ * s->edelim "From " "\001\001\001\n"
+ * s->edelimlen 5 4
+ * s->delimend " " "\n"
+ */
+
/*
* build a Boyer-Moore end-position map for the matcher in m_getfld.
* N.B. - we don't match just the first char (since it's the newline
return 1;
}
-
-
-static char *
-matchc(int patln, char *pat, int strln, char *str)
-{
- char *es = str + strln - patln;
- char *sp;
- char *pp;
- char *ep = pat + patln;
- char pc = *pat++;
-
- for(;;) {
- while (pc != *str++)
- if (str > es)
- return 0;
- if (str > es+1)
- return 0;
- sp = str; pp = pat;
- while (pp < ep && *sp++ == *pp)
- pp++;
- if (pp >= ep)
- return --str;
- }
-}