Page 1 of 1

Simple time saver for multi os compiling

Posted: Wed Jul 20, 2011 6:23 am
by J. Baker

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Linux Or #PB_OS_MacOS
  #Slash$ = "/"
CompilerElse
  #Slash$ = "\"
CompilerEndIf

Code: Select all

Pic1: IncludeBinary "game data" + #Slash$ + "image.png"
I just got tired of editing the code everytime I switched back and forth from a different OS. ;)

Re: Simple time saver for multi os compiling

Posted: Wed Jul 20, 2011 12:25 pm
by luis
The compilerif should be

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Linux Or #PB_Compiler_OS = #PB_OS_MacOS
otherwise it doesn't work (always true).

Probably it's shorter to reverse the thing and test for "windows or else" anyway :)

Re: Simple time saver for multi os compiling

Posted: Wed Jul 20, 2011 1:21 pm
by helpy
Some additional Information:

cite from msdn:
Microsoft MSDN wrote:Note:
File I/O functions in the Windows API convert "/" to "\" as part of converting the name to an NT-style name, except when using the "\\?\" prefix as detailed in the following sections.
History: Why is the DOS path character "\"?

Re: Simple time saver for multi os compiling

Posted: Wed Jul 20, 2011 6:32 pm
by J. Baker
luis wrote:The compilerif should be

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Linux Or #PB_Compiler_OS = #PB_OS_MacOS
otherwise it doesn't work (always true).

Probably it's shorter to reverse the thing and test for "windows or else" anyway :)
Why do you say that? It works just fine here on my Mac and my XP pc. Did it not work for you? What OS are you using?

Re: Simple time saver for multi os compiling

Posted: Wed Jul 20, 2011 6:52 pm
by luis
J. Baker wrote: Why do you say that? It works just fine here on my Mac and my XP pc. Did it not work for you? What OS are you using?
I would say It seem to work, since the "/" works anyway in normal paths under Windows too.

You are writing "IF[condition] OR TRUE".

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Linux Or #PB_OS_MacOS
  #Slash$ = "/"
CompilerElse
  #Slash$ = "\"
CompilerEndIf

Debug #Slash$ 
What does your XP machine prints ?

Re: Simple time saver for multi os compiling

Posted: Wed Jul 20, 2011 7:11 pm
by J. Baker
What the hell! :shock:

I didn't know that a "/" would work in Windows. I'll be a monkeys ass. :oops:
What does your XP machine prints ?
Not sure what you are asking here?

Re: Simple time saver for multi os compiling

Posted: Wed Jul 20, 2011 7:20 pm
by luis
J. Baker wrote: Not sure what you are asking here?
Just read my previous post, and try what I included between the CODE tags. All should be clear then (the reason why the compilerif you wrote is wrong). :wink:

Re: Simple time saver for multi os compiling

Posted: Wed Jul 20, 2011 7:50 pm
by J. Baker
luis wrote:
J. Baker wrote: Not sure what you are asking here?
Just read my previous post, and try what I included between the CODE tags. All should be clear then (the reason why the compilerif you wrote is wrong). :wink:
Sorry, didn't see you had Debug there.

Interesting! It gave me a "/". I guess it is always true then like you said. Being that Windows can be "/" or "\".

Well luis, I have to thank you for the tip today. Thanks! ;)

Re: Simple time saver for multi os compiling

Posted: Thu Jul 21, 2011 3:29 am
by kenmo
:) J., I do the exact same thing in a lot of my programs (except I keep the constant name short: #PS$ for Path Separator).

I was somewhat-aware that "/" usually works on Windows, but I still use an OS-dependent delimiter because you don't want your user to see non-native path characters! (whether in your GUI, a saved file, etc. etc.)