Hi,

This is my asm conversion from Jack Handy's wildcard matching algo. You can find original C code from http://www.codeproject.com/string/wildcmp.asp

Could you check if there are some conversion errors?

.486
.MODEL FLAT, STDCALL
option casemap:none

include d:\masm32\include\windows.inc
include d:\masm32\include\kernel32.inc
include d:\masm32\include\masm32.inc
includelib d:\masm32\lib\kernel32.lib
includelib d:\masm32\lib\masm32.lib


Main PROTO
WildMatch PROTO :DWORD, :DWORD

CTEXT MACRO text:VARARG
    LOCAL TxtName
    .data
    TxtName BYTE text,0
    .code
  EXITM <ADDR TxtName>
ENDM

.const

.data

.data?

.code
Start:
invoke Main
invoke ExitProcess, eax

Main proc
invoke WildMatch, CTEXT("bl?h.*"), CTEXT("blah.jpg")
.if eax != 0
invoke StdOut, CTEXT("Match")
.else
invoke StdOut, CTEXT("No Match")
.endif
xor eax, eax

ret
Main endp

WildMatch proc uses ebx esi edi wild :DWORD, string :DWORD
mov ecx, wild
mov edx, string
.while BYTE PTR != 0 && BYTE PTR != "*"
mov bl,
mov bh,
.if bl != bh && bl != "?"
xor eax, eax
ret
.endif
inc ecx
inc edx
.endw

.while BYTE PTR != 0
mov bl,
mov bh,
.if bl == "*"
inc ecx
mov bl,
.if bl == 0
xor eax, eax
inc eax
ret
.endif
mov esi, ecx
mov eax, edx
inc eax
.elseif bl == bh || bl == "?"
inc ecx
inc edx
.else
mov ecx, esi
mov edx, eax
inc eax
.endif
.endw

.while BYTE PTR == "*"
inc ecx
.endw

xor eax, eax
inc eax
ret
WildMatch endp

end Start


Best regards,
Sami
Posted on 2005-10-25 15:13:23 by SamiP
Nice, though a bit faulty:
invoke WildMatch,T("* ins good"),T("life is good")
returns 1


the last line "return !*wild;" isn't converted properly, I nearly missed it too.
Just put this code as end:

xor eax,eax
mov al,
or al,al
sete al

Posted on 2005-10-26 01:29:27 by Ultrano
Now I understand what I missed at the end. Big thanks to you, Ultrano.
Posted on 2005-10-26 02:53:15 by SamiP
You can check my implementation of comrade's algo here:
http://www.asmcommunity.net/board/index.php?topic=6558.0
http://comrade.ownz.com/sources/match.zip
Posted on 2005-10-26 13:26:06 by comrade
On a side note, a similar implementation of mine, that returns the wild-carded strings is here:
http://www.asmcommunity.net/board/index.php?topic=17089.0
I've been using it a lot in my simple IDE for intellisense, but yesterday I found a case when it doesn't return a correct result. Otherwise, has the same imperfections as Jack Handy's code ^^"
Posted on 2005-10-26 14:10:51 by Ultrano
Are there any implementations in Masm32 package?
Posted on 2005-10-26 22:04:13 by comrade
In MASM32 v7 there are no wildcard implementations, I haven't installed the v8 - but I don't remember having seen such code there either.
Posted on 2005-10-26 22:47:00 by Ultrano