Module Name:    src
Committed By:   rillig
Date:           Tue Oct 12 21:08:37 UTC 2021

Modified Files:
        src/tests/usr.bin/indent: token-comment.0 token-comment.0.stdout
        src/usr.bin/indent: pr_comment.c

Log Message:
indent: fix formatting of single-line comments (since today)

The change in pr_comment.c 1.70 from 3 hours ago did not cover all edge
cases correctly. Now it works for comments that are aligned with tabs.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/token-comment.0
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/indent/token-comment.0.stdout
cvs rdiff -u -r1.72 -r1.73 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/token-comment.0
diff -u src/tests/usr.bin/indent/token-comment.0:1.10 src/tests/usr.bin/indent/token-comment.0:1.11
--- src/tests/usr.bin/indent/token-comment.0:1.10	Tue Oct 12 20:52:02 2021
+++ src/tests/usr.bin/indent/token-comment.0	Tue Oct 12 21:08:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: token-comment.0,v 1.10 2021/10/12 20:52:02 rillig Exp $ */
+/* $NetBSD: token-comment.0,v 1.11 2021/10/12 21:08:37 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -25,6 +25,10 @@
 /* x							....... line length 81*/
 /* x							........ line length 82*/
 
+/* And now the same idea but the comment ends with a space already. */
+/* x							.... line length 78 */
+/* x							..... line length 79 */
+
 /* This is a traditional C block comment. */
 
 // This is a C99 line comment.

Index: src/tests/usr.bin/indent/token-comment.0.stdout
diff -u src/tests/usr.bin/indent/token-comment.0.stdout:1.12 src/tests/usr.bin/indent/token-comment.0.stdout:1.13
--- src/tests/usr.bin/indent/token-comment.0.stdout:1.12	Tue Oct 12 20:52:02 2021
+++ src/tests/usr.bin/indent/token-comment.0.stdout	Tue Oct 12 21:08:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: token-comment.0.stdout,v 1.12 2021/10/12 20:52:02 rillig Exp $ */
+/* $NetBSD: token-comment.0.stdout,v 1.13 2021/10/12 21:08:37 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -26,14 +26,8 @@
 
 /* x							. line length 75 */
 /* x							.. line length 76 */
-/* $ FIXME: the following comment is short enough for a single line. */
-/*
- * x							... line length 77
- */
-/* $ FIXME: the following comment is short enough for a single line. */
-/*
- * x							.... line length 78
- */
+/* x							... line length 77 */
+/* x							.... line length 78 */
 /*
  * x							..... line length 79
  */
@@ -47,6 +41,12 @@
  * x							........ line length 82
  */
 
+/* And now the same idea but the comment ends with a space already. */
+/* x							.... line length 78 */
+/*
+ * x							..... line length 79
+ */
+
 /* This is a traditional C block comment. */
 
 // This is a C99 line comment.

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.72 src/usr.bin/indent/pr_comment.c:1.73
--- src/usr.bin/indent/pr_comment.c:1.72	Tue Oct 12 19:57:53 2021
+++ src/usr.bin/indent/pr_comment.c	Tue Oct 12 21:08:37 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pr_comment.c,v 1.72 2021/10/12 19:57:53 rillig Exp $	*/
+/*	$NetBSD: pr_comment.c,v 1.73 2021/10/12 21:08:37 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.72 2021/10/12 19:57:53 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.73 2021/10/12 21:08:37 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -197,7 +197,8 @@ process_comment(void)
 	    if (!(p[0] == '*' && p[1] == '/'))
 		continue;
 
-	    int len = 3 + indentation_after_range(ps.com_ind, inp.s, p + 2);
+	    int len = indentation_after_range(ps.com_ind + 3, inp.s, p) +
+		(is_hspace(p[-1]) ? 2 : 3);
 	    if (len <= adj_max_line_length)
 		break_delim = false;
 	    break;

Reply via email to