]> diplodocus.org Git - nmh/blobdiff - uip/replsbr.c
Use macros in advertise() to simplify source.
[nmh] / uip / replsbr.c
index ee404efd7118bff11ae4eeb4a5a51cab4af6a61c..a9a659696ce147e52553e856d65079ff559148eb 100644 (file)
@@ -65,13 +65,14 @@ void
 replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen,
        int mime, char *form, char *filter, char *fcc, int fmtproc)
 {
-    register int state, i;
-    register struct comp *cptr;
+    int state, i;
+    struct comp *cptr;
     char tmpbuf[SBUFSIZ];
     struct format *fmt;
-    register char **ap;
+    char **ap;
     int        char_read = 0, format_len, mask;
-    char name[NAMESZ], *scanl, *cp;
+    char name[NAMESZ], *cp;
+    charstring_t scanl;
     static int dat[5];                 /* aux. data for format routine */
     m_getfld_state_t gstate = 0;
     struct fmt_callbacks cb;
@@ -110,23 +111,23 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen,
     if (!ccto) {
        cptr = fmt_findcomp ("to");
        if (cptr)
-           cptr->c_name = getcpy(NULL);
+           cptr->c_name = mh_xstrdup("");
     }
     if (!cccc) {
         cptr = fmt_findcomp("cc");
        if (cptr)
-           cptr->c_name = getcpy(NULL);
+           cptr->c_name = mh_xstrdup("");
     }
     /* set up the "fcc" pseudo-component */
     if (fcc) {
        cptr = fmt_findcomp ("fcc");
        if (cptr)
-           cptr->c_text = getcpy (fcc);
+           cptr->c_text = mh_xstrdup(fcc);
     }
     if ((cp = getenv("USER"))) {
        cptr = fmt_findcomp ("user");
        if (cptr)
-           cptr->c_text = getcpy(cp);
+           cptr->c_text = mh_xstrdup(cp);
     }
     if (!ccme)
        ismymbox (NULL);
@@ -186,7 +187,7 @@ finished:
      */
     cptr = fmt_findcomp ("subject");
     if (cptr && (cp = cptr->c_text)) {
-       register char *sp = cp;
+       char *sp = cp;
 
        for (;;) {
            while (isspace((unsigned char) *cp))
@@ -199,12 +200,12 @@ finished:
        }
        if (sp != cptr->c_text) {
            cp = cptr->c_text;
-           cptr->c_text = getcpy (sp);
+           cptr->c_text = mh_xstrdup(sp);
            free (cp);
        }
     }
     i = format_len + char_read + 256;
-    scanl = mh_xmalloc ((size_t) i + 2);
+    scanl = charstring_create (i + 2);
     dat[0] = 0;
     dat[1] = 0;
     dat[2] = 0;
@@ -213,8 +214,8 @@ finished:
     memset(&cb, 0, sizeof(cb));
     cb.formataddr = replformataddr;
     cb.concataddr = replconcataddr;
-    fmt_scan (fmt, scanl, i + 1, i, dat, &cb);
-    fputs (scanl, out);
+    fmt_scan (fmt, scanl, i, dat, &cb);
+    fputs (charstring_buffer (scanl), out);
     if (badaddrs) {
        fputs ("\nrepl: bad addresses:\n", out);
        fputs ( badaddrs, out);
@@ -241,7 +242,7 @@ finished:
     fclose (out);
 
     /* return dynamically allocated buffers */
-    free (scanl);
+    charstring_free (scanl);
     fmt_free(fmt, 1);
 }
 
@@ -284,13 +285,13 @@ static unsigned int bufsiz=0;     /* current size of buf */
 static char *
 replformataddr (char *orig, char *str)
 {
-    register int len;
+    int len;
     char baddr[BUFSIZ], error[BUFSIZ];
-    register int isgroup;
-    register char *dst;
-    register char *cp;
-    register char *sp;
-    register struct mailname *mp = NULL;
+    int isgroup;
+    char *dst;
+    char *cp;
+    char *sp;
+    struct mailname *mp = NULL;
     char *fixed_str = fix_addresses (str);
 
     /* if we don't have a buffer yet, get one */
@@ -317,7 +318,7 @@ replformataddr (char *orig, char *str)
 
     /* concatenate all the new addresses onto 'buf' */
     for (isgroup = 0; (cp = getname (fixed_str)); ) {
-       if ((mp = getm (cp, dfhost, dftype, AD_NAME, error)) == NULL) {
+       if ((mp = getm (cp, dfhost, dftype, error, sizeof(error))) == NULL) {
            snprintf (baddr, sizeof(baddr), "\t%s -- %s\n", cp, error);
            badaddrs = add (baddr, badaddrs);
            continue;
@@ -381,7 +382,7 @@ static int
 insert (struct mailname *np)
 {
     char buffer[BUFSIZ];
-    register struct mailname *mp;
+    struct mailname *mp;
 
     if (nodupcheck)
        return 1;
@@ -401,7 +402,7 @@ insert (struct mailname *np)
 
     if (querysw) {
        snprintf (buffer, sizeof(buffer), "Reply to %s? ", adrformat (np));
-       if (!gans (buffer, anoyes))
+       if (!read_switch (buffer, anoyes))
        return 0;
     }
     mp->m_next = np;
@@ -468,11 +469,13 @@ replfilter (FILE *in, FILE *out, char *filter, int fmtproc)
 
            execvp (mhl, arglist);
            errstr = strerror(errno);
-           write(2, "unable to exec ", 15);
-           write(2, mhlproc, strlen(mhlproc));
-           write(2, ": ", 2);
-           write(2, errstr, strlen(errstr));
-           write(2, "\n", 1);
+           if (write(2, "unable to exec ", 15) < 0  ||
+               write(2, mhlproc, strlen(mhlproc)) < 0  ||
+               write(2, ": ", 2) < 0  ||
+               write(2, errstr, strlen(errstr)) < 0  ||
+               write(2, "\n", 1) < 0) {
+               advise ("stderr", "write");
+           }
            _exit (-1);
 
        default: 
@@ -513,17 +516,19 @@ fix_addresses (char *str) {
          * local part.
          */
         while ((cp = getname (str))) {
-            struct adr_node *adr_nodep = mh_xmalloc (sizeof *adr_nodep);
+            struct adr_node *adr_nodep;
             char error[BUFSIZ];
             struct mailname *mp;
 
+            NEW(adr_nodep);
             adr_nodep->adr = strdup (cp);
             adr_nodep->escape_local_part = 0;
             adr_nodep->fixed = 0;
             adr_nodep->next = NULL;
 
             /* With AD_NAME, errors are not reported to user. */
-            if ((mp = getm (cp, dfhost, dftype, AD_NAME, error)) == NULL) {
+            if ((mp = getm (cp, dfhost, dftype, error,
+                           sizeof(error))) == NULL) {
                 const char *no_at_sign = "no at-sign after local-part";
 
                 adr_nodep->escape_local_part =
@@ -562,7 +567,7 @@ fix_addresses (char *str) {
                 new_adr = concat (display_name, " ", angle_addr, NULL);
                 adr = getname (new_adr);
                 if (adr != NULL  &&
-                    (mp = getm (adr, dfhost, dftype, AD_NAME, NULL)) != NULL) {
+                    (mp = getm (adr, dfhost, dftype, NULL, 0)) != NULL) {
                     fixed_address = 1;
                     mnfree (mp);
                 }
@@ -604,8 +609,7 @@ fix_addresses (char *str) {
 
     if (fixed_address) {
         return fixed_str;
-    } else {
-        free (fixed_str);
-        return str  ?  strdup (str)  :  NULL;
     }
+    free (fixed_str);
+    return str  ?  strdup (str)  :  NULL;
 }