Module Name:    src
Committed By:   rillig
Date:           Sat May 20 11:19:17 UTC 2023

Modified Files:
        src/tests/usr.bin/indent: lsym_comment.c opt_bbb.c
        src/usr.bin/indent: debug.c indent.h io.c pr_comment.c

Log Message:
indent: implement blank line above block comment


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/tests/usr.bin/indent/lsym_comment.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/opt_bbb.c
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/indent/debug.c
cvs rdiff -u -r1.154 -r1.155 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.181 -r1.182 src/usr.bin/indent/io.c
cvs rdiff -u -r1.146 -r1.147 src/usr.bin/indent/pr_comment.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/lsym_comment.c
diff -u src/tests/usr.bin/indent/lsym_comment.c:1.13 src/tests/usr.bin/indent/lsym_comment.c:1.14
--- src/tests/usr.bin/indent/lsym_comment.c:1.13	Tue May 16 11:32:02 2023
+++ src/tests/usr.bin/indent/lsym_comment.c	Sat May 20 11:19:17 2023
@@ -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.
 	 *

Index: src/tests/usr.bin/indent/opt_bbb.c
diff -u src/tests/usr.bin/indent/opt_bbb.c:1.7 src/tests/usr.bin/indent/opt_bbb.c:1.8
--- src/tests/usr.bin/indent/opt_bbb.c:1.7	Thu May 11 18:13:55 2023
+++ src/tests/usr.bin/indent/opt_bbb.c	Sat May 20 11:19:17 2023
@@ -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.
  */

Index: src/usr.bin/indent/debug.c
diff -u src/usr.bin/indent/debug.c:1.17 src/usr.bin/indent/debug.c:1.18
--- src/usr.bin/indent/debug.c:1.17	Sat May 20 10:46:21 2023
+++ src/usr.bin/indent/debug.c	Sat May 20 11:19:17 2023
@@ -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

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.154 src/usr.bin/indent/indent.h:1.155
--- src/usr.bin/indent/indent.h:1.154	Sat May 20 10:46:21 2023
+++ src/usr.bin/indent/indent.h	Sat May 20 11:19:17 2023
@@ -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 */

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.181 src/usr.bin/indent/io.c:1.182
--- src/usr.bin/indent/io.c:1.181	Sat May 20 10:46:21 2023
+++ src/usr.bin/indent/io.c	Sat May 20 11:19:17 2023
@@ -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;
 }
 

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.146 src/usr.bin/indent/pr_comment.c:1.147
--- src/usr.bin/indent/pr_comment.c:1.146	Thu May 18 05:33:27 2023
+++ src/usr.bin/indent/pr_comment.c	Sat May 20 11:19:17 2023
@@ -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();

Reply via email to