]> diplodocus.org Git - nmh/commitdiff
Removed the static m_getfld() state instance and replaced
authorDavid Levine <levinedl@acm.org>
Mon, 21 Jan 2013 03:27:54 +0000 (21:27 -0600)
committerDavid Levine <levinedl@acm.org>
Mon, 21 Jan 2013 03:27:54 +0000 (21:27 -0600)
with functions for callers to create and destroy their own
instances.  This also allows inc, msh, and pick to call
m_getfld() with an initial file stream position other than 0.

There is now a global state instance so that scan can call
m_unknown() on maildrop files.  It'd be nice to get rid of
that.

28 files changed:
h/mh.h
h/prototypes.h
sbr/m_getfld.c
sbr/readconfig.c
sbr/seq_read.c
uip/distsbr.c
uip/forwsbr.c
uip/inc.c
uip/mhbuildsbr.c
uip/mhcachesbr.c
uip/mhlsbr.c
uip/mhparse.c
uip/msh.c
uip/mshcmds.c
uip/new.c
uip/picksbr.c
uip/post.c
uip/prompter.c
uip/rcvdist.c
uip/rcvtty.c
uip/replsbr.c
uip/scan.c
uip/scansbr.c
uip/sendsbr.c
uip/show.c
uip/slocal.c
uip/sortm.c
uip/whatnowsbr.c

diff --git a/h/mh.h b/h/mh.h
index 07f6508d3f92e420184763d0f63d9c436f3457b3..44fc190737938f0a65456b063ebd845c25caf8c7 100644 (file)
--- a/h/mh.h
+++ b/h/mh.h
@@ -240,6 +240,9 @@ struct msgs {
 #define BODY     3             /* Body  returned with more to come */
 #define FILEEOF  5             /* Reached end of input file        */
 
+struct m_getfld_state;
+typedef struct m_getfld_state *m_getfld_state_t;
+
 /*
  * Maildrop styles
  */
index 619be9104d8b6548561982a454f09054c1ac4cf8..a1f1edc99906fcd7adbe9419976f58c0c2e8255f 100644 (file)
@@ -75,8 +75,11 @@ int m_atoi (char *);
 char *m_backup (char *);
 int m_convert (struct msgs *, char *);
 char *m_draft (char *, char *, int, int *);
-void m_eomsbr (int (*)(int));
-int m_getfld (int, unsigned char[NAMESZ], unsigned char *, int *, FILE *);
+void m_eomsbr (m_getfld_state_t, int (*)(int));
+void m_getfld_state_init (m_getfld_state_t *);
+void m_getfld_state_reset (m_getfld_state_t *);
+void m_getfld_state_destroy (m_getfld_state_t *);
+int m_getfld (m_getfld_state_t, unsigned char[NAMESZ], unsigned char *, int *, FILE *);
 int m_gmprot (void);
 char *m_maildir (char *);
 char *m_mailpath (char *);
@@ -85,7 +88,7 @@ int m_putenv (char *, char *);
 int m_rand (unsigned char *, size_t);
 char *m_mktemp(const char *, int *, FILE **);
 char *m_mktemp2(const char *, const char *, int *, FILE **);
-void m_unknown(FILE *);
+void m_unknown(m_getfld_state_t, FILE *);
 int makedir (char *);
 char *message_id (time_t, int);
 char *nmh_getpass(const char *);
index fae75bed83f04858d74a228c6de57e4d5d67d685..59b496777ea95ca5bc3e71b49c372aae9402f13f 100644 (file)
@@ -143,7 +143,7 @@ to m_getfld() reads one header field, or a portion of the body, in sequence.
 
 Inputs
 ======
-state:  message parse state
+gstate:  opaque parse state
 bufsz:  maximum number of characters to load into buf
 iob:  input file stream
 
@@ -162,12 +162,12 @@ void m_unknown(FILE *iob):  Determines the message delimiter string for the
 void m_eomsbr (int (*action)(int)):  Sets the hook to check for end of
   message in a maildrop.  Called only by msh.
 
-Those functions save state in the State variables listed below.
-
 State variables
 ===============
-m_getfld() retains state internally between calls in some state variables.
-These are used for detecting the end of each message when reading maildrops:
+m_getfld() retains state internally between calls in the m_getfld_state_t
+variable.  These are used for detecting the end of each message when reading
+maildrops:
+
   unsigned char **pat_map
   unsigned char *fdelim
   unsigned char *delimend
@@ -178,30 +178,28 @@ These are used for detecting the end of each message when reading maildrops:
   int msg_style
   int (*eom_action)(int)
 
-Restrictions
-============
-m_getfld() is restricted to operate on one file stream at a time
-because of the retained state (see "State variables" above).  And the
-first call to m_getfld() on that file stream requires that the read
-pointer be at the beginning of the file (ftell() of 0).
-
-Current usage
-=============
-The first call to m_getfld() on a file stream is with a state of FLD.
-Subsequent calls provide the state returned by the previous call.
-Therefore, given the Restrictions above, the state variable could be
-removed from the signature and just retained internally.
+Usage
+=====
+    m_getfld_state_t gstate;
+    m_getfld_state_init (&gstate);
+    int state = m_getfld (gstate, ...);
+       ...
+    m_getfld_state_destroy (&gstate);
+
+The state is retained internally by gstate.  To reset its state to FLD:
+
+    m_getfld_state_reset (&gstate);
 */
 
 /*
  * static prototypes
  */
 struct m_getfld_state;
-static int m_Eom (int, struct m_getfld_state *);
+static int m_Eom (m_getfld_state_t, int);
 static unsigned char *matchc(int, char *, int, char *);
 
 #define eom(c,s)       (s->msg_style != MS_DEFAULT && \
-                        (((c) == *s->msg_delim && m_Eom(c,s)) || \
+                        (((c) == *s->msg_delim && m_Eom(s,c)) || \
                          (s->eom_action && (*s->eom_action)(c))))
 
 /* This replaces the old approach, with its direct access to stdio
@@ -216,7 +214,7 @@ static unsigned char *matchc(int, char *, int, char *);
 #define MSG_INPUT_SIZE (BUFSIZ >= 1024 ? BUFSIZ : 1024)
 #define MAX_DELIMITER_SIZE 32
 
-static struct m_getfld_state {
+struct m_getfld_state {
     unsigned char msg_buf[2 * MSG_INPUT_SIZE + MAX_DELIMITER_SIZE];
     unsigned char *readpos;
     unsigned char *end;  /* One past the last character read in. */
@@ -224,7 +222,7 @@ static struct m_getfld_state {
        input file stream so that callers can interleave m_getfld()
        calls with ftell() and fseek().  ytes_read replaces the old
        m_getfld() msg_count global.  last_caller_pos is stored when
-       leaving m_getfld()/m_unkown(), then checked on the next entry.
+       leaving m_getfld()/m_unknown(), then checked on the next entry.
        last_internal_pos is used to remember the position used
        internally by m_getfld() (read_more(), actually). */
     off_t bytes_read;
@@ -254,7 +252,37 @@ static struct m_getfld_state {
     unsigned char *edelim;
     int edelimlen;
     int (*eom_action)(int);
-} m;
+    int state;
+};
+
+void
+m_getfld_state_init (m_getfld_state_t *s) {
+    *s = (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 gets loaded on every call to m_getfld()/m_unknown(). */
+    (*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)->eom_action = NULL;
+    (*s)->state = FLD;
+}
+
+/* scan() needs to force a state an initial state of FLD for each message. */
+void
+m_getfld_state_reset (m_getfld_state_t *s) {
+    (*s)->state = FLD;
+}
+
+void m_getfld_state_destroy (m_getfld_state_t *s) {
+    if (*s) {
+       free (*s);
+       *s = 0;
+    }
+}
 
 /*
   Summary of file and message input buffer positions:
@@ -286,64 +314,53 @@ static struct m_getfld_state {
 
 
 static void
-enter_getfld (struct m_getfld_state *m, FILE *iob) {
+enter_getfld (m_getfld_state_t s, FILE *iob) {
     off_t pos;
 
-    /* Ugly.  The parser opens the input file mutliple times, so we
+    /* Ugly.  The parser opens the input file multiple times, so we
        have to always use the FILE * that's passed to m_getfld(). */
-    m->iob = iob;
+    s->iob = iob;
+
     pos = ftello (iob);
 
-    /* Rely on Restriction that the first call to m_getfld (), etc.,
-       is with the read position for the file stream set to 0. */
-    if (pos == 0) {
-       /* A new file stream, so reset the buffer state. */
-        m->iob = iob;
-       m->readpos = m->end = m->msg_buf;
-       m->total_bytes_read = 0;
-       m->last_caller_pos = m->last_internal_pos = ftello (iob);
-       m->pat_map = NULL;
-       m->fdelim = m->delimend = m->edelim = NULL;
-       m->msg_style = MS_DEFAULT;
-       m->msg_delim = "";
-       m->fdelimlen = m->edelimlen = 0;
-       m->eom_action = NULL;
-    } else {
-       off_t pos_movement = pos - m->last_caller_pos; /* Can be < 0. */
+    if (pos != 0) {
+       off_t pos_movement = pos - s->last_caller_pos; /* Can be < 0. */
 
        if (pos_movement == 0) {
-           pos = m->last_internal_pos;
+           pos = s->last_internal_pos;
        } else {
-           /* The current file stream position differs from the last one, so
-              caller must have called ftell/o().  Adjust accordingly. */
-           if (m->readpos + pos_movement >= m->msg_buf  &&
-               m->readpos + pos_movement < m->end) {
+           /* The current file stream position differs from the last
+              one, so caller must have called ftell/o().  Or, this is
+              the first call and the file position was not at 0. */
+
+           if (s->readpos + pos_movement >= s->msg_buf  &&
+               s->readpos + pos_movement < s->end) {
                /* We can shift readpos and remain within the bounds of
                   msg_buf. */
-               m->readpos += pos_movement;
-               m->total_bytes_read += pos_movement;
-               pos = m->last_internal_pos;
+               s->readpos += pos_movement;
+               s->total_bytes_read += pos_movement;
+               pos = s->last_internal_pos;
            } else {
                size_t num_read;
 
                /* This seek skips past an integral number of chunks of
                   size MSG_INPUT_SIZE. */
                fseeko (iob, pos / MSG_INPUT_SIZE * MSG_INPUT_SIZE, SEEK_SET);
-               num_read = fread (m->msg_buf, 1, MSG_INPUT_SIZE, iob);
-               m->readpos = m->msg_buf  +  pos % MSG_INPUT_SIZE;
-               m->end = m->msg_buf + num_read;
-               m->total_bytes_read = pos;
+               num_read = fread (s->msg_buf, 1, MSG_INPUT_SIZE, iob);
+               s->readpos = s->msg_buf  +  pos % MSG_INPUT_SIZE;
+               s->end = s->msg_buf + num_read;
+               s->total_bytes_read = pos;
            }
        }
 
-       fseeko (iob, pos, SEEK_SET);
+       if (s->last_internal_pos != 0) fseeko (iob, pos, SEEK_SET);
     }
 
-    m->bytes_read = 0;
+    s->bytes_read = 0;
 }
 
 static void
-leave_getfld (struct m_getfld_state *s) {
+leave_getfld (m_getfld_state_t s) {
     /* Save the internal file position that we use for the input buffer. */
     s->last_internal_pos = ftello (s->iob);
 
@@ -354,7 +371,7 @@ leave_getfld (struct m_getfld_state *s) {
 }
 
 static size_t
-read_more (struct m_getfld_state *s) {
+read_more (m_getfld_state_t s) {
     /* Retain at least edelimlen characters that have already been
        read so that we can back up to them in m_Eom(). */
     ssize_t retain = s->edelimlen;
@@ -374,7 +391,7 @@ read_more (struct m_getfld_state *s) {
 }
 
 static int
-Getc (struct m_getfld_state *s) {
+Getc (m_getfld_state_t s) {
     if (s->end - s->readpos < 1) {
        if (read_more (s) == 0) {
            /* Pretend that we read a character.  That's what stdio does. */
@@ -388,7 +405,7 @@ Getc (struct m_getfld_state *s) {
 }
 
 static int
-Peek (struct m_getfld_state *s) {
+Peek (m_getfld_state_t s) {
     int next_char = Getc (s);
     --s->readpos;
     --s->bytes_read;
@@ -397,7 +414,7 @@ Peek (struct m_getfld_state *s) {
 }
 
 static int
-Ungetc (int c, struct m_getfld_state *s) {
+Ungetc (int c, m_getfld_state_t s) {
     if (s->readpos == s->msg_buf) {
        return EOF;
     } else {
@@ -408,10 +425,9 @@ Ungetc (int c, struct m_getfld_state *s) {
 
 
 int
-m_getfld (int state, unsigned char name[NAMESZ], unsigned char *buf,
+m_getfld (m_getfld_state_t s, unsigned char name[NAMESZ], unsigned char *buf,
           int *bufsz, FILE *iob)
 {
-    struct m_getfld_state *s = &m;
     register unsigned char *cp;
     register int max, n, c;
 
@@ -420,7 +436,7 @@ m_getfld (int state, unsigned char name[NAMESZ], unsigned char *buf,
     if ((c = Getc(s)) < 0) {
        *bufsz = *buf = 0;
        leave_getfld (s);
-       return FILEEOF;
+       return s->state = FILEEOF;
     }
     if (eom (c, s)) {
        if (! s->eom_action) {
@@ -433,10 +449,10 @@ m_getfld (int state, unsigned char name[NAMESZ], unsigned char *buf,
        }
        *bufsz = *buf = 0;
        leave_getfld (s);
-       return FILEEOF;
+       return s->state = FILEEOF;
     }
 
-    switch (state) {
+    switch (s->state) {
        case FLD:
            if (c == '\n' || c == '-') {
                /* we hit the header/body separator */
@@ -452,9 +468,9 @@ m_getfld (int state, unsigned char name[NAMESZ], unsigned char *buf,
                    }
                    *bufsz = *buf = 0;
                    leave_getfld (s);
-                   return FILEEOF;
+                   return s->state = FILEEOF;
                }
-               state = BODY;
+               s->state = BODY;
                goto body;
            }
            /*
@@ -482,7 +498,7 @@ m_getfld (int state, unsigned char name[NAMESZ], unsigned char *buf,
                    *bufsz = *cp = *buf = 0;
                    advise (NULL, "eof encountered in field \"%s\"", name);
                    leave_getfld (s);
-                   return FMTERR;
+                   return s->state = FMTERR;
                }
            }
 
@@ -507,7 +523,7 @@ m_getfld (int state, unsigned char name[NAMESZ], unsigned char *buf,
                    /* No, it can't.  Oh well, guess we'll blow up. */
                    *bufsz = *cp = *buf = 0;
                    advise (NULL, "eol encountered in field \"%s\"", name);
-                   state = FMTERR;
+                   s->state = FMTERR;
                    break;
                }
                memcpy (buf, name, n - 1);
@@ -518,7 +534,7 @@ m_getfld (int state, unsigned char name[NAMESZ], unsigned char *buf,
                   name array in the for loop above.  So subtract 1. */
                *bufsz = --s->bytes_read;  /* == n - 1 */
                leave_getfld (s);
-               return BODY;
+               return s->state = BODY;
            } else if (max <= n) {
                /* By design, the loop above discards the last character
                    it had read.  It's in c, use it. */
@@ -526,7 +542,7 @@ m_getfld (int state, unsigned char name[NAMESZ], unsigned char *buf,
                *bufsz = *cp = *buf = 0;
                advise (NULL, "field name \"%s\" exceeds %d bytes", name,
                        NAMESZ - 2);
-               state = LENERR;
+               s->state = LENERR;
                break;
            }
 
@@ -555,14 +571,14 @@ m_getfld (int state, unsigned char name[NAMESZ], unsigned char *buf,
                if (c != EOF) c = Peek (s);
                if (max < n) {
                    /* the dest buffer is full */
-                   state = FLDPLUS;
+                   s->state = FLDPLUS;
                    finished = 1;
                } else if (c != ' '  &&  c != '\t') {
                    /* The next character is not folded whitespace, so
                       prepare to move on to the next field.  It's OK
                       if c is EOF, it will be handled on the next
                       call to m_getfld (). */
-                   state = FLD;
+                   s->state = FLD;
                    finished = 1;
                } else {
                    /* Folded header field, continues on the next line. */
@@ -669,20 +685,19 @@ m_getfld (int state, unsigned char name[NAMESZ], unsigned char *buf,
         }
 
        default:
-           adios (NULL, "m_getfld() called with bogus state of %d", state);
+           adios (NULL, "m_getfld() called with bogus state of %d", s->state);
     }
 
     *cp = 0;
     leave_getfld (s);
 
-    return state;
+    return s->state;
 }
 
 
 void
-m_unknown(FILE *iob)
+m_unknown(m_getfld_state_t s, FILE *iob)
 {
-    struct m_getfld_state *s = &m;
     register int c;
     char text[MAX_DELIMITER_SIZE];
     register char *cp;
@@ -762,10 +777,8 @@ m_unknown(FILE *iob)
 
 
 void
-m_eomsbr (int (*action)(int))
+m_eomsbr (m_getfld_state_t s, int (*action)(int))
 {
-    struct m_getfld_state *s = &m;
-
     if ((s->eom_action = action)) {
        s->msg_style = MS_MSH;
        *s->msg_delim = 0;
@@ -785,7 +798,7 @@ m_eomsbr (int (*action)(int))
  */
 
 static int
-m_Eom (int c, struct m_getfld_state *s)
+m_Eom (m_getfld_state_t s, int c)
 {
     register int i;
     char text[MAX_DELIMITER_SIZE];
index b8b1b35753188290e715aad049ce47d033116f0a..4e02738ca1e0aeba0f462dc26c0767b754e92b5d 100644 (file)
@@ -52,15 +52,17 @@ readconfig (struct node **npp, FILE *ib, char *file, int ctx)
     char name[NAMESZ], field[BUFSIZ];
     register struct node *np;
     register struct procstr *ps;
+    m_getfld_state_t gstate;
 
     if (npp == NULL && (npp = opp) == NULL) {
        admonish (NULL, "bug: readconfig called but pump not primed");
        return;
     }
 
-    for (state = FLD;;) {
+    m_getfld_state_init (&gstate);
+    for (;;) {
        int fieldsz = sizeof field;
-       switch (state = m_getfld (state, name, field, &fieldsz, ib)) {
+       switch (state = m_getfld (gstate, name, field, &fieldsz, ib)) {
            case FLD:
            case FLDPLUS:
                np = (struct node *) mh_xmalloc (sizeof(*np));
@@ -71,7 +73,7 @@ readconfig (struct node **npp, FILE *ib, char *file, int ctx)
                    cp = getcpy (field);
                    while (state == FLDPLUS) {
                        fieldsz = sizeof field;
-                       state = m_getfld (state, name, field, &fieldsz, ib);
+                       state = m_getfld (gstate, name, field, &fieldsz, ib);
                        cp = add (field, cp);
                    }
                    np->n_field = trimcpy (cp);
@@ -103,6 +105,7 @@ readconfig (struct node **npp, FILE *ib, char *file, int ctx)
        }
        break;
     }
+    m_getfld_state_destroy (&gstate);
 
     /*
      * Special handling for the pager processes: lproc and moreproc.
index 08c67445e077b29b54038a0e81e06ec6a5a96a75..1b6844133db8a43a82121fca7ca1a23942b33200 100644 (file)
@@ -59,6 +59,7 @@ seq_public (struct msgs *mp)
     char *cp, seqfile[PATH_MAX];
     char name[NAMESZ], field[BUFSIZ];
     FILE *fp;
+    m_getfld_state_t gstate;
 
     /*
      * If mh_seq == NULL (such as if nmh been compiled with
@@ -76,16 +77,17 @@ seq_public (struct msgs *mp)
        return;
 
     /* Use m_getfld to scan sequence file */
-    for (state = FLD;;) {
+    m_getfld_state_init (&gstate);
+    for (;;) {
        int fieldsz = sizeof field;
-       switch (state = m_getfld (state, name, field, &fieldsz, fp)) {
+       switch (state = m_getfld (gstate, name, field, &fieldsz, fp)) {
            case FLD: 
            case FLDPLUS:
                if (state == FLDPLUS) {
                    cp = getcpy (field);
                    while (state == FLDPLUS) {
                        fieldsz = sizeof field;
-                       state = m_getfld (state, name, field, &fieldsz, fp);
+                       state = m_getfld (gstate, name, field, &fieldsz, fp);
                        cp = add (field, cp);
                    }
                    seq_init (mp, getcpy (name), trimcpy (cp));
@@ -107,6 +109,7 @@ seq_public (struct msgs *mp)
        }
        break;  /* break from for loop */
     }
+    m_getfld_state_destroy (&gstate);
 
     lkfclose (fp, seqfile);
 }
index e2aaab01de052b876a4fb19df1ae06559b6c66b8..457536a318b4a72be3bfdb76d2a0110f17e86afc 100644 (file)
@@ -32,6 +32,7 @@ distout (char *drft, char *msgnam, char *backup)
     register char *resent;
     char name[NAMESZ], buffer[BUFSIZ];
     register FILE *ifp, *ofp;
+    m_getfld_state_t gstate;
 
     if (rename (drft, strcpy (backup, m_backup (drft))) == NOTOK)
        adios (backup, "unable to rename %s to",drft);
@@ -46,9 +47,10 @@ distout (char *drft, char *msgnam, char *backup)
     lseek (hdrfd, (off_t) 0, SEEK_SET); /* msgnam not accurate */
     cpydata (hdrfd, fileno (ofp), msgnam, drft);
 
-    for (state = FLD, resent = NULL;;) {
+    m_getfld_state_init (&gstate);
+    for (resent = NULL;;) {
        int buffersz = sizeof buffer;
-       switch (state = m_getfld (state, name, buffer, &buffersz, ifp)) {
+       switch (state = m_getfld (gstate, name, buffer, &buffersz, ifp)) {
            case FLD: 
            case FLDPLUS: 
                if (uprf (name, "distribute-"))
@@ -65,7 +67,7 @@ distout (char *drft, char *msgnam, char *backup)
                fprintf (ofp, "%s: %s", name, buffer);
                while (state == FLDPLUS) {
                    buffersz = sizeof buffer;
-                   state = m_getfld (state, name, buffer, &buffersz, ifp);
+                   state = m_getfld (gstate, name, buffer, &buffersz, ifp);
                    resent = add (buffer, resent);
                    fputs (buffer, ofp);
                }
@@ -97,6 +99,7 @@ distout (char *drft, char *msgnam, char *backup)
        }
     }
 process: ;
+    m_getfld_state_destroy (&gstate);
     fclose (ifp);
     fflush (ofp);
 
@@ -128,6 +131,7 @@ ready_msg (char *msgnam)
     char name[NAMESZ], buffer[BUFSIZ], tmpfil[BUFSIZ];
     register FILE *ifp, *ofp;
     char *cp = NULL;
+    m_getfld_state_t gstate;
 
     if (hdrfd != NOTOK)
        close (hdrfd), hdrfd = NOTOK;
@@ -148,9 +152,10 @@ ready_msg (char *msgnam)
        adios (NULL, "no file descriptors -- you lose big");
     unlink (tmpfil);
 
-    for (state = FLD;;) {
+    m_getfld_state_init (&gstate);
+    for (;;) {
        int buffersz = sizeof buffer;
-       switch (state = m_getfld (state, name, buffer, &buffersz, ifp)) {
+       switch (state = m_getfld (gstate, name, buffer, &buffersz, ifp)) {
            case FLD: 
            case FLDPLUS: 
                if (uprf (name, "resent"))
@@ -158,7 +163,7 @@ ready_msg (char *msgnam)
                fprintf (ofp, "%s: %s", name, buffer);
                while (state == FLDPLUS) {
                    buffersz = sizeof buffer;
-                   state = m_getfld (state, name, buffer, &buffersz, ifp);
+                   state = m_getfld (gstate, name, buffer, &buffersz, ifp);
                    fputs (buffer, ofp);
                }
                break;
@@ -179,7 +184,7 @@ ready_msg (char *msgnam)
                fprintf (ofp, "\n%s", buffer);
                while (state == BODY) {
                    buffersz = sizeof buffer;
-                   state = m_getfld (state, name, buffer, &buffersz, ifp);
+                   state = m_getfld (gstate, name, buffer, &buffersz, ifp);
                    fputs (buffer, ofp);
                }
            case FILEEOF: 
@@ -194,6 +199,7 @@ ready_msg (char *msgnam)
        }
     }
 process: ;
+    m_getfld_state_destroy (&gstate);
     fclose (ifp);
     fclose (ofp);
 }
index 87006620010435ac41b76d6fe34b2303bb94d031..592f1eb26adfffddd99550ece339a9425c0c3878 100644 (file)
@@ -54,6 +54,7 @@ build_form (char *form, char *digest, int *dat, char *from, char *to,
     register struct comp *cptr;
     struct format *fmt;
     char *cp = NULL;
+    m_getfld_state_t gstate;
 
     /*
      * Open the message we'll be scanning for components
@@ -86,9 +87,10 @@ build_form (char *form, char *digest, int *dat, char *from, char *to,
      * these routines?
      */
 
-    for (state = FLD;;) {
+    m_getfld_state_init (&gstate);
+    for (;;) {
        int msg_count = sizeof msgbuf;
-       state = m_getfld(state, name, msgbuf, &msg_count, tmp);
+       state = m_getfld (gstate, name, msgbuf, &msg_count, tmp);
        switch (state) {
            case FLD:
            case FLDPLUS:
@@ -102,13 +104,13 @@ build_form (char *form, char *digest, int *dat, char *from, char *to,
                if (i != -1) {
                    while (state == FLDPLUS) {
                        msg_count = sizeof msgbuf;
-                       state = m_getfld(state, name, msgbuf, &msg_count, tmp);
+                       state = m_getfld (gstate, name, msgbuf, &msg_count, tmp);
                        fmt_appendcomp(i, name, msgbuf);
                    }
                }
                while (state == FLDPLUS)
                    msg_count = sizeof msgbuf;
-                   state = m_getfld(state, name, msgbuf, &msg_count, tmp);
+                   state = m_getfld (gstate, name, msgbuf, &msg_count, tmp);
                break;
 
            case LENERR:
@@ -121,6 +123,7 @@ build_form (char *form, char *digest, int *dat, char *from, char *to,
                adios(NULL, "m_getfld() returned %d", state);
        }
     }
+    m_getfld_state_destroy (&gstate);
 
     /*
      * Override any components just in case they were included in the
index 07440b123f3cd5e56f668dc28abcbbd45ba5c0dd..3d0830e564690a649ba82222a72a58ad74c341dd 100644 (file)
--- a/uip/inc.c
+++ b/uip/inc.c
@@ -46,6 +46,8 @@
 # define SASLminc(a)  0
 #endif
 
+extern m_getfld_state_t gstate;
+
 static struct swit switches[] = {
 #define        AUDSW                      0
     { "audit audit-file", 0 },
@@ -587,6 +589,8 @@ go_to_it:
        fflush (stdout);
     }
 
+    m_getfld_state_init (&gstate);
+
     /*
      * Get the mail from a POP server
      */
@@ -720,7 +724,7 @@ go_to_it:
      * Get the mail from file (usually mail spool)
      */
     if (inc_type == INC_FILE && Maildir == NULL) {
-       m_unknown (in);         /* the MAGIC invocation... */
+       m_unknown (gstate, in);         /* the MAGIC invocation... */
        hghnum = msgnum = mp->hghmsg;
        for (;;) {
            /*
@@ -887,6 +891,8 @@ go_to_it:
        free (Maildir); /* From now on Maildir is just a flag - don't dref! */
     }
 
+    m_getfld_state_destroy (&gstate);
+
     if (incerr < 0) {          /* error */
        if (locked) {
             GETGROUPPRIVS();      /* Be sure we can unlock mail file */
index 12479a54a94d9b42758751ec0affe98dc63cb01e..76c6dce026bea46139b02dfe1c687e7330244d65 100644 (file)
@@ -135,6 +135,7 @@ build_mime (char *infile, int directives)
     struct part **pp;
     CT ct;
     FILE *in;
+    m_getfld_state_t gstate;
 
     directive_init(directives);
 
@@ -162,9 +163,10 @@ build_mime (char *infile, int directives)
      * draft into the linked list of header fields for
      * the new MIME message.
      */
-    for (compnum = 1, state = FLD;;) {
+    m_getfld_state_init (&gstate);
+    for (compnum = 1;;) {
        int bufsz = sizeof buf;
-       switch (state = m_getfld (state, name, buf, &bufsz, in)) {
+       switch (state = m_getfld (gstate, name, buf, &bufsz, in)) {
        case FLD:
        case FLDPLUS:
            compnum++;
@@ -181,7 +183,7 @@ build_mime (char *infile, int directives)
            if (!mh_strcasecmp (name, TYPE_FIELD)) {
                while (state == FLDPLUS) {
                    bufsz = sizeof buf;
-                   state = m_getfld (state, name, buf, &bufsz, in);
+                   state = m_getfld (gstate, name, buf, &bufsz, in);
                }
                goto finish_field;
            }
@@ -193,7 +195,7 @@ build_mime (char *infile, int directives)
            /* if necessary, get rest of field */
            while (state == FLDPLUS) {
                bufsz = sizeof buf;
-               state = m_getfld (state, name, buf, &bufsz, in);
+               state = m_getfld (gstate, name, buf, &bufsz, in);
                vp = add (buf, vp);     /* add to previous value */
            }
 
@@ -221,6 +223,7 @@ finish_field:
        }
        break;
     }
+    m_getfld_state_destroy (&gstate);
 
     /*
      * Now add the MIME-Version header field
index 5970a9d1c322c3a522fafe27690bee24a97387e0..94c4bb34adefd97119e7a52f2d9d9b3c5ade39ff 100644 (file)
@@ -376,16 +376,18 @@ find_cache_aux2 (char *mapfile, char *id, char *mapname, int namelen)
     int        state;
     char buf[BUFSIZ], name[NAMESZ];
     FILE *fp;
+    m_getfld_state_t gstate;
 
     if (!(fp = lkfopen (mapfile, "r")))
        return NOTOK;
 
-    for (state = FLD;;) {
+    m_getfld_state_init (&gstate);
+    for (;;) {
        int result;
        char *cp, *dp;
        int bufsz = sizeof buf;
 
-       switch (state = m_getfld (state, name, buf, &bufsz, fp)) {
+       switch (state = m_getfld (gstate, name, buf, &bufsz, fp)) {
            case FLD:
            case FLDPLUS:
                strncpy (mapname, name, namelen);
@@ -395,7 +397,7 @@ find_cache_aux2 (char *mapfile, char *id, char *mapname, int namelen)
                    cp = add (buf, NULL);
                    while (state == FLDPLUS) {
                        bufsz = sizeof buf;
-                       state = m_getfld (state, name, buf, &bufsz, fp);
+                       state = m_getfld (gstate, name, buf, &bufsz, fp);
                        cp = add (buf, cp);
                    }
                }
@@ -420,6 +422,7 @@ find_cache_aux2 (char *mapfile, char *id, char *mapname, int namelen)
        }
        break;
     }
+    m_getfld_state_destroy (&gstate);
 
     lkfclose (fp, mapfile);
     return NOTOK;
index 2c24171437e4a6d826a3e445156935c4553b1bf0..bfa06873a3d281175258ca9fb01dc3942467b3d0 100644 (file)
@@ -353,7 +353,8 @@ static void quitser (int);
 static void mhladios (char *, char *, ...);
 static void mhldone (int);
 static void m_popen (char *);
-static void filterbody (struct mcomp *, char *, int, int, FILE *);
+static void filterbody (struct mcomp *, char *, int, int, FILE *,
+                        m_getfld_state_t);
 static void compile_formatfield(struct mcomp *);
 static void compile_filterargs (void);
 
@@ -953,6 +954,7 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec)
     int state, bucket;
     struct mcomp *c1, *c2, *c3;
     char **ip, name[NAMESZ], buf[BUFSIZ];
+    m_getfld_state_t gstate;
 
     compile_filterargs();
 
@@ -1014,9 +1016,10 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec)
        }
     }
 
-    for (state = FLD;;) {
+    m_getfld_state_init (&gstate);
+    for (;;) {
        int bufsz = sizeof buf;
-       switch (state = m_getfld (state, name, buf, &bufsz, fp)) {
+       switch (state = m_getfld (gstate, name, buf, &bufsz, fp)) {
            case FLD: 
            case FLDPLUS: 
                bucket = fmt_addcomptext(name, buf);
@@ -1024,7 +1027,7 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec)
                    if (!mh_strcasecmp (name, *ip)) {
                        while (state == FLDPLUS) {
                            bufsz = sizeof buf;
-                           state = m_getfld (state, name, buf, &bufsz, fp);
+                           state = m_getfld (gstate, name, buf, &bufsz, fp);
                            fmt_appendcomp(bucket, name, buf);
                        }
                        break;
@@ -1047,7 +1050,7 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec)
                    c1 = add_queue (&msghd, &msgtl, name, buf, 0);
                while (state == FLDPLUS) {
                    bufsz = sizeof buf;
-                   state = m_getfld (state, name, buf, &bufsz, fp);
+                   state = m_getfld (gstate, name, buf, &bufsz, fp);
                    c1->c_text = add (buf, c1->c_text);
                    fmt_appendcomp(bucket, name, buf);
                }
@@ -1080,14 +1083,14 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec)
                    if (dobody && !mh_strcasecmp (c1->c_name, "body")) {
                        if (c1->c_flags & FMTFILTER && state == BODY &&
                                                        formatproc != NULL) {
-                           filterbody(c1, buf, sizeof(buf), state, fp);
+                           filterbody(c1, buf, sizeof(buf), state, fp, gstate);
                        } else {
                            holder.c_text = mh_xmalloc (sizeof(buf));
                            strncpy (holder.c_text, buf, sizeof(buf));
                            while (state == BODY) {
                                putcomp (c1, &holder, BODYCOMP);
                                bufsz = sizeof buf;
-                               state = m_getfld (state, name, holder.c_text,
+                               state = m_getfld (gstate, name, holder.c_text,
                                            &bufsz, fp);
                            }
                            free (holder.c_text);
@@ -1114,6 +1117,7 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec)
                adios (NULL, "getfld() returned %d", state);
        }
     }
+    m_getfld_state_destroy (&gstate);
 }
 
 
@@ -1788,7 +1792,8 @@ compile_filterargs (void)
  */
 
 static void
-filterbody (struct mcomp *c1, char *buf, int bufsz, int state, FILE *fp)
+filterbody (struct mcomp *c1, char *buf, int bufsz, int state, FILE *fp,
+            m_getfld_state_t gstate)
 {
     struct mcomp holder;
     char name[NAMESZ];
@@ -1844,7 +1849,7 @@ filterbody (struct mcomp *c1, char *buf, int bufsz, int state, FILE *fp)
        while (state == BODY) {
            int bufsz2 = bufsz;
            write(fdinput[1], buf, strlen(buf));
-           state = m_getfld(state, name, buf, &bufsz2, fp);
+           state = m_getfld (gstate, name, buf, &bufsz2, fp);
        }
 
        /*
index ad499d019bfef80b7f919fdb60412a39b2cd0069..bf93b18ef51a0c4fd7befb1e1138af291e51e763 100644 (file)
@@ -262,6 +262,7 @@ get_content (FILE *in, char *file, int toplevel)
     char *np, *vp;
     CT ct;
     HF hp;
+    m_getfld_state_t gstate;
 
     /* allocate the content structure */
     if (!(ct = (CT) calloc (1, sizeof(*ct))))
@@ -275,9 +276,10 @@ get_content (FILE *in, char *file, int toplevel)
      * Parse the header fields for this
      * content into a linked list.
      */
-    for (compnum = 1, state = FLD;;) {
+    m_getfld_state_init (&gstate);
+    for (compnum = 1;;) {
        int bufsz = sizeof buf;
-       switch (state = m_getfld (state, name, buf, &bufsz, in)) {
+       switch (state = m_getfld (gstate, name, buf, &bufsz, in)) {
        case FLD:
        case FLDPLUS:
            compnum++;
@@ -289,7 +291,7 @@ get_content (FILE *in, char *file, int toplevel)
            /* if necessary, get rest of field */
            while (state == FLDPLUS) {
                bufsz = sizeof buf;
-               state = m_getfld (state, name, buf, &bufsz, in);
+               state = m_getfld (gstate, name, buf, &bufsz, in);
                vp = add (buf, vp);     /* add to previous value */
            }
 
@@ -319,6 +321,7 @@ get_content (FILE *in, char *file, int toplevel)
        /* break out of the loop */
        break;
     }
+    m_getfld_state_destroy (&gstate);
 
     /*
      * Read the content headers.  We will parse the
index cc2d5efb4f024b37c0249991c505ea3a0a65800a..7dc15d36fdd639e16ced955eb2507d2cd33129fe 100644 (file)
--- a/uip/msh.c
+++ b/uip/msh.c
@@ -150,6 +150,8 @@ int interrupted;            /* SIGINT detected  */
 int broken_pipe;               /* SIGPIPE detected */
 int told_to_quit;              /* SIGQUIT detected */
 
+extern m_getfld_state_t gstate;
+
 /*
  * prototypes
  */
@@ -342,6 +344,7 @@ main (int argc, char **argv)
 #endif /* SIGTSTP */
     }
 
+    m_getfld_state_init (&gstate);
     if (folder)
        fsetup (folder);
     else
@@ -350,6 +353,7 @@ main (int argc, char **argv)
     display_info (id > 0 ? scansw : 0);
 
     msh (id > 0 ? scansw : 0);
+    m_getfld_state_destroy (&gstate);
 
     m_reset ();
     
@@ -713,7 +717,7 @@ setup (char *file)
     mp->msgattrs[0] = getcpy ("unseen");
     mp->msgattrs[1] = NULL;
 
-    m_unknown (fp);            /* the MAGIC invocation */    
+    m_unknown (gstate, fp);            /* the MAGIC invocation */
     if (fmsh) {
        free (fmsh);
        fmsh = NULL;
@@ -836,7 +840,7 @@ msh_ready (int msgnum, int full)
        return yp;
     }
 
-    m_eomsbr ((int (*)()) 0);  /* XXX */
+    m_eomsbr (gstate, (int (*)()) 0);  /* XXX */
     fseek (fp, Msgs[msgnum].m_start, SEEK_SET);
     return fp;
 }
@@ -1005,16 +1009,16 @@ readid (int msgnum)
        return Msgs[msgnum].m_bboard_id;
 
     zp = msh_ready (msgnum, 0);
-    for (state = FLD;;) {
+    for (;;) {
        int bufsz = sizeof buf;
-       switch (state = m_getfld (state, name, buf, &bufsz, zp)) {
+       switch (state = m_getfld (gstate, name, buf, &bufsz, zp)) {
            case FLD: 
            case FLDPLUS: 
                if (!mh_strcasecmp (name, BBoard_ID)) {
                    bp = getcpy (buf);
                    while (state == FLDPLUS) {
                        bufsz = sizeof buf;
-                       state = m_getfld (state, name, buf, &bufsz, zp);
+                       state = m_getfld (gstate, name, buf, &bufsz, zp);
                        bp = add (buf, bp);
                    }
                    i = atoi (bp);
@@ -1026,7 +1030,7 @@ readid (int msgnum)
                }
                while (state == FLDPLUS)
                    bufsz = sizeof buf;
-                   state = m_getfld (state, name, buf, &bufsz, zp);
+                   state = m_getfld (gstate, name, buf, &bufsz, zp);
                continue;
 
            default: 
index cdda3c99b5a52cecf7412ed7c884bb4d80280952..9ab1592eb5471289b15405e3259dea4fea1adf7c 100644 (file)
@@ -51,6 +51,8 @@ static int process (int, char *, int, char **);
 static void copy_message (int, FILE *);
 static void copy_digest (int, FILE *);
 
+extern m_getfld_state_t gstate;
+
 void
 forkcmd (char **args, char *pgm)
 {
@@ -984,7 +986,7 @@ forw (char *proc, char *filter, int vecp, char **vec)
                        args[i++] = getcpy (m_name (msgnum));
                args[i] = NULL;
                mhlsbr (i, args, mhl_action);
-               m_eomsbr ((int (*) ()) 0);
+               m_eomsbr (gstate, (int (*) ()) 0);
                fclose (stdout);
                _exit (0);
 
@@ -2305,7 +2307,7 @@ finish: ;
        if (mp->numsel == 1 && headersw)
            show (mp->lowsel);
        mhlsbr (vecp, vec, mhl_action);
-       m_eomsbr ((int (*)()) 0);
+       m_eomsbr (gstate, (int (*)()) 0);
        while (msgp < vecp)
            free (vec[msgp++]);
     } else {
@@ -2377,7 +2379,7 @@ mhl_action (char *name)
 
     mhlfp = msh_ready (msgnum, 1);
     if (!fmsh)
-       m_eomsbr (eom_action);
+       m_eomsbr (gstate, eom_action);
 
     return mhlfp;
 }
@@ -2435,9 +2437,9 @@ is_nontext (int msgnum)
 
     fp = msh_ready (msgnum, 1);
 
-    for (state = FLD;;) {
+    for (;;) {
        int bufsz = sizeof buf;
-       switch (state = m_getfld (state, name, buf, &bufsz, fp)) {
+       switch (state = m_getfld (gstate, name, buf, &bufsz, fp)) {
        case FLD:
        case FLDPLUS:
            /*
@@ -2450,7 +2452,7 @@ is_nontext (int msgnum)
                cp = add (buf, NULL);
                while (state == FLDPLUS) {
                    bufsz = sizeof buf;
-                   state = m_getfld (state, name, buf, &bufsz, fp);
+                   state = m_getfld (gstate, name, buf, &bufsz, fp);
                    cp = add (buf, cp);
                }
                bp = cp;
@@ -2554,7 +2556,7 @@ out:
                cp = add (buf, NULL);
                while (state == FLDPLUS) {
                    bufsz = sizeof buf;
-                   state = m_getfld (state, name, buf, &bufsz, fp);
+                   state = m_getfld (gstate, name, buf, &bufsz, fp);
                    cp = add (buf, cp);
                }
                for (bp = cp; isspace (*bp); bp++)
@@ -2580,7 +2582,7 @@ out:
             */
            while (state == FLDPLUS) {
                bufsz = sizeof buf;
-               state = m_getfld (state, name, buf, &bufsz, fp);
+               state = m_getfld (gstate, name, buf, &bufsz, fp);
            }
            break;
 
@@ -2746,16 +2748,17 @@ get_fields (char *datesw, char *subjsw, int msgnum, struct Msg *msgp)
     register FILE *zp;
 
     zp = msh_ready (msgnum, 0);
-    for (state = FLD;;) {
+
+    for (;;) {
        int bufsz = sizeof buf;
-       switch (state = m_getfld (state, name, buf, &bufsz, zp)) {
+       switch (state = m_getfld (gstate, name, buf, &bufsz, zp)) {
            case FLD: 
            case FLDPLUS: 
                if (!mh_strcasecmp (name, datesw)) {
                    bp = getcpy (buf);
                    while (state == FLDPLUS) {
                        bufsz = sizeof buf;
-                       state = m_getfld (state, name, buf, &bufsz, zp);
+                       state = m_getfld (gstate, name, buf, &bufsz, zp);
                        bp = add (buf, bp);
                    }
                    if ((tw = dparsetime (bp)) == NULL)
@@ -2773,7 +2776,7 @@ get_fields (char *datesw, char *subjsw, int msgnum, struct Msg *msgp)
                    bp = getcpy (buf);
                    while (state == FLDPLUS) {
                        bufsz = sizeof buf;
-                       state = m_getfld (state, name, buf, &bufsz, zp);
+                       state = m_getfld (gstate, name, buf, &bufsz, zp);
                        bp = add (buf, bp);
                    }
                    msgp->m_scanl = sosmash(subjsw, bp);
@@ -2784,7 +2787,7 @@ get_fields (char *datesw, char *subjsw, int msgnum, struct Msg *msgp)
                } else {
                    while (state == FLDPLUS) {  /* flush this one */
                        bufsz = sizeof buf;
-                       state = m_getfld (state, name, buf, &bufsz, zp);
+                       state = m_getfld (gstate, name, buf, &bufsz, zp);
                    }
                }
                continue;
index 7bef56ace35b7d2a2c0fc6617b6668352b22c15b..666bc108e01c941033e5829e64a42802932efce9 100644 (file)
--- a/uip/new.c
+++ b/uip/new.c
@@ -97,6 +97,7 @@ get_msgnums(char *folder, char *sequences[])
     char name[NAMESZ], field[BUFSIZ];
     char *cp;
     char *msgnums = NULL, *this_msgnums, *old_msgnums;
+    m_getfld_state_t gstate;
 
     /* no sequences file -> no messages */
     if (fp == NULL) {
@@ -104,16 +105,17 @@ get_msgnums(char *folder, char *sequences[])
     }
 
     /* copied from seq_read.c:seq_public */
-    for (state = FLD;;) {
+    m_getfld_state_init (&gstate);
+    for (;;) {
        int fieldsz = sizeof field;
-       switch (state = m_getfld (state, name, field, &fieldsz, fp)) {
+       switch (state = m_getfld (gstate, name, field, &fieldsz, fp)) {
             case FLD:
             case FLDPLUS:
                 if (state == FLDPLUS) {
                     cp = getcpy (field);
                     while (state == FLDPLUS) {
                        fieldsz = sizeof field;
-                       state = m_getfld (state, name, field, &fieldsz, fp);
+                       state = m_getfld (gstate, name, field, &fieldsz, fp);
                         cp = add (field, cp);
                     }
 
@@ -162,6 +164,7 @@ get_msgnums(char *folder, char *sequences[])
         }
         break;  /* break from for loop */
     }
+    m_getfld_state_destroy (&gstate);
 
     fclose(fp);
 
index 5fa731890b25d79e71fce1f13891dfbfa9f55040..0acdedf0b9862dfb140d5bd8517599555f24e4d5 100644 (file)
@@ -943,12 +943,14 @@ plist
     register char *bp;
     char buf[BUFSIZ], name[NAMESZ];
     register struct tws *tw;
+    m_getfld_state_t gstate;
     NMH_UNUSED (stop);
 
     fseek (fp, start, SEEK_SET);
-    for (state = FLD, bp = NULL;;) {
+    m_getfld_state_init (&gstate);
+    for (bp = NULL;;) {
        int bufsz = sizeof buf;
-       switch (state = m_getfld (state, name, buf, &bufsz, fp)) {
+       switch (state = m_getfld (gstate, name, buf, &bufsz, fp)) {
            case FLD: 
            case FLDPLUS: 
                if (bp != NULL)
@@ -956,7 +958,7 @@ plist
                bp = add (buf, NULL);
                while (state == FLDPLUS) {
                    bufsz = sizeof buf;
-                   state = m_getfld (state, name, buf, &bufsz, fp);
+                   state = m_getfld (gstate, name, buf, &bufsz, fp);
                    bp = add (buf, bp);
                }
                if (!mh_strcasecmp (name, n->n_datef))
@@ -978,6 +980,7 @@ plist
        }
        break;
     }
+    m_getfld_state_destroy (&gstate);
 
     if ((tw = dparsetime (bp)) == NULL)
        advise (NULL, "unable to parse %s field in message %d, matching...",
index 10ebd2aca20869d6224ddd282c9852f32acedd89..972a97ccf75f4afbe76e3fdf69208ad4b05f4442 100644 (file)
@@ -322,6 +322,7 @@ main (int argc, char **argv)
     char *cp, *msg = NULL, **argp, **arguments, *envelope;
     char buf[BUFSIZ], name[NAMESZ];
     FILE *in, *out;
+    m_getfld_state_t gstate;
 
 #ifdef LOCALE
     setlocale(LC_ALL, "");
@@ -578,16 +579,17 @@ main (int argc, char **argv)
 
     hdrtab = msgstate == NORMAL ? NHeaders : RHeaders;
 
-    for (compnum = 1, state = FLD;;) {
+    m_getfld_state_init (&gstate);
+    for (compnum = 1;;) {
        int bufsz = sizeof buf;
-       switch (state = m_getfld (state, name, buf, &bufsz, in)) {
+       switch (state = m_getfld (gstate, name, buf, &bufsz, in)) {
            case FLD: 
            case FLDPLUS: 
                compnum++;
                cp = add (buf, NULL);
                while (state == FLDPLUS) {
                    bufsz = sizeof buf;
-                   state = m_getfld (state, name, buf, &bufsz, in);
+                   state = m_getfld (gstate, name, buf, &bufsz, in);
                    cp = add (buf, cp);
                }
                putfmt (name, cp, out);
@@ -601,7 +603,7 @@ main (int argc, char **argv)
                fprintf (out, "\n%s", buf);
                while (state == BODY) {
                    bufsz = sizeof buf;
-                   state = m_getfld (state, name, buf, &bufsz, in);
+                   state = m_getfld (gstate, name, buf, &bufsz, in);
                    fputs (buf, out);
                }
                break;
@@ -619,6 +621,7 @@ main (int argc, char **argv)
        }
        break;
     }
+    m_getfld_state_destroy (&gstate);
 
     if (pfd != NOTOK)
        anno ();
index a62f415e23530299db6edee692f582b5556e4903..1691547e426f05ee2142d5c6fc6c386869a1312b 100644 (file)
@@ -84,6 +84,7 @@ main (int argc, char **argv)
     char **arguments, **argp;
     FILE *in, *out;
     char *tfile = NULL;
+    m_getfld_state_t gstate;
 
 #ifdef LOCALE
     setlocale(LC_ALL, "");
@@ -208,9 +209,10 @@ main (int argc, char **argv)
     /*
      * Loop through the lines of the draft skeleton.
      */
-    for (state = FLD;;) {
+    m_getfld_state_init (&gstate);
+    for (;;) {
        int fieldsz = sizeof field;
-       switch (state = m_getfld (state, name, field, &fieldsz, in)) {
+       switch (state = m_getfld (gstate, name, field, &fieldsz, in)) {
            case FLD: 
            case FLDPLUS: 
                /*
@@ -227,7 +229,7 @@ main (int argc, char **argv)
                    fprintf (out, "%s:%s", name, field);
                    while (state == FLDPLUS) {
                        fieldsz = sizeof field;
-                       state = m_getfld (state, name, field, &fieldsz, in);
+                       state = m_getfld (gstate, name, field, &fieldsz, in);
                        printf ("%s", field);
                        fprintf (out, "%s", field);
                    }
@@ -286,7 +288,7 @@ abort:
                            printf ("%s", field);
                    } while (state == BODY &&
                            (fieldsz = sizeof field,
-                            state = m_getfld (state, name, field, &fieldsz, in)));
+                            state = m_getfld (gstate, name, field, &fieldsz, in)));
                    if (prepend || !body)
                        break;
                    else
@@ -309,6 +311,7 @@ abort:
        }
        break;
     }
+    m_getfld_state_destroy (&gstate);
 
     if (body)
        printf ("--------\n");
index fd58396a3874c0a4433bfc1403af1ce8ccdbf9d4..c11ac491658aced59243b391d74b88abafeaf6e6 100644 (file)
@@ -173,6 +173,7 @@ rcvdistout (FILE *inb, char *form, char *addrs)
     char *cp, *scanl, name[NAMESZ], tmpbuf[SBUFSIZ];
     register struct comp *cptr;
     FILE *out;
+    m_getfld_state_t gstate;
 
     if (!(out = fopen (drft, "w")))
        adios (drft, "unable to create");
@@ -192,9 +193,10 @@ rcvdistout (FILE *inb, char *form, char *addrs)
     if (cptr)
        cptr->c_text = addrs;
 
-    for (state = FLD;;) {
+    m_getfld_state_init (&gstate);
+    for (;;) {
        int msg_count = SBUFSIZ;
-       switch (state = m_getfld (state, name, tmpbuf, &msg_count, inb)) {
+       switch (state = m_getfld (gstate, name, tmpbuf, &msg_count, inb)) {
            case FLD: 
            case FLDPLUS: 
                i = fmt_addcomptext(name, tmpbuf);
@@ -202,7 +204,7 @@ rcvdistout (FILE *inb, char *form, char *addrs)
                    char_read += msg_count;
                    while (state == FLDPLUS) {
                        msg_count = SBUFSIZ;
-                       state = m_getfld (state, name, tmpbuf, &msg_count, inb);
+                       state = m_getfld (gstate, name, tmpbuf, &msg_count, inb);
                        fmt_appendcomp(i, name, tmpbuf);
                        char_read += msg_count;
                    }
@@ -210,7 +212,7 @@ rcvdistout (FILE *inb, char *form, char *addrs)
 
                while (state == FLDPLUS) {
                    msg_count = SBUFSIZ;
-                   state = m_getfld (state, name, tmpbuf, &msg_count, inb);
+                   state = m_getfld (gstate, name, tmpbuf, &msg_count, inb);
                }
                break;
 
@@ -225,6 +227,7 @@ rcvdistout (FILE *inb, char *form, char *addrs)
        }
     }
 finished: ;
+    m_getfld_state_destroy (&gstate);
 
     i = format_len + char_read + 256;
     scanl = mh_xmalloc ((size_t) i + 2);
index 29f2dd9d639845cbdfaef1d1ece030ede7e43299..25288d845f0304dd83aa1991d36bc926656c7ef1 100644 (file)
@@ -31,6 +31,8 @@
 %<(mymbox{from})%<{to}To:%14(friendly{to})%>%>%<(zero)%17(friendly{from})%>  \
 %{subject}%<{body}<<%{body}>>%>"
 
+extern m_getfld_state_t gstate;
+
 static struct swit switches[] = {
 #define        BIFFSW  0
     { "biff", 0 },
@@ -260,7 +262,9 @@ header_fd (void)
 
     /* get new format string */
     nfs = new_fs (form, format, SCANFMT);
+    m_getfld_state_init (&gstate);
     scan (stdin, 0, 0, nfs, width, 0, 0, NULL, 0L, 0);
+    m_getfld_state_destroy (&gstate);
     if (newline)
         write (fd, "\n\r", 2);
     write (fd, scanl, strlen (scanl));
index dc3c4f8c36c5ccda1a3effd29a4a21a501effe88..c0ffb726453c35122574213d581aa5e487117087 100644 (file)
@@ -72,6 +72,7 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen,
     char name[NAMESZ], *scanl;
     unsigned char *cp;
     static int dat[5];                 /* aux. data for format routine */
+    m_getfld_state_t gstate;
 
     FILE *out;
     NMH_UNUSED (msg);
@@ -131,9 +132,10 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen,
     /*
      * pick any interesting stuff out of msg "inb"
      */
-    for (state = FLD;;) {
+    m_getfld_state_init (&gstate);
+    for (;;) {
        int msg_count = sizeof tmpbuf;
-       state = m_getfld (state, name, tmpbuf, &msg_count, inb);
+       state = m_getfld (gstate, name, tmpbuf, &msg_count, inb);
        switch (state) {
            case FLD: 
            case FLDPLUS: 
@@ -149,7 +151,7 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen,
                    char_read += msg_count;
                    while (state == FLDPLUS) {
                        msg_count= sizeof tmpbuf;
-                       state = m_getfld(state, name, tmpbuf, &msg_count, inb);
+                       state = m_getfld (gstate, name, tmpbuf, &msg_count, inb);
                        fmt_appendcomp(i, name, tmpbuf);
                        char_read += msg_count;
                    }
@@ -157,7 +159,7 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen,
 
                while (state == FLDPLUS) {
                    msg_count= sizeof tmpbuf;
-                   state = m_getfld (state, name, tmpbuf, &msg_count, inb);
+                   state = m_getfld (gstate, name, tmpbuf, &msg_count, inb);
                }
                break;
 
@@ -171,6 +173,7 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen,
                adios (NULL, "m_getfld() returned %d", state);
        }
     }
+    m_getfld_state_destroy (&gstate);
 
     /*
      * format and output the header lines.
index 08c893b33211b00b8660c1b2b1f336613017e465..06b12c62f9e59481af6b429e6ee09e6215ac9c86 100644 (file)
@@ -51,6 +51,8 @@ static struct swit switches[] = {
 extern struct msgs *fmt_current_folder;        
 #endif
 
+extern m_getfld_state_t gstate;
+
 /*
  * prototypes
  */
@@ -188,13 +190,15 @@ main (int argc, char **argv)
            printf ("FOLDER %s\t%s\n", file, dtimenow (1));
        }
 
-       m_unknown (in);
+       m_getfld_state_init (&gstate);
+       m_unknown (gstate, in);
        for (msgnum = 1; ; ++msgnum) {
            state = scan (in, msgnum, -1, nfs, width, 0, 0,
                    hdrflag ? file : NULL, 0L, 1);
            if (state != SCNMSG && state != SCNENC)
                break;
        }
+       m_getfld_state_destroy (&gstate);
        fclose (in);
        done (0);
     }
@@ -279,6 +283,7 @@ main (int argc, char **argv)
                }
            }
 
+           m_getfld_state_init (&gstate);
            switch (state = scan (in, msgnum, 0, nfs, width,
                        msgnum == mp->curmsg, unseen,
                        folder, 0L, 1)) {
@@ -294,12 +299,14 @@ main (int argc, char **argv)
                    advise (NULL, "message %d: empty", msgnum);
                    break;
            }
+           m_getfld_state_destroy (&gstate);
            hdrflag = 0;
            fclose (in);
            if (ontty)
                fflush (stdout);
        }
     }
+    m_getfld_state_destroy (&gstate);
 
 #ifdef LBL
     seq_save (mp);     /* because formatsbr might have made changes */
index f863e9b78fd40defa419ea7904a7b20e4a354aec..9f77f86bb7d079ec709216f7e56caa5ce5a0f262 100644 (file)
@@ -14,6 +14,8 @@
 #include <h/tws.h>
 #include <h/utils.h>
 
+m_getfld_state_t gstate;
+
 #define MAXSCANL 256           /* longest possible scan line */
 
 /*
@@ -164,7 +166,8 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg,
      * and we're doing an "inc", open the output file.
      */
     bufsz = rlwidth;
-    if ((state = m_getfld (FLD, name, tmpbuf, &bufsz, inb)) == FILEEOF) {
+    m_getfld_state_reset (&gstate);
+    if ((state = m_getfld (gstate, name, tmpbuf, &bufsz, inb)) == FILEEOF) {
        if (ferror(inb)) {
            advise("read", "unable to"); /* "read error" */
            return SCNFAT;
@@ -187,7 +190,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg,
 
     /* scan - main loop */
     for (compnum = 1; ;
-       bufsz = rlwidth, state = m_getfld (state, name, tmpbuf, &bufsz, inb)) {
+       bufsz = rlwidth, state = m_getfld (gstate, name, tmpbuf, &bufsz, inb)) {
        switch (state) {
            case FLD: 
            case FLDPLUS: 
@@ -219,7 +222,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg,
 
                while (state == FLDPLUS) {
                    bufsz = rlwidth;
-                   state = m_getfld (state, name, tmpbuf, &bufsz, inb);
+                   state = m_getfld (gstate, name, tmpbuf, &bufsz, inb);
                    if (outnum)
                        FPUTS (tmpbuf);
                }
@@ -234,7 +237,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg,
 
                if ((i = strlen(tmpbuf)) < rlwidth) {
                    bufsz = rlwidth - i;
-                   state = m_getfld (state, name, tmpbuf + i, &bufsz, inb);
+                   state = m_getfld (gstate, name, tmpbuf + i, &bufsz, inb);
                }
 
                if (! outnum) {
@@ -269,7 +272,7 @@ body:;
 
                while (state == BODY) {
                    bufsz = rlwidth;
-                   state = m_getfld(state, name, tmpbuf, &bufsz, inb);
+                   state = m_getfld (gstate, name, tmpbuf, &bufsz, inb);
                    FPUTS(tmpbuf);
                }
                goto finished;
index 125bc027f06b8389ee010903f0fefef7e2ef31e5..d8fc9c7a1341ef405b8de290f413340c99d8821c 100644 (file)
@@ -591,6 +591,7 @@ splitmsg (char **vec, int vecp, char *drft, struct stat *st, int delay)
     char subject[BUFSIZ];
     char name[NAMESZ], partnum[BUFSIZ];
     FILE *in;
+    m_getfld_state_t gstate;
 
     if ((in = fopen (drft, "r")) == NULL)
        adios (drft, "unable to open for reading");
@@ -602,9 +603,10 @@ splitmsg (char **vec, int vecp, char *drft, struct stat *st, int delay)
      * Scan through the message and examine the various header fields,
      * as well as locate the beginning of the message body.
      */
-    for (compnum = 1, state = FLD;;) {
+    m_getfld_state_init (&gstate);
+    for (compnum = 1;;) {
        int bufsz = sizeof buffer;
-       switch (state = m_getfld (state, name, buffer, &bufsz, in)) {
+       switch (state = m_getfld (gstate, name, buffer, &bufsz, in)) {
            case FLD:
            case FLDPLUS:
                compnum++;
@@ -615,7 +617,7 @@ splitmsg (char **vec, int vecp, char *drft, struct stat *st, int delay)
                if (!mh_strcasecmp (name, "Message-ID")) {
                    while (state == FLDPLUS) {
                        bufsz = sizeof buffer;
-                       state = m_getfld (state, name, buffer, &bufsz, in);
+                       state = m_getfld (gstate, name, buffer, &bufsz, in);
                    }
                } else if (uprf (name, XXX_FIELD_PRF)
                        || !mh_strcasecmp (name, VRSN_FIELD)
@@ -641,7 +643,7 @@ splitmsg (char **vec, int vecp, char *drft, struct stat *st, int delay)
                    dp = add (concat (name, ":", buffer, NULL), dp);
                    while (state == FLDPLUS) {
                        bufsz = sizeof buffer;
-                       state = m_getfld (state, name, buffer, &bufsz, in);
+                       state = m_getfld (gstate, name, buffer, &bufsz, in);
                        dp = add (buffer, dp);
                    }
                } else {
@@ -652,7 +654,7 @@ splitmsg (char **vec, int vecp, char *drft, struct stat *st, int delay)
                    cp = add (concat (name, ":", buffer, NULL), cp);
                    while (state == FLDPLUS) {
                        bufsz = sizeof buffer;
-                       state = m_getfld (state, name, buffer, &bufsz, in);
+                       state = m_getfld (gstate, name, buffer, &bufsz, in);
                        cp = add (buffer, cp);
                    }
                }
@@ -674,6 +676,7 @@ splitmsg (char **vec, int vecp, char *drft, struct stat *st, int delay)
 
        break;
     }
+    m_getfld_state_destroy (&gstate);
     if (cp == NULL)
        adios (NULL, "headers missing from draft");
 
index dade251c48c16128238d638ada576fae3563b79f..d04835e67fd5c5a1b806722a9a7a6a56513db209 100644 (file)
@@ -348,13 +348,15 @@ is_nontext (char *msgnam)
     char *cp;
     char buf[BUFSIZ], name[NAMESZ];
     FILE *fp;
+    m_getfld_state_t gstate;
 
     if ((fp = fopen (msgnam, "r")) == NULL)
        return 0;
 
-    for (state = FLD;;) {
+    m_getfld_state_init (&gstate);
+    for (;;) {
        int bufsz = sizeof buf;
-       switch (state = m_getfld (state, name, buf, &bufsz, fp)) {
+       switch (state = m_getfld (gstate, name, buf, &bufsz, fp)) {
        case FLD:
        case FLDPLUS:
            /*
@@ -367,7 +369,7 @@ is_nontext (char *msgnam)
                cp = add (buf, NULL);
                while (state == FLDPLUS) {
                    bufsz = sizeof buf;
-                   state = m_getfld (state, name, buf, &bufsz, fp);
+                   state = m_getfld (gstate, name, buf, &bufsz, fp);
                    cp = add (buf, cp);
                }
                bp = cp;
@@ -471,7 +473,7 @@ out:
                cp = add (buf, NULL);
                while (state == FLDPLUS) {
                    bufsz = sizeof buf;
-                   state = m_getfld (state, name, buf, &bufsz, fp);
+                   state = m_getfld (gstate, name, buf, &bufsz, fp);
                    cp = add (buf, cp);
                }
                for (bp = cp; isspace (*bp); bp++)
@@ -497,7 +499,7 @@ out:
             */
            while (state == FLDPLUS) {
                bufsz = sizeof buf;
-               state = m_getfld (state, name, buf, &bufsz, fp);
+               state = m_getfld (gstate, name, buf, &bufsz, fp);
            }
            break;
 
@@ -510,4 +512,5 @@ out:
            return 0;
        }
     }
+    m_getfld_state_destroy (&gstate);
 }
index a665d0ad9bc2070186ef617ae148687df1aa6090..d8d427a4e4dcfa9382b431b831535d36a587ee47 100644 (file)
@@ -716,6 +716,7 @@ parse (int fd)
     char name[NAMESZ], field[BUFSIZ];
     struct pair *p, *q;
     FILE  *in;
+    m_getfld_state_t gstate;
 
     if (parsed++)
        return 0;
@@ -739,15 +740,16 @@ parse (int fd)
      * Scan the headers of the message and build
      * a lookup table.
      */
-    for (i = 0, state = FLD;;) {
+    m_getfld_state_init (&gstate);
+    for (i = 0;;) {
        int fieldsz = sizeof field;
-       switch (state = m_getfld (state, name, field, &fieldsz, in)) {
+       switch (state = m_getfld (gstate, name, field, &fieldsz, in)) {
            case FLD: 
            case FLDPLUS: 
                lp = add (field, NULL);
                while (state == FLDPLUS) {
                    fieldsz = sizeof field;
-                   state = m_getfld (state, name, field, &fieldsz, in);
+                   state = m_getfld (gstate, name, field, &fieldsz, in);
                    lp = add (field, lp);
                }
                for (p = hdrs; p->p_name; p++) {
@@ -794,6 +796,7 @@ parse (int fd)
        }
        break;
     }
+    m_getfld_state_destroy (&gstate);
     fclose (in);
 
     if ((p = lookup (vars, "reply-to"))) {
@@ -1412,6 +1415,7 @@ suppress_duplicates (int fd, char *file)
     datum key, value;
     DBM *db;
     FILE *in;
+    m_getfld_state_t gstate;
 
     if ((fd1 = dup (fd)) == -1)
        return -1;
@@ -1421,9 +1425,10 @@ suppress_duplicates (int fd, char *file)
     }
     rewind (in);
 
-    for (state = FLD;;) {
+    m_getfld_state_init (&gstate);
+    for (;;) {
        int bufsz = sizeof buf;
-       state = m_getfld (state, name, buf, &bufsz, in);
+       state = m_getfld (gstate, name, buf, &bufsz, in);
        switch (state) {
            case FLD:
            case FLDPLUS:
@@ -1431,7 +1436,7 @@ suppress_duplicates (int fd, char *file)
                if (mh_strcasecmp (name, "Message-ID")) {
                    while (state == FLDPLUS) {
                        bufsz = sizeof buf;
-                       state = m_getfld (state, name, buf, &bufsz, in);
+                       state = m_getfld (gstate, name, buf, &bufsz, in);
                    }
                    continue;
                }
@@ -1439,7 +1444,7 @@ suppress_duplicates (int fd, char *file)
                cp = add (buf, NULL);
                while (state == FLDPLUS) {
                    bufsz = sizeof buf;
-                   state = m_getfld (state, name, buf, &bufsz, in);
+                   state = m_getfld (gstate, name, buf, &bufsz, in);
                    cp = add (buf, cp);
                }
                key.dptr = trimcpy (cp);
@@ -1498,6 +1503,7 @@ suppress_duplicates (int fd, char *file)
 
        break;
     }
+    m_getfld_state_destroy (&gstate);
 
     fclose (in);
     return 0;
index b4e6d56e213a0f59b79bdd95809e91d7886450a5..b8df0d0ba761b1264c343d8bd604477b27c9367c 100644 (file)
@@ -365,14 +365,16 @@ get_fields (char *datesw, int msg, struct smsg *smsg)
     register struct tws *tw;
     register char *datecomp = NULL, *subjcomp = NULL;
     register FILE *in;
+    m_getfld_state_t gstate;
 
     if ((in = fopen (msgnam = m_name (msg), "r")) == NULL) {
        admonish (msgnam, "unable to read message");
        return (0);
     }
-    for (compnum = 1, state = FLD;;) {
+    m_getfld_state_init (&gstate);
+    for (compnum = 1;;) {
        int bufsz = sizeof buf;
-       switch (state = m_getfld (state, nam, buf, &bufsz, in)) {
+       switch (state = m_getfld (gstate, nam, buf, &bufsz, in)) {
        case FLD:
        case FLDPLUS:
            compnum++;
@@ -380,7 +382,7 @@ get_fields (char *datesw, int msg, struct smsg *smsg)
                datecomp = add (buf, datecomp);
                while (state == FLDPLUS) {
                    bufsz = sizeof buf;
-                   state = m_getfld (state, nam, buf, &bufsz, in);
+                   state = m_getfld (gstate, nam, buf, &bufsz, in);
                    datecomp = add (buf, datecomp);
                }
                if (!subjsort || subjcomp)
@@ -389,7 +391,7 @@ get_fields (char *datesw, int msg, struct smsg *smsg)
                subjcomp = add (buf, subjcomp);
                while (state == FLDPLUS) {
                    bufsz = sizeof buf;
-                   state = m_getfld (state, nam, buf, &bufsz, in);
+                   state = m_getfld (gstate, nam, buf, &bufsz, in);
                    subjcomp = add (buf, subjcomp);
                }
                if (datecomp)
@@ -398,7 +400,7 @@ get_fields (char *datesw, int msg, struct smsg *smsg)
                /* just flush this guy */
                while (state == FLDPLUS) {
                    bufsz = sizeof buf;
-                   state = m_getfld (state, nam, buf, &bufsz, in);
+                   state = m_getfld (gstate, nam, buf, &bufsz, in);
                }
            }
            continue;
@@ -426,6 +428,7 @@ get_fields (char *datesw, int msg, struct smsg *smsg)
        }
        break;
     }
+    m_getfld_state_destroy (&gstate);
 
     /*
      * If no date component, then use the modification
index 66cf41ffe4eb39db8f56fb7c103951c1ffa90e0f..d3f0fcf83e661d81be3d89d202b71cf84dd163df 100644 (file)
@@ -938,12 +938,14 @@ check_draft (char *msgnam)
     int        state;
     char buf[BUFSIZ], name[NAMESZ];
     FILE *fp;
+    m_getfld_state_t gstate;
 
     if ((fp = fopen (msgnam, "r")) == NULL)
        return 0;
-    for (state = FLD;;) {
+    m_getfld_state_init (&gstate);
+    for (;;) {
        int bufsz = sizeof buf;
-       switch (state = m_getfld (state, name, buf, &bufsz, fp)) {
+       switch (state = m_getfld (gstate, name, buf, &bufsz, fp)) {
            case FLD:
            case FLDPLUS:
                /*
@@ -957,7 +959,7 @@ check_draft (char *msgnam)
                }
                while (state == FLDPLUS) {
                    bufsz = sizeof buf;
-                   state = m_getfld (state, name, buf, &bufsz, fp);
+                   state = m_getfld (gstate, name, buf, &bufsz, fp);
                }
                break;
 
@@ -972,7 +974,7 @@ check_draft (char *msgnam)
                        }
 
                    bufsz = sizeof buf;
-                   state = m_getfld (state, name, buf, &bufsz, fp);
+                   state = m_getfld (gstate, name, buf, &bufsz, fp);
                } while (state == BODY);
                /* and fall... */
 
@@ -981,6 +983,7 @@ check_draft (char *msgnam)
                return 0;
        }
     }
+    m_getfld_state_destroy (&gstate);
 }