Skip to content

Commit 8ec196c

Browse files
committed
updated for version 7.4.122
Problem: Win32: When 'encoding' is set to "utf-8" and the active codepage is cp932 then ":grep" and other commands don't work for multi-byte characters. Solution: (Yasuhiro Matsumoto)
1 parent 60a61f5 commit 8ec196c

File tree

2 files changed

+73
-39
lines changed

2 files changed

+73
-39
lines changed

src/os_win32.c

Lines changed: 71 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3788,6 +3788,50 @@ mch_set_winsize_now(void)
37883788
}
37893789
#endif /* FEAT_GUI_W32 */
37903790

3791+
static BOOL
3792+
vim_create_process(
3793+
const char *cmd,
3794+
DWORD flags,
3795+
BOOL inherit_handles,
3796+
STARTUPINFO *si,
3797+
PROCESS_INFORMATION *pi)
3798+
{
3799+
# ifdef FEAT_MBYTE
3800+
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
3801+
{
3802+
WCHAR *wcmd = enc_to_utf16(cmd, NULL);
3803+
3804+
if (wcmd != NULL)
3805+
{
3806+
BOOL ret;
3807+
ret = CreateProcessW(
3808+
NULL, /* Executable name */
3809+
wcmd, /* Command to execute */
3810+
NULL, /* Process security attributes */
3811+
NULL, /* Thread security attributes */
3812+
inherit_handles, /* Inherit handles */
3813+
flags, /* Creation flags */
3814+
NULL, /* Environment */
3815+
NULL, /* Current directory */
3816+
si, /* Startup information */
3817+
pi); /* Process information */
3818+
vim_free(wcmd);
3819+
return ret;
3820+
}
3821+
}
3822+
#endif
3823+
return CreateProcess(
3824+
NULL, /* Executable name */
3825+
cmd, /* Command to execute */
3826+
NULL, /* Process security attributes */
3827+
NULL, /* Thread security attributes */
3828+
inherit_handles, /* Inherit handles */
3829+
flags, /* Creation flags */
3830+
NULL, /* Environment */
3831+
NULL, /* Current directory */
3832+
si, /* Startup information */
3833+
pi); /* Process information */
3834+
}
37913835

37923836

37933837
#if defined(FEAT_GUI_W32) || defined(PROTO)
@@ -3834,18 +3878,8 @@ mch_system_classic(char *cmd, int options)
38343878
cmd += 3;
38353879

38363880
/* Now, run the command */
3837-
CreateProcess(NULL, /* Executable name */
3838-
cmd, /* Command to execute */
3839-
NULL, /* Process security attributes */
3840-
NULL, /* Thread security attributes */
3841-
FALSE, /* Inherit handles */
3842-
CREATE_DEFAULT_ERROR_MODE | /* Creation flags */
3843-
CREATE_NEW_CONSOLE,
3844-
NULL, /* Environment */
3845-
NULL, /* Current directory */
3846-
&si, /* Startup information */
3847-
&pi); /* Process information */
3848-
3881+
vim_create_process(cmd, FALSE,
3882+
CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_CONSOLE, &si, &pi);
38493883

38503884
/* Wait for the command to terminate before continuing */
38513885
if (g_PlatformId != VER_PLATFORM_WIN32s)
@@ -4177,22 +4211,11 @@ mch_system_piped(char *cmd, int options)
41774211
p = cmd;
41784212
}
41794213

4180-
/* Now, run the command */
4181-
CreateProcess(NULL, /* Executable name */
4182-
p, /* Command to execute */
4183-
NULL, /* Process security attributes */
4184-
NULL, /* Thread security attributes */
4185-
4186-
// this command can be litigious, handle inheritance was
4187-
// deactivated for pending temp file, but, if we deactivate
4188-
// it, the pipes don't work for some reason.
4189-
TRUE, /* Inherit handles, first deactivated,
4190-
* but needed */
4191-
CREATE_DEFAULT_ERROR_MODE, /* Creation flags */
4192-
NULL, /* Environment */
4193-
NULL, /* Current directory */
4194-
&si, /* Startup information */
4195-
&pi); /* Process information */
4214+
/* Now, run the command.
4215+
* About "Inherit handles" being TRUE: this command can be litigious,
4216+
* handle inheritance was deactivated for pending temp file, but, if we
4217+
* deactivate it, the pipes don't work for some reason. */
4218+
vim_create_process(p, TRUE, CREATE_DEFAULT_ERROR_MODE, &si, &pi);
41964219

41974220
if (p != cmd)
41984221
vim_free(p);
@@ -4410,7 +4433,25 @@ mch_system(char *cmd, int options)
44104433
}
44114434
#else
44124435

4413-
# define mch_system(c, o) system(c)
4436+
# ifdef FEAT_MBYTE
4437+
static int
4438+
mch_system(char *cmd, int options)
4439+
{
4440+
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
4441+
{
4442+
WCHAR *wcmd = enc_to_utf16(cmd, NULL);
4443+
if (wcmd != NULL)
4444+
{
4445+
int ret = _wsystem(wcmd);
4446+
vim_free(wcmd);
4447+
return ret;
4448+
}
4449+
}
4450+
return system(cmd);
4451+
}
4452+
# else
4453+
# define mch_system(c, o) system(c)
4454+
# endif
44144455

44154456
#endif
44164457

@@ -4578,16 +4619,7 @@ mch_call_shell(
45784619
* inherit our handles which causes unpleasant dangling swap
45794620
* files if we exit before the spawned process
45804621
*/
4581-
if (CreateProcess(NULL, // Executable name
4582-
newcmd, // Command to execute
4583-
NULL, // Process security attributes
4584-
NULL, // Thread security attributes
4585-
FALSE, // Inherit handles
4586-
flags, // Creation flags
4587-
NULL, // Environment
4588-
NULL, // Current directory
4589-
&si, // Startup information
4590-
&pi)) // Process information
4622+
if (vim_create_process(newcmd, FALSE, flags, &si, &pi))
45914623
x = 0;
45924624
else
45934625
{

src/version.c

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

739739
static int included_patches[] =
740740
{ /* Add new patch number below this line */
741+
/**/
742+
122,
741743
/**/
742744
121,
743745
/**/

0 commit comments

Comments
 (0)