From: martin-s Date: Mon, 2 Nov 2009 11:10:26 +0000 (+0000) Subject: Fix:Core:Split out main_ functions from main.c, updated dtd X-Git-Tag: navit-0.5.0.5194svn~2476 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fbda5c06c85410fdc10bba4255aa59d2d4f9f494;p=profile%2Fivi%2Fnavit.git Fix:Core:Split out main_ functions from main.c, updated dtd git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@2715 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- diff --git a/navit/navit/Makefile.am b/navit/navit/Makefile.am index 36d2257..01968c4 100644 --- a/navit/navit/Makefile.am +++ b/navit/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/navit/attr_def.h b/navit/navit/attr_def.h index 4b1245b..cad04f5 100644 --- a/navit/navit/attr_def.h +++ b/navit/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/navit/config_.c b/navit/navit/config_.c new file mode 100644 index 0000000..4eecfe1 --- /dev/null +++ b/navit/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 +#include +#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/navit/config_.h b/navit/navit/config_.h new file mode 100644 index 0000000..9f47e99 --- /dev/null +++ b/navit/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/navit/main.c b/navit/navit/main.c index 2910196..8be0117 100644 --- a/navit/navit/main.c +++ b/navit/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/navit.c b/navit/navit/navit.c index d5eaaf1..72c2934 100644 --- a/navit/navit/navit.c +++ b/navit/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/navit.dtd b/navit/navit/navit.dtd index 4abbabc..8c3fbc2 100644 --- a/navit/navit/navit.dtd +++ b/navit/navit/navit.dtd @@ -1,19 +1,27 @@ + + - + + + + + + + - + @@ -23,18 +31,36 @@ - + - - + + + + + + + + + + + + + + - + + + + + + + @@ -45,10 +71,14 @@ + + + - + + @@ -56,20 +86,28 @@ - + - + + + + + + + + + - + - + @@ -77,7 +115,7 @@ - + @@ -90,4 +128,6 @@ - + + + diff --git a/navit/navit/start_real.c b/navit/navit/start_real.c index c647850..44f8279 100644 --- a/navit/navit/start_real.c +++ b/navit/navit/start_real.c @@ -22,6 +22,7 @@ #include #include #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/navit/xmlconfig.c b/navit/navit/xmlconfig.c index cbf8a8c..442efc2 100644 --- a/navit/navit/xmlconfig.c +++ b/navit/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;