|
|
1.1 root 1: /*
2: * Copyright (c) 1985 Sun Microsystems, Inc.
3: * Copyright (c) 1980 The Regents of the University of California.
4: * Copyright (c) 1976 Board of Trustees of the University of Illinois.
5: * All rights reserved.
6: *
7: * Redistribution and use in source and binary forms are permitted
8: * provided that: (1) source distributions retain this entire copyright
9: * notice and comment, and (2) distributions including binaries display
10: * the following acknowledgement: ``This product includes software
11: * developed by the University of California, Berkeley and its contributors''
12: * in the documentation or other materials provided with the distribution
13: * and in all advertising materials mentioning features or use of this
14: * software. Neither the name of the University nor the names of its
15: * contributors may be used to endorse or promote products derived
16: * from this software without specific prior written permission.
17: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
18: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
19: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20: *
21: * @(#)indent_globs.h 5.10 (Berkeley) 6/1/90
22: */
23:
24: #include <stdio.h>
25:
26: #define BACKSLASH '\\'
27: #define bufsize 200 /* size of internal buffers */
28: #define sc_size 5000 /* size of save_com buffer */
29: #define label_offset 2 /* number of levels a label is placed to left
30: * of code */
31:
32: #define tabsize 8 /* the size of a tab */
33: #define tabmask 0177770 /* mask used when figuring length of lines
34: * with tabs */
35:
36:
37: #define false 0
38: #define true 1
39:
40:
41: FILE *input; /* the fid for the input file */
42: FILE *output; /* the output file */
43:
44: #define CHECK_SIZE_CODE \
45: if (e_code >= l_code) { \
46: register nsize = l_code-s_code+400; \
47: codebuf = (char *) realloc(codebuf, nsize); \
48: e_code = codebuf + (e_code-s_code) + 1; \
49: l_code = codebuf + nsize - 5; \
50: s_code = codebuf + 1; \
51: }
52: #define CHECK_SIZE_COM \
53: if (e_com >= l_com) { \
54: register nsize = l_com-s_com+400; \
55: combuf = (char *) realloc(combuf, nsize); \
56: e_com = combuf + (e_com-s_com) + 1; \
57: l_com = combuf + nsize - 5; \
58: s_com = combuf + 1; \
59: }
60: #define CHECK_SIZE_LAB \
61: if (e_lab >= l_lab) { \
62: register nsize = l_lab-s_lab+400; \
63: labbuf = (char *) realloc(labbuf, nsize); \
64: e_lab = labbuf + (e_lab-s_lab) + 1; \
65: l_lab = labbuf + nsize - 5; \
66: s_lab = labbuf + 1; \
67: }
68: #define CHECK_SIZE_TOKEN \
69: if (e_token >= l_token) { \
70: register nsize = l_token-s_token+400; \
71: tokenbuf = (char *) realloc(tokenbuf, nsize); \
72: e_token = tokenbuf + (e_token-s_token) + 1; \
73: l_token = tokenbuf + nsize - 5; \
74: s_token = tokenbuf + 1; \
75: }
76:
77: char *labbuf; /* buffer for label */
78: char *s_lab; /* start ... */
79: char *e_lab; /* .. and end of stored label */
80: char *l_lab; /* limit of label buffer */
81:
82: char *codebuf; /* buffer for code section */
83: char *s_code; /* start ... */
84: char *e_code; /* .. and end of stored code */
85: char *l_code; /* limit of code section */
86:
87: char *combuf; /* buffer for comments */
88: char *s_com; /* start ... */
89: char *e_com; /* ... and end of stored comments */
90: char *l_com; /* limit of comment buffer */
91:
92: #define token s_token
93: char *tokenbuf; /* the last token scanned */
94: char *s_token;
95: char *e_token;
96: char *l_token;
97:
98: char *in_buffer; /* input buffer */
99: char *in_buffer_limit; /* the end of the input buffer */
100: char *buf_ptr; /* ptr to next character to be taken from
101: * in_buffer */
102: char *buf_end; /* ptr to first after last char in in_buffer */
103:
104: char save_com[sc_size]; /* input text is saved here when looking for
105: * the brace after an if, while, etc */
106: char *sc_end; /* pointer into save_com buffer */
107:
108: char *bp_save; /* saved value of buf_ptr when taking input
109: * from save_com */
110: char *be_save; /* similarly saved value of buf_end */
111:
112:
113: int pointer_as_binop;
114: int blanklines_after_declarations;
115: int blanklines_before_blockcomments;
116: int blanklines_after_procs;
117: int blanklines_around_conditional_compilation;
118: int swallow_optional_blanklines;
119: int n_real_blanklines;
120: int prefix_blankline_requested;
121: int postfix_blankline_requested;
122: int break_comma; /* when true and not in parens, break after a
123: * comma */
124: int btype_2; /* when true, brace should be on same line as
125: * if, while, etc */
126: float case_ind; /* indentation level to be used for a "case
127: * n:" */
128: int code_lines; /* count of lines with code */
129: int had_eof; /* set to true when input is exhausted */
130: int line_no; /* the current line number. */
131: int max_col; /* the maximum allowable line length */
132: int verbose; /* when true, non-essential error messages are
133: * printed */
134: int cuddle_else; /* true if else should cuddle up to '}' */
135: int star_comment_cont; /* true iff comment continuation lines should
136: * have stars at the beginning of each line. */
137: int comment_delimiter_on_blankline;
138: int troff; /* true iff were generating troff input */
139: int procnames_start_line; /* if true, the names of procedures
140: * being defined get placed in column
141: * 1 (ie. a newline is placed between
142: * the type of the procedure and its
143: * name) */
144: int proc_calls_space; /* If true, procedure calls look like:
145: * foo(bar) rather than foo (bar) */
146: int format_col1_comments; /* If comments which start in column 1
147: * are to be magically reformatted
148: * (just like comments that begin in
149: * later columns) */
150: int inhibit_formatting; /* true if INDENT OFF is in effect */
151: int suppress_blanklines;/* set iff following blanklines should be
152: * suppressed */
153: int continuation_indent;/* set to the indentation between the edge of
154: * code and continuation lines */
155: int lineup_to_parens; /* if true, continued code within parens will
156: * be lined up to the open paren */
157: int Bill_Shannon; /* true iff a blank should always be inserted
158: * after sizeof */
159: int blanklines_after_declarations_at_proctop; /* This is vaguely
160: * similar to
161: * blanklines_after_decla
162: * rations except that
163: * it only applies to
164: * the first set of
165: * declarations in a
166: * procedure (just after
167: * the first '{') and it
168: * causes a blank line
169: * to be generated even
170: * if there are no
171: * declarations */
172: int block_comment_max_col;
173: int extra_expression_indent; /* True if continuation lines from the
174: * expression part of "if(e)",
175: * "while(e)", "for(e;e;e)" should be
176: * indented an extra tab stop so that
177: * they don't conflict with the code
178: * that follows */
179:
180: /* -troff font state information */
181:
182: struct fstate {
183: char font[4];
184: char size;
185: int allcaps:1;
186: };
187: char *chfont();
188:
189: struct fstate
190: keywordf, /* keyword font */
191: stringf, /* string font */
192: boxcomf, /* Box comment font */
193: blkcomf, /* Block comment font */
194: scomf, /* Same line comment font */
195: bodyf; /* major body font */
196:
197:
198: #define STACKSIZE 150
199:
200: struct parser_state {
201: int last_token;
202: struct fstate cfont; /* Current font */
203: int p_stack[STACKSIZE]; /* this is the parsers stack */
204: int il[STACKSIZE]; /* this stack stores indentation levels */
205: float cstk[STACKSIZE];/* used to store case stmt indentation levels */
206: int box_com; /* set to true when we are in a "boxed"
207: * comment. In that case, the first non-blank
208: * char should be lined up with the / in /* */
209: int comment_delta,
210: n_comment_delta;
211: int cast_mask; /* indicates which close parens close off
212: * casts */
213: int sizeof_mask; /* indicates which close parens close off
214: * sizeof''s */
215: int block_init; /* true iff inside a block initialization */
216: int block_init_level; /* The level of brace nesting in an
217: * initialization */
218: int last_nl; /* this is true if the last thing scanned was
219: * a newline */
220: int in_or_st; /* Will be true iff there has been a
221: * declarator (e.g. int or char) and no left
222: * paren since the last semicolon. When true,
223: * a '{' is starting a structure definition or
224: * an initialization list */
225: int bl_line; /* set to 1 by dump_line if the line is blank */
226: int col_1; /* set to true if the last token started in
227: * column 1 */
228: int com_col; /* this is the column in which the current
229: * coment should start */
230: int com_ind; /* the column in which comments to the right
231: * of code should start */
232: int com_lines; /* the number of lines with comments, set by
233: * dump_line */
234: int dec_nest; /* current nesting level for structure or init */
235: int decl_com_ind; /* the column in which comments after
236: * declarations should be put */
237: int decl_on_line; /* set to true if this line of code has part
238: * of a declaration on it */
239: int i_l_follow; /* the level to which ind_level should be set
240: * after the current line is printed */
241: int in_decl; /* set to true when we are in a declaration
242: * stmt. The processing of braces is then
243: * slightly different */
244: int in_stmt; /* set to 1 while in a stmt */
245: int ind_level; /* the current indentation level */
246: int ind_size; /* the size of one indentation level */
247: int ind_stmt; /* set to 1 if next line should have an extra
248: * indentation level because we are in the
249: * middle of a stmt */
250: int last_u_d; /* set to true after scanning a token which
251: * forces a following operator to be unary */
252: int leave_comma; /* if true, never break declarations after
253: * commas */
254: int ljust_decl; /* true if declarations should be left
255: * justified */
256: int out_coms; /* the number of comments processed, set by
257: * pr_comment */
258: int out_lines; /* the number of lines written, set by
259: * dump_line */
260: int p_l_follow; /* used to remember how to indent following
261: * statement */
262: int paren_level; /* parenthesization level. used to indent
263: * within stmts */
264: short paren_indents[20]; /* column positions of each paren */
265: int pcase; /* set to 1 if the current line label is a
266: * case. It is printed differently from a
267: * regular label */
268: int search_brace; /* set to true by parse when it is necessary
269: * to buffer up all info up to the start of a
270: * stmt after an if, while, etc */
271: int unindent_displace; /* comments not to the right of code
272: * will be placed this many
273: * indentation levels to the left of
274: * code */
275: int use_ff; /* set to one if the current line should be
276: * terminated with a form feed */
277: int want_blank; /* set to true when the following token should
278: * be prefixed by a blank. (Said prefixing is
279: * ignored in some cases.) */
280: int else_if; /* True iff else if pairs should be handled
281: * specially */
282: int decl_indent; /* column to indent declared identifiers to */
283: int its_a_keyword;
284: int sizeof_keyword;
285: int dumped_decl_indent;
286: float case_indent; /* The distance to indent case labels from the
287: * switch statement */
288: int in_parameter_declaration;
289: int indent_parameters;
290: int tos; /* pointer to top of stack */
291: char procname[100]; /* The name of the current procedure */
292: int just_saw_decl;
293: } ps;
294:
295: int ifdef_level;
296: int rparen_count;
297: struct parser_state state_stack[5];
298: struct parser_state match_state[5];
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.