[PATCH 4/7] reg: Add wchar/type conversion functions
Jonathan Vollebregt
jnvsor at gmail.com
Tue Nov 4 14:15:11 CST 2014
---
programs/reg/reg.c | 90 +++++++++++++++++++++++++++++++++++++----------------
programs/reg/reg.h | 1 +
programs/reg/reg.rc | 1 +
3 files changed, 66 insertions(+), 26 deletions(-)
diff --git a/programs/reg/reg.c b/programs/reg/reg.c
index 453dbc4..7b7d297 100755
--- a/programs/reg/reg.c
+++ b/programs/reg/reg.c
@@ -23,6 +23,7 @@
#define ARRAY_SIZE(A) (sizeof(A)/sizeof(*A))
#define ERROR_NO_REMOTE 20000
+#define ERROR_INVALID_TYPE 20001
typedef struct
{
@@ -31,6 +32,12 @@ 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};
@@ -51,6 +58,39 @@ 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;
@@ -112,6 +152,8 @@ static int reg_print_error(LONG error_code)
return reg_message(STRING_INVALID_CMDLINE);
case ERROR_NO_REMOTE:
return reg_message(STRING_NO_REMOTE);
+ case ERROR_INVALID_TYPE:
+ return reg_message(STRING_INVALID_TYPE);
default:
{
static const WCHAR error_string[] = {'%','0','5','d',':',' ','%','s',0};
@@ -171,30 +213,26 @@ static LSTATUS path_get_key(const WCHAR *path, HKEY *out)
return ERROR_SUCCESS;
}
-static DWORD get_regtype(LPWSTR type)
+static LSTATUS wchar_get_type(const WCHAR *type_name, DWORD *out)
{
- 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;
-
- return -1;
+ DWORD i;
+
+ if (!type_name)
+ {
+ *out = REG_SZ;
+ return ERROR_SUCCESS;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(type_rels); i++)
+ {
+ if (!strcmpiW(type_rels[i].name, type_name))
+ {
+ *out = type_rels[i].type;
+ return ERROR_SUCCESS;
+ }
+ }
+
+ return ERROR_INVALID_TYPE;
}
static LPBYTE get_regdata(LPWSTR data, DWORD reg_type, WCHAR separator, DWORD *reg_count)
@@ -282,11 +320,11 @@ static int reg_add(WCHAR *key_name, WCHAR *value_name, BOOL value_empty,
}
}
- reg_type = get_regtype(type);
- if (reg_type == -1)
+ err = wchar_get_type(type, ®_type);
+ if (err != ERROR_SUCCESS)
{
RegCloseKey(subkey);
- reg_message(STRING_INVALID_CMDLINE);
+ reg_print_error(err);
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 74ef32e..9892b53 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, "Error: "
+ STRING_INVALID_TYPE, "Error: Invalid type\n"
}
--
2.1.1
More information about the wine-patches
mailing list