[PATCH 1/6] reg: Use is_switch() where possible

Hugh McMaster hugh.mcmaster at outlook.com
Thu Mar 18 06:36:48 CDT 2021


Signed-off-by: Hugh McMaster <hugh.mcmaster at 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,
-- 
2.31.0




More information about the wine-devel mailing list