Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id D8EE814D375 for ; Sun, 18 Mar 2012 06:05:09 -0300 (ADT) Received: from mail-bk0-f46.google.com ([209.85.214.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S9C31-0005l5-Ve for pgsql-bugs@postgresql.org; Sun, 18 Mar 2012 09:05:09 +0000 Received: by bkcik5 with SMTP id ik5so3678277bkc.19 for ; Sun, 18 Mar 2012 02:04:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type; bh=CMZslqFr0c5sJO+fpmLANd7hWgjlCWNCNUWxvKqtugs=; b=arZmO1FdD4gzae7pkfO3V3uNOc3M1pxLt8mdm+WR9VEhs1TQ9EhgnmuHmTEGAtbm8w Z6jPFR0MwwBhxRj3OYxLh5m5omS1SwQg2mOo2ktw1Dw8c4vN4yatFaq3yq+OrXfrWRAF VdrAjfX/lEMrmsUERF1YC36O+Xrjxt4/RowpodPv8+Xpm48K41ib2xDTtmz5fCaY3vqn UZiUjGo78JY7VRN53Z3iuhk39cULl2ubGyoUNXGwPWshZ/3q/NZtGx6r6IfoBv5BrozT 4fJRZXOGCeQeMhCoVxuZfuLgN/24NavnmOAu6nxQSznCjgeWcVnpYQtb9GcsuDlqfAG9 1EXA== Received: by 10.204.151.217 with SMTP id d25mr3137048bkw.89.1332061494624; Sun, 18 Mar 2012 02:04:54 -0700 (PDT) Received: from [1.0.0.7] ([94.138.18.52]) by mx.google.com with ESMTPS id f6sm18987189bkg.10.2012.03.18.02.04.52 (version=SSLv3 cipher=OTHER); Sun, 18 Mar 2012 02:04:53 -0700 (PDT) Message-ID: <4F65A533.7090208@gmail.com> Date: Sun, 18 Mar 2012 13:04:51 +0400 From: Alexander LAW User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 MIME-Version: 1.0 To: Alvaro Herrera CC: Pg Bugs Subject: Re: BUG #6510: A simple prompt is displayed using wrong charset References: <1331925178-sup-9261@alvh.no-ip.org> In-Reply-To: <1331925178-sup-9261@alvh.no-ip.org> Content-Type: multipart/mixed; boundary="------------050601040005010707080400" X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201203/126 X-Sequence-Number: 32687 This is a multi-part message in MIME format. --------------050601040005010707080400 Content-Type: multipart/alternative; boundary="------------070703030602010008050805" --------------070703030602010008050805 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit I see two ways to resolve the issue. First is to use CharToOemBuff when writing a string to the "con" and OemToCharBuff when reading an input from it. The other is to always use stderr/stdin for Win32 as it was done for msys before. I think it's more straightforward. I tested the attached patch (build the source with msvc) and it fixes the issue. If it looks acceptible, then probably DEVTTY should not be used on Windows at all. I found two other references of DEVTTY at psql/command.c success = saveHistory(fname ? fname : DEVTTY, -1, false, false); and contrib/pg_upgrade/option.c log_opts.debug_fd = fopen(DEVTTY, "w"); By the way, is there any reason to use stderr for the prompt output, not stdout? Regards, Alexander 16.03.2012 23:13, Alvaro Herrera пишет: > Excerpts from exclusion's message of sáb mar 03 15:44:37 -0300 2012: > >> I'm using postgresSQL in Windows with Russian locale and get unreadable >> messages when the postgres utilities prompting me for input. >> Please look at the screenshot: >> http://oi44.tinypic.com/aotje8.jpg >> (The psql writes the unreadable message prompting for the password.) >> But at the same time the following message (WARINING) displayed right. >> >> I believe it's related to setlocale and the difference between OEM and ANSI >> encoding, which we had in Windows with the Russian locale. >> The startup code of psql sets locale with the call setlocale(LC_ALL, "") and >> MSDN documentation says that the call: >> Sets the locale to the default, which is the user-default ANSI code page >> obtained from the operating system. >> >> After the call all the strings printed with the printf(stdout) will go >> through the ANSI->OEM conversion. >> >> But in the simple_prompt function strings written to con, and such writes go >> without conversion. > Were you able to come up with some way to make this work? > --------------070703030602010008050805 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit I see two ways to resolve the issue.
First is to use CharToOemBuff when writing a string to the "con" and OemToCharBuff when reading an input from it.
The other is to always use stderr/stdin for Win32 as it was done for msys before. I think it's more straightforward.
I tested the attached patch (build the source with msvc) and it fixes the issue. If it looks acceptible, then probably DEVTTY should not be used on Windows at all.
I found two other references of DEVTTY at
psql/command.c
success = saveHistory(fname ? fname : DEVTTY, -1, false, false);

and
contrib/pg_upgrade/option.c
log_opts.debug_fd = fopen(DEVTTY, "w");

By the way, is there any reason to use stderr for the prompt output, not stdout?

Regards,
Alexander


16.03.2012 23:13, Alvaro Herrera пишет:
Excerpts from exclusion's message of sáb mar 03 15:44:37 -0300 2012:

I'm using postgresSQL in Windows with Russian locale and get unreadable
messages when the postgres utilities prompting me for input.
Please look at the screenshot:
http://oi44.tinypic.com/aotje8.jpg
(The psql writes the unreadable message prompting for the password.)
But at the same time the following message (WARINING) displayed right.

I believe it's related to setlocale and the difference between OEM and ANSI
encoding, which we had in Windows with the Russian locale.
The startup code of psql sets locale with the call setlocale(LC_ALL, "") and
MSDN documentation says that the call:
Sets the locale to the default, which is the user-default ANSI code page
obtained from the operating system.

After the call all the strings printed with the printf(stdout) will go
through  the ANSI->OEM conversion.

But in the simple_prompt function strings written to con, and such writes go
without conversion.
Were you able to come up with some way to make this work?


--------------070703030602010008050805-- --------------050601040005010707080400 Content-Type: text/x-patch; name="sprompt.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="sprompt.diff" --- original/src/port/sprompt.c 2012-02-24 02:53:36.000000000 +0400 +++ fix/src/port/sprompt.c 2012-03-17 18:52:15.010559900 +0400 @@ -60,14 +60,13 @@ * Do not try to collapse these into one "w+" mode file. Doesn't work on * some platforms (eg, HPUX 10.20). */ +#ifdef WIN32 + termin = stdin; + termout = stderr; +#else termin = fopen(DEVTTY, "r"); termout = fopen(DEVTTY, "w"); - if (!termin || !termout -#ifdef WIN32 - /* See DEVTTY comment for msys */ - || (getenv("OSTYPE") && strcmp(getenv("OSTYPE"), "msys") == 0) -#endif - ) + if (!termin || !termout) { if (termin) fclose(termin); @@ -76,6 +75,7 @@ termin = stdin; termout = stderr; } +#endif #ifdef HAVE_TERMIOS_H if (!echo) --------------050601040005010707080400--