From 2509f0af5217bd7186ded2cd55f82b30a7db4fc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Fri, 10 Jun 2011 14:52:22 +0200 Subject: Workaround the ANSI codepage limitation on Win32. --- NEWS | 2 ++ src/logdiag.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/NEWS b/NEWS index 995f81c..58f9ef2 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,7 @@ Version TBD - Added scrolling using the middle mouse button. + - Fixed command line parsing on Windows, + it's not limited to the system ANSI codepage anymore. - Fixed checking for the shift key when selecting. - Terminals are ignored when hovering the cursor above a selection. - Disallowed wheel zooming when holding mouse buttons. diff --git a/src/logdiag.c b/src/logdiag.c index 90548d3..c44c1c3 100644 --- a/src/logdiag.c +++ b/src/logdiag.c @@ -16,6 +16,66 @@ #include "ld-window-main.h" +#ifdef _WIN32 +#include +#include + +/* + * get_utf8_args: + * @argc: where the number of arguments will be stored. + * @argv: where the actual array of arguments will be stored. + * Use g_strfreev() to free the array. + * + * Retrieve program arguments in UTF-8 encoding on Windows. + * + * Return value: %TRUE if the function has succeeded. + */ +static gboolean +get_utf8_args (int *argc, char ***argv) +{ + LPWSTR *argv_wide; + int i, argc_local, buff_size; + char **argv_local, *arg; + + argv_wide = CommandLineToArgvW (GetCommandLineW (), &argc_local); + if (!argv_wide) + return FALSE; + + argv_local = g_malloc ((argc_local + 1) * sizeof (char *)); + for (i = 0; i < argc_local; i++) + { + buff_size = WideCharToMultiByte (CP_UTF8, 0, argv_wide[i], -1, + NULL, 0, NULL, NULL); + if (!buff_size) + goto get_utf8_args_fail; + + argv_local[i] = g_malloc (buff_size); + if (!WideCharToMultiByte (CP_UTF8, 0, argv_wide[i], -1, + argv_local[i], buff_size, NULL, NULL)) + { + g_free (argv_local[i]); + goto get_utf8_args_fail; + } + } + argv_local[i] = NULL; + LocalFree (argv_wide); + + if (argc) + *argc = argc_local; + if (argv) + *argv = argv_local; + return TRUE; + +get_utf8_args_fail: + while (i--) + g_free (argv_local[i]); + g_free (argv_local); + + LocalFree (argv_wide); + return FALSE; +} +#endif + int main (int argc, char *argv[]) { @@ -29,6 +89,7 @@ main (int argc, char *argv[]) GError *error; #ifdef _WIN32 + gboolean argv_overriden; gchar *install_dir; install_dir = g_win32_get_package_installation_directory_of_module (NULL); @@ -45,6 +106,13 @@ main (int argc, char *argv[]) bind_textdomain_codeset (GETTEXT_DOMAIN, "UTF-8"); textdomain (GETTEXT_DOMAIN); +#ifdef _WIN32 + /* Don't be limited by the ANSI codepage. */ + argv_overriden = get_utf8_args (&argc, &argv); + if (argv_overriden) + _putenv ("CHARSET=UTF-8"); +#endif + error = NULL; gtk_init_with_args (&argc, &argv, N_("- Schematic editor"), option_entries, GETTEXT_DOMAIN, &error); @@ -55,6 +123,14 @@ main (int argc, char *argv[]) return 1; } +#ifdef _WIN32 + if (argv_overriden) + { + _putenv ("CHARSET="); + g_strfreev (argv); + } +#endif + gtk_window_set_default_icon_name (PROJECT_NAME); /* TODO: Be able to open multiple files. */ -- cgit v1.2.3