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"
30
/* Store wildcard-string in a easyer format */
32
WF_PACK *wf_comp(char * str)
39
DBUG_ENTER("wf_comp");
41
not_pos= -1; /* Skip space and '!' in front */
47
while (*++str == ' ') {};
49
if (*str == 0) /* Empty == everything */
50
DBUG_RETURN((WF_PACK *) NULL);
52
ant=1; /* Count filespecs */
53
for (pos=str ; *pos ; pos++)
54
ant+= test(*pos == ' ' || *pos == ',');
56
if ((ret= (WF_PACK*) my_malloc((uint) ant*(sizeof(char **)+2)+
57
sizeof(WF_PACK)+ (uint) strlen(str)+1,
60
DBUG_RETURN((WF_PACK *) NULL);
61
ret->wild= (char **) (ret+1);
62
buffer= (char *) (ret->wild+ant);
65
for (pos=str ; *pos ; str= pos)
67
ret->wild[ant++]=buffer;
68
while (*pos != ' ' && *pos != ',' && *pos != '!' && *pos)
72
while (*pos == ' ' || *pos == ',' || *pos == '!' )
73
if (*pos++ == '!' && not_pos <0)
81
ret->not_pos=(uint) not_pos;
83
DBUG_PRINT("exit",("antal: %d not_pos: %d",ret->wilds,ret->not_pos));
88
/* Test if a given filename is matched */
90
int wf_test(register WF_PACK *wf_pack, register const char *name)
93
register uint not_pos;
94
DBUG_ENTER("wf_test");
96
if (! wf_pack || wf_pack->wilds == 0)
97
DBUG_RETURN(0); /* Everything goes */
99
not_pos=wf_pack->not_pos;
100
for (i=0 ; i < not_pos; i++)
101
if (wild_compare(name,wf_pack->wild[i],0) == 0)
104
DBUG_RETURN(1); /* No-match */
107
/* Test that it isn't in not-list */
109
for (i=not_pos ; i < wf_pack->wilds; i++)
110
if (wild_compare(name,wf_pack->wild[i],0) == 0)
116
/* We need this because program don't know with malloc we used */
118
void wf_end(WF_PACK *buffer)
120
DBUG_ENTER("wf_end");
122
my_free((uchar*) buffer,MYF(0));