00001 00023 #include <stdio.h> 00024 00025 #define BACKSLASH '\\' 00026 #define bufsize 200 /* size of internal buffers */ 00027 #define inp_bufs 600 /* size of input buffer */ 00028 #define sc_size 5000 /* size of save_com buffer */ 00029 #define label_offset 2 /* number of levels a label is 00030 placed to left of code */ 00031 00032 #define tabsize 8 /* the size of a tab */ 00033 #define tabmask 0177770 /* mask used when figuring 00034 length of lines with tabs */ 00035 00036 00037 #define false 0 00038 #define true !false 00039 00040 00041 PUBLIC FILE *input; /* the fid for the input file */ 00042 PUBLIC FILE *output; /* the output file */ 00043 00044 PUBLIC char *labbuf; /* buffer for label */ 00045 PUBLIC char *s_lab; /* start ... */ 00046 PUBLIC char *e_lab; /* .. and end of stored label */ 00047 PUBLIC char *l_lab; /* limit of label buffer */ 00048 00049 PUBLIC char *codebuf; /* buffer for code section */ 00050 PUBLIC char *s_code; /* start ... */ 00051 PUBLIC char *e_code; /* .. and end of stored code */ 00052 PUBLIC char *l_code; /* limit of code section */ 00053 00054 PUBLIC char *combuf; /* buffer for comments */ 00055 PUBLIC char *s_com; /* start ... */ 00056 PUBLIC char *e_com; /* ... and end of stored 00057 comments */ 00058 PUBLIC char *l_com; /* limit of comment buffer */ 00059 00060 PUBLIC char in_buffer[inp_bufs]; /* input buffer */ 00061 PUBLIC char *buf_ptr; /* ptr to next character to be 00062 taken from in_buffer */ 00063 PUBLIC char *buf_end; /* ptr to first after last char 00064 in in_buffer */ 00065 00066 PUBLIC char save_com[sc_size]; /* input text is saved here 00067 when looking for the brace 00068 after an if, while, etc */ 00069 PUBLIC char *sc_end; /* pointer into save_com buffer */ 00070 00071 PUBLIC char *bp_save; /* saved value of buf_ptr when 00072 taking input from save_com */ 00073 PUBLIC char *be_save; /* similarly saved value of 00074 buf_end */ 00075 00076 PUBLIC char token[bufsize]; /* the last token scanned */ 00077 00078 00079 PUBLIC int ptr_binop; /* pointer as binop */ 00080 PUBLIC int bl_aft_decl; /* blanklines after 00081 declarations */ 00082 PUBLIC int bl_bef_bk; /* blanklines before 00083 blockcomments */ 00084 PUBLIC int bl_a_procs; /* blanklines after procs */ 00085 PUBLIC int bl_around; /* blanklines around 00086 conditional compilation */ 00087 PUBLIC int swallow_opt_bl; /* swallow optional blanklines */ 00088 PUBLIC int n_real_blanklines; 00089 PUBLIC int prefix_blankline_requested; 00090 PUBLIC int postfix_blankline_requested; 00091 PUBLIC int break_comma; /* when true and not in parens, 00092 break after a comma */ 00093 PUBLIC int btype_2; /* when true, brace should be 00094 on same line as if, while, 00095 etc */ 00096 PUBLIC long case_ind; /* indentation level to be used 00097 for a "case n:" */ 00098 PUBLIC int code_lines; /* count of lines with code */ 00099 PUBLIC int had_eof; /* set to true when input is 00100 exhausted */ 00101 PUBLIC int line_no; /* the current line number. */ 00102 PUBLIC int max_col; /* the maximum allowable line 00103 length */ 00104 PUBLIC int verbose; /* when true, non-essential 00105 error messages are printed */ 00106 PUBLIC int cuddle_else; /* true if else should cuddle 00107 up to '}' */ 00108 PUBLIC int star_comment_cont; /* true iff comment 00109 continuation lines should 00110 have stars at the beginning 00111 of each line. */ 00112 PUBLIC int del_on_bl; /* comment_delimiter_on_blanklin 00113 e */ 00114 PUBLIC int troff; /* true iff were generating 00115 troff input */ 00116 PUBLIC int proc_str_line; /* if true, the names of 00117 procedures being defined get 00118 placed in column 1 (ie. a 00119 newline is placed between 00120 the type of the procedure 00121 and its name) */ 00122 PUBLIC int proc_calls_space; /* If true, procedure calls 00123 look like: foo(bar) rather 00124 than foo (bar) */ 00125 PUBLIC int format_col1_comments; /* If comments which start in 00126 column 1 are to be magically 00127 reformatted (just like 00128 comments that begin in later 00129 columns) */ 00130 PUBLIC int inhibit_formatting; /* true if INDENT OFF is in 00131 effect */ 00132 PUBLIC int suppress_blanklines; /* set iff following blanklines 00133 should be suppressed */ 00134 PUBLIC int continuation_indent; /* set to the indentation 00135 between the edge of code and 00136 continuation lines */ 00137 PUBLIC int lineup_to_parens; /* if true, continued code 00138 within parens will be lined 00139 up to the open paren */ 00140 PUBLIC int Bill_Shannon; /* true iff a blank should 00141 always be inserted after 00142 sizeof */ 00143 PUBLIC int bl_at_proctop; /* This is vaguely similar to 00144 blanklines_after_declarations 00145 except that it only applies 00146 to the first set of 00147 declarations in a procedure 00148 (just after the first '{') 00149 and it causes a blank line 00150 to be generated even if 00151 there are no declarations */ 00152 PUBLIC int bk_max_col; 00153 PUBLIC int ex_expr_indent; /* True if continuation lines 00154 from the expression part of 00155 "if(e)", "while(e)", 00156 "for(e;e;e)" should be 00157 indented an extra tab stop 00158 so that they don't conflict 00159 with the code that follows */ 00160 00161 /* -troff font state information */ 00162 00163 struct fstate 00164 { 00165 char font[4]; 00166 char size; 00167 int allcaps; 00168 }; 00169 00170 PUBLIC struct fstate 00171 keywordf, /* keyword font */ 00172 stringf, /* string font */ 00173 boxcomf, /* Box comment font */ 00174 blkcomf, /* Block comment font */ 00175 scomf, /* Same line comment font */ 00176 bodyf; /* major body font */ 00177 00178 00179 #define STACKSIZE 150 00180 00181 PUBLIC struct parser_state 00182 { 00183 int last_token; 00184 struct fstate cfont; /* Current font */ 00185 int p_stack[STACKSIZE]; /* this is the parsers stack */ 00186 int il[STACKSIZE]; /* this stack stores 00187 indentation levels */ 00188 long cstk[STACKSIZE]; /* used to store case stmt 00189 indentation levels */ 00190 int box_com; /* set to true when we are in a 00191 "boxed" comment. In that 00192 case, the first non-blank 00193 char should be lined up with 00194 the / in / * */ 00195 int comment_delta, n_comment_delta; 00196 int cast_mask; /* indicates which close parens 00197 close off casts */ 00198 int sizeof_mask; /* indicates which close parens 00199 close off sizeof''s */ 00200 int block_init; /* true iff inside a block 00201 initialization */ 00202 int block_init_level; /* The level of brace nesting 00203 in an initialization */ 00204 int last_nl; /* this is true if the last 00205 thing scanned was a newline */ 00206 int in_or_st; /* Will be true iff there has 00207 been a declarator (e.g. int 00208 or char) and no left paren 00209 since the last semicolon. 00210 When true, a '{' is starting 00211 a structure definition or an 00212 initialization list */ 00213 int bl_line; /* set to 1 by dump_line if the 00214 line is blank */ 00215 int col_1; /* set to true if the last 00216 token started in column 1 */ 00217 int com_col; /* this is the column in which 00218 the current coment should 00219 start */ 00220 int com_ind; /* the column in which comments 00221 to the right of code should 00222 start */ 00223 int com_lines; /* the number of lines with 00224 comments, set by dump_line */ 00225 int dec_nest; /* current nesting level for 00226 structure or init */ 00227 int decl_com_ind; /* the column in which comments 00228 after declarations should be 00229 put */ 00230 int decl_on_line; /* set to true if this line of 00231 code has part of a 00232 declaration on it */ 00233 int i_l_follow; /* the level to which ind_level 00234 should be set after the 00235 current line is printed */ 00236 int in_decl; /* set to true when we are in a 00237 declaration stmt. The 00238 processing of braces is then 00239 slightly different */ 00240 int in_stmt; /* set to 1 while in a stmt */ 00241 int ind_level; /* the current indentation 00242 level */ 00243 int ind_size; /* the size of one indentation 00244 level */ 00245 int ind_stmt; /* set to 1 if next line should 00246 have an extra indentation 00247 level because we are in the 00248 middle of a stmt */ 00249 int last_u_d; /* set to true after scanning a 00250 token which forces a 00251 following operator to be 00252 unary */ 00253 int leave_comma; /* if true, never break 00254 declarations after commas */ 00255 int ljust_decl; /* true if declarations should 00256 be left justified */ 00257 int out_coms; /* the number of comments 00258 processed, set by pr_comment */ 00259 int out_lines; /* the number of lines written, 00260 set by dump_line */ 00261 int p_l_follow; /* used to remember how to 00262 indent following statement */ 00263 int paren_level; /* parenthesization level. used 00264 to indent within stmts */ 00265 short paren_indents[20]; /* column positions of each 00266 paren */ 00267 int pcase; /* set to 1 if the current line 00268 label is a case. It is 00269 printed differently from a 00270 regular label */ 00271 int search_brace; /* set to true by parse when it 00272 is necessary to buffer up 00273 all info up to the start of 00274 a stmt after an if, while, 00275 etc */ 00276 int unindent_displace; /* comments not to the right of 00277 code will be placed this 00278 many indentation levels to 00279 the left of code */ 00280 int use_ff; /* set to one if the current 00281 line should be terminated 00282 with a form feed */ 00283 int want_blank; /* set to true when the 00284 following token should be 00285 prefixed by a blank. (Said 00286 prefixing is ignored in some 00287 cases.) */ 00288 int else_if; /* True iff else if pairs 00289 should be handled specially */ 00290 int decl_indent; /* column to indent declared 00291 identifiers to */ 00292 int its_a_keyword; 00293 int sizeof_keyword; 00294 int dumped_decl_indent; 00295 int case_indent; /* The distance to indent case 00296 labels from the switch 00297 statement */ 00298 int in_par_decl; 00299 int indent_parameters; 00300 int tos; /* pointer to top of stack */ 00301 char procname[100]; /* The name of the current 00302 procedure */ 00303 int just_saw_decl; 00304 } ps; 00305 00306 PUBLIC int ifdef_level; 00307 PUBLIC struct parser_state state_stack[5]; 00308 PUBLIC struct parser_state match_state[5];
1.5.8