1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * Copyright (c) 1976 Board of Trustees of the University of Illinois.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms are permitted
7  * provided that this notice is preserved and that due credit is given
8  * to the University of California at Berkeley and the University of
9  * Illinois at Urbana.  The name of either University may not be used
10  * to endorse or promote products derived from this software without
11  * specific prior written permission. This software is provided
12  * ``as is'' without express or implied warranty.
13  *
14  *	@(#)indent_globs.h	5.5 (Berkeley) 03/22/88
15  */
16 
17 /*
18 FILE NAME:
19 	indent_globs.h
20 
21 PURPOSE:
22 	This include file contains the declarations for all global variables
23 	used in indent.
24 
25 GLOBALS:
26 	The names of all of the variables will not be repeated here.  The
27 	declarations start on the next page.
28 
29 FUNCTIONS:
30 	None
31 */
32 
33 #include <stdio.h>
34 
35 #define BACKSLASH '\\'
36 #define bufsize 600	   /* size of internal buffers */
37 #define inp_bufs 600	   /* size of input buffer */
38 #define sc_size 5000	   /* size of save_com buffer */
39 #define label_offset 2	   /* number of levels a label is placed to left of code
40 		   */
41 
42 #define tabsize 8  /* the size of a tab */
43 #define tabmask 0177770	   /* mask used when figuring length of lines with tabs */
44 
45 
46 #define false 0
47 #define true  1
48 
49 
50 FILE   *input;     /* the fid for the input file */
51 FILE   *output;    /* the output file */
52 
53 char    labbuf[bufsize];	/* buffer for label */
54 char   *s_lab;     /* start ... */
55 char   *e_lab;     /* .. and end of stored label */
56 
57 char    codebuf[bufsize];	/* buffer for code section */
58 char   *s_code;    /* start ... */
59 char   *e_code;    /* .. and end of stored code */
60 
61 char    combuf[bufsize];	/* buffer for comments */
62 char   *s_com;     /* start ... */
63 char   *e_com;     /* ... and end of stored comments */
64 
65 char    in_buffer[inp_bufs];	/* input buffer */
66 char   *buf_ptr;   /* ptr to next character to be taken from in_buffer */
67 char   *buf_end;   /* ptr to first after last char in in_buffer */
68 
69 char    save_com[sc_size];	/* input text is saved here when looking for the brace
70 		      after an if, while, etc */
71 char   *sc_end;    /* pointer into save_com buffer */
72 
73 char   *bp_save;   /* saved value of buf_ptr when taking input from
74 		      save_com */
75 char   *be_save;   /* similarly saved value of buf_end */
76 
77 char    token[bufsize];	/* the last token scanned */
78 
79 
80 
81 int	blanklines_after_declarations;
82 int	blanklines_before_blockcomments;
83 int	blanklines_after_procs;
84 int	swallow_optional_blanklines;
85 int	n_real_blanklines;
86 int	prefix_blankline_requested;
87 int	postfix_blankline_requested;
88 int     break_comma;	/* when true and not in parens, break after a comma */
89 int     btype_2;   /* when true, brace should be on same line as if,
90 		      while, etc */
91 float   case_ind;  /* indentation level to be used for a "case n:" */
92 int     code_lines;/* count of lines with code */
93 int     had_eof;   /* set to true when input is exhausted */
94 int     line_no;   /* the current line number. */
95 int     max_col;   /* the maximum allowable line length */
96 int     pointer_as_binop;	/* when true, "->" is treated as a binary
97 				   operator (giving, e.g., "p -> f") */
98 int     verbose;   /* when true, non-essential error messages are printed
99 		   */
100 int	cuddle_else;		/* true if else should cuddle up to '}' */
101 int	star_comment_cont;	/* true iff comment continuation lines should
102 				   have stars at the beginning of each line.
103 				   */
104 int     comment_delimiter_on_blankline;
105 int     troff;			/* true iff were generating troff input */
106 int	procnames_start_line;	/* if true, the names of procedures being
107 				   defined get placed in column 1 (ie. a
108 				   newline is placed between the type of the
109 				   procedure and its name) */
110 int	proc_calls_space;	/* If true, procedure calls look like:
111 				   foo(bar) rather than foo (bar) */
112 int	format_col1_comments;	/* If comments which start in column 1 are to
113 				   be magically reformatted (just like comments that
114 				   begin in later columns) */
115 int	inhibit_formatting;	/* true if INDENT OFF is in effect */
116 int	suppress_blanklines;	/* set iff following blanklines should be
117 				   suppressed */
118 int	continuation_indent;	/* set to the indentation between the edge of
119 				   code and continuation lines */
120 int	lineup_to_parens;	/* if true, continued code within parens will
121 				   be lined up to the open paren */
122 int	block_comment_max_col;
123 
124 
125 struct parser_state {
126     int         last_token;
127     int         p_stack[50];	/* this is the parsers stack */
128     int         il[50];		/* this stack stores indentation levels */
129     float       cstk[50];	/* used to store case stmt indentation
130 				 * levels */
131     int         box_com;	/* set to true when we are in a "boxed"
132 				 * comment. In that case, the first
133 				 * non-blank char should be lined up with
134 				 * the / in /* */
135     int         comment_delta,
136                 n_comment_delta;
137     int         cast_mask;	/* indicates which close parens close off
138 				 * casts */
139     int		sizeof_mask;	/* indicates which close parens close off
140 				   sizeof''s */
141     int         block_init;	/* true iff inside a block initialization */
142     int         last_nl;	/* this is true if the last thing scanned
143 				 * was a newline */
144     int         in_or_st;	/* Will be true iff there has been a
145 				 * declarator (e.g. int or char) and no
146 				 * left paren since the last semicolon.
147 				 * When true, a '{' is starting a
148 				 * structure definition or an
149 				 * initialization list */
150     int         bl_line;	/* set to 1 by dump_line if the line is
151 				 * blank */
152     int         col_1;		/* set to true if the last token started
153 				 * in column 1 */
154     int         com_col;	/* this is the column in which the current
155 				 * coment should start */
156     int         com_ind;	/* the column in which comments to the
157 				 * right of code should start */
158     int         com_lines;	/* the number of lines with comments, set
159 				 * by dump_line */
160     int         dec_nest;	/* current nesting level for structure or
161 				 * init */
162     int         decl_com_ind;	/* the column in which comments after
163 				 * declarations should be put */
164     int         decl_on_line;	/* set to true if this line of code has
165 				 * part of a declaration on it */
166     int         i_l_follow;	/* the level to which ind_level should be
167 				 * set after the current line is printed */
168     int         in_decl;	/* set to true when we are in a
169 				 * declaration stmt.  The processing of
170 				 * braces is then slightly different */
171     int         in_stmt;	/* set to 1 while in a stmt */
172     int         ind_level;	/* the current indentation level */
173     int         ind_size;	/* the size of one indentation level */
174     int         ind_stmt;	/* set to 1 if next line should have an
175 				 * extra indentation level because we are
176 				 * in the middle of a stmt */
177     int         last_u_d;	/* set to true after scanning a token
178 				 * which forces a following operator to be
179 				 * unary */
180     int         leave_comma;	/* if true, never break declarations after
181 				 * commas */
182     int         ljust_decl;	/* true if declarations should be left
183 				 * justified */
184     int         out_coms;	/* the number of comments processed, set
185 				 * by pr_comment */
186     int         out_lines;	/* the number of lines written, set by
187 				 * dump_line */
188     int         p_l_follow;	/* used to remember how to indent
189 				 * following statement */
190     int         paren_level;	/* parenthesization level. used to indent
191 				 * within stmts */
192     short       paren_indents[20];	/* column positions of each paren */
193     int         pcase;		/* set to 1 if the current line label is a
194 				 * case.  It is printed differently from
195 				 * a regular label */
196     int         search_brace;	/* set to true by parse when it is
197 				 * necessary to buffer up all info up to
198 				 * the start of a stmt after an if, while,
199 				 * etc */
200     int         unindent_displace;	/* comments not to the right of
201 					 * code will be placed this many
202 					 * indentation levels to the left
203 					 * of code */
204     int         use_ff;		/* set to one if the current line should
205 				 * be terminated with a form feed */
206     int         want_blank;	/* set to true when the following token
207 				 * should be prefixed by a blank. (Said
208 				 * prefixing is ignored in some cases.) */
209     int         else_if;	/* True iff else if pairs should be
210 				 * handled specially */
211     int         decl_indent;	/* column to indent declared identifiers
212 				 * to */
213     int         its_a_keyword;
214     int		sizeof_keyword;
215     int         dumped_decl_indent;
216     float       case_indent;	/* The distance to indent case labels from
217 				 * the switch statement */
218     int         in_parameter_declaration;
219     int         indent_parameters;
220     int         tos;		/* pointer to top of stack */
221     char        procname[100];	/* The name of the current procedure */
222     int		just_saw_decl;
223 }           ps;
224 
225 int ifdef_level;
226 struct parser_state state_stack[5];
227 struct parser_state match_state[5];
228