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