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: improve debug logging
details: https://anonhg.NetBSD.org/src/rev/990ac8c91624
branches: trunk
changeset: 990078:990ac8c91624
user: rillig <rillig%NetBSD.org@localhost>
date: Mon Oct 25 21:33:24 2021 +0000
description:
indent: improve debug logging
Output the various details in chronological order.
diffstat:
usr.bin/indent/indent.c | 8 ++++--
usr.bin/indent/lexi.c | 56 ++++++++++++++++++++++++++++++++++++++----------
2 files changed, 49 insertions(+), 15 deletions(-)
diffs (119 lines):
diff -r f044b3ffcd09 -r 990ac8c91624 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Mon Oct 25 20:32:38 2021 +0000
+++ b/usr.bin/indent/indent.c Mon Oct 25 21:33:24 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.158 2021/10/25 19:56:03 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.159 2021/10/25 21:33:24 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.158 2021/10/25 19:56:03 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.159 2021/10/25 21:33:24 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
#endif
@@ -1554,7 +1554,9 @@
{
debug_printf("%s", prefix);
for (const char *p = s; p < e; p++) {
- if (isprint((unsigned char)*p) && *p != '\\' && *p != '"')
+ if (*p == '\\' || *p == '"')
+ debug_printf("\\%c", *p);
+ else if (isprint((unsigned char)*p))
debug_printf("%c", *p);
else if (*p == '\n')
debug_printf("\\n");
diff -r f044b3ffcd09 -r 990ac8c91624 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c Mon Oct 25 20:32:38 2021 +0000
+++ b/usr.bin/indent/lexi.c Mon Oct 25 21:33:24 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lexi.c,v 1.100 2021/10/25 00:54:37 rillig Exp $ */
+/* $NetBSD: lexi.c,v 1.101 2021/10/25 21:33:24 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.100 2021/10/25 00:54:37 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.101 2021/10/25 21:33:24 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
#endif
@@ -260,29 +260,61 @@
return name[sym];
}
+static const char *
+kw_name(enum keyword_kind kw) {
+ static const char *name[] = {
+ "0",
+ "offsetof",
+ "sizeof",
+ "struct_or_union_or_enum",
+ "type",
+ "for",
+ "if",
+ "while",
+ "do",
+ "else",
+ "switch",
+ "case_or_default",
+ "jump",
+ "storage_class",
+ "typedef",
+ "inline_or_restrict",
+ };
+
+ return name[kw];
+}
+
static void
debug_print_buf(const char *name, const struct buffer *buf)
{
if (buf->s < buf->e) {
- debug_printf(" %s ", name);
- debug_vis_range("\"", buf->s, buf->e, "\"");
+ debug_printf("%s ", name);
+ debug_vis_range("\"", buf->s, buf->e, "\"\n");
}
}
+
+static void
+debug_lexi(lexer_symbol lsym)
+{
+ debug_printf("\n");
+ debug_printf("line %d\n", line_no);
+ debug_print_buf("label", &lab);
+ debug_print_buf("code", &code);
+ debug_print_buf("comment", &com);
+ debug_printf("lexi returns '%s'", lsym_name(lsym));
+ if (ps.keyword != kw_0)
+ debug_printf(" keyword '%s'", kw_name(ps.keyword));
+ debug_printf("\n");
+ debug_print_buf("token", &token);
+}
#endif
static lexer_symbol
lexi_end(lexer_symbol lsym)
{
#ifdef debug
- debug_printf("in line %d, lexi returns '%s'",
- line_no, lsym_name(lsym));
- debug_print_buf("token", &token);
- debug_print_buf("label", &lab);
- debug_print_buf("code", &code);
- debug_print_buf("comment", &com);
- debug_printf("\n");
+ debug_lexi(lsym);
#endif
-
return lsym;
}
Home |
Main Index |
Thread Index |
Old Index