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