-
/*
- * fmtdump.c -- compile format file and dump out instructions
- *
- * $Id$
- */
+** 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 <h/mh.h>
#include <h/fmt_scan.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 FORMSW 0
+ { "form formatfile", 0 },
+#define VERSIONSW 1
+ { "Version", 0 },
+#define HELPSW 2
+ { "help", 0 },
+ { NULL, 0 }
};
/* for assignlabel */
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 *);
static char *f_typestr(int);
static char *c_typestr(int);
+static char *c_flagsstr(int);
static void litputs(char *);
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;
+ char *cp, *form = NULL;
+ char buf[BUFSIZ], *fmtstr, **argp, **arguments;
+ struct format *fmt;
#ifdef LOCALE
- setlocale(LC_ALL, "");
+ 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;
-
- }
+ 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);
+ 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]);
+ continue;
+
+ }
+ }
+ if (form)
+ adios(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);
- return done(0);
+
+ /*
+ ** Get new format string. Must be before chdir().
+ */
+ fmtstr = new_fs(form, FORMAT);
+ fmt_compile(fmtstr, &fmt);
+
+ fmt_dump(fmt);
+ done(0);
+ return 1;
}
static void
-fmt_dump (struct format *fmth)
+fmt_dump(struct format *fmth)
{
int i;
register 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);
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:
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:
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:
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:
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");
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");
}
#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)
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)
+{
+ register int i;
+ static char buf[64];
+
+ buf[0] = '\0';
+ if (t & ~(CF_TRUE|CF_PARSED|CF_DATEFAB))
+ printf(buf, "0x%x ", t);
+ strcat(buf, "<");
+ i = 0;
+ FNORD(CF_TRUE, "TRUE");
+ FNORD(CF_PARSED, "PARSED");
+ FNORD(CF_DATEFAB, "DATEFAB");
+ strcat(buf, ">");
+ return(buf);
+}
+#undef FNORD
+
static void
litputs(char *s)
{
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);