From c5cd2b2443dc48aaeb61feac4a96071c7bc9790e Mon Sep 17 00:00:00 2001 From: Sopár Adrián Date: Tue, 5 Jul 2022 23:02:16 +0200 Subject: Init commit. --- src/args.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/args.c (limited to 'src/args.c') 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 +#include +#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 -- cgit v1.2.3