BASIC

### Author Topic: Command Line Seperator function  (Read 1529 times)

#### SBlectric

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

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.

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

#### Kitty Hello

• code monkey
• Prof. Inline
• Posts: 10713
• here on my island the sea says 'hello'
##### 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.

#### SBlectric

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