# HG changeset patch # User Matti Hamalainen # Date 1578845027 -7200 # Node ID 98812eb78d8ed66f8a10db04c20bb3378fff60d4 # Parent 446203207cba809fccf851a3b56a7b04e0dc92dd 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. diff -r 446203207cba -r 98812eb78d8e Makefile.gen --- 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 = ./ diff -r 446203207cba -r 98812eb78d8e tests.c --- 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 [,..]", 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" , "", "Perform test sets -s [,..]", OPT_ARGREQ }, + { 3, 't', "tests" , "", "Perform only tests (see below)", OPT_ARGREQ }, }; static const int arg_nopts = sizeof(arg_opts) / sizeof(arg_opts[0]); diff -r 446203207cba -r 98812eb78d8e th_args.c --- 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 } diff -r 446203207cba -r 98812eb78d8e th_args.h --- 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;