Hi Bruce,
As you have realised, it is not trivial code.
I have written some candidate code here. I propose putting it into a file called mainutil.inc.
//http://en.wikipedia.org/wiki/Main_function
includepath "$/inc/"
include "minwin.inc"
indexbase 1
zstring z at (getcommandline)
sys v[32]
sys argc
'print z
'char z[]=`"command" "one two three four"`
byte b at @z
byte a
sys i=1
indexbase 1
do
a=b[ i]
if a=34
do
i++
a=b[ i]
if a=34 then i++ : jmp fwd ncommand
if a=0 then jmp fwd ncommand
end do
end if 'a=34
if i<33
jmp fwd ncommand
end if
i++
end do
ncommand:
'skipspace
do
a=b[ i]
if a=0
jmp fwd nparam
elseif a>32
exit do
end if
i++
end do
'exclude quotes
if b[ i]=34
i++
sys j=i+1
do
if b[j]=34
b[j]=0
exit do
end if
j++
end do
end if
'array commands:
readnextparam:
do
a=b[ i]
if a=0
jmp fwd nparam
elseif a>32
exit do
end if
i++
end do
argc++
v[argc]=@z+i-1
do
a=b[ i]
if a=0 then jmp fwd nparam
if a<33
b[ i]=0
i++
exit do
end if
i++
end do
jmp readnextparam
nparam:
! main(sys c,v) as sys
main(argc,v)
'TEST
'====
function main(sys argc,argv) as sys
sys j
for j=1 to argc
print cast char* argv[j]
next
end function
Charles