flat assembler
Message board for the users of flat assembler.
Index
> Windows > Command line parsing |
Author |
|
vid 22 Mar 2007, 17:22
Hi, i'm implementing some command line parsing to FASMLIB. I've come upon strange behavior of WinAPI regarding usage of quotes and their escaping:
behavior is decsribed here. It seems to be some kind of all-compatible fix or something. Do you think i should follow this behavior, or do it differently? |
|||
22 Mar 2007, 17:22 |
|
vid 22 Mar 2007, 20:55
i can't:
MSDN wrote: Minimum operating systems: Windows NT Workstation 3.5, Windows NT Server 3.5, Windows 2000 Professional, Windows 2000 Server, Windows XP, Windows Server 2003 also it's unicode based, i would have to make 2 extra conversions (not THAT a big problem but still...) |
|||
22 Mar 2007, 20:55 |
|
asmfan 22 Mar 2007, 21:13
My one-pass parser i've done some time ago (of course with paper and pencil for the first time)) based on theory of finite automats;)
;;It doesn't handle those aspects (multiple /) that vid posted link to.
_________________ Any offers? |
|||||||||||
22 Mar 2007, 21:13 |
|
El Tangas 30 Mar 2007, 22:19
And I will contribute with my command line parser function. It doesn't understand "\" either, only quotes, its kinda incomplete, may have bugs and doesn't check for errors or lack of memory. Call this function at your own peril !!!
It does have some features: returns dword aligned ASCIIZ strings in argv/argc format, and, as a special bonus, these strings are prefixed by a dword containing their lenght, like Pascal strings. I find this useful.
|
|||||||||||
30 Mar 2007, 22:19 |
|
hidden 31 Mar 2007, 03:46
I also have written my command line parser. I don't like an idea to escape quotes by "\", I'm using double quotes to produce a single, like in assembler. And I don't pars all args in one call
Code: proc GetArg, line, num, buf, len xchg esi, [line] xchg edi, [buf] xchg ecx, [num] dec [len] jecxz .cur .lp1: lodsb or al, al jz .ret cmp al, '"' jne .nq1 .lp2: lodsb or al, al jz .ret cmp al, '"' jne .lp2 lodsb or al, al jz .ret cmp al, '"' je .lp2 .nq1: cmp al, ' ' jne .lp1 @@: lodsb cmp al, ' ' je @b dec esi loop .lp1 .cur: mov ecx, [len] .lp3: lodsb or al, al jz .end .chs: cmp al, ' ' je .end cmp al, '"' jne .nq2 .gq2: lodsb or al, al jz .ret cmp al, '"' jne .gq1 .nq2: stosb loop .lp3 .end: mov eax, [len] sub eax, ecx jz .ret mov byte[edi], 0 inc edi .ret: mov esi, [line] mov edi, [buf] mov ecx, [num] ret .lp4: lodsb or al, al jz .ret cmp al, '"' jne .gq1 lodsb or al, al jz .ret cmp al, '"' jne .chs .gq1: stosb loop .lp4 jmp .end .err: xor eax, eax jmp .ret endp |
|||
31 Mar 2007, 03:46 |
|
shoorick 02 Apr 2007, 07:52
you can also check function GetParameter in template there: http://board.flatassembler.net/topic.php?t=6663
|
|||
02 Apr 2007, 07:52 |
|
weiss 06 Apr 2007, 22:55
there is __getmainargs() in msvcrt.dll if anyone wants it already done for them.
Code: proc start local stinfo :STARTUPINFO local bWildCard :DWORD local pEnv :DWORD local pArgv :DWORD local nArgc :DWORD mov [bWildCard],FALSE ccall [__getmainargs],addr nArgc,addr pArgv,addr pEnv,[bWildCard],addr stinfo stdcall main,dword [nArgc],dword [pArgv] ccall [exit],0 endp proc main uses esi ebx edi, argc:DWORD, argv:DWORD .if [argc] = 4 ; do code .else stdcall usage,dword [argv] .endif ret endp probably better to rewrite that..but thats the general idea |
|||
06 Apr 2007, 22:55 |
|
weiss 09 May 2007, 23:03
having problems assembling the above code to 64-bits..anybody figure out the errors i get.
Code: format PE64 console 4.0 include 'include\win64w.inc' entry start section '.data' data readable writeable usage TCHAR 10,'Usage:%s <FILE>',10,0 section '.code' code readable executable proc start local nArgc :QWORD local pArgv :QWORD local pEnv :QWORD local bWildCard :QWORD local stinfo :STARTUPINFO invoke __wgetmainargs,nArgc,pArgv,pEnv,[bWildCard],stinfo mov rbx,[pArgv] .if qword[nArgc] = 2 invoke wprintf,usage,[rbx+8*0] .endif invoke exit,0 endp section '.idata' import data readable writeable library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL',\ msvcrt,'MSVCRT.DLL' include 'include\api\kernel32.inc' include 'include\api\user32.inc' import msvcrt,\ __wgetmainargs,'__wgetmainargs',\ exit,'exit',\ wprintf,'wprintf' errors are.. Quote: flat assembler version 1.67.21 (384470 kilobytes memory) |
|||
09 May 2007, 23:03 |
|
Chewy509 11 May 2007, 00:11
I've attached the snippets for the cmd line parsing used within the b0 compiler, used to create a normal argc, argv type environment with ANSI strings (not Unicode strings).
The function of interest is SetArgCV(); Hope this helps anyone in the future. Zip files contains both b0 and asm code. (Easy to read the b0 code). PS. Target = Win x64.
|
|||||||||||
11 May 2007, 00:11 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.