From 39ccae145aeb574da8ef83723f9f58a596bccdee Mon Sep 17 00:00:00 2001 From: Kevin Shanahan Date: Mon, 22 Apr 2013 11:40:17 +0930 Subject: [PATCH] qbsp: create an Error() function similar to the other tools Call it Error_() for now while I work on transitioning away from the arrays of global strings hidden away by error enums. Signed-off-by: Kevin Shanahan --- qbsp/qbsp.h | 2 ++ qbsp/util.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/qbsp/qbsp.h b/qbsp/qbsp.h index 9bc44ff1..37ad4708 100644 --- a/qbsp/qbsp.h +++ b/qbsp/qbsp.h @@ -683,6 +683,8 @@ extern void PrintMem(void); extern void Message(int MsgType, ...); extern void Error(int ErrType, ...) __attribute__((noreturn)); +extern void Error_(const char *error, ...) + __attribute__((format(printf,1,2),noreturn)); extern FILE *logfile; diff --git a/qbsp/util.c b/qbsp/util.c index 7b511fcb..77c99bc3 100644 --- a/qbsp/util.c +++ b/qbsp/util.c @@ -227,6 +227,24 @@ Error(int ErrType, ...) exit(1); } +void +Error_(const char *error, ...) +{ + va_list argptr; + char message[512]; + + va_start(argptr, error); + vsnprintf(message, sizeof(message), error, argptr); + va_end(argptr); + + fprintf(stderr, "\nERROR: %s\n\n", message); + if (logfile) { + fprintf(logfile, "\nERROR: %s\n\n", message); + fclose(logfile); + } + exit(1); +} + /* ================= Message