Module Name: src Committed By: rillig Date: Thu Jun 8 20:36:35 UTC 2023
Modified Files: src/tests/usr.bin/indent: opt_lp.c src/usr.bin/indent: io.c Log Message: indent: fix indentation in multi-line else-if conditions To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/opt_lp.c cvs rdiff -u -r1.203 -r1.204 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/tests/usr.bin/indent/opt_lp.c diff -u src/tests/usr.bin/indent/opt_lp.c:1.8 src/tests/usr.bin/indent/opt_lp.c:1.9 --- src/tests/usr.bin/indent/opt_lp.c:1.8 Thu Jun 8 20:28:50 2023 +++ src/tests/usr.bin/indent/opt_lp.c Thu Jun 8 20:36:35 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_lp.c,v 1.8 2023/06/08 20:28:50 rillig Exp $ */ +/* $NetBSD: opt_lp.c,v 1.9 2023/06/08 20:36:35 rillig Exp $ */ /* * Tests for the options '-lp' and '-nlp'. @@ -89,6 +89,11 @@ example(void) //indent end +/* + * Ensure that in multi-line else-if conditions, all lines are indented by the + * correct amount. The 'else if' condition is tricky because it has the same + * indentation as the preceding 'if' condition. + */ //indent input { if (cond11a @@ -121,8 +126,7 @@ stmt22; && cond11c) { stmt11; } else if (cond12a -// $ FIXME: Wrong indentation, should be 4 spaces only. - && cond12b + && cond12b && cond12c) { stmt12; } @@ -134,8 +138,7 @@ stmt22; && cond21c) stmt21; else if (cond22a -// $ FIXME: Wrong indentation, should be 4 spaces only. - && cond22b + && cond22b && cond22c) stmt22; } Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.203 src/usr.bin/indent/io.c:1.204 --- src/usr.bin/indent/io.c:1.203 Thu Jun 8 06:47:13 2023 +++ src/usr.bin/indent/io.c Thu Jun 8 20:36:35 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.203 2023/06/08 06:47:13 rillig Exp $ */ +/* $NetBSD: io.c,v 1.204 2023/06/08 20:36:35 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: io.c,v 1.203 2023/06/08 06:47:13 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.204 2023/06/08 20:36:35 rillig Exp $"); #include <stdio.h> @@ -378,7 +378,9 @@ prepare_next_line: ps.decl_indent_done = false; if (ps.extra_expr_indent == eei_last) ps.extra_expr_indent = eei_no; - ps.ind_level = ps.ind_level_follow; + if (!(ps.psyms.sym[ps.psyms.top] == psym_if_expr_stmt_else + && ps.nparen > 0)) + ps.ind_level = ps.ind_level_follow; ps.line_start_nparen = ps.nparen; ps.want_blank = false;