aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-03-23 17:59:27 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-03-23 17:59:27 +0100
commit20704f066250744c0c2b84920c27d0fd0aa9e935 (patch)
tree8a76e56e4be0beb84dbe993922d4be86ab694350
parent7f4b769c42f3773ff2e2e749547291dcb7e85d01 (diff)
downloadbusybox-w32-20704f066250744c0c2b84920c27d0fd0aa9e935.tar.gz
busybox-w32-20704f066250744c0c2b84920c27d0fd0aa9e935.tar.bz2
busybox-w32-20704f066250744c0c2b84920c27d0fd0aa9e935.zip
ash,hush: recheck LANG before every line input
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/unicode.h4
-rw-r--r--libbb/unicode.c28
-rw-r--r--shell/ash.c23
-rw-r--r--shell/hush.c25
4 files changed, 52 insertions, 28 deletions
diff --git a/include/unicode.h b/include/unicode.h
index dee02e777..0317a2151 100644
--- a/include/unicode.h
+++ b/include/unicode.h
@@ -27,6 +27,7 @@ enum {
27# define unicode_strwidth(string) strlen(string) 27# define unicode_strwidth(string) strlen(string)
28# define unicode_status UNICODE_OFF 28# define unicode_status UNICODE_OFF
29# define init_unicode() ((void)0) 29# define init_unicode() ((void)0)
30# define reinit_unicode(LANG) ((void)0)
30 31
31#else 32#else
32 33
@@ -67,6 +68,7 @@ char* FAST_FUNC unicode_conv_to_printable_fixedwidth(/*uni_stat_t *stats,*/ cons
67 68
68extern uint8_t unicode_status; 69extern uint8_t unicode_status;
69void init_unicode(void) FAST_FUNC; 70void init_unicode(void) FAST_FUNC;
71void reinit_unicode(const char *LANG) FAST_FUNC;
70 72
71# else 73# else
72 74
@@ -75,9 +77,11 @@ void init_unicode(void) FAST_FUNC;
75# if !ENABLE_FEATURE_CHECK_UNICODE_IN_ENV 77# if !ENABLE_FEATURE_CHECK_UNICODE_IN_ENV
76# define unicode_status UNICODE_ON 78# define unicode_status UNICODE_ON
77# define init_unicode() ((void)0) 79# define init_unicode() ((void)0)
80# define reinit_unicode(LANG) ((void)0)
78# else 81# else
79extern uint8_t unicode_status; 82extern uint8_t unicode_status;
80void init_unicode(void) FAST_FUNC; 83void init_unicode(void) FAST_FUNC;
84void reinit_unicode(const char *LANG) FAST_FUNC;
81# endif 85# endif
82 86
83# undef MB_CUR_MAX 87# undef MB_CUR_MAX
diff --git a/libbb/unicode.c b/libbb/unicode.c
index 08a4c7427..d01efd9a2 100644
--- a/libbb/unicode.c
+++ b/libbb/unicode.c
@@ -23,37 +23,43 @@ uint8_t unicode_status;
23 23
24/* Unicode support using libc locale support. */ 24/* Unicode support using libc locale support. */
25 25
26void FAST_FUNC init_unicode(void) 26void FAST_FUNC reinit_unicode(const char *LANG UNUSED_PARAM)
27{ 27{
28 static const char unicode_0x394[] = { 0xce, 0x94, 0 }; 28 static const char unicode_0x394[] = { 0xce, 0x94, 0 };
29 size_t width; 29 size_t width;
30 30
31 if (unicode_status != UNICODE_UNKNOWN) 31//TODO: call setlocale(LC_ALL, LANG) here?
32 return; 32
33 /* In unicode, this is a one character string */ 33 /* In unicode, this is a one character string */
34// can use unicode_strlen(string) too, but otherwise unicode_strlen() is unused 34// can use unicode_strlen(string) too, but otherwise unicode_strlen() is unused
35 width = mbstowcs(NULL, unicode_0x394, INT_MAX); 35 width = mbstowcs(NULL, unicode_0x394, INT_MAX);
36 unicode_status = (width == 1 ? UNICODE_ON : UNICODE_OFF); 36 unicode_status = (width == 1 ? UNICODE_ON : UNICODE_OFF);
37} 37}
38 38
39void FAST_FUNC init_unicode(void)
40{
41 if (unicode_status == UNICODE_UNKNOWN)
42 reinit_unicode(NULL /*getenv("LANG")*/);
43}
44
39#else 45#else
40 46
41/* Homegrown Unicode support. It knows only C and Unicode locales. */ 47/* Homegrown Unicode support. It knows only C and Unicode locales. */
42 48
43# if ENABLE_FEATURE_CHECK_UNICODE_IN_ENV 49# if ENABLE_FEATURE_CHECK_UNICODE_IN_ENV
44void FAST_FUNC init_unicode(void) 50void FAST_FUNC reinit_unicode(const char *LANG)
45{ 51{
46 char *lang;
47
48 if (unicode_status != UNICODE_UNKNOWN)
49 return;
50
51 unicode_status = UNICODE_OFF; 52 unicode_status = UNICODE_OFF;
52 lang = getenv("LANG"); 53 if (!LANG || !(strstr(LANG, ".utf") || strstr(LANG, ".UTF")))
53 if (!lang || !(strstr(lang, ".utf") || strstr(lang, ".UTF")))
54 return; 54 return;
55 unicode_status = UNICODE_ON; 55 unicode_status = UNICODE_ON;
56} 56}
57
58void FAST_FUNC init_unicode(void)
59{
60 if (unicode_status == UNICODE_UNKNOWN)
61 reinit_unicode(getenv("LANG"));
62}
57# endif 63# endif
58 64
59static size_t wcrtomb_internal(char *s, wchar_t wc) 65static size_t wcrtomb_internal(char *s, wchar_t wc)
diff --git a/shell/ash.c b/shell/ash.c
index 0baf7c8e5..1520c5ae5 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -36,12 +36,14 @@
36 36
37#define JOBS ENABLE_ASH_JOB_CONTROL 37#define JOBS ENABLE_ASH_JOB_CONTROL
38 38
39#include "busybox.h" /* for applet_names */
40#include <paths.h> 39#include <paths.h>
41#include <setjmp.h> 40#include <setjmp.h>
42#include <fnmatch.h> 41#include <fnmatch.h>
43#include <sys/times.h> 42#include <sys/times.h>
44 43
44#include "busybox.h" /* for applet_names */
45#include "unicode.h"
46
45#include "shell_common.h" 47#include "shell_common.h"
46#if ENABLE_SH_MATH_SUPPORT 48#if ENABLE_SH_MATH_SUPPORT
47# include "math.h" 49# include "math.h"
@@ -72,13 +74,6 @@
72# error "Do not even bother, ash will not run on NOMMU machine" 74# error "Do not even bother, ash will not run on NOMMU machine"
73#endif 75#endif
74 76
75//applet:IF_ASH(APPLET(ash, BB_DIR_BIN, BB_SUID_DROP))
76//applet:IF_FEATURE_SH_IS_ASH(APPLET_ODDNAME(sh, ash, BB_DIR_BIN, BB_SUID_DROP, sh))
77//applet:IF_FEATURE_BASH_IS_ASH(APPLET_ODDNAME(bash, ash, BB_DIR_BIN, BB_SUID_DROP, bash))
78
79//kbuild:lib-$(CONFIG_ASH) += ash.o ash_ptr_hack.o shell_common.o
80//kbuild:lib-$(CONFIG_ASH_RANDOM_SUPPORT) += random.o
81
82//config:config ASH 77//config:config ASH
83//config: bool "ash" 78//config: bool "ash"
84//config: default y 79//config: default y
@@ -190,6 +185,13 @@
190//config: variable each time it is displayed. 185//config: variable each time it is displayed.
191//config: 186//config:
192 187
188//applet:IF_ASH(APPLET(ash, BB_DIR_BIN, BB_SUID_DROP))
189//applet:IF_FEATURE_SH_IS_ASH(APPLET_ODDNAME(sh, ash, BB_DIR_BIN, BB_SUID_DROP, sh))
190//applet:IF_FEATURE_BASH_IS_ASH(APPLET_ODDNAME(bash, ash, BB_DIR_BIN, BB_SUID_DROP, bash))
191
192//kbuild:lib-$(CONFIG_ASH) += ash.o ash_ptr_hack.o shell_common.o
193//kbuild:lib-$(CONFIG_ASH_RANDOM_SUPPORT) += random.o
194
193 195
194/* ============ Hash table sizes. Configurable. */ 196/* ============ Hash table sizes. Configurable. */
195 197
@@ -9626,6 +9628,11 @@ preadfd(void)
9626# if ENABLE_FEATURE_TAB_COMPLETION 9628# if ENABLE_FEATURE_TAB_COMPLETION
9627 line_input_state->path_lookup = pathval(); 9629 line_input_state->path_lookup = pathval();
9628# endif 9630# endif
9631 /* Unicode support should be activated even if LANG is set
9632 * _during_ shell execution, not only if it was set when
9633 * shell was started. Therefore, re-check LANG every time:
9634 */
9635 reinit_unicode(lookupvar("LANG"));
9629 nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ, timeout); 9636 nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ, timeout);
9630 if (nr == 0) { 9637 if (nr == 0) {
9631 /* Ctrl+C pressed */ 9638 /* Ctrl+C pressed */
diff --git a/shell/hush.c b/shell/hush.c
index 64d5e8587..339f3349a 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -81,7 +81,6 @@
81 * $ "export" i=`echo 'aaa bbb'`; echo "$i" 81 * $ "export" i=`echo 'aaa bbb'`; echo "$i"
82 * aaa 82 * aaa
83 */ 83 */
84#include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */
85#if !(defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \ 84#if !(defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \
86 || defined(__APPLE__) \ 85 || defined(__APPLE__) \
87 ) 86 )
@@ -93,6 +92,8 @@
93# include <fnmatch.h> 92# include <fnmatch.h>
94#endif 93#endif
95 94
95#include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */
96#include "unicode.h"
96#include "shell_common.h" 97#include "shell_common.h"
97#include "math.h" 98#include "math.h"
98#include "match.h" 99#include "match.h"
@@ -105,14 +106,6 @@
105# define PIPE_BUF 4096 /* amount of buffering in a pipe */ 106# define PIPE_BUF 4096 /* amount of buffering in a pipe */
106#endif 107#endif
107 108
108//applet:IF_HUSH(APPLET(hush, BB_DIR_BIN, BB_SUID_DROP))
109//applet:IF_MSH(APPLET(msh, BB_DIR_BIN, BB_SUID_DROP))
110//applet:IF_FEATURE_SH_IS_HUSH(APPLET_ODDNAME(sh, hush, BB_DIR_BIN, BB_SUID_DROP, sh))
111//applet:IF_FEATURE_BASH_IS_HUSH(APPLET_ODDNAME(bash, hush, BB_DIR_BIN, BB_SUID_DROP, bash))
112
113//kbuild:lib-$(CONFIG_HUSH) += hush.o match.o shell_common.o
114//kbuild:lib-$(CONFIG_HUSH_RANDOM_SUPPORT) += random.o
115
116//config:config HUSH 109//config:config HUSH
117//config: bool "hush" 110//config: bool "hush"
118//config: default y 111//config: default y
@@ -249,6 +242,14 @@
249//config: msh is deprecated and will be removed, please migrate to hush. 242//config: msh is deprecated and will be removed, please migrate to hush.
250//config: 243//config:
251 244
245//applet:IF_HUSH(APPLET(hush, BB_DIR_BIN, BB_SUID_DROP))
246//applet:IF_MSH(APPLET(msh, BB_DIR_BIN, BB_SUID_DROP))
247//applet:IF_FEATURE_SH_IS_HUSH(APPLET_ODDNAME(sh, hush, BB_DIR_BIN, BB_SUID_DROP, sh))
248//applet:IF_FEATURE_BASH_IS_HUSH(APPLET_ODDNAME(bash, hush, BB_DIR_BIN, BB_SUID_DROP, bash))
249
250//kbuild:lib-$(CONFIG_HUSH) += hush.o match.o shell_common.o
251//kbuild:lib-$(CONFIG_HUSH_RANDOM_SUPPORT) += random.o
252
252/* -i (interactive) and -s (read stdin) are also accepted, 253/* -i (interactive) and -s (read stdin) are also accepted,
253 * but currently do nothing, therefore aren't shown in help. 254 * but currently do nothing, therefore aren't shown in help.
254 * NOMMU-specific options are not meant to be used by users, 255 * NOMMU-specific options are not meant to be used by users,
@@ -1906,6 +1907,12 @@ static void get_user_input(struct in_str *i)
1906 /* Enable command line editing only while a command line 1907 /* Enable command line editing only while a command line
1907 * is actually being read */ 1908 * is actually being read */
1908 do { 1909 do {
1910 /* Unicode support should be activated even if LANG is set
1911 * _during_ shell execution, not only if it was set when
1912 * shell was started. Therefore, re-check LANG every time:
1913 */
1914 reinit_unicode(get_local_var_value("LANG"));
1915
1909 G.flag_SIGINT = 0; 1916 G.flag_SIGINT = 0;
1910 /* buglet: SIGINT will not make new prompt to appear _at once_, 1917 /* buglet: SIGINT will not make new prompt to appear _at once_,
1911 * only after <Enter>. (^C will work) */ 1918 * only after <Enter>. (^C will work) */