]> diplodocus.org Git - nmh/blobdiff - uip/fmttest.c
fdcompare.c: Move interface to own file.
[nmh] / uip / fmttest.c
index 78f08561fcd56ecdbe85ff8771b09b83268d43a0..798b573d3bebfb4896fa022ee152ca565a2b55a5 100644 (file)
@@ -5,12 +5,25 @@
  * complete copyright information.
  */
 
  * 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"
 
 #include "sbr/m_maildir.h"
 #include "sbr/terminal.h"
 
@@ -101,8 +114,8 @@ static char *test_concataddr(char *, char *);
 static int insert(struct mailname *);
 static void mlistfree(void);
 
 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";
 
 static struct mailname mq;     /* Mail addresses to check for duplicates */
 static char *dummy = "dummy";
 
@@ -115,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};
     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;
 
     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;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -135,11 +152,11 @@ main (int argc, char **argv)
             */
            if (*++cp == '-') {
                if (*++cp == '\0')
             */
            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++))
                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;
            }
                app_msgarg(&compargs, cp);
                continue;
            }
@@ -148,7 +165,7 @@ main (int argc, char **argv)
                    ambigsw (cp, switches);
                    done (1);
                case UNKWNSW: 
                    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);
 
                case HELPSW: 
                    snprintf (buf, sizeof(buf), "%s [switches]", invo_name);
@@ -158,12 +175,12 @@ main (int argc, char **argv)
                    print_version(invo_name);
                    done (0);
                case OTHERSW:
                    print_version(invo_name);
                    done (0);
                case OTHERSW:
-                   adios(NULL, "internal argument error!");
+                   die("internal argument error!");
                    continue;
 
                case OUTSIZESW:
                    if (!(cp = *argp++) || *cp == '-')
                    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)
                    if (strcmp(cp, "max") == 0)
                        outputsize = INT_MAX;
                    else if (strcmp(cp, "width") == 0)
@@ -174,20 +191,20 @@ main (int argc, char **argv)
 
                case FORMSW: 
                    if (!(form = *argp++) || *form == '-')
 
                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 == '-')
                    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:
                    form = NULL;
                    continue;
 
                case TRACESW:
-                   trace++;
+                   trace = true;
                    continue;
                case NTRACESW:
                    continue;
                case NTRACESW:
-                   trace = 0;
+                   trace = false;
                    continue;
 
                case ADDRSW:
                    continue;
 
                case ADDRSW:
@@ -200,7 +217,7 @@ main (int argc, char **argv)
                case MESSAGESW:
                    mode = MESSAGE;
                    defformat = FORMAT;
                case MESSAGESW:
                    mode = MESSAGE;
                    defformat = FORMAT;
-                   dupaddrs = 0;
+                   dupaddrs = false;
                    continue;
                case DATESW:
                    mode = DATE;
                    continue;
                case DATESW:
                    mode = DATE;
@@ -215,50 +232,50 @@ main (int argc, char **argv)
                    continue;
 
                case DUPADDRSW:
                    continue;
 
                case DUPADDRSW:
-                   dupaddrs++;
+                   dupaddrs = true;
                    continue;
                case NDUPADDRSW:
                    continue;
                case NDUPADDRSW:
-                   dupaddrs = 0;
+                   dupaddrs = false;
                    continue;
 
                case CCMESW:
                    continue;
 
                case CCMESW:
-                   ccme++;
+                   ccme = true;
                    continue;
                case NCCMESW:
                    continue;
                case NCCMESW:
-                   ccme = 0;
+                   ccme = false;
                    continue;
 
                case WIDTHSW:
                    if (!(cp = *argp++) || *cp == '-')
                    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 == '-')
                    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 == '-')
                    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 == '-')
                    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 == '-')
                    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:
                    msgunseen = atoi(cp);
                    continue;
 
                case DUMPSW:
-                   dump++;
+                   dump = true;
                    continue;
                case NDUMPSW:
                    continue;
                case NDUMPSW:
-                   dump = 0;
+                   dump = false;
                    continue;
 
            }
                    continue;
 
            }
@@ -270,7 +287,7 @@ main (int argc, char **argv)
 
        if (mode == MESSAGE && !files && (*cp == '+' || *cp == '@')) {
            if (folder)
 
        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);
             folder = pluspath (cp);
        } else
            app_msgarg(&msgs, cp);
@@ -287,7 +304,7 @@ main (int argc, char **argv)
      */
 
    if (!dump && compargs.size == 0 && msgs.size == 0) {
      */
 
    if (!dump && compargs.size == 0 && msgs.size == 0) {
-        adios(NULL, "usage: [switches] [+folder] msgs | strings...");
+        die("usage: [switches] [+folder] msgs | strings...");
    }
 
    /*
    }
 
    /*
@@ -296,7 +313,7 @@ main (int argc, char **argv)
     */
 
    if (mode == RAW && form == NULL && format == NULL) {
     */
 
    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");
    }
 
               "using -raw");
    }
 
@@ -335,11 +352,11 @@ main (int argc, char **argv)
      * callback, do that now.  Also, prime ismymbox if we use it.
      */
 
      * callback, do that now.  Also, prime ismymbox if we use it.
      */
 
-    if (dupaddrs == 0 || trace) {
+    if (!dupaddrs || trace) {
        ZERO(&cb);
        cbp = &cb;
 
        ZERO(&cb);
        cbp = &cb;
 
-       if (dupaddrs == 0) {
+       if (!dupaddrs) {
            cb.formataddr = test_formataddr;
            cb.concataddr = test_concataddr;
            if (!ccme)
            cb.formataddr = test_formataddr;
            cb.concataddr = test_concataddr;
            if (!ccme)
@@ -500,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(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)
 
     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]))
 
     for (i = 0; i < msgs->size; i++)
        if (!m_convert(mp, msgs->msgs[i]))
@@ -720,20 +737,21 @@ test_trace(void *context, struct format *fmt, int num, char *str,
           const char *outbuf)
 {
     struct trace_context *ctx = (struct trace_context *) context;
           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;
 
     dumpone(fmt);
 
     if (num != ctx->num) {
        printf("num=%d", num);
        ctx->num = num;
-       changed++;
+       changed = true;
     }
 
     if (str != ctx->str) {
     }
 
     if (str != ctx->str) {
-       if (changed++)
+       if (changed)
             putchar(' ');
             putchar(' ');
-       printf("str=");
+        changed = true;
+       fputs("str=", stdout);
        litputs(str);
        ctx->str = str;
     }
        litputs(str);
        ctx->str = str;
     }
@@ -742,7 +760,7 @@ test_trace(void *context, struct format *fmt, int num, char *str,
         putchar('\n');
 
     if (strcmp(outbuf, ctx->outbuf) != 0) {
         putchar('\n');
 
     if (strcmp(outbuf, ctx->outbuf) != 0) {
-       printf("outbuf=");
+       fputs("outbuf=", stdout);
        litputs(outbuf);
        putchar('\n');
        free(ctx->outbuf);
        litputs(outbuf);
        putchar('\n');
        free(ctx->outbuf);
@@ -782,7 +800,7 @@ dumpone(struct format *fmt)
        case FT_LS_COMP:
        case FT_LV_COMPFLAG:
        case FT_LV_COMP:
        case FT_LS_COMP:
        case FT_LV_COMPFLAG:
        case FT_LV_COMP:
-               printf(", comp ");
+               fputs(", comp ", stdout);
                litputs(fmt->f_comp->c_name);
                if (fmt->f_comp->c_type)
                        printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
                litputs(fmt->f_comp->c_name);
                if (fmt->f_comp->c_type)
                        printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
@@ -814,7 +832,7 @@ dumpone(struct format *fmt)
        case FT_LOCALDATE:
        case FT_GMTDATE:
        case FT_PARSEDATE:
        case FT_LOCALDATE:
        case FT_GMTDATE:
        case FT_PARSEDATE:
-               printf(", c_name ");
+               fputs(", c_name ", stdout);
                litputs(fmt->f_comp->c_name);
                if (fmt->f_comp->c_type)
                        printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
                litputs(fmt->f_comp->c_name);
                if (fmt->f_comp->c_type)
                        printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
@@ -838,7 +856,7 @@ dumpone(struct format *fmt)
        case FT_MYMBOX:
        case FT_GETMYMBOX:
        case FT_GETMYADDR:
        case FT_MYMBOX:
        case FT_GETMYMBOX:
        case FT_GETMYADDR:
-               printf(", c_name ");
+               fputs(", c_name ", stdout);
                litputs(fmt->f_comp->c_name);
                if (fmt->f_comp->c_type)
                        printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
                litputs(fmt->f_comp->c_name);
                if (fmt->f_comp->c_type)
                        printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
@@ -849,7 +867,7 @@ dumpone(struct format *fmt)
        case FT_COMPF:
                printf(", width %d, fill '", fmt->f_width);
                litputc(fmt->f_fill);
        case FT_COMPF:
                printf(", width %d, fill '", fmt->f_width);
                litputc(fmt->f_fill);
-               printf("' name ");
+               fputs("' name ", stdout);
                litputs(fmt->f_comp->c_name);
                if (fmt->f_comp->c_type)
                        printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
                litputs(fmt->f_comp->c_name);
                if (fmt->f_comp->c_type)
                        printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
@@ -872,7 +890,7 @@ dumpone(struct format *fmt)
        case FT_LITF:
                printf(", width %d, fill '", fmt->f_width);
                litputc(fmt->f_fill);
        case FT_LITF:
                printf(", width %d, fill '", fmt->f_width);
                litputc(fmt->f_fill);
-               printf("' ");
+               fputs("' ", stdout);
                litputs(fmt->f_text);
                break;
 
                litputs(fmt->f_text);
                break;
 
@@ -888,7 +906,7 @@ dumpone(struct format *fmt)
        case FT_IF_S_NULL:
        case FT_IF_MATCH:
        case FT_IF_AMATCH:
        case FT_IF_S_NULL:
        case FT_IF_MATCH:
        case FT_IF_AMATCH:
-               printf(" continue else goto");
+               fputs(" continue else goto", stdout);
                /* FALLTHRU */
        case FT_GOTO:
                i = findlabel(fmt + fmt->f_skip);
                /* FALLTHRU */
        case FT_GOTO:
                i = findlabel(fmt + fmt->f_skip);
@@ -915,17 +933,17 @@ dumpone(struct format *fmt)
                break;
 
        case FT_LS_LIT:
                break;
 
        case FT_LS_LIT:
-               printf(" str ");
+               fputs(" str ", stdout);
                litputs(fmt->f_text);
                break;
 
        case FT_LS_GETENV:
                litputs(fmt->f_text);
                break;
 
        case FT_LS_GETENV:
-               printf(" getenv ");
+               fputs(" getenv ", stdout);
                litputs(fmt->f_text);
                break;
 
        case FT_LS_DECODECOMP:
                litputs(fmt->f_text);
                break;
 
        case FT_LS_DECODECOMP:
-               printf(", comp ");
+               fputs(", comp ", stdout);
                litputs(fmt->f_comp->c_name);
                break;
 
                litputs(fmt->f_comp->c_name);
                break;
 
@@ -982,8 +1000,8 @@ findlabel(struct format *addr)
 
        for (i = 0; i < lused; ++i)
                if (addr == lvec[i])
 
        for (i = 0; i < lused; ++i)
                if (addr == lvec[i])
-                       return(i);
-       return(-1);
+                       return i;
+       return -1;
 }
 
 static void
 }
 
 static void
@@ -1101,7 +1119,7 @@ f_typestr(int t)
        case FT_V_AMATCH: return "V_AMATCH";
        default:
                snprintf(buf, sizeof(buf), "/* ??? #%d */", t);
        case FT_V_AMATCH: return "V_AMATCH";
        default:
                snprintf(buf, sizeof(buf), "/* ??? #%d */", t);
-               return(buf);
+               return buf;
        }
 }
 
        }
 }
 
@@ -1111,7 +1129,7 @@ c_typestr(int t)
        static char buf[64];
 
        snprintb(buf, sizeof(buf), t, CT_BITS);
        static char buf[64];
 
        snprintb(buf, sizeof(buf), t, CT_BITS);
-       return(buf);
+       return buf;
 }
 
 static char *
 }
 
 static char *
@@ -1120,7 +1138,7 @@ c_flagsstr(int t)
        static char buf[64];
 
        snprintb(buf, sizeof(buf), t, CF_BITS);
        static char buf[64];
 
        snprintb(buf, sizeof(buf), t, CF_BITS);
-       return(buf);
+       return buf;
 }
 
 static void
 }
 
 static void
@@ -1209,7 +1227,7 @@ test_formataddr (char *orig, char *str)
 {
     int len;
     char error[BUFSIZ];
 {
     int len;
     char error[BUFSIZ];
-    int isgroup;
+    bool isgroup;
     char *dst;
     char *cp;
     char *sp;
     char *dst;
     char *cp;
     char *sp;
@@ -1238,14 +1256,14 @@ test_formataddr (char *orig, char *str)
     }
 
     /* concatenate all the new addresses onto 'buf' */
     }
 
     /* 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++ = ';';
        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 */
        }
        if (insert (mp)) {
            /* if we get here we're going to add an address */
@@ -1256,7 +1274,7 @@ test_formataddr (char *orig, char *str)
            if (mp->m_gname) {
                CHECKMEM (mp->m_gname);
                CPY (mp->m_gname);
            if (mp->m_gname) {
                CHECKMEM (mp->m_gname);
                CPY (mp->m_gname);
-               isgroup++;
+               isgroup = true;
            }
            sp = adrformat (mp);
            CHECKMEM (sp);
            }
            sp = adrformat (mp);
            CHECKMEM (sp);
@@ -1269,7 +1287,7 @@ test_formataddr (char *orig, char *str)
 
     *dst = '\0';
     last_dst = dst;
 
     *dst = '\0';
     last_dst = dst;
-    return (buf);
+    return buf;
 }
 
 
 }
 
 
@@ -1282,9 +1300,9 @@ test_concataddr(char *orig, char *str)
 {
     char *cp;
 
 {
     char *cp;
 
-    nodupcheck = 1;
+    nodupcheck = true;
     cp = test_formataddr(orig, str);
     cp = test_formataddr(orig, str);
-    nodupcheck = 0;
+    nodupcheck = false;
     return cp;
 }
 
     return cp;
 }