diff options
author | katherine <ageha@airen-no-jikken.icu> | 2019-12-10 23:29:21 -0700 |
---|---|---|
committer | katherine <ageha@airen-no-jikken.icu> | 2019-12-10 23:29:21 -0700 |
commit | 47b6e46d9bba6835018bdf7432ea742eaca45a03 (patch) | |
tree | 45bef2893919900d4987dcc033a67f6f743f4077 /src/main.c | |
parent | 8cb7ab5550a528b0fdb75533e6dc0bcbc7a42719 (diff) | |
download | every-47b6e46d9bba6835018bdf7432ea742eaca45a03.tar.gz |
implement option parsing and calendar locating
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 65 |
1 files changed, 65 insertions, 0 deletions
@@ -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; +} |