diff options
Diffstat (limited to 'libbb/lineedit.c')
-rw-r--r-- | libbb/lineedit.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index c50b31d67..8e339da53 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -1700,18 +1700,34 @@ static int lineedit_read_key(char *read_key_buffer) | |||
1700 | #endif | 1700 | #endif |
1701 | 1701 | ||
1702 | #if ENABLE_FEATURE_ASSUME_UNICODE | 1702 | #if ENABLE_FEATURE_ASSUME_UNICODE |
1703 | { | 1703 | if (unicode_status == UNICODE_ON) { |
1704 | wchar_t wc; | 1704 | wchar_t wc; |
1705 | 1705 | ||
1706 | if ((int32_t)ic < 0) /* KEYCODE_xxx */ | 1706 | if ((int32_t)ic < 0) /* KEYCODE_xxx */ |
1707 | return ic; | 1707 | return ic; |
1708 | // TODO: imagine sequence like: 0xff, <left-arrow>: we are currently losing 0xff... | ||
1709 | |||
1708 | unicode_buf[unicode_idx++] = ic; | 1710 | unicode_buf[unicode_idx++] = ic; |
1709 | unicode_buf[unicode_idx] = '\0'; | 1711 | unicode_buf[unicode_idx] = '\0'; |
1710 | if (mbstowcs(&wc, unicode_buf, 1) != 1 && unicode_idx < MB_CUR_MAX) { | 1712 | if (mbstowcs(&wc, unicode_buf, 1) != 1) { |
1711 | delay = 50; | 1713 | /* Not (yet?) a valid unicode char */ |
1712 | goto poll_again; | 1714 | if (unicode_idx < MB_CUR_MAX) { |
1715 | delay = 50; | ||
1716 | goto poll_again; | ||
1717 | } | ||
1718 | /* Invalid sequence. Save all "bad bytes" except first */ | ||
1719 | read_key_ungets(read_key_buffer, unicode_buf + 1, MB_CUR_MAX - 1); | ||
1720 | /* | ||
1721 | * ic = unicode_buf[0] sounds even better, but currently | ||
1722 | * this does not work: wchar_t[] -> char[] conversion | ||
1723 | * when lineedit finishes mangles such "raw bytes" | ||
1724 | * (by misinterpreting them as unicode chars): | ||
1725 | */ | ||
1726 | ic = CONFIG_SUBST_WCHAR; | ||
1727 | } else { | ||
1728 | /* Valid unicode char, return its code */ | ||
1729 | ic = wc; | ||
1713 | } | 1730 | } |
1714 | ic = wc; | ||
1715 | } | 1731 | } |
1716 | #endif | 1732 | #endif |
1717 | } while (errno == EAGAIN); | 1733 | } while (errno == EAGAIN); |