From fea66a5127120823aced137ec32857fd484837de Mon Sep 17 00:00:00 2001 From: rillig Date: Sat, 13 Mar 2021 18:46:39 +0000 Subject: [PATCH] indent: add debug logging for switching the input buffer No functional change outside debug mode. --- usr.bin/indent/indent.c | 19 +++++++++++++------ usr.bin/indent/io.c | 5 +++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/usr.bin/indent/indent.c b/usr.bin/indent/indent.c index 390eda3433ad..857c057315cd 100644 --- a/usr.bin/indent/indent.c +++ b/usr.bin/indent/indent.c @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.57 2021/03/13 13:51:08 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.58 2021/03/13 18:46:39 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.17 (Berkeley) 6/7/93"; #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.57 2021/03/13 13:51:08 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.58 2021/03/13 18:46:39 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -314,6 +314,7 @@ search_brace(token_type *inout_type_code, int *inout_force_nl, *sc_end++ = ' '; /* add trailing blank, just in case */ buf_end = sc_end; sc_end = NULL; + debug_println("switched buf_ptr to save_com"); break; } } /* end of switch */ @@ -640,11 +641,17 @@ process_lparen_or_lbracket(int dec_ind, int tabs_to_var, int sp_sw) *e_code++ = ' '; ps.want_blank = false; *e_code++ = token[0]; + ps.paren_indents[ps.p_l_follow - 1] = indentation_after_range(0, s_code, e_code); + debug_println("paren_indent[%d] is now %d", + ps.p_l_follow - 1, ps.paren_indents[ps.p_l_follow - 1]); + if (sp_sw && ps.p_l_follow == 1 && opt.extra_expression_indent - && ps.paren_indents[0] < 2 * opt.indent_size) + && ps.paren_indents[0] < 2 * opt.indent_size) { ps.paren_indents[0] = 2 * opt.indent_size; + debug_println("paren_indent[0] is now %d", ps.paren_indents[0]); + } if (ps.in_or_st && *token == '(' && ps.tos <= 2) { /* * this is a kluge to make sure that declarations will be @@ -1196,12 +1203,12 @@ process_preprocessing(void) e_lab--; bp_save = buf_ptr; /* save current input buffer */ be_save = buf_end; - buf_ptr = save_com; /* fix so that subsequent calls to - * lexi will take tokens out of - * save_com */ + buf_ptr = save_com; /* fix so that subsequent calls to lexi will + * take tokens out of save_com */ *sc_end++ = ' '; /* add trailing blank, just in case */ buf_end = sc_end; sc_end = NULL; + debug_println("switched buf_ptr to save_com"); } check_size_label(1); *e_lab = '\0'; /* null terminate line */ diff --git a/usr.bin/indent/io.c b/usr.bin/indent/io.c index 439d020765f8..5f555bd1871e 100644 --- a/usr.bin/indent/io.c +++ b/usr.bin/indent/io.c @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.46 2021/03/13 18:24:56 rillig Exp $ */ +/* $NetBSD: io.c,v 1.47 2021/03/13 18:46:39 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 6/6/93"; #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.46 2021/03/13 18:24:56 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.47 2021/03/13 18:46:39 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -346,6 +346,7 @@ fill_buffer(void) buf_ptr = bp_save; /* do not read anything, just switch buffers */ buf_end = be_save; bp_save = be_save = NULL; + debug_println("switched buf_ptr back to bp_save"); if (buf_ptr < buf_end) return; /* only return if there is really something in * this buffer */