Mercurial > hg > th-libs
changeset 587:98812eb78d8e
Add new compile-time optional th_optarg struct field o_arg for specifying the option argument description/name. TH_USE_OPT_ARG must be defined at compile time.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 12 Jan 2020 18:03:47 +0200 |
parents | 446203207cba |
children | ef71ef9b5862 |
files | Makefile.gen tests.c th_args.c th_args.h |
diffstat | 4 files changed, 12 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile.gen Sun Jan 12 18:01:47 2020 +0200 +++ b/Makefile.gen Sun Jan 12 18:03:47 2020 +0200 @@ -4,6 +4,7 @@ CFLAGS += -O2 CFLAGS += -DTH_USE_INTERNAL_SPRINTF=1 CFLAGS += -DTH_PRINTF_DEBUG=1 +CFLAGS += -DTH_USE_OPT_ARG=1 THLIBS = ./
--- a/tests.c Sun Jan 12 18:01:47 2020 +0200 +++ b/tests.c Sun Jan 12 18:03:47 2020 +0200 @@ -52,10 +52,10 @@ // Define option arguments static const th_optarg arg_opts[] = { - { 0, '?', "help", "Show this help", OPT_NONE }, - { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, - { 2, 's', "sets", "Perform test sets -s <set>[,<set2>..]", OPT_ARGREQ }, - { 3, 't', "tests", "Perform only tests (see below)", OPT_ARGREQ }, + { 0, '?', "help" , NULL, "Show this help", OPT_NONE }, + { 1, 'v', "verbose" , NULL, "Be more verbose", OPT_NONE }, + { 2, 's', "sets" , "<sets>", "Perform test sets -s <set>[,<set2>..]", OPT_ARGREQ }, + { 3, 't', "tests" , "<tests>", "Perform only tests (see below)", OPT_ARGREQ }, }; static const int arg_nopts = sizeof(arg_opts) / sizeof(arg_opts[0]);
--- a/th_args.c Sun Jan 12 18:01:47 2020 +0200 +++ b/th_args.c Sun Jan 12 18:03:47 2020 +0200 @@ -247,8 +247,12 @@ static inline const char *th_args_get_optarg(const th_optarg *opt) { +#ifdef TH_USE_OPT_ARG + return opt->o_arg != NULL ? opt->o_arg : "ARG"; +#else (void) opt; return "ARG"; +#endif }
--- a/th_args.h Sun Jan 12 18:01:47 2020 +0200 +++ b/th_args.h Sun Jan 12 18:03:47 2020 +0200 @@ -38,6 +38,9 @@ int id; ///< Option ID (should be unique for each option) char o_short; ///< Short option name (one character, can be 0 for none) char *o_long; ///< Long option name (can be NULL for none) +#ifdef TH_USE_OPT_ARG + char *o_arg; ///< Option argument name (can be NULL for none/default) +#endif char *desc; ///< Option description int flags; ///< Flags (see OPT_*) } th_optarg;