]> Pileus Git - lackey/blobdiff - cals/ical.c
Improve calendar debugging
[lackey] / cals / ical.c
index 3ee3c68b073352239701dc97354066e0c7e48b9c..8e51a8640802e813eabd6103972dbe9699f58022 100644 (file)
@@ -168,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);
        }
 }