]> granicus.if.org Git - vim/commitdiff
patch 8.0.1152: encoding of error message wrong in Cygwin terminal v8.0.1152
authorBram Moolenaar <Bram@vim.org>
Tue, 26 Sep 2017 17:10:37 +0000 (19:10 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 26 Sep 2017 17:10:37 +0000 (19:10 +0200)
Problem:    Encoding of error message wrong in Cygwin terminal.
Solution:   Get locale from environment variables. (Ken Takata)

src/main.c
src/mbyte.c
src/proto/mbyte.pro
src/version.c

index 5233db563f1ab4a64da7c9b9fa2a05b5be055602..3b18bf1e414e3d123a04f545ddb6e44e563c0534 100644 (file)
@@ -2564,6 +2564,21 @@ check_tty(mparm_T *parmp)
 #if defined(WIN3264) && !defined(FEAT_GUI_W32)
        if (is_cygpty_used())
        {
+# if defined(FEAT_MBYTE) && defined(HAVE_BIND_TEXTDOMAIN_CODESET) \
+       && defined(FEAT_GETTEXT)
+           char    *s, *tofree = NULL;
+
+           /* Set the encoding of the error message based on $LC_ALL or
+            * other environment variables instead of 'encoding'.
+            * Note that the message is shown on a Cygwin terminal (e.g.
+            * mintty) which encoding is based on $LC_ALL or etc., not the
+            * current codepage used by normal Win32 console programs. */
+           tofree = s = enc_locale_env(NULL);
+           if (s == NULL)
+               s = "utf-8";    /* Use "utf-8" by default. */
+           (void)bind_textdomain_codeset(VIMPACKAGE, s);
+           vim_free(tofree);
+# endif
            mch_errmsg(_("Vim: Error: This version of Vim does not run in a Cygwin terminal\n"));
            exit(1);
        }
index 29385a95719514c3ac0ec6e407af5e9cbf4ceedc..fe5673129bdd0c63e2b53925405668e9d8021904 100644 (file)
@@ -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)
+enc_locale_env(char *locale)
 {
-#ifndef WIN3264
-    char       *s;
+    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)
+       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;
+       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);
 }
+# 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)
+# 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)
 
index 44fcfc58a2dfa2bf075da642567adbb318649b8a..2ba9f1c9fc0e4423ba4b640f6b916a55323b387d 100644 (file)
@@ -71,6 +71,7 @@ int mb_lefthalve(int row, int col);
 int mb_fix_col(int col, int row);
 char_u *enc_skip(char_u *p);
 char_u *enc_canonize(char_u *enc);
+char_u *enc_locale_env(char *locale);
 char_u *enc_locale(void);
 int encname2codepage(char_u *name);
 void *my_iconv_open(char_u *to, char_u *from);
index f948b8e3070c5dc6a7de6792a465c341f08c27f1..2126c969ed42734ddef07c48cef9912ed1816ead 100644 (file)
@@ -761,6 +761,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1152,
 /**/
     1151,
 /**/