]> diplodocus.org Git - nmh/blobdiff - uip/replsbr.c
Added support for "-" to indicate stdout to output_message().
[nmh] / uip / replsbr.c
index c0ffb726453c35122574213d581aa5e487117087..25049af17d19e7b2dc2697fb980160302fc47b81 100644 (file)
@@ -72,7 +72,7 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen,
     char name[NAMESZ], *scanl;
     unsigned char *cp;
     static int dat[5];                 /* aux. data for format routine */
-    m_getfld_state_t gstate;
+    m_getfld_state_t gstate = 0;
 
     FILE *out;
     NMH_UNUSED (msg);
@@ -132,10 +132,9 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen,
     /*
      * pick any interesting stuff out of msg "inb"
      */
-    m_getfld_state_init (&gstate);
     for (;;) {
        int msg_count = sizeof tmpbuf;
-       state = m_getfld (gstate, name, tmpbuf, &msg_count, inb);
+       state = m_getfld (&gstate, name, tmpbuf, &msg_count, inb);
        switch (state) {
            case FLD: 
            case FLDPLUS: 
@@ -151,7 +150,7 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen,
                    char_read += msg_count;
                    while (state == FLDPLUS) {
                        msg_count= sizeof tmpbuf;
-                       state = m_getfld (gstate, name, tmpbuf, &msg_count, inb);
+                       state = m_getfld (&gstate, name, tmpbuf, &msg_count, inb);
                        fmt_appendcomp(i, name, tmpbuf);
                        char_read += msg_count;
                    }
@@ -159,7 +158,7 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen,
 
                while (state == FLDPLUS) {
                    msg_count= sizeof tmpbuf;
-                   state = m_getfld (gstate, name, tmpbuf, &msg_count, inb);
+                   state = m_getfld (&gstate, name, tmpbuf, &msg_count, inb);
                }
                break;
 
@@ -173,12 +172,12 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen,
                adios (NULL, "m_getfld() returned %d", state);
        }
     }
-    m_getfld_state_destroy (&gstate);
 
     /*
      * format and output the header lines.
      */
 finished:
+    m_getfld_state_destroy (&gstate);
 
     /*
      * if there's a "Subject" component, strip any "Re:"s off it
@@ -413,7 +412,8 @@ replfilter (FILE *in, FILE *out, char *filter, int fmtproc)
     int        pid;
     char *mhl;
     char *errstr;
-    char *arglist[7];
+    char **arglist;
+    int argnum;
 
     if (filter == NULL)
        return;
@@ -421,12 +421,10 @@ replfilter (FILE *in, FILE *out, char *filter, int fmtproc)
     if (access (filter, R_OK) == NOTOK)
        adios (filter, "unable to read");
 
-    mhl = r1bindex (mhlproc, '/');
-
     rewind (in);
     lseek (fileno(in), (off_t) 0, SEEK_SET);
 
-    switch (pid = vfork()) {
+    switch (pid = fork()) {
        case NOTOK: 
            adios ("fork", "unable to");
 
@@ -435,26 +433,29 @@ replfilter (FILE *in, FILE *out, char *filter, int fmtproc)
            dup2 (fileno (out), fileno (stdout));
            closefds (3);
 
-           arglist[0] = mhl;
-           arglist[1] = "-form";
-           arglist[2] = filter;
-           arglist[3] = "-noclear";
+           /*
+            * We're not allocating the memory for the extra arguments,
+            * because we never call arglist_free().  But if we ever change
+            * that be sure to use getcpy() for the extra arguments.
+            */
+           arglist = argsplit(mhlproc, &mhl, &argnum);
+           arglist[argnum++] = "-form";
+           arglist[argnum++] = filter;
+           arglist[argnum++] = "-noclear";
 
            switch (fmtproc) {
            case 1:
-               arglist[4] = "-fmtproc";
-               arglist[5] = formatproc;
-               arglist[6] = NULL;
+               arglist[argnum++] = "-fmtproc";
+               arglist[argnum++] = formatproc;
                break;
            case 0:
-               arglist[4] = "-nofmtproc";
-               arglist[5] = NULL;
+               arglist[argnum++] = "-nofmtproc";
                break;
-           default:
-               arglist[4] = NULL;
            }
 
-           execvp (mhlproc, arglist);
+           arglist[argnum++] = NULL;
+
+           execvp (mhl, arglist);
            errstr = strerror(errno);
            write(2, "unable to exec ", 15);
            write(2, mhlproc, strlen(mhlproc));