Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/indent indent: preserve block comments with delimiters



details:   https://anonhg.NetBSD.org/src/rev/058d207b34d5
branches:  trunk
changeset: 376283:058d207b34d5
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jun 09 07:18:52 2023 +0000

description:
indent: preserve block comments with delimiters

diffstat:

 tests/usr.bin/indent/opt_cdb.c |  47 ++++++++++++++++-------------------------
 usr.bin/indent/pr_comment.c    |   9 +++++--
 2 files changed, 25 insertions(+), 31 deletions(-)

diffs (129 lines):

diff -r 98fecbec6b55 -r 058d207b34d5 tests/usr.bin/indent/opt_cdb.c
--- a/tests/usr.bin/indent/opt_cdb.c    Fri Jun 09 07:04:51 2023 +0000
+++ b/tests/usr.bin/indent/opt_cdb.c    Fri Jun 09 07:18:52 2023 +0000
@@ -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
diff -r 98fecbec6b55 -r 058d207b34d5 usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Fri Jun 09 07:04:51 2023 +0000
+++ b/usr.bin/indent/pr_comment.c       Fri Jun 09 07:18:52 2023 +0000
@@ -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)



Home | Main Index | Thread Index | Old Index