]> diplodocus.org Git - nmh/blobdiff - uip/fmttest.c
In mhshow, copy result of call to norm_charmap() and get_charset()
[nmh] / uip / fmttest.c
index 858732c0524e06c25e07d8604e4a5af909ac7dbb..2f45e7b5363b96b5b0f7aee34c5837f94da42615 100644 (file)
@@ -28,8 +28,6 @@
     X("nodupaddrs", 0, NDUPADDRSW) \
     X("ccme", 0, CCMESW) \
     X("noccme", 0, NCCMESW) \
-    X("normalize", 0, NORMSW) \
-    X("nonormalize", 0, NNORMSW) \
     X("outsize size-in-characters", 0, OUTSIZESW) \
     X("bufsize size-in-bytes", 0, BUFSZSW) \
     X("width column-width", 0, WIDTHSW) \
@@ -60,7 +58,7 @@ static struct format **lvec = NULL;
 static int lused = 0;
 static int lallocated = 0;
 
-enum mode_t { MESSAGE, ADDRESS, RAW };
+enum mode_t { MESSAGE, ADDRESS, DATE, RAW };
 #define DEFADDRFORMAT "%<{error}%{error}: %{text}%|%(putstr(proper{text}))%>"
 #define DEFDATEFORMAT "%<(nodate{text})error: %{text}%|%(putstr(pretty{text}))%>"
 
@@ -88,7 +86,7 @@ static char *c_flagsstr(int);
 static void litputs(char *);
 static void litputc(char);
 static void process_addresses(struct format *, struct msgs_array *, char *,
-                             int, int, int *, int, struct fmt_callbacks *);
+                             int, int, int *, struct fmt_callbacks *);
 static void process_raw(struct format *, struct msgs_array *, char *,
                        int, int, int *, struct fmt_callbacks *);
 static void process_messages(struct format *, struct msgs_array *,
@@ -119,18 +117,11 @@ main (int argc, char **argv)
     int dump = 0, i;
     int outputsize = 0, bufsize = 0, dupaddrs = 1, trace = 0, files = 0;
     int colwidth = -1, msgnum = -1, msgcur = -1, msgsize = -1, msgunseen = -1;
-    int normalize = AD_HOST;
     enum mode_t mode = MESSAGE;
     int dat[5];
     struct fmt_callbacks cb, *cbp = NULL;
 
-#ifdef LOCALE
-    setlocale(LC_ALL, "");
-#endif
-    invo_name = r1bindex (argv[0], '/');
-
-    /* read user profile/context */
-    context_read();
+    if (nmh_init(argv[0], 1)) { return 1; }
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -196,13 +187,6 @@ main (int argc, char **argv)
                    form = NULL;
                    continue;
 
-               case NORMSW:
-                   normalize = AD_HOST;
-                   continue;
-               case NNORMSW:
-                   normalize = AD_NHST;
-                   continue;
-
                case TRACESW:
                    trace++;
                    continue;
@@ -223,7 +207,7 @@ main (int argc, char **argv)
                    dupaddrs = 0;
                    continue;
                case DATESW:
-                   mode = RAW;
+                   mode = DATE;
                    defformat = DEFDATEFORMAT;
                    continue;
 
@@ -403,10 +387,9 @@ main (int argc, char **argv)
        }
 
        if (mode == ADDRESS) {
-           fmt_norm = normalize;
            process_addresses(fmt, &msgs, buffer, bufsize, outputsize,
-                             dat, normalize, cbp);
-       } else
+                             dat, cbp);
+       } else /* Fall-through for RAW or DATE */
            process_raw(fmt, &msgs, buffer, bufsize, outputsize, dat, cbp);
     }
 
@@ -428,8 +411,7 @@ struct pqpair {
 
 static void
 process_addresses(struct format *fmt, struct msgs_array *addrs, char *buffer,
-                 int bufsize, int outwidth, int *dat, int norm,
-                 struct fmt_callbacks *cb)
+                 int bufsize, int outwidth, int *dat, struct fmt_callbacks *cb)
 {
     int i;
     char *cp, error[BUFSIZ];
@@ -452,7 +434,7 @@ process_addresses(struct format *fmt, struct msgs_array *addrs, char *buffer,
        while ((cp = getname(addrs->msgs[i]))) {
            if ((p = (struct pqpair *) calloc ((size_t) 1, sizeof(*p))) == NULL)
                adios (NULL, "unable to allocate pqpair memory");
-           if ((mp = getm(cp, NULL, 0, norm, error)) == NULL) {
+           if ((mp = getm(cp, NULL, 0, error, sizeof(error))) == NULL) {
                p->pq_text = getcpy(cp);
                p->pq_error = getcpy(error);
            } else {
@@ -773,7 +755,8 @@ test_trace(void *context, struct format *fmt, int num, char *str, char *outbuf)
     if (str != ctx->str) {
        if (changed++)
            printf(" ");
-       printf("str=\"%s\"", str ? str : "NULL");
+       printf("str=");
+       litputs(str);
        ctx->str = str;
     }
 
@@ -781,7 +764,9 @@ test_trace(void *context, struct format *fmt, int num, char *str, char *outbuf)
        printf("\n");
 
     if (strcmp(outbuf, ctx->outbuf) != 0) {
-       printf("outbuf=\"%s\"\n", outbuf);
+       printf("outbuf=");
+       litputs(outbuf);
+       putchar('\n');
        free(ctx->outbuf);
        ctx->outbuf = getcpy(outbuf);
     }
@@ -1143,47 +1128,23 @@ f_typestr(int t)
        }
 }
 
-#define FNORD(v, s) if (t & (v)) { \
-       if (i++ > 0) \
-               strcat(buf, "|"); \
-       strcat(buf, s); }
-
 static char *
 c_typestr(int t)
 {
-       register int i;
        static char buf[64];
 
-       buf[0] = '\0';
-       if (t & ~(CT_ADDR|CT_DATE))
-               printf(buf, "0x%x ", t);
-       strcat(buf, "<");
-       i = 0;
-       FNORD(CT_ADDR, "ADDR");
-       FNORD(CT_DATE, "DATE");
-       strcat(buf, ">");
+       snprintb(buf, sizeof(buf), t, CT_BITS);
        return(buf);
 }
 
 static char *
 c_flagsstr(int t)
 {
-       register int i;
        static char buf[64];
 
-       buf[0] = '\0';
-       if (t & ~(CF_TRUE|CF_PARSED|CF_DATEFAB|CF_TRIMMED))
-               printf(buf, "0x%x ", t);
-       strcat(buf, "<");
-       i = 0;
-       FNORD(CF_TRUE, "TRUE");
-       FNORD(CF_PARSED, "PARSED");
-       FNORD(CF_DATEFAB, "DATEFAB");
-       FNORD(CF_TRIMMED, "TRIMMED");
-       strcat(buf, ">");
+       snprintb(buf, sizeof(buf), t, CF_BITS);
        return(buf);
 }
-#undef FNORD
 
 static void
 litputs(char *s)
@@ -1201,11 +1162,8 @@ static void
 litputc(char c)
 {
        if (c & ~ 0177) {
-               putc('M', stdout);
-               putc('-', stdout);
-               c &= 0177;
-       }
-       if (c < 0x20 || c == 0177) {
+               printf("\\x%02x", (unsigned char) c);
+       } else if (c < 0x20 || c == 0177) {
                if (c == '\b') {
                        putc('\\', stdout);
                        putc('b', stdout);
@@ -1304,7 +1262,7 @@ test_formataddr (char *orig, char *str)
 
     /* concatenate all the new addresses onto 'buf' */
     for (isgroup = 0; (cp = getname (str)); ) {
-       if ((mp = getm (cp, NULL, 0, AD_NAME, error)) == NULL) {
+       if ((mp = getm (cp, NULL, 0, error, sizeof(error))) == NULL) {
            fprintf(stderr, "bad address \"%s\" -- %s\n", cp, error);
            continue;
        }