Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/export.c | 8 +------- programs/reg/reg.c | 7 ++----- programs/reg/reg.h | 1 + 3 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/programs/reg/export.c b/programs/reg/export.c index 4d8bf95be0b..3de57062b7f 100644 --- a/programs/reg/export.c +++ b/programs/reg/export.c @@ -361,13 +361,7 @@ static HANDLE get_file_handle(WCHAR *filename, BOOL overwrite_file)
static BOOL is_overwrite_switch(const WCHAR *s) { - if (lstrlenW(s) > 2) - return FALSE; - - if ((s[0] == '/' || s[0] == '-') && (s[1] == 'y' || s[1] == 'Y')) - return TRUE; - - return FALSE; + return is_switch(s, 'y'); }
int reg_export(int argc, WCHAR *argv[]) diff --git a/programs/reg/reg.c b/programs/reg/reg.c index 071fb6f88ea..dab77530cce 100644 --- a/programs/reg/reg.c +++ b/programs/reg/reg.c @@ -289,7 +289,7 @@ BOOL parse_registry_key(const WCHAR *key, HKEY *root, WCHAR **path, WCHAR **long return TRUE; }
-static BOOL is_switch(const WCHAR *s, const WCHAR c) +BOOL is_switch(const WCHAR *s, const WCHAR c) { if (lstrlenW(s) > 2) return FALSE; @@ -302,10 +302,7 @@ static BOOL is_switch(const WCHAR *s, const WCHAR c)
static BOOL is_help_switch(const WCHAR *s) { - if (is_switch(s, '?') || is_switch(s, 'h')) - return TRUE; - - return FALSE; + return (is_switch(s, '?') || is_switch(s, 'h')); }
enum operations { diff --git a/programs/reg/reg.h b/programs/reg/reg.h index b14470b2cbf..4cb31c4671a 100644 --- a/programs/reg/reg.h +++ b/programs/reg/reg.h @@ -40,6 +40,7 @@ BOOL ask_confirm(unsigned int msgid, WCHAR *reg_info); HKEY path_get_rootkey(const WCHAR *path); WCHAR *build_subkey_path(WCHAR *path, DWORD path_len, WCHAR *subkey_name, DWORD subkey_len); BOOL parse_registry_key(const WCHAR *key, HKEY *root, WCHAR **path, WCHAR **long_key); +BOOL is_switch(const WCHAR *s, const WCHAR c);
/* add.c */ int reg_add(HKEY root, WCHAR *path, WCHAR *value_name, BOOL value_empty,
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/add.c | 2 -- programs/reg/delete.c | 2 -- programs/reg/export.c | 4 ---- programs/reg/import.c | 6 +----- programs/reg/query.c | 2 -- programs/reg/reg.c | 4 +--- programs/reg/reg.h | 2 ++ 7 files changed, 4 insertions(+), 18 deletions(-)
diff --git a/programs/reg/add.c b/programs/reg/add.c index 2d8521f9234..054023df7ab 100644 --- a/programs/reg/add.c +++ b/programs/reg/add.c @@ -18,8 +18,6 @@
#include <errno.h> #include <stdlib.h> -#include <windows.h> -#include <wine/heap.h> #include "reg.h"
static DWORD wchar_get_type(const WCHAR *type_name) diff --git a/programs/reg/delete.c b/programs/reg/delete.c index 530d4513ece..e0730e5c12f 100644 --- a/programs/reg/delete.c +++ b/programs/reg/delete.c @@ -16,8 +16,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
-#include <windows.h> -#include <wine/heap.h> #include "reg.h"
int reg_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name, diff --git a/programs/reg/export.c b/programs/reg/export.c index 3de57062b7f..214c94b1368 100644 --- a/programs/reg/export.c +++ b/programs/reg/export.c @@ -16,12 +16,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
-#include <windows.h> #include <stdio.h> #include <stdlib.h> - -#include <wine/heap.h> - #include "reg.h"
static void write_file(HANDLE hFile, const WCHAR *str) diff --git a/programs/reg/import.c b/programs/reg/import.c index 7ad7b35d5dc..9e21bcc6a7e 100644 --- a/programs/reg/import.c +++ b/programs/reg/import.c @@ -16,15 +16,11 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
-#include <windows.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> - -#include <wine/debug.h> -#include <wine/heap.h> - #include "reg.h" +#include <wine/debug.h>
WINE_DEFAULT_DEBUG_CHANNEL(reg);
diff --git a/programs/reg/query.c b/programs/reg/query.c index 3d81d120bd2..b24edb2f0b2 100644 --- a/programs/reg/query.c +++ b/programs/reg/query.c @@ -17,8 +17,6 @@ */
#include <stdio.h> -#include <windows.h> -#include <wine/heap.h> #include "reg.h"
static const WCHAR *reg_type_to_wchar(DWORD type) diff --git a/programs/reg/reg.c b/programs/reg/reg.c index dab77530cce..354ece86f61 100644 --- a/programs/reg/reg.c +++ b/programs/reg/reg.c @@ -16,11 +16,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
-#include <windows.h> #include <stdlib.h> -#include <wine/debug.h> -#include <wine/heap.h> #include "reg.h" +#include <wine/debug.h>
WINE_DEFAULT_DEBUG_CHANNEL(reg);
diff --git a/programs/reg/reg.h b/programs/reg/reg.h index 4cb31c4671a..b29c2c21a1f 100644 --- a/programs/reg/reg.h +++ b/programs/reg/reg.h @@ -19,6 +19,8 @@ #ifndef __REG_H__ #define __REG_H__
+#include <windows.h> +#include <wine/heap.h> #include "resource.h"
#define MAX_SUBKEY_LEN 257
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/reg.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/programs/reg/reg.c b/programs/reg/reg.c index 354ece86f61..533a9378f92 100644 --- a/programs/reg/reg.c +++ b/programs/reg/reg.c @@ -349,7 +349,6 @@ static enum operations get_operation(const WCHAR *str, int *op_help) int __cdecl wmain(int argc, WCHAR *argvW[]) { int i, op, op_help, 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'; @@ -377,22 +376,26 @@ int __cdecl wmain(int argc, WCHAR *argvW[]) output_message(STRING_REG_HELP); return 1; } - - if (argc > 2) - show_op_help = is_help_switch(argvW[2]); - - if (argc == 2 || ((show_op_help || op == REG_IMPORT) && argc > 3)) + else if (argc == 2) /* Valid operation, no arguments supplied */ { output_message(STRING_INVALID_SYNTAX); output_message(STRING_FUNC_HELP, wcsupr(argvW[1])); return 1; } - else if (show_op_help) + + if (is_help_switch(argvW[2])) { output_message(op_help); return 0; }
+ if (op == REG_IMPORT && argc > 3) + { + output_message(STRING_INVALID_SYNTAX); + output_message(STRING_FUNC_HELP, wcsupr(argvW[1])); + return 1; + } + if (op == REG_IMPORT) return reg_import(argvW[2]);
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/import.c | 13 +++++++++++-- programs/reg/reg.c | 9 +-------- programs/reg/reg.h | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/programs/reg/import.c b/programs/reg/import.c index 9e21bcc6a7e..13e54e6a69a 100644 --- a/programs/reg/import.c +++ b/programs/reg/import.c @@ -983,13 +983,22 @@ cleanup: return NULL; }
-int reg_import(const WCHAR *filename) +int reg_import(int argc, WCHAR *argvW[]) { + WCHAR *filename, *pos; FILE *fp; static const WCHAR rb_mode[] = {'r','b',0}; BYTE s[2]; struct parser parser; - WCHAR *pos; + + if (argc > 3) + { + output_message(STRING_INVALID_SYNTAX); + output_message(STRING_FUNC_HELP, wcsupr(argvW[1])); + return 1; + } + + filename = argvW[2];
fp = _wfopen(filename, rb_mode); if (!fp) diff --git a/programs/reg/reg.c b/programs/reg/reg.c index 533a9378f92..daeec5f5718 100644 --- a/programs/reg/reg.c +++ b/programs/reg/reg.c @@ -389,15 +389,8 @@ int __cdecl wmain(int argc, WCHAR *argvW[]) return 0; }
- if (op == REG_IMPORT && argc > 3) - { - output_message(STRING_INVALID_SYNTAX); - output_message(STRING_FUNC_HELP, wcsupr(argvW[1])); - return 1; - } - if (op == REG_IMPORT) - return reg_import(argvW[2]); + return reg_import(argc, argvW);
if (op == REG_EXPORT) return reg_export(argc, argvW); diff --git a/programs/reg/reg.h b/programs/reg/reg.h index b29c2c21a1f..703dd0d37af 100644 --- a/programs/reg/reg.h +++ b/programs/reg/reg.h @@ -56,7 +56,7 @@ int reg_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name, int reg_export(int argc, WCHAR *argv[]);
/* import.c */ -int reg_import(const WCHAR *filename); +int reg_import(int argc, WCHAR *argvW[]);
/* query.c */ int reg_query(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name,
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/export.c | 10 +++++----- programs/reg/reg.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/programs/reg/export.c b/programs/reg/export.c index 214c94b1368..8ce1945a693 100644 --- a/programs/reg/export.c +++ b/programs/reg/export.c @@ -360,7 +360,7 @@ static BOOL is_overwrite_switch(const WCHAR *s) return is_switch(s, 'y'); }
-int reg_export(int argc, WCHAR *argv[]) +int reg_export(int argc, WCHAR *argvW[]) { HKEY root, hkey; WCHAR *path, *long_key; @@ -371,10 +371,10 @@ int reg_export(int argc, WCHAR *argv[]) if (argc == 3 || argc > 5) goto error;
- if (!parse_registry_key(argv[2], &root, &path, &long_key)) + if (!parse_registry_key(argvW[2], &root, &path, &long_key)) return 1;
- if (argc == 5 && !(overwrite_file = is_overwrite_switch(argv[4]))) + if (argc == 5 && !(overwrite_file = is_overwrite_switch(argvW[4]))) goto error;
if (RegOpenKeyExW(root, path, 0, KEY_READ, &hkey)) @@ -383,7 +383,7 @@ int reg_export(int argc, WCHAR *argv[]) return 1; }
- hFile = get_file_handle(argv[3], overwrite_file); + hFile = get_file_handle(argvW[3], overwrite_file); export_file_header(hFile); ret = export_registry_data(hFile, hkey, long_key); export_newline(hFile); @@ -395,6 +395,6 @@ int reg_export(int argc, WCHAR *argv[])
error: output_message(STRING_INVALID_SYNTAX); - output_message(STRING_FUNC_HELP, wcsupr(argv[1])); + output_message(STRING_FUNC_HELP, wcsupr(argvW[1])); return 1; } diff --git a/programs/reg/reg.h b/programs/reg/reg.h index 703dd0d37af..83bcf516297 100644 --- a/programs/reg/reg.h +++ b/programs/reg/reg.h @@ -53,7 +53,7 @@ int reg_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name, BOOL value_empty, BOOL value_all, BOOL force);
/* export.c */ -int reg_export(int argc, WCHAR *argv[]); +int reg_export(int argc, WCHAR *argvW[]);
/* import.c */ int reg_import(int argc, WCHAR *argvW[]);
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/reg.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/programs/reg/reg.c b/programs/reg/reg.c index daeec5f5718..309d855e996 100644 --- a/programs/reg/reg.c +++ b/programs/reg/reg.c @@ -306,8 +306,8 @@ static BOOL is_help_switch(const WCHAR *s) enum operations { REG_ADD, REG_DELETE, - REG_IMPORT, REG_EXPORT, + REG_IMPORT, REG_QUERY, REG_INVALID }; @@ -318,16 +318,16 @@ static enum operations get_operation(const WCHAR *str, int *op_help)
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 export[] = {'e','x','p','o','r','t',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[] = { { add, REG_ADD, STRING_ADD_USAGE }, { delete, REG_DELETE, STRING_DELETE_USAGE }, - { import, REG_IMPORT, STRING_IMPORT_USAGE }, { export, REG_EXPORT, STRING_EXPORT_USAGE }, + { import, REG_IMPORT, STRING_IMPORT_USAGE }, { query, REG_QUERY, STRING_QUERY_USAGE }, { NULL, -1, 0 } }; @@ -389,12 +389,12 @@ int __cdecl wmain(int argc, WCHAR *argvW[]) return 0; }
- if (op == REG_IMPORT) - return reg_import(argc, argvW); - if (op == REG_EXPORT) return reg_export(argc, argvW);
+ if (op == REG_IMPORT) + return reg_import(argc, argvW); + if (!parse_registry_key(argvW[2], &root, &path, &key_name)) return 1;