From: Jérôme Benoit Date: Wed, 23 Aug 2017 16:09:53 +0000 (+0200) Subject: Simplify the debugging functions X-Git-Url: https://git.piment-noir.org/?p=Project_algorithmic_C.git;a=commitdiff_plain;h=c8c562de07c5dcd2fd557ed100cf62a15140bbe4 Simplify the debugging functions Signed-off-by: Jérôme Benoit --- diff --git a/Makefile b/Makefile index fd4ca9a..16a35a1 100644 --- a/Makefile +++ b/Makefile @@ -22,8 +22,8 @@ SRC_PATH:=src LIBRARY_NAME:=lib$(BINARY_NAME) LIBRARY_PATH:=lib LDLIBS:=-l$(BINARY_NAME) -lncurses -ltinfo -BUILD_TYPE:=debug -#BUILD_TYPE:=release +#BUILD_TYPE:=debug +BUILD_TYPE:=release # ==================================== # DO NOT CHANGE STUFF BEYOND THIS LINE @@ -40,6 +40,7 @@ UNAME := $(shell uname -s) ifeq ($(BUILD_TYPE),debug) BUILDDIR := .build/debug DEBUG_FLAG = -g +DEBUG = 1 STRIP_FLAG = OPTI_FLAG = -O0 LTO_SUPPORT = yes @@ -47,6 +48,7 @@ GOLD_SUPPORT = yes else BUILDDIR := .build/release DEBUG_FLAG = +DEBUG = 0 STRIP_FLAG = -s OPTI_FLAG = -O3 LTO_SUPPORT = yes @@ -106,7 +108,7 @@ endif # Putting header files in the source directory is not the purpose of this INCLUDES_PATH variable INCLUDES_PATH := $(INCLUDES_PATH) -I$(LIBRARY_PATH) -CFLAGS := -DBUILD_TYPE=$(BUILD_TYPE) $(CFLAGS) $(CFLAGS_LTO) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG) $(INCLUDES_PATH) +CFLAGS := -DDEBUG=$(DEBUG) $(CFLAGS) $(CFLAGS_LTO) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG) $(INCLUDES_PATH) LIBCFLAGS := -fPIC $(CFLAGS) LDFLAGS := $(LDFLAGS) $(LDFLAGS_LTO) $(LDFLAGS_GOLD) $(STRIP_FLAG) LIBLDFLAGS := $(SHLIBLDFLAG) $(LDFLAGS) diff --git a/lib/debug.c b/lib/debug.c index a9ccc60..e6631c6 100644 --- a/lib/debug.c +++ b/lib/debug.c @@ -21,27 +21,17 @@ #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 - +#if DEBUG 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++) { - dbg_mvprintw(base_y + i, base_x, "%d", i); + mvprintw(base_y + i, base_x, "%d", i); for (int j = 1; j <= board_size; j++) { - 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)); + mvprintw(base_y, base_x + j, "%d", j); + mvprintw(base_y + i, base_x + j, "%d", get_box_value(i, j, pawn_array)); } } } +#else +void display_array(int base_y, int base_x, unsigned int pawn_array[board_size][board_size]) { } +#endif /* DEBUG */ diff --git a/lib/debug.h b/lib/debug.h index b8327ff..71f88ed 100644 --- a/lib/debug.h +++ b/lib/debug.h @@ -23,7 +23,12 @@ #include "constants.h" -void dbg_mvprintw(int y, int x, const char* debug_text, ...); +#if DEBUG +#define dbg_mvprintw(...) mvprintw(__VA_ARGS__) +#else +#define dbg_mvprintw(...) { } +#endif /* DEBUG */ + void display_array(int base_y, int base_x, unsigned int pawn_array[board_size][board_size]); #endif /* DEBUG_H */ diff --git a/src/main.c b/src/main.c index 224e35c..03b75cb 100644 --- a/src/main.c +++ b/src/main.c @@ -77,7 +77,7 @@ int main() { mvprintw(center_y, center_x - 42/2 - snprintf(NULL, 0, score_msg, "noirs", nb_black) - 2, score_msg, "noirs", nb_black); mvprintw(center_y, center_x + 42/2 + 2, score_msg, "blancs", nb_white); - //display_array(1, 1, pawns); + display_array(1, 1, pawns); int y; char x_char; @@ -85,7 +85,7 @@ int main() { unsigned int nb_pawns_reversed = 0; do { y = 0; - x_char = ""; + x_char = (char)""; const char* prompt_msg = "Prochain pion ? (ligne colonne - chiffre lettre):"; int prmt_rt = prompt_values(stdscr, center_y + 26/2 + 1, (center_x - strlen(prompt_msg)/2), prompt_msg, &y, &x_char); int x = map_col_letter_to_index(x_char);