Move debug macros from main.h to new debug.h.
authorLaurent Monin <geeqie@norz.org>
Thu, 24 Apr 2008 08:53:39 +0000 (08:53 +0000)
committerLaurent Monin <geeqie@norz.org>
Thu, 24 Apr 2008 08:53:39 +0000 (08:53 +0000)
Make debug_level static to debug.c and add utility functions
to manipulate it.
Add #include "debug.h" where needed.

35 files changed:
src/Makefile.am
src/bar_info.c
src/cache.c
src/cache_maint.c
src/collect-io.c
src/collect-table.c
src/collect.c
src/color-man.c
src/debug.c [new file with mode: 0644]
src/debug.h [new file with mode: 0644]
src/dupe.c
src/exif-common.c
src/exiv2.cc
src/filelist.c
src/format_raw.c
src/fullscreen.c
src/globals.c
src/image-load.c
src/image.c
src/layout.c
src/layout_image.c
src/main.c
src/main.h
src/pan-calendar.c
src/pan-view.c
src/pixbuf-renderer.c
src/preferences.c
src/print.c
src/remote.c
src/secure_save.c
src/thumb.c
src/thumb_standard.c
src/utilops.c
src/view_file_icon.c
src/view_file_list.c

index 0dc9c39..be3a34b 100644 (file)
@@ -91,6 +91,8 @@ geeqie_SOURCES = \
        color-man.h     \
        compat.c        \
        compat.h        \
+       debug.c         \
+       debug.h         \
        dnd.c           \
        dnd.h           \
        dupe.c          \
index b97f2f3..f9c9e25 100644 (file)
@@ -17,6 +17,7 @@
 #include "bar_info.h"
 
 #include "cache.h"
+#include "debug.h"
 #include "filelist.h"
 #include "info.h"
 #include "secure_save.h"
index 1f93e52..e7a4fe6 100644 (file)
@@ -13,6 +13,7 @@
 #include "main.h"
 #include "cache.h"
 
+#include "debug.h"
 #include "md5-util.h"
 #include "ui_fileops.h"
 
index 1c10006..c2b75c2 100644 (file)
@@ -14,6 +14,7 @@
 #include "cache_maint.h"
 
 #include "cache.h"
+#include "debug.h"
 #include "filelist.h"
 #include "thumb.h"
 #include "thumb_standard.h"
index 2705213..376f86e 100644 (file)
@@ -15,6 +15,7 @@
 #include "collect-io.h"
 
 #include "collect.h"
+#include "debug.h"
 #include "filelist.h"
 #include "layout_util.h"
 #include "rcfile.h"
index e27c0a8..1451e30 100644 (file)
@@ -17,6 +17,7 @@
 #include "cellrenderericon.h"
 #include "collect-dlg.h"
 #include "collect-io.h"
+#include "debug.h"
 #include "dnd.h"
 #include "dupe.h"
 #include "editors.h"
index bfaa8f3..595b5fb 100644 (file)
@@ -17,6 +17,7 @@
 #include "collect-dlg.h"
 #include "collect-io.h"
 #include "collect-table.h"
+#include "debug.h"
 #include "editors.h"
 #include "filelist.h"
 #include "img-view.h"
index 1b69150..967eddd 100644 (file)
@@ -14,6 +14,7 @@
 #include "main.h"
 #include "color-man.h"
 
+#include "debug.h"
 #include "image.h"
 #include "ui_fileops.h"
 
diff --git a/src/debug.c b/src/debug.c
new file mode 100644 (file)
index 0000000..a12cc30
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Geeqie
+ * Copyright (C) 2008 The Geeqie Team
+ *
+ * Authors: Vladimir Nadvornik, Laurent Monin
+ *
+ * This software is released under the GNU General Public License (GNU GPL).
+ * Please read the included file COPYING for more information.
+ * This software comes with no warranty of any kind, use at your own risk!
+ */
+
+#include "main.h"
+#include "debug.h"
+
+#ifdef DEBUG
+
+static gint debug_level = DEBUG_LEVEL_MIN;
+
+
+gint get_debug_level(void)
+{
+       return debug_level;
+}
+
+void set_debug_level(gint new_level)
+{
+       debug_level = CLAMP(new_level, DEBUG_LEVEL_MIN, DEBUG_LEVEL_MAX);       
+}
+
+void debug_level_add(gint delta)
+{
+       set_debug_level(debug_level + delta);
+}
+
+gint required_debug_level(gint level)
+{
+       return (debug_level >= level);
+}
+
+#endif
diff --git a/src/debug.h b/src/debug.h
new file mode 100644 (file)
index 0000000..d5aae8b
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Geeqie
+ * Copyright (C) 2008 The Geeqie Team
+ *
+ * Authors: Vladimir Nadvornik, Laurent Monin
+ *
+ * This software is released under the GNU General Public License (GNU GPL).
+ * Please read the included file COPYING for more information.
+ * This software comes with no warranty of any kind, use at your own risk!
+ */
+
+#ifndef DEBUG_H
+#define DEBUG_H
+
+#if 1 /* set to 0 to disable compilation of debugging code and related options */
+# ifndef DEBUG
+# define DEBUG 1
+# endif
+#endif
+
+#ifdef DEBUG
+
+#define DEBUG_LEVEL_MIN 0
+#define DEBUG_LEVEL_MAX 4
+
+gint get_debug_level(void);
+void set_debug_level(gint new_level);
+void debug_level_add(gint delta);
+gint required_debug_level(gint level);
+
+#define DEBUG_N(n, ...) do \
+                               { \
+                               gint debug_level = get_debug_level(); \
+                               if (debug_level >= (n))         \
+                                       {               \
+                                       if (debug_level != 1) printf("%s:%d: ", __FILE__, __LINE__); \
+                                       printf(__VA_ARGS__); \
+                                       putchar('\n'); \
+                                       } \
+                               } while (0)
+#else
+
+#define get_debug_level() (0)
+#define set_debug_level(new_level) do { } while(0)
+#define debug_level_add(delta) do { } while(0)
+#define required_debug_level(level) (0)
+#define DEBUG_N(n, ...)  do { } while(0)
+
+#endif
+
+#define DEBUG_0(...) DEBUG_N(0, __VA_ARGS__)
+#define DEBUG_1(...) DEBUG_N(1, __VA_ARGS__)
+#define DEBUG_2(...) DEBUG_N(2, __VA_ARGS__)
+#define DEBUG_3(...) DEBUG_N(3, __VA_ARGS__)
+#define DEBUG_4(...) DEBUG_N(4, __VA_ARGS__)
+
+
+#endif /* DEBUG_H */
index e2b5c0d..07543dc 100644 (file)
@@ -17,6 +17,7 @@
 #include "cache.h"
 #include "collect.h"
 #include "collect-table.h"
+#include "debug.h"
 #include "dnd.h"
 #include "editors.h"
 #include "filelist.h"
@@ -1097,7 +1098,7 @@ static void dupe_match_rank(DupeWindow *dw)
 
        list = dupe_match_rank_sort(dw->list);
 
-       if (debug >= 2) dupe_match_print_list(list);
+       if (required_debug_level(2)) dupe_match_print_list(list);
 
        DEBUG_1("Similar items: %d", g_list_length(list));
        list = dupe_match_group_trim(list, dw);
@@ -1105,7 +1106,7 @@ static void dupe_match_rank(DupeWindow *dw)
 
        dupe_match_sort_groups(list);
 
-       if (debug) dupe_match_print_list(list);
+       if (required_debug_level(2)) dupe_match_print_list(list);
 
        list = dupe_match_rank_sort(list);
 
index efafc87..8889116 100644 (file)
@@ -35,6 +35,7 @@
 #include "main.h"
 #include "exif.h"
 
+#include "debug.h"
 #include "filelist.h"
 #include "format_raw.h"
 #include "ui_fileops.h"
index 8483579..8d4d3a5 100644 (file)
 
 extern "C" {
 #include <glib.h> 
+
 #include "main.h"
 #include "exif.h"
+
+#include "debug.h"
 #include "filelist.h"
 #include "ui_fileops.h"
-
 }
 
 struct _ExifData
index 750d34a..6610939 100644 (file)
@@ -15,6 +15,7 @@
 #include "filelist.h"
 
 #include "cache.h"
+#include "debug.h"
 #include "rcfile.h"
 #include "secure_save.h"
 #include "thumb_standard.h"
index fc62896..f88d7c7 100644 (file)
 #include "main.h"
 #include "format_raw.h"
 
+#include "debug.h"
 #include "format_canon.h"
 #include "format_fuji.h"
 #include "format_nikon.h"
 #include "format_olympus.h"
 
-#ifdef DEBUG
-/* so that debugging is honored */
-extern gint debug;
-#endif
 
 typedef struct _FormatRawEntry FormatRawEntry;
 struct _FormatRawEntry {
index 86a5c03..395ee74 100644 (file)
@@ -14,6 +14,7 @@
 #include "main.h"
 #include "fullscreen.h"
 
+#include "debug.h"
 #include "image.h"
 #include "ui_fileops.h"
 #include "ui_menu.h"
index d5a97ac..7901cd2 100644 (file)
 
 #include "main.h"
 
-#ifdef DEBUG
-gint debug = FALSE;
-#endif
-
 
 ConfOptions *init_options(ConfOptions *options)
 {
index e5647d5..87b3a64 100644 (file)
 
 #include "main.h"
 #include "image-load.h"
-#include "filelist.h"
 
+#include "debug.h"
 #include "exif.h"
+#include "filelist.h"
 #include "ui_fileops.h"
 
 #include <fcntl.h>
index ffe5fce..3287a3c 100644 (file)
 #include "image.h"
 
 
-#include "image-load.h"
 #include "collect.h"
 #include "color-man.h"
+#include "debug.h"
 #include "exif.h"
 #include "histogram.h"
+#include "image-load.h"
 #include "image-overlay.h"
 #include "layout.h"
 #include "layout_image.h"
index 6c4c63c..9cde656 100644 (file)
 #include "main.h"
 #include "layout.h"
 
-#include "image.h"
 #include "color-man.h"
+#include "debug.h"
+#include "histogram.h"
+#include "image.h"
 #include "image-overlay.h"
 #include "layout_config.h"
 #include "layout_image.h"
@@ -31,7 +33,6 @@
 #include "ui_menu.h"
 #include "ui_misc.h"
 #include "ui_tabcomp.h"
-#include "histogram.h"
 
 
 #define MAINWINDOW_DEF_WIDTH 700
index 71c7b39..d1681af 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "collect.h"
 #include "dnd.h"
+#include "debug.h"
 #include "editors.h"
 #include "filelist.h"
 #include "fullscreen.h"
index 607f739..ee20132 100644 (file)
@@ -16,6 +16,7 @@
 #include "cache.h"
 #include "collect.h"
 #include "collect-io.h"
+#include "debug.h"
 #include "dnd.h"
 #include "editors.h"
 #include "filelist.h"
@@ -745,7 +746,7 @@ static void remote_control(const gchar *arg_exec, GList *remote_list, const gcha
                        }
 
                if (blank || cmd_list || path) g_string_append(command, " --blank");
-               if (debug) g_string_append(command, " --debug");
+               if (get_debug_level()) g_string_append(command, " --debug");
 
                g_string_append(command, " &");
                system(command->str);
@@ -1151,18 +1152,18 @@ static void parse_command_line_for_debug_option(int argc, char *argv[])
 
                                /* we now increment the debug state for verbosity */
                                if (cmd_line_len == len)
-                                       debug++;
+                                       debug_level_add(1);
                                else if (cmd_line[len] == '=' && g_ascii_isdigit(cmd_line[len+1]))
                                        {
                                        gint n = atoi(cmd_line + len + 1);
                                        if (n < 0) n = 1;
-                                       debug += n;
+                                       debug_level_add(n);
                                        }
                                }
                        }
                }
 
-       DEBUG_1("debugging output enabled (level %d)", debug);
+       DEBUG_1("debugging output enabled (level %d)", get_debug_level());
 #endif
 }
 
index 254c9f0..e5626c0 100644 (file)
                                "%fAperture%|%fShutterSpeed%|%fISOSpeedRating%|%fFocalLength%|%fExposureBias%\n" \
                                "%fCamera%|%fFlash%" \
 
-#if 1 /* set to 0 to disable debugging code and related options */
-# ifndef DEBUG
-# define DEBUG 1
-# endif
-#endif
-#ifndef DEBUG
-# define debug 0
-#endif
-
-#ifdef DEBUG
-#define DEBUG_N(n, ...) do \
-                               { \
-                               if (debug >= (n))       \
-                                       {               \
-                                       if (debug != 1) printf("%s:%d: ", __FILE__, __LINE__); \
-                                       printf(__VA_ARGS__); \
-                                       putchar('\n'); \
-                                       } \
-                               } while (0)
-#else
-#define DEBUG_N(n, ...)  do { } while(0)
-#endif
-
-#define DEBUG_0(...) DEBUG_N(0, __VA_ARGS__)
-#define DEBUG_1(...) DEBUG_N(1, __VA_ARGS__)
-#define DEBUG_2(...) DEBUG_N(2, __VA_ARGS__)
-#define DEBUG_3(...) DEBUG_N(3, __VA_ARGS__)
-#define DEBUG_4(...) DEBUG_N(4, __VA_ARGS__)
 
 #include "typedefs.h"
 
@@ -152,11 +124,6 @@ ConfOptions *options;
 
 
 
-#ifdef DEBUG
-extern gint debug;
-#endif
-
-
 
 /*
  *----------------------------------------------------------------------------
index b6f315f..dec9e59 100644 (file)
@@ -14,6 +14,8 @@
 #include "main.h"
 #include "pan-types.h"
 
+#include "debug.h"
+
 #include <math.h>
 
 
index cd975b1..97eaa8e 100644 (file)
 #include "main.h"
 #include "pan-view.h"
 
-#include "pan-types.h"
 #include "bar_exif.h"
 #include "dnd.h"
+#include "debug.h"
 #include "editors.h"
 #include "exif.h"
 #include "fullscreen.h"
 #include "img-view.h"
 #include "info.h"
 #include "menu.h"
+#include "pan-types.h"
 #include "thumb.h"
 #include "utilops.h"
 #include "ui_bookmark.h"
index 9b6abc8..c81f570 100644 (file)
@@ -12,7 +12,9 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <math.h>
+
 #include "pixbuf-renderer.h"
 #include "intl.h"
 
  */
 #define GQ_BUILD 1
 
-
 #ifdef GQ_BUILD
-       #include "pixbuf_util.h"
+#include "main.h"
+#include "pixbuf_util.h"
 
-       /* for debug */
-       #include "main.h"
+#include "debug.h"
 #endif
 
 
index 1d67e1d..d84581e 100644 (file)
@@ -15,6 +15,7 @@
 #include "preferences.h"
 
 #include "cache_maint.h"
+#include "debug.h"
 #include "editors.h"
 #include "filelist.h"
 #include "fullscreen.h"
@@ -278,7 +279,7 @@ static void config_window_apply(void)
                }
 
 #ifdef DEBUG
-       debug = debug_c;
+       set_debug_level(debug_c);
 #endif
 
 #ifdef HAVE_LCMS
@@ -1513,7 +1514,7 @@ static void config_tab_advanced(GtkWidget *notebook)
        group = pref_group_new(vbox, FALSE, _("Debugging"), GTK_ORIENTATION_VERTICAL);
 
        pref_spin_new_int(group, _("Debug level:"), NULL,
-                         0, 9, 1, debug, &debug_c);
+                         DEBUG_LEVEL_MIN, DEBUG_LEVEL_MAX, 1, get_debug_level(), &debug_c);
 #endif
 }
 
index 9dc490d..6be0665 100644 (file)
@@ -14,6 +14,7 @@
 #include "main.h"
 #include "print.h"
 
+#include "debug.h"
 #include "filelist.h"
 #include "image.h"
 #include "image-load.h"
index 0729ea7..198e3d3 100644 (file)
@@ -14,6 +14,7 @@
 #include "main.h"
 #include "remote.h"
 
+#include "debug.h"
 
 #include <sys/types.h>
 #include <sys/socket.h>
index fa8768f..64cc6bc 100644 (file)
@@ -16,6 +16,8 @@
 #include "main.h"
 #include "secure_save.h"
 
+#include "debug.h"
+
 /* ABOUT SECURE SAVE */
 /* This code was borrowed from the ELinks project (http://elinks.cz)
  * It was originally written by me (Laurent Monin aka Zas) and heavily
index 94f3015..9f6ad03 100644 (file)
@@ -15,6 +15,7 @@
 #include "thumb.h"
 
 #include "cache.h"
+#include "debug.h"
 #include "image-load.h"
 #include "filelist.h"
 #include "pixbuf_util.h"
index e4caf2c..4f48860 100644 (file)
@@ -15,6 +15,7 @@
 #include "thumb_standard.h"
 
 #include "cache.h"     /* for cache_ensure_dir_exists */
+#include "debug.h"
 #include "image-load.h"
 #include "md5-util.h"
 #include "pixbuf_util.h"
index bbb9c02..52225ff 100644 (file)
@@ -18,6 +18,7 @@
 #include "cache.h"
 #include "cache_maint.h"
 #include "collect.h"
+#include "debug.h"
 #include "dupe.h"
 #include "filelist.h"
 #include "image.h"
index 59bedc3..3d334fc 100644 (file)
@@ -17,6 +17,7 @@
 #include "collect.h"
 #include "collect-io.h"
 #include "collect-table.h"
+#include "debug.h"
 #include "dnd.h"
 #include "editors.h"
 #include "img-view.h"
index 931855b..71e7b37 100644 (file)
@@ -14,6 +14,7 @@
 #include "view_file_list.h"
 
 #include "cache_maint.h"
+#include "debug.h"
 #include "dnd.h"
 #include "editors.h"
 #include "img-view.h"