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