]> Pileus Git - lackey/blob - src/main.c
bf518ffdd7201ce9219be3ecc1868365788ad677
[lackey] / src / 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 "args.h"
24 #include "conf.h"
25 #include "date.h"
26 #include "cal.h"
27 #include "view.h"
28 #include "print.h"
29
30 /* Config parser */
31 static void on_config(const char *group, const char *name, const char *key, const char *value)
32 {
33         date_config(group, name, key, value);
34         cal_config(group, name, key, value);
35         view_config(group, name, key, value);
36 }
37
38 /* Control-C handler, so we don't hose the therminal */
39 static void on_sigint(int signum)
40 {
41         if (PRINT)
42                 print_exit();
43         else
44                 view_exit();
45         exit(0);
46 }
47
48 /* Main */
49 int main(int argc, char **argv)
50 {
51         /* Misc setup */
52         signal(SIGINT, on_sigint);
53
54         /* Configuration */
55         args_setup(argc, argv);
56         conf_setup(".lackeyrc", on_config);
57
58         /* Initialize */
59         util_init();
60         date_init();
61         cal_init();
62
63         /* Common main */
64         args_start();
65         conf_start();
66
67         /* Mode main */
68         if (PRINT) {
69                 print_init();
70                 print_main();
71                 print_exit();
72         }
73         else {
74                 view_init();
75                 view_main();
76                 view_exit();
77         }
78
79         return 0;
80 }