From: Andy Spencer Date: Fri, 12 Oct 2012 07:15:26 +0000 (+0000) Subject: Start on iCalendar support X-Git-Url: http://pileus.org/git/?p=lackey;a=commitdiff_plain;h=1eced58b01481c1658a00183f2f27f7c3cefef1a Start on iCalendar support --- diff --git a/.gitignore b/.gitignore index 01bc8a5..c06ce8f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*.ics *.log *.o *.swp diff --git a/cal/ical.c b/cal/ical.c new file mode 100644 index 0000000..f4709a9 --- /dev/null +++ b/cal/ical.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2012 Andy Spencer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +#include "util.h" +#include "date.h" +#include "event.h" + +/* Helper functions */ +static event_t *to_event(icalcomponent *comp) +{ + event_t *event = calloc(1, sizeof(event)); + return event; +} + +/* Event functions */ +event_t *ical_get(cal_t *cal, year_t year, month_t month, day_t day, int days) +{ + (void)to_event; + return NULL; +} + +/* Test functions */ +void ical_printr(icalcomponent *comp, int depth) +{ + /* Print component */ + icalcomponent_kind kind = icalcomponent_isa(comp); + printf("%*s", depth, ""); + printf("%s", icalcomponent_kind_to_string(kind)); + if (kind == ICAL_VEVENT_COMPONENT || + kind == ICAL_VTODO_COMPONENT) + printf(" - %s", icalcomponent_get_summary(comp) ?: "[no summary]"); + printf("\n"); + + /* Print children */ + icalcomponent_kind find = ICAL_ANY_COMPONENT; + icalcomponent *child = icalcomponent_get_first_component(comp, find); + while (child) { + ical_printr(child, depth+2); + child = icalcomponent_get_next_component(comp, find); + } +} + +void ical_test(void) +{ + FILE *file = fopen("data/all.ics", "r"); + icalparser *parser = icalparser_new(); + icalparser_set_gen_data(parser, file); + icalcomponent *ical = icalparser_parse(parser, (void*)fgets); + ical_printr(ical, 0); + icalparser_free(parser); +} diff --git a/makefile b/makefile index e8bd692..0162b3a 100644 --- a/makefile +++ b/makefile @@ -4,7 +4,7 @@ CC ?= gcc CFLAGS ?= -Wall --std=c99 CPPFLAGS ?= -Isrc -LDFLAGS ?= -lncursesw +LDFLAGS ?= -lncursesw -lical # Sources PROG = lackey @@ -12,7 +12,7 @@ PROG_SRC = main screen date event util TEST = test TEST_SRC = test date VIEWS = day week month year todo notes settings help -CALS = dummy +CALS = dummy ical # Targets all: $(PROG) $(TEST) diff --git a/src/date.c b/src/date.c index eebbe79..ec71579 100644 --- a/src/date.c +++ b/src/date.c @@ -144,7 +144,7 @@ const char *day_to_string(wday_t day) } /* Test functions */ -void test_time(void) +void date_test(void) { printf("Info\n"); printf(" Year Month Start Weeks Days\n"); diff --git a/src/date.h b/src/date.h index 77f7341..9b4d278 100644 --- a/src/date.h +++ b/src/date.h @@ -73,4 +73,4 @@ const char *day_to_str(wday_t day); const char *day_to_string(wday_t day); /* Tests */ -void test_time(void); +void date_test(void); diff --git a/src/event.h b/src/event.h index 199e1dc..b75f890 100644 --- a/src/event.h +++ b/src/event.h @@ -49,3 +49,7 @@ event_t *event_get(year_t year, month_t month, day_t day, int days); /* Calendar implementation functions */ event_t *dummy_get(cal_t *cal, year_t year, month_t month, day_t day, int days); +event_t *ical_get(cal_t *cal, year_t year, month_t month, day_t day, int days); + +/* Test fuctions */ +void ical_test(void); diff --git a/src/test.c b/src/test.c index 9255c94..53822f9 100644 --- a/src/test.c +++ b/src/test.c @@ -16,9 +16,11 @@ */ #include "date.h" +#include "event.h" int main(int argc, char **argv) { - test_time(); + //date_test(); + ical_test(); return 0; }