From: "Владимир Мартьянов" <vilgeforce@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH][PR server/24377] Fix mixing English and system default languages in error messages on Windows
Date: Sun, 31 Mar 2019 19:39:00 -0000 [thread overview]
Message-ID: <CAL5iTP+7snxFyw4B8bfBNJtfy+B3p3kSCfdQcChmkw+gwrN5eA@mail.gmail.com> (raw)
In-Reply-To: <8336n3hzkx.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 858 bytes --]
вс, 31 мар. 2019 г. в 17:45, Eli Zaretskii <eliz@gnu.org>:
> Bother: do we want to behave like a Posix platform here, or like a
> Windows system? Windows doesn't have LC_MESSAGES as a locale
> category.
I just saw LC_MESSAGES usage in gettext...
> Finally, a more general point: I'm not sure I understand the purpose
> of this change. Is the purpose to let users control the language of
> the gdbserver system error messages?
Yes, it's the purprose.
> If so, would they need to
> control that by setting environment variables? It sounds less
> convenient than it could have been, I think. Why not a GDB variable
> instead?
Environment variables are used in gettext anyway, I think single
source for localisation language is convenient.
I corrected issues you mentioned (I hope!) and made a function to get locale ID.
[-- Attachment #2: 0001-gettext-like-localisation-of-error-messages-added-to.patch --]
[-- Type: application/octet-stream, Size: 3285 bytes --]
From 85f46d36a2043c58248d2d6cb01e03acb66202fa Mon Sep 17 00:00:00 2001
From: Vladimir Martyanov <vilgeforce@gmail.com>
Date: Sun, 31 Mar 2019 22:18:24 +0300
Subject: [PATCH] gettext-like localisation of error messages added to
strwinerror
---
gdb/gdbserver/win32-low.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 69 insertions(+), 1 deletion(-)
diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c
index 1a50141c12..fe8c1453a3 100644
--- a/gdb/gdbserver/win32-low.c
+++ b/gdb/gdbserver/win32-low.c
@@ -496,6 +496,73 @@ child_store_inferior_registers (struct regcache *regcache, int r)
(*the_low_target.store_inferior_register) (regcache, th, regno);
}
+/* Return locale ID from environment variables (LC_ALL and LANG)
+ or 0 (which means system default). */
+LCID
+get_lcid(void)
+{
+ typedef HRESULT (WINAPI *RFC1766TOLCID)(LCID *pLocale, LPTSTR pszRfc1766);
+ typedef LCID (WINAPI *LOCALENAMETOLCID)(LPCWSTR lpName, DWORD dwFlags);
+
+ static HMODULE hMlang = LoadLibrary ("Mlang.dll");
+ HMODULE hKernel32 = GetModuleHandle ("kernel32.dll");
+
+ LCID lcid = 0; /* System default */
+ char buf[256];
+ WCHAR wbuf[256];
+ char *localeName = NULL;
+ char *ptr = NULL;
+ RFC1766TOLCID Rfc1766ToLcid = NULL;
+ LOCALENAMETOLCID LocaleNameToLCID = NULL;
+
+ LocaleNameToLCID = (LOCALENAMETOLCID) GetProcAddress (hKernel32,
+ "LocaleNameToLCID");
+ if (LocaleNameToLCID == NULL)
+ {
+ if (hMlang != NULL)
+ Rfc1766ToLcid = (RFC1766TOLCID) GetProcAddress (hMlang,
+ "Rfc1766ToLcidW");
+ if (Rfc1766ToLcid == NULL)
+ return lcid; /* No conversion funcions - return system default */
+ }
+
+ /* Setting of LC_ALL overwrites all other. */
+ localeName = getenv ("LC_ALL");
+ if (localeName == NULL || localeName[0] == '\0')
+ localeName = getenv ("LANG");
+
+
+ if (localeName == NULL || localeName[0] == '\0')
+ return lcid;
+
+ if (!strcmp (localeName, "C"))
+ return MAKELANGID (LANG_ENGLISH, SUBLANG_ENGLISH_US);
+
+ strncpy (buf, localeName, COUNTOF (buf) - 1);
+ ptr = strchr (buf, '.'); /* cut at "." */
+ if (ptr != NULL)
+ *ptr = 0x00;
+
+ ptr = strchr (buf, '_'); /* replace "_" */
+ if (ptr != NULL)
+ *ptr = '-';
+
+ if (LocaleNameToLCID != NULL)
+ {
+ MultiByteToWideChar (CP_ACP,
+ 0,
+ buf,
+ -1,
+ wbuf,
+ COUNTOF (wbuf) - 1);
+ lcid = LocaleNameToLCID (wbuf, 0);
+ }
+ else
+ Rfc1766ToLcid (&lcid, buf);
+
+ return lcid;
+}
+
/* Map the Windows error number in ERROR to a locale-dependent error
message string and return a pointer to it. Typically, the values
for ERROR come from GetLastError.
@@ -512,11 +579,12 @@ strwinerror (DWORD error)
static char buf[1024];
TCHAR *msgbuf;
DWORD lasterr = GetLastError ();
+
DWORD chars = FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_ALLOCATE_BUFFER,
NULL,
error,
- 0, /* Default language */
+ get_lcid (),
(LPTSTR) &msgbuf,
0,
NULL);
--
2.16.2.windows.1
next prev parent reply other threads:[~2019-03-31 19:39 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-23 11:59 Владимир Мартьянов
2019-03-23 13:11 ` Eli Zaretskii
2019-03-28 20:36 ` Владимир Мартьянов
2019-03-29 8:27 ` Eli Zaretskii
2019-03-29 8:42 ` Владимир Мартьянов
2019-03-29 9:29 ` Eli Zaretskii
2019-03-29 9:39 ` Владимир Мартьянов
2019-03-29 12:32 ` Eli Zaretskii
2019-03-30 21:26 ` Владимир Мартьянов
2019-03-31 14:45 ` Eli Zaretskii
2019-03-31 19:39 ` Владимир Мартьянов [this message]
2019-04-01 4:47 ` Eli Zaretskii
2019-04-02 20:08 ` Владимир Мартьянов
2019-04-03 4:30 ` Eli Zaretskii
2019-04-01 22:08 ` Jon Turney
2019-04-02 20:57 ` Владимир Мартьянов
2019-04-02 21:10 ` Jon Turney
2019-04-02 21:18 ` Владимир Мартьянов
2019-04-03 4:48 ` Eli Zaretskii
2019-04-03 4:58 ` LRN
2019-04-03 7:37 ` Eli Zaretskii
2019-04-03 11:32 ` LRN
2019-04-03 12:04 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAL5iTP+7snxFyw4B8bfBNJtfy+B3p3kSCfdQcChmkw+gwrN5eA@mail.gmail.com \
--to=vilgeforce@gmail.com \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox