guts of pmatch(), pmatchi(), and pmatchz(); match a string against a pattern */
| 102 | /* guts of pmatch(), pmatchi(), and pmatchz(); |
| 103 | match a string against a pattern */ |
| 104 | staticfn boolean |
| 105 | pmatch_internal(const char *patrn, const char *strng, |
| 106 | boolean ci, /* True => case-insensitive, |
| 107 | False => case-sensitive */ |
| 108 | const char *sk) /* set of characters to skip */ |
| 109 | { |
| 110 | char s, p; |
| 111 | /* |
| 112 | * Simple pattern matcher: '*' matches 0 or more characters, '?' matches |
| 113 | * any single character. Returns TRUE if 'strng' matches 'patrn'. |
| 114 | */ |
| 115 | pmatch_top: |
| 116 | if (!sk) { |
| 117 | s = *strng++; |
| 118 | p = *patrn++; /* get next chars and pre-advance */ |
| 119 | } else { |
| 120 | /* fuzzy match variant of pmatch; particular characters are ignored */ |
| 121 | do { |
| 122 | s = *strng++; |
| 123 | } while (strchr(sk, s)); |
| 124 | do { |
| 125 | p = *patrn++; |
| 126 | } while (strchr(sk, p)); |
| 127 | } |
| 128 | if (!p) /* end of pattern */ |
| 129 | return (boolean) (s == '\0'); /* matches iff end of string too */ |
| 130 | else if (p == '*') /* wildcard reached */ |
| 131 | return (boolean) ((!*patrn |
| 132 | || pmatch_internal(patrn, strng - 1, ci, sk)) |
| 133 | ? TRUE |
| 134 | : s ? pmatch_internal(patrn - 1, strng, ci, sk) |
| 135 | : FALSE); |
| 136 | else if ((ci ? lowc(p) != lowc(s) : p != s) /* check single character */ |
| 137 | && (p != '?' || !s)) /* & single-char wildcard */ |
| 138 | return FALSE; /* doesn't match */ |
| 139 | else /* return pmatch_internal(patrn, strng, ci, sk); */ |
| 140 | goto pmatch_top; /* optimize tail recursion */ |
| 141 | } |
| 142 | |
| 143 | /* case-sensitive wildcard match */ |
| 144 | boolean |