Module Name: src Committed By: rillig Date: Sat May 13 16:40:18 UTC 2023
Modified Files: src/tests/usr.bin/indent: lsym_comment.c opt_fc1.c t_errors.sh src/usr.bin/indent: indent.c Log Message: indent: do not add a space before a comment that starts a line To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/lsym_comment.c cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/opt_fc1.c cvs rdiff -u -r1.26 -r1.27 src/tests/usr.bin/indent/t_errors.sh cvs rdiff -u -r1.261 -r1.262 src/usr.bin/indent/indent.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.6 src/tests/usr.bin/indent/lsym_comment.c:1.7 --- src/tests/usr.bin/indent/lsym_comment.c:1.6 Sat May 13 06:52:48 2023 +++ src/tests/usr.bin/indent/lsym_comment.c Sat May 13 16:40:18 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_comment.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */ +/* $NetBSD: lsym_comment.c,v 1.7 2023/05/13 16:40:18 rillig Exp $ */ /* * Tests for the token lsym_comment, which starts a comment. @@ -732,8 +732,8 @@ loop(void) while (cond) /* comment */ ; while (cond) -/* $ XXX: The spaces around the comment look unintentional. */ - /* comment */ ; +/* $ XXX: The space after the comment looks unintentional. */ + /* comment */ ; } //indent end @@ -940,7 +940,7 @@ f(void) /* * 12 1234 123 123456 1234 1234567 123 * 1234. - */ ; + */ ; } //indent end @@ -950,7 +950,7 @@ int f(void) { if (0) - /* 12 1234 123 123456 1234 1234567 123 1234. */ ; + /* 12 1234 123 123456 1234 1234567 123 1234. */ ; } //indent end Index: src/tests/usr.bin/indent/opt_fc1.c diff -u src/tests/usr.bin/indent/opt_fc1.c:1.8 src/tests/usr.bin/indent/opt_fc1.c:1.9 --- src/tests/usr.bin/indent/opt_fc1.c:1.8 Sun Apr 24 09:04:12 2022 +++ src/tests/usr.bin/indent/opt_fc1.c Sat May 13 16:40:18 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_fc1.c,v 1.8 2022/04/24 09:04:12 rillig Exp $ */ +/* $NetBSD: opt_fc1.c,v 1.9 2023/05/13 16:40:18 rillig Exp $ */ /* * Tests for the options '-fc1' and '-nfc1'. @@ -135,9 +135,9 @@ //indent end //indent run -fc1 - /* comment */ int decl2; /* comment */ - /* looooooooooooooooooooooooooooooooooooooooong first comment */ int decl2; /* second comment */ - /* first comment */ int decl2; /* looooooooooooooooooooooooooooooooooooooooong +/* comment */ int decl2; /* comment */ +/* looooooooooooooooooooooooooooooooooooooooong first comment */ int decl2; /* second comment */ +/* first comment */ int decl2; /* looooooooooooooooooooooooooooooooooooooooong * second comment */ //indent end Index: src/tests/usr.bin/indent/t_errors.sh diff -u src/tests/usr.bin/indent/t_errors.sh:1.26 src/tests/usr.bin/indent/t_errors.sh:1.27 --- src/tests/usr.bin/indent/t_errors.sh:1.26 Sat May 13 08:33:39 2023 +++ src/tests/usr.bin/indent/t_errors.sh Sat May 13 16:40:18 2023 @@ -1,5 +1,5 @@ #! /bin/sh -# $NetBSD: t_errors.sh,v 1.26 2023/05/13 08:33:39 rillig Exp $ +# $NetBSD: t_errors.sh,v 1.27 2023/05/13 16:40:18 rillig Exp $ # # Copyright (c) 2021 The NetBSD Foundation, Inc. # All rights reserved. @@ -438,8 +438,8 @@ unbalanced_parentheses_3_body() "$indent" code.c } -atf_test_case 'search_stmt_comment_segv' -search_stmt_comment_segv_body() +atf_test_case 'crash_comment_after_controlling_expression' +crash_comment_after_controlling_expression_body() { # Before 2023-05-11, indent crashed while # trying to format the following artificial code. @@ -457,8 +457,8 @@ EOF "$indent" code.c -st } -atf_test_case 'search_stmt_fits_in_one_line' -search_stmt_fits_in_one_line_body() +atf_test_case 'comment_fits_in_one_line' +comment_fits_in_one_line_body() { # The comment is placed after 'if (0) ...', where it is processed # by search_stmt_comment. That function redirects the input buffer to @@ -482,7 +482,7 @@ f(void) if (0) /* * 0123456789012345678901 - */ ; + */ ; } EOF @@ -572,7 +572,7 @@ atf_init_test_cases() atf_add_test_case 'unbalanced_parentheses_1' atf_add_test_case 'unbalanced_parentheses_2' atf_add_test_case 'unbalanced_parentheses_3' - atf_add_test_case 'search_stmt_comment_segv' - atf_add_test_case 'search_stmt_fits_in_one_line' + atf_add_test_case 'crash_comment_after_controlling_expression' + atf_add_test_case 'comment_fits_in_one_line' atf_add_test_case 'compound_literal' } Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.261 src/usr.bin/indent/indent.c:1.262 --- src/usr.bin/indent/indent.c:1.261 Sat May 13 16:19:37 2023 +++ src/usr.bin/indent/indent.c Sat May 13 16:40:18 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.261 2023/05/13 16:19:37 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.262 2023/05/13 16:40:18 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include <sys/cdefs.h> #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.261 2023/05/13 16:19:37 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.262 2023/05/13 16:40:18 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -413,7 +413,8 @@ maybe_break_line(lexer_symbol lsym) static void move_com_to_code(void) { - buf_add_char(&code, ' '); + if (lab.e != lab.s || code.e != code.s) + buf_add_char(&code, ' '); buf_add_buf(&code, &com); buf_add_char(&code, ' '); buf_terminate(&code);