Module Name: src Committed By: rillig Date: Sat May 20 10:25:47 UTC 2023
Modified Files: src/tests/usr.bin/indent: indent_off_on.c src/usr.bin/indent: io.c Log Message: indent: ensure that no blank lines are inserted in INDENT OFF mode No blank lines were inserted previously, but the code looked suspicious as if that were possible. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/indent/indent_off_on.c cvs rdiff -u -r1.179 -r1.180 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/indent_off_on.c diff -u src/tests/usr.bin/indent/indent_off_on.c:1.11 src/tests/usr.bin/indent/indent_off_on.c:1.12 --- src/tests/usr.bin/indent/indent_off_on.c:1.11 Tue May 16 08:04:04 2023 +++ src/tests/usr.bin/indent/indent_off_on.c Sat May 20 10:25:47 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: indent_off_on.c,v 1.11 2023/05/16 08:04:04 rillig Exp $ */ +/* $NetBSD: indent_off_on.c,v 1.12 2023/05/20 10:25:47 rillig Exp $ */ /* * Tests for the comments 'INDENT OFF' and 'INDENT ON', which temporarily @@ -236,3 +236,19 @@ int still_on; /* INDENT OFF */ int finally_off ; //indent end + + +/* + * Ensure that in 'INDENT OFF' mode, no blank line is added between lines, even + * when requested via the -bacc option. + */ +//indent input +/* INDENT OFF */ +int declaration; +#if 0 +#endif +int declaration; +/* INDENT ON */ +//indent end + +//indent run-equals-input -bacc Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.179 src/usr.bin/indent/io.c:1.180 --- src/usr.bin/indent/io.c:1.179 Sat May 20 10:09:02 2023 +++ src/usr.bin/indent/io.c Sat May 20 10:25:47 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.179 2023/05/20 10:09:02 rillig Exp $ */ +/* $NetBSD: io.c,v 1.180 2023/05/20 10:25:47 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: io.c,v 1.179 2023/05/20 10:09:02 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.180 2023/05/20 10:25:47 rillig Exp $"); #include <stdio.h> @@ -136,26 +136,22 @@ output_indent(int old_ind, int new_ind) return ind; } -static void -maybe_output_blank_line(void) +static bool +want_blank_line(void) { - bool want_blank_line = false; - if (ps.blank_line_after_decl && ps.declaration == decl_no) { ps.blank_line_after_decl = false; - want_blank_line = true; + return true; } if (opt.blanklines_around_conditional_compilation) { if (ps.prev_line_kind != lk_if && ps.line_kind == lk_if) - want_blank_line = true; + return true; if (ps.prev_line_kind == lk_endif && ps.line_kind != lk_endif) - want_blank_line = true; + return true; } - if (want_blank_line && wrote_newlines < 2 - && (lab.len > 0 || code.len > 0 || com.len > 0)) - output_newline(); + return false; } static int @@ -248,9 +244,11 @@ output_line(void) ps.is_function_definition = false; - maybe_output_blank_line(); - if (indent_enabled == indent_on) { + if (want_blank_line() && wrote_newlines < 2 + && (lab.len > 0 || code.len > 0 || com.len > 0)) + output_newline(); + if (ps.ind_level == 0) ps.in_stmt_cont = false; /* this is a class A * kludge */