aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-09-02 12:03:11 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-09-02 12:03:11 +0200
commit61a36af45d9342b65d16a3d29818cf4c70ec992d (patch)
tree6096e7f94cb9847ff36c91d6996e377f5e1dd654
parentb068bd7a4189f86d55b22242ec65e2ad56a9d719 (diff)
downloadbusybox-w32-61a36af45d9342b65d16a3d29818cf4c70ec992d.tar.gz
busybox-w32-61a36af45d9342b65d16a3d29818cf4c70ec992d.tar.bz2
busybox-w32-61a36af45d9342b65d16a3d29818cf4c70ec992d.zip
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>
-rw-r--r--libbb/lineedit.c16
-rw-r--r--libbb/unicode.c2
2 files changed, 14 insertions, 4 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index de7042491..381203a22 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -1061,9 +1061,16 @@ static void input_tab(smallint *lastWasTab)
1061 1061
1062 /* Make a local copy of the string -- 1062 /* Make a local copy of the string --
1063 * up to the position of the cursor */ 1063 * up to the position of the cursor */
1064#if !ENABLE_UNICODE_SUPPORT
1064 save_string(matchBuf, cursor + 1); 1065 save_string(matchBuf, cursor + 1);
1065#if ENABLE_UNICODE_SUPPORT 1066#else
1066 cursor_mb = strlen(matchBuf); 1067 {
1068 CHAR_T wc = command_ps[cursor];
1069 command_ps[cursor] = 0;
1070 save_string(matchBuf, MAX_LINELEN);
1071 command_ps[cursor] = wc;
1072 cursor_mb = strlen(matchBuf);
1073 }
1067#endif 1074#endif
1068 tmp = matchBuf; 1075 tmp = matchBuf;
1069 1076
@@ -1167,7 +1174,10 @@ static void input_tab(smallint *lastWasTab)
1167 sprintf(&command[cursor_mb - recalc_pos], "%s%s", tmp, matchBuf); 1174 sprintf(&command[cursor_mb - recalc_pos], "%s%s", tmp, matchBuf);
1168 command_len = load_string(command, S.maxsize); 1175 command_len = load_string(command, S.maxsize);
1169 /* write out the matched command */ 1176 /* write out the matched command */
1170 redraw(cmdedit_y, command_len - len); 1177 /* paranoia: load_string can return 0 on conv error,
1178 * prevent passing len = (0 - 12) to redraw */
1179 len = command_len - len;
1180 redraw(cmdedit_y, len >= 0 ? len : 0);
1171 } 1181 }
1172 } 1182 }
1173#endif 1183#endif
diff --git a/libbb/unicode.c b/libbb/unicode.c
index c4b5f86ee..70c6abe00 100644
--- a/libbb/unicode.c
+++ b/libbb/unicode.c
@@ -131,7 +131,7 @@ size_t FAST_FUNC wcstombs(char *dest, const wchar_t *src, size_t n)
131 size_t len = wcrtomb_internal(tbuf, wc); 131 size_t len = wcrtomb_internal(tbuf, wc);
132 132
133 if (len > n) 133 if (len > n)
134 len = n; 134 break;
135 memcpy(dest, tbuf, len); 135 memcpy(dest, tbuf, len);
136 if (wc == L'\0') 136 if (wc == L'\0')
137 return org_n - n; 137 return org_n - n;