X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Ffmtdump.c;h=d75849b53dccb0f5339f3664bfcf2009cc224835;hp=a590a0063529bdff1b52c222a3d06a7d076a48a2;hb=fc9279e818dfc96c63a5d75a89080cc68cfe1170;hpb=38615191e71744b066425e0c44412b62dbe49cc2 diff --git a/uip/fmtdump.c b/uip/fmtdump.c index a590a00..d75849b 100644 --- a/uip/fmtdump.c +++ b/uip/fmtdump.c @@ -1,29 +1,26 @@ - /* - * 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. - */ +** 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 +#include 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 FORMSW 0 + { "form formatfile", 0 }, +#define VERSIONSW 1 + { "Version", 0 }, +#define HELPSW 2 + { "help", 0 }, + { NULL, 0 } }; /* for assignlabel */ @@ -31,9 +28,9 @@ static struct format *lvec[128]; static int lused = 0; /* - * static prototypes - */ -static void fmt_dump (struct format *); +** static prototypes +*/ +static void fmt_dump(struct format *); static void dumpone(struct format *); static int findlabel(struct format *); static void assignlabel(struct format *); @@ -45,88 +42,74 @@ static void litputc(char); int -main (int argc, char **argv) +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(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [switches]", invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case FORMSW: - if (!(form = *argp++) || *form == '-') - adios (NULL, "missing argument to %s", argp[-2]); - format = NULL; - continue; - case FMTSW: - if (!(format = *argp++) || *format == '-') - adios (NULL, "missing argument to %s", argp[-2]); - form = NULL; - continue; - - } + char *cp, *form = NULL; + char buf[BUFSIZ], *fmtstr, **argp, **arguments; + struct format *fmt; + + setlocale(LC_ALL, ""); + invo_name = mhbasename(argv[0]); + + /* read user profile/context */ + context_read(); + + arguments = getarguments(invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch(++cp, switches)) { + case AMBIGSW: + ambigsw(cp, switches); + exit(EX_USAGE); + case UNKWNSW: + adios(EX_USAGE, NULL, "-%s unknown", cp); + + case HELPSW: + snprintf(buf, sizeof(buf), "%s [switches]", + invo_name); + print_help(buf, switches, 1); + exit(argc == 2 ? EX_OK : EX_USAGE); + case VERSIONSW: + print_version(invo_name); + exit(argc == 2 ? EX_OK : EX_USAGE); + + case FORMSW: + if (!(form = *argp++) || *form == '-') + adios(EX_USAGE, NULL, "missing argument to %s", + argp[-2]); + continue; + + } + } + if (form) + adios(EX_USAGE, NULL, "only one form at a time!"); + else + form = cp; } - if (form) - adios (NULL, "only one form at a time!"); - else - form = cp; - } - - /* - * Get new format string. Must be before chdir(). - */ - nfs = new_fs (form, format, FORMAT); - ncomps = fmt_compile(nfs, &fmt); - - fmt_dump(fmt); - done(0); - return 1; + + /* Set format string. Must be before chdir(). */ + fmtstr = new_fs(form, scanformat); + fmt_compile(fmtstr, &fmt); + + fmt_dump(fmt); + return EX_OK; } static void -fmt_dump (struct format *fmth) +fmt_dump(struct format *fmth) { int i; - register struct format *fmt, *addr; + struct format *fmt, *addr; /* Assign labels */ for (fmt = fmth; fmt; ++fmt) { i = fmt->f_type; - if (i == FT_IF_S || - i == FT_IF_S_NULL || - i == FT_IF_V_EQ || - i == FT_IF_V_NE || - i == FT_IF_V_GT || - i == FT_IF_MATCH || - i == FT_IF_AMATCH || - i == FT_GOTO) { + if (i == FT_IF_S || i == FT_IF_S_NULL || i == FT_IF_V_EQ || + i == FT_IF_V_NE || i == FT_IF_V_GT || + i == FT_IF_MATCH || i == FT_IF_AMATCH || + i == FT_GOTO) { addr = fmt + fmt->f_skip; if (findlabel(addr) < 0) assignlabel(addr); @@ -146,7 +129,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); @@ -165,7 +148,8 @@ 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 %s", c_flagsstr(fmt->f_comp->c_flags)); + printf(", c_flags %s", + c_flagsstr(fmt->f_comp->c_flags)); break; case FT_LV_SEC: @@ -197,7 +181,8 @@ 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 %s", c_flagsstr(fmt->f_comp->c_flags)); + printf(", c_flags %s", + c_flagsstr(fmt->f_comp->c_flags)); break; case FT_LS_ADDR: @@ -219,7 +204,8 @@ 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 %s", c_flagsstr(fmt->f_comp->c_flags)); + printf(", c_flags %s", + c_flagsstr(fmt->f_comp->c_flags)); break; case FT_COMPF: @@ -230,7 +216,8 @@ 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 %s", c_flagsstr(fmt->f_comp->c_flags)); + printf(", c_flags %s", + c_flagsstr(fmt->f_comp->c_flags)); break; case FT_STRF: @@ -316,6 +303,9 @@ dumpone(struct format *fmt) case FT_LV_DAT: printf(", value dat[%d]", fmt->f_value); break; + + case FT_LS_UNMAILTO: + break; } putchar('\n'); } @@ -323,7 +313,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]) @@ -347,7 +337,7 @@ f_typestr(int t) case FT_COMPF: return("COMPF"); case FT_LIT: return("LIT"); case FT_LITF: return("LITF"); -#ifdef FT_LIT_FORCE +#ifdef FT_LIT_FORCE case FT_LIT_FORCE: return("LIT_FORCE"); #endif case FT_CHAR: return("CHAR"); @@ -412,11 +402,8 @@ f_typestr(int t) case FT_PARSEADDR: return("PARSEADDR"); case FT_FORMATADDR: return("FORMATADDR"); case FT_MYMBOX: return("MYMBOX"); -#ifdef FT_ADDTOSEQ - case FT_ADDTOSEQ: return("ADDTOSEQ"); -#endif case FT_SAVESTR: return("SAVESTR"); -#ifdef FT_PAUSE +#ifdef FT_PAUSE case FT_PAUSE: return ("PAUSE"); #endif case FT_DONE: return("DONE"); @@ -436,6 +423,7 @@ f_typestr(int t) case FT_V_GT: return("V_GT"); case FT_V_MATCH: return("V_MATCH"); case FT_V_AMATCH: return("V_AMATCH"); + case FT_LS_UNMAILTO: return("LS_UNMAILTO"); default: printf(buf, "/* ??? #%d */", t); return(buf); @@ -443,14 +431,14 @@ f_typestr(int t) } #define FNORD(v, s) if (t & (v)) { \ - if (i++ > 0) \ - strcat(buf, "|"); \ - strcat(buf, s); } + if (i++ > 0) \ + strcat(buf, "|"); \ + strcat(buf, s); } static char * c_typestr(int t) { - register int i; + int i; static char buf[64]; buf[0] = '\0'; @@ -467,7 +455,7 @@ c_typestr(int t) static char * c_flagsstr(int t) { - register int i; + int i; static char buf[64]; buf[0] = '\0'; @@ -521,7 +509,8 @@ litputc(char c) putc('t', stdout); } else { putc('^', stdout); - putc(c ^ 0x40, stdout); /* DEL to ?, others to alpha */ + putc(c ^ 0x40, stdout); + /* DEL to ?, others to alpha */ } } else putc(c, stdout);