]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/uip/fmtdump.c
1 /* fmtdump.c - compile format file and dump out instructions */
3 static char ident
[] = "@(#)$Id: fmtdump.c,v 1.10 1992/11/04 00:42:31 jromine Exp $";
7 #include "../h/formatsbr.h"
8 #include "../h/fmtcompile.h"
9 #include "../h/scansbr.h"
16 static struct swit switches
[] = {
30 static struct format
*lvec
[128];
33 static char *f_typestr(), *c_typestr();
34 static void fmt_dump(), dumpone(), assignlabel(), litputs(), litputc();
35 static int findlabel();
57 setlocale(LC_ALL
, "");
59 invo_name
= r1bindex (argv
[0], '/');
60 if ((cp
= m_find (invo_name
)) != NULL
) {
61 ap
= brkstring (cp
= getcpy (cp
), " ", "\n");
62 ap
= copyip (ap
, arguments
);
66 (void) copyip (argv
+ 1, ap
);
71 while (cp
= *argp
++) {
73 switch (smatch (++cp
, switches
)) {
75 ambigsw (cp
, switches
);
78 adios (NULLCP
, "-%s unknown", cp
);
80 (void) sprintf (buf
, "%s [switches]",
86 if (!(form
= *argp
++) || *form
== '-')
87 adios (NULLCP
, "missing argument to %s", argp
[-2]);
91 if (!(format
= *argp
++) || *format
== '-')
92 adios (NULLCP
, "missing argument to %s", argp
[-2]);
98 adios (NULLCP
, "only one form at a time!");
103 nfs
= new_fs (form
, format
, FORMAT
); /* must be before chdir() */
104 ncomps
= fmt_compile(nfs
, &fmt
);
112 register struct format
*fmth
;
115 register struct format
*fmt
, *addr
;
118 for (fmt
= fmth
; fmt
; ++fmt
) {
128 addr
= fmt
+ fmt
->f_skip
;
129 if (findlabel(addr
) < 0)
132 if (fmt
->f_type
== FT_DONE
&& fmt
->f_value
== 0)
137 for (fmt
= fmth
; fmt
; ++fmt
) {
139 if (fmt
->f_type
== FT_DONE
&& fmt
->f_value
== 0)
146 register struct format
*fmt
;
150 if ((i
= findlabel(fmt
)) >= 0)
154 fputs(f_typestr((int)fmt
->f_type
), stdout
);
156 switch (fmt
->f_type
) {
163 litputs(fmt
->f_comp
->c_name
);
164 if (fmt
->f_comp
->c_type
)
165 printf(", c_type %s", c_typestr(fmt
->f_comp
->c_type
));
166 if (fmt
->f_comp
->c_flags
)
167 printf(", c_flags %d", fmt
->f_comp
->c_flags
);
195 litputs(fmt
->f_comp
->c_name
);
196 if (fmt
->f_comp
->c_type
)
197 printf(", c_type %s", c_typestr(fmt
->f_comp
->c_type
));
198 if (fmt
->f_comp
->c_flags
)
199 printf(", c_flags %d", fmt
->f_comp
->c_flags
);
217 litputs(fmt
->f_comp
->c_name
);
218 if (fmt
->f_comp
->c_type
)
219 printf(", c_type %s", c_typestr(fmt
->f_comp
->c_type
));
220 if (fmt
->f_comp
->c_flags
)
221 printf(", c_flags %d", fmt
->f_comp
->c_flags
);
225 printf(", width %d, fill '", fmt
->f_width
);
226 litputc(fmt
->f_fill
);
228 litputs(fmt
->f_comp
->c_name
);
229 if (fmt
->f_comp
->c_type
)
230 printf(", c_type %s", c_typestr(fmt
->f_comp
->c_type
));
231 if (fmt
->f_comp
->c_flags
)
232 printf(", c_flags %d", fmt
->f_comp
->c_flags
);
237 printf(", width %d, fill '", fmt
->f_width
);
238 litputc(fmt
->f_fill
);
247 litputs(fmt
->f_text
);
251 printf(", width %d, fill '", fmt
->f_width
);
252 litputc(fmt
->f_fill
);
254 litputs(fmt
->f_text
);
260 litputc(fmt
->f_char
);
269 printf(" continue else goto");
271 i
= findlabel(fmt
+ fmt
->f_skip
);
278 i
= findlabel(fmt
+ fmt
->f_skip
);
279 printf(" %d continue else goto L%d", fmt
->f_value
, i
);
290 printf(" value %d", fmt
->f_value
);
295 litputs(fmt
->f_text
);
300 litputs(fmt
->f_text
);
304 printf(", width %d", fmt
->f_width
);
308 printf(", value dat[%d]", fmt
->f_value
);
316 register struct format
*addr
;
320 for (i
= 0; i
< lused
; ++i
)
328 register struct format
*addr
;
330 lvec
[lused
++] = addr
;
340 case FT_COMP
: return("COMP");
341 case FT_COMPF
: return("COMPF");
342 case FT_LIT
: return("LIT");
343 case FT_LITF
: return("LITF");
345 case FT_LIT_FORCE
: return("LIT_FORCE");
347 case FT_CHAR
: return("CHAR");
348 case FT_NUM
: return("NUM");
349 case FT_NUMF
: return("NUMF");
350 case FT_STR
: return("STR");
351 case FT_STRF
: return("STRF");
352 case FT_STRFW
: return("STRFW");
353 case FT_PUTADDR
: return("PUTADDR");
354 case FT_LS_COMP
: return("LS_COMP");
355 case FT_LS_LIT
: return("LS_LIT");
356 case FT_LS_GETENV
: return("LS_GETENV");
357 case FT_LS_TRIM
: return("LS_TRIM");
358 case FT_LV_COMP
: return("LV_COMP");
359 case FT_LV_COMPFLAG
: return("LV_COMPFLAG");
360 case FT_LV_LIT
: return("LV_LIT");
361 case FT_LV_DAT
: return("LV_DAT");
362 case FT_LV_STRLEN
: return("LV_STRLEN");
363 case FT_LV_PLUS_L
: return("LV_PLUS_L");
364 case FT_LV_MINUS_L
: return("LV_MINUS_L");
365 case FT_LV_DIVIDE_L
: return("LV_DIVIDE_L");
366 case FT_LV_MODULO_L
: return("LV_MODULO_L");
367 case FT_LV_CHAR_LEFT
: return("LV_CHAR_LEFT");
368 case FT_LS_MONTH
: return("LS_MONTH");
369 case FT_LS_LMONTH
: return("LS_LMONTH");
370 case FT_LS_ZONE
: return("LS_ZONE");
371 case FT_LS_DAY
: return("LS_DAY");
372 case FT_LS_WEEKDAY
: return("LS_WEEKDAY");
373 case FT_LS_822DATE
: return("LS_822DATE");
374 case FT_LS_PRETTY
: return("LS_PRETTY");
375 case FT_LV_SEC
: return("LV_SEC");
376 case FT_LV_MIN
: return("LV_MIN");
377 case FT_LV_HOUR
: return("LV_HOUR");
378 case FT_LV_MDAY
: return("LV_MDAY");
379 case FT_LV_MON
: return("LV_MON");
380 case FT_LV_YEAR
: return("LV_YEAR");
381 case FT_LV_YDAY
: return("LV_YDAY");
382 case FT_LV_WDAY
: return("LV_WDAY");
383 case FT_LV_ZONE
: return("LV_ZONE");
384 case FT_LV_CLOCK
: return("LV_CLOCK");
385 case FT_LV_RCLOCK
: return("LV_RCLOCK");
386 case FT_LV_DAYF
: return("LV_DAYF");
387 case FT_LV_DST
: return("LV_DST");
388 case FT_LV_ZONEF
: return("LV_ZONEF");
389 case FT_LS_ADDR
: return("LS_ADDR");
390 case FT_LS_PERS
: return("LS_PERS");
391 case FT_LS_MBOX
: return("LS_MBOX");
392 case FT_LS_HOST
: return("LS_HOST");
393 case FT_LS_PATH
: return("LS_PATH");
394 case FT_LS_GNAME
: return("LS_GNAME");
395 case FT_LS_NOTE
: return("LS_NOTE");
396 case FT_LS_822ADDR
: return("LS_822ADDR");
397 case FT_LS_FRIENDLY
: return("LS_FRIENDLY");
398 case FT_LV_HOSTTYPE
: return("LV_HOSTTYPE");
399 case FT_LV_INGRPF
: return("LV_INGRPF");
400 case FT_LV_NOHOSTF
: return("LV_NOHOSTF");
401 case FT_LOCALDATE
: return("LOCALDATE");
402 case FT_GMTDATE
: return("GMTDATE");
403 case FT_PARSEDATE
: return("PARSEDATE");
404 case FT_PARSEADDR
: return("PARSEADDR");
405 case FT_FORMATADDR
: return("FORMATADDR");
406 case FT_MYMBOX
: return("MYMBOX");
408 case FT_ADDTOSEQ
: return("ADDTOSEQ");
410 case FT_SAVESTR
: return("SAVESTR");
412 case FT_PAUSE
: return ("PAUSE");
414 case FT_DONE
: return("DONE");
415 case FT_NOP
: return("NOP");
416 case FT_GOTO
: return("GOTO");
417 case FT_IF_S_NULL
: return("IF_S_NULL");
418 case FT_IF_S
: return("IF_S");
419 case FT_IF_V_EQ
: return("IF_V_EQ");
420 case FT_IF_V_NE
: return("IF_V_NE");
421 case FT_IF_V_GT
: return("IF_V_GT");
422 case FT_IF_MATCH
: return("IF_MATCH");
423 case FT_IF_AMATCH
: return("IF_AMATCH");
424 case FT_S_NULL
: return("S_NULL");
425 case FT_S_NONNULL
: return("S_NONNULL");
426 case FT_V_EQ
: return("V_EQ");
427 case FT_V_NE
: return("V_NE");
428 case FT_V_GT
: return("V_GT");
429 case FT_V_MATCH
: return("V_MATCH");
430 case FT_V_AMATCH
: return("V_AMATCH");
432 (void)sprintf(buf
, "/* ??? #%d */", t
);
437 #define FNORD(v, s) if (t & (v)) { \
450 if (t
& ~(CT_ADDR
|CT_DATE
|CT_MYMBOX
|CT_ADDRPARSE
))
451 (void)sprintf(buf
, "0x%x ", t
);
454 FNORD(CT_ADDR
, "ADDR");
455 FNORD(CT_DATE
, "DATE");
456 FNORD(CT_MYMBOX
, "MYMBOX");
457 FNORD(CT_ADDRPARSE
, "ADDRPARSE");
473 fputs("<nil>", stdout
);
485 if (c
< 0x20 || c
== 0177) {
489 } else if (c
== '\f') {
492 } else if (c
== '\n') {
495 } else if (c
== '\r') {
498 } else if (c
== '\t') {
503 putc(c
^ 0x40, stdout
); /* DEL to ?, others to alpha */