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 indentation of ad-hoc tagged vari...



details:   https://anonhg.NetBSD.org/src/rev/53b185661452
branches:  trunk
changeset: 1024462:53b185661452
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Oct 24 20:43:27 2021 +0000

description:
indent: fix indentation of ad-hoc tagged variables

Seen among others in usr.bin/indent/lexi.c, variable 'keywords'.

diffstat:

 tests/usr.bin/indent/opt_di.c          |  20 ++++++++------
 tests/usr.bin/indent/opt_ldi.c         |  46 +++++++++++++++++++++++++++++++++-
 tests/usr.bin/indent/token_semicolon.c |   4 +-
 usr.bin/indent/indent.c                |   9 ++++--
 4 files changed, 64 insertions(+), 15 deletions(-)

diffs (147 lines):

diff -r b436cd8d2636 -r 53b185661452 tests/usr.bin/indent/opt_di.c
--- a/tests/usr.bin/indent/opt_di.c     Sun Oct 24 20:00:11 2021 +0000
+++ b/tests/usr.bin/indent/opt_di.c     Sun Oct 24 20:43:27 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_di.c,v 1.3 2021/10/24 19:24:22 rillig Exp $ */
+/* $NetBSD: opt_di.c,v 1.4 2021/10/24 20:43:28 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -101,6 +101,15 @@
 #indent end
 
 
+/*
+ * A variable that has an ad-hoc struct/union/enum type does not need to be
+ * indented to the right of the keyword 'struct', it only needs a single space
+ * of indentation.
+ *
+ * Before NetBSD indent.c 1.151 from 2021-10-24, the indentation depended on
+ * the length of the keyword 'struct', 'union' or 'enum', together with type
+ * qualifiers like 'const' or the storage class like 'static'.
+ */
 #indent input
 struct {
        int member;
@@ -109,14 +118,7 @@
 };
 #indent end
 
-/* FIXME: The variable name is indented by 6 spaces, should be 1. */
-#indent run -di0
-struct {
-       int member;
-}      var = {
-       3,
-};
-#indent end
+#indent run-equals-input -di0
 
 #indent run
 struct {
diff -r b436cd8d2636 -r 53b185661452 tests/usr.bin/indent/opt_ldi.c
--- a/tests/usr.bin/indent/opt_ldi.c    Sun Oct 24 20:00:11 2021 +0000
+++ b/tests/usr.bin/indent/opt_ldi.c    Sun Oct 24 20:43:27 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_ldi.c,v 1.1 2021/10/22 20:54:36 rillig Exp $ */
+/* $NetBSD: opt_ldi.c,v 1.2 2021/10/24 20:43:28 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -35,3 +35,47 @@
        int                     local;
 }
 #indent end
+
+
+/*
+ * A variable that has an ad-hoc struct/union/enum type does not need to be
+ * indented to the right of the keyword 'struct', it only needs a single space
+ * of indentation.
+ *
+ * Before NetBSD indent.c 1.151 from 2021-10-24, the indentation depended on
+ * the length of the keyword 'struct', 'union' or 'enum', together with type
+ * qualifiers like 'const' or the storage class like 'static'.
+ */
+#indent input
+{
+       struct {
+               int member;
+       } var = {
+               3,
+       };
+}
+#indent end
+
+/*
+ * Struct members use -di for indentation, no matter whether they are
+ * declared globally or locally.
+ */
+#indent run -ldi0
+{
+       struct {
+               int             member;
+       } var = {
+               3,
+       };
+}
+#indent end
+
+#indent run -ldi16
+{
+       struct {
+               int             member;
+       }               var = {
+               3,
+       };
+}
+#indent end
diff -r b436cd8d2636 -r 53b185661452 tests/usr.bin/indent/token_semicolon.c
--- a/tests/usr.bin/indent/token_semicolon.c    Sun Oct 24 20:00:11 2021 +0000
+++ b/tests/usr.bin/indent/token_semicolon.c    Sun Oct 24 20:43:27 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: token_semicolon.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */
+/* $NetBSD: token_semicolon.c,v 1.2 2021/10/24 20:43:28 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -14,7 +14,7 @@
 #indent input
 struct {
        int member;
-}      global_var;
+} global_var;
 #indent end
 
 #indent run-equals-input -di0
diff -r b436cd8d2636 -r 53b185661452 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Sun Oct 24 20:00:11 2021 +0000
+++ b/usr.bin/indent/indent.c   Sun Oct 24 20:43:27 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.150 2021/10/24 19:33:26 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.151 2021/10/24 20:43:27 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.150 2021/10/24 19:33:26 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.151 2021/10/24 20:43:27 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -1023,8 +1023,11 @@
 
     if (ps.decl_nest > 0) { /* we are in multi-level structure declaration */
        *decl_ind = di_stack[--ps.decl_nest];
-       if (ps.decl_nest == 0 && !ps.in_parameter_declaration)
+       if (ps.decl_nest == 0 && !ps.in_parameter_declaration) {
            ps.just_saw_decl = 2;
+           *decl_ind = ps.ind_level == 0
+               ? opt.decl_indent : opt.local_decl_indent;
+       }
        ps.in_decl = true;
     }
 



Home | Main Index | Thread Index | Old Index