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: fix missing blank before binary operator



details:   https://anonhg.NetBSD.org/src/rev/6a58df58ef92
branches:  trunk
changeset: 1024609:6a58df58ef92
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Oct 29 21:56:36 2021 +0000

description:
indent: fix missing blank before binary operator

diffstat:

 tests/usr.bin/indent/token_binary_op.c |  24 ++++++++++++++----------
 usr.bin/indent/indent.c                |   6 +++---
 usr.bin/indent/indent.h                |   5 +++--
 3 files changed, 20 insertions(+), 15 deletions(-)

diffs (87 lines):

diff -r 1a4af60b9218 -r 6a58df58ef92 tests/usr.bin/indent/token_binary_op.c
--- a/tests/usr.bin/indent/token_binary_op.c    Fri Oct 29 21:42:02 2021 +0000
+++ b/tests/usr.bin/indent/token_binary_op.c    Fri Oct 29 21:56:36 2021 +0000
@@ -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 @@
 #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
diff -r 1a4af60b9218 -r 6a58df58ef92 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Fri Oct 29 21:42:02 2021 +0000
+++ b/usr.bin/indent/indent.c   Fri Oct 29 21:56:36 2021 +0000
@@ -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 @@
 
 #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 @@
 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;
diff -r 1a4af60b9218 -r 6a58df58ef92 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Fri Oct 29 21:42:02 2021 +0000
+++ b/usr.bin/indent/indent.h   Fri Oct 29 21:56:36 2021 +0000
@@ -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 @@
     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



Home | Main Index | Thread Index | Old Index