summaryrefslogtreecommitdiff
path: root/src/fe-none/irssi.c
blob: 974ace414b2d6b222dde8b0c40c2e6f67dd227a4 (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
/*
 irssi.c : irssi

    Copyright (C) 1999-2000 Timo Sirainen

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/

#include "module.h"
#include "modules.h"
#include "modules-load.h"
#include "args.h"
#include "signals.h"
#include "core.h"

#ifdef HAVE_STATIC_PERL
void perl_core_init(void);
void perl_core_deinit(void);
#endif

void irc_init(void);
void irc_deinit(void);

static GMainLoop *main_loop;
static char *autoload_module;
static int reload;

static void sig_exit(void)
{
	g_main_quit(main_loop);
}

static void sig_reload(void)
{
	reload = TRUE;
}

void noui_init(void)
{
	static struct poptOption options[] = {
		POPT_AUTOHELP
		{ "load", 'l', POPT_ARG_STRING, &autoload_module, 0, "Module to load (default = bot)", "MODULE" },
		{ NULL, '\0', 0, NULL }
	};

	srand(time(NULL));

	autoload_module = NULL;
	args_register(options);

	irssi_gui = IRSSI_GUI_NONE;
	core_init();
	irc_init();

	module_register("core", "fe-none");

	signal_add("reload", (SIGNAL_FUNC) sig_reload);
	signal_add("gui exit", (SIGNAL_FUNC) sig_exit);

#ifdef HAVE_STATIC_PERL
        perl_core_init();
#endif

	signal_emit("irssi init finished", 0);
}

void noui_deinit(void)
{
#ifdef HAVE_STATIC_PERL
        perl_core_deinit();
#endif

	signal_remove("reload", (SIGNAL_FUNC) sig_reload);
	signal_remove("gui exit", (SIGNAL_FUNC) sig_exit);
	irc_deinit();
	core_deinit();
}

int main(int argc, char **argv)
{
	core_init_paths(argc, argv);

#ifdef HAVE_SOCKS
	SOCKSinit(argv[0]);
#endif
	noui_init();
	args_execute(argc, argv);

	if (autoload_module == NULL)
		autoload_module = "bot";

	do {
		reload = FALSE;
		module_load(autoload_module, NULL);
		main_loop = g_main_new(TRUE);
		g_main_run(main_loop);
		g_main_destroy(main_loop);
	}
	while (reload);
	noui_deinit();

	return 0;
}