]> Pileus Git - lackey/commitdiff
Improve calendar debugging
authorAndy Spencer <andy753421@gmail.com>
Tue, 22 Nov 2016 06:55:14 +0000 (06:55 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 28 Nov 2016 09:41:14 +0000 (09:41 +0000)
cals/ical.c
config.mk.example
src/cal.c
src/conf.c
src/util.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);
        }
 }
 
index 72d298a0d1a30f3c6d62c146ddc1a15875651dcc..79b317e1a00ae369f0ec1363eb83a5689665039f 100644 (file)
@@ -1,5 +1,5 @@
 PREFIX  ?= /usr
-CFLAGS  ?= -g -Wall -Werror --std=c99 -DDEBUG_CALS
+CFLAGS  ?= -g -Wall -Werror --std=c99 -DCAL_DEBUG
 
 default: all run-lackey
 #default: all run-test
index a05dd1feefe0d69868a934a51ab30538868f09ab..afc18f01670f5abd6a5203287e64190811d7fa6b 100644 (file)
--- a/src/cal.c
+++ b/src/cal.c
@@ -114,7 +114,7 @@ void cal_init(void)
        cal_load(SEL.year, SEL.month, SEL.day, 1);
 
        /* Debug */
-#ifdef DEBUG_CALS
+#ifdef CAL_DEBUG
        for (event_t *e = EVENTS; e; e = e->next)
                debug("event: %04d-%02d-%02d %02d:%02d: %s - %s",
                                e->start.year, e->start.month, e->start.day,
@@ -174,7 +174,7 @@ void cal_load(year_t year, month_t month, day_t day, int days)
                 ical_todos(start, end));
 
        /* Verify events and todos*/
-#ifdef DEBUG_CALS
+#ifdef CAL_ERROR
        for (event_t *cur = EVENTS; cur; cur = cur->next) {
                if (!cur->cal)
                        error("Missing cal in event '%s'", cur->name);
index 740932afcfb5f6a85ed8082602998f98f36498c0..e379cbf4f598bab3cafefacf93ede4499ae8068d 100644 (file)
@@ -271,7 +271,7 @@ static void conf_load(const char *path, parser_t parser)
                }
 
                /* debug printout */
-               printf("parse: %s.%s.%s = '%s'\n", group, name, line->key, line->value);
+               debug("parse: %s.%s.%s = '%s'", group, name, line->key, line->value);
 
                /* save line formatting for the next write */
                if (prev == NULL)
index 0d64fc4b2bb70598a4ccb26bb275a64f49d6385d..37b004d94896899b95312fdc3abc387fe5d725b6 100644 (file)
@@ -45,6 +45,7 @@ static void message(FILE *output_fd, const char *prefix, const char *fmt, va_lis
                fprintf(output_fd, "%s: ", prefix);
                vfprintf(output_fd, fmt, tmp);
                fprintf(output_fd, "\n");
+               fflush(output_fd);
        }
 
        /* Log to debug file */
@@ -53,6 +54,7 @@ static void message(FILE *output_fd, const char *prefix, const char *fmt, va_lis
                fprintf(debug_fd, "%s: ", prefix);
                vfprintf(debug_fd, fmt, tmp);
                fprintf(debug_fd, "\n");
+               fflush(debug_fd);
        }
 
        /* Log to status bar */