Module Name: src
Committed By: rillig
Date: Mon May 15 20:30:20 UTC 2023
Modified Files:
src/tests/usr.bin/indent: lsym_comment.c
src/usr.bin/indent: indent.c indent.h
Log Message:
indent: fix duplicate space between comment and binary operator
To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/indent/lsym_comment.c
cvs rdiff -u -r1.281 -r1.282 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.140 -r1.141 src/usr.bin/indent/indent.h
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.11 src/tests/usr.bin/indent/lsym_comment.c:1.12
--- src/tests/usr.bin/indent/lsym_comment.c:1.11 Mon May 15 19:55:51 2023
+++ src/tests/usr.bin/indent/lsym_comment.c Mon May 15 20:30:20 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_comment.c,v 1.11 2023/05/15 19:55:51 rillig Exp $ */
+/* $NetBSD: lsym_comment.c,v 1.12 2023/05/15 20:30:20 rillig Exp $ */
/*
* Tests for the token lsym_comment, which starts a comment.
@@ -1078,3 +1078,22 @@ error*/
* error
*/
//indent end
+
+
+/*
+ * Ensure that there is exactly one space between the comment and the
+ * following binary operator.
+ */
+//indent input
+{
+a /* */ > b;
+a>b;
+}
+//indent end
+
+//indent run
+{
+ a /* */ > b;
+ a > b;
+}
+//indent end
Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.281 src/usr.bin/indent/indent.c:1.282
--- src/usr.bin/indent/indent.c:1.281 Mon May 15 20:12:28 2023
+++ src/usr.bin/indent/indent.c Mon May 15 20:30:20 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.281 2023/05/15 20:12:28 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.282 2023/05/15 20:30:20 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.281 2023/05/15 20:12:28 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.282 2023/05/15 20:30:20 rillig Exp $");
#include <sys/param.h>
#include <err.h>
@@ -539,7 +539,7 @@ process_unary_op(void)
static void
process_binary_op(void)
{
- if (code.len > 0)
+ if (code.len > 0 && ps.want_blank)
buf_add_char(&code, ' ');
buf_add_buf(&code, &token);
ps.want_blank = true;
Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.140 src/usr.bin/indent/indent.h:1.141
--- src/usr.bin/indent/indent.h:1.140 Mon May 15 20:12:28 2023
+++ src/usr.bin/indent/indent.h Mon May 15 20:30:20 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.140 2023/05/15 20:12:28 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.141 2023/05/15 20:30:20 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -358,8 +358,8 @@ extern struct parser_state {
/* Vertical spacing */
- bool force_nl; /* whether the next token is forced to go to
- * a new line; used after 'if (expr)' and
+ bool force_nl; /* whether the next token is forced to go to a
+ * new line; used after 'if (expr)' and in
* similar situations; tokens like '{' may
* ignore this */