summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-10-26 12:57:55 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-10-26 12:57:55 +0000
commit012c91d5b8fab0bb75b98761a9b8096a1bd74009 (patch)
tree288d05e7181959ffc921e4fe059d8b59ad7bd149
parentcbaa1530774135e84360e1ebc552254b5e865444 (diff)
downloadnavit-012c91d5b8fab0bb75b98761a9b8096a1bd74009.tar.gz
Fix:Core:Further cleanup of xmlconfig
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@1566 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r--navit/attr.h1
-rw-r--r--navit/attr_def.h2
-rw-r--r--navit/binding/python/binding_python.c4
-rw-r--r--navit/debug.c15
-rw-r--r--navit/debug.h2
-rw-r--r--navit/map.c2
-rw-r--r--navit/map.h2
-rw-r--r--navit/mapset.c14
-rw-r--r--navit/mapset.h4
-rw-r--r--navit/navigation.c2
-rw-r--r--navit/navit.c25
-rw-r--r--navit/route.c2
-rw-r--r--navit/track.c2
-rw-r--r--navit/xmlconfig.c77
14 files changed, 64 insertions, 90 deletions
diff --git a/navit/attr.h b/navit/attr.h
index d070a3aca..ee3b6d22a 100644
--- a/navit/attr.h
+++ b/navit/attr.h
@@ -63,6 +63,7 @@ struct attr {
struct layout *layout;
struct layer *layer;
struct map *map;
+ struct mapset *mapset;
struct log *log;
struct route *route;
struct navigation *navigation;
diff --git a/navit/attr_def.h b/navit/attr_def.h
index 8640970a8..64b17a9af 100644
--- a/navit/attr_def.h
+++ b/navit/attr_def.h
@@ -78,6 +78,7 @@ ATTR(offset)
ATTR(directed)
ATTR(radius)
ATTR(text_size)
+ATTR(level)
ATTR2(0x00028000,type_boolean_begin)
/* boolean */
ATTR(overwrite)
@@ -199,6 +200,7 @@ ATTR(text)
ATTR(icon)
ATTR(image)
ATTR(arrows)
+ATTR(mapset)
ATTR2(0x0008ffff,type_object_end)
ATTR2(0x00090000,type_coord_begin)
ATTR2(0x0009ffff,type_coord_end)
diff --git a/navit/binding/python/binding_python.c b/navit/binding/python/binding_python.c
index b3e3ec28c..4fb623e59 100644
--- a/navit/binding/python/binding_python.c
+++ b/navit/binding/python/binding_python.c
@@ -194,7 +194,7 @@ map_new_py(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "ss:navit.map", &type, &filename))
return NULL;
ret=PyObject_NEW(mapObject, &map_Type);
- ret->m=map_new(NULL);
+ ret->m=map_new(NULL,NULL);
return (PyObject *)ret;
}
@@ -257,7 +257,7 @@ mapset_new_py(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, ":navit.mapset"))
return NULL;
ret=PyObject_NEW(mapsetObject, &mapset_Type);
- ret->ms=mapset_new();
+ ret->ms=mapset_new(NULL,NULL);
return (PyObject *)ret;
}
diff --git a/navit/debug.c b/navit/debug.c
index cfe14202d..d83d5469b 100644
--- a/navit/debug.c
+++ b/navit/debug.c
@@ -25,10 +25,12 @@
#include <time.h>
#include <glib.h>
#include "file.h"
+#include "item.h"
#include "debug.h"
int debug_level=0,segv_level=0;
+static int dummy;
static GHashTable *debug_hash;
static char *gdb_program;
@@ -78,6 +80,19 @@ debug_level_set(const char *name, int level)
}
}
+struct debug *
+debug_new(struct attr *parent, struct attr **attrs)
+{
+ struct attr *name,*level;
+ name=attr_search(attrs, NULL, attr_name);
+ level=attr_search(attrs, NULL, attr_level);
+ if (!name || !level)
+ return NULL;
+ debug_level_set(name->u.str, level->u.num);
+ return (struct debug *)&dummy;
+}
+
+
int
debug_level_get(const char *name)
{
diff --git a/navit/debug.h b/navit/debug.h
index 0d9512372..5a0317e89 100644
--- a/navit/debug.h
+++ b/navit/debug.h
@@ -33,9 +33,11 @@ extern int debug_level;
#define dbg_assert(expr) ((expr) ? (void) 0 : debug_assert_fail(dbg_module,strlen(dbg_module),__PRETTY_FUNCTION__, strlen(__PRETTY_FUNCTION__),__FILE__,__LINE__,dbg_str1(expr)))
/* prototypes */
+struct attr;
void debug_init(const char *program_name);
void debug_level_set(const char *name, int level);
int debug_level_get(const char *name);
+struct debug *debug_new(struct attr *parent, struct attr **attrs);
void debug_vprintf(int level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt, va_list ap);
void debug_printf(int level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt, ...);
void debug_assert_fail(char *module, const int mlen,const char *function, const int flen, char *file, int line, char *expr);
diff --git a/navit/map.c b/navit/map.c
index 934da5ff3..482665db5 100644
--- a/navit/map.c
+++ b/navit/map.c
@@ -88,7 +88,7 @@ struct map_rect {
* @return The opened map or NULL on failure
*/
struct map *
-map_new(struct attr **attrs)
+map_new(struct attr *parent, struct attr **attrs)
{
struct map *m;
struct map_priv *(*maptype_new)(struct map_methods *meth, struct attr **attrs);
diff --git a/navit/map.h b/navit/map.h
index bcbb10253..aac92917a 100644
--- a/navit/map.h
+++ b/navit/map.h
@@ -224,7 +224,7 @@ struct map_rect;
struct map_search;
struct map_selection;
struct pcoord;
-struct map *map_new(struct attr **attrs);
+struct map *map_new(struct attr *parent, struct attr **attrs);
int map_get_attr(struct map *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter);
int map_set_attr(struct map *this_, struct attr *attr);
void map_add_callback(struct map *this_, struct callback *cb);
diff --git a/navit/mapset.c b/navit/mapset.c
index 5001ef2c7..5ebec023d 100644
--- a/navit/mapset.c
+++ b/navit/mapset.c
@@ -49,7 +49,7 @@ struct mapset {
*
* @return The new mapset
*/
-struct mapset *mapset_new(void)
+struct mapset *mapset_new(struct attr *parent, struct attr **attrs)
{
struct mapset *ms;
@@ -58,15 +58,23 @@ struct mapset *mapset_new(void)
return ms;
}
+
/**
* @brief Adds a map to a mapset
*
* @param ms The mapset to add the map to
* @param m The map to be added
*/
-void mapset_add(struct mapset *ms, struct map *m)
+int
+mapset_add_attr(struct mapset *ms, struct attr *attr)
{
- ms->maps=g_list_append(ms->maps, m);
+ switch (attr->type) {
+ case attr_map:
+ ms->maps=g_list_append(ms->maps, attr->u.map);
+ return 1;
+ default:
+ return 0;
+ }
}
#if 0
diff --git a/navit/mapset.h b/navit/mapset.h
index acba75181..0e19010bd 100644
--- a/navit/mapset.h
+++ b/navit/mapset.h
@@ -27,8 +27,8 @@ struct map;
struct mapset;
struct mapset_handle;
struct mapset_search;
-struct mapset *mapset_new(void);
-void mapset_add(struct mapset *ms, struct map *m);
+struct mapset *mapset_new(struct attr *parent, struct attr **attrs);
+int mapset_add_attr(struct mapset *ms, struct attr *attr);
void mapset_destroy(struct mapset *ms);
struct mapset_handle *mapset_open(struct mapset *ms);
struct map *mapset_next(struct mapset_handle *msh, int active);
diff --git a/navit/navigation.c b/navit/navigation.c
index 1d0e60cd9..b705ac3b1 100644
--- a/navit/navigation.c
+++ b/navit/navigation.c
@@ -935,7 +935,7 @@ struct map *
navigation_get_map(struct navigation *this_)
{
if (! this_->map)
- this_->map=map_new((struct attr*[]){
+ this_->map=map_new(NULL, (struct attr*[]){
&(struct attr){attr_type,{"navigation"}},
&(struct attr){attr_navigation,.u.navigation=this_},
&(struct attr){attr_data,{""}},
diff --git a/navit/navit.c b/navit/navit.c
index a74c97d02..f0c690ffc 100644
--- a/navit/navit.c
+++ b/navit/navit.c
@@ -824,10 +824,11 @@ static void
navit_add_bookmarks_from_file(struct navit *this_)
{
char *bookmark_file = navit_get_bookmark_file(FALSE);
+ struct attr parent={attr_navit, .u.navit=this_};
struct attr type={attr_type, {"textfile"}}, data={attr_data, {bookmark_file}};
struct attr *attrs[]={&type, &data, NULL};
- this_->bookmark=map_new(attrs);
+ this_->bookmark=map_new(&parent, attrs);
g_free(bookmark_file);
}
@@ -835,10 +836,11 @@ static void
navit_add_former_destinations_from_file(struct navit *this_)
{
char *destination_file = navit_get_destination_file(FALSE);
+ struct attr parent={attr_navit, .u.navit=this_};
struct attr type={attr_type, {"textfile"}}, data={attr_data, {destination_file}};
struct attr *attrs[]={&type, &data, NULL};
- this_->former_destination=map_new(attrs);
+ this_->former_destination=map_new(&parent, attrs);
g_free(destination_file);
}
@@ -1206,9 +1208,13 @@ navit_init(struct navit *this_)
ms=this_->mapsets->data;
if (this_->route) {
if ((map=route_get_map(this_->route)))
- mapset_add(ms, map);
+ mapset_add_attr(ms, (struct attr*[]){
+ &(struct attr){attr_map,{map}},
+ NULL});
if ((map=route_get_graph_map(this_->route))) {
- mapset_add(ms, map);
+ mapset_add_attr(ms, (struct attr*[]){
+ &(struct attr){attr_map,{map}},
+ NULL});
map_set_attr(map, &(struct attr ){attr_active,.u.num=0});
}
route_set_mapset(this_->route, ms);
@@ -1221,13 +1227,17 @@ navit_init(struct navit *this_)
}
if (this_->navigation) {
if ((map=navigation_get_map(this_->navigation))) {
- mapset_add(ms, map);
+ mapset_add_attr(ms, (struct attr*[]){
+ &(struct attr){attr_map,{map}},
+ NULL});
map_set_attr(map, &(struct attr ){attr_active,.u.num=0});
}
}
if (this_->tracking) {
if ((map=tracking_get_map(this_->tracking))) {
- mapset_add(ms, map);
+ mapset_add_attr(ms, (struct attr*[]){
+ &(struct attr){attr_map,{map}},
+ NULL});
map_set_attr(map, &(struct attr ){attr_active,.u.num=0});
}
}
@@ -1505,6 +1515,9 @@ navit_add_attr(struct navit *this_, struct attr *attr)
case attr_route:
this_->route=attr->u.route;
break;
+ case attr_mapset:
+ this_->mapsets = g_list_append(this_->mapsets, attr->u.mapset);
+ break;
case attr_navigation:
this_->navigation=attr->u.navigation;
break;
diff --git a/navit/route.c b/navit/route.c
index 8bb224746..1cbc4204f 100644
--- a/navit/route.c
+++ b/navit/route.c
@@ -2267,7 +2267,7 @@ static struct map *
route_get_map_helper(struct route *this_, struct map **map, char *type, char *description)
{
if (! *map)
- *map=map_new((struct attr*[]){
+ *map=map_new(NULL, (struct attr*[]){
&(struct attr){attr_type,{type}},
&(struct attr){attr_route,.u.route=this_},
&(struct attr){attr_data,{""}},
diff --git a/navit/track.c b/navit/track.c
index 6111726a1..ef5cd0367 100644
--- a/navit/track.c
+++ b/navit/track.c
@@ -389,7 +389,7 @@ struct map *
tracking_get_map(struct tracking *this_)
{
if (! this_->map)
- this_->map=map_new((struct attr*[]){
+ this_->map=map_new(NULL, (struct attr*[]){
&(struct attr){attr_type,{"tracking"}},
&(struct attr){attr_trackingo,.u.tracking=this_},
&(struct attr){attr_data,{""}},
diff --git a/navit/xmlconfig.c b/navit/xmlconfig.c
index 44f036034..79d06e219 100644
--- a/navit/xmlconfig.c
+++ b/navit/xmlconfig.c
@@ -205,20 +205,6 @@ xmlconfig_speech(struct xmlstate *state)
}
static int
-xmlconfig_debug(struct xmlstate *state)
-{
- const char *name,*level;
- name=find_attribute(state, "name", 1);
- if (! name)
- return 0;
- level=find_attribute(state, "level", 1);
- if (! level)
- return 0;
- debug_level_set(name, convert_number(level));
- return 1;
-}
-
-static int
xmlconfig_window_items(struct xmlstate *state)
{
int distance=-1;
@@ -302,35 +288,6 @@ xmlconfig_speed(struct xmlstate *state)
static int
-xmlconfig_navigation(struct xmlstate *state)
-{
- struct attr **attrs;
- struct attr navigation_attr;
-
- attrs=convert_to_attrs(state,NULL);
- state->element_attr.u.data = navigation_new(attrs);
- if (! state->element_attr.u.data) {
- dbg(0,"Failed to create navigation object\n");
- return 0;
- }
- navigation_attr.type=attr_navigation;
- navigation_attr.u.navigation=state->element_attr.u.data;
- return navit_add_attr(state->parent->element_attr.u.data, &navigation_attr);
-}
-
-static int
-xmlconfig_osd(struct xmlstate *state)
-{
- struct attr **attrs;
- const char *type=find_attribute(state, "type", 1);
- if (! type)
- return 0;
- attrs=convert_to_attrs(state,NULL);
- state->element_attr.u.data = osd_new(state->parent->element_attr.u.data, type, attrs);
- return 1;
-}
-
-static int
xmlconfig_announce(struct xmlstate *state)
{
const char *type,*value;
@@ -362,30 +319,6 @@ xmlconfig_announce(struct xmlstate *state)
return 1;
}
-static int
-xmlconfig_mapset(struct xmlstate *state)
-{
- state->element_attr.u.data = mapset_new();
- if (! state->element_attr.u.data)
- return 0;
- navit_add_mapset(state->parent->element_attr.u.data, state->element_attr.u.data);
-
- return 1;
-}
-
-static int
-xmlconfig_map(struct xmlstate *state)
-{
- struct attr **attrs;
- attrs=convert_to_attrs(state,NULL);
- state->element_attr.u.data = map_new(attrs);
- if (! state->element_attr.u.data)
- return 0;
- mapset_add(state->parent->element_attr.u.data, state->element_attr.u.data);
-
- return 1;
-}
-
#define NEW(x) (void *(*)(struct attr *, struct attr **))(x)
#define ADD(x) (int (*)(void *, struct attr *attr))(x)
#define INIT(x) (int (*)(void *))(x)
@@ -400,16 +333,16 @@ struct element_func {
void (*destroy)(void *);
} elements[] = {
{ "config", NULL, xmlconfig_config},
- { "debug", "config", xmlconfig_debug},
- { "mapset", "navit", xmlconfig_mapset},
- { "map", "mapset", xmlconfig_map},
- { "navigation", "navit", xmlconfig_navigation},
- { "osd", "navit", xmlconfig_osd},
{ "announce", "navigation", xmlconfig_announce},
{ "speech", "navit", xmlconfig_speech},
{ "tracking", "navit", xmlconfig_tracking},
{ "route", "navit", xmlconfig_route},
{ "speed", "route", xmlconfig_speed},
+ { "mapset", "navit", NULL, NEW(mapset_new), ADD(mapset_add_attr)},
+ { "map", "mapset", NULL, NEW(map_new)},
+ { "debug", "config", NULL, NEW(debug_new)},
+ { "osd", "navit", NULL, NEW(osd_new)},
+ { "navigation", "navit", NULL, NEW(navigation_new)},
{ "navit", "config", NULL, NEW(navit_new), ADD(navit_add_attr), INIT(navit_init), DESTROY(navit_destroy)},
{ "graphics", "navit", NULL, NEW(graphics_new)},
{ "gui", "navit", NULL, NEW(gui_new)},