]> diplodocus.org Git - nmh/blobdiff - uip/fmttest.c
fdcompare.c: Move interface to own file.
[nmh] / uip / fmttest.c
index d458bb6bdec4fe081ca2581741dd3269037ef201..798b573d3bebfb4896fa022ee152ca565a2b55a5 100644 (file)
@@ -5,12 +5,24 @@
  * complete copyright information.
  */
 
-#include <h/mh.h>
-#include <h/fmt_scan.h>
-#include <h/fmt_compile.h>
-#include <h/utils.h>
-#include <h/scansbr.h>
-#include <h/addrsbr.h>
+#include "h/mh.h"
+#include "sbr/folder_read.h"
+#include "sbr/folder_free.h"
+#include "sbr/context_save.h"
+#include "sbr/context_replace.h"
+#include "sbr/context_find.h"
+#include "sbr/brkstring.h"
+#include "sbr/ambigsw.h"
+#include "sbr/path.h"
+#include "sbr/print_version.h"
+#include "sbr/print_help.h"
+#include "sbr/seq_getnum.h"
+#include "sbr/error.h"
+#include "h/fmt_scan.h"
+#include "h/fmt_compile.h"
+#include "h/utils.h"
+#include "h/scansbr.h"
+#include "h/addrsbr.h"
 #include "h/done.h"
 #include "sbr/m_maildir.h"
 #include "sbr/terminal.h"
@@ -102,8 +114,8 @@ static char *test_concataddr(char *, char *);
 static int insert(struct mailname *);
 static void mlistfree(void);
 
-static int nodupcheck = 0;     /* If set, no check for duplicates */
-static int ccme = 0;           /* Should I cc myself? */
+static bool nodupcheck;        /* If set, no check for duplicates */
+static bool ccme;              /* Should I cc myself? */
 static struct mailname mq;     /* Mail addresses to check for duplicates */
 static char *dummy = "dummy";
 
@@ -116,14 +128,18 @@ main (int argc, char **argv)
     struct format *fmt;
     struct comp *cptr;
     struct msgs_array msgs = { 0, 0, NULL }, compargs = { 0, 0, NULL};
-    int dump = 0, i;
-    int outputsize = 0, dupaddrs = 1, trace = 0, files = 0;
+    bool dump = false;
+    int i;
+    int outputsize = 0;
+    bool dupaddrs = true;
+    bool trace = false;
+    int files = 0;
     int colwidth = -1, msgnum = -1, msgcur = -1, msgsize = -1, msgunseen = -1;
     enum mode_t mode = MESSAGE;
     int dat[5];
     struct fmt_callbacks cb, *cbp = NULL;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], true, true)) { return 1; }
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -136,11 +152,11 @@ main (int argc, char **argv)
             */
            if (*++cp == '-') {
                if (*++cp == '\0')
-                   adios(NULL, "missing component name after --");
+                   die("missing component name after --");
                app_msgarg(&compargs, cp);
                /* Grab next argument for component text */
                if (!(cp = *argp++))
-                   adios(NULL, "missing argument to %s", argp[-2]);
+                   die("missing argument to %s", argp[-2]);
                app_msgarg(&compargs, cp);
                continue;
            }
@@ -149,7 +165,7 @@ main (int argc, char **argv)
                    ambigsw (cp, switches);
                    done (1);
                case UNKWNSW: 
-                   adios (NULL, "-%s unknown", cp);
+                   die("-%s unknown", cp);
 
                case HELPSW: 
                    snprintf (buf, sizeof(buf), "%s [switches]", invo_name);
@@ -159,12 +175,12 @@ main (int argc, char **argv)
                    print_version(invo_name);
                    done (0);
                case OTHERSW:
-                   adios(NULL, "internal argument error!");
+                   die("internal argument error!");
                    continue;
 
                case OUTSIZESW:
                    if (!(cp = *argp++) || *cp == '-')
-                       adios(NULL, "missing argument to %s", argp[-2]);
+                       die("missing argument to %s", argp[-2]);
                    if (strcmp(cp, "max") == 0)
                        outputsize = INT_MAX;
                    else if (strcmp(cp, "width") == 0)
@@ -175,20 +191,20 @@ main (int argc, char **argv)
 
                case FORMSW: 
                    if (!(form = *argp++) || *form == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
+                       die("missing argument to %s", argp[-2]);
                    format = NULL;
                    continue;
                case FMTSW: 
                    if (!(format = *argp++) || *format == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
+                       die("missing argument to %s", argp[-2]);
                    form = NULL;
                    continue;
 
                case TRACESW:
-                   trace++;
+                   trace = true;
                    continue;
                case NTRACESW:
-                   trace = 0;
+                   trace = false;
                    continue;
 
                case ADDRSW:
@@ -201,7 +217,7 @@ main (int argc, char **argv)
                case MESSAGESW:
                    mode = MESSAGE;
                    defformat = FORMAT;
-                   dupaddrs = 0;
+                   dupaddrs = false;
                    continue;
                case DATESW:
                    mode = DATE;
@@ -216,50 +232,50 @@ main (int argc, char **argv)
                    continue;
 
                case DUPADDRSW:
-                   dupaddrs++;
+                   dupaddrs = true;
                    continue;
                case NDUPADDRSW:
-                   dupaddrs = 0;
+                   dupaddrs = false;
                    continue;
 
                case CCMESW:
-                   ccme++;
+                   ccme = true;
                    continue;
                case NCCMESW:
-                   ccme = 0;
+                   ccme = false;
                    continue;
 
                case WIDTHSW:
                    if (!(cp = *argp++) || *cp == '-')
-                       adios(NULL, "missing argument to %s", argp[-2]);
+                       die("missing argument to %s", argp[-2]);
                    colwidth = atoi(cp);
                    continue;
                case MSGNUMSW:
                    if (!(cp = *argp++) || *cp == '-')
-                       adios(NULL, "missing argument to %s", argp[-2]);
+                       die("missing argument to %s", argp[-2]);
                    msgnum = atoi(cp);
                    continue;
                case MSGCURSW:
                    if (!(cp = *argp++) || *cp == '-')
-                       adios(NULL, "missing argument to %s", argp[-2]);
+                       die("missing argument to %s", argp[-2]);
                    msgcur = atoi(cp);
                    continue;
                case MSGSIZESW:
                    if (!(cp = *argp++) || *cp == '-')
-                       adios(NULL, "missing argument to %s", argp[-2]);
+                       die("missing argument to %s", argp[-2]);
                    msgsize = atoi(cp);
                    continue;
                case UNSEENSW:
                    if (!(cp = *argp++) || *cp == '-')
-                       adios(NULL, "missing argument to %s", argp[-2]);
+                       die("missing argument to %s", argp[-2]);
                    msgunseen = atoi(cp);
                    continue;
 
                case DUMPSW:
-                   dump++;
+                   dump = true;
                    continue;
                case NDUMPSW:
-                   dump = 0;
+                   dump = false;
                    continue;
 
            }
@@ -271,7 +287,7 @@ main (int argc, char **argv)
 
        if (mode == MESSAGE && !files && (*cp == '+' || *cp == '@')) {
            if (folder)
-               adios (NULL, "only one folder at a time!");
+               die("only one folder at a time!");
             folder = pluspath (cp);
        } else
            app_msgarg(&msgs, cp);
@@ -288,7 +304,7 @@ main (int argc, char **argv)
      */
 
    if (!dump && compargs.size == 0 && msgs.size == 0) {
-        adios(NULL, "usage: [switches] [+folder] msgs | strings...");
+        die("usage: [switches] [+folder] msgs | strings...");
    }
 
    /*
@@ -297,7 +313,7 @@ main (int argc, char **argv)
     */
 
    if (mode == RAW && form == NULL && format == NULL) {
-       adios (NULL, "You must specify a format with -form or -format when "
+       die("You must specify a format with -form or -format when "
               "using -raw");
    }
 
@@ -336,11 +352,11 @@ main (int argc, char **argv)
      * callback, do that now.  Also, prime ismymbox if we use it.
      */
 
-    if (dupaddrs == 0 || trace) {
+    if (!dupaddrs || trace) {
        ZERO(&cb);
        cbp = &cb;
 
-       if (dupaddrs == 0) {
+       if (!dupaddrs) {
            cb.formataddr = test_formataddr;
            cb.concataddr = test_concataddr;
            if (!ccme)
@@ -501,10 +517,10 @@ process_messages(struct format *fmt, struct msgs_array *comps,
        adios(maildir, "unable to change directory to");
 
     if (!(mp = folder_read(folder, 1)))
-       adios(NULL, "unable to read folder %s", folder);
+       die("unable to read folder %s", folder);
 
     if (mp->nummsg == 0)
-       adios(NULL, "no messages in %s", folder);
+       die("no messages in %s", folder);
 
     for (i = 0; i < msgs->size; i++)
        if (!m_convert(mp, msgs->msgs[i]))
@@ -721,19 +737,20 @@ test_trace(void *context, struct format *fmt, int num, char *str,
           const char *outbuf)
 {
     struct trace_context *ctx = (struct trace_context *) context;
-    int changed = 0;
+    bool changed = false;
 
     dumpone(fmt);
 
     if (num != ctx->num) {
        printf("num=%d", num);
        ctx->num = num;
-       changed++;
+       changed = true;
     }
 
     if (str != ctx->str) {
-       if (changed++)
+       if (changed)
             putchar(' ');
+        changed = true;
        fputs("str=", stdout);
        litputs(str);
        ctx->str = str;
@@ -1210,7 +1227,7 @@ test_formataddr (char *orig, char *str)
 {
     int len;
     char error[BUFSIZ];
-    int isgroup;
+    bool isgroup;
     char *dst;
     char *cp;
     char *sp;
@@ -1239,14 +1256,14 @@ test_formataddr (char *orig, char *str)
     }
 
     /* concatenate all the new addresses onto 'buf' */
-    for (isgroup = 0; (cp = getname (str)); ) {
+    for (isgroup = false; (cp = getname (str)); ) {
        if ((mp = getm (cp, NULL, 0, error, sizeof(error))) == NULL) {
            fprintf(stderr, "bad address \"%s\" -- %s\n", cp, error);
            continue;
        }
        if (isgroup && (mp->m_gname || !mp->m_ingrp)) {
            *dst++ = ';';
-           isgroup = 0;
+           isgroup = false;
        }
        if (insert (mp)) {
            /* if we get here we're going to add an address */
@@ -1257,7 +1274,7 @@ test_formataddr (char *orig, char *str)
            if (mp->m_gname) {
                CHECKMEM (mp->m_gname);
                CPY (mp->m_gname);
-               isgroup++;
+               isgroup = true;
            }
            sp = adrformat (mp);
            CHECKMEM (sp);
@@ -1283,9 +1300,9 @@ test_concataddr(char *orig, char *str)
 {
     char *cp;
 
-    nodupcheck = 1;
+    nodupcheck = true;
     cp = test_formataddr(orig, str);
-    nodupcheck = 0;
+    nodupcheck = false;
     return cp;
 }