This adds a new function to set the log level. This way, debuglevel is
not accessed directly, but through a mutt_log_* API.
---
lib.c | 10 ++++++++++
lib.h | 1 +
main.c | 10 +++++++---
3 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/lib.c b/lib.c
index 4b80639..eb04e3f 100644
--- a/lib.c
+++ b/lib.c
@@ -1037,6 +1037,16 @@ int mutt_log_init (const char *reldate, const char
*homedir)
return 0;
}
+
+int mutt_log_set_level (int level)
+{
+ if (level <= 0)
+ return 0;
+
+ debuglevel = level;
+
+ return level;
+}
#endif
void mutt_debug (FILE *fp, const char *fmt, ...)
diff --git a/lib.h b/lib.h
index 2ad091c..024484f 100644
--- a/lib.h
+++ b/lib.h
@@ -137,6 +137,7 @@ extern FILE *debugfile;
extern int debuglevel;
int mutt_log_init (const char *reldate, const char *homedir);
+int mutt_log_set_level (int level);
void mutt_debug (FILE *, const char *, ...);
# define dprint(N,X) do { if(debuglevel>=N && debugfile) mutt_debug X; }
while (0)
diff --git a/main.c b/main.c
index ffbb350..bbc1294 100644
--- a/main.c
+++ b/main.c
@@ -587,6 +587,9 @@ 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 */
@@ -674,12 +677,13 @@ int main (int argc, char **argv)
case 'd':
#ifdef DEBUG
- if (mutt_atoi (optarg, &debuglevel) < 0 || debuglevel <= 0)
- {
+ if (mutt_atoi (optarg, &loglevel) < 0 ||
+ !mutt_log_set_level (loglevel))
+ {
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"), loglevel);
#else
printf _("DEBUG was not defined during compilation. Ignored.\n");
#endif
--
2.9.0