diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2014-08-13 18:00:08 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-08-13 18:00:08 +0200 |
commit | e9ab07c211b283c0f798628858eaaef93a4893aa (patch) | |
tree | 9b1afa5a5dcac89c3e78337c4894eba4fa42fd0c /shell | |
parent | 841f8331d79c642b4268dae52c382fab2da9cddc (diff) | |
download | busybox-w32-e9ab07c211b283c0f798628858eaaef93a4893aa.tar.gz busybox-w32-e9ab07c211b283c0f798628858eaaef93a4893aa.tar.bz2 busybox-w32-e9ab07c211b283c0f798628858eaaef93a4893aa.zip |
ash: make ${#var} unicode-aware
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/shell/ash.c b/shell/ash.c index 3b8aac553..4ead6f990 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -2121,6 +2121,22 @@ lookupvar(const char *name) | |||
2121 | return NULL; | 2121 | return NULL; |
2122 | } | 2122 | } |
2123 | 2123 | ||
2124 | static void reinit_unicode_for_ash(void) | ||
2125 | { | ||
2126 | /* Unicode support should be activated even if LANG is set | ||
2127 | * _during_ shell execution, not only if it was set when | ||
2128 | * shell was started. Therefore, re-check LANG every time: | ||
2129 | */ | ||
2130 | if (ENABLE_FEATURE_CHECK_UNICODE_IN_ENV | ||
2131 | || ENABLE_UNICODE_USING_LOCALE | ||
2132 | ) { | ||
2133 | const char *s = lookupvar("LC_ALL"); | ||
2134 | if (!s) s = lookupvar("LC_CTYPE"); | ||
2135 | if (!s) s = lookupvar("LANG"); | ||
2136 | reinit_unicode(s); | ||
2137 | } | ||
2138 | } | ||
2139 | |||
2124 | /* | 2140 | /* |
2125 | * Search the environment of a builtin command. | 2141 | * Search the environment of a builtin command. |
2126 | */ | 2142 | */ |
@@ -6798,7 +6814,15 @@ evalvar(char *p, int flags, struct strlist *var_str_list) | |||
6798 | varunset(p, var, 0, 0); | 6814 | varunset(p, var, 0, 0); |
6799 | 6815 | ||
6800 | if (subtype == VSLENGTH) { | 6816 | if (subtype == VSLENGTH) { |
6801 | cvtnum(varlen > 0 ? varlen : 0); | 6817 | ssize_t n = varlen; |
6818 | if (n > 0) { | ||
6819 | reinit_unicode_for_ash(); | ||
6820 | if (unicode_status == UNICODE_ON) { | ||
6821 | const char *val = lookupvar(var); | ||
6822 | n = unicode_strlen(val); | ||
6823 | } | ||
6824 | } | ||
6825 | cvtnum(n > 0 ? n : 0); | ||
6802 | goto record; | 6826 | goto record; |
6803 | } | 6827 | } |
6804 | 6828 | ||
@@ -9657,18 +9681,7 @@ preadfd(void) | |||
9657 | # if ENABLE_FEATURE_TAB_COMPLETION | 9681 | # if ENABLE_FEATURE_TAB_COMPLETION |
9658 | line_input_state->path_lookup = pathval(); | 9682 | line_input_state->path_lookup = pathval(); |
9659 | # endif | 9683 | # endif |
9660 | /* Unicode support should be activated even if LANG is set | 9684 | reinit_unicode_for_ash(); |
9661 | * _during_ shell execution, not only if it was set when | ||
9662 | * shell was started. Therefore, re-check LANG every time: | ||
9663 | */ | ||
9664 | if (ENABLE_FEATURE_CHECK_UNICODE_IN_ENV | ||
9665 | || ENABLE_UNICODE_USING_LOCALE | ||
9666 | ) { | ||
9667 | const char *s = lookupvar("LC_ALL"); | ||
9668 | if (!s) s = lookupvar("LC_CTYPE"); | ||
9669 | if (!s) s = lookupvar("LANG"); | ||
9670 | reinit_unicode(s); | ||
9671 | } | ||
9672 | nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ, timeout); | 9685 | nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ, timeout); |
9673 | if (nr == 0) { | 9686 | if (nr == 0) { |
9674 | /* Ctrl+C pressed */ | 9687 | /* Ctrl+C pressed */ |