README.md

December 5, 2022 ยท View on GitHub

^NEW^ -- wildcard string compare (globbing)

Description

matches a string against a wildcard string such as "." or "bl?h.*" etc. This is good for file globbing or to match hostmasks.

More Info

1 on match, 0 on no match.

Submitted On
ByJack Handy
LevelBeginner
User Rating4.6 (46 globes from 10 users)
CompatibilityC, C++ (general), Microsoft Visual C++, Borland C++, UNIX C++
CategoryStrings
WorldC / C++
Archive File

Source Code

int wildcmp(char *wild, char *string) {
 char *cp, *mp;
 while ((*string) && (*wild != '*')) {
 if ((*wild != *string) && (*wild != '?')) {
  return 0;
 }
 wild++;
 string++;
 }
 while (*string) {
 if (*wild == '*') {
  if (!*++wild) {
  return 1;
  }
  mp = wild;
  cp = string+1;
 } else if ((*wild == *string) || (*wild == '?')) {
  wild++;
  string++;
 } else {
  wild = mp;
  string = cp++;
 }
 }
 while (*wild == '*') {
 wild++;
 }
 return !*wild;
}