This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH][PR server/24377] Fix mixing English and system default languages in error messages on Windows
I'm proposing this patch to translate messages in strwinerror.
Successfully built in Cygwin x86 and Cygwin x64
I didn't check locale name against "C" value because don't know what
locale to use: English or system default.
From fe4aa282fa917773ff77ca5da48d9439e1fd6fee Mon Sep 17 00:00:00 2001
From: Vladimir Martyanov <vilgeforce@gmail.com>
Date: Sat, 30 Mar 2019 23:21:27 +0300
Subject: [PATCH] gettext-like localisation of error messages added to
strwinerror
---
gdb/gdbserver/win32-low.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 47 insertions(+), 1 deletion(-)
diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c
index 1a50141c12..85cd559f05 100644
--- a/gdb/gdbserver/win32-low.c
+++ b/gdb/gdbserver/win32-low.c
@@ -512,11 +512,57 @@ strwinerror (DWORD error)
static char buf[1024];
TCHAR *msgbuf;
DWORD lasterr = GetLastError ();
+
+ //retrieve LCID
+ LCID lcid = 0; /* Will be default language*/
+ char* localeName = NULL;
+ char* ptr;
+ typedef HRESULT (WINAPI *RFC1766TOLCID)(LCID *pLocale, LPTSTR pszRfc1766);
+ RFC1766TOLCID Rfc1766ToLcid;
+
+ HMODULE hMlang = LoadLibrary("Mlang.dll");
+ if (hMlang != NULL)
+ {
+ Rfc1766ToLcid = (RFC1766TOLCID) GetProcAddress(hMlang, "Rfc1766ToLcidA");
+ if (Rfc1766ToLcid != NULL)
+ {
+ /* Setting of LC_ALL overwrites all other. */
+ localeName = getenv ("LC_ALL");
+ if (localeName == NULL || localeName[0] == '\0')
+ {
+ /* Next comes the name of the desired category. */
+ localeName = getenv ("LC_MESSAGES");
+ if (localeName == NULL || localeName[0] == '\0')
+ {
+ /* Last possibility is the LANG environment variable. */
+ localeName = getenv ("LANG");
+ }
+ }
+ }
+
+ if (localeName != NULL && localeName[0] != '\0'){ //have something to convert
+ strncpy(buf, localeName, (COUNTOF (buf)) - 1);
+
+ ptr = strchr(buf, '.'); //cut at "."
+ if (ptr != 0) {
+ *ptr = 0x00;
+ }
+
+ ptr = strchr(buf, '_'); //replace "_"
+ if (ptr != 0) {
+ *ptr = '-';
+ }
+ Rfc1766ToLcid(&lcid, buf);
+ }
+
+ FreeLibrary(hMlang);
+ }
+
DWORD chars = FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_ALLOCATE_BUFFER,
NULL,
error,
- 0, /* Default language */
+ lcid,
(LPTSTR) &msgbuf,
0,
NULL);
--
2.16.2.windows.1