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