reg: Recognise switches beginning with a forward slash or hyphen.

Signed-off-by: Hugh McMaster <hugh.mcmaster@outlook.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hugh McMaster 2016-06-08 10:48:18 +00:00 committed by Alexandre Julliard
parent 57c39cf2b6
commit f426ece3a1
2 changed files with 62 additions and 49 deletions

View File

@ -858,16 +858,11 @@ int wmain(int argc, WCHAR *argvW[])
{
int i, op, ret;
BOOL show_op_help = FALSE;
static const WCHAR switchVAW[] = {'v','a',0};
static const WCHAR switchVEW[] = {'v','e',0};
WCHAR *key_name, *path, *value_name = NULL, *type = NULL, *data = NULL, separator = '\0';
BOOL value_empty = FALSE, value_all = FALSE, recurse = FALSE, force = FALSE;
HKEY root;
static const WCHAR slashDW[] = {'/','d',0};
static const WCHAR slashFW[] = {'/','f',0};
static const WCHAR slashSW[] = {'/','s',0};
static const WCHAR slashTW[] = {'/','t',0};
static const WCHAR slashVW[] = {'/','v',0};
static const WCHAR slashVAW[] = {'/','v','a',0};
static const WCHAR slashVEW[] = {'/','v','e',0};
if (argc == 1)
{
@ -928,54 +923,72 @@ int wmain(int argc, WCHAR *argvW[])
for (i = 3; i < argc; i++)
{
if (!lstrcmpiW(argvW[i], slashVW))
if (argvW[i][0] == '/' || argvW[i][0] == '-')
{
if (value_name || !(value_name = argvW[++i]))
{
output_message(STRING_INVALID_CMDLINE);
return 1;
}
}
else if (!lstrcmpiW(argvW[i], slashVEW))
value_empty = TRUE;
else if (!lstrcmpiW(argvW[i], slashVAW))
value_all = TRUE;
else if (!lstrcmpiW(argvW[i], slashTW))
{
if (type || !(type = argvW[++i]))
{
output_message(STRING_INVALID_CMDLINE);
return 1;
}
}
else if (!lstrcmpiW(argvW[i], slashDW))
{
if (data || !(data = argvW[++i]))
{
output_message(STRING_INVALID_CMDLINE);
return 1;
}
}
else if (!lstrcmpiW(argvW[i], slashSW))
{
WCHAR *ptr;
WCHAR *ptr = &argvW[i][1];
if (op == REG_QUERY)
if (!lstrcmpiW(ptr, switchVEW))
{
recurse = TRUE;
value_empty = TRUE;
continue;
}
ptr = argvW[++i];
if (!ptr || strlenW(ptr) != 1)
else if (!lstrcmpiW(ptr, switchVAW))
{
value_all = TRUE;
continue;
}
else if (ptr[1])
{
output_message(STRING_INVALID_CMDLINE);
return 1;
}
separator = ptr[0];
switch(tolowerW(argvW[i][1]))
{
case 'v':
if (value_name || !(value_name = argvW[++i]))
{
output_message(STRING_INVALID_CMDLINE);
return 1;
}
break;
case 't':
if (type || !(type = argvW[++i]))
{
output_message(STRING_INVALID_CMDLINE);
return 1;
}
break;
case 'd':
if (data || !(data = argvW[++i]))
{
output_message(STRING_INVALID_CMDLINE);
return 1;
}
break;
case 's':
if (op == REG_QUERY)
{
recurse = TRUE;
break;
}
ptr = argvW[++i];
if (!ptr || strlenW(ptr) != 1)
{
output_message(STRING_INVALID_CMDLINE);
return 1;
}
separator = ptr[0];
break;
case 'f':
force = TRUE;
break;
default:
output_message(STRING_INVALID_CMDLINE);
return 1;
}
}
else if (!lstrcmpiW(argvW[i], slashFW))
force = TRUE;
}
if ((value_name && value_empty) || (value_name && value_all) || (value_empty && value_all))

View File

@ -452,16 +452,16 @@ static void test_add(void)
/* Test invalid switches */
run_reg_exe("reg add HKCU\\" KEY_BASE " /v invalid1 /a", &r);
todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
run_reg_exe("reg add HKCU\\" KEY_BASE " /v invalid2 /ae", &r);
todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
run_reg_exe("reg add HKCU\\" KEY_BASE " /v invalid3 /", &r);
todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
run_reg_exe("reg add HKCU\\" KEY_BASE " /v invalid4 -", &r);
todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
ok(err == ERROR_SUCCESS, "got %d\n", err);