+ FILE *iob;
+
+ char **pat_map;
+ int msg_style;
+ /*
+ * The "full" delimiter string for a packed maildrop consists
+ * of a newline followed by the actual delimiter. E.g., the
+ * full string for a Unix maildrop would be: "\n\nFrom ".
+ * "Fdelim" points to the start of the full string and is used
+ * in the BODY case of the main routine to search the buffer for
+ * a possible eom. Msg_delim points to the first character of
+ * the actual delim. string (i.e., fdelim+1). Edelim
+ * points to the 2nd character of actual delimiter string. It
+ * is used in m_Eom because the first character of the string
+ * has been read and matched before m_Eom is called.
+ */
+ char *msg_delim;
+ char *fdelim;
+ char *delimend;
+ int fdelimlen;
+ char *edelim;
+ int edelimlen;
+ int state;
+ int track_filepos;
+};
+
+static
+void
+m_getfld_state_init (m_getfld_state_t *gstate, FILE *iob) {
+ m_getfld_state_t s;
+
+ s = *gstate = (m_getfld_state_t) mh_xmalloc(sizeof (struct m_getfld_state));
+ s->readpos = s->end = s->msg_buf;
+ s->bytes_read = s->total_bytes_read = 0;
+ s->last_caller_pos = s->last_internal_pos = 0;
+ s->iob = iob;
+ s->pat_map = NULL;
+ s->msg_style = MS_DEFAULT;
+ s->msg_delim = "";
+ s->fdelim = s->delimend = s->edelim = NULL;
+ s->fdelimlen = s->edelimlen = 0;
+ s->state = FLD;
+ s->track_filepos = 0;
+}
+
+/* scan() needs to force a state an initial state of FLD for each message. */
+void
+m_getfld_state_reset (m_getfld_state_t *gstate) {
+ if (*gstate) {
+ (*gstate)->state = FLD;
+ }
+}
+
+/* If the caller interleaves ftell*()/fseek*() calls with m_getfld()
+ calls, m_getfld() must keep track of the file position. The caller
+ must use this function to inform m_getfld(). */
+void
+m_getfld_track_filepos (m_getfld_state_t *gstate, FILE *iob) {
+ if (! *gstate) {
+ m_getfld_state_init (gstate, iob);
+ }
+
+ (*gstate)->track_filepos = 1;
+}
+
+void m_getfld_state_destroy (m_getfld_state_t *gstate) {
+ m_getfld_state_t s = *gstate;
+
+ if (s) {
+ if (s->fdelim) {
+ free (s->fdelim-1);
+ free (s->pat_map);
+ }
+ free (s);
+ *gstate = 0;
+ }
+}
+
+/*
+ Summary of file and message input buffer positions:
+
+ input file -------------------------------------------EOF
+ | |
+ last_caller_pos last_internal_pos
+
+
+ msg_buf --------------------EOF
+ | | |
+ msg_buf readpos end
+
+ |<>|=retained characters, difference
+ between last_internal_pos and
+ first readpos value after reading
+ in new chunk in read_more()
+
+ When returning from m_getfld()/m_unknown():
+ 1) Save the internal file position in last_internal_pos. That's the
+ m_getfld() position reference in the input file.
+ 2) Set file stream position so that callers can use ftell().
+
+ When entering m_getfld()/m_unknown():
+ Check to see if the call had changed the file position. If so,
+ adjust the internal position reference accordingly. If not, restore
+ the internal file position from last_internal_pos.
+*/
+