Sign in Join

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

Mailing lists / lazarus / 2014-12

FPC 2.7.1 and console output

24 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Hans-Peter Diettrich

First I thank the Lazarus team for the fine 1.3 version, usable for development with FPC trunk (Unicode version). In detail the greyed-out branches in conditional compilation sections are very helpful when inspecting the RTL units :-)

On my first steps with the Unicode RTL I found a different behaviour, when a console program is compiled from an PAS file, and from an LPI/LPR project. [on WinXP, Ansi source files]

When compiled from an PAS file, the behaviour is identical to the direct compilation on the commandline, string output is readable.

When compiled from an LPR file (LPI project), the string output has unreadable UTF-8 encoding, even for UnicodeString. Did I miss some project setting, required for proper console output?

When I try {$codepage 1252}, I get an error during compilation ("file not open")? The "charset" unit, mentioned in help on $codepage, doesn't give any clues about allowed values. What's the correct value for Windows default (western)? Or how else can I establish a global default sourcecode codepage?

DoDi

Reply by email

Mattias Gaertner
to Hans-Peter Diettrich
First I thank the Lazarus team for the fine 1.3 version, usable for development with FPC trunk (Unicode version). In detail the greyed-out branches in conditional compilation sections are very helpful when inspecting the RTL units :-)

Thanks.
Keep in mind that the IDE does not know all flags, so maybe some highlights are wrong. Although so far no one has complained, so it seems to work pretty well.

On my first steps with the Unicode RTL I found a different behaviour, when a console program is compiled from an PAS file, and from an LPI/LPR project. [on WinXP, Ansi source files]

What do you mean with "compiled from an PAS file"?

You can see what parameters the IDE passed to the compiler. Right click on the messages (e.g. the "Compile Project..."), then "About Compiler Project...".

Show quoted text 6 lines
When compiled from an PAS file, the behaviour is identical to the direct compilation on the commandline, string output is readable. When compiled from an LPR file (LPI project), the string output has unreadable UTF-8 encoding, even for UnicodeString. Did I miss some project setting, required for proper console output?

Have you set any flags in the "Configure Build Lazarus" dialog?

What do you mean with "string output"?
In the LCL form?
In the console from writeln?
In the console from debugln?
In a file?

LCL and debugln expect UTF-8, writeln needs DefaultSystemCodePage in FPC 2.7.1 and file is a broad category.

When I try {$codepage 1252}, I get an error during compilation ("file not open")? The "charset" unit, mentioned in help on $codepage, doesn't give any clues about allowed values. What's the correct value for Windows default (western)?
{$codepage cp1252}
Or how else can I establish a global default sourcecode codepage?

If you mean with "global" your project: Add -FcCP1252 to the custom compiler options.

Mattias

Reply by email

Hans-Peter Diettrich
to Mattias Gaertner
Show quoted text 8 lines
On Tue, 02 Dec 2014 11:21:43 +0100 Hans-Peter Diettrich wrote: > On my first steps with the Unicode RTL I found a different behaviour, > when a console program is compiled from an PAS file, and from an LPI/LPR > project. [on WinXP, Ansi source files] What do you mean with "compiled from an PAS file"?

I wrote my first test programs with NotePad, and called FPC from the commandline. These files also compile okay with Lazarus, when loaded as projects.

Next I tried FP, but couldn't figure out how to configure it at all, for using the trunk compiler :-(

Finally I managed to build Lazarus trunk, and that's where I'm now. When creating a project in Lazarus, the default file encoding (now?) seems to be UTF-8 without BOM, at least I had no problems with older versions - maybe because I only used ASCII in my programs, and rarely wrote console programs.

So how can I convince Lazarus to use (and assume) source files of my (non-VCL) projects being Windows codepage (1252)?

You can see what parameters the IDE passed to the compiler. Right click on the messages (e.g. the "Compile Project..."), then "About Compiler Project...".

Then I need an wizard that explains me the consequences of (not) using any possible switch :-(

Have you set any flags in the "Configure Build Lazarus" dialog?

Not yet, I had a hard time until I could build and configure the current Lazarus trunk version. It looks to me as if the last FPC *release* version is required to build Lazarus, while I want to use the *trunk* version for compiling my own projects. If so, how do I tell all that to Lazarus?

What do you mean with "string output"?

WriteLn to the console.

LCL and debugln expect UTF-8, writeln needs DefaultSystemCodePage in FPC 2.7.1 and file is a broad category.

All that should become unimportant with the Unicode RTL, when every API stub expects/returns strings of the according encoding, or converts its arguments to the right encoding. Every file object (TFileStream...) has a settable encoding, under full control of the coder.

I can see two major problems with the current FPC AnsiString model. The first problem is the strange FPC convention, that a string variable can have a different static/dynamic encoding, not only with RawByteString. That convention (flaw) can require an explicit SetCodePage for every string parameter, because a string argument of e.g. static type CP_OEM (for console output) can have any other actual (dynamic) encoding, not useful when passing the string to the external function.

The next problem results from the Delphi incompatible dynamic encoding of CP_ACP(=0), that seems to be used when a literal is stored in an AnsiString. These strings have the encoding assumed at *compile time*, perhaps from a {$codepage ...} switch, which can differ from the DefaultSystemCodepage at *runtime*. Then the conversion routines assume the the string is encoded according to DefaultSystemCodepage, what's not necessarily true:

var
   A: AnsiString;
begin
   a := ' ???';
   WriteLn('CP_ACP=',DefaultSystemCodePage);
   WriteLn('Ansi CP=',StringCodePage(a),' Len=',Length(a),' ="',a,'"');
end.

Reports (on Windows) CP_ACP=1252, string CP=0, and due to the Lazarus File Encoding of UTF-8 the string literal and variable contains UTF-8 (Len=7), as assumed by the compiler. The attempt in WriteLn, to convert the string to CP_OEM from encoding 0, mapped by TranslatePlaceholderCP into DefaultSystemCodePage (=1252 at runtime), results in a conversion of the UTF-8 bytes from CP 1252 into CP_OEM :-(

Even if the string A is assigned to an AnsiString(CP_OEMCP), that string has a dynamic encoding of 437, but contains the 7 UTF-8 bytes :-(

This mess could be eliminated easily, when FPC would store the *true* compile-time encoding with all string literals, not CP_ACP(=0). Delphi string literals instead come with their true dynamic encoding, which never can be 0, and thus can be assigned and shown properly. Above code then will show CP=1252 and Len=4 for the AnsiString variable. What's missing from XE is the automatic conversion on console output into CP_OEM, as done by FPC.
The use of TranslatePlaceholderCP() then also could be reduced to the rare cases, where *user* code is allowed to supply an encoding value (TSystemCodePage) separate from an string, e.g. in the AnsiString type declarations or SetCodePage.

As an ugly hack the coder can use {$codepage UTF8}, *and* force Lazarus to store the source files accordingly, and hope that then the literals have a useful dynamic encoding. This *is* an hack, because it makes the source files almost unusable with other programs (editors...) on Windows and other platforms, which don't have UTF-8 for their default encoding (CP_ACP). I also wonder what will happen on platforms with a default encoding of CP_UTF8, when the user is allowed to and then changes that default codepage into something else, for his entire system or an (FPC) program.

Show quoted text 11 lines
> When I try {$codepage 1252}, I get an error during compilation ("file > not open")? The "charset" unit, mentioned in help on $codepage, doesn't > give any clues about allowed values. What's the correct value for > Windows default (western)? {$codepage cp1252} > Or how else can I establish a global default sourcecode codepage? If you mean with "global" your project: Add -FcCP1252 to the custom compiler options.

Thanks :-)
What does this switch mean, e.g. to my source files?

DoDi

Reply by email

Mattias Gaertner
to Hans-Peter Diettrich
Show quoted text 5 lines
Mattias Gaertner schrieb: [...] I wrote my first test programs with NotePad, and called FPC from the commandline. These files also compile okay with Lazarus, when loaded as projects.

Ok. If they create different output, please post the different command line parameters.

Next I tried FP, but couldn't figure out how to configure it at all, for using the trunk compiler :-(

Do you mean in Lazarus?
In Lazarus 1.2 you set it in Tools / Options / Files In Lazarus 1.3 you could set it global as above or for each project in Project Options / Compiler Options / Paths.

Finally I managed to build Lazarus trunk, and that's where I'm now.

Great.

When creating a project in Lazarus, the default file encoding (now?) seems to be UTF-8 without BOM, at least I had no problems with older versions - maybe because I only used ASCII in my programs, and rarely wrote console programs.

True.

So how can I convince Lazarus to use (and assume) source files of my (non-VCL) projects being Windows codepage (1252)?

There is no option to change the default codepage of new files. But you can change the encoding easily: Right click on source editor / File Settings / Encoding / CP1252.

Show quoted text 6 lines
> You can see what parameters the IDE passed to the compiler. Right click > on the messages (e.g. the "Compile Project..."), then "About Compiler > Project...". Then I need an wizard that explains me the consequences of (not) using any possible switch :-(

The lists and forums have this wizard power.

Show quoted text 5 lines
> Have you set any flags in the "Configure Build Lazarus" dialog? Not yet, I had a hard time until I could build and configure the current Lazarus trunk version. It looks to me as if the last FPC *release* version is required to build Lazarus,

No.
2.6.4 is guaranteed to work.
2.7.1 is a moving target, but we try hard to support it.

[...] > What do you mean with "string output"? WriteLn to the console.

Beware that if you want to test string encoding, console is deceiving. Input and output.

You can use your current codepage as source encoding, or use UTF-8 sources and function UTF8ToConsole for x-platform. The latter is does not magically extend the limitations of the console, but at least other people can read your sources and you can use your code with the LCL.

Mattias

Reply by email

Mattias Gaertner
to Hans-Peter Diettrich: I wrote my first test programs with NotePad, and called FPC from the commandline. These…
Show quoted text 8 lines
[...] I can see two major problems with the current FPC AnsiString model. The first problem is the strange FPC convention, that a string variable can have a different static/dynamic encoding, not only with RawByteString. That convention (flaw) can require an explicit SetCodePage for every string parameter, because a string argument of e.g. static type CP_OEM (for console output) can have any other actual (dynamic) encoding, not useful when passing the string to the external function.

The FPC sources need SetCodePage only in the RTL and only either for codepage conversion functions or for Default(RTL)FileSystemCodePage. It seems it is not a "major" problem for Lazarus users.

Show quoted text 22 lines
The next problem results from the Delphi incompatible dynamic encoding of CP_ACP(=0), that seems to be used when a literal is stored in an AnsiString. These strings have the encoding assumed at *compile time*, perhaps from a {$codepage ...} switch, which can differ from the DefaultSystemCodepage at *runtime*. Then the conversion routines assume the the string is encoded according to DefaultSystemCodepage, what's not necessarily true: var A: AnsiString; begin a := ' ???'; WriteLn('CP_ACP=',DefaultSystemCodePage); WriteLn('Ansi CP=',StringCodePage(a),' Len=',Length(a),' ="',a,'"'); end. Reports (on Windows) CP_ACP=1252, string CP=0, and due to the Lazarus File Encoding of UTF-8 the string literal and variable contains UTF-8 (Len=7), as assumed by the compiler. The attempt in WriteLn, to convert the string to CP_OEM from encoding 0, mapped by TranslatePlaceholderCP into DefaultSystemCodePage (=1252 at runtime), results in a conversion of the UTF-8 bytes from CP 1252 into CP_OEM :-(

I described two ways in my other mail how to handle that.

About the example:
Writeln on the Windows Console requires the console codepage and is therefore limited to characters of this codepage. If your code contains literals for a specific Windows codepage then you are limiting yourself to that codepage (not x-platform). That is your choice. OTOH Lazarus main target is x-platform programs. For example the UTF8ToConsole solution works on Unix too, while your CP1252 example does not.

With FPC 2.7.1 there is a new possibility. With the new UTF-8 mode your example gives:

CP_ACP=65001
Ansi CP=0 Len=7 =" ???"

This works on Unix too, while the CP1252 example does not. Under Windows it works if the console codepage contains "???" (which can be more than one codepage). Basically the compiler adds the UTF8ToConsole for you.

[...] Delphi string literals instead come with their true dynamic encoding, which never can be 0, and thus can be assigned and shown properly. Above code then will show CP=1252 and Len=4 for the AnsiString variable.

No, it should show garbage and Len=7, because the source is UTF-8, while the compiler treats it as your system codepage.

Show quoted text 5 lines
[...] I also wonder what will happen on platforms with a default encoding of CP_UTF8, when the user is allowed to and then changes that default codepage into something else, for his entire system or an (FPC) program.

Depends on what you do.

Show quoted text 5 lines
> If you mean with "global" your project: Add -FcCP1252 to the custom > compiler options. Thanks :-) What does this switch mean, e.g. to my source files?

Same as {$codepage}.
The IDE does not use this flag.

Mattias

Reply by email

Hans-Peter Diettrich
to Mattias Gaertner: On Tue, 02 Dec 2014 22:41:04 +0100 Ok. If they create different output, please post the…
Show quoted text 7 lines
On Tue, 02 Dec 2014 22:41:04 +0100 Hans-Peter Diettrich wrote: > Next I tried FP, but couldn't figure out how to configure it at all, for > using the trunk compiler :-( Do you mean in Lazarus?

No, the FP IDE. It has become almost useless, most options are read-only :-(

Show quoted text 5 lines
>> What do you mean with "string output"? > WriteLn to the console. Beware that if you want to test string encoding, console is deceiving. Input and output.

Until now wrong console output indicated a problem with the encoding of the strings to output - that's what I want to know, for further test. Otherwise the conversion to the actual console CP is working, because the fpc_Write_Text_xyz routines use RawByteString arguments, so that they have to check the dynamic string encoding. Ordinary subroutines, that use other string argument types, will almost produce random results, because AnsiStrings tend to have a dynamic encoding different from the expected (static) encoding. I wonder when this flaw will be fixed :-(

Show quoted text 5 lines
You can use your current codepage as source encoding, or use UTF-8 sources and function UTF8ToConsole for x-platform. The latter is does not magically extend the limitations of the console, but at least other people can read your sources and you can use your code with the LCL.

Using UTF-8 sources *and* {$codepage UTF8} cures the unusable CP_ACP encoding of string literals, they are converted as expected in immediate output or when assigned to any AnsiString. Other settings cannot work with the current handling of AnsiString :-(

DoDi

Reply by email

Hans-Peter Diettrich
to Mattias Gaertner: On Tue, 02 Dec 2014 22:41:04 +0100 The FPC sources need SetCodePage only in the RTL and…
Show quoted text 15 lines
On Tue, 02 Dec 2014 22:41:04 +0100 Hans-Peter Diettrich wrote: > [...] > I can see two major problems with the current FPC AnsiString model. The > first problem is the strange FPC convention, that a string variable can > have a different static/dynamic encoding, not only with RawByteString. > That convention (flaw) can require an explicit SetCodePage for every > string parameter, because a string argument of e.g. static type CP_OEM > (for console output) can have any other actual (dynamic) encoding, not > useful when passing the string to the external function. The FPC sources need SetCodePage only in the RTL and only either for codepage conversion functions or for Default(RTL)FileSystemCodePage. It seems it is not a "major" problem for Lazarus users.

Let's see, currently I try to debug AnsiUpperCase, that doesn't seem to work.
Q: how do I debug the RTL (step into)?

Show quoted text 24 lines
> The next problem results from the Delphi incompatible dynamic encoding > of CP_ACP(=0), that seems to be used when a literal is stored in an > AnsiString. These strings have the encoding assumed at *compile time*, > perhaps from a {$codepage ...} switch, which can differ from the > DefaultSystemCodepage at *runtime*. Then the conversion routines assume > the the string is encoded according to DefaultSystemCodepage, what's not > necessarily true: > > var > A: AnsiString; > begin > a := ' ???'; > WriteLn('CP_ACP=',DefaultSystemCodePage); > WriteLn('Ansi CP=',StringCodePage(a),' Len=',Length(a),' ="',a,'"'); > end. > > Reports (on Windows) CP_ACP=1252, string CP=0, and due to the Lazarus > File Encoding of UTF-8 the string literal and variable contains UTF-8 > (Len=7), as assumed by the compiler. The attempt in WriteLn, to convert > the string to CP_OEM from encoding 0, mapped by TranslatePlaceholderCP > into DefaultSystemCodePage (=1252 at runtime), results in a conversion > of the UTF-8 bytes from CP 1252 into CP_OEM :-( I described two ways in my other mail how to handle that.

I don't want want workarounds for a flawed FPC implementation, I want an FPC working on Windows without hacks.

About the example: Writeln on the Windows Console requires the console codepage and is therefore limited to characters of this codepage.

That's perfectly sufficient for my tests.

Show quoted text 6 lines
If your code contains literals for a specific Windows codepage then you are limiting yourself to that codepage (not x-platform). That is your choice. OTOH Lazarus main target is x-platform programs. For example the UTF8ToConsole solution works on Unix too, while your CP1252 example does not.

What's CP1252 specific in my example?

With FPC 2.7.1 there is a new possibility.

Please note that I *am* using and writing about FPC 2.7.1.

Show quoted text 10 lines
With the new UTF-8 mode your example gives: CP_ACP=65001 Ansi CP=0 Len=7 =" ???" This works on Unix too, while the CP1252 example does not. Under Windows it works if the console codepage contains "???" (which can be more than one codepage). Basically the compiler adds the UTF8ToConsole for you.

This works only for a DefaultSystemCodePage of UTF-8, see your CP_ACP encoding shown above :-(

If this doesn't change, the string encodings are quite useless, and a single AnsiString type of fixed encoding CP_UTF8 were sufficient (and faster, due to omitted string conversions). Windows users may not like that, some prefer to use the default Windows codepage or UTF_16 instead (Delphi compatible).

Show quoted text 7 lines
> [...] > Delphi string literals instead come with their true dynamic encoding, which > never can be 0, and thus can be assigned and shown properly. Above code > then will show CP=1252 and Len=4 for the AnsiString variable. No, it should show garbage and Len=7, because the source is UTF-8, while the compiler treats it as your system codepage.

Well, I tested my program with XE, with the default Windows textfile encoding. When FPC or Lazarus has problems with such a program file, then something is flawed :-(

DoDi

Reply by email

Mattias Gaertner
to Hans-Peter Diettrich: No, the FP IDE. It has become almost useless, most options are read-only :-( Until now…
Show quoted text 7 lines
[...] Otherwise the conversion to the actual console CP is working, because the fpc_Write_Text_xyz routines use RawByteString arguments, so that they have to check the dynamic string encoding. Ordinary subroutines, that use other string argument types, will almost produce random results, because AnsiStrings tend to have a dynamic encoding different from the expected (static) encoding.

What example are you referring to?

Show quoted text 5 lines
[...] Using UTF-8 sources *and* {$codepage UTF8} cures the unusable CP_ACP encoding of string literals, they are converted as expected in immediate output or when assigned to any AnsiString. Other settings cannot work with the current handling of AnsiString :-(

CP_ACP is usable with the DefaultSystemCodepage.

Mattias

Reply by email

Sven Barth
to Hans-Peter Diettrich: No, the FP IDE. It has become almost useless, most options are read-only :-( Until now…
"Hans-Peter Diettrich" wrote 8 lines
Mattias Gaertner schrieb: > On Tue, 02 Dec 2014 22:41:04 +0100 > Hans-Peter Diettrich wrote: >> Next I tried FP, but couldn't figure out how to configure it at all,

for using the trunk compiler :-(

Show quoted text 6 lines
> > > Do you mean in Lazarus? No, the FP IDE. It has become almost useless, most options are read-only

:-(

You need to build the FP included with trunk, because the compiler is statically linked into FP. This is usually done when you do a "make all" or at least when you do a "make install".

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20141203/d61f9bb5/attachment.html>

Reply by email

Mattias Gaertner
to Hans-Peter Diettrich: Let's see, currently I try to debug AnsiUpperCase, that doesn't seem to work. Q: how do I…
[...] Q: how do I debug the RTL (step into)?

Compile it with debugging info (-gl) and install it.

Show quoted text 9 lines
[...] > If your code contains > literals for a specific Windows codepage then you are limiting > yourself to that codepage (not x-platform). That is your choice. > OTOH Lazarus main target is x-platform programs. For example the > UTF8ToConsole solution works on Unix too, while your CP1252 > example does not. What's CP1252 specific in my example?

Your example works if you use CP1252 as source encoding, as I have told you. I'm not sure why you call that a 'hack'.

Show quoted text 10 lines
[...] >> Delphi string literals instead come with their true dynamic encoding, which >> never can be 0, and thus can be assigned and shown properly. Above code >> then will show CP=1252 and Len=4 for the AnsiString variable. > > No, it should show garbage and Len=7, because the source is UTF-8, > while the compiler treats it as your system codepage. Well, I tested my program with XE, with the default Windows textfile encoding.

Ah, so you tested CP1252 encoding under XE.
The same works under FPC.

When FPC or Lazarus has problems with such a program file, then something is flawed :-(

PEBCAK

Mattias

Reply by email

waldo kitty
to Hans-Peter Diettrich: No, the FP IDE. It has become almost useless, most options are read-only :-( Until now…
Hans-Peter Diettrich wrote 10 lines
Mattias Gaertner schrieb: > On Tue, 02 Dec 2014 22:41:04 +0100 > Hans-Peter Diettrich wrote: >> Next I tried FP, but couldn't figure out how to configure it at all, for >> using the trunk compiler :-( > > Do you mean in Lazarus? No, the FP IDE. It has become almost useless, most options are read-only :-(

i haven't found this... last night (really very early this morning) i had to add some paths to my FP so that i could get it to compile a FileMask demo program that uses the lazarus Masks unit... since i already had it working as a lazarus project, i went into the project's options and used the "show options" button at the bottom of the screen... i copied the values shown and pasted them into my FP.CFG file... some slight editing to fix them up as the rest and remove duplicates or conflicting ones and then i started FP again... when i went looking at the options and directories and such, everything was in place as expected and my project was able to be compiled with FP just as from lazarus...

something that comes to mind, though, is where you state that you wanted to configure FP for FPC trunk... mine is running FPC trunk and i don't see any way of changing that /within/ FP... the only way i can think of is maybe by the PATH that is set before starting FP or maybe there's a $fpversion that can be used but i've not found a way for that to contain and work with "trunk"... only numerics like "2.6.4" or "2.7.1" seem to show up in that variable...

NOTE: No off-list assistance is given without prior approval. Please *keep mailing list traffic on the list* unless private contact is specifically requested and granted.

Reply by email

waldo kitty
to Sven Barth: for using the trunk compiler :-( :-( You need to build the FP included with trunk,…
Sven Barth wrote 6 lines
Am 03.12.2014 16:51 schrieb "Hans-Peter Diettrich" < > No, the FP IDE. It has become almost useless, most options are read-only :-( You need to build the FP included with trunk, because the compiler is statically linked into FP. This is usually done when you do a "make all" or at least when you do a "make install".

ahhh... it would be nice to be able to specify which fpc to use in the same way that one can do with lazarus and other tools ;)

NOTE: No off-list assistance is given without prior approval. Please *keep mailing list traffic on the list* unless private contact is specifically requested and granted.

Reply by email

waldo kitty
to Mattias Gaertner: On Wed, 03 Dec 2014 16:46:43 +0100 Compile it with debugging info (-gl) and install it.…
Mattias Gaertner wrote 7 lines
On Wed, 03 Dec 2014 16:46:43 +0100 Hans-Peter Diettrich wrote: > [...] > Q: how do I debug the RTL (step into)? Compile it with debugging info (-gl) and install it.

would that be something like

OPT="-gl -gh -dHEAPTRC_WINDOW"

maybe like the following?

make all install INSTALL_PREFIX=%myFPCpath% PP=%myFPCbinutils%\%ppcbinary% DATA2INC=%myFPCpath%\utils\data2inc.exe OPT="-gl -gh -dHEAPTRC_WINDOW"

NOTE: No off-list assistance is given without prior approval. Please *keep mailing list traffic on the list* unless private contact is specifically requested and granted.

Reply by email

Sven Barth
to waldo kitty: ahhh... it would be nice to be able to specify which fpc to use in the same way that one…
"waldo kitty" wrote 5 lines
On 12/3/2014 11:26 AM, Sven Barth wrote: > > Am 03.12.2014 16:51 schrieb "Hans-Peter Diettrich" < > > No, the FP IDE. It has become almost useless, most options are

read-only :-(

> > You need to build the FP included with trunk, because the compiler is

statically

> linked into FP. This is usually done when you do a "make all" or at

least when

> you do a "make install". ahhh... it would be nice to be able to specify which fpc to use in the

same way that one can do with lazarus and other tools ;)

Considering that FP has a much smaller user base than Lazarus (not to speak of features even), it's just not worth it.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20141203/42584a12/attachment-0001.html>

Reply by email

waldo kitty
to Sven Barth
Sven Barth wrote 16 lines
Am 03.12.2014 18:33 schrieb "waldo kitty" : > > On 12/3/2014 11:26 AM, Sven Barth wrote: >> >> Am 03.12.2014 16:51 schrieb "Hans-Peter Diettrich" >> > No, the FP IDE. It has become almost useless, most options are read-only :-( >> >> You need to build the FP included with trunk, because the compiler is statically >> linked into FP. This is usually done when you do a "make all" or at least when >> you do a "make install". > > ahhh... it would be nice to be able to specify which fpc to use in the same > way that one can do with lazarus and other tools ;) Considering that FP has a much smaller user base than Lazarus (not to speak of features even), it's just not worth it.

;) i guess my current method whereby i change the path to point to the desired FPC version is the only real way... i have a little script that i use, runfp, which sets up my environment... it requires the version of FPC i want to use to be specified on the command line...

eg:
runfp 2.6.2
runfp 2.6.4
runfp trunk

but using "trunk" messes up things that use $FPVERSION as that requires that i have that version of FPC in a dedicated directory other than trunk... but hey, it works for now and i only have to make sure that my FP.CFG and similar files are correct for the version i'm currently playing with...

NOTE: No off-list assistance is given without prior approval. Please *keep mailing list traffic on the list* unless private contact is specifically requested and granted.

Reply by email

Sven Barth
to waldo kitty
waldo kitty wrote 40 lines
On 12/3/2014 1:58 PM, Sven Barth wrote: > Am 03.12.2014 18:33 schrieb "waldo kitty" : > > > > On 12/3/2014 11:26 AM, Sven Barth wrote: > >> > >> Am 03.12.2014 16:51 schrieb "Hans-Peter Diettrich" > > >> > No, the FP IDE. It has become almost useless, most options are > read-only :-( > >> > >> You need to build the FP included with trunk, because the compiler > is statically > >> linked into FP. This is usually done when you do a "make all" or > at least when > >> you do a "make install". > > > > ahhh... it would be nice to be able to specify which fpc to use in > the same > > way that one can do with lazarus and other tools ;) > > Considering that FP has a much smaller user base than Lazarus (not to > speak of > features even), it's just not worth it. ;) i guess my current method whereby i change the path to point to the desired FPC version is the only real way... i have a little script that i use, runfp, which sets up my environment... it requires the version of FPC i want to use to be specified on the command line... eg: runfp 2.6.2 runfp 2.6.4 runfp trunk but using "trunk" messes up things that use $FPVERSION as that requires that i have that version of FPC in a dedicated directory other than trunk... but hey, it works for now and i only have to make sure that my FP.CFG and similar files are correct for the version i'm currently playing with...

I have the same, just with 2.7.1 instead of trunk ;) Though I also replace my .fpc.cfg which is a symlink to ".config/fpc/NAME.cfg" (where NAME is the one I pass to my "switch-fpc" script :) )

Regards,
Sven

Reply by email

Hans-Peter Diettrich
to Mattias Gaertner: On Wed, 03 Dec 2014 16:46:43 +0100 Compile it with debugging info (-gl) and install it.…
Show quoted text 7 lines
On Wed, 03 Dec 2014 16:46:43 +0100 Hans-Peter Diettrich wrote: > [...] > Q: how do I debug the RTL (step into)? Compile it with debugging info (-gl) and install it.

Thanks, I added OPT="-gl" to the "make" commandline, and it worked :-)

Show quoted text 11 lines
> [...] >> If your code contains >> literals for a specific Windows codepage then you are limiting >> yourself to that codepage (not x-platform). That is your choice. >> OTOH Lazarus main target is x-platform programs. For example the >> UTF8ToConsole solution works on Unix too, while your CP1252 >> example does not. > What's CP1252 specific in my example? Your example works if you use CP1252 as source encoding, as I have told you. I'm not sure why you call that a 'hack'.

I included the code (readable by everybody), didn't transmit an file. Also UTF8ToConsole seems not to exist any more in FPC 2.7.1, and should not be required any more.
So I'm not sure what you mean :-(

Just tested on WinXP:

program test;
var a: AnsiString;
begin
   a := '???';
   WriteLn(a,'???');
end;

works differently with file encoding Ansi, UTF-8 and UTF-8bom. The latter correctly shows '??????', else a mix of several encodings shows up in the console.

Using the default Lazarus file encoding (UTF-8 without BOM) requires to add {$codepage UTF8}, to make the program (hopefully) work on either platform. {$codepage UTF8} requires UTF-8 file encoding as well, doesn't compile when stored as Ansi.

Adding SysUtils, and AnsiUpperCase for the WriteLn arguments, correctly shows '??????' in Ansi file encoding, but '??????' in UTF8bom encoding, garbage with UTF-8 file encoding, and again '??????' with added {$codepage UTF8}.

Thus portable source files seem to be bound to both file and $codepage UTF-8, disallowing different CP_ACP settings (for now).

Since I'm just exploring the Unicode support, I hope to mention in the future all related options, possibly influencing the behaviour of sample code. Apart from that I'd expect (hope) that a given (Delphi...) project will work in FPC/Lazarus as well, at least on Windows, regardless of inobvious requirements like CP_ACP settings (see bottom lines).

Show quoted text 10 lines
> [...] >>> Delphi string literals instead come with their true dynamic encoding, which >>> never can be 0, and thus can be assigned and shown properly. Above code >>> then will show CP=1252 and Len=4 for the AnsiString variable. >> No, it should show garbage and Len=7, because the source is UTF-8, >> while the compiler treats it as your system codepage. > Well, I tested my program with XE, with the default Windows textfile > encoding. Ah, so you tested CP1252 encoding under XE.

How else should I compare the results of running the same code in Delphi and FPC/Lazarus? Actually I'm testing the Delphi compatibility of FPC (trunk).

Show quoted text 6 lines
The same works under FPC. > When FPC or Lazarus has problems with such a program file, > then something is flawed :-( PEBCAK

Please point me to the according Lazarus documentation.

When some Delphi user wants to find out whether Lazarus is a usable alternative, what should he know before trying to run some Delphi code in Lazarus? If this is not documented appropriately, many people may drop Lazarus immediately as unusable (incompatible...) :-(

DoDi

Reply by email

Hans-Peter Diettrich
to Mattias Gaertner: On Wed, 03 Dec 2014 16:06:28 +0100 What example are you referring to? CP_ACP is usable…
Show quoted text 12 lines
On Wed, 03 Dec 2014 16:06:28 +0100 Hans-Peter Diettrich wrote: > [...] > Otherwise the conversion to the actual console CP is working, because > the fpc_Write_Text_xyz routines use RawByteString arguments, so that > they have to check the dynamic string encoding. Ordinary subroutines, > that use other string argument types, will almost produce random > results, because AnsiStrings tend to have a dynamic encoding different > from the expected (static) encoding. What example are you referring to?

See AnsiUpperCase.

Show quoted text 7 lines
> [...] > Using UTF-8 sources *and* {$codepage UTF8} cures the unusable CP_ACP > encoding of string literals, they are converted as expected in immediate > output or when assigned to any AnsiString. Other settings cannot work > with the current handling of AnsiString :-( CP_ACP is usable with the DefaultSystemCodepage.

Currently AnsiUpperCase etc. will work on Windows *only* if DefaultSystemCodePage matches the WinAPI CP_ACP.

DoDi

Reply by email

Mattias Gaertner
to Hans-Peter Diettrich: Thanks, I added OPT="-gl" to the "make" commandline, and it worked :-) I included the…
Show quoted text 5 lines
[...] I included the code (readable by everybody), didn't transmit an file. Also UTF8ToConsole seems not to exist any more in FPC 2.7.1, and should not be required any more. So I'm not sure what you mean :-(

UTF8Console is needed, when your source is UTF-8, but the compiler thinks it is Windows CP. UTF8Console is defined in LazUTF8. An alternative is UTF8Decode.

Show quoted text 12 lines
Just tested on WinXP: program test; var a: AnsiString; begin a := '???'; WriteLn(a,'???'); end; works differently with file encoding Ansi, UTF-8 and UTF-8bom. The latter correctly shows '??????', else a mix of several encodings shows up in the console.

I see. Indeed I never tried passing a constant in writeln. Does Delphi also pass constants unconverted to writeln?

Using the default Lazarus file encoding (UTF-8 without BOM) requires to add {$codepage UTF8}, to make the program (hopefully) work on either platform.

Well, it only works on platforms with '???' in their console codepage.

{$codepage UTF8} requires UTF-8 file encoding as well, doesn't compile when stored as Ansi.

What do you mean with "doesn't compile"? What compiler error?

Adding SysUtils, and AnsiUpperCase for the WriteLn arguments, correctly shows '??????' in Ansi file encoding, but '??????' in UTF8bom encoding, garbage with UTF-8 file encoding, and again '??????' with added {$codepage UTF8}.

Thanks. Confirmed.
I will add AnsiUpperCase to the list.

[...]

Mattias

Reply by email

Mattias Gaertner
to Hans-Peter Diettrich: See AnsiUpperCase. Currently AnsiUpperCase etc. will work on Windows *only* if…
Show quoted text 10 lines
[...] >> Using UTF-8 sources *and* {$codepage UTF8} cures the unusable CP_ACP >> encoding of string literals, they are converted as expected in immediate >> output or when assigned to any AnsiString. Other settings cannot work >> with the current handling of AnsiString :-( > > CP_ACP is usable with the DefaultSystemCodepage. Currently AnsiUpperCase etc. will work on Windows *only* if DefaultSystemCodePage matches the WinAPI CP_ACP.

Probably some other widestringmanager function have the same problem. And some other functions have some unneeded overhead for DefaultSystemCodePage CP_UTF8.
Maybe the paswstring can be adapted.

Mattias

Reply by email

Hans-Peter Diettrich
to Mattias Gaertner: On Thu, 04 Dec 2014 07:00:59 +0100 UTF8Console is needed, when your source is UTF-8, but…
Show quoted text 6 lines
On Thu, 04 Dec 2014 07:00:59 +0100 Hans-Peter Diettrich wrote: UTF8Console is needed, when your source is UTF-8, but the compiler thinks it is Windows CP. UTF8Console is defined in LazUTF8. An alternative is UTF8Decode.

Thanks :-)

Show quoted text 14 lines
> Just tested on WinXP: > > program test; > var a: AnsiString; > begin > a := '???'; > WriteLn(a,'???'); > end; > > works differently with file encoding Ansi, UTF-8 and UTF-8bom. The > latter correctly shows '??????', else a mix of several encodings shows > up in the console. I see.

Only after testing the string encodings I found out that $codepage does not affect CP_ACP, this was unclear to me before. A new Lazarus version instead may try to set DefaultSystemCodePage to UTF-8, in order to preserve compatibility with the current assumption about UTF-8 encoding with AnsiStrings.

Indeed I never tried passing a constant in writeln.

You never wrote text or separtors?

Does Delphi also pass constants unconverted to writeln?

Delphi does not convert anything in console output, the user must convert everything to CP_OEM :-(

> {$codepage UTF8} requires UTF-8 file encoding as well, doesn't > compile when stored as Ansi. What do you mean with "doesn't compile"? What compiler error?

Hmm, until yesterday the error message was "illegal character..." - or was it "file I/O error"? - with non-ASCII characters in string literals. Just tested, the error has disappeared, instead garbage is displayed at runtime. Now string literals seem to be stored as UTF-8 (file encoding), with 0 (CP_ACP) for the encoding. That means that the UTF-8 bytes are treated at runtime as being DefaultSystemCodePage characters. You certainly can imagine what happens in a conversion of these bytes into a different encoding :-(

DoDi

Reply by email

Mattias Gaertner
to Hans-Peter Diettrich
Show quoted text 30 lines
[...] Mattias Gaertner schrieb: > On Thu, 04 Dec 2014 07:00:59 +0100 > Hans-Peter Diettrich wrote: > UTF8Console is needed, when your source is UTF-8, but the compiler > thinks it is Windows CP. UTF8Console is defined in LazUTF8. > An alternative is UTF8Decode. Thanks :-) >> Just tested on WinXP: >> >> program test; >> var a: AnsiString; >> begin >> a := '???'; >> WriteLn(a,'???'); >> end; >> >> works differently with file encoding Ansi, UTF-8 and UTF-8bom. The >> latter correctly shows '??????', else a mix of several encodings shows >> up in the console. > > I see. Only after testing the string encodings I found out that $codepage does not affect CP_ACP, this was unclear to me before. A new Lazarus version instead may try to set DefaultSystemCodePage to UTF-8, in order to preserve compatibility with the current assumption about UTF-8 encoding with AnsiStrings.

Yes, this fixes many problems. OTOH it create some new (e.g. ThousandSeparator).

> Indeed I never tried passing a constant in writeln. You never wrote text or separtors?

I meant my tests with fpc 2.7.1. ;)

> Does Delphi also pass constants unconverted to writeln? Delphi does not convert anything in console output, the user must convert everything to CP_OEM :-(

Same as fpc 2.6.4.
What function do Delphians use?

Mattias

Reply by email