Module Name: src
Committed By: rillig
Date: Thu May 11 17:22:56 UTC 2023
Modified Files:
src/tests/usr.bin/indent: opt_bl_br.c
src/usr.bin/indent: indent.h io.c
Log Message:
indent: add debug output for tracking comments and braces
To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/opt_bl_br.c
cvs rdiff -u -r1.115 -r1.116 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.148 -r1.149 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_bl_br.c
diff -u src/tests/usr.bin/indent/opt_bl_br.c:1.7 src/tests/usr.bin/indent/opt_bl_br.c:1.8
--- src/tests/usr.bin/indent/opt_bl_br.c:1.7 Thu May 11 09:28:53 2023
+++ src/tests/usr.bin/indent/opt_bl_br.c Thu May 11 17:22:56 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_bl_br.c,v 1.7 2023/05/11 09:28:53 rillig Exp $ */
+/* $NetBSD: opt_bl_br.c,v 1.8 2023/05/11 17:22:56 rillig Exp $ */
//indent input
void
@@ -44,7 +44,7 @@ standard_style(int n)
*/
//indent input
void
-example(int n)
+condensed_style(int n)
{
if (n > 99) { print("large"); }
else if (n > 9) { print("double-digit"); }
@@ -55,7 +55,7 @@ example(int n)
//indent run -bl
void
-example(int n)
+condensed_style(int n)
{
if (n > 99)
{
@@ -76,7 +76,7 @@ example(int n)
//indent run -br
void
-example(int n)
+condensed_style(int n)
{
if (n > 99) {
print("large");
@@ -98,7 +98,8 @@ example(int n)
* line.
*/
//indent input
-void function(void)
+void
+eol_comment(void)
{
if (expr) // C99 comment
stmt();
@@ -110,9 +111,9 @@ void function(void)
}
//indent end
-//indent run
+//indent run -br
void
-function(void)
+eol_comment(void)
{
if (expr) // C99 comment
stmt();
@@ -124,6 +125,8 @@ function(void)
}
//indent end
+//indent run-equals-prev-output -bl
+
/*
* Test multiple mixed comments after 'if (expr)'.
@@ -173,3 +176,95 @@ function(void)
/* TODO: Remove the newline between ')' and '{'. */
//indent run-equals-input -br
+
+
+//indent input
+void
+comments(void)
+{
+ if(cond){}
+
+ if (cond)
+ {}
+
+ if (cond) /* comment */
+ {}
+
+ if (cond)
+ /* comment */
+ {}
+
+ if (cond)
+ // comment1
+ // comment2
+ {}
+
+ if (cond) // comment
+ {}
+}
+//indent end
+
+//indent run -bl
+void
+comments(void)
+{
+ if (cond)
+ {
+ }
+
+ if (cond)
+ {
+ }
+
+ if (cond) /* comment */
+ {
+ }
+
+ if (cond)
+ /* comment */
+ {
+ }
+
+ if (cond)
+ // comment1
+ // comment2
+ {
+ }
+
+ if (cond) // comment
+ {
+ }
+}
+//indent end
+
+//indent run -br
+void
+comments(void)
+{
+ if (cond) {
+ }
+
+ if (cond)
+ {
+ }
+
+ if (cond) /* comment */
+ {
+ }
+
+ if (cond)
+ /* comment */
+ {
+ }
+
+ if (cond)
+ // comment1
+ // comment2
+ {
+ }
+
+ if (cond) // comment
+ {
+ }
+}
+//indent end
Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.115 src/usr.bin/indent/indent.h:1.116
--- src/usr.bin/indent/indent.h:1.115 Thu May 11 11:25:47 2023
+++ src/usr.bin/indent/indent.h Thu May 11 17:22:56 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.115 2023/05/11 11:25:47 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.116 2023/05/11 17:22:56 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -279,7 +279,7 @@ extern struct parser_state {
bool force_nl; /* when true, the following token goes to the
* next line, unless it is a '{' and
- * opt.brace_right is set. */
+ * opt.brace_same_line is set. */
int line_start_nparen; /* the number of parentheses or brackets that
* were already open at the beginning of the
Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.148 src/usr.bin/indent/io.c:1.149
--- src/usr.bin/indent/io.c:1.148 Sat Apr 23 06:43:22 2022
+++ src/usr.bin/indent/io.c Thu May 11 17:22:56 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.148 2022/04/23 06:43:22 rillig Exp $ */
+/* $NetBSD: io.c,v 1.149 2023/05/11 17:22:56 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.148 2022/04/23 06:43:22 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.149 2023/05/11 17:22:56 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -514,6 +514,14 @@ output_complete_line(char line_terminato
ps.is_function_definition = false;
+ debug_println("%s: %d %s%s%s%s",
+ __func__,
+ out.blank_lines_to_output,
+ out.blank_lines_to_output == 1 ? "line" : "lines",
+ out.blank_line_before ? ", before" : "",
+ out.blank_line_after ? ", after" : "",
+ out.suppress_blanklines ? ", suppress" : "");
+
if (code.s == code.e && lab.s == lab.e && com.s == com.e) {
if (out.suppress_blanklines)
out.suppress_blanklines = false;