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