From 1d990840262af1b54d40c386dd92bc5d372d7fc3 Mon Sep 17 00:00:00 2001 From: Kp Date: Fri, 9 Oct 2015 02:46:11 +0000 Subject: [PATCH] Use UserError when main hog is missing Error traps to the debugger and then aborts, which is not appropriate for a user setup error. --- common/include/dxxerror.h | 12 +++++++++++- common/misc/error.cpp | 5 +++++ similar/main/inferno.cpp | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/common/include/dxxerror.h b/common/include/dxxerror.h index b5dcb52c1..4fa37381c 100644 --- a/common/include/dxxerror.h +++ b/common/include/dxxerror.h @@ -25,6 +25,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #pragma once +#include #include #include "dxxsconf.h" #include @@ -48,7 +49,16 @@ void Error_puts(const char *func, unsigned line, const char *str) __noreturn __a #define Error_puts(F) Error_puts(__func__, __LINE__,F) void Error(const char *func, unsigned line, const char *fmt,...) __noreturn __attribute_format_printf(3, 4); //exit with error code=1, print message #define Error(F,...) dxx_call_printf_checked(Error,(Error_puts),(__func__, __LINE__),(F),##__VA_ARGS__) -void UserError_puts(const char *str) __noreturn __attribute_nonnull(); + +__noreturn +void UserError_puts(const char *str, std::size_t); + +template +__noreturn +static inline void UserError_puts(const char (&str)[len]) +{ + UserError_puts(str, len - 1); +} void UserError(const char *fmt, ...) __noreturn __attribute_format_printf(1, 2); #define UserError(F,...) dxx_call_printf_checked(UserError,(UserError_puts),(),(F),##__VA_ARGS__) #define Assert assert diff --git a/common/misc/error.cpp b/common/misc/error.cpp index 4ad29d4c3..6755bc0a9 100644 --- a/common/misc/error.cpp +++ b/common/misc/error.cpp @@ -86,6 +86,11 @@ void (Error_puts)(const char *func, const unsigned line, const char *str) abort_print_exit_message(exit_message, len); } +void (UserError_puts)(const char *str, std::size_t len) +{ + graceful_print_exit_message(str, len); +} + //terminates with error code 1, printing message void (Error)(const char *func, const unsigned line, const char *fmt,...) { diff --git a/similar/main/inferno.cpp b/similar/main/inferno.cpp index b6efc5068..168e0443a 100644 --- a/similar/main/inferno.cpp +++ b/similar/main/inferno.cpp @@ -398,7 +398,7 @@ int main(int argc, char *argv[]) "\tIn a subdirectory called 'Data'\n" \ DXX_HOGFILE_APPLICATION_BUNDLE \ "Or use the -hogdir option to specify an alternate location." - Error(DXX_MISSING_HOGFILE_ERROR_TEXT); + UserError(DXX_MISSING_HOGFILE_ERROR_TEXT); } #if defined(DXX_BUILD_DESCENT_I)