home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BURKS 2
/
BURKS_AUG97.ISO
/
BURKS
/
SOFTWARE
/
SOURCES
/
INDE11AS.ZIP
/
INDENT_G.H
(
.txt
)
< prev
next >
Wrap
C/C++ Source or Header
|
1992-02-22
|
19KB
|
517 lines
/*
* Copyright (c) 1985 Sun Microsystems, Inc.
* Copyright (c) 1980 The Regents of the University of California.
* Copyright (c) 1976 Board of Trustees of the University of Illinois.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley, the University of Illinois,
* Urbana, and Sun Microsystems, Inc. The name of either University
* or Sun Microsystems may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#)indent_globs.h 5.7 (Berkeley) 9/15/88
*/
/*
* MS-DOS port (c) 1990 by Thorsten Ohl, ohl@gnu.ai.mit.edu
*
* To this port, the same copying conditions apply as to the
* original release.
*
* IMPORTANT:
* This file is not identical to the original GNU release!
* You should have received this code as patch to the official
* GNU release.
*
* MORE IMPORTANT:
* This port comes with ABSOLUTELY NO WARRANTY.
*
* $Header: e:/gnu/indent/RCS/indent_g.h'v 1.1.0.4 90/07/02 20:25:28 tho Exp $
*/
#include <stdio.h>
#ifdef MSDOS
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <io.h>
#define mymemcpy memcpy
#ifdef M_I86HM
/* This symbol is predefined by the Microsoft C Compiler,
when it is creating "huge memory model" code.
In that case we need long offsets and buffer lengths. */
#define LONG long
#else
#define LONG unsigned int
#endif
#else /* not MSDOS */
#include <strings.h>
/* Standard memory allocation routines. */
char *malloc ();
char *realloc ();
/* Do the same thing, but abort with an error if out of memory
(see globs.c). */
char *xmalloc ();
char *xrealloc ();
#define LONG unsigned int
#endif /* not MSDOS */
/* Because some systems lack memcpy, I have provided one, called
mymemcpy. If you system memcpy is more efficient, you might
want to use it by uncommenting the following line. */
/* #define mymemcpy memcpy */
/* char *mymemcpy (); see below, [tho] Mon Nov 13 01:12:02 1989 */
#define BACKSLASH '\\'
#define label_offset 2 /* number of levels a label is placed to left
* of code */
/* Initial size of internal buffers (they are extended as necessary). */
#define bufsize 1000
#define tabsize 8 /* the size of a tab */
#define tabmask 0177770 /* mask used when figuring length of lines
* with tabs */
enum codes {code_eof = 0, /* end of file */
newline,
lparen, /* '(' or '['. Also '{' in an initialization. */
rparen, /* ')' or ']'. Also '}' in an initialization. */
unary_op, binary_op, postop,
question, casestmt, colon, semicolon, lbrace, rbrace,
ident, /* string or char literal, identifier, number */
comma, comment, swstmt,
preesc, /* '#'. */
form_feed, decl,
sp_paren, /* if, for, or while token */
sp_nparen, ifstmt, whilestmt,
forstmt, stmt, stmtl, elselit, dolit, dohead, ifhead,
elsehead, period };
#define false 0
#define true 1
#ifdef MSDOS
char *my_name; /* argv[0] */
#endif /* MSDOS */
/* Name of input file. */
extern char *in_name;
char *in_prog; /* pointer to the null-terminated input program */
/* Point to the position in the input program which we are currently
looking at. */
char *in_prog_pos;
/* Point to the start of the current line. */
char *cur_line;
/* Size of the input program, not including the ' \n\0' we add at the end */
LONG in_prog_size;
FILE *output; /* the output file */
#define check_code_size \
if (e_code >= l_code) { \
register nsize = l_code-s_code+400; \
codebuf = (char *) realloc(codebuf, nsize); \
e_code = codebuf + (e_code-s_code) + 1; \
l_code = codebuf + nsize - 5; \
s_code = codebuf + 1; \
}
#define check_com_size \
if (e_com >= l_com) { \
register nsize = l_com-s_com+400; \
combuf = (char *) realloc(combuf, nsize); \
e_com = combuf + (e_com-s_com) + 1; \
l_com = combuf + nsize - 5; \
s_com = combuf + 1; \
}
#define check_lab_size \
if (e_lab >= l_lab) { \
register nsize = l_lab-s_lab+400; \
labbuf = (char *) realloc(labbuf, nsize); \
e_lab = labbuf + (e_lab-s_lab) + 1; \
l_lab = labbuf + nsize - 5; \
s_lab = labbuf + 1; \
}
char *labbuf; /* buffer for label */
char *s_lab; /* start ... */
char *e_lab; /* .. and end of stored label */
char *l_lab; /* limit of label buffer */
char *codebuf; /* buffer for code section */
char *s_code; /* start ... */
char *e_code; /* .. and end of stored code */
char *l_code; /* limit of code section */
char *combuf; /* buffer for comments */
char *s_com; /* start ... */
char *e_com; /* ... and end of stored comments */
char *l_com; /* limit of comment buffer */
char *buf_ptr; /* ptr to next character to be taken from
* in_buffer */
char *buf_end; /* ptr to first after last char in in_buffer */
/* pointer to the token that lexi() has just found */
char *token;
/* points to the first char after the end of token */
char *token_end;
/* Functions from lexi.c */
enum codes lexi ();
/* Used to keep track of buffers. */
struct buf {
char *ptr; /* points to the start of the buffer */
char *end; /* points to the character beyond the last one (e.g. is equal
to ptr if the buffer is empty). */
int size; /* how many chars are currently allocated. */
};
/* Insure that BUFSTRUC has at least REQ more chars left, if not extend it.
Note: This may change bufstruc.ptr. */
#define need_chars(bufstruc, req) \
if ((bufstruc.end - bufstruc.ptr + (req)) >= bufstruc.size) \
{\
int cur_chars = bufstruc.end - bufstruc.ptr;\
bufstruc.size *= 2;\
bufstruc.ptr = xrealloc(bufstruc.ptr,bufstruc.size);\
bufstruc.end = bufstruc.ptr + cur_chars;\
}
/* Initialize BUFSTRUC. */
#define init_buf(bufstruc) \
bufstruc.end = bufstruc.ptr = xmalloc(bufsize),\
bufstruc.size = bufsize
/* Buffer in which to save a comment which occurs between an if(), while(),
etc., and the statement following it. Note: the fact that we point
into this buffer, and that we might realloc() it (via the
need_chars macro) is a bad thing (since when the buffer is
realloc'd its address might change, making any pointers into it
point to garbage), but since the filling of the buffer (hence the
need_chars) and the using of the buffer (where buf_ptr points into
it) occur at different times, we can get away with it (it would not
be trivial to fix). */
struct buf save_com;
char *bp_save; /* saved value of buf_ptr when taking input
* from save_com */
char *be_save; /* similarly saved value of buf_end */
int pointer_as_binop;
int blanklines_after_declarations;
int blanklines_before_blockcomments;
extern int blanklines_after_procs;
#ifdef MSDOS
int blanklines_around_cond_comp;
#else /* not MSDOS */
int blanklines_around_conditional_compilation;
#endif /* not MSDOS */
int swallow_optional_blanklines;
int n_real_blanklines;
int prefix_blankline_requested;
int postfix_blankline_requested;
int break_comma; /* when true and not in parens, break after a
* comma */
/* number of spaces to indent braces from the suround if, while, etc.
in -bl (bype_2 == 0) code */
int brace_indent;
int btype_2; /* when true, brace should