]> diplodocus.org Git - nmh/blobdiff - uip/mhlsbr.c
sbr/utils.c: Delete dead-code open_form(); not called.
[nmh] / uip / mhlsbr.c
index ac5dc89a874ecf96594f115b6304f9bd9de1dbdd..a4402c567301d6eab9c44e7ec3f2b4efd1ad9b6c 100644 (file)
@@ -1,6 +1,4 @@
-
-/*
- * mhlsbr.c -- main routines for nmh message lister
+/* mhlsbr.c -- main routines for nmh message lister
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -13,6 +11,7 @@
 #include <h/fmt_scan.h>
 #include <h/tws.h>
 #include <h/utils.h>
 #include <h/fmt_scan.h>
 #include <h/tws.h>
 #include <h/utils.h>
+#include "../sbr/m_popen.h"
 #include <setjmp.h>
 #include <sys/types.h>
 
 #include <setjmp.h>
 #include <sys/types.h>
 
@@ -22,7 +21,7 @@
  * set, then addresses get split wrong (not at the spaces between commas).
  * To fix this correctly, putstr() should know about "atomic" strings that
  * must NOT be broken across lines.  That's too difficult for right now
  * set, then addresses get split wrong (not at the spaces between commas).
  * To fix this correctly, putstr() should know about "atomic" strings that
  * must NOT be broken across lines.  That's too difficult for right now
- * (it turns out that there are a number of degernate cases), so in
+ * (it turns out that there are a number of degenerate cases), so in
  * oneline(), instead of
  *
  *       (*onelp == '\n' && !onelp[1])
  * oneline(), instead of
  *
  *       (*onelp == '\n' && !onelp[1])
@@ -304,14 +303,7 @@ static char delim3[] =             /* from forw.c */
     "\n----------------------------------------------------------------------\n\n";
 static char delim4[] = "\n------------------------------\n\n";
 
     "\n----------------------------------------------------------------------\n\n";
 static char delim4[] = "\n------------------------------\n\n";
 
-static FILE *(*mhl_action) () = (FILE *(*) ()) 0;
-
-/*
- * Redefine a couple of functions.
- * These are undefined later in the code.
- */
-#define        adios mhladios
-#define        done  mhldone
+static FILE *(*mhl_action)(char *);
 
 /*
  * prototypes
 
 /*
  * prototypes
@@ -367,17 +359,21 @@ mhl (int argc, char **argv)
            switch (smatch (++cp, mhlswitches)) {
                case AMBIGSW: 
                    ambigsw (cp, mhlswitches);
            switch (smatch (++cp, mhlswitches)) {
                case AMBIGSW: 
                    ambigsw (cp, mhlswitches);
-                   done (1);
+                   mhldone (1);
+                   /* FALLTHRU */
                case UNKWNSW: 
                case UNKWNSW: 
-                   adios (NULL, "-%s unknown\n", cp);
+                   mhladios (NULL, "-%s unknown\n", cp);
+                   /* FALLTHRU */
 
                case HELPSW: 
                    snprintf (buf, sizeof(buf), "%s [switches] [files ...]", invo_name);
                    print_help (buf, mhlswitches, 1);
 
                case HELPSW: 
                    snprintf (buf, sizeof(buf), "%s [switches] [files ...]", invo_name);
                    print_help (buf, mhlswitches, 1);
-                   done (0);
+                   mhldone (0);
+                   /* FALLTHRU */
                case VERSIONSW:
                    print_version(invo_name);
                case VERSIONSW:
                    print_version(invo_name);
-                   done (0);
+                   mhldone (0);
+                   /* FALLTHRU */
 
                case BELLSW: 
                    bellflg = 1;
 
                case BELLSW: 
                    bellflg = 1;
@@ -395,23 +391,23 @@ mhl (int argc, char **argv)
 
                case FOLDSW: 
                    if (!(folder = *argp++) || *folder == '-')
 
                case FOLDSW: 
                    if (!(folder = *argp++) || *folder == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
+                       mhladios (NULL, "missing argument to %s", argp[-2]);
                    continue;
                case FORMSW: 
                    if (!(form = *argp++) || *form == '-')
                    continue;
                case FORMSW: 
                    if (!(form = *argp++) || *form == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
+                       mhladios (NULL, "missing argument to %s", argp[-2]);
                    continue;
 
                case SLEEPSW:
                    if (!(cp = *argp++) || *cp == '-')
                    continue;
 
                case SLEEPSW:
                    if (!(cp = *argp++) || *cp == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
+                       mhladios (NULL, "missing argument to %s", argp[-2]);
                    else
                        sleepsw = atoi (cp);/* ZERO ok! */
                    continue;
 
                case PROGSW:
                    if (!(moreproc = *argp++) || *moreproc == '-')
                    else
                        sleepsw = atoi (cp);/* ZERO ok! */
                    continue;
 
                case PROGSW:
                    if (!(moreproc = *argp++) || *moreproc == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
+                       mhladios (NULL, "missing argument to %s", argp[-2]);
                    continue;
                case NPROGSW:
                    nomore++;
                    continue;
                case NPROGSW:
                    nomore++;
@@ -419,7 +415,7 @@ mhl (int argc, char **argv)
 
                case FMTPROCSW:
                    if (!(formatproc = *argp++) || *formatproc == '-')
 
                case FMTPROCSW:
                    if (!(formatproc = *argp++) || *formatproc == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
+                       mhladios (NULL, "missing argument to %s", argp[-2]);
                    continue;
                case NFMTPROCSW:
                    formatproc = NULL;
                    continue;
                case NFMTPROCSW:
                    formatproc = NULL;
@@ -427,46 +423,47 @@ mhl (int argc, char **argv)
 
                case LENSW: 
                    if (!(cp = *argp++) || *cp == '-')
 
                case LENSW: 
                    if (!(cp = *argp++) || *cp == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
+                       mhladios (NULL, "missing argument to %s", argp[-2]);
                    else if ((length = atoi (cp)) < 1)
                    else if ((length = atoi (cp)) < 1)
-                       adios (NULL, "bad argument %s %s", argp[-2], cp);
+                       mhladios (NULL, "bad argument %s %s", argp[-2], cp);
                    continue;
                case WIDTHSW: 
                    if (!(cp = *argp++) || *cp == '-')
                    continue;
                case WIDTHSW: 
                    if (!(cp = *argp++) || *cp == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
+                       mhladios (NULL, "missing argument to %s", argp[-2]);
                    else if ((width = atoi (cp)) < 1)
                    else if ((width = atoi (cp)) < 1)
-                       adios (NULL, "bad argument %s %s", argp[-2], cp);
+                       mhladios (NULL, "bad argument %s %s", argp[-2], cp);
                    continue;
 
                case DGSTSW: 
                    if (!(digest = *argp++) || *digest == '-')
                    continue;
 
                case DGSTSW: 
                    if (!(digest = *argp++) || *digest == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
+                       mhladios (NULL, "missing argument to %s", argp[-2]);
                    continue;
                case ISSUESW:
                    if (!(cp = *argp++) || *cp == '-')
                    continue;
                case ISSUESW:
                    if (!(cp = *argp++) || *cp == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
+                       mhladios (NULL, "missing argument to %s", argp[-2]);
                    else if ((issue = atoi (cp)) < 1)
                    else if ((issue = atoi (cp)) < 1)
-                       adios (NULL, "bad argument %s %s", argp[-2], cp);
+                       mhladios (NULL, "bad argument %s %s", argp[-2], cp);
                    continue;
                case VOLUMSW:
                    if (!(cp = *argp++) || *cp == '-')
                    continue;
                case VOLUMSW:
                    if (!(cp = *argp++) || *cp == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
+                       mhladios (NULL, "missing argument to %s", argp[-2]);
                    else if ((volume = atoi (cp)) < 1)
                    else if ((volume = atoi (cp)) < 1)
-                       adios (NULL, "bad argument %s %s", argp[-2], cp);
+                       mhladios (NULL, "bad argument %s %s", argp[-2], cp);
                    continue;
 
                case FORW2SW: 
                    continue;
 
                case FORW2SW: 
-                   forwall++;  /* fall */
+                   forwall++;
+                   /* FALLTHRU */
                case FORW1SW: 
                    forwflg++;
                    clearflg = -1;/* XXX */
                    continue;
 
                case BITSTUFFSW: 
                case FORW1SW: 
                    forwflg++;
                    clearflg = -1;/* XXX */
                    continue;
 
                case BITSTUFFSW: 
-                   dashstuff = 1;      /* trinary logic */
+                   dashstuff = 1;      /* ternary logic */
                    continue;
                case NBITSTUFFSW: 
                    continue;
                case NBITSTUFFSW: 
-                   dashstuff = -1;     /* trinary logic */
+                   dashstuff = -1;     /* ternary logic */
                    continue;
 
                case NBODYSW: 
                    continue;
 
                case NBODYSW: 
@@ -525,12 +522,12 @@ mhl (int argc, char **argv)
        }
        else
            printf ("\n------- End of Forwarded Message%s\n",
        }
        else
            printf ("\n------- End of Forwarded Message%s\n",
-                   vecp > 1 ? "s" : "");
+                   PLURALS(vecp));
     }
 
     fflush(stdout);
     if(ferror(stdout)){
     }
 
     fflush(stdout);
     if(ferror(stdout)){
-           adios("output", "error writing");
+           mhladios("output", "error writing");
     }
     
     if (clearflg > 0 && ontty == NOTTY)
     }
     
     if (clearflg > 0 && ontty == NOTTY)
@@ -566,7 +563,7 @@ mhl_format (char *file, int length, int width)
     }
 
     if ((fp = fopen (etcpath (file), "r")) == NULL)
     }
 
     if ((fp = fopen (etcpath (file), "r")) == NULL)
-       adios (file, "unable to open format file");
+       mhladios (file, "unable to open format file");
 
     if (fstat (fileno (fp), &st) != NOTOK) {
        mtime = st.st_mtime;
 
     if (fstat (fileno (fp), &st) != NOTOK) {
        mtime = st.st_mtime;
@@ -592,7 +589,7 @@ mhl_format (char *file, int length, int width)
        if (*bp == ';')
            continue;
 
        if (*bp == ';')
            continue;
 
-        TrimSuffixC(bp, '\n');
+        trim_suffix_c(bp, '\n');
 
        if (*bp == ':') {
            (void) add_queue (&fmthd, &fmttl, NULL, bp + 1, CLEARTEXT);
 
        if (*bp == ':') {
            (void) add_queue (&fmthd, &fmttl, NULL, bp + 1, CLEARTEXT);
@@ -629,7 +626,7 @@ mhl_format (char *file, int length, int width)
                parptr = bp;
                while (*parptr) {
                    if (evalvar (&global))
                parptr = bp;
                while (*parptr) {
                    if (evalvar (&global))
-                       adios (NULL, "format file syntax error: %s", bp);
+                       mhladios (NULL, "format file syntax error: %s", bp);
                    if (*parptr)
                        parptr++;
                }
                    if (*parptr)
                        parptr++;
                }
@@ -640,7 +637,7 @@ mhl_format (char *file, int length, int width)
                while (*parptr == ':' || *parptr == ',') {
                    parptr++;
                    if (evalvar (c1))
                while (*parptr == ':' || *parptr == ',') {
                    parptr++;
                    if (evalvar (c1))
-                       adios (NULL, "format file syntax error: %s", bp);
+                       mhladios (NULL, "format file syntax error: %s", bp);
                }
                if (!c1->c_nfs && global.c_nfs) {
                    if (c1->c_flags & DATEFMT) {
                }
                if (!c1->c_nfs && global.c_nfs) {
                    if (c1->c_flags & DATEFMT) {
@@ -660,7 +657,7 @@ mhl_format (char *file, int length, int width)
                continue;
 
            default: 
                continue;
 
            default: 
-               adios (NULL, "format file syntax error: %s", bp);
+               mhladios (NULL, "format file syntax error: %s", bp);
        }
     }
     fclose (fp);
        }
     }
     fclose (fp);
@@ -773,7 +770,7 @@ evalvar (struct mcomp *c1)
            return 1;
 
        if (! c1->c_name  ||  strcasecmp (c1->c_name, "body")) {
            return 1;
 
        if (! c1->c_name  ||  strcasecmp (c1->c_name, "body")) {
-           advise (NULL, "format filters are currently only supported on "
+           inform("format filters are currently only supported on "
                    "the \"body\" component");
            return 1;
        }
                    "the \"body\" component");
            return 1;
        }
@@ -804,7 +801,7 @@ ptoi (char *name, int *i)
     char *cp;
 
     if (*parptr++ != '=' || !*(cp = parse ())) {
     char *cp;
 
     if (*parptr++ != '=' || !*(cp = parse ())) {
-       advise (NULL, "missing argument to variable %s", name);
+       inform("missing argument to variable %s", name);
        return 1;
     }
 
        return 1;
     }
 
@@ -819,7 +816,7 @@ ptos (char *name, char **s)
     char c, *cp;
 
     if (*parptr++ != '=') {
     char c, *cp;
 
     if (*parptr++ != '=') {
-       advise (NULL, "missing argument to variable %s", name);
+       inform("missing argument to variable %s", name);
        return 1;
     }
 
        return 1;
     }
 
@@ -852,15 +849,14 @@ parse (void)
 
     for (cp = result; *parptr && (cp - result < NAMESZ); parptr++) {
        c = *parptr;
 
     for (cp = result; *parptr && (cp - result < NAMESZ); parptr++) {
        c = *parptr;
-       if (isalnum (c)
-               || c == '.'
-               || c == '-'
-               || c == '_'
-               || c =='['
-               || c == ']')
-           *cp++ = c;
-       else
+       if (!isalnum (c)
+               && c != '.'
+               && c != '-'
+               && c != '_'
+               && c !='['
+               && c != ']')
            break;
            break;
+        *cp++ = c;
     }
     *cp = '\0';
 
     }
     *cp = '\0';
 
@@ -907,7 +903,7 @@ process (char *folder, char *fname, int ofilen, int ofilec)
            cp = folder ? concat (folder, ":", fname2, NULL) : mh_xstrdup(fname2);
            if (ontty != PITTY)
                SIGNAL (SIGINT, intrser);
            cp = folder ? concat (folder, ":", fname2, NULL) : mh_xstrdup(fname2);
            if (ontty != PITTY)
                SIGNAL (SIGINT, intrser);
-           mhlfile (fp, cp, ofilen, ofilec);  /* FALL THROUGH! */
+           mhlfile (fp, cp, ofilen, ofilec);
             free (cp);
 
            for (ap = arglist_head; ap; ap = ap->a_next) {
             free (cp);
 
            for (ap = arglist_head; ap; ap = ap->a_next) {
@@ -916,7 +912,8 @@ process (char *folder, char *fname, int ofilen, int ofilec)
            }
 
            if (arglist_head)
            }
 
            if (arglist_head)
-               fmt_free(NULL, 1);
+               fmt_free(NULL, 1);
+           /* FALLTHRU */
 
        default:
            if (ontty != PITTY)
 
        default:
            if (ontty != PITTY)
@@ -939,7 +936,7 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec)
 {
     int state, bucket;
     struct mcomp *c1, *c2, *c3;
 {
     int state, bucket;
     struct mcomp *c1, *c2, *c3;
-    char **ip, name[NAMESZ], buf[BUFSIZ];
+    char **ip, name[NAMESZ], buf[NMH_BUFSIZ];
     m_getfld_state_t gstate = 0;
 
     compile_filterargs();
     m_getfld_state_t gstate = 0;
 
     compile_filterargs();
@@ -950,7 +947,7 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec)
        else {
            printf ("\n-------");
            if (ofilen == 1)
        else {
            printf ("\n-------");
            if (ofilen == 1)
-               printf (" Forwarded Message%s", ofilec > 1 ? "s" : "");
+               printf (" Forwarded Message%s", PLURALS(ofilec));
            else
                printf (" Message %d", ofilen);
            printf ("\n\n");
            else
                printf (" Message %d", ofilen);
            printf ("\n\n");
@@ -1023,13 +1020,13 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec)
                    continue;
 
                for (c2 = fmthd; c2; c2 = c2->c_next)
                    continue;
 
                for (c2 = fmthd; c2; c2 = c2->c_next)
-                   if (!strcasecmp (c2->c_name ? c2->c_name : "", name))
+                   if (!strcasecmp (FENDNULL(c2->c_name), name))
                        break;
                c1 = NULL;
                if (!((c3 = c2 ? c2 : &global)->c_flags & SPLIT))
                    for (c1 = msghd; c1; c1 = c1->c_next)
                        break;
                c1 = NULL;
                if (!((c3 = c2 ? c2 : &global)->c_flags & SPLIT))
                    for (c1 = msghd; c1; c1 = c1->c_next)
-                       if (!strcasecmp (c1->c_name ? c1->c_name : "",
-                                        c3->c_name ? c3->c_name : "")) {
+                       if (!strcasecmp (FENDNULL(c1->c_name),
+                                        FENDNULL(c3->c_name))) {
                            c1->c_text =
                                mcomp_add (c1->c_flags, buf, c1->c_text);
                            break;
                            c1->c_text =
                                mcomp_add (c1->c_flags, buf, c1->c_text);
                            break;
@@ -1089,8 +1086,8 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec)
                        continue;
                    }
                    for (c2 = msghd; c2; c2 = c2->c_next)
                        continue;
                    }
                    for (c2 = msghd; c2; c2 = c2->c_next)
-                       if (!strcasecmp (c2->c_name ? c2->c_name : "",
-                                        c1->c_name ? c1->c_name : "")) {
+                       if (!strcasecmp (FENDNULL(c2->c_name),
+                                        FENDNULL(c1->c_name))) {
                            putcomp (c1, c2, ONECOMP);
                            if (!(c1->c_flags & SPLIT))
                                break;
                            putcomp (c1, c2, ONECOMP);
                            if (!(c1->c_flags & SPLIT))
                                break;
@@ -1101,13 +1098,13 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec)
 
            case LENERR: 
            case FMTERR: 
 
            case LENERR: 
            case FMTERR: 
-               advise (NULL, "format error in message %s", mname);
+               inform("format error in message %s", mname);
                exitstat++;
                m_getfld_state_destroy (&gstate);
                return;
 
            default: 
                exitstat++;
                m_getfld_state_destroy (&gstate);
                return;
 
            default: 
-               adios (NULL, "getfld() returned %d", state);
+               mhladios (NULL, "getfld() returned %d", state);
        }
     }
 }
        }
     }
 }
@@ -1310,7 +1307,7 @@ putcomp (struct mcomp *c1, struct mcomp *c2, int flag)
     if ((ovtxt = c1->c_ovtxt ? c1->c_ovtxt : global.c_ovtxt) == NULL)
        ovtxt = "";
     if (wid < ovoff + strlen (ovtxt) + 5)
     if ((ovtxt = c1->c_ovtxt ? c1->c_ovtxt : global.c_ovtxt) == NULL)
        ovtxt = "";
     if (wid < ovoff + strlen (ovtxt) + 5)
-       adios (NULL, "component: %s width(%d) too small for overflow(%d)",
+       mhladios (NULL, "component: %s width(%d) too small for overflow(%d)",
                c1->c_name, wid, ovoff + strlen (ovtxt) + 5);
     onelp = NULL;
 
                c1->c_name, wid, ovoff + strlen (ovtxt) + 5);
     onelp = NULL;
 
@@ -1337,7 +1334,7 @@ putcomp (struct mcomp *c1, struct mcomp *c2, int flag)
 
     if (!(c1->c_flags & HDROUTPUT) && !(c1->c_flags & NOCOMPONENT)) {
         if (c1->c_flags & UPPERCASE)           /* uppercase component also */
 
     if (!(c1->c_flags & HDROUTPUT) && !(c1->c_flags & NOCOMPONENT)) {
         if (c1->c_flags & UPPERCASE)           /* uppercase component also */
-            ToUpper(text);
+            to_upper(text);
        putstr(text, c1->c_flags);
        if (flag != BODYCOMP) {
            putstr (": ", c1->c_flags);
        putstr(text, c1->c_flags);
        if (flag != BODYCOMP) {
            putstr (": ", c1->c_flags);
@@ -1357,7 +1354,7 @@ putcomp (struct mcomp *c1, struct mcomp *c2, int flag)
            && !(c2->c_flags & HDROUTPUT)
            && !(c2->c_flags & NOCOMPONENT)) {
         if (c1->c_flags & UPPERCASE)
            && !(c2->c_flags & HDROUTPUT)
            && !(c2->c_flags & NOCOMPONENT)) {
         if (c1->c_flags & UPPERCASE)
-            ToUpper(c2->c_name);
+            to_upper(c2->c_name);
        putstr (c2->c_name, c1->c_flags);
        putstr (": ", c1->c_flags);
        if (!(c1->c_flags & SPLIT))
        putstr (c2->c_name, c1->c_flags);
        putstr (": ", c1->c_flags);
        if (!(c1->c_flags & SPLIT))
@@ -1369,7 +1366,7 @@ putcomp (struct mcomp *c1, struct mcomp *c2, int flag)
                putstr (" ", c1->c_flags);
     }
     if (c1->c_flags & UPPERCASE)
                putstr (" ", c1->c_flags);
     }
     if (c1->c_flags & UPPERCASE)
-        ToUpper(c2->c_text);
+        to_upper(c2->c_text);
 
     count = 0;
     if (cchdr) {
 
     count = 0;
     if (cchdr) {
@@ -1434,11 +1431,10 @@ oneline (char *stuff, unsigned long flags)
                    *onelp++ = 0;
                    break;
                }
                    *onelp++ = 0;
                    break;
                }
-               else
-                   if (!spc) {
-                       *cp++ = ' ';
-                       spc++;
-                   }
+                if (!spc) {
+                    *cp++ = ' ';
+                    spc++;
+                }
            }
            else {
                *cp++ = *onelp;
            }
            else {
                *cp++ = *onelp;
@@ -1486,7 +1482,7 @@ putstr (char *string, unsigned long flags)
     lm = 0;
 
 #ifdef MULTIBYTE_SUPPORT
     lm = 0;
 
 #ifdef MULTIBYTE_SUPPORT
-    (void) mbtowc (NULL, NULL, 0); /* reset shift state */
+    if (mbtowc (NULL, NULL, 0)) {} /* reset shift state */
     char_len = 0;
 #else
     NMH_UNUSED (char_len);
     char_len = 0;
 #else
     NMH_UNUSED (char_len);
@@ -1595,7 +1591,7 @@ putch (char ch, unsigned long flags)
        putch ('\n', flags);
        if (ovoff > 0)
            lm = ovoff;
        putch ('\n', flags);
        if (ovoff > 0)
            lm = ovoff;
-       putstr (ovtxt ? ovtxt : "", flags);
+       putstr (FENDNULL(ovtxt), flags);
        putch (ch, flags);
        return;
     }
        putch (ch, flags);
        return;
     }
@@ -1624,7 +1620,7 @@ pipeser (int i)
 {
     NMH_UNUSED (i);
 
 {
     NMH_UNUSED (i);
 
-    done (NOTOK);
+    mhldone (NOTOK);
 }
 
 
 }
 
 
@@ -1635,13 +1631,10 @@ quitser (int i)
 
     putchar ('\n');
     fflush (stdout);
 
     putchar ('\n');
     fflush (stdout);
-    done (NOTOK);
+    mhldone (NOTOK);
 }
 
 
 }
 
 
-#undef adios
-#undef done
-
 static void
 mhladios (char *what, char *fmt, ...)
 {
 static void
 mhladios (char *what, char *fmt, ...)
 {