break;
case DT_PATH:
FREE((char **) p->data);
- if (p->init)
+ char *init = NULL;
+#ifdef DEBUG
+ if (mutt_strcmp(p->option, "debug_file") == 0 && debugfile_cmdline)
+ init = debugfile_cmdline;
+ else
+#endif
+ init = (char *) p->init;
+ if (init)
{
char path[_POSIX_PATH_MAX];
- strfcpy(path, (char *) p->init, sizeof(path));
+ strfcpy(path, init, sizeof(path));
mutt_expand_path(path, sizeof(path));
*((char **) p->data) = safe_strdup(path);
}
case DT_NUM:
case DT_SORT:
case DT_MAGIC:
- *((short *) p->data) = p->init;
+#ifdef DEBUG
+ if (mutt_strcmp(p->option, "debug_level") == 0 && debuglevel_cmdline)
+ *((short *) p->data) = debuglevel_cmdline;
+ else
+#endif
+ *((short *) p->data) = p->init;
break;
case DT_RX:
{
return envlist;
}
+#ifdef DEBUG
+/**
+ * start_debug - prepare the debugging file
+ *
+ * @return nothing
+ *
+ * This method prepares and opens a new debug file for mutt_debug.
+ */
+static void start_debug(void)
+{
+ int i;
+ char buf[_POSIX_PATH_MAX];
+
+ /* rotate the old debug logs */
+ for (i = 3; i >= 0; i--)
+ {
+ snprintf(debugfilename, sizeof(debugfilename), "%s%d", DebugFile, i);
+ snprintf(buf, sizeof(buf), "%s%d", DebugFile, i + 1);
+ rename(debugfilename, buf);
+ }
+
+ if ((debugfile = safe_fopen(debugfilename, "w")) != NULL)
+ {
+ setbuf(debugfile, NULL); /* don't buffer the debugging output! */
+ mutt_debug(1, "NeoMutt/%s (%s) debugging at level %d\n", PACKAGE_VERSION,
+ MUTT_VERSION, debuglevel);
+ }
+}
+
+/**
+ * restart_debug - reload the debugging configuration
+ *
+ * @return nothing
+ *
+ * This method closes the old debug file is debug was enabled,
+ * then reconfigure the debugging system from the configuration options
+ * and start a new debug file if debug is enabled
+ */
+static void restart_debug(void)
+{
+ bool disable_debug = (debuglevel > 0 && DebugLevel == 0);
+ bool enable_debug = (debuglevel == 0 && DebugLevel > 0);
+ bool file_changed =
+ ((mutt_strlen(debugfilename) - 1) != mutt_strlen(DebugFile) ||
+ mutt_strncmp(debugfilename, DebugFile, mutt_strlen(debugfilename) - 1));
+
+ if (disable_debug || file_changed)
+ {
+ mutt_debug(1, "NeoMutt/%s (%s) stop debugging\n", PACKAGE_VERSION, MUTT_VERSION);
+ safe_fclose(&debugfile);
+ }
+
+ if (!enable_debug && !disable_debug && debuglevel != DebugLevel)
+ mutt_debug(1, "NeoMutt/%s (%s) debugging at level %d\n", PACKAGE_VERSION,
+ MUTT_VERSION, DebugLevel);
+
+ debuglevel = DebugLevel;
+
+ if (enable_debug || (file_changed && debuglevel > 0))
+ start_debug();
+}
+#endif
+
/* Helper function for parse_setenv().
* It's broken out because some other parts of mutt (filter.c) need
* to set/overwrite environment variables in envlist before execing.
}
else if (DTYPE(MuttVars[idx].type) == DT_PATH)
{
+#ifdef DEBUG
+ if (mutt_strcmp(MuttVars[idx].option, "debug_file") == 0 && debugfile_cmdline)
+ {
+ mutt_message(_("set debug_file ignored, it have been overridden "
+ "with cmdline"));
+ break;
+ }
+#endif
/* MuttVars[idx].data is already 'char**' (or some 'void**') or...
* so cast to 'void*' is okay */
FREE((void *) MuttVars[idx].data);
strfcpy(scratch, tmp->data, sizeof(scratch));
mutt_expand_path(scratch, sizeof(scratch));
*((char **) MuttVars[idx].data) = safe_strdup(scratch);
+#ifdef DEBUG
+ if (mutt_strcmp(MuttVars[idx].option, "debug_file") == 0)
+ restart_debug();
+#endif
}
else if (DTYPE(MuttVars[idx].type) == DT_STR)
{
r = -1;
break;
}
+#ifdef DEBUG
+ else if (mutt_strcmp(MuttVars[idx].option, "debug_level") == 0 && debuglevel_cmdline)
+ {
+ mutt_message(
+ _("set debug_level ignored, it have been overridden with cmdline"));
+ break;
+ }
+#endif
else
*ptr = val;
*ptr = 0;
mutt_init_history();
}
+#ifdef DEBUG
+ else if (mutt_strcmp(MuttVars[idx].option, "debug_level") == 0)
+ {
+ if (*ptr < 0)
+ *ptr = 0;
+ restart_debug();
+ }
+#endif
else if (mutt_strcmp(MuttVars[idx].option, "pager_index_lines") == 0)
{
if (*ptr < 0)
return -1;
}
-#ifdef DEBUG
-static void start_debug(void)
-{
- int i;
- char buf[_POSIX_PATH_MAX];
- char buf2[_POSIX_PATH_MAX];
-
- /* rotate the old debug logs */
- for (i = 3; i >= 0; i--)
- {
- snprintf(buf, sizeof(buf), "%s/.muttdebug%d", NONULL(Homedir), i);
- snprintf(buf2, sizeof(buf2), "%s/.muttdebug%d", NONULL(Homedir), i + 1);
- rename(buf, buf2);
- }
- if ((debugfile = safe_fopen(buf, "w")) != NULL)
- {
- setbuf(debugfile, NULL); /* don't buffer the debugging output! */
- mutt_debug(1, "NeoMutt %s%s (%s) debugging at level %d\n", PACKAGE_VERSION,
- GitVer, MUTT_VERSION, debuglevel);
- }
-}
-#endif
-
static int execute_commands(LIST *p)
{
BUFFER err, token;
Shell = safe_strdup((p = getenv("SHELL")) ? p : "/bin/sh");
}
+ /* Set standard defaults */
+ for (i = 0; MuttVars[i].option; i++)
+ {
+ set_default(&MuttVars[i]);
+ restore_default(&MuttVars[i]);
+ }
+
#ifdef DEBUG
- /* Start up debugging mode if requested */
- if (debuglevel > 0)
+ /* Start up debugging mode if requested from cmdline */
+ if (debuglevel_cmdline > 0)
+ {
+ debuglevel = debuglevel_cmdline;
start_debug();
+ }
#endif
/* And about the host... */
Matches = safe_calloc(Matches_listsize, sizeof(char *));
- /* Set standard defaults */
- for (i = 0; MuttVars[i].option; i++)
- {
- set_default(&MuttVars[i]);
- restore_default(&MuttVars[i]);
- }
-
CurrentMenu = MENU_MAIN;
#ifdef USE_NNTP
if ((i = getopt(argc, argv,
- "+A:a:Bb:F:f:c:Dd:Ee:g:GH:s:i:hm:npQ:RSvxyzZ")) != EOF)
+ "+A:a:Bb:F:f:c:Dd:l:Ee:g:GH:s:i:hm:npQ:RSvxyzZ")) != EOF)
#else
- if ((i = getopt(argc, argv, "+A:a:Bb:F:f:c:Dd:Ee:H:s:i:hm:npQ:RSvxyzZ")) != EOF)
+ if ((i = getopt(argc, argv,
+ "+A:a:Bb:F:f:c:Dd:l:Ee:H:s:i:hm:npQ:RSvxyzZ")) != EOF)
#endif
switch (i)
{
case 'd':
#ifdef DEBUG
- if (mutt_atoi(optarg, &debuglevel) < 0 || debuglevel <= 0)
+ if (mutt_atoi(optarg, &debuglevel_cmdline) < 0 || debuglevel_cmdline <= 0)
{
fprintf(stderr, _("Error: value '%s' is invalid for -d.\n"), optarg);
return 1;
}
- printf(_("Debugging at level %d.\n"), debuglevel);
+ printf(_("Debugging at level %d.\n"), debuglevel_cmdline);
#else
- printf(_("DEBUG was not defined during compilation. Ignored.\n"));
+ printf(_("DEBUG was not defined during compilation. -d Ignored.\n"));
#endif
break;
includeFile = optarg;
break;
+ case 'l':
+#ifdef DEBUG
+ debugfile_cmdline = optarg;
+ printf(_("Debugging at file %s.\n"), debugfile_cmdline);
+#else
+ printf(_("DEBUG was not defined during compilation. -l Ignored.\n"));
+#endif
+ break;
+
case 'm':
/* should take precedence over .muttrc setting, so save it for later */
newMagic = optarg;