[PATCH 5/8] reg: Add wchar/type conversion functions

Jonathan Vollebregt jnvsor at gmail.com
Thu Nov 6 15:17:39 CST 2014


---
 programs/reg/reg.c  | 72 +++++++++++++++++++++++++++++++++++++----------------
 programs/reg/reg.h  |  1 +
 programs/reg/reg.rc |  1 +
 3 files changed, 53 insertions(+), 21 deletions(-)

diff --git a/programs/reg/reg.c b/programs/reg/reg.c
index f6d4bbc..facd241 100755
--- a/programs/reg/reg.c
+++ b/programs/reg/reg.c
@@ -50,6 +50,44 @@ 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 struct
+{
+    DWORD type;
+    const WCHAR *name;
+}
+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;
@@ -111,6 +149,8 @@ static int reg_print_error(LSTATUS error_code)
             return reg_message(STRING_NO_REMOTE);
         case ERROR_FILE_NOT_FOUND:
             return reg_message(STRING_CANNOT_FIND);
+        case ERROR_INVALID_DATATYPE:
+            return reg_message(STRING_INVALID_TYPE);
         default:
         {
             static const WCHAR error_string[] = {'%','0','5','d',':',' ','%','s',0};
@@ -162,28 +202,18 @@ static LSTATUS path_open(const WCHAR *path, HKEY *out, BOOL create)
         return RegOpenKeyW(*out, path, out);
 }
 
-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)
+    DWORD i;
+
+    if (!type_name)
         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;
+    for (i = 0; i < ARRAY_SIZE(type_rels); i++)
+    {
+        if (!strcmpiW(type_rels[i].name, type_name))
+            return type_rels[i].type;
+    }
 
     return -1;
 }
@@ -278,11 +308,11 @@ 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(subkey);
-            reg_message(STRING_INVALID_CMDLINE);
+            reg_print_error(ERROR_INVALID_DATATYPE);
             return 1;
         }
 
diff --git a/programs/reg/reg.h b/programs/reg/reg.h
index 1c2ae83..d49d3d8 100644
--- a/programs/reg/reg.h
+++ b/programs/reg/reg.h
@@ -31,3 +31,4 @@
 #define STRING_NO_REMOTE        108
 #define STRING_CANNOT_FIND      109
 #define STRING_ERROR            110
+#define STRING_INVALID_TYPE     111
diff --git a/programs/reg/reg.rc b/programs/reg/reg.rc
index 5fc5a76..1c19375 100644
--- a/programs/reg/reg.rc
+++ b/programs/reg/reg.rc
@@ -36,4 +36,5 @@ STRINGTABLE
     STRING_NO_REMOTE, "Error: Unable to access remote machine\n"
     STRING_CANNOT_FIND, "Error: The system was unable to find the specified registry key or value\n"
     STRING_ERROR, "Unexpected error: "
+    STRING_INVALID_TYPE, "Error: Invalid type\n"
 }
-- 
2.1.1




More information about the wine-patches mailing list