Thread: Re: [PATCHES] WIN32_CONSOLE usage

Re: [PATCHES] WIN32_CONSOLE usage

From
Peter Eisentraut
Date:
Christoph Dalitz writes:

>  a) Write documentation how the win32 console needs to be set up so that
>     psql can handle 8-bit characters.
>     Where should it be added? The Section "Installation on Windows" in the
>     Administrator's Guide seems natural to me.

Sure.

>  b) Add code to psql that prints a warning on startup of psql when the
>     console codepage differs from the windows codepage, something like
>
>     Warning: Console codepage (850) differs from windows codepage (1252)
>              8-bit characters will not work correctly. See PostgreSQL
>              documentation "Installation on Windows" for details.

If you can detect that they are different, why can't you adjust the code
page in that case only?

--
Peter Eisentraut   peter_e@gmx.net


Re: [PATCHES] WIN32_CONSOLE usage

From
Christoph Dalitz
Date:
On Thu, 11 Sep 2003 20:51:24 +0200
Manfred Spraul <manfred@colorfullife.com> wrote:
>
> - OemToChar() and CharToOem() convert all console input/output. In the
> long run this might be the better solution, if it works entirely without
> user intervention. I'm not sure if it's possible to get all corner cases
> right.
>
I do not think that it is possible to handle all cases automatically.
Even restricting the conversion to input/output on stdin/stdout will fail in
some circumstances; eg. with the command "psql < script.sql" when the
script has been written with a windows editor (notepad, emacs or whatever).

That's why we introduced the WIN32_CONSOLE parameter, which was admittedly
not such a good idea and should be withdrawn.

Instructing the user how to set up the console so that 8-bit characters work
once and forever is the "rigth way" IMHO. The user will also profit from this
lesson when he uses some other console application, eg. the sqlite SQL-shell.

I will send in the "Win32 console setup instructions" next week.

Christoph


Re: [PATCHES] WIN32_CONSOLE usage

From
Manfred Spraul
Date:
Christoph Dalitz wrote:

>On Thu, 11 Sep 2003 20:51:24 +0200
>Manfred Spraul <manfred@colorfullife.com> wrote:
>
>
>>- OemToChar() and CharToOem() convert all console input/output. In the
>>long run this might be the better solution, if it works entirely without
>>user intervention. I'm not sure if it's possible to get all corner cases
>>right.
>>
>>
>>
>I do not think that it is possible to handle all cases automatically.
>Even restricting the conversion to input/output on stdin/stdout will fail in
>some circumstances; eg. with the command "psql < script.sql" when the
>script has been written with a windows editor (notepad, emacs or whatever).
>
It would be very hard to get right. Perhaps something like isatty(),
except that it's probably called GetHandleIsConsoleFlag() or something
like that, followed by a check of the code page. But I didn't find a
suitable function yet.

--
    Manfred



Re: [PATCHES] WIN32_CONSOLE usage

From
Manfred Spraul
Date:
Peter Eisentraut wrote:

>If you can detect that they are different, why can't you adjust the code
>page in that case only?
>
>
What should we do if we detect that they differ:
- set the console code page to the ansi code page. This has two
drawbacks: It doesn't work with Indic, because Indic doesn't have an
ansi code page. And the user must still switch the console font. But: if
the user must change the configuration, then he can as easily change
both the font and the code page. Which means: SetConsoleCP is the wrong
approach.
- OemToChar() and CharToOem() convert all console input/output. In the
long run this might be the better solution, if it works entirely without
user intervention. I'm not sure if it's possible to get all corner cases
right.

--
    Manfred




Re: [PATCHES] WIN32_CONSOLE usage

From
Christoph Dalitz
Date:
On Thu, 11 Sep 2003 20:30:53 +0200 (CEST)
Peter Eisentraut <peter_e@gmx.net> wrote:
>
> >  b) Add code to psql that prints a warning on startup of psql when the
> >     console codepage differs from the windows codepage, something like
> >
> >     Warning: Console codepage (850) differs from windows codepage (1252)
> >              8-bit characters will not work correctly. See PostgreSQL
> >              documentation "Installation on Windows" for details.
>
> If you can detect that they are different, why can't you adjust the code
> page in that case only?
>
Because 8-bit characters will not be displayed correctly unless the codepage
is set to the windows codepage *and* the console font is adjusted to a font
that is compatible with this codepage.

Unfortunately the default console font used in the german version of Windows
NT/2000/XP ("Rasterschriftart") is incompatible with the german windows codepage.
Thus the user must change the font to "Lucida Console" (that is the only alternative
font offered) in order to view 8-bit characters. AFAIK this font change cannot be done
automagically from within psql.

Why Microsoft does not configure the german version of Windows so that Umlauts work
out of the box in the console is a different story. Maybe they say: "Do not use
the console! If you do, we leave you in the rain!".

Christoph