From 74511b42f5faed58a6ffbdcd78a33ca3ead95992 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka <valenok@gmail.com> Date: Sun, 12 Jan 2014 07:20:12 +0000 Subject: [PATCH] Using unicode winapi to load config file --- build/main.c | 60 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/build/main.c b/build/main.c index 5f16719e3..f855ed65c 100644 --- a/build/main.c +++ b/build/main.c @@ -208,6 +208,34 @@ static void set_option(char **options, const char *name, const char *value) { } } +#ifdef WIN32 +static int my_argc; +static char **my_argv; + +static void to_utf8(wchar_t *src, char *dst, size_t dst_len) { + WideCharToMultiByte(CP_UTF8, 0, src, -1, dst, dst_len, 0, 0); +} + +static void to_wchar(const char *src, wchar_t *dst, size_t dst_len) { + MultiByteToWideChar(CP_UTF8, 0, src, -1, dst, dst_len); +} + +static void init_utf8_argc_argv(void) { + wchar_t **wargv = CommandLineToArgvW(GetCommandLineW(), &my_argc); + if (wargv != NULL) { + char buf[1024 * 8]; + int i; + // TODO(lsm): free that at some point. + my_argv = calloc(my_argc + 1, sizeof(my_argv[0])); + for (i = 0; i < my_argc; i++) { + to_utf8(wargv[i], buf, sizeof(buf)); + my_argv[i] = strdup(buf); + } + LocalFree(wargv); + } +} +#endif + static void process_command_line_arguments(char *argv[], char **options) { char line[MAX_CONF_FILE_LINE_SIZE], opt[sizeof(line)], val[sizeof(line)], *p; FILE *fp = NULL; @@ -225,7 +253,15 @@ static void process_command_line_arguments(char *argv[], char **options) { (int) (p - argv[0]), argv[0], DIRSEP, CONFIG_FILE); } +#ifdef WIN32 + { + wchar_t path[PATH_MAX]; + to_wchar(config_file, path, sizeof(path) / sizeof(path[0])); + fp = _wfopen(path, L"r"); + } +#else fp = fopen(config_file, "r"); +#endif // If config file was set in command line and open failed, die if (cmd_line_opts_start == 2 && fp == NULL) { @@ -318,30 +354,6 @@ static void verify_existence(char **options, const char *option_name, } } -#ifdef WIN32 -static int my_argc; -static char **my_argv; - -static void to_utf8(wchar_t *src, char *dst, size_t dst_len) { - WideCharToMultiByte(CP_UTF8, 0, src, -1, dst, dst_len, 0, 0); -} - -static void init_utf8_argc_argv(void) { - wchar_t **wargv = CommandLineToArgvW(GetCommandLineW(), &my_argc); - if (wargv != NULL) { - char buf[1024 * 8]; - int i; - // TODO(lsm): free that at some point. - my_argv = calloc(my_argc + 1, sizeof(my_argv[0])); - for (i = 0; i < my_argc; i++) { - to_utf8(wargv[i], buf, sizeof(buf)); - my_argv[i] = strdup(buf); - } - LocalFree(wargv); - } -} -#endif - static void set_absolute_path(char *options[], const char *option_name, const char *path_to_mongoose_exe) { char path[PATH_MAX], abs[PATH_MAX], *option_value; -- GitLab