From bf3dba2ae2b3c1f0e06191b6878dc7f22570f8f6 Mon Sep 17 00:00:00 2001 From: Lars Henriksen Date: Sun, 8 Dec 2019 09:16:24 +0100 Subject: Improve data load error reporting The last part of loading appointments and events is performed by four "scan" functions called from io_load_app(). Failure in this part of data load does not use io_load_error(). The four "scan" functions are changed to return an error message on failure and NULL otherwise (the previous return value was not used). Signed-off-by: Lukas Fleischer --- src/event.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/event.c') diff --git a/src/event.c b/src/event.c index 375dd66..e0da4c1 100644 --- a/src/event.c +++ b/src/event.c @@ -149,7 +149,7 @@ void event_write(struct event *o, FILE * f) } /* Load the events from file */ -struct event *event_scan(FILE * f, struct tm start, int id, char *note, +char *event_scan(FILE * f, struct tm start, int id, char *note, struct item_filter *filter) { char buf[BUFSIZ], *nl; @@ -157,13 +157,13 @@ struct event *event_scan(FILE * f, struct tm start, int id, char *note, struct event *ev = NULL; int cond; - EXIT_IF(!check_date(start.tm_year, start.tm_mon, start.tm_mday) || - !check_time(start.tm_hour, start.tm_min), - _("date error in event")); + if (!check_date(start.tm_year, start.tm_mon, start.tm_mday) || + !check_time(start.tm_hour, start.tm_min)) + return _("illegal date in event"); /* Read the event description */ if (!fgets(buf, sizeof buf, f)) - return NULL; + return _("error in appointment description"); nl = strchr(buf, '\n'); if (nl) { @@ -177,8 +177,9 @@ struct event *event_scan(FILE * f, struct tm start, int id, char *note, start.tm_mon--; tstart = mktime(&start); - EXIT_IF(tstart == -1, _("date error in the event\n")); - tend = tstart + DAYINSEC - 1; + if (tstart == -1) + return _("date error in event\n"); + tend = ENDOFDAY(tstart); /* Filter item. */ if (filter) { @@ -205,8 +206,7 @@ struct event *event_scan(FILE * f, struct tm start, int id, char *note, } if (!ev) ev = event_new(buf, note, tstart, id); - - return ev; + return NULL; } /* Delete an event from the list. */ -- cgit v1.2.3-54-g00ecf