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);
209 #ifdef HAVE_API_WIN32_BASE
210 char *nls_table[][3]={
211 {"DEU","DEU","de_DE"},
212 {"DEA","AUT","de_AT"},
219 wchar_t wcountry[32],wlang[32];
220 char country[32],lang[32];
223 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wlang, sizeof(wlang));
224 WideCharToMultiByte(CP_ACP,0,wlang,-1,lang,sizeof(lang),NULL,NULL);
225 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wcountry, sizeof(wcountry));
226 WideCharToMultiByte(CP_ACP,0,wcountry,-1,country,sizeof(country),NULL,NULL);
227 while (nls_table[i][0]) {
228 if (!strcmp(nls_table[i][0], lang) && !(strcmp(nls_table[i][1], country))) {
229 dbg(1,"Setting LANG=%s for Lang %s Country %s\n",nls_table[i][2], lang, country);
230 setenv("LANG",nls_table[i][2]);
235 dbg(1,"Lang %s Country %s not found\n",lang,country);
240 main_init(char *program)
246 signal(SIGCHLD, sigchld);
248 cbl=callback_list_new();
249 #ifdef HAVE_API_WIN32_BASE
252 setenv("LC_NUMERIC","C",1);
253 setlocale(LC_ALL,"");
254 setlocale(LC_NUMERIC,"C");
255 #if !defined _WIN32 && !defined _WIN32_WCE
256 if (file_exists("navit.c") || file_exists("navit.o") || file_exists("navit.lo")) {
257 char buffer[PATH_MAX];
258 printf(_("Running from source directory\n"));
259 getcwd(buffer, PATH_MAX); /* libc of navit returns "dummy" */
260 setenv("NAVIT_PREFIX", buffer, 0);
261 main_setup_environment(0);
263 if (!getenv("NAVIT_PREFIX")) {
265 char *progpath="/bin/navit";
267 progpath_len=strlen(progpath);
268 if (l > progpath_len && !strcmp(program+l-progpath_len,progpath)) {
270 s[l-progpath_len]='\0';
271 if (strcmp(s, PREFIX))
272 printf(_("setting '%s' to '%s'\n"), "NAVIT_PREFIX", s);
273 setenv("NAVIT_PREFIX", s, 0);
276 setenv("NAVIT_PREFIX", PREFIX, 0);
278 #ifdef HAVE_API_ANDROID
279 main_setup_environment(3);
281 main_setup_environment(1);
285 #else /* _WIN32 || _WIN32_WCE */
286 if (!getenv("NAVIT_PREFIX"))
288 char filename[MAX_PATH + 1],
292 #ifdef _UNICODE /* currently for wince */
293 wchar_t wfilename[MAX_PATH + 1];
294 if (GetModuleFileNameW(NULL, wfilename, MAX_PATH))
296 wcstombs(filename, wfilename, MAX_PATH);
298 if (GetModuleFileName(NULL, filename, MAX_PATH))
301 end = strrchr(filename, L'\\'); /* eliminate the file name which is on the right side */
305 setenv("NAVIT_PREFIX", filename, 0);
308 setenv("HOME", getenv("NAVIT_PREFIX"), 0);
309 main_setup_environment(2);
310 #endif /* _WIN32 || _WIN32_WCE */
312 if (getenv("LC_ALL"))
313 dbg(0,"Warning: LC_ALL is set, this might lead to problems (e.g. strange positions from GPS)\n");
314 s = getenv("NAVIT_WID");
316 setenv("SDL_WINDOWID", s, 0);
325 #define STRINGIFY2(x) #x
326 #define STRINGIFY(x) STRINGIFY2(x)
327 setlocale(LC_MESSAGES,STRINGIFY(FORCE_LOCALE));
329 bindtextdomain(PACKAGE, getenv("NAVIT_LOCALEDIR"));
330 bind_textdomain_codeset (PACKAGE, "UTF-8");