• Print

Author Topic: _OS$ function will be added to QB64 in the next release  (Read 224 times)

Galleon

  • Administrator
  • Hero Member
  • *******
  • Posts: 4226
  • QB Forever
    • Email
_OS$ function will be added to QB64 in the next release
« on: January 02, 2011, 06:06:07 PM »
I always get criticized for not announcing these things. ;)

Simply put, it returns a string containing some tags which you can use INSTR on to detect the environment under which QB64 programs are being built.

Example usage:
Code: [Select]
IF INSTR(_OS$, "[LINUX]") THEN PRINT "Use 'ls' in SHELL to list a directory"
IF INSTR(_OS$, "[WINDOWS]") THEN PRINT "Use 'dir' in SHELL to list a directory"
IF INSTR(_OS$, "[MACOSX]") THEN PRINT "Are we past February 2011 already?"

Here's the C code for how the function works:
Code: [Select]
qbs *func__os(){
qbs *tqbs;
#ifdef QB64_WINDOWS
tqbs=qbs_new_txt("[WINDOWS][32BIT]");
#else
 #ifdef QB64_MACOSX
  #ifdef QB64_32
  tqbs=qbs_new_txt("[MACOSX][32BIT][LINUX]");
  #else
  tqbs=qbs_new_txt("[MACOSX][64BIT][LINUX]");
  #endif
 #else
  #ifdef QB64_32
  tqbs=qbs_new_txt("[LINUX][32BIT]");
  #else
  tqbs=qbs_new_txt("[LINUX][64BIT]");
  #endif
 #endif
#endif
return tqbs;
}

Note: Even on 64-bit versions of Windows QB64 uses 32-bit libraries, so it generates 32-bit code. To avoid problems, I have made it always return 32-bit in Windows.

Pete

  • Moderator
  • Hero Member
  • *****
  • Posts: 5576
  • Cuz I sez so varmint!
Re: _OS$ function will be added to QB64 in the next release
« Reply #1 on: January 02, 2011, 07:23:07 PM »

LOL @ MACOSX detection.

Pete  ;D

Clippy

  • Hero Member
  • *****
  • Posts: 14397
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: _OS$ function will be added to QB64 in the next release
« Reply #2 on: January 02, 2011, 10:13:53 PM »
Exactly HOW does QB64 "detect" the OS? By the version number of QB64?

Why not just have the function return the OS only so INSTR is not required? What else will that string tell you?

Maybe the _TITLE of the program or even the program's name? That information could be used by an $INCLUDE BI file library for new program windows...

Just wondering...

Ted
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

Galleon

  • Administrator
  • Hero Member
  • *******
  • Posts: 4226
  • QB Forever
    • Email
Re: _OS$ function will be added to QB64 in the next release
« Reply #3 on: January 03, 2011, 03:42:08 AM »
Quote
Exactly HOW does QB64 "detect" the OS? By the version number of QB64?
When your code is compiled, certain items are defined within the GCC compiler depending on the platform you are compiling upon.

Quote
Why not just have the function return the OS only so INSTR is not required? What else will that string tell you?
You wouldn't use this command unless you were developing a multiplatform QB64 program and wanted to cater for specific differences between each platform. The [MACOSX] tag is found alongside a [LINUX] tag because MACOSX is built upon a LINUX sub-system. So even if you know nothing about MACs, but you cater for LINUX, odds are your program will run properly on a MAC too.

Quote
Maybe the _TITLE of the program or even the program's name? That information could be used by an $INCLUDE BI file library for new program windows...
That'd best be implemented as a different command.

rthorpe

  • Sr. Member
  • ****
  • Posts: 352
    • Email
Re: _OS$ function will be added to QB64 in the next release
« Reply #4 on: January 03, 2011, 07:51:25 AM »
Mac OS X is built on BSD Unix, not Linux. It's similar from the application programmer's point of view but not exactly the same.

  • Print