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.
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
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
Thanks Jibz for your suggestion. The command line parser from your C run-time library helped me a lot

__getmainargs() works
I used a lot the function __getmainargs()
It might be slower than my hand-coded algo.
It might be slower than my hand-coded algo.