Lines Matching full:pattern
51 * Filename pattern matches defined in section 2.13, "Pattern Matching Notation"
59 * number of consecutive slashes within pattern and string will NOT match;
71 * Supports BSD extensions FNM_LEADING_DIR to match pattern to the end of one
81 * state of pattern and string (rewinding pattern and string repeatedly).
104 classmatch(const char *pattern, char test, int foldcase, const char **ep) in classmatch() argument
106 const char * const mismatch = pattern; in classmatch()
112 if (pattern[0] != '[' || pattern[1] != ':') { in classmatch()
116 pattern += 2; in classmatch()
118 if ((colon = strchr(pattern, ':')) == NULL || colon[1] != ']') { in classmatch()
123 len = (size_t)(colon - pattern); in classmatch()
125 if (foldcase && strncmp(pattern, "upper:]", 7) == 0) in classmatch()
126 pattern = "lower:]"; in classmatch()
128 if (!strncmp(pattern, cc->name, len) && cc->name[len] == '\0') { in classmatch()
146 * Both pattern and string are **char to support pointer increment of arbitrary
149 static int fnmatch_ch(const char **pattern, const char **string, int flags) in fnmatch_ch() argument
151 const char * const mismatch = *pattern; in fnmatch_ch()
159 if (**pattern == '[') { in fnmatch_ch()
160 ++*pattern; in fnmatch_ch()
163 negate = (**pattern == '!') || (**pattern == '^'); in fnmatch_ch()
165 ++*pattern; in fnmatch_ch()
167 /* ']' is an ordinary char at the start of the range pattern */ in fnmatch_ch()
168 if (**pattern == ']') in fnmatch_ch()
171 while (**pattern) { in fnmatch_ch()
172 if (**pattern == ']') { in fnmatch_ch()
173 ++*pattern; in fnmatch_ch()
179 if (escape && (**pattern == '\\')) { in fnmatch_ch()
180 ++*pattern; in fnmatch_ch()
183 if (!**pattern) in fnmatch_ch()
188 if (slash && (**pattern == '/')) in fnmatch_ch()
192 switch (classmatch(*pattern, **string, nocase, pattern)) { in fnmatch_ch()
203 if (!**pattern) in fnmatch_ch()
211 if (((*pattern)[1] == '-') && ((*pattern)[2] != ']')) { in fnmatch_ch()
212 startch = *pattern; in fnmatch_ch()
213 *pattern += (escape && ((*pattern)[2] == '\\')) ? 3 : 2; in fnmatch_ch()
216 * NOT a properly balanced [expr] pattern, EOS in fnmatch_ch()
218 * FNM_PATHNAME mode pattern fall out to to the in fnmatch_ch()
221 if (!**pattern || (slash && (**pattern == '/'))) in fnmatch_ch()
225 if ((**string >= *startch) && (**string <= **pattern)) in fnmatch_ch()
230 isupper((unsigned char)**pattern)) && in fnmatch_ch()
234 tolower((unsigned char)**pattern))) in fnmatch_ch()
237 ++*pattern; in fnmatch_ch()
242 if ((**string == **pattern)) in fnmatch_ch()
245 isupper((unsigned char)**pattern)) && in fnmatch_ch()
247 tolower((unsigned char)**pattern))) in fnmatch_ch()
250 ++*pattern; in fnmatch_ch()
253 * NOT a properly balanced [expr] pattern; in fnmatch_ch()
256 *pattern = mismatch; in fnmatch_ch()
258 } else if (**pattern == '?') { in fnmatch_ch()
259 /* Optimize '?' match before unescaping **pattern */ in fnmatch_ch()
264 } else if (escape && (**pattern == '\\') && (*pattern)[1]) { in fnmatch_ch()
265 ++*pattern; in fnmatch_ch()
269 if (**string == **pattern) in fnmatch_ch()
272 isupper((unsigned char)**pattern)) && in fnmatch_ch()
274 tolower((unsigned char)**pattern))) in fnmatch_ch()
278 if (**string == '\0' || **pattern == '\0' || in fnmatch_ch()
279 (slash && ((**string == '/') || (**pattern == '/')))) in fnmatch_ch()
283 ++*pattern; in fnmatch_ch()
289 int fnmatch(const char *pattern, const char *string, int flags) in fnmatch() argument
304 if (*pattern == '*') in fnmatch()
307 while (*pattern && *string) { in fnmatch()
310 * match balanced slashes, starting a new segment pattern. in fnmatch()
312 if (slash && escape && (*pattern == '\\') && (pattern[1] == '/')) in fnmatch()
313 ++pattern; in fnmatch()
314 if (slash && (*pattern == '/') && (*string == '/')) { in fnmatch()
315 ++pattern; in fnmatch()
325 if (*pattern == '.') in fnmatch()
326 ++pattern; in fnmatch()
327 else if (escape && (*pattern == '\\') && (pattern[1] == '.')) in fnmatch()
328 pattern += 2; in fnmatch()
347 * Allow pattern '*' to be consumed even with no remaining in fnmatch()
350 while (*pattern) { in fnmatch()
352 ((string == strendseg) && (*pattern != '*'))) in fnmatch()
355 if (slash && ((*pattern == '/') || in fnmatch()
356 (escape && (*pattern == '\\') && (pattern[1] == '/')))) in fnmatch()
363 for (wild = 0; (*pattern == '*') || (*pattern == '?'); ++pattern) { in fnmatch()
364 if (*pattern == '*') { in fnmatch()
366 } else if (string < strendseg) { /* && (*pattern == '?') */ in fnmatch()
370 else { /* (string >= strendseg) && (*pattern == '?') */ in fnmatch()
377 mismatch = pattern; in fnmatch()
381 * in pattern * excluding '/' (or "\/") and '*'. in fnmatch()
383 for (matchptr = pattern, matchlen = 0; 1; ++matchlen) { in fnmatch()
420 * Skip forward in pattern by a single in fnmatch()
439 /* Incrementally match string against the pattern. */ in fnmatch()
440 while (*pattern && (string < strendseg)) { in fnmatch()
441 /* Success; begin a new wild pattern search. */ in fnmatch()
442 if (*pattern == '*') in fnmatch()
446 (*pattern == '/') || (escape && in fnmatch()
447 (*pattern == '\\') && (pattern[1] == '/')))) in fnmatch()
451 * Compare ch's (the pattern is advanced over in fnmatch()
455 if (!fnmatch_ch(&pattern, &string, flags)) in fnmatch()
462 * pattern. in fnmatch()
470 pattern = mismatch; in fnmatch()
480 if (*pattern && !(slash && ((*pattern == '/') || in fnmatch()
481 (escape && (*pattern == '\\') && (pattern[1] == '/'))))) in fnmatch()
484 if (leading_dir && !*pattern && *string == '/') in fnmatch()
488 /* Where both pattern and string are at EOS, declare success. */ in fnmatch()
489 if (!*string && !*pattern) in fnmatch()
492 /* Pattern didn't match to the end of string. */ in fnmatch()