From 245c22f767841eefeaef42d22b43d4cdf039bbee Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Wed, 9 Nov 2011 23:32:41 +0100 Subject: [PATCH] app: port gimp-log to also work with latest GLib --- app/gimp-log.c | 81 +++++++++++++++++++++++++++++--------------------- app/gimp-log.h | 24 +++++++-------- 2 files changed, 59 insertions(+), 46 deletions(-) diff --git a/app/gimp-log.c b/app/gimp-log.c index 182b3c68a4..ca62184d91 100644 --- a/app/gimp-log.c +++ b/app/gimp-log.c @@ -23,6 +23,30 @@ #include "gimp-log.h" +static const GDebugKey log_keys[] = +{ + { "tool-events", GIMP_LOG_TOOL_EVENTS }, + { "tool-focus", GIMP_LOG_TOOL_FOCUS }, + { "dnd", GIMP_LOG_DND }, + { "help", GIMP_LOG_HELP }, + { "dialog-factory", GIMP_LOG_DIALOG_FACTORY }, + { "menus", GIMP_LOG_MENUS }, + { "save-dialog", GIMP_LOG_SAVE_DIALOG }, + { "image-scale", GIMP_LOG_IMAGE_SCALE }, + { "shadow-tiles", GIMP_LOG_SHADOW_TILES }, + { "scale", GIMP_LOG_SCALE }, + { "wm", GIMP_LOG_WM }, + { "floating-selection", GIMP_LOG_FLOATING_SELECTION }, + { "shm", GIMP_LOG_SHM }, + { "text-editing", GIMP_LOG_TEXT_EDITING }, + { "key-events", GIMP_LOG_KEY_EVENTS }, + { "auto-tab-style", GIMP_LOG_AUTO_TAB_STYLE }, + { "instances", GIMP_LOG_INSTANCES }, + { "rectangle-tool", GIMP_LOG_RECTANGLE_TOOL }, + { "brush-cache", GIMP_LOG_BRUSH_CACHE } +}; + + GimpLogFlags gimp_log_flags = 0; @@ -35,30 +59,10 @@ gimp_log_init (void) env_log_val = g_getenv ("GIMP_DEBUG"); if (env_log_val) - { - const GDebugKey log_keys[] = - { - { "tool-events", GIMP_LOG_TOOL_EVENTS }, - { "tool-focus", GIMP_LOG_TOOL_FOCUS }, - { "dnd", GIMP_LOG_DND }, - { "help", GIMP_LOG_HELP }, - { "dialog-factory", GIMP_LOG_DIALOG_FACTORY }, - { "menus", GIMP_LOG_MENUS }, - { "save-dialog", GIMP_LOG_SAVE_DIALOG }, - { "image-scale", GIMP_LOG_IMAGE_SCALE }, - { "shadow-tiles", GIMP_LOG_SHADOW_TILES }, - { "scale", GIMP_LOG_SCALE }, - { "wm", GIMP_LOG_WM }, - { "floating-selection", GIMP_LOG_FLOATING_SELECTION }, - { "shm", GIMP_LOG_SHM }, - { "text-editing", GIMP_LOG_TEXT_EDITING }, - { "key-events", GIMP_LOG_KEY_EVENTS }, - { "auto-tab-style", GIMP_LOG_AUTO_TAB_STYLE }, - { "instances", GIMP_LOG_INSTANCES }, - { "rectangle-tool", GIMP_LOG_RECTANGLE_TOOL }, - { "brush-cache", GIMP_LOG_BRUSH_CACHE } - }; + g_setenv ("G_MESSAGES_DEBUG", env_log_val, TRUE); + if (env_log_val) + { /* g_parse_debug_string() has special treatment of the string 'help', * but we want to use it for the GIMP_LOG_HELP domain */ @@ -75,27 +79,36 @@ gimp_log_init (void) } void -gimp_log (const gchar *function, - gint line, - const gchar *domain, - const gchar *format, +gimp_log (GimpLogFlags flags, + const gchar *function, + gint line, + const gchar *format, ...) { va_list args; va_start (args, format); - gimp_logv (function, line, domain, format, args); + gimp_logv (flags, function, line, format, args); va_end (args); } void -gimp_logv (const gchar *function, - gint line, - const gchar *domain, - const gchar *format, - va_list args) +gimp_logv (GimpLogFlags flags, + const gchar *function, + gint line, + const gchar *format, + va_list args) { - gchar *message; + const gchar *domain = "unknown"; + gchar *message; + gint i; + + for (i = 0; i < G_N_ELEMENTS (log_keys); i++) + if (log_keys[i].value == flags) + { + domain = log_keys[i].key; + break; + } if (format) message = g_strdup_vprintf (format, args); diff --git a/app/gimp-log.h b/app/gimp-log.h index 02565311b1..2cf022fa77 100644 --- a/app/gimp-log.h +++ b/app/gimp-log.h @@ -47,16 +47,16 @@ extern GimpLogFlags gimp_log_flags; void gimp_log_init (void); -void gimp_log (const gchar *function, - gint line, - const gchar *domain, - const gchar *format, +void gimp_log (GimpLogFlags flags, + const gchar *function, + gint line, + const gchar *format, ...) G_GNUC_PRINTF (4, 5); -void gimp_logv (const gchar *function, - gint line, - const gchar *domain, - const gchar *format, - va_list args); +void gimp_logv (GimpLogFlags flags, + const gchar *function, + gint line, + const gchar *format, + va_list args); #ifdef G_HAVE_ISO_VARARGS @@ -64,7 +64,7 @@ void gimp_logv (const gchar *function, #define GIMP_LOG(type, ...) \ G_STMT_START { \ if (gimp_log_flags & GIMP_LOG_##type) \ - gimp_log (G_STRFUNC, __LINE__, #type, __VA_ARGS__); \ + gimp_log (GIMP_LOG_##type, G_STRFUNC, __LINE__, __VA_ARGS__); \ } G_STMT_END #elif defined(G_HAVE_GNUC_VARARGS) @@ -72,7 +72,7 @@ void gimp_logv (const gchar *function, #define GIMP_LOG(type, format...) \ G_STMT_START { \ if (gimp_log_flags & GIMP_LOG_##type) \ - gimp_log (G_STRFUNC, __LINE__, #type, format); \ + gimp_log (GIMP_LOG_##type, G_STRFUNC, __LINE__, format); \ } G_STMT_END #else /* no varargs macros */ @@ -112,7 +112,7 @@ GIMP_LOG (GimpLogFlags flags, va_list args; va_start (args, format); if (gimp_log_flags & flags) - gimp_logv ("", 0, "", format, args); + gimp_logv (type, "", 0, format, args); va_end (args); }