Recent

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

Roland57

  • Sr. Member
  • ****
  • Posts: 468
    • 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: 3496
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

Roland57

  • Sr. Member
  • ****
  • Posts: 468
    • 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: 3496
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

Roland57

  • Sr. Member
  • ****
  • Posts: 468
    • 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: 3496
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

Thaddy

  • Hero Member
  • *****
  • Posts: 15992
  • 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: 3402
    • 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: 15992
  • 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: 3402
    • 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: 571
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: 3402
    • 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: 468
    • 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.

 

TinyPortal © 2005-2018