Glob-style pattern matching. */
| 46 | |
| 47 | /* Glob-style pattern matching. */ |
| 48 | int stringmatchlen(const char *pattern, int patternLen, |
| 49 | const char *string, int stringLen, int nocase) |
| 50 | { |
| 51 | while(patternLen && stringLen) { |
| 52 | switch(pattern[0]) { |
| 53 | case '*': |
| 54 | while (patternLen && pattern[1] == '*') { |
| 55 | pattern++; |
| 56 | patternLen--; |
| 57 | } |
| 58 | if (patternLen == 1) |
| 59 | return 1; /* match */ |
| 60 | while(stringLen) { |
| 61 | if (stringmatchlen(pattern+1, patternLen-1, |
| 62 | string, stringLen, nocase)) |
| 63 | return 1; /* match */ |
| 64 | string++; |
| 65 | stringLen--; |
| 66 | } |
| 67 | return 0; /* no match */ |
| 68 | break; |
| 69 | case '?': |
| 70 | string++; |
| 71 | stringLen--; |
| 72 | break; |
| 73 | case '[': |
| 74 | { |
| 75 | int not, match; |
| 76 | |
| 77 | pattern++; |
| 78 | patternLen--; |
| 79 | not = pattern[0] == '^'; |
| 80 | if (not) { |
| 81 | pattern++; |
| 82 | patternLen--; |
| 83 | } |
| 84 | match = 0; |
| 85 | while(1) { |
| 86 | if (pattern[0] == '\\' && patternLen >= 2) { |
| 87 | pattern++; |
| 88 | patternLen--; |
| 89 | if (pattern[0] == string[0]) |
| 90 | match = 1; |
| 91 | } else if (pattern[0] == ']') { |
| 92 | break; |
| 93 | } else if (patternLen == 0) { |
| 94 | pattern--; |
| 95 | patternLen++; |
| 96 | break; |
| 97 | } else if (patternLen >= 3 && pattern[1] == '-') { |
| 98 | int start = pattern[0]; |
| 99 | int end = pattern[2]; |
| 100 | int c = string[0]; |
| 101 | if (start > end) { |
| 102 | int t = start; |
| 103 | start = end; |
| 104 | end = t; |
| 105 | } |
no test coverage detected