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 |
/* Functions for finding files with wildcards */
|
|
17 |
||
18 |
/*
|
|
19 |
The following file-name-test is supported:
|
|
20 |
- "name [[,] name...] ; Matches any of used filenames.
|
|
21 |
Each name can have "*" and/or "?"
|
|
22 |
wild-cards.
|
|
23 |
- [wildspec [,]] !wildspec2 ; File that matches wildspec and not
|
|
24 |
wildspec2.
|
|
25 |
*/
|
|
26 |
||
27 |
#include "mysys_priv.h" |
|
28 |
#include <m_string.h> |
|
29 |
||
30 |
/* Store wildcard-string in a easyer format */
|
|
31 |
||
32 |
WF_PACK *wf_comp(char * str) |
|
33 |
{
|
|
34 |
uint ant; |
|
35 |
int not_pos; |
|
36 |
register char * pos; |
|
37 |
char * buffer; |
|
38 |
WF_PACK *ret; |
|
39 |
||
40 |
not_pos= -1; /* Skip space and '!' in front */ |
|
41 |
while (*str == ' ') |
|
42 |
str++; |
|
43 |
if (*str == '!') |
|
44 |
{
|
|
45 |
not_pos=0; |
|
46 |
while (*++str == ' ') {}; |
|
47 |
}
|
|
48 |
if (*str == 0) /* Empty == everything */ |
|
51.3.13
by Jay Pipes
Phase 1 removal of DBUG in mysys |
49 |
return((WF_PACK *) NULL); |
1
by brian
clean slate |
50 |
|
51 |
ant=1; /* Count filespecs */ |
|
52 |
for (pos=str ; *pos ; pos++) |
|
53 |
ant+= test(*pos == ' ' || *pos == ','); |
|
54 |
||
55 |
if ((ret= (WF_PACK*) my_malloc((uint) ant*(sizeof(char **)+2)+ |
|
56 |
sizeof(WF_PACK)+ (uint) strlen(str)+1, |
|
57 |
MYF(MY_WME))) |
|
58 |
== 0) |
|
51.3.13
by Jay Pipes
Phase 1 removal of DBUG in mysys |
59 |
return((WF_PACK *) NULL); |
1
by brian
clean slate |
60 |
ret->wild= (char **) (ret+1); |
61 |
buffer= (char *) (ret->wild+ant); |
|
62 |
||
63 |
ant=0; |
|
64 |
for (pos=str ; *pos ; str= pos) |
|
65 |
{
|
|
66 |
ret->wild[ant++]=buffer; |
|
67 |
while (*pos != ' ' && *pos != ',' && *pos != '!' && *pos) |
|
68 |
*buffer++ = *pos++; |
|
69 |
||
70 |
*buffer++ = '\0'; |
|
71 |
while (*pos == ' ' || *pos == ',' || *pos == '!' ) |
|
72 |
if (*pos++ == '!' && not_pos <0) |
|
73 |
not_pos=(int) ant; |
|
74 |
}
|
|
75 |
||
76 |
ret->wilds=ant; |
|
77 |
if (not_pos <0) |
|
78 |
ret->not_pos=ant; |
|
79 |
else
|
|
80 |
ret->not_pos=(uint) not_pos; |
|
81 |
||
51.3.13
by Jay Pipes
Phase 1 removal of DBUG in mysys |
82 |
return(ret); |
1
by brian
clean slate |
83 |
} /* wf_comp */ |
84 |
||
85 |
||
86 |
/* Test if a given filename is matched */
|
|
87 |
||
88 |
int wf_test(register WF_PACK *wf_pack, register const char *name) |
|
89 |
{
|
|
90 |
register uint i; |
|
91 |
register uint not_pos; |
|
92 |
||
93 |
if (! wf_pack || wf_pack->wilds == 0) |
|
51.3.13
by Jay Pipes
Phase 1 removal of DBUG in mysys |
94 |
return(0); /* Everything goes */ |
1
by brian
clean slate |
95 |
|
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) |
|
99 |
goto found; |
|
100 |
if (i) |
|
51.3.13
by Jay Pipes
Phase 1 removal of DBUG in mysys |
101 |
return(1); /* No-match */ |
1
by brian
clean slate |
102 |
|
103 |
found: |
|
104 |
/* Test that it isn't in not-list */
|
|
105 |
||
106 |
for (i=not_pos ; i < wf_pack->wilds; i++) |
|
107 |
if (wild_compare(name,wf_pack->wild[i],0) == 0) |
|
51.3.13
by Jay Pipes
Phase 1 removal of DBUG in mysys |
108 |
return(1); |
109 |
return(0); |
|
1
by brian
clean slate |
110 |
} /* wf_test */ |
111 |
||
112 |
||
113 |
/* We need this because program don't know with malloc we used */
|
|
114 |
||
115 |
void wf_end(WF_PACK *buffer) |
|
116 |
{
|
|
117 |
if (buffer) |
|
118 |
my_free((uchar*) buffer,MYF(0)); |
|
51.3.13
by Jay Pipes
Phase 1 removal of DBUG in mysys |
119 |
return; |
1
by brian
clean slate |
120 |
} /* wf_end */ |