2 ** Do shell-style pattern matching for ?, \, [], and * characters.
5 ** Written by Rich $alz, mirror!rs, Wed Nov 26 19:03:17 EST 1986.
6 ** Rich $alz is now <rsalz@bbn.com>.
8 ** Modified by Wayne Davison to special-case '/' matching, to make '**'
9 ** work differently than '*', and to fix the character-class code.
14 /* What character marks an inverted character class? */
15 #define NEGATE_CLASS '!'
20 /* Look for pattern "p" in the "text" string. */
22 wildmatch(const char *p, const char *text)
27 for ( ; (ch = *p) != '\0'; text++, p++) {
28 if (*text == '\0' && ch != '*')
32 /* Literal match with following character. Note that the test
33 * in "default" handles the p[1] == '\0' failure case. */
41 /* Match anything but '/'. */
47 while (*++p == '*') {}
53 /* Trailing "**" matches everything. */
54 return special? true : strchr(text, '/') == 0;
56 for ( ; *text; text++) {
57 if (wildmatch(p, text))
59 if (!special && *text == '/')
64 special = *++p == NEGATE_CLASS ? true : false;
66 /* Inverted character class. */
72 if (ch == ']' || ch == '-') {
78 for ( ; ch != ']'; prev = ch, ch = *++p) {
81 if (ch == '-' && prev && p[1] && p[1] != ']') {
82 if (*text <= *++p && *text >= prev)
84 ch = 0; /* This makes "prev" get set to 0. */
89 if (matched == special)