Mercurial > vim
diff src/mbyte.c @ 12547:aa3f6d093f4b v8.0.1152
patch 8.0.1152: encoding of error message wrong in Cygwin terminal
commit https://github.com/vim/vim/commit/2a02745709127bd56ccdbac8c568b3c25f3072a7
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Sep 26 19:10:37 2017 +0200
patch 8.0.1152: encoding of error message wrong in Cygwin terminal
Problem: Encoding of error message wrong in Cygwin terminal.
Solution: Get locale from environment variables. (Ken Takata)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 26 Sep 2017 19:15:05 +0200 |
parents | 683fdeb89017 |
children | f58755eb453e |
line wrap: on
line diff
--- a/src/mbyte.c +++ b/src/mbyte.c @@ -4385,45 +4385,31 @@ enc_alias_search(char_u *name) #if defined(FEAT_MBYTE) || defined(PROTO) -#ifdef HAVE_LANGINFO_H -# include <langinfo.h> -#endif - +# ifdef HAVE_LANGINFO_H +# include <langinfo.h> +# endif + +# ifndef FEAT_GUI_W32 /* - * Get the canonicalized encoding of the current locale. + * Get the canonicalized encoding from the specified locale string "locale" + * or from the environment variables LC_ALL, LC_CTYPE and LANG. * Returns an allocated string when successful, NULL when not. */ char_u * -enc_locale(void) -{ -#ifndef WIN3264 - char *s; +enc_locale_env(char *locale) +{ + char *s = locale; char *p; int i; -#endif char buf[50]; -#ifdef WIN3264 - long acp = GetACP(); - - if (acp == 1200) - STRCPY(buf, "ucs-2le"); - else if (acp == 1252) /* cp1252 is used as latin1 */ - STRCPY(buf, "latin1"); - else - sprintf(buf, "cp%ld", acp); -#else -# ifdef HAVE_NL_LANGINFO_CODESET - if ((s = nl_langinfo(CODESET)) == NULL || *s == NUL) -# endif -# if defined(HAVE_LOCALE_H) || defined(X_LOCALE) - if ((s = setlocale(LC_CTYPE, NULL)) == NULL || *s == NUL) -# endif - if ((s = getenv("LC_ALL")) == NULL || *s == NUL) - if ((s = getenv("LC_CTYPE")) == NULL || *s == NUL) - s = getenv("LANG"); if (s == NULL || *s == NUL) - return FAIL; + if ((s = getenv("LC_ALL")) == NULL || *s == NUL) + if ((s = getenv("LC_CTYPE")) == NULL || *s == NUL) + s = getenv("LANG"); + + if (s == NULL || *s == NUL) + return NULL; /* The most generic locale format is: * language[_territory][.codeset][@modifier][+special][,[sponsor][_revision]] @@ -4458,12 +4444,46 @@ enc_locale(void) break; } buf[i] = NUL; -#endif return enc_canonize((char_u *)buf); } - -#if defined(WIN3264) || defined(PROTO) || defined(FEAT_CYGWIN_WIN32_CLIPBOARD) +# endif + +/* + * Get the canonicalized encoding of the current locale. + * Returns an allocated string when successful, NULL when not. + */ + char_u * +enc_locale(void) +{ +# ifdef WIN3264 + char buf[50]; + long acp = GetACP(); + + if (acp == 1200) + STRCPY(buf, "ucs-2le"); + else if (acp == 1252) /* cp1252 is used as latin1 */ + STRCPY(buf, "latin1"); + else + sprintf(buf, "cp%ld", acp); + + return enc_canonize((char_u *)buf); +# else + char *s; + +# ifdef HAVE_NL_LANGINFO_CODESET + if ((s = nl_langinfo(CODESET)) == NULL || *s == NUL) +# endif +# if defined(HAVE_LOCALE_H) || defined(X_LOCALE) + if ((s = setlocale(LC_CTYPE, NULL)) == NULL || *s == NUL) +# endif + s = NULL; + + return enc_locale_env(s); +# endif +} + +# if defined(WIN3264) || defined(PROTO) || defined(FEAT_CYGWIN_WIN32_CLIPBOARD) /* * Convert an encoding name to an MS-Windows codepage. * Returns zero if no codepage can be figured out. @@ -4490,7 +4510,7 @@ encname2codepage(char_u *name) return cp; return 0; } -#endif +# endif # if defined(USE_ICONV) || defined(PROTO)