aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorkatherine <ageha@airen-no-jikken.icu>2019-12-10 22:40:03 -0700
committerkatherine <ageha@airen-no-jikken.icu>2019-12-10 22:40:03 -0700
commit8cb7ab5550a528b0fdb75533e6dc0bcbc7a42719 (patch)
treeeb02f66c14a5bf3542b2abaacc87cf2144bb032a /src
downloadevery-8cb7ab5550a528b0fdb75533e6dc0bcbc7a42719.tar.gz
initial commit
Diffstat (limited to 'src')
-rw-r--r--src/calendar.c0
-rw-r--r--src/calendar.h4
-rw-r--r--src/conf.c0
-rw-r--r--src/conf.h4
-rw-r--r--src/main.c0
-rw-r--r--src/opt.c67
-rw-r--r--src/opt.h14
7 files changed, 89 insertions, 0 deletions
diff --git a/src/calendar.c b/src/calendar.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/calendar.c
diff --git a/src/calendar.h b/src/calendar.h
new file mode 100644
index 0000000..ebfe64a
--- /dev/null
+++ b/src/calendar.h
@@ -0,0 +1,4 @@
+#ifndef EVERY_CALENDAR_H
+#define EVERY_CALENDAR_H
+
+#endif
diff --git a/src/conf.c b/src/conf.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/conf.c
diff --git a/src/conf.h b/src/conf.h
new file mode 100644
index 0000000..f686a49
--- /dev/null
+++ b/src/conf.h
@@ -0,0 +1,4 @@
+#ifndef EVERY_CONF_H
+#define EVERY_CONF_H
+
+#endif
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/main.c
diff --git a/src/opt.c b/src/opt.c
new file mode 100644
index 0000000..579743d
--- /dev/null
+++ b/src/opt.c
@@ -0,0 +1,67 @@
+#include "version.h"
+#include "opt.h"
+
+#include "../reqs/simple-opt/simple-opt.h"
+
+#include <stdlib.h>
+
+#include <unistd.h>
+
+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", "<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;
+}
diff --git a/src/opt.h b/src/opt.h
new file mode 100644
index 0000000..10bc4c9
--- /dev/null
+++ b/src/opt.h
@@ -0,0 +1,14 @@
+#ifndef EVERY_OPT_H
+#define EVERY_OPT_H
+
+enum every_opt_outputmode {
+ EVERY_OPT_PRINTMODE_CONSOLE = 0,
+ EVERY_OPT_PRINTMODE_SCRIPT = 1,
+};
+
+void opt_parse(int argc, char **argv);
+
+const char* opt_confpath_str(void);
+enum every_opt_outputmode opt_outputmode(void);
+
+#endif