1
/* Copyright (C) 2000 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
/* Funktions for comparing with wild-cards */
18
#include "mysys_priv.h"
20
/* Test if a string is "comparable" to a wild-card string */
21
/* returns 0 if the strings are "comparable" */
25
char wild_prefix=0; /* QQ this can potentially cause a SIGSEGV */
27
int wild_compare(register const char *str, register const char *wildstr,
31
DBUG_ENTER("wild_compare");
35
while (*wildstr && *wildstr != wild_many && *wildstr != wild_one)
37
if (*wildstr == wild_prefix && wildstr[1])
40
if (str_is_pattern && *str++ != wild_prefix)
43
if (*wildstr++ != *str++)
47
DBUG_RETURN(*str != 0);
48
if (*wildstr++ == wild_one)
50
if (! *str || (str_is_pattern && *str == wild_many))
51
DBUG_RETURN(1); /* One char; skip */
52
if (*str++ == wild_prefix && str_is_pattern && *str)
57
while (str_is_pattern && *str == wild_many)
59
for (; *wildstr == wild_many || *wildstr == wild_one; wildstr++)
60
if (*wildstr == wild_many)
62
while (str_is_pattern && *str == wild_many)
67
if (str_is_pattern && *str == wild_prefix && str[1])
73
DBUG_RETURN(0); /* '*' as last char: OK */
74
if ((cmp= *wildstr) == wild_prefix && wildstr[1] && !str_is_pattern)
78
while (*str && *str != cmp)
82
if (wild_compare(str,wildstr,str_is_pattern) == 0)
85
/* We will never come here */
88
DBUG_RETURN (*str != 0);