basicv2 icon indicating copy to clipboard operation
basicv2 copied to clipboard

Using absolute file path doesn't work in an unix like environment.

Open schorsch3000 opened this issue 2 years ago • 1 comments

Since Mospeed is written in Java it works fine unter Linux or OSX.

The arg parser is just a little bit too easy.

Around this line here: https://github.com/EgonOlsen71/basicv2/blob/992bd1a58e5fac892077c02f0f26e8da054978e7/src/main/java/com/sixtyfour/cbmnative/shell/MoSpeedCL.java#L60

Every argument starting with a - or a / makes is a parameter, the first argument not starting with one of them ist da source file.

This results in 2 problems: a Filename cannot start with - You can't use an absolute File path like tmp/test.bas

Maybe just make the last argument the sourcefile?

Or use just - as a parameter prefix and make -- stop parameter parsing.

One of those are implemented by most cli tools.

I'm not firm in Java, but at least the first suggestion seems to be easy. Just pop the last element, set it as source file and don't set a sourcefile in the loop.

PS: there is no way to see which version my mospeed is, maybe also add a /version?

Thanks for your work Schorsch3000

schorsch3000 avatar Oct 07 '22 22:10 schorsch3000

Turns out, i'm not using a release version but a checked out version from master. i can confirm this behavior on the current master as well.

schorsch3000 avatar Oct 07 '22 22:10 schorsch3000

I don't really like the idea of using the last parameter as source. And I can happily live with not allowing files that start with a "-"... But I don't get the second problem that you mentioned:

You can't use an absolute File path like tmp/test.bas

Why can't I?

EgonOlsen71 avatar Jan 05 '23 15:01 EgonOlsen71

sorry, that's a typo. should be /tmp/test.bas that's because everything with a / is a parameter. using - or -- instead of / should be fine. sure, you can't access a file named -foo.bas directly, but ./-foo.bas works fine.

schorsch3000 avatar Jan 05 '23 15:01 schorsch3000

I see...I guess I could check first, if /whatever/some/file.bas actually is a file and if not, handle it as a parameter...and do the same for -. That's a bit...hacky, I guess. But then again, the whole MOSpeedCL-class is...I'll give it a try...

EgonOlsen71 avatar Jan 05 '23 15:01 EgonOlsen71

The most used way to do that in the unix was is to go from left to right, parse the parameters by the prefixed - or/and -- and stop parameter parsing if there is a -- by it self.

in this case i guess replacing / by - or checking if that is a file before using it as a parameter is going to be fine. Nobody is going to have a file named /deadcodeopt=true or -deadcodeopt=truewhich would be an edgecase. Also both cases would have a workaround: //deadcodeopt=true ./-deadcodeopt=true

schorsch3000 avatar Jan 05 '23 16:01 schorsch3000

I commited this "fix". Can you give it a try?

EgonOlsen71 avatar Jan 05 '23 16:01 EgonOlsen71

yep, this works fine, thanks :+1:

schorsch3000 avatar Jan 05 '23 16:01 schorsch3000