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>
41 #include "xmlconfig.h"
45 #include "navigation.h"
48 #include "navit_nls.h"
49 #if HAVE_API_WIN32_BASE
55 struct map_data *map_data_default;
57 struct callback_list *cbl;
60 static void sigchld(int sig)
62 #if !defined(_WIN32) && !defined(__CEGCC__)
64 while (waitpid(-1, &status, WNOHANG) > 0);
69 static gchar *get_home_directory(void)
71 static gchar *homedir = NULL;
73 if (homedir) return homedir;
74 homedir = getenv("HOME");
77 dbg(0,"Could not find home directory. Using current directory as home directory.\n");
78 homedir =g_strdup(".");
80 homedir=g_strdup(homedir);
95 struct iter *ret=g_new0(struct iter, 1);
101 main_iter_destroy(struct iter *iter)
107 main_get_navit(struct iter *iter)
110 struct navit *ret=NULL;
116 ret=(struct navit *)(list->data);
118 iter->list=g_list_next(iter->list);
124 main_add_navit(struct navit *nav)
126 navit=g_list_prepend(navit, nav);
127 callback_list_call_2(cbl, nav, 1);
131 main_remove_navit(struct navit *nav)
133 navit=g_list_remove(navit, nav);
134 callback_list_call_2(cbl, nav, 0);
136 event_main_loop_quit();
140 main_add_attr(struct attr *attr)
145 callback_list_add(cbl, attr->u.callback);
153 main_remove_attr(struct attr *attr)
158 callback_list_remove(cbl, attr->u.callback);
166 #ifdef HAVE_API_WIN32
168 setenv(char *var, char *val, int overwrite)
170 char *str=g_strdup_printf("%s=%s",var,val);
171 if (overwrite || !getenv(var))
177 static char *environment_vars[][4]={
178 {"NAVIT_LIBDIR", ":", "::/navit", ":/lib"},
179 {"NAVIT_SHAREDIR", ":", ":/share/navit", ":"},
180 {"NAVIT_LOCALEDIR", ":/../locale", ":/share/locale", ":/locale"},
181 {"NAVIT_USER_DATADIR", ":", "~/.navit", ":/data"},
182 {"NAVIT_LOGFILE", NULL, NULL, ":/navit.log"},
183 {"NAVIT_LIBPREFIX", "*/.libs/", NULL, NULL},
184 {NULL, NULL, NULL, NULL},
188 main_setup_environment(int mode)
192 while ((var=environment_vars[i][0])) {
193 val=environment_vars[i][mode+1];
198 val=g_strdup_printf("%s/%s%s", getenv("NAVIT_PREFIX"), LIBDIR+sizeof(PREFIX), val+2);
200 val=g_strdup_printf("%s%s", getenv("NAVIT_PREFIX"), val+1);
203 val=g_strdup_printf("%s%s", getenv("HOME"), val+1);
217 main_init(char *program)
223 signal(SIGCHLD, sigchld);
225 cbl=callback_list_new();
226 setenv("LC_NUMERIC","C",1);
227 setlocale(LC_ALL,"");
228 setlocale(LC_NUMERIC,"C");
229 if (file_exists("navit.c") || file_exists("navit.o") || file_exists("navit.lo")) {
230 char buffer[PATH_MAX];
231 printf(_("Running from source directory\n"));
232 getcwd(buffer, PATH_MAX);
233 setenv("NAVIT_PREFIX", buffer, 0);
234 main_setup_environment(0);
236 if (!getenv("NAVIT_PREFIX")) {
238 #ifdef HAVE_API_WIN32_BASE
239 wchar_t filename[MAX_PATH + 1];
240 char program[MAX_PATH + 1];
243 #ifdef HAVE_API_WIN32
244 char *progpath="\\bin\\navit.exe";
245 sz = GetModuleFileNameW(NULL, filename, MAX_PATH);
247 char *progpath="\\navit.exe";
248 sz = GetModuleFileName(NULL, filename, MAX_PATH);
251 wcstombs(program, filename, sz + 1);
253 strcpy(program, PREFIX);
255 char *progpath="/bin/navit";
258 progpath_len=strlen(progpath);
259 if (l > progpath_len && !strcmp(program+l-progpath_len,progpath)) {
261 s[l-progpath_len]='\0';
262 if (strcmp(s, PREFIX))
263 printf(_("setting '%s' to '%s'\n"), "NAVIT_PREFIX", s);
264 setenv("NAVIT_PREFIX", s, 0);
267 setenv("NAVIT_PREFIX", PREFIX, 0);
269 #ifdef HAVE_API_WIN32_BASE
270 setenv("HOME", getenv("NAVIT_PREFIX"), 0);
273 #ifdef HAVE_API_WIN32_CE
274 main_setup_environment(2);
276 main_setup_environment(1);
279 if (getenv("LC_ALL"))
280 dbg(0,"Warning: LC_ALL is set, this might lead to problems\n");
281 s = getenv("NAVIT_WID");
283 setenv("SDL_WINDOWID", s, 0);
292 #define STRINGIFY(x) #x
293 setlocale(LC_MESSAGES,STRINGIFY(FORCE_LOCALE));
295 bindtextdomain(PACKAGE, getenv("NAVIT_LOCALEDIR"));
296 bind_textdomain_codeset (PACKAGE, "UTF-8");