Module Name: src Committed By: rillig Date: Sun May 14 17:53:38 UTC 2023
Modified Files: src/tests/usr.bin/indent: indent_off_on.c lsym_comment.c opt_fc1.c src/usr.bin/indent: pr_comment.c Log Message: indent: fix handling of multiple block comments in a line To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/indent/indent_off_on.c cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/lsym_comment.c cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/opt_fc1.c cvs rdiff -u -r1.136 -r1.137 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/indent_off_on.c diff -u src/tests/usr.bin/indent/indent_off_on.c:1.9 src/tests/usr.bin/indent/indent_off_on.c:1.10 --- src/tests/usr.bin/indent/indent_off_on.c:1.9 Thu May 11 18:13:55 2023 +++ src/tests/usr.bin/indent/indent_off_on.c Sun May 14 17:53:38 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: indent_off_on.c,v 1.9 2023/05/11 18:13:55 rillig Exp $ */ +/* $NetBSD: indent_off_on.c,v 1.10 2023/05/14 17:53:38 rillig Exp $ */ /* * Tests for the comments 'INDENT OFF' and 'INDENT ON', which temporarily @@ -223,9 +223,10 @@ void indent_still_off ( void ) ; /* due void indent_on(void); /* INDENT: OFF */ void indent_still_on(void); /* due to the colon in the middle */ -/* $ The extra comment got moved to the left since there is no code in */ -/* $ that line. */ -/* INDENT OFF *//* extra comment */ +/* $ The extra comment got moved to a separate line, but indenting is still */ +/* $ off because the 'INDENT OFF' comment was not in a line of its own. */ +/* INDENT OFF */ +/* extra comment */ void indent_still_on(void); /* due to the extra comment to the * right */ //indent end Index: src/tests/usr.bin/indent/lsym_comment.c diff -u src/tests/usr.bin/indent/lsym_comment.c:1.7 src/tests/usr.bin/indent/lsym_comment.c:1.8 --- src/tests/usr.bin/indent/lsym_comment.c:1.7 Sat May 13 16:40:18 2023 +++ src/tests/usr.bin/indent/lsym_comment.c Sun May 14 17:53:38 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_comment.c,v 1.7 2023/05/13 16:40:18 rillig Exp $ */ +/* $NetBSD: lsym_comment.c,v 1.8 2023/05/14 17:53:38 rillig Exp $ */ /* * Tests for the token lsym_comment, which starts a comment. @@ -1066,10 +1066,10 @@ line 4 join*/ //indent end -/* FIXME: The last line of the first comment must not be modified. */ //indent run -nfc1 /* - *//* + */ + /* * join */ //indent end @@ -1088,7 +1088,8 @@ error*/ //indent run -nfc1 /* - *//* +*/ + /* * error */ //indent end Index: src/tests/usr.bin/indent/opt_fc1.c diff -u src/tests/usr.bin/indent/opt_fc1.c:1.10 src/tests/usr.bin/indent/opt_fc1.c:1.11 --- src/tests/usr.bin/indent/opt_fc1.c:1.10 Sun May 14 17:13:37 2023 +++ src/tests/usr.bin/indent/opt_fc1.c Sun May 14 17:53:38 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_fc1.c,v 1.10 2023/05/14 17:13:37 rillig Exp $ */ +/* $NetBSD: opt_fc1.c,v 1.11 2023/05/14 17:53:38 rillig Exp $ */ /* * Tests for the options '-fc1' and '-nfc1'. @@ -41,11 +41,11 @@ /* $ Indented by a single tab, single tabs around the text. */ /* indented tab */ -/* $ The space between these comments gets removed. */ -/* block1 */ /* block2 */ +/* $ The second comment is moved to a separate line. */ +/* col1 space-padded */ /* space-padded */ /* $ Both comment texts get surrounded by spaces. */ -/*block1*//*block2*/ +/*col1 no-padding*//*no-padding*/ //indent end //indent run -fc1 @@ -58,11 +58,13 @@ /* $ The indentation got removed. */ /* indented tab */ -/* $ The space between these comments got removed. */ -/* block1 *//* block2 */ +/* $ Each comment got its separate line. */ +/* col1 space-padded */ +/* space-padded */ /* $ Both comment texts got surrounded by spaces. */ -/* block1 *//* block2 */ +/* col1 no-padding */ +/* no-padding */ //indent end //indent run -nfc1 @@ -78,21 +80,15 @@ /* $ The indentation was changed from a single tab to a single space. */ /* indented tab */ -/* $ The space between these two comments got removed. */ -/* $ XXX: The option '-nfc1' says that comments in column 1 do not get */ -/* $ formatted, but the comment 'block1' was moved from column 1 to 2. */ -/* $ This is probably because there is a second comment in the same line. */ - /* block1 *//* block2 */ - -/* $ It may seem strange at first that the left comment is not touched */ -/* $ but the right comment gets spaces added. This difference is the */ -/* $ exact purpose of the option '-nfc1', which says "do not touch comments */ -/* $ that start in column 1. The first comment starts in column 1, the */ -/* $ second comment doesn't. */ -/* $ XXX: The option '-nfc1' says that comments in column 1 do not get */ -/* $ formatted, but the comment 'block1' was moved from column 1 to 2. */ -/* $ This is probably because there is a second comment in the same line. */ - /*block1*//* block2 */ +/* $ The second comment moved to a separate line. */ +/* col1 space-padded */ + /* space-padded */ + +/* $ The 'col1' comment starts in column 1 and is thus not modified. */ +/* $ The second comment started further to the right and thus was modified */ +/* $ by moving it to a separate line, but not to column 1. */ +/*col1 no-padding*/ + /* no-padding */ //indent end @@ -112,17 +108,18 @@ //indent run -fc1 /* * A multi-line comment that starts in column 1. - *//* + */ +/* * followed by another multi-line comment that starts in column 4. */ //indent end -/* FIXME: The last line of the first comment must not be modified. */ //indent run -nfc1 /* * A multi-line comment that starts * in column 1. - *//* + */ + /* * followed by another multi-line comment that starts in column 4. */ //indent end Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.136 src/usr.bin/indent/pr_comment.c:1.137 --- src/usr.bin/indent/pr_comment.c:1.136 Sun May 14 17:13:37 2023 +++ src/usr.bin/indent/pr_comment.c Sun May 14 17:53:38 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.136 2023/05/14 17:13:37 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.137 2023/05/14 17:53:38 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: pr_comment.c,v 1.136 2023/05/14 17:13:37 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.137 2023/05/14 17:53:38 rillig Exp $"); #include <string.h> @@ -107,18 +107,13 @@ analyze_comment(bool *p_may_wrap, bool * break_delim = false; } - /* - * XXX: This condition looks suspicious since it ignores the case - * where the end of the previous comment is still in 'com'. - * - * See test lsym_comment.c, keyword 'analyze_comment'. - */ + if (com.e != com.s) + output_line(); if (lab.s == lab.e && code.s == code.e) { adj_max_line_length = opt.block_comment_max_line_length; com_ind = (ps.ind_level - opt.unindent_displace) * opt.indent_size; if (com_ind <= 0) com_ind = opt.format_col1_comments ? 0 : 1; - } else { break_delim = false;