2 * Copyright (C) 2016 Andy Spencer <andy753421@gmail.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
33 const char *short_options = "hdw";
35 struct option long_options[] = {
36 {"help", 0, NULL, 'h'},
37 {"day", 2, NULL, 'd'},
38 {"week", 2, NULL, 'w'},
41 static int print_day = 0;
42 static int print_week = 0;
45 static void usage(char *name)
48 printf(" %s [OPTION...] [CALENDAR]\n", name);
51 printf(" -h, --help Print usage information\n");
52 printf(" -d, --day Show today's events\n");
53 printf(" -w, --week Show this week's events\n");
57 void args_setup(int _argc, char **_argv)
68 int c = getopt_long(argc, argv,
69 short_options, long_options, NULL);
87 for (int i = optind; i < argc; i++)
88 cal_config("ical", argv[i], "location", argv[i]);
90 /* Validate arguments */
91 if (print_day && print_week)
92 error("Cannot print both day and week");
97 if (print_day || print_week) {
98 event_t *event = EVENTS;
99 for (int d = 0; d < (print_day ? 1 : 7); d++) {
100 /* Get start and end of the day */
101 date_t start = {SEL.year, SEL.month, SEL.day, 0, 0};
102 date_t end = {SEL.year, SEL.month, SEL.day, 24, 0};
104 add_days(&start.year, &start.month, &start.day, d);
105 add_days(&end.year, &end.month, &end.day, d);
108 /* Print day header */
109 wday_t wday = day_of_week(start.year, start.month, start.day);
110 printf("%s%s, %s %d, %d\n",
113 month_to_string(start.month),
117 /* Skip forward to the day */
118 while (event && compare(&start, &event->start) > 0)
121 /* Print event info */
123 while (event && compare(&end, &event->start) > 0) {
124 printf("%s %02d:%02d",
129 printf(" %s\n", event->name);
131 printf("\n %s\n", event->desc);
136 /* Print no events */
138 printf(" No events\n");