Forum > Windows

Pascal version of the UCI Filter program

<< < (9/9)

tetrastes:

--- Quote from: Fred vS on October 19, 2024, 04:54:41 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.

--- End quote ---

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:

--- Quote from: tetrastes on October 19, 2024, 09:42:28 pm ---
--- Quote from: Fred vS on October 19, 2024, 04:54:41 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.

--- End quote ---

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.

--- End quote ---

Hello Tetrastes.
Many thanks for pointing packages\fcl-process\src\win\process.inc
But there is this as note line 280:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---// 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.  :-\

Roland57:

--- Quote from: tetrastes on October 18, 2024, 10:48:39 pm ---The problem is in WriteFile. You must dereference str_:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---WriteFile(pFilter^.hNachGui, str_^, len + 1, AnzGeschrieben, nil)
Then the first variant works like C code, the second has some regression.

--- End quote ---

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.

Roland57:
I fixed a last (?) error. This line was not properly translated:


--- Code: C  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---sscanf(str, "%15s", Kommando);
My first translation was:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---    StrLCopy(Kommando, str_, SizeOf(Kommando) - 1);
Which is obviously wrong.

Now it is:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---    FillChar(Kommando, SizeOf(Kommando), #0);    i := 0;    while (i < len) and (i < SizeOf(Kommando)) and ((str_ + i)^ <> #32) do    begin      Kommando[i] := (str_ + i)^;      Inc(i);    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!

Navigation

[0] Message Index

[*] Previous page

Go to full version