diff --git a/lib/msg_log.cpp b/lib/msg_log.cpp index d10ac4e7b0..9954150071 100644 --- a/lib/msg_log.cpp +++ b/lib/msg_log.cpp @@ -175,6 +175,36 @@ void MSG_LOG::printf_file( va_end(va); } +void MSG_LOG::cond_printf(int conditional,int kind, const char* format, ...) { + if (conditional) { + va_list va; + va_start(va, format); + vprintf(kind, format, va); + va_end(va); + } +} + +void MSG_LOG::cond_printf_multiline( + int conditional, int kind, const char* str, const char* prefix_format, ... +) { + if (conditional) { + va_list va; + va_start(va, prefix_format); + vprintf_multiline(kind, str, prefix_format, va); + va_end(va); + } +} + +void MSG_LOG::cond_printf_file( + int conditional, int kind, const char* filename, const char* prefix_format, ... +) { + if (conditional) { + va_list va; + va_start(va, prefix_format); + vprintf_file(kind, filename, prefix_format, va); + va_end(va); + } +} // These SCOPE_MSG_LOG functions are utility functions that call their // corresponding MSG_LOG functions with the same name, passing the KIND that // was specified on creation of the SCOPE_MSG_LOG object. @@ -204,3 +234,33 @@ void SCOPE_MSG_LOG::printf_file( va_end(va); } +void SCOPE_MSG_LOG::cond_printf(int conditional,const char* format, ...) { + if (conditional) { + va_list va; + va_start(va, format); + messages.vprintf(kind, format, va); + va_end(va); + } +} + +void SCOPE_MSG_LOG::cond_printf_multiline( + int conditional,const char* str, const char* prefix_format, ... +) { + if (conditional) { + va_list va; + va_start(va, prefix_format); + messages.vprintf_multiline(kind, str, prefix_format, va); + va_end(va); + } +} + +void SCOPE_MSG_LOG::cond_printf_file( + int conditional,const char* filename, const char* prefix_format, ... +) { + if (conditional) { + va_list va; + va_start(va, prefix_format); + messages.vprintf_file(kind, filename, prefix_format, va); + va_end(va); + } +} diff --git a/lib/msg_log.h b/lib/msg_log.h index c112d25768..5de85093c1 100644 --- a/lib/msg_log.h +++ b/lib/msg_log.h @@ -62,6 +62,11 @@ public: void vprintf_multiline(int kind, const char* str, const char* prefix_format, va_list va); void vprintf_file(int kind, const char* filename, const char* prefix_format, va_list va); + void cond_printf(int conditional,int kind, const char* format, ...) __attribute__ ((format (printf, 4, 5))); + void cond_printf_multiline(int conditional,int kind, const char* str, const char* prefix_format, ...) __attribute__ ((format (printf, 5, 6))); + void cond_printf_file(int conditional, int kind, const char* str, const char* prefix_format, ...) __attribute__ ((format (printf, 5, 6))); + + protected: virtual const char* v_format_kind(int kind) const = 0; @@ -88,6 +93,10 @@ public: void printf(const char* format, ...) __attribute__ ((format (printf, 2, 3))); void printf_multiline(const char* str, const char* prefix_format, ...) __attribute__ ((format (printf, 3, 4))); void printf_file(const char* filename, const char* prefix_format, ...) __attribute__ ((format (printf, 3, 4))); + + void cond_printf(int conditional, const char* format, ...) __attribute__ ((format (printf, 3, 4))); + void cond_printf_multiline(int conditional, const char* str, const char* prefix_format, ...) __attribute__ ((format (printf, 4, 5))); + void cond_printf_file(int conditional, const char* str, const char* prefix_format, ...) __attribute__ ((format (printf, 4, 5))); }; #if _MSC_VER >= 1300