From 8dc9dd02e68db51bf93d4061233399e55957d48e Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Thu, 10 Oct 2013 23:08:00 -0400 Subject: [PATCH] Replace macro EMU8051_DEBUG with logging functions --- src/app-config.c | 14 +++----------- src/common.h | 3 --- src/emuconsole.c | 4 +--- src/emugtk.c | 38 ++++++++++---------------------------- src/filemenu.c | 19 ++++--------------- src/memwin.c | 4 +--- src/pgmwin.c | 12 +++--------- 7 files changed, 22 insertions(+), 72 deletions(-) diff --git a/src/app-config.c b/src/app-config.c index 15bed2b..b61b900 100644 --- a/src/app-config.c +++ b/src/app-config.c @@ -62,17 +62,11 @@ app_config_key_file_get_int(GKeyFile *kf, const char *grp, const char *key, int { char *str = g_key_file_get_value(kf, grp, key, NULL); -#ifdef EMU8051_DEBUG - printf("key: %s\n", key); -#endif + log_debug("key: %s", key); if (G_LIKELY(str)) { *value = atoi(str); - -#ifdef EMU8051_DEBUG - printf(" value = %d\n", *value); -#endif - + log_debug(" value = %d", *value); g_free(str); } @@ -117,9 +111,7 @@ app_config_get_file_path(void) file_path = g_build_filename(dir_path, file, NULL); -#ifdef EMU8051_DEBUG - printf("app. config file = %s\n", file_path); -#endif + log_info("app. config file = %s", file_path); g_free(dir_path); diff --git a/src/common.h b/src/common.h index 51a8c1c..0058a01 100644 --- a/src/common.h +++ b/src/common.h @@ -22,9 +22,6 @@ #ifndef COMMON_H #define COMMON_H 1 -/* Define this to have debugging output. */ -/* #define EMU8051_DEBUG 1 */ - #include #include #include diff --git a/src/emuconsole.c b/src/emuconsole.c index 4c35f5a..3dcdf89 100644 --- a/src/emuconsole.c +++ b/src/emuconsole.c @@ -462,9 +462,7 @@ main(int argc, char **argv) console_main(); -#ifdef EMU8051_DEBUG - printf("End of program.\n"); -#endif + log_info("Terminate"); return 0; } diff --git a/src/emugtk.c b/src/emugtk.c index 656a07e..f3e6e37 100644 --- a/src/emugtk.c +++ b/src/emugtk.c @@ -60,9 +60,7 @@ static void emugtk_stop_running() { if (running) { -#ifdef EMU8051_DEBUG - printf("emugtk_StopRunning()\n"); -#endif + log_info("StopRunning()"); g_source_remove(running_function_tag); running = 0; regwin_Show(); @@ -77,9 +75,7 @@ emugtk_running(gpointer data) { cpu8051_Exec(); if (IsBreakpoint(cpu8051.pc)) { -#ifdef EMU8051_DEBUG - g_print("Breakpoint Hit, stopping!\n"); -#endif + log_info("Breakpoint Hit"); emugtk_stop_running(); } @@ -91,9 +87,7 @@ static void emugtk_start_running(void) { if (!running) { -#ifdef EMU8051_DEBUG - printf("emugtk_StartRunning()\n"); -#endif + log_info("StartRunning()"); running_function_tag = g_idle_add(emugtk_running, 0); running = 1; } @@ -131,9 +125,7 @@ emugtk_Reset(void) static void emugtk_ResetEvent(GtkWidget *widget, GdkEvent *event, gpointer data) { -#ifdef EMU8051_DEBUG - g_print("emugtk_ResetEvent(...)\n"); -#endif + log_info("ResetEvent()"); emugtk_stop_running(); emugtk_Reset(); } @@ -152,9 +144,8 @@ emugtk_Step(void) static void emugtk_RunEvent(GtkWidget *widget, GdkEvent *event, gpointer data) { -#ifdef EMU8051_DEBUG - g_print("emugtk_RunEvent(...)\n"); -#endif + log_info("RunEvent()"); + if (running) emugtk_stop_running(); else @@ -165,9 +156,7 @@ emugtk_RunEvent(GtkWidget *widget, GdkEvent *event, gpointer data) static void emugtk_StopEvent(GtkWidget *widget, GdkEvent *event, gpointer data) { -#ifdef EMU8051_DEBUG - g_print("emugtk_StopEvent(...)\n"); -#endif + log_info("StopEvent()"); emugtk_stop_running(); } @@ -175,9 +164,7 @@ emugtk_StopEvent(GtkWidget *widget, GdkEvent *event, gpointer data) static void emugtk_StepEvent(GtkWidget *widget, GdkEvent *event, gpointer data) { -#ifdef EMU8051_DEBUG - g_print("emugtk_StepEvent(...)\n"); -#endif + log_info("StepEvent()"); emugtk_stop_running(); emugtk_Step(); } @@ -399,10 +386,7 @@ emugtk_window_init(void) static void emugtk_UpdateDisplay(void) { -#ifdef EMU8051_DEBUG - g_print("emugtk_UpdateDisplay()\n"); -#endif - + log_debug("UpdateDisplay()"); regwin_Show(); pgmwin_Disasm(); memwin_DumpD("00"); @@ -449,9 +433,7 @@ main(int argc, char **argv) gtk_main(); -#ifdef EMU8051_DEBUG - printf("End of program.\n"); -#endif + log_info("Terminate"); app_config_save(); diff --git a/src/filemenu.c b/src/filemenu.c index 7e9e3dd..47e18aa 100644 --- a/src/filemenu.c +++ b/src/filemenu.c @@ -46,12 +46,9 @@ remember_current_folder(GtkFileChooser *chooser) if (folder != NULL) { if (strlen(folder) >= MAX_FILENAME_LENGTH) { /* Non-critical error */ - g_print("current folder name too long for buffer\n"); + log_warn("current folder name too long for buffer"); } else { -#if defined(DEBUG) - g_print("current folder = %s\n", folder); -#endif - + log_info("current folder = %s", folder); strncpy(previous_folder, folder, MAX_FILENAME_LENGTH); } @@ -66,9 +63,7 @@ FileOpenEvent(GtkObject *object, gpointer data) char *dir; char *cwd = NULL; -#if defined(DEBUG) - g_print("FileOpenEvent()\n"); -#endif + log_info("FileOpenEvent()"); /* Create a new file selection widget. */ file_dialog = gtk_file_chooser_dialog_new( @@ -97,9 +92,7 @@ FileOpenEvent(GtkObject *object, gpointer data) GTK_FILE_CHOOSER(file_dialog)); if (selected_file != NULL) { -#if defined(DEBUG) - g_print("emugtk_File = %s\n", selected_file); -#endif + log_info("emugtk_File = %s", selected_file); remember_current_folder(GTK_FILE_CHOOSER(file_dialog)); @@ -114,10 +107,6 @@ FileOpenEvent(GtkObject *object, gpointer data) static void FileQuitEvent(gchar *string) { -#if defined(DEBUG) - g_print("%s\n", string); -#endif - gtk_main_quit(); } diff --git a/src/memwin.c b/src/memwin.c index a7ecdc7..5f9170c 100644 --- a/src/memwin.c +++ b/src/memwin.c @@ -148,9 +148,7 @@ memwin_DumpD(char *MemAddress) unsigned int Address; GtkListStore *store; -#ifdef EMU8051_DEBUG - printf("memwin_DumpD, address = %s\n", MemAddress); -#endif + log_info("memwin_DumpD, address = %s", MemAddress); if (strlen(MemAddress) != 0) { if (STREQ(MemAddress, "PC")) diff --git a/src/pgmwin.c b/src/pgmwin.c index 3a54091..e4f9b46 100644 --- a/src/pgmwin.c +++ b/src/pgmwin.c @@ -107,9 +107,7 @@ pgmwin_sel_changed_event(GtkWidget *widget, GdkEvent *event, gpointer data) GtkTreeModel *model; GtkTreeIter iter; -#ifdef EMU8051_DEBUG - printf("pgmwin_sel_changed_event()\n"); -#endif + log_debug("pgmwin_sel_changed_event()"); /* This will only work in single or browse selection mode! */ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pgmlist)); @@ -123,18 +121,14 @@ pgmwin_sel_changed_event(GtkWidget *widget, GdkEvent *event, gpointer data) /* Convert hex address in ASCII to integer. */ sscanf(str_addr, "%x", &val); -#ifdef EMU8051_DEBUG - printf(" row address is: $%04X\n", val); -#endif + log_debug(" row address is: $%04X", val); ToggleBreakpoint(val); pgmwin_Disasm(); g_free(str_addr); } else { -#ifdef EMU8051_DEBUG - printf(" no row selected.\n"); -#endif + log_debug(" no row selected"); } return FALSE; -- 2.20.1