]> Pileus Git - ~andy/lamechat/blob - main.c
Make logfile optional.
[~andy/lamechat] / main.c
1 /*
2  * Copyright (C) 2012-2013 Andy Spencer <andy753421@gmail.com>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
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.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <signal.h>
21
22 #include "util.h"
23 #include "net.h"
24 #include "args.h"
25 #include "conf.h"
26 #include "chat.h"
27 #include "view.h"
28
29 /* Config parser */
30 static void on_config(const char *group, const char *name, const char *key, const char *value)
31 {
32         util_config(group, name, key, value);
33         view_config(group, name, key, value);
34         chat_config(group, name, key, value);
35 }
36
37 /* Control-C handler, so we don't hose the therminal */
38 static void on_sigint(int signum)
39 {
40         notice("Use /quit to exit");
41         signal(SIGINT, on_sigint);
42         view_sync();
43 }
44
45 /* Main */
46 int main(int argc, char **argv)
47 {
48         /* Misc setup */
49         signal(SIGINT, on_sigint);
50
51         /* Early setup */
52         args_setup(argc, argv);
53         conf_setup(".lamechatrc", on_config);
54
55         /* Initialize */
56         util_init();
57         net_init();
58         chat_init();
59         view_init();
60
61         /* Main loop */
62         while (poll_run(1000)) {
63                 view_sync();
64                 conf_sync();
65         }
66
67         /* Exit */
68         chat_exit();
69         view_exit();
70         util_exit();
71
72         return 0;
73 }