EgonOlsen71 / basicv2

A Commodore (CBM) BASIC V2 interpreter/compiler written in Java
https://egonolsen71.github.io/basicv2/
The Unlicense
84 stars 15 forks source link

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

Closed schorsch3000 closed 1 year ago

schorsch3000 commented 1 year ago

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 commented 1 year ago

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.

EgonOlsen71 commented 1 year ago

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?

schorsch3000 commented 1 year ago

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.

EgonOlsen71 commented 1 year ago

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...

schorsch3000 commented 1 year ago

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

EgonOlsen71 commented 1 year ago

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

schorsch3000 commented 1 year ago

yep, this works fine, thanks :+1: