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: implement blank line after function body



details:   https://anonhg.NetBSD.org/src/rev/af2cdc082b11
branches:  trunk
changeset: 375901:af2cdc082b11
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat May 20 10:46:21 2023 +0000

description:
indent: implement blank line after function body

diffstat:

 tests/usr.bin/indent/opt_bap.c |  42 ++++++++++++++++++++++++++++++++++--------
 usr.bin/indent/debug.c         |   5 +++--
 usr.bin/indent/indent.c        |   7 +++++--
 usr.bin/indent/indent.h        |   8 +++++---
 usr.bin/indent/io.c            |   7 +++++--
 5 files changed, 52 insertions(+), 17 deletions(-)

diffs (180 lines):

diff -r 7fc5b0813e53 -r af2cdc082b11 tests/usr.bin/indent/opt_bap.c
--- a/tests/usr.bin/indent/opt_bap.c    Sat May 20 10:25:47 2023 +0000
+++ b/tests/usr.bin/indent/opt_bap.c    Sat May 20 10:46:21 2023 +0000
@@ -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
diff -r 7fc5b0813e53 -r af2cdc082b11 usr.bin/indent/debug.c
--- a/usr.bin/indent/debug.c    Sat May 20 10:25:47 2023 +0000
+++ b/usr.bin/indent/debug.c    Sat May 20 10:46:21 2023 +0000
@@ -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
diff -r 7fc5b0813e53 -r af2cdc082b11 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Sat May 20 10:25:47 2023 +0000
+++ b/usr.bin/indent/indent.c   Sat May 20 10:46:21 2023 +0000
@@ -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);
 }
 
diff -r 7fc5b0813e53 -r af2cdc082b11 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Sat May 20 10:25:47 2023 +0000
+++ b/usr.bin/indent/indent.h   Sat May 20 10:46:21 2023 +0000
@@ -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 */
diff -r 7fc5b0813e53 -r af2cdc082b11 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Sat May 20 10:25:47 2023 +0000
+++ b/usr.bin/indent/io.c       Sat May 20 10:46:21 2023 +0000
@@ -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;
 }
 



Home | Main Index | Thread Index | Old Index