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

Contents of /navit/navit/start_real.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 27 - (show annotations) (download)
Mon Apr 9 21:27:36 2012 UTC (11 years, 11 months ago) by zoff99
File MIME type: text/plain
File size: 5209 byte(s)
lots of new stuff, tranlsations, bug fixes ...
1 /**
2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
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 #include <stdio.h>
21 #include <stdlib.h>
22 #include <glib.h>
23 #include "config.h"
24 #ifdef HAVE_GETOPT_H
25 #include <getopt.h>
26 #else
27 #include <XGetopt.h>
28 #endif
29 #include "config_.h"
30 #include "version.h"
31 #include "item.h"
32 #include "coord.h"
33 #include "main.h"
34 #include "route.h"
35 #include "navigation.h"
36 #include "track.h"
37 #include "debug.h"
38 #include "event.h"
39 #include "event_glib.h"
40 #include "xmlconfig.h"
41 #include "file.h"
42 #include "search.h"
43 #include "start_real.h"
44 #include "linguistics.h"
45 #include "navit_nls.h"
46 #include "atom.h"
47 #ifdef HAVE_API_WIN32_CE
48 #include <windows.h>
49 #include <winbase.h>
50 #endif
51
52 char *version=PACKAGE_VERSION" "SVN_VERSION""NAVIT_VARIANT;
53 int main_argc;
54 char **main_argv;
55
56 static void
57 print_usage(void)
58 {
59 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");
60 }
61
62
63 #ifndef USE_PLUGINS
64 extern void builtin_init(void);
65 #endif /* USE_PLUGINS*/
66
67 int main_real(int argc, char **argv)
68 {
69 xmlerror *error = NULL;
70 char *config_file = NULL;
71 int opt;
72 char *cp;
73 struct attr navit;
74
75 GList *list = NULL, *li;
76 main_argc=argc;
77 main_argv=argv;
78
79
80 #ifdef HAVE_GLIB
81 event_glib_init();
82 #else
83 _g_slice_thread_init_nomessage();
84 #endif
85 atom_init();
86 main_init(argv[0]);
87 main_init_nls();
88 debug_init(argv[0]);
89
90 cp = getenv("NAVIT_LOGFILE");
91 if (cp) {
92 debug_set_logfile(cp);
93 }
94 #ifdef HAVE_API_WIN32_CE
95 else {
96 debug_set_logfile("/Storage Card/navit.log");
97 }
98 #endif
99 file_init();
100 #ifndef USE_PLUGINS
101 builtin_init();
102 #endif
103 route_init();
104 navigation_init();
105 tracking_init();
106 search_init();
107 linguistics_init();
108 config_file=NULL;
109 #ifdef HAVE_GETOPT_H
110 opterr=0; //don't bomb out on errors.
111 #endif /* _MSC_VER */
112 if (argc > 1) {
113 /* DEVELOPPERS : don't forget to update the manpage if you modify theses options */
114 while((opt = getopt(argc, argv, ":hvc:d:")) != -1) {
115 switch(opt) {
116 case 'h':
117 print_usage();
118 exit(0);
119 break;
120 case 'v':
121 printf("%s %s\n", "navit", version);
122 exit(0);
123 break;
124 case 'c':
125 printf("config file n is set to `%s'\n", optarg);
126 config_file = optarg;
127 break;
128 case 'd':
129 printf("TODO Verbose option is set to `%s'\n", optarg);
130 break;
131 #ifdef HAVE_GETOPT_H
132 case ':':
133 fprintf(stderr, "navit: Error - Option `%c' needs a value\n", optopt);
134 print_usage();
135 exit(1);
136 break;
137 case '?':
138 fprintf(stderr, "navit: Error - No such option: `%c'\n", optopt);
139 print_usage();
140 exit(1);
141 #endif
142 }
143 }
144 // use 1st cmd line option that is left for the config file
145 if (optind < argc) config_file = argv[optind];
146 }
147
148 // if config file is explicitely given only look for it, otherwise try std paths
149 if (config_file)
150 {
151 list = g_list_append(list,g_strdup(config_file));
152 }
153 else
154 {
155
156 list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_USER_DATADIR"), "/navit.xml" , NULL));
157 list = g_list_append(list,g_strdup("navit.xml"));
158
159 #ifdef HAVE_API_ANDROID
160 // **disabled** // new preferred location (the new one should have priority over the legacy!)
161 // **disabled** // list = g_list_append(list,g_strdup("/sdcard/zanavi/navit.xml"));
162 #endif
163
164 list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml" , NULL));
165
166 #ifndef _WIN32
167 list = g_list_append(list,g_strdup("/etc/navit/navit.xml"));
168 #endif
169
170 }
171 li = list;
172 for (;;)
173 {
174 if (li == NULL)
175 {
176 // We have not found an existing config file from all possibilities
177 dbg(0,"No config file navit.xml, navit.xml.local found\n");
178 return 1;
179 }
180 // Try the next config file possibility from the list
181 config_file = li->data;
182 if (file_exists(config_file))
183 {
184 break;
185 }
186 else
187 g_free(config_file);
188 li = g_list_next(li);
189 }
190
191 if (!config_load(config_file, &error))
192 {
193 }
194
195 while (li)
196 {
197 g_free(li->data);
198 li = g_list_next(li);
199 }
200 g_list_free(list);
201 if (! config_get_attr(config, attr_navit, &navit, NULL) && !config_empty_ok) {
202 dbg(0, "No instance has been created, exiting\n");
203 exit(1);
204 }
205 event_main_loop_run();
206
207 dbg(0,"1 after main loop ##########################");
208 dbg(0,"2 after main loop ##########################");
209 dbg(0,"3 after main loop ##########################");
210 dbg(0,"4 after main loop ##########################");
211 dbg(0,"5 after main loop ##########################");
212
213 #ifndef HAVE_API_ANDROID
214 debug_finished();
215 #endif
216 return 0;
217 }

   
Visit the ZANavi Wiki