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.
27 #include <sys/types.h>
42 #include "xmlconfig.h"
46 #include "navigation.h"
49 #define _(STRING) gettext(STRING)
51 struct map_data *map_data_default;
53 static void sigchld(int sig)
57 while (waitpid(-1, &status, WNOHANG) > 0);
62 gchar *get_home_directory(void)
64 static gchar *homedir = NULL;
66 if (homedir) return homedir;
67 homedir = getenv("HOME");
70 g_warning("Could not find home directory. Using current directory as home directory.");
73 homedir=g_strdup(homedir);
87 struct iter *ret=g_new0(struct iter, 1);
93 main_iter_destroy(struct iter *iter)
99 main_get_navit(struct iter *iter)
102 struct navit *ret=NULL;
108 ret=(struct navit *)(list->data);
110 iter->list=g_list_next(iter->list);
116 main_add_navit(struct navit *nav)
118 navit=g_list_prepend(navit, nav);
122 main_remove_navit(struct navit *nav)
124 navit=g_list_remove(navit, nav);
126 event_main_loop_quit();
132 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"));
135 int main(int argc, char **argv)
137 GError *error = NULL;
138 char *config_file = NULL;
145 signal(SIGCHLD, sigchld);
148 setenv("LC_NUMERIC","C",1);
149 setlocale(LC_ALL,"");
150 setlocale(LC_NUMERIC,"C");
151 if (file_exists("navit.c") || file_exists("navit.o")) {
152 char buffer[PATH_MAX];
153 printf(_("Running from source directory\n"));
154 getcwd(buffer, PATH_MAX);
155 setenv("NAVIT_PREFIX", buffer, 0);
156 setenv("NAVIT_LIBDIR", buffer, 0);
157 setenv("NAVIT_SHAREDIR", buffer, 0);
158 setenv("NAVIT_LIBPREFIX", "*/.libs/", 0);
159 s=g_strdup_printf("%s/../locale", buffer);
160 setenv("NAVIT_LOCALEDIR", s, 0);
163 if (!getenv("NAVIT_PREFIX")) {
165 if (l > 10 && !strcmp(argv[0]+l-10,"/bin/navit")) {
168 if (strcmp(s, PREFIX))
169 printf(_("setting '%s' to '%s'\n"), "NAVIT_PREFIX", s);
170 setenv("NAVIT_PREFIX", s, 0);
173 setenv("NAVIT_PREFIX", PREFIX, 0);
176 s=g_strdup_printf("locale");
178 s=g_strdup_printf("%s/share/locale", getenv("NAVIT_PREFIX"));
180 setenv("NAVIT_LOCALEDIR", s, 0);
183 s=g_strdup_printf(".");
185 s=g_strdup_printf("%s/share/navit", getenv("NAVIT_PREFIX"));
187 setenv("NAVIT_SHAREDIR", s, 0);
189 s=g_strdup_printf("%s/lib/navit", getenv("NAVIT_PREFIX"));
190 setenv("NAVIT_LIBDIR", s, 0);
193 bindtextdomain(PACKAGE, getenv("NAVIT_LOCALEDIR"));
194 bind_textdomain_codeset (PACKAGE, "UTF-8");
198 if (getenv("LC_ALL"))
199 dbg(0,"Warning: LC_ALL is set, this might lead to problems\n");
201 extern void builtin_init(void);
205 /* handled in gui/gtk */
207 gtk_init(&argc, &argv);
210 s = getenv("NAVIT_WID");
212 setenv("SDL_WINDOWID", s, 0);
217 opterr=0; //don't bomb out on errors.
219 while((opt = getopt(argc, argv, ":hvc:d:")) != -1) {
226 printf("%s %s\n", "navit", "0.0.4+svn");
230 printf("config file n is set to `%s'\n", optarg);
231 config_file = optarg;
234 printf("TODO Verbose option is set to `%s'\n", optarg);
237 fprintf(stderr, "navit: Error - Option `%c' needs a value\n", optopt);
242 fprintf(stderr, "navit: Error - No such option: `%c'\n", optopt);
248 // use 1st cmd line option that is left for the config file
249 if (optind < argc) config_file = argv[optind];
251 GList *list = NULL, *li;
252 // if config file is explicitely given only look for it, otherwise try std paths
253 if (config_file) list = g_list_append(list,g_strdup(config_file));
255 list = g_list_append(list,g_strjoin(NULL,get_home_directory(), "/.navit/navit.xml" , NULL));
256 list = g_list_append(list,g_strdup("navit.xml.local"));
257 list = g_list_append(list,g_strdup("navit.xml"));
258 list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml.local" , NULL));
259 list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml" , NULL));
264 // We have not found an existing config file from all possibilities
265 printf(_("No config file navit.xml, navit.xml.local found\n"));
268 // Try the next config file possibility from the list
269 config_file = li->data;
270 if (!file_exists(config_file)) g_free(config_file);
271 li = g_list_next(li);
272 } while (!file_exists(config_file));
275 if (!config_load(config_file, &error)) {
276 printf(_("Error parsing '%s': %s\n"), config_file, error->message);
279 printf(_("Using '%s'\n"), config_file);
282 printf(_("No instance has been created, exiting\n"));
286 gui_run_main_loop(main_loop_gui);
288 event_main_loop_run();