[evolution-data-server/gnome-2-30] Allow debugging to be enabled with CAMEL_DEBUG environment variable



commit ae740ed87ef3508b65143efaef1ac2c09e9b9f02
Author: David Woodhouse <David Woodhouse intel com>
Date:   Sat Jun 19 10:51:22 2010 +0100

    Allow debugging to be enabled with CAMEL_DEBUG environment variable
    
    CAMEL_DEBUG=imapx will enable all debugging, or 'imapx:command',
    'imapx:token' etc. will enable certain types.
    
    Not entirely sure if 'debug' and 'extra' are the correct names for the
    old 'd()' and 'e()' debug output...
    (cherry picked from commit 22c8df8da28c4146a151a10efbb80cd5222923d7)

 camel/providers/imapx/camel-imapx-folder.c        |    3 +-
 camel/providers/imapx/camel-imapx-server.c        |    8 +++---
 camel/providers/imapx/camel-imapx-store-summary.c |    4 +-
 camel/providers/imapx/camel-imapx-stream.c        |    4 +-
 camel/providers/imapx/camel-imapx-utils.c         |   29 +++++++++++++++++++-
 camel/providers/imapx/camel-imapx-utils.h         |   13 +++++++++
 camel/providers/imapx/camel-imapx-view-summary.c  |    5 ++-
 7 files changed, 53 insertions(+), 13 deletions(-)
---
diff --git a/camel/providers/imapx/camel-imapx-folder.c b/camel/providers/imapx/camel-imapx-folder.c
index 75840f6..c627005 100644
--- a/camel/providers/imapx/camel-imapx-folder.c
+++ b/camel/providers/imapx/camel-imapx-folder.c
@@ -39,6 +39,7 @@
 #include  "camel/camel-string-utils.h"
 #include "camel-folder-search.h"
 
+#include "camel-imapx-utils.h"
 #include "camel-imapx-store.h"
 #include "camel-imapx-folder.h"
 #include "camel-imapx-summary.h"
@@ -50,7 +51,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#define d(x)
+#define d(x) camel_imapx_debug(debug, x)
 
 #define CF_CLASS(o) (CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(o)))
 static CamelObjectClass *parent_class;
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index ed54684..f5d5033 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -53,8 +53,8 @@
 #include "camel-imapx-store.h"
 #include "camel-imapx-summary.h"
 
-#define c(x)
-#define e(x) 
+#define c(x) camel_imapx_debug(command, x)
+#define e(x) camel_imapx_debug(extra, x)
 
 #define CFS_CLASS(x) ((CamelFolderSummaryClass *)((CamelObject *)x)->klass)
 
@@ -870,8 +870,8 @@ imapx_command_start_next(CamelIMAPXServer *is, CamelException *ex)
 
 	c(printf("** Starting next command\n"));
 	if (is->literal != NULL || is->select_pending != NULL) {
-		c(if (is->select_pending))
-			c(printf("* no, waiting for literal/pending select '%s'\n", is->select_pending->full_name));
+		c(if (is->select_pending)
+			  printf("* no, waiting for literal/pending select '%s'\n", is->select_pending->full_name));
 
 		/* TODO prolly start the store operations which do not require any folder to be selected */
 		return;
diff --git a/camel/providers/imapx/camel-imapx-store-summary.c b/camel/providers/imapx/camel-imapx-store-summary.c
index bc0854f..6ee84e7 100644
--- a/camel/providers/imapx/camel-imapx-store-summary.c
+++ b/camel/providers/imapx/camel-imapx-store-summary.c
@@ -36,8 +36,8 @@
 #include "camel-imapx-utils.h"
 #include "camel-imapx-store-summary.h"
 
-#define d(x)
-#define io(x)			/* io debug */
+#define d(x) camel_imapx_debug(debug, x)
+#define io(x) camel_imapx_debug(io, x)
 
 #define CAMEL_IMAPX_STORE_SUMMARY_VERSION_0 (0)
 
diff --git a/camel/providers/imapx/camel-imapx-stream.c b/camel/providers/imapx/camel-imapx-stream.c
index 9d5f8df..ac8cb64 100644
--- a/camel/providers/imapx/camel-imapx-stream.c
+++ b/camel/providers/imapx/camel-imapx-stream.c
@@ -37,8 +37,8 @@
 #include "camel-imapx-stream.h"
 #include "camel-imapx-exception.h"
 
-#define t(x) 
-#define io(x)
+#define t(x) camel_imapx_debug(token, x)
+#define io(x) camel_imapx_debug(io, x)
 
 static CamelObjectClass *parent_class = NULL;
 
diff --git a/camel/providers/imapx/camel-imapx-utils.c b/camel/providers/imapx/camel-imapx-utils.c
index e67cd4a..6b280c5 100644
--- a/camel/providers/imapx/camel-imapx-utils.c
+++ b/camel/providers/imapx/camel-imapx-utils.c
@@ -7,6 +7,7 @@
 #include <camel/camel-store.h>
 #include <camel/camel-utf8.h>
 #include <camel/camel-string-utils.h>
+#include <camel/camel-debug.h>
 
 #include "camel-imapx-folder.h"
 #include "camel-imapx-stream.h"
@@ -17,9 +18,32 @@
 #include "libedataserver/e-memory.h"
 
 /* high-level parser state */
-#define p(x)
+#define p(x) camel_imapx_debug(parse, x)
 /* debug */
-#define d(x)
+#define d(x) camel_imapx_debug(debug, x)
+
+gint camel_imapx_debug_flags;
+
+#define debug_set_flag(flag) do { \
+	if ((CAMEL_IMAPX_DEBUG_ALL & CAMEL_IMAPX_DEBUG_ ## flag) &&	\
+	    camel_debug("imapx:" #flag))				\
+		camel_imapx_debug_flags |= CAMEL_IMAPX_DEBUG_ ## flag;	\
+	} while (0)
+
+static void camel_imapx_set_debug_flags(void)
+{
+	if (camel_debug("imapx")) {
+		camel_imapx_debug_flags = CAMEL_IMAPX_DEBUG_ALL;
+		return;
+	}
+
+	debug_set_flag(command);
+	debug_set_flag(debug);
+	debug_set_flag(extra);
+	debug_set_flag(io);
+	debug_set_flag(token);
+	debug_set_flag(parse);
+}
 
 #include "camel-imapx-tokenise.h"
 #define SUBFOLDER_DIR_NAME     "subfolders"
@@ -1898,6 +1922,7 @@ void imapx_utils_init(void)
 
 		imapx_specials[i] = v;
 	}
+	camel_imapx_set_debug_flags();
 }
 
 guchar imapx_is_mask(const gchar *p)
diff --git a/camel/providers/imapx/camel-imapx-utils.h b/camel/providers/imapx/camel-imapx-utils.h
index e05f23e..8bcd763 100644
--- a/camel/providers/imapx/camel-imapx-utils.h
+++ b/camel/providers/imapx/camel-imapx-utils.h
@@ -220,6 +220,19 @@ guchar imapx_is_mask(const gchar *p);
 
 #define imapx_is_atom(s) (imapx_is_mask(s) & IMAPX_TYPE_ATOM_CHAR)
 
+extern gint camel_imapx_debug_flags;
+#define CAMEL_IMAPX_DEBUG_command	(1<<0)
+#define CAMEL_IMAPX_DEBUG_debug		(1<<1)
+#define CAMEL_IMAPX_DEBUG_extra		(1<<2)
+#define CAMEL_IMAPX_DEBUG_io		(1<<3)
+#define CAMEL_IMAPX_DEBUG_token		(1<<4)
+#define CAMEL_IMAPX_DEBUG_parse		(1<<5)
+
+/* Set this to zero to remove all debug output at build time */
+#define CAMEL_IMAPX_DEBUG_ALL		((1<<6)-1)
+
+#define camel_imapx_debug(type, ...) do { if (camel_imapx_debug_flags & CAMEL_IMAPX_DEBUG_ALL & CAMEL_IMAPX_DEBUG_ ## type) { __VA_ARGS__ ; } } while (0)
+
 /* ********************************************************************** */
 
 void imapx_utils_init(void);
diff --git a/camel/providers/imapx/camel-imapx-view-summary.c b/camel/providers/imapx/camel-imapx-view-summary.c
index b8a6a3e..20d01f2 100644
--- a/camel/providers/imapx/camel-imapx-view-summary.c
+++ b/camel/providers/imapx/camel-imapx-view-summary.c
@@ -27,12 +27,13 @@
 
 #include "camel-record.h"
 #include "camel-imapx-view-summary.h"
+#include "camel-imapx-utils.h"
 
 /* NB, this is only for the messy iterator_get interface, which could be better hidden */
 #include "libdb/dist/db.h"
 
-#define io(x)
-#define d(x) (printf("%s(%d): ", __FILE__, __LINE__),(x))
+#define d(x) camel_imapx_debug(debug, x)
+#define io(x) camel_imapx_debug(io, x)
 
 #define CVSD_CLASS(x) ((CamelViewSummaryDiskClass *)((CamelObject *)x)->klass)
 #define CVS_CLASS(x) ((CamelViewSummaryClass *)((CamelObject *)x)->klass)



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