mirror of
https://github.com/digarok/gsplus.git
synced 2024-06-08 10:45:07 +00:00
move fatal_printf logging to glog.c file with other logging that does the same thing.
This commit is contained in:
parent
e23f4494ca
commit
886a1a591a
49
src/glog.c
49
src/glog.c
|
@ -4,12 +4,20 @@
|
||||||
See COPYRIGHT.txt for Copyright information
|
See COPYRIGHT.txt for Copyright information
|
||||||
See LICENSE.txt for license (GPL v2)
|
See LICENSE.txt for license (GPL v2)
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "glog.h"
|
#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) {
|
int glog(const char *s) {
|
||||||
time_t timer;
|
time_t timer;
|
||||||
char buffer[26];
|
char buffer[26];
|
||||||
|
@ -45,3 +53,40 @@ int glogf(const char *fmt, ...) {
|
||||||
fputc('\n', stdout);
|
fputc('\n', stdout);
|
||||||
return 0;
|
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;
|
||||||
|
}
|
|
@ -3,6 +3,10 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
int glog(const char *s);
|
int glog(const char *s);
|
||||||
int glogf(const char *s, ...);
|
int glogf(const char *s, ...);
|
||||||
|
|
||||||
|
int fatal_printf(const char *fmt, ...);
|
||||||
|
void clear_fatal_logs(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -403,10 +403,6 @@ void do_wdm(word32 arg);
|
||||||
void do_wai(void);
|
void do_wai(void);
|
||||||
void do_stp(void);
|
void do_stp(void);
|
||||||
void size_fail(int val, word32 v1, word32 v2);
|
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);
|
char *gsplus_malloc_str(char *in_str);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
#include "defc.h"
|
#include "defc.h"
|
||||||
#include "scc.h"
|
#include "scc.h"
|
||||||
|
#include "glog.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
|
@ -209,11 +209,7 @@ int g_engine_doc_int = 0;
|
||||||
|
|
||||||
int g_testing = 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;
|
word32 stop_run_at;
|
||||||
|
|
||||||
|
@ -302,9 +298,6 @@ void sim65816_initglobals() {
|
||||||
|
|
||||||
g_testing = 0;
|
g_testing = 0;
|
||||||
|
|
||||||
g_debug_file_fd = -1;
|
|
||||||
g_fatal_log = -1;
|
|
||||||
|
|
||||||
g_25sec_cntr = 0;
|
g_25sec_cntr = 0;
|
||||||
g_1sec_cntr = 0;
|
g_1sec_cntr = 0;
|
||||||
|
|
||||||
|
@ -2485,70 +2478,7 @@ void size_fail(int val, word32 v1, word32 v2) {
|
||||||
halt_printf("Size failure, val: %08x, %08x %08x\n", val, v1, 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 *gsplus_malloc_str(char *in_str) {
|
||||||
char *str;
|
char *str;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user