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 formatting of single-line comment...



details:   https://anonhg.NetBSD.org/src/rev/20a0eed40d60
branches:  trunk
changeset: 989144:20a0eed40d60
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Oct 12 21:08:37 2021 +0000

description:
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.

diffstat:

 tests/usr.bin/indent/token-comment.0        |   6 +++++-
 tests/usr.bin/indent/token-comment.0.stdout |  18 +++++++++---------
 usr.bin/indent/pr_comment.c                 |   7 ++++---
 3 files changed, 18 insertions(+), 13 deletions(-)

diffs (87 lines):

diff -r 03291739df96 -r 20a0eed40d60 tests/usr.bin/indent/token-comment.0
--- a/tests/usr.bin/indent/token-comment.0      Tue Oct 12 20:52:02 2021 +0000
+++ b/tests/usr.bin/indent/token-comment.0      Tue Oct 12 21:08:37 2021 +0000
@@ -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.
diff -r 03291739df96 -r 20a0eed40d60 tests/usr.bin/indent/token-comment.0.stdout
--- a/tests/usr.bin/indent/token-comment.0.stdout       Tue Oct 12 20:52:02 2021 +0000
+++ b/tests/usr.bin/indent/token-comment.0.stdout       Tue Oct 12 21:08:37 2021 +0000
@@ -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.
diff -r 03291739df96 -r 20a0eed40d60 usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Tue Oct 12 20:52:02 2021 +0000
+++ b/usr.bin/indent/pr_comment.c       Tue Oct 12 21:08:37 2021 +0000
@@ -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 @@
 
 #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 @@
            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;



Home | Main Index | Thread Index | Old Index