reg: Simplify help handling by removing an if-else if-else block

Hugh McMaster hugh.mcmaster at outlook.com
Thu Aug 18 06:54:27 CDT 2016


This is in preparation for implementing 'import' and 'export' support.

Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
---
 programs/reg/reg.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/programs/reg/reg.c b/programs/reg/reg.c
index 6522fe6..0975acd 100644
--- a/programs/reg/reg.c
+++ b/programs/reg/reg.c
@@ -902,23 +902,32 @@ 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)
+static enum operations get_operation(const WCHAR *str, int *op_help)
 {
     if (!lstrcmpiW(str, addW))
+    {
+        *op_help = STRING_ADD_USAGE;
         return REG_ADD;
+    }
 
     if (!lstrcmpiW(str, deleteW))
+    {
+        *op_help = STRING_DELETE_USAGE;
         return REG_DELETE;
+    }
 
     if (!lstrcmpiW(str, queryW))
+    {
+        *op_help = STRING_QUERY_USAGE;
         return REG_QUERY;
+    }
 
     return REG_INVALID;
 }
 
 int wmain(int argc, WCHAR *argvW[])
 {
-    int i, op, ret;
+    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};
@@ -939,7 +948,7 @@ int wmain(int argc, WCHAR *argvW[])
         return 0;
     }
 
-    op = get_operation(argvW[1]);
+    op = get_operation(argvW[1], &op_help);
 
     if (op == REG_INVALID)
     {
@@ -959,12 +968,7 @@ int wmain(int argc, WCHAR *argvW[])
     }
     else if (show_op_help)
     {
-        if (op == REG_ADD)
-            output_message(STRING_ADD_USAGE);
-        else if (op == REG_DELETE)
-            output_message(STRING_DELETE_USAGE);
-        else
-            output_message(STRING_QUERY_USAGE);
+        output_message(op_help);
         return 0;
     }
 
-- 
2.7.4




More information about the wine-patches mailing list