Module Name: src Committed By: rillig Date: Fri Oct 8 19:03:34 UTC 2021
Modified Files: src/usr.bin/indent: args.c indent.c indent.h io.c pr_comment.c Log Message: indent: run indent on indent.h The formatting looks mostly OK. Some struct members had excessively long names, leaving no space for their corresponding comments. Renamed some of them using well-known abbreviations. The formatting for debug_vis_range is messed up, no idea why. It is clearly a function declaration, not a function definition, so there is no need to place the function name in column 1. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.51 -r1.52 src/usr.bin/indent/args.c cvs rdiff -u -r1.127 -r1.128 src/usr.bin/indent/indent.c cvs rdiff -u -r1.33 -r1.34 src/usr.bin/indent/indent.h cvs rdiff -u -r1.87 -r1.88 src/usr.bin/indent/io.c cvs rdiff -u -r1.62 -r1.63 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/indent/args.c diff -u src/usr.bin/indent/args.c:1.51 src/usr.bin/indent/args.c:1.52 --- src/usr.bin/indent/args.c:1.51 Thu Oct 7 22:56:49 2021 +++ src/usr.bin/indent/args.c Fri Oct 8 19:03:34 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: args.c,v 1.51 2021/10/07 22:56:49 rillig Exp $ */ +/* $NetBSD: args.c,v 1.52 2021/10/08 19:03:34 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -43,7 +43,7 @@ static char sccsid[] = "@(#)args.c 8.1 ( #include <sys/cdefs.h> #if defined(__NetBSD__) -__RCSID("$NetBSD: args.c,v 1.51 2021/10/07 22:56:49 rillig Exp $"); +__RCSID("$NetBSD: args.c,v 1.52 2021/10/08 19:03:34 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $"); #endif @@ -89,10 +89,10 @@ static const struct pro { void *p_var; /* the associated variable */ } pro[] = { bool_options("bacc", blanklines_around_conditional_compilation), - bool_options("bad", blanklines_after_declarations), - bool_options("badp", blanklines_after_declarations_at_proctop), + bool_options("bad", blanklines_after_decl), + bool_options("badp", blanklines_after_decl_at_top), bool_options("bap", blanklines_after_procs), - bool_options("bbb", blanklines_before_blockcomments), + bool_options("bbb", blanklines_before_block_comments), bool_options("bc", break_after_comma), bool_option("bl", false, brace_same_line), bool_option("br", true, brace_same_line), @@ -107,7 +107,7 @@ static const struct pro { int_option("d", unindent_displace), int_option("di", decl_indent), bool_options("dj", ljust_decl), - bool_options("eei", extra_expression_indent), + bool_options("eei", extra_expr_indent), bool_options("ei", else_if), bool_options("fbs", function_brace_split), bool_options("fc1", format_col1_comments), Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.127 src/usr.bin/indent/indent.c:1.128 --- src/usr.bin/indent/indent.c:1.127 Fri Oct 8 16:47:42 2021 +++ src/usr.bin/indent/indent.c Fri Oct 8 19:03:34 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.127 2021/10/08 16:47:42 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.128 2021/10/08 19:03:34 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include <sys/cdefs.h> #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.127 2021/10/08 16:47:42 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.128 2021/10/08 19:03:34 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -657,7 +657,7 @@ process_lparen_or_lbracket(int decl_ind, debug_println("paren_indent[%d] is now %d", ps.p_l_follow - 1, ps.paren_indents[ps.p_l_follow - 1]); - if (sp_sw && ps.p_l_follow == 1 && opt.extra_expression_indent + if (sp_sw && ps.p_l_follow == 1 && opt.extra_expr_indent && ps.paren_indents[0] < 2 * opt.indent_size) { ps.paren_indents[0] = (short)(2 * opt.indent_size); debug_println("paren_indent[0] is now %d", ps.paren_indents[0]); @@ -904,8 +904,7 @@ process_lbrace(bool *force_nl, bool *sp_ ps.decl_on_line = false; /* we can't be in the middle of a * declaration, so don't do special * indentation of comments */ - if (opt.blanklines_after_declarations_at_proctop - && ps.in_parameter_declaration) + if (opt.blanklines_after_decl_at_top && ps.in_parameter_declaration) postfix_blankline_requested = true; ps.in_parameter_declaration = false; ps.in_decl = false; Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.33 src/usr.bin/indent/indent.h:1.34 --- src/usr.bin/indent/indent.h:1.33 Fri Oct 8 17:19:49 2021 +++ src/usr.bin/indent/indent.h Fri Oct 8 19:03:34 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.33 2021/10/08 17:19:49 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.34 2021/10/08 19:03:34 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -123,103 +123,100 @@ struct buffer { char *l; /* limit */ }; -extern FILE *input; /* the fid for the input file */ -extern FILE *output; /* the output file */ +extern FILE *input; +extern FILE *output; -extern struct buffer lab; /* label or preprocessor directive */ -extern struct buffer code; /* code */ -extern struct buffer com; /* comment */ -extern struct buffer token; /* the last token scanned */ +extern struct buffer lab; /* label or preprocessor directive */ +extern struct buffer code; /* code */ +extern struct buffer com; /* comment */ +extern struct buffer token; /* the last token scanned */ extern struct buffer inp; -extern char sc_buf[sc_size]; /* input text is saved here when looking for +extern char sc_buf[sc_size]; /* input text is saved here when looking for * the brace after an if, while, etc */ -extern char *save_com; /* start of the comment stored in sc_buf */ +extern char *save_com; /* start of the comment stored in sc_buf */ -extern char *saved_inp_s; /* saved value of inp.s when taking input - * from save_com */ -extern char *saved_inp_e; /* similarly saved value of inp.e */ +extern char *saved_inp_s; /* saved value of inp.s when taking input from + * save_com */ +extern char *saved_inp_e; /* similarly saved value of inp.e */ extern struct options { - bool blanklines_around_conditional_compilation; - bool blanklines_after_declarations_at_proctop; /* this is vaguely - * similar to blanklines_after_declarations - * except that it only applies to the first - * set of declarations in a procedure (just - * after the first '{') and it causes a blank - * line to be generated even if there are no - * declarations */ - bool blanklines_after_declarations; - bool blanklines_after_procs; - bool blanklines_before_blockcomments; - bool break_after_comma; /* whether to break declarations after - * commas */ - bool brace_same_line;/* whether brace should be on same line - * as if, while, etc */ - bool blank_after_sizeof; /* whether a blank should always be - * inserted after sizeof */ - bool comment_delimiter_on_blankline; - int decl_comment_column; /* the column in which comments after + bool blanklines_around_conditional_compilation; + bool blanklines_after_decl_at_top; /* this is vaguely similar to + * blanklines_after_decl except that + * it only applies to the first set of + * declarations in a procedure (just + * after the first '{') and it causes + * a blank line to be generated even + * if there are no declarations */ + bool blanklines_after_decl; + bool blanklines_after_procs; + bool blanklines_before_block_comments; + bool break_after_comma; /* whether to break declarations after commas */ + bool brace_same_line; /* whether brace should be on same line as if, + * while, etc */ + bool blank_after_sizeof; /* whether a blank should always be inserted + * after sizeof */ + bool comment_delimiter_on_blankline; + int decl_comment_column; /* the column in which comments after * declarations should be put */ - bool cuddle_else; /* whether 'else' should cuddle up to '}' */ - int continuation_indent; /* the indentation between the - * edge of code and continuation lines */ - float case_indent; /* The distance (measured in indentation + bool cuddle_else; /* whether 'else' should cuddle up to '}' */ + int continuation_indent; /* the indentation between the edge of code + * and continuation lines */ + float case_indent; /* The distance (measured in indentation * levels) to indent case labels from the * switch statement */ - int comment_column; /* the column in which comments to the right + int comment_column; /* the column in which comments to the right * of code should start */ - int decl_indent; /* indentation of identifier in declaration */ - bool ljust_decl; /* true if declarations should be left + int decl_indent; /* indentation of identifier in declaration */ + bool ljust_decl; /* true if declarations should be left * justified */ - int unindent_displace; /* comments not to the right of code - * will be placed this many - * indentation levels to the left of - * code */ - bool extra_expression_indent; /* whether continuation lines from - * the expression part of "if(e)", - * "while(e)", "for(e;e;e)" should be - * indented an extra tab stop so that they - * don't conflict with the code that follows */ - bool else_if; /* whether else-if pairs should be handled + int unindent_displace; /* comments not to the right of code will be + * placed this many indentation levels to the + * left of code */ + bool extra_expr_indent; /* whether continuation lines from the + * expression part of "if(e)", "while(e)", + * "for(e;e;e)" should be indented an extra + * tab stop so that they don't conflict with + * the code that follows */ + bool else_if; /* whether else-if pairs should be handled * specially */ - bool function_brace_split; /* split function declaration and - * brace onto separate lines */ - bool format_col1_comments; /* If comments which start in column 1 - * are to be magically reformatted (just - * like comments that begin in later columns) */ - bool format_block_comments; /* whether comments beginning with - * '/ * \n' are to be reformatted */ - bool indent_parameters; - int indent_size; /* the size of one indentation level */ - int block_comment_max_line_length; - int local_decl_indent; /* like decl_indent but for locals */ - bool lineup_to_parens_always; /* whether to not(?) attempt to keep - * lined-up code within the margin */ - bool lineup_to_parens; /* whether continued code within parens - * will be lined up to the open paren */ - bool proc_calls_space; /* whether procedure calls look like: - * foo (bar) rather than foo(bar) */ - bool procnames_start_line; /* whether the names of procedures - * being defined get placed in column 1 (i.e. - * a newline is placed between the type of - * the procedure and its name) */ - bool space_after_cast; /* "b = (int) a" vs "b = (int)a" */ - bool star_comment_cont; /* whether comment continuation lines - * should have stars at the beginning of - * each line. */ - bool swallow_optional_blanklines; - bool auto_typedefs; /* whether to recognize identifiers - * ending in "_t" like typedefs */ - int tabsize; /* the size of a tab */ - int max_line_length; - bool use_tabs; /* set true to use tabs for spacing, false + bool function_brace_split; /* split function declaration and brace onto + * separate lines */ + bool format_col1_comments; /* If comments which start in column 1 are to + * be magically reformatted (just like + * comments that begin in later columns) */ + bool format_block_comments; /* whether comments beginning with '/ * \n' + * are to be reformatted */ + bool indent_parameters; + int indent_size; /* the size of one indentation level */ + int block_comment_max_line_length; + int local_decl_indent; /* like decl_indent but for locals */ + bool lineup_to_parens_always; /* whether to not(?) attempt to keep + * lined-up code within the margin */ + bool lineup_to_parens; /* whether continued code within parens will + * be lined up to the open paren */ + bool proc_calls_space; /* whether function calls look like: foo (bar) + * rather than foo(bar) */ + bool procnames_start_line; /* whether the names of procedures being + * defined get placed in column 1 (i.e. a + * newline is placed between the type of the + * procedure and its name) */ + bool space_after_cast; /* "b = (int) a" vs "b = (int)a" */ + bool star_comment_cont; /* whether comment continuation lines should + * have stars at the beginning of each line. */ + bool swallow_optional_blanklines; + bool auto_typedefs; /* whether to recognize identifiers ending in + * "_t" like typedefs */ + int tabsize; /* the size of a tab */ + int max_line_length; + bool use_tabs; /* set true to use tabs for spacing, false * uses all spaces */ - bool verbose; /* whether non-essential error messages - * are printed */ -} opt; + bool verbose; /* whether non-essential error messages are + * printed */ +} opt; enum keyword_kind { kw_0, @@ -238,135 +235,135 @@ enum keyword_kind { }; -extern bool found_err; -extern int next_blank_lines; -extern bool prefix_blankline_requested; -extern bool postfix_blankline_requested; -extern bool break_comma; /* when true and not in parens, break after a +extern bool found_err; +extern int next_blank_lines; +extern bool prefix_blankline_requested; +extern bool postfix_blankline_requested; +extern bool break_comma; /* when true and not in parens, break after a * comma */ -extern float case_ind; /* indentation level to be used for a "case +extern float case_ind; /* indentation level to be used for a "case * n:" */ -extern bool had_eof; /* whether input is exhausted */ -extern int line_no; /* the current line number. */ -extern bool inhibit_formatting; /* true if INDENT OFF is in effect */ +extern bool had_eof; /* whether input is exhausted */ +extern int line_no; /* the current line number. */ +extern bool inhibit_formatting; /* true if INDENT OFF is in effect */ #define STACKSIZE 256 extern struct parser_state { - token_type last_token; - token_type p_stack[STACKSIZE]; /* this is the parser's stack */ - int il[STACKSIZE]; /* this stack stores indentation levels */ - float cstk[STACKSIZE];/* used to store case stmt indentation levels */ - bool box_com; /* whether we are in a "boxed" comment. In + token_type last_token; + token_type p_stack[STACKSIZE]; + int il[STACKSIZE]; /* this stack stores indentation levels */ + float cstk[STACKSIZE]; /* used to store case stmt indentation levels */ + bool box_com; /* whether we are in a "boxed" comment. In * that case, the first non-blank char should * be lined up with the '/' in '/' + '*' */ - int comment_delta; /* used to set up indentation for all lines - * of a boxed comment after the first one */ - int n_comment_delta;/* remembers how many columns there were + int comment_delta; /* used to set up indentation for all lines of + * a boxed comment after the first one */ + int n_comment_delta; /* remembers how many columns there were * before the start of a box comment so that * forthcoming lines of the comment are * indented properly */ - int cast_mask; /* indicates which close parens potentially + int cast_mask; /* indicates which close parens potentially * close off casts */ - int not_cast_mask; /* indicates which close parens definitely + int not_cast_mask; /* indicates which close parens definitely * close off something else than casts */ - bool block_init; /* whether inside a block initialization */ - int block_init_level; /* The level of brace nesting in an + bool block_init; /* whether inside a block initialization */ + int block_init_level; /* The level of brace nesting in an * initialization */ - bool last_nl; /* whether the last thing scanned was - * a newline */ - bool in_or_st; /* true iff there has been a - * declarator (e.g. int or char) and no left - * paren since the last semicolon. When true, - * a '{' is starting a structure definition or - * an initialization list */ - bool col_1; /* whether the last token started in - * column 1 */ - int com_ind; /* indentation of the current comment */ - int decl_nest; /* current nesting level for structure or init */ - bool decl_on_line; /* whether this line of code has part - * of a declaration on it */ - int ind_level_follow; /* the level to which ind_level should be set + bool last_nl; /* whether the last thing scanned was a + * newline */ + bool in_or_st; /* true iff there has been a declarator (e.g. + * int or char) and no left paren since the + * last semicolon. When true, a '{' is + * starting a structure definition or an + * initialization list */ + bool col_1; /* whether the last token started in column 1 */ + int com_ind; /* indentation of the current comment */ + int decl_nest; /* current nesting level for structure or init */ + bool decl_on_line; /* whether this line of code has part of a + * declaration on it */ + int ind_level_follow; /* the level to which ind_level should be set * after the current line is printed */ - bool in_decl; /* whether we are in a declaration stmt. - * The processing of braces is then slightly + bool in_decl; /* whether we are in a declaration stmt. The + * processing of braces is then slightly * different */ - bool in_stmt; - int ind_level; /* the current indentation level */ - bool ind_stmt; /* whether the next line should have an extra + bool in_stmt; + int ind_level; /* the current indentation level */ + bool ind_stmt; /* whether the next line should have an extra * indentation level because we are in the * middle of a stmt */ - bool last_u_d; /* whether the following operator should be + bool last_u_d; /* whether the following operator should be * unary */ - int p_l_follow; /* used to remember how to indent the + int p_l_follow; /* used to remember how to indent the * following statement */ - int paren_level; /* parenthesization level. used to indent + int paren_level; /* parenthesization level. used to indent * within statements */ - short paren_indents[20]; /* indentation of the operand/argument of - * each level of parentheses or brackets, - * relative to the enclosing statement */ - bool is_case_label; /* 'case' and 'default' labels are indented + short paren_indents[20]; /* indentation of the operand/argument of each + * level of parentheses or brackets, relative + * to the enclosing statement */ + bool is_case_label; /* 'case' and 'default' labels are indented * differently from regular labels */ - bool search_brace; /* whether it is necessary - * to buffer up all info up to the start of a - * stmt after an if, while, etc */ - bool use_ff; /* whether the current line should be + bool search_brace; /* whether it is necessary to buffer up all + * info up to the start of a stmt after an if, + * while, etc */ + bool use_ff; /* whether the current line should be * terminated with a form feed */ - bool want_blank; /* whether the following token should - * be prefixed by a blank. (Said prefixing is + bool want_blank; /* whether the following token should be + * prefixed by a blank. (Said prefixing is * ignored in some cases.) */ enum keyword_kind keyword; - bool dumped_decl_indent; - bool in_parameter_declaration; - int tos; /* pointer to top of stack */ - char procname[100]; /* The name of the current procedure */ - int just_saw_decl; + bool dumped_decl_indent; + bool in_parameter_declaration; + int tos; /* pointer to top of stack */ + char procname[100]; /* The name of the current procedure */ + int just_saw_decl; struct { - int comments; - int lines; - int code_lines; - int comment_lines; - } stats; -} ps; + int comments; + int lines; + int code_lines; + int comment_lines; + } stats; +} ps; #ifndef nitems #define nitems(array) (sizeof (array) / sizeof (array[0])) #endif -void add_typename(const char *); -int compute_code_indent(void); -int compute_label_indent(void); -int indentation_after_range(int, const char *, const char *); -int indentation_after(int, const char *); +void add_typename(const char *); +int compute_code_indent(void); +int compute_label_indent(void); +int indentation_after_range(int, const char *, const char *); +int indentation_after(int, const char *); #ifdef debug -void debug_vis_range(const char *, const char *, const char *, - const char *); -void debug_printf(const char *, ...) __printflike(1, 2); -void debug_println(const char *, ...) __printflike(1, 2); -const char * token_type_name(token_type); +void +debug_vis_range(const char *, const char *, const char *, + const char *); +void debug_printf(const char *, ...)__printflike(1, 2); +void debug_println(const char *, ...)__printflike(1, 2); +const char *token_type_name(token_type); #else #define debug_printf(fmt, ...) do { } while (false) #define debug_println(fmt, ...) do { } while (false) #define debug_vis_range(prefix, s, e, suffix) do { } while (false) #endif -void inbuf_skip(void); -char inbuf_next(void); -token_type lexi(struct parser_state *); -void diag(int, const char *, ...) __printflike(2, 3); -void dump_line(void); -void fill_buffer(void); -void parse(token_type); -void process_comment(void); -void set_option(const char *, const char *); -void load_profiles(const char *); - -void *xmalloc(size_t); -void *xrealloc(void *, size_t); -char *xstrdup(const char *); +void inbuf_skip(void); +char inbuf_next(void); +token_type lexi(struct parser_state *); +void diag(int, const char *, ...)__printflike(2, 3); +void dump_line(void); +void fill_buffer(void); +void parse(token_type); +void process_comment(void); +void set_option(const char *, const char *); +void load_profiles(const char *); + +void *xmalloc(size_t); +void *xrealloc(void *, size_t); +char *xstrdup(const char *); -void buf_expand(struct buffer *, size_t); +void buf_expand(struct buffer *, size_t); static inline bool is_hspace(char ch) Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.87 src/usr.bin/indent/io.c:1.88 --- src/usr.bin/indent/io.c:1.87 Fri Oct 8 18:29:36 2021 +++ src/usr.bin/indent/io.c Fri Oct 8 19:03:34 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.87 2021/10/08 18:29:36 rillig Exp $ */ +/* $NetBSD: io.c,v 1.88 2021/10/08 19:03:34 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -43,7 +43,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include <sys/cdefs.h> #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.87 2021/10/08 18:29:36 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.88 2021/10/08 19:03:34 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -270,7 +270,7 @@ dump_line(void) output_char('\n'); ps.stats.lines++; - if (ps.just_saw_decl == 1 && opt.blanklines_after_declarations) { + if (ps.just_saw_decl == 1 && opt.blanklines_after_decl) { prefix_blankline_requested = true; ps.just_saw_decl = 0; } else Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.62 src/usr.bin/indent/pr_comment.c:1.63 --- src/usr.bin/indent/pr_comment.c:1.62 Fri Oct 8 18:29:36 2021 +++ src/usr.bin/indent/pr_comment.c Fri Oct 8 19:03:34 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.62 2021/10/08 18:29:36 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.63 2021/10/08 19:03:34 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -43,7 +43,7 @@ static char sccsid[] = "@(#)pr_comment.c #include <sys/cdefs.h> #if defined(__NetBSD__) -__RCSID("$NetBSD: pr_comment.c,v 1.62 2021/10/08 18:29:36 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.63 2021/10/08 19:03:34 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -197,7 +197,7 @@ process_comment(void) char *t = com.e; com.e = com.s + 2; *com.e = '\0'; - if (opt.blanklines_before_blockcomments && ps.last_token != lbrace) + if (opt.blanklines_before_block_comments && ps.last_token != lbrace) prefix_blankline_requested = true; dump_line(); com.e = com.s = t;