Mercurial > geeqie
changeset 507:135570a8bd96
Move debug macros from main.h to new debug.h.
Make debug_level static to debug.c and add utility functions
to manipulate it.
Add #include "debug.h" where needed.
author | zas_ |
---|---|
date | Thu, 24 Apr 2008 08:53:39 +0000 |
parents | fc9c8a3e1a8b |
children | 011a6be611c8 |
files | 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 src/debug.h 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 |
diffstat | 35 files changed, 153 insertions(+), 61 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Makefile.am Thu Apr 24 00:15:03 2008 +0000 +++ b/src/Makefile.am Thu Apr 24 08:53:39 2008 +0000 @@ -91,6 +91,8 @@ color-man.h \ compat.c \ compat.h \ + debug.c \ + debug.h \ dnd.c \ dnd.h \ dupe.c \
--- a/src/bar_info.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/bar_info.c Thu Apr 24 08:53:39 2008 +0000 @@ -17,6 +17,7 @@ #include "bar_info.h" #include "cache.h" +#include "debug.h" #include "filelist.h" #include "info.h" #include "secure_save.h"
--- a/src/cache.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/cache.c Thu Apr 24 08:53:39 2008 +0000 @@ -13,6 +13,7 @@ #include "main.h" #include "cache.h" +#include "debug.h" #include "md5-util.h" #include "ui_fileops.h"
--- a/src/cache_maint.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/cache_maint.c Thu Apr 24 08:53:39 2008 +0000 @@ -14,6 +14,7 @@ #include "cache_maint.h" #include "cache.h" +#include "debug.h" #include "filelist.h" #include "thumb.h" #include "thumb_standard.h"
--- a/src/collect-io.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/collect-io.c Thu Apr 24 08:53:39 2008 +0000 @@ -15,6 +15,7 @@ #include "collect-io.h" #include "collect.h" +#include "debug.h" #include "filelist.h" #include "layout_util.h" #include "rcfile.h"
--- a/src/collect-table.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/collect-table.c Thu Apr 24 08:53:39 2008 +0000 @@ -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"
--- a/src/collect.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/collect.c Thu Apr 24 08:53:39 2008 +0000 @@ -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"
--- a/src/color-man.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/color-man.c Thu Apr 24 08:53:39 2008 +0000 @@ -14,6 +14,7 @@ #include "main.h" #include "color-man.h" +#include "debug.h" #include "image.h" #include "ui_fileops.h"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/debug.c Thu Apr 24 08:53:39 2008 +0000 @@ -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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/debug.h Thu Apr 24 08:53:39 2008 +0000 @@ -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 */
--- a/src/dupe.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/dupe.c Thu Apr 24 08:53:39 2008 +0000 @@ -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 @@ 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 @@ 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);
--- a/src/exif-common.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/exif-common.c Thu Apr 24 08:53:39 2008 +0000 @@ -35,6 +35,7 @@ #include "main.h" #include "exif.h" +#include "debug.h" #include "filelist.h" #include "format_raw.h" #include "ui_fileops.h"
--- a/src/exiv2.cc Thu Apr 24 00:15:03 2008 +0000 +++ b/src/exiv2.cc Thu Apr 24 08:53:39 2008 +0000 @@ -50,11 +50,13 @@ extern "C" { #include <glib.h> + #include "main.h" #include "exif.h" + +#include "debug.h" #include "filelist.h" #include "ui_fileops.h" - } struct _ExifData
--- a/src/filelist.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/filelist.c Thu Apr 24 08:53:39 2008 +0000 @@ -15,6 +15,7 @@ #include "filelist.h" #include "cache.h" +#include "debug.h" #include "rcfile.h" #include "secure_save.h" #include "thumb_standard.h"
--- a/src/format_raw.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/format_raw.c Thu Apr 24 08:53:39 2008 +0000 @@ -31,15 +31,12 @@ #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 {
--- a/src/fullscreen.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/fullscreen.c Thu Apr 24 08:53:39 2008 +0000 @@ -14,6 +14,7 @@ #include "main.h" #include "fullscreen.h" +#include "debug.h" #include "image.h" #include "ui_fileops.h" #include "ui_menu.h"
--- a/src/globals.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/globals.c Thu Apr 24 08:53:39 2008 +0000 @@ -13,10 +13,6 @@ #include "main.h" -#ifdef DEBUG -gint debug = FALSE; -#endif - ConfOptions *init_options(ConfOptions *options) {
--- a/src/image-load.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/image-load.c Thu Apr 24 08:53:39 2008 +0000 @@ -13,9 +13,10 @@ #include "main.h" #include "image-load.h" + +#include "debug.h" +#include "exif.h" #include "filelist.h" - -#include "exif.h" #include "ui_fileops.h" #include <fcntl.h>
--- a/src/image.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/image.c Thu Apr 24 08:53:39 2008 +0000 @@ -15,11 +15,12 @@ #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"
--- a/src/layout.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/layout.c Thu Apr 24 08:53:39 2008 +0000 @@ -13,8 +13,10 @@ #include "main.h" #include "layout.h" +#include "color-man.h" +#include "debug.h" +#include "histogram.h" #include "image.h" -#include "color-man.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
--- a/src/layout_image.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/layout_image.c Thu Apr 24 08:53:39 2008 +0000 @@ -15,6 +15,7 @@ #include "collect.h" #include "dnd.h" +#include "debug.h" #include "editors.h" #include "filelist.h" #include "fullscreen.h"
--- a/src/main.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/main.c Thu Apr 24 08:53:39 2008 +0000 @@ -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 @@ } 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 @@ /* 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 }
--- a/src/main.h Thu Apr 24 00:15:03 2008 +0000 +++ b/src/main.h Thu Apr 24 08:53:39 2008 +0000 @@ -110,34 +110,6 @@ "%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 @@ -#ifdef DEBUG -extern gint debug; -#endif - - /* *----------------------------------------------------------------------------
--- a/src/pan-calendar.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/pan-calendar.c Thu Apr 24 08:53:39 2008 +0000 @@ -14,6 +14,8 @@ #include "main.h" #include "pan-types.h" +#include "debug.h" + #include <math.h>
--- a/src/pan-view.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/pan-view.c Thu Apr 24 08:53:39 2008 +0000 @@ -14,15 +14,16 @@ #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"
--- a/src/pixbuf-renderer.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/pixbuf-renderer.c Thu Apr 24 08:53:39 2008 +0000 @@ -12,7 +12,9 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <math.h> + #include "pixbuf-renderer.h" #include "intl.h" @@ -25,12 +27,11 @@ */ #define GQ_BUILD 1 - #ifdef GQ_BUILD - #include "pixbuf_util.h" - - /* for debug */ - #include "main.h" +#include "main.h" +#include "pixbuf_util.h" + +#include "debug.h" #endif
--- a/src/preferences.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/preferences.c Thu Apr 24 08:53:39 2008 +0000 @@ -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 @@ } #ifdef DEBUG - debug = debug_c; + set_debug_level(debug_c); #endif #ifdef HAVE_LCMS @@ -1513,7 +1514,7 @@ 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 }
--- a/src/print.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/print.c Thu Apr 24 08:53:39 2008 +0000 @@ -14,6 +14,7 @@ #include "main.h" #include "print.h" +#include "debug.h" #include "filelist.h" #include "image.h" #include "image-load.h"
--- a/src/remote.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/remote.c Thu Apr 24 08:53:39 2008 +0000 @@ -14,6 +14,7 @@ #include "main.h" #include "remote.h" +#include "debug.h" #include <sys/types.h> #include <sys/socket.h>
--- a/src/secure_save.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/secure_save.c Thu Apr 24 08:53:39 2008 +0000 @@ -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
--- a/src/thumb.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/thumb.c Thu Apr 24 08:53:39 2008 +0000 @@ -15,6 +15,7 @@ #include "thumb.h" #include "cache.h" +#include "debug.h" #include "image-load.h" #include "filelist.h" #include "pixbuf_util.h"
--- a/src/thumb_standard.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/thumb_standard.c Thu Apr 24 08:53:39 2008 +0000 @@ -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"
--- a/src/utilops.c Thu Apr 24 00:15:03 2008 +0000 +++ b/src/utilops.c Thu Apr 24 08:53:39 2008 +0000 @@ -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"