No error-checking for error-checking alloc functions
[mmh] / uip / sortm.c
index ae4038d..43dc7dc 100644 (file)
@@ -297,8 +297,6 @@ read_hdrs(struct msgs *mp, char *datesw)
 
        smsgs = (struct smsg *) mh_xcalloc((size_t) (mp->hghsel - mp->lowsel + 2),
                        sizeof(*smsgs));
-       if (smsgs == NULL)
-               adios(EX_OSERR, NULL, "unable to allocate sort storage");
 
        s = smsgs;
        for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
@@ -322,9 +320,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,51 +332,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 FLDEOF:
-               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 BODYEOF:
-               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);