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

Contents of /navit/navit/start_real.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations) (download)
Fri Oct 28 21:19:04 2011 UTC (12 years, 5 months ago) by zoff99
File MIME type: text/plain
File size: 5454 byte(s)
import files
1 zoff99 2 /**
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) list = g_list_append(list,g_strdup(config_file));
150     else {
151     list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_USER_DATADIR"), "/navit.xml" , NULL));
152     list = g_list_append(list,g_strdup("navit.xml.local"));
153     list = g_list_append(list,g_strdup("navit.xml"));
154     #ifdef HAVE_API_ANDROID
155     // new preferred location (the new one should have priority over the legacy!)
156     list = g_list_append(list,g_strdup("/sdcard/zanavi/navit.xml"));
157     #endif
158     list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml.local" , NULL));
159     list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml" , NULL));
160     #ifndef _WIN32
161     list = g_list_append(list,g_strdup("/etc/navit/navit.xml"));
162     #endif
163     }
164     li = list;
165     for (;;) {
166     if (li == NULL) {
167     // We have not found an existing config file from all possibilities
168     dbg(0,_("No config file navit.xml, navit.xml.local found\n"));
169     return 1;
170     }
171     // Try the next config file possibility from the list
172     config_file = li->data;
173     if (file_exists(config_file))
174     {
175     break;
176     }
177     else
178     g_free(config_file);
179     li = g_list_next(li);
180     }
181    
182     if (!config_load(config_file, &error)) {
183     dbg(0, _("Error parsing '%s': %s\n"), config_file, error ? error->message : "");
184     } else {
185     dbg(0, _("Using '%s'\n"), config_file);
186     }
187     while (li) {
188     g_free(li->data);
189     li = g_list_next(li);
190     }
191     g_list_free(list);
192     if (! config_get_attr(config, attr_navit, &navit, NULL) && !config_empty_ok) {
193     dbg(0, _("No instance has been created, exiting\n"));
194     exit(1);
195     }
196     event_main_loop_run();
197    
198     dbg(0,"1 after main loop ##########################");
199     dbg(0,"2 after main loop ##########################");
200     dbg(0,"3 after main loop ##########################");
201     dbg(0,"4 after main loop ##########################");
202     dbg(0,"5 after main loop ##########################");
203    
204     #ifndef HAVE_API_ANDROID
205     debug_finished();
206     #endif
207     return 0;
208     }

   
Visit the ZANavi Wiki