[try 3] Move console codepages to the server

Kirill K. Smirnov lich at math.spbu.ru
Thu May 10 12:19:47 CDT 2007


Propagate changes in server/protocol.def too.
-------------- 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 99f9f82..930fb1b 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); */
 };
 
@@ -4722,6 +4728,6 @@ union generic_reply
     struct get_next_device_request_reply get_next_device_request_reply;
 };
 
-#define SERVER_PROTOCOL_VERSION 303
+#define SERVER_PROTOCOL_VERSION 304
 
 #endif /* __WINE_WINE_SERVER_PROTOCOL_H */
diff --git a/server/console.c b/server/console.c
index 8e667d4..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 */
 };
 
diff --git a/server/protocol.def b/server/protocol.def
index fb2d8cd..e6f1fb3 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -1104,6 +1104,8 @@ struct console_renderer_event
     int          history_mode;  /* whether we duplicate lines in history */
     int          history_size;  /* number of lines in history */
     int          edition_mode;  /* index to the edition mode flavors */
+    unsigned int input_cp;      /* console input codepage */
+    unsigned int output_cp;     /* console output codepage */
     VARARG(title,unicode_str);  /* console title */
 @END
 #define SET_CONSOLE_INPUT_INFO_ACTIVE_SB        0x01
@@ -1111,6 +1113,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
 
 
 /* Get info about a console (input only) */
@@ -1121,6 +1125,8 @@ #define SET_CONSOLE_INPUT_INFO_EDITION_M
     int          history_size;  /* number of lines in history */
     int          history_index; /* number of used lines in history */
     int          edition_mode;  /* index to the edition mode flavors */
+    unsigned int input_cp;      /* console input codepage */
+    unsigned int output_cp;     /* console output codepage */
     VARARG(title,unicode_str);  /* console title */
 @END
 
diff --git a/server/request.h b/server/request.h
diff --git a/server/trace.c b/server/trace.c
index 8ae8d73..35afad4 100644
--- a/server/trace.c
+++ b/server/trace.c
@@ -1466,6 +1466,8 @@ static void dump_set_console_input_info_
     fprintf( stderr, " history_mode=%d,", req->history_mode );
     fprintf( stderr, " history_size=%d,", req->history_size );
     fprintf( stderr, " edition_mode=%d,", req->edition_mode );
+    fprintf( stderr, " input_cp=%08x,", req->input_cp );
+    fprintf( stderr, " output_cp=%08x,", req->output_cp );
     fprintf( stderr, " title=" );
     dump_varargs_unicode_str( cur_size );
 }
@@ -1481,6 +1483,8 @@ static void dump_get_console_input_info_
     fprintf( stderr, " history_size=%d,", req->history_size );
     fprintf( stderr, " history_index=%d,", req->history_index );
     fprintf( stderr, " edition_mode=%d,", req->edition_mode );
+    fprintf( stderr, " input_cp=%08x,", req->input_cp );
+    fprintf( stderr, " output_cp=%08x,", req->output_cp );
     fprintf( stderr, " title=" );
     dump_varargs_unicode_str( cur_size );
 }


More information about the wine-patches mailing list