diff options
author | Denys Vlasenko | 2010-09-02 12:03:11 +0200 |
---|---|---|
committer | Denys Vlasenko | 2010-09-02 12:03:11 +0200 |
commit | 61a36af45d9342b65d16a3d29818cf4c70ec992d (patch) | |
tree | 6096e7f94cb9847ff36c91d6996e377f5e1dd654 /libbb/lineedit.c | |
parent | b068bd7a4189f86d55b22242ec65e2ad56a9d719 (diff) | |
download | busybox-61a36af45d9342b65d16a3d29818cf4c70ec992d.zip busybox-61a36af45d9342b65d16a3d29818cf4c70ec992d.tar.gz |
lineedit: fix completion with Unicode chars
function old new delta
read_line_input 4966 5002 +36
bb_wcstombs 170 159 -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 36/-11) Total: 25 bytes
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'libbb/lineedit.c')
-rw-r--r-- | libbb/lineedit.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index de70424..381203a 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -1061,9 +1061,16 @@ static void input_tab(smallint *lastWasTab) /* Make a local copy of the string -- * up to the position of the cursor */ +#if !ENABLE_UNICODE_SUPPORT save_string(matchBuf, cursor + 1); -#if ENABLE_UNICODE_SUPPORT - cursor_mb = strlen(matchBuf); +#else + { + CHAR_T wc = command_ps[cursor]; + command_ps[cursor] = 0; + save_string(matchBuf, MAX_LINELEN); + command_ps[cursor] = wc; + cursor_mb = strlen(matchBuf); + } #endif tmp = matchBuf; @@ -1167,7 +1174,10 @@ static void input_tab(smallint *lastWasTab) sprintf(&command[cursor_mb - recalc_pos], "%s%s", tmp, matchBuf); command_len = load_string(command, S.maxsize); /* write out the matched command */ - redraw(cmdedit_y, command_len - len); + /* paranoia: load_string can return 0 on conv error, + * prevent passing len = (0 - 12) to redraw */ + len = command_len - len; + redraw(cmdedit_y, len >= 0 ? len : 0); } } #endif |