This adds a new function to get the log level. This way, debuglevel is
not accessed directly, but through a mutt_log_* API.
---
 imap/auth_gss.c | 2 +-
 imap/imap.c     | 4 ++--
 init.c          | 4 ++--
 lib.c           | 7 ++++++-
 lib.h           | 4 ++--
 5 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/imap/auth_gss.c b/imap/auth_gss.c
index 39786c4..ce391ab 100644
--- a/imap/auth_gss.c
+++ b/imap/auth_gss.c
@@ -114,7 +114,7 @@ imap_auth_res_t imap_auth_gss (IMAP_DATA* idata, const 
char* method)
     return IMAP_AUTH_UNAVAIL;
   }
 #ifdef DEBUG   
-  else if (debuglevel >= 2)
+  else if (mutt_log_get_level () >= 2)
   {
     maj_stat = gss_display_name (&min_stat, target_name, &request_buf,
       &mech_name);
diff --git a/imap/imap.c b/imap/imap.c
index 2e3d27d..3a31b93 100644
--- a/imap/imap.c
+++ b/imap/imap.c
@@ -235,7 +235,7 @@ int imap_read_literal (FILE* fp, IMAP_DATA* idata, long 
bytes, progress_t* pbar)
     if (pbar && !(pos % 1024))
       mutt_progress_update (pbar, pos, -1);
 #ifdef DEBUG
-    if (debuglevel >= IMAP_LOG_LTRL)
+    if (mutt_log_get_level () >= IMAP_LOG_LTRL)
       fputc (c, debugfile);
 #endif
   }
@@ -720,7 +720,7 @@ static int imap_open_mailbox (CONTEXT* ctx)
 
 #ifdef DEBUG
   /* dump the mailbox flags we've found */
-  if (debuglevel > 2)
+  if (mutt_log_get_level () > 2)
   {
     if (!idata->flags)
       dprint (3, (debugfile, "No folder flags found\n"));
diff --git a/init.c b/init.c
index 3ce6888..bda10ca 100644
--- a/init.c
+++ b/init.c
@@ -1350,7 +1350,7 @@ static int parse_alias (BUFFER *buf, BUFFER *s, unsigned 
long data, BUFFER *err)
   mutt_alias_add_reverse (tmp);
 
 #ifdef DEBUG
-  if (debuglevel >= 2) 
+  if (mutt_log_get_level () >= 2)
   {
     ADDRESS *a;
     /* A group is terminated with an empty address, so check a->mailbox */
@@ -2941,7 +2941,7 @@ void mutt_init (int skip_sys_rc, LIST *commands)
 
 #ifdef DEBUG
   /* Start up debugging mode if requested */
-  if (debuglevel > 0)
+  if (mutt_log_get_level () > 0)
     mutt_log_init (ReleaseDate, Homedir);
 #endif
 
diff --git a/lib.c b/lib.c
index eb04e3f..efd9b75 100644
--- a/lib.c
+++ b/lib.c
@@ -52,7 +52,7 @@
 
 #ifdef DEBUG
 FILE *debugfile = NULL;
-int debuglevel = 0;
+static int debuglevel = 0;
 #endif
 
 static const struct sysexits
@@ -1047,6 +1047,11 @@ int mutt_log_set_level (int level)
 
   return level;
 }
+
+int mutt_log_get_level (void)
+{
+  return debuglevel;
+}
 #endif
 
 void mutt_debug (FILE *fp, const char *fmt, ...)
diff --git a/lib.h b/lib.h
index 024484f..057af57 100644
--- a/lib.h
+++ b/lib.h
@@ -134,13 +134,13 @@ void mutt_exit (int);
 # ifdef DEBUG
 
 extern FILE *debugfile;
-extern int debuglevel;
 
 int mutt_log_init (const char *reldate, const char *homedir);
 int mutt_log_set_level (int level);
+int mutt_log_get_level (void);
 void mutt_debug (FILE *, const char *, ...);
 
-#  define dprint(N,X) do { if(debuglevel>=N && debugfile) mutt_debug X; } 
while (0)
+#  define dprint(N,X) do { if(mutt_log_get_level()>=N && debugfile) mutt_debug 
X; } while (0)
 
 # else
 
-- 
2.9.0

Reply via email to