reg: Parse 'reg delete' command-line arguments in delete.c.

Signed-off-by: Hugh McMaster <hugh.mcmaster@outlook.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hugh McMaster 2021-03-30 23:00:12 +11:00 committed by Alexandre Julliard
parent 62f96b0397
commit 434c345e41
3 changed files with 67 additions and 19 deletions

View File

@ -18,8 +18,8 @@
#include "reg.h"
int reg_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name,
BOOL value_empty, BOOL value_all, BOOL force)
static int run_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name,
BOOL value_empty, BOOL value_all, BOOL force)
{
HKEY key;
@ -105,3 +105,60 @@ int reg_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name,
output_message(STRING_SUCCESS);
return 0;
}
int reg_delete(int argc, WCHAR *argvW[])
{
HKEY root;
WCHAR *path, *key_name, *value_name = NULL;
BOOL value_all = FALSE, value_empty = FALSE, force = FALSE;
int i;
if (!parse_registry_key(argvW[2], &root, &path, &key_name))
return 1;
for (i = 3; i < argc; i++)
{
if (argvW[i][0] == '/' || argvW[i][0] == '-')
{
WCHAR *str = &argvW[i][1];
if (!lstrcmpiW(str, L"va"))
{
if (value_all) goto invalid;
value_all = TRUE;
continue;
}
else if (!lstrcmpiW(str, L"ve"))
{
if (value_empty) goto invalid;
value_empty = TRUE;
continue;
}
else if (!str[0] || str[1])
goto invalid;
switch (towlower(*str))
{
case 'v':
if (value_name || !(value_name = argvW[++i]))
goto invalid;
break;
case 'f':
if (force) goto invalid;
force = TRUE;
break;
default:
goto invalid;
}
}
}
if ((value_name && value_empty) || (value_name && value_all) || (value_empty && value_all))
goto invalid;
return run_delete(root, path, key_name, value_name, value_empty, value_all, force);
invalid:
output_message(STRING_INVALID_CMDLINE);
return 1;
}

View File

@ -333,11 +333,10 @@ static enum operations get_operation(const WCHAR *str, int *op_help)
int __cdecl wmain(int argc, WCHAR *argvW[])
{
int i, op, op_help, ret;
static const WCHAR switchVAW[] = {'v','a',0};
int i, op, op_help;
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, force = FALSE;
BOOL value_empty = FALSE, force = FALSE;
HKEY root;
if (argc == 1)
@ -374,6 +373,9 @@ int __cdecl wmain(int argc, WCHAR *argvW[])
return 0;
}
if (op == REG_DELETE)
return reg_delete(argc, argvW);
if (op == REG_EXPORT)
return reg_export(argc, argvW);
@ -397,11 +399,6 @@ int __cdecl wmain(int argc, WCHAR *argvW[])
value_empty = TRUE;
continue;
}
else if (!lstrcmpiW(ptr, switchVAW))
{
value_all = TRUE;
continue;
}
else if (!ptr[0] || ptr[1])
{
output_message(STRING_INVALID_CMDLINE);
@ -450,16 +447,11 @@ int __cdecl wmain(int argc, WCHAR *argvW[])
}
}
if ((value_name && value_empty) || (value_name && value_all) || (value_empty && value_all))
if (value_name && value_empty)
{
output_message(STRING_INVALID_CMDLINE);
return 1;
}
if (op == REG_ADD)
ret = reg_add(root, path, value_name, value_empty, type, separator, data, force);
else
ret = reg_delete(root, path, key_name, value_name, value_empty, value_all, force);
return ret;
return reg_add(root, path, value_name, value_empty, type, separator, data, force);
}

View File

@ -47,8 +47,7 @@ int reg_add(HKEY root, WCHAR *path, WCHAR *value_name, BOOL value_empty,
WCHAR *type, WCHAR separator, WCHAR *data, BOOL force);
/* delete.c */
int reg_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name,
BOOL value_empty, BOOL value_all, BOOL force);
int reg_delete(int argc, WCHAR *argvW[]);
/* export.c */
int reg_export(int argc, WCHAR *argvW[]);