Implemented wrapper for @open (fix #336) #344

Merged
mxlgv merged 13 commits from Matou1306/kolibrios:quotes-fix into main 2026-03-23 14:34:09 +00:00
Contributor

Fixes #336:

Implemented a wrapper for placing the path to a file in quotes. This corrects the problem of handling paths containing spaces in C programs such as DGEN, since the space is the argument delimiter.

The wrapper should have the name <app>_open. Wrapper trims the _open postfix and launches the <app>.

Fixes #336: Implemented a wrapper for placing the path to a file in quotes. This corrects the problem of handling paths containing spaces in C programs such as `DGEN`, since the space is the argument delimiter. The wrapper should have the name `<app>_open`. Wrapper trims the `_open` postfix and launches the `<app>`.
Matou1306 force-pushed quotes-fix from 6dd27a94f6 to c8efe352dc 2026-02-24 12:06:12 +00:00 Compare
Matou1306 force-pushed quotes-fix from c8efe352dc to e7d1a0b5db 2026-02-27 16:05:43 +00:00 Compare
Owner

I already wrote about what can be done. This solution, in my opinion, is bad.

I already wrote about what can be done. This solution, in my opinion, is bad.
Author
Contributor

@mxlgv Just to make sure we're on the same page, I realized the PR description was outdated (just updated it).

I completely removed the global macro and the @open changes. The current code only modifies dgen/main.c to handle arguments locally.

If you already reviewed this latest committed code and still see issues, could you please give more specific details on what's wrong?

@mxlgv Just to make sure we're on the same page, I realized the PR description was outdated (just updated it). I completely removed the global macro and the @open changes. The current code only modifies dgen/main.c to handle arguments locally. If you already reviewed this latest committed code and still see issues, could you please give more specific details on what's wrong?
Owner

@Matou1306 #336 (comment) here I wrote that you can make a launcher specifically for working with files. The launcher is a simple fasm program that adds quotes to the path and launches the program. Thus, changes to the port are not necessary.

@Matou1306 https://git.kolibrios.org/KolibriOS/kolibrios/issues/336#issuecomment-4405 here I wrote that you can make a launcher specifically for working with files. The launcher is a simple fasm program that adds quotes to the path and launches the program. Thus, changes to the port are not necessary.
Author
Contributor

@mxlgv Oh my bad!! I just realized I totally missed this comment from last week! I had the page open so it didn't send me a notification.
I really appreciate your apology from that message, and sorry for the confusion I caused by missing this for a whole week while you had already pointed out the preferred path.

Thanks for referencing it, I will discard the past changes and start working on your approach then push the edits asap

@mxlgv Oh my bad!! I just realized I totally missed this comment from last week! I had the page open so it didn't send me a notification. I really appreciate your apology from that message, and sorry for the confusion I caused by missing this for a whole week while you had already pointed out the preferred path. Thanks for referencing it, I will discard the past changes and start working on your approach then push the edits asap
mxlgv marked the pull request as work in progress 2026-03-02 18:30:28 +00:00
mxlgv added the
Category
Applications
Lang/FASM
Kind
Bug
Priority
Low
4
labels 2026-03-02 18:31:06 +00:00
Owner

@Matou1306 Thank you for showing such interest in the project)

@Matou1306 Thank you for showing such interest in the project)
Matou1306 force-pushed quotes-fix from e7d1a0b5db to d8d4759097 2026-03-03 18:25:09 +00:00 Compare
Author
Contributor

@mxlgv I implemented your suggested FASM wrapper and pushed the latest version. Please take a look and tell me your thoughts

(Note: I tested it with a dummy file with spaces in the path. The path truncation error is completely gone. It hangs on the DGen logo though but it did that before the fix too (since it's not a valid file I guess)).

Waiting for your comments and review.

@mxlgv I implemented your suggested FASM wrapper and pushed the latest version. Please take a look and tell me your thoughts (Note: I tested it with a dummy file with spaces in the path. The path truncation error is completely gone. It hangs on the DGen logo though but it did that before the fix too (since it's not a valid file I guess)). Waiting for your comments and review.
mxlgv requested changes 2026-03-04 16:34:27 +00:00
Dismissed
mxlgv left a comment
Owner

You took writing the template too literally, I suggest giving up inc and making a program in a separate folder.

I suggest that it be universal. To have the program automatically launch a file in its folder with the same name without open: for example /kolibrios/blabalbal/dgen_open will launch /kolibrios/blablabal/dgen.

You took writing the template too literally, I suggest giving up inc and making a program in a separate folder. I suggest that it be universal. To have the program automatically launch a file in its folder with the same name without `open`: for example `/kolibrios/blabalbal/dgen_open` will launch `/kolibrios/blablabal/dgen`.
@@ -0,0 +3,4 @@
format binary as ""
TARGET equ '/kolibrios/emul/dgen/dgen'
Owner

It's a bad decision to hardcode the file path

It's a bad decision to hardcode the file path
mxlgv marked this conversation as resolved
@@ -0,0 +21,4 @@
mov edi, new_params
mov byte [edi], '"'
inc edi
Owner

Why are you copying the path? It is better to hardcode the quote before the path and add the last quote to the end of the line.

Why are you copying the path? It is better to hardcode the quote before the path and add the last quote to the end of the line.
Matou1306 marked this conversation as resolved
@@ -0,0 +37,4 @@
mov dword [fi + 8], new_params
.launch:
mov eax, 70
Owner

Use constants from KOSfunc.inc.

Use constants from KOSfunc.inc.
Matou1306 marked this conversation as resolved
Owner

@Matou1306
What's the bug in DGEN? Which specific file is not valid. Does DGEN run a file with quotes via SHELL for example?

@Matou1306 What's the bug in DGEN? Which specific file is not valid. Does DGEN run a file with quotes via SHELL for example?
Author
Contributor

@mxlgv Sorry for the delay, I had university exams today.

Regarding your question: initially, no, I didn't try it via SHELL. I just double-clicked the file from Eolite and got DGen opening but stuck on the logo. The file I used is a dummy file (just an empty/random char filled New file.md). I don't actually know of a valid file/ROM that works on DGen to test this properly (help finding one to test would be appreciated).
I just tried using SHELL per your suggestion. After some trial and error, the final result I got was: 'dgen' started. PID = 31, but no actual window opened.

And regarding your requested changes:
-Do you mean something like ../../? Or by universal you mean something even more general like dynamically reading the file's own executable path? Like for dgen it should read /kolibrios/emul/dgen_open, chop off _open and launch /kolibrios/emul/dgen ?
-My original intention was to avoid memory access violations in case the path didn't have a free byte in the beginning, but yeah I realized it would already be O(n) time to reach the null terminator, so maybe just shifting it while parsing would be a better solution by avoiding O(n) space too?
-Regarding KOSfunc.inc, noted.

I will start working on these updates and push them asap

@mxlgv Sorry for the delay, I had university exams today. Regarding your question: initially, no, I didn't try it via SHELL. I just double-clicked the file from Eolite and got DGen opening but stuck on the logo. The file I used is a dummy file (just an empty/random char filled New file.md). I don't actually know of a valid file/ROM that works on DGen to test this properly (help finding one to test would be appreciated). I just tried using SHELL per your suggestion. After some trial and error, the final result I got was: 'dgen' started. PID = 31, but no actual window opened. And regarding your requested changes: -Do you mean something like ../../? Or by universal you mean something even more general like dynamically reading the file's own executable path? Like for dgen it should read `/kolibrios/emul/dgen_open`, chop off _open and launch `/kolibrios/emul/dgen` ? -My original intention was to avoid memory access violations in case the path didn't have a free byte in the beginning, but yeah I realized it would already be O(n) time to reach the null terminator, so maybe just shifting it while parsing would be a better solution by avoiding O(n) space too? -Regarding KOSfunc.inc, noted. I will start working on these updates and push them asap
Matou1306 added 1 commit 2026-03-07 12:15:23 +00:00
requested changes
Build system / Check kernel codestyle (pull_request) Successful in 52s
Build system / Build (pull_request) Successful in 17m51s
2c20243949
Matou1306 added 1 commit 2026-03-07 12:22:04 +00:00
use SSF_START_APP instead of hardcoded subfunction number 7
Build system / Build (pull_request) Failing after 2s
Build system / Check kernel codestyle (pull_request) Successful in 28s
0b422c07ac
Author
Contributor

Hey @mxlgv, I just pushed your requested changes. Please take a look and let me know if there is anything else.

The only thing remaining is the relative path change you requested. I am not totally sure I understand your plan correctly on this one, so I am waiting for your answer to my previous question before making this specific change.

Hey @mxlgv, I just pushed your requested changes. Please take a look and let me know if there is anything else. The only thing remaining is the relative path change you requested. I am not totally sure I understand your plan correctly on this one, so I am waiting for your answer to my previous question before making this specific change.
Owner

@Matou1306 Hi!
Yes:

Or by universal you mean something even more general like dynamically reading the file's own executable path? Like for dgen it should read /kolibrios/emul/dgen_open, chop off _open and launch /kolibrios/emul/dgen

Regarding the quote.
If I'm not mistaken, then according to the documentation, the argument cannot be larger than 256 bytes (including '\0'). I suggest using this size for now.

* Command line must be terminated by the character with the code 0

What was approximately expected:

A separate program #344 (comment) that works approximately on this principle:

q_path:  ; You can also not use a label but write path+1 in the MENUET header
       rb 1
path:
       rb 256+1 ; + 1 for end quote

and

mov al,'"'
mov [q_path], al 

and

path[strlen(path)] = '"';

and RUN.

@Matou1306 Hi! Yes: > Or by universal you mean something even more general like dynamically reading the file's own executable path? Like for dgen it should read /kolibrios/emul/dgen_open, chop off _open and launch /kolibrios/emul/dgen Regarding the quote. If I'm not mistaken, then according to the documentation, the argument cannot be larger than 256 bytes (including '\0'). I suggest using this size for now. https://git.kolibrios.org/KolibriOS/kolibrios/src/commit/6f2a947deb6add78781762d3d8cbad7bf1ef0e3d/kernel/trunk/docs/sysfuncs.txt#L4348 What was approximately expected: A separate program https://git.kolibrios.org/KolibriOS/kolibrios/pulls/344#issuecomment-4582 that works approximately on this principle: ```asm q_path: ; You can also not use a label but write path+1 in the MENUET header rb 1 path: rb 256+1 ; + 1 for end quote ``` and ```asm mov al,'"' mov [q_path], al ``` and ```c path[strlen(path)] = '"'; ``` and RUN.
Matou1306 added 1 commit 2026-03-08 16:15:54 +00:00
requested changes (all)
Build system / Check kernel codestyle (pull_request) Successful in 24s
Build system / Build (pull_request) Successful in 9m48s
a259518124
Author
Contributor

@mxlgv Hello,
Thanks for the review. I implemented your requested changes, please take a look and tell me what else I can improve.

@mxlgv Hello, Thanks for the review. I implemented your requested changes, please take a look and tell me what else I can improve.
mxlgv requested changes 2026-03-11 10:52:12 +00:00
Dismissed
mxlgv left a comment
Owner

I think I came up with a pretty stupid name... I suggest adding this AS A PROGRAM to programs/fs/open_wrap/open_wrap.asm

I think I came up with a pretty stupid name... I suggest adding this AS A PROGRAM to `programs/fs/open_wrap/open_wrap.asm`
@@ -0,0 +5,4 @@
virtual
db WRAPPER_SUFFIX
SUFFIX_SIZE = $ - $$
Owner

I think this is unnecessary for now. Let's leave only _open, if other cases appear we will improve it.

I think this is unnecessary for now. Let's leave only _open, if other cases appear we will improve it.
Matou1306 marked this conversation as resolved
@@ -0,0 +26,4 @@
xor al, al
repne scasb
sub edi, SUFFIX_SIZE + 1
Owner

I suggest hardcoding to the size of "_open" since other postfixes are not planned yet

I suggest hardcoding to the size of "_open" since other postfixes are not planned yet
Matou1306 marked this conversation as resolved
@@ -0,0 +48,4 @@
mov ebx, fi
int 0x40
mov eax, SF_TERMINATE_PROCESS
Owner

I would recommend the mcall macro for system calls:

macro mcall a,b,c,d,e,f,g { ; [mike.dld], [Ghost]

I would recommend the mcall macro for system calls: https://git.kolibrios.org/KolibriOS/kolibrios/src/commit/0253ec87530d26e76ee38ecb101d8839d6c354d0/programs/macros.inc#L297
Matou1306 marked this conversation as resolved
mxlgv requested changes 2026-03-11 10:57:17 +00:00
Dismissed
@@ -67,1 +67,4 @@
link_gcc("dgen")
tup.include(HELPERDIR .. "/use_fasm.lua")
tup.rule({"dgen_open.asm", extra_inputs = {"../../quotkinizer.inc"}}, FASM .. " %f %o " .. tup.getconfig("KPACK_CMD"), "dgen_open")
Owner

Then something like:

tup.rule("../../../fs/open_wrap/open_wrap.asm", FASM .. " %f %o " .. tup.getconfig("KPACK_CMD"), "dgen_open")
Then something like: ```tup tup.rule("../../../fs/open_wrap/open_wrap.asm", FASM .. " %f %o " .. tup.getconfig("KPACK_CMD"), "dgen_open") ```
Owner

Or perhaps even better, place the tup file in the open_wrap folder, as this is how ports are planned to be removed from the monorep.

Or perhaps even better, place the tup file in the open_wrap folder, as this is how ports are planned to be removed from the monorep.
Matou1306 marked this conversation as resolved
mxlgv changed title from WIP: quotes-fix to WIP: Implemented wrapper for @open (fix #336) 2026-03-11 10:59:46 +00:00
Matou1306 added 1 commit 2026-03-11 13:14:15 +00:00
moved wrapper to programs/fs
Build system / Check kernel codestyle (pull_request) Successful in 55s
Build system / Build (pull_request) Failing after 13m31s
50d31a0500
hardcoded _open in quotes wrapper

replaced manual systemcalls with macro calls

Updated Tupfile to reflect the changes
Author
Contributor

I just pushed the requested changes and marked them as resolved. Thanks for the tip on the mcall macro.

I just pushed the requested changes and marked them as resolved. Thanks for the tip on the `mcall` macro.
mxlgv requested changes 2026-03-11 16:10:14 +00:00
Dismissed
mxlgv left a comment
Owner

@Matou1306
Forgot to remind you to add this there:

{"kolibrios/emul/dgen/dgen", VAR_PROGS .. "/emulator/dgen-sdl-1.33/dgen"},

@Matou1306 Forgot to remind you to add this there: https://git.kolibrios.org/KolibriOS/kolibrios/src/commit/42c205be32e7e55b7174b0aa79ea76b08c0db1cf/data/Tupfile.lua#L802
Matou1306 added 1 commit 2026-03-11 16:39:13 +00:00
added dgen_open to Tupfile
Build system / Build (pull_request) Successful in 9m59s
Build system / Check kernel codestyle (pull_request) Successful in 51s
c8e91f3cd5
Author
Contributor

@mxlgv Done

@mxlgv Done
mxlgv marked the pull request as ready for review 2026-03-11 18:09:19 +00:00
mxlgv requested review from Burer 2026-03-11 18:09:31 +00:00
dunkaist requested changes 2026-03-15 23:34:31 +00:00
Dismissed
data/Tupfile.lua Outdated
@@ -801,6 +801,7 @@ if tup.getconfig('NO_NASM') ~= 'full' then
{"kolibrios/games/wolf3d/", VAR_CONTRIB .. "/games/wolf3d/wolf3d"},
{"kolibrios/games/wolf3d/", "common/games/wolf3d/*"},
{"kolibrios/emul/dgen/dgen", VAR_PROGS .. "/emulator/dgen-sdl-1.33/dgen"},
{"kolibrios/emul/dgen/dgen_open", VAR_PROGS .. "/fs/open_wrap/dgen_open"},
Owner

I believe it should be '/fs/open_wrap/open_wrap' on the right side.

By the way, if we rename the program to dgen_open, blah_open, etc, then maybe it should be called wrap_open, not open_wrap? Just a thought, not a requirement.

I believe it should be '/fs/open_wrap/open_wrap' on the right side. By the way, if we rename the program to dgen_open, blah_open, etc, then maybe it should be called wrap_open, not open_wrap? Just a thought, not a requirement.
Author
Contributor

That path was depending on the name fs/wrap_open/Tupfile.lua created, I updated both.

I also renamed open_wrap to wrap_open like u said, it feels cleaner indeed.

That path was depending on the name `fs/wrap_open/Tupfile.lua` created, I updated both. I also renamed `open_wrap` to `wrap_open` like u said, it feels cleaner indeed.
dunkaist marked this conversation as resolved
@@ -192,3 +192,2 @@
ch8=/kolibrios/emul/chip8/chip8
md=/kolibrios/emul/dgen/dgen
gen=/kolibrios/emul/dgen/dgen
md=/kolibrios/emul/dgen/dgen_open
Owner

What does 'md' mean here, markdown? I understand it was like this before your change, I'm just trying to find the logic.

What does 'md' mean here, markdown? I understand it was like this before your change, I'm just trying to find the logic.
Author
Contributor

Dgen itself is an ancient Genesis/MegaDrive emulator, so that's what gen and md stand for. The .md extension here just means it's a Sega game image.
(Honestly I had no idea at the start too and I even once tried testing with markdown text lmao)

Dgen itself is an ancient Genesis/MegaDrive emulator, so that's what gen and md stand for. The .md extension here just means it's a Sega game image. (Honestly I had no idea at the start too and I even once tried testing with markdown text lmao)
dunkaist marked this conversation as resolved
@@ -0,0 +1,4 @@
if tup.getconfig("NO_FASM") ~= "" then return end
tup.include("../../use_fasm.lua")
tup.rule("open_wrap.asm", FASM .. " %f %o " ..
Owner

Lines 3 and 4 are a single rule, no need to split it as it is not too long.

Lines 3 and 4 are a single rule, no need to split it as it is not too long.
Matou1306 marked this conversation as resolved
@@ -0,0 +1,4 @@
if tup.getconfig("NO_FASM") ~= "" then return end
tup.include("../../use_fasm.lua")
tup.rule("open_wrap.asm", FASM .. " %f %o " ..
tup.getconfig("KPACK_CMD"), "dgen_open")
Owner

Since the final design of the program can be used to call any other program, not just dgen, there is no need to call its binary dgen_open. Let the binary be wrap_open here and then copy it to the dgen directory as dgen_open, to a potential blahblah directory as blahblah_open, etc.

Since the final design of the program can be used to call any other program, not just dgen, there is no need to call its binary dgen_open. Let the binary be wrap_open here and then copy it to the dgen directory as dgen_open, to a potential blahblah directory as blahblah_open, etc.
Author
Contributor

Oh I actually thought that this name was the one that would be added into the dgen directory.
You're right though, I just updated it now.

Oh I actually thought that this name was the one that would be added into the dgen directory. You're right though, I just updated it now.
Matou1306 added 1 commit 2026-03-16 08:37:23 +00:00
Merge remote-tracking branch 'upstream/main' into quotes-fix
Build system / Check kernel codestyle (pull_request) Successful in 1m57s
Build system / Build (pull_request) Successful in 11m36s
bb3cdba580
Matou1306 added 1 commit 2026-03-16 09:53:10 +00:00
Rename open_wrap to wrap_open
Build system / Check kernel codestyle (pull_request) Successful in 35s
Build system / Build (pull_request) Successful in 9m55s
7ff5162fc3
Updated the binary name inside programs/fs/wrap_open to a generic wrap_open. data/Tupfile.lua would handle the new name copied to the target location
Owner

@Matou1306, please, remove these files: .vscode and test.img

@Matou1306, please, remove these files: .vscode and test.img
Matou1306 added 1 commit 2026-03-17 05:39:58 +00:00
removed accidental .vscode files
Build system / Check kernel codestyle (pull_request) Successful in 1m3s
Build system / Build (pull_request) Successful in 15m36s
8d454ce3b3
Matou1306 added 1 commit 2026-03-17 05:44:03 +00:00
removed test.img
Build system / Check kernel codestyle (pull_request) Successful in 34s
Build system / Build (pull_request) Successful in 14m59s
1c22b9fb0b
Author
Contributor

@dunkaist sorry the fasm extension prompted me and automatically added the .vscode files.
Removed thx for catching them alongside the test.img

@dunkaist sorry the fasm extension prompted me and automatically added the .vscode files. Removed thx for catching them alongside the test.img
dunkaist requested changes 2026-03-18 00:23:16 +00:00
Dismissed
@@ -0,0 +10,4 @@
dd start
dd i_end
dd m_end
dd m_end
Owner

I think your stack will overwrite the variable 'target_path'. Check a few random programs written in fasm to see how they deal with stack memory.

I think your stack will overwrite the variable 'target_path'. Check a few random programs written in fasm to see how they deal with stack memory.
dunkaist marked this conversation as resolved
@@ -0,0 +48,4 @@
i_end:
params rb 256
Owner

You define the label 'params' but never use it. Check if the following two lines will do the same as the current lines 51--55:
q_path rb 1
path rb 255

You define the label 'params' but never use it. Check if the following two lines will do the same as the current lines 51--55: q_path rb 1 path rb 255
Author
Contributor

This was there since the start since at first I used to treat params as one single block. When dividing it I just added a virtual block. But like you said there is no difference in the output binary so I'll just keep it simple and do it as you suggested.

This was there since the start since at first I used to treat params as one single block. When dividing it I just added a virtual block. But like you said there is no difference in the output binary so I'll just keep it simple and do it as you suggested.
dunkaist marked this conversation as resolved
Matou1306 added 1 commit 2026-03-18 17:30:59 +00:00
Style: Cleaned params to q_path and path for readability
Build system / Check kernel codestyle (pull_request) Successful in 37s
Build system / Build (pull_request) Successful in 18m55s
5b812995af
Matou1306 added 1 commit 2026-03-18 17:31:58 +00:00
Style: Cleaned params to q_path and path for readability
Build system / Check kernel codestyle (pull_request) Successful in 40s
Build system / Build (pull_request) Successful in 18m17s
1025bec2ce
dunkaist approved these changes 2026-03-18 19:23:49 +00:00
Matou1306 added 1 commit 2026-03-18 19:59:37 +00:00
Applying KolibriOS Style guide
Build system / Build (pull_request) Successful in 10m31s
Build system / Check kernel codestyle (pull_request) Successful in 31s
10dadba776
Author
Contributor

Hello, I just want to add a comment that I tested the changes locally yesterday with a real .md game file and they work fine:
I installed an old dgen game (Fix It Felix, Jr.) .md image file and tried opening the file on qemu. It worked just fine. I then tried adding spaces to the path and it also worked, meaning the fix worked and wrap_open handles everything perfectly.

Hello, I just want to add a comment that I tested the changes locally yesterday with a real .md game file and they work fine: I installed an old dgen game (Fix It Felix, Jr.) .md image file and tried opening the file on qemu. It worked just fine. I then tried adding spaces to the path and it also worked, meaning the fix worked and wrap_open handles everything perfectly.
mxlgv approved these changes 2026-03-23 14:30:53 +00:00
mxlgv left a comment
Owner

@Matou1306 thanks! It really works.

@Matou1306 thanks! It really works.
mxlgv merged commit e9e9ebb4c8 into main 2026-03-23 14:34:09 +00:00
Matou1306 deleted branch quotes-fix 2026-03-23 15:03:34 +00:00
Sign in to join this conversation.
No Reviewers
3 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: KolibriOS/kolibrios#344