Module Name:    src
Committed By:   rillig
Date:           Mon Jun  5 12:01:34 UTC 2023

Modified Files:
        src/tests/usr.bin/indent: opt_sob.c
        src/usr.bin/indent: indent.c io.c

Log Message:
indent: don't remove blank line after 'if (expr) {'


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/indent/opt_sob.c
cvs rdiff -u -r1.333 -r1.334 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.196 -r1.197 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_sob.c
diff -u src/tests/usr.bin/indent/opt_sob.c:1.9 src/tests/usr.bin/indent/opt_sob.c:1.10
--- src/tests/usr.bin/indent/opt_sob.c:1.9	Fri Jun  2 13:59:33 2023
+++ src/tests/usr.bin/indent/opt_sob.c	Mon Jun  5 12:01:34 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_sob.c,v 1.9 2023/06/02 13:59:33 rillig Exp $ */
+/* $NetBSD: opt_sob.c,v 1.10 2023/06/05 12:01:34 rillig Exp $ */
 
 /*
  * Tests for the options '-sob' and '-nsob'.
@@ -115,8 +115,8 @@ function_with_1_blank_line(void)
 		var--;
 
 	if (var > 0) {
+
 		var--;
-// $ XXX: The following blank line may be considered optional.
 
 	}
 
@@ -137,8 +137,8 @@ function_with_2_blank_lines(void)
 		var--;
 
 	if (var > 0) {
+
 		var--;
-// $ XXX: The following blank line may be considered optional.
 
 	}
 
@@ -148,3 +148,27 @@ function_with_2_blank_lines(void)
 //indent end
 
 //indent run-equals-input -nsob
+
+
+//indent input
+{
+	switch (expr) {
+
+	case 1:
+
+	}
+}
+//indent end
+
+//indent run-equals-input -sob
+
+//indent run -sob -bl
+{
+	switch (expr)
+	{
+
+	case 1:
+
+	}
+}
+//indent end

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.333 src/usr.bin/indent/indent.c:1.334
--- src/usr.bin/indent/indent.c:1.333	Mon Jun  5 10:12:21 2023
+++ src/usr.bin/indent/indent.c	Mon Jun  5 12:01:33 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.333 2023/06/05 10:12:21 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.334 2023/06/05 12:01:33 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.333 2023/06/05 10:12:21 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.334 2023/06/05 12:01:33 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -682,6 +682,8 @@ process_colon_other(void)
 static void
 process_semicolon(void)
 {
+	if (out.line_kind == lk_stmt_head)
+		out.line_kind = lk_other;
 	if (ps.decl_level == 0)
 		ps.init_or_struct = false;
 	ps.seen_case = false;	/* only needs to be reset on error */
@@ -737,6 +739,9 @@ process_lbrace(void)
 		ps.init_or_struct = true;
 	}
 
+	if (out.line_kind == lk_stmt_head)
+		out.line_kind = lk_other;
+
 	ps.in_stmt_or_decl = false;	/* don't indent the {} */
 
 	if (!ps.block_init)

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.196 src/usr.bin/indent/io.c:1.197
--- src/usr.bin/indent/io.c:1.196	Mon Jun  5 09:41:40 2023
+++ src/usr.bin/indent/io.c	Mon Jun  5 12:01:33 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.196 2023/06/05 09:41:40 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.197 2023/06/05 12:01:33 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.196 2023/06/05 09:41:40 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.197 2023/06/05 12:01:33 rillig Exp $");
 
 #include <stdio.h>
 
@@ -169,8 +169,7 @@ want_blank_line(void)
 static bool
 is_blank_line_optional(void)
 {
-	if (out.prev_line_kind == lk_stmt_head
-	    && ps.prev_lsym != lsym_semicolon)
+	if (out.prev_line_kind == lk_stmt_head)
 		return wrote_newlines >= 1;
 	if (ps.tos >= 2)
 		return wrote_newlines >= 2;

Reply via email to