121975Sdist /*
221975Sdist  * Copyright (c) 1980 Regents of the University of California.
3*33767Sbostic  * Copyright (c) 1976 Board of Trustees of the University of Illinois.
4*33767Sbostic  * All rights reserved.
521975Sdist  *
6*33767Sbostic  * Redistribution and use in source and binary forms are permitted
7*33767Sbostic  * provided that this notice is preserved and that due credit is given
8*33767Sbostic  * to the University of California at Berkeley and the University of
9*33767Sbostic  * Illinois at Urbana.  The name of either University may not be used
10*33767Sbostic  * to endorse or promote products derived from this software without
11*33767Sbostic  * specific prior written permission. This software is provided
12*33767Sbostic  * ``as is'' without express or implied warranty.
13*33767Sbostic  *
14*33767Sbostic  *	@(#)indent_globs.h	5.5 (Berkeley) 03/22/88
1521975Sdist  */
168802Smckusick 
17*33767Sbostic /*
188802Smckusick FILE NAME:
198802Smckusick 	indent_globs.h
208802Smckusick 
218802Smckusick PURPOSE:
228802Smckusick 	This include file contains the declarations for all global variables
238802Smckusick 	used in indent.
248802Smckusick 
258802Smckusick GLOBALS:
268802Smckusick 	The names of all of the variables will not be repeated here.  The
278802Smckusick 	declarations start on the next page.
288802Smckusick 
298802Smckusick FUNCTIONS:
308802Smckusick 	None
3124454Smckusick */
3224454Smckusick 
3324454Smckusick #include <stdio.h>
3424454Smckusick 
3524454Smckusick #define BACKSLASH '\\'
3624454Smckusick #define bufsize 600	   /* size of internal buffers */
3724454Smckusick #define inp_bufs 600	   /* size of input buffer */
3824454Smckusick #define sc_size 5000	   /* size of save_com buffer */
3924454Smckusick #define label_offset 2	   /* number of levels a label is placed to left of code
408802Smckusick 		   */
418802Smckusick 
428802Smckusick #define tabsize 8  /* the size of a tab */
4324454Smckusick #define tabmask 0177770	   /* mask used when figuring length of lines with tabs */
448802Smckusick 
458802Smckusick 
468802Smckusick #define false 0
478802Smckusick #define true  1
488802Smckusick 
498802Smckusick 
5024454Smckusick FILE   *input;     /* the fid for the input file */
5124454Smckusick FILE   *output;    /* the output file */
528802Smckusick 
5324454Smckusick char    labbuf[bufsize];	/* buffer for label */
548802Smckusick char   *s_lab;     /* start ... */
558802Smckusick char   *e_lab;     /* .. and end of stored label */
568802Smckusick 
5724454Smckusick char    codebuf[bufsize];	/* buffer for code section */
588802Smckusick char   *s_code;    /* start ... */
598802Smckusick char   *e_code;    /* .. and end of stored code */
608802Smckusick 
6124454Smckusick char    combuf[bufsize];	/* buffer for comments */
628802Smckusick char   *s_com;     /* start ... */
638802Smckusick char   *e_com;     /* ... and end of stored comments */
648802Smckusick 
6524454Smckusick char    in_buffer[inp_bufs];	/* input buffer */
668802Smckusick char   *buf_ptr;   /* ptr to next character to be taken from in_buffer */
678802Smckusick char   *buf_end;   /* ptr to first after last char in in_buffer */
688802Smckusick 
6924454Smckusick char    save_com[sc_size];	/* input text is saved here when looking for the brace
708802Smckusick 		      after an if, while, etc */
718802Smckusick char   *sc_end;    /* pointer into save_com buffer */
728802Smckusick 
738802Smckusick char   *bp_save;   /* saved value of buf_ptr when taking input from
748802Smckusick 		      save_com */
758802Smckusick char   *be_save;   /* similarly saved value of buf_end */
768802Smckusick 
7724454Smckusick char    token[bufsize];	/* the last token scanned */
788802Smckusick 
798802Smckusick 
808802Smckusick 
8124454Smckusick int	blanklines_after_declarations;
8224454Smckusick int	blanklines_before_blockcomments;
8324454Smckusick int	blanklines_after_procs;
8424454Smckusick int	swallow_optional_blanklines;
8524454Smckusick int	n_real_blanklines;
8624454Smckusick int	prefix_blankline_requested;
8724454Smckusick int	postfix_blankline_requested;
8824454Smckusick int     break_comma;	/* when true and not in parens, break after a comma */
898802Smckusick int     btype_2;   /* when true, brace should be on same line as if,
908802Smckusick 		      while, etc */
9124454Smckusick float   case_ind;  /* indentation level to be used for a "case n:" */
928802Smckusick int     code_lines;/* count of lines with code */
938802Smckusick int     had_eof;   /* set to true when input is exhausted */
948802Smckusick int     line_no;   /* the current line number. */
958802Smckusick int     max_col;   /* the maximum allowable line length */
9624677Smckusick int     pointer_as_binop;	/* when true, "->" is treated as a binary
9724677Smckusick 				   operator (giving, e.g., "p -> f") */
988802Smckusick int     verbose;   /* when true, non-essential error messages are printed
998802Smckusick 		   */
10024454Smckusick int	cuddle_else;		/* true if else should cuddle up to '}' */
10124454Smckusick int	star_comment_cont;	/* true iff comment continuation lines should
10224454Smckusick 				   have stars at the beginning of each line.
10324454Smckusick 				   */
10424454Smckusick int     comment_delimiter_on_blankline;
10524454Smckusick int     troff;			/* true iff were generating troff input */
10624454Smckusick int	procnames_start_line;	/* if true, the names of procedures being
10724454Smckusick 				   defined get placed in column 1 (ie. a
10824454Smckusick 				   newline is placed between the type of the
10924454Smckusick 				   procedure and its name) */
11024454Smckusick int	proc_calls_space;	/* If true, procedure calls look like:
11124454Smckusick 				   foo(bar) rather than foo (bar) */
11224454Smckusick int	format_col1_comments;	/* If comments which start in column 1 are to
11324454Smckusick 				   be magically reformatted (just like comments that
11424454Smckusick 				   begin in later columns) */
11524454Smckusick int	inhibit_formatting;	/* true if INDENT OFF is in effect */
11624454Smckusick int	suppress_blanklines;	/* set iff following blanklines should be
11724454Smckusick 				   suppressed */
11824454Smckusick int	continuation_indent;	/* set to the indentation between the edge of
11924454Smckusick 				   code and continuation lines */
12024454Smckusick int	lineup_to_parens;	/* if true, continued code within parens will
12124454Smckusick 				   be lined up to the open paren */
12224454Smckusick int	block_comment_max_col;
12324454Smckusick 
12424454Smckusick 
12524454Smckusick struct parser_state {
12624454Smckusick     int         last_token;
12724454Smckusick     int         p_stack[50];	/* this is the parsers stack */
12824454Smckusick     int         il[50];		/* this stack stores indentation levels */
12924454Smckusick     float       cstk[50];	/* used to store case stmt indentation
13024454Smckusick 				 * levels */
13124454Smckusick     int         box_com;	/* set to true when we are in a "boxed"
13224454Smckusick 				 * comment. In that case, the first
13324454Smckusick 				 * non-blank char should be lined up with
13424454Smckusick 				 * the / in /* */
13524454Smckusick     int         comment_delta,
13624454Smckusick                 n_comment_delta;
13724454Smckusick     int         cast_mask;	/* indicates which close parens close off
13824454Smckusick 				 * casts */
13924454Smckusick     int		sizeof_mask;	/* indicates which close parens close off
14024454Smckusick 				   sizeof''s */
14124454Smckusick     int         block_init;	/* true iff inside a block initialization */
14224454Smckusick     int         last_nl;	/* this is true if the last thing scanned
14324454Smckusick 				 * was a newline */
14424454Smckusick     int         in_or_st;	/* Will be true iff there has been a
14524454Smckusick 				 * declarator (e.g. int or char) and no
14624454Smckusick 				 * left paren since the last semicolon.
14724454Smckusick 				 * When true, a '{' is starting a
14824454Smckusick 				 * structure definition or an
14924454Smckusick 				 * initialization list */
15024454Smckusick     int         bl_line;	/* set to 1 by dump_line if the line is
15124454Smckusick 				 * blank */
15224454Smckusick     int         col_1;		/* set to true if the last token started
15324454Smckusick 				 * in column 1 */
15424454Smckusick     int         com_col;	/* this is the column in which the current
15524454Smckusick 				 * coment should start */
15624454Smckusick     int         com_ind;	/* the column in which comments to the
15724454Smckusick 				 * right of code should start */
15824454Smckusick     int         com_lines;	/* the number of lines with comments, set
15924454Smckusick 				 * by dump_line */
16024454Smckusick     int         dec_nest;	/* current nesting level for structure or
16124454Smckusick 				 * init */
16224454Smckusick     int         decl_com_ind;	/* the column in which comments after
16324454Smckusick 				 * declarations should be put */
16424454Smckusick     int         decl_on_line;	/* set to true if this line of code has
16524454Smckusick 				 * part of a declaration on it */
16624454Smckusick     int         i_l_follow;	/* the level to which ind_level should be
16724454Smckusick 				 * set after the current line is printed */
16824454Smckusick     int         in_decl;	/* set to true when we are in a
16924454Smckusick 				 * declaration stmt.  The processing of
17024454Smckusick 				 * braces is then slightly different */
17124454Smckusick     int         in_stmt;	/* set to 1 while in a stmt */
17224454Smckusick     int         ind_level;	/* the current indentation level */
17324454Smckusick     int         ind_size;	/* the size of one indentation level */
17424454Smckusick     int         ind_stmt;	/* set to 1 if next line should have an
17524454Smckusick 				 * extra indentation level because we are
17624454Smckusick 				 * in the middle of a stmt */
17724454Smckusick     int         last_u_d;	/* set to true after scanning a token
17824454Smckusick 				 * which forces a following operator to be
17924454Smckusick 				 * unary */
18024454Smckusick     int         leave_comma;	/* if true, never break declarations after
18124454Smckusick 				 * commas */
18224454Smckusick     int         ljust_decl;	/* true if declarations should be left
18324454Smckusick 				 * justified */
18424454Smckusick     int         out_coms;	/* the number of comments processed, set
18524454Smckusick 				 * by pr_comment */
18624454Smckusick     int         out_lines;	/* the number of lines written, set by
18724454Smckusick 				 * dump_line */
18824454Smckusick     int         p_l_follow;	/* used to remember how to indent
18924454Smckusick 				 * following statement */
19024454Smckusick     int         paren_level;	/* parenthesization level. used to indent
19124454Smckusick 				 * within stmts */
19224454Smckusick     short       paren_indents[20];	/* column positions of each paren */
19324454Smckusick     int         pcase;		/* set to 1 if the current line label is a
19424454Smckusick 				 * case.  It is printed differently from
19524454Smckusick 				 * a regular label */
19624454Smckusick     int         search_brace;	/* set to true by parse when it is
19724454Smckusick 				 * necessary to buffer up all info up to
19824454Smckusick 				 * the start of a stmt after an if, while,
19924454Smckusick 				 * etc */
20024454Smckusick     int         unindent_displace;	/* comments not to the right of
20124454Smckusick 					 * code will be placed this many
20224454Smckusick 					 * indentation levels to the left
20324454Smckusick 					 * of code */
20424454Smckusick     int         use_ff;		/* set to one if the current line should
20524454Smckusick 				 * be terminated with a form feed */
20624454Smckusick     int         want_blank;	/* set to true when the following token
20724454Smckusick 				 * should be prefixed by a blank. (Said
20824454Smckusick 				 * prefixing is ignored in some cases.) */
20924454Smckusick     int         else_if;	/* True iff else if pairs should be
21024454Smckusick 				 * handled specially */
21124454Smckusick     int         decl_indent;	/* column to indent declared identifiers
21224454Smckusick 				 * to */
21324454Smckusick     int         its_a_keyword;
21424454Smckusick     int		sizeof_keyword;
21524454Smckusick     int         dumped_decl_indent;
21624454Smckusick     float       case_indent;	/* The distance to indent case labels from
21724454Smckusick 				 * the switch statement */
21824454Smckusick     int         in_parameter_declaration;
21924454Smckusick     int         indent_parameters;
22024454Smckusick     int         tos;		/* pointer to top of stack */
22124454Smckusick     char        procname[100];	/* The name of the current procedure */
22224454Smckusick     int		just_saw_decl;
22324454Smckusick }           ps;
22424454Smckusick 
22524454Smckusick int ifdef_level;
22624454Smckusick struct parser_state state_stack[5];
22724454Smckusick struct parser_state match_state[5];
228