From 31632d4edbd903826cbf8f6bb93969f0d1a983fb Mon Sep 17 00:00:00 2001 From: katherine Date: Wed, 18 Dec 2019 21:54:46 -0700 Subject: implement calendar parsing --- src/main.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 86def80..5c01fe0 100644 --- a/src/main.c +++ b/src/main.c @@ -3,6 +3,8 @@ #include "../reqs/simple-xdg-bdirs/simple-xdg-bdirs.h" +#include "calendar.h" + #include #include @@ -14,7 +16,8 @@ int main(int argc, char **argv) enum opt_command_e cmd; char *calpath; - FILE *cal; + FILE *calf; + struct calendar_s cal; char *ed; pid_t pid; @@ -43,9 +46,12 @@ int main(int argc, char **argv) if (calpath == NULL) ERR("no calendar specified, and default was not found or readable"); + + calpath_alloced = true; } /* edit command */ + if (cmd == OPT_COMMAND_EDIT) { ed = opt_editor(); @@ -86,10 +92,11 @@ int main(int argc, char **argv) exit(EXIT_SUCCESS); } - /* output commands */ - cal = fopen(calpath, "r"); - if (cal == NULL) { - fprintf(stderr, "err: could not read calendar at `%s`\n", calpath); + /* parse calendar */ + + calf = fopen(calpath, "r"); + if (calf == NULL) { + ERRM("could not read calendar at `%s`\n", calpath); if (calpath_alloced) free(calpath); @@ -100,9 +107,14 @@ int main(int argc, char **argv) if (calpath_alloced) free(calpath); - if (cmd == OPT_COMMAND_CONSOLE) + cal = calendar_parse(calf); - fclose(cal); + fclose(calf); + + if (cal.err_flag) + exit(EXIT_FAILURE); + + /* output commands */ return 0; } -- cgit v1.2.3