9 date 92.11.04.00.42.31; author jromine; state Exp;
14 date 92.02.13.20.50.54; author jromine; state Exp;
19 date 92.02.09.07.14.20; author jromine; state Exp;
24 date 92.01.24.00.04.45; author jromine; state Exp;
29 date 91.11.27.23.52.39; author jromine; state Exp;
34 date 91.11.27.23.50.51; author jromine; state Exp;
39 date 91.11.27.23.44.22; author jromine; state Exp;
44 date 91.01.25.16.08.27; author mh; state Exp;
49 date 91.01.25.15.38.06; author mh; state Exp;
54 date 91.01.25.15.37.45; author mh; state Exp;
68 @/* fmtdump.c - compile format file and dump out instructions */
70 static char ident[] = "@@(#)$Id: fmtdump.c,v 1.9 1992/02/13 20:50:54 jromine Exp jromine $";
74 #include "../h/formatsbr.h"
75 #include "../h/fmtcompile.h"
76 #include "../h/scansbr.h"
83 static struct swit switches[] = {
97 static struct format *lvec[128];
100 static char *f_typestr(), *c_typestr();
101 static void fmt_dump(), dumpone(), assignlabel(), litputs(), litputc();
102 static int findlabel();
124 setlocale(LC_ALL, "");
126 invo_name = r1bindex (argv[0], '/');
127 if ((cp = m_find (invo_name)) != NULL) {
128 ap = brkstring (cp = getcpy (cp), " ", "\n");
129 ap = copyip (ap, arguments);
133 (void) copyip (argv + 1, ap);
138 while (cp = *argp++) {
140 switch (smatch (++cp, switches)) {
142 ambigsw (cp, switches);
145 adios (NULLCP, "-%s unknown", cp);
147 (void) sprintf (buf, "%s [switches]",
149 help (buf, switches);
153 if (!(form = *argp++) || *form == '-')
154 adios (NULLCP, "missing argument to %s", argp[-2]);
158 if (!(format = *argp++) || *format == '-')
159 adios (NULLCP, "missing argument to %s", argp[-2]);
165 adios (NULLCP, "only one form at a time!");
170 nfs = new_fs (form, format, FORMAT); /* must be before chdir() */
171 ncomps = fmt_compile(nfs, &fmt);
179 register struct format *fmth;
182 register struct format *fmt, *addr;
185 for (fmt = fmth; fmt; ++fmt) {
195 addr = fmt + fmt->f_skip;
196 if (findlabel(addr) < 0)
199 if (fmt->f_type == FT_DONE && fmt->f_value == 0)
204 for (fmt = fmth; fmt; ++fmt) {
206 if (fmt->f_type == FT_DONE && fmt->f_value == 0)
213 register struct format *fmt;
217 if ((i = findlabel(fmt)) >= 0)
221 fputs(f_typestr((int)fmt->f_type), stdout);
223 switch (fmt->f_type) {
230 litputs(fmt->f_comp->c_name);
231 if (fmt->f_comp->c_type)
232 printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
233 if (fmt->f_comp->c_flags)
234 printf(", c_flags %d", fmt->f_comp->c_flags);
262 litputs(fmt->f_comp->c_name);
263 if (fmt->f_comp->c_type)
264 printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
265 if (fmt->f_comp->c_flags)
266 printf(", c_flags %d", fmt->f_comp->c_flags);
284 litputs(fmt->f_comp->c_name);
285 if (fmt->f_comp->c_type)
286 printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
287 if (fmt->f_comp->c_flags)
288 printf(", c_flags %d", fmt->f_comp->c_flags);
292 printf(", width %d, fill '", fmt->f_width);
293 litputc(fmt->f_fill);
295 litputs(fmt->f_comp->c_name);
296 if (fmt->f_comp->c_type)
297 printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
298 if (fmt->f_comp->c_flags)
299 printf(", c_flags %d", fmt->f_comp->c_flags);
304 printf(", width %d, fill '", fmt->f_width);
305 litputc(fmt->f_fill);
314 litputs(fmt->f_text);
318 printf(", width %d, fill '", fmt->f_width);
319 litputc(fmt->f_fill);
321 litputs(fmt->f_text);
327 litputc(fmt->f_char);
336 printf(" continue else goto");
338 i = findlabel(fmt + fmt->f_skip);
345 i = findlabel(fmt + fmt->f_skip);
346 printf(" %d continue else goto L%d", fmt->f_value, i);
357 printf(" value %d", fmt->f_value);
362 litputs(fmt->f_text);
367 litputs(fmt->f_text);
371 printf(", width %d", fmt->f_width);
375 printf(", value dat[%d]", fmt->f_value);
383 register struct format *addr;
387 for (i = 0; i < lused; ++i)
395 register struct format *addr;
397 lvec[lused++] = addr;
407 case FT_COMP: return("COMP");
408 case FT_COMPF: return("COMPF");
409 case FT_LIT: return("LIT");
410 case FT_LITF: return("LITF");
412 case FT_LIT_FORCE: return("LIT_FORCE");
414 case FT_CHAR: return("CHAR");
415 case FT_NUM: return("NUM");
416 case FT_NUMF: return("NUMF");
417 case FT_STR: return("STR");
418 case FT_STRF: return("STRF");
419 case FT_STRFW: return("STRFW");
420 case FT_PUTADDR: return("PUTADDR");
421 case FT_LS_COMP: return("LS_COMP");
422 case FT_LS_LIT: return("LS_LIT");
423 case FT_LS_GETENV: return("LS_GETENV");
424 case FT_LS_TRIM: return("LS_TRIM");
425 case FT_LV_COMP: return("LV_COMP");
426 case FT_LV_COMPFLAG: return("LV_COMPFLAG");
427 case FT_LV_LIT: return("LV_LIT");
428 case FT_LV_DAT: return("LV_DAT");
429 case FT_LV_STRLEN: return("LV_STRLEN");
430 case FT_LV_PLUS_L: return("LV_PLUS_L");
431 case FT_LV_MINUS_L: return("LV_MINUS_L");
432 case FT_LV_DIVIDE_L: return("LV_DIVIDE_L");
433 case FT_LV_MODULO_L: return("LV_MODULO_L");
434 case FT_LV_CHAR_LEFT: return("LV_CHAR_LEFT");
435 case FT_LS_MONTH: return("LS_MONTH");
436 case FT_LS_LMONTH: return("LS_LMONTH");
437 case FT_LS_ZONE: return("LS_ZONE");
438 case FT_LS_DAY: return("LS_DAY");
439 case FT_LS_WEEKDAY: return("LS_WEEKDAY");
440 case FT_LS_822DATE: return("LS_822DATE");
441 case FT_LS_PRETTY: return("LS_PRETTY");
442 case FT_LV_SEC: return("LV_SEC");
443 case FT_LV_MIN: return("LV_MIN");
444 case FT_LV_HOUR: return("LV_HOUR");
445 case FT_LV_MDAY: return("LV_MDAY");
446 case FT_LV_MON: return("LV_MON");
447 case FT_LV_YEAR: return("LV_YEAR");
448 case FT_LV_YDAY: return("LV_YDAY");
449 case FT_LV_WDAY: return("LV_WDAY");
450 case FT_LV_ZONE: return("LV_ZONE");
451 case FT_LV_CLOCK: return("LV_CLOCK");
452 case FT_LV_RCLOCK: return("LV_RCLOCK");
453 case FT_LV_DAYF: return("LV_DAYF");
454 case FT_LV_DST: return("LV_DST");
455 case FT_LV_ZONEF: return("LV_ZONEF");
456 case FT_LS_ADDR: return("LS_ADDR");
457 case FT_LS_PERS: return("LS_PERS");
458 case FT_LS_MBOX: return("LS_MBOX");
459 case FT_LS_HOST: return("LS_HOST");
460 case FT_LS_PATH: return("LS_PATH");
461 case FT_LS_GNAME: return("LS_GNAME");
462 case FT_LS_NOTE: return("LS_NOTE");
463 case FT_LS_822ADDR: return("LS_822ADDR");
464 case FT_LS_FRIENDLY: return("LS_FRIENDLY");
465 case FT_LV_HOSTTYPE: return("LV_HOSTTYPE");
466 case FT_LV_INGRPF: return("LV_INGRPF");
467 case FT_LV_NOHOSTF: return("LV_NOHOSTF");
468 case FT_LOCALDATE: return("LOCALDATE");
469 case FT_GMTDATE: return("GMTDATE");
470 case FT_PARSEDATE: return("PARSEDATE");
471 case FT_PARSEADDR: return("PARSEADDR");
472 case FT_FORMATADDR: return("FORMATADDR");
473 case FT_MYMBOX: return("MYMBOX");
475 case FT_ADDTOSEQ: return("ADDTOSEQ");
477 case FT_SAVESTR: return("SAVESTR");
479 case FT_PAUSE: return ("PAUSE");
481 case FT_DONE: return("DONE");
482 case FT_NOP: return("NOP");
483 case FT_GOTO: return("GOTO");
484 case FT_IF_S_NULL: return("IF_S_NULL");
485 case FT_IF_S: return("IF_S");
486 case FT_IF_V_EQ: return("IF_V_EQ");
487 case FT_IF_V_NE: return("IF_V_NE");
488 case FT_IF_V_GT: return("IF_V_GT");
489 case FT_IF_MATCH: return("IF_MATCH");
490 case FT_IF_AMATCH: return("IF_AMATCH");
491 case FT_S_NULL: return("S_NULL");
492 case FT_S_NONNULL: return("S_NONNULL");
493 case FT_V_EQ: return("V_EQ");
494 case FT_V_NE: return("V_NE");
495 case FT_V_GT: return("V_GT");
496 case FT_V_MATCH: return("V_MATCH");
497 case FT_V_AMATCH: return("V_AMATCH");
499 (void)sprintf(buf, "/* ??? #%d */", t);
504 #define FNORD(v, s) if (t & (v)) { \
517 if (t & ~(CT_ADDR|CT_DATE|CT_MYMBOX|CT_ADDRPARSE))
518 (void)sprintf(buf, "0x%x ", t);
521 FNORD(CT_ADDR, "ADDR");
522 FNORD(CT_DATE, "DATE");
523 FNORD(CT_MYMBOX, "MYMBOX");
524 FNORD(CT_ADDRPARSE, "ADDRPARSE");
540 fputs("<nil>", stdout);
552 if (c < 0x20 || c == 0177) {
556 } else if (c == '\f') {
559 } else if (c == '\n') {
562 } else if (c == '\r') {
565 } else if (c == '\t') {
570 putc(c ^ 0x40, stdout); /* DEL to ?, others to alpha */
585 static char ident[] = "@@(#)$Id: fmtdump.c,v 1.8 1992/02/09 07:14:20 jromine Exp jromine $";
593 @cleanup output slightly
600 static char ident[] = "@@(#)$Id: fmtdump.c,v 1.7 1992/01/24 00:04:45 jromine Exp jromine $";
603 * fmtdump - compile format file and dump out instructions
607 * fmtdump [formatfile]
612 static struct format *lvec[128];
616 char *f_typestr(), *c_typestr();
617 static int findlabel();
628 char *file = "scan.format";
636 /* Read format file into memory */
637 str = new_fs(file, 0, 0);
641 n = fmt_compile(str, &fmt);
650 register struct format *fmth;
671 static char ident[] = "@@(#)$Id: fmtdump.c,v 1.6 1991/11/27 23:52:39 jromine Exp jromine $";
674 printf(" false, goto");
677 printf(" %d goto L%d", fmt->f_value, i);
685 @*** empty log message ***
690 static char ident[] = "@@(#)$Id: fmtdump.c,v 1.5 1991/11/27 23:50:51 jromine Exp jromine $";
693 if (fmt->f_type == FT_DONE)
696 if (fmt->f_type == FT_DONE)
711 static char ident[] = "@@(#)$Id: fmtdump.c,v 1.4 1991/11/27 23:44:22 jromine Exp jromine $";
720 @explain IF_S statements better
725 static char ident[] = "@@(#)$Id: fmtdump.c,v 1.3 91/01/25 16:08:27 mh Exp $";
729 printf(" false goto L%d", i);
740 static char ident[] = "@@(#)$Id: fmtdump.c,v 1.2 91/01/25 15:38:06 mh Exp Locker: mh $";
749 @*** empty log message ***
754 static char ident[] = "@@(#)$Id: fmtdump.c,v 1.1 91/01/25 15:37:45 mh Exp Locker: mh $";
767 static char ident[] = "@@(#)$Id: fmtdump.c,v 1.3 90/08/09 22:04:27 leres Exp $ (LBL)";