diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/conf.c | 0 | ||||
-rw-r--r-- | src/conf.h | 4 | ||||
-rw-r--r-- | src/main.c | 65 | ||||
-rw-r--r-- | src/opt.c | 36 | ||||
-rw-r--r-- | src/opt.h | 6 |
5 files changed, 90 insertions, 21 deletions
diff --git a/src/conf.c b/src/conf.c deleted file mode 100644 index e69de29..0000000 --- a/src/conf.c +++ /dev/null diff --git a/src/conf.h b/src/conf.h deleted file mode 100644 index f686a49..0000000 --- a/src/conf.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef EVERY_CONF_H -#define EVERY_CONF_H - -#endif @@ -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; +} @@ -5,11 +5,9 @@ #include <stdlib.h> -#include <unistd.h> - const char *set[] = { - [EVERY_OPT_PRINTMODE_CONSOLE] = "console", - [EVERY_OPT_PRINTMODE_SCRIPT] = "script", + [EVERY_OPT_OUTPUTMODE_CONSOLE] = "console", + [EVERY_OPT_OUTPUTMODE_SCRIPT] = "script", NULL, }; @@ -17,9 +15,9 @@ static struct simple_opt options[] = { { SIMPLE_OPT_FLAG, 'h', "help", false, "print this help message and exit" }, { SIMPLE_OPT_FLAG, 'v', "version", false, - "print the version of confconf in use and exit" }, - { SIMPLE_OPT_STRING, 'c', "config", true, - "path to config file", "<file>" }, + "print the version of every in use and exit" }, + { SIMPLE_OPT_STRING, 'c', "calendar", true, + "path to calendar", "<file>" }, { SIMPLE_OPT_STRING_SET, 'm', "output-mode", true, "output mode (default is console)", "(console|script)", set }, @@ -29,8 +27,6 @@ static struct simple_opt options[] = { void opt_parse(int argc, char **argv) { struct simple_opt_result result; - size_t i; - char c, cend; result = simple_opt_parse(argc, argv, options); @@ -43,8 +39,8 @@ void opt_parse(int argc, char **argv) /* help */ if (options[0].was_seen) { simple_opt_print_usage(stdout, 80, argv[0], - "[-c FILE] [-m OUTPUT_MODE]", - "every is a flexible console-based event calendar", + "[-c CALENDAR_FILE] [-m OUTPUT_MODE]", + "every is a flexible, console-based event calendar", options); exit(EXIT_SUCCESS); } @@ -54,14 +50,26 @@ void opt_parse(int argc, char **argv) puts(VERSION); exit(EXIT_SUCCESS); } + + /* bad calendar path*/ + if (options[2].was_seen && options[2].val.v_string[0] == '\0') { + printf("err: could not read calendar at ``\n"); + exit(EXIT_FAILURE); + } } -const char* opt_confpath_str(void) +char* opt_calpath(void) { - return options[2].val.v_string; + if (options[2].was_seen) + return options[2].val.v_string; + + return NULL; } enum every_opt_outputmode opt_outputmode(void) { - return options[3].val.v_string_set_idx; + if (options[3].was_seen) + return options[3].val.v_string_set_idx; + + return EVERY_OPT_OUTPUTMODE_CONSOLE; } @@ -2,13 +2,13 @@ #define EVERY_OPT_H enum every_opt_outputmode { - EVERY_OPT_PRINTMODE_CONSOLE = 0, - EVERY_OPT_PRINTMODE_SCRIPT = 1, + EVERY_OPT_OUTPUTMODE_CONSOLE = 0, + EVERY_OPT_OUTPUTMODE_SCRIPT = 1, }; void opt_parse(int argc, char **argv); -const char* opt_confpath_str(void); +char* opt_calpath(void); enum every_opt_outputmode opt_outputmode(void); #endif |