[PATCH 1/2] regedit: Convert regedit.c to Unicode
Hugh McMaster
hugh.mcmaster at outlook.com
Fri Jun 17 04:05:48 CDT 2016
Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
---
programs/regedit/Makefile.in | 2 +-
programs/regedit/main.c | 7 ++--
programs/regedit/regedit.c | 82 ++++++++++++++++++++------------------------
3 files changed, 41 insertions(+), 50 deletions(-)
diff --git a/programs/regedit/Makefile.in b/programs/regedit/Makefile.in
index acbfbd4..54f00f7 100644
--- a/programs/regedit/Makefile.in
+++ b/programs/regedit/Makefile.in
@@ -1,5 +1,5 @@
MODULE = regedit.exe
-APPMODE = -mwindows -mno-cygwin
+APPMODE = -mwindows -municode -mno-cygwin
IMPORTS = advapi32
DELAYIMPORTS = shlwapi shell32 comdlg32 comctl32 user32 gdi32
diff --git a/programs/regedit/main.c b/programs/regedit/main.c
index 593ffef..3f9e432 100644
--- a/programs/regedit/main.c
+++ b/programs/regedit/main.c
@@ -30,7 +30,7 @@
WCHAR g_pszDefaultValueName[64];
-BOOL ProcessCmdLine(LPSTR lpCmdLine);
+BOOL ProcessCmdLine(WCHAR *lpCmdLine);
static const WCHAR hkey_local_machine[] = {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',0};
static const WCHAR hkey_users[] = {'H','K','E','Y','_','U','S','E','R','S',0};
@@ -134,10 +134,7 @@ static BOOL TranslateChildTabMessage(MSG *msg)
return TRUE;
}
-int APIENTRY WinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int nCmdShow)
+int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, WCHAR *lpCmdLine, int nCmdShow)
{
MSG msg;
HACCEL hAccel;
diff --git a/programs/regedit/regedit.c b/programs/regedit/regedit.c
index 2cbd4bb..3ce25ce 100644
--- a/programs/regedit/regedit.c
+++ b/programs/regedit/regedit.c
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
+#include "wine/unicode.h"
#include "regproc.h"
static const char *usage =
@@ -76,9 +77,9 @@ const CHAR *getAppName(void)
* where *s[0] is the first symbol of the file name.
* file_name - buffer to write the file name to.
*/
-static void get_file_name(CHAR **command_line, CHAR *file_name)
+static void get_file_name(WCHAR **command_line, WCHAR *file_name)
{
- CHAR *s = *command_line;
+ WCHAR *s = *command_line;
int pos = 0; /* position of pointer "s" in *command_line */
file_name[0] = 0;
@@ -99,7 +100,7 @@ static void get_file_name(CHAR **command_line, CHAR *file_name)
pos++;
}
} else {
- while(s[0] && !isspace(s[0])) {
+ while(s[0] && !isspaceW(s[0])) {
s++;
pos++;
}
@@ -116,19 +117,20 @@ static void get_file_name(CHAR **command_line, CHAR *file_name)
s++;
pos++;
}
- while(s[0] && isspace(s[0])) {
+ while(s[0] && isspaceW(s[0])) {
s++;
pos++;
}
(*command_line) += pos;
}
-static BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s)
+static BOOL PerformRegAction(REGEDIT_ACTION action, WCHAR *s)
{
switch (action) {
case ACTION_ADD: {
- CHAR filename[MAX_PATH];
+ WCHAR filename[MAX_PATH];
FILE *reg_file;
+ WCHAR hyphenW[] = {'-',0};
get_file_name(&s, filename);
if (!filename[0]) {
@@ -138,33 +140,34 @@ static BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s)
}
while(filename[0]) {
- char* realname = NULL;
+ WCHAR *realname = NULL;
- if (strcmp(filename, "-") == 0)
+ if (!strcmpW(filename, hyphenW))
{
reg_file = stdin;
}
else
{
int size;
+ WCHAR rb_modeW[] = {'r','b',0};
- size = SearchPathA(NULL, filename, NULL, 0, NULL, NULL);
+ size = SearchPathW(NULL, filename, NULL, 0, NULL, NULL);
if (size > 0)
{
- realname = HeapAlloc(GetProcessHeap(), 0, size);
- size = SearchPathA(NULL, filename, NULL, size, realname, NULL);
+ realname = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
+ size = SearchPathW(NULL, filename, NULL, size, realname, NULL);
}
if (size == 0)
{
- fprintf(stderr, "%s: File not found \"%s\" (%d)\n",
+ fprintf(stderr, "%s: File not found \"%ls\" (%d)\n",
getAppName(), filename, GetLastError());
exit(1);
}
- reg_file = fopen(realname, "rb");
+ reg_file = _wfopen(realname, rb_modeW);
if (reg_file == NULL)
{
perror("");
- fprintf(stderr, "%s: Can't open file \"%s\"\n", getAppName(), filename);
+ fprintf(stderr, "%s: Can't open file \"%ls\"\n", getAppName(), filename);
exit(1);
}
}
@@ -179,7 +182,7 @@ static BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s)
break;
}
case ACTION_DELETE: {
- CHAR reg_key_name[KEY_MAX_LEN];
+ WCHAR reg_key_name[KEY_MAX_LEN];
get_file_name(&s, reg_key_name);
if (!reg_key_name[0]) {
@@ -187,17 +190,13 @@ static BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s)
getAppName());
fprintf(stderr,usage);
exit(1);
- } else
- {
- WCHAR* reg_key_nameW = GetWideString(reg_key_name);
- delete_registry_key(reg_key_nameW);
- HeapFree(GetProcessHeap(), 0, reg_key_nameW);
+ } else {
+ delete_registry_key(reg_key_name);
}
break;
}
case ACTION_EXPORT: {
- CHAR filename[MAX_PATH];
- WCHAR* filenameW;
+ WCHAR filename[MAX_PATH];
filename[0] = '\0';
get_file_name(&s, filename);
@@ -207,19 +206,14 @@ static BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s)
exit(1);
}
- filenameW = GetWideString(filename);
if (s[0]) {
- CHAR reg_key_name[KEY_MAX_LEN];
- WCHAR* reg_key_nameW;
+ WCHAR reg_key_name[KEY_MAX_LEN];
get_file_name(&s, reg_key_name);
- reg_key_nameW = GetWideString(reg_key_name);
- export_registry_key(filenameW, reg_key_nameW, REG_FORMAT_4);
- HeapFree(GetProcessHeap(), 0, reg_key_nameW);
+ export_registry_key(filename, reg_key_name, REG_FORMAT_4);
} else {
- export_registry_key(filenameW, NULL, REG_FORMAT_4);
+ export_registry_key(filename, NULL, REG_FORMAT_4);
}
- HeapFree(GetProcessHeap(), 0, filenameW);
break;
}
default:
@@ -237,38 +231,38 @@ static BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s)
* chu - the switch character in upper-case.
* s - the command line string where s points to the switch character.
*/
-static void error_unknown_switch(char chu, char *s)
+static void error_unknown_switch(WCHAR chu, WCHAR *s)
{
- if (isalpha(chu)) {
- fprintf(stderr,"%s: Undefined switch /%c!\n", getAppName(), chu);
+ if (isalphaW(chu)) {
+ fprintf(stderr,"%s: Undefined switch /%lc!\n", getAppName(), chu);
} else {
- fprintf(stderr,"%s: Alphabetic character is expected after '%c' "
+ fprintf(stderr,"%s: Alphabetic character is expected after '%lc' "
"in switch specification\n", getAppName(), *(s - 1));
}
exit(1);
}
-BOOL ProcessCmdLine(LPSTR lpCmdLine)
+BOOL ProcessCmdLine(WCHAR *lpCmdLine)
{
REGEDIT_ACTION action = ACTION_UNDEF;
- LPSTR s = lpCmdLine; /* command line pointer */
- CHAR ch = *s; /* current character */
+ WCHAR *s = lpCmdLine; /* command line pointer */
+ WCHAR ch = *s; /* current character */
while (ch && ((ch == '-') || (ch == '/'))) {
- char chu;
- char ch2;
+ WCHAR chu;
+ WCHAR ch2;
s++;
ch = *s;
- if (!ch || isspace(ch))
+ if (!ch || isspaceW(ch))
{
/* '-' is a file name. It indicates we should use stdin */
s--;
break;
}
ch2 = *(s+1);
- chu = toupper(ch);
- if (!ch2 || isspace(ch2)) {
+ chu = toupperW(ch);
+ if (!ch2 || isspaceW(ch2)) {
if (chu == 'S' || chu == 'V') {
/* ignore these switches */
} else {
@@ -296,7 +290,7 @@ BOOL ProcessCmdLine(LPSTR lpCmdLine)
/* fall through */
case 'R':
s += 2;
- while (*s && !isspace(*s)) {
+ while (*s && !isspaceW(*s)) {
s++;
}
break;
@@ -312,7 +306,7 @@ BOOL ProcessCmdLine(LPSTR lpCmdLine)
}
/* skip spaces to the next parameter */
ch = *s;
- while (ch && isspace(ch)) {
+ while (ch && isspaceW(ch)) {
s++;
ch = *s;
}
--
2.7.4
More information about the wine-patches
mailing list