libwinpr-utils: added post/pre command-line filters
This commit is contained in:
parent
e133d01376
commit
d4045895ef
@ -160,7 +160,7 @@ int freerdp_client_print_command_line_help()
|
||||
return 1;
|
||||
}
|
||||
|
||||
int freerdp_client_command_line_filter(int index, LPCSTR arg, void* context)
|
||||
int freerdp_client_command_line_pre_filter(void* context, int index, LPCSTR arg)
|
||||
{
|
||||
if (index == 1)
|
||||
{
|
||||
@ -182,6 +182,26 @@ int freerdp_client_command_line_filter(int index, LPCSTR arg, void* context)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT_A* arg)
|
||||
{
|
||||
CommandLineSwitchStart(arg)
|
||||
|
||||
CommandLineSwitchCase(arg, "a")
|
||||
{
|
||||
int index;
|
||||
int nCommas;
|
||||
|
||||
nCommas = 0;
|
||||
|
||||
for (index = 0; arg->Value[index]; index++)
|
||||
nCommas += (arg->Value[index] == ',') ? 1 : 0;
|
||||
}
|
||||
|
||||
CommandLineSwitchEnd(arg)
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int freerdp_client_parse_command_line_arguments(int argc, char** argv, rdpSettings* settings)
|
||||
{
|
||||
char* p;
|
||||
@ -193,8 +213,8 @@ int freerdp_client_parse_command_line_arguments(int argc, char** argv, rdpSettin
|
||||
|
||||
flags = COMMAND_LINE_SIGIL_SLASH | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_SIGIL_PLUS_MINUS;
|
||||
|
||||
status = CommandLineParseArgumentsA(argc, (const char**) argv, args,
|
||||
flags, freerdp_client_command_line_filter, settings);
|
||||
status = CommandLineParseArgumentsA(argc, (const char**) argv, args, flags, settings,
|
||||
freerdp_client_command_line_pre_filter, freerdp_client_command_line_post_filter);
|
||||
|
||||
if (status == COMMAND_LINE_STATUS_PRINT_HELP)
|
||||
{
|
||||
|
@ -110,16 +110,19 @@ struct _COMMAND_LINE_ARGUMENT_W
|
||||
#define COMMAND_LINE_ARGUMENT COMMAND_LINE_ARGUMENT_A
|
||||
#endif
|
||||
|
||||
typedef int (*COMMAND_LINE_FILTER_FN_A)(int index, LPCSTR arg, void* context);
|
||||
typedef int (*COMMAND_LINE_FILTER_FN_W)(int index, LPCWSTR arg, void* context);
|
||||
typedef int (*COMMAND_LINE_PRE_FILTER_FN_A)(void* context, int index, LPCSTR arg);
|
||||
typedef int (*COMMAND_LINE_PRE_FILTER_FN_W)(void* context, int index, LPCWSTR arg);
|
||||
|
||||
typedef int (*COMMAND_LINE_POST_FILTER_FN_A)(void* context, COMMAND_LINE_ARGUMENT_A* arg);
|
||||
typedef int (*COMMAND_LINE_POST_FILTER_FN_W)(void* context, COMMAND_LINE_ARGUMENT_W* arg);
|
||||
|
||||
WINPR_API int CommandLineClearArgumentsA(COMMAND_LINE_ARGUMENT_A* 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, COMMAND_LINE_FILTER_FN_A filter, void* context);
|
||||
WINPR_API int CommandLineParseArgumentsW(int argc, LPCWSTR* argv, COMMAND_LINE_ARGUMENT_W* options,
|
||||
DWORD flags, COMMAND_LINE_FILTER_FN_W filter, void* context);
|
||||
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);
|
||||
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);
|
||||
|
||||
WINPR_API COMMAND_LINE_ARGUMENT_A* CommandLineFindArgumentA(COMMAND_LINE_ARGUMENT_A* options, LPCSTR Name);
|
||||
WINPR_API COMMAND_LINE_ARGUMENT_W* CommandLineFindArgumentW(COMMAND_LINE_ARGUMENT_W* options, LPCWSTR Name);
|
||||
|
@ -83,8 +83,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A* options,
|
||||
DWORD flags, COMMAND_LINE_FILTER_FN_A filter, void* context)
|
||||
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)
|
||||
{
|
||||
int i, j;
|
||||
int length;
|
||||
@ -104,8 +104,8 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
if (filter)
|
||||
filter(i, argv[i], context);
|
||||
if (preFilter)
|
||||
preFilter(context, i, argv[i]);
|
||||
|
||||
sigil_index = 0;
|
||||
sigil_length = 0;
|
||||
@ -227,6 +227,9 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
|
||||
}
|
||||
}
|
||||
|
||||
if (postFilter)
|
||||
postFilter(context, &options[j]);
|
||||
|
||||
if (options[j].Flags & COMMAND_LINE_PRINT)
|
||||
return COMMAND_LINE_STATUS_PRINT;
|
||||
else if (options[j].Flags & COMMAND_LINE_PRINT_HELP)
|
||||
@ -240,8 +243,8 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CommandLineParseArgumentsW(int argc, LPCWSTR* argv, COMMAND_LINE_ARGUMENT_W* options,
|
||||
DWORD flags, COMMAND_LINE_FILTER_FN_W filter, void* context)
|
||||
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)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ int TestCmdLine(int argc, char* argv[])
|
||||
COMMAND_LINE_ARGUMENT_A* arg;
|
||||
|
||||
flags = COMMAND_LINE_SIGIL_SLASH | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_SIGIL_PLUS_MINUS;
|
||||
status = CommandLineParseArgumentsA(testArgc, testArgv, args, flags, NULL, NULL);
|
||||
status = CommandLineParseArgumentsA(testArgc, testArgv, args, flags, NULL, NULL, NULL);
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user