Module Name: src
Committed By: rillig
Date: Thu Jun 15 08:40:20 UTC 2023
Modified Files:
src/tests/usr.bin/indent: fmt_decl.c
src/usr.bin/indent: indent.c
Log Message:
indent: fix alignment of multi-line declarations
To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/tests/usr.bin/indent/fmt_decl.c
cvs rdiff -u -r1.367 -r1.368 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.55 src/tests/usr.bin/indent/fmt_decl.c:1.56
--- src/tests/usr.bin/indent/fmt_decl.c:1.55 Wed Jun 14 20:46:08 2023
+++ src/tests/usr.bin/indent/fmt_decl.c Thu Jun 15 08:40:20 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: fmt_decl.c,v 1.55 2023/06/14 20:46:08 rillig Exp $ */
+/* $NetBSD: fmt_decl.c,v 1.56 2023/06/15 08:40:20 rillig Exp $ */
/*
* Tests for declarations of global variables, external functions, and local
@@ -295,36 +295,33 @@ struct s01234567890123 a,b;
struct s a, b;
/* $ XXX: See process_comma, varname_len for why this line is broken. */
struct s0 a,
- b;
-/* $ XXX: The indentation of the second line is wrong. The variable names */
-/* $ XXX: 'a' and 'b' should be in the same column; the word 'struct' is */
-/* $ XXX: missing in the calculation for the indentation. */
+ b;
struct s01 a,
- b;
+ b;
struct s012 a,
- b;
+ b;
struct s0123 a,
- b;
+ b;
struct s01234 a,
- b;
+ b;
struct s012345 a,
- b;
+ b;
struct s0123456 a,
- b;
+ b;
struct s01234567 a,
- b;
+ b;
struct s012345678 a,
- b;
+ b;
struct s0123456789 a,
- b;
+ b;
struct s01234567890 a,
- b;
+ b;
struct s012345678901 a,
- b;
+ b;
struct s0123456789012 a,
- b;
+ b;
struct s01234567890123 a,
- b;
+ b;
//indent end
Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.367 src/usr.bin/indent/indent.c:1.368
--- src/usr.bin/indent/indent.c:1.367 Wed Jun 14 20:46:08 2023
+++ src/usr.bin/indent/indent.c Thu Jun 15 08:40:20 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.367 2023/06/14 20:46:08 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.368 2023/06/15 08:40:20 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.367 2023/06/14 20:46:08 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.368 2023/06/15 08:40:20 rillig Exp $");
#include <sys/param.h>
#include <err.h>
@@ -933,7 +933,8 @@ process_type_outside_parentheses(void)
if (ps.decl_level <= 0)
ps.declaration = decl_begin;
- int len = (int)token.len + 1;
+ int len = (code.len > 0 ? ind_add(0, code.s, code.len) + 1 : 0)
+ + (int)token.len + 1;
int ind = ps.ind_level > 0 && ps.decl_level == 0
? opt.local_decl_indent /* local variable */
: opt.decl_indent; /* global variable, or member */