Commit 9138f589 authored by Hugh McMaster's avatar Hugh McMaster Committed by Alexandre Julliard

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

parent 434c345e
......@@ -149,8 +149,8 @@ static LPBYTE get_regdata(const WCHAR *data, DWORD reg_type, WCHAR separator, DW
return out_data;
}
int reg_add(HKEY root, WCHAR *path, WCHAR *value_name, BOOL value_empty,
WCHAR *type, WCHAR separator, WCHAR *data, BOOL force)
static int run_add(HKEY root, WCHAR *path, WCHAR *value_name, BOOL value_empty,
WCHAR *type, WCHAR separator, WCHAR *data, BOOL force)
{
HKEY key;
......@@ -208,3 +208,66 @@ int reg_add(HKEY root, WCHAR *path, WCHAR *value_name, BOOL value_empty,
return 0;
}
int reg_add(int argc, WCHAR *argvW[])
{
HKEY root;
WCHAR *path, *key_name, *value_name = NULL, *type = NULL, *data = NULL, separator = '\0';
BOOL 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"ve"))
{
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 't':
if (type || !(type = argvW[++i]))
goto invalid;
break;
case 'd':
if (data || !(data = argvW[++i]))
goto invalid;
break;
case 's':
str = argvW[++i];
if (!str || lstrlenW(str) != 1)
goto invalid;
separator = str[0];
break;
case 'f':
force = TRUE;
break;
default:
goto invalid;
}
}
}
if (value_name && value_empty)
goto invalid;
return run_add(root, path, value_name, value_empty, type, separator, data, force);
invalid:
output_message(STRING_INVALID_CMDLINE);
return 1;
}
......@@ -333,11 +333,7 @@ static enum operations get_operation(const WCHAR *str, int *op_help)
int __cdecl wmain(int argc, WCHAR *argvW[])
{
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, force = FALSE;
HKEY root;
int op, op_help;
if (argc == 1)
{
......@@ -373,6 +369,9 @@ int __cdecl wmain(int argc, WCHAR *argvW[])
return 0;
}
if (op == REG_ADD)
return reg_add(argc, argvW);
if (op == REG_DELETE)
return reg_delete(argc, argvW);
......@@ -382,76 +381,5 @@ int __cdecl wmain(int argc, WCHAR *argvW[])
if (op == REG_IMPORT)
return reg_import(argc, argvW);
if (op == REG_QUERY)
return reg_query(argc, argvW);
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 *ptr = &argvW[i][1];
if (!lstrcmpiW(ptr, switchVEW))
{
value_empty = TRUE;
continue;
}
else if (!ptr[0] || ptr[1])
{
output_message(STRING_INVALID_CMDLINE);
return 1;
}
switch(towlower(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':
ptr = argvW[++i];
if (!ptr || lstrlenW(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;
}
}
}
if (value_name && value_empty)
{
output_message(STRING_INVALID_CMDLINE);
return 1;
}
return reg_add(root, path, value_name, value_empty, type, separator, data, force);
return reg_query(argc, argvW);
}
......@@ -43,8 +43,7 @@ BOOL parse_registry_key(const WCHAR *key, HKEY *root, WCHAR **path, WCHAR **long
BOOL is_switch(const WCHAR *s, const WCHAR c);
/* add.c */
int reg_add(HKEY root, WCHAR *path, WCHAR *value_name, BOOL value_empty,
WCHAR *type, WCHAR separator, WCHAR *data, BOOL force);
int reg_add(int arc, WCHAR *argvW[]);
/* delete.c */
int reg_delete(int argc, WCHAR *argvW[]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment