X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=lib%2Freadline%2Fnls.c;h=d3b36344f103b20945158f2e8a3db7a8a993d5f7;hb=ac50fbac377e32b98d2de396f016ea81e8ee9961;hp=e3599eb76f4295f3f8327632cee4c35170c2a1e6;hpb=4539d736f1aff232857a854fd2a68df0c98d9f34;p=platform%2Fupstream%2Fbash.git diff --git a/lib/readline/nls.c b/lib/readline/nls.c index e3599eb..d3b3634 100644 --- a/lib/readline/nls.c +++ b/lib/readline/nls.c @@ -43,6 +43,10 @@ # include #endif +#if defined (HAVE_LANGINFO_CODESET) +# include +#endif + #include #include "rldefs.h" @@ -50,6 +54,8 @@ #include "rlshell.h" #include "rlprivate.h" +static int utf8locale PARAMS((char *)); + #if !defined (HAVE_SETLOCALE) /* A list of legal values for the LANG or LC_CTYPE environment variables. If a locale name in this list is the value for the LC_ALL, LC_CTYPE, @@ -72,9 +78,10 @@ static char *legal_lang_values[] = }; static char *normalize_codeset PARAMS((char *)); -static char *find_codeset PARAMS((char *, size_t *)); #endif /* !HAVE_SETLOCALE */ +static char *find_codeset PARAMS((char *, size_t *)); + static char *_rl_get_locale_var PARAMS((const char *)); static char * @@ -91,7 +98,26 @@ _rl_get_locale_var (v) return lspec; } - + +static int +utf8locale (lspec) + char *lspec; +{ + char *cp; + size_t len; + +#if HAVE_LANGINFO_CODESET + cp = nl_langinfo (CODESET); + return (STREQ (cp, "UTF-8") || STREQ (cp, "utf8")); +#else + cp = find_codeset (lspec, &len); + + if (cp == 0 || len < 4 || len > 5) + return 0; + return ((len == 5) ? strncmp (cp, "UTF-8", len) == 0 : strncmp (cp, "utf8", 4) == 0); +#endif +} + /* Check for LC_ALL, LC_CTYPE, and LANG and use the first with a value to decide the defaults for 8-bit character input and output. Returns 1 if we set eight-bit mode. */ @@ -116,6 +142,9 @@ _rl_init_eightbit () lspec = ""; t = setlocale (LC_CTYPE, lspec); + if (t && *t) + _rl_utf8locale = utf8locale (t); + if (t && *t && (t[0] != 'C' || t[1]) && (STREQ (t, "POSIX") == 0)) { _rl_meta_flag = 1; @@ -197,6 +226,7 @@ normalize_codeset (codeset) return retval; } +#endif /* !HAVE_SETLOCALE */ /* Isolate codeset portion of locale specification. */ static char * @@ -249,4 +279,3 @@ find_codeset (name, lenp) return result; } -#endif /* !HAVE_SETLOCALE */