home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / INDENTSR.ZIP / GLOBALS.H < prev    next >
C/C++ Source or Header  |  1992-08-27  |  12KB  |  319 lines

  1. /*
  2.  * Copyright 1989 Object Design, Inc.
  3.  * Copyright (c) 1985 Sun Microsystems, Inc.
  4.  * Copyright (c) 1980 The Regents of the University of California.
  5.  * Copyright (c) 1976 Board of Trustees of the University of Illinois.
  6.  * All rights reserved.
  7.  *
  8.  * Redistribution and use in source and binary forms are permitted
  9.  * provided that the above copyright notice and this paragraph are
  10.  * duplicated in all such forms and that any documentation,
  11.  * advertising materials, and other materials related to such
  12.  * distribution and use acknowledge that the software was developed
  13.  * by the University of California, Berkeley, the University of Illinois,
  14.  * Urbana, and Sun Microsystems, Inc.  The name of either University
  15.  * or Sun Microsystems may not be used to endorse or promote products
  16.  * derived from this software without specific prior written permission.
  17.  * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  19.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20.  *
  21.  *  @(#)indent_globs.h    5.7 (Berkeley) 15 sep 88
  22.  */
  23.  
  24. #include <stdio.h>
  25. #include <memory.h>            /* gst: 24 mar 89 */
  26.  
  27. #define BACKSLASH '\\'
  28. #define bufsize 1000            /* size of internal buffers */
  29. #define inp_bufs 600            /* size of input buffer */
  30. #define sc_size 5000            /* size of save_com buffer */
  31. #define label_offset 2            /* number of levels a label is placed
  32.                      * to left of code */
  33. #define cplus_ppp_indent 2        /* spaces to indent public, private,
  34.                      * protected in c++ */
  35.  
  36. #define false 0
  37. #define true  1
  38.  
  39.  
  40. FILE *input;                /* the fid for the input file */
  41. FILE *output;                /* the output file */
  42.  
  43. #ifdef MSDOS
  44. #define check_size(name) \
  45.     if (e_##name >= l_##name) { \
  46.     register nsize = l_##name-s_##name+400; \
  47.     name##buf = (char *) realloc(name##buf, nsize); \
  48.     e_##name = name##buf + (e_##name-s_##name) + 1; \
  49.     l_##name = name##buf + nsize - 5; \
  50.     s_##name = name##buf + 1; \
  51.     }
  52. #else
  53. #define check_size(name) \
  54.     if (e_/**/name >= l_/**/name) { \
  55.     register nsize = l_/**/name-s_/**/name+400; \
  56.     name/**/buf = (char *) realloc(name/**/buf, nsize); \
  57.     e_/**/name = name/**/buf + (e_/**/name-s_/**/name) + 1; \
  58.     l_/**/name = name/**/buf + nsize - 5; \
  59.     s_/**/name = name/**/buf + 1; \
  60.     }
  61. #endif
  62.  
  63. char *labbuf;                /* buffer for label */
  64. char *s_lab;                /* start ... */
  65. char *e_lab;                /* .. and end of stored label */
  66. char *l_lab;                /* limit of label buffer */
  67.  
  68. char *codebuf;                /* buffer for code section */
  69. char *s_code;                /* start ... */
  70. char *e_code;                /* .. and end of stored code */
  71. char *l_code;                /* limit of code section */
  72.  
  73. char *combuf;                /* buffer for comments */
  74. char *s_com;                /* start ... */
  75. char *e_com;                /* ... and end of stored comments */
  76. char *l_com;                /* limit of comment buffer */
  77.  
  78. char in_buffer[inp_bufs];        /* input buffer */
  79. char *buf_ptr;                /* ptr to next character to be taken
  80.                      * from in_buffer */
  81. char *buf_end;                /* ptr to first after last char in
  82.                      * in_buffer */
  83.  
  84. char save_com[sc_size];            /* input text is saved here when
  85.                      * looking for the brace after an if,
  86.                      * while, etc */
  87. char *sc_end;                /* pointer into save_com buffer */
  88.  
  89. char *bp_save;                /* saved value of buf_ptr when taking
  90.                      * input from save_com */
  91. char *be_save;                /* similarly saved value of buf_end */
  92.  
  93. char token[bufsize];            /* the last token scanned */
  94.  
  95. int cplus;                /* c++ */
  96. int pointer_as_binop;
  97. int blanklines_after_declarations;
  98. int blanklines_before_blockcomments;
  99. int blanklines_after_procs;
  100. int blanklines_around_conditional_compilation;
  101. int swallow_optional_blanklines;
  102. int n_real_blanklines;
  103. int prefix_blankline_requested;
  104. int postfix_blankline_requested;
  105.  
  106. int tabsize;
  107.  
  108. int break_comma;            /* when true and not in parens, break
  109.                      * after a comma */
  110. int btype_2;                /* when true, brace should be on same
  111.                      * line as if, while, etc */
  112. int btype_3;                /* when true, braces are not only on
  113.                      * the next line but indented with
  114.                      * the enclosed code */
  115. float case_ind;                /* indentation level to be used for a
  116.                      * "case n:" */
  117. int code_lines;                /* count of lines with code */
  118. int had_eof;                /* set to true when input is
  119.                      * exhausted */
  120. int line_no;                /* the current line number. */
  121. int max_col;                /* the maximum allowable line length */
  122. int verbose;                /* when true, non-essential error
  123.                      * messages are printed */
  124. int cuddle_else;            /* true if else should cuddle up to
  125.                      * '}' */
  126. int star_comment_cont;            /* true iff comment continuation
  127.                      * lines should have stars at the
  128.                      * beginning of each line. */
  129. int comment_delimiter_on_blankline;
  130. int troff;                /* true iff were generating troff
  131.                      * input */
  132. int procnames_start_line;        /* if true, the names of procedures
  133.                      * being defined get placed in column
  134.                      * 1 (ie. a newline is placed between
  135.                      * the type of the procedure and its
  136.                      * name) */
  137. int proc_calls_space;            /* If true, procedure calls look
  138.                      * like: foo(bar) rather than foo
  139.                      * (bar) */
  140. int parens_space;            /* If true, parens gets spaces inside
  141.                      * them */
  142. int format_col1_comments;        /* If comments which start in column
  143.                      * 1 are to be magically reformatted
  144.                      * (just like comments that begin in
  145.                      * later columns) */
  146. int inhibit_formatting;            /* true if INDENT OFF is in effect */
  147. int suppress_blanklines;        /* set iff following blanklines
  148.                      * should be suppressed */
  149. int continuation_indent;        /* set to the indentation between the
  150.                      * edge of code and continuation
  151.                      * lines */
  152. int lineup_to_parens;            /* if true, continued code within
  153.                      * parens will be lined up to the
  154.                      * open paren */
  155. int Bill_Shannon;            /* true iff a blank should always be
  156.                      * inserted after sizeof */
  157. int blanklines_after_declarations_at_proctop;    /* This is vaguely similar to
  158.                          * blanklines_after_decla
  159.                          * rations except that it
  160.                          * only applies to the first
  161.                          * set of declarations in a
  162.                          * procedure (just after the
  163.                          * first '{') and it causes a
  164.                          * blank line to be generated
  165.                          * even if there are no
  166.                          * declarations */
  167. int block_comment_max_col;
  168. int extra_expression_indent;        /* True if continuation lines from
  169.                      * the expression part of "if(e)",
  170.                      * "while(e)", "for(e;e;e)" should be
  171.                      * indented an extra tab stop so that
  172.                      * they don't conflict with the code
  173.                      * that follows */
  174.  
  175. /* -troff font state information */
  176.  
  177. struct fstate {
  178.     char font[4];
  179.     char size;
  180.     int allcaps:1;
  181. };
  182. char *chfont();
  183.  
  184. struct fstate
  185.  keywordf,                /* keyword font */
  186.  stringf,                /* string font */
  187.  boxcomf,                /* Box comment font */
  188.  blkcomf,                /* Block comment font */
  189.  scomf,                    /* Same line comment font */
  190.  bodyf;                    /* major body font */
  191.  
  192.  
  193. #define STACKSIZE 150
  194.  
  195. struct parser_state {
  196.     int last_token;
  197.     struct fstate cfont;        /* Current font */
  198.     int p_stack[STACKSIZE];        /* this is the parsers stack */
  199.     int il[STACKSIZE];            /* this stack stores indentation
  200.                      * levels */
  201.     float cstk[STACKSIZE];        /* used to store case stmt
  202.                      * indentation levels */
  203.     int box_com;            /* set to true when we are in a
  204.                      * "boxed" comment. In that case, the
  205.                      * first non-blank char should be
  206.                      * lined up with the / in '/-*' */
  207.     int comment_delta, n_comment_delta;
  208.     int cast_mask;            /* indicates which close parens close
  209.                      * off casts */
  210.     int sizeof_mask;            /* indicates which close parens close
  211.                      * off sizeof''s */
  212.     int block_init;            /* true iff inside a block
  213.                      * initialization */
  214.     int block_init_level;        /* The level of brace nesting in an
  215.                      * initialization */
  216.     int last_nl;            /* this is true if the last thing
  217.                      * scanned was a newline */
  218.     int in_or_st;            /* Will be true iff there has been a
  219.                      * declarator (e.g. int or char) and
  220.                      * no left paren since the last
  221.                      * semicolon. When true, a '{' is
  222.                      * starting a structure definition or
  223.                      * an initialization list */
  224.     int bl_line;            /* set to 1 by dump_line if the line
  225.                      * is blank */
  226.     int col_1;                /* set to true if the last token
  227.                      * started in column 1 */
  228.     int com_col;            /* this is the column in which the
  229.                      * current coment should start */
  230.     int com_ind;            /* the column in which comments to
  231.                      * the right of code should start */
  232.     int com_lines;            /* the number of lines with comments,
  233.                      * set by dump_line */
  234.     int dec_nest;            /* current nesting level for
  235.                      * structure or init */
  236.     int decl_com_ind;            /* the column in which comments after
  237.                      * declarations should be put */
  238.     int decl_on_line;            /* set to true if this line of code
  239.                      * has part of a declaration on it */
  240.     int i_l_follow;            /* the level to which ind_level
  241.                      * should be set after the current
  242.                      * line is printed */
  243.     int in_decl;            /* set to true when we are in a
  244.                      * declaration stmt.  The processing
  245.                      * of braces is then slightly
  246.                      * different */
  247.     int in_stmt;            /* set to 1 while in a stmt */
  248.     int ind_level;            /* the current indentation level */
  249.     int ind_size;            /* the size of one indentation level */
  250.     int ind_stmt;            /* set to 1 if next line should have
  251.                      * an extra indentation level because
  252.                      * we are in the middle of a stmt */
  253.     int last_u_d;            /* set to true after scanning a token
  254.                      * which forces a following operator
  255.                      * to be unary */
  256.     int leave_comma;            /* if true, never break declarations
  257.                      * after commas */
  258.     int ljust_decl;            /* true if declarations should be
  259.                      * left justified */
  260.     int out_coms;            /* the number of comments processed,
  261.                      * set by pr_comment */
  262.     int out_lines;            /* the number of lines written, set
  263.                      * by dump_line */
  264.     int p_l_follow;            /* used to remember how to indent
  265.                      * following statement */
  266.     int paren_level;            /* parenthesization level. used to
  267.                      * indent within stmts */
  268.     short paren_indents[20];        /* column positions of each paren */
  269.     int pcase;                /* set to 1 if the current line label
  270.                      * is a case.  It is printed
  271.                      * differently from a regular label */
  272.     int search_brace;            /* set to true by parse when it is
  273.                      * necessary to buffer up all info up
  274.                      * to the start of a stmt after an
  275.                      * if, while, etc */
  276.     int unindent_displace;        /* comments not to the right of code
  277.                      * will be placed this many
  278.                      * indentation levels to the left of
  279.                      * code */
  280.     int use_ff;                /* set to one if the current line
  281.                      * should be terminated with a form
  282.                      * feed */
  283.     int want_blank;            /* set to true when the following
  284.                      * token should be prefixed by a
  285.                      * blank. (Said prefixing is ignored
  286.                      * in some cases.) */
  287.     int else_if;            /* True iff else if pairs should be
  288.                      * handled specially */
  289.     int decl_indent;            /* column to indent declared
  290.                      * identifiers to */
  291.     int its_a_keyword;
  292.     int sizeof_keyword;
  293.     int dumped_decl_indent;
  294.     float case_indent;            /* The distance to indent case labels
  295.                      * from the switch statement */
  296.     float case_code_indent;        /* The distance to indent case code
  297.                      * from the case label */
  298.     int in_parameter_declaration;
  299.     int indent_parameters;
  300.     int tos;                /* pointer to top of stack */
  301.     char procname[100];            /* The name of the current procedure */
  302.     int just_saw_decl;
  303.     int cc_comment;            /* saw a C++ comment ("//...") */
  304. } ps;
  305.  
  306. int ifdef_level;
  307. struct parser_state state_stack[5];
  308. struct parser_state match_state[5];
  309.  
  310. typedef enum cplus_flag {
  311.     c_only,
  312.     c_and_cplus,
  313.     cplus_only
  314. } cplus_flag;
  315.  
  316. #ifdef ANSIC
  317. #include "proto.h"
  318. #endif
  319.