From dbfd41e2df44113d1d2d07fb751db11b443f186b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 27 Oct 2014 18:08:46 +0100 Subject: calendarspec: parse 'quarterly' and 'semi-annually' as shortcuts --- src/shared/calendarspec.c | 59 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 3 deletions(-) (limited to 'src/shared') diff --git a/src/shared/calendarspec.c b/src/shared/calendarspec.c index da920b6dd9..7efcf7b371 100644 --- a/src/shared/calendarspec.c +++ b/src/shared/calendarspec.c @@ -474,7 +474,7 @@ static int const_chain(int value, CalendarComponent **c) { cc->value = value; cc->repeat = 0; - cc->next = NULL; + cc->next = *c; *c = cc; @@ -693,8 +693,10 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) { if (r < 0) goto fail; - } else if (strcaseeq(p, "annually") || strcaseeq(p, "yearly") - || strcaseeq(p, "anually") /* backwards compatibility */ ) { + } else if (strcaseeq(p, "annually") || + strcaseeq(p, "yearly") || + strcaseeq(p, "anually") /* backwards compatibility */ ) { + r = const_chain(1, &c->month); if (r < 0) goto fail; @@ -725,6 +727,57 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) { if (r < 0) goto fail; + } else if (strcaseeq(p, "quarterly")) { + + r = const_chain(1, &c->month); + if (r < 0) + goto fail; + r = const_chain(4, &c->month); + if (r < 0) + goto fail; + r = const_chain(7, &c->month); + if (r < 0) + goto fail; + r = const_chain(10, &c->month); + if (r < 0) + goto fail; + r = const_chain(1, &c->day); + if (r < 0) + goto fail; + r = const_chain(0, &c->hour); + if (r < 0) + goto fail; + r = const_chain(0, &c->minute); + if (r < 0) + goto fail; + r = const_chain(0, &c->second); + if (r < 0) + goto fail; + + } else if (strcaseeq(p, "biannually") || + strcaseeq(p, "bi-annually") || + strcaseeq(p, "semiannually") || + strcaseeq(p, "semi-annually")) { + + r = const_chain(1, &c->month); + if (r < 0) + goto fail; + r = const_chain(7, &c->month); + if (r < 0) + goto fail; + r = const_chain(1, &c->day); + if (r < 0) + goto fail; + r = const_chain(0, &c->hour); + if (r < 0) + goto fail; + r = const_chain(0, &c->minute); + if (r < 0) + goto fail; + r = const_chain(0, &c->second); + if (r < 0) + goto fail; + } else { r = parse_weekdays(&p, c); if (r < 0) -- cgit v1.2.3-54-g00ecf