Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/indent indent: do not add a space before a comment t...
details: https://anonhg.NetBSD.org/src/rev/f511d0c441ee
branches: trunk
changeset: 374835:f511d0c441ee
user: rillig <rillig%NetBSD.org@localhost>
date: Sat May 13 16:40:18 2023 +0000
description:
indent: do not add a space before a comment that starts a line
diffstat:
tests/usr.bin/indent/lsym_comment.c | 10 +++++-----
tests/usr.bin/indent/opt_fc1.c | 8 ++++----
tests/usr.bin/indent/t_errors.sh | 16 ++++++++--------
usr.bin/indent/indent.c | 7 ++++---
4 files changed, 21 insertions(+), 20 deletions(-)
diffs (139 lines):
diff -r a2a21d2735e9 -r f511d0c441ee tests/usr.bin/indent/lsym_comment.c
--- a/tests/usr.bin/indent/lsym_comment.c Sat May 13 16:19:37 2023 +0000
+++ b/tests/usr.bin/indent/lsym_comment.c Sat May 13 16:40:18 2023 +0000
@@ -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
diff -r a2a21d2735e9 -r f511d0c441ee tests/usr.bin/indent/opt_fc1.c
--- a/tests/usr.bin/indent/opt_fc1.c Sat May 13 16:19:37 2023 +0000
+++ b/tests/usr.bin/indent/opt_fc1.c Sat May 13 16:40:18 2023 +0000
@@ -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
diff -r a2a21d2735e9 -r f511d0c441ee tests/usr.bin/indent/t_errors.sh
--- a/tests/usr.bin/indent/t_errors.sh Sat May 13 16:19:37 2023 +0000
+++ b/tests/usr.bin/indent/t_errors.sh Sat May 13 16:40:18 2023 +0000
@@ -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'
}
diff -r a2a21d2735e9 -r f511d0c441ee usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Sat May 13 16:19:37 2023 +0000
+++ b/usr.bin/indent/indent.c Sat May 13 16:40:18 2023 +0000
@@ -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);
Home |
Main Index |
Thread Index |
Old Index