From ee74335c8440803006aeca6b1a427c0cf28b4a98 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Thu, 9 May 2024 03:22:37 +0200 Subject: Rename optparse.h to cli.h --- include/cli.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ include/optparse.h | 46 ---------------------------------------------- 2 files changed, 45 insertions(+), 46 deletions(-) create mode 100644 include/cli.h delete mode 100644 include/optparse.h (limited to 'include') diff --git a/include/cli.h b/include/cli.h new file mode 100644 index 0000000..7b5b611 --- /dev/null +++ b/include/cli.h @@ -0,0 +1,45 @@ +#ifndef MLIB_CLI_H +#define MLIB_CLI_H + +#include + +#include "_attrs.h" +#include "_rune.h" +#include "_u8view.h" + +struct optparser { + bool _b; + int _subopt; + char **_argv; + + int optind; + char errmsg[128]; + struct u8view optarg; +}; + +enum cliarg { + CLI_NONE, + CLI_OPT, + CLI_REQ, +}; + +struct cli_option { + rune shortopt; + struct u8view longopt; + enum cliarg argtype; +}; + +[[nodiscard]] rune optparse(struct optparser *, const struct cli_option *, + size_t); + +[[_mlib_inline]] +static inline struct optparser +mkoptparser(char **argv) +{ + return (struct optparser){ + ._argv = argv, + .optind = argv[0] != nullptr, + }; +} + +#endif /* !MLIB_CLI_H */ diff --git a/include/optparse.h b/include/optparse.h deleted file mode 100644 index 7e2c315..0000000 --- a/include/optparse.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef MLIB_OPTPARSE_H -#define MLIB_OPTPARSE_H - -#include - -#include "_attrs.h" -#include "_charN_t.h" -#include "_rune.h" -#include "_u8view.h" - -struct optparse { - bool _b; - int _subopt; - char **_argv; - - int optind; - char errmsg[128]; - struct u8view optarg; -}; - -enum op_argkind { - OPT_NONE, - OPT_OPT, - OPT_REQ, -}; - -struct op_option { - rune shortopt; - struct u8view longopt; - enum op_argkind argtype; -}; - -[[nodiscard]] rune optparse(struct optparse *, const struct op_option *, - size_t); - -[[_mlib_inline]] -static inline struct optparse -mkoptparser(char **argv) -{ - return (struct optparse){ - ._argv = argv, - .optind = argv[0] != nullptr, - }; -} - -#endif /* !MLIB_OPTPARSE_H */ -- cgit v1.2.3