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/>.
31 char **calendars = NULL;
34 static char *short_options = "hp::d";
36 struct option long_options[] = {
37 {"help", 0, NULL, 'h'},
38 {"print", 2, NULL, 'p'},
42 static void usage(char *name)
45 printf(" %s [OPTION...] [CALENDAR]\n", name);
48 printf(" -h, --help Print usage information\n");
49 printf(" -p, --print=[dw] Show upcomming events\n");
53 void args_setup(int argc, char **argv)
57 int c = getopt_long(argc, argv,
58 short_options, long_options, NULL);
67 PRINT = match(optarg, NULL) ? 1 :
68 match(optarg, "d") ? 1 :
69 match(optarg, "day") ? 1 :
70 match(optarg, "w") ? 7 :
71 match(optarg, "week") ? 7 : -1;
76 /* Save default calendar */
77 calendars = &argv[optind];
79 /* Validate arguments */
81 error("Unknown print: %s\n", optarg);
84 for (int i = 0; calendars[i]; i++)
85 cal_config("ical", calendars[i], "location", calendars[i]);
90 /* Focus the default calendar */
92 event_t *event = EVENTS;
93 date_t start = {SEL.year, SEL.month, SEL.day, 0, 0};
94 while (event && compare(&start, &event->start) > 0)
96 while (event && !match(calendars[0], event->cal->name))
100 while (event && !match(calendars[0], event->cal->name))