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/>.
32 char **calendars = NULL;
35 static char *short_options = "hp::d";
37 struct option long_options[] = {
38 {"help", 0, NULL, 'h'},
39 {"print", 2, NULL, 'p'},
40 {"daemon", 0, NULL, 'd'},
44 static void usage(char *name)
47 printf(" %s [OPTION...] [CALENDAR]\n", name);
50 printf(" -h, --help Print usage information\n");
51 printf(" -p, --print=[dw] Show upcomming events\n");
52 printf(" -d, --daemon Run in daemon mode\n");
56 void args_setup(int argc, char **argv)
60 int c = getopt_long(argc, argv,
61 short_options, long_options, NULL);
70 PRINT = match(optarg, NULL) ? 1 :
71 match(optarg, "d") ? 1 :
72 match(optarg, "day") ? 1 :
73 match(optarg, "w") ? 7 :
74 match(optarg, "week") ? 7 : -1;
82 /* Save default calendar */
83 calendars = &argv[optind];
85 /* Validate arguments */
87 error("Unknown print: %s\n", optarg);
89 error("Cannot print and run as daemon");
92 for (int i = 0; calendars[i]; i++)
93 cal_config("ical", calendars[i], "location", calendars[i]);
98 /* Focus the default calendar */
100 event_t *event = EVENTS;
101 date_t start = {SEL.year, SEL.month, SEL.day, 0, 0};
102 while (event && compare(&start, &event->start) > 0)
104 while (event && !match(calendars[0], event->cal->name))
108 while (event && !match(calendars[0], event->cal->name))