00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <config.h>
00019
00020 #include <drizzled/internal/my_sys.h>
00021
00022 namespace drizzled
00023 {
00024 namespace internal
00025 {
00026
00027
00028
00029
00030 char wild_many='%';
00031 char wild_one='_';
00032 char wild_prefix= '\\';
00033
00034 int wild_compare(const char *str, const char *wildstr, bool str_is_pattern)
00035 {
00036 char cmp;
00037
00038 while (*wildstr)
00039 {
00040 while (*wildstr && *wildstr != wild_many && *wildstr != wild_one)
00041 {
00042 if (*wildstr == wild_prefix && wildstr[1])
00043 {
00044 wildstr++;
00045 if (str_is_pattern && *str++ != wild_prefix)
00046 return(1);
00047 }
00048 if (*wildstr++ != *str++)
00049 return(1);
00050 }
00051 if (! *wildstr )
00052 return(*str != 0);
00053 if (*wildstr++ == wild_one)
00054 {
00055 if (! *str || (str_is_pattern && *str == wild_many))
00056 return(1);
00057 if (*str++ == wild_prefix && str_is_pattern && *str)
00058 str++;
00059 }
00060 else
00061 {
00062 while (str_is_pattern && *str == wild_many)
00063 str++;
00064 for (; *wildstr == wild_many || *wildstr == wild_one; wildstr++)
00065 if (*wildstr == wild_many)
00066 {
00067 while (str_is_pattern && *str == wild_many)
00068 str++;
00069 }
00070 else
00071 {
00072 if (str_is_pattern && *str == wild_prefix && str[1])
00073 str+=2;
00074 else if (! *str++)
00075 return (1);
00076 }
00077 if (!*wildstr)
00078 return(0);
00079 if ((cmp= *wildstr) == wild_prefix && wildstr[1] && !str_is_pattern)
00080 cmp=wildstr[1];
00081 for (;;str++)
00082 {
00083 while (*str && *str != cmp)
00084 str++;
00085 if (!*str)
00086 return (1);
00087 if (wild_compare(str,wildstr,str_is_pattern) == 0)
00088 return (0);
00089 }
00090
00091 }
00092 }
00093 return (*str != 0);
00094 }
00095
00096 }
00097 }