[PATCH 3/5] reg.exe: Add wchar/type conversion functions
Jonathan Vollebregt
jnvsor at gmail.com
Mon Sep 1 08:05:32 CDT 2014
---
programs/reg/reg.c | 64 +++++++++++++++++++++++++++++++++++-------------------
1 file changed, 42 insertions(+), 22 deletions(-)
diff --git a/programs/reg/reg.c b/programs/reg/reg.c
index c57caa5..dcf6a91 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 32
static const WCHAR short_HKEY_name[][5] = {
{'H','K','L','M',0},
@@ -46,6 +47,19 @@ 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},
+ {0},
+ {'R','E','G','_','M','U','L','T','I','_','S','Z',0},
+};
+
+
+
static int reg_printfW(const WCHAR *msg, ...)
{
va_list va_args;
@@ -159,28 +173,34 @@ static HKEY path_get_key(LPWSTR 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][0];
+ }
+ else
+ {
+ return &type_names[REG_NONE][0];
+ }
+}
+
+static DWORD wchar_get_type(LPWSTR 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]) == 0)
+ {
+ return i;
+ }
+ }
return -1;
}
@@ -248,7 +268,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