23 #include "xmlconfig.h"
27 #include "navigation.h"
30 #define _(STRING) gettext(STRING)
32 struct map_data *map_data_default;
34 static void sigchld(int sig)
38 while (waitpid(-1, &status, WNOHANG) > 0);
43 gchar *get_home_directory(void)
45 static gchar *homedir = NULL;
47 if (homedir) return homedir;
48 homedir = getenv("HOME");
51 g_warning("Could not find home directory. Using current directory as home directory.");
66 struct iter *ret=g_new0(struct iter, 1);
72 main_iter_destroy(struct iter *iter)
78 main_get_navit(struct iter *iter)
81 struct navit *ret=NULL;
87 ret=(struct navit *)(list->data);
89 iter->list=g_list_next(iter->list);
95 main_add_navit(struct navit *nav)
97 navit=g_list_prepend(navit, nav);
101 main_remove_navit(struct navit *nav)
103 navit=g_list_remove(navit, nav);
105 event_main_loop_quit();
111 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"));
114 int main(int argc, char **argv)
116 GError *error = NULL;
117 char *config_file = NULL;
123 signal(SIGCHLD, sigchld);
126 setenv("LC_NUMERIC","C",1);
127 setlocale(LC_ALL,"");
128 setlocale(LC_NUMERIC,"C");
129 if (file_exists("navit.c") || file_exists("navit.o")) {
130 char buffer[PATH_MAX];
131 printf(_("Running from source directory\n"));
132 getcwd(buffer, PATH_MAX);
133 setenv("NAVIT_PREFIX", buffer, 0);
134 setenv("NAVIT_LIBDIR", buffer, 0);
135 setenv("NAVIT_SHAREDIR", buffer, 0);
136 setenv("NAVIT_LIBPREFIX", "*/.libs/", 0);
137 s=g_strdup_printf("%s/../locale", buffer);
138 setenv("NAVIT_LOCALEDIR", s, 0);
141 if (!getenv("NAVIT_PREFIX")) {
143 if (l > 10 && !strcmp(argv[0]+l-10,"/bin/navit")) {
146 if (strcmp(s, PREFIX))
147 printf(_("setting '%s' to '%s'\n"), "NAVIT_PREFIX", s);
148 setenv("NAVIT_PREFIX", s, 0);
151 setenv("NAVIT_PREFIX", PREFIX, 0);
154 s=g_strdup_printf("locale");
156 s=g_strdup_printf("%s/share/locale", getenv("NAVIT_PREFIX"));
158 setenv("NAVIT_LOCALEDIR", s, 0);
161 s=g_strdup_printf(".");
163 s=g_strdup_printf("%s/share/navit", getenv("NAVIT_PREFIX"));
165 setenv("NAVIT_SHAREDIR", s, 0);
167 s=g_strdup_printf("%s/lib/navit", getenv("NAVIT_PREFIX"));
168 setenv("NAVIT_LIBDIR", s, 0);
171 bindtextdomain(PACKAGE, getenv("NAVIT_LOCALEDIR"));
172 bind_textdomain_codeset (PACKAGE, "UTF-8");
176 if (getenv("LC_ALL"))
177 dbg(0,"Warning: LC_ALL is set, this might lead to problems\n");
179 extern void builtin_init(void);
183 /* handled in gui/gtk */
185 gtk_init(&argc, &argv);
188 s = getenv("NAVIT_WID");
190 setenv("SDL_WINDOWID", s, 0);
196 opterr=0; //don't bomb out on errors.
198 while((opt = getopt(argc, argv, ":hvc:d:")) != -1) {
205 printf("%s %s\n", "navit", "0.0.4+svn");
209 printf("config file n is set to `%s'\n", optarg);
210 config_file = optarg;
213 printf("TODO Verbose option is set to `%s'\n", optarg);
216 fprintf(stderr, "navit: Error - Option `%c' needs a value\n", optopt);
221 fprintf(stderr, "navit: Error - No such option: `%c'\n", optopt);
227 // use 1st cmd line option that is left for the config file
228 if (optind < argc) config_file = argv[optind];
230 GList *list = NULL, *li;
231 // if config file is explicitely given only look for it, otherwise try std paths
232 if (config_file) list = g_list_append(list,g_strdup(config_file));
234 list = g_list_append(list,g_strjoin(NULL,get_home_directory(), "/.navit/navit.xml" , NULL));
235 list = g_list_append(list,g_strdup("navit.xml.local"));
236 list = g_list_append(list,g_strdup("navit.xml"));
237 list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml.local" , NULL));
238 list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml" , NULL));
243 // We have not found an existing config file from all possibilities
244 printf(_("No config file navit.xml, navit.xml.local found\n"));
247 // Try the next config file possibility from the list
248 config_file = li->data;
249 if (!file_exists(config_file)) g_free(config_file);
250 li = g_list_next(li);
251 } while (!file_exists(config_file));
254 if (!config_load(config_file, &error)) {
255 printf(_("Error parsing '%s': %s\n"), config_file, error->message);
258 printf(_("Using '%s'\n"), config_file);
261 printf(_("No instance has been created, exiting\n"));
265 gui_run_main_loop(main_loop_gui);
267 event_main_loop_run();