pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexander LAW <exclusion@gmail.com>
To: Alvaro Herrera <alvherre@commandprompt.com>
Cc: Pg Bugs <pgsql-bugs@postgresql.org>
Subject: Re: BUG #6510: A simple prompt is displayed using wrong charset
Date: Sun, 18 Mar 2012 13:04:51 +0400
Message-ID: <4F65A533.7090208@gmail.com> (raw)
In-Reply-To: <1331925178-sup-9261@alvh.no-ip.org>
References: <E1S3twb-0004OY-4g@wrigleys.postgresql.org>
	<1331925178-sup-9261@alvh.no-ip.org>

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?
>

Attachments:

sprompt.diff (text/x-patch, 720B) download --- 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)

view thread (26+ messages)  latest in thread

Message-ID: <4F65A533.7090208@gmail.com>
Permalink:  ../4F65A533.7090208@gmail.com/
Also on:    postgresql.org/message-id/4F65A533.7090208@gmail.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: exclusion@gmail.com, alvherre@commandprompt.com
  Subject: Re: BUG #6510: A simple prompt is displayed using wrong charset
  In-Reply-To: <4F65A533.7090208@gmail.com>
  References: <E1S3twb-0004OY-4g@wrigleys.postgresql.org> <1331925178-sup-9261@alvh.no-ip.org> <4F65A533.7090208@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox