Author Topic: Command Line Seperator function  (Read 1531 times)

Offline SBlectric

  • Mc. Print
  • *
  • Posts: 49
  • Coding is neat I guess
    • View Profile
    • SBlectric Studios
Command Line Seperator function
« on: 2011-Dec-27 »
My first post! Woo!  :D

When I call GETCOMMANDLINE$() the commands are separated by either quotes (if they contain spaces) or just by spaces. Here is a function that will separate each one into elements of an array.

Check it out.  =D

Code: GLBasic [Select]
FUNCTION CmdLine: cmd$,e$[]

LOCAL a%,b%,exit%,pos%,endpos%

cmd$=REPLACE$(cmd$,CHR$(92),"/")

DIM e$[0]

WHILE 1

IF pos>LEN(cmd$)-1 THEN BREAK

SELECT ASC(MID$(cmd$,pos,1))

CASE 34 // if the value is an open quote

b=INSTR(cmd$,CHR$(34),pos+1)
        IF b<pos+1
        endpos=-1
        exit=1
        ELSE
        endpos=b-1-(pos)
        ENDIF

DIMPUSH e$[],MID$(cmd$,pos+1,endpos)
pos=b+1


CASE 32 // if it's a space
INC pos,1


DEFAULT // if it's any other character

b=INSTR(cmd$,CHR$(32),pos)
        IF b<pos+1
        endpos=-1
        exit=1
        ELSE
        endpos=b-1-(pos-1)
        ENDIF

DIMPUSH e$[],MID$(cmd$,pos,endpos)
pos=b


ENDSELECT

IF exit THEN BREAK
WEND

ENDFUNCTION

 
Cool stuff and whatever

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10714
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Command Line Seperator function
« Reply #1 on: 2011-Dec-27 »
I think a solution already existed?
http://www.glbasic.com/forum/index.php?topic=2066.msg15078#msg15078

and.. hello, welcome to the forums.

Offline SBlectric

  • Mc. Print
  • *
  • Posts: 49
  • Coding is neat I guess
    • View Profile
    • SBlectric Studios
Re: Command Line Seperator function
« Reply #2 on: 2011-Dec-27 »
Oh. Sorry, didn't see that. Cool!
Cool stuff and whatever