]> diplodocus.org Git - nmh/commitdiff
Add FENDNULL(s): fends off NULL by giving an empty string instead.
authorRalph Corderoy <ralph@inputplus.co.uk>
Sat, 13 May 2017 12:13:18 +0000 (13:13 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Sat, 13 May 2017 12:13:18 +0000 (13:13 +0100)
Use it in place of all the `foo->bar_xyzzy ? foo->bar_xyzzy : ""'.
Avoids the reader having to check first two of the ternary operands are
the same.

22 files changed:
config/config.c
h/mh.h
mts/smtp/smtp.c
sbr/addrsbr.c
sbr/context_del.c
sbr/context_find.c
sbr/context_replace.c
sbr/fmt_compile.c
sbr/mf.c
sbr/mime_type.c
sbr/seq_print.c
uip/ali.c
uip/fmttest.c
uip/folder.c
uip/mhbuildsbr.c
uip/mhfixmsg.c
uip/mhlistsbr.c
uip/mhlsbr.c
uip/mhparam.c
uip/mhshowsbr.c
uip/post.c
uip/replsbr.c

index 7d9f263..633293e 100644 (file)
@@ -56,7 +56,7 @@ etcpath (char *file)
                }
            }
 
-           snprintf (epath, sizeof(epath), "%s/%s", pp, cp ? cp : "");
+           snprintf (epath, sizeof(epath), "%s/%s", pp, FENDNULL(cp));
            if (cp)
                *--cp = '/';
 
diff --git a/h/mh.h b/h/mh.h
index e549b2d..77671f8 100644 (file)
--- a/h/mh.h
+++ b/h/mh.h
@@ -48,6 +48,9 @@ typedef unsigned char  boolean;  /* not int so we can pack in a structure */
  * terminating NUL. */
 #define LEN(s) (sizeof (s) - 1)
 
+/* FENDNULL fends off NULL by giving an empty string instead. */
+#define FENDNULL(s) ((s) ? (s) : "")
+
 /*
  * char array that keeps track of size in both bytes and characters
  * Usage note:
index 003aa6a..b09fde3 100644 (file)
@@ -493,7 +493,7 @@ sm_wadr (char *mbox, char *host, char *path)
 {
     switch (smtalk (SM_RCPT, host && *host ? "RCPT TO:<%s%s@%s>"
                                           : "RCPT TO:<%s%s>",
-                            path ? path : "", mbox, host)) {
+                            FENDNULL(path), mbox, host)) {
        case 250: 
        case 251: 
            sm_addrs++;
index 68bb6de..1e43550 100644 (file)
@@ -89,7 +89,7 @@ getname (const char *addrs)
     pers = mbox = host = route = grp = note = NULL;
     err[0] = '\0';
 
-    if ((ap = getadrx (addrs ? addrs : "", eai)) == NULL) {
+    if ((ap = getadrx (FENDNULL(addrs), eai)) == NULL) {
        return NULL;
     }
 
@@ -216,7 +216,7 @@ mnfree (struct mailname *mp)
 }
 
 
-#define empty(s) ((s) ? (s) : "")
+#define empty(s) FENDNULL(s)
 
 char *
 auxformat (struct mailname *mp, int extras)
@@ -225,7 +225,7 @@ auxformat (struct mailname *mp, int extras)
     static char buffer[BUFSIZ];
 
        if (mp->m_nohost)
-           strncpy (addr, mp->m_mbox ? mp->m_mbox : "", sizeof(addr));
+           strncpy (addr, FENDNULL(mp->m_mbox), sizeof(addr));
        else
 
        if (mp->m_type != UUCPHOST) {
@@ -355,8 +355,8 @@ ismymbox (struct mailname *np)
            for (mp = &mq; mp; mp = mp->m_next) {
              fprintf (stderr, "Local- or Alternate-Mailbox: text=\"%s\" "
                       "mbox=\"%s\" host=\"%s\" %s\n",
-                      mp->m_text ? mp->m_text : "", mp->m_mbox,
-                      mp->m_host ? mp->m_host : "",
+                      FENDNULL(mp->m_text), mp->m_mbox,
+                      FENDNULL(mp->m_host),
                       snprintb (buffer, sizeof(buffer), (unsigned) mp->m_type,
                                 WBITS));
            }
index 62585f9..efe5e41 100644 (file)
@@ -19,7 +19,7 @@ context_del (char *key)
     struct node *np, *pp;
 
     for (np = m_defs, pp = NULL; np; pp = np, np = np->n_next) {
-       if (!strcasecmp (np->n_name ? np->n_name : "", key ? key : "")) {
+       if (!strcasecmp (FENDNULL(np->n_name), FENDNULL(key))) {
            if (!np->n_context)
                inform("bug: context_del(key=\"%s\"), continuing...", np->n_name);
            if (pp)
index 3a7b920..4d89fbc 100644 (file)
@@ -14,7 +14,7 @@ context_find (const char *str)
     struct node *np;
 
     for (np = m_defs; np; np = np->n_next)
-       if (!strcasecmp (np->n_name ? np->n_name : "", str ? str : ""))
+       if (!strcasecmp (FENDNULL(np->n_name), FENDNULL(str)))
            return (np->n_field);
 
     return NULL;
index b97162b..1027dcf 100644 (file)
@@ -33,7 +33,7 @@ context_replace (char *key, char *value)
      * this key, and replace its value if found.
      */
     for (np = m_defs;; np = np->n_next) {
-       if (!strcasecmp (np->n_name ? np->n_name : "", key ? key : "")) {
+       if (!strcasecmp (FENDNULL(np->n_name), FENDNULL(key))) {
            if (strcmp (value, np->n_field)) {
                if (!np->n_context)
                    inform("bug: context_replace(key=\"%s\",value=\"%s\"), continuing...", key, value);
index 33f34ef..b0ce646 100644 (file)
@@ -998,7 +998,7 @@ fmt_findcasecomp(char *component)
     struct comp *cm;
 
     for (cm = wantcomp[CHASH(component)]; cm; cm = cm->c_next)
-       if (strcasecmp(component, cm->c_name ? cm->c_name : "") == 0)
+       if (strcasecmp(component, FENDNULL(cm->c_name)) == 0)
            break;
 
     return cm;
@@ -1050,7 +1050,7 @@ fmt_addcomptext(char *component, char *text)
     char *cp;
 
     while (cptr) {
-       if (strcasecmp(component, cptr->c_name ? cptr->c_name : "") == 0) {
+       if (strcasecmp(component, FENDNULL(cptr->c_name)) == 0) {
            found++;
            if (! cptr->c_text) {
                cptr->c_text = getcpy(text);
@@ -1085,7 +1085,7 @@ fmt_appendcomp(int bucket, char *component, char *text)
 
     if (bucket != -1) {
        for (cptr = wantcomp[bucket]; cptr; cptr = cptr->c_next)
-           if (strcasecmp(component, cptr->c_name ? cptr->c_name : "") == 0)
+           if (strcasecmp(component, FENDNULL(cptr->c_name)) == 0)
                cptr->c_text = add(text, cptr->c_text);
     }
 }
index e0abb29..b6c7291 100644 (file)
--- a/sbr/mf.c
+++ b/sbr/mf.c
@@ -163,7 +163,7 @@ getadrx (const char *addrs, int eai)
     err[0] = 0;
 
     if (dp == NULL) {
-       dp = cp = strdup (addrs ? addrs : "");
+       dp = cp = strdup (FENDNULL(addrs));
        glevel = 0;
     }
     else
index bcc1c39..379c248 100644 (file)
@@ -68,7 +68,7 @@ mime_type(const char *file_name) {
        if ((p = strrchr(file_name, '.')) != NULL) {
            for (np = m_defs; np; np = np->n_next) {
                if (strncasecmp(np->n_name, "mhshow-suffix-", 14) == 0 &&
-                   strcasecmp(p, np->n_field ? np->n_field : "") == 0) {
+                   strcasecmp(p, FENDNULL(np->n_field)) == 0) {
                    content_type = strdup(np->n_name + 14);
                    break;
                }
index 24f669a..ce3c45f 100644 (file)
@@ -7,7 +7,7 @@
 
 #include <h/mh.h>
 
-#define empty(s) ((s) ? (s) : "")
+#define empty(s) FENDNULL(s)
 
 /*
  * Print all the sequences in a folder
index fe57ef3..a75edf3 100644 (file)
--- a/uip/ali.c
+++ b/uip/ali.c
@@ -217,10 +217,10 @@ print_usr (char *s, int list)
        while ((cp = getname (pp))) {
            if ((np = getm (cp, NULL, 0, NULL, 0)) == NULL)
                continue;
-           if (!strcasecmp (mp->m_host ? mp->m_host : "",
-                            np->m_host ? np->m_host : "")  &&
-               !strcasecmp (mp->m_mbox ? mp->m_mbox : "",
-                            np->m_mbox ? np->m_mbox : "")) {
+           if (!strcasecmp (FENDNULL(mp->m_host),
+                            FENDNULL(np->m_host))  &&
+               !strcasecmp (FENDNULL(mp->m_mbox),
+                            FENDNULL(np->m_mbox))) {
                vp = vp ? add (ak->ak_name, add (",", vp))
                    : getcpy (ak->ak_name);
                mnfree (np);
index 5f52fdc..19df310 100644 (file)
@@ -1302,10 +1302,10 @@ insert (struct mailname *np)
        return 0;
 
     for (mp = &mq; mp->m_next; mp = mp->m_next) {
-       if (!strcasecmp (np->m_host ? np->m_host : "",
-                        mp->m_next->m_host ? mp->m_next->m_host : "") &&
-           !strcasecmp (np->m_mbox ? np->m_mbox : "",
-                        mp->m_next->m_mbox ? mp->m_next->m_mbox : ""))
+       if (!strcasecmp (FENDNULL(np->m_host),
+                        FENDNULL(mp->m_next->m_host)) &&
+           !strcasecmp (FENDNULL(np->m_mbox),
+                        FENDNULL(mp->m_next->m_mbox)))
            return 0;
     }
     if (!ccme && ismymbox (np))
index bfeee8f..23aea0b 100644 (file)
@@ -335,7 +335,8 @@ main (int argc, char **argv)
            if (msg)
                inform("no folder given for message %s, continuing...", msg);
            readonly_folders (); /* do any readonly folders */
-           strncpy (folder, (cp = context_find (pfolder)) ? cp : "", sizeof(folder));
+           cp = context_find(pfolder);
+           strncpy (folder, FENDNULL(cp), sizeof(folder));
            crawl_folders (".", get_folder_info_callback, NULL);
        } else {
            strncpy (folder, argfolder, sizeof(folder));
index 412f871..b5d88a3 100644 (file)
@@ -2066,7 +2066,7 @@ set_disposition (CT ct) {
                "continuing...", invo_name,
                ct->c_ctinfo.ci_type,
                ct->c_ctinfo.ci_subtype ? "/" : "",
-               ct->c_ctinfo.ci_subtype ? ct->c_ctinfo.ci_subtype : "",
+               FENDNULL(ct->c_ctinfo.ci_subtype),
                cp);
         }
 
@@ -2231,7 +2231,7 @@ expand_pseudoheader (CT ct, CT *text_plain_ct, struct multipart *m,
     /* reply_file is used to pass the output of the convert. */
     reply_file = getcpy (m_mktemp2 (NULL, invo_name, NULL, NULL));
     convert_command =
-        concat (convert, " ", argstring ? argstring : "", " >", reply_file,
+        concat (convert, " ", FENDNULL(argstring), " >", reply_file,
                 NULL);
 
     /* Convert here . . . */
index acdb9d7..615575b 100644 (file)
@@ -870,7 +870,7 @@ replace_boundary (CT ct, char *file, char *boundary) {
                                           strlen(new_ctline) + 1,
                                           ct->c_ctinfo.ci_first_pm, NULL, 0);
                 fprintf (fpout, "%s:%s%s\n", np, new_ctline,
-                        new_params ? new_params : "");
+                        FENDNULL(new_params));
                free(new_ctline);
                 mh_xfree(new_params);
             }
@@ -1657,7 +1657,7 @@ reformat_part (CT ct, char *file, char *type, char *subtype, int c_type) {
     if (strchr (cf, '>')) {
         inform("'>' prohibited in \"%s\",\nplease fix your "
                 "%s-format-%s/%s profile entry", cf, invo_name, type,
-                subtype ? subtype : "");
+                FENDNULL(subtype));
 
         return NOTOK;
     }
@@ -1774,7 +1774,7 @@ build_multipart_alt (CT first_alt, CT new_part, int type, int subtype) {
                 snprintf (buffer2, sizeof buffer2, "%d", serial);
                 boundary =
                     concat (boundary_prefix,
-                            first_alt->c_partno ? first_alt->c_partno : "",
+                            FENDNULL(first_alt->c_partno),
                             "-", buffer2,  NULL);
             }
         }
@@ -2017,8 +2017,7 @@ decode_text_parts (CT ct, int encoding, const char *decodetypes,
                         report (NULL, ct->c_partno, ct->c_file,
                                 "will not decode%s because it is binary (%s)",
                                 ct->c_partno  ?  ""
-                                              :  ct->c_ctline  ?  ct->c_ctline
-                                                               :  "",
+                                              :  (FENDNULL(ct->c_ctline)),
                                 reason);
                     }
                     (void) m_unlink (ct->c_cefile.ce_file);
@@ -2032,8 +2031,7 @@ decode_text_parts (CT ct, int encoding, const char *decodetypes,
                         report (NULL, ct->c_partno, ct->c_file,
                                 "will not decode%s because it is 8bit",
                                 ct->c_partno  ?  ""
-                                              :  ct->c_ctline  ?  ct->c_ctline
-                                                               :  "");
+                                              :  (FENDNULL(ct->c_ctline)));
                     }
                     (void) m_unlink (ct->c_cefile.ce_file);
                     free (ct->c_cefile.ce_file);
@@ -2052,7 +2050,7 @@ decode_text_parts (CT ct, int encoding, const char *decodetypes,
                         ++*message_mods;
                         if (verbosw) {
                             report (NULL, ct->c_partno, ct->c_file, "decode%s",
-                                    ct->c_ctline ? ct->c_ctline : "");
+                                    FENDNULL(ct->c_ctline));
                         }
                         if (lf_line_endings) {
                             strip_crs (ct, message_mods);
@@ -2809,7 +2807,7 @@ report (char *what, char *partno, char *filename, char *message, ...) {
     if (verbosw) {
         va_start (args, message);
         fmt = concat (filename, partno ? " part " : ", ",
-                      partno ? partno : "", partno ? ", " : "", message, NULL);
+                      FENDNULL(partno), partno ? ", " : "", message, NULL);
 
         advertise (what, NULL, fmt, args);
 
index 452c7fd..42b04ae 100644 (file)
@@ -133,7 +133,7 @@ list_switch (CT ct, int toplevel, int realsize, int verbose, int debug,
 }
 
 
-#define empty(s) ((s) ? (s) : "")
+#define empty(s) FENDNULL(s)
 
 /*
  * Method for listing information about a simple/generic content
@@ -452,7 +452,7 @@ list_encoding (CT ct)
 
     fprintf (stderr, "    decoded fp 0x%x file \"%s\"\n",
             (unsigned int)(unsigned long) ce->ce_fp,
-            ce->ce_file ? ce->ce_file : "");
+            FENDNULL(ce->ce_file));
 
     return OK;
 }
index 6dd1850..ea0c7d3 100644 (file)
@@ -1019,13 +1019,13 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec)
                    continue;
 
                for (c2 = fmthd; c2; c2 = c2->c_next)
-                   if (!strcasecmp (c2->c_name ? c2->c_name : "", name))
+                   if (!strcasecmp (FENDNULL(c2->c_name), name))
                        break;
                c1 = NULL;
                if (!((c3 = c2 ? c2 : &global)->c_flags & SPLIT))
                    for (c1 = msghd; c1; c1 = c1->c_next)
-                       if (!strcasecmp (c1->c_name ? c1->c_name : "",
-                                        c3->c_name ? c3->c_name : "")) {
+                       if (!strcasecmp (FENDNULL(c1->c_name),
+                                        FENDNULL(c3->c_name))) {
                            c1->c_text =
                                mcomp_add (c1->c_flags, buf, c1->c_text);
                            break;
@@ -1085,8 +1085,8 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec)
                        continue;
                    }
                    for (c2 = msghd; c2; c2 = c2->c_next)
-                       if (!strcasecmp (c2->c_name ? c2->c_name : "",
-                                        c1->c_name ? c1->c_name : "")) {
+                       if (!strcasecmp (FENDNULL(c2->c_name),
+                                        FENDNULL(c1->c_name))) {
                            putcomp (c1, c2, ONECOMP);
                            if (!(c1->c_flags & SPLIT))
                                break;
@@ -1590,7 +1590,7 @@ putch (char ch, unsigned long flags)
        putch ('\n', flags);
        if (ovoff > 0)
            lm = ovoff;
-       putstr (ovtxt ? ovtxt : "", flags);
+       putstr (FENDNULL(ovtxt), flags);
        putch (ch, flags);
        return;
     }
index 4d8407d..1498884 100644 (file)
@@ -228,7 +228,7 @@ main(int argc, char **argv)
         * value (as determined after context is read).
          */
        for (ps = procs; ps->p_name; ps++)
-           printf ("%s: %s\n", ps->p_name, *ps->p_field ? *ps->p_field : "");
+           printf ("%s: %s\n", ps->p_name, FENDNULL(*ps->p_field));
 
     }
 
index 2ef4734..1e3a4ba 100644 (file)
@@ -370,7 +370,7 @@ show_content_aux (CT ct, int alternate, char *cp, char *cracked, struct format *
             char *charset = content_charset (ct);
             inform("unable to convert character set%s%s from %s, continuing...",
                       ct->c_partno  ?  " of part "  :  "",
-                      ct->c_partno  ?  ct->c_partno  :  "",
+                      FENDNULL(ct->c_partno),
                       charset);
             free (charset);
         }
index 1323e19..3c9a61e 100644 (file)
@@ -1211,7 +1211,7 @@ get_header (char *header, struct headers *table)
     struct headers *h;
 
     for (h = table; h->value; h++)
-       if (!strcasecmp (header ? header : "", h->value ? h->value : ""))
+       if (!strcasecmp (FENDNULL(header), FENDNULL(h->value)))
            return (h - table);
 
     return NOTOK;
@@ -1312,10 +1312,10 @@ insert (struct mailname *np)
            : &netaddrs;
            mp->m_next;
            mp = mp->m_next)
-       if (!strcasecmp (np->m_host ? np->m_host : "",
-                        mp->m_next->m_host ? mp->m_next->m_host : "") &&
-           !strcasecmp (np->m_mbox ? np->m_mbox : "",
-                        mp->m_next->m_mbox ? mp->m_next->m_mbox : "") &&
+       if (!strcasecmp (FENDNULL(np->m_host),
+                        FENDNULL(mp->m_next->m_host)) &&
+           !strcasecmp (FENDNULL(np->m_mbox),
+                        FENDNULL(mp->m_next->m_mbox)) &&
            np->m_bcc == mp->m_next->m_bcc)
            return 0;
 
@@ -1339,7 +1339,7 @@ pl (void)
 
     printf ("\nnet:\t");
     for (mp = netaddrs.m_next; mp; mp = mp->m_next)
-       printf ("%s%s@%s%s%s", mp->m_path ? mp->m_path : "",
+       printf ("%s%s@%s%s%s", FENDNULL(mp->m_path),
                mp->m_mbox, mp->m_host,
                mp->m_bcc ? "[BCC]" : "",
                mp->m_next ? ",\n\t" : "");
index fe79c29..3f40a61 100644 (file)
@@ -384,10 +384,10 @@ insert (struct mailname *np)
        return 0;
 
     for (mp = &mq; mp->m_next; mp = mp->m_next) {
-       if (!strcasecmp (np->m_host ? np->m_host : "",
-                        mp->m_next->m_host ? mp->m_next->m_host : "")  &&
-           !strcasecmp (np->m_mbox ? np->m_mbox : "",
-                        mp->m_next->m_mbox ? mp->m_next->m_mbox : ""))
+       if (!strcasecmp (FENDNULL(np->m_host),
+                        FENDNULL(mp->m_next->m_host))  &&
+           !strcasecmp (FENDNULL(np->m_mbox),
+                        FENDNULL(mp->m_next->m_mbox)))
            return 0;
     }
     if (!ccme && ismymbox (np))