X-Git-Url: http://pileus.org/git/?p=lackey;a=blobdiff_plain;f=src%2Fprint.c;fp=src%2Fprint.c;h=9daf92dcea2499cba2e9670ef7bc8c870206113c;hp=0000000000000000000000000000000000000000;hb=7edd7d3a9f0bdaaa8df9f68a73f7c84e2b514ce6;hpb=9a9c6808d386091c75bbc00b764d308034ac1c0f diff --git a/src/print.c b/src/print.c new file mode 100644 index 0000000..9daf92d --- /dev/null +++ b/src/print.c @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2017 Andy Spencer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "args.h" +#include "date.h" +#include "cal.h" +#include "print.h" + +/* Initialize */ +void print_init(void) +{ +} + +void print_main(void) +{ + event_t *event = EVENTS; + for (int d = 0; d < PRINT; d++) { + /* Get start and end of the day */ + date_t start = {SEL.year, SEL.month, SEL.day, 0, 0}; + date_t end = {SEL.year, SEL.month, SEL.day, 24, 0}; + + add_days(&start.year, &start.month, &start.day, d); + add_days(&end.year, &end.month, &end.day, d); + + /* Print day header */ + wday_t wday = day_of_week(start.year, start.month, start.day); + if (d > 0) + printf("\n"); + printf("%s, %s %d, %d\n", + day_to_string(wday), + month_to_string(start.month), + start.day+1, + start.year); + + /* Skip forward to the day */ + while (event && compare(&start, &event->start) > 0) + event = event->next; + + /* Print event info */ + int printed = 0; + while (event && compare(&end, &event->start) > 0) { + if (printed > 0) + printf("\n"); + printf("* %02d:%02d - %02d:%02d", + event->start.hour, event->start.min, + event->end.hour, event->end.min); + if (!event->name) + printf("\n"); + if (event->name) + printf(" %s\n", event->name); + if (event->loc) + printf(" Location: %s\n", event->loc); + if (event->desc) + printf(" Description: %s\n", event->desc); + printed++; + event = event->next; + } + + /* Print no events */ + if (!printed) + printf(" No events\n"); + } +} + +void print_exit(void) +{ +}