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: clean up handling of whitespace
details: https://anonhg.NetBSD.org/src/rev/26c4118bdd6e
branches: trunk
changeset: 376223:26c4118bdd6e
user: rillig <rillig%NetBSD.org@localhost>
date: Mon Jun 05 07:23:03 2023 +0000
description:
indent: clean up handling of whitespace
No functional change.
diffstat:
tests/usr.bin/indent/t_misc.sh | 13 ++++++++++++-
usr.bin/indent/indent.c | 7 ++-----
usr.bin/indent/io.c | 13 ++++---------
3 files changed, 18 insertions(+), 15 deletions(-)
diffs (103 lines):
diff -r 617d1d00477e -r 26c4118bdd6e tests/usr.bin/indent/t_misc.sh
--- a/tests/usr.bin/indent/t_misc.sh Mon Jun 05 06:43:14 2023 +0000
+++ b/tests/usr.bin/indent/t_misc.sh Mon Jun 05 07:23:03 2023 +0000
@@ -1,5 +1,5 @@
#! /bin/sh
-# $NetBSD: t_misc.sh,v 1.25 2023/05/15 17:38:56 rillig Exp $
+# $NetBSD: t_misc.sh,v 1.26 2023/06/05 07:23:03 rillig Exp $
#
# Copyright (c) 2021 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -405,6 +405,16 @@ opt_v_break_line_body()
"$indent" -v code.c -st
}
+
+atf_test_case 'trailing_whitespace_in_preprocessing_line'
+trailing_whitespace_in_preprocessing_line_body()
+{
+ printf '#if trailing && space \n#endif\n' > code.c
+
+ atf_check -o 'inline:#if trailing && space\n#endif\n' \
+ "$indent" code.c -st
+}
+
atf_init_test_cases()
{
atf_add_test_case 'in_place'
@@ -421,4 +431,5 @@ atf_init_test_cases()
atf_add_test_case 'several_profiles'
atf_add_test_case 'command_line_vs_profile'
atf_add_test_case 'in_place_parse_error'
+ atf_add_test_case 'trailing_whitespace_in_preprocessing_line'
}
diff -r 617d1d00477e -r 26c4118bdd6e usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Mon Jun 05 06:43:14 2023 +0000
+++ b/usr.bin/indent/indent.c Mon Jun 05 07:23:03 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.327 2023/06/04 20:51:19 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.328 2023/06/05 07:23:03 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.327 2023/06/04 20:51:19 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.328 2023/06/05 07:23:03 rillig Exp $");
#include <sys/param.h>
#include <err.h>
@@ -1001,9 +1001,6 @@ read_preprocessing_line(void)
buf_add_char(&lab, '#');
- while (ch_isblank(inp_p[0]))
- buf_add_char(&lab, *inp_p++);
-
while (inp_p[0] != '\n' || (state == COMM && !had_eof)) {
buf_add_char(&lab, inp_next());
switch (lab.s[lab.len - 1]) {
diff -r 617d1d00477e -r 26c4118bdd6e usr.bin/indent/io.c
--- a/usr.bin/indent/io.c Mon Jun 05 06:43:14 2023 +0000
+++ b/usr.bin/indent/io.c Mon Jun 05 07:23:03 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.194 2023/06/05 06:43:14 rillig Exp $ */
+/* $NetBSD: io.c,v 1.195 2023/06/05 07:23:03 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.194 2023/06/05 06:43:14 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.195 2023/06/05 07:23:03 rillig Exp $");
#include <stdio.h>
@@ -179,10 +179,6 @@ is_blank_line_optional(void)
static void
output_line_label(void)
{
-
- while (lab.len > 0 && ch_isblank(lab.s[lab.len - 1]))
- lab.len--;
-
output_indent(compute_label_indent());
output_range(lab.s, lab.len);
}
@@ -202,10 +198,9 @@ output_line_code(void)
}
}
- int label_end_ind = out_ind;
+ if (lab.len > 0 && target_ind <= out_ind)
+ output_range(" ", 1);
output_indent(target_ind);
- if (label_end_ind > 0 && out_ind == label_end_ind)
- output_range(" ", 1);
output_range(code.s, code.len);
}
Home |
Main Index |
Thread Index |
Old Index