From a26eac91ef2ce79135811d6824d4bfdd68031898 Mon Sep 17 00:00:00 2001 From: Broxzier Date: Wed, 4 Jan 2017 23:51:50 +0100 Subject: [PATCH] Use typedef for diagnostic levels, small refactor --- src/openrct2/cmdline/RootCommands.cpp | 2 +- src/openrct2/diagnostic.c | 8 +++---- src/openrct2/diagnostic.h | 30 +++++++++------------------ 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/openrct2/cmdline/RootCommands.cpp b/src/openrct2/cmdline/RootCommands.cpp index 9872b91f71..44f02193ac 100644 --- a/src/openrct2/cmdline/RootCommands.cpp +++ b/src/openrct2/cmdline/RootCommands.cpp @@ -163,7 +163,7 @@ exitcode_t CommandLine::HandleCommandDefault() { if (_verbose) { - _log_levels[DIAGNOSTIC_LEVEL_VERBOSE] = 1; + _log_levels[DIAGNOSTIC_LEVEL_VERBOSE] = true; PrintLaunchInformation(); } diff --git a/src/openrct2/diagnostic.c b/src/openrct2/diagnostic.c index ebb34b8029..10e9a8466a 100644 --- a/src/openrct2/diagnostic.c +++ b/src/openrct2/diagnostic.c @@ -19,8 +19,8 @@ #include #include "diagnostic.h" -sint32 _log_levels[DIAGNOSTIC_LEVEL_COUNT] = { 1, 1, 1, 0, 1 }; -sint32 _log_location_enabled = 1; +static bool _log_location_enabled = true; +bool _log_levels[DIAGNOSTIC_LEVEL_COUNT] = { true, true, true, false, true }; const char * _level_strings[] = { "FATAL", @@ -30,7 +30,7 @@ const char * _level_strings[] = { "INFO" }; -void diagnostic_log(sint32 diagnosticLevel, const char *format, ...) +void diagnostic_log(DiagnosticLevel diagnosticLevel, const char *format, ...) { FILE *stream; va_list args; @@ -52,7 +52,7 @@ void diagnostic_log(sint32 diagnosticLevel, const char *format, ...) fprintf(stream, "\n"); } -void diagnostic_log_with_location(sint32 diagnosticLevel, const char *file, const char *function, sint32 line, const char *format, ...) +void diagnostic_log_with_location(DiagnosticLevel diagnosticLevel, const char *file, const char *function, sint32 line, const char *format, ...) { FILE *stream; va_list args; diff --git a/src/openrct2/diagnostic.h b/src/openrct2/diagnostic.h index 0368b6236e..0df941c6b9 100644 --- a/src/openrct2/diagnostic.h +++ b/src/openrct2/diagnostic.h @@ -17,14 +17,16 @@ #ifndef _DIAGNOSTIC_H_ #define _DIAGNOSTIC_H_ -enum { +#include "common.h" + +typedef enum { DIAGNOSTIC_LEVEL_FATAL, DIAGNOSTIC_LEVEL_ERROR, DIAGNOSTIC_LEVEL_WARNING, DIAGNOSTIC_LEVEL_VERBOSE, DIAGNOSTIC_LEVEL_INFORMATION, DIAGNOSTIC_LEVEL_COUNT -}; +} DiagnosticLevel; /** * Compile-time debug levels. @@ -48,8 +50,6 @@ enum { * only checking whether the define is present or not. */ -#include "common.h" - #if defined(DEBUG) #if DEBUG > 0 #define DEBUG_LEVEL_1 1 @@ -75,32 +75,24 @@ enum { #define DEBUG_LEVEL_1 0 #endif // defined(DEBUG) -extern sint32 _log_levels[DIAGNOSTIC_LEVEL_COUNT]; +extern bool _log_levels[DIAGNOSTIC_LEVEL_COUNT]; #ifdef __cplusplus extern "C" { #endif // __cplusplus -void diagnostic_log(sint32 diagnosticLevel, const char *format, ...); -void diagnostic_log_with_location(sint32 diagnosticLevel, const char *file, const char *function, sint32 line, const char *format, ...); +void diagnostic_log(DiagnosticLevel diagnosticLevel, const char *format, ...); +void diagnostic_log_with_location(DiagnosticLevel diagnosticLevel, const char *file, const char *function, sint32 line, const char *format, ...); #ifdef __cplusplus } #endif // __cplusplus #ifdef _MSC_VER - -#define diagnostic_log_macro(level, format, ...) diagnostic_log_with_location(level, __FILE__, __FUNCTION__, __LINE__, format, __VA_ARGS__) - -#define log_fatal(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_FATAL, format, __VA_ARGS__) -#define log_error(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_ERROR, format, __VA_ARGS__) -#define log_warning(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_WARNING, format, __VA_ARGS__) -#define log_verbose(format, ...) diagnostic_log(DIAGNOSTIC_LEVEL_VERBOSE, format, __VA_ARGS__) -#define log_info(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_INFORMATION, format, __VA_ARGS__) - +#define diagnostic_log_macro(level, format, ...) diagnostic_log_with_location(level, __FILE__, __FUNCTION__, __LINE__, format, ## __VA_ARGS__) #else - -#define diagnostic_log_macro(level, format, ...) diagnostic_log_with_location(level, __FILE__, __func__, __LINE__, format, ## __VA_ARGS__) + #define diagnostic_log_macro(level, format, ...) diagnostic_log_with_location(level, __FILE__, __func__, __LINE__, format, ## __VA_ARGS__) +#endif // _MSC_VER #define log_fatal(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_FATAL, format, ## __VA_ARGS__) #define log_error(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_ERROR, format, ## __VA_ARGS__) @@ -109,5 +101,3 @@ void diagnostic_log_with_location(sint32 diagnosticLevel, const char *file, cons #define log_info(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_INFORMATION, format, ## __VA_ARGS__) #endif - -#endif