Added plat_break() for raising breakpoints and warning() and log_warning() to raise visible non-fatal warnings to the user.

This commit is contained in:
OBattler
2025-03-22 00:49:20 +01:00
parent 6df6eae482
commit 63f106a0fd
6 changed files with 108 additions and 5 deletions

View File

@@ -440,6 +440,75 @@ fatal_ex(const char *fmt, va_list ap)
fflush(stdlog);
}
/* Log a warning error, and display a UI message without exiting. */
void
warning(const char *fmt, ...)
{
char temp[1024];
va_list ap;
char *sp;
va_start(ap, fmt);
if (stdlog == NULL) {
if (log_path[0] != '\0') {
stdlog = plat_fopen(log_path, "w");
if (stdlog == NULL)
stdlog = stdout;
} else
stdlog = stdout;
}
vsprintf(temp, fmt, ap);
fprintf(stdlog, "%s", temp);
fflush(stdlog);
va_end(ap);
/* Make sure the message does not have a trailing newline. */
if ((sp = strchr(temp, '\n')) != NULL)
*sp = '\0';
do_pause(2);
ui_msgbox(MBX_ERROR | MBX_ANSI, temp);
fflush(stdlog);
do_pause(0);
}
void
warning_ex(const char *fmt, va_list ap)
{
char temp[1024];
char *sp;
if (stdlog == NULL) {
if (log_path[0] != '\0') {
stdlog = plat_fopen(log_path, "w");
if (stdlog == NULL)
stdlog = stdout;
} else
stdlog = stdout;
}
vsprintf(temp, fmt, ap);
fprintf(stdlog, "%s", temp);
fflush(stdlog);
/* Make sure the message does not have a trailing newline. */
if ((sp = strchr(temp, '\n')) != NULL)
*sp = '\0';
do_pause(2);
ui_msgbox(MBX_ERROR | MBX_ANSI, temp);
fflush(stdlog);
do_pause(0);
}
#ifdef ENABLE_PC_LOG
int pc_do_log = ENABLE_PC_LOG;

View File

@@ -194,15 +194,12 @@ extern __thread int is_cpu_thread; /* Is this the CPU thread? */
#ifdef HAVE_STDARG_H
extern void pclog_ex(const char *fmt, va_list ap);
extern void fatal_ex(const char *fmt, va_list ap);
extern void warning_ex(const char *fmt, va_list ap);
#endif
extern void pclog_toggle_suppr(void);
#ifdef _MSC_VER
extern void pclog(const char *fmt, ...);
extern void fatal(const char *fmt, ...);
#else
extern void pclog(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
extern void fatal(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
#endif
extern void warning(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
extern void set_screen_size(int x, int y);
extern void set_screen_size_monitor(int x, int y, int monitor_index);
extern void reset_screen_size(void);

View File

@@ -36,6 +36,7 @@ extern void log_out(void *priv, const char *fmt, va_list);
extern void log_out_cyclic(void* priv, const char *fmt, va_list);
#endif /*RELEASE_BUILD*/
extern void log_fatal(void *priv, const char *fmt, ...);
extern void log_warning(void *priv, const char *fmt, ...);
extern void *log_open(const char *dev_name);
extern void *log_open_cyclic(const char *dev_name);
extern void log_close(void *priv);

View File

@@ -164,6 +164,7 @@ extern uint32_t plat_language_code(char *langcode);
extern void plat_language_code_r(uint32_t lcid, char *outbuf, int len);
extern void plat_get_cpu_string(char *outbuf, uint8_t len);
extern void plat_set_thread_name(void *thread, const char *name);
extern void plat_break(void);
/* Resource management. */
extern wchar_t *plat_get_string(int id);

View File

@@ -842,3 +842,13 @@ plat_set_thread_name(void *thread, const char *name)
# endif
#endif
}
void
plat_break(void)
{
#ifdef Q_OS_WINDOWS
DebugBreak();
#else
raise(SIGTRAP);
#endif
}

View File

@@ -294,6 +294,31 @@ log_fatal(void *priv, const char *fmt, ...)
exit(-1);
}
void
log_warning(void *priv, const char *fmt, ...)
{
log_t *log = (log_t *) priv;
char temp[1024];
char fmt2[1024];
va_list ap;
if (log == NULL)
return;
if (log->cyclic_buff != NULL) {
for (int i = 0; i < LOG_SIZE_BUFFER_CYCLIC_LINES; i++)
if (log->cyclic_buff[i] != NULL)
free(log->cyclic_buff[i]);
free(log->cyclic_buff);
}
va_start(ap, fmt);
log_copy(log, fmt2, fmt, 1024);
vsprintf(temp, fmt2, ap);
warning_ex(fmt2, ap);
va_end(ap);
}
static void *
log_open_common(const char *dev_name, const int cyclic)
{