Match pattern "p" against "text" */
| 97 | |
| 98 | /* Match pattern "p" against "text" */ |
| 99 | static int dowild(const uchar *p, const uchar *text, unsigned int flags) |
| 100 | { |
| 101 | uchar p_ch; |
| 102 | const uchar *pattern = p; |
| 103 | |
| 104 | for ( ; (p_ch = *p) != '\0'; text++, p++) { |
| 105 | int matched, match_slash, negated; |
| 106 | uchar t_ch, prev_ch; |
| 107 | if ((t_ch = *text) == '\0' && p_ch != '*') |
| 108 | return WM_ABORT_ALL; |
| 109 | if ((flags & WM_CASEFOLD) && ISUPPER(t_ch)) |
| 110 | t_ch = tolower(t_ch); |
| 111 | if ((flags & WM_CASEFOLD) && ISUPPER(p_ch)) |
| 112 | p_ch = tolower(p_ch); |
| 113 | switch (p_ch) { |
| 114 | case '\\': |
| 115 | /* Literal match with following character. Note that the test |
| 116 | * in "default" handles the p[1] == '\0' failure case. */ |
| 117 | p_ch = *++p; |
| 118 | /* FALLTHROUGH */ |
| 119 | default: |
| 120 | if (t_ch != p_ch) |
| 121 | return WM_NOMATCH; |
| 122 | continue; |
| 123 | case '?': |
| 124 | /* Match anything but '/'. */ |
| 125 | if ((flags & WM_PATHNAME) && t_ch == '/') |
| 126 | return WM_NOMATCH; |
| 127 | continue; |
| 128 | case '*': |
| 129 | if (*++p == '*') { |
| 130 | const uchar *prev_p = p - 2; |
| 131 | while (*++p == '*') {} |
| 132 | if (!(flags & WM_PATHNAME)) |
| 133 | /* without WM_PATHNAME, '*' == '**' */ |
| 134 | match_slash = 1; |
| 135 | else if ((prev_p < pattern || *prev_p == '/') && |
| 136 | (*p == '\0' || *p == '/' || |
| 137 | (p[0] == '\\' && p[1] == '/'))) { |
| 138 | /* |
| 139 | * Assuming we already match 'foo/' and are at |
| 140 | * <star star slash>, just assume it matches |
| 141 | * nothing and go ahead match the rest of the |
| 142 | * pattern with the remaining string. This |
| 143 | * helps make foo/<*><*>/bar (<> because |
| 144 | * otherwise it breaks C comment syntax) match |
| 145 | * both foo/bar and foo/a/bar. |
| 146 | */ |
| 147 | if (p[0] == '/' && |
| 148 | dowild(p + 1, text, flags) == WM_MATCH) |
| 149 | return WM_MATCH; |
| 150 | match_slash = 1; |
| 151 | } else /* WM_PATHNAME is set */ |
| 152 | match_slash = 0; |
| 153 | } else |
| 154 | /* without WM_PATHNAME, '*' == '**' */ |
| 155 | match_slash = flags & WM_PATHNAME ? 0 : 1; |
| 156 | if (*p == '\0') { |
no outgoing calls
no test coverage detected
searching dependent graphs…