00001
00002
00003
00004
00005
00006 #include "common.h"
00007
00008 static char const rcsid[] = "$Id: wildcmp.c,v 1.5 2003/05/06 07:33:44 kate Exp $";
00009
00010 static int subMatch(char *str, char *wild)
00011
00012
00013 {
00014 int len = 0;
00015
00016 for(;;)
00017 {
00018 if(toupper(*str++) != toupper(*wild++) )
00019 return(0);
00020 ++len;
00021 switch(*wild)
00022 {
00023 case 0:
00024 case '?':
00025 case '*':
00026 return(len);
00027 }
00028 }
00029 }
00030
00031 boolean wildMatch(char *wildCard, char *string)
00032
00033
00034
00035
00036 {
00037 boolean matchStar = 0;
00038 int starMatchSize;
00039
00040 for(;;)
00041 {
00042 NEXT_WILD:
00043 switch(*wildCard)
00044 {
00045 case 0:
00046 {
00047 if(matchStar)
00048 {
00049 while(*string++)
00050 ;
00051 return TRUE;
00052 }
00053 else if(*string)
00054 return FALSE;
00055 else
00056 return TRUE;
00057 }
00058 case '*':
00059 matchStar = TRUE;
00060 break;
00061 case '?':
00062 {
00063 if(*string == 0)
00064 return FALSE;
00065 ++string;
00066 break;
00067 }
00068 default:
00069 {
00070 if(matchStar)
00071 {
00072 for(;;)
00073 {
00074 if(*string == 0)
00075 return FALSE;
00076
00077
00078
00079 if((starMatchSize = subMatch(string,wildCard)) != 0)
00080 {
00081 string += starMatchSize;
00082 wildCard += starMatchSize;
00083 matchStar = FALSE;
00084 goto NEXT_WILD;
00085 }
00086 ++string;
00087 }
00088 }
00089
00090
00091 if(toupper(*string) != toupper(*wildCard))
00092 return FALSE;
00093 ++string;
00094 break;
00095 }
00096 }
00097 ++wildCard;
00098 }
00099 }