Skip to content

Commit 2a02745

Browse files
committed
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)
1 parent 09ca932 commit 2a02745

File tree

4 files changed

+68
-30
lines changed

4 files changed

+68
-30
lines changed

src/main.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,6 +2564,21 @@ check_tty(mparm_T *parmp)
25642564
#if defined(WIN3264) && !defined(FEAT_GUI_W32)
25652565
if (is_cygpty_used())
25662566
{
2567+
# if defined(FEAT_MBYTE) && defined(HAVE_BIND_TEXTDOMAIN_CODESET) \
2568+
&& defined(FEAT_GETTEXT)
2569+
char *s, *tofree = NULL;
2570+
2571+
/* Set the encoding of the error message based on $LC_ALL or
2572+
* other environment variables instead of 'encoding'.
2573+
* Note that the message is shown on a Cygwin terminal (e.g.
2574+
* mintty) which encoding is based on $LC_ALL or etc., not the
2575+
* current codepage used by normal Win32 console programs. */
2576+
tofree = s = enc_locale_env(NULL);
2577+
if (s == NULL)
2578+
s = "utf-8"; /* Use "utf-8" by default. */
2579+
(void)bind_textdomain_codeset(VIMPACKAGE, s);
2580+
vim_free(tofree);
2581+
# endif
25672582
mch_errmsg(_("Vim: Error: This version of Vim does not run in a Cygwin terminal\n"));
25682583
exit(1);
25692584
}

src/mbyte.c

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4385,45 +4385,31 @@ enc_alias_search(char_u *name)
43854385

43864386
#if defined(FEAT_MBYTE) || defined(PROTO)
43874387

4388-
#ifdef HAVE_LANGINFO_H
4389-
# include <langinfo.h>
4390-
#endif
4388+
# ifdef HAVE_LANGINFO_H
4389+
# include <langinfo.h>
4390+
# endif
43914391

4392+
# ifndef FEAT_GUI_W32
43924393
/*
4393-
* Get the canonicalized encoding of the current locale.
4394+
* Get the canonicalized encoding from the specified locale string "locale"
4395+
* or from the environment variables LC_ALL, LC_CTYPE and LANG.
43944396
* Returns an allocated string when successful, NULL when not.
43954397
*/
43964398
char_u *
4397-
enc_locale(void)
4399+
enc_locale_env(char *locale)
43984400
{
4399-
#ifndef WIN3264
4400-
char *s;
4401+
char *s = locale;
44014402
char *p;
44024403
int i;
4403-
#endif
44044404
char buf[50];
4405-
#ifdef WIN3264
4406-
long acp = GetACP();
44074405

4408-
if (acp == 1200)
4409-
STRCPY(buf, "ucs-2le");
4410-
else if (acp == 1252) /* cp1252 is used as latin1 */
4411-
STRCPY(buf, "latin1");
4412-
else
4413-
sprintf(buf, "cp%ld", acp);
4414-
#else
4415-
# ifdef HAVE_NL_LANGINFO_CODESET
4416-
if ((s = nl_langinfo(CODESET)) == NULL || *s == NUL)
4417-
# endif
4418-
# if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
4419-
if ((s = setlocale(LC_CTYPE, NULL)) == NULL || *s == NUL)
4420-
# endif
4421-
if ((s = getenv("LC_ALL")) == NULL || *s == NUL)
4422-
if ((s = getenv("LC_CTYPE")) == NULL || *s == NUL)
4423-
s = getenv("LANG");
4406+
if (s == NULL || *s == NUL)
4407+
if ((s = getenv("LC_ALL")) == NULL || *s == NUL)
4408+
if ((s = getenv("LC_CTYPE")) == NULL || *s == NUL)
4409+
s = getenv("LANG");
44244410

44254411
if (s == NULL || *s == NUL)
4426-
return FAIL;
4412+
return NULL;
44274413

44284414
/* The most generic locale format is:
44294415
* language[_territory][.codeset][@modifier][+special][,[sponsor][_revision]]
@@ -4458,12 +4444,46 @@ enc_locale(void)
44584444
break;
44594445
}
44604446
buf[i] = NUL;
4461-
#endif
44624447

44634448
return enc_canonize((char_u *)buf);
44644449
}
4450+
# endif
4451+
4452+
/*
4453+
* Get the canonicalized encoding of the current locale.
4454+
* Returns an allocated string when successful, NULL when not.
4455+
*/
4456+
char_u *
4457+
enc_locale(void)
4458+
{
4459+
# ifdef WIN3264
4460+
char buf[50];
4461+
long acp = GetACP();
4462+
4463+
if (acp == 1200)
4464+
STRCPY(buf, "ucs-2le");
4465+
else if (acp == 1252) /* cp1252 is used as latin1 */
4466+
STRCPY(buf, "latin1");
4467+
else
4468+
sprintf(buf, "cp%ld", acp);
4469+
4470+
return enc_canonize((char_u *)buf);
4471+
# else
4472+
char *s;
4473+
4474+
# ifdef HAVE_NL_LANGINFO_CODESET
4475+
if ((s = nl_langinfo(CODESET)) == NULL || *s == NUL)
4476+
# endif
4477+
# if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
4478+
if ((s = setlocale(LC_CTYPE, NULL)) == NULL || *s == NUL)
4479+
# endif
4480+
s = NULL;
4481+
4482+
return enc_locale_env(s);
4483+
# endif
4484+
}
44654485

4466-
#if defined(WIN3264) || defined(PROTO) || defined(FEAT_CYGWIN_WIN32_CLIPBOARD)
4486+
# if defined(WIN3264) || defined(PROTO) || defined(FEAT_CYGWIN_WIN32_CLIPBOARD)
44674487
/*
44684488
* Convert an encoding name to an MS-Windows codepage.
44694489
* Returns zero if no codepage can be figured out.
@@ -4490,7 +4510,7 @@ encname2codepage(char_u *name)
44904510
return cp;
44914511
return 0;
44924512
}
4493-
#endif
4513+
# endif
44944514

44954515
# if defined(USE_ICONV) || defined(PROTO)
44964516

src/proto/mbyte.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ int mb_lefthalve(int row, int col);
7171
int mb_fix_col(int col, int row);
7272
char_u *enc_skip(char_u *p);
7373
char_u *enc_canonize(char_u *enc);
74+
char_u *enc_locale_env(char *locale);
7475
char_u *enc_locale(void);
7576
int encname2codepage(char_u *name);
7677
void *my_iconv_open(char_u *to, char_u *from);

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1152,
764766
/**/
765767
1151,
766768
/**/

0 commit comments

Comments
 (0)