~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000 MySQL AB
2
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.
6
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.
11
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 */
15
16
/* Funktions for comparing with wild-cards */
17
18
#include "mysys_priv.h"
19
20
	/* Test if a string is "comparable" to a wild-card string */
21
	/* returns 0 if the strings are "comparable" */
22
23
char wild_many='*';
24
char wild_one='?';
25
char wild_prefix=0; /* QQ this can potentially cause a SIGSEGV */
26
27
int wild_compare(register const char *str, register const char *wildstr,
154 by Brian Aker
Removed oddball types in my_global.h
28
                 bool str_is_pattern)
1 by brian
clean slate
29
{
30
  char cmp;
31
32
  while (*wildstr)
33
  {
34
    while (*wildstr && *wildstr != wild_many && *wildstr != wild_one)
35
    {
36
      if (*wildstr == wild_prefix && wildstr[1])
37
      {
38
	wildstr++;
39
        if (str_is_pattern && *str++ != wild_prefix)
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
40
          return(1);
1 by brian
clean slate
41
      }
42
      if (*wildstr++ != *str++)
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
43
        return(1);
1 by brian
clean slate
44
    }
45
    if (! *wildstr )
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
46
      return(*str != 0);
1 by brian
clean slate
47
    if (*wildstr++ == wild_one)
48
    {
49
      if (! *str || (str_is_pattern && *str == wild_many))
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
50
        return(1);                     /* One char; skip */
1 by brian
clean slate
51
      if (*str++ == wild_prefix && str_is_pattern && *str)
52
        str++;
53
    }
54
    else
55
    {						/* Found '*' */
56
      while (str_is_pattern && *str == wild_many)
57
        str++;
58
      for (; *wildstr ==  wild_many || *wildstr == wild_one; wildstr++)
59
        if (*wildstr == wild_many)
60
        {
61
          while (str_is_pattern && *str == wild_many)
62
            str++;
63
        }
64
        else
65
        {
66
          if (str_is_pattern && *str == wild_prefix && str[1])
67
            str+=2;
68
          else if (! *str++)
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
69
            return (1);
1 by brian
clean slate
70
        }
71
      if (!*wildstr)
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
72
        return(0);		/* '*' as last char: OK */
1 by brian
clean slate
73
      if ((cmp= *wildstr) == wild_prefix && wildstr[1] && !str_is_pattern)
74
        cmp=wildstr[1];
75
      for (;;str++)
76
      {
77
        while (*str && *str != cmp)
78
          str++;
79
        if (!*str)
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
80
          return (1);
1 by brian
clean slate
81
	if (wild_compare(str,wildstr,str_is_pattern) == 0)
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
82
          return (0);
1 by brian
clean slate
83
      }
84
      /* We will never come here */
85
    }
86
  }
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
87
  return (*str != 0);
1 by brian
clean slate
88
} /* wild_compare */