Recent

Author Topic: How to write all unicode chars?  (Read 1042 times)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5795
    • wiki
Re: How to write all unicode chars?
« Reply #15 on: November 15, 2019, 04:15:38 am »
Maybe a look at the begin of the crt unit can help ....
Code: Pascal  [Select]
  1. procedure SetSafeCPSwitching(Switching:Boolean);
  2. procedure SetUseACP(ACP:Boolean);
  3.  
Code: Pascal  [Select]
  1.     UseACP        : Boolean; (* True means using active process codepage for
  2.                                 console output, False means use the original
  3.                                 setting (usually OEM codepage). *)
  4.     SafeCPSwitching : Boolean; (* True in combination with UseACP means that
  5.                                   the console codepage will be set on every
  6.                                   output, False means that the console codepage
  7.                                   will only be set on Initialization and
  8.                                   Finalization *)
  9.  

I haven't done any tests, but those global vars sound like they are all you need. Though no idea if they have side effects.

lucamar

  • Hero Member
  • *****
  • Posts: 2145
Re: How to write all unicode chars?
« Reply #16 on: November 15, 2019, 11:45:00 am »
IIRC the crt unit resets the console codepage upon every write it does.

Is there any way to circumvent this? Then I could set my own codepages as needed (e.g., before and after writes).

This bit of code should do the trick:

Code: Pascal  [Select]
  1. Assign(Input, ''); Reset(Input);
  2. Assign(Output, ''); Rewrite(Output);

Any Read/Write from/to console should then go through the "normal" channels rather than CRT's replacements.

Note, though, that I've not tested it.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.4/2.0.6  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

dculp

  • Full Member
  • ***
  • Posts: 111
Re: How to write all unicode chars?
« Reply #17 on: November 15, 2019, 12:00:19 pm »
Martin_fr --

This seems like exactly what I need.

After searching through all files on my Lazarus distribution (2.0.2, FPC 3.0.4), I couldn't find either  SetSafeCPSwitching or SetUseACP. However, I did find them here (
https://github.com/graemeg/freepascal/blob/master/packages/rtl-console/src/win/crt.pp) and a discussion here (https://bugs.freepascal.org/view.php?id=32558). The discussion from the last link is the exact problem that I was ultimately trying to resolve (writing extended ASCII chars under Windows 10). I have not read through the entire discussion but I see that it was resolved on 2017-12-14 but not scheduled for release until v.3.2.0 (so not in the current release 3.0.4).

I'll try this revised crt.pp.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5795
    • wiki
Re: How to write all unicode chars?
« Reply #18 on: November 15, 2019, 02:31:11 pm »
After searching through all files on my Lazarus distribution (2.0.2, FPC 3.0.4), I couldn't find either  SetSafeCPSwitching or SetUseACP.

They are part of fpc. If you used the official installer, then that is in a subfolder of your install.

Anyway, you can always use code navigation.
"uses crt;"
ctrl left mouse click on crt.

lucamar

  • Hero Member
  • *****
  • Posts: 2145
Re: How to write all unicode chars?
« Reply #19 on: November 15, 2019, 02:46:32 pm »
After searching through all files on my Lazarus distribution (2.0.2, FPC 3.0.4), I couldn't find either  SetSafeCPSwitching or SetUseACP.

They are part of fpc. If you used the official installer, then that is in a subfolder of your install.

Not in FP 3.0.4; they'll be in 3.2
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.4/2.0.6  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

dculp

  • Full Member
  • ***
  • Posts: 111
Re: How to write all unicode chars?
« Reply #20 on: November 15, 2019, 03:02:34 pm »
Quote
They are part of fpc. If you used the official installer, then that is in a subfolder of your install.

Yes, I can find the crt.pp unit in my Lazarus folder path. However, my crt.pp unit has neither SetSafeCPSwitching nor SetUseACP (see short intro code comparisons below). I had downloaded Lazarus 2.0.2 (FPC 3.0.4; Windows 32 bits version) from the Lazarus website and then installed directly from the download.

My crt.pp --
Code: Pascal  [Select]
  1. unit crt;
  2.  
  3. interface
  4.  
  5. {$i crth.inc}
  6.  
  7. procedure Window32(X1,Y1,X2,Y2: DWord);
  8. procedure GotoXY32(X,Y: DWord);
  9. function WhereX32: DWord;
  10. function WhereY32: DWord;
  11.  
  12. implementation
  13.  
  14. uses
  15.   windows;
  16.  

Updated crt.pp from https://github.com/graemeg/freepascal/blob/master/packages/rtl-console/src/win/crt.pp --
Code: Pascal  [Select]
  1. unit crt;
  2.  
  3. interface
  4.  
  5. {$i crth.inc}
  6.  
  7. procedure SetSafeCPSwitching(Switching:Boolean);
  8. procedure SetUseACP(ACP:Boolean);
  9. procedure Window32(X1,Y1,X2,Y2: DWord);
  10. procedure GotoXY32(X,Y: DWord);
  11. function WhereX32: DWord;
  12. function WhereY32: DWord;
  13.  
  14. implementation
  15.  
  16. {$DEFINE FPC_CRT_CTRLC_TREATED_AS_KEY}
  17. (* Treatment of Ctrl-C as a regular key ensured during initialization (SetupConsoleInput). *)
  18.  
  19. uses
  20.   windows;
  21.  


dculp

  • Full Member
  • ***
  • Posts: 111
Re: How to write all unicode chars?
« Reply #21 on: November 15, 2019, 06:13:48 pm »
After searching through all files on my Lazarus distribution (2.0.2, FPC 3.0.4), I couldn't find either  SetSafeCPSwitching or SetUseACP.

They are part of fpc. If you used the official installer, then that is in a subfolder of your install.

Not in FP 3.0.4; they'll be in 3.2

Is there any way to use the new crt unit? I tried just copying it to D:\Lazarus_32bit_2.0.x\fpc\3.0.4\source\packages\rtl-console\src\win but compiling a simple test program (below) gave an error "Identifier not found" for both SetUseACP and SetSafeCPSwitching.

I then tried deleting crt.ppu in D:\Lazarus_32bit_2.0.x\fpc\3.0.4\units\i386-win32\rtl-console but then got the error "Write_ASCII_extended_chars_10a.pas(11,1) Fatal: Cannot find crt used by Write_ASCII_extended_chars_10a. Make sure all ppu files of a package are in its output directory. ppu in wrong directory=D:\Lazarus_32bit_2.0.x\fpc\3.0.4\units\i386-win32\rtl-console\crt.ppu..".

I had assumed that the required crt.ppu would be created during compilation of the test program but I couldn't find it anywhere.

How can I get the correct crt.ppu for the new crt.pp? Can it just be uploaded (if it exists) and copied to the required folder? What else would I need to do?

Any idea on when FP 3.2 will be released? (Since this issue with the extended ASCII chars was resolved almost two years ago, I might have hoped that the fix would have been incorporated by now.)

Code: Pascal  [Select]
  1. program Write_ASCII_extended_chars_10a;
  2. uses
  3.    crt;
  4.  
  5. (* Also tried explicit path -
  6. uses
  7.    crt in 'D:\Lazarus_32bit_2.0.x\fpc\3.0.4\source\packages\rtl-console\src\win\';
  8. *)
  9.  
  10. begin
  11. clrscr; // just to test that the crt is actually being used
  12. SetUseACP(true);
  13. SetSafeCPSwitching(false);
  14. end.
  15.  
« Last Edit: November 15, 2019, 09:16:11 pm by dculp »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5795
    • wiki
Re: How to write all unicode chars?
« Reply #22 on: November 15, 2019, 06:49:52 pm »
First of all, sorry I did not realize I was looking at my 3.0.2 install...

The proper way, install 3.2

The "maybe works" way: Copy the crt.pas file into your project.
However, if you use any other fcp-unit, or fpc/laz-package that uses crt, then that will not work.

I don't know if anything else in the rtl uses crt. If so, then you need to install 3.2. Or do a custom build of the entire 3.0.4


« Last Edit: November 15, 2019, 06:51:27 pm by Martin_fr »

dculp

  • Full Member
  • ***
  • Posts: 111
Re: How to write all unicode chars?
« Reply #23 on: November 15, 2019, 07:08:52 pm »
Martin_fr --

I was able to compile by adding crt.pp to the Project Inspector files (see image) and then adding the path to crth.inc (required included file for crt.pp) in the project paths. This gave crt.ppu in subfolder lib\i386-win32. Perhaps this is what you have suggested.

Where can I find v.3.2 for Windows 32bit? I didn't see it on the Lazarus site. (Note - I don't know anything about compiling FPC if this is required.)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5795
    • wiki
Re: How to write all unicode chars?
« Reply #24 on: November 15, 2019, 09:42:03 pm »
FPC 3.2 is still beta. It has not yet been released. And it is still changing.

A download of a recent beta build can be found here: https://sourceforge.net/projects/lazarus-snapshots/files/
Go for  lazarus-2.0.6-62131-fpc-3.2.0-beta-43271  (43271 is the svn revision of fpc svn fixes branch)
You can install it as "secondary install" => check the checkbox, choose a new install dir,  and for config specify an empty folder (can be a sub-folder of the new install dir)



But you should be fine with the copied file.
Path to inc is ok. Alternative copy the inc too.

This works, because you deleted the original crt.ppu.
If you want to keep this, you can rename the copy (including the unit name in the source), and use the unit by its new name. (should work / not tested)
« Last Edit: November 15, 2019, 09:46:11 pm by Martin_fr »