home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / utilities / utilsf / indent / Source / h / indntglobs < prev   
Text File  |  1995-10-30  |  13KB  |  297 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) 9/15/88
  22.  */
  23.  
  24. /* Archimedes port by Steven Flintham
  25.    Wednesday 25th October 1995
  26.    Friday 27th October 1995
  27.    Saturday 28th October 1995
  28.    Monday 30th October 1995 */
  29.  
  30. /* SF: None of the external variables declared in this file had the extern
  31.    keyword prefixing them. See the accompanying documentation for more
  32.    details. */
  33.  
  34. #include <stdio.h>
  35. #ifndef __riscos /* SF */
  36. #include <memory.h>        /* gst: 3/24/89 */
  37. #endif /* __riscos */
  38.  
  39. #define BACKSLASH '\\'
  40. #define bufsize 200        /* size of internal buffers */
  41. #define inp_bufs 600        /* size of input buffer */
  42. #define sc_size 5000        /* size of save_com buffer */
  43. #define label_offset 2        /* number of levels a label is placed to left
  44.                  * of code */
  45. #define cplus_ppp_indent 2      /* spaces to indent public, private, protected in c++ */
  46.  
  47. #define tabsize 8        /* the size of a tab */
  48. #define tabmask 0177770        /* mask used when figuring length of lines
  49.                  * with tabs */
  50.  
  51.  
  52. #define false 0
  53. #define true  1
  54.  
  55.  
  56. extern FILE       *input;        /* the fid for the input file */
  57. extern FILE       *output;        /* the output file */
  58.  
  59. /* SF: changed to use ## */
  60. #define check_size(name) \
  61.     if (e_##name >= l_##name) { \
  62.         register nsize = l_##name-s_##name+400; \
  63.         name##buf = (char *) realloc(name##buf, nsize); \
  64.         e_##name = name##buf + (e_##name-s_##name) + 1; \
  65.         l_##name = name##buf + nsize - 5; \
  66.         s_##name = name##buf + 1; \
  67.     }
  68.  
  69. extern char       *labbuf;        /* buffer for label */
  70. extern char       *s_lab;        /* start ... */
  71. extern char       *e_lab;        /* .. and end of stored label */
  72. extern char       *l_lab;        /* limit of label buffer */
  73.  
  74. extern char       *codebuf;        /* buffer for code section */
  75. extern char       *s_code;        /* start ... */
  76. extern char       *e_code;        /* .. and end of stored code */
  77. extern char       *l_code;        /* limit of code section */
  78.  
  79. extern char       *combuf;        /* buffer for comments */
  80. extern char       *s_com;        /* start ... */
  81. extern char       *e_com;        /* ... and end of stored comments */
  82. extern char       *l_com;        /* limit of comment buffer */
  83.  
  84. extern char        in_buffer[inp_bufs];/* input buffer */
  85. extern char       *buf_ptr;        /* ptr to next character to be taken from
  86.                  * in_buffer */
  87. extern char       *buf_end;        /* ptr to first after last char in in_buffer */
  88.  
  89. extern char        save_com[sc_size];    /* input text is saved here when looking for
  90.                  * the brace after an if, while, etc */
  91. extern char       *sc_end;        /* pointer into save_com buffer */
  92.  
  93. extern char       *bp_save;        /* saved value of buf_ptr when taking input
  94.                  * from save_com */
  95. extern char       *be_save;        /* similarly saved value of buf_end */
  96.  
  97. extern char        token[bufsize];    /* the last token scanned */
  98.  
  99. extern int         cplus;        /* c++ */
  100. extern int         pointer_as_binop;
  101. extern int         blanklines_after_declarations;
  102. extern int         blanklines_before_blockcomments;
  103. extern int         blanklines_after_procs;
  104. extern int         blanklines_around_conditional_compilation;
  105. extern int         swallow_optional_blanklines;
  106. extern int         n_real_blanklines;
  107. extern int         prefix_blankline_requested;
  108. extern int         postfix_blankline_requested;
  109. extern int         break_comma;    /* when true and not in parens, break after a
  110.                  * comma */
  111. extern int         btype_2;        /* when true, brace should be on same line as
  112.                  * if, while, etc */
  113. extern int         btype_3;        /* when true, braces are not only on the next
  114.                  * line but indented with the enclosed code */
  115. extern float       case_ind;        /* indentation level to be used for a "case
  116.                  * n:" */
  117. extern int         code_lines;        /* count of lines with code */
  118. extern int         had_eof;        /* set to true when input is exhausted */
  119. extern int         line_no;        /* the current line number. */
  120. extern int         max_col;        /* the maximum allowable line length */
  121. extern int         verbose;        /* when true, non-essential error messages are
  122.                  * printed */
  123. extern int         cuddle_else;    /* true if else should cuddle up to '}' */
  124. extern int         star_comment_cont;    /* true iff comment continuation lines should
  125.                  * have stars at the beginning of each line. */
  126. extern int         comment_delimiter_on_blankline;
  127. extern int         troff;        /* true iff were generating troff input */
  128. extern int         procnames_start_line;    /* if true, the names of procedures
  129.                      * being defined get placed in column
  130.                      * 1 (ie. a newline is placed between
  131.                      * the type of the procedure and its
  132.                      * name) */
  133. extern int         proc_calls_space;    /* If true, procedure calls look like:
  134.                  * foo(bar) rather than foo (bar) */
  135. extern int         parens_space;    /* If true, parens gets spaces inside them */
  136. extern int         format_col1_comments;    /* If comments which start in column 1
  137.                      * are to be magically reformatted
  138.                      * (just like comments that begin in
  139.                      * later columns) */
  140. extern int         inhibit_formatting;    /* true if INDENT OFF is in effect */
  141. extern int         suppress_blanklines;/* set iff following blanklines should be
  142.                  * suppressed */
  143. extern int         continuation_indent;/* set to the indentation between the edge of
  144.                  * code and continuation lines */
  145. extern int         lineup_to_parens;    /* if true, continued code within parens will
  146.                  * be lined up to the open paren */
  147. extern int         Bill_Shannon;    /* true iff a blank should always be inserted
  148.                  * after sizeof */
  149. extern int         blanklines_after_declarations_at_proctop;    /* This is vaguely
  150.                              * similar to
  151.                              * blanklines_after_decla
  152.                              * rations except that
  153.                              * it only applies to
  154.                              * the first set of
  155.                              * declarations in a
  156.                              * procedure (just after
  157.                              * the first '{') and it
  158.                              * causes a blank line
  159.                              * to be generated even
  160.                              * if there are no
  161.                              * declarations */
  162. extern int         block_comment_max_col;
  163. extern int         extra_expression_indent;    /* True if continuation lines from the
  164.                      * 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.     char        font[4];
  174.     char        size;
  175.     int         allcaps:1;
  176. };
  177. extern char       *chfont();
  178.  
  179. extern struct fstate
  180.             keywordf,        /* keyword font */
  181.             stringf,        /* string font */
  182.             boxcomf,        /* Box comment font */
  183.             blkcomf,        /* Block comment font */
  184.             scomf,        /* Same line comment font */
  185.             bodyf;        /* major body font */
  186.  
  187.  
  188. #define STACKSIZE 150
  189.  
  190. extern struct parser_state {
  191.     int         last_token;
  192.     struct fstate cfont;    /* Current font */
  193.     int         p_stack[STACKSIZE];    /* this is the parsers stack */
  194.     int         il[STACKSIZE];    /* this stack stores indentation levels */
  195.     float       cstk[STACKSIZE];/* used to store case stmt indentation levels */
  196.     int         box_com;    /* set to true when we are in a "boxed"
  197.                  * comment. In that case, the first non-blank
  198.                  * char should be lined up with the / in /* */
  199.