diff options
-rw-r--r-- | navit/Makefile.am | 15 | ||||
-rw-r--r-- | navit/main.c | 110 | ||||
-rw-r--r-- | navit/main.h | 1 | ||||
-rw-r--r-- | navit/search.c | 5 | ||||
-rw-r--r-- | navit/start.c | 155 |
5 files changed, 179 insertions, 107 deletions
diff --git a/navit/Makefile.am b/navit/Makefile.am index 5f4ecd09c..b628c6c8a 100644 --- a/navit/Makefile.am +++ b/navit/Makefile.am @@ -6,14 +6,15 @@ if BUILD_SAMPLEMAP endif AM_CPPFLAGS = -I$(top_srcdir)/navit/fib-1.1 @NAVIT_CFLAGS@ -DPREFIX=\"@prefix@\" -DMODULE=navit -BUILT_SOURCES=osm2navit +BUILT_SOURCES=osm2navit libnavit.la bin_PROGRAMS = navit osm2navit pkgdata_DATA = navit.xml EXTRA_DIST = navit.xml -navit_SOURCES = attr.c callback.c compass.c coord.c country.c cursor.c data_window.c debug.c \ +noinst_LTLIBRARIES = libnavit.la +libnavit_la_SOURCES = attr.c callback.c compass.c coord.c country.c cursor.c data_window.c debug.c \ event.c file.c graphics.c gui.c item.c layout.c log.c main.c map.c \ mapset.c maptype.c menu.c navit.c navigation.c osd.c param.c phrase.c plugin.c popup.c \ profile.c projection.c route.c search.c speech.c transform.c track.c \ @@ -24,9 +25,12 @@ navit_SOURCES = attr.c callback.c compass.c coord.c country.c cursor.c data_wind param.h phrase.h plugin.h point.h plugin_def.h projection.h popup.h route.h profile.h search.h speech.h \ transform.h track.h util.h vehicle.h window.h xmlconfig.h -osm2navit_SOURCES = osm2navit.c item.c debug.c zipfile.h +navit_SOURCES = start.c +navit_LDADD = @NAVIT_LIBS@ @ZLIB_LIBS@ -lnavit -Lfib-1.1 -lfib -navit_LDADD = @NAVIT_LIBS@ @ZLIB_LIBS@ -Lfib-1.1 -lfib +osm2navit_CPPFLAGS = $(AM_CPPFLAGS) @POSTGRESQL_CFLAGS@ +osm2navit_SOURCES = osm2navit.c +osm2navit_LDADD = @NAVIT_LIBS@ @ZLIB_LIBS@ @POSTGRESQL_LIBS@ -lnavit if !PLUGINS navit_SOURCES += builtin.c @@ -39,6 +43,3 @@ builtin.c: echo "void builtin_init(void) {" >>builtin.c ls $(top_builddir)/navit/*/*/*.la | sed -e "s/.la/_init();/" -e "s/.*lib/ module_/" >>builtin.c echo "}" >>builtin.c - -osm2navit_CPPFLAGS = $(AM_CPPFLAGS) @POSTGRESQL_CFLAGS@ -osm2navit_LDADD = @NAVIT_LIBS@ @ZLIB_LIBS@ @POSTGRESQL_LIBS@ diff --git a/navit/main.c b/navit/main.c index 4b9867acc..ec29bd337 100644 --- a/navit/main.c +++ b/navit/main.c @@ -127,12 +127,7 @@ main_remove_navit(struct navit *nav) } void -print_usage(void) -{ - printf(_("navit usage:\nnavit [options] [configfile]\n\t-c <file>: use <file> as config file\n\t-d <n>: set the debug output level to <n>. (TODO)\n\t-h: print this usage info and exit.\n\t-v: Print the version and exit.\n")); -} - -int main(int argc, char **argv) +main_init(char *program) { GError *error = NULL; char *config_file = NULL; @@ -162,9 +157,9 @@ int main(int argc, char **argv) g_free(s); } else { if (!getenv("NAVIT_PREFIX")) { - l=strlen(argv[0]); - if (l > 10 && !strcmp(argv[0]+l-10,"/bin/navit")) { - s=g_strdup(argv[0]); + l=strlen(program); + if (l > 10 && !strcmp(program+l-10,"/bin/navit")) { + s=g_strdup(program); s[l-10]='\0'; if (strcmp(s, PREFIX)) printf(_("setting '%s' to '%s'\n"), "NAVIT_PREFIX", s); @@ -191,101 +186,18 @@ int main(int argc, char **argv) setenv("NAVIT_LIBDIR", s, 0); g_free(s); } - bindtextdomain(PACKAGE, getenv("NAVIT_LOCALEDIR")); - bind_textdomain_codeset (PACKAGE, "UTF-8"); - textdomain(PACKAGE); - - debug_init(argv[0]); if (getenv("LC_ALL")) dbg(0,"Warning: LC_ALL is set, this might lead to problems\n"); -#ifndef USE_PLUGINS - extern void builtin_init(void); - builtin_init(); -#endif -#if 0 - /* handled in gui/gtk */ - gtk_set_locale(); - gtk_init(&argc, &argv); - gdk_rgb_init(); -#endif s = getenv("NAVIT_WID"); if (s) { setenv("SDL_WINDOWID", s, 0); } - route_init(); - navigation_init(); - config_file=NULL; - opterr=0; //don't bomb out on errors. - if (argc > 1) { - while((opt = getopt(argc, argv, ":hvc:d:")) != -1) { - switch(opt) { - case 'h': - print_usage(); - exit(0); - break; - case 'v': - printf("%s %s\n", "navit", "0.0.4+svn"); - exit(0); - break; - case 'c': - printf("config file n is set to `%s'\n", optarg); - config_file = optarg; - break; - case 'd': - printf("TODO Verbose option is set to `%s'\n", optarg); - break; - case ':': - fprintf(stderr, "navit: Error - Option `%c' needs a value\n", optopt); - print_usage(); - exit(1); - break; - case '?': - fprintf(stderr, "navit: Error - No such option: `%c'\n", optopt); - print_usage(); - exit(1); - } - } - } - // use 1st cmd line option that is left for the config file - if (optind < argc) config_file = argv[optind]; - - // if config file is explicitely given only look for it, otherwise try std paths - if (config_file) list = g_list_append(list,g_strdup(config_file)); - else { - list = g_list_append(list,g_strjoin(NULL,get_home_directory(), "/.navit/navit.xml" , NULL)); - list = g_list_append(list,g_strdup("navit.xml.local")); - list = g_list_append(list,g_strdup("navit.xml")); - list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml.local" , NULL)); - list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml" , NULL)); - } - li = list; - do { - if (li == NULL) { - // We have not found an existing config file from all possibilities - printf(_("No config file navit.xml, navit.xml.local found\n")); - exit(1); - } - // Try the next config file possibility from the list - config_file = li->data; - if (!file_exists(config_file)) g_free(config_file); - li = g_list_next(li); - } while (!file_exists(config_file)); - g_list_free(list); - - if (!config_load(config_file, &error)) { - printf(_("Error parsing '%s': %s\n"), config_file, error->message); - exit(1); - } else { - printf(_("Using '%s'\n"), config_file); - } - if (! navit) { - printf(_("No instance has been created, exiting\n")); - exit(1); - } - if (main_loop_gui) { - gui_run_main_loop(main_loop_gui); - } else - event_main_loop_run(); +} - return 0; +void +main_init_nls(void) +{ + bindtextdomain(PACKAGE, getenv("NAVIT_LOCALEDIR")); + bind_textdomain_codeset (PACKAGE, "UTF-8"); + textdomain(PACKAGE); } diff --git a/navit/main.h b/navit/main.h index a0acedfc8..2cb27edd0 100644 --- a/navit/main.h +++ b/navit/main.h @@ -28,7 +28,6 @@ void main_iter_destroy(struct iter *iter); struct navit * main_get_navit(struct iter *iter); void main_add_navit(struct navit *nav); void main_remove_navit(struct navit *nav); -void print_usage(void); int main(int argc, char **argv); /* end of prototypes */ diff --git a/navit/search.c b/navit/search.c index b697989f4..f4ddf4942 100644 --- a/navit/search.c +++ b/navit/search.c @@ -350,3 +350,8 @@ search_list_destroy(struct search_list *this_) { g_free(this_); } + +void +search_init(void) +{ +} diff --git a/navit/start.c b/navit/start.c new file mode 100644 index 000000000..315978cae --- /dev/null +++ b/navit/start.c @@ -0,0 +1,155 @@ +/** + * 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 <stdio.h> +#include <stdlib.h> +#include <glib.h> +#include <getopt.h> +#include <libintl.h> +#include "config.h" +#include "item.h" +#include "coord.h" +#include "main.h" +#include "route.h" +#include "navigation.h" +#include "debug.h" +#include "event.h" +#include "xmlconfig.h" +#include "file.h" +#include "search.h" + +#define _(STRING) gettext(STRING) + +static void +print_usage(void) +{ + printf(_("navit usage:\nnavit [options] [configfile]\n\t-c <file>: use <file> as config file\n\t-d <n>: set the debug output level to <n>. (TODO)\n\t-h: print this usage info and exit.\n\t-v: Print the version and exit.\n")); +} + + +static gchar * +get_home_directory(void) +{ + static gchar *homedir = NULL; + + if (homedir) return homedir; + homedir = getenv("HOME"); + if (!homedir) + { + g_warning("Could not find home directory. Using current directory as home directory."); + homedir = "."; + } else { + homedir=g_strdup(homedir); + } + return homedir; +} + +int main(int argc, char **argv) +{ + GError *error = NULL; + char *config_file = NULL; + char *s; + int l; + int opt; + + GList *list = NULL, *li; + + + main_init(argv[0]); + main_init_nls(); + debug_init(argv[0]); +#ifndef USE_PLUGINS + extern void builtin_init(void); + builtin_init(); +#endif + route_init(); + navigation_init(); + search_init(); + config_file=NULL; + opterr=0; //don't bomb out on errors. + if (argc > 1) { + while((opt = getopt(argc, argv, ":hvc:d:")) != -1) { + switch(opt) { + case 'h': + print_usage(); + exit(0); + break; + case 'v': + printf("%s %s\n", "navit", "0.0.4+svn"); + exit(0); + break; + case 'c': + printf("config file n is set to `%s'\n", optarg); + config_file = optarg; + break; + case 'd': + printf("TODO Verbose option is set to `%s'\n", optarg); + break; + case ':': + fprintf(stderr, "navit: Error - Option `%c' needs a value\n", optopt); + print_usage(); + exit(1); + break; + case '?': + fprintf(stderr, "navit: Error - No such option: `%c'\n", optopt); + print_usage(); + exit(1); + } + } + } + // use 1st cmd line option that is left for the config file + if (optind < argc) config_file = argv[optind]; + + // if config file is explicitely given only look for it, otherwise try std paths + if (config_file) list = g_list_append(list,g_strdup(config_file)); + else { + list = g_list_append(list,g_strjoin(NULL,get_home_directory(), "/.navit/navit.xml" , NULL)); + list = g_list_append(list,g_strdup("navit.xml.local")); + list = g_list_append(list,g_strdup("navit.xml")); + list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml.local" , NULL)); + list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml" , NULL)); + } + li = list; + do { + if (li == NULL) { + // We have not found an existing config file from all possibilities + printf(_("No config file navit.xml, navit.xml.local found\n")); + exit(1); + } + // Try the next config file possibility from the list + config_file = li->data; + if (!file_exists(config_file)) g_free(config_file); + li = g_list_next(li); + } while (!file_exists(config_file)); + g_list_free(list); + + if (!config_load(config_file, &error)) { + printf(_("Error parsing '%s': %s\n"), config_file, error->message); + exit(1); + } else { + printf(_("Using '%s'\n"), config_file); + } + if (! main_get_navit(NULL)) { + printf(_("No instance has been created, exiting\n")); + exit(1); + } + event_main_loop_run(); + + return 0; +} |