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 <lfleischer@calcurse.org>
This commit is contained in:
Lars Henriksen
2019-12-08 09:16:24 +01:00
committed by Lukas Fleischer
parent ce81c0fa63
commit bf3dba2ae2
5 changed files with 54 additions and 53 deletions

View File

@@ -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. */