more charset improvements.
[apps/madmutt.git] / init.c
diff --git a/init.c b/init.c
index c55a0da..583b02d 100644 (file)
--- a/init.c
+++ b/init.c
 # include "config.h"
 #endif
 
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/utsname.h>
+#include <errno.h>
+#include <sys/wait.h>
+
 #include <lib-lib/mem.h>
 #include <lib-lib/str.h>
 #include <lib-lib/file.h>
 #include <lib-lib/macros.h>
 #include <lib-lib/buffer.h>
 #include <lib-lib/mapping.h>
-#include <lib-lib/debug.h>
 #include <lib-lib/rx.h>
 
 #include <lib-sys/unix.h>
+#include <lib-sys/mutt_ssl.h>
 
 #include <lib-ui/curses.h>
 #include <lib-ui/history.h>
 #include <lib-crypt/crypt.h>
 #include "mutt_idna.h"
 
-#if defined(USE_SSL) || defined(USE_GNUTLS)
-#include <lib-sys/mutt_ssl.h>
-#endif
-
 #if defined (USE_LIBESMTP) && (defined (USE_SSL) || defined (USE_GNUTLS))
 #include "mutt_libesmtp.h"
 #endif
 
+#include "alias.h"
 #include "mx.h"
 #include "init.h"
 
 #include "lib/list.h"
 
-#include <ctype.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/utsname.h>
-#include <errno.h>
-#include <sys/wait.h>
-
 /*
  * prototypes
  */
@@ -92,10 +89,6 @@ static int check_history    (const char* option, unsigned long val,
 /* this checks that numbers are >= 0 */
 static int check_num        (const char* option, unsigned long val,
                              char* errbuf, ssize_t errlen);
-#ifdef DEBUG
-static int check_debug      (const char* option, unsigned long val,
-                             char* errbuf, ssize_t errlen);
-#endif
 
 /* use this to check only */
 static int check_special (const char* option, unsigned long val,
@@ -117,9 +110,6 @@ static struct {
 #endif
   { "history",                  check_history },
   { "pager_index_lines",        check_num },
-#ifdef DEBUG
-  { "debug_level",              check_debug },
-#endif
   /* last */
   { NULL,         NULL }
 };
@@ -540,7 +530,6 @@ int mutt_option_value (const char* val, char* dst, ssize_t dstlen) {
   ssize_t l = 0;
 
   if (!(option = hash_find (ConfigOptions, val))) {
-    debug_print (1, ("var '%s' not found\n", val));
     *dst = '\0';
     return (0);
   }
@@ -549,7 +538,6 @@ int mutt_option_value (const char* val, char* dst, ssize_t dstlen) {
 
   /* as we get things of type $var=value and don't want to bloat the
    * above "just" for expansion, we do the stripping here */
-  debug_print (1, ("orig == '%s'\n", tmp));
   t = strchr (tmp, '=');
   t++;
   l = m_strlen(t);
@@ -561,7 +549,6 @@ int mutt_option_value (const char* val, char* dst, ssize_t dstlen) {
   }
   memcpy (dst, t, l+1);
   p_delete(&tmp);
-  debug_print (1, ("stripped == '%s'\n", dst));
 
   return (1);
 }
@@ -1101,11 +1088,8 @@ static int parse_attach_list (BUFFER *buf, BUFFER *s, string_list_t **ldata,
 
   /* Find the last item in the list that data points to. */
   lastp = NULL;
-  debug_print (5, ("parse_attach_list: ldata = %p, *ldata = %p\n",
-                   ldata, *ldata));
   for (listp = *ldata; listp; listp = listp->next) {
     a = (ATTACH_MATCH *)listp->data;
-    debug_print (5, ("parse_attach_list: skipping %s/%s\n", a->major, a->minor));
     lastp = listp;
   }
 
@@ -1145,9 +1129,6 @@ static int parse_attach_list (BUFFER *buf, BUFFER *s, string_list_t **ldata,
 
     p_delete(&tmpminor);
 
-    debug_print (5, ("parse_attach_list: added %s/%s [%d]\n",
-                     a->major, a->minor, a->major_int));
-
     listp = p_new(string_list_t, 1);
     listp->data = (char *)a;
     listp->next = NULL;
@@ -1195,11 +1176,7 @@ static int parse_unattach_list (BUFFER *buf, BUFFER *s, string_list_t **ldata,
     lastp = NULL;
     for(lp = *ldata; lp; ) {
       a = (ATTACH_MATCH *)lp->data;
-      debug_print(5, ("parse_unattach_list: check %s/%s [%d] : %s/%s [%d]\n",
-                      a->major, a->minor, a->major_int, tmp, minor, major));
       if (a->major_int == major && !m_strcasecmp(minor, a->minor)) {
-        debug_print(5, ("parse_unattach_list: removed %s/%s [%d]\n",
-                        a->major, a->minor, a->major_int));
         regfree(&a->minor_rx);
         p_delete(&a->major);
 
@@ -1437,8 +1414,6 @@ static int parse_alias (BUFFER * buf, BUFFER * s,
 
   mutt_extract_token (buf, s, 0);
 
-  debug_print (2, ("first token is '%s'.\n", buf->data));
-
   /* check to see if an alias with this name already exists */
   for (; tmp; tmp = tmp->next) {
     if (!m_strcasecmp(tmp->name, buf->data))
@@ -1463,7 +1438,6 @@ static int parse_alias (BUFFER * buf, BUFFER * s,
 
   mutt_extract_token (buf, s,
                       M_TOKEN_QUOTE | M_TOKEN_SPACE | M_TOKEN_SEMICOLON);
-  debug_print (2, ("second token is '%s'.\n", buf->data));
   tmp->addr = mutt_parse_adrlist (tmp->addr, buf->data);
   if (last)
     last->next = tmp;
@@ -1474,19 +1448,7 @@ static int parse_alias (BUFFER * buf, BUFFER * s,
               _("Warning: Bad IDN '%s' in alias '%s'.\n"), estr, tmp->name);
     return -1;
   }
-#ifdef DEBUG
-  if (DebugLevel >= 2) {
-    address_t *a;
 
-    /* A group is terminated with an empty address, so check a->mailbox */
-    for (a = tmp->addr; a && a->mailbox; a = a->next) {
-      if (!a->group)
-        debug_print (2, ("%s\n", a->mailbox));
-      else
-        debug_print (2, ("group %s\n", a->mailbox));
-    }
-  }
-#endif
   return 0;
 }
 
@@ -1622,8 +1584,6 @@ static struct option_t* add_option (const char* name, const char* init,
                                     short type, short dodup) {
   struct option_t* option = p_new(struct option_t, 1);
 
-  debug_print (1, ("adding $%s\n", name));
-
   option->option = m_strdup(name);
   option->type = type;
   if (init)
@@ -1640,7 +1600,6 @@ static struct option_t* add_user_option (const char* name) {
 static void del_option (void* p) {
   struct option_t *ptr = (struct option_t*) p;
   char* s = (char*) ptr->data;
-  debug_print (1, ("removing option '%s' from table\n", NONULL (ptr->option)));
   p_delete(&ptr->option);
   p_delete(&s);
   p_delete(&ptr->init);
@@ -1774,19 +1733,6 @@ static int check_num (const char* option, unsigned long p,
   return (1);
 }
 
-#ifdef DEBUG
-static int check_debug (const char* option, unsigned long p,
-                        char* errbuf, ssize_t errlen) {
-  if ((int) p <= DEBUG_MAX_LEVEL &&
-      (int) p >= DEBUG_MIN_LEVEL)
-    return (1);
-
-  if (errbuf)
-    snprintf (errbuf, errlen, _("'%d' is invalid for $%s"), (int) p, option);
-  return (0);
-}
-#endif
-
 static int check_history (const char* option __attribute__ ((unused)), unsigned long p,
                           char* errbuf, ssize_t errlen) {
   if (!check_num ("history", p, errbuf, errlen))
@@ -1886,7 +1832,6 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data,
       /* there's no option named like this yet so only add one
        * if the action isn't any of: reset, unset, query */
       if (!(reset || unset || query || *s->dptr != '=')) {
-        debug_print (1, ("adding user option '%s'\n", tmp->data));
         option = add_user_option (tmp->data);
         hash_insert (ConfigOptions, option->option, option, 0);
       }
@@ -2094,8 +2039,6 @@ static int source_rc (const char *rcfile, BUFFER * err)
   ssize_t buflen;
   pid_t pid;
 
-  debug_print (2, ("reading configuration file '%s'.\n", rcfile));
-
   if ((f = mutt_open_read (rcfile, &pid)) == NULL) {
     snprintf (err->data, err->dsize, "%s: %s", rcfile, strerror (errno));
     return (-1);
@@ -2193,8 +2136,6 @@ int mutt_parse_rc_line ( /* const */ char *line, BUFFER * token, BUFFER * err)
 
   *err->data = 0;
 
-  debug_print (1, ("expand '%s'\n", line));
-
   expn.dptr = vskipspaces(expn.dptr);
   while (*expn.dptr) {
     if (*expn.dptr == '#')
@@ -2629,8 +2570,6 @@ void mutt_init (int skip_sys_rc, string_list_t * commands)
     Shell = m_strdup((p = getenv ("SHELL")) ? p : "/bin/sh");
   }
 
-  debug_start(Homedir);
-
   /* And about the host... */
   uname (&utsname);
   /* some systems report the FQDN instead of just the hostname */
@@ -2722,9 +2661,7 @@ void mutt_init (int skip_sys_rc, string_list_t * commands)
   if ((p = getenv ("EMAIL")) != NULL)
     From = rfc822_parse_adrlist (NULL, p);
 
-  mutt_set_langinfo_charset ();
-  mutt_set_charset (Charset);
-
+  charset_initialize();
 
   /* Set standard defaults */
   hash_map (ConfigOptions, mutt_set_default, 0);