From f45d7e37ac9dd4e70a89671edf862a868f8ab343 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Tue, 22 Nov 2016 06:55:14 +0000 Subject: [PATCH 1/1] Improve calendar debugging --- cals/ical.c | 26 +++++++++++++++----------- config.mk.example | 2 +- src/cal.c | 4 ++-- src/conf.c | 2 +- src/util.c | 2 ++ 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/cals/ical.c b/cals/ical.c index 3ee3c68..8e51a86 100644 --- a/cals/ical.c +++ b/cals/ical.c @@ -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); } } diff --git a/config.mk.example b/config.mk.example index 72d298a..79b317e 100644 --- a/config.mk.example +++ b/config.mk.example @@ -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 diff --git a/src/cal.c b/src/cal.c index a05dd1f..afc18f0 100644 --- 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); diff --git a/src/conf.c b/src/conf.c index 740932a..e379cbf 100644 --- a/src/conf.c +++ b/src/conf.c @@ -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) diff --git a/src/util.c b/src/util.c index 0d64fc4..37b004d 100644 --- a/src/util.c +++ b/src/util.c @@ -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 */ -- 2.43.2