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

Contents of /navit/navit/start_real.c

Parent Directory Parent Directory | Revision Log Revision Log


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

   
Visit the ZANavi Wiki