From c90479c7f58ba7ad6e16880dadb4036d55b30d00 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Wed, 18 Mar 2020 21:00:06 +0000 Subject: [PATCH] winpr/utils: allow COMMAND_LINE_VALUE_{OPTIONAL,BOOL} to coexist. Now you can give an option the combination of flags COMMAND_LINE_VALUE_OPTIONAL and COMMAND_LINE_VALUE_BOOL. If you do, then all three of the syntaxes +foo, -foo and /foo:value are allowed at once, and the receiving code can tell the difference because the Value field is set to BoolValueTrue, BoolValueFalse or a valid char pointer. --- client/X11/generate_argument_docbook.c | 3 ++- winpr/libwinpr/utils/cmdline.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/client/X11/generate_argument_docbook.c b/client/X11/generate_argument_docbook.c index 78de2f9be..4fd07b85a 100644 --- a/client/X11/generate_argument_docbook.c +++ b/client/X11/generate_argument_docbook.c @@ -244,7 +244,8 @@ int main(int argc, char* argv[]) if (text) fprintf(fp, "%s", text); - if (arg->Flags == COMMAND_LINE_VALUE_BOOL) + if (arg->Flags & COMMAND_LINE_VALUE_BOOL && + (!arg->Default || arg->Default == BoolValueTrue)) fprintf(fp, " (default:%s)", arg->Default ? "on" : "off"); else if (arg->Default) { diff --git a/winpr/libwinpr/utils/cmdline.c b/winpr/libwinpr/utils/cmdline.c index 548d5074f..8b9744db0 100644 --- a/winpr/libwinpr/utils/cmdline.c +++ b/winpr/libwinpr/utils/cmdline.c @@ -312,7 +312,8 @@ int CommandLineParseArgumentsA(int argc, LPSTR* argv, COMMAND_LINE_ARGUMENT_A* o if (value) { - if (options[j].Flags & (COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_VALUE_BOOL)) + if (!(options[j].Flags & + (COMMAND_LINE_VALUE_OPTIONAL | COMMAND_LINE_VALUE_REQUIRED))) { log_error(flags, "Failed at index %d [%s]: Unexpected value", i, argv[i]); return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;