]> granicus.if.org Git - neomutt/commitdiff
use dedicated set_default() and reset_value()
authorRichard Russon <rich@flatcap.org>
Tue, 13 Mar 2018 20:24:21 +0000 (20:24 +0000)
committerRichard Russon <rich@flatcap.org>
Thu, 15 Mar 2018 18:38:04 +0000 (18:38 +0000)
init.c
main.c
protos.h

diff --git a/init.c b/init.c
index 374be99640c410a566e3567743ae72e25ab9a3d8..6697c02e1f7ba2a8b27306c91a3356deff88e9ed 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1899,11 +1899,7 @@ static void restore_default(struct Option *p)
       break;
     case DT_PATH:
       FREE((char **) p->var);
-      char *init = NULL;
-      if (mutt_str_strcmp(p->name, "debug_file") == 0 && debugfile_cmdline)
-        init = debugfile_cmdline;
-      else
-        init = (char *) p->initial;
+      char *init = (char *) p->initial;
       if (init)
       {
         char path[_POSIX_PATH_MAX];
@@ -1929,10 +1925,7 @@ static void restore_default(struct Option *p)
     case DT_NUMBER:
     case DT_SORT:
     case DT_MAGIC:
-      if (mutt_str_strcmp(p->name, "debug_level") == 0 && debuglevel_cmdline)
-        *((short *) p->var) = debuglevel_cmdline;
-      else
-        *((short *) p->var) = p->initial;
+      *((short *) p->var) = p->initial;
       break;
     case DT_REGEX:
     {
@@ -2075,7 +2068,7 @@ char **mutt_envlist(void)
  *
  * This method prepares and opens a new debug file for mutt_debug.
  */
-static void start_debug(void)
+void start_debug(void)
 {
   if (!DebugFile)
     return;
@@ -3808,23 +3801,6 @@ int mutt_init(int skip_sys_rc, struct ListHead *commands)
   snprintf(AttachmentMarker, sizeof(AttachmentMarker), "\033]9;%" PRIu64 "\a",
            mutt_rand64());
 
-  /* Start up debugging mode if requested from cmdline */
-  if (debuglevel_cmdline > 0)
-  {
-    debuglevel = debuglevel_cmdline;
-    if (debugfile_cmdline)
-    {
-      DebugFile = mutt_str_strdup(debugfile_cmdline);
-    }
-    else
-    {
-      int i = mutt_option_index("debug_file");
-      if ((i >= 0) && (MuttVars[i].initial != 0))
-        DebugFile = mutt_str_strdup((const char *) MuttVars[i].initial);
-    }
-    start_debug();
-  }
-
   /* And about the host... */
 
   /*
@@ -4400,3 +4376,28 @@ int mutt_label_complete(char *buffer, size_t len, int numtabs)
 
   return 1;
 }
+
+bool set_default_value(const char *name, intptr_t value)
+{
+  if (!name)
+    return false;
+
+  int idx = mutt_option_index(name);
+  if (!idx)
+    return false;
+
+  MuttVars[idx].initial = value;
+  return true;
+}
+
+void reset_value(const char *name)
+{
+  if (!name)
+    return;
+
+  int idx = mutt_option_index(name);
+  if (!idx)
+    return;
+
+  restore_default(&MuttVars[idx]);
+}
diff --git a/main.c b/main.c
index 29e87a9956edcbb6079e05268755284e5542906d..4df8bd5948dd76b9f1b43c5eeaf8770b9602c303 100644 (file)
--- a/main.c
+++ b/main.c
@@ -67,6 +67,7 @@
 #endif
 
 char **envlist = NULL;
+void start_debug(void);
 
 void mutt_exit(int code)
 {
@@ -240,6 +241,8 @@ int main(int argc, char **argv, char **env)
   char *include_file = NULL;
   char *draft_file = NULL;
   char *new_magic = NULL;
+  char *dlevel = NULL;
+  char *dfile = NULL;
   struct Header *msg = NULL;
   struct ListHead attach = STAILQ_HEAD_INITIALIZER(attach);
   struct ListHead commands = STAILQ_HEAD_INITIALIZER(commands);
@@ -351,12 +354,7 @@ int main(int argc, char **argv, char **env)
           dump_variables = true;
           break;
         case 'd':
-          if (mutt_str_atoi(optarg, &debuglevel_cmdline) < 0 || debuglevel_cmdline <= 0)
-          {
-            mutt_error(_("Error: value '%s' is invalid for -d."), optarg);
-            goto main_exit;
-          }
-          printf(_("Debugging at level %d.\n"), debuglevel_cmdline);
+          dlevel = optarg;
           break;
         case 'E':
           edit_infile = true;
@@ -373,11 +371,7 @@ int main(int argc, char **argv, char **env)
           break;
 #ifdef USE_NNTP
         case 'g': /* Specify a news server */
-        {
-          char buf[LONG_STRING];
-          snprintf(buf, sizeof(buf), "set news_server=%s", optarg);
-          mutt_list_insert_tail(&commands, mutt_str_strdup(buf));
-        }
+          set_default_value("news_server", (intptr_t) mutt_str_strdup(optarg));
           /* fallthrough */
         case 'G': /* List of newsgroups */
           flags |= MUTT_SELECT | MUTT_NEWS;
@@ -390,8 +384,7 @@ int main(int argc, char **argv, char **env)
           include_file = optarg;
           break;
         case 'l':
-          debugfile_cmdline = optarg;
-          printf(_("Debugging at file %s.\n"), debugfile_cmdline);
+          dfile = optarg;
           break;
         case 'm':
           new_magic = optarg;
@@ -456,6 +449,24 @@ int main(int argc, char **argv, char **env)
     goto main_exit;
   }
 
+  if (dfile)
+  {
+    set_default_value("debug_file", (intptr_t) mutt_str_strdup(dfile));
+  }
+  reset_value("debug_file");
+
+  if (dlevel)
+  {
+    short num = 0;
+    if ((mutt_str_atos(dlevel, &num) < 0) || (num < 0) || (num > 5))
+    {
+      mutt_error(_("Error: value '%s' is invalid for -d."), dlevel);
+      goto main_exit;
+    }
+    set_default_value("debug_level", (intptr_t) num);
+  }
+  reset_value("debug_level");
+
   if (!STAILQ_EMPTY(&cc_list) || !STAILQ_EMPTY(&bcc_list))
   {
     msg = mutt_new_header();
@@ -505,13 +516,23 @@ int main(int argc, char **argv, char **env)
   if (rc != 0)
     goto main_curses;
 
+  /* The command line overrides the config */
+  if (dlevel)
+    reset_value("debug_level");
+  if (dfile)
+    reset_value("debug_file");
+  start_debug();
+
   mutt_list_free(&commands);
 
   /* Initialize crypto backends.  */
   crypt_init();
 
   if (new_magic)
+  {
     mx_set_magic(new_magic);
+    set_default_value("mbox_type", (intptr_t) MboxType);
+  }
 
   if (!STAILQ_EMPTY(&queries))
   {
index 7b2bff0650987e610c649f5e3c33c47e2636a44e..73abab37517f65e5e1551dc56974d65633840c71 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -364,4 +364,7 @@ int wcscasecmp(const wchar_t *a, const wchar_t *b);
 bool message_is_tagged(struct Context *ctx, int index);
 bool message_is_visible(struct Context *ctx, int index);
 
+bool set_default_value(const char *name, intptr_t value);
+void reset_value(const char *name);
+
 #endif /* _MUTT_PROTOS_H */