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: ensure that no blank lines are insert...
details: https://anonhg.NetBSD.org/src/rev/7fc5b0813e53
branches: trunk
changeset: 375900:7fc5b0813e53
user: rillig <rillig%NetBSD.org@localhost>
date: Sat May 20 10:25:47 2023 +0000
description:
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.
diffstat:
tests/usr.bin/indent/indent_off_on.c | 18 +++++++++++++++++-
usr.bin/indent/io.c | 26 ++++++++++++--------------
2 files changed, 29 insertions(+), 15 deletions(-)
diffs (94 lines):
diff -r f19dcc612ab7 -r 7fc5b0813e53 tests/usr.bin/indent/indent_off_on.c
--- a/tests/usr.bin/indent/indent_off_on.c Sat May 20 10:09:02 2023 +0000
+++ b/tests/usr.bin/indent/indent_off_on.c Sat May 20 10:25:47 2023 +0000
@@ -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
diff -r f19dcc612ab7 -r 7fc5b0813e53 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c Sat May 20 10:09:02 2023 +0000
+++ b/usr.bin/indent/io.c Sat May 20 10:25:47 2023 +0000
@@ -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 (indent_enabled == indent_on) {
if (ps.ind_level == 0)
ps.in_stmt_cont = false; /* this is a class A
* kludge */
Home |
Main Index |
Thread Index |
Old Index