Module Name: src Committed By: rillig Date: Tue Oct 12 18:22:01 UTC 2021
Modified Files: src/tests/usr.bin/indent: elsecomment.0.stdout token-comment.0.stdout src/usr.bin/indent: pr_comment.c Log Message: indent: fix wrapping for comments in otherwise empty lines The comment above the code was wrong. The leading 3 characters were indeed ignored, but the first of them was '/', not ' '. Of the trailing 3 characters, 2 were not ignored. The start and end of the comment would not cancel out, they would rather sum up. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/indent/elsecomment.0.stdout cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/token-comment.0.stdout cvs rdiff -u -r1.69 -r1.70 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/elsecomment.0.stdout diff -u src/tests/usr.bin/indent/elsecomment.0.stdout:1.1 src/tests/usr.bin/indent/elsecomment.0.stdout:1.2 --- src/tests/usr.bin/indent/elsecomment.0.stdout:1.1 Thu Apr 4 15:27:35 2019 +++ src/tests/usr.bin/indent/elsecomment.0.stdout Tue Oct 12 18:22:01 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: elsecomment.0.stdout,v 1.1 2019/04/04 15:27:35 kamil Exp $ */ +/* $NetBSD: elsecomment.0.stdout,v 1.2 2021/10/12 18:22:01 rillig Exp $ */ /* $FreeBSD: head/usr.bin/indent/tests/elsecomment.0.stdout 334559 2018-06-03 14:03:20Z pstef $ */ /* See r303484 and r309342 */ void @@ -23,7 +23,9 @@ t(void) - /* Old indent would remove the 3 blank lines above, awaiting "else". */ + /* + * Old indent would remove the 3 blank lines above, awaiting "else". + */ if (1) { Index: src/tests/usr.bin/indent/token-comment.0.stdout diff -u src/tests/usr.bin/indent/token-comment.0.stdout:1.8 src/tests/usr.bin/indent/token-comment.0.stdout:1.9 --- src/tests/usr.bin/indent/token-comment.0.stdout:1.8 Fri Oct 8 23:53:37 2021 +++ src/tests/usr.bin/indent/token-comment.0.stdout Tue Oct 12 18:22:01 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: token-comment.0.stdout,v 1.8 2021/10/08 23:53:37 rillig Exp $ */ +/* $NetBSD: token-comment.0.stdout,v 1.9 2021/10/12 18:22:01 rillig Exp $ */ /* $FreeBSD$ */ /* @@ -10,8 +10,12 @@ */ /* 456789 123456789 123456789 123456789 123456789 123456789 123456789 12345 */ -/* 456789 123456789 123456789 123456789 123456789 123456789 123456789 123456 */ -/* 456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567 */ +/* + * 456789 123456789 123456789 123456789 123456789 123456789 123456789 123456 + */ +/* + * 456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567 + */ /* * 456789 123456789 123456789 123456789 123456789 123456789 123456789 12345678 */ Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.69 src/usr.bin/indent/pr_comment.c:1.70 --- src/usr.bin/indent/pr_comment.c:1.69 Sat Oct 9 11:00:27 2021 +++ src/usr.bin/indent/pr_comment.c Tue Oct 12 18:22:01 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.69 2021/10/09 11:00:27 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.70 2021/10/12 18:22:01 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.69 2021/10/09 11:00:27 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.70 2021/10/12 18:22:01 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -172,19 +172,14 @@ process_comment(void) if (break_delim) { for (const char *p = inp.s; *p != '\n'; p++) { assert(*p != '\0'); - assert(p < inp.e); - if (p[0] == '*' && p[1] == '/') { - /* - * XXX: This computation ignores the leading " * ", as well as - * the trailing ' ' '*' '/'. In simple cases, these cancel - * out since they are equally long. - */ - int right_margin = indentation_after_range(ps.com_ind, - inp.s, p + 2); - if (right_margin < adj_max_line_length) - break_delim = false; - break; - } + assert(inp.e - p >= 2); + if (!(p[0] == '*' && p[1] == '/')) + continue; + + int len = 3 + indentation_after_range(ps.com_ind, inp.s, p + 2); + if (len <= adj_max_line_length) + break_delim = false; + break; } }