aboutsummaryrefslogtreecommitdiff
path: root/src/args.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/args.c')
-rw-r--r--src/args.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/args.c b/src/args.c
new file mode 100644
index 0000000..fb73e6c
--- /dev/null
+++ b/src/args.c
@@ -0,0 +1,89 @@
+#include "args.h"
+#include <string.h>
+#include <stdlib.h>
+#include "pattern/next.h"
+#include "io/text.h"
+#include "io/svg.h"
+
+/*
+ * Options start.
+ */
+
+#define OPTIONS \
+ { \
+ {"w", "wait", false, wait}, \
+ {"n", "num", true, num}, \
+ {"p", "print", true, print}, \
+ {"os", "outputs", true, outputs}, \
+ {"fn", "from-num", true, fn}, \
+ {"tn", "to-num", true, tn}, \
+ }
+
+void wait(void *args, const char *str)
+{
+ ((struct args *)args)->wait = true;
+}
+
+void num(void *args, const char *str)
+{
+ ((struct args *)args)->gen_count = atoi(str);
+}
+
+void fn(void *args, const char *str)
+{
+ ((struct args *)args)->from_count = atoi(str);
+}
+
+void tn(void *args, const char *str)
+{
+ ((struct args *)args)->to_count = atoi(str);
+}
+
+void print(void *args, const char *str)
+{
+ ((struct args *)args)->print = str[0] == 's' ? print_pattern_svg : print_pattern_text;
+}
+
+void outputs(void *args, const char *str)
+{
+ struct args *args_ = (struct args *)args;
+ args_->standard_output = false;
+ args_->single_output = false;
+ strcpy(args_->output, str);
+}
+
+/*
+ * Options end.
+ */
+
+void load_defaults(struct args *args)
+{
+ // Pattern
+ args->pattern.length = 0;
+ args->pattern.type = gen_pattern_type(3, 4, -1);
+ // Params
+ args->params.aggregated = false;
+ args->params.count = 0;
+ args->params.print_author = true;
+ args->params.print_code = true;
+ args->params.print_count = true;
+ // Egyéb
+ args->gen_count = -1;
+ args->from_count = -1;
+ args->to_count = -1;
+ args->gen = next_point;
+ args->print = print_pattern_text;
+ args->single_output = true;
+ args->standard_output = true;
+ args->wait = false;
+}
+
+enum alr load_args(int argc, char **argv, struct args *args)
+{
+ // Init
+ load_defaults(args);
+ struct option options[] = OPTIONS;
+ int opt_length = sizeof(options) / sizeof(struct option);
+ // Process
+ return process_args(argc, argv, options, opt_length, args);
+} \ No newline at end of file