X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Frcvdist.c;h=d3f36caa594f7734c105c8a376e3b243c74013cf;hb=e69044f7624abe5cb2cb796d528c0cc5f29515f7;hp=922670b52448c74d97d181cf3c240dc8e97e6ae4;hpb=794dab6aa5027ffaf024506140c258f6a0a9322d;p=mmh diff --git a/uip/rcvdist.c b/uip/rcvdist.c index 922670b..d3f36ca 100644 --- a/uip/rcvdist.c +++ b/uip/rcvdist.c @@ -2,13 +2,17 @@ /* * rcvdist.c -- asynchronously redistribute messages * - * $Id$ + * 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 #include #include -#include +#include +#include +#include static struct swit switches[] = { #define FORMSW 0 @@ -16,7 +20,7 @@ static struct swit switches[] = { #define VERSIONSW 1 { "version", 0 }, #define HELPSW 2 - { "help", 4 }, + { "help", 0 }, { NULL, 0 } }; @@ -28,7 +32,7 @@ static char tmpfil[BUFSIZ] = ""; * prototypes */ static void rcvdistout (FILE *, char *, char *); -int done (int); +static void unlink_done (int) NORETURN; int @@ -38,7 +42,10 @@ main (int argc, char **argv) int i, vecp = 1; char *addrs = NULL, *cp, *form = NULL, buf[BUFSIZ]; char **argp, **arguments, *vec[MAXARGS]; - register FILE *fp; + FILE *fp; + char *tfile = NULL; + + done=unlink_done; #ifdef LOCALE setlocale(LC_ALL, ""); @@ -67,10 +74,10 @@ main (int argc, char **argv) "%s [switches] [switches for postproc] address ...", invo_name); print_help (buf, switches, 1); - done (1); + done (0); case VERSIONSW: print_version(invo_name); - done (1); + done (0); case FORMSW: if (!(form = *argp++) || *form == '-') @@ -86,12 +93,18 @@ main (int argc, char **argv) invo_name); umask (~m_gmprot ()); - strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil)); - if ((fp = fopen (tmpfil, "w+")) == NULL) - adios (tmpfil, "unable to create"); + + tfile = m_mktemp2(NULL, invo_name, NULL, &fp); + if (tfile == NULL) adios("rcvdist", "unable to create temporary file"); + strncpy (tmpfil, tfile, sizeof(tmpfil)); + cpydata (fileno (stdin), fileno (fp), "message", tmpfil); fseek (fp, 0L, SEEK_SET); - strncpy (drft, m_tmpfil (invo_name), sizeof(drft)); + + tfile = m_mktemp2(NULL, invo_name, NULL, NULL); + if (tfile == NULL) adios("forw", "unable to create temporary file"); + strncpy (drft, tfile, sizeof(tmpfil)); + rcvdistout (fp, form, addrs); fclose (fp); @@ -101,6 +114,10 @@ main (int argc, char **argv) vec[0] = r1bindex (postproc, '/'); vec[vecp++] = "-dist"; vec[vecp++] = drft; + if ((cp = context_find ("mhlproc"))) { + vec[vecp++] = "-mhlproc"; + vec[vecp++] = cp; + } vec[vecp] = NULL; for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) @@ -129,10 +146,6 @@ static int outputlinelen = OUTPUTLINELEN; static struct format *fmt; -static int ncomps = 0; -static char **compbuffers = 0; -static struct comp **used_buf = 0; - static int dat[5]; static char *addrcomps[] = { @@ -156,9 +169,9 @@ static void rcvdistout (FILE *inb, char *form, char *addrs) { register int char_read = 0, format_len, i, state; - register char *tmpbuf, **nxtbuf, **ap; - char *cp, *scanl, name[NAMESZ]; - register struct comp *cptr, **savecomp; + register char **ap; + char *cp, *scanl, name[NAMESZ], tmpbuf[SBUFSIZ]; + register struct comp *cptr; FILE *out; if (!(out = fopen (drft, "w"))) @@ -167,27 +180,15 @@ rcvdistout (FILE *inb, char *form, char *addrs) /* get new format string */ cp = new_fs (form ? form : rcvdistcomps, NULL, NULL); format_len = strlen (cp); - ncomps = fmt_compile (cp, &fmt) + 1; - if (!(nxtbuf = compbuffers = (char **) calloc ((size_t) ncomps, sizeof(char *)))) - adios (NULL, "unable to allocate component buffers"); - if (!(savecomp = used_buf = (struct comp **) calloc ((size_t) (ncomps + 1), sizeof(struct comp *)))) - adios (NULL, "unable to allocate component buffer stack"); - savecomp += ncomps + 1; - *--savecomp = 0; - - for (i = ncomps; i--;) - if (!(*nxtbuf++ = malloc (SBUFSIZ))) - adios (NULL, "unable to allocate component buffer"); - nxtbuf = compbuffers; - tmpbuf = *nxtbuf++; + fmt_compile (cp, &fmt, 1); for (ap = addrcomps; *ap; ap++) { - FINDCOMP (cptr, *ap); + cptr = fmt_findcomp (*ap); if (cptr) cptr->c_type |= CT_ADDR; } - FINDCOMP (cptr, "addresses"); + cptr = fmt_findcomp ("addresses"); if (cptr) cptr->c_text = addrs; @@ -195,36 +196,15 @@ rcvdistout (FILE *inb, char *form, char *addrs) switch (state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb)) { case FLD: case FLDPLUS: - if ((cptr = wantcomp[CHASH (name)])) - do { - if (!strcasecmp (name, cptr->c_name)) { - char_read += msg_count; - if (!cptr->c_text) { - cptr->c_text = tmpbuf; - *--savecomp = cptr; - tmpbuf = *nxtbuf++; - } - else { - i = strlen (cp = cptr->c_text) - 1; - if (cp[i] == '\n') { - if (cptr->c_type & CT_ADDR) { - cp[i] = 0; - cp = add (",\n\t", cp); - } - else - cp = add ("\t", cp); - } - cptr->c_text = add (tmpbuf, cp); - } - while (state == FLDPLUS) { - state = m_getfld (state, name, tmpbuf, - SBUFSIZ, inb); - cptr->c_text = add (tmpbuf, cptr->c_text); - char_read += msg_count; - } - break; - } - } while ((cptr = cptr->c_next)); + i = fmt_addcomptext(name, tmpbuf); + if (i != -1) { + char_read += msg_count; + while (state == FLDPLUS) { + state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb); + fmt_appendcomp(i, name, tmpbuf); + char_read += msg_count; + } + } while (state == FLDPLUS) state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb); @@ -243,10 +223,10 @@ rcvdistout (FILE *inb, char *form, char *addrs) finished: ; i = format_len + char_read + 256; - scanl = malloc ((size_t) i + 2); + scanl = mh_xmalloc ((size_t) i + 2); dat[0] = dat[1] = dat[2] = dat[4] = 0; dat[3] = outputlinelen; - fmt_scan (fmt, scanl, i, dat); + fmt_scan (fmt, scanl, i + 1, i, dat); fputs (scanl, out); if (ferror (out)) @@ -254,17 +234,12 @@ finished: ; fclose (out); free (scanl); - for (nxtbuf = compbuffers, i = ncomps; (cptr = *savecomp++); nxtbuf++, i--) - free (cptr->c_text); - while (i-- > 0) - free (*nxtbuf++); - free ((char *) compbuffers); - free ((char *) used_buf); + fmt_free(fmt, 1); } -int -done (int status) +static void +unlink_done (int status) { if (backup[0]) unlink (backup); @@ -274,5 +249,4 @@ done (int status) unlink (tmpfil); exit (status ? RCV_MBX : RCV_MOK); - return 1; /* dead code to satisfy the compiler */ }