diff options
| author | rillig <rillig@NetBSD.org> | 2023-05-14 17:53:38 +0000 |
|---|---|---|
| committer | rillig <rillig@NetBSD.org> | 2023-05-14 17:53:38 +0000 |
| commit | eb4f3bd7339c63af4e418420d8a004e77cc93e67 (patch) | |
| tree | ac39fccb72342f37f739838e84cc4afeab2bfc95 | |
| parent | 7dc87b12cdcf7de5c6eefaceeac69e508c7fe430 (diff) | |
indent: fix handling of multiple block comments in a line
| -rw-r--r-- | tests/usr.bin/indent/indent_off_on.c | 9 | ||||
| -rw-r--r-- | tests/usr.bin/indent/lsym_comment.c | 9 | ||||
| -rw-r--r-- | tests/usr.bin/indent/opt_fc1.c | 47 | ||||
| -rw-r--r-- | usr.bin/indent/pr_comment.c | 13 |
4 files changed, 36 insertions, 42 deletions
diff --git a/tests/usr.bin/indent/indent_off_on.c b/tests/usr.bin/indent/indent_off_on.c index ab0ca5c4728..51355e05c2e 100644 --- a/tests/usr.bin/indent/indent_off_on.c +++ b/tests/usr.bin/indent/indent_off_on.c @@ -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 to the extra '*' at the end */ 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 diff --git a/tests/usr.bin/indent/lsym_comment.c b/tests/usr.bin/indent/lsym_comment.c index 92f707a153b..c9f6ea01e35 100644 --- a/tests/usr.bin/indent/lsym_comment.c +++ b/tests/usr.bin/indent/lsym_comment.c @@ -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 diff --git a/tests/usr.bin/indent/opt_fc1.c b/tests/usr.bin/indent/opt_fc1.c index e5bbaeb334f..aaea5957ac4 100644 --- a/tests/usr.bin/indent/opt_fc1.c +++ b/tests/usr.bin/indent/opt_fc1.c @@ -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 diff --git a/usr.bin/indent/pr_comment.c b/usr.bin/indent/pr_comment.c index 47cd416c361..589f3630028 100644 --- a/usr.bin/indent/pr_comment.c +++ b/usr.bin/indent/pr_comment.c @@ -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 *p_break_delim, 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; |
