Hi friends,

Here is a simple command line parser algo, it can handle quoted parameters. I coded also a tiny C run-time startup module using my algo to get command line parameters. The zip file includes examples for Digital Mars , Pelle's C and Visual C/C++ compilers.


.386
.model flat, stdcall
option casemap :none

include \masm32\include\kernel32.inc

ParseCmdLine PROTO :DWORD

.code

ParseCmdLine PROC uses esi buffer:DWORD

invoke GetCommandLine
lea edx,[eax-1]
mov esi,buffer
xor eax,eax
scan:
inc edx
mov cl,byte ptr [edx]
or cl,cl
jz finish
cmp cl,32
je scan
nospace:
inc eax
mov [esi],edx
cmp cl,34
je quote
mov ch,32
jmp incbuff
quote:
inc dword ptr [esi]
mov ch,34
incbuff:
add esi,4
@@:
inc edx
mov cl,byte ptr [edx]
or cl,cl
jz finish
cmp cl,ch
jne @b
mov byte ptr [edx],0
jmp scan
finish:
ret

ParseCmdLine ENDP
END
Posted on 2004-09-03 15:09:35 by Vortex
Here is the second version allowing to insert a literal double quote inside an argument.

Thanks Jibz for your suggestion. The command line parser from your C run-time library helped me a lot
Posted on 2004-09-13 16:24:45 by Vortex
__getmainargs() works
Posted on 2004-09-13 16:57:05 by Drocon
I used a lot the function __getmainargs()
It might be slower than my hand-coded algo.
Posted on 2004-09-13 17:11:00 by Vortex