Author
Topic: strcmp with wildcards (Read 774 times)

A recent thread in here reminded me of a time I needed simple wildcard support (specifically * and ?) for a rough lstrcmpA equivalent. While this doesn't handle all sorts of special circumstances, it did its job, but it always bugged me that I had a jump and label when the rest of the function was able to use .if/.repeat/etc. Anyone have any suggestions? Or is it just screwed because MASM doesn't let you break out of multiple loops (or does it and I've just never figured out the syntax)?

The example strings aren't comprehensive, but do cover quirks like "*?". I realize naming it _lstrcmpA_* isn't great since it doesn't match lstrcmpA behavior, but in my defense, when it was written, it matched behavior in the specific circumstance it was designed for.

Right, notice the macro is named to mimic the option. Sometimes declaring and then redeclaring the prologue option is a pain in the butt. Note that this macro causes issues if there's a relocatable address in an instruction in the proc.

Quote from: jj2007

Btw can you give a short real life example where to use this wildcard comparison? I have never thought of it, just curious how it could be applied.

Any time you want to check if part of a string matches your search criteria without needing a complete match. I guess an example could be: use with EnumWindows and GetWindowTextA to find a window whose title contains both the program's name and a filename. It's an imperfect example because there'd be better ways to find said window, and you'd be better off using unicode functions if you resorted to a text search, but that's beside the point. It'd arguably be better (more precise) than using "strstr" and way less expensive than a RegExp implementation.

Regarding UASM, neat, though I rely on some weirdness of MASM for an everyday macro I use that I'm fairly certain UASM doesn't (and likely wouldn't) support. I'll post about that in a new topic some time in the future (it involves option oldmacros).

To my knowledge, this is not implemented in UAsm. But most probably your macro needs only a minor modification to work without that option (I am curious to see the new thread). One reason why UAsm64 is my default nowadays is speed: It makes a real difference if you have to wait 3 (UAsm) or 10 (ML) seconds for your build to complete...

If you have the MASM32 distribution, have a look at one of the library routines called "partial.asm". It does not do what you are doing but it is doing a similar things, scanning a text for partial matches.