Module Name: src Committed By: rillig Date: Sun Nov 7 10:13:26 UTC 2021
Modified Files: src/tests/usr.bin/indent: token_comment.c src/usr.bin/indent: pr_comment.c Log Message: indent: make copy_comment_nowrap simpler Since a nowrap comment is copied unmodified, it need not depend on any maximum line length. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/tests/usr.bin/indent/token_comment.c cvs rdiff -u -r1.102 -r1.103 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/token_comment.c diff -u src/tests/usr.bin/indent/token_comment.c:1.19 src/tests/usr.bin/indent/token_comment.c:1.20 --- src/tests/usr.bin/indent/token_comment.c:1.19 Sun Nov 7 07:45:00 2021 +++ src/tests/usr.bin/indent/token_comment.c Sun Nov 7 10:13:26 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: token_comment.c,v 1.19 2021/11/07 07:45:00 rillig Exp $ */ +/* $NetBSD: token_comment.c,v 1.20 2021/11/07 10:13:26 rillig Exp $ */ /* $FreeBSD$ */ /* @@ -962,3 +962,27 @@ f(void) #indent end #indent run-equals-input + + +/* + * Tests for comments that are not wrapped. + */ +#indent input +/*- tab space tab space */ +/*- very-long-word-that-cannot-be-broken very-long-word-that-cannot-be-broken */ +/*- very-long-word-that-cannot-be-broken very-long-word-that-cannot-be-broken */ +#indent end + +#indent run-equals-input -l5 +#indent run-equals-input -l32 + + +/* + * Test for form feeds in nowrap comments. + */ +#indent input +/*-*/ +/*-<>*/ +#indent end + +#indent run-equals-input Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.102 src/usr.bin/indent/pr_comment.c:1.103 --- src/usr.bin/indent/pr_comment.c:1.102 Sun Nov 7 08:41:13 2021 +++ src/usr.bin/indent/pr_comment.c Sun Nov 7 10:13:26 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.102 2021/11/07 08:41:13 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.103 2021/11/07 10:13:26 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.102 2021/11/07 08:41:13 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.103 2021/11/07 10:13:26 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -330,10 +330,8 @@ copy_comment_wrap(int adj_max_line_lengt } static void -copy_comment_nowrap(int adj_max_line_length) +copy_comment_nowrap(void) { - ssize_t last_blank = -1; /* index of the last blank in com.buf */ - for (;;) { switch (*inp.s) { case '\f': @@ -351,7 +349,6 @@ copy_comment_nowrap(int adj_max_line_len return; } - last_blank = -1; if (com.s == com.e) com_add_char(' '); /* force output of an empty line */ dump_line(); @@ -370,28 +367,15 @@ copy_comment_nowrap(int adj_max_line_len com_add_char('/'); } com_terminate(); + ps.next_col_1 = false; return; } else /* handle isolated '*' */ com_add_char('*'); break; - default: /* we have a random char */ - ; - int now_len = ind_add(ps.com_ind, com.s, com.e); - for (;;) { - char ch = inp_next(); - if (ch_isblank(ch)) - last_blank = com.e - com.buf; - com_add_char(ch); - now_len++; - if (memchr("*\n\r\b\t", *inp.s, 6) != NULL) - break; - if (now_len >= adj_max_line_length && last_blank != -1) - break; - } - - ps.next_col_1 = false; + default: + com_add_char(inp_next()); break; } } @@ -432,6 +416,6 @@ process_comment(void) if (may_wrap) copy_comment_wrap(adj_max_line_length, break_delim); else - copy_comment_nowrap(adj_max_line_length); + copy_comment_nowrap(); ps.just_saw_decl = l_just_saw_decl; }