Module Name:    src
Committed By:   rillig
Date:           Thu Nov 25 20:44:10 UTC 2021

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

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/opt_fc1.c
cvs rdiff -u -r1.25 -r1.26 src/tests/usr.bin/indent/token_comment.c
cvs rdiff -u -r1.122 -r1.123 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_fc1.c
diff -u src/tests/usr.bin/indent/opt_fc1.c:1.5 src/tests/usr.bin/indent/opt_fc1.c:1.6
--- src/tests/usr.bin/indent/opt_fc1.c:1.5	Sat Nov 20 16:54:17 2021
+++ src/tests/usr.bin/indent/opt_fc1.c	Thu Nov 25 20:44:10 2021
@@ -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
 
 

Index: src/tests/usr.bin/indent/token_comment.c
diff -u src/tests/usr.bin/indent/token_comment.c:1.25 src/tests/usr.bin/indent/token_comment.c:1.26
--- src/tests/usr.bin/indent/token_comment.c:1.25	Thu Nov 25 20:14:00 2021
+++ src/tests/usr.bin/indent/token_comment.c	Thu Nov 25 20:44:10 2021
@@ -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 @@ line 4
 
 
 /*
- * 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 @@ line 4
 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 @@ error*/
 
 #indent run -nfc1
 /*
- */
+ *//*
   * error
   */
 #indent end

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.122 src/usr.bin/indent/pr_comment.c:1.123
--- src/usr.bin/indent/pr_comment.c:1.122	Thu Nov 25 20:14:00 2021
+++ src/usr.bin/indent/pr_comment.c	Thu Nov 25 20:44:09 2021
@@ -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 @@ static char sccsid[] = "@(#)pr_comment.c
 
 #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 @@ analyze_comment(bool *p_may_wrap, bool *
 	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;

Reply via email to