Author Topic: Commandline options  (Read 5944 times)

Matir

  • Full Member
  • ***
  • Posts: 179
  • QB64 for Android works!!!
Re: Commandline options
« Reply #15 on: April 29, 2015, 08:04:05 am »
-o would definitely be nice, but it would be quite difficult to implement reliably, especially regarding the handling of spaces. It all boils down to the fact that COMMAND$ is a single string, a concatenation of all the arguments passed (that is, each element of argv[]). You lose the information necessary to detect filenames with spaces properly on the command line. Until QB64 can provide access to the argv array, this would be very ugly, both internally and for the user on the command line.

Current QB64 options are:
Code: [Select]
-c    Compile file
-x    As -c, but use the console instead of a graphical window for progress reporting. My favourite.
-z    Do not compile generated C++ code.
-q    Compile for Qloud.
-g    Do not include graphics runtime (equivalent to $CONSOLE:ONLY I think, but don't quote me on that)
All switches imply -c; -z and -q imply -x.
Options must proceed the filename.
-- can be used as a dummy option to force the next thing to be a file (ordinaraily, -crapfile.bas would be interpreted as the -c switch)
[/code]

That shouldn't be too hard:

Code: [Select]
'$DYNAMIC

GetArgs args$(), count

FOR x = 0 TO count
 PRINT args$(x)
NEXT x

SUB GetArgs (args() AS STRING, count)
REDIM args(-1) AS STRING: count = -1

s$ = " " + COMMAND$

DO
 p = lastpos + 1
 lastpos = INSTR(p, s$, " ")
 p = lastpos + 1
 nextpos = INSTR(p, s$, " ")
 IF nextpos = 0 THEN nextpos = LEN(s$) + 1
 IF lastpos = 0 THEN EXIT DO
 count = count + 1
 REDIM _PRESERVE args(count)
 args(count) = MID$(s$, p, nextpos - p)
LOOP
END SUB
:):( ;)

Johny B.

  • QB64 Partner Site Owner
  • Hero Member
  • *
  • Posts: 1499
Re: Commandline options
« Reply #16 on: May 01, 2015, 09:18:09 pm »
Let's look at how COMMAND$ renders some command lines. In the following table (monospaced to preserve number of spaces) we have the original command line, the content of COMMAND$, and what the argv array
contains.
Code: [Select]
Commandline:                           COMMAND$:                          argv:
hello                                  hello                              {helllo}
hello world                            hello world                        {hello, world}
hello    world                         hello world                        {hello, world}
"hello    world"                       hello    world                     {hello    world}
-o outfile infile                     -o outfile infile                   {-o, outfile, infile}
-o "outfile spaces" "infile spaces"   -o outfile spaces infile spaces     {-o, outfile spaces, infile spaces}
Hopefully this makes the issue apparent. The shell separates the arguments based on spaces, quoting, character escapes etc., and passes this to the program. QB64 then rejoins them all together, but without the original quoting information. As the 4th and 5th examples show, it is impossible to tell where one file name ends, and the next begins. QBasic programs, of course, did not have this problem because file names could not contain spaces.

I am attempting to work on some kind of solution to this (ideally allowing COMMAND$ to be optionally subscripted like an array, to access the original argv, not affecting plain COMMAND$) but that involved trawling through a lot of QB64 internals, and doesn't look like it's going to happen any time soon.

SkyCharger001

  • Hero Member
  • *****
  • Posts: 2384
Re: Commandline options
« Reply #17 on: May 02, 2015, 06:43:42 am »
does anyone know how to make argv/argc (or any internal variable) available to an external .H function/ library?
My idea is to use a .H function that returns the content of one argv[] entry (or "" if the entry doesn't exist) as a temporary solution for the commandline issue.

SMcNeill

  • Moderator
  • Hero Member
  • *****
  • Posts: 6071
Re: Commandline options
« Reply #18 on: May 02, 2015, 10:41:02 am »
does anyone know how to make argv/argc (or any internal variable) available to an external .H function/ library?
My idea is to use a .H function that returns the content of one argv[] entry (or "" if the entry doesn't exist) as a temporary solution for the commandline issue.

I was just working with Luke on this last night; give us a few days and we'll see what we can come up with.  :)

My basic idea is to make a couple global variables to hold the values of argc and argv and then it'll be a simple matter to create 2 new functions to return those values to us as needed.  I've got argc where I can easily pass it back and forth in QB64, but my routine for argc is still giving me a compiler error I just haven't sorted out fully yet.  I'm thinking we're on the right track for a reliable way to get those values back for us, once we get the bugs sorted out, if you can wait a few days.  :)
http://bit.ly/TextImage -- Library of QB64 code to manipulate text and images, as a BM library.

http://bit.ly/Color32 -- A set of color CONST for use in 32 bit mode, as a BI library.

Billbo

  • Hero Member
  • *****
  • Posts: 1143
Re: Commandline options
« Reply #19 on: May 02, 2015, 07:31:00 pm »
To all,

How about an option to load a program so it's waiting for you to work on?

Bill

P.S. It just dawned on me that you are probably talking about options that have QB64 do something but itself not open.


Superloach

  • Newbie
  • *
  • Posts: 2
LINUX???
« Reply #20 on: September 11, 2017, 04:40:13 pm »
So... I found a list of command line options here.
However, this is all talking about Windows. I tried most of them on Linux, and they seemed to try to work, but I couldn't find the output file anywhere. Am I doing something wrong?

btw i am running this:
Code: [Select]
~/qb64/qb64 -z ~/Downloads/project\ 1.bas -o ~/Downloads/project\ 1
if that is wrong let me know :P

FellippeHeitor

  • QB64 Partner Site Owner
  • Hero Member
  • *
  • Posts: 1522
  • LET IT = BE
    • QB64.org
Re: Commandline options
« Reply #21 on: September 11, 2017, 04:47:36 pm »
Linux doesn't tend to like binaries with spaces in their names in my limited experience. Rename "project 1.bas" to "project1.bas" and try:

~/qb64/qb64 -x "~/Downloads/project1.bas"

With the above, your binary will be in ~/qb64/qb64.

~/qb64/qb64 -x "~/Downloads/project1.bas" -o "~/Downloads/project1"

Now your binary will be in ~/Downloads.

In the IDE, check "Run->Save EXE in the source folder" if you want it to always act that way, even in the command line.
« Last Edit: September 11, 2017, 04:53:54 pm by FellippeHeitor »

Superloach

  • Newbie
  • *
  • Posts: 2
Re: Commandline options
« Reply #22 on: September 12, 2017, 07:41:10 am »
Oh, okay! Thanks for replying so quickly, too!
Now I can set up a script that cycles between nano and QB64!
Something like this? I feel I may be using $1 wrong.
Code: [Select]
while true; do
    nano "$1.bas"
    ~/qb64/qb64 -x "$1.bas" -o "$1"
done

BTW, what does -g do? Does that make it output into the command line? Because I just get
Code: [Select]
freeglut (/home/superloach/Downloads/p1): as output from my compiled program, and I think this might be the problem.

p.s. - I am using crouton... May change things.

FellippeHeitor

  • QB64 Partner Site Owner
  • Hero Member
  • *
  • Posts: 1522
  • LET IT = BE
    • QB64.org
Re: Commandline options
« Reply #23 on: September 12, 2017, 08:45:21 am »
The switch -g isn't effective as of version 1.1:

Quote
C:\qb64>qb64 -help
QB64 COMPILER V1.1

USAGE: qb64 [switches] <inputs>

OPTIONS:
  <file>                  Source file to load
  -c                      Compile instead of edit
  -x                      Compile instead of edit and output the result to the
                             console
  -z                      Generate C code without compiling to executable
  -o <file>               Write output executable to <file>
  -e                      Enables OPTION _EXPLICIT, making variable declaration
                             mandatory (per-compilation; doesn't affect the
                             source file or global settings)
  -s[:switch=true/false]  View/edit compiler settings

What's yet to be removed of the -g code internally in qb64.bas is almost identical to the -x switch (which should be used instead), but will fail to compile, which is why it's not even listed in the help screen above.
« Last Edit: September 12, 2017, 09:09:00 am by FellippeHeitor »

Clippy

  • Hero Member
  • *****
  • Posts: 19374
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
Re: Commandline options
« Reply #24 on: September 12, 2017, 06:33:15 pm »
When was the g switch removed and why?
QB64 WIKI: Main Page
Download Q-Basics Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
QB64 SDL

FellippeHeitor

  • QB64 Partner Site Owner
  • Hero Member
  • *
  • Posts: 1522
  • LET IT = BE
    • QB64.org
Re: Commandline options
« Reply #25 on: September 12, 2017, 06:54:39 pm »
It's never been officially available as far as I can tell, as it was supposed to be for the G-WAN functionality that's never happened.