Module Name:    src
Committed By:   rillig
Date:           Tue May 23 16:53:57 UTC 2023

Modified Files:
        src/tests/usr.bin/indent: fmt_decl.c
        src/usr.bin/indent: debug.c indent.c

Log Message:
indent: fix indentation of struct declarations


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/tests/usr.bin/indent/fmt_decl.c
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/indent/debug.c
cvs rdiff -u -r1.308 -r1.309 src/usr.bin/indent/indent.c

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/fmt_decl.c
diff -u src/tests/usr.bin/indent/fmt_decl.c:1.45 src/tests/usr.bin/indent/fmt_decl.c:1.46
--- src/tests/usr.bin/indent/fmt_decl.c:1.45	Tue May 23 06:43:19 2023
+++ src/tests/usr.bin/indent/fmt_decl.c	Tue May 23 16:53:57 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: fmt_decl.c,v 1.45 2023/05/23 06:43:19 rillig Exp $	*/
+/*	$NetBSD: fmt_decl.c,v 1.46 2023/05/23 16:53:57 rillig Exp $	*/
 
 /*
  * Tests for declarations of global variables, external functions, and local
@@ -602,7 +602,8 @@ ToToken(bool cond)
 
 
 /*
- * Indent gets easily confused by unknown type names in struct declarations.
+ * Before indent.c 1.309 from 2023-05-23, indent easily got confused by unknown
+ * type names in struct declarations, as a ';' did not finish a declaration.
  */
 //indent input
 typedef struct OpenDirs {
@@ -611,20 +612,14 @@ typedef struct OpenDirs {
 }		OpenDirs;
 //indent end
 
-/* FIXME: The word 'HashTable' must not be aligned like a member name. */
-//indent run
-typedef struct OpenDirs {
-	CachedDirList	list;
-			HashTable /* of CachedDirListNode */ table;
-}		OpenDirs;
-//indent end
-
 //indent run-equals-input -THashTable
 
+//indent run-equals-input
+
 
 /*
- * Indent gets easily confused by unknown type names, even in declarations
- * that are syntactically unambiguous.
+ * Before lexi.c 1.153 from 2021-11-25, indent easily got confused by unknown
+ * type names, even in declarations that are syntactically unambiguous.
  */
 //indent input
 static CachedDir *dot = NULL;
@@ -632,14 +627,12 @@ static CachedDir *dot = NULL;
 
 //indent run-equals-input -TCachedDir
 
-/* Since lexi.c 1.153 from 2021-11-25. */
 //indent run-equals-input
 
 
 /*
- * Before lexi.c 1.156 from 2021-11-25, indent easily got confused by unknown
- * type names in declarations and generated 'HashEntry * he' with an extra
- * space.
+ * Before lexi.c 1.153 from 2021-11-25, indent easily got confused by unknown
+ * type names in declarations.
  */
 //indent input
 static CachedDir *
@@ -648,7 +641,6 @@ CachedDir_New(const char *name)
 }
 //indent end
 
-/* Since lexi.c 1.153 from 2021-11-25. */
 //indent run-equals-input
 
 
@@ -697,15 +689,15 @@ CachedDir_Assign(CachedDir **var, Cached
 }
 //indent end
 
-//indent run-equals-input
-
 //indent run-equals-input -TCachedDir
 
+//indent run-equals-input
+
 
 /*
  * Before lexi.c 1.153 from 2021-11-25, all initializer expressions after the
- * first one were indented as if they would be statement continuations. This
- * was because the token 'Shell' was identified as a word, not as a type name.
+ * first one were indented as if they were statement continuations. This was
+ * caused by the token 'Shell' being identified as a word, not as a type name.
  */
 //indent input
 static Shell	shells[] = {
@@ -716,7 +708,6 @@ static Shell	shells[] = {
 };
 //indent end
 
-/* Since lexi.c 1.153 from 2021-11-25. */
 //indent run-equals-input
 
 
@@ -963,22 +954,6 @@ ch_isalpha(char ch)
 
 
 //indent input
-struct {
-	void *list;
-	Table /* comment */ table;
-} var;
-//indent end
-
-//indent run -di0
-struct {
-	void *list;
-// $ FIXME: Wrong indentation, as 'Table' starts a new declaration.
-	     Table /* comment */ table;
-} var;
-//indent end
-
-
-//indent input
 void __printflike(1, 2)
 debug_printf(const char *fmt, ...)
 {

Index: src/usr.bin/indent/debug.c
diff -u src/usr.bin/indent/debug.c:1.22 src/usr.bin/indent/debug.c:1.23
--- src/usr.bin/indent/debug.c:1.22	Tue May 23 12:12:29 2023
+++ src/usr.bin/indent/debug.c	Tue May 23 16:53:57 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: debug.c,v 1.22 2023/05/23 12:12:29 rillig Exp $	*/
+/*	$NetBSD: debug.c,v 1.23 2023/05/23 16:53:57 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: debug.c,v 1.22 2023/05/23 12:12:29 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.23 2023/05/23 16:53:57 rillig Exp $");
 
 #include <stdarg.h>
 
@@ -134,7 +134,7 @@ static const char *const decl_ptr_name[]
 	"other",
 };
 
-static unsigned wrote_newlines;
+static unsigned wrote_newlines = 1;
 
 void
 debug_printf(const char *fmt, ...)

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.308 src/usr.bin/indent/indent.c:1.309
--- src/usr.bin/indent/indent.c:1.308	Tue May 23 12:12:29 2023
+++ src/usr.bin/indent/indent.c	Tue May 23 16:53:57 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.308 2023/05/23 12:12:29 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.309 2023/05/23 16:53:57 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.308 2023/05/23 12:12:29 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.309 2023/05/23 16:53:57 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -687,6 +687,7 @@ process_semicolon(void)
 	buf_add_char(&code, ';');
 	ps.want_blank = true;
 	ps.in_stmt_or_decl = ps.nparen > 0;
+	ps.decl_ind = 0;
 
 	if (ps.spaced_expr_psym == psym_0) {
 		parse(psym_0);	/* let parser know about end of stmt */

Reply via email to