shellexp - match string against a cruft filter pattern
extern int shellexp(const char *string, const char *pattern);
The shellexp() function is similar to fnmatch(3),
but works with cruft patterns instead of standard glob(7) patterns.
The function returns a true value if string matches the cruft pattern
pattern, and a false value (0) otherwise. Returns -1 in case of
pattern syntax error.
Cruft patterns are similar to glob(7) patterns, but are not
fully compatible. The following special characters are supported:
- ? (a question mark)
- matches exactly one character of string other than a slash.
- *
- matches zero or more characters of string other than a slash.
- /** or /**/
- matches zero or more path components in string. Please note that
you can only use ** when directly following a slash, and
furthermore, only when either directly preceding a slash or at the very
end of pattern. A ** followed by anything other than a slash
makes pattern invalid. A ** following anything else than a
slash reduces it to having the same effect as *.
- [character-class]
- Matches any character between the brackets exactly once. Named character
classes are NOT supported. If the first character of the class is !
or ^, then the meaning is inverted (matches any character NOT
listed between the brackets). If you want to specify a literal closing
bracket in the class, then specify it as the first (or second, if you want
to negate) character after the opening bracket. Also, simple ASCII-order
ranges are supported using a dash character (see examples section).
Any other character matches itself.
- /a/b*/*c
- matches /a/b/xyz.c, as well as /a/bcd/.c, but not
/a/b/c/d.c.
- /a/**/*.c
- matches all of the following: /a/a.c, /a/b/a.c,
/a/b/c/a.c and /a/b/c/d/a.c.
- /a/[0-9][^0-9]*
- matches /a/1abc, but not /a/12bc.
Uses constant-length 1000 byte buffers to hold filenames. Also
uses recursive function calls, which are not very efficient. Does not
validate the pattern before matching, so any pattern errors (unbalanced
brackets or misplaced **) are only reported when and if the matching
algorithm reaches them.
This manual page was written by Marcin Owsiany
<porridge@debian.org>, for the Debian GNU/Linux system (but may be
used by others).