1 |
/**
|
2 |
* ZANavi, Zoff Android Navigation system.
|
3 |
* Copyright (C) 2011-2012 Zoff <zoff@zoff.cc>
|
4 |
*
|
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.
|
8 |
*
|
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.
|
13 |
*
|
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.
|
18 |
*/
|
19 |
|
20 |
/**
|
21 |
* Navit, a modular navigation system.
|
22 |
* Copyright (C) 2005-2008 Navit Team
|
23 |
*
|
24 |
* This program is free software; you can redistribute it and/or
|
25 |
* modify it under the terms of the GNU General Public License
|
26 |
* version 2 as published by the Free Software Foundation.
|
27 |
*
|
28 |
* This program is distributed in the hope that it will be useful,
|
29 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
30 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
31 |
* GNU General Public License for more details.
|
32 |
*
|
33 |
* You should have received a copy of the GNU General Public License
|
34 |
* along with this program; if not, write to the
|
35 |
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
36 |
* Boston, MA 02110-1301, USA.
|
37 |
*/
|
38 |
|
39 |
#include <locale.h>
|
40 |
#include <stdlib.h>
|
41 |
#include <stdio.h>
|
42 |
#include <string.h>
|
43 |
#include <signal.h>
|
44 |
#include <glib.h>
|
45 |
#include <sys/types.h>
|
46 |
|
47 |
#include "config.h"
|
48 |
|
49 |
#ifdef HAVE_UNISTD_H
|
50 |
#include <unistd.h>
|
51 |
#endif
|
52 |
|
53 |
#ifndef _WIN32
|
54 |
#include <sys/wait.h>
|
55 |
#include <signal.h>
|
56 |
#endif
|
57 |
|
58 |
#include "file.h"
|
59 |
#include "debug.h"
|
60 |
#include "main.h"
|
61 |
#include "navit.h"
|
62 |
#include "gui.h"
|
63 |
#include "item.h"
|
64 |
#include "xmlconfig.h"
|
65 |
#include "coord.h"
|
66 |
#include "route.h"
|
67 |
#include "navigation.h"
|
68 |
#include "event.h"
|
69 |
#include "callback.h"
|
70 |
#include "navit_nls.h"
|
71 |
#include "util.h"
|
72 |
#if HAVE_API_WIN32_BASE
|
73 |
#include <windows.h>
|
74 |
#include <winbase.h>
|
75 |
#endif
|
76 |
|
77 |
#ifdef HAVE_API_WIN32_CE
|
78 |
#include "libc.h"
|
79 |
#endif
|
80 |
|
81 |
|
82 |
struct map_data *map_data_default;
|
83 |
|
84 |
struct callback_list *cbl;
|
85 |
|
86 |
#ifdef HAVE_API_WIN32
|
87 |
void
|
88 |
setenv(char *var, char *val, int overwrite)
|
89 |
{
|
90 |
char *str=g_strdup_printf("%s=%s",var,val);
|
91 |
if (overwrite || !getenv(var))
|
92 |
putenv(str);
|
93 |
g_free(str);
|
94 |
}
|
95 |
#endif
|
96 |
|
97 |
/*
|
98 |
* environment_vars[][0:name,1-3:mode]
|
99 |
* ':' replaced with NAVIT_PREFIX
|
100 |
* '::' replaced with NAVIT_PREFIX and LIBDIR
|
101 |
* '~' replaced with HOME
|
102 |
*/
|
103 |
static char *environment_vars[][5] = { { "NAVIT_LIBDIR", ":", "::/navit", ":\\lib", ":/lib" }, { "NAVIT_SHAREDIR", ":", ":/share/navit", ":", ":/share" }, { "NAVIT_LOCALEDIR", ":/../locale", ":/share/locale", ":\\locale", ":/locale" }, { "NAVIT_USER_DATADIR", ":", "~/.navit", ":\\data", ":/home" },
|
104 |
#if 1
|
105 |
{ "NAVIT_LOGFILE", NULL, NULL, ":\\navit.log", NULL },
|
106 |
#endif
|
107 |
{ "NAVIT_LIBPREFIX", "*/.libs/", NULL, NULL, NULL }, { NULL, NULL, NULL, NULL, NULL }, };
|
108 |
|
109 |
static void main_setup_environment(int mode)
|
110 |
{
|
111 |
int i = 0;
|
112 |
char *var, *val, *homedir;
|
113 |
while ((var = environment_vars[i][0]))
|
114 |
{
|
115 |
val = environment_vars[i][mode + 1];
|
116 |
if (val)
|
117 |
{
|
118 |
switch (val[0])
|
119 |
{
|
120 |
case ':':
|
121 |
if (val[1] == ':')
|
122 |
val = g_strdup_printf("%s/%s%s", getenv("NAVIT_PREFIX"), LIBDIR + sizeof(PREFIX), val + 2);
|
123 |
else
|
124 |
val = g_strdup_printf("%s%s", getenv("NAVIT_PREFIX"), val + 1);
|
125 |
break;
|
126 |
case '~':
|
127 |
homedir = getenv("HOME");
|
128 |
if (!homedir)
|
129 |
homedir = "./";
|
130 |
val = g_strdup_printf("%s%s", homedir, val + 1);
|
131 |
break;
|
132 |
default:
|
133 |
val = g_strdup(val);
|
134 |
break;
|
135 |
}
|
136 |
setenv(var, val, 0);
|
137 |
g_free(val);
|
138 |
}
|
139 |
i++;
|
140 |
}
|
141 |
}
|
142 |
|
143 |
#ifdef HAVE_API_WIN32_BASE
|
144 |
char *nls_table[][3]=
|
145 |
{
|
146 |
// NLS Table compiled by Nick "Number6" Geoghegan
|
147 |
// Not an exhaustive list, but supports 99% of all languages in Windows
|
148 |
//{"LANGNAME", "CTRYNAME", "Language Code"},
|
149 |
|
150 |
{ "AFK", "ZAF", "af_ZA"}, // Afrikaans (South Africa)
|
151 |
|
152 |
{ "SQI", "ALB", "sq_AL"}, // Albanian (Albania)
|
153 |
|
154 |
{ "AMH", "ETH", "am_ET"}, // Amharic (Ethiopia)
|
155 |
|
156 |
{ "ARG", "DZA", "ar_DZ"}, // Arabic (Algeria)
|
157 |
|
158 |
{ "ARH", "BHR", "ar_BH"}, // Arabic (Bahrain)
|
159 |
|
160 |
{ "ARE", "EGY", "ar_EG"}, // Arabic (Egypt)
|
161 |
|
162 |
{ "ARI", "IRQ", "ar_IQ"}, // Arabic (Iraq)
|
163 |
|
164 |
{ "ARJ", "JOR", "ar_JO"}, // Arabic (Jordan)
|
165 |
|
166 |
{ "ARK", "KWT", "ar_KW"}, // Arabic (Kuwait)
|
167 |
|
168 |
{ "ARB", "LBN", "ar_LB"}, // Arabic (Lebanon)
|
169 |
|
170 |
{ "ARL", "LBY", "ar_LY"}, // Arabic (Libya)
|
171 |
|
172 |
{ "ARM", "MAR", "ar_MA"}, // Arabic (Morocco)
|
173 |
|
174 |
{ "ARO", "OMN", "ar_OM"}, // Arabic (Oman)
|
175 |
|
176 |
{ "ARQ", "QAT", "ar_QA"}, // Arabic (Qatar)
|
177 |
|
178 |
{ "ARA", "SAU", "ar_SA"}, // Arabic (Saudi Arabia)
|
179 |
|
180 |
{ "ARS", "SYR", "ar_SY"}, // Arabic (Syria)
|
181 |
|
182 |
{ "ART", "TUN", "ar_TN"}, // Arabic (Tunisia)
|
183 |
|
184 |
{ "ARU", "ARE", "ar_AE"}, // Arabic (U.A.E.)
|
185 |
|
186 |
{ "ARY", "YEM", "ar_YE"}, // Arabic (Yemen)
|
187 |
|
188 |
{ "HYE", "ARM", "hy_AM"}, // Armenian (Armenia)
|
189 |
|
190 |
{ "ASM", "IND", "as_IN"}, // Assamese (India)
|
191 |
|
192 |
{ "BAS", "RUS", "ba_RU"}, // Bashkir (Russia)
|
193 |
|
194 |
{ "EUQ", "ESP", "eu_ES"}, // Basque (Basque)
|
195 |
|
196 |
{ "BEL", "BLR", "be_BY"}, // Belarusian (Belarus)
|
197 |
|
198 |
{ "BNG", "BDG", "bn_BD"}, // Bengali (Bangladesh)
|
199 |
|
200 |
{ "BNG", "IND", "bn_IN"}, // Bengali (India)
|
201 |
|
202 |
{ "BRE", "FRA", "br_FR"}, // Breton (France)
|
203 |
|
204 |
{ "BGR", "BGR", "bg_BG"}, // Bulgarian (Bulgaria)
|
205 |
|
206 |
{ "CAT", "ESP", "ca_ES"}, // Catalan (Catalan)
|
207 |
|
208 |
{ "ZHH", "HKG", "zh_HK"}, // Chinese (Hong Kong S.A.R.)
|
209 |
|
210 |
{ "ZHM", "MCO", "zh_MO"}, // Chinese (Macao S.A.R.)
|
211 |
|
212 |
{ "CHS", "CHN", "zh_CN"}, // Chinese (People's Republic of China)
|
213 |
|
214 |
{ "ZHI", "SGP", "zh_SG"}, // Chinese (Singapore)
|
215 |
|
216 |
{ "CHT", "TWN", "zh_TW"}, // Chinese (Taiwan)
|
217 |
|
218 |
{ "COS", "FRA", "co_FR"}, // Corsican (France)
|
219 |
|
220 |
{ "HRV", "HRV", "hr_HR"}, // Croatian (Croatia)
|
221 |
|
222 |
{ "HRB", "BIH", "hr_BA"}, // Croatian (Latin, Bosnia and Herzegovina)
|
223 |
|
224 |
{ "CSY", "CZE", "cs_CZ"}, // Czech (Czech Republic)
|
225 |
|
226 |
{ "DAN", "DNK", "da_DK"}, // Danish (Denmark)
|
227 |
|
228 |
{ "NLB", "BEL", "nl_BE"}, // Dutch (Belgium)
|
229 |
|
230 |
{ "NLD", "NLD", "nl_NL"}, // Dutch (Netherlands)
|
231 |
|
232 |
{ "ENA", "AUS", "en_AU"}, // English (Australia)
|
233 |
|
234 |
{ "ENL", "BLZ", "en_BZ"}, // English (Belize)
|
235 |
|
236 |
{ "ENC", "CAN", "en_CA"}, // English (Canada)
|
237 |
|
238 |
{ "ENB", "CAR", "en_CB"}, // English (Caribbean)
|
239 |
|
240 |
{ "ENN", "IND", "en_IN"}, // English (India)
|
241 |
|
242 |
{ "ENI", "IRL", "en_IE"}, // English (Ireland)
|
243 |
|
244 |
{ "ENJ", "JAM", "en_JM"}, // English (Jamaica)
|
245 |
|
246 |
{ "ENM", "MYS", "en_MY"}, // English (Malaysia)
|
247 |
|
248 |
{ "ENZ", "NZL", "en_NZ"}, // English (New Zealand)
|
249 |
|
250 |
{ "ENP", "PHL", "en_PH"}, // English (Republic of the Philippines)
|
251 |
|
252 |
{ "ENE", "SGP", "en_SG"}, // English (Singapore)
|
253 |
|
254 |
{ "ENS", "ZAF", "en_ZA"}, // English (South Africa)
|
255 |
|
256 |
{ "ENT", "TTO", "en_TT"}, // English (Trinidad and Tobago)
|
257 |
|
258 |
{ "ENG", "GBR", "en_GB"}, // English (United Kingdom)
|
259 |
|
260 |
{ "ENU", "USA", "en_US"}, // English (United States)
|
261 |
|
262 |
{ "ENW", "ZWE", "en_ZW"}, // English (Zimbabwe)
|
263 |
|
264 |
{ "ETI", "EST", "et_EE"}, // Estonian (Estonia)
|
265 |
|
266 |
{ "FOS", "FRO", "fo_FO"}, // Faroese (Faroe Islands)
|
267 |
|
268 |
{ "FIN", "FIN", "fi_FI"}, // Finnish (Finland)
|
269 |
|
270 |
{ "FRB", "BEL", "fr_BE"}, // French (Belgium)
|
271 |
|
272 |
{ "FRC", "CAN", "fr_CA"}, // French (Canada)
|
273 |
|
274 |
{ "FRA", "FRA", "fr_FR"}, // French (France)
|
275 |
|
276 |
{ "FRL", "LUX", "fr_LU"}, // French (Luxembourg)
|
277 |
|
278 |
{ "FRM", "MCO", "fr_MC"}, // French (Principality of Monaco)
|
279 |
|
280 |
{ "FRS", "CHE", "fr_CH"}, // French (Switzerland)
|
281 |
|
282 |
{ "FYN", "NLD", "fy_NL"}, // Frisian (Netherlands)
|
283 |
|
284 |
{ "GLC", "ESP", "gl_ES"}, // Galician (Galician)
|
285 |
|
286 |
{ "KAT", "GEO", "ka_GE"}, // Georgian (Georgia)
|
287 |
|
288 |
{ "DEA", "AUT", "de_AT"}, // German (Austria)
|
289 |
|
290 |
{ "DEU", "DEU", "de_DE"}, // German (Germany)
|
291 |
|
292 |
{ "DEC", "LIE", "de_LI"}, // German (Liechtenstein)
|
293 |
|
294 |
{ "DEL", "LUX", "de_LU"}, // German (Luxembourg)
|
295 |
|
296 |
{ "DES", "CHE", "de_CH"}, // German (Switzerland)
|
297 |
|
298 |
{ "ELL", "GRC", "el_GR"}, // Greek (Greece)
|
299 |
|
300 |
{ "KAL", "GRL", "kl_GL"}, // Greenlandic (Greenland)
|
301 |
|
302 |
{ "GUJ", "IND", "gu_IN"}, // Gujarati (India)
|
303 |
|
304 |
{ "HEB", "ISR", "he_IL"}, // Hebrew (Israel)
|
305 |
|
306 |
{ "HIN", "IND", "hi_IN"}, // Hindi (India)
|
307 |
|
308 |
{ "HUN", "HUN", "hu_HU"}, // Hungarian (Hungary)
|
309 |
|
310 |
{ "ISL", "ISL", "is_IS"}, // Icelandic (Iceland)
|
311 |
|
312 |
{ "IBO", "NGA", "ig_NG"}, // Igbo (Nigeria)
|
313 |
|
314 |
{ "IND", "IDN", "id_ID"}, // Indonesian (Indonesia)
|
315 |
|
316 |
{ "IRE", "IRL", "ga_IE"}, // Irish (Ireland)
|
317 |
|
318 |
{ "XHO", "ZAF", "xh_ZA"}, // isiXhosa (South Africa)
|
319 |
|
320 |
{ "ZUL", "ZAF", "zu_ZA"}, // isiZulu (South Africa)
|
321 |
|
322 |
{ "ITA", "ITA", "it_IT"}, // Italian (Italy)
|
323 |
|
324 |
{ "ITS", "CHE", "it_CH"}, // Italian (Switzerland)
|
325 |
|
326 |
{ "JPN", "JPN", "ja_JP"}, // Japanese (Japan)
|
327 |
|
328 |
{ "KDI", "IND", "kn_IN"}, // Kannada (India)
|
329 |
|
330 |
{ "KKZ", "KAZ", "kk_KZ"}, // Kazakh (Kazakhstan)
|
331 |
|
332 |
{ "KHM", "KHM", "km_KH"}, // Khmer (Cambodia)
|
333 |
|
334 |
{ "KIN", "RWA", "rw_RW"}, // Kinyarwanda (Rwanda)
|
335 |
|
336 |
{ "SWK", "KEN", "sw_KE"}, // Kiswahili (Kenya)
|
337 |
|
338 |
{ "KOR", "KOR", "ko_KR"}, // Korean (Korea)
|
339 |
|
340 |
{ "KYR", "KGZ", "ky_KG"}, // Kyrgyz (Kyrgyzstan)
|
341 |
|
342 |
{ "LAO", "LAO", "lo_LA"}, // Lao (Lao P.D.R.)
|
343 |
|
344 |
{ "LVI", "LVA", "lv_LV"}, // Latvian (Latvia)
|
345 |
|
346 |
{ "LTH", "LTU", "lt_LT"}, // Lithuanian (Lithuania)
|
347 |
|
348 |
{ "LBX", "LUX", "lb_LU"}, // Luxembourgish (Luxembourg)
|
349 |
|
350 |
{ "MKI", "MKD", "mk_MK"}, // Macedonian (Former Yugoslav Republic of Macedonia)
|
351 |
|
352 |
{ "MSB", "BRN", "ms_BN"}, // Malay (Brunei Darussalam)
|
353 |
|
354 |
{ "MSL", "MYS", "ms_MY"}, // Malay (Malaysia)
|
355 |
|
356 |
{ "MYM", "IND", "ml_IN"}, // Malayalam (India)
|
357 |
|
358 |
{ "MLT", "MLT", "mt_MT"}, // Maltese (Malta)
|
359 |
|
360 |
{ "MRI", "NZL", "mi_NZ"}, // Maori (New Zealand)
|
361 |
|
362 |
{ "MAR", "IND", "mr_IN"}, // Marathi (India)
|
363 |
|
364 |
{ "MON", "MNG", "mn_MN"}, // Mongolian (Cyrillic, Mongolia)
|
365 |
|
366 |
{ "NEP", "NEP", "ne_NP"}, // Nepali (Nepal)
|
367 |
|
368 |
{ "NOR", "NOR", "nb_NO"}, // Norwegian, Bokmå(Norway)
|
369 |
|
370 |
{ "NON", "NOR", "nn_NO"}, // Norwegian, Nynorsk (Norway)
|
371 |
|
372 |
{ "OCI", "FRA", "oc_FR"}, // Occitan (France)
|
373 |
|
374 |
{ "ORI", "IND", "or_IN"}, // Oriya (India)
|
375 |
|
376 |
{ "PAS", "AFG", "ps_AF"}, // Pashto (Afghanistan)
|
377 |
|
378 |
{ "FAR", "IRN", "fa_IR"}, // Persian
|
379 |
|
380 |
{ "PLK", "POL", "pl_PL"}, // Polish (Poland)
|
381 |
|
382 |
{ "PTB", "BRA", "pt_BR"}, // Portuguese (Brazil)
|
383 |
|
384 |
{ "PTG", "PRT", "pt_PT"}, // Portuguese (Portugal)
|
385 |
|
386 |
{ "PAN", "IND", "pa_IN"}, // Punjabi (India)
|
387 |
|
388 |
{ "ROM", "ROM", "ro_RO"}, // Romanian (Romania)
|
389 |
|
390 |
{ "RMC", "CHE", "rm_CH"}, // Romansh (Switzerland)
|
391 |
|
392 |
{ "RUS", "RUS", "ru_RU"}, // Russian (Russia)
|
393 |
|
394 |
{ "SMG", "FIN", "se_FI"}, // Sami, Northern (Finland)
|
395 |
|
396 |
{ "SME", "NOR", "se_NO"}, // Sami, Northern (Norway)
|
397 |
|
398 |
{ "SMF", "SWE", "se_SE"}, // Sami, Northern (Sweden)
|
399 |
|
400 |
{ "SAN", "IND", "sa_IN"}, // Sanskrit (India)
|
401 |
|
402 |
{ "TSN", "ZAF", "tn_ZA"}, // Setswana (South Africa)
|
403 |
|
404 |
{ "SIN", "LKA", "si_LK"}, // Sinhala (Sri Lanka)
|
405 |
|
406 |
{ "SKY", "SVK", "sk_SK"}, // Slovak (Slovakia)
|
407 |
|
408 |
{ "SLV", "SVN", "sl_SI"}, // Slovenian (Slovenia)
|
409 |
|
410 |
{ "ESS", "ARG", "es_AR"}, // Spanish (Argentina)
|
411 |
|
412 |
{ "ESB", "BOL", "es_BO"}, // Spanish (Bolivia)
|
413 |
|
414 |
{ "ESL", "CHL", "es_CL"}, // Spanish (Chile)
|
415 |
|
416 |
{ "ESO", "COL", "es_CO"}, // Spanish (Colombia)
|
417 |
|
418 |
{ "ESC", "CRI", "es_CR"}, // Spanish (Costa Rica)
|
419 |
|
420 |
{ "ESD", "DOM", "es_DO"}, // Spanish (Dominican Republic)
|
421 |
|
422 |
{ "ESF", "ECU", "es_EC"}, // Spanish (Ecuador)
|
423 |
|
424 |
{ "ESE", "SLV", "es_SV"}, // Spanish (El Salvador)
|
425 |
|
426 |
{ "ESG", "GTM", "es_GT"}, // Spanish (Guatemala)
|
427 |
|
428 |
{ "ESH", "HND", "es_HN"}, // Spanish (Honduras)
|
429 |
|
430 |
{ "ESM", "MEX", "es_MX"}, // Spanish (Mexico)
|
431 |
|
432 |
{ "ESI", "NIC", "es_NI"}, // Spanish (Nicaragua)
|
433 |
|
434 |
{ "ESA", "PAN", "es_PA"}, // Spanish (Panama)
|
435 |
|
436 |
{ "ESZ", "PRY", "es_PY"}, // Spanish (Paraguay)
|
437 |
|
438 |
{ "ESR", "PER", "es_PE"}, // Spanish (Peru)
|
439 |
|
440 |
{ "ESU", "PRI", "es_PR"}, // Spanish (Puerto Rico)
|
441 |
|
442 |
{ "ESN", "ESP", "es_ES"}, // Spanish (Spain)
|
443 |
|
444 |
{ "EST", "USA", "es_US"}, // Spanish (United States)
|
445 |
|
446 |
{ "ESY", "URY", "es_UY"}, // Spanish (Uruguay)
|
447 |
|
448 |
{ "ESV", "VEN", "es_VE"}, // Spanish (Venezuela)
|
449 |
|
450 |
{ "SVF", "FIN", "sv_FI"}, // Swedish (Finland)
|
451 |
|
452 |
{ "SVE", "SWE", "sv_SE"}, // Swedish (Sweden)
|
453 |
|
454 |
{ "TAM", "IND", "ta_IN"}, // Tamil (India)
|
455 |
|
456 |
{ "TTT", "RUS", "tt_RU"}, // Tatar (Russia)
|
457 |
|
458 |
{ "TEL", "IND", "te_IN"}, // Telugu (India)
|
459 |
|
460 |
{ "THA", "THA", "th_TH"}, // Thai (Thailand)
|
461 |
|
462 |
{ "BOB", "CHN", "bo_CN"}, // Tibetan (PRC)
|
463 |
|
464 |
{ "TRK", "TUR", "tr_TR"}, // Turkish (Turkey)
|
465 |
|
466 |
{ "TUK", "TKM", "tk_TM"}, // Turkmen (Turkmenistan)
|
467 |
|
468 |
{ "UIG", "CHN", "ug_CN"}, // Uighur (PRC)
|
469 |
|
470 |
{ "UKR", "UKR", "uk_UA"}, // Ukrainian (Ukraine)
|
471 |
|
472 |
{ "URD", "PAK", "ur_PK"}, // Urdu (Islamic Republic of Pakistan)
|
473 |
|
474 |
{ "VIT", "VNM", "vi_VN"}, // Vietnamese (Vietnam)
|
475 |
|
476 |
{ "CYM", "GBR", "cy_GB"}, // Welsh (United Kingdom)
|
477 |
|
478 |
{ "WOL", "SEN", "wo_SN"}, // Wolof (Senegal)
|
479 |
|
480 |
{ "III", "CHN", "ii_CN"}, // Yi (PRC)
|
481 |
|
482 |
{ "YOR", "NGA", "yo_NG"}, // Yoruba (Nigeria)
|
483 |
|
484 |
{ NULL,NULL,NULL}, // Default - Can't find the language / Language not listed above
|
485 |
};
|
486 |
|
487 |
static void
|
488 |
win_set_nls(void)
|
489 |
{
|
490 |
char country[32],lang[32];
|
491 |
int i=0;
|
492 |
|
493 |
#ifdef HAVE_API_WIN32_CE
|
494 |
wchar_t wcountry[32],wlang[32];
|
495 |
GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wlang, sizeof(wlang));
|
496 |
WideCharToMultiByte(CP_ACP,0,wlang,-1,lang,sizeof(lang),NULL,NULL);
|
497 |
GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wcountry, sizeof(wcountry));
|
498 |
WideCharToMultiByte(CP_ACP,0,wcountry,-1,country,sizeof(country),NULL,NULL);
|
499 |
#else
|
500 |
GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, lang, sizeof(lang));
|
501 |
GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, country, sizeof(country));
|
502 |
#endif
|
503 |
while (nls_table[i][0])
|
504 |
{
|
505 |
if (!strcmp(nls_table[i][0], lang) && !(strcmp(nls_table[i][1], country)))
|
506 |
{
|
507 |
dbg(1,"Setting LANG=%s for Lang %s Country %s\n",nls_table[i][2], lang, country);
|
508 |
setenv("LANG",nls_table[i][2],0);
|
509 |
return;
|
510 |
}
|
511 |
i++;
|
512 |
}
|
513 |
dbg(1,"Lang %s Country %s not found\n",lang,country);
|
514 |
}
|
515 |
#endif
|
516 |
|
517 |
void main_init(const char *program)
|
518 |
{
|
519 |
char *s;
|
520 |
#ifdef _UNICODE /* currently for wince */
|
521 |
wchar_t wfilename[MAX_PATH + 1];
|
522 |
#endif
|
523 |
|
524 |
spawn_process_init();
|
525 |
|
526 |
cbl = callback_list_new("main_init:cbl");
|
527 |
#ifdef HAVE_API_WIN32_BASE
|
528 |
win_set_nls();
|
529 |
#endif
|
530 |
setenv("LC_NUMERIC", "C", 1);
|
531 |
setlocale(LC_ALL, "");
|
532 |
setlocale(LC_NUMERIC, "C");
|
533 |
#if !defined _WIN32 && !defined _WIN32_WCE
|
534 |
if (file_exists("navit.c") || file_exists("navit.o") || file_exists("navit.lo") || file_exists("version.h"))
|
535 |
{
|
536 |
char buffer[PATH_MAX];
|
537 |
printf("Running from source directory\n");
|
538 |
getcwd(buffer, PATH_MAX); /* libc of navit returns "dummy" */
|
539 |
setenv("NAVIT_PREFIX", buffer, 0);
|
540 |
main_setup_environment(0);
|
541 |
}
|
542 |
else
|
543 |
{
|
544 |
if (!getenv("NAVIT_PREFIX"))
|
545 |
{
|
546 |
int l;
|
547 |
int progpath_len;
|
548 |
char *progpath = "/bin/navit";
|
549 |
l = strlen(program);
|
550 |
progpath_len = strlen(progpath);
|
551 |
if (l > progpath_len && !strcmp(program + l - progpath_len, progpath))
|
552 |
{
|
553 |
s = g_strdup(program);
|
554 |
s[l - progpath_len] = '\0';
|
555 |
if (strcmp(s, PREFIX))
|
556 |
{
|
557 |
// printf("setting '%s' to '%s'\n", "NAVIT_PREFIX", s);
|
558 |
}
|
559 |
setenv("NAVIT_PREFIX", s, 0);
|
560 |
g_free(s);
|
561 |
}
|
562 |
else
|
563 |
setenv("NAVIT_PREFIX", PREFIX, 0);
|
564 |
}
|
565 |
#ifdef HAVE_API_ANDROID
|
566 |
main_setup_environment(3);
|
567 |
#else
|
568 |
main_setup_environment(1);
|
569 |
#endif
|
570 |
}
|
571 |
|
572 |
#else /* _WIN32 || _WIN32_WCE */
|
573 |
if (!getenv("NAVIT_PREFIX"))
|
574 |
{
|
575 |
char filename[MAX_PATH + 1],
|
576 |
*end;
|
577 |
|
578 |
*filename = '\0';
|
579 |
#ifdef _UNICODE /* currently for wince */
|
580 |
if (GetModuleFileNameW(NULL, wfilename, MAX_PATH))
|
581 |
{
|
582 |
wcstombs(filename, wfilename, MAX_PATH);
|
583 |
#else
|
584 |
if (GetModuleFileName(NULL, filename, MAX_PATH))
|
585 |
{
|
586 |
#endif
|
587 |
end = strrchr(filename, L'\\'); /* eliminate the file name which is on the right side */
|
588 |
if(end)
|
589 |
*end = '\0';
|
590 |
}
|
591 |
setenv("NAVIT_PREFIX", filename, 0);
|
592 |
}
|
593 |
if (!getenv("HOME"))
|
594 |
setenv("HOME", getenv("NAVIT_PREFIX"), 0);
|
595 |
main_setup_environment(2);
|
596 |
#endif /* _WIN32 || _WIN32_WCE */
|
597 |
|
598 |
if (getenv("LC_ALL"))
|
599 |
dbg(0, "Warning: LC_ALL is set, this might lead to problems (e.g. strange positions from GPS)\n");
|
600 |
s = getenv("NAVIT_WID");
|
601 |
if (s)
|
602 |
{
|
603 |
setenv("SDL_WINDOWID", s, 0);
|
604 |
}
|
605 |
}
|
606 |
|
607 |
|
608 |
|
609 |
void main_init_nls(void)
|
610 |
{
|
611 |
char *locale_dir;
|
612 |
|
613 |
locale_dir = g_strdup_printf("%s/%s", navit_data_dir, "locale");
|
614 |
dbg(0, "NLS:locale_dir=%s\n", locale_dir);
|
615 |
|
616 |
bindtextdomain(PACKAGE, locale_dir);
|
617 |
bind_textdomain_codeset(PACKAGE, "UTF-8");
|
618 |
textdomain(PACKAGE);
|
619 |
|
620 |
g_free(locale_dir);
|
621 |
|
622 |
|
623 |
#if 0
|
624 |
|
625 |
char *rr22 = NULL;
|
626 |
|
627 |
//dbg(0, "XXXX777:%s\n",_("Follow the road for the next %s"), "");
|
628 |
//dbg(0, "XXXX777:%s\n",_("When possible, please turn around"));
|
629 |
|
630 |
//rr22 = g_strdup_printf(_("Follow the road for the next %s"), "");
|
631 |
//dbg(0, "XXXX777:01:%s\n", rr22);
|
632 |
//g_free(rr22);
|
633 |
|
634 |
//rr22 = g_strdup_printf(_("When possible, please turn around"));
|
635 |
//dbg(0, "XXXX777:01:%s\n", rr22);
|
636 |
//g_free(rr22);
|
637 |
|
638 |
rr22 = g_strdup_printf("dem Straßenverlauf", "");
|
639 |
dbg(0, "XXXX777:01:%s\n", rr22);
|
640 |
g_free(rr22);
|
641 |
|
642 |
rr22 = g_strdup_printf_custom("dem Straßenverlauf", "");
|
643 |
dbg(0, "XXXX777:01a:%s\n", rr22);
|
644 |
g_free(rr22);
|
645 |
|
646 |
|
647 |
rr22 = g_strdup("dem Straßenverlauf");
|
648 |
dbg(0, "XXXX777:02:%s\n", rr22);
|
649 |
g_free(rr22);
|
650 |
|
651 |
|
652 |
va_list args2;
|
653 |
rr22 = g_strdup_vprintf("dem Straßenverlauf", args2);
|
654 |
dbg(0, "XXXX777:03:%s\n", rr22);
|
655 |
g_free(rr22);
|
656 |
|
657 |
|
658 |
|
659 |
va_list args3;
|
660 |
char *string_ret = NULL;
|
661 |
int aa = g_vasprintf(&string_ret, "dem Straßenverlauf", args3);
|
662 |
dbg(0, "XXXX777:04:%d\n", aa);
|
663 |
rr22 = string_ret;
|
664 |
dbg(0, "XXXX777:04:%s\n", rr22);
|
665 |
g_free(rr22);
|
666 |
|
667 |
|
668 |
rr22 = g_strdup(_("then turn %1$s%2$s %3$s%4$s"));
|
669 |
dbg(0, "XXXX777:05:%s\n", rr22);
|
670 |
g_free(rr22);
|
671 |
|
672 |
|
673 |
rr22 = g_strdup_printf(_("then turn %1$s%2$s %3$s%4$s"), "scharf", "links", "in 100 Metern", "Kagran");
|
674 |
dbg(0, "XXXX777:06:%s\n", rr22);
|
675 |
g_free(rr22);
|
676 |
|
677 |
rr22 = g_strdup_printf_4_str(_("then turn %1$s%2$s %3$s%4$s"), "scharf", "links", "in 100 Metern", "Kagran");
|
678 |
dbg(0, "XXXX777:06a:%s\n", rr22);
|
679 |
g_free(rr22);
|
680 |
|
681 |
rr22 = g_strdup_printf_2_str(_("then turn %2$s%1$s"), "scharf", "links");
|
682 |
dbg(0, "XXXX777:06b:%s\n", rr22);
|
683 |
g_free(rr22);
|
684 |
|
685 |
rr22 = g_strdup_printf_2_str(_("then turn %1$s%2$s"), "scharf", "links");
|
686 |
dbg(0, "XXXX777:06c:%s\n", rr22);
|
687 |
g_free(rr22);
|
688 |
|
689 |
rr22 = g_strdup_printf("then turn %1$s%2$s %3$s%4$s", "scharf ", "links ", "in 100 Metern ", "Kagran ");
|
690 |
dbg(0, "XXXX777:07:%s\n", rr22);
|
691 |
g_free(rr22);
|
692 |
|
693 |
rr22 = g_strdup_printf("then turn %s%s %s%s", "scharf ", "links ", "in 100 Metern ", "Kagran" );
|
694 |
dbg(0, "XXXX777:08:%s\n", rr22);
|
695 |
g_free(rr22);
|
696 |
|
697 |
rr22 = g_strdup_printf("%s %f %d", "sßel3p2", 3.4583453f, -3472);
|
698 |
dbg(0, "XXXX777:09:%s\n", rr22);
|
699 |
g_free(rr22);
|
700 |
|
701 |
|
702 |
#endif
|
703 |
|
704 |
}
|
705 |
|
706 |
|
707 |
gchar* g_strdup_printf_custom(const gchar *format, ...)
|
708 |
{
|
709 |
gchar *buffer;
|
710 |
va_list args;
|
711 |
|
712 |
va_start (args, format);
|
713 |
buffer = g_strdup_vprintf_custom (format, args);
|
714 |
va_end (args);
|
715 |
|
716 |
return buffer;
|
717 |
}
|
718 |
|
719 |
gchar* g_strdup_vprintf_custom(const gchar *format, va_list args)
|
720 |
{
|
721 |
gchar *string = NULL;
|
722 |
|
723 |
g_vasprintf_custom (&string, format, args);
|
724 |
|
725 |
return string;
|
726 |
}
|
727 |
|
728 |
gint g_vasprintf_custom (gchar **string, gchar const *format, va_list args)
|
729 |
{
|
730 |
gint len;
|
731 |
g_return_val_if_fail (string != NULL, -1);
|
732 |
|
733 |
len = rpl_vasprintf(string , format, args);
|
734 |
if (len < 0)
|
735 |
{
|
736 |
*string = NULL;
|
737 |
}
|
738 |
else if (!g_mem_is_system_malloc ())
|
739 |
{
|
740 |
/* vasprintf returns malloc-allocated memory */
|
741 |
gchar *string1 = g_strndup (*string, len);
|
742 |
free (*string);
|
743 |
*string = string1;
|
744 |
}
|
745 |
|
746 |
return len;
|
747 |
}
|
748 |
|
749 |
|
750 |
char *replace_str2(const char *str, const char *old, const char *new)
|
751 |
{
|
752 |
char *ret, *r;
|
753 |
const char *p, *q;
|
754 |
size_t oldlen = strlen(old);
|
755 |
size_t count, retlen, newlen = strlen(new);
|
756 |
int samesize = (oldlen == newlen);
|
757 |
|
758 |
if (!samesize) {
|
759 |
for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen)
|
760 |
count++;
|
761 |
/* This is undefined if p - str > PTRDIFF_MAX */
|
762 |
retlen = p - str + strlen(p) + count * (newlen - oldlen);
|
763 |
} else
|
764 |
retlen = strlen(str);
|
765 |
|
766 |
if ((ret = malloc(retlen + 1)) == NULL)
|
767 |
return NULL;
|
768 |
|
769 |
r = ret, p = str;
|
770 |
while (1) {
|
771 |
/* If the old and new strings are different lengths - in other
|
772 |
* words we have already iterated through with strstr above,
|
773 |
* and thus we know how many times we need to call it - then we
|
774 |
* can avoid the final (potentially lengthy) call to strstr,
|
775 |
* which we already know is going to return NULL, by
|
776 |
* decrementing and checking count.
|
777 |
*/
|
778 |
if (!samesize && !count--)
|
779 |
break;
|
780 |
/* Otherwise i.e. when the old and new strings are the same
|
781 |
* length, and we don't know how many times to call strstr,
|
782 |
* we must check for a NULL return here (we check it in any
|
783 |
* event, to avoid further conditions, and because there's
|
784 |
* no harm done with the check even when the old and new
|
785 |
* strings are different lengths).
|
786 |
*/
|
787 |
if ((q = strstr(p, old)) == NULL)
|
788 |
break;
|
789 |
/* This is undefined if q - p > PTRDIFF_MAX */
|
790 |
ptrdiff_t l = q - p;
|
791 |
memcpy(r, p, l);
|
792 |
r += l;
|
793 |
memcpy(r, new, newlen);
|
794 |
r += newlen;
|
795 |
p = q + oldlen;
|
796 |
}
|
797 |
strcpy(r, p);
|
798 |
|
799 |
return ret;
|
800 |
}
|
801 |
|
802 |
|
803 |
static __inline__ unsigned int sort4(unsigned int *d)
|
804 |
{
|
805 |
#define SWAP(x,y) if (d[y] < d[x]) { unsigned int tmp = d[x]; d[x] = d[y]; d[y] = tmp; }
|
806 |
SWAP(0, 1);
|
807 |
SWAP(2, 3);
|
808 |
SWAP(0, 2);
|
809 |
SWAP(1, 3);
|
810 |
SWAP(1, 2);
|
811 |
#undef SWAP
|
812 |
}
|
813 |
|
814 |
|
815 |
char* g_strdup_printf_4_str(const char *format, const char *str1, const char *str2, const char *str3, const char *str4)
|
816 |
{
|
817 |
static int str_pos_array[4];
|
818 |
static int str_pos_array_copy[4];
|
819 |
static char* str_array[4];
|
820 |
|
821 |
str_pos_array[0] = (unsigned int)strstr(format, "%1$s");
|
822 |
str_pos_array[1] = (unsigned int)strstr(format, "%2$s");
|
823 |
str_pos_array[2] = (unsigned int)strstr(format, "%3$s");
|
824 |
str_pos_array[3] = (unsigned int)strstr(format, "%4$s");
|
825 |
str_pos_array_copy[0] = str_pos_array[0];
|
826 |
str_pos_array_copy[1] = str_pos_array[1];
|
827 |
str_pos_array_copy[2] = str_pos_array[2];
|
828 |
str_pos_array_copy[3] = str_pos_array[3];
|
829 |
|
830 |
// dbg(0, "XXXX777:%d %d %d %d \n", str_pos_array[0], str_pos_array[1], str_pos_array[2], str_pos_array[3]);
|
831 |
sort4(str_pos_array);
|
832 |
// dbg(0, "XXXX777:%d %d %d %d \n", str_pos_array[0], str_pos_array[1], str_pos_array[2], str_pos_array[3]);
|
833 |
|
834 |
// -- now remove the position info for format --
|
835 |
char *format_changed_2 = replace_str2(format, "%1$s", "%s");
|
836 |
char *format_changed = replace_str2(format_changed_2, "%2$s", "%s");
|
837 |
free(format_changed_2);
|
838 |
format_changed_2 = replace_str2(format_changed, "%3$s", "%s");
|
839 |
free(format_changed);
|
840 |
format_changed = replace_str2(format_changed_2, "%4$s", "%s");
|
841 |
free(format_changed_2);
|
842 |
// -- now remove the position info for format --
|
843 |
|
844 |
char* ret_str = NULL;
|
845 |
// ---- here comes the ugly part ...
|
846 |
if (str_pos_array[0] == str_pos_array_copy[0])
|
847 |
{
|
848 |
str_array[0] = str1;
|
849 |
}
|
850 |
else if (str_pos_array[0] == str_pos_array_copy[1])
|
851 |
{
|
852 |
str_array[0] = str2;
|
853 |
}
|
854 |
else if (str_pos_array[0] == str_pos_array_copy[2])
|
855 |
{
|
856 |
str_array[0] = str3;
|
857 |
}
|
858 |
else if (str_pos_array[0] == str_pos_array_copy[3])
|
859 |
{
|
860 |
str_array[0] = str4;
|
861 |
}
|
862 |
|
863 |
if (str_pos_array[1] == str_pos_array_copy[0])
|
864 |
{
|
865 |
str_array[1] = str1;
|
866 |
}
|
867 |
else if (str_pos_array[1] == str_pos_array_copy[1])
|
868 |
{
|
869 |
str_array[1] = str2;
|
870 |
}
|
871 |
else if (str_pos_array[1] == str_pos_array_copy[2])
|
872 |
{
|
873 |
str_array[1] = str3;
|
874 |
}
|
875 |
else if (str_pos_array[1] == str_pos_array_copy[3])
|
876 |
{
|
877 |
str_array[1] = str4;
|
878 |
}
|
879 |
|
880 |
if (str_pos_array[2] == str_pos_array_copy[0])
|
881 |
{
|
882 |
str_array[2] = str1;
|
883 |
}
|
884 |
else if (str_pos_array[2] == str_pos_array_copy[1])
|
885 |
{
|
886 |
str_array[2] = str2;
|
887 |
}
|
888 |
else if (str_pos_array[2] == str_pos_array_copy[2])
|
889 |
{
|
890 |
str_array[2] = str3;
|
891 |
}
|
892 |
else if (str_pos_array[2] == str_pos_array_copy[3])
|
893 |
{
|
894 |
str_array[2] = str4;
|
895 |
}
|
896 |
|
897 |
if (str_pos_array[3] == str_pos_array_copy[0])
|
898 |
{
|
899 |
str_array[3] = str1;
|
900 |
}
|
901 |
else if (str_pos_array[3] == str_pos_array_copy[1])
|
902 |
{
|
903 |
str_array[3] = str2;
|
904 |
}
|
905 |
else if (str_pos_array[3] == str_pos_array_copy[2])
|
906 |
{
|
907 |
str_array[3] = str3;
|
908 |
}
|
909 |
else if (str_pos_array[3] == str_pos_array_copy[3])
|
910 |
{
|
911 |
str_array[3] = str4;
|
912 |
}
|
913 |
|
914 |
ret_str = g_strdup_printf(format_changed, str_array[0], str_array[1], str_array[2], str_array[3]);
|
915 |
// ---- here comes the ugly part ...
|
916 |
|
917 |
free(format_changed);
|
918 |
|
919 |
return ret_str;
|
920 |
}
|
921 |
|
922 |
|
923 |
char* g_strdup_printf_2_str(const char *format, const char *str1, const char *str2)
|
924 |
{
|
925 |
static int str_pos_array[2];
|
926 |
|
927 |
str_pos_array[0] = (unsigned int)strstr(format, "%1$s");
|
928 |
str_pos_array[1] = (unsigned int)strstr(format, "%2$s");
|
929 |
|
930 |
// -- now remove the position info for format --
|
931 |
char *format_changed_2 = replace_str2(format, "%1$s", "%s");
|
932 |
char *format_changed = replace_str2(format_changed_2, "%2$s", "%s");
|
933 |
free(format_changed_2);
|
934 |
// -- now remove the position info for format --
|
935 |
|
936 |
char* ret_str = NULL;
|
937 |
// ---- here comes the ugly part ...
|
938 |
|
939 |
if (str_pos_array[0] > str_pos_array[1])
|
940 |
{
|
941 |
ret_str = g_strdup_printf(format_changed, str2, str1);
|
942 |
}
|
943 |
else
|
944 |
{
|
945 |
ret_str = g_strdup_printf(format_changed, str1, str2);
|
946 |
}
|
947 |
// ---- here comes the ugly part ...
|
948 |
|
949 |
free(format_changed);
|
950 |
|
951 |
return ret_str;
|
952 |
}
|
953 |
|
954 |
|
955 |
|
956 |
|