Module Name: src Committed By: rillig Date: Mon Oct 25 19:56:03 UTC 2021
Modified Files: src/usr.bin/indent: indent.c indent.h parse.c Log Message: indent: rename search_brace to search_stmt No functional change. To generate a diff of this commit: cvs rdiff -u -r1.157 -r1.158 src/usr.bin/indent/indent.c cvs rdiff -u -r1.49 -r1.50 src/usr.bin/indent/indent.h cvs rdiff -u -r1.39 -r1.40 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.157 src/usr.bin/indent/indent.c:1.158 --- src/usr.bin/indent/indent.c:1.157 Mon Oct 25 01:06:13 2021 +++ src/usr.bin/indent/indent.c Mon Oct 25 19:56:03 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.157 2021/10/25 01:06:13 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.158 2021/10/25 19:56:03 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.157 2021/10/25 01:06:13 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.158 2021/10/25 19:56:03 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -157,7 +157,7 @@ diag(int level, const char *msg, ...) } static void -search_brace_newline(bool *force_nl) +search_stmt_newline(bool *force_nl) { if (sc_end == NULL) { save_com = sc_buf; @@ -180,7 +180,7 @@ search_brace_newline(bool *force_nl) } static void -search_brace_comment(bool *comment_buffered) +search_stmt_comment(bool *comment_buffered) { if (sc_end == NULL) { /* @@ -215,7 +215,7 @@ search_brace_comment(bool *comment_buffe } static bool -search_brace_lbrace(void) +search_stmt_lbrace(void) { /* * Put KNF-style lbraces before the buffered up tokens and jump out of @@ -239,7 +239,7 @@ search_brace_lbrace(void) } static bool -search_brace_other(lexer_symbol lsym, bool *force_nl, +search_stmt_other(lexer_symbol lsym, bool *force_nl, bool comment_buffered, bool last_else) { bool remove_newlines; @@ -254,7 +254,7 @@ search_brace_other(lexer_symbol lsym, bo if (sc_end == NULL) { /* ignore buffering if comment wasn't saved * up */ - ps.search_brace = false; + ps.search_stmt = false; return false; } @@ -289,7 +289,7 @@ search_brace_other(lexer_symbol lsym, bo static void switch_buffer(void) { - ps.search_brace = false; /* stop looking for start of stmt */ + ps.search_stmt = false; saved_inp_s = inp.s; /* save current input buffer */ saved_inp_e = inp.e; inp.s = save_com; /* fix so that subsequent calls to lexi will @@ -301,7 +301,7 @@ switch_buffer(void) } static void -search_brace_lookahead(lexer_symbol *lsym) +search_stmt_lookahead(lexer_symbol *lsym) { if (*lsym == lsym_eof) return; @@ -337,37 +337,37 @@ search_brace_lookahead(lexer_symbol *lsy transient_state = ps; *lsym = lexi(&transient_state); /* read another token */ if (*lsym != lsym_newline && *lsym != lsym_form_feed && - *lsym != lsym_comment && !transient_state.search_brace) { + *lsym != lsym_comment && !transient_state.search_stmt) { ps = transient_state; } } static void -search_brace(lexer_symbol *lsym, bool *force_nl, +search_stmt(lexer_symbol *lsym, bool *force_nl, bool *comment_buffered, bool *last_else) { - while (ps.search_brace) { + while (ps.search_stmt) { switch (*lsym) { case lsym_newline: - search_brace_newline(force_nl); + search_stmt_newline(force_nl); break; case lsym_form_feed: break; case lsym_comment: - search_brace_comment(comment_buffered); + search_stmt_comment(comment_buffered); break; case lsym_lbrace: - if (search_brace_lbrace()) + if (search_stmt_lbrace()) goto switch_buffer; /* FALLTHROUGH */ default: /* it is the start of a normal statement */ - if (!search_brace_other(*lsym, force_nl, + if (!search_stmt_other(*lsym, force_nl, *comment_buffered, *last_else)) return; switch_buffer: switch_buffer(); } - search_brace_lookahead(lsym); + search_stmt_lookahead(lsym); } *last_else = false; @@ -792,7 +792,7 @@ process_rparen_or_rbracket(bool *spaced_ * This should ensure that constructs such as main(){...} and int[]{...} * have their braces put in the right place. */ - ps.search_brace = opt.brace_same_line; + ps.search_stmt = opt.brace_same_line; } static void @@ -1028,7 +1028,7 @@ process_rbrace(bool *spaced_expr, int *d blank_line_before = false; parse(psym_rbrace); - ps.search_brace = opt.cuddle_else + ps.search_stmt = opt.cuddle_else && ps.s_sym[ps.tos] == psym_if_expr_stmt && ps.s_ind_level[ps.tos] >= ps.ind_level; @@ -1357,7 +1357,7 @@ main_loop(void) * proper handling of both kinds of brace placement (-br, -bl) and * cuddling "else" (-ce). */ - search_brace(&lsym, &force_nl, &comment_buffered, &last_else); + search_stmt(&lsym, &force_nl, &comment_buffered, &last_else); if (lsym == lsym_eof) { process_end_of_file(); Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.49 src/usr.bin/indent/indent.h:1.50 --- src/usr.bin/indent/indent.h:1.49 Mon Oct 25 00:54:37 2021 +++ src/usr.bin/indent/indent.h Mon Oct 25 19:56:03 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.49 2021/10/25 00:54:37 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.50 2021/10/25 19:56:03 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -326,9 +326,9 @@ extern struct parser_state { * 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 search_stmt; /* whether it is necessary to buffer up all + * text up to the start of a statement after + * an 'if', 'while', etc. */ bool want_blank; /* whether the following token should be * prefixed by a blank. (Said prefixing is * ignored in some cases.) */ Index: src/usr.bin/indent/parse.c diff -u src/usr.bin/indent/parse.c:1.39 src/usr.bin/indent/parse.c:1.40 --- src/usr.bin/indent/parse.c:1.39 Mon Oct 25 00:54:37 2021 +++ src/usr.bin/indent/parse.c Mon Oct 25 19:56:03 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.39 2021/10/25 00:54:37 rillig Exp $ */ +/* $NetBSD: parse.c,v 1.40 2021/10/25 19:56:03 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -104,7 +104,7 @@ parse(parser_symbol psym) switch (psym) { case psym_decl: - ps.search_brace = opt.brace_same_line; + ps.search_stmt = opt.brace_same_line; /* indicate that following brace should be on same line */ if (ps.s_sym[ps.tos] != psym_decl) { /* only put one declaration @@ -139,7 +139,7 @@ parse(parser_symbol psym) 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.search_brace = opt.brace_same_line; + ps.search_stmt = opt.brace_same_line; break; case psym_lbrace: @@ -180,7 +180,7 @@ parse(parser_symbol psym) ps.s_sym[++ps.tos] = psym_while_expr; ps.s_ind_level[ps.tos] = ps.ind_level_follow; ++ps.ind_level_follow; - ps.search_brace = opt.brace_same_line; + ps.search_stmt = opt.brace_same_line; } break; @@ -194,7 +194,7 @@ parse(parser_symbol psym) ps.ind_level_follow = ps.ind_level + 1; ps.s_sym[ps.tos] = psym_if_expr_stmt_else; /* remember if with else */ - ps.search_brace = opt.brace_same_line || opt.else_if; + ps.search_stmt = opt.brace_same_line || opt.else_if; } break; @@ -216,7 +216,7 @@ parse(parser_symbol psym) case_ind = (float)ps.ind_level_follow + opt.case_indent; /* statements should be two levels deeper */ ps.ind_level_follow += (int)opt.case_indent + 1; - ps.search_brace = opt.brace_same_line; + ps.search_stmt = opt.brace_same_line; break; case psym_semicolon: /* this indicates a simple stmt */