Home | History | Annotate | Line # | Download | only in indent
indent.h revision 1.136
      1  1.136  rillig /*	$NetBSD: indent.h,v 1.136 2023/05/15 09:53:32 rillig Exp $	*/
      2    1.1   kamil 
      3    1.1   kamil /*-
      4    1.1   kamil  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
      5    1.1   kamil  *
      6    1.1   kamil  * Copyright (c) 2001 Jens Schweikhardt
      7    1.1   kamil  * All rights reserved.
      8    1.1   kamil  *
      9    1.1   kamil  * Redistribution and use in source and binary forms, with or without
     10    1.1   kamil  * modification, are permitted provided that the following conditions
     11    1.1   kamil  * are met:
     12    1.1   kamil  * 1. Redistributions of source code must retain the above copyright
     13    1.1   kamil  *    notice, this list of conditions and the following disclaimer.
     14    1.1   kamil  * 2. Redistributions in binary form must reproduce the above copyright
     15    1.1   kamil  *    notice, this list of conditions and the following disclaimer in the
     16    1.1   kamil  *    documentation and/or other materials provided with the distribution.
     17    1.1   kamil  *
     18    1.1   kamil  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
     19    1.1   kamil  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     20    1.1   kamil  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     21    1.1   kamil  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
     22    1.1   kamil  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23    1.1   kamil  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     24    1.1   kamil  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25    1.1   kamil  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     26    1.1   kamil  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27    1.1   kamil  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28    1.1   kamil  * SUCH DAMAGE.
     29    1.1   kamil  */
     30   1.31  rillig /*-
     31   1.31  rillig  * SPDX-License-Identifier: BSD-4-Clause
     32   1.31  rillig  *
     33   1.31  rillig  * Copyright (c) 1985 Sun Microsystems, Inc.
     34   1.31  rillig  * Copyright (c) 1980, 1993
     35   1.31  rillig  *	The Regents of the University of California.  All rights reserved.
     36   1.31  rillig  * All rights reserved.
     37   1.31  rillig  *
     38   1.31  rillig  * Redistribution and use in source and binary forms, with or without
     39   1.31  rillig  * modification, are permitted provided that the following conditions
     40   1.31  rillig  * are met:
     41   1.31  rillig  * 1. Redistributions of source code must retain the above copyright
     42   1.31  rillig  *    notice, this list of conditions and the following disclaimer.
     43   1.31  rillig  * 2. Redistributions in binary form must reproduce the above copyright
     44   1.31  rillig  *    notice, this list of conditions and the following disclaimer in the
     45   1.31  rillig  *    documentation and/or other materials provided with the distribution.
     46   1.31  rillig  * 3. All advertising materials mentioning features or use of this software
     47   1.31  rillig  *    must display the following acknowledgement:
     48   1.31  rillig  *	This product includes software developed by the University of
     49   1.31  rillig  *	California, Berkeley and its contributors.
     50   1.31  rillig  * 4. Neither the name of the University nor the names of its contributors
     51   1.31  rillig  *    may be used to endorse or promote products derived from this software
     52   1.31  rillig  *    without specific prior written permission.
     53   1.31  rillig  *
     54   1.31  rillig  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     55   1.31  rillig  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     56   1.31  rillig  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     57   1.31  rillig  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     58   1.31  rillig  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     59   1.31  rillig  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     60   1.31  rillig  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     61   1.31  rillig  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     62   1.31  rillig  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     63   1.31  rillig  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     64   1.31  rillig  * SUCH DAMAGE.
     65   1.31  rillig  */
     66    1.1   kamil 
     67   1.98  rillig #include <ctype.h>
     68   1.20  rillig #include <stdbool.h>
     69   1.65  rillig #include <stdio.h>
     70   1.20  rillig 
     71   1.49  rillig typedef enum lexer_symbol {
     72   1.49  rillig     lsym_eof,
     73   1.49  rillig     lsym_preprocessing,		/* '#' */
     74   1.49  rillig     lsym_newline,
     75   1.49  rillig     lsym_form_feed,
     76   1.74  rillig     lsym_comment,		/* the initial '/ *' or '//' of a comment */
     77   1.49  rillig     lsym_lparen_or_lbracket,
     78   1.49  rillig     lsym_rparen_or_rbracket,
     79   1.49  rillig     lsym_lbrace,
     80   1.49  rillig     lsym_rbrace,
     81   1.49  rillig     lsym_period,
     82   1.74  rillig     lsym_unary_op,		/* e.g. '*', '&', '-' or leading '++' */
     83   1.74  rillig     lsym_binary_op,		/* e.g. '*', '&', '<<', '&&' or '/=' */
     84   1.49  rillig     lsym_postfix_op,		/* trailing '++' or '--' */
     85   1.49  rillig     lsym_question,		/* the '?' from a '?:' expression */
     86   1.49  rillig     lsym_colon,
     87   1.49  rillig     lsym_comma,
     88   1.49  rillig     lsym_semicolon,
     89   1.49  rillig     lsym_typedef,
     90   1.49  rillig     lsym_storage_class,
     91   1.81  rillig     lsym_type_outside_parentheses,
     92   1.80  rillig     lsym_type_in_parentheses,
     93   1.53  rillig     lsym_tag,			/* 'struct', 'union' or 'enum' */
     94   1.53  rillig     lsym_case_label,		/* 'case' or 'default' */
     95   1.69  rillig     lsym_sizeof,
     96   1.70  rillig     lsym_offsetof,
     97   1.80  rillig     lsym_word,			/* identifier, constant or string */
     98   1.49  rillig     lsym_funcname,
     99   1.49  rillig     lsym_do,
    100   1.49  rillig     lsym_else,
    101   1.49  rillig     lsym_for,
    102   1.49  rillig     lsym_if,
    103   1.49  rillig     lsym_switch,
    104   1.49  rillig     lsym_while,
    105   1.75  rillig     lsym_return
    106   1.49  rillig } lexer_symbol;
    107   1.49  rillig 
    108   1.49  rillig typedef enum parser_symbol {
    109  1.122  rillig     psym_0,			/* a placeholder */
    110   1.49  rillig     psym_lbrace,
    111   1.49  rillig     psym_rbrace,
    112   1.49  rillig     psym_decl,
    113   1.49  rillig     psym_stmt,
    114   1.49  rillig     psym_stmt_list,
    115   1.49  rillig     psym_for_exprs,		/* 'for' '(' ... ')' */
    116   1.49  rillig     psym_if_expr,		/* 'if' '(' expr ')' */
    117   1.49  rillig     psym_if_expr_stmt,		/* 'if' '(' expr ')' stmt */
    118   1.49  rillig     psym_if_expr_stmt_else,	/* 'if' '(' expr ')' stmt 'else' */
    119  1.124  rillig     psym_else,			/* 'else'; not stored on the stack */
    120   1.49  rillig     psym_switch_expr,		/* 'switch' '(' expr ')' */
    121   1.49  rillig     psym_do,			/* 'do' */
    122   1.49  rillig     psym_do_stmt,		/* 'do' stmt */
    123   1.49  rillig     psym_while_expr,		/* 'while' '(' expr ')' */
    124   1.49  rillig } parser_symbol;
    125   1.49  rillig 
    126  1.132  rillig /* A range of characters, not null-terminated. */
    127   1.31  rillig struct buffer {
    128  1.133  rillig     const char *st;		/* start of the usable text */
    129  1.133  rillig     char *mem;
    130  1.133  rillig     size_t len;			/* length of the usable text, from 'mem' */
    131  1.133  rillig     size_t cap;
    132   1.31  rillig };
    133   1.31  rillig 
    134   1.34  rillig extern FILE *input;
    135   1.34  rillig extern FILE *output;
    136   1.31  rillig 
    137   1.61  rillig extern struct buffer token;	/* the current token to be processed, is
    138  1.105  rillig 				 * typically copied to the buffer 'code', or
    139  1.105  rillig 				 * in some cases to 'lab'. */
    140   1.61  rillig 
    141   1.61  rillig extern struct buffer lab;	/* the label or preprocessor directive */
    142   1.61  rillig extern struct buffer code;	/* the main part of the current line of code */
    143   1.61  rillig extern struct buffer com;	/* the trailing comment of the line, or the
    144   1.83  rillig 				 * start or end of a multi-line comment, or
    145   1.83  rillig 				 * while in process_comment, a single line of
    146   1.83  rillig 				 * a multi-line comment */
    147   1.31  rillig 
    148   1.31  rillig extern struct options {
    149   1.34  rillig     bool blanklines_around_conditional_compilation;
    150  1.126  rillig     bool blank_line_after_decl_at_top;	/* this is vaguely similar to
    151  1.126  rillig 					 * blank_line_after_decl except that
    152   1.34  rillig 					 * it only applies to the first set of
    153   1.34  rillig 					 * declarations in a procedure (just
    154   1.34  rillig 					 * after the first '{') and it causes
    155   1.34  rillig 					 * a blank line to be generated even
    156   1.34  rillig 					 * if there are no declarations */
    157  1.126  rillig     bool blank_line_after_decl;
    158   1.34  rillig     bool blanklines_after_procs;
    159   1.34  rillig     bool blanklines_before_block_comments;
    160   1.34  rillig     bool break_after_comma;	/* whether to break declarations after commas */
    161   1.34  rillig     bool brace_same_line;	/* whether brace should be on same line as if,
    162   1.34  rillig 				 * while, etc */
    163   1.34  rillig     bool blank_after_sizeof;	/* whether a blank should always be inserted
    164   1.34  rillig 				 * after sizeof */
    165   1.34  rillig     bool comment_delimiter_on_blankline;
    166   1.34  rillig     int decl_comment_column;	/* the column in which comments after
    167   1.31  rillig 				 * declarations should be put */
    168   1.34  rillig     bool cuddle_else;		/* whether 'else' should cuddle up to '}' */
    169   1.34  rillig     int continuation_indent;	/* the indentation between the edge of code
    170   1.34  rillig 				 * and continuation lines */
    171   1.34  rillig     float case_indent;		/* The distance (measured in indentation
    172   1.31  rillig 				 * levels) to indent case labels from the
    173   1.31  rillig 				 * switch statement */
    174   1.34  rillig     int comment_column;		/* the column in which comments to the right
    175   1.31  rillig 				 * of code should start */
    176   1.34  rillig     int decl_indent;		/* indentation of identifier in declaration */
    177   1.34  rillig     bool ljust_decl;		/* true if declarations should be left
    178   1.31  rillig 				 * justified */
    179   1.34  rillig     int unindent_displace;	/* comments not to the right of code will be
    180   1.34  rillig 				 * placed this many indentation levels to the
    181   1.34  rillig 				 * left of code */
    182   1.34  rillig     bool extra_expr_indent;	/* whether continuation lines from the
    183  1.124  rillig 				 * expression part of "if (e)", "while (e)",
    184  1.124  rillig 				 * "for (e; e; e)" should be indented an extra
    185   1.34  rillig 				 * tab stop so that they don't conflict with
    186   1.34  rillig 				 * the code that follows */
    187  1.129  rillig     bool else_if;		/* whether else-if pairs use the same line */
    188   1.34  rillig     bool function_brace_split;	/* split function declaration and brace onto
    189   1.34  rillig 				 * separate lines */
    190   1.34  rillig     bool format_col1_comments;	/* If comments which start in column 1 are to
    191  1.129  rillig 				 * be reformatted (just like comments that
    192  1.129  rillig 				 * begin in later columns) */
    193   1.34  rillig     bool format_block_comments;	/* whether comments beginning with '/ * \n'
    194   1.34  rillig 				 * are to be reformatted */
    195   1.34  rillig     bool indent_parameters;
    196   1.34  rillig     int indent_size;		/* the size of one indentation level */
    197   1.34  rillig     int block_comment_max_line_length;
    198   1.34  rillig     int local_decl_indent;	/* like decl_indent but for locals */
    199   1.34  rillig     bool lineup_to_parens_always;	/* whether to not(?) attempt to keep
    200   1.34  rillig 					 * lined-up code within the margin */
    201   1.34  rillig     bool lineup_to_parens;	/* whether continued code within parens will
    202   1.34  rillig 				 * be lined up to the open paren */
    203   1.34  rillig     bool proc_calls_space;	/* whether function calls look like: foo (bar)
    204   1.34  rillig 				 * rather than foo(bar) */
    205   1.34  rillig     bool procnames_start_line;	/* whether the names of procedures being
    206   1.34  rillig 				 * defined get placed in column 1 (i.e. a
    207   1.34  rillig 				 * newline is placed between the type of the
    208   1.34  rillig 				 * procedure and its name) */
    209   1.34  rillig     bool space_after_cast;	/* "b = (int) a" vs "b = (int)a" */
    210   1.34  rillig     bool star_comment_cont;	/* whether comment continuation lines should
    211   1.34  rillig 				 * have stars at the beginning of each line. */
    212   1.34  rillig     bool swallow_optional_blanklines;
    213   1.34  rillig     bool auto_typedefs;		/* whether to recognize identifiers ending in
    214   1.34  rillig 				 * "_t" like typedefs */
    215   1.34  rillig     int tabsize;		/* the size of a tab */
    216   1.34  rillig     int max_line_length;
    217   1.34  rillig     bool use_tabs;		/* set true to use tabs for spacing, false
    218   1.31  rillig 				 * uses all spaces */
    219   1.34  rillig     bool verbose;		/* whether non-essential error messages are
    220   1.34  rillig 				 * printed */
    221   1.51  rillig } opt;
    222   1.31  rillig 
    223   1.34  rillig extern bool found_err;
    224   1.56  rillig extern bool break_comma;	/* when true and not in parentheses, break
    225   1.56  rillig 				 * after a comma */
    226   1.34  rillig extern float case_ind;		/* indentation level to be used for a "case
    227   1.31  rillig 				 * n:" */
    228   1.34  rillig extern bool had_eof;		/* whether input is exhausted */
    229   1.34  rillig extern int line_no;		/* the current line number. */
    230   1.34  rillig extern bool inhibit_formatting;	/* true if INDENT OFF is in effect */
    231   1.31  rillig 
    232   1.31  rillig #define	STACKSIZE 256
    233   1.31  rillig 
    234  1.110  rillig /* Properties of each level of parentheses or brackets. */
    235  1.110  rillig typedef struct paren_level_props {
    236  1.110  rillig     short indent;		/* indentation of the operand/argument,
    237  1.110  rillig 				 * relative to the enclosing statement; if
    238  1.110  rillig 				 * negative, reflected at -1 */
    239  1.110  rillig     bool maybe_cast;		/* whether the parentheses may form a type
    240  1.110  rillig 				 * cast */
    241  1.110  rillig     bool no_cast;		/* whether the parentheses definitely do not
    242  1.110  rillig 				 * form a type cast */
    243  1.110  rillig } paren_level_props;
    244  1.110  rillig 
    245  1.129  rillig /*
    246  1.129  rillig  * The parser state determines the layout of the formatted text.
    247  1.129  rillig  *
    248  1.129  rillig  * In a function body, the number of block braces determines the indentation
    249  1.129  rillig  * of statements and declarations.
    250  1.129  rillig  *
    251  1.129  rillig  * In a statement, the number of parentheses or brackets determines the
    252  1.129  rillig  * indentation of follow-up lines.
    253  1.129  rillig  *
    254  1.129  rillig  * In an expression, the token type determine whether to put spaces around.
    255  1.129  rillig  *
    256  1.129  rillig  * In a source file, the types of line determine the vertical spacing, such as
    257  1.129  rillig  * around preprocessing directives or function bodies, or above block
    258  1.129  rillig  * comments.
    259  1.129  rillig  */
    260   1.31  rillig extern struct parser_state {
    261   1.84  rillig     lexer_symbol prev_token;	/* the previous token, but never comment,
    262   1.84  rillig 				 * newline or preprocessing line */
    263  1.136  rillig 
    264  1.136  rillig     /* Token classification */
    265  1.136  rillig 
    266  1.136  rillig     int quest_level;		/* when this is positive, we have seen a '?'
    267  1.136  rillig 				 * without the matching ':' in a '?:'
    268  1.136  rillig 				 * expression */
    269  1.136  rillig     bool is_function_definition;
    270  1.136  rillig     bool block_init;		/* whether inside a block initialization */
    271  1.136  rillig     int block_init_level;	/* the level of brace nesting in an
    272  1.136  rillig 				 * initialization */
    273  1.136  rillig     bool init_or_struct;	/* whether there has been a type name and no
    274  1.136  rillig 				 * left parenthesis since the last semicolon.
    275  1.136  rillig 				 * When true, a '{' starts a structure
    276  1.136  rillig 				 * definition or an initialization list */
    277  1.136  rillig     bool decl_on_line;		/* whether this line of code has part of a
    278  1.136  rillig 				 * declaration on it */
    279  1.136  rillig     bool in_stmt_or_decl;	/* whether in a statement or a struct
    280  1.136  rillig 				 * declaration or a plain declaration */
    281  1.136  rillig     bool in_decl;		/* whether we are in a declaration. The
    282  1.136  rillig 				 * processing of braces is then slightly
    283  1.136  rillig 				 * different */
    284  1.136  rillig     bool in_func_def_params;
    285  1.136  rillig     bool seen_case;		/* set to true when we see a 'case', so we
    286  1.136  rillig 				 * know what to do with the following colon */
    287  1.136  rillig     bool is_case_label;		/* 'case' and 'default' labels are indented
    288  1.136  rillig 				 * differently from regular labels */
    289  1.136  rillig     parser_symbol spaced_expr_psym;	/* the parser symbol to be shifted
    290  1.136  rillig 					 * after the parenthesized expression
    291  1.136  rillig 					 * from a 'for', 'if', 'switch' or
    292  1.136  rillig 					 * 'while'; or psym_0 */
    293  1.136  rillig 
    294  1.136  rillig     /* Indentation of statements and declarations */
    295  1.136  rillig 
    296  1.136  rillig     int ind_level;		/* the indentation level for the line that is
    297  1.136  rillig 				 * currently prepared for output */
    298  1.136  rillig     int ind_level_follow;	/* the level to which ind_level should be set
    299  1.136  rillig 				 * after the current line is printed */
    300  1.136  rillig     bool in_stmt_cont;		/* whether the next line should have an extra
    301  1.136  rillig 				 * indentation level because we are in the
    302  1.136  rillig 				 * middle of a statement */
    303  1.136  rillig     int decl_level;		/* current nesting level for a structure
    304  1.136  rillig 				 * declaration or an initializer */
    305  1.136  rillig     bool decl_indent_done;	/* whether the indentation for a declaration
    306  1.136  rillig 				 * has been added to the code buffer. */
    307  1.136  rillig     int decl_ind;		/* current indentation for declarations */
    308  1.136  rillig     int di_stack[20];		/* a stack of structure indentation levels */
    309  1.136  rillig     bool tabs_to_var;		/* true if using tabs to indent to var name */
    310  1.136  rillig 
    311  1.136  rillig     enum {
    312  1.136  rillig 	in_enum_no,		/* outside any 'enum { ... }' */
    313  1.136  rillig 	in_enum_enum,		/* after keyword 'enum' */
    314  1.136  rillig 	in_enum_type,		/* after 'enum' or 'enum tag' */
    315  1.136  rillig 	in_enum_brace		/* between '{' and '}' */
    316  1.136  rillig     } in_enum;			/* enum { . } */
    317  1.136  rillig 
    318  1.136  rillig     int tos;			/* pointer to top of stack */
    319  1.136  rillig     parser_symbol s_sym[STACKSIZE];
    320  1.136  rillig     int s_ind_level[STACKSIZE];
    321  1.136  rillig     float s_case_ind_level[STACKSIZE];
    322  1.136  rillig 
    323  1.136  rillig     /* Spacing inside a statement or declaration */
    324  1.136  rillig 
    325   1.59  rillig     bool next_unary;		/* whether the following operator should be
    326  1.124  rillig 				 * unary; is used in declarations for '*', as
    327  1.124  rillig 				 * well as in expressions */
    328   1.59  rillig     bool want_blank;		/* whether the following token should be
    329   1.59  rillig 				 * prefixed by a blank. (Said prefixing is
    330   1.59  rillig 				 * ignored in some cases.) */
    331  1.111  rillig     int line_start_nparen;	/* the number of parentheses or brackets that
    332  1.111  rillig 				 * were already open at the beginning of the
    333  1.111  rillig 				 * current line; used to indent within
    334  1.111  rillig 				 * statements, initializers and declarations */
    335  1.111  rillig     int nparen;			/* the number of parentheses or brackets that
    336  1.111  rillig 				 * are currently open; used to indent the
    337  1.111  rillig 				 * remaining lines of the statement,
    338  1.111  rillig 				 * initializer or declaration */
    339  1.110  rillig     paren_level_props paren[20];
    340  1.111  rillig 
    341  1.136  rillig     /* Horizontal spacing for comments */
    342  1.136  rillig 
    343   1.34  rillig     int comment_delta;		/* used to set up indentation for all lines of
    344   1.34  rillig 				 * a boxed comment after the first one */
    345   1.34  rillig     int n_comment_delta;	/* remembers how many columns there were
    346   1.31  rillig 				 * before the start of a box comment so that
    347   1.31  rillig 				 * forthcoming lines of the comment are
    348   1.31  rillig 				 * indented properly */
    349   1.59  rillig     int com_ind;		/* indentation of the current comment */
    350   1.59  rillig 
    351  1.136  rillig     /* Vertical spacing */
    352   1.59  rillig 
    353  1.136  rillig     bool force_nl;		/* whether the next token goes to a new
    354  1.136  rillig 				 * line */
    355  1.128  rillig 
    356  1.127  rillig     enum declaration {
    357  1.127  rillig 	decl_no,		/* no declaration anywhere nearby */
    358  1.127  rillig 	decl_begin,		/* collecting tokens of a declaration */
    359  1.127  rillig 	decl_end,		/* finished a declaration */
    360  1.127  rillig     } declaration;
    361  1.128  rillig     bool blank_line_after_decl;
    362  1.128  rillig 
    363  1.136  rillig     /* Comments */
    364   1.31  rillig 
    365  1.136  rillig     bool curr_col_1;		/* whether the current token started in column
    366  1.136  rillig 				 * 1 of the original input */
    367  1.136  rillig     bool next_col_1;
    368   1.51  rillig } ps;
    369   1.31  rillig 
    370    1.3  rillig 
    371   1.59  rillig #define array_length(array) (sizeof(array) / sizeof((array)[0]))
    372    1.1   kamil 
    373    1.5  rillig #ifdef debug
    374  1.123  rillig void debug_printf(const char *, ...) __printflike(1, 2);
    375  1.123  rillig void debug_println(const char *, ...) __printflike(1, 2);
    376  1.133  rillig void debug_vis_range(const char *, const char *, size_t, const char *);
    377  1.123  rillig void debug_parser_state(lexer_symbol);
    378  1.123  rillig void debug_parse_stack(const char *);
    379  1.123  rillig void debug_buffers(void);
    380  1.123  rillig extern const char *const lsym_name[];
    381  1.123  rillig extern const char *const psym_name[];
    382    1.9  rillig #else
    383  1.123  rillig #define debug_noop() do { } while (false)
    384  1.123  rillig #define	debug_printf(fmt, ...) debug_noop()
    385  1.123  rillig #define	debug_println(fmt, ...) debug_noop()
    386  1.123  rillig #define	debug_vis_range(prefix, s, e, suffix) debug_noop()
    387  1.134  rillig #define	debug_parser_state(lsym) debug_noop()
    388  1.123  rillig #define	debug_parse_stack(situation) debug_noop()
    389  1.123  rillig #define	debug_buffers() debug_noop()
    390    1.5  rillig #endif
    391   1.67  rillig 
    392   1.74  rillig void register_typename(const char *);
    393   1.67  rillig int compute_code_indent(void);
    394   1.67  rillig int compute_label_indent(void);
    395  1.133  rillig int ind_add(int, const char *, size_t);
    396   1.94  rillig 
    397   1.91  rillig const char *inp_p(void);
    398   1.95  rillig const char *inp_line_start(void);
    399   1.89  rillig char inp_peek(void);
    400   1.90  rillig char inp_lookahead(size_t);
    401   1.79  rillig void inp_skip(void);
    402   1.79  rillig char inp_next(void);
    403   1.89  rillig 
    404   1.54  rillig lexer_symbol lexi(void);
    405  1.129  rillig void diag(int, const char *, ...) __printflike(2, 3);
    406  1.104  rillig void output_line(void);
    407  1.104  rillig void output_line_ff(void);
    408   1.79  rillig void inp_read_line(void);
    409   1.49  rillig void parse(parser_symbol);
    410   1.34  rillig void process_comment(void);
    411   1.34  rillig void set_option(const char *, const char *);
    412   1.34  rillig void load_profiles(const char *);
    413   1.34  rillig 
    414  1.135  rillig void *nonnull(void *);
    415   1.25  rillig 
    416  1.103  rillig void buf_add_char(struct buffer *, char);
    417  1.133  rillig void buf_add_chars(struct buffer *, const char *, size_t);
    418   1.29  rillig 
    419   1.29  rillig static inline bool
    420   1.98  rillig ch_isalnum(char ch)
    421   1.98  rillig {
    422   1.98  rillig     return isalnum((unsigned char)ch) != 0;
    423   1.98  rillig }
    424   1.98  rillig 
    425   1.98  rillig static inline bool
    426   1.98  rillig ch_isalpha(char ch)
    427   1.98  rillig {
    428   1.98  rillig     return isalpha((unsigned char)ch) != 0;
    429   1.98  rillig }
    430   1.98  rillig 
    431   1.98  rillig static inline bool
    432   1.62  rillig ch_isblank(char ch)
    433   1.29  rillig {
    434   1.29  rillig     return ch == ' ' || ch == '\t';
    435   1.29  rillig }
    436   1.38  rillig 
    437   1.98  rillig static inline bool
    438   1.98  rillig ch_isdigit(char ch)
    439   1.98  rillig {
    440   1.98  rillig     return '0' <= ch && ch <= '9';
    441   1.98  rillig }
    442   1.98  rillig 
    443   1.98  rillig static inline bool
    444   1.98  rillig ch_isspace(char ch)
    445   1.98  rillig {
    446   1.98  rillig     return isspace((unsigned char)ch) != 0;
    447   1.98  rillig }
    448   1.98  rillig 
    449   1.38  rillig static inline int
    450   1.38  rillig next_tab(int ind)
    451   1.38  rillig {
    452   1.38  rillig     return ind - ind % opt.tabsize + opt.tabsize;
    453   1.38  rillig }
    454