From 21e06607a012704bed3c3b009fa76c4a7f973887 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 21 Aug 2017 15:31:06 +0200 Subject: [PATCH] Improve the debug printing function: MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - Add va_arg support; - Flag the debug char* properly; - Use the function in the pawns array displaying helper function. Signed-off-by: Jérôme Benoit --- lib/debug.c | 28 +++++++++++++++++----------- lib/debug.h | 3 ++- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/debug.c b/lib/debug.c index e00ce9f..ead3216 100644 --- a/lib/debug.c +++ b/lib/debug.c @@ -21,21 +21,27 @@ #include "othello.h" #include "debug.h" +#if BUILD_TYPE == debug +void dbg_mvprintw(int y, int x, const char* debug_text, ...) { + va_list func_args; + char debug_msg[256]; + + snprintf(debug_msg, sizeof(debug_msg), "%s%s", "DEBUG: ", debug_text); + va_start(func_args, debug_text); + mvprintw(y, x, debug_msg, func_args); + va_end(func_args); +} +#else +void dbg_mvprintw(int y, int x, const char* debug_text, ...) { } +#endif + void display_array(int base_y, int base_x, unsigned int pawn_array[board_size][board_size]) { for (int i = 1; i <= board_size; i++) { - mvprintw(base_y + i, base_x, "%d", i); + dbg_mvprintw(base_y + i, base_x, "%d", i); for (int j = 1; j <= board_size; j++) { - mvprintw(base_y, base_x + j, "%d", j); - mvprintw(base_y + i, base_x + j, "%d", get_box_value(i, j, pawn_array)); + dbg_mvprintw(base_y, base_x + j, "%d", j); + dbg_mvprintw(base_y + i, base_x + j, "%d", get_box_value(i, j, pawn_array)); } } } - -#if BUILD_TYPE == debug -void dbg_mvprintv(int y, int x, char* debug_text) { - mvprintw(y, x, debug_text); -} -#else -void dbg_mvprintv(int y, int x, char* debug_text) { } -#endif diff --git a/lib/debug.h b/lib/debug.h index e87809d..b8327ff 100644 --- a/lib/debug.h +++ b/lib/debug.h @@ -22,7 +22,8 @@ #include #include "constants.h" - + +void dbg_mvprintw(int y, int x, const char* debug_text, ...); void display_array(int base_y, int base_x, unsigned int pawn_array[board_size][board_size]); #endif /* DEBUG_H */ -- 2.34.1