diff options
author | Ron Yorston <rmy@pobox.com> | 2019-02-02 15:57:59 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2019-02-02 16:21:12 +0000 |
commit | 93a63809f9146e39a1c36bdccdfb8ef3b7046c98 (patch) | |
tree | 41adedb1f386dce9c163ff1bc634a725e8e1c8b8 /win32/termios.c | |
parent | 0e26e2ff3b87f8db635d3c7dca23f441a3961fd2 (diff) | |
download | busybox-w32-93a63809f9146e39a1c36bdccdfb8ef3b7046c98.tar.gz busybox-w32-93a63809f9146e39a1c36bdccdfb8ef3b7046c98.tar.bz2 busybox-w32-93a63809f9146e39a1c36bdccdfb8ef3b7046c98.zip |
win32: add support for the euro currency symbol
The euro currency symbol was added to some OEM code pages. See:
https://www.aivosto.com/articles/charsets-codepages-dos.html
Add a configuration option (enabled by default) to support this.
When enabled:
- The read_key() function requests wide character key events. This
allows the euro symbol to be entered regardless of the console OEM
code page, though it needs to be available in the ANSI code page.
- Conversions between OEM and ANSI code pages in winansi.c are
modified to work around a bug in the Microsoft routines.
- If the OEM code page is 850 when BusyBox starts it's changed to
858. This is the only currently supported OEM code page.
Also, the shell read builtin is modified to use read_key() whenever
input is being taken from the console.
Diffstat (limited to 'win32/termios.c')
-rw-r--r-- | win32/termios.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/win32/termios.c b/win32/termios.c index 7a107c5bd..fe6f0c546 100644 --- a/win32/termios.c +++ b/win32/termios.c | |||
@@ -6,7 +6,12 @@ int64_t FAST_FUNC read_key(int fd, char *buf UNUSED_PARAM, int timeout) | |||
6 | INPUT_RECORD record; | 6 | INPUT_RECORD record; |
7 | DWORD nevent_out, mode; | 7 | DWORD nevent_out, mode; |
8 | int ret = -1; | 8 | int ret = -1; |
9 | #if ENABLE_FEATURE_EURO | ||
10 | wchar_t uchar; | ||
11 | char achar; | ||
12 | #else | ||
9 | char *s; | 13 | char *s; |
14 | #endif | ||
10 | int alt_pressed = FALSE; | 15 | int alt_pressed = FALSE; |
11 | DWORD state; | 16 | DWORD state; |
12 | 17 | ||
@@ -22,7 +27,11 @@ int64_t FAST_FUNC read_key(int fd, char *buf UNUSED_PARAM, int timeout) | |||
22 | if (WaitForSingleObject(cin, timeout) != WAIT_OBJECT_0) | 27 | if (WaitForSingleObject(cin, timeout) != WAIT_OBJECT_0) |
23 | goto done; | 28 | goto done; |
24 | } | 29 | } |
30 | #if ENABLE_FEATURE_EURO | ||
31 | if (!ReadConsoleInputW(cin, &record, 1, &nevent_out)) | ||
32 | #else | ||
25 | if (!ReadConsoleInput(cin, &record, 1, &nevent_out)) | 33 | if (!ReadConsoleInput(cin, &record, 1, &nevent_out)) |
34 | #endif | ||
26 | goto done; | 35 | goto done; |
27 | 36 | ||
28 | if (record.EventType != KEY_EVENT) | 37 | if (record.EventType != KEY_EVENT) |
@@ -40,7 +49,11 @@ int64_t FAST_FUNC read_key(int fd, char *buf UNUSED_PARAM, int timeout) | |||
40 | alt_pressed = ((state & LEFT_ALT_PRESSED) != 0); | 49 | alt_pressed = ((state & LEFT_ALT_PRESSED) != 0); |
41 | } | 50 | } |
42 | 51 | ||
52 | #if ENABLE_FEATURE_EURO | ||
53 | if (!record.Event.KeyEvent.uChar.UnicodeChar) { | ||
54 | #else | ||
43 | if (!record.Event.KeyEvent.uChar.AsciiChar) { | 55 | if (!record.Event.KeyEvent.uChar.AsciiChar) { |
56 | #endif | ||
44 | if (alt_pressed) { | 57 | if (alt_pressed) { |
45 | switch (record.Event.KeyEvent.wVirtualKeyCode) { | 58 | switch (record.Event.KeyEvent.wVirtualKeyCode) { |
46 | case VK_MENU: | 59 | case VK_MENU: |
@@ -91,11 +104,19 @@ int64_t FAST_FUNC read_key(int fd, char *buf UNUSED_PARAM, int timeout) | |||
91 | } | 104 | } |
92 | continue; | 105 | continue; |
93 | } | 106 | } |
107 | #if ENABLE_FEATURE_EURO | ||
108 | uchar = record.Event.KeyEvent.uChar.UnicodeChar; | ||
109 | achar = uchar & 0x7f; | ||
110 | if (achar != uchar) | ||
111 | WideCharToMultiByte(CP_ACP, 0, &uchar, 1, &achar, 1, NULL, NULL); | ||
112 | ret = achar; | ||
113 | #else | ||
94 | if ( (record.Event.KeyEvent.uChar.AsciiChar & 0x80) == 0x80 ) { | 114 | if ( (record.Event.KeyEvent.uChar.AsciiChar & 0x80) == 0x80 ) { |
95 | s = &record.Event.KeyEvent.uChar.AsciiChar; | 115 | s = &record.Event.KeyEvent.uChar.AsciiChar; |
96 | OemToCharBuff(s, s, 1); | 116 | OemToCharBuff(s, s, 1); |
97 | } | 117 | } |
98 | ret = record.Event.KeyEvent.uChar.AsciiChar; | 118 | ret = record.Event.KeyEvent.uChar.AsciiChar; |
119 | #endif | ||
99 | break; | 120 | break; |
100 | } | 121 | } |
101 | done: | 122 | done: |