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: handle the indentation of 'case' in a...
details: https://anonhg.NetBSD.org/src/rev/0b877c880e91
branches: trunk
changeset: 376193:0b877c880e91
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Jun 04 11:09:18 2023 +0000
description:
indent: handle the indentation of 'case' in a simpler way
diffstat:
usr.bin/indent/debug.c | 6 +++---
usr.bin/indent/indent.c | 9 ++++-----
usr.bin/indent/indent.h | 5 ++---
usr.bin/indent/io.c | 14 +++++---------
4 files changed, 14 insertions(+), 20 deletions(-)
diffs (145 lines):
diff -r 72209aee3ac2 -r 0b877c880e91 usr.bin/indent/debug.c
--- a/usr.bin/indent/debug.c Sun Jun 04 10:23:36 2023 +0000
+++ b/usr.bin/indent/debug.c Sun Jun 04 11:09:18 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.26 2023/06/04 10:23:36 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.27 2023/06/04 11:09:18 rillig Exp $ */
/*-
* Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: debug.c,v 1.26 2023/06/04 10:23:36 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.27 2023/06/04 11:09:18 rillig Exp $");
#include <stdarg.h>
@@ -127,6 +127,7 @@ const char *const line_kind_name[] = {
"stmt head",
"}",
"block comment",
+ "case/default",
};
static const char *const decl_ptr_name[] = {
@@ -329,7 +330,6 @@ debug_parser_state(void)
debug_ps_bool(in_stmt_or_decl);
debug_ps_bool(in_stmt_cont);
- debug_ps_bool(is_case_label);
debug_ps_bool(seen_case);
// The debug output for the parser symbols is done in 'parse' instead.
diff -r 72209aee3ac2 -r 0b877c880e91 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Sun Jun 04 10:23:36 2023 +0000
+++ b/usr.bin/indent/indent.c Sun Jun 04 11:09:18 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.318 2023/06/04 10:23:36 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.319 2023/06/04 11:09:18 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.318 2023/06/04 10:23:36 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.319 2023/06/04 11:09:18 rillig Exp $");
#include <sys/param.h>
#include <err.h>
@@ -712,8 +712,9 @@ process_colon(void)
buf_add_char(&lab, ':');
code.len = 0;
+ if (ps.seen_case)
+ out.line_kind = lk_case_or_default;
ps.in_stmt_or_decl = false;
- ps.is_case_label = ps.seen_case;
ps.force_nl = ps.seen_case;
ps.seen_case = false;
ps.want_blank = false;
@@ -1058,8 +1059,6 @@ process_preprocessing(void)
read_preprocessing_line();
- ps.is_case_label = false;
-
const char *end = lab.mem + lab.len;
const char *dir = lab.st + 1;
while (dir < end && ch_isblank(*dir))
diff -r 72209aee3ac2 -r 0b877c880e91 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h Sun Jun 04 10:23:36 2023 +0000
+++ b/usr.bin/indent/indent.h Sun Jun 04 11:09:18 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.163 2023/06/04 10:23:36 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.164 2023/06/04 11:09:18 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -313,8 +313,6 @@ extern struct parser_state {
bool in_func_def_params;
bool seen_case; /* set to true when we see a 'case', so we know
* what to do with the following colon */
- bool is_case_label; /* 'case' and 'default' labels are indented
- * differently from regular labels */
parser_symbol spaced_expr_psym; /* the parser symbol to be shifted
* after the parenthesized expression
* from a 'for', 'if', 'switch' or
@@ -425,6 +423,7 @@ extern struct output_state {
* 'if (expr)' or 'for (expr; expr; expr)' */
lk_func_end, /* the last '}' of a function body */
lk_block_comment,
+ lk_case_or_default,
} line_kind; /* kind of the line that is being prepared for
* output; is reset to lk_other each time after
* trying to send a line to the output, even if
diff -r 72209aee3ac2 -r 0b877c880e91 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c Sun Jun 04 10:23:36 2023 +0000
+++ b/usr.bin/indent/io.c Sun Jun 04 11:09:18 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.187 2023/05/23 18:16:28 rillig Exp $ */
+/* $NetBSD: io.c,v 1.188 2023/06/04 11:09:18 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.187 2023/05/23 18:16:28 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.188 2023/06/04 11:09:18 rillig Exp $");
#include <stdio.h>
@@ -174,17 +174,13 @@ is_blank_line_optional(void)
static int
output_line_label(void)
{
- int ind;
while (lab.len > 0 && ch_isblank(lab.mem[lab.len - 1]))
lab.len--;
- ind = output_indent(0, compute_label_indent());
+ int ind = output_indent(0, compute_label_indent());
output_range(lab.st, lab.len);
- ind = ind_add(ind, lab.st, lab.len);
-
- ps.is_case_label = false;
- return ind;
+ return ind_add(ind, lab.st, lab.len);
}
static int
@@ -376,7 +372,7 @@ compute_code_indent(void)
int
compute_label_indent(void)
{
- if (ps.is_case_label)
+ if (out.line_kind == lk_case_or_default)
return (int)(case_ind * (float)opt.indent_size);
if (lab.st[0] == '#')
return 0;
Home |
Main Index |
Thread Index |
Old Index