2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
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.
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.
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.
35 #include "navigation.h"
39 #include "event_glib.h"
40 #include "xmlconfig.h"
43 #include "start_real.h"
44 #include "linguistics.h"
45 #include "navit_nls.h"
48 #ifdef HAVE_API_WIN32_CE
53 char *version=PACKAGE_VERSION" "SVN_VERSION""NAVIT_VARIANT;
60 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"));
65 extern void builtin_init(void);
66 #endif /* USE_PLUGINS*/
68 int main_real(int argc, char **argv)
70 xmlerror *error = NULL;
71 char *config_file = NULL, *command=NULL, *startup_file=NULL;
74 struct attr navit, conf;
76 GList *list = NULL, *li;
84 _g_slice_thread_init_nomessage();
91 cp = getenv("NAVIT_LOGFILE");
93 debug_set_logfile(cp);
95 #ifdef HAVE_API_WIN32_CE
97 debug_set_logfile("/Storage Card/navit.log");
111 opterr=0; //don't bomb out on errors.
112 #endif /* _MSC_VER */
113 /* ingore iphone command line argument */
114 if (argc == 2 && !strcmp(argv[1],"-RegisterForSystemEvents"))
117 /* DEVELOPPERS : don't forget to update the manpage if you modify theses options */
118 while((opt = getopt(argc, argv, ":hvc:d:e:s:")) != -1) {
125 printf("%s %s\n", "navit", version);
129 printf("config file n is set to `%s'\n", optarg);
130 config_file = optarg;
133 printf("TODO Verbose option is set to `%s'\n", optarg);
143 fprintf(stderr, "navit: Error - Option `%c' needs a value\n", optopt);
148 fprintf(stderr, "navit: Error - No such option: `%c'\n", optopt);
154 // use 1st cmd line option that is left for the config file
155 if (optind < argc) config_file = argv[optind];
158 // if config file is explicitely given only look for it, otherwise try std paths
159 if (config_file) list = g_list_append(list,g_strdup(config_file));
161 list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_USER_DATADIR"), "/navit.xml" , NULL));
162 list = g_list_append(list,g_strdup("navit.xml.local"));
163 list = g_list_append(list,g_strdup("navit.xml"));
164 #ifdef HAVE_API_ANDROID
165 // new preferred location (the new one should have priority over the legacy!)
166 list = g_list_append(list,g_strdup("/sdcard/navit/navit.xml"));
167 // legacy location, still supported
168 list = g_list_append(list,g_strdup("/sdcard/navit.xml"));
170 list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml.local" , NULL));
171 list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml" , NULL));
173 list = g_list_append(list,g_strdup("/etc/navit/navit.xml"));
179 // We have not found an existing config file from all possibilities
180 dbg(0,_("No config file navit.xml, navit.xml.local found\n"));
183 // Try the next config file possibility from the list
184 config_file = li->data;
185 if (file_exists(config_file))
191 li = g_list_next(li);
194 if (!config_load(config_file, &error)) {
195 dbg(0, _("Error parsing '%s': %s\n"), config_file, error ? error->message : "");
197 dbg(0, _("Using '%s'\n"), config_file);
201 li = g_list_next(li);
204 if (! config_get_attr(config, attr_navit, &navit, NULL) && !config_empty_ok) {
205 dbg(0, _("No instance has been created, exiting\n"));
208 conf.type=attr_config;
209 conf.u.config=config;
211 FILE *f=fopen(startup_file,"r");
214 while(fgets(buffer, sizeof(buffer), f)) {
215 command_evaluate(&conf, buffer);
220 command_evaluate(&conf, command);
222 event_main_loop_run();
224 #ifndef HAVE_API_ANDROID