calendar

BSD calendar reimplementation
git clone https://git.ce9e.org/calendar.git

commit
a6bd4a41e08983d7d67ace82935f726ec86516ec
parent
4925931536733fe1bb17b87617bc2319845f6b05
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2019-04-21 10:01
catch more invalid dates

Diffstat

M calendar.c 20 ++++++++++++++++----

1 files changed, 16 insertions, 4 deletions


diff --git a/calendar.c b/calendar.c

@@ -198,6 +198,11 @@ bool is_match(struct tpl tpl, struct tm date) {
  198   198 	return true;
  199   199 }
  200   200 
   -1   201 void invalid_date(char *s) {
   -1   202 	fprintf(stderr, "Error: Invalid date template: %s\n", s);
   -1   203 	exit(1);
   -1   204 }
   -1   205 
  201   206 struct tpl parse_date(char *s) {
  202   207 	struct tm *TODAY = today();
  203   208 	struct tpl tpl = mktpl();
@@ -205,10 +210,18 @@ struct tpl parse_date(char *s) {
  205   210 	int n = 0;
  206   211 	if (strchr(s, '+')) {
  207   212 		strtok(s, "+");
  208    -1 		n = atoi(strtok(NULL, ""));
   -1   213 		char *s_n = strtok(NULL, "");
   -1   214 		if (s_n == NULL) {
   -1   215 			invalid_date(s);
   -1   216 		}
   -1   217 		n = atoi(s_n);
  209   218 	} else if (strchr(s, '-')) {
  210   219 		strtok(s, "-");
  211    -1 		n = -atoi(strtok(NULL, ""));
   -1   220 		char *s_n = strtok(NULL, "");
   -1   221 		if (s_n == NULL) {
   -1   222 			invalid_date(s);
   -1   223 		}
   -1   224 		n = -atoi(s_n);
  212   225 	}
  213   226 
  214   227 	/* easter */
@@ -274,8 +287,7 @@ struct tpl parse_date(char *s) {
  274   287 		return tpl;
  275   288 	}
  276   289 
  277    -1 	fprintf(stderr, "Error: Invalid date template: %s\n", s);
  278    -1 	exit(1);
   -1   290 	invalid_date(s);
  279   291 }
  280   292 
  281   293 struct line *parse_line(char *s_line) {