Module Name: src Committed By: rillig Date: Tue Jun 6 07:51:35 UTC 2023
Modified Files: src/tests/usr.bin/indent: lsym_comment.c src/usr.bin/indent: pr_comment.c Log Message: indent: right-trim single-line comments To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/tests/usr.bin/indent/lsym_comment.c cvs rdiff -u -r1.154 -r1.155 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/lsym_comment.c diff -u src/tests/usr.bin/indent/lsym_comment.c:1.17 src/tests/usr.bin/indent/lsym_comment.c:1.18 --- src/tests/usr.bin/indent/lsym_comment.c:1.17 Tue Jun 6 05:39:49 2023 +++ src/tests/usr.bin/indent/lsym_comment.c Tue Jun 6 07:51:35 2023 @@ -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 Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.154 src/usr.bin/indent/pr_comment.c:1.155 --- src/usr.bin/indent/pr_comment.c:1.154 Tue Jun 6 07:14:20 2023 +++ src/usr.bin/indent/pr_comment.c Tue Jun 6 07:51:35 2023 @@ -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);