121975Sdist /* 235500Sbostic * Copyright (c) 1985 Sun Microsystems, Inc. 3*62038Sbostic * Copyright (c) 1980, 1993 4*62038Sbostic * The Regents of the University of California. All rights reserved. 533767Sbostic * All rights reserved. 621975Sdist * 742688Sbostic * %sccs.include.redist.c% 833767Sbostic * 9*62038Sbostic * @(#)indent_globs.h 8.1 (Berkeley) 06/06/93 1021975Sdist */ 118802Smckusick 1224454Smckusick #define BACKSLASH '\\' 1335500Sbostic #define bufsize 200 /* size of internal buffers */ 1435500Sbostic #define sc_size 5000 /* size of save_com buffer */ 1535500Sbostic #define label_offset 2 /* number of levels a label is placed to left 1635500Sbostic * of code */ 178802Smckusick 1835500Sbostic #define tabsize 8 /* the size of a tab */ 1935500Sbostic #define tabmask 0177770 /* mask used when figuring length of lines 2035500Sbostic * with tabs */ 218802Smckusick 228802Smckusick 238802Smckusick #define false 0 248802Smckusick #define true 1 258802Smckusick 268802Smckusick 2735500Sbostic FILE *input; /* the fid for the input file */ 2835500Sbostic FILE *output; /* the output file */ 298802Smckusick 3040275Sbostic #define CHECK_SIZE_CODE \ 3140275Sbostic if (e_code >= l_code) { \ 3240275Sbostic register nsize = l_code-s_code+400; \ 3340275Sbostic codebuf = (char *) realloc(codebuf, nsize); \ 3440275Sbostic e_code = codebuf + (e_code-s_code) + 1; \ 3540275Sbostic l_code = codebuf + nsize - 5; \ 3640275Sbostic s_code = codebuf + 1; \ 3735500Sbostic } 3840275Sbostic #define CHECK_SIZE_COM \ 3940275Sbostic if (e_com >= l_com) { \ 4040275Sbostic register nsize = l_com-s_com+400; \ 4140275Sbostic combuf = (char *) realloc(combuf, nsize); \ 4240275Sbostic e_com = combuf + (e_com-s_com) + 1; \ 4340275Sbostic l_com = combuf + nsize - 5; \ 4440275Sbostic s_com = combuf + 1; \ 4540275Sbostic } 4640275Sbostic #define CHECK_SIZE_LAB \ 4740275Sbostic if (e_lab >= l_lab) { \ 4840275Sbostic register nsize = l_lab-s_lab+400; \ 4940275Sbostic labbuf = (char *) realloc(labbuf, nsize); \ 5040275Sbostic e_lab = labbuf + (e_lab-s_lab) + 1; \ 5140275Sbostic l_lab = labbuf + nsize - 5; \ 5240275Sbostic s_lab = labbuf + 1; \ 5340275Sbostic } 5440275Sbostic #define CHECK_SIZE_TOKEN \ 5540275Sbostic if (e_token >= l_token) { \ 5640275Sbostic register nsize = l_token-s_token+400; \ 5740275Sbostic tokenbuf = (char *) realloc(tokenbuf, nsize); \ 5840275Sbostic e_token = tokenbuf + (e_token-s_token) + 1; \ 5940275Sbostic l_token = tokenbuf + nsize - 5; \ 6040275Sbostic s_token = tokenbuf + 1; \ 6140275Sbostic } 628802Smckusick 6335500Sbostic char *labbuf; /* buffer for label */ 6435500Sbostic char *s_lab; /* start ... */ 6535500Sbostic char *e_lab; /* .. and end of stored label */ 6635500Sbostic char *l_lab; /* limit of label buffer */ 678802Smckusick 6835500Sbostic char *codebuf; /* buffer for code section */ 6935500Sbostic char *s_code; /* start ... */ 7035500Sbostic char *e_code; /* .. and end of stored code */ 7135500Sbostic char *l_code; /* limit of code section */ 728802Smckusick 7335500Sbostic char *combuf; /* buffer for comments */ 7435500Sbostic char *s_com; /* start ... */ 7535500Sbostic char *e_com; /* ... and end of stored comments */ 7635500Sbostic char *l_com; /* limit of comment buffer */ 778802Smckusick 7838011Sbostic #define token s_token 7938011Sbostic char *tokenbuf; /* the last token scanned */ 8038011Sbostic char *s_token; 8138011Sbostic char *e_token; 8238011Sbostic char *l_token; 8338011Sbostic 8438011Sbostic char *in_buffer; /* input buffer */ 8538011Sbostic char *in_buffer_limit; /* the end of the input buffer */ 8635500Sbostic char *buf_ptr; /* ptr to next character to be taken from 8735500Sbostic * in_buffer */ 8835500Sbostic char *buf_end; /* ptr to first after last char in in_buffer */ 898802Smckusick 9035500Sbostic char save_com[sc_size]; /* input text is saved here when looking for 9135500Sbostic * the brace after an if, while, etc */ 9235500Sbostic char *sc_end; /* pointer into save_com buffer */ 938802Smckusick 9435500Sbostic char *bp_save; /* saved value of buf_ptr when taking input 9535500Sbostic * from save_com */ 9635500Sbostic char *be_save; /* similarly saved value of buf_end */ 978802Smckusick 988802Smckusick 9935500Sbostic int pointer_as_binop; 10035500Sbostic int blanklines_after_declarations; 10135500Sbostic int blanklines_before_blockcomments; 10235500Sbostic int blanklines_after_procs; 10335500Sbostic int blanklines_around_conditional_compilation; 10435500Sbostic int swallow_optional_blanklines; 10535500Sbostic int n_real_blanklines; 10635500Sbostic int prefix_blankline_requested; 10735500Sbostic int postfix_blankline_requested; 10835500Sbostic int break_comma; /* when true and not in parens, break after a 10935500Sbostic * comma */ 11035500Sbostic int btype_2; /* when true, brace should be on same line as 11135500Sbostic * if, while, etc */ 11235500Sbostic float case_ind; /* indentation level to be used for a "case 11335500Sbostic * n:" */ 11435500Sbostic int code_lines; /* count of lines with code */ 11535500Sbostic int had_eof; /* set to true when input is exhausted */ 11635500Sbostic int line_no; /* the current line number. */ 11735500Sbostic int max_col; /* the maximum allowable line length */ 11835500Sbostic int verbose; /* when true, non-essential error messages are 11935500Sbostic * printed */ 12035500Sbostic int cuddle_else; /* true if else should cuddle up to '}' */ 12135500Sbostic int star_comment_cont; /* true iff comment continuation lines should 12235500Sbostic * have stars at the beginning of each line. */ 12335500Sbostic int comment_delimiter_on_blankline; 12435500Sbostic int troff; /* true iff were generating troff input */ 12535500Sbostic int procnames_start_line; /* if true, the names of procedures 12635500Sbostic * being defined get placed in column 12735500Sbostic * 1 (ie. a newline is placed between 12835500Sbostic * the type of the procedure and its 12935500Sbostic * name) */ 13035500Sbostic int proc_calls_space; /* If true, procedure calls look like: 13135500Sbostic * foo(bar) rather than foo (bar) */ 13235500Sbostic int format_col1_comments; /* If comments which start in column 1 13335500Sbostic * are to be magically reformatted 13435500Sbostic * (just like comments that begin in 13535500Sbostic * later columns) */ 13635500Sbostic int inhibit_formatting; /* true if INDENT OFF is in effect */ 13735500Sbostic int suppress_blanklines;/* set iff following blanklines should be 13835500Sbostic * suppressed */ 13935500Sbostic int continuation_indent;/* set to the indentation between the edge of 14035500Sbostic * code and continuation lines */ 14135500Sbostic int lineup_to_parens; /* if true, continued code within parens will 14235500Sbostic * be lined up to the open paren */ 14335500Sbostic int Bill_Shannon; /* true iff a blank should always be inserted 14435500Sbostic * after sizeof */ 14535500Sbostic int blanklines_after_declarations_at_proctop; /* This is vaguely 14635500Sbostic * similar to 14735500Sbostic * blanklines_after_decla 14835500Sbostic * rations except that 14935500Sbostic * it only applies to 15035500Sbostic * the first set of 15135500Sbostic * declarations in a 15235500Sbostic * procedure (just after 15335500Sbostic * the first '{') and it 15435500Sbostic * causes a blank line 15535500Sbostic * to be generated even 15635500Sbostic * if there are no 15735500Sbostic * declarations */ 15835500Sbostic int block_comment_max_col; 15935500Sbostic int extra_expression_indent; /* True if continuation lines from the 16035500Sbostic * expression part of "if(e)", 16135500Sbostic * "while(e)", "for(e;e;e)" should be 16235500Sbostic * indented an extra tab stop so that 16335500Sbostic * they don't conflict with the code 16435500Sbostic * that follows */ 16524454Smckusick 16635500Sbostic /* -troff font state information */ 16724454Smckusick 16835500Sbostic struct fstate { 16935500Sbostic char font[4]; 17035500Sbostic char size; 17135500Sbostic int allcaps:1; 17235500Sbostic }; 17335500Sbostic char *chfont(); 17435500Sbostic 17535500Sbostic struct fstate 17635500Sbostic keywordf, /* keyword font */ 17735500Sbostic stringf, /* string font */ 17835500Sbostic boxcomf, /* Box comment font */ 17935500Sbostic blkcomf, /* Block comment font */ 18035500Sbostic scomf, /* Same line comment font */ 18135500Sbostic bodyf; /* major body font */ 18235500Sbostic 18335500Sbostic 18435500Sbostic #define STACKSIZE 150 18535500Sbostic 18624454Smckusick struct parser_state { 18724454Smckusick int last_token; 18835500Sbostic struct fstate cfont; /* Current font */ 18935500Sbostic int p_stack[STACKSIZE]; /* this is the parsers stack */ 19035500Sbostic int il[STACKSIZE]; /* this stack stores indentation levels */ 19135500Sbostic float cstk[STACKSIZE];/* used to store case stmt indentation levels */ 19224454Smckusick int box_com; /* set to true when we are in a "boxed" 19335500Sbostic * comment. In that case, the first non-blank 19435500Sbostic * char should be lined up with the / in /* */ 19524454Smckusick int comment_delta, 19624454Smckusick n_comment_delta; 19724454Smckusick int cast_mask; /* indicates which close parens close off 19824454Smckusick * casts */ 19935500Sbostic int sizeof_mask; /* indicates which close parens close off 20035500Sbostic * sizeof''s */ 20124454Smckusick int block_init; /* true iff inside a block initialization */ 20235500Sbostic int block_init_level; /* The level of brace nesting in an 20335500Sbostic * initialization */ 20435500Sbostic int last_nl; /* this is true if the last thing scanned was 20535500Sbostic * a newline */ 20624454Smckusick int in_or_st; /* Will be true iff there has been a 20735500Sbostic * declarator (e.g. int or char) and no left 20835500Sbostic * paren since the last semicolon. When true, 20935500Sbostic * a '{' is starting a structure definition or 21035500Sbostic * an initialization list */ 21135500Sbostic int bl_line; /* set to 1 by dump_line if the line is blank */ 21235500Sbostic int col_1; /* set to true if the last token started in 21335500Sbostic * column 1 */ 21424454Smckusick int com_col; /* this is the column in which the current 21524454Smckusick * coment should start */ 21635500Sbostic int com_ind; /* the column in which comments to the right 21735500Sbostic * of code should start */ 21835500Sbostic int com_lines; /* the number of lines with comments, set by 21935500Sbostic * dump_line */ 22035500Sbostic int dec_nest; /* current nesting level for structure or init */ 22124454Smckusick int decl_com_ind; /* the column in which comments after 22224454Smckusick * declarations should be put */ 22335500Sbostic int decl_on_line; /* set to true if this line of code has part 22435500Sbostic * of a declaration on it */ 22535500Sbostic int i_l_follow; /* the level to which ind_level should be set 22635500Sbostic * after the current line is printed */ 22735500Sbostic int in_decl; /* set to true when we are in a declaration 22835500Sbostic * stmt. The processing of braces is then 22935500Sbostic * slightly different */ 23024454Smckusick int in_stmt; /* set to 1 while in a stmt */ 23124454Smckusick int ind_level; /* the current indentation level */ 23224454Smckusick int ind_size; /* the size of one indentation level */ 23335500Sbostic int ind_stmt; /* set to 1 if next line should have an extra 23435500Sbostic * indentation level because we are in the 23535500Sbostic * middle of a stmt */ 23635500Sbostic int last_u_d; /* set to true after scanning a token which 23735500Sbostic * forces a following operator to be unary */ 23824454Smckusick int leave_comma; /* if true, never break declarations after 23924454Smckusick * commas */ 24024454Smckusick int ljust_decl; /* true if declarations should be left 24124454Smckusick * justified */ 24235500Sbostic int out_coms; /* the number of comments processed, set by 24335500Sbostic * pr_comment */ 24424454Smckusick int out_lines; /* the number of lines written, set by 24524454Smckusick * dump_line */ 24635500Sbostic int p_l_follow; /* used to remember how to indent following 24735500Sbostic * statement */ 24824454Smckusick int paren_level; /* parenthesization level. used to indent 24924454Smckusick * within stmts */ 25024454Smckusick short paren_indents[20]; /* column positions of each paren */ 25124454Smckusick int pcase; /* set to 1 if the current line label is a 25235500Sbostic * case. It is printed differently from a 25335500Sbostic * regular label */ 25435500Sbostic int search_brace; /* set to true by parse when it is necessary 25535500Sbostic * to buffer up all info up to the start of a 25635500Sbostic * stmt after an if, while, etc */ 25735500Sbostic int unindent_displace; /* comments not to the right of code 25835500Sbostic * will be placed this many 25935500Sbostic * indentation levels to the left of 26035500Sbostic * code */ 26135500Sbostic int use_ff; /* set to one if the current line should be 26235500Sbostic * terminated with a form feed */ 26335500Sbostic int want_blank; /* set to true when the following token should 26435500Sbostic * be prefixed by a blank. (Said prefixing is 26535500Sbostic * ignored in some cases.) */ 26635500Sbostic int else_if; /* True iff else if pairs should be handled 26735500Sbostic * specially */ 26835500Sbostic int decl_indent; /* column to indent declared identifiers to */ 26924454Smckusick int its_a_keyword; 27035500Sbostic int sizeof_keyword; 27124454Smckusick int dumped_decl_indent; 27235500Sbostic float case_indent; /* The distance to indent case labels from the 27335500Sbostic * switch statement */ 27424454Smckusick int in_parameter_declaration; 27524454Smckusick int indent_parameters; 27624454Smckusick int tos; /* pointer to top of stack */ 27724454Smckusick char procname[100]; /* The name of the current procedure */ 27835500Sbostic int just_saw_decl; 27924454Smckusick } ps; 28024454Smckusick 28135500Sbostic int ifdef_level; 28238011Sbostic int rparen_count; 28324454Smckusick struct parser_state state_stack[5]; 28424454Smckusick struct parser_state match_state[5]; 285