Fix:core:Make command line option -d override the global debug level in navit.xml.
authorsleske <sleske@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 8 Jul 2012 19:15:00 +0000 (19:15 +0000)
committersleske <sleske@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 8 Jul 2012 19:15:00 +0000 (19:15 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@5186 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/debug.c
navit/navit/navit_shipped.xml
navit/navit/start_real.c

index 4fd4d1c..0bcbfe0 100644 (file)
@@ -53,7 +53,8 @@ static struct sockaddr_in debug_sin;
 
 
 int debug_level=0;
-int global_debug_level=0;
+#define GLOBAL_DEBUG_LEVEL_UNSET -1
+int global_debug_level=GLOBAL_DEBUG_LEVEL_UNSET;
 int segv_level=0;
 int timestamp_prefix=0;
 
@@ -105,6 +106,16 @@ debug_update_level(gpointer key, gpointer value, gpointer user_data)
 }
 
 void
+debug_set_global_level(int level, int override_old_value ) {
+       if (global_debug_level == GLOBAL_DEBUG_LEVEL_UNSET || override_old_value) {
+               global_debug_level=level;
+               if (debug_level < global_debug_level){
+                       debug_level = global_debug_level;
+               }
+       }
+}
+
+void
 debug_level_set(const char *name, int level)
 {
        if (!strcmp(name, "segv")) {
@@ -116,10 +127,7 @@ debug_level_set(const char *name, int level)
        } else if (!strcmp(name, "timestamps")) {
                timestamp_prefix=level;
        } else if (!strcmp(name, DEBUG_MODULE_GLOBAL)) {
-               global_debug_level=level;
-               if (debug_level < global_debug_level){
-                       debug_level = global_debug_level;
-               }
+               debug_set_global_level(level, 0);
        } else {
                g_hash_table_insert(debug_hash, g_strdup(name), GINT_TO_POINTER(level));
                g_hash_table_foreach(debug_hash, debug_update_level, NULL);
index 08e3cac..2d1c784 100644 (file)
@@ -14,7 +14,7 @@
                <plugin path="$NAVIT_LIBDIR/*/${NAVIT_LIBPREFIX}libgraphics_null.so" active="no"/>
        </plugins>
 
-       <!-- The global debug level (like using command line option "-d"). -->
+       <!-- The global debug level (like using command line option "-d"). Ignored if option -d is used. -->
        <debug name="global" level="0"/>
        <!-- Example of setting the debug level for a single function.  -->
        <debug name="navit:do_draw" level="0"/>
index 0865406..a11f0c2 100644 (file)
@@ -57,7 +57,12 @@ char **main_argv;
 static void
 print_usage(void)
 {
-       printf(_("navit usage:\nnavit [options] [configfile]\n\t-c <file>: use <file> as config file\n\t-d <n>: set the global debug output level to <n> (0-3).\n\t-h: print this usage info and exit.\n\t-v: Print the version and exit.\n"));
+       printf(_("navit usage:\n"
+       "navit [options] [configfile]\n"
+       "\t-c <file>: use <file> as config file\n"
+       "\t-d <n>: set the global debug output level to <n> (0-3). Overrides setting from config file.\n"
+       "\t-h: print this usage info and exit.\n"
+       "\t-v: Print the version and exit.\n"));
 }
 
 
@@ -114,7 +119,7 @@ int main_real(int argc, char **argv)
        if (argc == 2 && !strcmp(argv[1],"-RegisterForSystemEvents"))
                argc=1;
        if (argc > 1) {
-               /* DEVELOPPERS : don't forget to update the manpage if you modify theses options */
+               /* Don't forget to update the manpage if you modify theses options */
                while((opt = getopt(argc, argv, ":hvc:d:e:s:")) != -1) {
                        switch(opt) {
                        case 'h':
@@ -130,7 +135,7 @@ int main_real(int argc, char **argv)
                    config_file = optarg;
                                break;
                        case 'd':
-                               debug_level_set(DEBUG_MODULE_GLOBAL, atoi(optarg));
+                               debug_set_global_level(atoi(optarg), 1);
                                break;
                        case 'e':
                                command=optarg;