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: in -bad mode, don't add a blank line ...
details: https://anonhg.NetBSD.org/src/rev/ffc7c3fafe63
branches: trunk
changeset: 376631:ffc7c3fafe63
user: rillig <rillig%NetBSD.org@localhost>
date: Mon Jun 26 14:54:40 2023 +0000
description:
indent: in -bad mode, don't add a blank line above a comment or '}'
diffstat:
tests/usr.bin/indent/opt_bad.c | 41 +++++++++++++++++------------------------
usr.bin/indent/indent.c | 6 ++++--
usr.bin/indent/io.c | 7 ++++---
3 files changed, 25 insertions(+), 29 deletions(-)
diffs (133 lines):
diff -r 3d0a9de873cb -r ffc7c3fafe63 tests/usr.bin/indent/opt_bad.c
--- a/tests/usr.bin/indent/opt_bad.c Mon Jun 26 12:21:18 2023 +0000
+++ b/tests/usr.bin/indent/opt_bad.c Mon Jun 26 14:54:40 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_bad.c,v 1.11 2023/06/17 22:09:24 rillig Exp $ */
+/* $NetBSD: opt_bad.c,v 1.12 2023/06/26 14:54:40 rillig Exp $ */
/*
* Tests for the options '-bad' and '-nbad'.
@@ -12,14 +12,6 @@
/* Test global declarations. */
//indent input
-int global_variable;
-void function_declaration(void);
-#if 0
-#endif
-/* comment */
-//indent end
-
-//indent run -bad
int global_variable;
void function_declaration(void);
#if 0
@@ -27,7 +19,9 @@ void function_declaration(void);
/* comment */
//indent end
-//indent run-equals-prev-output -nbad
+//indent run-equals-input -bad
+
+//indent run-equals-input -nbad
/* See FreeBSD r303599. */
@@ -110,8 +104,10 @@ comments(void)
{
int local_var_1; /* comment */
int local_var_2; /* comment */
+// $ Indent does not look ahead much, so it doesn't know whether this comment
+// $ will be followed by a declaration or a statement.
+ /* comment line */
- /* comment line */
function_call();
}
//indent end
@@ -169,20 +165,17 @@ initializer_with_blank(void)
//indent input
{
- int decl;
+ // $ The '}' in an initializer does not finish a declaration,
+ // $ only a semicolon does.
+ int decl1[2][2] = {
+ {1, 2},
+ {3, 4},
+ };
/* comment */
- int decl;
+ int decl2;
+ // $ If the declaration is followed by a '}' that terminates the block
+ // $ statement, * there is no need for a blank line before the '}'.
}
//indent end
-//indent run -bad -di0
-{
- int decl;
-// $ FIXME: This blank line is _between_ the declarations, not _after_ them.
-
- /* comment */
- int decl;
-// $ XXX: This blank line is unnecessary, it doesn't occur in practice, though.
-
-}
-//indent end
+//indent run-equals-input -bad -di0
diff -r 3d0a9de873cb -r ffc7c3fafe63 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Mon Jun 26 12:21:18 2023 +0000
+++ b/usr.bin/indent/indent.c Mon Jun 26 14:54:40 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.384 2023/06/25 19:35:45 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.385 2023/06/26 14:54:40 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.384 2023/06/25 19:35:45 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.385 2023/06/26 14:54:40 rillig Exp $");
#include <sys/param.h>
#include <err.h>
@@ -767,6 +767,8 @@ process_rbrace(void)
}
ps.declaration = decl_no;
+ if (ps.decl_level == 0)
+ ps.blank_line_after_decl = false;
if (ps.init_level > 0)
ps.init_level--;
diff -r 3d0a9de873cb -r ffc7c3fafe63 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c Mon Jun 26 12:21:18 2023 +0000
+++ b/usr.bin/indent/io.c Mon Jun 26 14:54:40 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.229 2023/06/17 23:03:20 rillig Exp $ */
+/* $NetBSD: io.c,v 1.230 2023/06/26 14:54:40 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.229 2023/06/17 23:03:20 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.230 2023/06/26 14:54:40 rillig Exp $");
#include <stdio.h>
@@ -171,7 +171,8 @@ want_blank_line(void)
debug_println("%s: %s -> %s", __func__,
line_kind_name[out.prev_line_kind], line_kind_name[out.line_kind]);
- if (ps.blank_line_after_decl && ps.declaration == decl_no) {
+ if (ps.blank_line_after_decl && ps.declaration == decl_no
+ && (lab.len > 0 || code.len > 0)) {
ps.blank_line_after_decl = false;
return true;
}
Home |
Main Index |
Thread Index |
Old Index