]> diplodocus.org Git - nmh/commitdiff
Use new PLURALS(n) macro instead of variety of tests.
authorRalph Corderoy <ralph@inputplus.co.uk>
Sun, 14 May 2017 10:23:33 +0000 (11:23 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Sun, 14 May 2017 10:23:33 +0000 (11:23 +0100)
Whether to output a plural noun in a message was decided by ternary
operators that tested n==1, n!=1, n>1, etc.  Make them all consistent by
using PLURALS(n).

h/mh.h
sbr/utils.c
uip/burst.c
uip/folder.c
uip/forw.c
uip/mhlsbr.c
uip/msgchk.c
uip/pick.c
uip/post.c

diff --git a/h/mh.h b/h/mh.h
index 77671f8..22e3a0b 100644 (file)
--- a/h/mh.h
+++ b/h/mh.h
@@ -51,6 +51,15 @@ typedef unsigned char  boolean;  /* not int so we can pack in a structure */
 /* FENDNULL fends off NULL by giving an empty string instead. */
 #define FENDNULL(s) ((s) ? (s) : "")
 
+/* PLURALS gives a pointer to the string "s" when n isn't 1, and to the
+ * empty string "" when it is.  Suitable for obtaining the plural `s'
+ * used for English nouns.  It treats -1 as plural, as does GNU gettext.
+ * Having output vary for plurals is annoying for those writing parsers;
+ * better to phrase the output such that no test is needed, e.g.
+ * "messages found: 42". */
+extern const char plurals[];
+#define PLURALS(n) (plurals + ((n) == 1))
+
 /*
  * char array that keeps track of size in both bytes and characters
  * Usage note:
index 4c87b38..ef7df4a 100644 (file)
@@ -17,6 +17,11 @@ extern void remove_registered_files_atexit();
 
 extern char *mhdocdir;
 
+/* plurals gives the letter ess to indicate a plural noun, or an empty
+ * string as plurals+1 for the singular noun.  Used by the PLURALS
+ * macro. */
+const char plurals[] = "s";
+
 /*
  * We allocate space for messages (msgs array)
  * this number of elements at a time.
index 0f62db7..0b15ebc 100644 (file)
@@ -172,7 +172,7 @@ main (int argc, char **argv)
            if ((numburst = find_delim (msgnum, smsgs, &mimesw)) >= 1) {
                if (verbosw)
                    printf ("%d message%s exploded from digest %d\n",
-                           numburst, numburst > 1 ? "s" : "", msgnum);
+                           numburst, PLURALS(numburst), msgnum);
                burst (&mp, msgnum, smsgs, numburst, inplace, verbosw,
                       maildir, mimesw);
            } else {
index 5fd411c..077fa05 100644 (file)
@@ -570,7 +570,7 @@ print_folders (void)
            } else {
                printf ("has %*d message%1s  (%*d-%*d)",
                        nummsgdigits, fi[i].nummsg,
-                       (fi[i].nummsg == 1) ? "" : "s",
+                       PLURALS(fi[i].nummsg),
                        lowmsgdigits, fi[i].lowmsg,
                        hghmsgdigits, fi[i].hghmsg);
                if (fi[i].curmsg >= fi[i].lowmsg && fi[i].curmsg <= fi[i].hghmsg) {
@@ -592,8 +592,8 @@ print_folders (void)
        if (all)
            putchar('\n');
        printf ("TOTAL = %d message%s in %d folder%s.\n",
-               total_msgs, total_msgs != 1 ? "s" : "",
-               total_folders, total_folders != 1 ? "s" : "");
+               total_msgs, PLURALS(total_msgs),
+               total_folders, PLURALS(total_folders));
     }
 
     fflush (stdout);
index 8746d45..ef536a5 100644 (file)
@@ -588,7 +588,7 @@ copy_draft (int out, char *digest, char *file, int volume, int issue, int dashst
 
                if (msgnum == mp->lowsel) {
                    snprintf (bp, buflen, " Forwarded Message%s",
-                       mp->numsel > 1 ? "s" : "");
+                       PLURALS(mp->numsel));
                } else {
                    snprintf (bp, buflen, " Message %d", msgcnt);
                }
@@ -625,7 +625,7 @@ copy_draft (int out, char *digest, char *file, int volume, int issue, int dashst
        strncpy (buffer, delim4, sizeof(buffer));
     } else {
        snprintf (buffer, sizeof(buffer), "\n------- End of Forwarded Message%s\n",
-               mp->numsel > 1 ? "s" : "");
+               PLURALS(mp->numsel));
     }
     if (write (out, buffer, strlen (buffer)) < 0) {
        advise (drft, "write");
@@ -657,7 +657,7 @@ copy_mime_draft (int out)
     char buffer[BUFSIZ];
 
     snprintf (buffer, sizeof(buffer), "#forw [forwarded message%s] +%s",
-       mp->numsel == 1 ? "" : "s", mp->foldpath);
+       PLURALS(mp->numsel), mp->foldpath);
     if (write (out, buffer, strlen (buffer)) < 0) {
        advise (drft, "write");
     }
index ea0c7d3..e2d9760 100644 (file)
@@ -521,7 +521,7 @@ mhl (int argc, char **argv)
        }
        else
            printf ("\n------- End of Forwarded Message%s\n",
-                   vecp > 1 ? "s" : "");
+                   PLURALS(vecp));
     }
 
     fflush(stdout);
@@ -946,7 +946,7 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec)
        else {
            printf ("\n-------");
            if (ofilen == 1)
-               printf (" Forwarded Message%s", ofilec > 1 ? "s" : "");
+               printf (" Forwarded Message%s", PLURALS(ofilec));
            else
                printf (" Message %d", ofilen);
            printf ("\n\n");
index 2fede57..44d9352 100644 (file)
@@ -399,7 +399,7 @@ remotemail (char *host, char *port, char *user, char *proxy, int notifysw,
                printf ("%s has ", user);
 
            printf ("%d message%s (%d bytes)",
-                   nmsgs, nmsgs != 1 ? "s" : "", nbytes);
+                   nmsgs, PLURALS(nmsgs), nbytes);
        }
        else
            notifysw = 0;
index c502588..eb7e357 100644 (file)
@@ -304,7 +304,7 @@ main (int argc, char **argv)
      * Print total matched if not printing each matched message number.
      */
     if (!listsw) {
-       printf ("%d hit%s\n", mp2->numsel, mp2->numsel == 1 ? "" : "s");
+       printf ("%d hit%s\n", mp2->numsel, PLURALS(mp2->numsel));
     }
 
     svector_free (seqs);
index 3c9a61e..021aba8 100644 (file)
@@ -1566,18 +1566,16 @@ find_prefix (void)
 }
 
 
-#define        plural(x) (x == 1 ? "" : "s")
-
 static void
 chkadr (void)
 {
     if (badadr && unkadr)
        die (NULL, "%d address%s unparsable, %d addressee%s undeliverable",
-               badadr, plural (badadr), unkadr, plural (badadr));
+               badadr, PLURALS(badadr), unkadr, PLURALS(badadr));
     if (badadr)
-       die (NULL, "%d address%s unparsable", badadr, plural (badadr));
+       die (NULL, "%d address%s unparsable", badadr, PLURALS(badadr));
     if (unkadr)
-       die (NULL, "%d addressee%s undeliverable", unkadr, plural (unkadr));
+       die (NULL, "%d addressee%s undeliverable", unkadr, PLURALS(unkadr));
 }