From 03fb088594b278301e373b1cbd5a439ce1e6bf1e Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Thu, 11 Apr 2019 19:38:29 -0400 Subject: [PATCH] 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 177e52f..2a3e07e 100644 --- a/src/config.c +++ b/src/config.c @@ -58,7 +58,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; @@ -3223,9 +3222,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; cfg_printf("%s\n\n", menuptr[0].str); 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 0625684..db92142 100644 --- a/src/scc_socket_driver.c +++ b/src/scc_socket_driver.c @@ -224,7 +224,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 70e18d3..16f0ed9 100644 --- a/src/sim65816.c +++ b/src/sim65816.c @@ -904,7 +904,6 @@ int gsplusmain(int argc, char **argv) { iwm_shut(); fixed_memory_ptrs_shut(); load_roms_shut_memory(); - clear_fatal_logs(); #if HAVE_RAWNET if (g_ethernet_enabled) { @@ -1084,8 +1083,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 81a417a..f6004dc 100644 --- a/src/win_console.c +++ b/src/win_console.c @@ -63,6 +63,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; @@ -337,10 +338,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); #if 0 // Enable non-blocking, character-at-a-time console I/O. 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; }