This commit adds variant of the mutt_log* functions when mutt is
compiled without --enable-debug. This allows to get rid of most "#ifdef
DEBUG", and the compiler should be able to get rid of the dead code,
leading to no (or minimal) increase of the executable size in favor of
readibility.
---
 copy.c            |  3 +--
 hcache.c          | 21 +++++++++++++--------
 imap/auth_gss.c   |  7 +------
 imap/auth_login.c |  2 --
 imap/imap.c       |  5 +----
 init.c            |  5 +----
 lib.h             | 25 +++++++++++++++++++++++--
 main.c            | 26 +++++++++++++-------------
 mutt_ssl.c        | 10 +++++-----
 muttlib.c         |  2 --
 pop_lib.c         | 14 ++++++--------
 rfc3676.c         | 27 ++++++++++++++-------------
 12 files changed, 78 insertions(+), 69 deletions(-)

diff --git a/copy.c b/copy.c
index e5a3be0..7fdbb33 100644
--- a/copy.c
+++ b/copy.c
@@ -533,7 +533,7 @@ _mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, 
BODY *body,
       if (copy_delete_attach (body, fpin, fpout, date))
        return -1;
 
-#ifdef DEBUG
+      if (mutt_log_get_level () > 0)
       {
        LOFF_T fail = ((ftello (fpout) - new_offset) - new_length);
 
@@ -544,7 +544,6 @@ _mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, 
BODY *body,
          mutt_sleep (1);
        }
       }
-#endif
 
       /* Update original message if we are sync'ing a mailfolder */ 
       if (flags & MUTT_CM_UPDATE)
diff --git a/hcache.c b/hcache.c
index fff6d69..4bd5f5a 100644
--- a/hcache.c
+++ b/hcache.c
@@ -931,10 +931,13 @@ hcache_open_tc (struct header_cache* h, const char* path)
     return 0;
   else
   {
-#ifdef DEBUG
-    int ecode = tcbdbecode (h->db);
-    mutt_log (2, "tcbdbopen failed for %s: %s (ecode %d)\n", path, tcbdberrmsg 
(ecode), ecode);
-#endif
+    if (mutt_log_get_level () >= 2)
+    {
+      int ecode = tcbdbecode (h->db);
+      mutt_log (2, "tcbdbopen failed for %s: %s (ecode %d)\n",
+                path, tcbdberrmsg (ecode), ecode);
+    }
+
     tcbdbdel(h->db);
     return -1;
   }
@@ -948,10 +951,12 @@ mutt_hcache_close(header_cache_t *h)
 
   if (!tcbdbclose(h->db))
   {
-#ifdef DEBUG
-    int ecode = tcbdbecode (h->db);
-    mutt_log (2, "tcbdbclose failed for %s: %s (ecode %d)\n", h->folder, 
tcbdberrmsg (ecode), ecode);
-#endif
+    if (mutt_log_get_level () >= 2)
+    {
+      int ecode = tcbdbecode (h->db);
+      mutt_log (2, "tcbdbclose failed for %s: %s (ecode %d)\n",
+                h->folder, tcbdberrmsg (ecode), ecode);
+    }
   }
   tcbdbdel(h->db);
   FREE(&h->folder);
diff --git a/imap/auth_gss.c b/imap/auth_gss.c
index b03db38..96015d1 100644
--- a/imap/auth_gss.c
+++ b/imap/auth_gss.c
@@ -85,10 +85,8 @@ imap_auth_res_t imap_auth_gss (IMAP_DATA* idata, const char* 
method)
   gss_buffer_t sec_token;
   gss_name_t target_name;
   gss_ctx_id_t context;
-#ifdef DEBUG
   gss_OID mech_name;
   char server_conf_flags;
-#endif
   gss_qop_t quality;
   int cflags;
   OM_uint32 maj_stat, min_stat;
@@ -113,7 +111,6 @@ imap_auth_res_t imap_auth_gss (IMAP_DATA* idata, const 
char* method)
     mutt_log (2, "Couldn't get service name for [%s]\n", buf1);
     return IMAP_AUTH_UNAVAIL;
   }
-#ifdef DEBUG   
   else if (mutt_log_get_level () >= 2)
   {
     maj_stat = gss_display_name (&min_stat, target_name, &request_buf,
@@ -122,7 +119,7 @@ imap_auth_res_t imap_auth_gss (IMAP_DATA* idata, const 
char* method)
       (char*) request_buf.value);
     maj_stat = gss_release_buffer (&min_stat, &request_buf);
   }
-#endif
+
   /* Acquire initial credentials - without a TGT GSSAPI is UNAVAIL */
   sec_token = GSS_C_NO_BUFFER;
   context = GSS_C_NO_CONTEXT;
@@ -231,9 +228,7 @@ imap_auth_res_t imap_auth_gss (IMAP_DATA* idata, const 
char* method)
   mutt_log (2, "Credential exchange complete\n");
 
   /* first octet is security levels supported. We want NONE */
-#ifdef DEBUG
   server_conf_flags = ((char*) send_token.value)[0];
-#endif
   if ( !(((char*) send_token.value)[0] & GSS_AUTH_P_NONE) )
   {
     mutt_log (2, "Server requires integrity or privacy\n");
diff --git a/imap/auth_login.c b/imap/auth_login.c
index b2dbf22..d599a4c 100644
--- a/imap/auth_login.c
+++ b/imap/auth_login.c
@@ -49,10 +49,8 @@ imap_auth_res_t imap_auth_login (IMAP_DATA* idata, const 
char* method)
   imap_quote_string (q_user, sizeof (q_user), idata->conn->account.user);
   imap_quote_string (q_pass, sizeof (q_pass), idata->conn->account.pass);
 
-#ifdef DEBUG
   mutt_log (2, "Sending LOGIN command for %s...\n",
             idata->conn->account.user);
-#endif
 
   snprintf (buf, sizeof (buf), "LOGIN %s %s", q_user, q_pass);
   rc = imap_exec (idata, buf, IMAP_CMD_FAIL_OK | IMAP_CMD_PASS);
diff --git a/imap/imap.c b/imap/imap.c
index 181e9f7..b841df0 100644
--- a/imap/imap.c
+++ b/imap/imap.c
@@ -234,9 +234,8 @@ 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
+
     mutt_log_append (IMAP_LOG_LTRL, "%c", c);
-#endif
   }
 
   return 0;
@@ -717,7 +716,6 @@ static int imap_open_mailbox (CONTEXT* ctx)
     ctx->readonly = 1;
   }
 
-#ifdef DEBUG
   /* dump the mailbox flags we've found */
   if (mutt_log_get_level () > 2)
   {
@@ -738,7 +736,6 @@ static int imap_open_mailbox (CONTEXT* ctx)
       mutt_log (3, "\n");
     }
   }
-#endif
 
   if (!(mutt_bit_isset(idata->ctx->rights, MUTT_ACL_DELETE) ||
         mutt_bit_isset(idata->ctx->rights, MUTT_ACL_SEEN) ||
diff --git a/init.c b/init.c
index fb57c3a..84030ab 100644
--- a/init.c
+++ b/init.c
@@ -1349,7 +1349,6 @@ static int parse_alias (BUFFER *buf, BUFFER *s, unsigned 
long data, BUFFER *err)
   mutt_group_context_add_adrlist (gc, tmp->addr);
   mutt_alias_add_reverse (tmp);
 
-#ifdef DEBUG
   if (mutt_log_get_level () >= 2)
   {
     ADDRESS *a;
@@ -1364,7 +1363,7 @@ static int parse_alias (BUFFER *buf, BUFFER *s, unsigned 
long data, BUFFER *err)
                    a->mailbox);
     }
   }
-#endif
+
   mutt_group_context_destroy (&gc);
   return 0;
   
@@ -2931,11 +2930,9 @@ void mutt_init (int skip_sys_rc, LIST *commands)
     Shell = safe_strdup ((p = getenv ("SHELL")) ? p : "/bin/sh");
   }
 
-#ifdef DEBUG
   /* Start up debugging mode if requested */
   if (mutt_log_get_level () > 0)
     mutt_log_init (ReleaseDate, Homedir);
-#endif
 
   /* And about the host... */
 
diff --git a/lib.h b/lib.h
index f35ed04..502ceea 100644
--- a/lib.h
+++ b/lib.h
@@ -141,10 +141,31 @@ void mutt_log_append (int level, const char *, ...);
 
 # else
 
-#define mutt_log(...) do { } while (0)
+static inline int mutt_log_init (const char *path, const char *reldate)
+{
+  return -1;
+}
 
-# endif
+static inline int mutt_log_set_level(int level)
+{
+  return -1;
+}
+
+static inline int mutt_log_get_level(void)
+{
+  return 0;
+}
 
+static inline void mutt_log (int level, const char *fmt, ...)
+{
+
+}
+
+static inline void mutt_log_append (int level, const char *fmt, ...)
+{
+
+}
+#endif
 
 /* Exit values used in send_msg() */
 #define S_ERR 127
diff --git a/main.c b/main.c
index bbc1294..419d1c3 100644
--- a/main.c
+++ b/main.c
@@ -587,9 +587,7 @@ int main (int argc, char **argv)
   extern char *optarg;
   extern int optind;
   int double_dash = argc, nargc = 1;
-#ifdef DEBUG
   int loglevel = 0;
-#endif
 
   /* sanity check against stupid administrators */
   
@@ -676,18 +674,20 @@ int main (int argc, char **argv)
        break;
 
       case 'd':
-#ifdef DEBUG
-        if (mutt_atoi (optarg, &loglevel) < 0 ||
-            !mutt_log_set_level (loglevel))
+        if (mutt_atoi (optarg, &loglevel) < 0)
         {
-         fprintf (stderr, _("Error: value '%s' is invalid for -d.\n"), optarg);
-         return 1;
-       }
-       printf (_("Debugging at level %d.\n"), loglevel);
-#else
-       printf _("DEBUG was not defined during compilation.  Ignored.\n");
-#endif
-       break;
+                fprintf (stderr, _("Error: value '%s' is invalid for -d.\n"), 
optarg);
+                return 1;
+        }
+
+        loglevel = mutt_log_set_level (loglevel);
+        if (loglevel > 0)
+                printf (_("Debugging at level %d.\n"), loglevel);
+        else if (loglevel == 0)
+                fprintf (stderr, _("Error: value '%d' is invalid for -d.\n"), 
loglevel);
+        else
+                printf (_("DEBUG was not defined during compilation.  
Ignored.\n"));
+        break;
 
       case 'E':
         edit_infile = 1;
diff --git a/mutt_ssl.c b/mutt_ssl.c
index 9796ff5..66b97b5 100644
--- a/mutt_ssl.c
+++ b/mutt_ssl.c
@@ -546,11 +546,13 @@ static void ssl_err (sslsockdata *data, int err)
 
 static void ssl_dprint_err_stack (void)
 {
-#ifdef DEBUG
   BIO *bio;
   char *buf = NULL;
   long buflen;
   char *output;
+  
+  if (mutt_log_get_level () < 1)
+    return;
 
   if (! (bio = BIO_new (BIO_s_mem ())))
     return;
@@ -564,7 +566,6 @@ static void ssl_dprint_err_stack (void)
     FREE (&output);
   }
   BIO_free (bio);
-#endif
 }
 
 
@@ -664,8 +665,7 @@ static int check_certificate_by_signer (X509 *peercert)
   X509_STORE_CTX_init (&xsc, ctx, peercert, SslSessionCerts);
 
   pass = (X509_verify_cert (&xsc) > 0);
-#ifdef DEBUG
-  if (! pass)
+  if (! pass && mutt_log_get_level () >= 2)
   {
     char buf[SHORT_STRING];
     int err;
@@ -676,7 +676,7 @@ static int check_certificate_by_signer (X509 *peercert)
     mutt_log (2, "X509_verify_cert: %s\n", buf);
     mutt_log (2, " [%s]\n", peercert->name);
   }
-#endif
+
   X509_STORE_CTX_cleanup (&xsc);
   X509_STORE_free (ctx);
 
diff --git a/muttlib.c b/muttlib.c
index a866264..03bf234 100644
--- a/muttlib.c
+++ b/muttlib.c
@@ -1092,9 +1092,7 @@ void mutt_FormatString (char *dest,               /* 
output buffer */
     {
       BUFFER *srcbuf, *word, *command;
       char    srccopy[LONG_STRING];
-#ifdef DEBUG
       int     i = 0;
-#endif
 
       mutt_log (3, "fmtpipe = %s\n", src);
 
diff --git a/pop_lib.c b/pop_lib.c
index 96baaf4..1b788a3 100644
--- a/pop_lib.c
+++ b/pop_lib.c
@@ -424,14 +424,12 @@ int pop_query_d (POP_DATA *pop_data, char *buf, size_t 
buflen, char *msg)
   if (pop_data->status != POP_CONNECTED)
     return -1;
 
-#ifdef DEBUG
-    /* print msg instead of real command */
-    if (msg)
-    {
-      dbg = MUTT_SOCK_LOG_FULL;
-      mutt_log (MUTT_SOCK_LOG_CMD, "> %s", msg);
-    }
-#endif
+  /* print msg instead of real command */
+  if (msg && mutt_log_get_level () > 0)
+  {
+    dbg = MUTT_SOCK_LOG_FULL;
+    mutt_log (MUTT_SOCK_LOG_CMD, "> %s", msg);
+  }
 
   mutt_socket_write_d (pop_data->conn, buf, -1, dbg);
 
diff --git a/rfc3676.c b/rfc3676.c
index d008b1d..d4439ad 100644
--- a/rfc3676.c
+++ b/rfc3676.c
@@ -337,11 +337,9 @@ int rfc3676_handler (BODY * a, STATE * s)
  */
 void rfc3676_space_stuff (HEADER* hdr)
 {
-#if DEBUG
   int lc = 0;
   size_t len = 0;
   unsigned char c = '\0';
-#endif
   FILE *in = NULL, *out = NULL;
   char buf[LONG_STRING];
   char tmpfile[_POSIX_PATH_MAX];
@@ -365,19 +363,22 @@ void rfc3676_space_stuff (HEADER* hdr)
   {
     if (ascii_strncmp ("From ", buf, 5) == 0 || buf[0] == ' ') {
       fputc (' ', out);
-#if DEBUG
-      lc++;
-      len = mutt_strlen (buf);
-      if (len > 0)
+
+      if (mutt_log_get_level () > 0)
       {
-        c = buf[len-1];
-        buf[len-1] = '\0';
+        lc++;
+        len = mutt_strlen (buf);
+        if (len > 0)
+        {
+          c = buf[len-1];
+          buf[len-1] = '\0';
+        }
+
+        mutt_log (4, "f=f: line %d needs space-stuffing: '%s'\n",
+                    lc, buf);
+        if (len > 0)
+          buf[len-1] = c;
       }
-      mutt_log (4, "f=f: line %d needs space-stuffing: '%s'\n",
-                  lc, buf);
-      if (len > 0)
-        buf[len-1] = c;
-#endif
     }
     fputs (buf, out);
   }
-- 
2.9.0

Reply via email to