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: right-trim single-line comments
details: https://anonhg.NetBSD.org/src/rev/a7e29192de5a
branches: trunk
changeset: 376254:a7e29192de5a
user: rillig <rillig%NetBSD.org@localhost>
date: Tue Jun 06 07:51:35 2023 +0000
description:
indent: right-trim single-line comments
diffstat:
tests/usr.bin/indent/lsym_comment.c | 18 ++++++++++++++----
usr.bin/indent/pr_comment.c | 13 +++++++++++--
2 files changed, 25 insertions(+), 6 deletions(-)
diffs (93 lines):
diff -r 922e6dbeb62b -r a7e29192de5a tests/usr.bin/indent/lsym_comment.c
--- a/tests/usr.bin/indent/lsym_comment.c Tue Jun 06 07:49:06 2023 +0000
+++ b/tests/usr.bin/indent/lsym_comment.c Tue Jun 06 07:51:35 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_comment.c,v 1.17 2023/06/06 05:39:49 rillig Exp $ */
+/* $NetBSD: lsym_comment.c,v 1.18 2023/06/06 07:51:35 rillig Exp $ */
/*
* Tests for the token lsym_comment, which starts a comment.
@@ -371,21 +371,31 @@ tab1+++ tab2--- tab3+++ tab4--- tab5+++
/*
- * TODO: Trailing whitespace in a comment is ignored when determining whether the
- * comment fits in a single line.
+ * When determining whether the comment fits in a single line, only the first
+ * trailing space or tab is kept, the others are removed.
*/
//indent input
+/* tab: */
/* 456789 123456789 123456789 12345 */
/* 456789 123456789 123456789 123456 */
+/* space: */
+/* 456789 123456789 123456789 12345 */
+/* 456789 123456789 123456789 123456 */
//indent end
//indent run -l38
+/* tab: */
/*
* 456789 123456789 123456789 12345
*/
/*
* 456789 123456789 123456789 123456
*/
+/* space: */
+/* 456789 123456789 123456789 12345 */
+/*
+ * 456789 123456789 123456789 123456
+ */
//indent end
@@ -965,7 +975,7 @@ int
f(void)
{
if (0)
- /* 12 1234 123 123456 1234 1234567 123 1234. */;
+ /* 12 1234 123 123456 1234 1234567 123 1234. */;
}
//indent end
diff -r 922e6dbeb62b -r a7e29192de5a usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c Tue Jun 06 07:49:06 2023 +0000
+++ b/usr.bin/indent/pr_comment.c Tue Jun 06 07:51:35 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pr_comment.c,v 1.154 2023/06/06 07:14:20 rillig Exp $ */
+/* $NetBSD: pr_comment.c,v 1.155 2023/06/06 07:51:35 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: pr_comment.c,v 1.154 2023/06/06 07:14:20 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.155 2023/06/06 07:51:35 rillig Exp $");
#include <string.h>
@@ -62,6 +62,10 @@ fits_in_one_line(int com_ind, int max_li
{
for (const char *start = inp_p, *p = start; *p != '\n'; p++) {
if (p[0] == '*' && p[1] == '/') {
+ while (p - inp_p >= 2
+ && ch_isblank(p[-1])
+ && ch_isblank(p[-2]))
+ p--;
int len = ind_add(com_ind + 3,
start, (size_t)(p - start));
len += p == start || ch_isblank(p[-1]) ? 2 : 3;
@@ -257,6 +261,11 @@ copy_comment_wrap_finish(int line_length
output_line();
}
+ while (com.len >= 2
+ && ch_isblank(com.s[com.len - 1])
+ && ch_isblank(com.s[com.len - 2]))
+ com.len--;
+
inp_p += 2;
if (com.len > 0 && ch_isblank(com.s[com.len - 1]))
buf_add_chars(&com, "*/", 2);
Home |
Main Index |
Thread Index |
Old Index