From ff7f9ceb2522157b65a05d3087612abe9b266a33 Mon Sep 17 00:00:00 2001 From: katherine Date: Fri, 20 Dec 2019 12:12:01 -0700 Subject: add comments and make default cal 'every/cal.every' --- src/calendar.c | 32 +++++++++++++++++++++++++++----- src/main.c | 2 +- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/calendar.c b/src/calendar.c index 06d80d7..4eabc12 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -60,10 +60,9 @@ static void sub_set_pos(struct state_s *s, struct pos_s p) s->last_col = p.col; } -static bool sub_eat_spaces(struct state_s *s) +static void sub_eat_spaces(struct state_s *s) { int c; - bool seen = false; while (true) { c = getc(s->f); @@ -81,10 +80,22 @@ static bool sub_eat_spaces(struct state_s *s) s->col++; - seen = true; } +} + +static void sub_eat_comment(struct state_s *s) +{ + int c; - return seen; + while (true) { + c = getc(s->f); + + if (c == '\n' || c == EOF) + break; + } + + s->col = 1; + s->line++; } static struct entry_interval_s sub_get_interval(struct state_s *s) @@ -224,6 +235,7 @@ static time_t sub_get_date(struct state_s *s) .tm_mday = 1, .tm_isdst = -1, }; + bool seen = false; sub_set_pos(s, sub_get_pos(s)); @@ -258,11 +270,16 @@ static time_t sub_get_date(struct state_s *s) /* no int found */ if (r == 0) { - ERRP("expected date"); + if (seen) + ERRP("invalid date"); + else + ERRP("expected date"); s->err_flag = true; return rt; } + seen = true; + /* range err interval */ if (l < 0) { ERRP("invalid date"); @@ -828,6 +845,11 @@ struct calendar_s calendar_parse(FILE *f) if (c == EOF) break; + if (c == '#') { + sub_eat_comment(&s); + continue; + } + if (c == '.') { s.col++; cmd = sub_get_cmd(&s); diff --git a/src/main.c b/src/main.c index 27c5349..2d6c7c8 100644 --- a/src/main.c +++ b/src/main.c @@ -38,7 +38,7 @@ int main(int argc, char **argv) if (rdirs == NULL) ERR("no calendar specified, and default was not found or readable"); - calpath = simple_xdg_bdirs_fullpath_read("every/calendar", rdirs); + calpath = simple_xdg_bdirs_fullpath_read("every/cal.every", rdirs); for (cur = rdirs; *cur != NULL; cur++) free(*cur); -- cgit v1.2.3