source: trunk/minix/commands/indent/globs.h@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

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