From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin-patches@cygwin.com
Subject: Re: [PATCH 3/3] fhandler_pty_slave::setup_locale: respect charset == "UTF-8"
Date: Mon, 7 Sep 2020 11:08:23 +0200 [thread overview]
Message-ID: <20200907090823.GF4127@calimero.vinschen.de> (raw)
In-Reply-To: <20200907134558.3e1cd8bd4070991b856f58bb@nifty.ne.jp>
Hi Takashi,
On Sep 7 13:45, Takashi Yano via Cygwin-patches wrote:
> #if 0 /* Let's try this if setting codepage at pty open time is not enough */
> - if (!cygheap->locale.term_code_page)
> - cygheap->locale.term_code_page = __eval_codepage_from_internal_charset ();
> + if (!get_ttyp ()->term_code_page)
> + get_ttyp ()->term_code_page = __eval_codepage_from_internal_charset (NULL);
> #endif
*If* we revert back to using setup_locale, these #if blocks would
go away.
> -__eval_codepage_from_internal_charset ()
> +__eval_codepage_from_internal_charset (const WCHAR *envblock)
> {
> - const char *charset = __locale_charset (__get_global_locale ());
> + const char *charset;
> + __locale_t *loc = NULL;
> + if (__get_current_locale ()->lc_cat[LC_CTYPE].buf)
> + charset = __locale_charset (__get_current_locale ());
> + else
> + {
> + char locale[ENCODING_LEN + 1] = {0, };
> + if (envblock)
> + {
> + const WCHAR *lc_all = NULL, *lc_ctype = NULL, *lang = NULL;
> + for (const WCHAR *p = envblock; *p != L'\0'; p += wcslen (p) + 1)
> + if (wcsncmp (p, L"LC_ALL=", 7) == 0)
> + lc_all = p + 7;
> + else if (wcsncmp (p, L"LC_CTYPE=", 9) == 0)
> + lc_ctype = p + 9;
> + else if (wcsncmp (p, L"LANG=", 5) == 0)
> + lang = p + 5;
> + if (lc_all && *lc_all)
> + snprintf (locale, ENCODING_LEN + 1, "%ls", lc_all);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sys_wcstombs (locale, ENCODING_LEN + 1, lc_all);
OTOH, if you read these environment vars right from our current POSIX
env, you don't have to convert from mbs to wcs at all. Just call
getenv("LC_ALL"), etc. After all, envblock is just the wide char
copy of our current POSIX env.
> + else if (lc_ctype && *lc_ctype)
> + snprintf (locale, ENCODING_LEN + 1, "%ls", lc_ctype);
> + else if (lang && *lang)
> + snprintf (locale, ENCODING_LEN + 1, "%ls", lang);
> + }
> + if (!*locale)
> + {
> + const char *env = __get_locale_env (_REENT, LC_CTYPE);
> + strncpy (locale, env, ENCODING_LEN);
> + locale[ENCODING_LEN] = '\0';
> + }
> + loc = duplocale (__get_current_locale ());
> + __loadlocale (loc, LC_CTYPE, locale);
> + charset = __locale_charset (loc);
> + }
Oh, boy, this is really a lot. I have some doubts this complexity is
really necessary. It's a bit weird to go to such great lengths for
native applications. Still, why not just do this once in the process
creating the pty rather than trying on every execve?
> case 'I': /* ISO-8859-x */
> - codepage = strtoul (charset + 9, NULL, 10);
> + codepage = strtoul (charset + 9, NULL, 10) + 28590;
Oops, I just fixed that in my original patch already.
Corinna
next prev parent reply other threads:[~2020-09-07 9:08 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-01 16:19 Johannes Schindelin
2020-09-02 6:06 ` Johannes Schindelin
2020-09-02 8:30 ` Corinna Vinschen
2020-09-02 8:38 ` Corinna Vinschen
2020-09-02 10:54 ` Takashi Yano
2020-09-02 15:24 ` Corinna Vinschen
2020-09-02 16:09 ` Corinna Vinschen
2020-09-02 16:25 ` Takashi Yano
2020-09-02 16:38 ` Corinna Vinschen
2020-09-03 17:59 ` Corinna Vinschen
2020-09-04 9:21 ` Takashi Yano
2020-09-04 12:44 ` Corinna Vinschen
2020-09-04 14:05 ` Brian Inglis
2020-09-04 14:50 ` Takashi Yano
2020-09-04 19:22 ` Corinna Vinschen
2020-09-05 8:43 ` Takashi Yano
2020-09-05 11:15 ` Takashi Yano
2020-09-05 14:15 ` Takashi Yano
2020-09-06 8:57 ` Takashi Yano
2020-09-06 10:15 ` Takashi Yano
2020-09-06 16:04 ` Takashi Yano
2020-09-07 4:45 ` Takashi Yano
2020-09-07 9:08 ` Corinna Vinschen [this message]
2020-09-07 9:54 ` Takashi Yano
2020-09-07 9:59 ` Takashi Yano
2020-09-08 8:40 ` Corinna Vinschen
2020-09-08 9:45 ` Takashi Yano
2020-09-08 19:16 ` Corinna Vinschen
2020-09-10 13:08 ` Takashi Yano
2020-09-07 8:27 ` Corinna Vinschen
2020-09-07 8:38 ` Takashi Yano
2020-09-07 9:09 ` Corinna Vinschen
2020-09-07 8:26 ` Corinna Vinschen
2020-09-07 9:36 ` Takashi Yano
2020-09-07 18:24 ` Takashi Yano
2020-09-07 21:08 ` Johannes Schindelin
2020-09-08 4:52 ` Brian Inglis
2020-09-07 10:27 ` Takashi Yano
2020-09-07 13:40 ` Takashi Yano
2020-09-08 7:55 ` Corinna Vinschen
2020-09-06 10:28 ` Takashi Yano
2020-09-07 8:33 ` Corinna Vinschen
2020-09-02 9:41 ` Takashi Yano
2020-09-02 6:26 ` Johannes Schindelin
2020-09-02 13:06 ` Takashi Yano
2020-09-02 9:12 ` Johannes Schindelin
2020-09-02 14:52 ` Takashi Yano
2020-09-04 10:03 ` Takashi Yano
2020-09-04 6:23 ` Johannes Schindelin
2020-09-04 15:03 ` Takashi Yano
2020-09-07 21:17 ` Johannes Schindelin
2020-09-08 8:16 ` Takashi Yano
2020-09-09 7:21 ` Corinna Vinschen
2020-09-10 0:15 ` Takashi Yano
2020-09-10 12:34 ` Takashi Yano
2020-09-11 9:05 ` Corinna Vinschen
2020-09-11 9:23 ` Corinna Vinschen
2020-09-10 14:04 ` Corinna Vinschen
2020-09-10 14:16 ` Takashi Yano
2020-09-10 14:18 ` Takashi Yano
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=20200907090823.GF4127@calimero.vinschen.de \
--to=corinna-cygwin@cygwin.com \
--cc=cygwin-patches@cygwin.com \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).