Module Name: src Committed By: rillig Date: Mon Jun 5 07:23:03 UTC 2023
Modified Files: src/tests/usr.bin/indent: t_misc.sh src/usr.bin/indent: indent.c io.c Log Message: indent: clean up handling of whitespace No functional change. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/tests/usr.bin/indent/t_misc.sh cvs rdiff -u -r1.327 -r1.328 src/usr.bin/indent/indent.c cvs rdiff -u -r1.194 -r1.195 src/usr.bin/indent/io.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/t_misc.sh diff -u src/tests/usr.bin/indent/t_misc.sh:1.25 src/tests/usr.bin/indent/t_misc.sh:1.26 --- src/tests/usr.bin/indent/t_misc.sh:1.25 Mon May 15 17:38:56 2023 +++ src/tests/usr.bin/indent/t_misc.sh Mon Jun 5 07:23:03 2023 @@ -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' } Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.327 src/usr.bin/indent/indent.c:1.328 --- src/usr.bin/indent/indent.c:1.327 Sun Jun 4 20:51:19 2023 +++ src/usr.bin/indent/indent.c Mon Jun 5 07:23:03 2023 @@ -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]) { Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.194 src/usr.bin/indent/io.c:1.195 --- src/usr.bin/indent/io.c:1.194 Mon Jun 5 06:43:14 2023 +++ src/usr.bin/indent/io.c Mon Jun 5 07:23:03 2023 @@ -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; - output_indent(target_ind); - if (label_end_ind > 0 && out_ind == label_end_ind) + if (lab.len > 0 && target_ind <= out_ind) output_range(" ", 1); + output_indent(target_ind); output_range(code.s, code.len); }