Changeset 1416 for trunk/dll/literal.c
- Timestamp:
- Apr 25, 2009, 5:46:39 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/literal.c
r1183 r1416 18 18 16 Nov 07 SHL Report fixup buffer overflow 19 19 15 Mar 08 KOMH Fix wildcard for multiple dots 20 24 Apr 09 SHL Rework wildcard for clarity 20 21 21 22 ***********************************************************************/ … … 204 205 * @parm pszBuf Buffer to check 205 206 * @parm pszWildCard wildcard to match 206 * @parm f NotFileSpec TRUE if generic match else filespec match207 * @parm fIgnorePathSep TRUE if match ignores path separators 207 208 * @return TRUE if matched else FALSE 209 * @fixme need to rework to scan from right to left if not ignoring path separators 208 210 */ 209 211 210 BOOL wildcard(const PSZ pszBuf , const PSZ pszWildCard,211 const BOOL fNotFileSpec)212 BOOL wildcard(const PSZ pszBufIn, const PSZ pszWildCardIn, 213 const BOOL fIgnorePathSep) 212 214 { 213 PSZ fstr = pszBuf;214 PSZ fcard = pszWildCard;215 216 while (* fstr && *fcard) {217 switch (* fcard) {215 PSZ pszBuf = pszBufIn; 216 PSZ pszWild = pszWildCardIn; 217 218 while (*pszBuf && *pszWild) { 219 switch (*pszWild) { 218 220 case '*' : 219 221 { 220 PSZ fstr1;222 PSZ pszLook; 221 223 222 224 // find next non-wild character in wildcard 223 while (*fcard && ( *fcard == '*' || *fcard == '?'))224 fcard++;225 226 // if last char of wildcard is *, it matches 227 if (!*fcard)225 while (*pszWild && ( *pszWild == '*' || *pszWild == '?')) 226 pszWild++; 227 228 // if last char of wildcard is *, got match 229 if (!*pszWild) 228 230 return TRUE; 229 231 230 fstr1 = fstr; 231 while (*fstr1) { 232 // skip until partition, match, or eos 233 while (*fstr1 && toupper( *fstr1 ) != toupper( *fcard ) && 234 (fNotFileSpec || ( *fstr1 != '/' && *fstr1 != '\\'))) 235 fstr1++; 236 237 if (!*fstr1 || ( !fNotFileSpec && ( *fstr1 == '/' || *fstr1 == '\\'))) 232 pszLook = pszBuf; 233 while (*pszLook) { 234 // scan until match, eos or path separator (maybe) 235 while (*pszLook && toupper(*pszLook) != toupper(*pszWild) && 236 (fIgnorePathSep || ( *pszLook != '/' && *pszLook != '\\'))) 237 pszLook++; 238 239 // If eos or path separator (maybe), stop scan 240 if (!*pszLook || (!fIgnorePathSep && (*pszLook == '/' || *pszLook == '\\'))) 238 241 break; 239 242 240 if (wildcard( fstr1, fcard, fNotFileSpec ) == TRUE) 243 // Not ignoring path separators, match next path component 244 if (wildcard(pszLook, pszWild, fIgnorePathSep) == TRUE) 241 245 return TRUE; 242 246 243 fstr1++;244 } 245 246 fstr = fstr1;247 pszLook++; 248 } // while 249 250 pszBuf = pszLook; 247 251 break; 248 252 } 249 253 250 254 case '?' : // character substitution 251 fcard++;252 253 if (fNotFileSpec || ( *fstr != '.' && *fstr != '/' && *fstr!= '\\'))254 fstr++; // skip (match) next character255 pszWild++; 256 257 if (fIgnorePathSep || (*pszBuf != '.' && *pszBuf != '/' && *pszBuf != '\\')) 258 pszBuf++; // skip (match) next character 255 259 break; 256 260 257 261 default : 258 if (fNotFileSpec || (*fstr != '/' && *fstr!= '\\') ||259 (*fcard != '/' && *fcard != '\\')) {260 if (toupper( *fstr ) != toupper( *fcard))262 if (fIgnorePathSep || (*pszBuf != '/' && *pszBuf != '\\') || 263 (*pszWild != '/' && *pszWild != '\\')) { 264 if (toupper( *pszBuf ) != toupper( *pszWild)) 261 265 return FALSE; 262 266 } 263 267 264 fcard++;265 fstr++;268 pszWild++; 269 pszBuf++; 266 270 break; 271 } // switch 272 } // while 273 274 if (!*pszBuf) { 275 // Skip trailing * and ? 276 while (*pszWild && (*pszWild == '?' || *pszWild == '*')) 277 pszWild++; 278 279 if (!fIgnorePathSep) { 280 // remove trailing . 281 while (*pszWild && *pszWild == '.') 282 pszWild++; 267 283 } 268 284 } 269 285 270 if (!*fstr) { 271 // remove trailing * and ? 272 while (*fcard && ( *fcard == '?' || *fcard == '*')) 273 fcard++; 274 275 if (!fNotFileSpec) { 276 // remove trailing . 277 while (*fcard && *fcard == '.') 278 fcard++; 279 } 280 } 281 282 return (*fstr == *fcard); 286 return (*pszBuf == *pszWild); 283 287 } 284 288
Note:
See TracChangeset
for help on using the changeset viewer.