aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorkatherine <ageha@airen-no-jikken.icu>2019-12-10 23:29:21 -0700
committerkatherine <ageha@airen-no-jikken.icu>2019-12-10 23:29:21 -0700
commit47b6e46d9bba6835018bdf7432ea742eaca45a03 (patch)
tree45bef2893919900d4987dcc033a67f6f743f4077 /src/main.c
parent8cb7ab5550a528b0fdb75533e6dc0bcbc7a42719 (diff)
downloadevery-47b6e46d9bba6835018bdf7432ea742eaca45a03.tar.gz
implement option parsing and calendar locating
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index e69de29..625e860 100644
--- a/src/main.c
+++ b/src/main.c
@@ -0,0 +1,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;
+}