]> Pileus Git - lackey/blob - cals/dummy.c
Add simple config file parser
[lackey] / cals / dummy.c
1 /*
2  * Copyright (C) 2012 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 <stdlib.h>
19
20 #include "util.h"
21 #include "conf.h"
22 #include "date.h"
23 #include "cal.h"
24
25 /* Test data */
26 static cal_t cal = {
27         .name  = "dummy",
28         .desc  = "dummy calendar",
29         .data  = NULL,
30 };
31
32 static event_t event = {
33         .cal   = &cal,
34         .start = {2012, OCT, 0, 12, 0},
35         .end   = {2012, OCT, 0, 13, 0},
36         .name  = "dummy event",
37         .desc  = "this event is random and does not exist",
38 };
39
40 static todo_t todo = {
41         .cal     = &cal,
42         .name    = "dummy todo",
43         .desc    = "this todo is random and does not exist",
44         .due     = {2012, OCT, 0, 13, 0},
45         .status  = 50,
46 };
47
48 static int     enable;
49
50 /* Config parser */
51 void dummy_config(const char *group, const char *name, const char *key, const char *value)
52 {
53         if (match(group, "dummy") && match(key, "enable"))
54                 enable = get_bool(value);
55 }
56
57 /* Event functions */
58 event_t *dummy_events(date_t start, date_t end)
59 {
60         event_t *last = &event;
61         for (int i = 0; i < 8; i++) {
62                 last->next        = new0(event_t);
63                 last->next->cal   = event.cal;
64                 last->next->start = event.start;
65                 last->next->end   = event.end;
66                 last->next->name  = strcopy(event.name);
67                 last->next->desc  = strcopy(event.desc);
68
69                 date_t *s = &last->next->start;
70                 date_t *e = &last->next->end;
71                 add_days(&s->year, &s->month, &s->day, 7*i);
72                 add_days(&e->year, &e->month, &e->day, 7*i);
73
74                 last = last->next;
75                 last->next = NULL;
76         }
77         return enable ? event.next : 0;
78 }
79
80 /* Todo functions */
81 todo_t *dummy_todos(date_t start, date_t end)
82 {
83         todo_t *last = &todo;
84         for (int i = 0; i < 6; i++) {
85                 last->next = new0(event_t);
86                 last->next->cal    = todo.cal;
87                 last->next->name   = strcopy(todo.name);
88                 last->next->desc   = strcopy(todo.desc);
89                 last->next->due    = todo.due;
90                 last->next->status = todo.status;
91                 last = last->next;
92                 last->next = NULL;
93         }
94         return enable ? todo.next : 0;
95 }