]> diplodocus.org Git - nmh/blobdiff - uip/fmtdump.c
Commit ddf3a8574f65 is a fix to commit af586ebe59b7.
[nmh] / uip / fmtdump.c
index 95a77926b58dfeeec979ec31d2858d104141c5f0..b5a4660c94da3c91e08fccf9ccbeedc3b5d83487 100644 (file)
@@ -5,11 +5,19 @@
  * complete copyright information.
  */
 
-#include <h/mh.h>
-#include <h/fmt_scan.h>
-#include <h/fmt_compile.h>
-#include <h/scansbr.h>
-#include <h/utils.h>
+#include "h/mh.h"
+#include "sbr/fmt_new.h"
+#include "scansbr.h"
+#include "sbr/getarguments.h"
+#include "sbr/smatch.h"
+#include "sbr/ambigsw.h"
+#include "sbr/print_version.h"
+#include "sbr/print_help.h"
+#include "sbr/error.h"
+#include "h/fmt_scan.h"
+#include "h/fmt_compile.h"
+#include "h/done.h"
+#include "h/utils.h"
 
 #define FMTDUMP_SWITCHES \
     X("form formatfile", 0, FORMSW) \
@@ -50,7 +58,7 @@ main (int argc, char **argv)
     char buf[BUFSIZ], *nfs, **argp, **arguments;
     struct format *fmt;
 
-    if (nmh_init(argv[0], 2)) { return 1; }
+    if (nmh_init(argv[0], true, false)) { return 1; }
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -62,7 +70,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);
@@ -74,21 +82,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;
 
            }
        }
        if (form)
-           adios (NULL, "only one form at a time!");
-       else
-           form = cp;
+           die("only one form at a time!");
+        form = cp;
     }
 
     /*
@@ -155,7 +162,7 @@ dumpone(struct format *fmt)
        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));
@@ -187,7 +194,7 @@ dumpone(struct format *fmt)
        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));
@@ -211,7 +218,7 @@ dumpone(struct format *fmt)
        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));
@@ -222,7 +229,7 @@ dumpone(struct format *fmt)
        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));
@@ -245,7 +252,7 @@ dumpone(struct format *fmt)
        case FT_LITF:
                printf(", width %d, fill '", fmt->f_width);
                litputc(fmt->f_fill);
-               printf("' ");
+               fputs("' ", stdout);
                litputs(fmt->f_text);
                break;
 
@@ -261,7 +268,7 @@ dumpone(struct format *fmt)
        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);
@@ -288,17 +295,17 @@ dumpone(struct format *fmt)
                break;
 
        case FT_LS_LIT:
-               printf(" str ");
+               fputs(" str ", stdout);
                litputs(fmt->f_text);
                break;
 
        case FT_LS_GETENV:
-               printf(" getenv ");
+               fputs(" getenv ", stdout);
                litputs(fmt->f_text);
                break;
 
        case FT_LS_DECODECOMP:
-               printf(", comp ");
+               fputs(", comp ", stdout);
                litputs(fmt->f_comp->c_name);
                break;
 
@@ -323,8 +330,8 @@ findlabel(struct format *addr)
 
        for (i = 0; i < lused; ++i)
                if (addr == lvec[i])
-                       return(i);
-       return(-1);
+                       return i;
+       return -1;
 }
 
 static void
@@ -436,7 +443,7 @@ f_typestr(int t)
        case FT_V_AMATCH: return "V_AMATCH";
        default:
                 snprintf(buf, sizeof buf, "/* ??? #%d */", t);
-               return(buf);
+               return buf;
        }
 }
 
@@ -459,7 +466,7 @@ c_typestr(int t)
        FNORD(CT_ADDR, "ADDR");
        FNORD(CT_DATE, "DATE");
        strcat(buf, ">");
-       return(buf);
+       return buf;
 }
 
 static char *
@@ -478,7 +485,7 @@ c_flagsstr(int t)
        FNORD(CF_DATEFAB, "DATEFAB");
        FNORD(CF_TRIMMED, "TRIMMED");
        strcat(buf, ">");
-       return(buf);
+       return buf;
 }
 #undef FNORD