~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
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
15
16
/* Funktions for comparing with wild-cards */
17
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
18
#include <config.h>
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
19
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
20
#include <drizzled/internal/my_sys.h>
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
21
22
namespace drizzled
23
{
24
namespace internal
25
{
1 by brian
clean slate
26
27
	/* Test if a string is "comparable" to a wild-card string */
28
	/* returns 0 if the strings are "comparable" */
29
909 by Brian Aker
Remove the need for unireg init
30
char wild_many='%';
31
char wild_one='_';
32
char wild_prefix= '\\';
1 by brian
clean slate
33
2194.3.1 by Olaf van der Spek
Remove register keyword
34
int wild_compare(const char *str, const char *wildstr, bool str_is_pattern)
1 by brian
clean slate
35
{
36
  char cmp;
37
38
  while (*wildstr)
39
  {
40
    while (*wildstr && *wildstr != wild_many && *wildstr != wild_one)
41
    {
42
      if (*wildstr == wild_prefix && wildstr[1])
43
      {
44
	wildstr++;
45
        if (str_is_pattern && *str++ != wild_prefix)
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
46
          return(1);
1 by brian
clean slate
47
      }
48
      if (*wildstr++ != *str++)
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
49
        return(1);
1 by brian
clean slate
50
    }
51
    if (! *wildstr )
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
52
      return(*str != 0);
1 by brian
clean slate
53
    if (*wildstr++ == wild_one)
54
    {
55
      if (! *str || (str_is_pattern && *str == wild_many))
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
56
        return(1);                     /* One char; skip */
1 by brian
clean slate
57
      if (*str++ == wild_prefix && str_is_pattern && *str)
58
        str++;
59
    }
60
    else
61
    {						/* Found '*' */
62
      while (str_is_pattern && *str == wild_many)
63
        str++;
64
      for (; *wildstr ==  wild_many || *wildstr == wild_one; wildstr++)
65
        if (*wildstr == wild_many)
66
        {
67
          while (str_is_pattern && *str == wild_many)
68
            str++;
69
        }
70
        else
71
        {
72
          if (str_is_pattern && *str == wild_prefix && str[1])
73
            str+=2;
74
          else if (! *str++)
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
75
            return (1);
1 by brian
clean slate
76
        }
77
      if (!*wildstr)
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
78
        return(0);		/* '*' as last char: OK */
1 by brian
clean slate
79
      if ((cmp= *wildstr) == wild_prefix && wildstr[1] && !str_is_pattern)
80
        cmp=wildstr[1];
81
      for (;;str++)
82
      {
83
        while (*str && *str != cmp)
84
          str++;
85
        if (!*str)
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
86
          return (1);
1 by brian
clean slate
87
	if (wild_compare(str,wildstr,str_is_pattern) == 0)
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
88
          return (0);
1 by brian
clean slate
89
      }
90
      /* We will never come here */
91
    }
92
  }
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
93
  return (*str != 0);
1 by brian
clean slate
94
} /* wild_compare */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
95
96
} /* namespace internal */
97
} /* namespace drizzled */