Hi,
After Vim 7.4.1963, running Win32 version of vim.exe on a Cygwin terminal (e.g.
mintty) shows an error message which indicates that the version cannot run on
it. But the encoding of the message is wrong, so the message will not be shown
correctly especially when the message is translated.
This is because Win32 version of vim.exe will output the message with the
current codepage (e.g. CP932 on Japanese Windows), but mintty uses the locale
based on the environment variables $LC_ALL, $LC_CTYPE or $LANG (normally
utf-8). When the vim.exe detects a Cygwin terminal, the encoding should
follow the environment variables $LC_ALL, etc.
Attached patch fixes the problem.
* Split enc_locale() to two parts. enc_locale() and enc_locale_env().
* Call enc_locale_env() and bind_textdomain_codeset() when a Cygwin terminal
is detected.
* Also fix some indentation errors with #ifdefs.
* Also revert unintended change in iscygpty.c by 7.4.2293.
Regards,
Ken Takata
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
# HG changeset patch
# Parent 12e23c09af7ba15360f6ca3ea151c6131e7bb79d
diff --git a/src/iscygpty.c b/src/iscygpty.c
--- a/src/iscygpty.c
+++ b/src/iscygpty.c
@@ -178,4 +178,4 @@ int is_cygpty_used(void)
return ret;
}
-/* vi:set ts=8 sts=4 sw=4 noet: */
+/* vim: set ts=4 sw=4: */
diff --git a/src/main.c b/src/main.c
--- a/src/main.c
+++ b/src/main.c
@@ -2519,6 +2519,24 @@ 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"; /* Make "utf-8" as 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);
}
diff --git a/src/mbyte.c b/src/mbyte.c
--- a/src/mbyte.c
+++ b/src/mbyte.c
@@ -4307,45 +4307,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)
- 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]]
@@ -4380,12 +4366,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.
@@ -4412,7 +4432,7 @@ encname2codepage(char_u *name)
return cp;
return 0;
}
-#endif
+# endif
# if defined(USE_ICONV) || defined(PROTO)
diff --git a/src/proto/mbyte.pro b/src/proto/mbyte.pro
--- a/src/proto/mbyte.pro
+++ b/src/proto/mbyte.pro
@@ -68,6 +68,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);