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 accidentally joined and broken co...



details:   https://anonhg.NetBSD.org/src/rev/b3b65c870e5e
branches:  trunk
changeset: 1026472:b3b65c870e5e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Nov 25 20:44:09 2021 +0000

description:
indent: fix accidentally joined and broken comments (since 2019-04-04)

The fixed version is not perfect as it gets the indentation of the last
line of the first comment wrong, but at least indent doesn't generate
malformed output anymore.

diffstat:

 tests/usr.bin/indent/opt_fc1.c       |  13 ++++++++-----
 tests/usr.bin/indent/token_comment.c |  14 +++++++++-----
 usr.bin/indent/pr_comment.c          |  12 ++----------
 3 files changed, 19 insertions(+), 20 deletions(-)

diffs (127 lines):

diff -r 4399766a6aa6 -r b3b65c870e5e tests/usr.bin/indent/opt_fc1.c
--- a/tests/usr.bin/indent/opt_fc1.c    Thu Nov 25 20:14:00 2021 +0000
+++ b/tests/usr.bin/indent/opt_fc1.c    Thu Nov 25 20:44:09 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_fc1.c,v 1.5 2021/11/20 16:54:17 rillig Exp $ */
+/* $NetBSD: opt_fc1.c,v 1.6 2021/11/25 20:44:10 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -97,6 +97,10 @@
 #indent end
 
 
+/*
+ * Since 2019-04-04 and before pr_comment.c 1.123 from 2021-11-25, the
+ * function analyze_comment wrongly joined the two comments.
+ */
 #indent input
 /*
  * A multi-line comment that starts
@@ -109,20 +113,19 @@
 #indent run -fc1
 /*
  * A multi-line comment that starts in column 1.
- *
+ *//*
  * followed by another multi-line comment that starts in column 4.
  */
-/* $ FIXME: The two comments have been merged into a single comment. */
 #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.
   */
-/* $ FIXME: The two comments have been merged into a single comment. */
 #indent end
 
 
diff -r 4399766a6aa6 -r b3b65c870e5e tests/usr.bin/indent/token_comment.c
--- a/tests/usr.bin/indent/token_comment.c      Thu Nov 25 20:14:00 2021 +0000
+++ b/tests/usr.bin/indent/token_comment.c      Thu Nov 25 20:44:09 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: token_comment.c,v 1.25 2021/11/25 20:14:00 rillig Exp $ */
+/* $NetBSD: token_comment.c,v 1.26 2021/11/25 20:44:10 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -1052,7 +1052,8 @@
 
 
 /*
- * The function analyze_comment wrongly joins the two comments.
+ * Since 2019-04-04 and before pr_comment.c 1.123 from 2021-11-25, the
+ * function analyze_comment wrongly joined the two comments.
  */
 #indent input
 /*
@@ -1060,16 +1061,19 @@
 join*/
 #indent end
 
+/* FIXME: The last line of the first comment must not be modified. */
 #indent run -nfc1
 /*
-  *
+  *//*
   * join
   */
 #indent end
 
 
 /*
- * The function analyze_comment generates malformed output.
+ * Since 2019-04-04 and before pr_comment.c 1.123 from 2021-11-25, the
+ * function analyze_comment generated malformed output by terminating the
+ * first comment but omitting the start of the second comment.
  */
 #indent input
 /*
@@ -1079,7 +1083,7 @@
 
 #indent run -nfc1
 /*
- */
+ *//*
   * error
   */
 #indent end
diff -r 4399766a6aa6 -r b3b65c870e5e usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Thu Nov 25 20:14:00 2021 +0000
+++ b/usr.bin/indent/pr_comment.c       Thu Nov 25 20:44:09 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pr_comment.c,v 1.122 2021/11/25 20:14:00 rillig Exp $  */
+/*     $NetBSD: pr_comment.c,v 1.123 2021/11/25 20:44:09 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.122 2021/11/25 20:14:00 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.123 2021/11/25 20:44:09 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -178,14 +178,6 @@
        break_delim = false;
 
     if (break_delim) {
-       /*
-        * FIXME: This code wrongly joins comments in '-nfc1' mode and
-        * generates malformed code.
-        *
-        * See test token_comment.c, keyword 'analyze_comment'.
-        */
-       com.e = com.s + 2;
-       *com.e = '\0';
        if (opt.blanklines_before_block_comments &&
                ps.prev_token != lsym_lbrace)
            blank_line_before = true;



Home | Main Index | Thread Index | Old Index