Mercurial > mxe-octave
view src/readline-4-locale.patch @ 6554:a6f1111a9f1d
readline: Check console codepage for UTF-8 locale on Windows.
* src/readline-4-locale.patch: Get console input codepage to check for UTF-8
locale on Windows. Be more careful with setting locale on Windows.
* src/readline-2-event-hook.patch: Support non-UTF-8 locale. (Not really
compatible to Octave which expects that all character arrays are UTF-8 encoded).
* dist-files.mk: Add new file to list.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Sun, 27 Nov 2022 19:08:31 +0100 |
parents | |
children |
line wrap: on
line source
--- readline-8.2/nls.c.orig 2022-11-22 18:41:48.302144300 +0100 +++ readline-8.2/nls.c 2022-12-03 18:37:54.991412600 +0100 @@ -49,6 +49,11 @@ #include <ctype.h> +#if defined (_WIN32) +# include <windows.h> +# include <versionhelpers.h> +#endif + #include "rldefs.h" #include "readline.h" #include "rlshell.h" @@ -109,7 +114,11 @@ char *cp; size_t len; -#if HAVE_LANGINFO_CODESET +#if defined (_WIN32) + /* On Windows, the relevant "locale" is the selected codepage of the used + console. */ + return (IsWindows7OrGreater () && (GetConsoleCP () == 65001)); +#elif HAVE_LANGINFO_CODESET cp = nl_langinfo (CODESET); return (STREQ (cp, "UTF-8") || STREQ (cp, "utf8")); #else @@ -138,11 +147,18 @@ #if defined (HAVE_SETLOCALE) if (lspec == 0 || *lspec == 0) lspec = setlocale (LC_CTYPE, (char *)NULL); +#if defined (_WIN32) + /* Setting an UTF-8 locale is not a no-op on Windows. Instead the + information about the locale is lost. Use whatever we got at this + point. */ + ret = lspec; +#else if (lspec == 0) lspec = ""; ret = setlocale (LC_CTYPE, lspec); /* ok, since it does not change locale */ if (ret == 0 || *ret == 0) ret = setlocale (LC_CTYPE, (char *)NULL); +#endif if (ret == 0 || *ret == 0) ret = RL_DEFAULT_LOCALE; #else