[evince] debug: Simplify code



commit 9237127ab69558ff1a20c569517d4170d068c16a
Author: Christian Persch <chpe gnome org>
Date:   Sun Oct 27 22:39:49 2013 +0100

    debug: Simplify code
    
    Use g_parse_debug_string() instead of a handwritten variant, and use debug
    flags instead of extra env variables.

 libdocument/ev-debug.c |   71 +++++++++++------------------------------------
 1 files changed, 17 insertions(+), 54 deletions(-)
---
diff --git a/libdocument/ev-debug.c b/libdocument/ev-debug.c
index 475f612..920007d 100644
--- a/libdocument/ev-debug.c
+++ b/libdocument/ev-debug.c
@@ -48,63 +48,26 @@ static EvDebugBorders ev_debug_borders = EV_DEBUG_BORDER_NONE;
 
 static GHashTable *timers = NULL;
 
-static gboolean
-ev_debug_parse_show_borders (const gchar *show_debug_borders)
-{
-        gchar **items;
-        guint   i;
-
-        if (!show_debug_borders)
-                return FALSE;
-
-        items = g_strsplit (show_debug_borders, ",", -1);
-        if (!items)
-                return FALSE;
-
-        for (i = 0; items[i]; i++) {
-                if (g_strcmp0 (items[i], "all") == 0) {
-                        ev_debug_borders = EV_DEBUG_BORDER_ALL;
-                        break;
-                }
-
-                if (g_strcmp0 (items[i], "none") == 0) {
-                        ev_debug_borders = EV_DEBUG_BORDER_NONE;
-                        break;
-                }
-
-                if (strcmp (items[i], "chars") == 0)
-                        ev_debug_borders |= EV_DEBUG_BORDER_CHARS;
-                if (strcmp (items[i], "links") == 0)
-                        ev_debug_borders |= EV_DEBUG_BORDER_LINKS;
-                if (strcmp (items[i], "forms") == 0)
-                        ev_debug_borders |= EV_DEBUG_BORDER_FORMS;
-                if (strcmp (items[i], "annots") == 0)
-                        ev_debug_borders |= EV_DEBUG_BORDER_ANNOTS;
-                if (strcmp (items[i], "images") == 0)
-                        ev_debug_borders |= EV_DEBUG_BORDER_IMAGES;
-                if (strcmp (items[i], "selections") == 0)
-                        ev_debug_borders |= EV_DEBUG_BORDER_SELECTIONS;
-        }
-
-        g_strfreev (items);
-
-        return ev_debug_borders != EV_DEBUG_BORDER_NONE;
-}
-
 static void
 debug_init (void)
 {
-       if (g_getenv ("EV_DEBUG") != NULL) {
-               /* enable all debugging */
-               ev_debug = ~EV_NO_DEBUG;
-               return;
-       }
-
-       if (g_getenv ("EV_DEBUG_JOBS") != NULL)
-               ev_debug |= EV_DEBUG_JOBS;
-
-        if (ev_debug_parse_show_borders (g_getenv ("EV_DEBUG_SHOW_BORDERS")))
-                ev_debug |= EV_DEBUG_SHOW_BORDERS;
+        const GDebugKey keys[] = {
+                { "jobs",    EV_DEBUG_JOBS         },
+                { "borders", EV_DEBUG_SHOW_BORDERS }
+        };
+        const GDebugKey border_keys[] = {
+                { "chars",      EV_DEBUG_BORDER_CHARS      },
+                { "links",      EV_DEBUG_BORDER_LINKS      },
+                { "forms",      EV_DEBUG_BORDER_FORMS      },
+                { "annots",     EV_DEBUG_BORDER_ANNOTS     },
+                { "images",     EV_DEBUG_BORDER_IMAGES     },
+                { "selections", EV_DEBUG_BORDER_SELECTIONS }
+        };
+
+        ev_debug = g_parse_debug_string (g_getenv ("EV_DEBUG"), keys, G_N_ELEMENTS (keys));
+        if (ev_debug & EV_DEBUG_SHOW_BORDERS)
+                ev_debug_borders = g_parse_debug_string (g_getenv ("EV_DEBUG_SHOW_BORDERS"),
+                                                         border_keys, G_N_ELEMENTS (border_keys));
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]