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
/* Functions for finding files with wildcards */
19
The following file-name-test is supported:
20
- "name [[,] name...] ; Matches any of used filenames.
21
Each name can have "*" and/or "?"
23
- [wildspec [,]] !wildspec2 ; File that matches wildspec and not
27
#include "mysys_priv.h"
28
#include <mystrings/m_string.h>
30
/* Store wildcard-string in a easyer format */
32
WF_PACK *wf_comp(char * str)
40
not_pos= -1; /* Skip space and '!' in front */
46
while (*++str == ' ') {};
48
if (*str == 0) /* Empty == everything */
49
return((WF_PACK *) NULL);
51
ant=1; /* Count filespecs */
52
for (pos=str ; *pos ; pos++)
53
ant+= test(*pos == ' ' || *pos == ',');
55
if ((ret= (WF_PACK*) my_malloc((uint) ant*(sizeof(char **)+2)+
56
sizeof(WF_PACK)+ (uint) strlen(str)+1,
59
return((WF_PACK *) NULL);
60
ret->wild= (char **) (ret+1);
61
buffer= (char *) (ret->wild+ant);
64
for (pos=str ; *pos ; str= pos)
66
ret->wild[ant++]=buffer;
67
while (*pos != ' ' && *pos != ',' && *pos != '!' && *pos)
71
while (*pos == ' ' || *pos == ',' || *pos == '!' )
72
if (*pos++ == '!' && not_pos <0)
80
ret->not_pos=(uint) not_pos;
86
/* Test if a given filename is matched */
88
int wf_test(register WF_PACK *wf_pack, register const char *name)
91
register uint not_pos;
93
if (! wf_pack || wf_pack->wilds == 0)
94
return(0); /* Everything goes */
96
not_pos=wf_pack->not_pos;
97
for (i=0 ; i < not_pos; i++)
98
if (wild_compare(name,wf_pack->wild[i],0) == 0)
101
return(1); /* No-match */
104
/* Test that it isn't in not-list */
106
for (i=not_pos ; i < wf_pack->wilds; i++)
107
if (wild_compare(name,wf_pack->wild[i],0) == 0)
113
/* We need this because program don't know with malloc we used */
115
void wf_end(WF_PACK *buffer)
118
my_free((uchar*) buffer,MYF(0));