1 /* $NetBSD: indent_globs.h,v 1.9 2009/04/12 11:09:49 lukem Exp $ */
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * from: @(#)indent_globs.h 8.1 (Berkeley) 6/6/93
35 * Copyright (c) 1985 Sun Microsystems, Inc.
36 * Copyright (c) 1976 Board of Trustees of the University of Illinois.
37 * All rights reserved.
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. All advertising materials mentioning features or use of this software
48 * must display the following acknowledgement:
49 * This product includes software developed by the University of
50 * California, Berkeley and its contributors.
51 * 4. Neither the name of the University nor the names of its contributors
52 * may be used to endorse or promote products derived from this software
53 * without specific prior written permission.
55 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
67 * from: @(#)indent_globs.h 8.1 (Berkeley) 6/6/93
70 #define BACKSLASH '\\'
71 #define bufsize 200 /* size of internal buffers */
72 #define sc_size 5000 /* size of save_com buffer */
73 #define label_offset 2 /* number of levels a label is placed to left
76 #define tabsize 8 /* the size of a tab */
77 #define tabmask 0177770 /* mask used when figuring length of lines
90 EXTERN
FILE *input
; /* the fid for the input file */
91 EXTERN
FILE *output
; /* the output file */
93 #define CHECK_SIZE_CODE \
94 if (e_code >= l_code) { \
95 int nsize = l_code-s_code+400; \
96 codebuf = (char *) realloc(codebuf, nsize); \
97 e_code = codebuf + (e_code-s_code) + 1; \
98 l_code = codebuf + nsize - 5; \
99 s_code = codebuf + 1; \
101 #define CHECK_SIZE_COM \
102 if (e_com >= l_com) { \
103 int nsize = l_com-s_com+400; \
104 combuf = (char *) realloc(combuf, nsize); \
105 e_com = combuf + (e_com-s_com) + 1; \
106 l_com = combuf + nsize - 5; \
107 s_com = combuf + 1; \
109 #define CHECK_SIZE_LAB \
110 if (e_lab >= l_lab) { \
111 int nsize = l_lab-s_lab+400; \
112 labbuf = (char *) realloc(labbuf, nsize); \
113 e_lab = labbuf + (e_lab-s_lab) + 1; \
114 l_lab = labbuf + nsize - 5; \
115 s_lab = labbuf + 1; \
117 #define CHECK_SIZE_TOKEN \
118 if (e_token >= l_token) { \
119 int nsize = l_token-s_token+400; \
120 tokenbuf = (char *) realloc(tokenbuf, nsize); \
121 e_token = tokenbuf + (e_token-s_token) + 1; \
122 l_token = tokenbuf + nsize - 5; \
123 s_token = tokenbuf + 1; \
126 EXTERN
char *labbuf
; /* buffer for label */
127 EXTERN
char *s_lab
; /* start ... */
128 EXTERN
char *e_lab
; /* .. and end of stored label */
129 EXTERN
char *l_lab
; /* limit of label buffer */
131 EXTERN
char *codebuf
; /* buffer for code section */
132 EXTERN
char *s_code
; /* start ... */
133 EXTERN
char *e_code
; /* .. and end of stored code */
134 EXTERN
char *l_code
; /* limit of code section */
136 EXTERN
char *combuf
; /* buffer for comments */
137 EXTERN
char *s_com
; /* start ... */
138 EXTERN
char *e_com
; /* ... and end of stored comments */
139 EXTERN
char *l_com
; /* limit of comment buffer */
141 #define token s_token
142 EXTERN
char *tokenbuf
; /* the last token scanned */
143 EXTERN
char *s_token
;
144 EXTERN
char *e_token
;
145 EXTERN
char *l_token
;
147 EXTERN
char *in_buffer
; /* input buffer */
148 EXTERN
char *in_buffer_limit
; /* the end of the input buffer */
149 EXTERN
char *buf_ptr
; /* ptr to next character to be taken from
151 EXTERN
char *buf_end
; /* ptr to first after last char in in_buffer */
153 EXTERN
char save_com
[sc_size
]; /* input text is saved here when looking for
154 * the brace after an if, while, etc */
155 EXTERN
char *sc_end
; /* pointer into save_com buffer */
157 EXTERN
char *bp_save
; /* saved value of buf_ptr when taking input
159 EXTERN
char *be_save
; /* similarly saved value of buf_end */
162 EXTERN
int pointer_as_binop
;
163 EXTERN
int blanklines_after_declarations
;
164 EXTERN
int blanklines_before_blockcomments
;
165 EXTERN
int blanklines_after_procs
;
166 EXTERN
int blanklines_around_conditional_compilation
;
167 EXTERN
int swallow_optional_blanklines
;
168 EXTERN
int n_real_blanklines
;
169 EXTERN
int prefix_blankline_requested
;
170 EXTERN
int postfix_blankline_requested
;
171 EXTERN
int break_comma
; /* when true and not in parens, break after a
173 EXTERN
int btype_2
; /* when true, brace should be on same line as
175 EXTERN
float case_ind
; /* indentation level to be used for a "case
177 EXTERN
int code_lines
; /* count of lines with code */
178 EXTERN
int had_eof
; /* set to true when input is exhausted */
179 EXTERN
int line_no
; /* the current line number. */
180 EXTERN
int max_col
; /* the maximum allowable line length */
181 EXTERN
int verbose
; /* when true, non-essential error messages are
183 EXTERN
int cuddle_else
; /* true if else should cuddle up to '}' */
184 EXTERN
int star_comment_cont
; /* true iff comment continuation lines should
185 * have stars at the beginning of each line. */
186 EXTERN
int comment_delimiter_on_blankline
;
187 EXTERN
int troff
; /* true iff were generating troff input */
188 EXTERN
int procnames_start_line
; /* if true, the names of procedures being
189 * defined get placed in column 1 (ie. a
190 * newline is placed between the type of the
191 * procedure and its name) */
192 EXTERN
int proc_calls_space
; /* If true, procedure calls look like:
193 * foo(bar) rather than foo (bar) */
194 EXTERN
int format_col1_comments
; /* If comments which start in column 1 are to
195 * be magically reformatted (just like
196 * comments that begin in later columns) */
197 EXTERN
int inhibit_formatting
; /* true if INDENT OFF is in effect */
198 EXTERN
int suppress_blanklines
; /* set iff following blanklines should be
200 EXTERN
int continuation_indent
; /* set to the indentation between the edge of
201 * code and continuation lines */
202 EXTERN
int lineup_to_parens
; /* if true, continued code within parens will
203 * be lined up to the open paren */
204 EXTERN
int Bill_Shannon
; /* true iff a blank should always be inserted
206 EXTERN
int blanklines_after_declarations_at_proctop
; /* This is vaguely
208 * blanklines_after_decla
209 * rations except that
213 * procedure (just after
214 * the first '{') and it
215 * causes a blank line
216 * to be generated even
219 EXTERN
int block_comment_max_col
;
220 EXTERN
int extra_expression_indent
; /* True if continuation lines from the
221 * expression part of "if(e)", "while(e)",
222 * "for(e;e;e)" should be indented an extra
223 * tab stop so that they don't conflict with
224 * the code that follows */
226 /* -troff font state information */
235 keywordf
, /* keyword font */
236 stringf
, /* string font */
237 boxcomf
, /* Box comment font */
238 blkcomf
, /* Block comment font */
239 scomf
, /* Same line comment font */
240 bodyf
; /* major body font */
242 #define STACK_SIZE 150
244 EXTERN
struct parser_state
{
246 struct fstate cfont
; /* Current font */
247 int p_stack
[STACK_SIZE
]; /* this is the parsers stack */
248 int il
[STACK_SIZE
]; /* this stack stores indentation levels */
249 float cstk
[STACK_SIZE
];/* used to store case stmt indentation levels */
250 int box_com
; /* set to true when we are in a "boxed"
251 * comment. In that case, the first non-blank
252 * char should be lined up with the comment / */
253 int comment_delta
, n_comment_delta
;
254 int cast_mask
; /* indicates which close parens close off
256 int sizeof_mask
; /* indicates which close parens close off
258 int block_init
; /* true iff inside a block initialization */
259 int block_init_level
; /* The level of brace nesting in an
261 int last_nl
; /* this is true if the last thing scanned was
263 int in_or_st
; /* Will be true iff there has been a
264 * declarator (e.g. int or char) and no left
265 * paren since the last semicolon. When true,
266 * a '{' is starting a structure definition or
267 * an initialization list */
268 int bl_line
; /* set to 1 by dump_line if the line is blank */
269 int col_1
; /* set to true if the last token started in
271 int com_col
; /* this is the column in which the current
272 * coment should start */
273 int com_ind
; /* the column in which comments to the right
274 * of code should start */
275 int com_lines
; /* the number of lines with comments, set by
277 int dec_nest
; /* current nesting level for structure or init */
278 int decl_com_ind
; /* the column in which comments after
279 * declarations should be put */
280 int decl_on_line
; /* set to true if this line of code has part
281 * of a declaration on it */
282 int i_l_follow
; /* the level to which ind_level should be set
283 * after the current line is printed */
284 int in_decl
; /* set to true when we are in a declaration
285 * stmt. The processing of braces is then
286 * slightly different */
287 int in_stmt
; /* set to 1 while in a stmt */
288 int ind_level
; /* the current indentation level */
289 int ind_size
; /* the size of one indentation level */
290 int ind_stmt
; /* set to 1 if next line should have an extra
291 * indentation level because we are in the
292 * middle of a stmt */
293 int last_u_d
; /* set to true after scanning a token which
294 * forces a following operator to be unary */
295 int leave_comma
; /* if true, never break declarations after
297 int ljust_decl
; /* true if declarations should be left
299 int out_coms
; /* the number of comments processed, set by
301 int out_lines
; /* the number of lines written, set by
303 int p_l_follow
; /* used to remember how to indent following
305 int paren_level
; /* parenthesization level. used to indent
307 short paren_indents
[20]; /* column positions of each paren */
308 int pcase
; /* set to 1 if the current line label is a
309 * case. It is printed differently from a
311 int search_brace
; /* set to true by parse when it is necessary
312 * to buffer up all info up to the start of a
313 * stmt after an if, while, etc */
314 int unindent_displace
; /* comments not to the right of code
315 * will be placed this many
316 * indentation levels to the left of
318 int use_ff
; /* set to one if the current line should be
319 * terminated with a form feed */
320 int want_blank
; /* set to true when the following token should
321 * be prefixed by a blank. (Said prefixing is
322 * ignored in some cases.) */
323 int else_if
; /* True iff else if pairs should be handled
325 int decl_indent
; /* column to indent declared identifiers to */
328 int dumped_decl_indent
;
329 float case_indent
; /* The distance to indent case labels from the
330 * switch statement */
331 int in_parameter_declaration
;
332 int indent_parameters
;
333 int tos
; /* pointer to top of stack */
334 char procname
[100]; /* The name of the current procedure */
338 EXTERN
int ifdef_level
;
339 EXTERN
int rparen_count
;
340 EXTERN
struct parser_state state_stack
[5];
341 EXTERN
struct parser_state match_state
[5];
343 int compute_code_target(void);
344 int compute_label_target(void);
345 int count_spaces(int, char *);
346 void diag(int, const char *,...) __attribute__((__format__(__printf__
, 2, 3)));
347 void dump_line(void);
348 int eqin(const char *, const char *);
349 void fill_buffer(void);
350 int pad_output(int, int);
351 void scan_profile(FILE *);
352 void set_defaults(void);
353 void set_option(char *);
354 void addkey(char *, int);
355 void set_profile(void);
356 char *chfont(struct fstate
*, struct fstate
*, char *);
357 void parsefont(struct fstate
*, const char *);
358 void writefdef(struct fstate
*, int);
362 void pr_comment(void);