aboutsummaryrefslogtreecommitdiffstats
path: root/src/opt.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/opt.c
parent8cb7ab5550a528b0fdb75533e6dc0bcbc7a42719 (diff)
downloadevery-47b6e46d9bba6835018bdf7432ea742eaca45a03.tar.gz
implement option parsing and calendar locating
Diffstat (limited to 'src/opt.c')
-rw-r--r--src/opt.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/opt.c b/src/opt.c
index 579743d..eb796e7 100644
--- a/src/opt.c
+++ b/src/opt.c
@@ -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;
}