X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/0a032eea07f6d77ac6ea4d5a39c9491c34358058..ec173fd2c:/uip/fmtdump.c?ds=inline diff --git a/uip/fmtdump.c b/uip/fmtdump.c index edaa06df..b5a4660c 100644 --- a/uip/fmtdump.c +++ b/uip/fmtdump.c @@ -1,15 +1,23 @@ -/* - * fmtdump.c -- compile format file and dump out instructions +/* fmtdump.c -- compile format file and dump out instructions * * 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 -#include -#include -#include +#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)); @@ -238,9 +245,6 @@ dumpone(struct format *fmt) break; case FT_LIT: -#ifdef FT_LIT_FORCE - case FT_LIT_FORCE: -#endif putchar(' '); litputs(fmt->f_text); break; @@ -248,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; @@ -264,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); @@ -291,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; @@ -326,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 @@ -342,105 +346,104 @@ f_typestr(int t) static char buf[32]; switch (t) { - case FT_COMP: return("COMP"); - case FT_COMPF: return("COMPF"); - case FT_LIT: return("LIT"); - case FT_LITF: return("LITF"); -#ifdef FT_LIT_FORCE - case FT_LIT_FORCE: return("LIT_FORCE"); -#endif - case FT_CHAR: return("CHAR"); - case FT_NUM: return("NUM"); - case FT_NUMF: return("NUMF"); - case FT_STR: return("STR"); - 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"); - case FT_LS_DECODECOMP: return("FT_LS_DECODECOMP"); - case FT_LS_DECODE: return("FT_LS_DECODE"); - case FT_LS_TRIM: return("LS_TRIM"); - case FT_LV_COMP: return("LV_COMP"); - case FT_LV_COMPFLAG: return("LV_COMPFLAG"); - case FT_LV_LIT: return("LV_LIT"); - case FT_LV_DAT: return("LV_DAT"); - 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"); - case FT_LS_DAY: return("LS_DAY"); - case FT_LS_WEEKDAY: return("LS_WEEKDAY"); - case FT_LS_822DATE: return("LS_822DATE"); - case FT_LS_PRETTY: return("LS_PRETTY"); - case FT_LV_SEC: return("LV_SEC"); - case FT_LV_MIN: return("LV_MIN"); - case FT_LV_HOUR: return("LV_HOUR"); - case FT_LV_MDAY: return("LV_MDAY"); - case FT_LV_MON: return("LV_MON"); - case FT_LV_YEAR: return("LV_YEAR"); - case FT_LV_YDAY: return("LV_YDAY"); - case FT_LV_WDAY: return("LV_WDAY"); - case FT_LV_ZONE: return("LV_ZONE"); - case FT_LV_CLOCK: return("LV_CLOCK"); - case FT_LV_RCLOCK: return("LV_RCLOCK"); - case FT_LV_DAYF: return("LV_DAYF"); - case FT_LV_DST: return("LV_DST"); - case FT_LV_ZONEF: return("LV_ZONEF"); - case FT_LS_ADDR: return("LS_ADDR"); - case FT_LS_PERS: return("LS_PERS"); - case FT_LS_MBOX: return("LS_MBOX"); - case FT_LS_HOST: return("LS_HOST"); - case FT_LS_PATH: return("LS_PATH"); - case FT_LS_GNAME: return("LS_GNAME"); - case FT_LS_NOTE: return("LS_NOTE"); - case FT_LS_822ADDR: return("LS_822ADDR"); - case FT_LS_FRIENDLY: return("LS_FRIENDLY"); - case FT_LV_HOSTTYPE: return("LV_HOSTTYPE"); - case FT_LV_INGRPF: return("LV_INGRPF"); - case FT_LV_NOHOSTF: return("LV_NOHOSTF"); - case FT_LOCALDATE: return("LOCALDATE"); - case FT_GMTDATE: return("GMTDATE"); - 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"); - case FT_GETMYMBOX: return("GETMYMBOX"); - case FT_GETMYADDR: return("GETMYADDR"); - case FT_SAVESTR: return("SAVESTR"); - case FT_PAUSE: return ("PAUSE"); - case FT_DONE: return("DONE"); - case FT_NOP: return("NOP"); - case FT_GOTO: return("GOTO"); - case FT_IF_S_NULL: return("IF_S_NULL"); - case FT_IF_S: return("IF_S"); - case FT_IF_V_EQ: return("IF_V_EQ"); - case FT_IF_V_NE: return("IF_V_NE"); - case FT_IF_V_GT: return("IF_V_GT"); - case FT_IF_MATCH: return("IF_MATCH"); - case FT_IF_AMATCH: return("IF_AMATCH"); - case FT_S_NULL: return("S_NULL"); - case FT_S_NONNULL: return("S_NONNULL"); - case FT_V_EQ: return("V_EQ"); - case FT_V_NE: return("V_NE"); - case FT_V_GT: return("V_GT"); - case FT_V_MATCH: return("V_MATCH"); - case FT_V_AMATCH: return("V_AMATCH"); + case FT_COMP: return "COMP"; + case FT_COMPF: return "COMPF"; + case FT_LIT: return "LIT"; + case FT_LITF: return "LITF"; + case FT_CHAR: return "CHAR"; + case FT_NUM: return "NUM"; + case FT_NUMF: return "NUMF"; + case FT_STR: return "STR"; + case FT_STRF: return "STRF"; + case FT_STRFW: return "STRFW"; + case FT_STRLIT: return "STRLIT"; + case FT_STRLITZ: return "STRLITZ"; + case FT_PUTADDR: return "PUTADDR"; + case FT_LS_COMP: return "LS_COMP"; + case FT_LS_LIT: return "LS_LIT"; + case FT_LS_GETENV: return "LS_GETENV"; + case FT_LS_CFIND: return "LS_CFIND"; + case FT_LS_DECODECOMP: return "LS_DECODECOMP"; + case FT_LS_DECODE: return "LS_DECODE"; + case FT_LS_TRIM: return "LS_TRIM"; + case FT_LV_COMP: return "LV_COMP"; + case FT_LV_COMPFLAG: return "LV_COMPFLAG"; + case FT_LV_LIT: return "LV_LIT"; + case FT_LV_DAT: return "LV_DAT"; + 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_MONTH: return "LS_MONTH"; + case FT_LS_LMONTH: return "LS_LMONTH"; + case FT_LS_ZONE: return "LS_ZONE"; + case FT_LS_DAY: return "LS_DAY"; + case FT_LS_WEEKDAY: return "LS_WEEKDAY"; + case FT_LS_822DATE: return "LS_822DATE"; + case FT_LS_PRETTY: return "LS_PRETTY"; + case FT_LS_KILO: return "LS_KILO"; + case FT_LS_KIBI: return "LS_KIBI"; + case FT_LV_SEC: return "LV_SEC"; + case FT_LV_MIN: return "LV_MIN"; + case FT_LV_HOUR: return "LV_HOUR"; + case FT_LV_MDAY: return "LV_MDAY"; + case FT_LV_MON: return "LV_MON"; + case FT_LV_YEAR: return "LV_YEAR"; + case FT_LV_YDAY: return "LV_YDAY"; + case FT_LV_WDAY: return "LV_WDAY"; + case FT_LV_ZONE: return "LV_ZONE"; + case FT_LV_CLOCK: return "LV_CLOCK"; + case FT_LV_RCLOCK: return "LV_RCLOCK"; + case FT_LV_DAYF: return "LV_DAYF"; + case FT_LV_DST: return "LV_DST"; + case FT_LV_ZONEF: return "LV_ZONEF"; + case FT_LS_PERS: return "LS_PERS"; + case FT_LS_MBOX: return "LS_MBOX"; + case FT_LS_HOST: return "LS_HOST"; + case FT_LS_PATH: return "LS_PATH"; + case FT_LS_GNAME: return "LS_GNAME"; + case FT_LS_NOTE: return "LS_NOTE"; + case FT_LS_ADDR: return "LS_ADDR"; + case FT_LS_822ADDR: return "LS_822ADDR"; + case FT_LS_FRIENDLY: return "LS_FRIENDLY"; + case FT_LV_HOSTTYPE: return "LV_HOSTTYPE"; + case FT_LV_INGRPF: return "LV_INGRPF"; + case FT_LS_UNQUOTE: return "LS_UNQUOTE"; + case FT_LV_NOHOSTF: return "LV_NOHOSTF"; + case FT_LOCALDATE: return "LOCALDATE"; + case FT_GMTDATE: return "GMTDATE"; + 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"; + case FT_GETMYMBOX: return "GETMYMBOX"; + case FT_GETMYADDR: return "GETMYADDR"; + case FT_SAVESTR: return "SAVESTR"; + case FT_DONE: return "DONE"; + case FT_PAUSE: return "PAUSE"; + case FT_NOP: return "NOP"; + case FT_GOTO: return "GOTO"; + case FT_IF_S_NULL: return "IF_S_NULL"; + case FT_IF_S: return "IF_S"; + case FT_IF_V_EQ: return "IF_V_EQ"; + case FT_IF_V_NE: return "IF_V_NE"; + case FT_IF_V_GT: return "IF_V_GT"; + case FT_IF_MATCH: return "IF_MATCH"; + case FT_IF_AMATCH: return "IF_AMATCH"; + case FT_S_NULL: return "S_NULL"; + case FT_S_NONNULL: return "S_NONNULL"; + case FT_V_EQ: return "V_EQ"; + case FT_V_NE: return "V_NE"; + case FT_V_GT: return "V_GT"; + case FT_V_MATCH: return "V_MATCH"; + case FT_V_AMATCH: return "V_AMATCH"; default: - printf(buf, "/* ??? #%d */", t); - return(buf); + snprintf(buf, sizeof buf, "/* ??? #%d */", t); + return buf; } } @@ -457,13 +460,13 @@ c_typestr(int t) buf[0] = '\0'; if (t & ~(CT_ADDR|CT_DATE)) - printf(buf, "0x%x ", t); + snprintf(buf, sizeof buf, "0x%x ", t); strcat(buf, "<"); i = 0; FNORD(CT_ADDR, "ADDR"); FNORD(CT_DATE, "DATE"); strcat(buf, ">"); - return(buf); + return buf; } static char * @@ -474,7 +477,7 @@ c_flagsstr(int t) buf[0] = '\0'; if (t & ~(CF_TRUE|CF_PARSED|CF_DATEFAB|CF_TRIMMED)) - printf(buf, "0x%x ", t); + snprintf(buf, sizeof buf, "0x%x ", t); strcat(buf, "<"); i = 0; FNORD(CF_TRUE, "TRUE"); @@ -482,7 +485,7 @@ c_flagsstr(int t) FNORD(CF_DATEFAB, "DATEFAB"); FNORD(CF_TRIMMED, "TRIMMED"); strcat(buf, ">"); - return(buf); + return buf; } #undef FNORD