#include "vehicle.h"
#include "color.h"
#include "layout.h"
+#include "log.h"
#define _(STRING) gettext(STRING)
/**
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;
}
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;
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);
}
}
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)
{
static int
xmlconfig_config(struct xmlstate *state)
{
- state->element_object = 1;
+ state->element_object = (void *)1;
return 1;
}
}
static int
-xmlconfig_log(struct xmlstate *state)
+xmlconfig_log_vehicle(struct xmlstate *state)
{
struct attr attr;
struct attr **attrs;
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)
{ "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},
{
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;