/* * call-seq: * File.fnmatch( pattern, path, [flags] ) => (true or false) * File.fnmatch?( pattern, path, [flags] ) => (true or false) * * Returns true if <i>path</i> matches against <i>pattern</i> The * pattern is not a regular expression; instead it follows rules * similar to shell filename globbing. It may contain the following * metacharacters: * * <code>*</code>:: Matches any file. Can be restricted by * other values in the glob. <code>*</code> * will match all files; <code>c*</code> will * match all files beginning with * <code>c</code>; <code>*c</code> will match * all files ending with <code>c</code>; and * <code>*c*</code> will match all files that * have <code>c</code> in them (including at * the beginning or end). Equivalent to * <code>/ .* /x</code> in regexp. * <code>?</code>:: Matches any one character. Equivalent to * <code>/.{1}/</code> in regexp. * <code>[set]</code>:: Matches any one character in +set+. * Behaves exactly like character sets in * Regexp, including set negation * (<code>[^a-z]</code>). * <code>\</code>:: Escapes the next metacharacter. * * <i>flags</i> is a bitwise OR of the <code>FNM_xxx</code> * parameters. The same glob pattern and flags are used by * <code>Dir::glob</code>. * * File.fnmatch('cat', 'cat') #=> true * File.fnmatch('cat', 'category') #=> false * File.fnmatch('c{at,ub}s', 'cats') #=> false * File.fnmatch('c{at,ub}s', 'cubs') #=> false * File.fnmatch('c{at,ub}s', 'cat') #=> false * * File.fnmatch('c?t', 'cat') #=> true * File.fnmatch('c\?t', 'cat') #=> false * File.fnmatch('c??t', 'cat') #=> false * File.fnmatch('c*', 'cats') #=> true * File.fnmatch('c/ * FIXME * /t', 'c/a/b/c/t') #=> true * File.fnmatch('c*t', 'cat') #=> true * File.fnmatch('c\at', 'cat') #=> true * File.fnmatch('c\at', 'cat', File::FNM_NOESCAPE) #=> false * File.fnmatch('a?b', 'a/b') #=> true * File.fnmatch('a?b', 'a/b', File::FNM_PATHNAME) #=> false * * File.fnmatch('*', '.profile') #=> false * File.fnmatch('*', '.profile', File::FNM_DOTMATCH) #=> true * File.fnmatch('*', 'dave/.profile') #=> true * File.fnmatch('*', 'dave/.profile', File::FNM_DOTMATCH) #=> true * File.fnmatch('*', 'dave/.profile', File::FNM_PATHNAME) #=> false * File.fnmatch('* / FIXME *', 'dave/.profile', File::FNM_PATHNAME) #=> false * STRICT = File::FNM_PATHNAME | File::FNM_DOTMATCH * File.fnmatch('* / FIXME *', 'dave/.profile', STRICT) #=> true */ static VALUE file_s_fnmatch(argc, argv, obj) int argc; VALUE *argv; VALUE obj; { VALUE pattern, path; VALUE rflags; int flags; if (rb_scan_args(argc, argv, "21", &pattern, &path, &rflags) == 3) flags = NUM2INT(rflags); else flags = 0; StringValue(pattern); StringValue(path); if (fnmatch(RSTRING(pattern)->ptr, RSTRING(path)->ptr, flags) == 0) return Qtrue; return Qfalse; }