[PATCH 3/3] reg: Recognise switches beginning with a forward slash or hyphen

Hugh McMaster hugh.mcmaster at outlook.com
Wed Jun 8 05:48:18 CDT 2016


Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
---
 programs/reg/reg.c       | 91 +++++++++++++++++++++++++++---------------------
 programs/reg/tests/reg.c |  8 ++---
 2 files changed, 56 insertions(+), 43 deletions(-)

diff --git a/programs/reg/reg.c b/programs/reg/reg.c
index 28133de..7d9c972 100644
--- a/programs/reg/reg.c
+++ b/programs/reg/reg.c
@@ -858,16 +858,11 @@ int wmain(int argc, WCHAR *argvW[])
 {
     int i, op, 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';
     BOOL value_empty = FALSE, value_all = FALSE, recurse = FALSE, force = FALSE;
     HKEY root;
-    static const WCHAR slashDW[] = {'/','d',0};
-    static const WCHAR slashFW[] = {'/','f',0};
-    static const WCHAR slashSW[] = {'/','s',0};
-    static const WCHAR slashTW[] = {'/','t',0};
-    static const WCHAR slashVW[] = {'/','v',0};
-    static const WCHAR slashVAW[] = {'/','v','a',0};
-    static const WCHAR slashVEW[] = {'/','v','e',0};
 
     if (argc == 1)
     {
@@ -928,54 +923,72 @@ int wmain(int argc, WCHAR *argvW[])
 
     for (i = 3; i < argc; i++)
     {
-        if (!lstrcmpiW(argvW[i], slashVW))
+        if (argvW[i][0] == '/' || argvW[i][0] == '-')
         {
-            if (value_name || !(value_name = argvW[++i]))
+            WCHAR *ptr = &argvW[i][1];
+
+            if (!lstrcmpiW(ptr, switchVEW))
             {
-                output_message(STRING_INVALID_CMDLINE);
-                return 1;
+                value_empty = TRUE;
+                continue;
             }
-        }
-        else if (!lstrcmpiW(argvW[i], slashVEW))
-            value_empty = TRUE;
-        else if (!lstrcmpiW(argvW[i], slashVAW))
-            value_all = TRUE;
-        else if (!lstrcmpiW(argvW[i], slashTW))
-        {
-            if (type || !(type = argvW[++i]))
+            else if (!lstrcmpiW(ptr, switchVAW))
             {
-                output_message(STRING_INVALID_CMDLINE);
-                return 1;
+                value_all = TRUE;
+                continue;
             }
-        }
-        else if (!lstrcmpiW(argvW[i], slashDW))
-        {
-            if (data || !(data = argvW[++i]))
+            else if (ptr[1])
             {
                 output_message(STRING_INVALID_CMDLINE);
                 return 1;
             }
-        }
-        else if (!lstrcmpiW(argvW[i], slashSW))
-        {
-            WCHAR *ptr;
 
-            if (op == REG_QUERY)
+            switch(tolowerW(argvW[i][1]))
             {
-                recurse = TRUE;
-                continue;
-            }
+            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':
+                if (op == REG_QUERY)
+                {
+                    recurse = TRUE;
+                    break;
+                }
 
-            ptr = argvW[++i];
-            if (!ptr || strlenW(ptr) != 1)
-            {
+                ptr = argvW[++i];
+                if (!ptr || strlenW(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;
             }
-            separator = ptr[0];
         }
-        else if (!lstrcmpiW(argvW[i], slashFW))
-            force = TRUE;
     }
 
     if ((value_name && value_empty) || (value_name && value_all) || (value_empty && value_all))
diff --git a/programs/reg/tests/reg.c b/programs/reg/tests/reg.c
index d34f19d..7556870 100644
--- a/programs/reg/tests/reg.c
+++ b/programs/reg/tests/reg.c
@@ -452,16 +452,16 @@ static void test_add(void)
 
     /* Test invalid switches */
     run_reg_exe("reg add HKCU\\" KEY_BASE " /v invalid1 /a", &r);
-    todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
+    ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
 
     run_reg_exe("reg add HKCU\\" KEY_BASE " /v invalid2 /ae", &r);
-    todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
+    ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
 
     run_reg_exe("reg add HKCU\\" KEY_BASE " /v invalid3 /", &r);
-    todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
+    ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
 
     run_reg_exe("reg add HKCU\\" KEY_BASE " /v invalid4 -", &r);
-    todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
+    ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
 
     err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
     ok(err == ERROR_SUCCESS, "got %d\n", err);
-- 
1.9.1




More information about the wine-patches mailing list