Of all the commandline parsers i've seen here, they "overdid" everything to me. So i decided to just create my own for the text editor i have created. All i wanted to do was to be able to associate a file type with my editor and have it open it. The file is placed into the commandline as such : "NameOfTheExe" "FileToOpen.blah"
so all my little algo does is search for that 2nd parameter in quotes and returns a pointer to it in eax, else if it isn't there it returns null. Just posting up incase anyone could use it( ,but of course the masm32 library has that nice GetCL function, inwhich would make this irrelevant)

Tis in Nasm, but i know you all can convert to your other assemblers syntax =)





;CommandLine Processing for file name.
ProcessCL:

enter 0,0

call GetCommandLineA
mov esi, eax
mov edi, Buffer ;just a 128 byte data buffer, you can declare this in the data segment of your code
xor ecx, ecx
inc esi ;skips past the first quote(22h)

part00:

cmp byte [esi], 22h
je part01
inc esi
jmp part00

part01:

;after finding the end quote for the executable name it
;shifts over two bytes to the assumed opening quote for
;the filename param. If it is not there the algo returns 0 and ends
inc esi
inc esi
cmp byte [esi], 22h
jne part04
inc esi

part02:

;reads up until the end quote then places a null byte into that
;position and returns this in eax.
cmp byte [esi], 22h
je part03
mov dl, byte [esi]
mov byte [edi], dl
inc edi
inc esi
inc ecx
jmp part02

part03:

mov byte [edi], 00h
sub edi, ecx
mov eax, edi

leave
ret

part04:

xor eax, eax
leave
ret

Posted on 2003-08-05 19:42:25 by Guy on ASM
Weird to see a stack frame set up when you never actually did mess around much with the stack. hmm

Why not rearrange the loop


inc esi ;skips past the first quote(22h)

part00:

cmp byte [esi], 22h
je part01
inc esi
jmp part00

to


_part00:
inc esi
cmp byte [esi], 22h
jnz _part00

Just skimming through ur code...
Posted on 2003-08-06 02:55:44 by roticv
Hmm thanks, I guess i'll add that in =):alright:
Posted on 2003-08-06 07:49:53 by Guy on ASM