home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / SOFTWARE / SOURCES / INDE11AS.ZIP / INDENT_G.H (.txt) < prev    next >
C/C++ Source or Header  |  1992-02-22  |  19KB  |  517 lines

  1. /*
  2.  * Copyright (c) 1985 Sun Microsystems, Inc.
  3.  * Copyright (c) 1980 The Regents of the University of California.
  4.  * Copyright (c) 1976 Board of Trustees of the University of Illinois.
  5.  * All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms are permitted
  8.  * provided that the above copyright notice and this paragraph are
  9.  * duplicated in all such forms and that any documentation,
  10.  * advertising materials, and other materials related to such
  11.  * distribution and use acknowledge that the software was developed
  12.  * by the University of California, Berkeley, the University of Illinois,
  13.  * Urbana, and Sun Microsystems, Inc.  The name of either University
  14.  * or Sun Microsystems may not be used to endorse or promote products
  15.  * derived from this software without specific prior written permission.
  16.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  17.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  18.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  19.  *
  20.  *    @(#)indent_globs.h    5.7 (Berkeley) 9/15/88
  21.  */
  22.  
  23. /*
  24.  * MS-DOS port (c) 1990 by Thorsten Ohl, ohl@gnu.ai.mit.edu
  25.  *
  26.  * To this port, the same copying conditions apply as to the
  27.  * original release.
  28.  *
  29.  * IMPORTANT:
  30.  * This file is not identical to the original GNU release!
  31.  * You should have received this code as patch to the official
  32.  * GNU release.
  33.  *
  34.  * MORE IMPORTANT:
  35.  * This port comes with ABSOLUTELY NO WARRANTY.
  36.  *
  37.  * $Header: e:/gnu/indent/RCS/indent_g.h'v 1.1.0.4 90/07/02 20:25:28 tho Exp $
  38.  */
  39.  
  40. #include <stdio.h>
  41.  
  42. #ifdef MSDOS
  43.  
  44. #include <stdlib.h>
  45. #include <string.h>
  46. #include <malloc.h>
  47. #include <io.h>
  48.  
  49. #define mymemcpy memcpy
  50.  
  51. #ifdef M_I86HM
  52. /* This symbol is predefined by the Microsoft C Compiler,
  53.    when it is creating "huge memory model" code.
  54.    In that case we need long offsets and buffer lengths.  */
  55. #define LONG long
  56. #else
  57. #define LONG unsigned int
  58. #endif
  59.  
  60. #else /* not MSDOS */
  61.  
  62. #include <strings.h>
  63.  
  64. /* Standard memory allocation routines.  */
  65. char *malloc ();
  66. char *realloc ();
  67. /* Do the same thing, but abort with an error if out of memory
  68.    (see globs.c).  */
  69. char *xmalloc ();
  70. char *xrealloc ();
  71.  
  72. #define LONG unsigned int
  73.  
  74. #endif /* not MSDOS */
  75.  
  76. /* Because some systems lack memcpy, I have provided one, called
  77.    mymemcpy.  If you system memcpy is more efficient, you might
  78.    want to use it by uncommenting the following line.  */
  79. /* #define mymemcpy memcpy */
  80. /* char *mymemcpy ();        see below, [tho] Mon Nov 13 01:12:02 1989 */
  81.  
  82. #define BACKSLASH '\\'
  83. #define label_offset 2        /* number of levels a label is placed to left
  84.                  * of code */
  85. /* Initial size of internal buffers (they are extended as necessary).  */
  86. #define bufsize 1000
  87.  
  88. #define tabsize 8        /* the size of a tab */
  89. #define tabmask 0177770        /* mask used when figuring length of lines
  90.                  * with tabs */
  91.  
  92. enum codes {code_eof = 0,  /* end of file */
  93.           newline,
  94.           lparen, /* '(' or '['.  Also '{' in an initialization.  */
  95.           rparen, /* ')' or ']'.  Also '}' in an initialization.  */
  96.           unary_op, binary_op, postop,
  97.           question, casestmt, colon, semicolon, lbrace, rbrace,
  98.           ident, /* string or char literal, identifier, number */
  99.           comma, comment, swstmt,
  100.           preesc,  /* '#'.  */
  101.           form_feed, decl,
  102.           sp_paren, /* if, for, or while token */
  103.           sp_nparen, ifstmt, whilestmt,
  104.           forstmt, stmt, stmtl, elselit, dolit, dohead, ifhead,
  105.           elsehead, period };
  106.  
  107. #define false 0
  108. #define true  1
  109.  
  110. #ifdef MSDOS
  111. char *my_name;                /* argv[0] */
  112. #endif /* MSDOS */
  113.  
  114. /* Name of input file.  */
  115. extern char *in_name;
  116.  
  117. char *in_prog; /* pointer to the null-terminated input program */
  118.  
  119. /* Point to the position in the input program which we are currently
  120.    looking at.  */
  121. char *in_prog_pos;
  122.  
  123. /* Point to the start of the current line.  */
  124. char *cur_line;
  125.  
  126. /* Size of the input program, not including the ' \n\0' we add at the end */
  127. LONG in_prog_size;
  128.  
  129.  
  130. FILE       *output;        /* the output file */
  131.  
  132. #define check_code_size \
  133.     if (e_code >= l_code) { \
  134.         register nsize = l_code-s_code+400; \
  135.         codebuf = (char *) realloc(codebuf, nsize); \
  136.         e_code = codebuf + (e_code-s_code) + 1; \
  137.         l_code = codebuf + nsize - 5; \
  138.         s_code = codebuf + 1; \
  139.     }
  140.  
  141. #define check_com_size \
  142.     if (e_com >= l_com) { \
  143.         register nsize = l_com-s_com+400; \
  144.         combuf = (char *) realloc(combuf, nsize); \
  145.         e_com = combuf + (e_com-s_com) + 1; \
  146.         l_com = combuf + nsize - 5; \
  147.         s_com = combuf + 1; \
  148.     }
  149.  
  150. #define check_lab_size \
  151.     if (e_lab >= l_lab) { \
  152.         register nsize = l_lab-s_lab+400; \
  153.         labbuf = (char *) realloc(labbuf, nsize); \
  154.         e_lab = labbuf + (e_lab-s_lab) + 1; \
  155.         l_lab = labbuf + nsize - 5; \
  156.         s_lab = labbuf + 1; \
  157.     }
  158.  
  159. char       *labbuf;        /* buffer for label */
  160. char       *s_lab;        /* start ... */
  161. char       *e_lab;        /* .. and end of stored label */
  162. char       *l_lab;        /* limit of label buffer */
  163.  
  164. char       *codebuf;        /* buffer for code section */
  165. char       *s_code;        /* start ... */
  166. char       *e_code;        /* .. and end of stored code */
  167. char       *l_code;        /* limit of code section */
  168.  
  169. char       *combuf;        /* buffer for comments */
  170. char       *s_com;        /* start ... */
  171. char       *e_com;        /* ... and end of stored comments */
  172. char       *l_com;        /* limit of comment buffer */
  173.  
  174. char       *buf_ptr;        /* ptr to next character to be taken from
  175.                  * in_buffer */
  176. char       *buf_end;        /* ptr to first after last char in in_buffer */
  177.  
  178. /* pointer to the token that lexi() has just found */
  179. char *token;
  180. /* points to the first char after the end of token */
  181. char *token_end;
  182. /* Functions from lexi.c */
  183. enum codes lexi ();
  184.  
  185. /* Used to keep track of buffers.  */
  186. struct buf {
  187.   char *ptr;  /* points to the start of the buffer */
  188.   char *end;  /* points to the character beyond the last one (e.g. is equal
  189.          to ptr if the buffer is empty).  */
  190.   int size;  /* how many chars are currently allocated.  */
  191. };
  192. /* Insure that BUFSTRUC has at least REQ more chars left, if not extend it.
  193.    Note:  This may change bufstruc.ptr.  */
  194. #define need_chars(bufstruc, req) \
  195.   if ((bufstruc.end - bufstruc.ptr + (req)) >= bufstruc.size) \
  196.     {\
  197.       int cur_chars = bufstruc.end - bufstruc.ptr;\
  198.       bufstruc.size *= 2;\
  199.       bufstruc.ptr = xrealloc(bufstruc.ptr,bufstruc.size);\
  200.       bufstruc.end = bufstruc.ptr + cur_chars;\
  201.     }
  202. /* Initialize BUFSTRUC.  */
  203. #define init_buf(bufstruc) \
  204.   bufstruc.end = bufstruc.ptr = xmalloc(bufsize),\
  205.   bufstruc.size = bufsize
  206.  
  207. /* Buffer in which to save a comment which occurs between an if(), while(),
  208.    etc., and the statement following it.  Note: the fact that we point
  209.    into this buffer, and that we might realloc() it (via the
  210.    need_chars macro) is a bad thing (since when the buffer is
  211.    realloc'd its address might change, making any pointers into it
  212.    point to garbage), but since the filling of the buffer (hence the
  213.    need_chars) and the using of the buffer (where buf_ptr points into
  214.    it) occur at different times, we can get away with it (it would not
  215.    be trivial to fix).  */
  216. struct buf save_com;
  217.  
  218. char       *bp_save;        /* saved value of buf_ptr when taking input
  219.                  * from save_com */
  220. char       *be_save;        /* similarly saved value of buf_end */
  221.  
  222.  
  223. int         pointer_as_binop;
  224. int         blanklines_after_declarations;
  225. int         blanklines_before_blockcomments;
  226. extern int blanklines_after_procs;
  227. #ifdef MSDOS
  228. int         blanklines_around_cond_comp;
  229. #else /* not MSDOS */
  230. int         blanklines_around_conditional_compilation;
  231. #endif /* not MSDOS */
  232. int         swallow_optional_blanklines;
  233. int         n_real_blanklines;
  234. int         prefix_blankline_requested;
  235. int         postfix_blankline_requested;
  236. int         break_comma;    /* when true and not in parens, break after a
  237.                  * comma */
  238.  
  239. /* number of spaces to indent braces from the suround if, while, etc.
  240.    in -bl (bype_2 == 0) code */
  241. int brace_indent;
  242.  
  243. int         btype_2;        /* when true, brace should