#include "version.h" #include "opt.h" #include "../reqs/simple-opt/simple-opt.h" #include #include const char *set[] = { [EVERY_OPT_PRINTMODE_CONSOLE] = "console", [EVERY_OPT_PRINTMODE_SCRIPT] = "script", NULL, }; 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", "" }, { SIMPLE_OPT_STRING_SET, 'm', "output-mode", true, "output mode (default is console)", "(console|script)", set }, { SIMPLE_OPT_END } }; 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); /* parse err */ if (result.result_type != SIMPLE_OPT_RESULT_SUCCESS) { simple_opt_print_error(stderr, 80, argv[0], result); exit(EXIT_FAILURE); } /* 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", options); exit(EXIT_SUCCESS); } /* version */ if (options[1].was_seen) { puts(VERSION); exit(EXIT_SUCCESS); } } const char* opt_confpath_str(void) { return options[2].val.v_string; } enum every_opt_outputmode opt_outputmode(void) { return options[3].val.v_string_set_idx; }