Fixed command line parser, now printing help, if an invalid option is detected.
This commit is contained in:
parent
31b9b93548
commit
4274b266c0
@ -870,6 +870,8 @@ int freerdp_detect_windows_style_command_line_syntax(int argc, char** argv, int*
|
||||
detect_status = 0;
|
||||
CommandLineClearArgumentsA(args);
|
||||
status = CommandLineParseArgumentsA(argc, (const char**) argv, args, flags, NULL, NULL, NULL);
|
||||
if (status < 0)
|
||||
return status;
|
||||
|
||||
arg = args;
|
||||
|
||||
@ -903,6 +905,8 @@ int freerdp_detect_posix_style_command_line_syntax(int argc, char** argv, int* c
|
||||
detect_status = 0;
|
||||
CommandLineClearArgumentsA(args);
|
||||
status = CommandLineParseArgumentsA(argc, (const char**) argv, args, flags, NULL, NULL, NULL);
|
||||
if (status < 0)
|
||||
return status;
|
||||
|
||||
arg = args;
|
||||
|
||||
@ -945,7 +949,8 @@ BOOL freerdp_client_detect_command_line(int argc, char** argv, DWORD* flags)
|
||||
*flags = COMMAND_LINE_SEPARATOR_COLON;
|
||||
*flags |= COMMAND_LINE_SIGIL_SLASH | COMMAND_LINE_SIGIL_PLUS_MINUS;
|
||||
}
|
||||
else
|
||||
/* Ignore legacy parsing in case there is an error in the command line. */
|
||||
else if (old_cli_status >= 0)
|
||||
{
|
||||
if ((old_cli_status == 1) || ((old_cli_count > posix_cli_count) && (old_cli_status != -1)))
|
||||
{
|
||||
@ -966,12 +971,7 @@ int freerdp_client_command_line_status_print(int argc, char** argv, rdpSettings*
|
||||
{
|
||||
COMMAND_LINE_ARGUMENT_A* arg;
|
||||
|
||||
if (status == COMMAND_LINE_STATUS_PRINT_HELP)
|
||||
{
|
||||
freerdp_client_print_command_line_help(argc, argv);
|
||||
return COMMAND_LINE_STATUS_PRINT_HELP;
|
||||
}
|
||||
else if (status == COMMAND_LINE_STATUS_PRINT_VERSION)
|
||||
if (status == COMMAND_LINE_STATUS_PRINT_VERSION)
|
||||
{
|
||||
freerdp_client_print_version();
|
||||
return COMMAND_LINE_STATUS_PRINT_VERSION;
|
||||
@ -1015,6 +1015,11 @@ int freerdp_client_command_line_status_print(int argc, char** argv, rdpSettings*
|
||||
|
||||
return COMMAND_LINE_STATUS_PRINT;
|
||||
}
|
||||
else if (status < 0)
|
||||
{
|
||||
freerdp_client_print_command_line_help(argc, argv);
|
||||
return COMMAND_LINE_STATUS_PRINT_HELP;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1043,6 +1048,8 @@ int freerdp_client_parse_command_line_arguments(int argc, char** argv, rdpSettin
|
||||
CommandLineClearArgumentsA(args);
|
||||
status = CommandLineParseArgumentsA(argc, (const char**) argv, args, flags, settings,
|
||||
freerdp_client_command_line_pre_filter, freerdp_client_command_line_post_filter);
|
||||
if (status < 0)
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -1624,7 +1631,8 @@ int freerdp_client_parse_command_line_arguments(int argc, char** argv, rdpSettin
|
||||
}
|
||||
CommandLineSwitchDefault(arg)
|
||||
{
|
||||
|
||||
fprintf(stderr, "Unknown argument %s\n", __func__, arg->Name);
|
||||
return COMMAND_LINE_ERROR;
|
||||
}
|
||||
|
||||
CommandLineSwitchEnd(arg)
|
||||
|
@ -309,6 +309,8 @@ int freerdp_detect_old_command_line_syntax(int argc, char** argv, int* count)
|
||||
CommandLineClearArgumentsA(old_args);
|
||||
status = CommandLineParseArgumentsA(argc, (const char**) argv, old_args, flags, settings,
|
||||
freerdp_client_old_command_line_pre_filter, NULL);
|
||||
if (status < 0)
|
||||
return status;
|
||||
|
||||
arg = old_args;
|
||||
|
||||
@ -374,12 +376,7 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe
|
||||
status = CommandLineParseArgumentsA(argc, (const char**) argv, old_args, flags, settings,
|
||||
freerdp_client_old_command_line_pre_filter, freerdp_client_old_command_line_post_filter);
|
||||
|
||||
if (status == COMMAND_LINE_STATUS_PRINT_HELP)
|
||||
{
|
||||
freerdp_client_print_command_line_help(argc, argv);
|
||||
return COMMAND_LINE_STATUS_PRINT_HELP;
|
||||
}
|
||||
else if (status == COMMAND_LINE_STATUS_PRINT_VERSION)
|
||||
if (status == COMMAND_LINE_STATUS_PRINT_VERSION)
|
||||
{
|
||||
freerdp_client_print_version();
|
||||
return COMMAND_LINE_STATUS_PRINT_VERSION;
|
||||
@ -388,6 +385,15 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe
|
||||
{
|
||||
return COMMAND_LINE_STATUS_PRINT;
|
||||
}
|
||||
else if (status < 0)
|
||||
{
|
||||
if (status != COMMAND_LINE_STATUS_PRINT_HELP)
|
||||
{
|
||||
|
||||
}
|
||||
freerdp_client_print_command_line_help(argc, argv);
|
||||
return COMMAND_LINE_STATUS_PRINT_HELP;
|
||||
}
|
||||
|
||||
arg = old_args;
|
||||
|
||||
|
@ -53,7 +53,7 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
|
||||
int count;
|
||||
int length;
|
||||
int index;
|
||||
BOOL match;
|
||||
BOOL match, found, argument = FALSE;
|
||||
char* sigil;
|
||||
int sigil_length;
|
||||
int sigil_index;
|
||||
@ -86,7 +86,6 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
|
||||
if (preFilter)
|
||||
{
|
||||
count = preFilter(context, i, argc, argv);
|
||||
|
||||
if (count < 0)
|
||||
{
|
||||
status = COMMAND_LINE_ERROR;
|
||||
@ -133,9 +132,9 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
return COMMAND_LINE_ERROR;
|
||||
}
|
||||
|
||||
|
||||
if ((sigil_length > 0) || (flags & COMMAND_LINE_SIGIL_NONE))
|
||||
{
|
||||
if (length < (sigil_length + 1))
|
||||
@ -192,6 +191,7 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
|
||||
value_length = 0;
|
||||
}
|
||||
|
||||
found = FALSE;
|
||||
for (j = 0; options[j].Name != NULL; j++)
|
||||
{
|
||||
match = FALSE;
|
||||
@ -214,6 +214,7 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
|
||||
if (!match)
|
||||
continue;
|
||||
|
||||
found = match;
|
||||
options[j].Index = index;
|
||||
|
||||
if ((flags & COMMAND_LINE_SEPARATOR_SPACE) && ((i + 1) < argc))
|
||||
@ -238,7 +239,12 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
|
||||
value_present = 0;
|
||||
}
|
||||
|
||||
if (value_present)
|
||||
if (options[j].Flags & COMMAND_LINE_VALUE_REQUIRED)
|
||||
argument = TRUE;
|
||||
else
|
||||
argument = FALSE;
|
||||
|
||||
if (value_present && argument)
|
||||
{
|
||||
i++;
|
||||
value_index = 0;
|
||||
@ -247,6 +253,8 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
|
||||
value = (char*) &argv[i][value_index];
|
||||
value_length = (length - value_index);
|
||||
}
|
||||
else
|
||||
return COMMAND_LINE_ERROR;
|
||||
}
|
||||
|
||||
if (!(flags & COMMAND_LINE_SEPARATOR_SPACE))
|
||||
@ -320,6 +328,9 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
|
||||
else if (options[j].Flags & COMMAND_LINE_PRINT_VERSION)
|
||||
return COMMAND_LINE_STATUS_PRINT_VERSION;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
return COMMAND_LINE_ERROR_NO_KEYWORD;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user