1 | /* Check wildcard match |
---|
2 | * @parm pszBuf Buffer to check |
---|
3 | * @parm pszWildCard wildcard to match |
---|
4 | * @parm fNotFileSpec TRUE if generic match else filespec match |
---|
5 | * @return TRUE if matched else FALSE |
---|
6 | */ |
---|
7 | |
---|
8 | BOOL wildcard(const PSZ pszBuf, const PSZ pszWildCard, |
---|
9 | const BOOL fNotFileSpec) |
---|
10 | { |
---|
11 | PSZ fstr = pszBuf; |
---|
12 | PSZ fcard = pszWildCard; |
---|
13 | |
---|
14 | while( *fstr && *fcard ) |
---|
15 | { |
---|
16 | switch( *fcard ) |
---|
17 | { |
---|
18 | case '*' : |
---|
19 | { |
---|
20 | PSZ fstr1; |
---|
21 | |
---|
22 | /* find next non-wild character in wildcard */ |
---|
23 | while( *fcard && ( *fcard == '*' || *fcard == '?')) |
---|
24 | fcard++; |
---|
25 | |
---|
26 | /* if last char of wildcard is *, it matches */ |
---|
27 | if( !*fcard ) |
---|
28 | return TRUE; |
---|
29 | |
---|
30 | fstr1 = fstr; |
---|
31 | while( *fstr1 ) |
---|
32 | { |
---|
33 | /* skip until partition, match, or eos */ |
---|
34 | while( *fstr1 && toupper( *fstr1 ) != toupper( *fcard ) && |
---|
35 | ( fNotFileSpec || ( *fstr1 != '/' && *fstr1 != '\\' ))) |
---|
36 | fstr1++; |
---|
37 | |
---|
38 | if( !*fstr1 || ( !fNotFileSpec && ( *fstr1 == '/' || *fstr1 == '\\' ))) |
---|
39 | break; |
---|
40 | |
---|
41 | if( wildcard( fstr1, fcard, fNotFileSpec ) == TRUE ) |
---|
42 | return TRUE; |
---|
43 | |
---|
44 | fstr1++; |
---|
45 | } |
---|
46 | |
---|
47 | fstr = fstr1; |
---|
48 | break; |
---|
49 | } |
---|
50 | |
---|
51 | case '?' : /* character substitution */ |
---|
52 | fcard++; |
---|
53 | |
---|
54 | if( fNotFileSpec || ( *fstr != '.' && *fstr != '/' && *fstr != '\\')) |
---|
55 | fstr++; /* skip (match) next character */ |
---|
56 | break; |
---|
57 | |
---|
58 | default : |
---|
59 | if( fNotFileSpec || |
---|
60 | ( *fstr != '/' && *fstr != '\\') || |
---|
61 | ( *fcard != '/' && *fcard != '\\' )) |
---|
62 | { |
---|
63 | if( toupper( *fstr ) != toupper( *fcard )) |
---|
64 | return FALSE; |
---|
65 | } |
---|
66 | |
---|
67 | fcard++; |
---|
68 | fstr++; |
---|
69 | break; |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | if( !*fstr ) |
---|
74 | { |
---|
75 | /* remove trailing * and ? */ |
---|
76 | while( *fcard && ( *fcard == '?' || *fcard == '*' )) |
---|
77 | fcard++; |
---|
78 | |
---|
79 | if( !fNotFileSpec ) |
---|
80 | { |
---|
81 | /* remove trailing . */ |
---|
82 | while( *fcard && *fcard == '.' ) |
---|
83 | fcard++; |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | return ( *fstr == *fcard ); |
---|
88 | } |
---|
89 | |
---|