Commit | Line | Data |
---|---|---|
f1525c23 WH |
1 | /* nice_printf -- same arguments as fprintf. |
2 | ||
3 | All output which is to become C code must be directed through this | |
4 | function. For now, no buffering is done. Later on, every line of | |
5 | output will be filtered to accomodate the style definitions (e.g. one | |
6 | statement per line, spaces between function names and argument lists, | |
7 | etc.) | |
8 | */ | |
9 | #include "niceprintf.h" | |
10 | ||
11 | extern int nice_printf (); | |
12 | ||
13 | ||
14 | /* Definitions for the opcode table. The table is indexed by the macros | |
15 | which are #defined in defines.h */ | |
16 | ||
17 | #define UNARY_OP 01 | |
18 | #define BINARY_OP 02 | |
19 | ||
20 | #define SPECIAL_FMT NULL | |
21 | ||
22 | #define is_unary_op(x) (opcode_table[x].type == UNARY_OP) | |
23 | #define is_binary_op(x) (opcode_table[x].type == BINARY_OP) | |
24 | #define op_precedence(x) (opcode_table[x].prec) | |
25 | #define op_format(x) (opcode_table[x].format) | |
26 | ||
27 | /* _assoc_table -- encodes left-associativity and right-associativity | |
28 | information; indexed by precedence level. Only 2, 3, 14 are | |
29 | right-associative. Source: Kernighan & Ritchie, p. 49 */ | |
30 | ||
31 | extern char _assoc_table[]; | |
32 | ||
33 | #define is_right_assoc(x) (_assoc_table [x]) | |
34 | #define is_left_assoc(x) (! _assoc_table [x]) | |
35 | ||
36 | ||
37 | typedef struct { | |
38 | int type; /* UNARY_OP or BINARY_OP */ | |
39 | int prec; /* Precedence level, useful for adjusting | |
40 | number of parens to insert. Zero is a | |
41 | special level, and 2, 3, 14 are | |
42 | right-associative */ | |
43 | char *format; | |
44 | } table_entry; | |
45 | ||
46 | ||
47 | extern char *fl_fmt_string; /* Float constant format string */ | |
48 | extern char *db_fmt_string; /* Double constant format string */ | |
49 | extern char *cm_fmt_string; /* Complex constant format string */ | |
50 | extern char *dcm_fmt_string; /* Double Complex constant format string */ | |
51 | ||
52 | extern int indent; /* Number of spaces to indent; this is a | |
53 | temporary fix */ | |
54 | extern int tab_size; /* Number of spaces in each tab */ | |
55 | extern int in_string; | |
56 | ||
57 | extern table_entry opcode_table[]; | |
58 | ||
59 | ||
60 | void expr_out (), out_init (), out_addr (), out_const (); | |
61 | void out_name (), extern_out (), out_asgoto (); | |
62 | void out_if (), out_else (), elif_out (); | |
63 | void endif_out (), end_else_out (); | |
64 | void compgoto_out (), out_for (); | |
65 | void out_end_for (), out_and_free_statement (); |