From d244e4e3cb702dcb87f1c3c1232abd2fc936d8ec Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 8 Sep 2024 22:02:02 +0200 Subject: OPTION_WITHARG --- src/util/option.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/util/option.h') diff --git a/src/util/option.h b/src/util/option.h index 780a6e9..a5a698b 100644 --- a/src/util/option.h +++ b/src/util/option.h @@ -7,6 +7,7 @@ enum option_spec_kind { OPTSPECKIND_SETBOOL, OPTSPECKIND_CALL, OPTSPECKIND_CALLP, + OPTSPECKIND_WITHARG, OPTSPECKIND_HELPUSAGE, OPTSPECKIND_VERSION, @@ -25,6 +26,7 @@ struct option_spec { struct { bool *ptr; } setbool; struct { void (*fun)(void); } call; struct { void (*fun)(void*); void *data; } callp; + struct { char **dst; } witharg; struct { const char *usagestr; } helpusage; struct {} version; } spec_sub; @@ -43,6 +45,12 @@ struct option_spec { #define OPTION_CALLP(funptr, dataptr) \ OPTSPECKIND_CALLP, {.callp={.fun=(funptr), .data=(dataptr)}} +// An option with an argument. Takes a char** and stores a newly malloc()ed +// string in that pointer for the given argument. Later occurrences override any +// previous ones, and NULL is written if the option never occurs. +#define OPTION_WITHARG(argptr) \ + OPTSPECKIND_WITHARG, {.witharg={.dst=(argptr)}} + // Takes a printf format string with a single %s, which is substituted (by // printf) for argv[0]. Prints the formatted string and exits with code 0. #define OPTION_HELPUSAGE(usagestring) \ -- cgit v1.2.3-70-g09d2