aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2013-08-19 16:44:05 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2013-08-19 16:44:05 +0200
commit7a18043a968ec6d4b8c4c8cac059ad977d14e47c (patch)
tree3f2926bc556542b689d284338a7137ede9544d56
parent8395bd3f52f8ed46fa3ffc316b2d113afa748bae (diff)
downloadbusybox-w32-7a18043a968ec6d4b8c4c8cac059ad977d14e47c.tar.gz
busybox-w32-7a18043a968ec6d4b8c4c8cac059ad977d14e47c.tar.bz2
busybox-w32-7a18043a968ec6d4b8c4c8cac059ad977d14e47c.zip
lineedit: improve Unicode handling (still buggy though)
function old new delta unicode_strlen - 31 +31 read_line_input 3876 3879 +3 lineedit_read_key 255 246 -9 parse_and_put_prompt 785 755 -30 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/2 up/down: 34/-39) Total: -5 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--libbb/lineedit.c30
-rw-r--r--libbb/unicode.c5
2 files changed, 24 insertions, 11 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 1313dd5d9..ecf3066b1 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -1763,7 +1763,7 @@ static void ask_terminal(void)
1763static void parse_and_put_prompt(const char *prmt_ptr) 1763static void parse_and_put_prompt(const char *prmt_ptr)
1764{ 1764{
1765 cmdedit_prompt = prmt_ptr; 1765 cmdedit_prompt = prmt_ptr;
1766 cmdedit_prmt_len = strlen(prmt_ptr); 1766 cmdedit_prmt_len = unicode_strlen(prmt_ptr);
1767 put_prompt(); 1767 put_prompt();
1768} 1768}
1769#else 1769#else
@@ -1781,7 +1781,7 @@ static void parse_and_put_prompt(const char *prmt_ptr)
1781 char c; 1781 char c;
1782 char *pbuf; 1782 char *pbuf;
1783 1783
1784 cmdedit_prmt_len = 0; 1784 /*cmdedit_prmt_len = 0; - already is */
1785 1785
1786 cbuf[1] = '\0'; /* never changes */ 1786 cbuf[1] = '\0'; /* never changes */
1787 1787
@@ -1915,7 +1915,8 @@ static void parse_and_put_prompt(const char *prmt_ptr)
1915 } 1915 }
1916 case '[': case ']': 1916 case '[': case ']':
1917 if (c == flg_not_length) { 1917 if (c == flg_not_length) {
1918 flg_not_length = (flg_not_length == '[' ? ']' : '['); 1918 /* Toggle '['/']' hex 5b/5d */
1919 flg_not_length ^= 6;
1919 continue; 1920 continue;
1920 } 1921 }
1921 break; 1922 break;
@@ -1925,8 +1926,13 @@ static void parse_and_put_prompt(const char *prmt_ptr)
1925 cbuf[0] = c; 1926 cbuf[0] = c;
1926 cur_prmt_len = strlen(pbuf); 1927 cur_prmt_len = strlen(pbuf);
1927 prmt_len += cur_prmt_len; 1928 prmt_len += cur_prmt_len;
1928 if (flg_not_length != ']') 1929 if (flg_not_length != ']') {
1930#if 0 /*ENABLE_UNICODE_SUPPORT - won't work, pbuf is one BYTE string here. FIXME */
1931 cmdedit_prmt_len += unicode_strlen(pbuf);
1932#else
1929 cmdedit_prmt_len += cur_prmt_len; 1933 cmdedit_prmt_len += cur_prmt_len;
1934#endif
1935 }
1930 prmt_mem_ptr = strcat(xrealloc(prmt_mem_ptr, prmt_len+1), pbuf); 1936 prmt_mem_ptr = strcat(xrealloc(prmt_mem_ptr, prmt_len+1), pbuf);
1931 free(free_me); 1937 free(free_me);
1932 } /* while */ 1938 } /* while */
@@ -1996,7 +2002,15 @@ static int lineedit_read_key(char *read_key_buffer, int timeout)
1996 S.sent_ESC_br6n = 0; 2002 S.sent_ESC_br6n = 0;
1997 if (cursor == 0) { /* otherwise it may be bogus */ 2003 if (cursor == 0) { /* otherwise it may be bogus */
1998 int col = ((ic >> 32) & 0x7fff) - 1; 2004 int col = ((ic >> 32) & 0x7fff) - 1;
1999 if (col > cmdedit_prmt_len) { 2005 /*
2006 * Is col > cmdedit_prmt_len?
2007 * If yes (terminal says cursor is farther to the right
2008 * of where we think it should be),
2009 * the prompt wasn't printed starting at col 1,
2010 * there was additional text before it.
2011 */
2012 if ((int)(col - cmdedit_prmt_len) > 0) {
2013 /* Fix our understanding of current x position */
2000 cmdedit_x += (col - cmdedit_prmt_len); 2014 cmdedit_x += (col - cmdedit_prmt_len);
2001 while (cmdedit_x >= cmdedit_termw) { 2015 while (cmdedit_x >= cmdedit_termw) {
2002 cmdedit_x -= cmdedit_termw; 2016 cmdedit_x -= cmdedit_termw;
@@ -2087,6 +2101,7 @@ static int32_t reverse_i_search(void)
2087 char read_key_buffer[KEYCODE_BUFFER_SIZE]; 2101 char read_key_buffer[KEYCODE_BUFFER_SIZE];
2088 const char *matched_history_line; 2102 const char *matched_history_line;
2089 const char *saved_prompt; 2103 const char *saved_prompt;
2104 unsigned saved_prmt_len;
2090 int32_t ic; 2105 int32_t ic;
2091 2106
2092 matched_history_line = NULL; 2107 matched_history_line = NULL;
@@ -2095,6 +2110,7 @@ static int32_t reverse_i_search(void)
2095 2110
2096 /* Save and replace the prompt */ 2111 /* Save and replace the prompt */
2097 saved_prompt = cmdedit_prompt; 2112 saved_prompt = cmdedit_prompt;
2113 saved_prmt_len = cmdedit_prmt_len;
2098 goto set_prompt; 2114 goto set_prompt;
2099 2115
2100 while (1) { 2116 while (1) {
@@ -2170,7 +2186,7 @@ static int32_t reverse_i_search(void)
2170 free((char*)cmdedit_prompt); 2186 free((char*)cmdedit_prompt);
2171 set_prompt: 2187 set_prompt:
2172 cmdedit_prompt = xasprintf("(reverse-i-search)'%s': ", match_buf); 2188 cmdedit_prompt = xasprintf("(reverse-i-search)'%s': ", match_buf);
2173 cmdedit_prmt_len = strlen(cmdedit_prompt); 2189 cmdedit_prmt_len = unicode_strlen(cmdedit_prompt);
2174 goto do_redraw; 2190 goto do_redraw;
2175 } 2191 }
2176 } 2192 }
@@ -2192,7 +2208,7 @@ static int32_t reverse_i_search(void)
2192 2208
2193 free((char*)cmdedit_prompt); 2209 free((char*)cmdedit_prompt);
2194 cmdedit_prompt = saved_prompt; 2210 cmdedit_prompt = saved_prompt;
2195 cmdedit_prmt_len = strlen(cmdedit_prompt); 2211 cmdedit_prmt_len = saved_prmt_len;
2196 redraw(cmdedit_y, command_len - cursor); 2212 redraw(cmdedit_y, command_len - cursor);
2197 2213
2198 return ic; 2214 return ic;
diff --git a/libbb/unicode.c b/libbb/unicode.c
index 2e5dd5adc..9c4da50d3 100644
--- a/libbb/unicode.c
+++ b/libbb/unicode.c
@@ -43,8 +43,7 @@ void FAST_FUNC reinit_unicode(const char *LANG)
43 setlocale(LC_CTYPE, LANG ? LANG : ""); 43 setlocale(LC_CTYPE, LANG ? LANG : "");
44 44
45 /* In unicode, this is a one character string */ 45 /* In unicode, this is a one character string */
46// can use unicode_strlen(string) too, but otherwise unicode_strlen() is unused 46 width = unicode_strlen(unicode_0x394);
47 width = mbstowcs(NULL, unicode_0x394, INT_MAX);
48 unicode_status = (width == 1 ? UNICODE_ON : UNICODE_OFF); 47 unicode_status = (width == 1 ? UNICODE_ON : UNICODE_OFF);
49} 48}
50 49
@@ -986,7 +985,6 @@ int FAST_FUNC unicode_bidi_is_neutral_wchar(wint_t wc)
986 985
987/* The rest is mostly same for libc and for "homegrown" support */ 986/* The rest is mostly same for libc and for "homegrown" support */
988 987
989#if 0 // UNUSED
990size_t FAST_FUNC unicode_strlen(const char *string) 988size_t FAST_FUNC unicode_strlen(const char *string)
991{ 989{
992 size_t width = mbstowcs(NULL, string, INT_MAX); 990 size_t width = mbstowcs(NULL, string, INT_MAX);
@@ -994,7 +992,6 @@ size_t FAST_FUNC unicode_strlen(const char *string)
994 return strlen(string); 992 return strlen(string);
995 return width; 993 return width;
996} 994}
997#endif
998 995
999size_t FAST_FUNC unicode_strwidth(const char *string) 996size_t FAST_FUNC unicode_strwidth(const char *string)
1000{ 997{