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