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: fix handling of multiple block commen...



details:   https://anonhg.NetBSD.org/src/rev/aaee45dd3bd9
branches:  trunk
changeset: 375314:aaee45dd3bd9
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun May 14 17:53:38 2023 +0000

description:
indent: fix handling of multiple block comments in a line

diffstat:

 tests/usr.bin/indent/indent_off_on.c |   9 ++++---
 tests/usr.bin/indent/lsym_comment.c  |   9 ++++---
 tests/usr.bin/indent/opt_fc1.c       |  45 ++++++++++++++++-------------------
 usr.bin/indent/pr_comment.c          |  13 +++-------
 4 files changed, 35 insertions(+), 41 deletions(-)

diffs (187 lines):

diff -r d91f225d4aeb -r aaee45dd3bd9 tests/usr.bin/indent/indent_off_on.c
--- a/tests/usr.bin/indent/indent_off_on.c      Sun May 14 17:50:29 2023 +0000
+++ b/tests/usr.bin/indent/indent_off_on.c      Sun May 14 17:53:38 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent_off_on.c,v 1.9 2023/05/11 18:13:55 rillig Exp $ */
+/* $NetBSD: indent_off_on.c,v 1.10 2023/05/14 17:53:38 rillig Exp $ */
 
 /*
  * Tests for the comments 'INDENT OFF' and 'INDENT ON', which temporarily
@@ -223,9 +223,10 @@ void indent_still_off ( void ) ;   /* due 
 void           indent_on(void);
 /* INDENT: OFF */
 void           indent_still_on(void);  /* due to the colon in the middle */
-/* $ The extra comment got moved to the left since there is no code in */
-/* $ that line. */
-/* INDENT OFF *//* extra comment */
+/* $ The extra comment got moved to a separate line, but indenting is still */
+/* $ off because the 'INDENT OFF' comment was not in a line of its own. */
+/* INDENT OFF */
+/* extra comment */
 void           indent_still_on(void);  /* due to the extra comment to the
                                         * right */
 //indent end
diff -r d91f225d4aeb -r aaee45dd3bd9 tests/usr.bin/indent/lsym_comment.c
--- a/tests/usr.bin/indent/lsym_comment.c       Sun May 14 17:50:29 2023 +0000
+++ b/tests/usr.bin/indent/lsym_comment.c       Sun May 14 17:53:38 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_comment.c,v 1.7 2023/05/13 16:40:18 rillig Exp $ */
+/* $NetBSD: lsym_comment.c,v 1.8 2023/05/14 17:53:38 rillig Exp $ */
 
 /*
  * Tests for the token lsym_comment, which starts a comment.
@@ -1066,10 +1066,10 @@ line 4
 join*/
 //indent end
 
-/* FIXME: The last line of the first comment must not be modified. */
 //indent run -nfc1
 /*
-  *//*
+ */
+ /*
   * join
   */
 //indent end
@@ -1088,7 +1088,8 @@ error*/
 
 //indent run -nfc1
 /*
- *//*
+*/
+ /*
   * error
   */
 //indent end
diff -r d91f225d4aeb -r aaee45dd3bd9 tests/usr.bin/indent/opt_fc1.c
--- a/tests/usr.bin/indent/opt_fc1.c    Sun May 14 17:50:29 2023 +0000
+++ b/tests/usr.bin/indent/opt_fc1.c    Sun May 14 17:53:38 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_fc1.c,v 1.10 2023/05/14 17:13:37 rillig Exp $ */
+/* $NetBSD: opt_fc1.c,v 1.11 2023/05/14 17:53:38 rillig Exp $ */
 
 /*
  * Tests for the options '-fc1' and '-nfc1'.
@@ -41,11 +41,11 @@
 /* $ Indented by a single tab, single tabs around the text. */
        /*      indented tab    */
 
-/* $ The space between these comments gets removed. */
-/* block1 */ /* block2 */
+/* $ The second comment is moved to a separate line. */
+/* col1 space-padded */ /* space-padded */
 
 /* $ Both comment texts get surrounded by spaces. */
-/*block1*//*block2*/
+/*col1 no-padding*//*no-padding*/
 //indent end
 
 //indent run -fc1
@@ -58,11 +58,13 @@
 /* $ The indentation got removed. */
 /*     indented tab    */
 
-/* $ The space between these comments got removed. */
-/* block1 *//* block2 */
+/* $ Each comment got its separate line. */
+/* col1 space-padded */
+/* space-padded */
 
 /* $ Both comment texts got surrounded by spaces. */
-/* block1 *//* block2 */
+/* col1 no-padding */
+/* no-padding */
 //indent end
 
 //indent run -nfc1
@@ -78,21 +80,15 @@
 /* $ The indentation was changed from a single tab to a single space. */
  /*    indented tab    */
 
-/* $ The space between these two comments got removed. */
-/* $ XXX: The option '-nfc1' says that comments in column 1 do not get */
-/* $ formatted, but the comment 'block1' was moved from column 1 to 2. */
-/* $ This is probably because there is a second comment in the same line. */
- /* block1 *//* block2 */
+/* $ The second comment moved to a separate line. */
+/* col1 space-padded */
+ /* space-padded */
 
-/* $ It may seem strange at first that the left comment is not touched */
-/* $ but the right comment gets spaces added. This difference is the */
-/* $ exact purpose of the option '-nfc1', which says "do not touch comments */
-/* $ that start in column 1. The first comment starts in column 1, the */
-/* $ second comment doesn't. */
-/* $ XXX: The option '-nfc1' says that comments in column 1 do not get */
-/* $ formatted, but the comment 'block1' was moved from column 1 to 2. */
-/* $ This is probably because there is a second comment in the same line. */
- /*block1*//* block2 */
+/* $ The 'col1' comment starts in column 1 and is thus not modified. */
+/* $ The second comment started further to the right and thus was modified */
+/* $ by moving it to a separate line, but not to column 1. */
+/*col1 no-padding*/
+ /* no-padding */
 //indent end
 
 
@@ -112,17 +108,18 @@
 //indent run -fc1
 /*
  * A multi-line comment that starts in column 1.
- *//*
+ */
+/*
  * followed by another multi-line comment that starts in column 4.
  */
 //indent end
 
-/* FIXME: The last line of the first comment must not be modified. */
 //indent run -nfc1
 /*
  * A multi-line comment that starts
  * in column 1.
-  *//*
+ */
+ /*
   * followed by another multi-line comment that starts in column 4.
   */
 //indent end
diff -r d91f225d4aeb -r aaee45dd3bd9 usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Sun May 14 17:50:29 2023 +0000
+++ b/usr.bin/indent/pr_comment.c       Sun May 14 17:53:38 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pr_comment.c,v 1.136 2023/05/14 17:13:37 rillig Exp $  */
+/*     $NetBSD: pr_comment.c,v 1.137 2023/05/14 17:53:38 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pr_comment.c,v 1.136 2023/05/14 17:13:37 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.137 2023/05/14 17:53:38 rillig Exp $");
 
 #include <string.h>
 
@@ -107,18 +107,13 @@ analyze_comment(bool *p_may_wrap, bool *
            break_delim = false;
        }
 
-       /*
-        * XXX: This condition looks suspicious since it ignores the case
-        * where the end of the previous comment is still in 'com'.
-        *
-        * See test lsym_comment.c, keyword 'analyze_comment'.
-        */
+       if (com.e != com.s)
+           output_line();
        if (lab.s == lab.e && code.s == code.e) {
            adj_max_line_length = opt.block_comment_max_line_length;
            com_ind = (ps.ind_level - opt.unindent_displace) * opt.indent_size;
            if (com_ind <= 0)
                com_ind = opt.format_col1_comments ? 0 : 1;
-
        } else {
            break_delim = false;
 



Home | Main Index | Thread Index | Old Index