ash,hush: recheck LANG before every line input
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
7f4b769c42
commit
20704f0662
@ -27,6 +27,7 @@ enum {
|
||||
# define unicode_strwidth(string) strlen(string)
|
||||
# define unicode_status UNICODE_OFF
|
||||
# define init_unicode() ((void)0)
|
||||
# define reinit_unicode(LANG) ((void)0)
|
||||
|
||||
#else
|
||||
|
||||
@ -67,6 +68,7 @@ char* FAST_FUNC unicode_conv_to_printable_fixedwidth(/*uni_stat_t *stats,*/ cons
|
||||
|
||||
extern uint8_t unicode_status;
|
||||
void init_unicode(void) FAST_FUNC;
|
||||
void reinit_unicode(const char *LANG) FAST_FUNC;
|
||||
|
||||
# else
|
||||
|
||||
@ -75,9 +77,11 @@ void init_unicode(void) FAST_FUNC;
|
||||
# if !ENABLE_FEATURE_CHECK_UNICODE_IN_ENV
|
||||
# define unicode_status UNICODE_ON
|
||||
# define init_unicode() ((void)0)
|
||||
# define reinit_unicode(LANG) ((void)0)
|
||||
# else
|
||||
extern uint8_t unicode_status;
|
||||
void init_unicode(void) FAST_FUNC;
|
||||
void reinit_unicode(const char *LANG) FAST_FUNC;
|
||||
# endif
|
||||
|
||||
# undef MB_CUR_MAX
|
||||
|
@ -23,37 +23,43 @@ uint8_t unicode_status;
|
||||
|
||||
/* Unicode support using libc locale support. */
|
||||
|
||||
void FAST_FUNC init_unicode(void)
|
||||
void FAST_FUNC reinit_unicode(const char *LANG UNUSED_PARAM)
|
||||
{
|
||||
static const char unicode_0x394[] = { 0xce, 0x94, 0 };
|
||||
size_t width;
|
||||
|
||||
if (unicode_status != UNICODE_UNKNOWN)
|
||||
return;
|
||||
//TODO: call setlocale(LC_ALL, LANG) here?
|
||||
|
||||
/* In unicode, this is a one character string */
|
||||
// can use unicode_strlen(string) too, but otherwise unicode_strlen() is unused
|
||||
width = mbstowcs(NULL, unicode_0x394, INT_MAX);
|
||||
unicode_status = (width == 1 ? UNICODE_ON : UNICODE_OFF);
|
||||
}
|
||||
|
||||
void FAST_FUNC init_unicode(void)
|
||||
{
|
||||
if (unicode_status == UNICODE_UNKNOWN)
|
||||
reinit_unicode(NULL /*getenv("LANG")*/);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* Homegrown Unicode support. It knows only C and Unicode locales. */
|
||||
|
||||
# if ENABLE_FEATURE_CHECK_UNICODE_IN_ENV
|
||||
void FAST_FUNC init_unicode(void)
|
||||
void FAST_FUNC reinit_unicode(const char *LANG)
|
||||
{
|
||||
char *lang;
|
||||
|
||||
if (unicode_status != UNICODE_UNKNOWN)
|
||||
return;
|
||||
|
||||
unicode_status = UNICODE_OFF;
|
||||
lang = getenv("LANG");
|
||||
if (!lang || !(strstr(lang, ".utf") || strstr(lang, ".UTF")))
|
||||
if (!LANG || !(strstr(LANG, ".utf") || strstr(LANG, ".UTF")))
|
||||
return;
|
||||
unicode_status = UNICODE_ON;
|
||||
}
|
||||
|
||||
void FAST_FUNC init_unicode(void)
|
||||
{
|
||||
if (unicode_status == UNICODE_UNKNOWN)
|
||||
reinit_unicode(getenv("LANG"));
|
||||
}
|
||||
# endif
|
||||
|
||||
static size_t wcrtomb_internal(char *s, wchar_t wc)
|
||||
|
23
shell/ash.c
23
shell/ash.c
@ -36,12 +36,14 @@
|
||||
|
||||
#define JOBS ENABLE_ASH_JOB_CONTROL
|
||||
|
||||
#include "busybox.h" /* for applet_names */
|
||||
#include <paths.h>
|
||||
#include <setjmp.h>
|
||||
#include <fnmatch.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
#include "busybox.h" /* for applet_names */
|
||||
#include "unicode.h"
|
||||
|
||||
#include "shell_common.h"
|
||||
#if ENABLE_SH_MATH_SUPPORT
|
||||
# include "math.h"
|
||||
@ -72,13 +74,6 @@
|
||||
# error "Do not even bother, ash will not run on NOMMU machine"
|
||||
#endif
|
||||
|
||||
//applet:IF_ASH(APPLET(ash, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_FEATURE_SH_IS_ASH(APPLET_ODDNAME(sh, ash, BB_DIR_BIN, BB_SUID_DROP, sh))
|
||||
//applet:IF_FEATURE_BASH_IS_ASH(APPLET_ODDNAME(bash, ash, BB_DIR_BIN, BB_SUID_DROP, bash))
|
||||
|
||||
//kbuild:lib-$(CONFIG_ASH) += ash.o ash_ptr_hack.o shell_common.o
|
||||
//kbuild:lib-$(CONFIG_ASH_RANDOM_SUPPORT) += random.o
|
||||
|
||||
//config:config ASH
|
||||
//config: bool "ash"
|
||||
//config: default y
|
||||
@ -190,6 +185,13 @@
|
||||
//config: variable each time it is displayed.
|
||||
//config:
|
||||
|
||||
//applet:IF_ASH(APPLET(ash, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_FEATURE_SH_IS_ASH(APPLET_ODDNAME(sh, ash, BB_DIR_BIN, BB_SUID_DROP, sh))
|
||||
//applet:IF_FEATURE_BASH_IS_ASH(APPLET_ODDNAME(bash, ash, BB_DIR_BIN, BB_SUID_DROP, bash))
|
||||
|
||||
//kbuild:lib-$(CONFIG_ASH) += ash.o ash_ptr_hack.o shell_common.o
|
||||
//kbuild:lib-$(CONFIG_ASH_RANDOM_SUPPORT) += random.o
|
||||
|
||||
|
||||
/* ============ Hash table sizes. Configurable. */
|
||||
|
||||
@ -9626,6 +9628,11 @@ preadfd(void)
|
||||
# if ENABLE_FEATURE_TAB_COMPLETION
|
||||
line_input_state->path_lookup = pathval();
|
||||
# endif
|
||||
/* Unicode support should be activated even if LANG is set
|
||||
* _during_ shell execution, not only if it was set when
|
||||
* shell was started. Therefore, re-check LANG every time:
|
||||
*/
|
||||
reinit_unicode(lookupvar("LANG"));
|
||||
nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ, timeout);
|
||||
if (nr == 0) {
|
||||
/* Ctrl+C pressed */
|
||||
|
25
shell/hush.c
25
shell/hush.c
@ -81,7 +81,6 @@
|
||||
* $ "export" i=`echo 'aaa bbb'`; echo "$i"
|
||||
* aaa
|
||||
*/
|
||||
#include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */
|
||||
#if !(defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \
|
||||
|| defined(__APPLE__) \
|
||||
)
|
||||
@ -93,6 +92,8 @@
|
||||
# include <fnmatch.h>
|
||||
#endif
|
||||
|
||||
#include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */
|
||||
#include "unicode.h"
|
||||
#include "shell_common.h"
|
||||
#include "math.h"
|
||||
#include "match.h"
|
||||
@ -105,14 +106,6 @@
|
||||
# define PIPE_BUF 4096 /* amount of buffering in a pipe */
|
||||
#endif
|
||||
|
||||
//applet:IF_HUSH(APPLET(hush, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_MSH(APPLET(msh, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_FEATURE_SH_IS_HUSH(APPLET_ODDNAME(sh, hush, BB_DIR_BIN, BB_SUID_DROP, sh))
|
||||
//applet:IF_FEATURE_BASH_IS_HUSH(APPLET_ODDNAME(bash, hush, BB_DIR_BIN, BB_SUID_DROP, bash))
|
||||
|
||||
//kbuild:lib-$(CONFIG_HUSH) += hush.o match.o shell_common.o
|
||||
//kbuild:lib-$(CONFIG_HUSH_RANDOM_SUPPORT) += random.o
|
||||
|
||||
//config:config HUSH
|
||||
//config: bool "hush"
|
||||
//config: default y
|
||||
@ -249,6 +242,14 @@
|
||||
//config: msh is deprecated and will be removed, please migrate to hush.
|
||||
//config:
|
||||
|
||||
//applet:IF_HUSH(APPLET(hush, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_MSH(APPLET(msh, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_FEATURE_SH_IS_HUSH(APPLET_ODDNAME(sh, hush, BB_DIR_BIN, BB_SUID_DROP, sh))
|
||||
//applet:IF_FEATURE_BASH_IS_HUSH(APPLET_ODDNAME(bash, hush, BB_DIR_BIN, BB_SUID_DROP, bash))
|
||||
|
||||
//kbuild:lib-$(CONFIG_HUSH) += hush.o match.o shell_common.o
|
||||
//kbuild:lib-$(CONFIG_HUSH_RANDOM_SUPPORT) += random.o
|
||||
|
||||
/* -i (interactive) and -s (read stdin) are also accepted,
|
||||
* but currently do nothing, therefore aren't shown in help.
|
||||
* NOMMU-specific options are not meant to be used by users,
|
||||
@ -1906,6 +1907,12 @@ static void get_user_input(struct in_str *i)
|
||||
/* Enable command line editing only while a command line
|
||||
* is actually being read */
|
||||
do {
|
||||
/* Unicode support should be activated even if LANG is set
|
||||
* _during_ shell execution, not only if it was set when
|
||||
* shell was started. Therefore, re-check LANG every time:
|
||||
*/
|
||||
reinit_unicode(get_local_var_value("LANG"));
|
||||
|
||||
G.flag_SIGINT = 0;
|
||||
/* buglet: SIGINT will not make new prompt to appear _at once_,
|
||||
* only after <Enter>. (^C will work) */
|
||||
|
Loading…
Reference in New Issue
Block a user