[4/4] Fix console codepages handling
Kirill K. Smirnov
lich at math.spbu.ru
Mon May 7 15:59:00 CDT 2007
Move codepages to server side.
Input and output codepages are properties of console_input.
--
Kirill
-------------- next part --------------
diff --git a/dlls/kernel32/console.c b/dlls/kernel32/console.c
index 66bc796..b4e8437 100644
--- a/dlls/kernel32/console.c
+++ b/dlls/kernel32/console.c
@@ -55,9 +55,6 @@ #include "kernel_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(console);
-static UINT console_input_codepage;
-static UINT console_output_codepage;
-
static const WCHAR coninW[] = {'C','O','N','I','N','$',0};
static const WCHAR conoutW[] = {'C','O','N','O','U','T','$',0};
@@ -141,12 +138,19 @@ HWND WINAPI GetConsoleWindow(VOID)
*/
UINT WINAPI GetConsoleCP(VOID)
{
- if (!console_input_codepage)
+ BOOL ret;
+ UINT codepage = GetOEMCP(); /* default value */
+
+ SERVER_START_REQ(get_console_input_info)
{
- console_input_codepage = GetOEMCP();
- TRACE("%u\n", console_input_codepage);
+ req->handle = 0;
+ ret = !wine_server_call_err(req);
+ if (ret && reply->input_cp)
+ codepage = reply->input_cp;
}
- return console_input_codepage;
+ SERVER_END_REQ;
+
+ return codepage;
}
@@ -155,9 +159,24 @@ UINT WINAPI GetConsoleCP(VOID)
*/
BOOL WINAPI SetConsoleCP(UINT cp)
{
- if (!IsValidCodePage( cp )) return FALSE;
- console_input_codepage = cp;
- return TRUE;
+ BOOL ret;
+
+ if (!IsValidCodePage(cp))
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+
+ SERVER_START_REQ(set_console_input_info)
+ {
+ req->handle = 0;
+ req->mask = SET_CONSOLE_INPUT_INFO_INPUT_CODEPAGE;
+ req->input_cp = cp;
+ ret = !wine_server_call_err(req);
+ }
+ SERVER_END_REQ;
+
+ return ret;
}
@@ -166,12 +185,19 @@ BOOL WINAPI SetConsoleCP(UINT cp)
*/
UINT WINAPI GetConsoleOutputCP(VOID)
{
- if (!console_output_codepage)
+ BOOL ret;
+ UINT codepage = GetOEMCP(); /* default value */
+
+ SERVER_START_REQ(get_console_input_info)
{
- console_output_codepage = GetOEMCP();
- TRACE("%u\n", console_output_codepage);
+ req->handle = 0;
+ ret = !wine_server_call_err(req);
+ if (ret && reply->output_cp)
+ codepage = reply->output_cp;
}
- return console_output_codepage;
+ SERVER_END_REQ;
+
+ return codepage;
}
@@ -187,9 +213,24 @@ UINT WINAPI GetConsoleOutputCP(VOID)
*/
BOOL WINAPI SetConsoleOutputCP(UINT cp)
{
- if (!IsValidCodePage( cp )) return FALSE;
- console_output_codepage = cp;
- return TRUE;
+ BOOL ret;
+
+ if (!IsValidCodePage(cp))
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+
+ SERVER_START_REQ(set_console_input_info)
+ {
+ req->handle = 0;
+ req->mask = SET_CONSOLE_INPUT_INFO_OUTPUT_CODEPAGE;
+ req->output_cp = cp;
+ ret = !wine_server_call_err(req);
+ }
+ SERVER_END_REQ;
+
+ return ret;
}
diff --git a/include/wine/server_protocol.h b/include/wine/server_protocol.h
index 7f6def0..5117cce 100644
--- a/include/wine/server_protocol.h
+++ b/include/wine/server_protocol.h
@@ -1378,6 +1378,8 @@ struct set_console_input_info_request
int history_mode;
int history_size;
int edition_mode;
+ unsigned int input_cp;
+ unsigned int output_cp;
/* VARARG(title,unicode_str); */
};
struct set_console_input_info_reply
@@ -1389,6 +1391,8 @@ #define SET_CONSOLE_INPUT_INFO_TITLE
#define SET_CONSOLE_INPUT_INFO_HISTORY_MODE 0x04
#define SET_CONSOLE_INPUT_INFO_HISTORY_SIZE 0x08
#define SET_CONSOLE_INPUT_INFO_EDITION_MODE 0x10
+#define SET_CONSOLE_INPUT_INFO_INPUT_CODEPAGE 0x20
+#define SET_CONSOLE_INPUT_INFO_OUTPUT_CODEPAGE 0x40
@@ -1404,6 +1408,8 @@ struct get_console_input_info_reply
int history_size;
int history_index;
int edition_mode;
+ unsigned int input_cp;
+ unsigned int output_cp;
/* VARARG(title,unicode_str); */
};
@@ -4628,6 +4634,6 @@ union generic_reply
struct allocate_locally_unique_id_reply allocate_locally_unique_id_reply;
};
-#define SERVER_PROTOCOL_VERSION 300
+#define SERVER_PROTOCOL_VERSION 301
#endif /* __WINE_WINE_SERVER_PROTOCOL_H */
diff --git a/server/console.c b/server/console.c
index cb34cb3..f1f3f3d 100644
--- a/server/console.c
+++ b/server/console.c
@@ -255,6 +255,8 @@ static struct object *create_console_inp
console_input->history_index = 0;
console_input->history_mode = 0;
console_input->edition_mode = 0;
+ console_input->input_cp = 0;
+ console_input->output_cp = 0;
console_input->event = create_event( NULL, NULL, 0, 1, 0 );
if (!console_input->history || !console_input->evt)
@@ -680,6 +682,14 @@ static int set_console_input_info( const
{
console->edition_mode = req->edition_mode;
}
+ if (req->mask & SET_CONSOLE_INPUT_INFO_INPUT_CODEPAGE)
+ {
+ console->input_cp = req->input_cp;
+ }
+ if (req->mask & SET_CONSOLE_INPUT_INFO_OUTPUT_CODEPAGE)
+ {
+ console->output_cp = req->output_cp;
+ }
release_object( console );
return 1;
error:
@@ -1372,6 +1382,8 @@ DECL_HANDLER(get_console_input_info)
reply->history_size = console->history_size;
reply->history_index = console->history_index;
reply->edition_mode = console->edition_mode;
+ reply->input_cp = console->input_cp;
+ reply->output_cp = console->output_cp;
release_object( console );
}
diff --git a/server/console.h b/server/console.h
index 3864ee9..b8338ed 100644
--- a/server/console.h
+++ b/server/console.h
@@ -42,6 +42,8 @@ struct console_input
int history_index; /* number of used entries in history array */
int history_mode; /* mode of history (non zero means remove doubled strings */
int edition_mode; /* index to edition mode flavors */
+ unsigned int input_cp; /* console input codepage */
+ unsigned int output_cp; /* console output codepage */
struct event *event; /* event to wait on for input queue */
};
More information about the wine-patches
mailing list