[PATCH 2/4] reg.exe: Add wchar/type conversion functions

Jonathan Vollebregt jnvsor at gmail.com
Wed Sep 3 07:54:45 CDT 2014


---
 programs/reg/reg.c | 55 ++++++++++++++++++++++++++++++++----------------------
 1 file changed, 33 insertions(+), 22 deletions(-)

diff --git a/programs/reg/reg.c b/programs/reg/reg.c
index 56aa618..c688f6d 100644
--- a/programs/reg/reg.c
+++ b/programs/reg/reg.c
@@ -21,6 +21,7 @@
 #include "reg.h"
 
 #define MAX_ROOT_KEY_NAME_LENGTH 20
+#define MAX_TYPE_LENGTH 21
 
 static const WCHAR short_HKEY_name[][5] = {
     {'H','K','L','M',0},
@@ -46,6 +47,17 @@ static const HKEY HKEYs[] = {
     HKEY_CURRENT_CONFIG,
 };
 
+static const WCHAR type_names[][MAX_TYPE_LENGTH] = {
+    {'R','E','G','_','N','O','N','E',0},
+    {'R','E','G','_','S','Z',0},
+    {'R','E','G','_','E','X','P','A','N','D','_','S','Z',0},
+    {'R','E','G','_','B','I','N','A','R','Y',0},
+    {'R','E','G','_','D','W','O','R','D',0},
+    {'R','E','G','_','D','W','O','R','D','_','B','I','G','_','E','N','D','I','A','N',0},
+    {'R','E','G','_','L','I','N','K',0},
+    {'R','E','G','_','M','U','L','T','I','_','S','Z',0},
+};
+
 static int reg_printfW(const WCHAR *msg, ...)
 {
     va_list va_args;
@@ -171,28 +183,27 @@ static HKEY path_get_key(WCHAR *path)
     return out;
 }
 
-static DWORD get_regtype(LPWSTR type)
+static const WCHAR *type_get_wchar(const DWORD type)
+{
+    if(type_names[type][0])
+        return type_names[type];
+    else
+        return type_names[REG_NONE];
+}
+
+static DWORD wchar_get_type(WCHAR *type)
 {
-    static const WCHAR szREG_SZ[] = {'R','E','G','_','S','Z',0};
-    static const WCHAR szREG_MULTI_SZ[] = {'R','E','G','_','M','U','L','T','I','_','S','Z',0};
-    static const WCHAR szREG_DWORD_BIG_ENDIAN[] = {'R','E','G','_','D','W','O','R','D','_','B','I','G','_','E','N','D','I','A','N',0};
-    static const WCHAR szREG_DWORD[] = {'R','E','G','_','D','W','O','R','D',0};
-    static const WCHAR szREG_BINARY[] = {'R','E','G','_','B','I','N','A','R','Y',0};
-    static const WCHAR szREG_DWORD_LITTLE_ENDIAN[] = {'R','E','G','_','D','W','O','R','D','_','L','I','T','T','L','E','_','E','N','D','I','A','N',0};
-    static const WCHAR szREG_NONE[] = {'R','E','G','_','N','O','N','E',0};
-    static const WCHAR szREG_EXPAND_SZ[] = {'R','E','G','_','E','X','P','A','N','D','_','S','Z',0};
-
-    if (!type)
-        return REG_SZ;
-
-    if (lstrcmpiW(type,szREG_SZ)==0) return REG_SZ;
-    if (lstrcmpiW(type,szREG_DWORD)==0) return REG_DWORD;
-    if (lstrcmpiW(type,szREG_MULTI_SZ)==0) return REG_MULTI_SZ;
-    if (lstrcmpiW(type,szREG_EXPAND_SZ)==0) return REG_EXPAND_SZ;
-    if (lstrcmpiW(type,szREG_DWORD_BIG_ENDIAN)==0) return REG_DWORD_BIG_ENDIAN;
-    if (lstrcmpiW(type,szREG_DWORD_LITTLE_ENDIAN)==0) return REG_DWORD_LITTLE_ENDIAN;
-    if (lstrcmpiW(type,szREG_BINARY)==0) return REG_BINARY;
-    if (lstrcmpiW(type,szREG_NONE)==0) return REG_NONE;
+    DWORD i;
+    WCHAR type_dword_le[] = {'R','E','G','_','D','W','O','R','D','_','L','I','T','T','L','E','_','E','N','D','I','A','N',0};
+
+    if (lstrcmpiW(type, type_dword_le) == 0)
+        return REG_DWORD_LITTLE_ENDIAN;
+
+    for (i = 0; i < 8; i++)
+    {
+        if (lstrcmpiW(type, type_names[i]) == 0)
+            return i;
+    }
 
     return -1;
 }
@@ -260,7 +271,7 @@ static int reg_add(WCHAR *key_name, WCHAR *value_name, BOOL value_empty,
             }
         }
 
-        reg_type = get_regtype(type);
+        reg_type = wchar_get_type(type);
         if (reg_type == -1)
         {
             RegCloseKey(key);
-- 
2.1.0




More information about the wine-patches mailing list