home *** CD-ROM | disk | FTP | other *** search
-
- #include <stdio.h>
- #include <string.h>
-
- typedef int bool;
-
- bool match(const char *wildcard, const char *string)
- {
- char process[256], *i = process;
- while((unsigned char) *string >= ' ') *i++ = *string++;
- *i = 0;
- string = process;
-
- /* Match the beginning of string */
- while((*wildcard != '*') && (*wildcard != 0))
- if(*wildcard++ != *string++) return 0;
- if(*wildcard++ == 0 && *string == 0) return 1;
-
- /* Match the middle */
- while(strchr(wildcard, '*')) {
- char match[256], *m = match;
- int length = 0;
- while(*wildcard != '*') length++, *m++ = *wildcard++;
- *m = 0;
- wildcard++;
-
- while(strncmp(match, string, length)) {
- if(strlen(string) < length) return 0;
- string++;
- }
- }
-
- /* Match the end */
- if(strcmp(wildcard, string + strlen(string) - strlen(wildcard))) return 0;
- return 1;
- }
-