Module Name: src
Committed By: rillig
Date: Fri Oct 29 21:56:37 UTC 2021
Modified Files:
src/tests/usr.bin/indent: token_binary_op.c
src/usr.bin/indent: indent.c indent.h
Log Message:
indent: fix missing blank before binary operator
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/indent/token_binary_op.c
cvs rdiff -u -r1.177 -r1.178 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.62 -r1.63 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/token_binary_op.c
diff -u src/tests/usr.bin/indent/token_binary_op.c:1.3 src/tests/usr.bin/indent/token_binary_op.c:1.4
--- src/tests/usr.bin/indent/token_binary_op.c:1.3 Tue Oct 26 22:00:38 2021
+++ src/tests/usr.bin/indent/token_binary_op.c Fri Oct 29 21:56:36 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: token_binary_op.c,v 1.3 2021/10/26 22:00:38 rillig Exp $ */
+/* $NetBSD: token_binary_op.c,v 1.4 2021/10/29 21:56:36 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -220,18 +220,22 @@ peculiarities(void)
#indent end
+/*
+ * Before NetBSD indent.c 1.178 from 2021-10-29, indent removed the blank
+ * before the '=', in the second and third of these function pointer
+ * declarations. This was because indent interpreted the prototype parameters
+ * 'int' and 'int, int' as type casts, which doesn't make sense at all. Fixing
+ * this properly requires large style changes since indent is based on simple
+ * heuristics all over. This didn't change in indent.c 1.178; instead, the
+ * rule for inserting a blank before a binary operator was changed to always
+ * insert a blank, except at the beginning of a line.
+ */
#indent input
char *(*fn)() = NULL;
char *(*fn)(int) = NULL;
char *(*fn)(int, int) = NULL;
#indent end
-/* FIXME: The parameter '(int)' is wrongly interpreted as a type cast. */
-/* FIXME: The parameter '(int, int)' is wrongly interpreted as a type cast. */
-#indent run -di0
-char *(*fn)() = NULL;
-/* $ FIXME: Missing space before '='. */
-char *(*fn)(int)= NULL;
-/* $ FIXME: Missing space before '='. */
-char *(*fn)(int, int)= NULL;
-#indent end
+/* XXX: The parameter '(int)' is wrongly interpreted as a type cast. */
+/* XXX: The parameter '(int, int)' is wrongly interpreted as a type cast. */
+#indent run-equals-input -di0
Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.177 src/usr.bin/indent/indent.c:1.178
--- src/usr.bin/indent/indent.c:1.177 Fri Oct 29 20:27:42 2021
+++ src/usr.bin/indent/indent.c Fri Oct 29 21:56:36 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.177 2021/10/29 20:27:42 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.178 2021/10/29 21:56:36 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c 5.1
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.177 2021/10/29 20:27:42 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.178 2021/10/29 21:56:36 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
#endif
@@ -815,7 +815,7 @@ process_unary_op(int decl_ind, bool tabs
static void
process_binary_op(void)
{
- if (ps.want_blank)
+ if (!ps.prev_newline && buf_len(&code) > 0)
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.62 src/usr.bin/indent/indent.h:1.63
--- src/usr.bin/indent/indent.h:1.62 Fri Oct 29 20:27:42 2021
+++ src/usr.bin/indent/indent.h Fri Oct 29 21:56:36 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.62 2021/10/29 20:27:42 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.63 2021/10/29 21:56:36 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -285,7 +285,8 @@ extern struct parser_state {
lexer_symbol prev_token;
bool prev_newline; /* whether the last thing scanned was a
* newline */
- bool prev_col_1; /* whether the last token started in column 1 */
+ bool prev_col_1; /* whether the last token started in column 1
+ * of the unformatted input */
enum keyword_kind prev_keyword;
enum keyword_kind curr_keyword;
bool next_unary; /* whether the following operator should be