Module Name: src
Committed By: rillig
Date: Sat May 20 10:46:22 UTC 2023
Modified Files:
src/tests/usr.bin/indent: opt_bap.c
src/usr.bin/indent: debug.c indent.c indent.h io.c
Log Message:
indent: implement blank line after function body
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/opt_bap.c
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/indent/debug.c
cvs rdiff -u -r1.297 -r1.298 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.153 -r1.154 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.180 -r1.181 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/opt_bap.c
diff -u src/tests/usr.bin/indent/opt_bap.c:1.6 src/tests/usr.bin/indent/opt_bap.c:1.7
--- src/tests/usr.bin/indent/opt_bap.c:1.6 Sun Apr 24 09:04:12 2022
+++ src/tests/usr.bin/indent/opt_bap.c Sat May 20 10:46:22 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_bap.c,v 1.6 2022/04/24 09:04:12 rillig Exp $ */
+/* $NetBSD: opt_bap.c,v 1.7 2023/05/20 10:46:22 rillig Exp $ */
/*
* Tests for the options '-bap' and '-nbap' ("blank line after procedure
@@ -7,9 +7,6 @@
* The option '-bap' forces a blank line after every function body.
*
* The option '-nbap' keeps everything as is.
- *
- * FIXME: These options don't have any effect since at least 2000.
- * TODO: Investigate how nobody could have noticed this for 20 years.
*/
//indent input
@@ -39,18 +36,18 @@ static void
one_liner(void)
{
}
-/* $ FIXME: needs a blank line here */
+
static void
several_lines(void)
{
action();
}
-/* $ FIXME: needs a blank line here */
+
int
main(void)
{
}
-/* $ FIXME: needs a blank line here */
+
int global_variable;
void
@@ -68,4 +65,33 @@ has_several_blank_lines_below(void)
int the_end;
//indent end
-//indent run-equals-prev-output -nbap
+//indent run -nbap
+static void
+one_liner(void)
+{
+}
+static void
+several_lines(void)
+{
+ action();
+}
+int
+main(void)
+{
+}
+int global_variable;
+
+void
+already_has_blank_line_below(void)
+{
+}
+
+void
+has_several_blank_lines_below(void)
+{
+}
+
+
+
+int the_end;
+//indent end
Index: src/usr.bin/indent/debug.c
diff -u src/usr.bin/indent/debug.c:1.16 src/usr.bin/indent/debug.c:1.17
--- src/usr.bin/indent/debug.c:1.16 Sat May 20 10:09:02 2023
+++ src/usr.bin/indent/debug.c Sat May 20 10:46:21 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.16 2023/05/20 10:09:02 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.17 2023/05/20 10:46:21 rillig Exp $ */
/*-
* Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: debug.c,v 1.16 2023/05/20 10:09:02 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.17 2023/05/20 10:46:21 rillig Exp $");
#include <stdarg.h>
@@ -121,6 +121,7 @@ static const char *const line_kind_name[
"other",
"#if",
"#endif",
+ "}",
};
void
Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.297 src/usr.bin/indent/indent.c:1.298
--- src/usr.bin/indent/indent.c:1.297 Sat May 20 10:09:02 2023
+++ src/usr.bin/indent/indent.c Sat May 20 10:46:21 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.297 2023/05/20 10:09:02 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.298 2023/05/20 10:46:21 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.297 2023/05/20 10:09:02 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.298 2023/05/20 10:46:21 rillig Exp $");
#include <sys/param.h>
#include <err.h>
@@ -750,6 +750,9 @@ process_rbrace(void)
ps.in_decl = true;
}
+ if (ps.tos == 2 && code.len == 1 && code.st[0] == '}')
+ ps.line_kind = lk_func_end;
+
parse(psym_rbrace);
}
Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.153 src/usr.bin/indent/indent.h:1.154
--- src/usr.bin/indent/indent.h:1.153 Sat May 20 10:09:02 2023
+++ src/usr.bin/indent/indent.h Sat May 20 10:46:21 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.153 2023/05/20 10:09:02 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.154 2023/05/20 10:46:21 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -398,8 +398,10 @@ extern struct parser_state {
lk_other,
lk_if, /* #if, #ifdef, #ifndef */
lk_endif, /* #endif */
- } line_kind; /* kind of the current line, is reset to
- * lk_other at the beginning of each line */
+ lk_func_end, /* the last '}' of a function body */
+ } line_kind; /* kind of the current output line, is reset to
+ * lk_other at the beginning of each output
+ * line; used for inserting blank lines */
enum line_kind prev_line_kind;
/* Comments */
Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.180 src/usr.bin/indent/io.c:1.181
--- src/usr.bin/indent/io.c:1.180 Sat May 20 10:25:47 2023
+++ src/usr.bin/indent/io.c Sat May 20 10:46:21 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.180 2023/05/20 10:25:47 rillig Exp $ */
+/* $NetBSD: io.c,v 1.181 2023/05/20 10:46:21 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.180 2023/05/20 10:25:47 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.181 2023/05/20 10:46:21 rillig Exp $");
#include <stdio.h>
@@ -151,6 +151,9 @@ want_blank_line(void)
return true;
}
+ if (opt.blanklines_after_procs && ps.prev_line_kind == lk_func_end)
+ return true;
+
return false;
}