// // Scans memory buffer for a substring containing a wildcast. // If found returns the pointer to the substring and it's size. // CHAR* __cdecl __memwiscan( const CHAR *mem, int size, const CHAR *wild, int *psize ) { const CHAR *wp = wild, *mp = NULL; char c; int s; while((size) && (*wp)) { while((c = *wp) && (c != '*') && (c != '?') && (size) && (__ascii_tolower(c) != __ascii_tolower(*mem))) { size -= 1; mem += 1; } mp = mem; s = size; while((c = *wp) && (c != '*') && (size) && ((c == '?') || (__ascii_tolower(c) == __ascii_tolower(*mem)))) { size -= 1; mem += 1; wp += 1; } if (c == '*') { while(*wp == '*') wp += 1; if (mem = __memwiscan(mem, size, wp, &size)) *psize = ((int)(mem - mp) + size); else mp = NULL; break; } if (c == 0) { *psize = s - size; break; } mem = mp + 1; if (s) size = s - 1; wp = wild; mp = NULL; } // while((size) && (*wp)) return((CHAR*)mp); }
extern "C" int __cdecl __ascii_memicmp( const void* first, const void* last, size_t count ) { int f = 0; int l = 0; while (count--) { if ((*(unsigned char*)first == *(unsigned char*)last) || ((f = __ascii_tolower(*(unsigned char*)first)) == (l = __ascii_tolower(*(unsigned char*)last)))) { first = (char*)first + 1; last = (char*)last + 1; } else { break; } } return (f - l); }
// // Compare string with wildcast ignore case. // int __cdecl __strwicmp(const CHAR *wild, const CHAR *string) { const CHAR *cp = NULL, *mp = NULL; while ((*string) && (*wild != '*')) { if ((__ascii_tolower(*wild) != __ascii_tolower(*string)) && (*wild != '?')) return 0; wild++; string++; } while (*string) { if (*wild == '*') { if (!*++wild) return 1; mp = wild; // cp = string+1; // '*' requires any symbol (*a != a) cp = string; // '*' doesn't require a symbol (*a == a) } else if ((__ascii_tolower(*wild) == __ascii_tolower(*string)) || (*wild == '?')) { wild++; string++; } else { wild = mp; string = cp++; } } // while (*string) while (*wild == '*') wild++; return !*wild; }