[PATCH 03/13] reg: Add initial support for the import operation
Hugh McMaster
hugh.mcmaster at outlook.com
Fri Aug 18 04:29:54 CDT 2017
Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
---
programs/reg/Makefile.in | 4 +++-
programs/reg/import.c | 30 ++++++++++++++++++++++++++++++
programs/reg/reg.c | 45 +++++++++++++++++++++++++++------------------
programs/reg/reg.h | 26 ++++++++++++++++++++++++++
programs/reg/reg.rc | 3 ++-
programs/reg/resource.h | 1 +
programs/reg/tests/reg.c | 2 +-
7 files changed, 90 insertions(+), 21 deletions(-)
create mode 100644 programs/reg/import.c
create mode 100644 programs/reg/reg.h
diff --git a/programs/reg/Makefile.in b/programs/reg/Makefile.in
index 7a70a33a69..ef5f45298c 100644
--- a/programs/reg/Makefile.in
+++ b/programs/reg/Makefile.in
@@ -3,6 +3,8 @@ APPMODE = -mconsole -municode -mno-cygwin
IMPORTS = advapi32
DELAYIMPORTS = user32
-C_SRCS = reg.c
+C_SRCS = \
+ import.c \
+ reg.c
RC_SRCS = reg.rc
diff --git a/programs/reg/import.c b/programs/reg/import.c
new file mode 100644
index 0000000000..734e6ae94c
--- /dev/null
+++ b/programs/reg/import.c
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2017 Hugh McMaster
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <windows.h>
+#include <wine/debug.h>
+
+#include "reg.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(reg);
+
+int reg_import(const WCHAR *filename)
+{
+ FIXME(": operation not yet implemented\n");
+ return 1;
+}
diff --git a/programs/reg/reg.c b/programs/reg/reg.c
index 595dcab8e7..43e5321704 100644
--- a/programs/reg/reg.c
+++ b/programs/reg/reg.c
@@ -21,7 +21,7 @@
#include <stdlib.h>
#include <wine/unicode.h>
#include <wine/debug.h>
-#include "resource.h"
+#include "reg.h"
#define ARRAY_SIZE(A) (sizeof(A)/sizeof(*A))
@@ -909,32 +909,38 @@ static BOOL is_help_switch(const WCHAR *s)
enum operations {
REG_ADD,
REG_DELETE,
+ REG_IMPORT,
REG_QUERY,
REG_INVALID
};
-static const WCHAR addW[] = {'a','d','d',0};
-static const WCHAR deleteW[] = {'d','e','l','e','t','e',0};
-static const WCHAR queryW[] = {'q','u','e','r','y',0};
-
static enum operations get_operation(const WCHAR *str, int *op_help)
{
- if (!lstrcmpiW(str, addW))
- {
- *op_help = STRING_ADD_USAGE;
- return REG_ADD;
- }
+ struct op_info { const WCHAR *op; int id; int help_id; };
- if (!lstrcmpiW(str, deleteW))
+ static const WCHAR add[] = {'a','d','d',0};
+ static const WCHAR delete[] = {'d','e','l','e','t','e',0};
+ static const WCHAR import[] = {'i','m','p','o','r','t',0};
+ static const WCHAR query[] = {'q','u','e','r','y',0};
+
+ static const struct op_info op_array[] =
{
- *op_help = STRING_DELETE_USAGE;
- return REG_DELETE;
- }
+ { add, REG_ADD, STRING_ADD_USAGE },
+ { delete, REG_DELETE, STRING_DELETE_USAGE },
+ { import, REG_IMPORT, STRING_IMPORT_USAGE },
+ { query, REG_QUERY, STRING_QUERY_USAGE },
+ { NULL, -1, 0 }
+ };
- if (!lstrcmpiW(str, queryW))
+ const struct op_info *ptr;
+
+ for (ptr = op_array; ptr->op; ptr++)
{
- *op_help = STRING_QUERY_USAGE;
- return REG_QUERY;
+ if (!lstrcmpiW(str, ptr->op))
+ {
+ *op_help = ptr->help_id;
+ return ptr->id;
+ }
}
return REG_INVALID;
@@ -975,7 +981,7 @@ int wmain(int argc, WCHAR *argvW[])
if (argc > 2)
show_op_help = is_help_switch(argvW[2]);
- if (argc == 2 || (show_op_help && argc > 3))
+ if (argc == 2 || ((show_op_help || op == REG_IMPORT) && argc > 3))
{
output_message(STRING_INVALID_SYNTAX);
output_message(STRING_FUNC_HELP, struprW(argvW[1]));
@@ -987,6 +993,9 @@ int wmain(int argc, WCHAR *argvW[])
return 0;
}
+ if (op == REG_IMPORT)
+ return reg_import(argvW[2]);
+
if (!parse_registry_key(argvW[2], &root, &path, &key_name))
return 1;
diff --git a/programs/reg/reg.h b/programs/reg/reg.h
new file mode 100644
index 0000000000..1fbef7806c
--- /dev/null
+++ b/programs/reg/reg.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2017 Hugh McMaster
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef __REG_H__
+#define __REG_H__
+
+#include "resource.h"
+
+int reg_import(const WCHAR *filename);
+
+#endif /* __REG_H__ */
diff --git a/programs/reg/reg.rc b/programs/reg/reg.rc
index 2e0da68534..e26970916f 100644
--- a/programs/reg/reg.rc
+++ b/programs/reg/reg.rc
@@ -29,7 +29,7 @@ STRINGTABLE
STRING_USAGE, "Usage:\n\
\ REG [operation] [parameters]\n\n\
\Supported operations:\n\
-\ ADD | DELETE | QUERY\n\n\
+\ ADD | DELETE | IMPORT | QUERY\n\n\
\For help on a specific operation, type:\n\
\ REG [operation] /?\n\n"
STRING_ADD_USAGE, "REG ADD key_name [/v value_name | /ve] [/t type] [/s separator] [/d data] [/f]\n"
@@ -62,4 +62,5 @@ STRINGTABLE
STRING_REG_HELP, "Type \"REG /?\" for help.\n"
STRING_FUNC_HELP, "Type \"REG %1 /?\" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
+ STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
}
diff --git a/programs/reg/resource.h b/programs/reg/resource.h
index 1142278a19..31a83ee115 100644
--- a/programs/reg/resource.h
+++ b/programs/reg/resource.h
@@ -52,3 +52,4 @@
#define STRING_REG_HELP 129
#define STRING_FUNC_HELP 130
#define STRING_VALUE_NOT_SET 131
+#define STRING_IMPORT_USAGE 132
diff --git a/programs/reg/tests/reg.c b/programs/reg/tests/reg.c
index a2728cad58..69c01c00b9 100644
--- a/programs/reg/tests/reg.c
+++ b/programs/reg/tests/reg.c
@@ -801,7 +801,7 @@ static void test_import(void)
ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
run_reg_exe("reg import /?", &r);
- todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+ ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
run_reg_exe("reg import missing.reg", &r);
ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
--
2.14.1
More information about the wine-patches
mailing list