]> diplodocus.org Git - nmh/blobdiff - uip/mhlsbr.c
Added -[no]rmmproc switches to rmm and mhfixmsg.
[nmh] / uip / mhlsbr.c
index 58ffe94c26939315d3552d2c4eff5e3775d2388f..5dbf341cc09c99ccf366db7cbd2eef4e723d2ca4 100644 (file)
 
 #define        QUOTE   '\\'
 
-static struct swit mhlswitches[] = {
-#define        BELLSW         0
-    { "bell", 0 },
-#define        NBELLSW        1
-    { "nobell", 0 },
-#define        CLRSW          2
-    { "clear", 0 },
-#define        NCLRSW         3
-    { "noclear", 0 },
-#define        FOLDSW         4
-    { "folder +folder", 0 },
-#define        FORMSW         5
-    { "form formfile", 0 },
-#define        PROGSW         6
-    { "moreproc program", 0 },
-#define        NPROGSW        7
-    { "nomoreproc", 0 },
-#define        LENSW          8
-    { "length lines", 0 },
-#define        WIDTHSW        9
-    { "width columns", 0 },
-#define        SLEEPSW       10
-    { "sleep seconds",  0 },
-#define        BITSTUFFSW    11
-    { "dashstuffing", -12 },   /* interface from forw */
-#define        NBITSTUFFSW   12
-    { "nodashstuffing", -14 }, /* interface from forw */
-#define VERSIONSW     13
-    { "version", 0 },
-#define        HELPSW        14
-    { "help", 0 },
-#define        FORW1SW       15
-    { "forward", -7 },         /* interface from forw */
-#define        FORW2SW       16
-    { "forwall", -7 },         /* interface from forw */
-#define        DGSTSW        17
-    { "digest list", -6 },
-#define VOLUMSW       18
-    { "volume number", -6 },
-#define ISSUESW       19
-    { "issue number", -5 },
-#define NBODYSW       20
-    { "nobody", -6 },
-#define FMTPROCSW     21
-    { "fmtproc program", 0 },
-#define NFMTPROCSW    22
-    { "nofmtproc", 0 },
-    { NULL, 0 }
-};
+#define MHL_SWITCHES \
+    X("bell", 0, BELLSW) \
+    X("nobell", 0, NBELLSW) \
+    X("clear", 0, CLRSW) \
+    X("noclear", 0, NCLRSW) \
+    X("folder +folder", 0, FOLDSW) \
+    X("form formfile", 0, FORMSW) \
+    X("moreproc program", 0, PROGSW) \
+    X("nomoreproc", 0, NPROGSW) \
+    X("length lines", 0, LENSW) \
+    X("width columns", 0, WIDTHSW) \
+    X("sleep seconds", 0, SLEEPSW) \
+    X("dashstuffing", -12, BITSTUFFSW)    /* interface from forw */ \
+    X("nodashstuffing", -14, NBITSTUFFSW) /* interface from forw */ \
+    X("version", 0, VERSIONSW) \
+    X("help", 0, HELPSW) \
+    X("forward", -7, FORW1SW)             /* interface from forw */ \
+    X("forwall", -7, FORW2SW)             /* interface from forw */ \
+    X("digest list", -6, DGSTSW) \
+    X("volume number", -6, VOLUMSW) \
+    X("issue number", -5, ISSUESW) \
+    X("nobody", -6, NBODYSW) \
+    X("fmtproc program", 0, FMTPROCSW) \
+    X("nofmtproc", 0, NFMTPROCSW) \
+
+#define X(sw, minchars, id) id,
+DEFINE_SWITCH_ENUM(MHL);
+#undef X
+
+#define X(sw, minchars, id) { sw, minchars, id },
+DEFINE_SWITCH_ARRAY(MHL, mhlswitches);
+#undef X
 
 #define NOCOMPONENT 0x000001   /* don't show component name         */
 #define UPPERCASE   0x000002   /* display in all upper case         */
@@ -305,7 +288,7 @@ static unsigned int wid;
 
 static char *ovtxt;
 
-static unsigned char *onelp;
+static char *onelp;
 
 static char *parptr;
 
@@ -1104,19 +1087,20 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec)
                                break;
                        }
                }
+               m_getfld_state_destroy (&gstate);
                return;
 
            case LENERR: 
            case FMTERR: 
                advise (NULL, "format error in message %s", mname);
                exitstat++;
+               m_getfld_state_destroy (&gstate);
                return;
 
            default: 
                adios (NULL, "getfld() returned %d", state);
        }
     }
-    m_getfld_state_destroy (&gstate);
 }
 
 
@@ -1180,7 +1164,8 @@ mcomp_format (struct mcomp *c1, struct mcomp *c2)
            if (!cp[1])
                *cp = 0;
 
-       fmt_scan (c1->c_fmt, buffer, sizeof buffer - 1, sizeof buffer - 1, dat);
+       fmt_scan (c1->c_fmt, buffer, sizeof buffer - 1, sizeof buffer - 1,
+                 dat, NULL);
        /* Don't need to append a newline, dctime() already did */
        c2->c_text = getcpy (buffer);
 
@@ -1213,7 +1198,8 @@ mcomp_format (struct mcomp *c1, struct mcomp *c2)
            p->pq_error = NULL;
        }
 
-       fmt_scan (c1->c_fmt, buffer, sizeof buffer - 1, sizeof buffer - 1, dat);
+       fmt_scan (c1->c_fmt, buffer, sizeof buffer - 1, sizeof buffer - 1,
+                 dat, NULL);
        if (*buffer) {
            if (c2->c_text)
                c2->c_text = add (",\n", c2->c_text);
@@ -1294,7 +1280,7 @@ static void
 putcomp (struct mcomp *c1, struct mcomp *c2, int flag)
 {
     int count, cchdr;
-    unsigned char *cp;
+    char *cp;
 
     cchdr = 0;
     lm = 0;
@@ -1332,8 +1318,8 @@ 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 */
            for (cp = (c1->c_text ? c1->c_text : c1->c_name); *cp; cp++)
-               if (islower (*cp))
-                   *cp = toupper (*cp);
+               if (islower ((unsigned char) *cp))
+                   *cp = toupper ((unsigned char) *cp);
        putstr (c1->c_text ? c1->c_text : c1->c_name, c1->c_flags);
        if (flag != BODYCOMP) {
            putstr (": ", c1->c_flags);
@@ -1355,8 +1341,8 @@ putcomp (struct mcomp *c1, struct mcomp *c2, int flag)
            && !(c2->c_flags & NOCOMPONENT)) {
         if (c1->c_flags & UPPERCASE)
            for (cp = c2->c_name; *cp; cp++)
-               if (islower (*cp))
-                   *cp = toupper (*cp);
+               if (islower ((unsigned char) *cp))
+                   *cp = toupper ((unsigned char) *cp);
        putstr (c2->c_name, c1->c_flags);
        putstr (": ", c1->c_flags);
        if (!(c1->c_flags & SPLIT))
@@ -1369,8 +1355,8 @@ putcomp (struct mcomp *c1, struct mcomp *c2, int flag)
     }
     if (c1->c_flags & UPPERCASE)
        for (cp = c2->c_text; *cp; cp++)
-           if (islower (*cp))
-               *cp = toupper (*cp);
+           if (islower ((unsigned char) *cp))
+               *cp = toupper ((unsigned char) *cp);
 
     count = 0;
     if (cchdr) {
@@ -1417,7 +1403,7 @@ oneline (char *stuff, long flags)
     term = 0;
     if (flags & COMPRESS) {
        for (spc = 1, cp = ret; *onelp; onelp++)
-           if (isspace (*onelp)) {
+           if (isspace ((unsigned char) *onelp)) {
                if (*onelp == '\n' && (!onelp[1] || (flags & ADDRFMT))) {
                    term = '\n';
                    *onelp++ = 0;
@@ -1665,6 +1651,8 @@ static void
 m_popen (char *name)
 {
     int pd[2];
+    char *file;
+    char **arglist;
 
     if (mhl_action && (sd = dup (fileno (stdout))) == NOTOK)
        adios ("standard output", "unable to dup()");
@@ -1672,7 +1660,7 @@ m_popen (char *name)
     if (pipe (pd) == NOTOK)
        adios ("pipe", "unable to");
 
-    switch (m_pid = vfork()) {
+    switch (m_pid = fork()) {
        case NOTOK: 
            adios ("fork", "unable to");
 
@@ -1685,7 +1673,8 @@ m_popen (char *name)
                dup2 (pd[0], fileno (stdin));
                close (pd[0]);
            }
-           execlp (name, r1bindex (name, '/'), NULL);
+           arglist = argsplit(name, &file, NULL);
+           execvp (file, arglist);
            fprintf (stderr, "unable to exec ");
            perror (name);
            _exit (-1);
@@ -1873,18 +1862,17 @@ filterbody (struct mcomp *c1, char *buf, int bufsz, int state, FILE *fp,
      */
 
     switch (filterpid = fork()) {
-        char **args;
+        char **args, *program;
        struct arglist *a;
-       int i, dat[5], s;
+       int i, dat[5], s, argp;
 
     case 0:
        /*
-        * Allocate an argument array for us
+        * Configure an argument array for us
         */
 
-       args = (char **) mh_xmalloc((filter_nargs + 2) * sizeof(char *));
-       args[0] = formatproc;
-       args[filter_nargs + 1] = NULL;
+       args = argsplit(formatproc, &program, &argp);
+       args[argp + filter_nargs] = NULL;
        dat[0] = 0;
        dat[1] = 0;
        dat[2] = 0;
@@ -1895,9 +1883,9 @@ filterbody (struct mcomp *c1, char *buf, int bufsz, int state, FILE *fp,
         * Pull out each argument and scan them.
         */
 
-       for (a = arglist_head, i = 1; a != NULL; a = a->a_next, i++) {
+       for (a = arglist_head, i = argp; a != NULL; a = a->a_next, i++) {
            args[i] = mh_xmalloc(BUFSIZ);
-           fmt_scan(a->a_fmt, args[i], BUFSIZ - 1, BUFSIZ, dat);
+           fmt_scan(a->a_fmt, args[i], BUFSIZ - 1, BUFSIZ, dat, NULL);
            /*
             * fmt_scan likes to put a trailing newline at the end of the
             * format string.  If we have one, get rid of it.