diff src/debug.h @ 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
children b78a91d0779e
line wrap: on
line diff
--- /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 */