mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysys / mf_wfile.c
blob3a6dc1225f86d24d58c2add9f470c89328c218a1
1 /*
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 "?"
24 wild-cards.
25 - [wildspec [,]] !wildspec2 ; File that matches wildspec and not
26 wildspec2.
29 #include "mysys_priv.h"
30 #include <m_string.h>
32 /* Store wildcard-string in a easyer format */
34 WF_PACK *wf_comp(char * str)
36 uint ant;
37 int not_pos;
38 register char * pos;
39 char * buffer;
40 WF_PACK *ret;
41 DBUG_ENTER("wf_comp");
43 not_pos= -1; /* Skip space and '!' in front */
44 while (*str == ' ')
45 str++;
46 if (*str == '!')
48 not_pos=0;
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,
60 MYF(MY_WME)))
61 == 0)
62 DBUG_RETURN((WF_PACK *) NULL);
63 ret->wild= (char **) (ret+1);
64 buffer= (char *) (ret->wild+ant);
66 ant=0;
67 for (pos=str ; *pos ; str= pos)
69 ret->wild[ant++]=buffer;
70 while (*pos != ' ' && *pos != ',' && *pos != '!' && *pos)
71 *buffer++ = *pos++;
73 *buffer++ = '\0';
74 while (*pos == ' ' || *pos == ',' || *pos == '!' )
75 if (*pos++ == '!' && not_pos <0)
76 not_pos=(int) ant;
79 ret->wilds=ant;
80 if (not_pos <0)
81 ret->not_pos=ant;
82 else
83 ret->not_pos=(uint) not_pos;
85 DBUG_PRINT("exit",("antal: %d not_pos: %d",ret->wilds,ret->not_pos));
86 DBUG_RETURN(ret);
87 } /* wf_comp */
90 /* Test if a given filename is matched */
92 int wf_test(register WF_PACK *wf_pack, register const char *name)
94 reg2 uint i;
95 reg3 uint not_pos;
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)
104 goto found;
105 if (i)
106 DBUG_RETURN(1); /* No-match */
108 found:
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)
113 DBUG_RETURN(1);
114 DBUG_RETURN(0);
115 } /* wf_test */
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");
123 if (buffer)
124 my_free(buffer, MYF(0));
125 DBUG_VOID_RETURN;
126 } /* wf_end */