Merge pull request #73 from ksherlock/merge_logging

Merge duplicate logging
This commit is contained in:
Dagen Brock 2019-05-11 10:20:08 -05:00 committed by GitHub
commit 403cee6ca7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 47 additions and 147 deletions

View File

@ -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);

View File

@ -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) {

View File

@ -4,12 +4,16 @@
See COPYRIGHT.txt for Copyright information
See LICENSE.txt for license (GPL v2)
*/
#include <stdio.h>
#include <time.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "glog.h"
extern int x_show_alert(int fatal, const char *str);
int glog(const char *s) {
time_t timer;
char buffer[26];
@ -45,3 +49,21 @@ 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);
ret = vsnprintf(buffer, sizeof(buffer), fmt, ap);
glog(buffer);
x_show_alert(1, buffer);
va_end(ap);
return ret;
}

View File

@ -3,6 +3,9 @@ extern "C" {
#endif
int glog(const char *s);
int glogf(const char *s, ...);
int fatal_printf(const char *fmt, ...);
#ifdef __cplusplus
}
#endif

View File

@ -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);
}
}

View File

@ -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);

View File

@ -9,6 +9,8 @@
#include "defc.h"
#include "scc.h"
#include "glog.h"
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
@ -222,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,

View File

@ -209,11 +209,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;
@ -302,9 +298,6 @@ void sim65816_initglobals() {
g_testing = 0;
g_debug_file_fd = -1;
g_fatal_log = -1;
g_25sec_cntr = 0;
g_1sec_cntr = 0;
@ -911,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) {
@ -1091,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.
@ -2485,70 +2475,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;

View File

@ -60,7 +60,12 @@ 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) {
adb_all_keys_up();
MessageBox(NULL, str, "GS+", is_fatal ? MB_ICONERROR : MB_ICONWARNING);
}
return 0;
}
@ -333,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.

View File

@ -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;
}