summaryrefslogtreecommitdiff
path: root/navit/main.c
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-05-18 10:01:53 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-05-18 10:01:53 +0000
commit0b74d7f4ee6d448ac811e2741e8cb1ed04f5ce76 (patch)
treebe7bb1cb1020f4022e41c004e2fa9d561ea3580d /navit/main.c
parentf46eb419c46011d6d103b7f06cb2c842a2cbe6c9 (diff)
downloadnavit-0b74d7f4ee6d448ac811e2741e8cb1ed04f5ce76.tar.gz
Fix:Core:Renamed src to navit for cleanup of includes
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@1059 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/main.c')
-rw-r--r--navit/main.c246
1 files changed, 246 insertions, 0 deletions
diff --git a/navit/main.c b/navit/main.c
new file mode 100644
index 000000000..f320ae67e
--- /dev/null
+++ b/navit/main.c
@@ -0,0 +1,246 @@
+#include <locale.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <glib.h>
+#include <sys/types.h>
+
+#ifndef _WIN32
+#include <sys/wait.h>
+#include <signal.h>
+#endif
+
+#include <unistd.h>
+#include <libintl.h>
+#include "config.h"
+#include "file.h"
+#include "debug.h"
+#include "main.h"
+#include "navit.h"
+#include "gui.h"
+#include "xmlconfig.h"
+#include "item.h"
+#include "coord.h"
+#include "route.h"
+#include "navigation.h"
+#include "event.h"
+
+#define _(STRING) gettext(STRING)
+
+struct map_data *map_data_default;
+
+static void sigchld(int sig)
+{
+#ifndef _WIN32
+ int status;
+ while (waitpid(-1, &status, WNOHANG) > 0);
+#endif
+}
+
+
+static gchar *get_home_directory(void)
+{
+ static gchar *homedir = NULL;
+
+ if (homedir) return homedir;
+ homedir = getenv("HOME");
+ if (!homedir)
+ {
+// struct passwd *p;
+
+// p = getpwuid(getuid());
+// if (p) homedir = p->pw_dir;
+ }
+ if (!homedir)
+ {
+ g_warning("Could not find home directory. Using current directory as home directory.");
+ homedir = ".";
+ }
+ return homedir;
+}
+
+static GList *navit;
+
+struct iter {
+ GList *list;
+};
+
+struct iter *
+main_iter_new(void)
+{
+ struct iter *ret=g_new0(struct iter, 1);
+ ret->list=navit;
+ return ret;
+}
+
+void
+main_iter_destroy(struct iter *iter)
+{
+ g_free(iter);
+}
+
+struct navit *
+main_get_navit(struct iter *iter)
+{
+ GList *list;
+ struct navit *ret=NULL;
+ if (iter)
+ list=iter->list;
+ else
+ list=navit;
+ if (list) {
+ ret=(struct navit *)(list->data);
+ if (iter)
+ iter->list=g_list_next(iter->list);
+ }
+ return ret;
+
+}
+void
+main_add_navit(struct navit *nav)
+{
+ navit=g_list_prepend(navit, nav);
+}
+
+void
+main_remove_navit(struct navit *nav)
+{
+ navit=g_list_remove(navit, nav);
+ if (! navit)
+ event_main_loop_quit();
+}
+
+int main(int argc, char **argv)
+{
+ GError *error = NULL;
+ char *config_file = NULL;
+ char *s;
+ int l;
+
+
+#ifndef _WIN32
+ signal(SIGCHLD, sigchld);
+#endif
+
+ setenv("LC_NUMERIC","C",1);
+ setlocale(LC_ALL,"");
+ setlocale(LC_NUMERIC,"C");
+ if (file_exists("navit.c") || file_exists("navit.o")) {
+ char buffer[PATH_MAX];
+ printf(_("Running from source directory\n"));
+ getcwd(buffer, PATH_MAX);
+ setenv("NAVIT_PREFIX", buffer, 0);
+ setenv("NAVIT_LIBDIR", buffer, 0);
+ setenv("NAVIT_SHAREDIR", buffer, 0);
+ setenv("NAVIT_LIBPREFIX", "*/.libs/", 0);
+ s=g_strdup_printf("%s/../locale", buffer);
+ setenv("NAVIT_LOCALEDIR", s, 0);
+ g_free(s);
+ } else {
+ if (!getenv("NAVIT_PREFIX")) {
+ l=strlen(argv[0]);
+ if (l > 10 && !strcmp(argv[0]+l-10,"/bin/navit")) {
+ s=g_strdup(argv[0]);
+ s[l-10]='\0';
+ if (strcmp(s, PREFIX))
+ printf(_("setting '%s' to '%s'\n"), "NAVIT_PREFIX", s);
+ setenv("NAVIT_PREFIX", s, 0);
+ g_free(s);
+ } else
+ setenv("NAVIT_PREFIX", PREFIX, 0);
+ }
+#ifdef _WIN32
+ s=g_strdup_printf("locale");
+#else
+ s=g_strdup_printf("%s/share/locale", getenv("NAVIT_PREFIX"));
+#endif
+ setenv("NAVIT_LOCALEDIR", s, 0);
+ g_free(s);
+#ifdef _WIN32
+ s=g_strdup_printf(".");
+#else
+ s=g_strdup_printf("%s/share/navit", getenv("NAVIT_PREFIX"));
+#endif
+ setenv("NAVIT_SHAREDIR", s, 0);
+ g_free(s);
+ s=g_strdup_printf("%s/lib/navit", getenv("NAVIT_PREFIX"));
+ setenv("NAVIT_LIBDIR", s, 0);
+ g_free(s);
+ }
+ bindtextdomain(PACKAGE, getenv("NAVIT_LOCALEDIR"));
+ bind_textdomain_codeset (PACKAGE, "UTF-8");
+ textdomain(PACKAGE);
+
+ debug_init(argv[0]);
+ if (getenv("LC_ALL"))
+ dbg(0,"Warning: LC_ALL is set, this might lead to problems\n");
+#ifndef USE_PLUGINS
+ extern void builtin_init(void);
+ builtin_init();
+#endif
+#if 0
+ /* handled in gui/gtk */
+ gtk_set_locale();
+ gtk_init(&argc, &argv);
+ gdk_rgb_init();
+#endif
+ s = getenv("NAVIT_WID");
+ if (s) {
+ setenv("SDL_WINDOWID", s, 0);
+ }
+ route_init();
+ navigation_init();
+ config_file=NULL;
+ if (argc > 1)
+ config_file=argv[1];
+ if (! config_file) {
+ config_file=g_strjoin(NULL,get_home_directory(), "/.navit/navit.xml" , NULL);
+ if (!file_exists(config_file)) {
+ g_free(config_file);
+ config_file=NULL;
+ }
+ }
+ if (! config_file) {
+ if (file_exists("navit.xml.local"))
+ config_file="navit.xml.local";
+ }
+ if (! config_file) {
+ if (file_exists("navit.xml"))
+ config_file="navit.xml";
+ }
+ if (! config_file) {
+ config_file=g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml.local" , NULL);
+ if (!file_exists(config_file)) {
+ g_free(config_file);
+ config_file=NULL;
+ }
+ }
+ if (! config_file) {
+ config_file=g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml" , NULL);
+ if (!file_exists(config_file)) {
+ g_free(config_file);
+ config_file=NULL;
+ }
+ }
+ if (!config_file) {
+ printf(_("No config file navit.xml, navit.xml.local found\n"));
+ exit(1);
+ }
+ if (!config_load(config_file, &error)) {
+ printf(_("Error parsing '%s': %s\n"), config_file, error->message);
+ exit(1);
+ } else {
+ printf(_("Using '%s'\n"), config_file);
+ }
+ if (! navit) {
+ printf(_("No instance has been created, exiting\n"));
+ exit(1);
+ }
+ if (main_loop_gui) {
+ gui_run_main_loop(main_loop_gui);
+ } else
+ event_main_loop_run();
+
+ return 0;
+}