- commit
- 283a3b217e7971b19e51f164f22473c64128aa19
- parent
- 3554fa955345c9c200a308bd7932322be657d92f
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2019-01-12 10:01
c: add -B arg
Diffstat
| M | calendar.c | 14 | +++++++++----- |
1 files changed, 9 insertions, 5 deletions
diff --git a/calendar.c b/calendar.c
@@ -369,22 +369,26 @@ void print_matches(struct tm date, struct line *first) {
369 369 void help() {
370 370 printf(
371 371 "BSD calendar reimplementation\n"
372 -1 "usage: calendar [-h] [-A DAYS_AFTER]\n"
-1 372 "usage: calendar [-h] [-B DAYS_BEFORE] [-A DAYS_AFTER]\n"
373 373 );
374 374 }
375 375
376 376 #ifndef test
377 377 int main(int argc, char *argv[]) {
378 -1 int days = 3;
-1 378 int days_before = 0;
-1 379 int days_after = 3;
379 380
380 381 int c;
381 -1 while ((c = getopt(argc, argv, "hA:")) != -1) {
-1 382 while ((c = getopt(argc, argv, "hB:A:")) != -1) {
382 383 switch (c) {
383 384 case 'h':
384 385 help();
385 386 return 0;
-1 387 case 'B':
-1 388 days_before = atoi(optarg);
-1 389 break;
386 390 case 'A':
387 -1 days = 1 + atoi(optarg);
-1 391 days_after = 1 + atoi(optarg);
388 392 break;
389 393 case '?':
390 394 exit(EXIT_FAILURE);
@@ -396,7 +400,7 @@ int main(int argc, char *argv[]) {
396 400 struct tm *TODAY = today();
397 401
398 402 struct tm day;
399 -1 for (int i = 0; i < days; i++) {
-1 403 for (int i = -days_before; i < days_after; i++) {
400 404 day = add_days(*TODAY, i);
401 405 print_matches(day, first);
402 406 }