Lines Matching refs: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).
99 classmatch(const char *pattern, char test, int foldcase, const char **ep)
105 const char * const mismatch = pattern;
107 if (*pattern != '[' || pattern[1] != ':') {
112 pattern += 2;
114 if ((colon = strchr(pattern, ':')) == NULL || colon[1] != ']') {
119 len = (size_t)(colon - pattern);
121 if (foldcase && strncmp(pattern, "upper:]", 7) == 0)
122 pattern = "lower:]";
124 if (!strncmp(pattern, cc->name, len) && cc->name[len] == '\0') {
142 * Both pattern and string are **char to support pointer increment of arbitrary
145 static int fnmatch_ch(const char **pattern, const char **string, int flags)
147 const char * const mismatch = *pattern;
155 if (**pattern == '[')
157 ++*pattern;
160 negate = ((**pattern == '!') || (**pattern == '^'));
162 ++*pattern;
164 /* ']' is an ordinary character at the start of the range pattern */
165 if (**pattern == ']')
168 while (**pattern)
170 if (**pattern == ']') {
171 ++*pattern;
177 if (escape && (**pattern == '\\')) {
178 ++*pattern;
181 if (!**pattern)
186 if (slash && (**pattern == '/'))
190 if (classmatch(*pattern, **string, nocase, pattern)
195 if (!**pattern)
203 if (((*pattern)[1] == '-') && ((*pattern)[2] != ']'))
205 startch = *pattern;
206 *pattern += (escape && ((*pattern)[2] == '\\')) ? 3 : 2;
208 /* NOT a properly balanced [expr] pattern, EOS terminated
209 * or ranges containing a slash in FNM_PATHNAME mode pattern
212 if (!**pattern || (slash && (**pattern == '/')))
216 if ((**string >= *startch) && (**string <= **pattern))
220 isupper((unsigned char)**pattern))
224 tolower((unsigned char)**pattern)))
227 ++*pattern;
232 if ((**string == **pattern))
235 isupper((unsigned char)**pattern))
237 tolower((unsigned char)**pattern)))
240 ++*pattern;
243 /* NOT a properly balanced [expr] pattern; Rewind
246 *pattern = mismatch;
249 else if (**pattern == '?') {
250 /* Optimize '?' match before unescaping **pattern */
256 else if (escape && (**pattern == '\\') && (*pattern)[1]) {
257 ++*pattern;
261 if (**string == **pattern)
264 isupper((unsigned char)**pattern))
266 tolower((unsigned char)**pattern)))
271 if (!**string || !**pattern || (slash && ((**string == '/') || (**pattern == '/'))))
275 ++*pattern;
281 int fnmatch(const char *pattern, const char *string, int flags)
298 if (*pattern == '*')
301 while (*pattern && *string)
304 * match balanced slashes, starting a new segment pattern
306 if (slash && escape && (*pattern == '\\') && (pattern[1] == '/'))
307 ++pattern;
308 if (slash && (*pattern == '/') && (*string == '/')) {
309 ++pattern;
318 if (*pattern == '.')
319 ++pattern;
320 else if (escape && (*pattern == '\\') && (pattern[1] == '.'))
321 pattern += 2;
340 /* Allow pattern '*' to be consumed even with no remaining string to match
342 while (*pattern)
345 || ((string == strendseg) && (*pattern != '*')))
348 if (slash && ((*pattern == '/')
349 || (escape && (*pattern == '\\')
350 && (pattern[1] == '/'))))
356 for (wild = 0; ((*pattern == '*') || (*pattern == '?')); ++pattern)
358 if (*pattern == '*') {
361 else if (string < strendseg) { /* && (*pattern == '?') */
365 else { /* (string >= strendseg) && (*pattern == '?') */
373 mismatch = pattern;
375 /* Count fixed (non '*') char matches remaining in pattern
378 for (matchptr = pattern, matchlen = 0; 1; ++matchlen)
410 /* Skip forward in pattern by a single character match
427 /* Incrementally match string against the pattern
429 while (*pattern && (string < strendseg))
431 /* Success; begin a new wild pattern search
433 if (*pattern == '*')
437 || (*pattern == '/')
438 || (escape && (*pattern == '\\')
439 && (pattern[1] == '/'))))
442 /* Compare ch's (the pattern is advanced over "\/" to the '/',
445 if (!fnmatch_ch(&pattern, &string, flags))
449 * until not enough string chars remain to match the fixed pattern
457 pattern = mismatch;
468 if (*pattern && !(slash && ((*pattern == '/')
469 || (escape && (*pattern == '\\')
470 && (pattern[1] == '/')))))
473 if (leading_dir && !*pattern && *string == '/')
477 /* Where both pattern and string are at EOS, declare success
479 if (!*string && !*pattern)
482 /* pattern didn't match to the end of string */