Mercurial > geeqie
changeset 378:f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
--debug[=level] syntax.
Only display message indication debug level once.
author | zas_ |
---|---|
date | Tue, 15 Apr 2008 21:47:03 +0000 |
parents | 9efefd85684a |
children | a430eb2e3c95 |
files | src/main.c |
diffstat | 1 files changed, 38 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main.c Tue Apr 15 21:06:00 2008 +0000 +++ b/src/main.c Tue Apr 15 21:47:03 2008 +0000 @@ -952,14 +952,10 @@ parse_command_line_process_file(cmd_all, path, file, &list, collection_list, &first_dir); } -#ifdef DEBUG - else if (strcmp(cmd_line, "--debug") == 0) + else if (strncmp(cmd_line, "--debug", 7) == 0 && (cmd_line[7] == '\0' || cmd_line[7] == '=')) { - /* we now increment the debug state for verbosity */ - debug++; - printf("debugging output enabled (level %d)\n", debug); + /* do nothing but do not produce warnings */ } -#endif else if (strcmp(cmd_line, "+t") == 0 || strcmp(cmd_line, "--with-tools") == 0) { @@ -1100,6 +1096,40 @@ } } +static void parse_command_line_for_debug_option(int argc, char *argv[]) +{ +#ifdef DEBUG + const gchar *debug_option = "--debug"; + gint len = strlen(debug_option); + + if (argc > 1) + { + gint i; + + for (i = 1; i < argc; i++) + { + const gchar *cmd_line = argv[i]; + if (strncmp(cmd_line, debug_option, len) == 0) + { + gint cmd_line_len = strlen(cmd_line); + + /* we now increment the debug state for verbosity */ + if (cmd_line_len == len) + debug++; + else if (cmd_line[len] == '=' && g_ascii_isdigit(cmd_line[len+1])) + { + gint n = atoi(cmd_line + len + 1); + if (n < 0) n = 1; + debug += n; + } + } + } + } + + if (debug > 0) printf("debugging output enabled (level %d)\n", debug); +#endif +} + /* *----------------------------------------------------------------------------- * startup, init, and exit @@ -1321,6 +1351,8 @@ #if 1 printf("%s %s, This is an alpha release.\n", GQ_APPNAME, VERSION); #endif + parse_command_line_for_debug_option(argc, argv); + options = init_options(NULL); setup_default_options(); load_options();