Recent

Author Topic: Pascal version of the UCI Filter program  (Read 3797 times)

Roland57

  • Sr. Member
  • ****
  • Posts: 475
    • msegui.net
Re: Pascal version of the UCI Filter program
« Reply #30 on: October 19, 2024, 11:20:55 am »
@tetrastes

Great! Many thanks. I can't wait to test by myself. (Unfortunately I am at home today, where I have only a Linux installation.)
My projects are on Gitlab and on Codeberg.

TRon

  • Hero Member
  • *****
  • Posts: 3650
Re: Pascal version of the UCI Filter program
« Reply #31 on: October 19, 2024, 11:27:33 am »
(Unfortunately I am at home today, where I have only a Linux installation.)
Now, if you only had ....  :D

BTW: in the case that was indeed the (only) issue then you might be able to get away with just using #10 but be advised that in case of issues the specification explicitly mentions to use #13#10 for windows. In practice most code simply ignores the #13 and 'chops' on the #10 (but that could differ per engine).
« Last Edit: October 19, 2024, 11:39:38 am by TRon »
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

Roland57

  • Sr. Member
  • ****
  • Posts: 475
    • msegui.net
Re: Pascal version of the UCI Filter program
« Reply #32 on: October 19, 2024, 12:04:24 pm »
Now, if you only had ....  :D

I don't understand. Sorry, english is not my native language.  :)

BTW: in the case that was indeed the (only) issue then you might be able to get away with just using #10 but be advised that in case of issues the specification explicitly mentions to use #13#10 for windows. In practice most code simply ignores the #13 and 'chops' on the #10 (but that could differ per engine).

Thanks for the clarification.
My projects are on Gitlab and on Codeberg.

TRon

  • Hero Member
  • *****
  • Posts: 3650
Re: Pascal version of the UCI Filter program
« Reply #33 on: October 19, 2024, 12:14:22 pm »
I don't understand. Sorry, english is not my native language.  :)
I ruins the (bad) joke but...

The full sentence would have been: "Now, if you only had used Free Pascal's RTL functions for the file- and pipe- handling, then you would have been able to compile/run it on/for Linux"

(and yes I understand that defeats the purpose of your translation of this program, which was the second layer of the joke).
« Last Edit: October 19, 2024, 12:37:42 pm by TRon »
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

Roland57

  • Sr. Member
  • ****
  • Posts: 475
    • msegui.net
Re: Pascal version of the UCI Filter program
« Reply #34 on: October 19, 2024, 12:38:01 pm »
I see.  :)

Maybe when I have time, I will try to make a multiplatform version.

By the way, I already made something similar, using TProcess.

When you say RTL, do you mean the Process unit, or something else?
My projects are on Gitlab and on Codeberg.

TRon

  • Hero Member
  • *****
  • Posts: 3650
Re: Pascal version of the UCI Filter program
« Reply #35 on: October 19, 2024, 12:45:48 pm »
Maybe when I have time, I will try to make a multiplatform version.
That was not the intention of the "joke" but could perhaps be a nice exercise.

Quote
By the way, I already made something similar, using TProcess.
Ah yes, I see. Not the exact same functionality as the filter program but the base functionality seems to be in place.

Quote
When you say RTL, do you mean the Process unit, or something else?
Indeed TProcess but perhaps also in combination with the pipes unit.
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

Thaddy

  • Hero Member
  • *****
  • Posts: 16199
  • Censorship about opinions does not belong here.
Re: Pascal version of the UCI Filter program
« Reply #36 on: October 19, 2024, 02:35:35 pm »
The last sentence is exactly what I meant.
If I smell bad code it usually is bad code and that includes my own code.

Fred vS

  • Hero Member
  • *****
  • Posts: 3414
    • StrumPract is the musicians best friend
Re: Pascal version of the UCI Filter program
« Reply #37 on: October 19, 2024, 04:54:41 pm »
Hello.
The boring one is back!  :-[

Doing this:
Code: Pascal  [Select][+][-]
  1. program launchprogram;
  2.  
  3. uses
  4.   Process;
  5.  
  6. var
  7.   AProcess: TProcess;
  8.  
  9. begin
  10.    AProcess := TProcess.Create(nil);
  11.    AProcess.Executable:= 'CT800_V1.34_x32.exe';
  12.    AProcess.Options := AProcess.Options + [poWaitOnExit];
  13.    AProcess.Execute;
  14.    AProcess.Free;  
  15. end.

Gives this:
Quote
$ wine launchprogram.exe

CT800 V1.34 32 bit UCI version
2016-2019 by Rasmus Althoff
Free software under GPLv3+

As you can see, using TProcess gives a good result in the standard output.
So I still have doubts about how fpc handles the standard output while using the Windows API CreateProcess() and related methods.
« Last Edit: October 19, 2024, 05:40:48 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Thaddy

  • Hero Member
  • *****
  • Posts: 16199
  • Censorship about opinions does not belong here.
Re: Pascal version of the UCI Filter program
« Reply #38 on: October 19, 2024, 06:28:27 pm »
Fred, your only and biggest problem is that in a Lazarus GUI app, stdin/out/err are not available by default on Windows.
That is all.
This is also true for Delphi.
The easiest way to get around it is specifying {$apptype console} and hide the console.
I have shown quite a few times how to do that. On almost all other platforms, there is always a working set of stdin/out/err by default.
If I smell bad code it usually is bad code and that includes my own code.

Fred vS

  • Hero Member
  • *****
  • Posts: 3414
    • StrumPract is the musicians best friend
Re: Pascal version of the UCI Filter program
« Reply #39 on: October 19, 2024, 06:45:33 pm »
Fred, your only and biggest problem is that in a Lazarus GUI app, stdin/out/err are not available by default on Windows.
That is all.

Hello Thaddy.
I hope this is my only problem!
But it shouldn't be this time, in Roland's demo I added right at the beginning of testing:
Code: Pascal  [Select][+][-]
  1. {$APPTYPE CONSOLE}

Also added this to be sure (but it is done by default):
Code: Pascal  [Select][+][-]
  1.  StartInfo.hStdInput := GetStdHandle(STD_INPUT_HANDLE);
  2.   StartInfo.hStdoutput := GetStdHandle(STD_OutPUT_HANDLE);

And the StartInfo.hStdoutput has not same result than the STD_OutPUT from TProcess.
Sadly, I dont have Delphi installed to test the demo of Roland compiled with Delphi vs with fpc.
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

tetrastes

  • Hero Member
  • *****
  • Posts: 600
Re: Pascal version of the UCI Filter program
« Reply #40 on: October 19, 2024, 09:42:28 pm »
As you can see, using TProcess gives a good result in the standard output.
So I still have doubts about how fpc handles the standard output while using the Windows API CreateProcess() and related methods.

What do you mean? At windows TProcess uses CreateProcess (CreateProcessW to be precise). So "how fpc handles ... etc" you can see in sources of TProcess (packages\fcl-process\src\win\process.inc). How the particular programmer handles this, is the matter of this programmer.

Fred vS

  • Hero Member
  • *****
  • Posts: 3414
    • StrumPract is the musicians best friend
Re: Pascal version of the UCI Filter program
« Reply #41 on: October 20, 2024, 01:39:53 am »
As you can see, using TProcess gives a good result in the standard output.
So I still have doubts about how fpc handles the standard output while using the Windows API CreateProcess() and related methods.

What do you mean? At windows TProcess uses CreateProcess (CreateProcessW to be precise). So "how fpc handles ... etc" you can see in sources of TProcess (packages\fcl-process\src\win\process.inc). How the particular programmer handles this, is the matter of this programmer.

Hello Tetrastes.
Many thanks for pointing packages\fcl-process\src\win\process.inc
But there is this as note line 280:
Code: Pascal  [Select][+][-]
  1. // Beware: CreateProcess can alter the strings

So I will study the code using CreateProcessW.
[EDIT] I did try using CreateProcessW, with the vars adapted for widestring and following the code of process.inc but there is still garbage in the output strings.  So there is something I don't catch. I pass my turn.  :-\
« Last Edit: October 20, 2024, 03:06:20 am by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Roland57

  • Sr. Member
  • ****
  • Posts: 475
    • msegui.net
Re: Pascal version of the UCI Filter program
« Reply #42 on: November 06, 2024, 01:03:32 pm »
The problem is in WriteFile. You must dereference str_:
Code: Pascal  [Select][+][-]
  1. WriteFile(pFilter^.hNachGui, str_^, len + 1, AnzGeschrieben, nil)

Then the first variant works like C code, the second has some regression.

I finally could test that modification and indeed it solves the issue. So thank you very much!  :)

I have to do a last review of the whole code, for proper line endings management, as suggested by TRon.
My projects are on Gitlab and on Codeberg.

Roland57

  • Sr. Member
  • ****
  • Posts: 475
    • msegui.net
Re: Pascal version of the UCI Filter program
« Reply #43 on: November 08, 2024, 08:25:19 am »
I fixed a last (?) error. This line was not properly translated:

Code: C  [Select][+][-]
  1. sscanf(str, "%15s", Kommando);

My first translation was:

Code: Pascal  [Select][+][-]
  1.     StrLCopy(Kommando, str_, SizeOf(Kommando) - 1);

Which is obviously wrong.

Now it is:

Code: Pascal  [Select][+][-]
  1.     FillChar(Kommando, SizeOf(Kommando), #0);
  2.     i := 0;
  3.     while (i < len) and (i < SizeOf(Kommando)) and ((str_ + i)^ <> #32) do
  4.     begin
  5.       Kommando[i] := (str_ + i)^;
  6.       Inc(i);
  7.     end;

I know there is a Pascal sscanf function, but I didn't find how to use it in that case.  :)

@TRon
After reflection, '\n' (please notice the single quotes) is the equivalent of #10, not #13#10. So, it would probably be better to use #13#10 as you suggested, but as my first goal was to translate the C program as it is, I went back to my first translation.

Here is the final (?) state of the program, if ever someone is interested. Thank you all for your help!
« Last Edit: November 08, 2024, 08:29:13 am by Roland57 »
My projects are on Gitlab and on Codeberg.

 

TinyPortal © 2005-2018