Module Name:    src
Committed By:   rillig
Date:           Fri Jun  9 07:18:53 UTC 2023

Modified Files:
        src/tests/usr.bin/indent: opt_cdb.c
        src/usr.bin/indent: pr_comment.c

Log Message:
indent: preserve block comments with delimiters


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/indent/opt_cdb.c
cvs rdiff -u -r1.156 -r1.157 src/usr.bin/indent/pr_comment.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_cdb.c
diff -u src/tests/usr.bin/indent/opt_cdb.c:1.9 src/tests/usr.bin/indent/opt_cdb.c:1.10
--- src/tests/usr.bin/indent/opt_cdb.c:1.9	Fri May 19 07:05:26 2023
+++ src/tests/usr.bin/indent/opt_cdb.c	Fri Jun  9 07:18:52 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_cdb.c,v 1.9 2023/05/19 07:05:26 rillig Exp $ */
+/* $NetBSD: opt_cdb.c,v 1.10 2023/06/09 07:18:52 rillig Exp $ */
 
 /*
  * Tests for the options '-cdb' and '-ncdb'.
@@ -7,8 +7,7 @@
  * a separate line. This only affects block comments, but not comments to the
  * right of the code.
  *
- * The option '-ncdb' compresses multi-line comments to single-line comments,
- * as far as possible.
+ * The option '-ncdb' preserves comments with delimiters.
  */
 
 //indent input
@@ -50,9 +49,13 @@
 
 /* Multiple lines without delimiters. */
 
-/* A single line with delimiters. */
+/*
+ * A single line with delimiters.
+ */
 
-/* Multiple lines with delimiters. */
+/*
+ * Multiple lines with delimiters.
+ */
 //indent end
 
 
@@ -153,10 +156,14 @@ example(void)
 	/* Multiple lines without delimiters. */
 	int local_multi_without;
 
-	/* A single line with delimiters. */
+	/*
+	 * A single line with delimiters.
+	 */
 	int local_single_with;
 
-	/* Multiple lines with delimiters. */
+	/*
+	 * Multiple lines with delimiters.
+	 */
 	int local_multi_with;
 }
 //indent end
@@ -174,11 +181,7 @@ example(void)
  */
 //indent end
 
-/* FIXME: Looks bad. */
-//indent run -ncdb
-/*
- * */
-//indent end
+//indent run-equals-prev-output -ncdb
 
 
 //indent input
@@ -193,18 +196,12 @@ example(void)
  */
 //indent end
 
-/* FIXME: Looks bad. */
-//indent run -ncdb
-/*
- * */
-//indent end
+//indent run-equals-prev-output -ncdb
 
 
 /*
- * Since 2019-04-04, the -ncdb option condenses multi-line comments as well,
- * not only single-line comments.
- *
- * XXX: Is this intended?
+ * Between 2019-04-04 and 2023-06-09, the -ncdb option condensed multi-line
+ * comments as well, not only single-line comments.
  */
 //indent input
 {
@@ -218,10 +215,4 @@ example(void)
 
 //indent run-equals-input -cdb
 
-//indent run -ncdb
-{
-	/* This is the first paragraph.
-	 *
-	 * This is the second paragraph. */
-}
-//indent end
+//indent run-equals-input -ncdb

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.156 src/usr.bin/indent/pr_comment.c:1.157
--- src/usr.bin/indent/pr_comment.c:1.156	Fri Jun  9 07:04:51 2023
+++ src/usr.bin/indent/pr_comment.c	Fri Jun  9 07:18:52 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: pr_comment.c,v 1.156 2023/06/09 07:04:51 rillig Exp $	*/
+/*	$NetBSD: pr_comment.c,v 1.157 2023/06/09 07:18:52 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pr_comment.c,v 1.156 2023/06/09 07:04:51 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.157 2023/06/09 07:18:52 rillig Exp $");
 
 #include <string.h>
 
@@ -103,7 +103,10 @@ analyze_comment(bool *p_may_wrap, bool *
 			if (ind <= 0)
 				ind = opt.format_col1_comments ? 0 : 1;
 			line_length = opt.block_comment_max_line_length;
-			delim = opt.comment_delimiter_on_blankline;
+			if (may_wrap && inp_p[0] == '\n')
+				delim = true;
+			if (may_wrap && opt.comment_delimiter_on_blankline)
+				delim = true;
 		} else {
 			int target_ind = code.len > 0
 			    ? ind_add(compute_code_indent(), code.s, code.len)

Reply via email to