| 1 |
#include <string.h> |
| 2 |
#include "filematch.h" |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
int matchpattern( const char *in, const char *pattern, int caseinsensitive ){ |
| 7 |
return matchpattern_with_separator( in, pattern, caseinsensitive, "/\\:", 0 ); |
| 8 |
} |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
int matchpattern_with_separator( const char *in, const char *pattern, int caseinsensitive, const char *separators, int wildcard_least_one ){ |
| 13 |
int c1, c2; |
| 14 |
while ( *pattern ) |
| 15 |
{ |
| 16 |
switch ( *pattern ) |
| 17 |
{ |
| 18 |
case 0: |
| 19 |
return 1; |
| 20 |
case '?': |
| 21 |
if ( *in == 0 || strchr( separators, *in ) ) { |
| 22 |
return 0; |
| 23 |
} |
| 24 |
in++; |
| 25 |
pattern++; |
| 26 |
break; |
| 27 |
case '*': |
| 28 |
if ( wildcard_least_one ) { |
| 29 |
if ( *in == 0 || strchr( separators, *in ) ) { |
| 30 |
return 0; |
| 31 |
} |
| 32 |
in++; |
| 33 |
} |
| 34 |
pattern++; |
| 35 |
while ( *in ) |
| 36 |
{ |
| 37 |
if ( strchr( separators, *in ) ) { |
| 38 |
break; |
| 39 |
} |
| 40 |
|
| 41 |
if ( matchpattern_with_separator( in, pattern, caseinsensitive, separators, wildcard_least_one ) ) { |
| 42 |
return 1; |
| 43 |
} |
| 44 |
|
| 45 |
in++; |
| 46 |
} |
| 47 |
break; |
| 48 |
default: |
| 49 |
if ( *in != *pattern ) { |
| 50 |
if ( !caseinsensitive ) { |
| 51 |
return 0; |
| 52 |
} |
| 53 |
c1 = *in; |
| 54 |
if ( c1 >= 'A' && c1 <= 'Z' ) { |
| 55 |
c1 += 'a' - 'A'; |
| 56 |
} |
| 57 |
c2 = *pattern; |
| 58 |
if ( c2 >= 'A' && c2 <= 'Z' ) { |
| 59 |
c2 += 'a' - 'A'; |
| 60 |
} |
| 61 |
if ( c1 != c2 ) { |
| 62 |
return 0; |
| 63 |
} |
| 64 |
} |
| 65 |
in++; |
| 66 |
pattern++; |
| 67 |
break; |
| 68 |
} |
| 69 |
} |
| 70 |
if ( *in ) { |
| 71 |
return 0; |
| 72 |
} |
| 73 |
return 1; |
| 74 |
} |