fix bad error enum type - ics2txt - convert icalendar .ics file to plain text HTML git clone git://bitreich.org/ics2txt git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/ics2txt DIR Log DIR Files DIR Refs DIR Tags DIR README --- DIR commit 5364436bda9ac04c42dbd6eeaab75914128046b6 DIR parent 7a6ceff37018ad2f867397aee9f3b3289f16427f HTML Author: Josuah Demangeon <me@josuah.net> Date: Sun, 28 Jun 2020 21:01:03 +0200 fix bad error enum type Diffstat: M src/ical.c | 24 ++++++++++++++++-------- M src/ical.h | 3 +++ 2 files changed, 19 insertions(+), 8 deletions(-) --- DIR diff --git a/src/ical.c b/src/ical.c @@ -18,18 +18,20 @@ ical_getline(char **line, char **ln, size_t *sz, FILE *fp) void *v; if ((v = realloc(*line, 1)) == NULL) - return -1; + return -ICAL_ERR_SYSTEM; *line = v; (*line)[0] = '\0'; - do { + do { top: if (getline(ln, sz, fp) <= 0) - return ferror(fp) ? -1 : 0; + return ferror(fp) ? -ICAL_ERR_SYSTEM : 0; strchomp(*ln); + if (**ln == '\0') + goto top; if (strappend(line, *ln) < 0) - return -1; + return -ICAL_ERR_SYSTEM; if ((c = fgetc(fp)) == EOF) - return ferror(fp) ? -1 : 1; + return ferror(fp) ? -ICAL_ERR_SYSTEM : 1; } while (c == ' '); ungetc(c, fp); @@ -51,6 +53,12 @@ ical_strerror(int i) return "END: does not match its corresponding BEGIN:"; case ICAL_ERR_MISSING_BEGIN: return "unexpected content line before any BEGIN:"; + case ICAL_ERR_MISSING_COLUMN: + return "missing ':' character from line"; + case ICAL_ERR_MISSING_SEMICOLUMN: + return "missing ';' character before ':'"; + case ICAL_ERR_MISSING_EQUAL: + return "missing '=' character in parameter before ':'"; case ICAL_ERR_MIN_NESTED: return "too many END: for the number of BEGIN:"; case ICAL_ERR_MAX_NESTED: @@ -92,7 +100,7 @@ ical_parse_value(struct ical_value *value) value->name = value->buf; if ((column = strchr(value->buf, ':')) == NULL) - return -1; + return -ICAL_ERR_MISSING_COLUMN; *column = '\0'; value->value = column + 1; @@ -100,10 +108,10 @@ ical_parse_value(struct ical_value *value) *cp++ = '\0'; while ((param = strsep(&cp, ";")) != NULL) { if ((equal = strchr(param, '=')) == NULL) - return -1; + return -ICAL_ERR_MISSING_EQUAL; *equal = '\0'; if (map_set(&value->param, param, equal + 1) < 0) - return -1; + return -ICAL_ERR_SYSTEM; } assert(errno == e); DIR diff --git a/src/ical.h b/src/ical.h @@ -13,6 +13,9 @@ enum ical_err { ICAL_ERR_SYSTEM, ICAL_ERR_END_MISMATCH, ICAL_ERR_MISSING_BEGIN, + ICAL_ERR_MISSING_COLUMN, + ICAL_ERR_MISSING_SEMICOLUMN, + ICAL_ERR_MISSING_EQUAL, ICAL_ERR_MIN_NESTED, ICAL_ERR_MAX_NESTED,