From ca0d95e26663e05d702c6f3a5627812dbf0c9f90 Mon Sep 17 00:00:00 2001 From: katherine Date: Wed, 8 May 2019 07:06:27 -0700 Subject: initial commit --- src/gen.c | 0 src/gen.h | 0 src/main.c | 16 ++++++++++++++++ src/opt.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/opt.h | 9 +++++++++ src/parse.c | 0 src/parse.h | 0 7 files changed, 87 insertions(+) create mode 100644 src/gen.c create mode 100644 src/gen.h create mode 100644 src/main.c create mode 100644 src/opt.c create mode 100644 src/opt.h create mode 100644 src/parse.c create mode 100644 src/parse.h (limited to 'src') diff --git a/src/gen.c b/src/gen.c new file mode 100644 index 0000000..e69de29 diff --git a/src/gen.h b/src/gen.h new file mode 100644 index 0000000..e69de29 diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..cd5eb3a --- /dev/null +++ b/src/main.c @@ -0,0 +1,16 @@ +#include "opt.h" + +#include + +int main(int argc, char **argv) +{ + opt_parse(argc, argv); + + if (opt_infile_str()) + puts(opt_infile_str()); + + if (opt_outfile_str()) + puts(opt_outfile_str()); + + return 0; +} diff --git a/src/opt.c b/src/opt.c new file mode 100644 index 0000000..f4a1969 --- /dev/null +++ b/src/opt.c @@ -0,0 +1,62 @@ +#include "opt.h" + +#include "../reqs/simple-opt/simple-opt.h" + +#include +#include +#include + +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, 'i', "input", true, + "specify file to read from (default is stdin)", "" }, + { SIMPLE_OPT_STRING, 'o', "output", true, + "specify file to write to (default is stdout)", "" }, + { SIMPLE_OPT_END } +}; + +void opt_parse(int argc, char **argv) +{ + struct simple_opt_result result; + const char version[] = "confconf develop"; + + 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, 70, argv[0], + "[-i input] [-o output]", + "confconf is a config file parser generator for C", + options); + exit(EXIT_SUCCESS); + } + + /* version */ + if (options[1].was_seen) { + puts(version); + exit(EXIT_SUCCESS); + } +} + +const char* opt_infile_str(void) +{ + return (options[2].was_seen + ? options[2].val_string + : NULL); +} + +const char* opt_outfile_str(void) +{ + return (options[3].was_seen + ? options[3].val_string + : NULL); +} diff --git a/src/opt.h b/src/opt.h new file mode 100644 index 0000000..ec328e6 --- /dev/null +++ b/src/opt.h @@ -0,0 +1,9 @@ +#ifndef CONFCONF_OPT_H +#define CONFCONF_OPT_H + +void opt_parse(int argc, char **argv); + +const char* opt_infile_str(void); +const char* opt_outfile_str(void); + +#endif diff --git a/src/parse.c b/src/parse.c new file mode 100644 index 0000000..e69de29 diff --git a/src/parse.h b/src/parse.h new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3