Posts: 1,272
Threads: 119
Joined: Apr 2022
Reputation:
100
I was under the impression that at some point QB64 had the ability added to change the backslash character in path strings to foreslashes if it detected it was running within Linux.
For example, this line of code:
MySprite& = _LOADIMAGE(".\assets\sprite.png", 32)
would be seen as
MySprite& = _LOADIMAGE("./assets/sprite.png", 32)
when running in Linux. Was or is this still the case or is my age showing again?
I really need to get another Linux box up and running so I can test these things out.
Posts: 734
Threads: 30
Joined: Apr 2022
Reputation:
43
That sounds right but I can't be 100% for certain
Tread on those who tread on you
Posts: 2,698
Threads: 327
Joined: Apr 2022
Reputation:
217
It won't change it inside your code automatically, but most of the file commands will work with it either way for you. Where you'd have to be careful is with SHELL and such. SHELL "./foo \e /a" <-- is \e a path? or /a? Or both params of foo? Who knows!! So, QB64 won't mess with those for you, so you'll have to have your slashes right then, for your programs.
As for _LOADIMAGE though? I *think* it doesn't really matter, as QB64 will swap those slashes to what's proper, before loading the file for you. (I say I *think*, because QB64 has a dozen different load routines inside it for files, includes, fonts, sounds, ect, ect. There's always an off chance that some of those missed out on the internal swapping of slashes.)
If you can test it, and it works, all is fine. If you can't test it for yourself, and are in doubt of the behavior, swap them out manually. Better to play it safe than sorry, in my opinion.
Posts: 734
Threads: 30
Joined: Apr 2022
Reputation:
43
Something as simple as
$IF LINUX THEN
LOADIMAGE("./a/directory/with/forward/slashes")
$ELSE IF WINDOWS THEN
LOADIMAGE(".\a\directory\with\backslashes")
$END IF
Tread on those who tread on you
Posts: 1,586
Threads: 59
Joined: Jul 2022
Reputation:
52
01-10-2023, 06:34 PM
(This post was last modified: 01-10-2023, 06:40 PM by mnrvovrfc.)
To extend that theme, and to exaggerate a little bit to be clear as possible:
Code: (Select All) DIM slosh AS STRING, pichan AS LONG
$IF WIN THEN
slosh = "\"
$ELSE
slosh = "/"
$END IF
pichan = _LOADIMAGE("." + slosh + "a" + slosh + "directory" + slosh + "with" + slosh + "forward" + slosh + "slashes", 32)
Could also write a simple search-and-replace routine that uses "MID$()" LHS for one character:
Code: (Select All) DIM slosh AS STRING, mypath AS STRING
$IF WIN THEN
slosh = "\"
$ELSE
slosh = "/"
$END IF
mypath = ".|a|directory|with|forward|slashes"
ReplaceString mypath, "|", slosh
pichan = _LOADIMAGE(mypath, 32)
Pipe symbol is special to shell so cannot be used in a filename neither in Linux nor Windows. On MacOS, who knows? Maybe Fifi could tell us.
Note: I didn't include the subprogram because I don't have it with me at the moment. I have another one which works differently, ie. for search and replace strings of different lengths and therefore it doesn't use "MID$()" command.
Posts: 2,698
Threads: 327
Joined: Apr 2022
Reputation:
217
I was thinking more along the lines of something simple such as:
Code: (Select All) foo$ = "./mydir/foo.txt"
Print foo$
Print setSlash$(foo$)
foo2$ = ".\mydir\foo.txt"
Print foo2$
Print setSlash$(foo2$)
foo3$ = "./mydir\foo.txt"
Print foo3$
Print setSlash$(foo3$)
Function setSlash$ (text$)
temp$ = text$
$If WIN Then
desiredSlash$ = "\"
badSlash$ = "/"
$Else
desiredSlash$ ="/"
badSlash$ = "\"
$End If
Do
p = InStr(temp$, badSlash$)
If p Then Mid$(temp$, p, 1) = desiredSlash$
Loop Until p <= 0
setSlash$ = temp$
End Function
Posts: 1,272
Threads: 119
Joined: Apr 2022
Reputation:
100
Thanks for the replies guys. I knew the code itself would not change but underneath the correct interpretation of the slash would be used given the OS involved.
The reason I asked is that a tutorial user stated he had to change all of the backslashes to foreslashes to get the example listings to work in Linux. But like I said I could have swore QB64 would handle this behind the scenes. It could be that he is using a version of QB64 before this was implemented. I haven't gotten a reply back from him yet to find out.
I was hoping to avoid having to add directives to detect Windows and Linux in all of the source code I posted on the tutorial. I'll probably add a section in the tutorial detailing this and other differences between OS' when using QB64.
I'm going to set up another Linux box in the mean time. Those of you that use QB64 with Linux which distribution would you recommend? In the past I usually went with Mint. Any downside to using Mint?
Posts: 2,698
Threads: 327
Joined: Apr 2022
Reputation:
217
Mint is what I last used for my VM with Linux. Was a 1 click download and install, with no problems, so I'd have to recommend it for use with QB64.
If you find out that _LOADIMAGE doesn't swap those slashes automatically, toss us a note or make an issue at github. Something like that should be easy enough to make a quick fix for.
Posts: 1,272
Threads: 119
Joined: Apr 2022
Reputation:
100
(01-10-2023, 06:54 PM)SMcNeill Wrote: Mint is what I last used for my VM with Linux. Was a 1 click download and install, with no problems, so I'd have to recommend it for use with QB64.
If you find out that _LOADIMAGE doesn't swap those slashes automatically, toss us a note or make an issue at github. Something like that should be easy enough to make a quick fix for.
Will do, thanks.
Posts: 62
Threads: 12
Joined: Apr 2022
Reputation:
1
(01-10-2023, 06:34 PM)mnrvovrfc Wrote: Pipe symbol is special to shell so cannot be used in a filename neither in Linux nor Windows. On MacOS, who knows? Maybe Fifi could tell us.
Hi all,
As far as I know, the use of pipe symbols on macOS is the same as with Linux and can't be used in a filename on a hfs+ formatted drive. However, I never tried the apfs format but I guess the use of the pipe symbols is the same since it's used with bash.
About Linux on a VM, I recommend both Linuxmint and LMDE (Linus Mint Debian Edition).
However, whatever your main OS is (macOS, Linux or the crippled M$ Windows), the VM tool I definitely recommend is VMware for its real performances and efficient memory management Vs VirtualBox or Parallels Desktop.
Just my 2 cents.
Cheers.
Fifi
Before to send the arrow of truth, dip the head in a honey pot (Cheyenne saying).
Don't tell my Mom I'm on iMac with macOS, she thinks I work on PC with Windows.
|