Allow printing of custom arguments in help.

This commit is contained in:
Armin Novak 2017-05-04 14:46:58 +02:00
parent f4f23454c9
commit 8c2bd951ae
4 changed files with 102 additions and 88 deletions

View File

@ -199,36 +199,23 @@ static COMMAND_LINE_ARGUMENT_A args[] =
{ NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL }
}; };
BOOL freerdp_client_print_version() BOOL freerdp_client_print_version(void)
{ {
printf("This is FreeRDP version %s (%s)\n", FREERDP_VERSION_FULL, printf("This is FreeRDP version %s (%s)\n", FREERDP_VERSION_FULL,
GIT_REVISION); GIT_REVISION);
return TRUE; return TRUE;
} }
BOOL freerdp_client_print_buildconfig() BOOL freerdp_client_print_buildconfig(void)
{ {
printf("%s", freerdp_get_build_config()); printf("%s", freerdp_get_build_config());
return TRUE; return TRUE;
} }
BOOL freerdp_client_print_command_line_help(int argc, char** argv) static void freerdp_client_print_command_line_args(COMMAND_LINE_ARGUMENT_A* arg)
{ {
char* str; if (!arg)
int length; return;
COMMAND_LINE_ARGUMENT_A* arg;
printf("\n");
printf("FreeRDP - A Free Remote Desktop Protocol Implementation\n");
printf("See www.freerdp.com for more information\n");
printf("\n");
printf("Usage: %s [file] [options] [/v:<server>[:port]]\n", argv[0]);
printf("\n");
printf("Syntax:\n");
printf(" /flag (enables flag)\n");
printf(" /option:<value> (specifies option with value)\n");
printf(" +toggle -toggle (enables or disables toggle, where '/' is a synonym of '+')\n");
printf("\n");
arg = args;
do do
{ {
@ -242,12 +229,12 @@ BOOL freerdp_client_print_command_line_help(int argc, char** argv)
|| (arg->Flags & COMMAND_LINE_VALUE_OPTIONAL)) || (arg->Flags & COMMAND_LINE_VALUE_OPTIONAL))
{ {
BOOL overlong = FALSE; BOOL overlong = FALSE;
printf(" %s", "/"); printf(" %s", "/");
if (arg->Format) if (arg->Format)
{ {
length = (int)(strlen(arg->Name) + strlen(arg->Format) + 2); size_t length = (strlen(arg->Name) + strlen(arg->Format) + 2);
if (arg->Flags & COMMAND_LINE_VALUE_OPTIONAL) if (arg->Flags & COMMAND_LINE_VALUE_OPTIONAL)
length += 2; length += 2;
@ -257,18 +244,10 @@ BOOL freerdp_client_print_command_line_help(int argc, char** argv)
overlong = TRUE; overlong = TRUE;
} }
str = (char*) calloc(length + 1UL, sizeof(char));
if (!str)
return FALSE;
if (arg->Flags & COMMAND_LINE_VALUE_OPTIONAL) if (arg->Flags & COMMAND_LINE_VALUE_OPTIONAL)
sprintf_s(str, length + 1, "%s[:%s]", arg->Name, overlong ? "..." : arg->Format); printf("%s[:%s]", arg->Name, overlong ? "..." : arg->Format);
else else
sprintf_s(str, length + 1, "%s:%s", arg->Name, overlong ? "..." : arg->Format); printf("%s:%s", arg->Name, overlong ? "..." : arg->Format);
printf("%-20s", str);
free(str);
} }
else else
{ {
@ -285,7 +264,29 @@ BOOL freerdp_client_print_command_line_help(int argc, char** argv)
} }
} }
while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
}
BOOL freerdp_client_print_command_line_help(int argc, char** argv)
{
return freerdp_client_print_command_line_help_ex(argc, argv, NULL);
}
BOOL freerdp_client_print_command_line_help_ex(int argc, char** argv,
COMMAND_LINE_ARGUMENT_A* custom)
{
printf("\n");
printf("FreeRDP - A Free Remote Desktop Protocol Implementation\n");
printf("See www.freerdp.com for more information\n");
printf("\n");
printf("Usage: %s [file] [options] [/v:<server>[:port]]\n", argv[0]);
printf("\n");
printf("Syntax:\n");
printf(" /flag (enables flag)\n");
printf(" /option:<value> (specifies option with value)\n");
printf(" +toggle -toggle (enables or disables toggle, where '/' is a synonym of '+')\n");
printf("\n");
freerdp_client_print_command_line_args(custom);
freerdp_client_print_command_line_args(args);
printf("\n"); printf("\n");
printf("Examples:\n"); printf("Examples:\n");
printf(" xfreerdp connection.rdp /p:Pwd123! /f\n"); printf(" xfreerdp connection.rdp /p:Pwd123! /f\n");
@ -311,7 +312,6 @@ BOOL freerdp_client_print_command_line_help(int argc, char** argv)
printf("Multimedia Redirection: /multimedia:sys:alsa\n"); printf("Multimedia Redirection: /multimedia:sys:alsa\n");
printf("USB Device Redirection: /usb:id,dev:054c:0268\n"); printf("USB Device Redirection: /usb:id,dev:054c:0268\n");
printf("\n"); printf("\n");
printf("For Gateways, the https_proxy environment variable is respected:\n"); printf("For Gateways, the https_proxy environment variable is respected:\n");
#ifdef _WIN32 #ifdef _WIN32
printf(" set HTTPS_PROXY=http://proxy.contoso.com:3128/\n"); printf(" set HTTPS_PROXY=http://proxy.contoso.com:3128/\n");
@ -320,7 +320,6 @@ BOOL freerdp_client_print_command_line_help(int argc, char** argv)
#endif #endif
printf(" xfreerdp /g:rdp.contoso.com ...\n"); printf(" xfreerdp /g:rdp.contoso.com ...\n");
printf("\n"); printf("\n");
printf("More documentation is coming, in the meantime consult source files\n"); printf("More documentation is coming, in the meantime consult source files\n");
printf("\n"); printf("\n");
return TRUE; return TRUE;
@ -866,8 +865,6 @@ static int freerdp_client_command_line_post_filter(void* context,
free(p); free(p);
} }
CommandLineSwitchCase(arg, "smartcard") CommandLineSwitchCase(arg, "smartcard")
{
if (arg->Flags & COMMAND_LINE_VALUE_PRESENT)
{ {
char** p; char** p;
int count; int count;
@ -877,15 +874,6 @@ static int freerdp_client_command_line_post_filter(void* context,
status = freerdp_client_add_device_channel(settings, count, p); status = freerdp_client_add_device_channel(settings, count, p);
free(p); free(p);
} }
else
{
char* p[1];
int count;
count = 1;
p[0] = "smartcard";
status = freerdp_client_add_device_channel(settings, count, p);
}
}
CommandLineSwitchCase(arg, "printer") CommandLineSwitchCase(arg, "printer")
{ {
if (arg->Flags & COMMAND_LINE_VALUE_PRESENT) if (arg->Flags & COMMAND_LINE_VALUE_PRESENT)
@ -1395,6 +1383,13 @@ static BOOL freerdp_client_detect_command_line(int argc, char** argv,
int freerdp_client_settings_command_line_status_print(rdpSettings* settings, int freerdp_client_settings_command_line_status_print(rdpSettings* settings,
int status, int argc, char** argv) int status, int argc, char** argv)
{
return freerdp_client_settings_command_line_status_print_ex(
settings, status, argc, argv, NULL);
}
int freerdp_client_settings_command_line_status_print_ex(rdpSettings* settings,
int status, int argc, char** argv, COMMAND_LINE_ARGUMENT_A* custom)
{ {
COMMAND_LINE_ARGUMENT_A* arg; COMMAND_LINE_ARGUMENT_A* arg;
@ -1456,7 +1451,7 @@ int freerdp_client_settings_command_line_status_print(rdpSettings* settings,
} }
else if (status < 0) else if (status < 0)
{ {
freerdp_client_print_command_line_help(argc, argv); freerdp_client_print_command_line_help_ex(argc, argv, custom);
return COMMAND_LINE_STATUS_PRINT_HELP; return COMMAND_LINE_STATUS_PRINT_HELP;
} }
@ -1621,6 +1616,7 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
settings->PercentScreenUseWidth = 1; settings->PercentScreenUseWidth = 1;
partial = TRUE; partial = TRUE;
} }
if (strchr(p, 'h')) if (strchr(p, 'h'))
{ {
settings->PercentScreenUseHeight = 1; settings->PercentScreenUseHeight = 1;
@ -2148,6 +2144,7 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
if (arg->Value) if (arg->Value)
{ {
#ifdef WITH_GFX_H264 #ifdef WITH_GFX_H264
if (_strnicmp("AVC444", arg->Value, 6) == 0) if (_strnicmp("AVC444", arg->Value, 6) == 0)
{ {
settings->GfxH264 = TRUE; settings->GfxH264 = TRUE;
@ -2166,8 +2163,10 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
CommandLineSwitchCase(arg, "gfx-thin-client") CommandLineSwitchCase(arg, "gfx-thin-client")
{ {
settings->GfxThinClient = arg->Value ? TRUE : FALSE; settings->GfxThinClient = arg->Value ? TRUE : FALSE;
if (settings->GfxThinClient) if (settings->GfxThinClient)
settings->GfxSmallCache = TRUE; settings->GfxSmallCache = TRUE;
settings->SupportGraphicsPipeline = TRUE; settings->SupportGraphicsPipeline = TRUE;
} }
CommandLineSwitchCase(arg, "gfx-small-cache") CommandLineSwitchCase(arg, "gfx-small-cache")
@ -2427,6 +2426,7 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
{ {
settings->NSCodec = TRUE; settings->NSCodec = TRUE;
} }
#if defined(WITH_JPEG) #if defined(WITH_JPEG)
else if (strcmp(arg->Value, "jpeg") == 0) else if (strcmp(arg->Value, "jpeg") == 0)
{ {
@ -2435,6 +2435,7 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
if (settings->JpegQuality == 0) if (settings->JpegQuality == 0)
settings->JpegQuality = 75; settings->JpegQuality = 75;
} }
#endif #endif
} }
CommandLineSwitchCase(arg, "fast-path") CommandLineSwitchCase(arg, "fast-path")

View File

@ -20,6 +20,8 @@
#ifndef FREERDP_CLIENT_CMDLINE_H #ifndef FREERDP_CLIENT_CMDLINE_H
#define FREERDP_CLIENT_CMDLINE_H #define FREERDP_CLIENT_CMDLINE_H
#include <winpr/cmdline.h>
#include <freerdp/api.h> #include <freerdp/api.h>
#include <freerdp/freerdp.h> #include <freerdp/freerdp.h>
@ -29,12 +31,18 @@ extern "C" {
FREERDP_API int freerdp_client_settings_parse_command_line_arguments( FREERDP_API int freerdp_client_settings_parse_command_line_arguments(
rdpSettings* settings, int argc, char** argv, BOOL allowUnknown); rdpSettings* settings, int argc, char** argv, BOOL allowUnknown);
FREERDP_API int freerdp_client_settings_command_line_status_print(rdpSettings* settings, int status, int argc, char** argv); FREERDP_API int freerdp_client_settings_command_line_status_print(
rdpSettings* settings, int status, int argc, char** argv);
FREERDP_API int freerdp_client_settings_command_line_status_print_ex(
rdpSettings* settings, int status, int argc, char** argv,
COMMAND_LINE_ARGUMENT_A* custom);
FREERDP_API BOOL freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings); FREERDP_API BOOL freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings);
FREERDP_API BOOL freerdp_client_print_version(void); FREERDP_API BOOL freerdp_client_print_version(void);
FREERDP_API BOOL freerdp_client_print_buildconfig(void); FREERDP_API BOOL freerdp_client_print_buildconfig(void);
FREERDP_API BOOL freerdp_client_print_command_line_help(int argc, char** argv); FREERDP_API BOOL freerdp_client_print_command_line_help(int argc, char** argv);
FREERDP_API BOOL freerdp_client_print_command_line_help_ex(
int argc, char** argv, COMMAND_LINE_ARGUMENT_A* custom);
FREERDP_API BOOL freerdp_parse_username(char* username, char** user, char** domain); FREERDP_API BOOL freerdp_parse_username(char* username, char** user, char** domain);
FREERDP_API BOOL freerdp_parse_hostname(char* hostname, char** host, int* port); FREERDP_API BOOL freerdp_parse_hostname(char* hostname, char** host, int* port);
@ -42,7 +50,8 @@ FREERDP_API BOOL freerdp_set_connection_type(rdpSettings* settings, int type);
FREERDP_API BOOL freerdp_client_add_device_channel(rdpSettings* settings, int count, char** params); FREERDP_API BOOL freerdp_client_add_device_channel(rdpSettings* settings, int count, char** params);
FREERDP_API BOOL freerdp_client_add_static_channel(rdpSettings* settings, int count, char** params); FREERDP_API BOOL freerdp_client_add_static_channel(rdpSettings* settings, int count, char** params);
FREERDP_API BOOL freerdp_client_add_dynamic_channel(rdpSettings* settings, int count, char** params); FREERDP_API BOOL freerdp_client_add_dynamic_channel(rdpSettings* settings, int count,
char** params);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -137,13 +137,17 @@ extern "C" {
WINPR_API int CommandLineClearArgumentsA(COMMAND_LINE_ARGUMENT_A* options); WINPR_API int CommandLineClearArgumentsA(COMMAND_LINE_ARGUMENT_A* options);
WINPR_API int CommandLineClearArgumentsW(COMMAND_LINE_ARGUMENT_W* options); WINPR_API int CommandLineClearArgumentsW(COMMAND_LINE_ARGUMENT_W* options);
WINPR_API int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A* options, DWORD flags, WINPR_API int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A* options,
DWORD flags,
void* context, COMMAND_LINE_PRE_FILTER_FN_A preFilter, COMMAND_LINE_POST_FILTER_FN_A postFilter); void* context, COMMAND_LINE_PRE_FILTER_FN_A preFilter, COMMAND_LINE_POST_FILTER_FN_A postFilter);
WINPR_API int CommandLineParseArgumentsW(int argc, LPCWSTR* argv, COMMAND_LINE_ARGUMENT_W* options, DWORD flags, WINPR_API int CommandLineParseArgumentsW(int argc, LPCWSTR* argv, COMMAND_LINE_ARGUMENT_W* options,
DWORD flags,
void* context, COMMAND_LINE_PRE_FILTER_FN_W preFilter, COMMAND_LINE_POST_FILTER_FN_W postFilter); void* context, COMMAND_LINE_PRE_FILTER_FN_W preFilter, COMMAND_LINE_POST_FILTER_FN_W postFilter);
WINPR_API COMMAND_LINE_ARGUMENT_A* CommandLineFindArgumentA(COMMAND_LINE_ARGUMENT_A* options, LPCSTR Name); WINPR_API COMMAND_LINE_ARGUMENT_A* CommandLineFindArgumentA(COMMAND_LINE_ARGUMENT_A* options,
WINPR_API COMMAND_LINE_ARGUMENT_W* CommandLineFindArgumentW(COMMAND_LINE_ARGUMENT_W* options, LPCWSTR Name); LPCSTR Name);
WINPR_API COMMAND_LINE_ARGUMENT_W* CommandLineFindArgumentW(COMMAND_LINE_ARGUMENT_W* options,
LPCWSTR Name);
WINPR_API COMMAND_LINE_ARGUMENT_A* CommandLineFindNextArgumentA(COMMAND_LINE_ARGUMENT_A* argument); WINPR_API COMMAND_LINE_ARGUMENT_A* CommandLineFindNextArgumentA(COMMAND_LINE_ARGUMENT_A* argument);

View File

@ -45,7 +45,8 @@
* *
*/ */
int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A* options, DWORD flags, int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A* options,
DWORD flags,
void* context, COMMAND_LINE_PRE_FILTER_FN_A preFilter, COMMAND_LINE_POST_FILTER_FN_A postFilter) void* context, COMMAND_LINE_PRE_FILTER_FN_A preFilter, COMMAND_LINE_POST_FILTER_FN_A postFilter)
{ {
int i, j; int i, j;
@ -71,9 +72,7 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
int value_length; int value_length;
int value_index; int value_index;
int toggle; int toggle;
status = 0; status = 0;
match = FALSE; match = FALSE;
found = FALSE; found = FALSE;
argument = FALSE; argument = FALSE;
@ -92,7 +91,6 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
{ {
index = i; index = i;
escaped = TRUE; escaped = TRUE;
if (preFilter) if (preFilter)
@ -160,15 +158,16 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
if ((sigil_length > 0) || (flags & COMMAND_LINE_SIGIL_NONE) || if ((sigil_length > 0) || (flags & COMMAND_LINE_SIGIL_NONE) ||
(flags & COMMAND_LINE_SIGIL_NOT_ESCAPED)) (flags & COMMAND_LINE_SIGIL_NOT_ESCAPED))
{ {
if (length < (sigil_length + 1)) { if (length < (sigil_length + 1))
{
if ((flags & COMMAND_LINE_IGN_UNKNOWN_KEYWORD)) if ((flags & COMMAND_LINE_IGN_UNKNOWN_KEYWORD))
continue; continue;
return COMMAND_LINE_ERROR_NO_KEYWORD; return COMMAND_LINE_ERROR_NO_KEYWORD;
} }
keyword_index = sigil_index + sigil_length; keyword_index = sigil_index + sigil_length;
keyword = (char*) &argv[i][keyword_index]; keyword = (char*) &argv[i][keyword_index];
toggle = -1; toggle = -1;
if (flags & COMMAND_LINE_SIGIL_ENABLE_DISABLE) if (flags & COMMAND_LINE_SIGIL_ENABLE_DISABLE)
@ -198,10 +197,8 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
if (separator) if (separator)
{ {
separator_length = 1; separator_length = 1;
separator_index = (int) (separator - argv[i]); separator_index = (int)(separator - argv[i]);
keyword_length = (int)(separator - keyword);
keyword_length = (int) (separator - keyword);
value_index = separator_index + separator_length; value_index = separator_index + separator_length;
value = (char*) &argv[i][value_index]; value = (char*) &argv[i][value_index];
value_length = (length - value_index); value_length = (length - value_index);
@ -211,7 +208,6 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
separator_length = 0; separator_length = 0;
separator_index = -1; separator_index = -1;
keyword_length = (length - keyword_index); keyword_length = (length - keyword_index);
value_index = -1; value_index = -1;
value = NULL; value = NULL;
value_length = 0; value_length = 0;
@ -221,6 +217,7 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
continue; continue;
found = FALSE; found = FALSE;
for (j = 0; options[j].Name != NULL; j++) for (j = 0; options[j].Name != NULL; j++)
{ {
match = FALSE; match = FALSE;
@ -279,7 +276,6 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
i++; i++;
value_index = 0; value_index = 0;
length = (int) strlen(argv[i]); length = (int) strlen(argv[i]);
value = (char*) &argv[i][value_index]; value = (char*) &argv[i][value_index];
value_length = (length - value_index); value_length = (length - value_index);
} }
@ -375,7 +371,8 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
return status; return status;
} }
int CommandLineParseArgumentsW(int argc, LPCWSTR* argv, COMMAND_LINE_ARGUMENT_W* options, DWORD flags, int CommandLineParseArgumentsW(int argc, LPCWSTR* argv, COMMAND_LINE_ARGUMENT_W* options,
DWORD flags,
void* context, COMMAND_LINE_PRE_FILTER_FN_W preFilter, COMMAND_LINE_POST_FILTER_FN_W postFilter) void* context, COMMAND_LINE_PRE_FILTER_FN_W preFilter, COMMAND_LINE_POST_FILTER_FN_W postFilter)
{ {
return 0; return 0;
@ -409,7 +406,7 @@ int CommandLineClearArgumentsW(COMMAND_LINE_ARGUMENT_W* options)
COMMAND_LINE_ARGUMENT_A* CommandLineFindArgumentA(COMMAND_LINE_ARGUMENT_A* options, LPCSTR Name) COMMAND_LINE_ARGUMENT_A* CommandLineFindArgumentA(COMMAND_LINE_ARGUMENT_A* options, LPCSTR Name)
{ {
int i; size_t i;
for (i = 0; options[i].Name != NULL; i++) for (i = 0; options[i].Name != NULL; i++)
{ {
@ -428,7 +425,7 @@ COMMAND_LINE_ARGUMENT_A* CommandLineFindArgumentA(COMMAND_LINE_ARGUMENT_A* optio
COMMAND_LINE_ARGUMENT_W* CommandLineFindArgumentW(COMMAND_LINE_ARGUMENT_W* options, LPCWSTR Name) COMMAND_LINE_ARGUMENT_W* CommandLineFindArgumentW(COMMAND_LINE_ARGUMENT_W* options, LPCWSTR Name)
{ {
int i; size_t i;
for (i = 0; options[i].Name != NULL; i++) for (i = 0; options[i].Name != NULL; i++)
{ {
@ -449,6 +446,9 @@ COMMAND_LINE_ARGUMENT_A* CommandLineFindNextArgumentA(COMMAND_LINE_ARGUMENT_A* a
{ {
COMMAND_LINE_ARGUMENT_A* nextArgument; COMMAND_LINE_ARGUMENT_A* nextArgument;
if (!argument)
return NULL;
nextArgument = &argument[1]; nextArgument = &argument[1];
if (nextArgument->Name == NULL) if (nextArgument->Name == NULL)