Module Name: src Committed By: rillig Date: Thu Jun 15 11:27:37 UTC 2023
Modified Files: src/usr.bin/indent: indent.c io.c Log Message: indent: consolidate handling of statement continuations To generate a diff of this commit: cvs rdiff -u -r1.371 -r1.372 src/usr.bin/indent/indent.c cvs rdiff -u -r1.224 -r1.225 src/usr.bin/indent/io.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.371 src/usr.bin/indent/indent.c:1.372 --- src/usr.bin/indent/indent.c:1.371 Thu Jun 15 10:59:06 2023 +++ src/usr.bin/indent/indent.c Thu Jun 15 11:27:36 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.371 2023/06/15 10:59:06 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.372 2023/06/15 11:27:36 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: indent.c,v 1.371 2023/06/15 10:59:06 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.372 2023/06/15 11:27:36 rillig Exp $"); #include <sys/param.h> #include <err.h> @@ -562,12 +562,6 @@ process_newline(void) output_line(); - if (ps.psyms.len >= 2 - && ps.psyms.sym[ps.psyms.len - 2] == psym_lbrace_enum - && ps.paren.len == 0 - && ps.prev_lsym == lsym_comma) - ps.line_is_stmt_cont = false; - stay_in_line: ++line_no; } Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.224 src/usr.bin/indent/io.c:1.225 --- src/usr.bin/indent/io.c:1.224 Thu Jun 15 10:59:06 2023 +++ src/usr.bin/indent/io.c Thu Jun 15 11:27:36 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.224 2023/06/15 10:59:06 rillig Exp $ */ +/* $NetBSD: io.c,v 1.225 2023/06/15 11:27:36 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: io.c,v 1.224 2023/06/15 10:59:06 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.225 2023/06/15 11:27:36 rillig Exp $"); #include <stdio.h> @@ -55,7 +55,7 @@ static unsigned newlines = 2; /* the tot * finished line, anything > 1 are trailing * blank lines */ static unsigned buffered_newlines; /* not yet written */ -static int paren_indent; +static int paren_indent; /* total indentation when parenthesized */ static void @@ -368,6 +368,19 @@ output_indented_line(void) out.prev_line_kind = out.line_kind; } +static bool +is_stmt_cont(void) +{ + if (ps.psyms.len >= 2 + && ps.psyms.sym[ps.psyms.len - 2] == psym_lbrace_enum + && ps.prev_lsym == lsym_comma + && ps.paren.len == 0) + return false; + return ps.in_stmt_or_decl + && (!ps.in_decl || ps.in_init) + && ps.init_level == 0; +} + /* * Write a line of formatted source to the output file. The line consists of * the label, the code and the comment. @@ -393,9 +406,7 @@ output_line(void) ps.line_has_decl = ps.in_decl; ps.line_has_func_def = false; - ps.line_is_stmt_cont = ps.in_stmt_or_decl - && (!ps.in_decl || ps.in_init) - && ps.init_level == 0; + ps.line_is_stmt_cont = is_stmt_cont(); ps.decl_indent_done = false; if (ps.extra_expr_indent == eei_last) ps.extra_expr_indent = eei_no;