Add:Core:Added a debug map
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Thu, 14 Feb 2008 18:09:41 +0000 (18:09 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Thu, 14 Feb 2008 18:09:41 +0000 (18:09 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@866 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/src/navit.c
navit/src/xmlconfig.c

index 210363c..d0c9c12 100644 (file)
@@ -32,6 +32,7 @@
 #include "vehicle.h"
 #include "color.h"
 #include "layout.h"
+#include "log.h"
 
 #define _(STRING)    gettext(STRING)
 /**
@@ -97,6 +98,7 @@ struct navit {
        struct point pressed, last, current;
        int button_pressed,moved,popped;
        guint button_timeout, motion_timeout;
+       struct log *textfile_debug_log;
 };
 
 struct gui *main_loop_gui;
@@ -794,6 +796,23 @@ navit_add_menu_vehicle(struct navit *this_, struct menu *men)
 }
 
 void
+navit_textfile_debug_log(struct navit *this_, const char *fmt, ...)
+{
+       va_list ap;
+       char *str1,*str2;
+       va_start(ap, fmt);
+       if (this_->textfile_debug_log && this_->vehicle) {
+               str1=g_strdup_vprintf(fmt, ap);
+               str2=g_strdup_printf("0x%x 0x%x%s%s\n", this_->vehicle->coord.x, this_->vehicle->coord.y, strlen(str1) ? " " : "", str1);
+               log_write(this_->textfile_debug_log, str2, strlen(str2));
+               g_free(str2);
+               g_free(str1);
+       }
+               va_end(ap);
+}
+
+
+void
 navit_speak(struct navit *this_)
 {
        struct navigation *nav=this_->navigation;
@@ -808,8 +827,10 @@ navit_speak(struct navit *this_)
                mr=map_rect_new(map, NULL);
        if (mr) {
                item=map_rect_get_item(mr);
-               if (item && item_attr_get(item, attr_navigation_speech, &attr))
+               if (item && item_attr_get(item, attr_navigation_speech, &attr)) {
                        speech_say(this_->speech, attr.u.str);
+                       navit_textfile_debug_log(this_, "item=point_debug debug=\"speech_say('%s')\"", attr.u.str);
+               }
                map_rect_destroy(mr);
        }
 }
@@ -1317,6 +1338,36 @@ navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr)
        return 1;
 }
 
+static int
+navit_add_log(struct navit *this_, struct log *log,
+                struct attr **attrs)
+{
+       struct attr *type;
+       type = attr_search(attrs, NULL, attr_type);
+       if (!type)
+               return 1;
+       if (!strcmp(type->u.str, "textfile_debug")) {
+               if (this_->textfile_debug_log)
+                       return 1;
+               this_->textfile_debug_log=log;
+               return 0;
+       }
+       return 1;
+}
+
+int
+navit_add_attr(struct navit *this_, struct attr *attr,
+                 struct attr **attrs)
+{
+       switch (attr->type) {
+       case attr_log:
+               return navit_add_log(this_, attr->u.log, attrs);
+       default:
+               return 0;
+       }
+       return 1;
+}
+
 void
 navit_add_attr_cb(struct navit *this_, struct callback *cb)
 {
index 2867c50..97c6c25 100644 (file)
@@ -147,7 +147,7 @@ convert_number(const char *val)
 static int
 xmlconfig_config(struct xmlstate *state)
 {
-       state->element_object = 1;
+       state->element_object = (void *)1;
        return 1;
 }
 
@@ -262,7 +262,7 @@ xmlconfig_vehicle(struct xmlstate *state)
 }
 
 static int
-xmlconfig_log(struct xmlstate *state)
+xmlconfig_log_vehicle(struct xmlstate *state)
 {
        struct attr attr;
        struct attr **attrs;
@@ -277,6 +277,22 @@ xmlconfig_log(struct xmlstate *state)
        return 1;
 }
 
+static int
+xmlconfig_log_navit(struct xmlstate *state)
+{
+       struct attr attr;
+       struct attr **attrs;
+       attrs=convert_to_attrs(state);
+       state->element_object = log_new(attrs);
+       if (! state->element_object)
+               return 0;
+       attr.type=attr_log;
+       attr.u.log=state->element_object;
+       if (navit_add_attr(state->parent->element_object, &attr, attrs))
+               return 0;
+       return 1;
+}
+
 
 static int
 xmlconfig_window_items(struct xmlstate *state)
@@ -627,7 +643,8 @@ struct element_func {
        { "route", "navit", xmlconfig_route},
        { "speed", "route", xmlconfig_speed},
        { "vehicle", "navit", xmlconfig_vehicle},
-       { "log", "vehicle", xmlconfig_log},
+       { "log", "vehicle", xmlconfig_log_vehicle},
+       { "log", "navit", xmlconfig_log_navit},
        { "window_items", "navit", xmlconfig_window_items},
        { "plugins", "config", xmlconfig_plugins},
        { "plugin", "plugins", xmlconfig_plugin},
@@ -644,28 +661,39 @@ start_element (GMarkupParseContext *context,
 {
        struct xmlstate *new=NULL, **parent = user_data;
        struct element_func *e=elements,*func=NULL;
+       int found=0;
        const char *parent_name=NULL;
+       char *s,*sep="",*possible_parents=g_strdup("");
        dbg(2,"name='%s'\n", element_name);
+       if (*parent)
+               parent_name=(*parent)->element;
        while (e->name) {
                if (!g_ascii_strcasecmp(element_name, e->name)) {
-                       func=e;
+                       found=1;
+                       s=g_strconcat(possible_parents,sep,e->parent,NULL);
+                       g_free(possible_parents);
+                       possible_parents=s;
+                       sep=",";
+                       if ((parent_name && e->parent && !g_ascii_strcasecmp(parent_name, e->parent)) ||
+                           (!parent_name && !e->parent))
+                               func=e;
                }
                e++;
        }
-       if (! func) {
+       if (! found) {
                g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_UNKNOWN_ELEMENT,
                                "Unknown element '%s'", element_name);
+               g_free(possible_parents);
                return;
        }
-       if (*parent)
-               parent_name=(*parent)->element;
-       if ((parent_name && func->parent && g_ascii_strcasecmp(parent_name, func->parent)) || 
-           (!parent_name && func->parent) || (parent_name && !func->parent)) {
+       if (! func) {
                g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_INVALID_CONTENT,
                                "Element '%s' within unexpected context '%s'. Expected '%s'%s",
-                               element_name, parent_name, func->parent, ! strcmp(func->parent,"config") ? "\nPlease add <config> </config> tags at the beginning/end of your navit.xml": "");
+                               element_name, parent_name, possible_parents, ! strcmp(possible_parents, "config") ? "\nPlease add <config> </config> tags at the beginning/end of your navit.xml": "");
+               g_free(possible_parents);
                return;
        }
+       g_free(possible_parents);
 
        new=g_new(struct xmlstate, 1);
        new->attribute_names=attribute_names;