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: enhance debug logging for input handling



details:   https://anonhg.NetBSD.org/src/rev/8c4a459f892e
branches:  trunk
changeset: 1026491:8c4a459f892e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Nov 26 15:21:38 2021 +0000

description:
indent: enhance debug logging for input handling

diffstat:

 usr.bin/indent/io.c |  35 +++++++++++++++++++++++------------
 1 files changed, 23 insertions(+), 12 deletions(-)

diffs (85 lines):

diff -r 1bb4aa8c9e95 -r 8c4a459f892e usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Fri Nov 26 15:18:18 2021 +0000
+++ b/usr.bin/indent/io.c       Fri Nov 26 15:21:38 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.138 2021/11/26 15:08:48 rillig Exp $  */
+/*     $NetBSD: io.c,v 1.139 2021/11/26 15:21:38 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.138 2021/11/26 15:08:48 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.139 2021/11/26 15:21:38 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -133,18 +133,25 @@
 }
 
 #ifdef debug
+static void
+debug_inp_buf(const char *name, const char *s, const char *e)
+{
+    if (s != NULL && e != NULL) {
+       debug_printf("    %-12s ", name);
+       debug_vis_range("\"", s, e, "\"\n");
+    }
+}
+
 void
 debug_inp(const char *prefix)
 {
-    debug_printf("%s:", prefix);
-    debug_vis_range(" inp \"", inbuf.inp.s, inbuf.inp.e, "\"");
-    if (inbuf.save_com_s != NULL)
-       debug_vis_range(" save_com \"",
-                       inbuf.save_com_s, inbuf.save_com_e, "\"");
-    if (inbuf.saved_inp_s != NULL)
-       debug_vis_range(" saved_inp \"",
-                       inbuf.saved_inp_s, inbuf.saved_inp_e, "\"");
-    debug_printf("\n");
+    debug_println("%s %s:", __func__, prefix);
+    if (inbuf.saved_inp_s == NULL)
+       debug_inp_buf("inp.buf", inbuf.inp.buf, inbuf.inp.s);
+    debug_inp_buf("inp", inbuf.inp.s, inbuf.inp.e);    /* never null */
+    debug_inp_buf("save_com.buf", inbuf.save_com_buf, inbuf.save_com_s);
+    debug_inp_buf("save_com", inbuf.save_com_s, inbuf.save_com_e);
+    debug_inp_buf("saved_inp", inbuf.saved_inp_s, inbuf.saved_inp_e);
 }
 #endif
 
@@ -202,11 +209,14 @@
     assert((size_t)(inbuf.inp.s - inbuf.inp.buf) >= 4);
     size_t line_len = (size_t)(inbuf.inp.s - inbuf.inp.buf) - 4;
     assert(line_len < array_length(inbuf.save_com_buf));
+
     memcpy(inbuf.save_com_buf, inbuf.inp.buf, line_len);
     inbuf.save_com_s = inbuf.save_com_buf + line_len;
+
     inbuf.save_com_s[0] = ' '; /* see inp_comment_insert_lbrace */
     inbuf.save_com_s[1] = ' '; /* see inp_comment_insert_lbrace */
     inbuf.save_com_e = &inbuf.save_com_s[2];
+
     debug_vis_range("search_stmt_comment: before save_com is \"",
        inbuf.save_com_buf, inbuf.save_com_s, "\"\n");
     debug_vis_range("search_stmt_comment: save_com is \"",
@@ -272,6 +282,7 @@
 void
 inp_from_comment(void)
 {
+    debug_inp("before inp_from_comment");
     inbuf.saved_inp_s = inbuf.inp.s;
     inbuf.saved_inp_e = inbuf.inp.e;
 
@@ -279,7 +290,7 @@
     inbuf.inp.e = inbuf.save_com_e;
     inbuf.save_com_s = NULL;
     inbuf.save_com_e = NULL;
-    debug_inp(__func__);
+    debug_inp("after inp_from_comment");
 }
 
 /*



Home | Main Index | Thread Index | Old Index