Module Name:    src
Committed By:   rillig
Date:           Mon Oct 25 21:33:24 UTC 2021

Modified Files:
        src/usr.bin/indent: indent.c lexi.c

Log Message:
indent: improve debug logging

Output the various details in chronological order.


To generate a diff of this commit:
cvs rdiff -u -r1.158 -r1.159 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.100 -r1.101 src/usr.bin/indent/lexi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.158 src/usr.bin/indent/indent.c:1.159
--- src/usr.bin/indent/indent.c:1.158	Mon Oct 25 19:56:03 2021
+++ src/usr.bin/indent/indent.c	Mon Oct 25 21:33:24 2021
@@ -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 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #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_vis_range(const char *prefix, cons
 {
     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");

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.100 src/usr.bin/indent/lexi.c:1.101
--- src/usr.bin/indent/lexi.c:1.100	Mon Oct 25 00:54:37 2021
+++ src/usr.bin/indent/lexi.c	Mon Oct 25 21:33:24 2021
@@ -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 @@ static char sccsid[] = "@(#)lexi.c	8.1 (
 
 #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 @@ lsym_name(lexer_symbol sym)
     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");
     }
 }
-#endif
 
-static lexer_symbol
-lexi_end(lexer_symbol lsym)
+static void
+debug_lexi(lexer_symbol lsym)
 {
-#ifdef debug
-    debug_printf("in line %d, lexi returns '%s'",
-	line_no, lsym_name(lsym));
-    debug_print_buf("token", &token);
+    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_lexi(lsym);
+#endif
     return lsym;
 }
 

Reply via email to