Changeset 1416 for trunk/dll/literal.c


Ignore:
Timestamp:
Apr 25, 2009, 5:46:39 PM (16 years ago)
Author:
Gregg Young
Message:

The palettes and system clock now work from the config toolbar (Ticket 352); Steven's cleanup of wildcard code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/literal.c

    r1183 r1416  
    1818  16 Nov 07 SHL Report fixup buffer overflow
    1919  15 Mar 08 KOMH Fix wildcard for multiple dots
     20  24 Apr 09 SHL Rework wildcard for clarity
    2021
    2122***********************************************************************/
     
    204205 * @parm pszBuf Buffer to check
    205206 * @parm pszWildCard wildcard to match
    206  * @parm fNotFileSpec TRUE if generic match else filespec match
     207 * @parm fIgnorePathSep TRUE if match ignores path separators
    207208 * @return TRUE if matched else FALSE
     209 * @fixme need to rework to scan from right to left if not ignoring path separators
    208210 */
    209211
    210 BOOL wildcard(const PSZ pszBuf, const PSZ pszWildCard,
    211               const BOOL fNotFileSpec)
     212BOOL wildcard(const PSZ pszBufIn, const PSZ pszWildCardIn,
     213              const BOOL fIgnorePathSep)
    212214{
    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) {
    218220        case '*' :
    219221        {
    220           PSZ fstr1;
     222          PSZ pszLook;
    221223
    222224          // 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)
    228230            return TRUE;
    229231
    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 == '\\')))
    238241              break;
    239242
    240             if (wildcard( fstr1, fcard, fNotFileSpec ) == TRUE)
     243            // Not ignoring path separators, match next path component
     244            if (wildcard(pszLook, pszWild, fIgnorePathSep) == TRUE)
    241245              return TRUE;
    242246
    243             fstr1++;
    244           }
    245 
    246           fstr = fstr1;
     247            pszLook++;
     248          } // while
     249
     250          pszBuf = pszLook;
    247251          break;
    248252        }
    249253
    250254        case '?' :          // character substitution
    251           fcard++;
    252 
    253           if (fNotFileSpec || ( *fstr != '.' && *fstr != '/' && *fstr != '\\'))
    254             fstr++;     // skip (match) next character
     255          pszWild++;
     256
     257          if (fIgnorePathSep || (*pszBuf != '.' && *pszBuf != '/' && *pszBuf != '\\'))
     258            pszBuf++;     // skip (match) next character
    255259          break;
    256260
    257261        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))
    261265              return FALSE;
    262266          }
    263267
    264           fcard++;
    265           fstr++;
     268          pszWild++;
     269          pszBuf++;
    266270          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++;
    267283      }
    268284    }
    269285
    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);
    283287}
    284288
Note: See TracChangeset for help on using the changeset viewer.