Hugh McMaster : reg: Use wide-char string literals.

Alexandre Julliard julliard at winehq.org
Tue Mar 30 15:19:51 CDT 2021


Module: wine
Branch: master
Commit: 0c73f95b336ba2ae4b49fa7f652c622ce47038c5
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=0c73f95b336ba2ae4b49fa7f652c622ce47038c5

Author: Hugh McMaster <hugh.mcmaster at outlook.com>
Date:   Tue Mar 30 23:00:16 2021 +1100

reg: Use wide-char string literals.

Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 programs/reg/query.c | 18 ++++++--------
 programs/reg/reg.c   | 68 ++++++++++++++++------------------------------------
 2 files changed, 27 insertions(+), 59 deletions(-)

diff --git a/programs/reg/query.c b/programs/reg/query.c
index c8277cd7114..961d926a10b 100644
--- a/programs/reg/query.c
+++ b/programs/reg/query.c
@@ -48,12 +48,11 @@ static WCHAR *reg_data_to_wchar(DWORD type, const BYTE *src, DWORD size_bytes)
         case REG_BINARY:
         {
             WCHAR *ptr;
-            static const WCHAR fmt[] = {'%','0','2','X',0};
 
             buffer = malloc((size_bytes * 2 + 1) * sizeof(WCHAR));
             ptr = buffer;
             for (i = 0; i < size_bytes; i++)
-                ptr += swprintf(ptr, 3, fmt, src[i]);
+                ptr += swprintf(ptr, 3, L"%02X", src[i]);
             break;
         }
         case REG_DWORD:
@@ -61,10 +60,9 @@ static WCHAR *reg_data_to_wchar(DWORD type, const BYTE *src, DWORD size_bytes)
         case REG_DWORD_BIG_ENDIAN:
         {
             const int zero_x_dword = 10;
-            static const WCHAR fmt[] = {'0','x','%','x',0};
 
             buffer = malloc((zero_x_dword + 1) * sizeof(WCHAR));
-            swprintf(buffer, zero_x_dword + 1, fmt, *(DWORD *)src);
+            swprintf(buffer, zero_x_dword + 1, L"0x%x", *(DWORD *)src);
             break;
         }
         case REG_MULTI_SZ:
@@ -102,11 +100,11 @@ static WCHAR *reg_data_to_wchar(DWORD type, const BYTE *src, DWORD size_bytes)
     return buffer;
 }
 
-static const WCHAR newlineW[] = {'\n',0};
+static const WCHAR *newlineW = L"\n";
 
 static void output_value(const WCHAR *value_name, DWORD type, BYTE *data, DWORD data_size)
 {
-    static const WCHAR fmt[] = {' ',' ',' ',' ','%','1',0};
+    static const WCHAR *fmt = L"    %1";
     WCHAR defval[32];
     WCHAR *reg_data;
 
@@ -142,7 +140,7 @@ static int query_value(HKEY key, WCHAR *value_name, WCHAR *path, BOOL recurse)
     DWORD subkey_len;
     DWORD type, path_len, i;
     BYTE *data;
-    WCHAR fmt[] = {'%','1','\n',0};
+    static const WCHAR *fmt = L"%1\n";
     WCHAR *subkey_name, *subkey_path;
     HKEY subkey;
 
@@ -219,13 +217,11 @@ static int query_all(HKEY key, WCHAR *path, BOOL recurse)
     DWORD max_data_bytes = 2048, data_size;
     DWORD subkey_len;
     DWORD i, type, path_len;
-    WCHAR fmt[] = {'%','1','\n',0};
-    WCHAR fmt_path[] = {'%','1','\\','%','2','\n',0};
     WCHAR *value_name, *subkey_name, *subkey_path;
     BYTE *data;
     HKEY subkey;
 
-    output_string(fmt, path);
+    output_string(L"%1\n", path);
 
     value_name = malloc(max_value_len * sizeof(WCHAR));
     data = malloc(max_data_bytes);
@@ -284,7 +280,7 @@ static int query_all(HKEY key, WCHAR *path, BOOL recurse)
                 }
                 free(subkey_path);
             }
-            else output_string(fmt_path, path, subkey_name);
+            else output_string(L"%1\\%2\n", path, subkey_name);
             i++;
         }
         else break;
diff --git a/programs/reg/reg.c b/programs/reg/reg.c
index e419799676f..10aaabf92da 100644
--- a/programs/reg/reg.c
+++ b/programs/reg/reg.c
@@ -21,17 +21,6 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(reg);
 
-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};
-static const WCHAR short_hku[] = {'H','K','U',0};
-static const WCHAR short_hkcc[] = {'H','K','C','C',0};
-static const WCHAR long_hklm[] = {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',0};
-static const WCHAR long_hkcu[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R',0};
-static const WCHAR long_hkcr[] = {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T',0};
-static const WCHAR long_hku[] = {'H','K','E','Y','_','U','S','E','R','S',0};
-static const WCHAR long_hkcc[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','C','O','N','F','I','G',0};
-
 static const struct
 {
     HKEY key;
@@ -40,32 +29,23 @@ static const struct
 }
 root_rels[] =
 {
-    {HKEY_LOCAL_MACHINE, short_hklm, long_hklm},
-    {HKEY_CURRENT_USER, short_hkcu, long_hkcu},
-    {HKEY_CLASSES_ROOT, short_hkcr, long_hkcr},
-    {HKEY_USERS, short_hku, long_hku},
-    {HKEY_CURRENT_CONFIG, short_hkcc, long_hkcc},
+    {HKEY_LOCAL_MACHINE,  L"HKLM", L"HKEY_LOCAL_MACHINE"},
+    {HKEY_CURRENT_USER,   L"HKCU", L"HKEY_CURRENT_USER"},
+    {HKEY_CLASSES_ROOT,   L"HKCR", L"HKEY_CLASSES_ROOT"},
+    {HKEY_USERS,          L"HKU",  L"HKEY_USERS"},
+    {HKEY_CURRENT_CONFIG, L"HKCC", L"HKEY_CURRENT_CONFIG"},
 };
 
-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_multi_sz[] = {'R','E','G','_','M','U','L','T','I','_','S','Z',0};
-
 const struct reg_type_rels 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_MULTI_SZ, type_multi_sz},
+    {REG_NONE,                L"REG_NONE"},
+    {REG_SZ,                  L"REG_SZ"},
+    {REG_EXPAND_SZ,           L"REG_EXPAND_SZ"},
+    {REG_BINARY,              L"REG_BINARY"},
+    {REG_DWORD,               L"REG_DWORD"},
+    {REG_DWORD_LITTLE_ENDIAN, L"REG_DWORD_LITTLE_ENDIAN"},
+    {REG_DWORD_BIG_ENDIAN,    L"REG_DWORD_BIG_ENDIAN"},
+    {REG_MULTI_SZ,            L"REG_MULTI_SZ"},
 };
 
 void output_writeconsole(const WCHAR *str, DWORD wlen)
@@ -216,10 +196,9 @@ static BOOL sane_path(const WCHAR *key)
 WCHAR *build_subkey_path(WCHAR *path, DWORD path_len, WCHAR *subkey_name, DWORD subkey_len)
 {
     WCHAR *subkey_path;
-    static const WCHAR fmt[] = {'%','s','\\','%','s',0};
 
     subkey_path = malloc((path_len + subkey_len + 2) * sizeof(WCHAR));
-    swprintf(subkey_path, path_len + subkey_len + 2, fmt, path, subkey_name);
+    swprintf(subkey_path, path_len + subkey_len + 2, L"%s\\%s", path, subkey_name);
 
     return subkey_path;
 }
@@ -228,7 +207,6 @@ static WCHAR *get_long_key(HKEY root, WCHAR *path)
 {
     DWORD i, array_size = ARRAY_SIZE(root_rels), len;
     WCHAR *long_key;
-    WCHAR fmt[] = {'%','s','\\','%','s',0};
 
     for (i = 0; i < array_size; i++)
     {
@@ -247,7 +225,7 @@ static WCHAR *get_long_key(HKEY root, WCHAR *path)
 
     len += lstrlenW(path) + 1; /* add one for the backslash */
     long_key = malloc((len + 1) * sizeof(WCHAR));
-    swprintf(long_key, len + 1, fmt, root_rels[i].long_name, path);
+    swprintf(long_key, len + 1, L"%s\\%s", root_rels[i].long_name, path);
     return long_key;
 }
 
@@ -301,19 +279,13 @@ static enum operations get_operation(const WCHAR *str, int *op_help)
 {
     struct op_info { const WCHAR *op; int id; int help_id; };
 
-    static const WCHAR add[] = {'a','d','d',0};
-    static const WCHAR delete[] = {'d','e','l','e','t','e',0};
-    static const WCHAR export[] = {'e','x','p','o','r','t',0};
-    static const WCHAR import[] = {'i','m','p','o','r','t',0};
-    static const WCHAR query[] = {'q','u','e','r','y',0};
-
     static const struct op_info op_array[] =
     {
-        { add,     REG_ADD,     STRING_ADD_USAGE },
-        { delete,  REG_DELETE,  STRING_DELETE_USAGE },
-        { export,  REG_EXPORT,  STRING_EXPORT_USAGE },
-        { import,  REG_IMPORT,  STRING_IMPORT_USAGE },
-        { query,   REG_QUERY,   STRING_QUERY_USAGE },
+        { L"add",     REG_ADD,     STRING_ADD_USAGE },
+        { L"delete",  REG_DELETE,  STRING_DELETE_USAGE },
+        { L"export",  REG_EXPORT,  STRING_EXPORT_USAGE },
+        { L"import",  REG_IMPORT,  STRING_IMPORT_USAGE },
+        { L"query",   REG_QUERY,   STRING_QUERY_USAGE },
         { NULL,    -1,          0 }
     };
 




More information about the wine-cvs mailing list