]> diplodocus.org Git - nmh/blobdiff - uip/rcvdist.c
vector.c: Move interface to own file.
[nmh] / uip / rcvdist.c
index a8231e911167c424b6aa4b07f490b45addd5372e..bfcf57d4c3741cf02305c6a68c0cc79c8d4c47ef 100644 (file)
@@ -1,18 +1,23 @@
-
-/*
- * rcvdist.c -- asynchronously redistribute messages
+/* rcvdist.c -- asynchronously redistribute messages
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
  * complete copyright information.
  */
 
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
  * 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/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) \
 
 #define RCVDIST_SWITCHES \
     X("form formfile", 4, FORMSW) \
@@ -42,15 +47,15 @@ int
 main (int argc, char **argv)
 {
     pid_t child_id;
 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;
 
     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
 
     /*
      * Configure this now, since any unknown switches to rcvdist get
@@ -85,7 +90,7 @@ main (int argc, char **argv)
 
                case FORMSW: 
                    if (!(form = *argp++) || *form == '-')
 
                case FORMSW: 
                    if (!(form = *argp++) || *form == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
+                       die("missing argument to %s", argp[-2]);
                    continue;
            }
        }
                    continue;
            }
        }
@@ -93,13 +98,13 @@ main (int argc, char **argv)
     }
 
     if (addrs == NULL)
     }
 
     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) {
            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));
 
     }
     strncpy (tmpfil, tfile, sizeof(tmpfil));
 
@@ -107,7 +112,7 @@ main (int argc, char **argv)
     fseek (fp, 0L, SEEK_SET);
 
     if ((tfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
     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));
 
     }
     strncpy (drft, tfile, sizeof(tmpfil));
 
@@ -125,11 +130,11 @@ main (int argc, char **argv)
     vec[vecp++] = drft;
     vec[vecp] = NULL;
 
     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: 
     switch (child_id) {
        case NOTOK: 
-           admonish (NULL, "unable to fork");/* fall */
+            adios("fork", "failed:");
+
        case OK: 
            execvp (program, vec);
            fprintf (stderr, "unable to exec ");
        case OK: 
            execvp (program, vec);
            fprintf (stderr, "unable to exec ");
@@ -145,8 +150,6 @@ main (int argc, char **argv)
 
 /* very similar to routine in replsbr.c */
 
 
 /* very similar to routine in replsbr.c */
 
-#define        SBUFSIZ 256
-
 static int outputlinelen = OUTPUTLINELEN;
 
 static struct format *fmt;
 static int outputlinelen = OUTPUTLINELEN;
 
 static struct format *fmt;
@@ -175,11 +178,11 @@ rcvdistout (FILE *inb, char *form, char *addrs)
 {
     int char_read = 0, format_len, i, state;
     char **ap;
 {
     int char_read = 0, format_len, i, state;
     char **ap;
-    char *cp, name[NAMESZ], tmpbuf[SBUFSIZ];
+    char *cp, name[NAMESZ], tmpbuf[NMH_BUFSIZ];
     charstring_t scanl;
     struct comp *cptr;
     FILE *out;
     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");
 
     if (!(out = fopen (drft, "w")))
        adios (drft, "unable to create");
@@ -199,25 +202,26 @@ rcvdistout (FILE *inb, char *form, char *addrs)
     if (cptr)
        cptr->c_text = addrs;
 
     if (cptr)
        cptr->c_text = addrs;
 
+    gstate = m_getfld_state_init(inb);
     for (;;) {
     for (;;) {
-       int msg_count = SBUFSIZ;
-       switch (state = m_getfld (&gstate, name, tmpbuf, &msg_count, inb)) {
+       int msg_count = sizeof tmpbuf;
+       switch (state = m_getfld2(&gstate, name, tmpbuf, &msg_count)) {
            case FLD: 
            case FLDPLUS: 
                i = fmt_addcomptext(name, tmpbuf);
                if (i != -1) {
                    char_read += msg_count;
                    while (state == FLDPLUS) {
            case FLD: 
            case FLDPLUS: 
                i = fmt_addcomptext(name, tmpbuf);
                if (i != -1) {
                    char_read += msg_count;
                    while (state == FLDPLUS) {
-                       msg_count = SBUFSIZ;
-                       state = m_getfld (&gstate, name, tmpbuf, &msg_count, inb);
+                       msg_count = sizeof tmpbuf;
+                       state = m_getfld2(&gstate, name, tmpbuf, &msg_count);
                        fmt_appendcomp(i, name, tmpbuf);
                        char_read += msg_count;
                    }
                }
 
                while (state == FLDPLUS) {
                        fmt_appendcomp(i, name, tmpbuf);
                        char_read += msg_count;
                    }
                }
 
                while (state == FLDPLUS) {
-                   msg_count = SBUFSIZ;
-                   state = m_getfld (&gstate, name, tmpbuf, &msg_count, inb);
+                   msg_count = sizeof tmpbuf;
+                   state = m_getfld2(&gstate, name, tmpbuf, &msg_count);
                }
                break;
 
                }
                break;
 
@@ -228,7 +232,7 @@ rcvdistout (FILE *inb, char *form, char *addrs)
                goto finished;
 
            default: 
                goto finished;
 
            default: 
-               adios (NULL, "m_getfld() returned %d", state);
+               die("m_getfld2() returned %d", state);
        }
     }
 finished: ;
        }
     }
 finished: ;
@@ -250,7 +254,7 @@ finished: ;
 }
 
 
 }
 
 
-static void
+static void NORETURN
 unlink_done (int status)
 {
     if (backup[0])
 unlink_done (int status)
 {
     if (backup[0])