Convert most of the tools from m_getfld() to m_getfld2()
authormarkus schnalke <meillo@marmaro.de>
Mon, 9 Nov 2015 21:07:54 +0000 (22:07 +0100)
committermarkus schnalke <meillo@marmaro.de>
Mon, 9 Nov 2015 21:07:54 +0000 (22:07 +0100)
13 files changed:
sbr/readconfig.c
sbr/seq_read.c
uip/distsbr.c
uip/mhbuild.c
uip/mhl.c
uip/mhparse.c
uip/new.c
uip/pick.c
uip/prompter.c
uip/slocal.c
uip/sortm.c
uip/spost.c
uip/whom.c

index bc9329f..ccdf867 100644 (file)
@@ -36,9 +36,8 @@ static struct node **opp = NULL;
 void
 readconfig(struct node **npp, FILE *ib, char *file, int ctx)
 {
-       int state;
-       char *cp;
-       char name[NAMESZ], field[BUFSIZ];
+       enum state state;
+       struct field f = {{0}};
        struct node *np;
        struct procstr *ps;
 
@@ -47,46 +46,34 @@ readconfig(struct node **npp, FILE *ib, char *file, int ctx)
                return;
        }
 
-       for (state = FLD;;) {
-               switch (state = m_getfld(state, name, field, sizeof(field),
-                               ib)) {
-               case FLD:
-               case FLDPLUS:
+       for (state = FLD2;;) {
+               switch (state = m_getfld2(state, &f, ib)) {
+               case FLD2:
                        np = (struct node *) mh_xmalloc(sizeof(*np));
                        *npp = np;
                        *(npp = &np->n_next) = NULL;
-                       np->n_name = getcpy(name);
-                       if (state == FLDPLUS) {
-                               cp = getcpy(field);
-                               while (state == FLDPLUS) {
-                                       state = m_getfld(state, name, field,
-                                                       sizeof(field), ib);
-                                       cp = add(field, cp);
-                               }
-                               np->n_field = trimcpy(cp);
-                               free(cp);
-                       } else {
-                               np->n_field = trimcpy(field);
-                       }
+                       np->n_name = getcpy(f.name);
+                       np->n_field = trimcpy(f.value);
                        np->n_context = ctx;
 
                        /*
                        ** Now scan the list of `procs' and link in
                        ** the field value to the global variable.
                        */
-                       for (ps = procs; ps->procname; ps++)
+                       for (ps = procs; ps->procname; ps++) {
                                if (mh_strcasecmp(np->n_name,
                                                ps->procname) == 0) {
                                        *ps->procnaddr = np->n_field;
                                        break;
                                }
+                       }
                        continue;
 
-               case BODY:
+               case BODY2:
                        adios(EX_CONFIG, NULL, "no blank lines are permitted in %s",
                                        file);
 
-               case FILEEOF:
+               case FILEEOF2:
                        break;
 
                default:
index b932cad..1929b26 100644 (file)
@@ -55,9 +55,9 @@ seq_read(struct msgs *mp)
 static void
 seq_public(struct msgs *mp)
 {
-       int state;
-       char *cp, seqfile[PATH_MAX];
-       char name[NAMESZ], field[BUFSIZ];
+       enum state state;
+       struct field f = {{0}};
+       char seqfile[PATH_MAX];
        FILE *fp;
 
        /*
@@ -74,37 +74,24 @@ seq_public(struct msgs *mp)
                return;
 
        /* Use m_getfld to scan sequence file */
-       for (state = FLD;;) {
-               switch (state = m_getfld(state, name, field, sizeof(field),
-                               fp)) {
-               case FLD:
-               case FLDPLUS:
-                       if (state == FLDPLUS) {
-                               cp = getcpy(field);
-                               while (state == FLDPLUS) {
-                                       state = m_getfld(state, name, field,
-                                                       sizeof(field), fp);
-                                       cp = add(field, cp);
-                               }
-                               seq_init(mp, getcpy(name), trimcpy(cp));
-                               free(cp);
-                       } else {
-                               seq_init(mp, getcpy(name), trimcpy(field));
-                       }
+       for (state = FLD2;;) {
+               switch (state = m_getfld2(state, &f, fp)) {
+               case FLD2:
+                       seq_init(mp, getcpy(f.name), trimcpy(f.value));
                        continue;
 
-               case BODY:
+               case BODY2:
                        adios(EX_CONFIG, NULL, "no blank lines are permitted in %s",
                                        seqfile);
-                       /* fall */
+                       /* FALL */
 
-               case FILEEOF:
+               case FILEEOF2:
                        break;
 
                default:
                        adios(EX_CONFIG, NULL, "%s is poorly formatted", seqfile);
                }
-               break;  /* break from for loop */
+               break;
        }
 
        lkfclose(fp, seqfile);
index d1b9474..494c298 100644 (file)
@@ -24,10 +24,10 @@ static int ready_msg(char *);
 int
 distout(char *drft, char *msgnam, char *backup)
 {
-       int state;
+       enum state state;
+       struct field f = {{0}};
        unsigned char *dp;
-       char *resent;
-       char name[NAMESZ], buffer[BUFSIZ];
+       int resent = 0;
        FILE *ifp, *ofp;
 
        strcpy(backup, m_mktemp(toabsdir(invo_name), NULL, NULL));
@@ -52,43 +52,32 @@ distout(char *drft, char *msgnam, char *backup)
        lseek(hdrfd, (off_t) 0, SEEK_SET); /* msgnam not accurate */
        cpydata(hdrfd, fileno(ofp), msgnam, drft);
 
-       state = FLD;
-       resent = NULL;
+       state = FLD2;
        while (1) {
-               switch (state = m_getfld(state, name, buffer, sizeof buffer,
-                               ifp)) {
-               case FLD:
-               case FLDPLUS:
-                       if (!uprf(name, "resent")) {
-                               advise(NULL, "Please re-edit draft to remove the ``%s'' header.", name);
+               switch (state = m_getfld2(state, &f, ifp)) {
+               case FLD2:
+                       if (!uprf(f.name, "resent")) {
+                               advise(NULL, "Please re-edit draft to remove the ``%s'' header.", f.name);
                                goto leave_bad;
                        }
-                       if (state == FLD) {
-                               resent = add(":", add(name, resent));
-                       }
-                       resent = add(buffer, resent);
-                       fprintf(ofp, "%s: %s", name, buffer);
-                       while (state == FLDPLUS) {
-                               state = m_getfld(state, name, buffer,
-                                               sizeof buffer, ifp);
-                               resent = add(buffer, resent);
-                               fputs(buffer, ofp);
-                       }
+                       resent = 1;
+                       fprintf(ofp, "%s: %s", f.name, f.value);
                        break;
 
-               case BODY:
-                       for (dp = buffer; *dp; dp++) {
+               case BODY2:
+                       for (dp = f.value; *dp; dp++) {
                                if (!isspace(*dp)) {
                                        advise(NULL, "Please re-edit draft to consist of headers only.");
                                        goto leave_bad;
                                }
                        }
 
-               case FILEEOF:
+               case FILEEOF2:
                        goto process;
 
-               case LENERR:
-               case FMTERR:
+               case LENERR2:
+               case FMTERR2:
+               case ERR2:
                        advise(NULL, "Please re-edit draft and fix that header.");
 leave_bad: ;
                        fclose(ifp);
@@ -118,7 +107,6 @@ process: ;
                }
                return NOTOK;
        }
-       free(resent);
 
        if (txtfd != NOTOK) {
                lseek(txtfd, (off_t) 0, SEEK_SET);  /* msgnam not accurate */
@@ -134,8 +122,10 @@ process: ;
 static int
 ready_msg(char *msgnam)
 {
-       int state, out;
-       char name[NAMESZ], buffer[BUFSIZ], tmpfil[BUFSIZ];
+       enum state state;
+       struct field f = {{0}};
+       char tmpfil[BUFSIZ];
+       int out;
        FILE *ifp, *ofp;
        char *cp = NULL;
 
@@ -165,24 +155,18 @@ ready_msg(char *msgnam)
        }
        unlink(tmpfil);
 
-       state = FLD;
+       state = FLD2;
        while (1) {
-               state = m_getfld(state, name, buffer, sizeof buffer, ifp);
+               state = m_getfld2(state, &f, ifp);
                switch (state) {
-               case FLD:
-               case FLDPLUS:
-                       if (uprf(name, "resent")) {
+               case FLD2:
+                       if (uprf(f.name, "resent")) {
                                fprintf(ofp, "Prev-");
                        }
-                       fprintf(ofp, "%s: %s", name, buffer);
-                       while (state == FLDPLUS) {
-                               state = m_getfld(state, name, buffer,
-                                               sizeof buffer, ifp);
-                               fputs(buffer, ofp);
-                       }
+                       fprintf(ofp, "%s: %s", f.name, f.value);
                        break;
 
-               case BODY:
+               case BODY2:
                        fclose(ofp);
 
                        cp = m_mktemp2(NULL, "dist", &txtfd, NULL);
@@ -198,17 +182,19 @@ ready_msg(char *msgnam)
                                return NOTOK;
                        }
                        unlink(tmpfil);
-                       fprintf(ofp, "\n%s", buffer);
-                       while (state == BODY) {
-                               state = m_getfld(state, name, buffer,
-                                               sizeof buffer, ifp);
-                               fputs(buffer, ofp);
+                       fprintf(ofp, "\n%s", f.value);
+                       while (state == BODY2) {
+                               state = m_getfld2(state, &f, ifp);
+                               fputs(f.value, ofp);
                        }
-               case FILEEOF:
+                       /* FALL */
+
+               case FILEEOF2:
                        goto process;
 
-               case LENERR:
-               case FMTERR:
+               case LENERR2:
+               case FMTERR2:
+               case ERR2:
                        advise(NULL, "format error in message %s", msgnam);
                        return NOTOK;
 
index 01acdb7..4f764f4 100644 (file)
@@ -312,8 +312,10 @@ unlink_done()
 static CT
 build_mime(char *infile)
 {
-       int compnum, state;
-       char buf[BUFSIZ], name[NAMESZ];
+       enum state state;
+       struct field f = {{0}};
+       int compnum;
+       char buf[BUFSIZ];
        char *cp, *np, *vp;
        struct multipart *m;
        struct part **pp;
@@ -324,14 +326,16 @@ build_mime(char *infile)
        umask(~m_gmprot());
 
        /* open the composition draft */
-       if ((in = fopen(infile, "r")) == NULL)
+       if ((in = fopen(infile, "r")) == NULL) {
                adios(EX_IOERR, infile, "unable to open for reading");
+       }
 
        /*
        ** Allocate space for primary (outside) content
        */
-       if ((ct = (CT) mh_xcalloc(1, sizeof(*ct))) == NULL)
+       if ((ct = (CT) mh_xcalloc(1, sizeof(*ct))) == NULL) {
                adios(EX_OSERR, NULL, "out of memory");
+       }
 
        /*
        ** Allocate structure for handling decoded content
@@ -345,57 +349,45 @@ build_mime(char *infile)
        ** draft into the linked list of header fields for
        ** the new MIME message.
        */
-       for (compnum = 1, state = FLD;;) {
-               switch (state = m_getfld(state, name, buf, sizeof(buf), in)) {
-               case FLD:
-               case FLDPLUS:
+       for (compnum = 1, state = FLD2;;) {
+               switch (state = m_getfld2(state, &f, in)) {
+               case FLD2:
                        compnum++;
 
                        /* abort if draft has Mime-Version header field */
-                       if (!mh_strcasecmp(name, VRSN_FIELD))
+                       if (!mh_strcasecmp(f.name, VRSN_FIELD)) {
                                adios(EX_CONFIG, NULL, "draft shouldn't contain %s: field", VRSN_FIELD);
+                       }
 
                        /*
                        ** abort if draft has Content-Transfer-Encoding
                        ** header field
                        */
-                       if (!mh_strcasecmp(name, ENCODING_FIELD))
+                       if (!mh_strcasecmp(f.name, ENCODING_FIELD)) {
                                adios(EX_CONFIG, NULL, "draft shouldn't contain %s: field", ENCODING_FIELD);
+                       }
 
                        /* ignore any Content-Type fields in the header */
-                       if (!mh_strcasecmp(name, TYPE_FIELD)) {
-                               while (state == FLDPLUS)
-                                       state = m_getfld(state, name, buf,
-                                                       sizeof(buf), in);
+                       if (!mh_strcasecmp(f.name, TYPE_FIELD)) {
                                continue;
                        }
 
-                       /* get copies of the buffers */
-                       np = getcpy(name);
-                       vp = getcpy(buf);
-
-                       /* if necessary, get rest of field */
-                       while (state == FLDPLUS) {
-                               state = m_getfld(state, name, buf,
-                                               sizeof(buf), in);
-                               vp = add(buf, vp);  /* add to prev value */
-                       }
-
-                       /* Now add the header data to the list */
-                       add_header(ct, np, vp);
+                       /* add the header data to the list */
+                       add_header(ct, getcpy(f.name), getcpy(f.value));
 
                        continue;
 
-               case FILEEOF:
+               case BODY2:
+                       fseek(in, (long) (-strlen(f.value)), SEEK_CUR);
+                       break;
+
+               case FILEEOF2:
                        adios(EX_CONFIG, NULL, "draft has empty body -- no directives!");
                        /* NOTREACHED */
 
-               case BODY:
-                       fseek(in, (long) (-strlen(buf)), SEEK_CUR);
-                       break;
-
-               case LENERR:
-               case FMTERR:
+               case LENERR2:
+               case FMTERR2:
+               case ERR2:
                        adios(EX_CONFIG, NULL, "message format error in component #%d",
                                        compnum);
 
index f3f7477..5caa717 100644 (file)
--- a/uip/mhl.c
+++ b/uip/mhl.c
@@ -598,16 +598,18 @@ process(char *fname, int ofilen, int ofilec)
 static void
 mhlfile(FILE *fp, char *mname, int ofilen, int ofilec)
 {
-       int state;
+       enum state state;
+       struct field f = {{0}};
        struct mcomp *c1, *c2, *c3;
-       char **ip, name[NAMESZ], buf[BUFSIZ];
+       char **ip;
 
        if (forwall) {
                printf("\n-------");
-               if (ofilen == 1)
+               if (ofilen == 1) {
                        printf(" Forwarded Message%s", ofilec > 1 ? "s" : "");
-               else
+               } else {
                        printf(" Message %d", ofilen);
+               }
                printf("\n\n");
        } else if (ofilec > 1) {
                if (ofilen > 1) {
@@ -616,50 +618,46 @@ mhlfile(FILE *fp, char *mname, int ofilen, int ofilec)
                printf(">>> %s\n\n", mname);
        }
 
-       for (state = FLD;!eflag;) {
-               switch (state = m_getfld(state, name, buf, sizeof(buf), fp)) {
-               case FLD:
-               case FLDPLUS:
+       for (state = FLD2; !eflag; ) {
+               switch (state = m_getfld2(state, &f, fp)) {
+               case FLD2:
                        for (ip = ignores; *ip; ip++)
-                               if (!mh_strcasecmp(name, *ip)) {
-                                       while (state == FLDPLUS)
-                                               state = m_getfld(state, name, buf, sizeof(buf), fp);
+                               if (mh_strcasecmp(f.name, *ip)==0) {
                                        break;
                                }
-                       if (*ip)
+                       if (*ip) {
                                continue;
+                       }
 
                        for (c2 = fmthd; c2; c2 = c2->c_next)
-                               if (!mh_strcasecmp(c2->c_name, name))
+                               if (mh_strcasecmp(c2->c_name, f.name)==0) {
                                        break;
+                               }
                        c1 = NULL;
                        if (!((c3 = c2 ? c2 : &global)->c_flags & SPLIT))
                                for (c1 = msghd; c1; c1 = c1->c_next)
-                                       if (!mh_strcasecmp(c1->c_name,
-                                                       c3->c_name)) {
-                                               c1->c_text = mcomp_add(c1->c_flags, buf, c1->c_text);
+                                       if (mh_strcasecmp(c1->c_name,
+                                                       c3->c_name)==0) {
+                                               c1->c_text = mcomp_add(c1->c_flags, f.value, c1->c_text);
                                                break;
                                        }
-                       if (c1 == NULL)
-                               c1 = add_queue(&msghd, &msgtl, name, buf, 0);
-                       while (state == FLDPLUS) {
-                               state = m_getfld(state, name, buf,
-                                               sizeof(buf), fp);
-                               c1->c_text = add(buf, c1->c_text);
+                       if (c1 == NULL) {
+                               c1 = add_queue(&msghd, &msgtl, f.name, f.value, 0);
                        }
-                       if (c2 == NULL)
+                       if (c2 == NULL) {
                                c1->c_flags |= EXTRA;
+                       }
                        continue;
 
-               case BODY:
-               case FILEEOF:
+               case BODY2:
+               case FILEEOF2:
                        column = 0;
                        for (c1 = fmthd; c1; c1 = c1->c_next) {
                                if (c1->c_flags & CLEARTEXT) {
                                        putcomp(c1, c1, ONECOMP);
                                        continue;
                                }
-                               if (!mh_strcasecmp(c1->c_name, "messagename")) {
+                               if (mh_strcasecmp(c1->c_name, "messagename")==0) {
                                        holder.c_text = concat("(Message ",
                                                        mname, ")\n", NULL);
                                        putcomp(c1, &holder, ONECOMP);
@@ -667,35 +665,41 @@ mhlfile(FILE *fp, char *mname, int ofilen, int ofilec)
                                        holder.c_text = NULL;
                                        continue;
                                }
-                               if (!mh_strcasecmp(c1->c_name, "extras")) {
-                                       for (c2 = msghd; c2; c2 = c2->c_next)
-                                               if (c2->c_flags & EXTRA)
+                               if (mh_strcasecmp(c1->c_name, "extras")==0) {
+                                       for (c2 = msghd; c2; c2 = c2->c_next) {
+                                               if (c2->c_flags & EXTRA) {
                                                        putcomp(c1, c2, TWOCOMP);
+                                               }
+                                       }
                                        continue;
                                }
-                               if (dobody && !mh_strcasecmp(c1->c_name, "body")) {
-                                       holder.c_text = mh_xmalloc(sizeof(buf));
-                                       strncpy(holder.c_text, buf, sizeof(buf));
-                                       while (state == BODY) {
+                               if (dobody && mh_strcasecmp(c1->c_name, "body")==0) {
+                                       holder.c_text = getcpy(f.value);
+                                       while (state == BODY2) {
                                                putcomp(c1, &holder, BODYCOMP);
-                                               state = m_getfld(state, name, holder.c_text, sizeof(buf), fp);
+                                               state = m_getfld2(state, &f, fp);
+                                               free(holder.c_text);
+                                               holder.c_text = getcpy(f.value);
                                        }
                                        free(holder.c_text);
                                        holder.c_text = NULL;
                                        continue;
                                }
-                               for (c2 = msghd; c2; c2 = c2->c_next)
-                                       if (!mh_strcasecmp(c2->c_name,
-                                                       c1->c_name)) {
+                               for (c2 = msghd; c2; c2 = c2->c_next) {
+                                       if (mh_strcasecmp(c2->c_name,
+                                                       c1->c_name)==0) {
                                                putcomp(c1, c2, ONECOMP);
-                                               if (!(c1->c_flags & SPLIT))
+                                               if (!(c1->c_flags & SPLIT)) {
                                                        break;
+                                               }
                                        }
+                               }
                        }
                        return;
 
-               case LENERR:
-               case FMTERR:
+               case LENERR2:
+               case FMTERR2:
+               case ERR2:
                        advise(NULL, "format error in message %s", mname);
                        exitstat++;
                        return;
index 4885572..b144c37 100644 (file)
@@ -231,9 +231,9 @@ parse_mime(char *file)
 static CT
 get_content(FILE *in, char *file, int toplevel)
 {
-       int compnum, state;
-       char buf[BUFSIZ], name[NAMESZ];
-       char *np, *vp;
+       enum state state;
+       struct field f = {{0}};
+       int compnum;
        CT ct;
        HF hp;
 
@@ -249,47 +249,34 @@ get_content(FILE *in, char *file, int toplevel)
        ** Parse the header fields for this
        ** content into a linked list.
        */
-       for (compnum = 1, state = FLD;;) {
-               switch (state = m_getfld(state, name, buf, sizeof(buf), in)) {
-               case FLD:
-               case FLDPLUS:
+       for (compnum = 1, state = FLD2;;) {
+               switch (state = m_getfld2(state, &f, in)) {
+               case FLD2:
                        compnum++;
 
-                       /* get copies of the buffers */
-                       np = getcpy(name);
-                       vp = getcpy(buf);
-
-                       /* if necessary, get rest of field */
-                       while (state == FLDPLUS) {
-                               state = m_getfld(state, name, buf,
-                                               sizeof(buf), in);
-                               vp = add(buf, vp);  /* add to previous value */
-                       }
-
-                       /* Now add the header data to the list */
-                       add_header(ct, np, vp);
+                       /* add the header data to the list */
+                       add_header(ct, getcpy(f.name), getcpy(f.value));
 
                        ct->c_begin = ftell(in) + 1;
                        continue;
 
-               case BODY:
-                       ct->c_begin = ftell(in) - strlen(buf);
+               case BODY2:
+                       ct->c_begin = ftell(in) - strlen(f.value);
                        break;
 
-               case FILEEOF:
+               case FILEEOF2:
                        ct->c_begin = ftell(in);
                        break;
 
-               case LENERR:
-               case FMTERR:
+               case LENERR2:
+               case FMTERR2:
+               case ERR2:
                        adios(EX_DATAERR, NULL, "message format error in component #%d",
                                        compnum);
 
                default:
                        adios(EX_SOFTWARE, NULL, "getfld() returned %d", state);
                }
-
-               /* break out of the loop */
                break;
        }
 
index cb16dea..a2be29b 100644 (file)
--- a/uip/new.c
+++ b/uip/new.c
@@ -95,11 +95,10 @@ seq_in_list(char *name, char *sequences[])
 static char *
 get_msgnums(char *folder, char *sequences[])
 {
+       enum state state;
+       struct field f = {{0}};
        char *seqfile = concat(toabsdir(folder), "/", mh_seq, (void *)NULL);
        FILE *fp = fopen(seqfile, "r");
-       int state;
-       char name[NAMESZ], field[BUFSIZ];
-       char *cp;
        char *msgnums = NULL, *this_msgnums, *old_msgnums;
 
        /* no sequences file -> no messages */
@@ -107,67 +106,39 @@ get_msgnums(char *folder, char *sequences[])
                return NULL;
        }
 
-       /* copied from seq_read.c:seq_public */
-       for (state = FLD;;) {
-               switch (state = m_getfld(state, name, field, sizeof(field),
-                               fp)) {
-               case FLD:
-               case FLDPLUS:
-                       if (state == FLDPLUS) {
-                               cp = getcpy(field);
-                               while (state == FLDPLUS) {
-                                       state = m_getfld(state, name, field,
-                                                       sizeof(field), fp);
-                                       cp = add(field, cp);
-                               }
-
-                               /*
-                               ** Here's where we differ from
-                               ** seq_public: if it's in a
-                               ** sequence we want, save the list
-                               ** of messages.
-                               */
-                               if (seq_in_list(name, sequences)) {
-                                       this_msgnums = trimcpy(cp);
-                                       if (msgnums == NULL) {
-                                               msgnums = this_msgnums;
-                                       } else {
-                                               old_msgnums = msgnums;
-                                               msgnums = concat(old_msgnums, " ", this_msgnums, (void *)NULL);
-                                               free(old_msgnums);
-                                               free(this_msgnums);
-                                       }
-                               }
-                               free(cp);
-                       } else {
-                               /* and here */
-                               if (seq_in_list(name, sequences)) {
-                                       this_msgnums = trimcpy(field);
-                                       if (msgnums == NULL) {
-                                               msgnums = this_msgnums;
-                                       } else {
-                                               old_msgnums = msgnums;
-                                               msgnums = concat(old_msgnums, " ", this_msgnums, (void *)NULL);
-                                               free(old_msgnums);
-                                               free(this_msgnums);
-                                       }
+       for (state = FLD2;;) {
+               switch (state = m_getfld2(state, &f, fp)) {
+               case FLD2:
+                       /*
+                       ** if it's in a sequence we want,
+                       ** save the list of messages.
+                       */
+                       if (seq_in_list(f.name, sequences)) {
+                               this_msgnums = trimcpy(f.value);
+                               if (msgnums == NULL) {
+                                       msgnums = this_msgnums;
+                               } else {
+                                       old_msgnums = msgnums;
+                                       msgnums = concat(old_msgnums, " ",
+                                                       this_msgnums,
+                                                       (void *)NULL);
+                                       free(old_msgnums);
+                                       free(this_msgnums);
                                }
                        }
-
                        continue;
 
-               case BODY:
-                       adios(EX_DATAERR, NULL, "no blank lines are permitted in %s",
-                                       seqfile);
-                       /* fall */
+               case BODY2:
+                       adios(EX_DATAERR, NULL, "no blank lines are permitted in %s", seqfile);
+                       /* FALL */
 
-               case FILEEOF:
+               case FILEEOF2:
                        break;
 
                default:
                        adios(EX_SOFTWARE, NULL, "%s is poorly formatted", seqfile);
                }
-               break;  /* break from for loop */
+               break;
        }
 
        fclose(fp);
index 984d80b..3ac9e11 100644 (file)
@@ -1243,38 +1243,36 @@ static int
 TWSaction(params)
 plist
 {
-       int state;
+       enum state state;
+       struct field f = {{0}};
        char *bp;
-       char buf[BUFSIZ], name[NAMESZ];
        struct tws *tw;
 
        fseek(fp, start, SEEK_SET);
-       for (state = FLD, bp = NULL;;) {
-               switch (state = m_getfld(state, name, buf, sizeof buf, fp)) {
-               case FLD:
-               case FLDPLUS:
-                       if (bp != NULL) {
+       for (state = FLD2, bp = NULL;;) {
+               switch (state = m_getfld2(state, &f, fp)) {
+               case FLD2:
+                       if (bp) {
                                free(bp);
                                bp = NULL;
                        }
-                       bp = getcpy(buf);
-                       while (state == FLDPLUS) {
-                               state = m_getfld(state, name, buf,
-                                               sizeof buf, fp);
-                               bp = add(buf, bp);
-                       }
-                       if (!mh_strcasecmp(name, n->n_datef))
+                       bp = getcpy(f.value);
+                       if (mh_strcasecmp(f.name, n->n_datef)==0) {
                                break;
+                       }
                        continue;
 
-               case BODY:
-               case FILEEOF:
-               case LENERR:
-               case FMTERR:
-                       if (state == LENERR || state == FMTERR)
-                               advise(NULL, "format error in message %d", msgnum);
-                       if (bp != NULL)
+               case LENERR2:
+               case FMTERR2:
+               case ERR2:
+                       advise(NULL, "format error in message %d", msgnum);
+                       /* FALL */
+
+               case BODY2:
+               case FILEEOF2:
+                       if (bp) {
                                free(bp);
+                       }
                        return 0;
 
                default:
index 2adbd48..24f2d9f 100644 (file)
@@ -54,9 +54,10 @@ int
 main(int argc, char **argv)
 {
        int qbody = 1, prepend = 1, rapid = 0;
-       int fdi, fdo, i, state;
+       int fdi, fdo, i;
        char *cp, *drft = NULL;
-       char name[NAMESZ], field[BUFSIZ];
+       enum state state;
+       struct field f = {{0}};
        char buffer[BUFSIZ], tmpfil[BUFSIZ];
        char **arguments, **argp;
        FILE *in, *out;
@@ -137,58 +138,53 @@ main(int argc, char **argv)
        /*
        ** Loop through the lines of the draft skeleton.
        */
-       for (state = FLD;;) {
-               switch (state = m_getfld(state, name, field, sizeof(field),
-                               in)) {
-               case FLD:
-               case FLDPLUS:
+       for (state = FLD2;;) {
+               switch (state = m_getfld2(state, &f, in)) {
+               case FLD2:
                        /*
                        ** Check if the value of field contains
                        ** anything other than space or tab.
                        */
-                       for (cp = field; *cp; cp++)
-                               if (*cp != ' ' && *cp != '\t')
+                       for (cp = f.value; *cp; cp++) {
+                               if (*cp != ' ' && *cp != '\t') {
                                        break;
+                               }
+                       }
 
                        /* If so, just add header line to draft */
                        if (*cp++ != '\n' || *cp) {
-                               printf("%s:%s", name, field);
-                               fprintf(out, "%s:%s", name, field);
-                               while (state == FLDPLUS) {
-                                       state = m_getfld(state, name, field,
-                                                       sizeof(field), in);
-                                       printf("%s", field);
-                                       fprintf(out, "%s", field);
-                               }
+                               printf("%s:%s", f.name, f.value);
+                               fprintf(out, "%s:%s", f.name, f.value);
                        } else {
                                /* Else, get value of header field */
-                               printf("%s: ", name);
+                               printf("%s: ", f.name);
                                fflush(stdout);
-                               i = getln(field, sizeof(field));
+                               i = getln(buffer, sizeof(buffer));
                                if (i == -1) {
 abort:
                                        unlink(tmpfil);
                                        exit(EX_DATAERR);
                                }
-                               if (i || (field[0]!='\n' && field[0]!='\0')) {
-                                       fprintf(out, "%s:", name);
+                               if (i || (buffer[0]!='\n' && buffer[0]!='\0')) {
+                                       fprintf(out, "%s:", f.name);
                                        do {
-                                               if (field[0] != ' ' && field[0] != '\t')
+                                               if (buffer[0] != ' ' && buffer[0] != '\t') {
                                                        putc(' ', out);
-                                               fprintf(out, "%s", field);
-                                       } while (i == 1 && (i = getln(field, sizeof(field))) >= 0);
-                                       if (i == -1)
+                                               }
+                                               fprintf(out, "%s", buffer);
+                                       } while (i == 1 && (i = getln(buffer, sizeof(buffer))) >= 0);
+                                       if (i == -1) {
                                                goto abort;
+                                       }
                                }
                        }
-
                        continue;
 
-               case BODY:
-               case FILEEOF:
+               case BODY2:
+               case FILEEOF2:
                        fprintf(out, "--------\n");
                        if (qbody) {
-                               if (!*field) {
+                               if (!*f.value) {
                                        printf("--------\n");
                                        goto has_no_body;
                                }
@@ -198,8 +194,9 @@ abort:
                                        fflush(stdout);
                                        for (;;) {
                                                getln(buffer, sizeof(buffer));
-                                               if (!*buffer)
+                                               if (!*buffer) {
                                                        break;
+                                               }
                                                fprintf(out, "%s", buffer);
                                        }
                                } else {
@@ -207,25 +204,29 @@ abort:
                                }
                        }
 
-                       do {
-                               fprintf(out, "%s", field);
-                               if (!rapid && !sigint)
-                                       printf("%s", field);
-                       } while (state == BODY &&
-                                       (state = m_getfld(state, name,
-                                       field, sizeof(field), in)));
+                       if (state == BODY2) {
+                               do {
+                                       fprintf(out, "%s", f.value);
+                                       if (!rapid && !sigint) {
+                                               printf("%s", f.value);
+                                       }
+                               } while ((state = m_getfld2(state, &f, in))
+                                               ==BODY2);
+                       }
 
-                       if (prepend || !qbody)
+                       if (prepend || !qbody) {
                                break;
+                       }
 
                        printf("--------Enter additional text\n");
 has_no_body:
                        fflush(stdout);
                        for (;;) {
-                               getln(field, sizeof(field));
-                               if (!*field)
+                               getln(buffer, sizeof(buffer));
+                               if (!*buffer) {
                                        break;
-                               fprintf(out, "%s", field);
+                               }
+                               fprintf(out, "%s", buffer);
                        }
                        break;
 
@@ -235,8 +236,9 @@ has_no_body:
                break;
        }
 
-       if (qbody)
+       if (qbody) {
                printf("--------\n");
+       }
 
        fflush(stdout);
        fclose(in);
@@ -254,7 +256,7 @@ has_no_body:
        close(fdo);
        unlink(tmpfil);
 
-       context_save();  /* save the context file */
+       context_save();
        return EX_OK;
 }
 
index ca267fa..5760a83 100644 (file)
@@ -724,10 +724,10 @@ split(char *cp, char **vec)
 static int
 parse(int fd)
 {
-       int i, state;
-       int fd1;
+       enum state state;
+       struct field f = {{0}};
+       int i, fd1;
        char *cp, *dp, *lp;
-       char name[NAMESZ], field[BUFSIZ];
        struct pair *p, *q;
        FILE  *in;
 
@@ -756,19 +756,12 @@ parse(int fd)
        /*
        ** Scan the headers of the message and build a lookup table.
        */
-       for (i = 0, state = FLD;;) {
-               switch (state = m_getfld(state, name, field, sizeof(field),
-                               in)) {
-               case FLD:
-               case FLDPLUS:
-                       lp = getcpy(field);
-                       while (state == FLDPLUS) {
-                               state = m_getfld(state, name, field,
-                                               sizeof(field), in);
-                               lp = add(field, lp);
-                       }
+       for (i = 0, state = FLD2;;) {
+               switch (state = m_getfld2(state, &f, in)) {
+               case FLD2:
+                       lp = getcpy(f.value);
                        for (p = hdrs; p->p_name; p++) {
-                               if (mh_strcasecmp(p->p_name, name)!=0) {
+                               if (mh_strcasecmp(p->p_name, f.name)!=0) {
                                        if (!(p->p_flags & P_HID)) {
                                                if ((cp = p->p_value)) {
                                                        if (p->p_flags & P_ADR) {
@@ -788,7 +781,7 @@ parse(int fd)
                                }
                        }
                        if (!p->p_name && i < NVEC) {
-                               p->p_name = getcpy(name);
+                               p->p_name = getcpy(f.name);
                                p->p_value = lp;
                                p->p_flags = P_NIL;
                                p++, i++;
@@ -796,12 +789,13 @@ parse(int fd)
                        }
                        continue;
 
-               case BODY:
-               case FILEEOF:
+               case BODY2:
+               case FILEEOF2:
                        break;
 
-               case LENERR:
-               case FMTERR:
+               case LENERR2:
+               case FMTERR2:
+               case ERR2:
                        advise(NULL, "format error in message");
                        break;
 
index 4ca0c72..75aa2e3 100644 (file)
@@ -322,9 +322,10 @@ read_hdrs(struct msgs *mp, char *datesw)
 static int
 get_fields(char *datesw, int msg, struct smsg *smsg)
 {
-       int state;
+       enum state state;
+       struct field f = {{0}};
        int compnum;
-       char *msgnam, buf[BUFSIZ], nam[NAMESZ];
+       char *msgnam;
        struct tws *tw;
        char *datecomp = NULL, *subjcomp = NULL;
        FILE *in;
@@ -333,49 +334,37 @@ get_fields(char *datesw, int msg, struct smsg *smsg)
                admonish(msgnam, "unable to read message");
                return (0);
        }
-       for (compnum = 1, state = FLD;;) {
-               switch (state = m_getfld(state, nam, buf, sizeof(buf), in)) {
-               case FLD:
-               case FLDPLUS:
-                       compnum++;
-                       if (!mh_strcasecmp(nam, datesw)) {
-                               datecomp = add(buf, datecomp);
-                               while (state == FLDPLUS) {
-                                       state = m_getfld(state, nam, buf,
-                                                       sizeof(buf), in);
-                                       datecomp = add(buf, datecomp);
-                               }
-                               if (!subjsort || subjcomp)
+       for (compnum = 1, state = FLD2;; compnum++) {
+               switch (state = m_getfld2(state, &f, in)) {
+               case FLD2:
+                       if (mh_strcasecmp(f.name, datesw)==0) {
+                               datecomp = getcpy(f.value);
+                               if (!subjsort || subjcomp) {
                                        break;
-                       } else if (subjsort && !mh_strcasecmp(nam, subjsort)) {
-                               subjcomp = add(buf, subjcomp);
-                               while (state == FLDPLUS) {
-                                       state = m_getfld(state, nam, buf,
-                                                       sizeof(buf), in);
-                                       subjcomp = add(buf, subjcomp);
                                }
-                               if (datecomp)
+                       } else if (subjsort && mh_strcasecmp(f.name,
+                                       subjsort)==0) {
+                               subjcomp = getcpy(f.value);
+                               if (datecomp) {
                                        break;
-                       } else {
-                               /* just flush this guy */
-                               while (state == FLDPLUS)
-                                       state = m_getfld(state, nam, buf,
-                                                       sizeof(buf), in);
+                               }
                        }
                        continue;
 
-               case BODY:
-               case FILEEOF:
+               case BODY2:
+               case FILEEOF2:
                        break;
 
-               case LENERR:
-               case FMTERR:
-                       if (state == LENERR || state == FMTERR)
-                               admonish(NULL, "format error in message %d (header #%d)", msg, compnum);
-                       if (datecomp)
+               case LENERR2:
+               case FMTERR2:
+               case ERR2:
+                       admonish(NULL, "format error in message %d (header #%d)", msg, compnum);
+                       if (datecomp) {
                                free(datecomp);
-                       if (subjcomp)
+                       }
+                       if (subjcomp) {
                                free(subjcomp);
+                       }
                        fclose(in);
                        return (0);
 
index 7729e9b..6282e75 100644 (file)
@@ -143,9 +143,11 @@ static size_t do_aliasing(struct mailname *, struct mailname **);
 int
 main(int argc, char **argv)
 {
-       int state, compnum;
+       enum state state;
+       struct field f = {{0}};
+       int compnum;
        char *cp, *msg = NULL, **argp, **arguments;
-       char **sargv, buf[BUFSIZ], name[NAMESZ];
+       char **sargv, buf[BUFSIZ];
        FILE *in;
 
        setlocale(LC_ALL, "");
@@ -230,37 +232,28 @@ main(int argc, char **argv)
 
        hdrtab = (msgstate == normal) ? NHeaders : RHeaders;
 
-       for (compnum = 1, state = FLD;;) {
-               switch (state = m_getfld(state, name, buf, sizeof(buf), in)) {
-               case FLD:
-               case FLDPLUS:
+       for (compnum = 1, state = FLD2;;) {
+               switch (state = m_getfld2(state, &f, in)) {
+               case FLD2:
                        compnum++;
-                       cp = getcpy(buf);
-                       while (state == FLDPLUS) {
-                               state = m_getfld(state, name, buf,
-                                               sizeof(buf), in);
-                               cp = add(buf, cp);
-                       }
-                       putfmt(name, cp, out);
-                       free(cp);
+                       putfmt(f.name, f.value, out);
                        continue;
 
-               case BODY:
+               case BODY2:
                        finish_headers(out);
-                       fprintf(out, "\n%s", buf);
-                       while (state == BODY) {
-                               state = m_getfld(state, name, buf,
-                                               sizeof(buf), in);
-                               fputs(buf, out);
+                       fprintf(out, "\n%s", f.value);
+                       while ((state = m_getfld2(state, &f, in)) == BODY2) {
+                               fputs(f.value, out);
                        }
                        break;
 
-               case FILEEOF:
+               case FILEEOF2:
                        finish_headers(out);
                        break;
 
-               case LENERR:
-               case FMTERR:
+               case LENERR2:
+               case FMTERR2:
+               case ERR2:
                        adios(EX_DATAERR, NULL, "message format error in component #%d",
                                        compnum);
 
index d313f05..e1aab77 100644 (file)
@@ -203,9 +203,9 @@ main(int argc, char **argv)
 static int
 process(char *file)
 {
-        int state, compnum;
-       char *cp = NULL;
-       char buf[BUFSIZ], name[NAMESZ];
+       enum state state;
+       struct field f = {{0}};
+       int compnum;
        FILE *in;
 
 
@@ -213,31 +213,19 @@ process(char *file)
                adios(EX_IOERR, file, "unable to open");
        }
 
-       for (compnum = 1, state = FLD;;) {
-               switch (state = m_getfld(state, name, buf, sizeof(buf), in)) {
-               case FLD:
-                       compnum++;
-                       proc_hdr(name, buf);
+       for (compnum=1, state=FLD2;; compnum++) {
+               switch (state = m_getfld2(state, &f, in)) {
+               case FLD2:
+                       proc_hdr(f.name, f.value);
                        continue;
 
-               case FLDPLUS:
-                       compnum++;
-                       cp = getcpy(buf);
-                       while (state == FLDPLUS) {
-                               state = m_getfld(state, name, buf,
-                                               sizeof(buf), in);
-                               cp = add(buf, cp);
-                       }
-                       proc_hdr(name, cp);
-                       free(cp);
-                       continue;
-
-               case BODY:
-               case FILEEOF:
+               case BODY2:
+               case FILEEOF2:
                        break;
 
-               case LENERR:
-               case FMTERR:
+               case LENERR2:
+               case FMTERR2:
+               case ERR2:
                        adios(EX_DATAERR, NULL, "message format error in component #%d",
                                        compnum);