]> diplodocus.org Git - nmh/blobdiff - uip/fmtdump.c
Alter HasSuffixC()'s char * to be const.
[nmh] / uip / fmtdump.c
index cc0bc70402a8ecaf0283ddf189c87f7940d47a64..594a46149fcee6e06a2807d2c6b7d6dd4453065d 100644 (file)
@@ -2,8 +2,6 @@
 /*
  * fmtdump.c -- compile format file and dump out instructions
  *
- * $Id$
- *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
  * complete copyright information.
 #include <h/fmt_compile.h>
 #include <h/scansbr.h>
 
-static struct swit switches[] = {
-#define        FORMSW              0
-    { "form formatfile", 0 },
-#define        FMTSW               1
-    { "format string", 5 },
-#define VERSIONSW           2
-    { "version", 0 },
-#define        HELPSW              3
-    { "help", 0 },
-    { NULL, 0 }
-};
+#define FMTDUMP_SWITCHES \
+    X("form formatfile", 0, FORMSW) \
+    X("format string", 5, FMTSW) \
+    X("version", 0, VERSIONSW) \
+    X("help", 0, HELPSW) \
+
+#define X(sw, minchars, id) id,
+DEFINE_SWITCH_ENUM(FMTDUMP);
+#undef X
+
+#define X(sw, minchars, id) { sw, minchars, id },
+DEFINE_SWITCH_ARRAY(FMTDUMP, switches);
+#undef X
 
 /* for assignlabel */
 static struct format *lvec[128];
@@ -39,6 +39,7 @@ static int findlabel(struct format *);
 static void assignlabel(struct format *);
 static char *f_typestr(int);
 static char *c_typestr(int);
+static char *c_flagsstr(int);
 static void litputs(char *);
 static void litputc(char);
 
@@ -46,18 +47,11 @@ static void litputc(char);
 int
 main (int argc, char **argv)
 {
-    int ncomps;
     char *cp, *form = NULL, *format = NULL;
     char buf[BUFSIZ], *nfs, **argp, **arguments;
     struct format *fmt;
 
-#ifdef LOCALE
-    setlocale(LC_ALL, "");
-#endif
-    invo_name = r1bindex (argv[0], '/');
-
-    /* read user profile/context */
-    context_read();
+    if (nmh_init(argv[0], 2)) { return 1; }
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -74,10 +68,10 @@ main (int argc, char **argv)
                case HELPSW: 
                    snprintf (buf, sizeof(buf), "%s [switches]", invo_name);
                    print_help (buf, switches, 1);
-                   done (1);
+                   done (0);
                case VERSIONSW:
                    print_version(invo_name);
-                   done (1);
+                   done (0);
 
                case FORMSW: 
                    if (!(form = *argp++) || *form == '-')
@@ -102,17 +96,21 @@ main (int argc, char **argv)
      * Get new format string.  Must be before chdir().
      */
     nfs = new_fs (form, format, FORMAT);
-    ncomps = fmt_compile(nfs, &fmt);
+    (void) fmt_compile(nfs, &fmt, 1);
 
     fmt_dump(fmt);
-    return done(0);
+
+    fmt_free(fmt, 1);
+
+    done(0);
+    return 1;
 }
 
 static void
 fmt_dump (struct format *fmth)
 {
        int i;
-       register struct format *fmt, *addr;
+       struct format *fmt, *addr;
 
        /* Assign labels */
        for (fmt = fmth; fmt; ++fmt) {
@@ -144,7 +142,7 @@ fmt_dump (struct format *fmth)
 static void
 dumpone(struct format *fmt)
 {
-       register int i;
+       int i;
 
        if ((i = findlabel(fmt)) >= 0)
                printf("L%d:", i);
@@ -163,7 +161,7 @@ dumpone(struct format *fmt)
                if (fmt->f_comp->c_type)
                        printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
                if (fmt->f_comp->c_flags)
-                       printf(", c_flags %d", fmt->f_comp->c_flags);
+                       printf(", c_flags %s", c_flagsstr(fmt->f_comp->c_flags));
                break;
 
        case FT_LV_SEC:
@@ -195,7 +193,7 @@ dumpone(struct format *fmt)
                if (fmt->f_comp->c_type)
                        printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
                if (fmt->f_comp->c_flags)
-                       printf(", c_flags %d", fmt->f_comp->c_flags);
+                       printf(", c_flags %s", c_flagsstr(fmt->f_comp->c_flags));
                break;
 
        case FT_LS_ADDR:
@@ -212,12 +210,14 @@ dumpone(struct format *fmt)
        case FT_LS_FRIENDLY:
        case FT_PARSEADDR:
        case FT_MYMBOX:
+       case FT_GETMYMBOX:
+       case FT_GETMYADDR:
                printf(", c_name ");
                litputs(fmt->f_comp->c_name);
                if (fmt->f_comp->c_type)
                        printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
                if (fmt->f_comp->c_flags)
-                       printf(", c_flags %d", fmt->f_comp->c_flags);
+                       printf(", c_flags %s", c_flagsstr(fmt->f_comp->c_flags));
                break;
 
        case FT_COMPF:
@@ -228,7 +228,7 @@ dumpone(struct format *fmt)
                if (fmt->f_comp->c_type)
                        printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
                if (fmt->f_comp->c_flags)
-                       printf(", c_flags %d", fmt->f_comp->c_flags);
+                       printf(", c_flags %s", c_flagsstr(fmt->f_comp->c_flags));
                break;
 
        case FT_STRF:
@@ -284,6 +284,7 @@ dumpone(struct format *fmt)
        case FT_LV_LIT:
        case FT_LV_PLUS_L:
        case FT_LV_MINUS_L:
+       case FT_LV_MULTIPLY_L:
        case FT_LV_DIVIDE_L:
        case FT_LV_MODULO_L:
                printf(" value %d", fmt->f_value);
@@ -321,7 +322,7 @@ dumpone(struct format *fmt)
 static int
 findlabel(struct format *addr)
 {
-       register int i;
+       int i;
 
        for (i = 0; i < lused; ++i)
                if (addr == lvec[i])
@@ -355,6 +356,8 @@ f_typestr(int t)
        case FT_STRF: return("STRF");
        case FT_STRFW: return("STRFW");
        case FT_PUTADDR: return("PUTADDR");
+       case FT_STRLIT: return("STRLIT");
+       case FT_STRLITZ: return("STRLITZ");
        case FT_LS_COMP: return("LS_COMP");
        case FT_LS_LIT: return("LS_LIT");
        case FT_LS_GETENV: return("LS_GETENV");
@@ -368,9 +371,12 @@ f_typestr(int t)
        case FT_LV_STRLEN: return("LV_STRLEN");
        case FT_LV_PLUS_L: return("LV_PLUS_L");
        case FT_LV_MINUS_L: return("LV_MINUS_L");
+       case FT_LV_MULTIPLY_L: return("LV_MULTIPLY_L");
        case FT_LV_DIVIDE_L: return("LV_DIVIDE_L");
        case FT_LV_MODULO_L: return("LV_MODULO_L");
        case FT_LV_CHAR_LEFT: return("LV_CHAR_LEFT");
+       case FT_LS_KILO: return("LS_KILO");
+       case FT_LS_KIBI: return("LS_KIBI");
        case FT_LS_MONTH: return("LS_MONTH");
        case FT_LS_LMONTH: return("LS_LMONTH");
        case FT_LS_ZONE: return("LS_ZONE");
@@ -409,10 +415,10 @@ f_typestr(int t)
        case FT_PARSEDATE: return("PARSEDATE");
        case FT_PARSEADDR: return("PARSEADDR");
        case FT_FORMATADDR: return("FORMATADDR");
+       case FT_CONCATADDR: return("CONCATADDR");
        case FT_MYMBOX: return("MYMBOX");
-#ifdef FT_ADDTOSEQ
-       case FT_ADDTOSEQ: return("ADDTOSEQ");
-#endif
+       case FT_GETMYMBOX: return("GETMYMBOX");
+       case FT_GETMYADDR: return("GETMYADDR");
        case FT_SAVESTR: return("SAVESTR");
 #ifdef FT_PAUSE
        case FT_PAUSE: return ("PAUSE");
@@ -448,23 +454,40 @@ f_typestr(int t)
 static char *
 c_typestr(int t)
 {
-       register int i;
+       int i;
        static char buf[64];
 
        buf[0] = '\0';
-       if (t & ~(CT_ADDR|CT_DATE|CT_MYMBOX|CT_ADDRPARSE))
+       if (t & ~(CT_ADDR|CT_DATE))
                printf(buf, "0x%x ", t);
        strcat(buf, "<");
        i = 0;
        FNORD(CT_ADDR, "ADDR");
        FNORD(CT_DATE, "DATE");
-       FNORD(CT_MYMBOX, "MYMBOX");
-       FNORD(CT_ADDRPARSE, "ADDRPARSE");
        strcat(buf, ">");
        return(buf);
-#undef FNORD
 }
 
+static char *
+c_flagsstr(int t)
+{
+       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, ">");
+       return(buf);
+}
+#undef FNORD
+
 static void
 litputs(char *s)
 {