From 9f7b1073ad4e1cc8f17e83fb13b85e4a20d5320e Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 5 Nov 2013 13:42:27 +0300 Subject: add libxml2 error logging. --- src/utils/xml.cpp | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'src/utils/xml.cpp') diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index 5f691fd68..a81e1b4ef 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -34,9 +34,39 @@ #include "debug.h" -static void xmlNullLogger(void *ctx A_UNUSED, const char *msg A_UNUSED, ...) +static void xmlErrorLogger(void *ctx A_UNUSED, const char *msg A_UNUSED, ...) +#ifdef __GNUC__ +#ifdef __OpenBSD__ + __attribute__((__format__(printf, 2, 3))) +#else + __attribute__((__format__(gnu_printf, 2, 3))) +#endif +#endif +; + +static void xmlErrorLogger(void *ctx A_UNUSED, const char *msg A_UNUSED, ...) { - // Does nothing, that's the whole point of it + unsigned size = 1024; + const unsigned msgSize = strlen(msg); + if (msgSize * 3 > size) + size = static_cast(msgSize * 3); + + char* buf = new char[size + 1]; + va_list ap; + + // Use a temporary buffer to fill in the variables + va_start(ap, msg); + vsnprintf(buf, size, msg, ap); + buf[size] = 0; + va_end(ap); + + if (logger) + logger->log(buf); + else + puts(buf); + + // Delete temporary buffer + delete [] buf; } namespace XML @@ -213,7 +243,7 @@ namespace XML LIBXML_TEST_VERSION; // Suppress libxml2 error messages - xmlSetGenericErrorFunc(nullptr, &xmlNullLogger); + xmlSetGenericErrorFunc(nullptr, &xmlErrorLogger); } // Shutdown libxml -- cgit v1.2.3-70-g09d2 From c8639374e4ca2c50440b0885e902a0b428836e40 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 7 Nov 2013 14:31:29 +0300 Subject: use safer logger function in xml logger. --- src/utils/xml.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/utils/xml.cpp') diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index a81e1b4ef..60b4505c5 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -61,7 +61,7 @@ static void xmlErrorLogger(void *ctx A_UNUSED, const char *msg A_UNUSED, ...) va_end(ap); if (logger) - logger->log(buf); + logger->log1(buf); else puts(buf); -- cgit v1.2.3-70-g09d2 From 5564df0ae67373da8ffb148fde95fdd9142c870b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 8 Nov 2013 14:52:18 +0300 Subject: fix code style. --- src/graphicsmanager.cpp | 10 +++++++--- src/gui/windows/editdialog.cpp | 2 -- src/net/netconsts.h | 7 ++++--- src/utils/files.cpp | 6 +++--- src/utils/xml.cpp | 2 +- 5 files changed, 15 insertions(+), 12 deletions(-) (limited to 'src/utils/xml.cpp') diff --git a/src/graphicsmanager.cpp b/src/graphicsmanager.cpp index c6c36d15d..ace00663e 100644 --- a/src/graphicsmanager.cpp +++ b/src/graphicsmanager.cpp @@ -365,9 +365,13 @@ void GraphicsManager::setVideoMode() int width = res[0]; int height = res[1]; #elif defined __native_client__ - const SDL_VideoInfo* info = SDL_GetVideoInfo(); - int width = info->current_w; - int height = info->current_h; +#ifdef USE_SDL2 + // not implimented +#else + const SDL_VideoInfo* info = SDL_GetVideoInfo(); + int width = info->current_w; + int height = info->current_h; +#endif #else int width = config.getIntValue("screenwidth"); int height = config.getIntValue("screenheight"); diff --git a/src/gui/windows/editdialog.cpp b/src/gui/windows/editdialog.cpp index 05f55ad67..a4711784e 100644 --- a/src/gui/windows/editdialog.cpp +++ b/src/gui/windows/editdialog.cpp @@ -26,8 +26,6 @@ #include "utils/gettext.h" -#include - #include "debug.h" EditDialog::EditDialog(const std::string &title, const std::string &msg, diff --git a/src/net/netconsts.h b/src/net/netconsts.h index 38f84ebaa..0af23b8a9 100644 --- a/src/net/netconsts.h +++ b/src/net/netconsts.h @@ -18,9 +18,10 @@ * along with this program. If not, see . */ -#ifndef NET_DEFAULTS_H -#define NET_DEFAULTS_H +#ifndef NET_NETCONSTS_H +#define NET_NETCONSTS_H +#include static const uint16_t DEFAULT_PORT = 6901; -#endif // NET_DEFAULTS_H +#endif // NET_NETCONSTS_H diff --git a/src/utils/files.cpp b/src/utils/files.cpp index bfaed472a..15b667ba8 100644 --- a/src/utils/files.cpp +++ b/src/utils/files.cpp @@ -20,12 +20,12 @@ #include "utils/files.h" -#include "logger.h" - +#if defined(ANDROID) || defined(__native_client__) #include "resources/resourcemanager.h" +#include "utils/physfstools.h" +#endif #include "utils/mkdir.h" -#include "utils/physfstools.h" #include "localconsts.h" diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index 60b4505c5..b87418079 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -44,7 +44,7 @@ static void xmlErrorLogger(void *ctx A_UNUSED, const char *msg A_UNUSED, ...) #endif ; -static void xmlErrorLogger(void *ctx A_UNUSED, const char *msg A_UNUSED, ...) +static void xmlErrorLogger(void *ctx A_UNUSED, const char *msg, ...) { unsigned size = 1024; const unsigned msgSize = strlen(msg); -- cgit v1.2.3-70-g09d2