aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c26
1 files changed, 19 insertions, 7 deletions
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 <stdbool.h>
#include <unistd.h>
@@ -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;
}