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"
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);
77 struct iter *ret=g_new0(struct iter, 1);
83 main_iter_destroy(struct iter *iter)
89 main_get_navit(struct iter *iter)
92 struct navit *ret=NULL;
98 ret=(struct navit *)(list->data);
100 iter->list=g_list_next(iter->list);
106 main_add_navit(struct navit *nav)
108 navit=g_list_prepend(navit, nav);
109 callback_list_call_2(cbl, nav, 1);
113 main_remove_navit(struct navit *nav)
115 navit=g_list_remove(navit, nav);
116 callback_list_call_2(cbl, nav, 0);
118 event_main_loop_quit();
122 main_add_attr(struct attr *attr)
127 callback_list_add(cbl, attr->u.callback);
135 main_remove_attr(struct attr *attr)
140 callback_list_remove(cbl, attr->u.callback);
148 #ifdef HAVE_API_WIN32
150 setenv(char *var, char *val, int overwrite)
152 char *str=g_strdup_printf("%s=%s",var,val);
153 if (overwrite || !getenv(var))
160 * environment_vars[][0:name,1-3:mode]
161 * ':' replaced with NAVIT_PREFIX
162 * '::' replaced with NAVIT_PREFIX and LIBDIR
163 * '~' replaced with HOME
165 static char *environment_vars[][5]={
166 {"NAVIT_LIBDIR", ":", "::/navit", ":\\lib", ":/lib"},
167 {"NAVIT_SHAREDIR", ":", ":/share/navit", ":", ":/share"},
168 {"NAVIT_LOCALEDIR", ":/../locale",":/share/locale",":\\locale", ":/locale"},
169 {"NAVIT_USER_DATADIR",":", "~/.navit", ":\\data", ":/home"},
171 {"NAVIT_LOGFILE", NULL, NULL, ":\\navit.log",NULL},
173 {"NAVIT_LIBPREFIX", "*/.libs/", NULL, NULL, NULL},
174 {NULL, NULL, NULL, NULL, NULL},
178 main_setup_environment(int mode)
181 char *var,*val,*homedir;
182 while ((var=environment_vars[i][0])) {
183 val=environment_vars[i][mode+1];
188 val=g_strdup_printf("%s/%s%s", getenv("NAVIT_PREFIX"), LIBDIR+sizeof(PREFIX), val+2);
190 val=g_strdup_printf("%s%s", getenv("NAVIT_PREFIX"), val+1);
193 homedir=getenv("HOME");
196 val=g_strdup_printf("%s%s", homedir, val+1);
210 main_init(char *program)
216 signal(SIGCHLD, sigchld);
218 cbl=callback_list_new();
219 setenv("LC_NUMERIC","C",1);
220 setlocale(LC_ALL,"");
221 setlocale(LC_NUMERIC,"C");
222 #if !defined _WIN32 && !defined _WIN32_WCE
223 if (file_exists("navit.c") || file_exists("navit.o") || file_exists("navit.lo")) {
224 char buffer[PATH_MAX];
225 printf(_("Running from source directory\n"));
226 getcwd(buffer, PATH_MAX); /* libc of navit returns "dummy" */
227 setenv("NAVIT_PREFIX", buffer, 0);
228 main_setup_environment(0);
230 if (!getenv("NAVIT_PREFIX")) {
232 char *progpath="/bin/navit";
234 progpath_len=strlen(progpath);
235 if (l > progpath_len && !strcmp(program+l-progpath_len,progpath)) {
237 s[l-progpath_len]='\0';
238 if (strcmp(s, PREFIX))
239 printf(_("setting '%s' to '%s'\n"), "NAVIT_PREFIX", s);
240 setenv("NAVIT_PREFIX", s, 0);
243 setenv("NAVIT_PREFIX", PREFIX, 0);
245 #ifdef HAVE_API_ANDROID
246 main_setup_environment(3);
248 main_setup_environment(1);
252 #else /* _WIN32 || _WIN32_WCE */
253 if (!getenv("NAVIT_PREFIX"))
255 char filename[MAX_PATH + 1],
259 #ifdef _UNICODE /* currently for wince */
260 wchar_t wfilename[MAX_PATH + 1];
261 if (GetModuleFileNameW(NULL, wfilename, MAX_PATH))
263 wcstombs(filename, wfilename, MAX_PATH);
265 if (GetModuleFileName(NULL, filename, MAX_PATH))
268 end = strrchr(filename, L'\\'); /* eliminate the file name which is on the right side */
272 setenv("NAVIT_PREFIX", filename, 0);
275 setenv("HOME", getenv("NAVIT_PREFIX"), 0);
276 main_setup_environment(2);
277 #endif /* _WIN32 || _WIN32_WCE */
279 if (getenv("LC_ALL"))
280 dbg(0,"Warning: LC_ALL is set, this might lead to problems (e.g. strange positions from GPS)\n");
281 s = getenv("NAVIT_WID");
283 setenv("SDL_WINDOWID", s, 0);
292 #define STRINGIFY2(x) #x
293 #define STRINGIFY(x) STRINGIFY2(x)
294 setlocale(LC_MESSAGES,STRINGIFY(FORCE_LOCALE));
296 bindtextdomain(PACKAGE, getenv("NAVIT_LOCALEDIR"));
297 bind_textdomain_codeset (PACKAGE, "UTF-8");