win: wmain(): locale-independent argv (#7180)

fix #7060
This commit is contained in:
Yuto Tokunaga 2017-08-23 07:55:00 +09:00 committed by Justin M. Keyes
parent 85f3084e21
commit e5565891af
2 changed files with 28 additions and 0 deletions

View File

@ -10,6 +10,11 @@ if(USE_GCOV)
endif() endif()
endif() endif()
if(WIN32)
# tell MinGW compiler to enable wmain
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -municode")
endif()
set(TOUCHES_DIR ${PROJECT_BINARY_DIR}/touches) set(TOUCHES_DIR ${PROJECT_BINARY_DIR}/touches)
set(GENERATOR_DIR ${CMAKE_CURRENT_LIST_DIR}/generators) set(GENERATOR_DIR ${CMAKE_CURRENT_LIST_DIR}/generators)
set(GENERATED_DIR ${PROJECT_BINARY_DIR}/src/nvim/auto) set(GENERATED_DIR ${PROJECT_BINARY_DIR}/src/nvim/auto)

View File

@ -7,6 +7,11 @@
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#ifdef WIN32
# include <wchar.h>
# include <winnls.h>
#endif
#include <msgpack.h> #include <msgpack.h>
#include "nvim/ascii.h" #include "nvim/ascii.h"
@ -215,10 +220,28 @@ void early_init(void)
#ifdef MAKE_LIB #ifdef MAKE_LIB
int nvim_main(int argc, char **argv) int nvim_main(int argc, char **argv)
#elif defined WIN32
// don't use codepage encoded arguments. see #7060
int wmain(int argc, wchar_t **argv_w)
#else #else
int main(int argc, char **argv) int main(int argc, char **argv)
#endif #endif
{ {
#ifdef WIN32
char *argv[argc];
for (size_t i = 0; i < (size_t)argc; i++) {
// get required buffer size
size_t dest_size = (size_t)WideCharToMultiByte(
CP_UTF8, 0, argv_w[i], -1, NULL, 0, NULL, NULL);
char *buf = (char *)xmallocz(dest_size);
// convert from utf16 (widechar) utf8 (multibyte)
WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1, buf, (int)dest_size,
NULL, NULL);
argv[i] = buf;
}
#endif
argv0 = argv[0]; argv0 = argv[0];
char_u *fname = NULL; // file name from command line char_u *fname = NULL; // file name from command line