home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Archive / OS2_Archive_CD-ROM_Walnut_Creek_May_1992.iso / novell / progrmng / indent.zoo / globs.h < prev    next >
C/C++ Source or Header  |  1989-10-30  |  13KB  |  304 lines

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