/[zanavi_public1]/navit/navit/start_real.c
ZANavi

Contents of /navit/navit/start_real.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Mon Feb 4 17:41:59 2013 UTC (7 years, 6 months ago) by zoff99
File MIME type: text/plain
File size: 7299 byte(s)
new map version, lots of fixes and experimental new features
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 <stdio.h>
40 #include <stdlib.h>
41 #include <glib.h>
42 #include "config.h"
43 #ifdef HAVE_GETOPT_H
44 #include <getopt.h>
45 #else
46 #include <XGetopt.h>
47 #endif
48 #include "config_.h"
49 #include "version.h"
50 #include "item.h"
51 #include "coord.h"
52 #include "main.h"
53 #include "route.h"
54 #include "navigation.h"
55 #include "track.h"
56 #include "debug.h"
57 #include "event.h"
58 #include "event_glib.h"
59 #include "xmlconfig.h"
60 #include "file.h"
61 #include "search.h"
62 #include "start_real.h"
63 #include "linguistics.h"
64 #include "navit_nls.h"
65 #include "atom.h"
66 #ifdef HAVE_API_WIN32_CE
67 #include <windows.h>
68 #include <winbase.h>
69 #endif
70
71 char *version=PACKAGE_VERSION" "SVN_VERSION""NAVIT_VARIANT;
72 int main_argc;
73 char **main_argv;
74
75 static void print_usage(void)
76 {
77 printf("navit usage:\nnavit [options] [configfile]\n\t-c <file>: use <file> as config file\n\t-d <n>: set the debug output level to <n>. (TODO)\n\t-h: print this usage info and exit.\n\t-v: Print the version and exit.\n");
78 }
79
80 #ifndef USE_PLUGINS
81 extern void builtin_init(void);
82 #endif /* USE_PLUGINS*/
83
84 int main_real(int argc, char **argv)
85 {
86 dbg(0, "in main loop 001 ##########################\n");
87
88 xmlerror *error = NULL;
89 char *config_file = NULL;
90 int opt;
91 char *cp;
92 struct attr navit;
93
94 GList *list = NULL, *li;
95 main_argc = argc;
96 main_argv = argv;
97
98 //dbg(0, "in main loop 002 ##########################\n");
99
100 #ifdef HAVE_GLIB
101 event_glib_init();
102 //dbg(0,"in main loop 003 ##########################\n");
103 #else
104 _g_slice_thread_init_nomessage();
105 //dbg(0, "in main loop 004 ##########################\n");
106 #endif
107 atom_init();
108 main_init(argv[0]);
109 main_init_nls();
110 debug_init(argv[0]);
111
112 cp = getenv("NAVIT_LOGFILE");
113 if (cp)
114 {
115 debug_set_logfile(cp);
116 }
117 #ifdef HAVE_API_WIN32_CE
118 else
119 {
120 debug_set_logfile("/Storage Card/navit.log");
121 }
122 #endif
123
124 //dbg(0, "in main loop 005 ##########################\n");
125 file_init();
126 //dbg(0, "in main loop 006 ##########################\n");
127
128 #ifndef USE_PLUGINS
129 //dbg(0, "in main loop 007 ##########################\n");
130 builtin_init();
131 #endif
132
133 //dbg(0, "in main loop 008 ##########################\n");
134 route_init();
135 //dbg(0, "in main loop 008.1 ##########################\n");
136 navigation_init();
137 //dbg(0, "in main loop 008.2 ##########################\n");
138 tracking_init();
139 //dbg(0, "in main loop 008.3 ##########################\n");
140 search_init();
141 //dbg(0, "in main loop 008.4 ##########################\n");
142 linguistics_init();
143 //dbg(0, "in main loop 0014 ##########################\n");
144
145 config_file = NULL;
146 #ifdef HAVE_GETOPT_H
147 opterr=0; //don't bomb out on errors.
148 #endif /* _MSC_VER */
149 if (argc > 1)
150 {
151 /* DEVELOPPERS : don't forget to update the manpage if you modify theses options */
152 while ((opt = getopt(argc, argv, ":hvc:d:")) != -1)
153 {
154 switch (opt)
155 {
156 case 'h':
157 print_usage();
158 exit(0);
159 break;
160 case 'v':
161 printf("%s %s\n", "navit", version);
162 exit(0);
163 break;
164 case 'c':
165 printf("config file n is set to `%s'\n", optarg);
166 config_file = optarg;
167 break;
168 case 'd':
169 printf("TODO Verbose option is set to `%s'\n", optarg);
170 break;
171 #ifdef HAVE_GETOPT_H
172 case ':':
173 fprintf(stderr, "navit: Error - Option `%c' needs a value\n", optopt);
174 print_usage();
175 exit(1);
176 break;
177 case '?':
178 fprintf(stderr, "navit: Error - No such option: `%c'\n", optopt);
179 print_usage();
180 exit(1);
181 #endif
182 }
183 }
184 // use 1st cmd line option that is left for the config file
185 if (optind < argc)
186 config_file = argv[optind];
187 }
188
189 // if config file is explicitely given only look for it, otherwise try std paths
190 if (config_file)
191 {
192 list = g_list_append(list, g_strdup(config_file));
193 }
194 else
195 {
196
197 list = g_list_append(list, g_strjoin(NULL, getenv("NAVIT_USER_DATADIR"), "/navit.xml", NULL));
198 list = g_list_append(list, g_strdup("navit.xml"));
199
200 #ifdef HAVE_API_ANDROID
201 // **disabled** // new preferred location (the new one should have priority over the legacy!)
202 // **disabled** // list = g_list_append(list,g_strdup("/sdcard/zanavi/navit.xml"));
203 #endif
204
205 list = g_list_append(list, g_strjoin(NULL, getenv("NAVIT_SHAREDIR"), "/navit.xml", NULL));
206
207 #ifndef _WIN32
208 list = g_list_append(list, g_strdup("/etc/navit/navit.xml"));
209 #endif
210
211 }
212 li = list;
213 for (;;)
214 {
215 if (li == NULL)
216 {
217 // We have not found an existing config file from all possibilities
218 dbg(0, "No config file navit.xml, navit.xml.local found\n");
219 return 1;
220 }
221 // Try the next config file possibility from the list
222 config_file = li->data;
223 if (file_exists(config_file))
224 {
225 break;
226 }
227 else
228 {
229 g_free(config_file);
230 }
231 li = g_list_next(li);
232 }
233
234 // ############### load XML config file, and call all the init/new functions ################
235 // ############### load XML config file, and call all the init/new functions ################
236 // ############### load XML config file, and call all the init/new functions ################
237 clock_t s_ = debug_measure_start();
238 if (!config_load(config_file, &error))
239 {
240 }
241 debug_mrp("load and init xmlconfig:", debug_measure_end(s_));
242 // ############### load XML config file, and call all the init/new functions ################
243 // ############### load XML config file, and call all the init/new functions ################
244 // ############### load XML config file, and call all the init/new functions ################
245
246
247 while (li)
248 {
249 g_free(li->data);
250 li = g_list_next(li);
251 }
252
253 g_list_free(list);
254
255 if (!config_get_attr(config, attr_navit, &navit, NULL) && !config_empty_ok)
256 {
257 dbg(0, "No instance has been created, exiting\n");
258 exit(1);
259 }
260
261 dbg(0, "in main loop 026 ##########################\n");
262 event_main_loop_run();
263 dbg(0, "after main loop ##########################");
264
265 #ifndef HAVE_API_ANDROID
266 debug_finished();
267 #endif
268 return 0;
269 }

   
Visit the ZANavi Wiki