summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2009-11-02 11:10:26 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2009-11-02 11:10:26 +0000
commit1e3fc12eb944b01388c1a60fdf5af09d8f6f6689 (patch)
treed13d3166a710835007f887f05251c77bcc5fedf3
parent2184a5c28f06277b0acde6fb9274fbb77c3ff2fe (diff)
downloadnavit-1e3fc12eb944b01388c1a60fdf5af09d8f6f6689.tar.gz
Fix:Core:Split out main_ functions from main.c, updated dtd
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@2715 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r--navit/Makefile.am4
-rw-r--r--navit/attr_def.h1
-rw-r--r--navit/config_.c137
-rw-r--r--navit/config_.h15
-rw-r--r--navit/main.c80
-rw-r--r--navit/navit.c2
-rw-r--r--navit/navit.dtd66
-rw-r--r--navit/start_real.c4
-rw-r--r--navit/xmlconfig.c20
9 files changed, 221 insertions, 108 deletions
diff --git a/navit/Makefile.am b/navit/Makefile.am
index 36d2257fa..01968c40f 100644
--- a/navit/Makefile.am
+++ b/navit/Makefile.am
@@ -29,11 +29,11 @@ pkgdata_DATA = navit.xml
EXTRA_DIST = navit_shipped.xml navit.dtd
-libnavit_la_SOURCES = announcement.c atom.c attr.c cache.c callback.c command.c compass.c coord.c country.c data_window.c debug.c \
+libnavit_la_SOURCES = announcement.c atom.c attr.c cache.c callback.c command.c compass.c config_.c coord.c country.c data_window.c debug.c \
event.c event_glib.h file.c graphics.c gui.c item.c layout.c log.c main.c map.c \
linguistics.c mapset.c maptype.c menu.c messages.c navit.c navigation.c osd.c param.c phrase.c plugin.c popup.c \
profile.c projection.c roadprofile.c route.c search.c speech.c start_real.c transform.c track.c \
- util.c vehicle.c vehicleprofile.c xmlconfig.c announcement.h atom.h attr.h attr_def.h cache.h callback.h color.h command.h compass.h coord.h country.h \
+ util.c vehicle.c vehicleprofile.c xmlconfig.c announcement.h atom.h attr.h attr_def.h cache.h callback.h color.h command.h compass.h config_.h coord.h country.h \
data.h data_window.h data_window_int.h debug.h destination.h draw_info.h endianess.h event.h \
file.h graphics.h gtkext.h gui.h item.h item_def.h keys.h log.h layer.h layout.h linguistics.h main.h map-share.h map.h\
map_data.h mapset.h maptype.h menu.h messages.h navigation.h navit.h osd.h \
diff --git a/navit/attr_def.h b/navit/attr_def.h
index 4b1245ba7..cad04f50f 100644
--- a/navit/attr_def.h
+++ b/navit/attr_def.h
@@ -324,6 +324,7 @@ ATTR(vehicleprofile)
ATTR(roadprofile)
ATTR(announcement)
ATTR(cursor)
+ATTR(config)
ATTR2(0x0008ffff,type_object_end)
ATTR2(0x00090000,type_coord_begin)
ATTR2(0x0009ffff,type_coord_end)
diff --git a/navit/config_.c b/navit/config_.c
new file mode 100644
index 000000000..4eecfe101
--- /dev/null
+++ b/navit/config_.c
@@ -0,0 +1,137 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <stdlib.h>
+#include <glib.h>
+#include "debug.h"
+#include "item.h"
+#include "callback.h"
+#include "config_.h"
+
+struct config {
+ struct attr **attrs;
+ struct callback_list *cbl;
+} *config;
+
+struct attr_iter {
+ void *iter;
+};
+
+void
+config_destroy(struct config *this_)
+{
+ attr_list_free(this_->attrs);
+ callback_list_destroy(this_->cbl);
+ g_free(config);
+ dbg(0,"exit");
+ exit(0);
+}
+
+int
+config_get_attr(struct config *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
+{
+ dbg(0,"enter\n");
+ return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
+}
+
+static int
+config_set_attr_int(struct config *this_, struct attr *attr)
+{
+ switch (attr->type) {
+ case attr_language:
+ setenv("LANG",attr->u.str,1);
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+int
+config_set_attr(struct config *this_, struct attr *attr)
+{
+ return config_set_attr_int(this_, attr);
+}
+
+int
+config_add_attr(struct config *this_, struct attr *attr)
+{
+ switch (attr->type) {
+ case attr_callback:
+ callback_list_add(this_->cbl, attr->u.callback);
+ default:
+ this_->attrs=attr_generic_add_attr(this_->attrs, attr);
+ }
+ callback_list_call_attr_2(this_->cbl, attr->type, attr->u.data, 1);
+ return 1;
+}
+
+int
+config_remove_attr(struct config *this_, struct attr *attr)
+{
+ switch (attr->type) {
+ case attr_callback:
+ callback_list_remove(this_->cbl, attr->u.callback);
+ default:
+ this_->attrs=attr_generic_remove_attr(this_->attrs, attr);
+ }
+ callback_list_call_attr_2(this_->cbl, attr->type, attr->u.data, -1);
+ return 1;
+}
+
+struct attr_iter *
+config_attr_iter_new()
+{
+ dbg(0,"enter\n");
+ return g_new0(struct attr_iter, 1);
+}
+
+void
+config_attr_iter_destroy(struct attr_iter *iter)
+{
+ dbg(0,"enter\n");
+ g_free(iter);
+}
+
+
+struct config *
+config_new(struct attr *parent, struct attr **attrs)
+{
+ dbg(0,"enter\n");
+ if (config) {
+ dbg(0,"only one config allowed\n");
+ return NULL;
+ }
+ if (parent) {
+ dbg(0,"no parent in config allowed\n");
+ return NULL;
+ }
+ config=g_new0(struct config, 1);
+ config->attrs=attr_list_dup(attrs);
+ config->cbl=callback_list_new();
+ while (*attrs) {
+ if (!config_set_attr_int(config,*attrs)) {
+ dbg(0,"failed to set attribute '%s'\n",attr_to_name((*attrs)->type));
+ config_destroy(config);
+ config=NULL;
+ break;
+ }
+ attrs++;
+ }
+ return config;
+}
diff --git a/navit/config_.h b/navit/config_.h
new file mode 100644
index 000000000..9f47e995e
--- /dev/null
+++ b/navit/config_.h
@@ -0,0 +1,15 @@
+extern struct config *config;
+/* prototypes */
+enum attr_type;
+struct attr;
+struct attr_iter;
+struct config;
+void config_destroy(struct config *this_);
+int config_get_attr(struct config *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter);
+int config_set_attr(struct config *this_, struct attr *attr);
+int config_add_attr(struct config *this_, struct attr *attr);
+int config_remove_attr(struct config *this_, struct attr *attr);
+struct attr_iter *config_attr_iter_new(void);
+void config_attr_iter_destroy(struct attr_iter *iter);
+struct config *config_new(struct attr *parent, struct attr **attrs);
+/* end of prototypes */
diff --git a/navit/main.c b/navit/main.c
index 2910196ed..8be01176a 100644
--- a/navit/main.c
+++ b/navit/main.c
@@ -65,86 +65,6 @@ static void sigchld(int sig)
#endif
}
-static GList *navit;
-
-struct iter {
- GList *list;
-};
-
-struct iter *
-main_iter_new(void)
-{
- struct iter *ret=g_new0(struct iter, 1);
- ret->list=navit;
- return ret;
-}
-
-void
-main_iter_destroy(struct iter *iter)
-{
- g_free(iter);
-}
-
-struct navit *
-main_get_navit(struct iter *iter)
-{
- GList *list;
- struct navit *ret=NULL;
- if (iter)
- list=iter->list;
- else
- list=navit;
- if (list) {
- ret=(struct navit *)(list->data);
- if (iter)
- iter->list=g_list_next(iter->list);
- }
- return ret;
-
-}
-void
-main_add_navit(struct navit *nav)
-{
- navit=g_list_prepend(navit, nav);
- callback_list_call_2(cbl, nav, 1);
-}
-
-void
-main_remove_navit(struct navit *nav)
-{
- navit=g_list_remove(navit, nav);
- callback_list_call_2(cbl, nav, 0);
- if (! navit)
- event_main_loop_quit();
-}
-
-int
-main_add_attr(struct attr *attr)
-{
- switch (attr->type)
- {
- case attr_callback:
- callback_list_add(cbl, attr->u.callback);
- return 1;
- default:
- return 0;
- }
-}
-
-int
-main_remove_attr(struct attr *attr)
-{
- switch (attr->type)
- {
- case attr_callback:
- callback_list_remove(cbl, attr->u.callback);
- return 1;
- default:
- return 0;
- }
-}
-
-
#ifdef HAVE_API_WIN32
void
setenv(char *var, char *val, int overwrite)
diff --git a/navit/navit.c b/navit/navit.c
index d5eaaf1c5..72c2934a2 100644
--- a/navit/navit.c
+++ b/navit/navit.c
@@ -638,7 +638,6 @@ navit_new(struct attr *parent, struct attr **attrs)
this_->self.type=attr_navit;
this_->self.u.navit=this_;
this_->attr_cbl=callback_list_new();
- main_add_navit(this_);
this_->bookmarks_hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
@@ -2272,7 +2271,6 @@ navit_destroy(struct navit *this_)
/* TODO: destroy objects contained in this_ */
if (this_->vehicle)
vehicle_destroy(this_->vehicle->vehicle);
- main_remove_navit(this_);
char *center_file = navit_get_center_file(TRUE);
navit_write_center_to_file(this_, center_file);
g_free(center_file);
diff --git a/navit/navit.dtd b/navit/navit.dtd
index 4abbabcec..8c3fbc2db 100644
--- a/navit/navit.dtd
+++ b/navit/navit.dtd
@@ -1,19 +1,27 @@
<!ELEMENT config (plugins,debug*,navit)>
<!ATTLIST config xmlns:xi CDATA #REQUIRED>
+<!ATTLIST config language CDATA #IMPLIED>
<!ELEMENT plugins (plugin*)>
<!ELEMENT plugin EMPTY>
<!ATTLIST plugin path CDATA #REQUIRED>
<!ATTLIST plugin active CDATA #IMPLIED>
+<!ATTLIST plugin ondemand CDATA #IMPLIED>
<!ELEMENT debug EMPTY>
<!ATTLIST debug name CDATA #REQUIRED>
<!ATTLIST debug level CDATA "0">
-<!ELEMENT navit (gui,graphics,vehicle*,tracking,route,navigation,speech,mapset+,layout+)>
+<!ELEMENT log EMPTY>
+<!ATTLIST log enabled CDATA #IMPLIED>
+<!ATTLIST log type CDATA #REQUIRED>
+<!ATTLIST log data CDATA #REQUIRED>
+<!ATTLIST log flush_size CDATA #IMPLIED>
+<!ATTLIST log flush_time CDATA #IMPLIED>
+<!ELEMENT navit (gui,graphics,vehicle*,vehicleprofile*,tracking,route,navigation,speech,osd*,mapset+,layout+,log*)>
<!ATTLIST navit center CDATA #REQUIRED>
<!ATTLIST navit zoom CDATA #REQUIRED>
<!ATTLIST navit tracking CDATA #REQUIRED>
-<!ATTLIST navit cursor CDATA #REQUIRED>
<!ATTLIST navit orientation CDATA #REQUIRED>
<!ATTLIST navit recent_dest CDATA #IMPLIED>
+<!ATTLIST navit drag_bitmap CDATA #IMPLIED>
<!ELEMENT gui EMPTY>
<!ATTLIST gui type CDATA #REQUIRED>
<!ATTLIST gui menubar CDATA #IMPLIED>
@@ -23,18 +31,36 @@
<!ATTLIST gui fullscreen CDATA #IMPLIED>
<!ELEMENT graphics EMPTY>
<!ATTLIST graphics type CDATA #REQUIRED>
-<!ELEMENT vehicle (cursor)>
+<!ELEMENT vehicle (cursor*)>
<!ATTLIST vehicle name CDATA #REQUIRED>
<!ATTLIST vehicle source CDATA #REQUIRED>
-<!ATTLIST vehicle color CDATA #REQUIRED>
<!ATTLIST vehicle enabled CDATA #IMPLIED>
<!ATTLIST vehicle active CDATA #IMPLIED>
<!ATTLIST vehicle follow CDATA #IMPLIED>
<!ATTLIST vehicle update CDATA #IMPLIED>
<!ATTLIST vehicle gpsd_query CDATA #IMPLIED>
-<!ELEMENT cursor EMPTY>
+<!ATTLIST vehicle profilename CDATA #IMPLIED>
+<!ELEMENT vehicleprofile (roadprofile+)>
+<!ATTLIST vehicleprofile name CDATA #REQUIRED>
+<!ATTLIST vehicleprofile flags CDATA #REQUIRED>
+<!ATTLIST vehicleprofile flags_forward_mask CDATA #REQUIRED>
+<!ATTLIST vehicleprofile flags_reverse_mask CDATA #REQUIRED>
+<!ATTLIST vehicleprofile maxspeed_handling CDATA #REQUIRED>
+<!ATTLIST vehicleprofile route_mode CDATA #REQUIRED>
+<!ELEMENT coord EMPTY>
+<!ATTLIST coord x CDATA #REQUIRED>
+<!ATTLIST coord y CDATA #REQUIRED>
+<!ELEMENT cursor (itemgra+)>
+<!ATTLIST cursor w CDATA #REQUIRED>
+<!ATTLIST cursor h CDATA #REQUIRED>
<!ELEMENT tracking ANY>
-<!ELEMENT route (speed+)>
+<!ATTLIST tracking cdf_histsize CDATA #IMPLIED>
+<!ELEMENT route EMPTY>
+<!ATTLIST route destination_distance CDATA #IMPLIED>
+<!ELEMENT roadprofile (announcement*)>
+<!ATTLIST roadprofile item_types CDATA #REQUIRED>
+<!ATTLIST roadprofile speed CDATA #REQUIRED>
+<!ATTLIST roadprofile route_weight CDATA #REQUIRED>
<!ELEMENT speed EMPTY>
<!ATTLIST speed type CDATA #REQUIRED>
<!ATTLIST speed value CDATA #REQUIRED>
@@ -45,10 +71,14 @@
<!ATTLIST announce level1 CDATA #IMPLIED>
<!ATTLIST announce level2 CDATA #IMPLIED>
<!ATTLIST announce unit CDATA #REQUIRED>
+<!ELEMENT announcement EMPTY>
+<!ATTLIST announcement level CDATA #REQUIRED>
+<!ATTLIST announcement distance_metric CDATA #REQUIRED>
<!ELEMENT speech EMPTY>
<!ATTLIST speech type CDATA #REQUIRED>
<!ATTLIST speech data CDATA #REQUIRED>
-<!ELEMENT mapset (map+)>
+<!ATTLIST speech cps CDATA #IMPLIED>
+<!ELEMENT mapset (map*,xi:include*)>
<!ATTLIST mapset enabled CDATA #IMPLIED>
<!ELEMENT map EMPTY>
<!ATTLIST map type CDATA #REQUIRED>
@@ -56,20 +86,28 @@
<!ATTLIST map active CDATA #IMPLIED>
<!ATTLIST map data CDATA #REQUIRED>
<!ATTLIST map debug CDATA #IMPLIED>
-<!ELEMENT layout (layer*)>
+<!ELEMENT layout (cursor*,layer*,xi:include*)>
<!ATTLIST layout name CDATA #REQUIRED>
<!ATTLIST layout color CDATA #IMPLIED>
<!ATTLIST layout font CDATA #IMPLIED>
-<!ELEMENT layer (itemgra+)>
+<!ELEMENT layer (itemgra*)>
+<!ATTLIST layer enabled CDATA #IMPLIED>
<!ATTLIST layer name CDATA #IMPLIED>
<!ATTLIST layer details CDATA #IMPLIED>
+<!ELEMENT osd EMPTY>
+<!ATTLIST osd enabled CDATA #IMPLIED>
+<!ATTLIST osd type CDATA #REQUIRED>
+<!ATTLIST osd x CDATA #IMPLIED>
+<!ATTLIST osd y CDATA #IMPLIED>
+<!ATTLIST osd src CDATA #IMPLIED>
+<!ATTLIST osd command CDATA #IMPLIED>
<!ELEMENT itemgra (polygon|polyline|text|circle|icon|image|arrows)*>
<!ATTLIST itemgra item_types CDATA #IMPLIED>
<!ATTLIST itemgra order CDATA #IMPLIED>
<!ATTLIST itemgra speed_range CDATA #IMPLIED>
-<!ELEMENT polygon EMPTY>
+<!ELEMENT polygon (coord*)>
<!ATTLIST polygon color CDATA #REQUIRED>
-<!ELEMENT polyline EMPTY>
+<!ELEMENT polyline (coord*)>
<!ATTLIST polyline color CDATA #REQUIRED>
<!ATTLIST polyline width CDATA #IMPLIED>
<!ATTLIST polyline dash CDATA #IMPLIED>
@@ -77,7 +115,7 @@
<!ELEMENT text EMPTY>
<!ATTLIST text text_size CDATA #REQUIRED>
<!ATTLIST text color CDATA #IMPLIED>
-<!ELEMENT circle EMPTY>
+<!ELEMENT circle (coord*)>
<!ATTLIST circle color CDATA #REQUIRED>
<!ATTLIST circle radius CDATA #REQUIRED>
<!ATTLIST circle width CDATA #IMPLIED>
@@ -90,4 +128,6 @@
<!ATTLIST arrows color CDATA #REQUIRED>
<!ATTLIST arrows width CDATA #IMPLIED>
<!ELEMENT image EMPTY>
-
+<!ELEMENT xi:include EMPTY>
+<!ATTLIST xi:include href CDATA #IMPLIED>
+<!ATTLIST xi:include xpointer CDATA #IMPLIED>
diff --git a/navit/start_real.c b/navit/start_real.c
index c647850de..44f8279c1 100644
--- a/navit/start_real.c
+++ b/navit/start_real.c
@@ -22,6 +22,7 @@
#include <glib.h>
#include <getopt.h>
#include "config.h"
+#include "config_.h"
#include "version.h"
#include "item.h"
#include "coord.h"
@@ -59,6 +60,7 @@ int main_real(int argc, char **argv)
char *config_file = NULL;
int opt;
char *cp;
+ struct attr navit;
GList *list = NULL, *li;
@@ -165,7 +167,7 @@ int main_real(int argc, char **argv)
li = g_list_next(li);
}
g_list_free(list);
- if (! main_get_navit(NULL)) {
+ if (! config_get_attr(config, attr_navit, &navit, NULL)) {
dbg(0, _("No instance has been created, exiting\n"));
exit(1);
}
diff --git a/navit/xmlconfig.c b/navit/xmlconfig.c
index cbf8a8c42..442efc2fe 100644
--- a/navit/xmlconfig.c
+++ b/navit/xmlconfig.c
@@ -47,6 +47,7 @@
#include "announcement.h"
#include "vehicleprofile.h"
#include "roadprofile.h"
+#include "config_.h"
#include "xmlconfig.h"
#ifdef HAVE_GLIB
@@ -186,13 +187,6 @@ convert_number(const char *val)
}
static int
-xmlconfig_config(struct xmlstate *state)
-{
- state->element_attr.u.data = (void *)1;
- return 1;
-}
-
-static int
xmlconfig_announce(struct xmlstate *state)
{
const char *type,*value;
@@ -242,6 +236,7 @@ static struct object_func object_funcs[] = {
{ attr_announcement,NEW(announcement_new), GET(announcement_get_attr), NULL, NULL, SET(announcement_set_attr), ADD(announcement_add_attr) },
{ attr_arrows, NEW(arrows_new)},
{ attr_circle, NEW(circle_new), NULL, NULL, NULL, NULL, ADD(element_add_attr)},
+ { attr_config, NEW(config_new), GET(config_get_attr), ITERN(config_attr_iter_new), ITERD(config_attr_iter_destroy), SET(config_set_attr), ADD(config_add_attr), REMOVE(config_remove_attr), NULL, DESTROY(config_destroy)},
{ attr_coord, NEW(coord_new_from_attrs)},
{ attr_cursor, NEW(cursor_new), NULL, NULL, NULL, NULL, ADD(cursor_add_attr)},
{ attr_debug, NEW(debug_new)},
@@ -288,7 +283,7 @@ struct element_func {
int (*func)(struct xmlstate *state);
enum attr_type type;
} elements[] = {
- { "config", NULL, xmlconfig_config},
+ { "config", NULL, NULL, attr_config},
{ "announce", "navigation", xmlconfig_announce},
{ "speech", "navit", NULL, attr_speech},
{ "tracking", "navit", NULL, attr_tracking},
@@ -388,6 +383,7 @@ start_element(GMarkupParseContext *context,
static int fixme_count;
const char *parent_name=NULL;
char *s,*sep="",*possible_parents;
+ struct attr *parent_attr;
dbg(2,"name='%s' parent='%s'\n", element_name, *parent ? (*parent)->element:NULL);
/* determine if we have to fix any attributes */
@@ -467,13 +463,17 @@ start_element(GMarkupParseContext *context,
return;
attrs=convert_to_attrs(new,attr_fixme);
new->element_attr.type=attr_none;
- new->element_attr.u.data = new->object_func->new(&new->parent->element_attr, attrs);
+ if (!new->parent || new->parent->element_attr.type == attr_none)
+ parent_attr=NULL;
+ else
+ parent_attr=&new->parent->element_attr;
+ new->element_attr.u.data = new->object_func->new(parent_attr, attrs);
if (! new->element_attr.u.data)
return;
new->element_attr.type=attr_from_name(element_name);
if (new->element_attr.type == attr_none)
dbg(0,"failed to create object of type '%s'\n", element_name);
- if (new->parent->object_func && new->parent->object_func->add_attr)
+ if (new->parent && new->parent->object_func && new->parent->object_func->add_attr)
new->parent->object_func->add_attr(new->parent->element_attr.u.data, &new->element_attr);
}
return;