[PATCH 3/6] reg: Add wchar/type conversion functions

Jonathan Vollebregt jnvsor at gmail.com
Mon Oct 27 07:10:06 CDT 2014


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

diff --git a/programs/reg/reg.c b/programs/reg/reg.c
index d8e1c24..581ecb9 100755
--- a/programs/reg/reg.c
+++ b/programs/reg/reg.c
@@ -28,6 +28,11 @@ typedef struct {
     const WCHAR *long_name;
 } hkey_rel;
 
+typedef struct {
+    DWORD type;
+    const WCHAR *name;
+} type_rel;
+
 static const WCHAR short_hklm[] = {'H','K','L','M',0};
 static const WCHAR short_hkcu[] = {'H','K','C','U',0};
 static const WCHAR short_hkcr[] = {'H','K','C','R',0};
@@ -47,6 +52,38 @@ static const hkey_rel root_rels[] = {
     {HKEY_CURRENT_CONFIG, short_hkcc, long_hkcc},
 };
 
+static const WCHAR type_none[] = {'R','E','G','_','N','O','N','E',0};
+static const WCHAR type_sz[] = {'R','E','G','_','S','Z',0};
+static const WCHAR type_expand_sz[] = {'R','E','G','_','E','X','P','A','N','D','_','S','Z',0};
+static const WCHAR type_binary[] = {'R','E','G','_','B','I','N','A','R','Y',0};
+static const WCHAR type_dword[] = {'R','E','G','_','D','W','O','R','D',0};
+static const 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};
+static const WCHAR type_dword_be[] = {'R','E','G','_','D','W','O','R','D','_','B','I','G','_','E','N','D','I','A','N',0};
+static const WCHAR type_link[] = {'R','E','G','_','L','I','N','K',0};
+static const WCHAR type_multi_sz[] = {'R','E','G','_','M','U','L','T','I','_','S','Z',0};
+static const WCHAR type_resource_list[] = {'R','E','G','_','R','E','S','O','U','R','C','E','_','L','I','S','T',0};
+static const WCHAR type_full_resource_descriptor[] = {'R','E','G','_','F','U','L','L','_','R','E','S','O','U','R','C','E','_','D','E','S','C','R','I','P','T','O','R',0};
+static const WCHAR type_resource_requirements_list[] = {'R','E','G','_','R','E','S','O','U','R','C','E','_','R','E','Q','U','I','R','E','M','E','N','T','S','_','L','I','S','T',0};
+static const WCHAR type_qword[] = {'R','E','G','_','Q','W','O','R','D',0};
+static const WCHAR type_qword_le[] = {'R','E','G','_','Q','W','O','R','D','_','L','I','T','T','L','E','_','E','N','D','I','A','N',0};
+
+static const type_rel type_rels[] = {
+    {REG_NONE, type_none},
+    {REG_SZ, type_sz},
+    {REG_EXPAND_SZ, type_expand_sz},
+    {REG_BINARY, type_binary},
+    {REG_DWORD, type_dword},
+    {REG_DWORD_LITTLE_ENDIAN, type_dword_le},
+    {REG_DWORD_BIG_ENDIAN, type_dword_be},
+    {REG_LINK, type_link},
+    {REG_MULTI_SZ, type_multi_sz},
+    {REG_RESOURCE_LIST, type_resource_list},
+    {REG_FULL_RESOURCE_DESCRIPTOR, type_full_resource_descriptor},
+    {REG_RESOURCE_REQUIREMENTS_LIST, type_resource_requirements_list},
+    {REG_QWORD, type_qword},
+    {REG_QWORD_LITTLE_ENDIAN, type_qword_le},
+};
+
 static int reg_printfW(const WCHAR *msg, ...)
 {
     va_list va_args;
@@ -166,28 +203,15 @@ static HKEY path_get_key(const WCHAR *path)
     return k;
 }
 
-static DWORD get_regtype(LPWSTR type)
+static DWORD wchar_get_type(const WCHAR *type_name)
 {
-    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;
+
+    for (i = 0; i < ARRAY_COUNT(type_rels); i++)
+    {
+        if (strcmpiW(type_rels[i].name, type_name) == 0)
+            return type_rels[i].type;
+    }
 
     return -1;
 }
@@ -273,7 +297,11 @@ static int reg_add(WCHAR *key_name, WCHAR *value_name, BOOL value_empty,
             }
         }
 
-        reg_type = get_regtype(type);
+        if (!type)
+            reg_type = REG_SZ;
+        else
+            reg_type = wchar_get_type(type);
+
         if (reg_type == -1)
         {
             RegCloseKey(subkey);
-- 
2.1.1




More information about the wine-patches mailing list