[BACK]Return to indent_globs.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / indent

Annotation of src/usr.bin/indent/indent_globs.h, Revision 1.9

1.9     ! deraadt     1: /* *   $OpenBSD: indent_globs.h,v 1.8 2003/06/11 23:31:50 deraadt Exp $*/
1.1       deraadt     2: /*
                      3:  * Copyright (c) 1985 Sun Microsystems, Inc.
1.5       pjanzen     4:  * Copyright (c) 1980, 1993
                      5:  *     The Regents of the University of California.
1.1       deraadt     6:  * Copyright (c) 1976 Board of Trustees of the University of Illinois.
                      7:  * All rights reserved.
                      8:  *
                      9:  * Redistribution and use in source and binary forms, with or without
                     10:  * modification, are permitted provided that the following conditions
                     11:  * are met:
                     12:  * 1. Redistributions of source code must retain the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer.
                     14:  * 2. Redistributions in binary form must reproduce the above copyright
                     15:  *    notice, this list of conditions and the following disclaimer in the
                     16:  *    documentation and/or other materials provided with the distribution.
1.9     ! deraadt    17:  * 3. Neither the name of the University nor the names of its contributors
1.1       deraadt    18:  *    may be used to endorse or promote products derived from this software
                     19:  *    without specific prior written permission.
                     20:  *
                     21:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     22:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     23:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     24:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     25:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     26:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     27:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     28:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     29:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     30:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     31:  * SUCH DAMAGE.
                     32:  *
1.5       pjanzen    33:  *     from: @(#)indent_globs.h        8.1 (Berkeley) 6/6/93
1.1       deraadt    34:  */
                     35:
                     36: #define BACKSLASH '\\'
                     37: #define bufsize 200            /* size of internal buffers */
                     38: #define sc_size 5000           /* size of save_com buffer */
                     39: #define label_offset 2         /* number of levels a label is placed to left
                     40:                                 * of code */
                     41:
                     42: #define tabsize 8              /* the size of a tab */
                     43: #define tabmask 0177770                /* mask used when figuring length of lines
                     44:                                 * with tabs */
                     45:
                     46:
                     47: #define false 0
                     48: #define true  1
                     49:
                     50:
                     51: FILE       *input;             /* the fid for the input file */
                     52: FILE       *output;            /* the output file */
                     53:
                     54: #define CHECK_SIZE_CODE \
                     55:        if (e_code >= l_code) { \
1.8       deraadt    56:            int nsize = l_code-s_code+400; \
                     57:        \
1.1       deraadt    58:            codebuf = (char *) realloc(codebuf, nsize); \
1.5       pjanzen    59:            if (codebuf == NULL) \
1.6       pjanzen    60:                    err(1, NULL); \
1.1       deraadt    61:            e_code = codebuf + (e_code-s_code) + 1; \
                     62:            l_code = codebuf + nsize - 5; \
                     63:            s_code = codebuf + 1; \
                     64:        }
                     65: #define CHECK_SIZE_COM \
                     66:        if (e_com >= l_com) { \
1.8       deraadt    67:            int nsize = l_com-s_com+400; \
                     68:        \
1.1       deraadt    69:            combuf = (char *) realloc(combuf, nsize); \
1.5       pjanzen    70:            if (combuf == NULL) \
1.6       pjanzen    71:                    err(1, NULL); \
1.1       deraadt    72:            e_com = combuf + (e_com-s_com) + 1; \
                     73:            l_com = combuf + nsize - 5; \
                     74:            s_com = combuf + 1; \
                     75:        }
                     76: #define CHECK_SIZE_LAB \
                     77:        if (e_lab >= l_lab) { \
1.8       deraadt    78:            int nsize = l_lab-s_lab+400; \
                     79:        \
1.1       deraadt    80:            labbuf = (char *) realloc(labbuf, nsize); \
1.5       pjanzen    81:            if (labbuf == NULL) \
1.6       pjanzen    82:                    err(1, NULL); \
1.1       deraadt    83:            e_lab = labbuf + (e_lab-s_lab) + 1; \
                     84:            l_lab = labbuf + nsize - 5; \
                     85:            s_lab = labbuf + 1; \
                     86:        }
                     87: #define CHECK_SIZE_TOKEN \
                     88:        if (e_token >= l_token) { \
1.8       deraadt    89:            int nsize = l_token-s_token+400; \
                     90:        \
1.1       deraadt    91:            tokenbuf = (char *) realloc(tokenbuf, nsize); \
1.5       pjanzen    92:            if (tokenbuf == NULL) \
1.6       pjanzen    93:                    err(1, NULL); \
1.1       deraadt    94:            e_token = tokenbuf + (e_token-s_token) + 1; \
                     95:            l_token = tokenbuf + nsize - 5; \
                     96:            s_token = tokenbuf + 1; \
                     97:        }
                     98:
                     99: char       *labbuf;            /* buffer for label */
                    100: char       *s_lab;             /* start ... */
                    101: char       *e_lab;             /* .. and end of stored label */
                    102: char       *l_lab;             /* limit of label buffer */
                    103:
                    104: char       *codebuf;           /* buffer for code section */
                    105: char       *s_code;            /* start ... */
                    106: char       *e_code;            /* .. and end of stored code */
                    107: char       *l_code;            /* limit of code section */
                    108:
                    109: char       *combuf;            /* buffer for comments */
                    110: char       *s_com;             /* start ... */
                    111: char       *e_com;             /* ... and end of stored comments */
                    112: char       *l_com;             /* limit of comment buffer */
                    113:
                    114: #define token s_token
                    115: char       *tokenbuf;          /* the last token scanned */
                    116: char      *s_token;
                    117: char       *e_token;
                    118: char      *l_token;
                    119:
                    120: char       *in_buffer;         /* input buffer */
                    121: char      *in_buffer_limit;    /* the end of the input buffer */
                    122: char       *buf_ptr;           /* ptr to next character to be taken from
                    123:                                 * in_buffer */
                    124: char       *buf_end;           /* ptr to first after last char in in_buffer */
                    125:
                    126: char        save_com[sc_size]; /* input text is saved here when looking for
                    127:                                 * the brace after an if, while, etc */
                    128: char       *sc_end;            /* pointer into save_com buffer */
                    129:
                    130: char       *bp_save;           /* saved value of buf_ptr when taking input
                    131:                                 * from save_com */
                    132: char       *be_save;           /* similarly saved value of buf_end */
                    133:
                    134:
                    135: int         pointer_as_binop;
                    136: int         blanklines_after_declarations;
                    137: int         blanklines_before_blockcomments;
                    138: int         blanklines_after_procs;
                    139: int         blanklines_around_conditional_compilation;
                    140: int         swallow_optional_blanklines;
                    141: int         n_real_blanklines;
                    142: int         prefix_blankline_requested;
                    143: int         postfix_blankline_requested;
                    144: int         break_comma;       /* when true and not in parens, break after a
                    145:                                 * comma */
                    146: int         btype_2;           /* when true, brace should be on same line as
                    147:                                 * if, while, etc */
                    148: float       case_ind;          /* indentation level to be used for a "case
                    149:                                 * n:" */
                    150: int         code_lines;                /* count of lines with code */
                    151: int         had_eof;           /* set to true when input is exhausted */
                    152: int         line_no;           /* the current line number. */
                    153: int         max_col;           /* the maximum allowable line length */
                    154: int         verbose;           /* when true, non-essential error messages are
                    155:                                 * printed */
                    156: int         cuddle_else;       /* true if else should cuddle up to '}' */
                    157: int         star_comment_cont; /* true iff comment continuation lines should
                    158:                                 * have stars at the beginning of each line. */
                    159: int         comment_delimiter_on_blankline;
                    160: int         troff;             /* true iff were generating troff input */
                    161: int         procnames_start_line;      /* if true, the names of procedures
                    162:                                         * being defined get placed in column
                    163:                                         * 1 (ie. a newline is placed between
                    164:                                         * the type of the procedure and its
                    165:                                         * name) */
                    166: int         proc_calls_space;  /* If true, procedure calls look like:
                    167:                                 * foo(bar) rather than foo (bar) */
                    168: int         format_col1_comments;      /* If comments which start in column 1
                    169:                                         * are to be magically reformatted
                    170:                                         * (just like comments that begin in
                    171:                                         * later columns) */
                    172: int         inhibit_formatting;        /* true if INDENT OFF is in effect */
                    173: int         suppress_blanklines;/* set iff following blanklines should be
                    174:                                 * suppressed */
                    175: int         continuation_indent;/* set to the indentation between the edge of
                    176:                                 * code and continuation lines */
                    177: int         lineup_to_parens;  /* if true, continued code within parens will
                    178:                                 * be lined up to the open paren */
                    179: int         Bill_Shannon;      /* true iff a blank should always be inserted
                    180:                                 * after sizeof */
                    181: int         blanklines_after_declarations_at_proctop;  /* This is vaguely
                    182:                                                         * similar to
                    183:                                                         * blanklines_after_decla
                    184:                                                         * rations except that
                    185:                                                         * it only applies to
                    186:                                                         * the first set of
                    187:                                                         * declarations in a
                    188:                                                         * procedure (just after
                    189:                                                         * the first '{') and it
                    190:                                                         * causes a blank line
                    191:                                                         * to be generated even
                    192:                                                         * if there are no
                    193:                                                         * declarations */
                    194: int         block_comment_max_col;
                    195: int         extra_expression_indent;   /* True if continuation lines from the
                    196:                                         * expression part of "if(e)",
                    197:                                         * "while(e)", "for(e;e;e)" should be
                    198:                                         * indented an extra tab stop so that
                    199:                                         * they don't conflict with the code
                    200:                                         * that follows */
                    201:
                    202: /* -troff font state information */
                    203:
                    204: struct fstate {
                    205:     char        font[4];
                    206:     char        size;
                    207:     int         allcaps:1;
                    208: };
                    209: char       *chfont();
                    210:
                    211: struct fstate
                    212:             keywordf,          /* keyword font */
                    213:             stringf,           /* string font */
                    214:             boxcomf,           /* Box comment font */
                    215:             blkcomf,           /* Block comment font */
                    216:             scomf,             /* Same line comment font */
                    217:             bodyf;             /* major body font */
                    218:
                    219:
                    220: #define STACKSIZE 150
                    221:
                    222: struct parser_state {
                    223:     int         last_token;
                    224:     struct fstate cfont;       /* Current font */
                    225:     int         p_stack[STACKSIZE];    /* this is the parsers stack */
                    226:     int         il[STACKSIZE]; /* this stack stores indentation levels */
                    227:     float       cstk[STACKSIZE];/* used to store case stmt indentation levels */
                    228:     int         box_com;       /* set to true when we are in a "boxed"
                    229:                                 * comment. In that case, the first non-blank
1.3       mickey    230:                                 * char should be lined up with the / in rem */
1.1       deraadt   231:     int         comment_delta,
                    232:                 n_comment_delta;
                    233:     int         cast_mask;     /* indicates which close parens close off
                    234:                                 * casts */
                    235:     int         sizeof_mask;   /* indicates which close parens close off
                    236:                                 * sizeof''s */
                    237:     int         block_init;    /* true iff inside a block initialization */
                    238:     int         block_init_level;      /* The level of brace nesting in an
                    239:                                         * initialization */
                    240:     int         last_nl;       /* this is true if the last thing scanned was
                    241:                                 * a newline */
                    242:     int         in_or_st;      /* Will be true iff there has been a
                    243:                                 * declarator (e.g. int or char) and no left
                    244:                                 * paren since the last semicolon. When true,
                    245:                                 * a '{' is starting a structure definition or
                    246:                                 * an initialization list */
                    247:     int         bl_line;       /* set to 1 by dump_line if the line is blank */
                    248:     int         col_1;         /* set to true if the last token started in
                    249:                                 * column 1 */
                    250:     int         com_col;       /* this is the column in which the current
                    251:                                 * coment should start */
                    252:     int         com_ind;       /* the column in which comments to the right
                    253:                                 * of code should start */
                    254:     int         com_lines;     /* the number of lines with comments, set by
                    255:                                 * dump_line */
                    256:     int         dec_nest;      /* current nesting level for structure or init */
                    257:     int         decl_com_ind;  /* the column in which comments after
                    258:                                 * declarations should be put */
                    259:     int         decl_on_line;  /* set to true if this line of code has part
                    260:                                 * of a declaration on it */
                    261:     int         i_l_follow;    /* the level to which ind_level should be set
                    262:                                 * after the current line is printed */
                    263:     int         in_decl;       /* set to true when we are in a declaration
                    264:                                 * stmt.  The processing of braces is then
                    265:                                 * slightly different */
                    266:     int         in_stmt;       /* set to 1 while in a stmt */
                    267:     int         ind_level;     /* the current indentation level */
                    268:     int         ind_size;      /* the size of one indentation level */
                    269:     int         ind_stmt;      /* set to 1 if next line should have an extra
                    270:                                 * indentation level because we are in the
                    271:                                 * middle of a stmt */
                    272:     int         last_u_d;      /* set to true after scanning a token which
                    273:                                 * forces a following operator to be unary */
                    274:     int         leave_comma;   /* if true, never break declarations after
                    275:                                 * commas */
                    276:     int         ljust_decl;    /* true if declarations should be left
                    277:                                 * justified */
                    278:     int         out_coms;      /* the number of comments processed, set by
                    279:                                 * pr_comment */
                    280:     int         out_lines;     /* the number of lines written, set by
                    281:                                 * dump_line */
                    282:     int         p_l_follow;    /* used to remember how to indent following
                    283:                                 * statement */
                    284:     int         paren_level;   /* parenthesization level. used to indent
                    285:                                 * within stmts */
                    286:     short       paren_indents[20];     /* column positions of each paren */
                    287:     int         pcase;         /* set to 1 if the current line label is a
                    288:                                 * case.  It is printed differently from a
                    289:                                 * regular label */
                    290:     int         search_brace;  /* set to true by parse when it is necessary
                    291:                                 * to buffer up all info up to the start of a
                    292:                                 * stmt after an if, while, etc */
                    293:     int         unindent_displace;     /* comments not to the right of code
                    294:                                         * will be placed this many
                    295:                                         * indentation levels to the left of
                    296:                                         * code */
                    297:     int         use_ff;                /* set to one if the current line should be
                    298:                                 * terminated with a form feed */
                    299:     int         want_blank;    /* set to true when the following token should
                    300:                                 * be prefixed by a blank. (Said prefixing is
                    301:                                 * ignored in some cases.) */
                    302:     int         else_if;       /* True iff else if pairs should be handled
                    303:                                 * specially */
                    304:     int         decl_indent;   /* column to indent declared identifiers to */
                    305:     int         its_a_keyword;
                    306:     int         sizeof_keyword;
                    307:     int         dumped_decl_indent;
                    308:     float       case_indent;   /* The distance to indent case labels from the
                    309:                                 * switch statement */
                    310:     int         in_parameter_declaration;
                    311:     int         indent_parameters;
                    312:     int         tos;           /* pointer to top of stack */
                    313:     char        procname[100]; /* The name of the current procedure */
                    314:     int         just_saw_decl;
                    315: }           ps;
                    316:
                    317: int         ifdef_level;
                    318: int        rparen_count;
                    319: struct parser_state state_stack[5];
                    320: struct parser_state match_state[5];
1.5       pjanzen   321:
1.7       millert   322: int compute_code_target(void);
                    323: int compute_label_target(void);
                    324: int count_spaces(int, char *);
                    325: void diag(int, char *, ...);
                    326: void dump_line(void);
                    327: int eqin(char *, char *);
                    328: void fill_buffer(void);
                    329: int pad_output(int, int);
                    330: void scan_profile(FILE *);
                    331: void set_defaults(void);
                    332: void set_option(char *);
                    333: void addkey(char *, int);
                    334: void set_profile(void);
                    335: char   *chfont(struct fstate *, struct fstate *, char *);
                    336: void parsefont(struct fstate *, char *);
                    337: void writefdef(struct fstate *, int);
                    338: int lexi(void);
                    339: void reduce(void);
                    340: void parse(int);
                    341: void pr_comment(void);
                    342: void bakcopy(void);