Simple time saver for multi os compiling

Share your advanced PureBasic knowledge/code with the community.
User avatar
J. Baker
Addict
Addict
Posts: 2181
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Simple time saver for multi os compiling

Post 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. ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Simple time saver for multi os compiling

Post 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 :)
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Re: Simple time saver for multi os compiling

Post 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 "\"?
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
User avatar
J. Baker
Addict
Addict
Posts: 2181
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Simple time saver for multi os compiling

Post 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?
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Simple time saver for multi os compiling

Post 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 ?
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
J. Baker
Addict
Addict
Posts: 2181
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Simple time saver for multi os compiling

Post 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?
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Simple time saver for multi os compiling

Post 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:
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
J. Baker
Addict
Addict
Posts: 2181
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Simple time saver for multi os compiling

Post 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! ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
User avatar
kenmo
Addict
Addict
Posts: 2042
Joined: Tue Dec 23, 2003 3:54 am

Re: Simple time saver for multi os compiling

Post 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.)
Post Reply