X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Freplsbr.c;h=e26badd112fffca4fae68e29400de5f04e00272f;hp=8e60a526a3f90a092b03cf8338908152c9cedb5d;hb=714b5c530ece27ea2835a313013f5b770163403c;hpb=ced6090a330d3d83d0bce709f756aa3d7d65fea4 diff --git a/uip/replsbr.c b/uip/replsbr.c index 8e60a52..e26badd 100644 --- a/uip/replsbr.c +++ b/uip/replsbr.c @@ -61,12 +61,12 @@ static char *addrcomps[] = { /* ** static prototypes */ -static int insert (struct mailname *); -static void replfilter (FILE *, FILE *, char *); +static int insert(struct mailname *); +static void replfilter(FILE *, FILE *, char *); void -replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen, +replout(FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen, int mime, char *form, char *filter, char *fcc) { register int state, i; @@ -81,24 +81,24 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen, FILE *out; mask = umask(~m_gmprot()); - if ((out = fopen (drft, "w")) == NULL) - adios (drft, "unable to create"); + if ((out = fopen(drft, "w")) == NULL) + adios(drft, "unable to create"); umask(mask); /* get new format string */ - cp = new_fs (form, NULL, NULL); - format_len = strlen (cp); + cp = new_fs(form, NULL, NULL); + format_len = strlen(cp); /* compile format string */ - ncomps = fmt_compile (cp, &fmt) + 1; + ncomps = fmt_compile(cp, &fmt) + 1; if (!(nxtbuf = compbuffers = (char **) calloc((size_t) ncomps, sizeof(char *)))) - adios (NULL, "unable to allocate component buffers"); + 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"); + adios(NULL, "unable to allocate component buffer stack"); savecomp += ncomps + 1; *--savecomp = NULL; /* point at zero'd end minus 1 */ @@ -109,7 +109,7 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen, tmpbuf = *nxtbuf++; for (ap = addrcomps; *ap; ap++) { - FINDCOMP (cptr, *ap); + FINDCOMP(cptr, *ap); if (cptr) cptr->c_type |= CT_ADDR; } @@ -118,34 +118,34 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen, ** ignore any components killed by command line switches */ if (!ccto) { - FINDCOMP (cptr, "to"); + FINDCOMP(cptr, "to"); if (cptr) cptr->c_name = ""; } if (!cccc) { - FINDCOMP (cptr, "cc"); + FINDCOMP(cptr, "cc"); if (cptr) cptr->c_name = ""; } /* set up the "fcc" pseudo-component */ if (fcc) { - FINDCOMP (cptr, "fcc"); + FINDCOMP(cptr, "fcc"); if (cptr) - cptr->c_text = getcpy (fcc); + cptr->c_text = getcpy(fcc); } if ((cp = getenv("USER"))) { - FINDCOMP (cptr, "user"); + FINDCOMP(cptr, "user"); if (cptr) cptr->c_text = getcpy(cp); } if (!ccme) - ismymbox (NULL); + ismymbox(NULL); /* ** pick any interesting stuff out of msg "inb" */ for (state = FLD;;) { - state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb); + state = m_getfld(state, name, tmpbuf, SBUFSIZ, inb); switch (state) { case FLD: case FLDPLUS: @@ -168,21 +168,21 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen, *--savecomp = cptr; tmpbuf = *nxtbuf++; } else { - i = strlen (cp = cptr->c_text) - 1; + 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); + cp = add(",\n\t", cp); } else { - cp = add ("\t", cp); + cp = add("\t", cp); } } - cptr->c_text = add (tmpbuf, cp); + cptr->c_text = add(tmpbuf, cp); } while (state == FLDPLUS) { - state = m_getfld (state, name, tmpbuf, + state = m_getfld(state, name, tmpbuf, SBUFSIZ, inb); - cptr->c_text = add (tmpbuf, cptr->c_text); + cptr->c_text = add(tmpbuf, cptr->c_text); char_read += msg_count; } break; @@ -190,7 +190,7 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen, } while ((cptr = cptr->c_next)); while (state == FLDPLUS) - state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb); + state = m_getfld(state, name, tmpbuf, SBUFSIZ, inb); break; case LENERR: @@ -200,7 +200,7 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen, goto finished; default: - adios (NULL, "m_getfld() returned %d", state); + adios(NULL, "m_getfld() returned %d", state); } } @@ -212,7 +212,7 @@ finished: /* ** if there's a "Subject" component, strip any "Re:"s off it */ - FINDCOMP (cptr, "subject") + FINDCOMP(cptr, "subject") if (cptr && (cp = cptr->c_text)) { register char *sp = cp; @@ -227,22 +227,22 @@ finished: } if (sp != cptr->c_text) { cp = cptr->c_text; - cptr->c_text = getcpy (sp); - free (cp); + cptr->c_text = getcpy(sp); + free(cp); } } i = format_len + char_read + 256; - scanl = mh_xmalloc ((size_t) i + 2); + scanl = mh_xmalloc((size_t) i + 2); dat[0] = 0; dat[1] = 0; dat[2] = 0; dat[3] = outputlinelen; dat[4] = 0; - fmt_scan (fmt, scanl, i, dat); - fputs (scanl, out); + fmt_scan(fmt, scanl, i, dat); + fputs(scanl, out); if (badaddrs) { - fputs ("\nrepl: bad addresses:\n", out); - fputs ( badaddrs, out); + fputs("\nrepl: bad addresses:\n", out); + fputs( badaddrs, out); } /* @@ -251,29 +251,29 @@ finished: */ if (filter) { fflush(out); - if (ferror (out)) - adios (drft, "error writing"); + if (ferror(out)) + adios(drft, "error writing"); - replfilter (inb, out, filter); + replfilter(inb, out, filter); } else if (mime && mp) { - fprintf (out, "#forw [original message] +%s %s\n", - mp->foldpath, m_name (mp->lowsel)); + fprintf(out, "#forw [original message] +%s %s\n", + mp->foldpath, m_name(mp->lowsel)); } fflush(out); - if (ferror (out)) - adios (drft, "error writing"); - fclose (out); + if (ferror(out)) + adios(drft, "error writing"); + fclose(out); /* return dynamically allocated buffers */ - free (scanl); + free(scanl); for (nxtbuf = compbuffers, i = ncomps; (cptr = *savecomp++); nxtbuf++, i--) - free (cptr->c_text); /* if not nxtbuf, nxtbuf already freed */ + free(cptr->c_text); /* if not nxtbuf, nxtbuf already freed */ while ( i-- > 0) - free (*nxtbuf++); /* free unused nxtbufs */ - free ((char *) compbuffers); - free ((char *) used_buf); + free(*nxtbuf++); /* free unused nxtbufs */ + free((char *) compbuffers); + free((char *) used_buf); } static char *buf; /* our current working buffer */ @@ -290,11 +290,11 @@ static unsigned int bufsiz=0; /* current size of buf */ ** add more mem if needed */ #define CHECKMEM(str) \ - if ((len = strlen (str)) >= bufend - dst) {\ + if ((len = strlen(str)) >= bufend - dst) {\ int i = dst - buf;\ int n = last_dst - buf;\ bufsiz += ((dst + len - bufend) / BUFINCR + 1) * BUFINCR;\ - buf = mh_xrealloc (buf, bufsiz);\ + buf = mh_xrealloc(buf, bufsiz);\ dst = buf + i;\ last_dst = buf + n;\ bufend = buf + bufsiz;\ @@ -313,7 +313,7 @@ static unsigned int bufsiz=0; /* current size of buf */ ** length of the result string. */ char * -formataddr (char *orig, char *str) +formataddr(char *orig, char *str) { register int len; char baddr[BUFSIZ], error[BUFSIZ]; @@ -325,7 +325,7 @@ formataddr (char *orig, char *str) /* if we don't have a buffer yet, get one */ if (bufsiz == 0) { - buf = mh_xmalloc (BUFINCR); + buf = mh_xmalloc(BUFINCR); last_dst = buf; /* XXX */ bufsiz = BUFINCR - 6; /* leave some slop */ bufend = buf + bufsiz; @@ -341,36 +341,36 @@ formataddr (char *orig, char *str) *dst = '\0'; } else { dst = last_dst; /* XXX */ - CHECKMEM (orig); - CPY (orig); + CHECKMEM(orig); + CPY(orig); } /* concatenate all the new addresses onto 'buf' */ - for (isgroup = 0; (cp = getname (str)); ) { - if ((mp = getm (cp, dfhost, dftype, AD_NAME, error)) == NULL) { - snprintf (baddr, sizeof(baddr), "\t%s -- %s\n", + for (isgroup = 0; (cp = getname(str)); ) { + if ((mp = getm(cp, dfhost, dftype, AD_NAME, error)) == NULL) { + snprintf(baddr, sizeof(baddr), "\t%s -- %s\n", cp, error); - badaddrs = add (baddr, badaddrs); + badaddrs = add(baddr, badaddrs); continue; } if (isgroup && (mp->m_gname || !mp->m_ingrp)) { *dst++ = ';'; isgroup = 0; } - if (insert (mp)) { + if (insert(mp)) { /* if we get here we're going to add an address */ if (dst != buf) { *dst++ = ','; *dst++ = ' '; } if (mp->m_gname) { - CHECKMEM (mp->m_gname); - CPY (mp->m_gname); + CHECKMEM(mp->m_gname); + CPY(mp->m_gname); isgroup++; } - sp = adrformat (mp); - CHECKMEM (sp); - CPY (sp); + sp = adrformat(mp); + CHECKMEM(sp); + CPY(sp); } } @@ -384,7 +384,7 @@ formataddr (char *orig, char *str) static int -insert (struct mailname *np) +insert(struct mailname *np) { char buffer[BUFSIZ]; register struct mailname *mp; @@ -393,24 +393,23 @@ insert (struct mailname *np) return 0; for (mp = &mq; mp->m_next; mp = mp->m_next) { - if (!mh_strcasecmp (np->m_host, mp->m_next->m_host) - && !mh_strcasecmp (np->m_mbox, - mp->m_next->m_mbox)) + if (!mh_strcasecmp(np->m_host, mp->m_next->m_host) && + !mh_strcasecmp(np->m_mbox, mp->m_next->m_mbox)) return 0; } - if (!ccme && ismymbox (np)) + if (!ccme && ismymbox(np)) return 0; if (querysw) { - snprintf (buffer, sizeof(buffer), "Reply to %s? ", - adrformat (np)); - if (!gans (buffer, anoyes)) + snprintf(buffer, sizeof(buffer), "Reply to %s? ", + adrformat(np)); + if (!gans(buffer, anoyes)) return 0; } mp->m_next = np; #ifdef ISI - if (ismymbox (np)) + if (ismymbox(np)) ccme = 0; #endif @@ -425,7 +424,7 @@ insert (struct mailname *np) */ static void -replfilter (FILE *in, FILE *out, char *filter) +replfilter(FILE *in, FILE *out, char *filter) { int pid; char *mhl; @@ -434,24 +433,24 @@ replfilter (FILE *in, FILE *out, char *filter) if (filter == NULL) return; - if (access (filter, R_OK) == NOTOK) - adios (filter, "unable to read"); + if (access(filter, R_OK) == NOTOK) + adios(filter, "unable to read"); - mhl = r1bindex (mhlproc, '/'); + mhl = r1bindex(mhlproc, '/'); - rewind (in); - lseek (fileno(in), (off_t) 0, SEEK_SET); + rewind(in); + lseek(fileno(in), (off_t) 0, SEEK_SET); - switch (pid = vfork ()) { + switch (pid = vfork()) { case NOTOK: - adios ("fork", "unable to"); + adios("fork", "unable to"); case OK: - dup2 (fileno (in), fileno (stdin)); - dup2 (fileno (out), fileno (stdout)); - closefds (3); + dup2(fileno(in), fileno(stdin)); + dup2(fileno(out), fileno(stdout)); + closefds(3); - execlp (mhlproc, mhl, "-form", filter, "-noclear", + execlp(mhlproc, mhl, "-form", filter, "-noclear", NULL); errstr = strerror(errno); write(2, "unable to exec ", 15); @@ -459,12 +458,12 @@ replfilter (FILE *in, FILE *out, char *filter) write(2, ": ", 2); write(2, errstr, strlen(errstr)); write(2, "\n", 1); - _exit (-1); + _exit(-1); default: - if (pidXwait (pid, mhl)) - done (1); - fseek (out, 0L, SEEK_END); + if (pidXwait(pid, mhl)) + done(1); + fseek(out, 0L, SEEK_END); break; } }