X-Git-Url: http://pileus.org/git/?p=lackey;a=blobdiff_plain;f=cals%2Fical.c;h=8e51a8640802e813eabd6103972dbe9699f58022;hp=4336e8157b305539cf50bd6762e5ebcd8942bb5c;hb=f45d7e37ac9dd4e70a89671edf862a868f8ab343;hpb=6ac1b1fd9d2e720954d6cc4d9d493ce6a3c3fd8d diff --git a/cals/ical.c b/cals/ical.c index 4336e81..8e51a86 100644 --- a/cals/ical.c +++ b/cals/ical.c @@ -114,6 +114,18 @@ static void add_recur(cal_t *cal, /* Add all recurrences */ rrule = icalcomponent_get_first_property(comp, ICAL_RRULE_PROPERTY); + + /* One-time event */ + if (!rrule) { + icalarray_append(array, &(ical_inst){ + .cal = cal, + .comp = comp, + .start = cstart, + .end = cend, + }); + } + + /* Recurring events */ while (rrule) { recur = icalproperty_get_rrule(rrule); iter = icalrecur_iterator_new(recur, cstart); @@ -156,20 +168,24 @@ static void add_recur(cal_t *cal, static void read_icals(void) { for (ical_t *cal = calendars; cal; cal = cal->next) { - if (cal->comp == NULL && cal->location) { - wordexp_t wexp; - wordexp(cal->location, &wexp, WRDE_NOCMD); - icalparser *parser = icalparser_new(); - for (int i = 0; i < wexp.we_wordc; i++) { - FILE *file = fopen(wexp.we_wordv[i], "r"); - if (!file) - continue; - icalparser_set_gen_data(parser, file); - } + if (!cal->location) + debug("Missing location for ical '%s'", cal->cal.name); + if (cal->comp) + continue; + wordexp_t wexp; + wordexp(cal->location, &wexp, WRDE_NOCMD); + icalparser *parser = icalparser_new(); + if (wexp.we_wordc > 1) + debug("Multiple calendards are not supported '%s'", cal->location); + FILE *file = fopen(wexp.we_wordv[0], "r"); + if (!file) { + debug("Cannot open ical file '%s'", wexp.we_wordv[0]); + } else { + icalparser_set_gen_data(parser, file); cal->comp = icalparser_parse(parser, (void*)fgets); icalparser_free(parser); - wordfree(&wexp); } + wordfree(&wexp); } } @@ -350,10 +366,10 @@ void ical_printr(icalcomponent *comp, int depth) } } -void ical_test(void) +void ical_test(char *path) { /* Load ical */ - FILE *file = fopen("data/all.ics", "r"); + FILE *file = fopen(path, "r"); icalparser *parser = icalparser_new(); icalparser_set_gen_data(parser, file); icalcomponent *comp = icalparser_parse(parser, (void*)fgets);