Module Name: src Committed By: rillig Date: Mon May 15 20:12:28 UTC 2023
Modified Files: src/usr.bin/indent: indent.c indent.h parse.c Log Message: indent: format its own code, extend some comments With manual corrections, as there are still some bugs left. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.280 -r1.281 src/usr.bin/indent/indent.c cvs rdiff -u -r1.139 -r1.140 src/usr.bin/indent/indent.h cvs rdiff -u -r1.57 -r1.58 src/usr.bin/indent/parse.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/indent.c diff -u src/usr.bin/indent/indent.c:1.280 src/usr.bin/indent/indent.c:1.281 --- src/usr.bin/indent/indent.c:1.280 Mon May 15 18:22:40 2023 +++ src/usr.bin/indent/indent.c Mon May 15 20:12:28 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.280 2023/05/15 18:22:40 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.281 2023/05/15 20:12:28 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: indent.c,v 1.280 2023/05/15 18:22:40 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.281 2023/05/15 20:12:28 rillig Exp $"); #include <sys/param.h> #include <err.h> @@ -269,7 +269,8 @@ main_parse_command_line(int argc, char * } if (opt.comment_column <= 1) - opt.comment_column = 2; /* don't put normal comments before column 2 */ + opt.comment_column = 2; /* don't put normal comments in column 1, see + * opt.format_col1_comments */ if (opt.block_comment_max_line_length <= 0) opt.block_comment_max_line_length = opt.max_line_length; if (opt.local_decl_indent < 0) @@ -605,8 +606,8 @@ process_semicolon(void) { if (ps.decl_level == 0) ps.init_or_struct = false; - ps.seen_case = false; /* these will only need resetting in an error */ - ps.quest_level = 0; + ps.seen_case = false; /* only needs to be reset on error */ + ps.quest_level = 0; /* only needs to be reset on error */ if (ps.prev_token == lsym_rparen_or_rbracket) ps.in_func_def_params = false; ps.block_init = false; @@ -718,7 +719,7 @@ process_rbrace(void) ps.declaration = decl_no; ps.block_init_level--; - if (code.len > 0 && !ps.block_init) { /* '}' must be first on line */ + if (code.len > 0 && !ps.block_init) { if (opt.verbose) diag(0, "Line broken"); output_line(); Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.139 src/usr.bin/indent/indent.h:1.140 --- src/usr.bin/indent/indent.h:1.139 Mon May 15 13:33:19 2023 +++ src/usr.bin/indent/indent.h Mon May 15 20:12:28 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.139 2023/05/15 13:33:19 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.140 2023/05/15 20:12:28 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -139,7 +139,8 @@ extern struct buffer token; /* the curre * in some cases to 'lab'. */ extern struct buffer lab; /* the label or preprocessor directive */ -extern struct buffer code; /* the main part of the current line of code */ +extern struct buffer code; /* the main part of the current line of code, + * containing declarations or statements */ extern struct buffer com; /* the trailing comment of the line, or the * start or end of a multi-line comment, or * while in process_comment, a single line of @@ -157,7 +158,8 @@ extern struct options { bool blank_line_after_decl; bool blanklines_after_procs; bool blanklines_before_block_comments; - bool break_after_comma; /* whether to break declarations after commas */ + bool break_after_comma; /* whether to add a line break after each + * declarator */ 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 @@ -208,7 +210,7 @@ extern struct options { * 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. */ + * have stars at the beginning of each line */ bool swallow_optional_blanklines; bool auto_typedefs; /* whether to recognize identifiers ending in * "_t" like typedefs */ @@ -335,9 +337,9 @@ extern struct parser_state { * prefixed by a blank. (Said prefixing is * ignored in some cases.) */ int line_start_nparen; /* the number of parentheses or brackets that - * were already open at the beginning of the - * current line; used to indent within - * statements, initializers and declarations */ + * were open at the beginning of the current + * line; used to indent within statements, + * initializers and declarations */ int nparen; /* the number of parentheses or brackets that * are currently open; used to indent the * remaining lines of the statement, @@ -356,8 +358,10 @@ extern struct parser_state { /* Vertical spacing */ - bool force_nl; /* whether the next token goes to a new - * line */ + bool force_nl; /* whether the next token is forced to go to + * a new line; used after 'if (expr)' and + * similar situations; tokens like '{' may + * ignore this */ enum declaration { decl_no, /* no declaration anywhere nearby */ Index: src/usr.bin/indent/parse.c diff -u src/usr.bin/indent/parse.c:1.57 src/usr.bin/indent/parse.c:1.58 --- src/usr.bin/indent/parse.c:1.57 Mon May 15 08:11:27 2023 +++ src/usr.bin/indent/parse.c Mon May 15 20:12:28 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.57 2023/05/15 08:11:27 rillig Exp $ */ +/* $NetBSD: parse.c,v 1.58 2023/05/15 20:12:28 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: parse.c,v 1.57 2023/05/15 08:11:27 rillig Exp $"); +__RCSID("$NetBSD: parse.c,v 1.58 2023/05/15 20:12:28 rillig Exp $"); #include <err.h> @@ -100,7 +100,7 @@ parse(parser_symbol psym) case psym_for_exprs: ps.s_sym[++ps.tos] = psym; ps.s_ind_level[ps.tos] = ps.ind_level = ps.ind_level_follow; - ++ps.ind_level_follow; /* subsequent statements should be indented 1 */ + ++ps.ind_level_follow; break; case psym_lbrace: