]> Pileus Git - lackey/blob - cal/ical.c
Start on iCalendar support
[lackey] / cal / ical.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 <stdio.h>
19 #include <stdlib.h>
20 #include <libical/ical.h>
21
22 #include "util.h"
23 #include "date.h"
24 #include "event.h"
25
26 /* Helper functions */
27 static event_t *to_event(icalcomponent *comp)
28 {
29         event_t *event = calloc(1, sizeof(event));
30         return event;
31 }
32
33 /* Event functions */
34 event_t *ical_get(cal_t *cal, year_t year, month_t month, day_t day, int days)
35 {
36         (void)to_event;
37         return NULL;
38 }
39
40 /* Test functions */
41 void ical_printr(icalcomponent *comp, int depth)
42 {
43         /* Print component */
44         icalcomponent_kind kind = icalcomponent_isa(comp);
45         printf("%*s", depth, "");
46         printf("%s",  icalcomponent_kind_to_string(kind));
47         if (kind == ICAL_VEVENT_COMPONENT ||
48             kind == ICAL_VTODO_COMPONENT)
49                 printf(" - %s", icalcomponent_get_summary(comp) ?: "[no summary]");
50         printf("\n");
51
52         /* Print children */
53         icalcomponent_kind find = ICAL_ANY_COMPONENT;
54         icalcomponent *child = icalcomponent_get_first_component(comp, find);
55         while (child) {
56                 ical_printr(child, depth+2);
57                 child = icalcomponent_get_next_component(comp, find);
58         }
59 }
60
61 void ical_test(void)
62 {
63         FILE *file = fopen("data/all.ics", "r");
64         icalparser *parser = icalparser_new();
65         icalparser_set_gen_data(parser, file);
66         icalcomponent *ical = icalparser_parse(parser, (void*)fgets);
67         ical_printr(ical, 0);
68         icalparser_free(parser);
69 }