~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_wfile.c

  • Committer: Brian Aker
  • Date: 2008-08-09 21:43:24 UTC
  • mfrom: (279.1.4 codestyle)
  • Revision ID: brian@tangent.org-20080809214324-jy2c15bx49naddsf
Merge from Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 <mystrings/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 */
49
 
    return((WF_PACK *) NULL);
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)
59
 
    return((WF_PACK *) NULL);
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
 
 
82
 
  return(ret);
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)
94
 
    return(0);                  /* Everything goes */
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)
101
 
    return(1);                  /* No-match */
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)
108
 
      return(1);
109
 
  return(0);
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));
119
 
  return;
120
 
} /* wf_end */