]> diplodocus.org Git - nmh/blobdiff - uip/rcvdist.c
fdcompare.c: Move interface to own file.
[nmh] / uip / rcvdist.c
index 3707e8b5e047f0bfbd686995295705b83b206f53..6f6f5559c0ff744f9af79815c49bb4b8a42a0db2 100644 (file)
@@ -5,12 +5,21 @@
  * complete copyright information.
  */
 
-#include <h/mh.h>
-#include <h/fmt_scan.h>
-#include <h/rcvmail.h>
-#include <h/tws.h>
-#include <h/mts.h>
-#include <h/utils.h>
+#include "h/mh.h"
+#include "sbr/context_find.h"
+#include "sbr/ambigsw.h"
+#include "sbr/pidstatus.h"
+#include "sbr/print_version.h"
+#include "sbr/print_help.h"
+#include "sbr/arglist.h"
+#include "sbr/error.h"
+#include "h/fmt_scan.h"
+#include "h/rcvmail.h"
+#include "h/tws.h"
+#include "h/mts.h"
+#include "h/done.h"
+#include "h/utils.h"
+#include "sbr/m_mktemp.h"
 
 #define RCVDIST_SWITCHES \
     X("form formfile", 4, FORMSW) \
@@ -40,15 +49,15 @@ int
 main (int argc, char **argv)
 {
     pid_t child_id;
-    int i, vecp;
+    int vecp;
     char *addrs = NULL, *cp, *form = NULL, buf[BUFSIZ], *program;
     char **argp, **arguments, **vec;
     FILE *fp;
     char *tfile = NULL;
 
-    if (nmh_init(argv[0], 2)) { return 1; }
+    if (nmh_init(argv[0], true, false)) { return 1; }
 
-    done=unlink_done;
+    set_done(unlink_done);
 
     /*
      * Configure this now, since any unknown switches to rcvdist get
@@ -83,7 +92,7 @@ main (int argc, char **argv)
 
                case FORMSW: 
                    if (!(form = *argp++) || *form == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
+                       die("missing argument to %s", argp[-2]);
                    continue;
            }
        }
@@ -91,13 +100,13 @@ main (int argc, char **argv)
     }
 
     if (addrs == NULL)
-       adios (NULL, "usage: %s [switches] [switches for postproc] address ...",
+       die("usage: %s [switches] [switches for postproc] address ...",
            invo_name);
 
     umask (~m_gmprot ());
 
     if ((tfile = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) {
-       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+       die("unable to create temporary file in %s", get_temp_dir());
     }
     strncpy (tmpfil, tfile, sizeof(tmpfil));
 
@@ -105,7 +114,7 @@ main (int argc, char **argv)
     fseek (fp, 0L, SEEK_SET);
 
     if ((tfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
-       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+       die("unable to create temporary file in %s", get_temp_dir());
     }
     strncpy (drft, tfile, sizeof(tmpfil));
 
@@ -123,12 +132,11 @@ main (int argc, char **argv)
     vec[vecp++] = drft;
     vec[vecp] = NULL;
 
-    for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++)
-       sleep (5);
+    child_id = fork();
     switch (child_id) {
        case NOTOK: 
-           inform("unable to fork, continuing...");
-           /* FALLTHRU */
+            adios("fork", "failed:");
+
        case OK: 
            execvp (program, vec);
            fprintf (stderr, "unable to exec ");
@@ -176,7 +184,7 @@ rcvdistout (FILE *inb, char *form, char *addrs)
     charstring_t scanl;
     struct comp *cptr;
     FILE *out;
-    m_getfld_state_t gstate = 0;
+    m_getfld_state_t gstate;
 
     if (!(out = fopen (drft, "w")))
        adios (drft, "unable to create");
@@ -196,9 +204,10 @@ rcvdistout (FILE *inb, char *form, char *addrs)
     if (cptr)
        cptr->c_text = addrs;
 
+    gstate = m_getfld_state_init(inb);
     for (;;) {
        int msg_count = sizeof tmpbuf;
-       switch (state = m_getfld (&gstate, name, tmpbuf, &msg_count, inb)) {
+       switch (state = m_getfld2(&gstate, name, tmpbuf, &msg_count)) {
            case FLD: 
            case FLDPLUS: 
                i = fmt_addcomptext(name, tmpbuf);
@@ -206,7 +215,7 @@ rcvdistout (FILE *inb, char *form, char *addrs)
                    char_read += msg_count;
                    while (state == FLDPLUS) {
                        msg_count = sizeof tmpbuf;
-                       state = m_getfld (&gstate, name, tmpbuf, &msg_count, inb);
+                       state = m_getfld2(&gstate, name, tmpbuf, &msg_count);
                        fmt_appendcomp(i, name, tmpbuf);
                        char_read += msg_count;
                    }
@@ -214,7 +223,7 @@ rcvdistout (FILE *inb, char *form, char *addrs)
 
                while (state == FLDPLUS) {
                    msg_count = sizeof tmpbuf;
-                   state = m_getfld (&gstate, name, tmpbuf, &msg_count, inb);
+                   state = m_getfld2(&gstate, name, tmpbuf, &msg_count);
                }
                break;
 
@@ -225,7 +234,7 @@ rcvdistout (FILE *inb, char *form, char *addrs)
                goto finished;
 
            default: 
-               adios (NULL, "m_getfld() returned %d", state);
+               die("m_getfld2() returned %d", state);
        }
     }
 finished: ;