2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
30 #include "navigation.h"
33 #include "event_glib.h"
34 #include "xmlconfig.h"
38 #define _(STRING) gettext(STRING)
43 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"));
48 get_home_directory(void)
50 static gchar *homedir = NULL;
52 if (homedir) return homedir;
53 homedir = getenv("HOME");
56 g_warning("Could not find home directory. Using current directory as home directory.");
59 homedir=g_strdup(homedir);
64 int main(int argc, char **argv)
67 char *config_file = NULL;
72 GList *list = NULL, *li;
80 extern void builtin_init(void);
87 opterr=0; //don't bomb out on errors.
89 /* DEVELOPPERS : don't forget to update the manpage if you modify theses options */
90 while((opt = getopt(argc, argv, ":hvc:d:")) != -1) {
97 printf("%s %s\n", "navit", "0.0.4+svn");
101 printf("config file n is set to `%s'\n", optarg);
102 config_file = optarg;
105 printf("TODO Verbose option is set to `%s'\n", optarg);
108 fprintf(stderr, "navit: Error - Option `%c' needs a value\n", optopt);
113 fprintf(stderr, "navit: Error - No such option: `%c'\n", optopt);
119 // use 1st cmd line option that is left for the config file
120 if (optind < argc) config_file = argv[optind];
122 // if config file is explicitely given only look for it, otherwise try std paths
123 if (config_file) list = g_list_append(list,g_strdup(config_file));
125 list = g_list_append(list,g_strjoin(NULL,get_home_directory(), "/.navit/navit.xml" , NULL));
126 list = g_list_append(list,g_strdup("navit.xml.local"));
127 list = g_list_append(list,g_strdup("navit.xml"));
128 list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml.local" , NULL));
129 list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml" , NULL));
131 list = g_list_append(list,g_strdup("/etc/navit/navit.xml"));
137 // We have not found an existing config file from all possibilities
138 printf(_("No config file navit.xml, navit.xml.local found\n"));
141 // Try the next config file possibility from the list
142 config_file = li->data;
143 if (!file_exists(config_file)) g_free(config_file);
144 li = g_list_next(li);
145 } while (!file_exists(config_file));
148 if (!config_load(config_file, &error)) {
149 printf(_("Error parsing '%s': %s\n"), config_file, error->message);
152 printf(_("Using '%s'\n"), config_file);
154 if (! main_get_navit(NULL)) {
155 printf(_("No instance has been created, exiting\n"));
158 event_request_system("glib","start");
159 event_main_loop_run();