diff options
author | Ron Yorston <rmy@pobox.com> | 2023-07-01 12:52:24 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2023-07-01 12:52:24 +0100 |
commit | 40217f5588a34d9ddf456307bcd79ce3ef8af2c0 (patch) | |
tree | 2528f11ed41e28bdf7aeecc59d765b08516046b6 | |
parent | b2ea663bada3acc89a5aa8ffb96f053ef90d6ac7 (diff) | |
download | busybox-w32-40217f5588a34d9ddf456307bcd79ce3ef8af2c0.tar.gz busybox-w32-40217f5588a34d9ddf456307bcd79ce3ef8af2c0.tar.bz2 busybox-w32-40217f5588a34d9ddf456307bcd79ce3ef8af2c0.zip |
win32: code shrink readConsoleInput_utf8
Move decision about how to read console input from windows_read_key()
to readConsoleInput_utf8().
Saves 48-64 bytes.
-rw-r--r-- | win32/termios.c | 5 | ||||
-rw-r--r-- | win32/winansi.c | 4 |
2 files changed, 5 insertions, 4 deletions
diff --git a/win32/termios.c b/win32/termios.c index d70c1e685..23184e901 100644 --- a/win32/termios.c +++ b/win32/termios.c | |||
@@ -57,10 +57,7 @@ int64_t FAST_FUNC windows_read_key(int fd, char *buf UNUSED_PARAM, int timeout) | |||
57 | #if ENABLE_FEATURE_EURO_INPUT | 57 | #if ENABLE_FEATURE_EURO_INPUT |
58 | if (!ReadConsoleInputW(cin, &record, 1, &nevent_out)) | 58 | if (!ReadConsoleInputW(cin, &record, 1, &nevent_out)) |
59 | #else | 59 | #else |
60 | // if ACP is UTF8 then we read UTF8 regardless of console (in) CP | 60 | if (!readConsoleInput_utf8(cin, &record, 1, &nevent_out)) |
61 | if (GetConsoleCP() == CP_UTF8 || GetACP() == CP_UTF8 | ||
62 | ? !readConsoleInput_utf8(cin, &record, 1, &nevent_out) | ||
63 | : !ReadConsoleInput(cin, &record, 1, &nevent_out)) | ||
64 | #endif | 61 | #endif |
65 | goto done; | 62 | goto done; |
66 | 63 | ||
diff --git a/win32/winansi.c b/win32/winansi.c index 4beef3eb8..83ce076c0 100644 --- a/win32/winansi.c +++ b/win32/winansi.c | |||
@@ -1293,6 +1293,10 @@ BOOL readConsoleInput_utf8(HANDLE h, INPUT_RECORD *r, DWORD len, DWORD *got) | |||
1293 | if (len != 1) | 1293 | if (len != 1) |
1294 | return FALSE; | 1294 | return FALSE; |
1295 | 1295 | ||
1296 | // if ACP is UTF8 then we read UTF8 regardless of console (in) CP | ||
1297 | if (GetConsoleCP() != CP_UTF8 && GetACP() != CP_UTF8) | ||
1298 | return ReadConsoleInput(h, r, len, got); | ||
1299 | |||
1296 | if (u8pos == u8len) { | 1300 | if (u8pos == u8len) { |
1297 | DWORD codepoint; | 1301 | DWORD codepoint; |
1298 | 1302 | ||