| 1 |
/*- |
| 2 |
* Copyright (c) 1985 Sun Microsystems, Inc. |
| 3 |
* Copyright (c) 1980, 1993 |
| 4 |
* The Regents of the University of California. All rights reserved. |
| 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. 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. |
| 18 |
* |
| 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 |
| 29 |
* SUCH DAMAGE. |
| 30 |
* |
| 31 |
* @(#)indent_globs.h 8.1 (Berkeley) 6/6/93 |
| 32 |
* $FreeBSD: head/usr.bin/indent/indent_globs.h 303735 2016-08-03 22:08:07Z pfg $ |
| 33 |
*/ |
| 34 |
|
| 35 |
#define BACKSLASH '\\' |
| 36 |
#define bufsize 200 /* size of internal buffers */ |
| 37 |
#define sc_size 5000 /* size of save_com buffer */ |
| 38 |
#define label_offset 2 /* number of levels a label is placed to left |
| 39 |
* of code */ |
| 40 |
|
| 41 |
|
| 42 |
#ifndef false |
| 43 |
#define false 0 |
| 44 |
#endif |
| 45 |
#ifndef true |
| 46 |
#define true 1 |
| 47 |
#endif |
| 48 |
|
| 49 |
/* |
| 50 |
* Exactly one calling file should define this symbol. The global variables |
| 51 |
* will be defined in that file, and just referenced elsewhere. |
| 52 |
*/ |
| 53 |
#ifdef DECLARE_INDENT_GLOBALS |
| 54 |
#define extern |
| 55 |
#endif |
| 56 |
|
| 57 |
extern FILE *input; /* the fid for the input file */ |
| 58 |
extern FILE *output; /* the output file */ |
| 59 |
|
| 60 |
#define CHECK_SIZE_CODE(desired_size) \ |
| 61 |
if (e_code + (desired_size) >= l_code) { \ |
| 62 |
int nsize = l_code-s_code + 400 + desired_size; \ |
| 63 |
int code_len = e_code-s_code; \ |
| 64 |
codebuf = (char *) realloc(codebuf, nsize); \ |
| 65 |
if (codebuf == NULL) \ |
| 66 |
err(1, NULL); \ |
| 67 |
e_code = codebuf + code_len + 1; \ |
| 68 |
l_code = codebuf + nsize - 5; \ |
| 69 |
s_code = codebuf + 1; \ |
| 70 |
} |
| 71 |
#define CHECK_SIZE_COM(desired_size) \ |
| 72 |
if (e_com + (desired_size) >= l_com) { \ |
| 73 |
int nsize = l_com-s_com + 400 + desired_size; \ |
| 74 |
int com_len = e_com - s_com; \ |
| 75 |
int blank_pos; \ |
| 76 |
if (last_bl != NULL) \ |
| 77 |
blank_pos = last_bl - combuf; \ |
| 78 |
else \ |
| 79 |
blank_pos = -1; \ |
| 80 |
combuf = (char *) realloc(combuf, nsize); \ |
| 81 |
if (combuf == NULL) \ |
| 82 |
err(1, NULL); \ |
| 83 |
e_com = combuf + com_len + 1; \ |
| 84 |
if (blank_pos > 0) \ |
| 85 |
last_bl = combuf + blank_pos; \ |
| 86 |
l_com = combuf + nsize - 5; \ |
| 87 |
s_com = combuf + 1; \ |
| 88 |
} |
| 89 |
#define CHECK_SIZE_LAB(desired_size) \ |
| 90 |
if (e_lab + (desired_size) >= l_lab) { \ |
| 91 |
int nsize = l_lab-s_lab + 400 + desired_size; \ |
| 92 |
int label_len = e_lab - s_lab; \ |
| 93 |
labbuf = (char *) realloc(labbuf, nsize); \ |
| 94 |
if (labbuf == NULL) \ |
| 95 |
err(1, NULL); \ |
| 96 |
e_lab = labbuf + label_len + 1; \ |
| 97 |
l_lab = labbuf + nsize - 5; \ |
| 98 |
s_lab = labbuf + 1; \ |
| 99 |
} |
| 100 |
#define CHECK_SIZE_TOKEN(desired_size) \ |
| 101 |
if (e_token + (desired_size) >= l_token) { \ |
| 102 |
int nsize = l_token-s_token + 400 + desired_size; \ |
| 103 |
int token_len = e_token - s_token; \ |
| 104 |
tokenbuf = (char *) realloc(tokenbuf, nsize); \ |
| 105 |
if (tokenbuf == NULL) \ |
| 106 |
err(1, NULL); \ |
| 107 |
e_token = tokenbuf + token_len + 1; \ |
| 108 |
l_token = tokenbuf + nsize - 5; \ |
| 109 |
s_token = tokenbuf + 1; \ |
| 110 |
} |
| 111 |
|
| 112 |
extern char *labbuf; /* buffer for label */ |
| 113 |
extern char *s_lab; /* start ... */ |
| 114 |
extern char *e_lab; /* .. and end of stored label */ |
| 115 |
extern char *l_lab; /* limit of label buffer */ |
| 116 |
|
| 117 |
extern char *codebuf; /* buffer for code section */ |
| 118 |
extern char *s_code; /* start ... */ |
| 119 |
extern char *e_code; /* .. and end of stored code */ |
| 120 |
extern char *l_code; /* limit of code section */ |
| 121 |
|
| 122 |
extern char *combuf; /* buffer for comments */ |
| 123 |
extern char *s_com; /* start ... */ |
| 124 |
extern char *e_com; /* ... and end of stored comments */ |
| 125 |
extern char *l_com; /* limit of comment buffer */ |
| 126 |
|
| 127 |
#define token s_token |
| 128 |
extern char *tokenbuf; /* the last token scanned */ |
| 129 |
extern char *s_token; |
| 130 |
extern char *e_token; |
| 131 |
extern char *l_token; |
| 132 |
|
| 133 |
extern char *in_buffer; /* input buffer */ |
| 134 |
extern char *in_buffer_limit; /* the end of the input buffer */ |
| 135 |
extern char *buf_ptr; /* ptr to next character to be taken from |
| 136 |
* in_buffer */ |
| 137 |
extern char *buf_end; /* ptr to first after last char in in_buffer */ |
| 138 |
|
| 139 |
extern char sc_buf[sc_size]; /* input text is saved here when looking for |
| 140 |
* the brace after an if, while, etc */ |
| 141 |
extern char *save_com; /* start of the comment stored in sc_buf */ |
| 142 |
extern char *sc_end; /* pointer into save_com buffer */ |
| 143 |
|
| 144 |
extern char *bp_save; /* saved value of buf_ptr when taking input |
| 145 |
* from save_com */ |
| 146 |
extern char *be_save; /* similarly saved value of buf_end */ |
| 147 |
|
| 148 |
|
| 149 |
extern int found_err; |
| 150 |
extern int blanklines_after_declarations; |
| 151 |
extern int blanklines_before_blockcomments; |
| 152 |
extern int blanklines_after_procs; |
| 153 |
extern int blanklines_around_conditional_compilation; |
| 154 |
extern int swallow_optional_blanklines; |
| 155 |
extern int n_real_blanklines; |
| 156 |
extern int prefix_blankline_requested; |
| 157 |
extern int postfix_blankline_requested; |
| 158 |
extern int break_comma; /* when true and not in parens, break after a |
| 159 |
* comma */ |
| 160 |
extern int btype_2; /* when true, brace should be on same line as |
| 161 |
* if, while, etc */ |
| 162 |
extern float case_ind; /* indentation level to be used for a "case |
| 163 |
* n:" */ |
| 164 |
extern int code_lines; /* count of lines with code */ |
| 165 |
extern int had_eof; /* set to true when input is exhausted */ |
| 166 |
extern int line_no; /* the current line number. */ |
| 167 |
extern int max_col; /* the maximum allowable line length */ |
| 168 |
extern int verbose; /* when true, non-essential error messages are |
| 169 |
* printed */ |
| 170 |
extern int cuddle_else; /* true if else should cuddle up to '}' */ |
| 171 |
extern int star_comment_cont; /* true iff comment continuation lines should |
| 172 |
* have stars at the beginning of each line. */ |
| 173 |
extern int comment_delimiter_on_blankline; |
| 174 |
extern int troff; /* true iff were generating troff input */ |
| 175 |
extern int procnames_start_line; /* if true, the names of procedures |
| 176 |
* being defined get placed in column |
| 177 |
* 1 (ie. a newline is placed between |
| 178 |
* the type of the procedure and its |
| 179 |
* name) */ |
| 180 |
extern int proc_calls_space; /* If true, procedure calls look like: |
| 181 |
* foo(bar) rather than foo (bar) */ |
| 182 |
extern int format_block_comments; /* true if comments beginning with |
| 183 |
* `/ * \n' are to be reformatted */ |
| 184 |
extern int format_col1_comments; /* If comments which start in column 1 |
| 185 |
* are to be magically reformatted |
| 186 |
* (just like comments that begin in |
| 187 |
* later columns) */ |
| 188 |
extern int inhibit_formatting; /* true if INDENT OFF is in effect */ |
| 189 |
extern int suppress_blanklines;/* set iff following blanklines should be |
| 190 |
* suppressed */ |
| 191 |
extern int continuation_indent;/* set to the indentation between the edge of |
| 192 |
* code and continuation lines */ |
| 193 |
extern int lineup_to_parens; /* if true, continued code within parens will |
| 194 |
* be lined up to the open paren */ |
| 195 |
extern int lineup_to_parens_always; /* if true, do not attempt to keep |
| 196 |
* lined-up code within the margin */ |
| 197 |
extern int Bill_Shannon; /* true iff a blank should always be inserted |
| 198 |
* after sizeof */ |
| 199 |
extern int blanklines_after_declarations_at_proctop; /* This is vaguely |
| 200 |
* similar to |
| 201 |
* blanklines_after_decla |
| 202 |
* rations except that |
| 203 |
* it only applies to |
| 204 |
* the first set of |
| 205 |
* declarations in a |
| 206 |
* procedure (just after |
| 207 |
* the first '{') and it |
| 208 |
* causes a blank line |
| 209 |
* to be generated even |
| 210 |
* if there are no |
| 211 |
* declarations */ |
| 212 |
extern int block_comment_max_col; |
| 213 |
extern int extra_expression_indent; /* true if continuation lines from the |
| 214 |
* expression part of "if(e)", |
| 215 |
* "while(e)", "for(e;e;e)" should be |
| 216 |
* indented an extra tab stop so that |
| 217 |
* they don't conflict with the code |
| 218 |
* that follows */ |
| 219 |
extern int function_brace_split; /* split function declaration and |
| 220 |
* brace onto separate lines */ |
| 221 |
extern int use_tabs; /* set true to use tabs for spacing, |
| 222 |
* false uses all spaces */ |
| 223 |
extern int auto_typedefs; /* set true to recognize identifiers |
| 224 |
* ending in "_t" like typedefs */ |
| 225 |
extern int space_after_cast; /* "b = (int) a" vs "b = (int)a" */ |
| 226 |
extern int postgres_tab_rules; /* use Postgres tab-vs-space rules */ |
| 227 |
extern int tabsize; /* the size of a tab */ |
| 228 |
extern int else_endif_com_ind; /* the column in which comments to |
| 229 |
* the right of #else and #endif |
| 230 |
* should start */ |
| 231 |
|
| 232 |
extern int ifdef_level; |
| 233 |
|
| 234 |
struct parser_state { |
| 235 |
int last_token; |
| 236 |
int p_stack[256]; /* this is the parsers stack */ |
| 237 |
int il[64]; /* this stack stores indentation levels */ |
| 238 |
float cstk[32]; /* used to store case stmt indentation levels */ |
| 239 |
int box_com; /* set to true when we are in a "boxed" |
| 240 |
* comment. In that case, the first non-blank |
| 241 |
* char should be lined up with the / in / followed by * */ |
| 242 |
int comment_delta; /* used to set up indentation for all lines |
| 243 |
* of a boxed comment after the first one */ |
| 244 |
int n_comment_delta;/* remembers how many columns there were |
| 245 |
* before the start of a box comment so that |
| 246 |
* forthcoming lines of the comment are |
| 247 |
* indented properly */ |
| 248 |
int cast_mask; /* indicates which close parens potentially |
| 249 |
* close off casts */ |
| 250 |
int not_cast_mask; /* indicates which close parens definitely |
| 251 |
* close off something else than casts */ |
| 252 |
int block_init; /* true iff inside a block initialization */ |
| 253 |
int block_init_level; /* The level of brace nesting in an |
| 254 |
* initialization */ |
| 255 |
int last_nl; /* this is true if the last thing scanned was |
| 256 |
* a newline */ |
| 257 |
int in_or_st; /* Will be true iff there has been a |
| 258 |
* declarator (e.g. int or char) and no left |
| 259 |
* paren since the last semicolon. When true, |
| 260 |
* a '{' is starting a structure definition or |
| 261 |
* an initialization list */ |
| 262 |
int bl_line; /* set to 1 by dump_line if the line is blank */ |
| 263 |
int col_1; /* set to true if the last token started in |
| 264 |
* column 1 */ |
| 265 |
int com_col; /* this is the column in which the current |
| 266 |
* comment should start */ |
| 267 |
int com_ind; /* the column in which comments to the right |
| 268 |
* of code should start */ |
| 269 |
int com_lines; /* the number of lines with comments, set by |
| 270 |
* dump_line */ |
| 271 |
int dec_nest; /* current nesting level for structure or init */ |
| 272 |
int decl_com_ind; /* the column in which comments after |
| 273 |
* declarations should be put */ |
| 274 |
int decl_on_line; /* set to true if this line of code has part |
| 275 |
* of a declaration on it */ |
| 276 |
int i_l_follow; /* the level to which ind_level should be set |
| 277 |
* after the current line is printed */ |
| 278 |
int in_decl; /* set to true when we are in a declaration |
| 279 |
* stmt. The processing of braces is then |
| 280 |
* slightly different */ |
| 281 |
int in_stmt; /* set to 1 while in a stmt */ |
| 282 |
int ind_level; /* the current indentation level */ |
| 283 |
int ind_size; /* the size of one indentation level */ |
| 284 |
int ind_stmt; /* set to 1 if next line should have an extra |
| 285 |
* indentation level because we are in the |
| 286 |
* middle of a stmt */ |
| 287 |
int last_u_d; /* set to true after scanning a token which |
| 288 |
* forces a following operator to be unary */ |
| 289 |
int leave_comma; /* if true, never break declarations after |
| 290 |
* commas */ |
| 291 |
int ljust_decl; /* true if declarations should be left |
| 292 |
* justified */ |
| 293 |
int out_coms; /* the number of comments processed, set by |
| 294 |
* pr_comment */ |
| 295 |
int out_lines; /* the number of lines written, set by |
| 296 |
* dump_line */ |
| 297 |
int p_l_follow; /* used to remember how to indent following |
| 298 |
* statement */ |
| 299 |
int paren_level; /* parenthesization level. used to indent |
| 300 |
* within statements */ |
| 301 |
short paren_indents[20]; /* column positions of each paren */ |
| 302 |
int pcase; /* set to 1 if the current line label is a |
| 303 |
* case. It is printed differently from a |
| 304 |
* regular label */ |
| 305 |
int search_brace; /* set to true by parse when it is necessary |
| 306 |
* to buffer up all info up to the start of a |
| 307 |
* stmt after an if, while, etc */ |
| 308 |
int unindent_displace; /* comments not to the right of code |
| 309 |
* will be placed this many |
| 310 |
* indentation levels to the left of |
| 311 |
* code */ |
| 312 |
int use_ff; /* set to one if the current line should be |
| 313 |
* terminated with a form feed */ |
| 314 |
int want_blank; /* set to true when the following token should |
| 315 |
* be prefixed by a blank. (Said prefixing is |
| 316 |
* ignored in some cases.) */ |
| 317 |
int else_if; /* True iff else if pairs should be handled |
| 318 |
* specially */ |
| 319 |
int decl_indent; /* column to indent declared identifiers to */ |
| 320 |
int local_decl_indent; /* like decl_indent but for locals */ |
| 321 |
int keyword; /* the type of a keyword or 0 */ |
| 322 |
int dumped_decl_indent; |
| 323 |
float case_indent; /* The distance to indent case labels from the |
| 324 |
* switch statement */ |
| 325 |
int in_parameter_declaration; |
| 326 |
int indent_parameters; |
| 327 |
int tos; /* pointer to top of stack */ |
| 328 |
char procname[100]; /* The name of the current procedure */ |
| 329 |
int just_saw_decl; |
| 330 |
}; |
| 331 |
|
| 332 |
extern struct parser_state ps; |
| 333 |
extern struct parser_state state_stack[5]; |
| 334 |
extern struct parser_state match_state[5]; |
| 335 |
|
| 336 |
/* Undo previous hackery */ |
| 337 |
#ifdef DECLARE_INDENT_GLOBALS |
| 338 |
#undef extern |
| 339 |
#endif |