]> diplodocus.org Git - nmh/blobdiff - uip/sortm.c
Started revising m_getfld() code to replace direct buffer
[nmh] / uip / sortm.c
index 45e2b292fea355c434f209e333323d272e7204ea..95c76b5f8d2e6eba51d43dd62a4038ea138b8d88 100644 (file)
@@ -32,9 +32,13 @@ static struct swit switches[] = {
      { "all", 0 },
 #define NALLMSGS               9
      { "noall", 0 },
-#define VERSIONSW             10
+#define CHECKSW               10
+     { "check", 0 },
+#define NCHECKSW              11
+     { "nocheck", 0 },
+#define VERSIONSW             12
      { "version", 0 },
-#define HELPSW                11
+#define HELPSW                13
      { "help", 0 },
      { NULL, 0 }
 };
@@ -53,6 +57,7 @@ time_t datelimit = 0;
 int submajor = 0;              /* if true, sort on subject-major */
 int verbose;
 int allmsgs = 1;
+int check_failed = 0;
 
 /* This keeps compiler happy on calls to qsort */
 typedef int (*qsort_comp) (const void *, const void *);
@@ -80,6 +85,7 @@ main (int argc, char **argv)
     struct msgs_array msgs = { 0, 0, NULL };
     struct msgs *mp;
     struct smsg **dlist;
+    int checksw = 0;
 
 #ifdef LOCALE
     setlocale(LC_ALL, "");
@@ -165,6 +171,13 @@ main (int argc, char **argv)
            case NALLMSGS:
                allmsgs = 0;
                continue;
+
+           case CHECKSW:
+               checksw = 1;
+               continue;
+           case NCHECKSW:
+               checksw = 0;
+               continue;
            }
        }
        if (*cp == '+' || *cp == '@') {
@@ -211,6 +224,10 @@ main (int argc, char **argv)
     if ((nmsgs = read_hdrs (mp, datesw)) <= 0)
        adios (NULL, "no messages to sort");
 
+    if (checksw  &&  check_failed) {
+       adios (NULL, "errors found, no messages sorted");
+    }
+
     /*
      * sort a list of pointers to our "messages to be sorted".
      */
@@ -354,7 +371,8 @@ get_fields (char *datesw, int msg, struct smsg *smsg)
        return (0);
     }
     for (compnum = 1, state = FLD;;) {
-       switch (state = m_getfld (state, nam, buf, sizeof(buf), in)) {
+       int bufsz = sizeof buf;
+       switch (state = m_getfld (state, nam, buf, &bufsz, in)) {
        case FLD:
        case FLDEOF:
        case FLDPLUS:
@@ -362,7 +380,8 @@ get_fields (char *datesw, int msg, struct smsg *smsg)
            if (!mh_strcasecmp (nam, datesw)) {
                datecomp = add (buf, datecomp);
                while (state == FLDPLUS) {
-                   state = m_getfld (state, nam, buf, sizeof(buf), in);
+                   bufsz = sizeof buf;
+                   state = m_getfld (state, nam, buf, &bufsz, in);
                    datecomp = add (buf, datecomp);
                }
                if (!subjsort || subjcomp)
@@ -370,15 +389,18 @@ get_fields (char *datesw, int msg, struct smsg *smsg)
            } else if (subjsort && !mh_strcasecmp (nam, subjsort)) {
                subjcomp = add (buf, subjcomp);
                while (state == FLDPLUS) {
-                   state = m_getfld (state, nam, buf, sizeof(buf), in);
+                   bufsz = sizeof buf;
+                   state = m_getfld (state, nam, buf, &bufsz, in);
                    subjcomp = add (buf, subjcomp);
                }
                if (datecomp)
                    break;
            } else {
                /* just flush this guy */
-               while (state == FLDPLUS)
-                   state = m_getfld (state, nam, buf, sizeof(buf), in);
+               while (state == FLDPLUS) {
+                   bufsz = sizeof buf;
+                   state = m_getfld (state, nam, buf, &bufsz, in);
+               }
            }
            continue;
 
@@ -389,9 +411,11 @@ get_fields (char *datesw, int msg, struct smsg *smsg)
 
        case LENERR:
        case FMTERR:
-           if (state == LENERR || state == FMTERR)
+           if (state == LENERR || state == FMTERR) {
                admonish (NULL, "format error in message %d (header #%d)",
                      msg, compnum);
+               check_failed = 1;
+           }
            if (datecomp)
                free (datecomp);
            if (subjcomp)
@@ -415,6 +439,7 @@ get_fields (char *datesw, int msg, struct smsg *smsg)
        admonish (NULL, "can't parse %s field in message %d", datesw, msg);
        fstat (fileno (in), &st);
        smsg->s_clock = st.st_mtime;
+       check_failed = 1;
     } else {
        smsg->s_clock = dmktime (tw);
     }