aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
blob: 625e8601b6e94848d81a5a6ae9e4a8d2194626a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "opt.h"

#include "../reqs/simple-xdg-bdirs/simple-xdg-bdirs.h"

int main(int argc, char **argv)
{
	enum every_opt_outputmode omode;
	FILE *calendar;

	char **rdirs, **cur, *s;

	opt_parse(argc, argv);

	omode = opt_outputmode();

	if (opt_calpath() != NULL) {
		s = opt_calpath();

		calendar = fopen(s, "r");
		if (calendar == NULL) {
			printf("err: could not read calendar at `%s`\n", s);
			exit(EXIT_FAILURE);
		}
	} else {
		rdirs = simple_xdg_bdirs_read_dirs(SIMPLE_XDG_BDIRS_CONFIG);

		if (rdirs == NULL) {
			printf(
				"err: no calendar specified, and default was not found or "
				"readable\n"
			);
			exit(EXIT_FAILURE);
		}

		s = simple_xdg_bdirs_fullpath_read("every/calendar", rdirs);

		for (cur = rdirs; *cur != NULL; cur++)
			free(*cur);
		free(rdirs);

		if (s == NULL) {
			printf(
				"err: no calendar specified, and default was not found or "
				"readable\n"
			);
			exit(EXIT_FAILURE);
		}

		calendar = fopen(s, "r");

		free(s);

		if (calendar == NULL) {
			printf(
				"err: no calendar specified, and default was not found or "
				"readable\n"
			);
			exit(EXIT_FAILURE);
		}
	}

	fclose(calendar);
	
	return 0;
}