Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2012-06

How to set code page in terminal? (Windows)

15 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

silvioprog

Hello,

I'm trying to write "Atenção" in terminal, but it writes "At├º├úo" instead of "Atenção" (please see http://imagebin.org/217387 ). :(

On Linux it's OK.

My test code is (or zip in attached):

------------------------------------------------------------
program test;
{$mode objfpc}{$H+}
{$IFDEF MSWINDOWS}
uses
  windows;
{$ENDIF}
const
  C = 'Atenção';
begin
{$IFDEF MSWINDOWS}
  SetConsoleOutputCP(CP_UTF8);
  SetTextCodePage(Output, CP_UTF8);
{$ENDIF}
  WriteLn(C);
end.
------------------------------------------------------------

Lazarus 1.1 r37649 FPC 2.7.1 i386-win32-win32/win64 | Windows 7 - 64

Thanks.

Silvio Clécio My public projects - github.com/silvioprog

Reply by email

waldo kitty
to silvioprog
silvioprog wrote
Hello, I'm trying to write "Atenção" in terminal, but it writes "At├º├úo" instead of "Atenção" (please see http://imagebin.org/217387 ). :(

open a cmd window and type "chcp"... if that still exists in win7, it should tell you the codepage being used... looking at your example, it appears that something is translating what you type to utf-8 and that your terminal cannot render utf-8... i fight the same battle in another world with a huge amount of CP437 oriented software that will never be updated...

i will try your code on my boxen to see what it gives... now to figure out how to generate those characters with my US keyboard... i /think/ ALT-135 is the "lowercase c with a tail" 'ç' and the other one is the "lowercase a with a wavy line over it" but i can't find it :? maybe i can paste it from this message into that window?

Reply by email

waldo kitty
to silvioprog: I'm trying to write "Atenção" in terminal, but it writes "At├º├úo" instead of…

i said i'd try to test...

silvioprog wrote 16 lines
------------------------------------------------------------ program test; {$mode objfpc}{$H+} {$IFDEF MSWINDOWS} uses windows; {$ENDIF} const C = 'Atenção'; begin {$IFDEF MSWINDOWS} SetConsoleOutputCP(CP_UTF8); SetTextCodePage(Output, CP_UTF8);

Options changed, recompiling clean with -B
Hint: Start of reading config file C:\freepascal\fpc\2.6.0\bin\i386-win32\fpc.cfg Hint: End of reading config file C:\freepascal\fpc\2.6.0\bin\i386-win32\fpc.cfg Free Pascal Compiler version 2.6.0 [2012/05/21] for i386 Copyright (c) 1993-2011 by Florian Klaempfl and others Target OS: Win32 for i386
Compiling test.lpr
test.lpr(15,18) Error: Identifier not found "SetTextCodePage" test.lpr(20) Fatal: There were 1 errors compiling module, stopping

Show quoted text 6 lines
{$ENDIF} WriteLn(C); end. ------------------------------------------------------------ Lazarus 1.1 r37649 FPC 2.7.1 i386-win32-win32/win64 | Windows 7 - 64

lazarus 1.1 r37695 fpc 2.6.0 i386-win32 | w2k

maybe i'll try on my vista box? i need to updatelaz on it anyway ;)

Reply by email

waldo kitty
to Paul Ishenin: 22.06.12 5:39, silvioprog пишет: ... try {$codepage utf8} or add an utf8 BOM because…
Paul Ishenin wrote 11 lines
22.06.12 5:39, silvioprog пишет: > Hello, > > I'm trying to write "Atenção" in terminal, but it writes "At├º├úo" > instead of "Atenção" (please see http://imagebin.org/217387 ). :( ... > program test; > > {$mode objfpc}{$H+} try {$codepage utf8} or add an utf8 BOM because your constant is encoded in utf8.

ha! i should have caught that when i was playing with it in fp because it did show as 2character characters... i just didn't recognize for such... my eyes are crossed from too much codepage fighting in my other world :?

Reply by email

silvioprog
to Paul Ishenin: 22.06.12 5:39, silvioprog пишет: ... try {$codepage utf8} or add an utf8 BOM because…

2012/6/21 Paul Ishenin :

Show quoted text 19 lines
22.06.12 5:39, silvioprog пишет: > Hello, > > I'm trying to write "Atenção" in terminal, but it writes "At├º├úo" > instead of "Atenção" (please see http://imagebin.org/217387 ). :( ... > program test; > > {$mode objfpc}{$H+} try {$codepage utf8} or add an utf8 BOM because your constant is encoded in utf8. Best regards, Paul Ishenin

Oh yeah! Worked fine with this define: http://imagebin.org/217405.

Thank you! ^^

Silvio Clécio My public projects - github.com/silvioprog

Reply by email

Mark Morgan Lloyd
to Paul Ishenin: 22.06.12 5:39, silvioprog пишет: ... try {$codepage utf8} or add an utf8 BOM because…
Paul Ishenin wrote 12 lines
22.06.12 5:39, silvioprog пишет: > Hello, > > I'm trying to write "Atenção" in terminal, but it writes "At├º├úo" > instead of "Atenção" (please see http://imagebin.org/217387 ). :( ... > program test; > > {$mode objfpc}{$H+} try {$codepage utf8} or add an utf8 BOM because your constant is encoded in utf8.

What version of FPC introduced this directive? I've got a couple of places I could do with documenting it as a prerequisite.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Sven Barth
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 17 lines
Paul Ishenin wrote: > 22.06.12 5:39, silvioprog пишет: >> Hello, >> >> I'm trying to write "Atenção" in terminal, but it writes "At├º├úo" >> instead of "Atenção" (please see http://imagebin.org/217387 ). :( > ... >> program test; >> >> {$mode objfpc}{$H+} > > try {$codepage utf8} or add an utf8 BOM because your constant is > encoded in utf8. What version of FPC introduced this directive? I've got a couple of places I could do with documenting it as a prerequisite.

2.6.0 has it already, AFAIK at least also 2.4.x.

Regards,
sven

Reply by email

Jonas Maebe
to Sven Barth

Sven Barth wrote on Fri, 22 Jun 2012:

Show quoted text 9 lines
Am 22.06.2012 09:27, schrieb Mark Morgan Lloyd: > Paul Ishenin wrote: >> try {$codepage utf8} or add an utf8 BOM because your constant is >> encoded in utf8. > > What version of FPC introduced this directive? I've got a couple of > places I could do with documenting it as a prerequisite. 2.6.0 has it already, AFAIK at least also 2.4.x.

Support for this feature predates svn revision 1, so it was probably already in 2.0.x.

Jonas

Reply by email

Sven Barth
to Jonas Maebe
"Jonas Maebe" wrote 20 lines
Sven Barth wrote on Fri, 22 Jun 2012: > Am 22.06.2012 09:27, schrieb Mark Morgan Lloyd: >> >> Paul Ishenin wrote: >>> >>> try {$codepage utf8} or add an utf8 BOM because your constant is >>> encoded in utf8. >> >> >> What version of FPC introduced this directive? I've got a couple of >> places I could do with documenting it as a prerequisite. > > > 2.6.0 has it already, AFAIK at least also 2.4.x. Support for this feature predates svn revision 1, so it was probably

already in 2.0.x.

Even better then :)

Regards,
Sven

Reply by email

Mark Morgan Lloyd
to Jonas Maebe: Sven Barth wrote on Fri, 22 Jun 2012: Support for this feature predates svn revision 1,…
Jonas Maebe wrote 14 lines
Sven Barth wrote on Fri, 22 Jun 2012: > Am 22.06.2012 09:27, schrieb Mark Morgan Lloyd: >> Paul Ishenin wrote: >>> try {$codepage utf8} or add an utf8 BOM because your constant is >>> encoded in utf8. >> >> What version of FPC introduced this directive? I've got a couple of >> places I could do with documenting it as a prerequisite. > > 2.6.0 has it already, AFAIK at least also 2.4.x. Support for this feature predates svn revision 1, so it was probably already in 2.0.x.

Thanks Jonas, noted. So in practical terms it predates the point at which the LCL moved from favouring GTK to GTK2.

I've been using non-ASCII characters for a year or so when displaying e.g. Cyrillic RTTY output, but in general have set up the translation tables using numeric constants.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Marco van de Voort
to silvioprog: I'm trying to write "Atenção" in terminal, but it writes "At├º├úo" instead of…

In our previous episode, silvioprog said:

Show quoted text 20 lines
------------------------------------------------------------ program test; {$mode objfpc}{$H+} {$IFDEF MSWINDOWS} uses windows; {$ENDIF} const C = 'Aten??o'; begin {$IFDEF MSWINDOWS} SetConsoleOutputCP(CP_UTF8); SetTextCodePage(Output, CP_UTF8); {$ENDIF} WriteLn(C); end. ------------------------------------------------------------

Windows has two sets of console routines. One set that is universal over win9x and WinNT, one that is WinNT only.

FPC uses the universal ones (still), the above code is WinNT only.

Reply by email

Sven Barth
to Marco van de Voort
Marco van de Voort wrote 26 lines
In our previous episode, silvioprog said: > ------------------------------------------------------------ > program test; > > {$mode objfpc}{$H+} > > {$IFDEF MSWINDOWS} > uses > windows; > {$ENDIF} > > const > C = 'Aten??o'; > begin > {$IFDEF MSWINDOWS} > SetConsoleOutputCP(CP_UTF8); > SetTextCodePage(Output, CP_UTF8); > {$ENDIF} > WriteLn(C); > end. > ------------------------------------------------------------ Windows has two sets of console routines. One set that is universal over win9x and WinNT, one that is WinNT only. FPC uses the universal ones (still), the above code is WinNT only.

Another reason to deprecate 9x? ;)

Regards,
Sven

Reply by email

Marco van de Voort
to Sven Barth

In our previous episode, Sven Barth said:

Show quoted text 6 lines
> Windows has two sets of console routines. One set that is universal over > win9x and WinNT, one that is WinNT only. > > FPC uses the universal ones (still), the above code is WinNT only. Another reason to deprecate 9x? ;)

Unicode? Actually, it was the main one.

Reply by email

Sven Barth
to Marco van de Voort
Marco van de Voort wrote 9 lines
In our previous episode, Sven Barth said: >> Windows has two sets of console routines. One set that is universal over >> win9x and WinNT, one that is WinNT only. >> >> FPC uses the universal ones (still), the above code is WinNT only. > > Another reason to deprecate 9x? ;) Unicode? Actually, it was the main one.

No, the point that we currently use the universal APIs while there is a NT only set of APIs which might solve some things.

Regards,
Sven

Reply by email