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: move debugging code to separate file
details: https://anonhg.NetBSD.org/src/rev/585d69643666
branches: trunk
changeset: 375327:585d69643666
user: rillig <rillig%NetBSD.org@localhost>
date: Mon May 15 07:57:22 2023 +0000
description:
indent: move debugging code to separate file
No functional change.
diffstat:
usr.bin/indent/debug.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++-
usr.bin/indent/indent.c | 50 +-----------------------------------------------
usr.bin/indent/indent.h | 4 +-
usr.bin/indent/lexi.c | 22 +++++++-------------
4 files changed, 60 insertions(+), 66 deletions(-)
diffs (217 lines):
diff -r fc625e067213 -r 585d69643666 usr.bin/indent/debug.c
--- a/usr.bin/indent/debug.c Mon May 15 07:28:45 2023 +0000
+++ b/usr.bin/indent/debug.c Mon May 15 07:57:22 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.5 2023/05/15 07:28:45 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.6 2023/05/15 07:57:22 rillig Exp $ */
/*-
* Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,9 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: debug.c,v 1.5 2023/05/15 07:28:45 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.6 2023/05/15 07:57:22 rillig Exp $");
+
+#include <stdarg.h>
#include "indent.h"
@@ -105,6 +107,50 @@ static const char *in_enum_name[] = {
static bool debug_full_parser_state = true;
+void
+debug_printf(const char *fmt, ...)
+{
+ FILE *f = output == stdout ? stderr : stdout;
+ va_list ap;
+
+ va_start(ap, fmt);
+ vfprintf(f, fmt, ap);
+ va_end(ap);
+}
+
+void
+debug_println(const char *fmt, ...)
+{
+ FILE *f = output == stdout ? stderr : stdout;
+ va_list ap;
+
+ va_start(ap, fmt);
+ vfprintf(f, fmt, ap);
+ va_end(ap);
+ fprintf(f, "\n");
+}
+
+void
+debug_vis_range(const char *prefix, const char *s, size_t len,
+ const char *suffix)
+{
+ debug_printf("%s", prefix);
+ for (size_t i = 0; i < len; i++) {
+ const char *p = s + i;
+ if (*p == '\\' || *p == '"')
+ debug_printf("\\%c", *p);
+ else if (isprint((unsigned char)*p))
+ debug_printf("%c", *p);
+ else if (*p == '\n')
+ debug_printf("\\n");
+ else if (*p == '\t')
+ debug_printf("\\t");
+ else
+ debug_printf("\\x%02x", (unsigned char)*p);
+ }
+ debug_printf("%s", suffix);
+}
+
static void
debug_print_buf(const char *name, const struct buffer *buf)
{
diff -r fc625e067213 -r 585d69643666 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Mon May 15 07:28:45 2023 +0000
+++ b/usr.bin/indent/indent.c Mon May 15 07:57:22 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.268 2023/05/15 07:28:45 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.269 2023/05/15 07:57:22 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.268 2023/05/15 07:28:45 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.269 2023/05/15 07:57:22 rillig Exp $");
#include <sys/param.h>
#include <err.h>
@@ -1125,52 +1125,6 @@ main(int argc, char **argv)
return main_loop();
}
-#ifdef debug
-void
-debug_printf(const char *fmt, ...)
-{
- FILE *f = output == stdout ? stderr : stdout;
- va_list ap;
-
- va_start(ap, fmt);
- vfprintf(f, fmt, ap);
- va_end(ap);
-}
-
-void
-debug_println(const char *fmt, ...)
-{
- FILE *f = output == stdout ? stderr : stdout;
- va_list ap;
-
- va_start(ap, fmt);
- vfprintf(f, fmt, ap);
- va_end(ap);
- fprintf(f, "\n");
-}
-
-void
-debug_vis_range(const char *prefix, const char *s, size_t len,
- const char *suffix)
-{
- debug_printf("%s", prefix);
- for (size_t i = 0; i < len; i++) {
- const char *p = s + i;
- if (*p == '\\' || *p == '"')
- debug_printf("\\%c", *p);
- else if (isprint((unsigned char)*p))
- debug_printf("%c", *p);
- else if (*p == '\n')
- debug_printf("\\n");
- else if (*p == '\t')
- debug_printf("\\t");
- else
- debug_printf("\\x%02x", (unsigned char)*p);
- }
- debug_printf("%s", suffix);
-}
-#endif
-
static void *
nonnull(void *p)
{
diff -r fc625e067213 -r 585d69643666 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h Mon May 15 07:28:45 2023 +0000
+++ b/usr.bin/indent/indent.h Mon May 15 07:57:22 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.133 2023/05/15 07:28:45 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.134 2023/05/15 07:57:22 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -377,7 +377,7 @@ extern const char *const psym_name[];
#define debug_printf(fmt, ...) debug_noop()
#define debug_println(fmt, ...) debug_noop()
#define debug_vis_range(prefix, s, e, suffix) debug_noop()
-#define debug_parser_state() debug_noop()
+#define debug_parser_state(lsym) debug_noop()
#define debug_parse_stack(situation) debug_noop()
#define debug_buffers() debug_noop()
#endif
diff -r fc625e067213 -r 585d69643666 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c Mon May 15 07:28:45 2023 +0000
+++ b/usr.bin/indent/lexi.c Mon May 15 07:57:22 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lexi.c,v 1.185 2023/05/15 07:28:45 rillig Exp $ */
+/* $NetBSD: lexi.c,v 1.186 2023/05/15 07:57:22 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: lexi.c,v 1.185 2023/05/15 07:28:45 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.186 2023/05/15 07:57:22 rillig Exp $");
#include <stdlib.h>
#include <string.h>
@@ -173,15 +173,6 @@ token_add_char(char ch)
}
-static lexer_symbol
-lexi_end(lexer_symbol lsym)
-{
-#ifdef debug
- debug_parser_state(lsym);
-#endif
- return lsym;
-}
-
static void
lex_number(void)
{
@@ -491,8 +482,10 @@ lexi(void)
}
lexer_symbol alnum_lsym = lexi_alnum();
- if (alnum_lsym != lsym_eof)
- return lexi_end(alnum_lsym);
+ if (alnum_lsym != lsym_eof) {
+ debug_parser_state(alnum_lsym);
+ return alnum_lsym;
+ }
/* Scan a non-alphanumeric token */
@@ -623,7 +616,8 @@ lexi(void)
ps.next_unary = next_unary;
- return lexi_end(lsym);
+ debug_parser_state(lsym);
+ return lsym;
}
void
Home |
Main Index |
Thread Index |
Old Index