summaryrefslogtreecommitdiff
path: root/main.c
blob: ea6b6900612958709496dd3c18fdf7ce62b95d7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <locale.h>
#include <stdlib.h>
#include <stdio.h>
#include <glib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <libintl.h>
#ifdef USE_GTK_MAIN_LOOP
#include <gtk/gtk.h>
#endif
#include "file.h"
#include "debug.h"
#include "main.h"
#include "navit.h"
#include "gui.h"
#include "plugin.h"
#include "xmlconfig.h"

#define _(STRING)    gettext(STRING)

struct map_data *map_data_default;

static void sigchld(int sig)
{
	int status;
	while (waitpid(-1, &status, WNOHANG) > 0);
}


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;
#ifndef USE_GTK_MAIN_LOOP
static GMainLoop *loop;
#endif

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) {
#ifdef USE_GTK_MAIN_LOOP
		gtk_main_quit();
#else
		if (loop)
			g_main_loop_quit(loop);
#endif
	}
}

int main(int argc, char **argv)
{
	GError *error = NULL;
	char *config_file = NULL;

	signal(SIGCHLD, sigchld);

	setenv("LC_NUMERIC","C",1);
	setlocale(LC_ALL,"");
	setlocale(LC_NUMERIC,"C");
	setlocale(LC_NUMERIC,"C");

	if (file_exists("navit.c")) {
		printf(_("Running from source directory\n"));
	}
        bindtextdomain( "navit", "/usr/share/locale" );
	textdomain( "navit" );

	debug_init();
#if 0
	/* handled in gui/gtk */
	gtk_set_locale();
	gtk_init(&argc, &argv);
	gdk_rgb_init();
#endif

	if (argc > 1) 
		config_file=argv[1];
	else {
		config_file=g_strjoin(NULL,get_home_directory(), "/.navit/navit.xml" , NULL);
		if (!file_exists(config_file)) {
			if (file_exists("navit.xml.local"))
				config_file="navit.xml.local";
			else
				config_file="navit.xml";
		}
	}
	if (!config_load(config_file, &error)) {
		g_error(_("Error parsing '%s': %s\n"), config_file, error->message);
	} 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 {
#ifdef USE_GTK_MAIN_LOOP
		gtk_main();
#else
		loop = g_main_loop_new (NULL, TRUE);
		if (g_main_loop_is_running (loop))
		{
			g_main_loop_run (loop);
		}
#endif
	}

	return 0;
}