New implementation of pseudo console support (experimental)
Takashi Yano
takashi.yano@nifty.ne.jp
Tue Sep 1 09:42:15 GMT 2020
Hi Johannes,
On Tue, 1 Sep 2020 18:23:03 +0900
Takashi Yano via Cygwin-developers <cygwin-developers@cygwin.com> wrote:
> On Tue, 1 Sep 2020 06:46:53 +0200 (CEST)
> Johannes Schindelin wrote:
>
> > -- snip --
> > diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
> > index 43eebc174..65b4d45fa 100644
> > --- a/winsup/cygwin/fhandler_tty.cc
> > +++ b/winsup/cygwin/fhandler_tty.cc
> > @@ -2867,7 +2867,16 @@ fhandler_pty_slave::setup_locale (void)
> > char charset[ENCODING_LEN + 1] = "ASCII";
> > LCID lcid = get_langinfo (locale, charset);
> >
> > - /* Set console code page form locale */
> > + /* Special-case the UTF-8 character set */
> > + if (strcasecmp (charset, "UTF-8") == 0)
> > + {
> > + get_ttyp ()->term_code_page = CP_UTF8;
> > + SetConsoleCP (CP_UTF8);
> > + SetConsoleOutputCP (CP_UTF8);
> > + return;
> > + }
> > +
> > + /* Set console code page from locale */
> > if (get_pseudo_console ())
> > {
> > UINT code_page;
> > -- snap --
>
> I don't think you do right thing. Your first test case makes
> garbled output in command prompt, therefore output in cygwin
> should be the same.
>
> I believe the correct maner as Windows programs are such as:
>
> [Code A]
> #include <windows.h>
> #include <stdio.h>
>
> int main(){
> int origcp = GetConsoleOutputCP();
> SetConsoleOutputCP(CP_UTF8);
> puts("Привет мир! Hello world!");
> SetConsoleOutputCP(origcp);
> return 0;
> }
>
> [Code B]
> #include <locale.h>
> #include <stdio.h>
>
> int main(){
> setlocale (LC_ALL, "");
> _putws(L"Привет мир! Hello world!");
> return 0;
> }
>
> if the source code is in UTF-8 coding. Or compiled
> with -fexec-charset=utf-8.
>
> Both work as expected in command prompt as well as
> in current cygwin.
What is your expectation if your test case is compiled
with -fexec-charset=cp1251?
This will cause garbled output if your default code page
is not 1251.
In this case, SetConsoleOutputCP(1251) is necessary.
Why do you think only the UTF-8 output should work without
SetConsoleOutputCP(CP_UTF8)?
--
Takashi Yano <takashi.yano@nifty.ne.jp>
More information about the Cygwin-developers
mailing list