gnucash master: Multiple changes pushed
John Ralls
jralls at code.gnucash.org
Sat May 30 17:21:19 EDT 2020
Updated via https://github.com/Gnucash/gnucash/commit/14ed3222 (commit)
via https://github.com/Gnucash/gnucash/commit/e810ee1c (commit)
from https://github.com/Gnucash/gnucash/commit/b0effbc3 (commit)
commit 14ed322297ff57d0e7091367d562511e5ff55b50
Author: John Ralls <jralls at ceridwen.us>
Date: Sat May 30 14:21:07 2020 -0700
Extract set_win32_thread_locale() to a new C file gnucash-windows-locale.c
g++ can't find the Microsoft Locale symbols, gcc can.
diff --git a/gnucash/CMakeLists.txt b/gnucash/CMakeLists.txt
index 769e05f5d..8f738c1dc 100644
--- a/gnucash/CMakeLists.txt
+++ b/gnucash/CMakeLists.txt
@@ -41,6 +41,7 @@ set (gnucash_SOURCES
gnucash-commands.cpp
gnucash-core-app.cpp
gnucash-gresources.c
+ gnucash-windows-locale.c
${GNUCASH_RESOURCE_FILE}
)
@@ -66,6 +67,7 @@ add_executable (gnucash-cli
gnucash-cli.cpp
gnucash-commands.cpp
gnucash-core-app.cpp
+ gnucash-windows-locale.c
${GNUCASH_RESOURCE_FILE}
${gnucash_noinst_HEADERS}
)
diff --git a/gnucash/gnucash-core-app.cpp b/gnucash/gnucash-core-app.cpp
index 7c3ae318d..7fba6ddd8 100644
--- a/gnucash/gnucash-core-app.cpp
+++ b/gnucash/gnucash-core-app.cpp
@@ -25,6 +25,7 @@
#include <libguile.h>
#include <guile-mappings.h>
#ifdef __MINGW32__
+extern "C" void set_win32_thread_locale(char**);
#include <Windows.h>
#include <fcntl.h>
#endif
@@ -412,51 +413,6 @@ gnc_log_init (std::vector <std::string> &log_flags, std::string &log_to_filename
}
}
-#ifdef __MINGW32__
-/* If one of the Unix locale variables LC_ALL, LC_MESSAGES, or LANG is
- * set in the environment check to see if it's a valid locale and if
- * it is set both the Windows and POSIX locales to that. If not
- * retrieve the Windows locale and set POSIX to match.
- */
-static void
-set_win32_thread_locale()
-{
- WCHAR lpLocaleName[LOCALE_NAME_MAX_LENGTH];
- char *locale = NULL;
-
- if (((locale = getenv ("LC_ALL")) != NULL && locale[0] != '\0') ||
- ((locale = getenv ("LC_MESSAGES")) != NULL && locale[0] != '\0') ||
- ((locale = getenv ("LANG")) != NULL && locale[0] != '\0'))
- {
- gunichar2* wlocale = NULL;
- int len = 0;
- len = strchr(locale, '.') - locale;
- locale[2] = '-';
- wlocale = g_utf8_to_utf16 (locale, len, NULL, NULL, NULL);
- if (IsValidLocaleName(wlocale))
- {
- LCID lcid = LocaleNameToLCID(wlocale, LOCALE_ALLOW_NEUTRAL_NAMES);
- SetThreadLocale(lcid);
- locale[2] = '_';
- setlocale (LC_ALL, locale);
- sys_locale = locale;
- g_free(wlocale);
- return;
- }
- g_free(locale);
- g_free(wlocale);
- }
- if (GetUserDefaultLocaleName(lpLocaleName, LOCALE_NAME_MAX_LENGTH))
- {
- sys_locale = g_utf16_to_utf8((gunichar2*)lpLocaleName,
- LOCALE_NAME_MAX_LENGTH,
- NULL, NULL, NULL);
- sys_locale[2] = '_';
- setlocale (LC_ALL, sys_locale);
- return;
- }
-}
-#endif
/* Creates a console window on MSWindows to display stdout and stderr
* when __MSWIN_CONSOLE__ is defined at the top of the file.
@@ -529,7 +485,7 @@ Gnucash::CoreApp::CoreApp ()
#ifdef MAC_INTEGRATION
set_mac_locale();
#elif defined __MINGW32__
- set_win32_thread_locale();
+ set_win32_thread_locale(&sys_locale);
#endif
gnc_environment_setup();
#if ! defined MAC_INTEGRATION && ! defined __MINGW32__/* setlocale already done */
diff --git a/gnucash/gnucash-windows-locale.c b/gnucash/gnucash-windows-locale.c
new file mode 100644
index 000000000..95709a9aa
--- /dev/null
+++ b/gnucash/gnucash-windows-locale.c
@@ -0,0 +1,73 @@
+/*
+ * gnucash-core-app.cpp -- Basic application object for gnucash binaries
+ *
+ * Copyright (C) 2020 John Ralls <jralls at ceridwen.us>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation Voice: +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
+ * Boston, MA 02110-1301, USA gnu at gnu.org
+ */
+
+#include <Windows.h>
+#include <fcntl.h>
+#include <glib/gi18n.h>
+
+//sacrificial prototype
+void set_win32_thread_locale(char **sys_locale);
+
+/* If one of the Unix locale variables LC_ALL, LC_MESSAGES, or LANG is
+ * set in the environment check to see if it's a valid locale and if
+ * it is set both the Windows and POSIX locales to that. If not
+ * retrieve the Windows locale and set POSIX to match.
+ */
+void
+set_win32_thread_locale(char **sys_locale)
+{
+ WCHAR lpLocaleName[LOCALE_NAME_MAX_LENGTH];
+ char *locale = NULL;
+
+ if (((locale = getenv ("LC_ALL")) != NULL && locale[0] != '\0') ||
+ ((locale = getenv ("LC_MESSAGES")) != NULL && locale[0] != '\0') ||
+ ((locale = getenv ("LANG")) != NULL && locale[0] != '\0'))
+ {
+ gunichar2* wlocale = NULL;
+ int len = 0;
+ len = strchr(locale, '.') - locale;
+ locale[2] = '-';
+ wlocale = g_utf8_to_utf16 (locale, len, NULL, NULL, NULL);
+ if (IsValidLocaleName(wlocale))
+ {
+ LCID lcid = LocaleNameToLCID(wlocale, LOCALE_ALLOW_NEUTRAL_NAMES);
+ SetThreadLocale(lcid);
+ locale[2] = '_';
+ setlocale (LC_ALL, locale);
+ *sys_locale = g_strdup (locale);
+ g_free(wlocale);
+ return;
+ }
+ g_free(locale);
+ g_free(wlocale);
+ }
+ if (GetUserDefaultLocaleName(lpLocaleName, LOCALE_NAME_MAX_LENGTH))
+ {
+ *sys_locale = g_utf16_to_utf8((gunichar2*)lpLocaleName,
+ LOCALE_NAME_MAX_LENGTH,
+ NULL, NULL, NULL);
+ (*sys_locale)[2] = '_';
+ setlocale (LC_ALL, *sys_locale);
+ return;
+ }
+}
commit e810ee1c09bbe7472a1f6e3d755d5639a2f027aa
Author: John Ralls <jralls at ceridwen.us>
Date: Sat May 30 14:18:34 2020 -0700
gi18n.h, binreloc.h, and gnc-engine.h have C linkage.
diff --git a/gnucash/gnucash-core-app.cpp b/gnucash/gnucash-core-app.cpp
index 4d0f6919a..7c3ae318d 100644
--- a/gnucash/gnucash-core-app.cpp
+++ b/gnucash/gnucash-core-app.cpp
@@ -23,9 +23,6 @@
#include <config.h>
#include <libguile.h>
-#include <glib/gi18n.h>
-#include <binreloc.h>
-#include <gnc-engine.h>
#include <guile-mappings.h>
#ifdef __MINGW32__
#include <Windows.h>
@@ -35,6 +32,9 @@
#include "gnucash-core-app.hpp"
extern "C" {
+#include <glib/gi18n.h>
+#include <binreloc.h>
+#include <gnc-engine.h>
#include <gfec.h>
#include <gnc-environment.h>
#include <gnc-filepath-utils.h>
Summary of changes:
gnucash/CMakeLists.txt | 2 ++
gnucash/gnucash-core-app.cpp | 54 +++--------------------------
gnucash/gnucash-windows-locale.c | 73 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 80 insertions(+), 49 deletions(-)
create mode 100644 gnucash/gnucash-windows-locale.c
More information about the gnucash-changes
mailing list