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

Contents of /navit/navit/start_real.c

Parent Directory Parent Directory | Revision Log Revision Log


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

   
Visit the ZANavi Wiki