2 Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 /* Functions for finding files with wildcards */
21 The following file-name-test is supported:
22 - "name [[,] name...] ; Matches any of used filenames.
23 Each name can have "*" and/or "?"
25 - [wildspec [,]] !wildspec2 ; File that matches wildspec and not
29 #include "mysys_priv.h"
32 /* Store wildcard-string in a easyer format */
34 WF_PACK
*wf_comp(char * str
)
41 DBUG_ENTER("wf_comp");
43 not_pos
= -1; /* Skip space and '!' in front */
49 while (*++str
== ' ') {};
51 if (*str
== 0) /* Empty == everything */
52 DBUG_RETURN((WF_PACK
*) NULL
);
54 ant
=1; /* Count filespecs */
55 for (pos
=str
; *pos
; pos
++)
56 ant
+= test(*pos
== ' ' || *pos
== ',');
58 if ((ret
= (WF_PACK
*) my_malloc((uint
) ant
*(sizeof(char **)+2)+
59 sizeof(WF_PACK
)+ (uint
) strlen(str
)+1,
62 DBUG_RETURN((WF_PACK
*) NULL
);
63 ret
->wild
= (char **) (ret
+1);
64 buffer
= (char *) (ret
->wild
+ant
);
67 for (pos
=str
; *pos
; str
= pos
)
69 ret
->wild
[ant
++]=buffer
;
70 while (*pos
!= ' ' && *pos
!= ',' && *pos
!= '!' && *pos
)
74 while (*pos
== ' ' || *pos
== ',' || *pos
== '!' )
75 if (*pos
++ == '!' && not_pos
<0)
83 ret
->not_pos
=(uint
) not_pos
;
85 DBUG_PRINT("exit",("antal: %d not_pos: %d",ret
->wilds
,ret
->not_pos
));
90 /* Test if a given filename is matched */
92 int wf_test(register WF_PACK
*wf_pack
, register const char *name
)
96 DBUG_ENTER("wf_test");
98 if (! wf_pack
|| wf_pack
->wilds
== 0)
99 DBUG_RETURN(0); /* Everything goes */
101 not_pos
=wf_pack
->not_pos
;
102 for (i
=0 ; i
< not_pos
; i
++)
103 if (wild_compare(name
,wf_pack
->wild
[i
],0) == 0)
106 DBUG_RETURN(1); /* No-match */
109 /* Test that it isn't in not-list */
111 for (i
=not_pos
; i
< wf_pack
->wilds
; i
++)
112 if (wild_compare(name
,wf_pack
->wild
[i
],0) == 0)
118 /* We need this because program don't know with malloc we used */
120 void wf_end(WF_PACK
*buffer
)
122 DBUG_ENTER("wf_end");
124 my_free(buffer
, MYF(0));