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);
70 setenv(char *var, char *val, int overwrite)
72 char *str=g_strdup_printf("%s=%s",var,val);
73 if (overwrite || !getenv(var))
80 * environment_vars[][0:name,1-3:mode]
81 * ':' replaced with NAVIT_PREFIX
82 * '::' replaced with NAVIT_PREFIX and LIBDIR
83 * '~' replaced with HOME
85 static char *environment_vars[][5]={
86 {"NAVIT_LIBDIR", ":", "::/navit", ":\\lib", ":/lib"},
87 {"NAVIT_SHAREDIR", ":", ":/share/navit", ":", ":/share"},
88 {"NAVIT_LOCALEDIR", ":/../locale",":/share/locale",":\\locale", ":/locale"},
89 {"NAVIT_USER_DATADIR",":", "~/.navit", ":\\data", ":/home"},
91 {"NAVIT_LOGFILE", NULL, NULL, ":\\navit.log",NULL},
93 {"NAVIT_LIBPREFIX", "*/.libs/", NULL, NULL, NULL},
94 {NULL, NULL, NULL, NULL, NULL},
98 main_setup_environment(int mode)
101 char *var,*val,*homedir;
102 while ((var=environment_vars[i][0])) {
103 val=environment_vars[i][mode+1];
108 val=g_strdup_printf("%s/%s%s", getenv("NAVIT_PREFIX"), LIBDIR+sizeof(PREFIX), val+2);
110 val=g_strdup_printf("%s%s", getenv("NAVIT_PREFIX"), val+1);
113 homedir=getenv("HOME");
116 val=g_strdup_printf("%s%s", homedir, val+1);
129 #ifdef HAVE_API_WIN32_BASE
130 char *nls_table[][3]={
131 {"DEU","DEU","de_DE"},
132 {"DEA","AUT","de_AT"},
133 {"ENU","USA","en_US"},
134 {"RUS","RUS","ru_RU"},
141 wchar_t wcountry[32],wlang[32];
142 char country[32],lang[32];
145 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wlang, sizeof(wlang));
146 WideCharToMultiByte(CP_ACP,0,wlang,-1,lang,sizeof(lang),NULL,NULL);
147 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wcountry, sizeof(wcountry));
148 WideCharToMultiByte(CP_ACP,0,wcountry,-1,country,sizeof(country),NULL,NULL);
149 while (nls_table[i][0]) {
150 if (!strcmp(nls_table[i][0], lang) && !(strcmp(nls_table[i][1], country))) {
151 dbg(1,"Setting LANG=%s for Lang %s Country %s\n",nls_table[i][2], lang, country);
152 setenv("LANG",nls_table[i][2],0);
157 dbg(1,"Lang %s Country %s not found\n",lang,country);
162 main_init(char *program)
168 signal(SIGCHLD, sigchld);
170 cbl=callback_list_new();
171 #ifdef HAVE_API_WIN32_BASE
174 setenv("LC_NUMERIC","C",1);
175 setlocale(LC_ALL,"");
176 setlocale(LC_NUMERIC,"C");
177 #if !defined _WIN32 && !defined _WIN32_WCE
178 if (file_exists("navit.c") || file_exists("navit.o") || file_exists("navit.lo")) {
179 char buffer[PATH_MAX];
180 printf(_("Running from source directory\n"));
181 getcwd(buffer, PATH_MAX); /* libc of navit returns "dummy" */
182 setenv("NAVIT_PREFIX", buffer, 0);
183 main_setup_environment(0);
185 if (!getenv("NAVIT_PREFIX")) {
187 char *progpath="/bin/navit";
189 progpath_len=strlen(progpath);
190 if (l > progpath_len && !strcmp(program+l-progpath_len,progpath)) {
192 s[l-progpath_len]='\0';
193 if (strcmp(s, PREFIX))
194 printf(_("setting '%s' to '%s'\n"), "NAVIT_PREFIX", s);
195 setenv("NAVIT_PREFIX", s, 0);
198 setenv("NAVIT_PREFIX", PREFIX, 0);
200 #ifdef HAVE_API_ANDROID
201 main_setup_environment(3);
203 main_setup_environment(1);
207 #else /* _WIN32 || _WIN32_WCE */
208 if (!getenv("NAVIT_PREFIX"))
210 char filename[MAX_PATH + 1],
214 #ifdef _UNICODE /* currently for wince */
215 wchar_t wfilename[MAX_PATH + 1];
216 if (GetModuleFileNameW(NULL, wfilename, MAX_PATH))
218 wcstombs(filename, wfilename, MAX_PATH);
220 if (GetModuleFileName(NULL, filename, MAX_PATH))
223 end = strrchr(filename, L'\\'); /* eliminate the file name which is on the right side */
227 setenv("NAVIT_PREFIX", filename, 0);
230 setenv("HOME", getenv("NAVIT_PREFIX"), 0);
231 main_setup_environment(2);
232 #endif /* _WIN32 || _WIN32_WCE */
234 if (getenv("LC_ALL"))
235 dbg(0,"Warning: LC_ALL is set, this might lead to problems (e.g. strange positions from GPS)\n");
236 s = getenv("NAVIT_WID");
238 setenv("SDL_WINDOWID", s, 0);
247 #define STRINGIFY2(x) #x
248 #define STRINGIFY(x) STRINGIFY2(x)
249 setlocale(LC_MESSAGES,STRINGIFY(FORCE_LOCALE));
251 bindtextdomain(PACKAGE, getenv("NAVIT_LOCALEDIR"));
252 bind_textdomain_codeset (PACKAGE, "UTF-8");