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 above block comment



details:   https://anonhg.NetBSD.org/src/rev/aa0a6000996a
branches:  trunk
changeset: 375902:aa0a6000996a
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat May 20 11:19:17 2023 +0000

description:
indent: implement blank line above block comment

diffstat:

 tests/usr.bin/indent/lsym_comment.c |   3 ++-
 tests/usr.bin/indent/opt_bbb.c      |  10 +++++-----
 usr.bin/indent/debug.c              |   5 +++--
 usr.bin/indent/indent.h             |   3 ++-
 usr.bin/indent/io.c                 |   9 ++++-----
 usr.bin/indent/pr_comment.c         |   6 ++++--
 6 files changed, 20 insertions(+), 16 deletions(-)

diffs (161 lines):

diff -r af2cdc082b11 -r aa0a6000996a tests/usr.bin/indent/lsym_comment.c
--- a/tests/usr.bin/indent/lsym_comment.c       Sat May 20 10:46:21 2023 +0000
+++ b/tests/usr.bin/indent/lsym_comment.c       Sat May 20 11:19:17 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_comment.c,v 1.13 2023/05/16 11:32:02 rillig Exp $ */
+/* $NetBSD: lsym_comment.c,v 1.14 2023/05/20 11:19:17 rillig Exp $ */
 
 /*
  * Tests for the token lsym_comment, which starts a comment.
@@ -100,6 +100,7 @@ t(void) {
 void
 t(void)
 {
+
        /*
         * Old indent wrapped the URL near where this sentence ends.
         *
diff -r af2cdc082b11 -r aa0a6000996a tests/usr.bin/indent/opt_bbb.c
--- a/tests/usr.bin/indent/opt_bbb.c    Sat May 20 10:46:21 2023 +0000
+++ b/tests/usr.bin/indent/opt_bbb.c    Sat May 20 11:19:17 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_bbb.c,v 1.7 2023/05/11 18:13:55 rillig Exp $ */
+/* $NetBSD: opt_bbb.c,v 1.8 2023/05/20 11:19:17 rillig Exp $ */
 
 /*
  * Tests for the options '-bbb' and '-nbbb'.
@@ -39,22 +39,22 @@ function_definition(void)
  * This is a block comment.
  */
 /* This is not a block comment since it is single-line. */
-/* $ TODO: Add a blank line here. */
+
 /*
  * This is a second block comment.
  */
 /* This is not a block comment. */
-/* $ TODO: Add a blank line here. */
+
 /*
  * Documentation of global_variable.
  */
 int            global_variable;
-/* $ TODO: Add a blank line here. */
+
 /*
  * Documentation of function_declaration.
  */
 void           function_declaration(void);
-/* $ TODO: Add a blank line here. */
+
 /*
  * Documentation of function_definition.
  */
diff -r af2cdc082b11 -r aa0a6000996a usr.bin/indent/debug.c
--- a/usr.bin/indent/debug.c    Sat May 20 10:46:21 2023 +0000
+++ b/usr.bin/indent/debug.c    Sat May 20 11:19:17 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: debug.c,v 1.17 2023/05/20 10:46:21 rillig Exp $        */
+/*     $NetBSD: debug.c,v 1.18 2023/05/20 11:19:17 rillig Exp $        */
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: debug.c,v 1.17 2023/05/20 10:46:21 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.18 2023/05/20 11:19:17 rillig Exp $");
 
 #include <stdarg.h>
 
@@ -122,6 +122,7 @@ static const char *const line_kind_name[
        "#if",
        "#endif",
        "}",
+       "block comment",
 };
 
 void
diff -r af2cdc082b11 -r aa0a6000996a usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Sat May 20 10:46:21 2023 +0000
+++ b/usr.bin/indent/indent.h   Sat May 20 11:19:17 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.154 2023/05/20 10:46:21 rillig Exp $      */
+/*     $NetBSD: indent.h,v 1.155 2023/05/20 11:19:17 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -399,6 +399,7 @@ extern struct parser_state {
                lk_if,          /* #if, #ifdef, #ifndef */
                lk_endif,       /* #endif */
                lk_func_end,    /* the last '}' of a function body */
+               lk_block_comment,
        } 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 */
diff -r af2cdc082b11 -r aa0a6000996a usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Sat May 20 10:46:21 2023 +0000
+++ b/usr.bin/indent/io.c       Sat May 20 11:19:17 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.181 2023/05/20 10:46:21 rillig Exp $  */
+/*     $NetBSD: io.c,v 1.182 2023/05/20 11:19:17 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.181 2023/05/20 10:46:21 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.182 2023/05/20 11:19:17 rillig Exp $");
 
 #include <stdio.h>
 
@@ -143,17 +143,16 @@ want_blank_line(void)
                ps.blank_line_after_decl = false;
                return true;
        }
-
        if (opt.blanklines_around_conditional_compilation) {
                if (ps.prev_line_kind != lk_if && ps.line_kind == lk_if)
                        return true;
                if (ps.prev_line_kind == lk_endif && ps.line_kind != lk_endif)
                        return true;
        }
-
        if (opt.blanklines_after_procs && ps.prev_line_kind == lk_func_end)
                return true;
-
+       if (opt.blanklines_before_block_comments && ps.line_kind == lk_block_comment)
+               return true;
        return false;
 }
 
diff -r af2cdc082b11 -r aa0a6000996a usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Sat May 20 10:46:21 2023 +0000
+++ b/usr.bin/indent/pr_comment.c       Sat May 20 11:19:17 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pr_comment.c,v 1.146 2023/05/18 05:33:27 rillig Exp $  */
+/*     $NetBSD: pr_comment.c,v 1.147 2023/05/20 11:19:17 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pr_comment.c,v 1.146 2023/05/18 05:33:27 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.147 2023/05/20 11:19:17 rillig Exp $");
 
 #include <string.h>
 
@@ -92,6 +92,8 @@ analyze_comment(bool *p_may_wrap, bool *
                        may_wrap = false;
                        delim = false;
                }
+               if (code.len == 0 && inp.st[strspn(inp.st, "*")] == '\n')
+                       ps.line_kind = lk_block_comment;
 
                if (com.len > 0)
                        output_line();



Home | Main Index | Thread Index | Old Index