I needed this for a toy I am writing. Nothing fancy but seems to work OK on Explorer, Winfile and from the command line. I am sure it could be faster, smaller etc etc .. but it ain't like it matters much.
Call code. Note that it should also have a test if the file exists, I have not written a unicode one for this yet.
; -----------------------------------------
invoke GetCmdTail ; get the address of the command tail
mov CmdTail, eax
movzx edx, WORD PTR [eax] ; test if 1st WORD is zero (0)
.if edx != 0
invoke file_read,hEdit,CmdTail
fn SetWindowTextW,hWnd,CmdTail
.endif
; -----------------------------------------
Algorithm.
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
GetCmdTail proc
invoke GetCommandLineW
sub eax, 2
@@:
add eax, 2
cmp WORD PTR [eax], 0
je zero
cmp WORD PTR [eax], 34 ; branch on leading double quote
je quoted
cmp WORD PTR [eax], 32
je @B
unquoted:
add eax, 2
cmp WORD PTR [eax], 0
je zero
cmp WORD PTR [eax], 32 ; scan to 1st space
jne unquoted
jmp trimit
quoted:
add eax, 2
cmp WORD PTR [eax], 0
je zero
cmp WORD PTR [eax], 34 ; scan to closing double quote
jne quoted
trimit:
add eax, 2
cmp WORD PTR [eax], 32 ; trim any leading spaces off cmd tail
je trimit
zero:
ret
GetCmdTail endp
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
not unicode, but i thought you might be interested...
INVOKE GetCommandLine
xor ecx,ecx
mov dx,2220h ;double quote and space
mov lpCmndLineFull,eax
Start0: cmp cl,dh ;double quote
jnz Start2
Start1: mov cl,[eax]
jecxz Start4
inc eax
cmp cl,dh ;double quote
jnz Start1
Start2: mov cl,[eax]
jecxz Start4
inc eax
cmp cl,dl ;space
jnz Start0
Start3: mov cl,[eax]
inc eax
cmp cl,dl ;space
jz Start3
dec eax
Start4: mov lpCmndLine,eax
it could be adapted for unicode fairly easily, i think
i was shooting for small :P
writing parsers is a love-hate thing - lol