From 308363c47ad7809356e1c7e3c2583b85ddf1ddf0 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Mon, 8 Apr 2019 23:56:59 -0400 Subject: [PATCH 1/3] move fatal_printf logging to glog.c file with other logging that does the same thing. --- src/glog.c | 49 +++++++++++++++++++++++++++-- src/glog.h | 4 +++ src/protos.h | 4 --- src/scc_socket_driver.c | 2 ++ src/sim65816.c | 70 ----------------------------------------- 5 files changed, 53 insertions(+), 76 deletions(-) diff --git a/src/glog.c b/src/glog.c index 55f7f01..856fca6 100644 --- a/src/glog.c +++ b/src/glog.c @@ -4,12 +4,20 @@ See COPYRIGHT.txt for Copyright information See LICENSE.txt for license (GPL v2) */ -#include -#include #include +#include +#include +#include +#include #include "glog.h" + +#define MAX_FATAL_LOGS 20 + +int g_fatal_log = 0; +char *g_fatal_log_strs[MAX_FATAL_LOGS]; + int glog(const char *s) { time_t timer; char buffer[26]; @@ -45,3 +53,40 @@ int glogf(const char *fmt, ...) { fputc('\n', stdout); return 0; } + + +int fatal_printf(const char *fmt, ...) { + static char buffer[4096]; + va_list ap; + int ret; + + va_start(ap, fmt); + + if(g_fatal_log < 0) { + g_fatal_log = 0; + } + + ret = vsnprintf(buffer, sizeof(buffer), fmt, ap); + + glog(buffer); + + if (g_fatal_log < MAX_FATAL_LOGS) { + g_fatal_log_strs[g_fatal_log++] = strdup(buffer); + } + + + va_end(ap); + return ret; +} + + + +void clear_fatal_logs() { + int i; + + for(i = 0; i < g_fatal_log; i++) { + free(g_fatal_log_strs[i]); + g_fatal_log_strs[i] = 0; + } + g_fatal_log = 0; +} \ No newline at end of file diff --git a/src/glog.h b/src/glog.h index db005c3..479403b 100644 --- a/src/glog.h +++ b/src/glog.h @@ -3,6 +3,10 @@ extern "C" { #endif int glog(const char *s); int glogf(const char *s, ...); + + int fatal_printf(const char *fmt, ...); + void clear_fatal_logs(void); + #ifdef __cplusplus } #endif diff --git a/src/protos.h b/src/protos.h index 23932ff..cfb569f 100644 --- a/src/protos.h +++ b/src/protos.h @@ -403,10 +403,6 @@ void do_wdm(word32 arg); void do_wai(void); void do_stp(void); void size_fail(int val, word32 v1, word32 v2); -int fatal_printf(const char *fmt, ...); -int gsport_vprintf(const char *fmt, va_list ap); -void must_write(int fd, char *bufptr, int len); -void clear_fatal_logs(void); char *gsplus_malloc_str(char *in_str); diff --git a/src/scc_socket_driver.c b/src/scc_socket_driver.c index bf43bfd..ce5c4d3 100644 --- a/src/scc_socket_driver.c +++ b/src/scc_socket_driver.c @@ -9,6 +9,8 @@ #include "defc.h" #include "scc.h" +#include "glog.h" + #include #include #ifndef UNDER_CE //OG diff --git a/src/sim65816.c b/src/sim65816.c index 56e2a2e..2650897 100644 --- a/src/sim65816.c +++ b/src/sim65816.c @@ -196,11 +196,7 @@ int g_engine_doc_int = 0; int g_testing = 0; -#define MAX_FATAL_LOGS 20 -int g_debug_file_fd = -1; -int g_fatal_log = -1; -char *g_fatal_log_strs[MAX_FATAL_LOGS]; word32 stop_run_at; @@ -289,9 +285,6 @@ void sim65816_initglobals() { g_testing = 0; - g_debug_file_fd = -1; - g_fatal_log = -1; - g_25sec_cntr = 0; g_1sec_cntr = 0; @@ -2571,70 +2564,7 @@ void size_fail(int val, word32 v1, word32 v2) { halt_printf("Size failure, val: %08x, %08x %08x\n", val, v1, v2); } -int gsplus_vprintf(const char *fmt, va_list ap) { - char *bufptr, *buf2ptr; - int len; - int ret; - bufptr = (char*)malloc(4096); // OG Added Cast - ret = vsnprintf(bufptr, 4090, fmt, ap); - - // OG Display warning - printf("Warning:%s",bufptr); - - len = strlen(bufptr); - if(g_fatal_log >= 0 && g_fatal_log < MAX_FATAL_LOGS) { - buf2ptr = (char*)malloc(len+1); // OG Added Cast - memcpy(buf2ptr, bufptr, len+1); - g_fatal_log_strs[g_fatal_log++] = buf2ptr; - } - must_write(1, bufptr, len); - if(g_debug_file_fd >= 0) { - must_write(g_debug_file_fd, bufptr, len); - } - free(bufptr); - - return ret; -} - - -int fatal_printf(const char *fmt, ...) { - va_list ap; - int ret; - - va_start(ap, fmt); - - if(g_fatal_log < 0) { - g_fatal_log = 0; - } - ret = gsplus_vprintf(fmt, ap); - va_end(ap); - - return ret; -} - -void must_write(int fd, char *bufptr, int len) { - int ret; - while(len > 0) { - ret = write(fd, bufptr, len); - if(ret >= 0) { - len -= ret; - bufptr += ret; - } else if(errno != EAGAIN && errno != EINTR) { - return; // just get out - } - } -} - -void clear_fatal_logs() { - int i; - - for(i = 0; i < g_fatal_log; i++) { - free(g_fatal_log_strs[i]); - g_fatal_log_strs[i] = 0; - } - g_fatal_log = -1; -} char *gsplus_malloc_str(char *in_str) { char *str; From f842678e433e0e2ffb7bc5ad5918295b0b30596e Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Tue, 9 Apr 2019 13:00:22 -0400 Subject: [PATCH 2/3] fatal_printf - show an alert immediately. win32 - actually show the alert. --- src/glog.c | 5 ++++- src/win_console.c | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/glog.c b/src/glog.c index 856fca6..4a66fcf 100644 --- a/src/glog.c +++ b/src/glog.c @@ -12,6 +12,7 @@ #include "glog.h" +extern int x_show_alert(int fatal, const char *str); #define MAX_FATAL_LOGS 20 @@ -70,10 +71,12 @@ int fatal_printf(const char *fmt, ...) { glog(buffer); + x_show_alert(1, buffer); + /* if (g_fatal_log < MAX_FATAL_LOGS) { g_fatal_log_strs[g_fatal_log++] = strdup(buffer); } - + */ va_end(ap); return ret; diff --git a/src/win_console.c b/src/win_console.c index 983e6a6..59aa04d 100644 --- a/src/win_console.c +++ b/src/win_console.c @@ -55,7 +55,11 @@ void x_dialog_create_gsport_conf(const char *str) { config_write_config_gsplus_file(); } -int x_show_alert(int is_fatal, const char *str) { +int x_show_alert(int is_fatal, const char *str) { + + if (str && *str) { + MessageBox(NULL, str, "GS+", is_fatal ? MB_ICONERROR : MB_ICONWARNING); + } return 0; } From 1a06196ae76bd39699ee306b5c1f745eba5194b9 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Thu, 11 Apr 2019 19:38:29 -0400 Subject: [PATCH 3/3] eliminate the g_fatal_log array since fatal_printf() shows warning messages immediately. --- src/config.c | 4 --- src/fbdriver.c | 1 - src/glog.c | 26 ---------------- src/glog.h | 1 - src/macdriver_console.c | 68 ++++++++--------------------------------- src/scc_socket_driver.c | 1 - src/sim65816.c | 3 -- src/win_console.c | 5 +-- src/xdriver.c | 1 - 9 files changed, 13 insertions(+), 97 deletions(-) diff --git a/src/config.c b/src/config.c index fd0f9e5..700eb93 100644 --- a/src/config.c +++ b/src/config.c @@ -44,7 +44,6 @@ extern byte *g_rom_fc_ff_ptr; extern byte *g_rom_cards_ptr; extern double g_cur_dcycs; extern int g_rom_version; -extern int g_fatal_log; extern word32 g_adb_repeat_vbl; @@ -3183,9 +3182,6 @@ void config_control_panel() { g_cfg_slotdrive = -1; g_cfg_select_partition = -1; while(g_config_control_panel & !(halt_sim&HALT_WANTTOQUIT)) { - if(g_fatal_log > 0) { - x_show_alert(0, 0); - } cfg_home(); line = 1; max_line = 1; diff --git a/src/fbdriver.c b/src/fbdriver.c index b32abe1..a269ecf 100644 --- a/src/fbdriver.c +++ b/src/fbdriver.c @@ -421,7 +421,6 @@ void x_dialog_create_gsport_conf(const char *str) { int x_show_alert(int is_fatal, const char *str) { // Not implemented yet adb_all_keys_up(); - clear_fatal_logs(); return 0; } void x_toggle_status_lines(void) { diff --git a/src/glog.c b/src/glog.c index 4a66fcf..07bc368 100644 --- a/src/glog.c +++ b/src/glog.c @@ -14,11 +14,6 @@ extern int x_show_alert(int fatal, const char *str); -#define MAX_FATAL_LOGS 20 - -int g_fatal_log = 0; -char *g_fatal_log_strs[MAX_FATAL_LOGS]; - int glog(const char *s) { time_t timer; char buffer[26]; @@ -63,33 +58,12 @@ int fatal_printf(const char *fmt, ...) { va_start(ap, fmt); - if(g_fatal_log < 0) { - g_fatal_log = 0; - } - ret = vsnprintf(buffer, sizeof(buffer), fmt, ap); glog(buffer); x_show_alert(1, buffer); - /* - if (g_fatal_log < MAX_FATAL_LOGS) { - g_fatal_log_strs[g_fatal_log++] = strdup(buffer); - } - */ va_end(ap); return ret; } - - - -void clear_fatal_logs() { - int i; - - for(i = 0; i < g_fatal_log; i++) { - free(g_fatal_log_strs[i]); - g_fatal_log_strs[i] = 0; - } - g_fatal_log = 0; -} \ No newline at end of file diff --git a/src/glog.h b/src/glog.h index 479403b..4571297 100644 --- a/src/glog.h +++ b/src/glog.h @@ -5,7 +5,6 @@ extern "C" { int glogf(const char *s, ...); int fatal_printf(const char *fmt, ...); - void clear_fatal_logs(void); #ifdef __cplusplus } diff --git a/src/macdriver_console.c b/src/macdriver_console.c index 8e02f43..8b1ca03 100644 --- a/src/macdriver_console.c +++ b/src/macdriver_console.c @@ -79,19 +79,15 @@ extern int g_screen_mdepth; Ptr g_mac_fullscreen_state = 0; Rect g_main_window_saved_rect; -extern char *g_fatal_log_strs[]; -extern int g_fatal_log; - int x_show_alert(int is_fatal, const char *str) { DialogRef alert; DialogItemIndex out_item_hit; - CFStringRef cfstrref, cfstrref2; + CFStringRef cfstrref; CFStringRef okstrref; AlertStdCFStringAlertParamRec alert_param; OSStatus osstat; - char *bufptr, *buf2ptr; - int sum, len; - int i; + + if (!str || !*str) return 0; /* The dialog eats all events--including key-up events */ /* Call adb_all_keys_up() to prevent annoying key-repeat problems */ @@ -100,36 +96,14 @@ int x_show_alert(int is_fatal, const char *str) { /* auto-repeat will repeat the key, and the dialog re-appears...*/ adb_all_keys_up(); - sum = 20; - for(i = 0; i < g_fatal_log; i++) { - sum += strlen(g_fatal_log_strs[i]); - } - bufptr = (char*)malloc(sum); - buf2ptr = bufptr; - for(i = 0; i < g_fatal_log; i++) { - len = strlen(g_fatal_log_strs[i]); - len = MIN(len, sum); - len = MAX(len, 0); - memcpy(bufptr, g_fatal_log_strs[i], MIN(len, sum)); - bufptr += len; - bufptr[0] = 0; - sum = sum - len; - } - cfstrref = CFStringCreateWithCString(NULL, buf2ptr, + cfstrref = CFStringCreateWithCString(NULL, str, kCFStringEncodingMacRoman); - printf("buf2ptr: :%s:\n", buf2ptr); osstat = GetStandardAlertDefaultParams(&alert_param, kStdCFStringAlertVersionOne); - if(str) { - // Provide an extra option--create a file - cfstrref2 = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, - CFSTR("Create ./%s"), str); - alert_param.otherText = cfstrref2; - } okstrref = CFSTR("Click OK to continue"); if(is_fatal) { okstrref = CFSTR("Click OK to exit GSplus"); @@ -138,12 +112,9 @@ int x_show_alert(int is_fatal, const char *str) { &alert_param, &alert); out_item_hit = -1; RunStandardAlert(alert, NULL, &out_item_hit); - printf("out_item_hit: %d\n", out_item_hit); - free(buf2ptr); - clear_fatal_logs(); /* free the fatal_log string memory */ + CFRelease(cfstrref); return (out_item_hit >= 3); - } @@ -159,28 +130,18 @@ pascal OSStatus quit_event_handler(EventHandlerCallRef call_ref, EventRef event, } void show_simple_alert(char *str1, char *str2, char *str3, int num) { - char buf[256]; + char buf[4096]; - g_fatal_log_strs[0] = gsplus_malloc_str(str1); - g_fatal_log_strs[1] = gsplus_malloc_str(str2); - g_fatal_log_strs[2] = gsplus_malloc_str(str3); - g_fatal_log = 3; - if(num != 0) { - snprintf(buf, 250, ": %d", num); - g_fatal_log_strs[g_fatal_log++] = gsplus_malloc_str(buf); + if (num) { + snprintf(buffer, sizeof(buffer), "%s%s%s: %d", str1, str2, str3, num); + } else { + snprintf(buffer, sizeof(buffer), "%s%s%s", str1, str2, str3); } - x_show_alert(0, 0); + x_show_alert(0, buf); } void x_dialog_create_gsport_conf(const char *str) { - char *path; - char tmp_buf[512]; - int ret; - - ret = x_show_alert(1, str); - if(ret) { - config_write_config_gsplus_file(); - } + config_write_config_gsplus_file(); } @@ -698,11 +659,6 @@ CantGetNibRef: void xdriver_end() { - printf("xdriver_end\n"); - - if(g_fatal_log >= 0) { - x_show_alert(1, 0); - } } diff --git a/src/scc_socket_driver.c b/src/scc_socket_driver.c index ce5c4d3..42f955c 100644 --- a/src/scc_socket_driver.c +++ b/src/scc_socket_driver.c @@ -226,7 +226,6 @@ void scc_socket_open_outgoing(int port, double dcycs) { #endif scc_socket_close_handle(sockfd); scc_socket_close(port, 1, dcycs); - x_show_alert(0, 0); return; } memcpy(&sa_in.sin_addr.s_addr, hostentptr->h_addr, diff --git a/src/sim65816.c b/src/sim65816.c index 2650897..479cfbf 100644 --- a/src/sim65816.c +++ b/src/sim65816.c @@ -1011,7 +1011,6 @@ int gsplusmain(int argc, char **argv) { iwm_shut(); fixed_memory_ptrs_shut(); load_roms_shut_memory(); - clear_fatal_logs(); // OG Not needed anymore : the emulator will quit gently //my_exit(0); @@ -1184,8 +1183,6 @@ void setup_gsplus_file(char *outname, int maxlen, int ok_if_missing, int can_cre x_dialog_create_gsport_conf(*name_ptr); can_create_file = 0; - // But clear out the fatal_printfs first - clear_fatal_logs(); setup_gsplus_file(outname, maxlen, ok_if_missing, can_create_file, name_ptr); // It's one-level of recursion--it cannot loop since we // clear can_create_file. diff --git a/src/win_console.c b/src/win_console.c index 59aa04d..8ae578a 100644 --- a/src/win_console.c +++ b/src/win_console.c @@ -58,6 +58,7 @@ void x_dialog_create_gsport_conf(const char *str) { int x_show_alert(int is_fatal, const char *str) { if (str && *str) { + adb_all_keys_up(); MessageBox(NULL, str, "GS+", is_fatal ? MB_ICONERROR : MB_ICONWARNING); } return 0; @@ -143,10 +144,6 @@ int main(int argc, char **argv) { size.cx, size.cy, NULL, NULL, GetModuleHandle(NULL), NULL); - printf("g_hwnd_main = %p, height = %d\n", hwnd, size.cx); - GetWindowRect(hwnd, &rect); - printf("...rect is: %ld, %ld, %ld, %ld\n", rect.left, rect.top, - rect.right, rect.bottom); // Enable non-blocking, character-at-a-time console I/O. // win_nonblock_read_stdin() expects this behavior. diff --git a/src/xdriver.c b/src/xdriver.c index de03155..0590315 100644 --- a/src/xdriver.c +++ b/src/xdriver.c @@ -254,7 +254,6 @@ int x_show_alert(int is_fatal, const char *str) { /* Not implemented yet */ adb_all_keys_up(); - clear_fatal_logs(); return 0; }