Commit aee674c9 authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

kernel32: Properly manage UTF-8 (and any wcs) input strings.

parent ff057db6
...@@ -1101,8 +1101,9 @@ static enum read_console_input_return bare_console_fetch_input(HANDLE handle, in ...@@ -1101,8 +1101,9 @@ static enum read_console_input_return bare_console_fetch_input(HANDLE handle, in
{ {
enum read_console_input_return ret; enum read_console_input_return ret;
char input[8]; char input[8];
WCHAR inputw[8];
int i; int i;
size_t idx = 0; size_t idx = 0, idxw;
unsigned numEvent; unsigned numEvent;
INPUT_RECORD ir[8]; INPUT_RECORD ir[8];
DWORD written; DWORD written;
...@@ -1157,12 +1158,21 @@ static enum read_console_input_return bare_console_fetch_input(HANDLE handle, in ...@@ -1157,12 +1158,21 @@ static enum read_console_input_return bare_console_fetch_input(HANDLE handle, in
break; break;
case -1: case -1:
/* we haven't found the string into key-db, push full input string into server */ /* we haven't found the string into key-db, push full input string into server */
for (i = 0; i < idx; i++) idxw = MultiByteToWideChar(CP_UNIXCP, 0, input, idx, inputw, sizeof(inputw) / sizeof(inputw[0]));
/* we cannot translate yet... likely we need more chars (wait max 1/2s for next char) */
if (idxw == 0)
{
timeout = 500;
next_char = TRUE;
break;
}
for (i = 0; i < idxw; i++)
{ {
numEvent = TERM_FillSimpleChar(input[i], ir); numEvent = TERM_FillSimpleChar(inputw[i], ir);
WriteConsoleInputW(handle, ir, numEvent, &written); WriteConsoleInputW(handle, ir, numEvent, &written);
} }
ret = idx == 0 ? rci_timeout : rci_gotone; ret = rci_gotone;
break; break;
default: default:
/* we got a transformation from key-db... push this into server */ /* we got a transformation from key-db... push this into server */
......
...@@ -36,7 +36,7 @@ extern WCHAR* CONSOLE_Readline(HANDLE, BOOL); ...@@ -36,7 +36,7 @@ extern WCHAR* CONSOLE_Readline(HANDLE, BOOL);
/* term.c */ /* term.c */
extern BOOL TERM_Init(void); extern BOOL TERM_Init(void);
extern BOOL TERM_Exit(void); extern BOOL TERM_Exit(void);
extern unsigned TERM_FillSimpleChar(unsigned real_inchar, INPUT_RECORD* ir); extern unsigned TERM_FillSimpleChar(WCHAR real_inchar, INPUT_RECORD* ir);
extern int TERM_FillInputRecord(const char* in, size_t len, INPUT_RECORD* ir); extern int TERM_FillInputRecord(const char* in, size_t len, INPUT_RECORD* ir);
#endif /* __WINE_CONSOLE_PRIVATE_H */ #endif /* __WINE_CONSOLE_PRIVATE_H */
...@@ -87,11 +87,10 @@ static inline void init_complex_char(INPUT_RECORD* ir, BOOL down, WORD vk, WORD ...@@ -87,11 +87,10 @@ static inline void init_complex_char(INPUT_RECORD* ir, BOOL down, WORD vk, WORD
* TERM_FillSimpleChar * TERM_FillSimpleChar
* *
*/ */
unsigned TERM_FillSimpleChar(unsigned real_inchar, INPUT_RECORD* ir) unsigned TERM_FillSimpleChar(WCHAR real_inchar, INPUT_RECORD* ir)
{ {
unsigned vk; unsigned vk;
unsigned inchar; WCHAR inchar;
char ch;
unsigned numEvent = 0; unsigned numEvent = 0;
DWORD cks = 0; DWORD cks = 0;
...@@ -110,8 +109,7 @@ unsigned TERM_FillSimpleChar(unsigned real_inchar, INPUT_RECORD* ir) ...@@ -110,8 +109,7 @@ unsigned TERM_FillSimpleChar(unsigned real_inchar, INPUT_RECORD* ir)
inchar = real_inchar; inchar = real_inchar;
break; break;
} }
if ((inchar & ~0xFF) != 0) FIXME("What a char (%u)\n", inchar); vk = (inchar < 256) ? vkkeyscan_table[inchar] : 0;
vk = vkkeyscan_table[inchar];
if (vk & 0x0100) if (vk & 0x0100)
init_complex_char(&ir[numEvent++], 1, 0x2a, 0x10, SHIFT_PRESSED); init_complex_char(&ir[numEvent++], 1, 0x2a, 0x10, SHIFT_PRESSED);
if ((vk & 0x0200) || (unsigned char)real_inchar <= 26) if ((vk & 0x0200) || (unsigned char)real_inchar <= 26)
...@@ -132,8 +130,7 @@ unsigned TERM_FillSimpleChar(unsigned real_inchar, INPUT_RECORD* ir) ...@@ -132,8 +130,7 @@ unsigned TERM_FillSimpleChar(unsigned real_inchar, INPUT_RECORD* ir)
ir[numEvent].Event.KeyEvent.wVirtualKeyCode = vk; ir[numEvent].Event.KeyEvent.wVirtualKeyCode = vk;
ir[numEvent].Event.KeyEvent.wVirtualScanCode = mapvkey_0[vk & 0x00ff]; /* VirtualKeyCodes to ScanCode */ ir[numEvent].Event.KeyEvent.wVirtualScanCode = mapvkey_0[vk & 0x00ff]; /* VirtualKeyCodes to ScanCode */
ch = inchar; ir[numEvent].Event.KeyEvent.uChar.UnicodeChar = inchar;
MultiByteToWideChar(CP_UNIXCP, 0, &ch, 1, &ir[numEvent].Event.KeyEvent.uChar.UnicodeChar, 1);
ir[numEvent + 1] = ir[numEvent]; ir[numEvent + 1] = ir[numEvent];
ir[numEvent + 1].Event.KeyEvent.bKeyDown = 0; ir[numEvent + 1].Event.KeyEvent.bKeyDown = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment