if we don't have setlocale(), just look at the env vars ourselves

This commit is contained in:
tg 2008-05-04 01:58:15 +00:00
parent 604ec0ff6c
commit c5db7903dd
3 changed files with 20 additions and 7 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.317 2008/05/04 01:51:28 tg Exp $' srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.318 2008/05/04 01:58:14 tg Exp $'
#- #-
# Environment used: CC CFLAGS CPPFLAGS LDFLAGS LIBS NOWARN NROFF TARGET_OS # Environment used: CC CFLAGS CPPFLAGS LDFLAGS LIBS NOWARN NROFF TARGET_OS
# CPPFLAGS recognised: MKSH_SMALL MKSH_ASSUME_UTF8 MKSH_NOPWNAM MKSH_NOVI # CPPFLAGS recognised: MKSH_SMALL MKSH_ASSUME_UTF8 MKSH_NOPWNAM MKSH_NOVI
@ -830,7 +830,7 @@ if test 0 = $HAVE_MKSH_FULL; then
ac_flags 1 fnoinline -fno-inline ac_flags 1 fnoinline -fno-inline
fi fi
: ${HAVE_MKNOD=0} ${HAVE_SETLOCALE_CTYPE=0} : ${HAVE_MKNOD=0}
check_categories=$check_categories,smksh check_categories=$check_categories,smksh
fi fi
@ -1070,7 +1070,7 @@ ac_test setgroups setresugid 0 <<-'EOF'
int main(void) { gid_t gid = 0; return (setgroups(0, &gid)); } int main(void) { gid_t gid = 0; return (setgroups(0, &gid)); }
EOF EOF
ac_test strcasestr setlocale_ctype 1 <<-'EOF' ac_test strcasestr <<-'EOF'
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
int main(int ac, char *av[]) { int main(int ac, char *av[]) {

13
main.c
View File

@ -13,7 +13,7 @@
#include <locale.h> #include <locale.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.95 2008/04/01 20:40:21 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/main.c,v 1.96 2008/05/04 01:58:14 tg Exp $");
extern char **environ; extern char **environ;
@ -285,22 +285,29 @@ main(int argc, const char *argv[])
/* Do this after j_init(), as tty_fd is not initialised 'til then */ /* Do this after j_init(), as tty_fd is not initialised 'til then */
if (Flag(FTALKING)) { if (Flag(FTALKING)) {
#ifndef MKSH_ASSUME_UTF8 #ifndef MKSH_ASSUME_UTF8
#if HAVE_SETLOCALE_CTYPE
#define isuc(x) (((x) != NULL) && \ #define isuc(x) (((x) != NULL) && \
(stristr((x), "UTF-8") || stristr((x), "utf8"))) (stristr((x), "UTF-8") || stristr((x), "utf8")))
/* Check if we're in a UTF-8 locale */ /* Check if we're in a UTF-8 locale */
if (!Flag(FUTFHACK)) { if (!Flag(FUTFHACK)) {
const char *ccp; const char *ccp;
#if HAVE_SETLOCALE_CTYPE
ccp = setlocale(LC_CTYPE, ""); ccp = setlocale(LC_CTYPE, "");
#if HAVE_LANGINFO_CODESET #if HAVE_LANGINFO_CODESET
if (!isuc(ccp)) if (!isuc(ccp))
ccp = nl_langinfo(CODESET); ccp = nl_langinfo(CODESET);
#endif
#else
ccp = getenv("LC_ALL");
if (!ccp || !*ccp) {
ccp = getenv("LC_CTYPE");
if (!ccp || !*ccp)
ccp = getenv("LANG");
}
#endif #endif
Flag(FUTFHACK) = isuc(ccp); Flag(FUTFHACK) = isuc(ccp);
} }
#undef isuc #undef isuc
#endif
#else #else
Flag(FUTFHACK) = 1; Flag(FUTFHACK) = 1;
#endif #endif

8
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.124 2008/05/04 01:51:30 tg Exp $ .\" $MirOS: src/bin/mksh/mksh.1,v 1.125 2008/05/04 01:58:15 tg Exp $
.\" $OpenBSD: ksh.1,v 1.121 2008/03/21 12:51:19 millert Exp $ .\" $OpenBSD: ksh.1,v 1.121 2008/03/21 12:51:19 millert Exp $
.\"- .\"-
.\" Try to make GNU groff and AT&T nroff more compatible .\" Try to make GNU groff and AT&T nroff more compatible
@ -3422,6 +3422,12 @@ This is enabled automatically for interactive shells if your system supports
.Fn setlocale LC_CTYPE \&"" .Fn setlocale LC_CTYPE \&""
and optionally and optionally
.Fn nl_langinfo CODESET , .Fn nl_langinfo CODESET ,
or the
.Ev LC_ALL ,
.Ev LC_CTYPE ,
or
.Ev LANG
environment variables,
and at least one of these returns something that matches and at least one of these returns something that matches
.Dq UTF\-8 .Dq UTF\-8
or or