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 formatting of function definition...



details:   https://anonhg.NetBSD.org/src/rev/9ee2bf7fb5b0
branches:  trunk
changeset: 1026340:9ee2bf7fb5b0
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Nov 19 19:37:13 2021 +0000

description:
indent: fix formatting of function definitions (since 2019-04-04)

In the definition of a function with a pointer return type, the
formatting depended on the name of the function.  Function names
matching [A-Za-z+] were formatted correctly, those containing [$0-9_]
weren't.

diffstat:

 tests/usr.bin/indent/fmt_decl.c |  40 ++++++++++++----------------------------
 tests/usr.bin/indent/opt_bacc.c |  17 +++--------------
 usr.bin/indent/lexi.c           |  24 ++++++++++++++++++------
 3 files changed, 33 insertions(+), 48 deletions(-)

diffs (168 lines):

diff -r 668fc06b383f -r 9ee2bf7fb5b0 tests/usr.bin/indent/fmt_decl.c
--- a/tests/usr.bin/indent/fmt_decl.c   Fri Nov 19 19:15:55 2021 +0000
+++ b/tests/usr.bin/indent/fmt_decl.c   Fri Nov 19 19:37:13 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fmt_decl.c,v 1.17 2021/11/19 18:55:10 rillig Exp $     */
+/*     $NetBSD: fmt_decl.c,v 1.18 2021/11/19 19:37:13 rillig Exp $     */
 /* $FreeBSD: head/usr.bin/indent/tests/declarations.0 334478 2018-06-01 09:41:15Z pstef $ */
 
 /* See FreeBSD r303570 */
@@ -160,22 +160,6 @@
 
 
 #indent input
-int *int_create(void)
-{
-
-}
-#indent end
-
-#indent run
-int           *
-int_create(void)
-{
-
-}
-#indent end
-
-
-#indent input
 static
 _attribute_printf(1, 2)
 void
@@ -437,6 +421,9 @@
  * In some ancient time long before ISO C90, variable declarations with
  * initializer could be written without '='. The C Programming Language from
  * 1978 doesn't mention this form anymore.
+ *
+ * Before NetBSD lexi.c 1.123 from 2021-10-31, indent treated the '-' as a
+ * unary operator.
  */
 #indent input
 int a - 1;
@@ -454,8 +441,11 @@
 
 
 /*
- * Since 2019-04-04, the indentation of the '*' depends on the function name,
- * which does not make sense.
+ * Between 2019-04-04 and before lexi.c 1.146 from 2021-11-09, the indentation
+ * of the '*' depended on the function name, which did not make sense.  For
+ * function names that matched [A-Za-z]+, the '*' was placed correctly, for
+ * all other function names (containing [$0-9_]) the '*' was right-aligned on
+ * declaration indentation, which defaults to 16.
  */
 #indent input
 int *
@@ -467,21 +457,15 @@
 yy(void)
 {
 }
-#indent end
-
-/* FIXME: Both function definitions must be formatted in the same way. */
-#indent run
-int           *
-f2(void)
-{
-}
 
 int *
-yy(void)
+int_create(void)
 {
 }
 #indent end
 
+#indent run-equals-input
+
 
 /*
  * Since 2019-04-04, the space between the '){' is missing.
diff -r 668fc06b383f -r 9ee2bf7fb5b0 tests/usr.bin/indent/opt_bacc.c
--- a/tests/usr.bin/indent/opt_bacc.c   Fri Nov 19 19:15:55 2021 +0000
+++ b/tests/usr.bin/indent/opt_bacc.c   Fri Nov 19 19:37:13 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_bacc.c,v 1.4 2021/10/20 05:14:21 rillig Exp $ */
+/* $NetBSD: opt_bacc.c,v 1.5 2021/11/19 19:37:13 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -86,8 +86,7 @@
 #indent end
 
 #indent run -bacc
-/* $ XXX: The '*' should not be set apart from the rest of the return type. */
-const char     *
+const char *
 os_name(void)
 {
 /* $ FIXME: expecting a blank line here. */
@@ -104,14 +103,4 @@
 }
 #indent end
 
-#indent run -nbacc
-const char     *
-os_name(void)
-{
-#if defined(__NetBSD__) || defined(__FreeBSD__)
-       return "BSD";
-#else
-       return "unknown";
-#endif
-}
-#indent end
+#indent run-equals-input -nbacc
diff -r 668fc06b383f -r 9ee2bf7fb5b0 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Fri Nov 19 19:15:55 2021 +0000
+++ b/usr.bin/indent/lexi.c     Fri Nov 19 19:37:13 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.145 2021/11/19 19:15:55 rillig Exp $        */
+/*     $NetBSD: lexi.c,v 1.146 2021/11/19 19:37:13 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.145 2021/11/19 19:15:55 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.146 2021/11/19 19:37:13 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -350,6 +350,12 @@
 }
 
 static bool
+is_identifier_start(char ch)
+{
+    return isalpha((unsigned char)ch) || ch == '_' || ch == '$';
+}
+
+static bool
 is_identifier_part(char ch)
 {
     return isalnum((unsigned char)ch) || ch == '_' || ch == '$';
@@ -687,10 +693,16 @@
        if (ps.in_decl) {
            const char *tp = inp_p(), *e = inp_line_end();
 
-           /* XXX: is_identifier_start */
-           while (tp < e && (isalpha((unsigned char)*tp) ||
-                   isspace((unsigned char)*tp)))
-               tp++;
+           while (tp < e) {
+               if (isspace((unsigned char)*tp))
+                   tp++;
+               else if (is_identifier_start(*tp)) {
+                   tp++;
+                   while (tp < e && is_identifier_part(*tp))
+                       tp++;
+               } else
+                   break;
+           }
 
            if (tp < e && *tp == '(')
                ps.procname[0] = ' ';   /* XXX: why not '\0'? */



Home | Main Index | Thread Index | Old Index