ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/match.c
(Generate patch)

Comparing ircd-hybrid/trunk/src/match.c (file contents):
Revision 1592 by michael, Sat Oct 27 21:02:32 2012 UTC vs.
Revision 1652 by michael, Tue Nov 13 20:28:53 2012 UTC

# Line 65 | Line 65 | match(const char *mask, const char *name
65      if (!*m)
66      {
67        if (!*n)
68        return 1;
69      if (!ma)
68          return 0;
69 +      if (!ma)
70 +        return 1;
71        for (m--; (m > (const unsigned char *)mask) && (*m == '?'); m--)
72          ;
73        if (*m == '*')
74 <        return 1;
74 >        return 0;
75        m = ma;
76        n = ++na;
77      }
# Line 79 | Line 79 | match(const char *mask, const char *name
79      {
80        while (*m == '*')
81          m++;
82 <      return *m == 0;
82 >      return *m != '\0';
83      }
84  
85      if (ToLower(*m) != ToLower(*n) && *m != '?' && (*m != '#' || !IsDigit(*n)))
86      {
87        if (!ma)
88 <        return 0;
88 >        return 1;
89        m = ma;
90        n = ++na;
91      }
# Line 93 | Line 93 | match(const char *mask, const char *name
93        m++, n++;
94    }
95  
96 <  return 0;
96 >  return 1;
97   }
98  
99   /* match_esc()
# Line 125 | Line 125 | match_esc(const char *mask, const char *
125      if (!*m)
126      {
127        if (!*n)
128        return 1;
129      if (!ma)
128          return 0;
129 +      if (!ma)
130 +        return 1;
131        for (m--; (m > (const unsigned char *)mask) && (*m == '?'); m--)
132          ;
133        if (*m == '*')
134 <        return 1;
134 >        return 0;
135        m = ma;
136        n = ++na;
137      }
# Line 139 | Line 139 | match_esc(const char *mask, const char *
139      {
140        while (*m == '*')
141          m++;
142 <      return *m == 0;
142 >      return *m != '\0';
143      }
144  
145      if (*m != '?' && (*m != '#' || IsDigit(*n)))
146      {
147        if (*m == '\\')
148          if (!*++m)
149 <          return 0;
149 >          return 1;
150        if (ToLower(*m) != ToLower(*n))
151        {
152          if (!ma)
153 <          return 0;
153 >          return 1;
154          m = ma;
155          n = ++na;
156        }
# Line 161 | Line 161 | match_esc(const char *mask, const char *
161        m++, n++;
162    }
163  
164 <  return 0;
164 >  return 1;
165   }
166  
167   /* match_chan()
# Line 179 | Line 179 | match_chan(const char *mask, const char
179      ++name, ++mask;
180    }
181  
182 <  return match_esc(mask, name);
182 >  return match_esc(mask, name) == 0;
183   }
184  
185 < /* collapse()
185 > /*
186 > * collapse()
187 > * Collapse a pattern string into minimal components.
188 > * This particular version is "in place", so that it changes the pattern
189 > * which is to be reduced to a "minimal" size.
190   *
191 < * collapses a string containing multiple *'s.
191 > * (C) Carlo Wood - 6 Oct 1998
192 > * Speedup rewrite by Andrea Cocito, December 1998.
193 > * Note that this new optimized algorithm can *only* work in place.
194   */
189 char *
190 collapse(char *pattern)
191 {
192  char *p = pattern, *po = pattern;
193  char c;
195  
196 <  if (p == NULL)
197 <    return NULL;
198 <
199 <  while ((c = *p++))
200 <  {
201 <    if (c != '*')
201 <      *po++ = c;
202 <    else if (*p != '*')
203 <      *po++ = '*';
204 <  }
205 <
206 <  *po = 0;
207 <
208 <  return pattern;
209 < }
210 <
211 < /* collapse_esc()
212 < *
213 < * The collapse() function with support for escaping characters
196 > /*! \brief Collapse a mask string to remove redundancies.
197 > * Specifically, it replaces a sequence of '*' followed by additional
198 > * '*' or '?' with the same number of '?'s as the input, followed by
199 > * one '*'.  This minimizes useless backtracking when matching later.
200 > * \param mask Mask string to collapse.
201 > * \return Pointer to the start of the string.
202   */
203   char *
204 < collapse_esc(char *pattern)
204 > collapse(char *mask)
205   {
206 <  char *p = pattern, *po = pattern;
207 <  char c;
206 >  int star = 0;
207 >  char *m = mask;
208 >  char *b = NULL;
209  
210 <  if (p == NULL)
222 <    return NULL;
223 <
224 <  while ((c = *p++))
210 >  if (m)
211    {
212 <    if (c != '*')
212 >    do
213      {
214 <      *po++ = c;
215 <      if (c == '\\' && *p)
216 <        *po++ = *p++;
231 <    }
232 <    else if (*p != '*')
233 <      *po++ = '*';
234 <  }
214 >      if ((*m == '*') && ((m[1] == '*') || (m[1] == '?')))
215 >      {
216 >        b = m;
217  
218 <  *po = 0;
218 >        do
219 >        {
220 >          if (*m == '*')
221 >            star = 1;
222 >          else
223 >          {
224 >            if (star && (*m != '?'))
225 >            {
226 >              *b++ = '*';
227 >              star = 0;
228 >            }
229 >
230 >            *b++ = *m;
231 >
232 >            if ((*m == '\\') && ((m[1] == '*') || (m[1] == '?')))
233 >              *b++ = *++m;
234 >          }
235 >        } while (*m++);
236 >
237 >        break;
238 >      }
239 >      else
240 >      {
241 >        if ((*m == '\\') && ((m[1] == '*') || (m[1] == '?')))
242 >          m++;
243 >      }
244 >    } while (*m++);
245 >  }
246  
247 <  return pattern;
247 >  return mask;
248   }
249  
250   /*

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)