/[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 - (hide 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 zoff99 2 /**
2 zoff99 30 * 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 zoff99 2 * 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 zoff99 56 #pragma clang diagnostic push
44     #pragma ide diagnostic ignored "CannotResolve"
45 zoff99 2 #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 zoff99 34 #include "navit.h"
53 zoff99 2 #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 zoff99 56 //char *version=PACKAGE_VERSION" "SVN_VERSION""NAVIT_VARIANT;
75     char *version="xxx";
76 zoff99 2 int main_argc;
77     char **main_argv;
78    
79 zoff99 31 static void print_usage(void)
80 zoff99 2 {
81 zoff99 34 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 zoff99 2 }
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 zoff99 31 dbg(0, "in main loop 001 ##########################\n");
91 zoff99 30
92 zoff99 40
93 zoff99 2 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 zoff99 31 main_argc = argc;
101     main_argv = argv;
102 zoff99 2
103 zoff99 31 //dbg(0, "in main loop 002 ##########################\n");
104 zoff99 2
105     #ifdef HAVE_GLIB
106     event_glib_init();
107 zoff99 31 //dbg(0,"in main loop 003 ##########################\n");
108 zoff99 2 #else
109     _g_slice_thread_init_nomessage();
110 zoff99 31 //dbg(0, "in main loop 004 ##########################\n");
111 zoff99 2 #endif
112 zoff99 40
113    
114 zoff99 2 atom_init();
115     main_init(argv[0]);
116     main_init_nls();
117 zoff99 40 debug_init(argv[0]); // ??
118 zoff99 2
119 zoff99 40
120 zoff99 2 cp = getenv("NAVIT_LOGFILE");
121 zoff99 30 if (cp)
122     {
123 zoff99 2 debug_set_logfile(cp);
124     }
125     #ifdef HAVE_API_WIN32_CE
126 zoff99 30 else
127     {
128 zoff99 2 debug_set_logfile("/Storage Card/navit.log");
129     }
130     #endif
131 zoff99 30
132 zoff99 40
133    
134    
135 zoff99 31 //dbg(0, "in main loop 005 ##########################\n");
136 zoff99 2 file_init();
137 zoff99 31 //dbg(0, "in main loop 006 ##########################\n");
138 zoff99 30
139 zoff99 2 #ifndef USE_PLUGINS
140 zoff99 31 //dbg(0, "in main loop 007 ##########################\n");
141 zoff99 2 builtin_init();
142     #endif
143 zoff99 30
144 zoff99 31 //dbg(0, "in main loop 008 ##########################\n");
145 zoff99 2 route_init();
146 zoff99 31 //dbg(0, "in main loop 008.1 ##########################\n");
147 zoff99 2 navigation_init();
148 zoff99 31 //dbg(0, "in main loop 008.2 ##########################\n");
149 zoff99 2 tracking_init();
150 zoff99 31 //dbg(0, "in main loop 008.3 ##########################\n");
151 zoff99 2 search_init();
152 zoff99 31 //dbg(0, "in main loop 008.4 ##########################\n");
153 zoff99 2 linguistics_init();
154 zoff99 31 //dbg(0, "in main loop 0014 ##########################\n");
155 zoff99 30
156 zoff99 40
157 zoff99 31 config_file = NULL;
158 zoff99 2 #ifdef HAVE_GETOPT_H
159 zoff99 31 opterr=0; //don't bomb out on errors.
160 zoff99 2 #endif /* _MSC_VER */
161 zoff99 31 if (argc > 1)
162     {
163 zoff99 2 /* DEVELOPPERS : don't forget to update the manpage if you modify theses options */
164 zoff99 31 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 zoff99 2 #ifdef HAVE_GETOPT_H
184 zoff99 31 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 zoff99 2 #endif
194     }
195 zoff99 31 }
196 zoff99 2 // use 1st cmd line option that is left for the config file
197 zoff99 31 if (optind < argc)
198     config_file = argv[optind];
199 zoff99 2 }
200    
201 zoff99 31 // if config file is explicitely given only look for it, otherwise try std paths
202 zoff99 34 //if (config_file)
203     //{
204     // list = g_list_append(list, g_strdup(config_file));
205     //}
206     //else
207     //{
208 zoff99 27
209 zoff99 34 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 zoff99 27
213 zoff99 2 #ifdef HAVE_API_ANDROID
214 zoff99 27 // **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 zoff99 2 #endif
217 zoff99 27
218 zoff99 34 //list = g_list_append(list, g_strjoin(NULL, getenv("NAVIT_SHAREDIR"), "/navit.xml", NULL));
219 zoff99 27
220 zoff99 2 #ifndef _WIN32
221 zoff99 34 //list = g_list_append(list, g_strdup("/etc/navit/navit.xml"));
222 zoff99 2 #endif
223 zoff99 27
224 zoff99 40
225 zoff99 34 //}
226 zoff99 2 li = list;
227 zoff99 27 for (;;)
228     {
229     if (li == NULL)
230     {
231 zoff99 2 // We have not found an existing config file from all possibilities
232 zoff99 31 dbg(0, "No config file navit.xml, navit.xml.local found\n");
233 zoff99 2 return 1;
234     }
235 zoff99 31 // Try the next config file possibility from the list
236 zoff99 2 config_file = li->data;
237     if (file_exists(config_file))
238     {
239     break;
240     }
241     else
242 zoff99 30 {
243 zoff99 2 g_free(config_file);
244 zoff99 30 }
245 zoff99 2 li = g_list_next(li);
246     }
247    
248 zoff99 40
249 zoff99 30 // ############### 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 zoff99 27 if (!config_load(config_file, &error))
254     {
255 zoff99 2 }
256 zoff99 30 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 zoff99 27
261     while (li)
262     {
263 zoff99 2 g_free(li->data);
264     li = g_list_next(li);
265     }
266 zoff99 30
267 zoff99 2 g_list_free(list);
268 zoff99 30
269 zoff99 40
270 zoff99 31 if (!config_get_attr(config, attr_navit, &navit, NULL) && !config_empty_ok)
271 zoff99 30 {
272 zoff99 27 dbg(0, "No instance has been created, exiting\n");
273 zoff99 2 exit(1);
274     }
275 zoff99 30
276 zoff99 31 dbg(0, "in main loop 026 ##########################\n");
277 zoff99 2 event_main_loop_run();
278 zoff99 31 dbg(0, "after main loop ##########################");
279 zoff99 2
280     #ifndef HAVE_API_ANDROID
281     debug_finished();
282     #endif
283 zoff99 40
284    
285 zoff99 2 return 0;
286     }
287 zoff99 56
288     #pragma clang diagnostic pop

   
Visit the ZANavi Wiki