libfreerdp-client: accept posix-style command-line syntax

This commit is contained in:
Marc-André Moreau 2012-12-02 13:34:00 -05:00
parent 9416e7355e
commit e6f524f6c3
8 changed files with 76 additions and 27 deletions

View File

@ -462,7 +462,7 @@ int main(int argc, char* argv[])
instance->context->argc = argc;
instance->context->argv = argv;
if (freerdp_detect_old_command_line_syntax(instance->context->argc,instance->context->argv))
if (freerdp_detect_posix_style_command_line_syntax(instance->context->argc,instance->context->argv))
{
printf("warning: deprecated command-line syntax detected!\n");
freerdp_client_print_command_line_help(argc, argv);

View File

@ -320,7 +320,7 @@ int main(int argc, char* argv[])
channels = instance->context->channels;
if (freerdp_detect_old_command_line_syntax(instance->context->argc,instance->context->argv))
if (freerdp_detect_posix_style_command_line_syntax(instance->context->argc, instance->context->argv))
{
printf("warning: deprecated command-line syntax detected!\n");
freerdp_client_print_command_line_help(argc, argv);

View File

@ -771,7 +771,7 @@ INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
freerdp_register_addin_provider(freerdp_channels_load_static_addin_entry, 0);
if (freerdp_detect_new_command_line_syntax(__argc, __argv))
if (freerdp_detect_windows_style_command_line_syntax(__argc, __argv))
{
status = freerdp_client_parse_command_line_arguments(__argc, __argv, instance->settings);

View File

@ -494,14 +494,8 @@ BOOL xf_pre_connect(freerdp* instance)
xfi->context->settings = instance->settings;
xfi->instance = instance;
if (freerdp_detect_old_command_line_syntax(instance->context->argc,instance->context->argv))
{
printf("warning: deprecated command-line syntax detected!\n");
freerdp_client_print_command_line_help(instance->context->argc,instance->context->argv);
exit(XF_EXIT_PARSE_ARGUMENTS);
}
status = freerdp_client_parse_command_line_arguments(instance->context->argc,instance->context->argv, instance->settings);
status = freerdp_client_parse_command_line_arguments(instance->context->argc,
instance->context->argv, instance->settings);
if (status < 0)
exit(XF_EXIT_PARSE_ARGUMENTS);

View File

@ -109,7 +109,7 @@ COMMAND_LINE_ARGUMENT_A args[] =
{ NULL, 0, NULL, NULL, NULL, -1, NULL, NULL }
};
BOOL freerdp_detect_new_command_line_syntax(int argc, char* argv[])
BOOL freerdp_detect_windows_style_command_line_syntax(int argc, char** argv)
{
int index;
@ -122,9 +122,9 @@ BOOL freerdp_detect_new_command_line_syntax(int argc, char* argv[])
return FALSE;
}
BOOL freerdp_detect_old_command_line_syntax(int argc, char* argv[])
BOOL freerdp_detect_posix_style_command_line_syntax(int argc, char** argv)
{
return (!freerdp_detect_new_command_line_syntax(argc, argv));
return (!freerdp_detect_windows_style_command_line_syntax(argc, argv));
}
int freerdp_client_print_version()
@ -637,11 +637,23 @@ int freerdp_client_parse_command_line_arguments(int argc, char** argv, rdpSettin
freerdp_register_addin_provider(freerdp_channels_load_static_addin_entry, 0);
flags = COMMAND_LINE_SIGIL_SLASH | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_SIGIL_PLUS_MINUS;
if (freerdp_detect_windows_style_command_line_syntax(argc, argv))
{
flags = COMMAND_LINE_SEPARATOR_COLON;
flags |= COMMAND_LINE_SIGIL_SLASH | COMMAND_LINE_SIGIL_PLUS_MINUS;
}
else
{
flags = COMMAND_LINE_SEPARATOR_SPACE;
flags |= COMMAND_LINE_SIGIL_DASH | COMMAND_LINE_SIGIL_DOUBLE_DASH;
flags |= COMMAND_LINE_SIGIL_ENABLE_DISABLE;
}
status = CommandLineParseArgumentsA(argc, (const char**) argv, args, flags, settings,
freerdp_client_command_line_pre_filter, freerdp_client_command_line_post_filter);
printf("status: %d\n", status);
if (status == COMMAND_LINE_STATUS_PRINT_HELP)
{
freerdp_client_print_command_line_help(argc, argv);

View File

@ -23,8 +23,8 @@
#include <freerdp/api.h>
#include <freerdp/freerdp.h>
FREERDP_API BOOL freerdp_detect_new_command_line_syntax(int argc, char* argv[]);
FREERDP_API BOOL freerdp_detect_old_command_line_syntax(int argc, char* argv[]);
FREERDP_API BOOL freerdp_detect_windows_style_command_line_syntax(int argc, char** argv);
FREERDP_API BOOL freerdp_detect_posix_style_command_line_syntax(int argc, char** argv);
FREERDP_API int freerdp_client_parse_command_line_arguments(int argc, char** argv, rdpSettings* settings);
FREERDP_API int freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings);

View File

@ -52,6 +52,7 @@
#define COMMAND_LINE_SIGIL_DASH 0x00000004
#define COMMAND_LINE_SIGIL_DOUBLE_DASH 0x00000008
#define COMMAND_LINE_SIGIL_PLUS_MINUS 0x00000010
#define COMMAND_LINE_SIGIL_ENABLE_DISABLE 0x00000020
#define COMMAND_LINE_SEPARATOR_COLON 0x00000100
#define COMMAND_LINE_SEPARATOR_EQUAL 0x00000200
@ -63,6 +64,7 @@
#define COMMAND_LINE_ERROR_UNEXPECTED_VALUE -1002
#define COMMAND_LINE_ERROR_MISSING_VALUE -1003
#define COMMAND_LINE_ERROR_MISSING_ARGUMENT -1004
#define COMMAND_LINE_ERROR_UNEXPECTED_SIGIL -1005
/* Command-Line Parsing Status Codes */

View File

@ -102,6 +102,7 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
char* value;
int value_length;
int value_index;
int toggle;
if (!argv)
return 0;
@ -128,6 +129,12 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
else if ((sigil[0] == '-') && (flags & COMMAND_LINE_SIGIL_DASH))
{
sigil_length = 1;
if (length > 2)
{
if ((sigil[1] == '-') && (flags & COMMAND_LINE_SIGIL_DOUBLE_DASH))
sigil_length = 2;
}
}
else if ((sigil[0] == '+') && (flags & COMMAND_LINE_SIGIL_PLUS_MINUS))
{
@ -154,6 +161,24 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
keyword_index = sigil_index + sigil_length;
keyword = (char*) &argv[i][keyword_index];
toggle = -1;
if (flags & COMMAND_LINE_SIGIL_ENABLE_DISABLE)
{
if (strncmp(keyword, "enable-", 7) == 0)
{
toggle = TRUE;
keyword_index += 7;
keyword = (char*) &argv[i][keyword_index];
}
else if (strncmp(keyword, "disable-", 8) == 0)
{
toggle = FALSE;
keyword_index += 8;
keyword = (char*) &argv[i][keyword_index];
}
}
separator = NULL;
if ((flags & COMMAND_LINE_SEPARATOR_COLON) && (!separator))
@ -210,12 +235,16 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
if ((flags & COMMAND_LINE_SEPARATOR_SPACE) && ((i + 1) < argc))
{
i++;
value_index = 0;
length = strlen(argv[i]);
if ((options[j].Flags & COMMAND_LINE_VALUE_REQUIRED) ||
(options[j].Flags & COMMAND_LINE_VALUE_OPTIONAL))
{
i++;
value_index = 0;
length = strlen(argv[i]);
value = (char*) &argv[i][value_index];
value_length = (length - value_index);
value = (char*) &argv[i][value_index];
value_length = (length - value_index);
}
}
if (!(flags & COMMAND_LINE_SEPARATOR_SPACE))
@ -253,12 +282,24 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
}
else if (options[j].Flags & COMMAND_LINE_VALUE_BOOL)
{
if (sigil[0] == '+')
options[j].Value = BoolValueTrue;
else if (sigil[0] == '-')
options[j].Value = BoolValueFalse;
if (flags & COMMAND_LINE_SIGIL_ENABLE_DISABLE)
{
if (toggle == -1)
options[j].Value = BoolValueTrue;
else if (!toggle)
options[j].Value = BoolValueFalse;
else
options[j].Value = BoolValueTrue;
}
else
options[j].Value = BoolValueTrue;
{
if (sigil[0] == '+')
options[j].Value = BoolValueTrue;
else if (sigil[0] == '-')
options[j].Value = BoolValueFalse;
else
options[j].Value = BoolValueTrue;
}
options[j].Flags |= COMMAND_LINE_VALUE_PRESENT;
}