Simplify handling warning function

This commit is contained in:
Kp 2018-12-30 00:43:58 +00:00
parent 82f2f17c66
commit b08dac2971
5 changed files with 13 additions and 12 deletions

View file

@ -45,8 +45,10 @@ namespace dcx {
void Warning_puts(const char *str) __attribute_nonnull();
void Warning(const char *fmt,...) __attribute_format_printf(1, 2); //print out warning message to user
#define Warning(F,...) dxx_call_printf_checked(Warning,Warning_puts,(),(F),##__VA_ARGS__)
#if DXX_USE_EDITOR
void set_warn_func(void (*f)(const char *s));//specifies the function to call with warning messages
void clear_warn_func();//say this function no longer valid
#endif
__noreturn
__attribute_nonnull()
void Error_puts(const char *file, unsigned line, const char *func, const char *str);

View file

@ -16,11 +16,11 @@
namespace dcx {
#if defined(WIN32) || defined(__APPLE__) || defined(__MACH__)
// Display a warning in a messagebox
extern void msgbox_warning(const char *message);
// Display an error in a messagebox
#if defined(WIN32) || defined(__APPLE__) || defined(__MACH__)
extern void msgbox_error(const char *message);
#else
#define msgbox_error(M) (static_cast<void>(M))

View file

@ -36,12 +36,12 @@ namespace dcx {
#define MAX_MSG_LEN 2048
//takes string in register, calls printf with string on stack
static void warn_printf(const char *s)
{
con_puts(CON_URGENT,s);
}
#if DXX_USE_EDITOR
static void (*warn_func)(const char *s)=warn_printf;
//provides a function to call with warning messages
@ -55,6 +55,9 @@ void clear_warn_func()
{
warn_func = warn_printf;
}
#else
constexpr auto warn_func = &warn_printf;
#endif
static void print_exit_message(const char *exit_message, size_t len)
{

View file

@ -900,7 +900,7 @@ static void close_editor()
{
// _MARK_("end of editor");//Nuked to compile -KRB
#if !defined(__linux__) && !defined(__OpenBSD__)
#if defined(WIN32) || defined(__APPLE__) || defined(__MACH__)
set_warn_func(msgbox_warning);
#else
clear_warn_func();

View file

@ -38,6 +38,7 @@ char copyright[] = "DESCENT COPYRIGHT (C) 1994,1995 PARALLAX SOFTWARE CORPORAT
char copyright[] = "DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPORATION";
#endif
#include "dxxsconf.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -63,7 +64,6 @@ char copyright[] = "DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPOR
#include "dxxerror.h"
#include "player.h"
#include "game.h"
#include "segment.h" //for Side_to_verts
#include "u_mem.h"
#include "screens.h"
#include "texmap.h"
@ -95,14 +95,11 @@ char copyright[] = "DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPOR
#endif
#include "event.h"
#include "rbaudio.h"
#if !defined(__linux__) && !defined(__OpenBSD__)
#include "messagebox.h"
#else
#if DXX_WORDS_NEED_ALIGNMENT
#include <sys/prctl.h>
#endif
#endif
#if DXX_USE_EDITOR
#include "messagebox.h"
#include "editor/editor.h"
#include "editor/kdefs.h"
#include "ui.h"
@ -111,8 +108,6 @@ char copyright[] = "DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPOR
#if DXX_USE_UDP
#include "net_udp.h"
#endif
#include "dxxsconf.h"
#include "dsx-ns.h"
#include "compiler-begin.h"
@ -715,16 +710,17 @@ static int main(int argc, char *argv[])
int main(int argc, char *argv[])
{
mem_init();
#if defined(__linux__) || defined(__OpenBSD__)
#if DXX_WORDS_NEED_ALIGNMENT
prctl(PR_SET_UNALIGN, PR_UNALIGN_NOPRINT, 0, 0, 0);
#endif
#else
#if defined(WIN32) || defined(__APPLE__) || defined(__MACH__)
#if DXX_USE_EDITOR
set_warn_func(msgbox_warning);
#endif
#ifdef WIN32
void d_set_exception_handler();
d_set_exception_handler();
#endif
#endif
return dsx::main(argc, argv);
}