Module Name: src Committed By: rillig Date: Mon May 15 19:55:51 UTC 2023
Modified Files: src/tests/usr.bin/indent: lsym_comment.c src/usr.bin/indent: pr_comment.c Log Message: indent: fix line wrapping of comments to the right of code To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/lsym_comment.c cvs rdiff -u -r1.141 -r1.142 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.10 src/tests/usr.bin/indent/lsym_comment.c:1.11 --- src/tests/usr.bin/indent/lsym_comment.c:1.10 Mon May 15 07:28:45 2023 +++ src/tests/usr.bin/indent/lsym_comment.c Mon May 15 19:55:51 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_comment.c,v 1.10 2023/05/15 07:28:45 rillig Exp $ */ +/* $NetBSD: lsym_comment.c,v 1.11 2023/05/15 19:55:51 rillig Exp $ */ /* * Tests for the token lsym_comment, which starts a comment. @@ -584,7 +584,12 @@ function(void) { int decl; /* indented declaration */ { - int decl; /* indented declaration */ +// $ This comment is indented so far to the right that it may overshoot the +// $ right margin. The allowed line length is increased to the starting +// $ indentation of 56 plus a fixed amount of 25 columns, resulting in 81. +// $ The trailing '*' would fit, but the trailing '/' is too much. + int decl; /* indented declaration + */ } } } @@ -641,23 +646,29 @@ function(void) } //indent end -//indent run +//indent run -l78 void function(void) { code(); /* code comment */ code(); /* code comment _________ to line length 78 */ - code(); /* code comment __________ to line length 79 */ - code(); /* code comment ___________ to line length 80 */ - code(); /* code comment ____________ to line length 81 */ + code(); /* code comment __________ to line length 79 + */ + code(); /* code comment ___________ to line length 80 + */ + code(); /* code comment ____________ to line length 81 + */ code(); /* code comment _____________ to line length * 82 */ /* $ In the following comments, the line length is measured after formatting. */ code(); /* code comment _________ to line length 78 */ - code(); /* code comment __________ to line length 79 */ - code(); /* code comment ___________ to line length 80 */ - code(); /* code comment ____________ to line length 81 */ + code(); /* code comment __________ to line length 79 + */ + code(); /* code comment ___________ to line length 80 + */ + code(); /* code comment ____________ to line length 81 + */ code(); /* code comment _____________ to line length * 82 */ Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.141 src/usr.bin/indent/pr_comment.c:1.142 --- src/usr.bin/indent/pr_comment.c:1.141 Mon May 15 09:22:53 2023 +++ src/usr.bin/indent/pr_comment.c Mon May 15 19:55:51 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.141 2023/05/15 09:22:53 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.142 2023/05/15 19:55:51 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: pr_comment.c,v 1.141 2023/05/15 09:22:53 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.142 2023/05/15 19:55:51 rillig Exp $"); #include <string.h> @@ -225,6 +225,13 @@ copy_comment_wrap(int line_length, bool else com.len = 0; com_add_char(' '); + } else { + size_t trimmed_len = com.len; + while (ch_isblank(com.mem[trimmed_len - 1])) + trimmed_len--; + int now_len = ind_add(ps.com_ind, com.st, trimmed_len); + if (now_len + 3 /* ' ' '*' '/' */ > line_length) + output_line(); } if (!(com.len > 0 && ch_isblank(com.mem[com.len - 1])))