Changeset 999 for trunk/dll/literal.c


Ignore:
Timestamp:
Mar 15, 2008, 7:34:05 PM (18 years ago)
Author:
Gregg Young
Message:

Fix from KO Myung-Hun for filename association containing multiple dots reformatted to FM/2 style (Ticket 235)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/literal.c

    r985 r999  
    1818  16 Nov 07 SHL Report fixup buffer overflow
    1919  29 Feb 08 GKY Use xfree where appropriate
     20  15 Mar 08 KOMH Fix wildcard for multiple dots
    2021
    2122***********************************************************************/
     
    198199}
    199200
    200 /* Check wildcard match
     201/** Check wildcard match
    201202 * @parm pszBuf Buffer to check
    202203 * @parm pszWildCard wildcard to match
     
    206207
    207208BOOL wildcard(const PSZ pszBuf, const PSZ pszWildCard,
     209              const BOOL fNotFileSpec)
     210{
     211    PSZ fstr = pszBuf;
     212    PSZ fcard = pszWildCard;
     213
     214    while (*fstr && *fcard) {
     215      switch (*fcard) {
     216        case '*' :
     217        {
     218          PSZ fstr1;
     219
     220          // find next non-wild character in wildcard
     221          while (*fcard && ( *fcard == '*' || *fcard == '?'))
     222            fcard++;
     223
     224          // if last char of wildcard is *, it matches
     225          if (!*fcard)
     226            return TRUE;
     227
     228          fstr1 = fstr;
     229          while (*fstr1) {
     230            // skip until partition, match, or eos
     231            while (*fstr1 && toupper( *fstr1 ) != toupper( *fcard ) &&
     232                   (fNotFileSpec || ( *fstr1 != '/' && *fstr1 != '\\')))
     233              fstr1++;
     234
     235            if (!*fstr1 || ( !fNotFileSpec && ( *fstr1 == '/' || *fstr1 == '\\')))
     236              break;
     237
     238            if (wildcard( fstr1, fcard, fNotFileSpec ) == TRUE)
     239              return TRUE;
     240
     241            fstr1++;
     242          }
     243
     244          fstr = fstr1;
     245          break;
     246        }
     247
     248        case '?' :          // character substitution
     249          fcard++;
     250
     251          if (fNotFileSpec || ( *fstr != '.' && *fstr != '/' && *fstr != '\\'))
     252            fstr++;     // skip (match) next character
     253          break;
     254
     255        default :
     256          if (fNotFileSpec || (*fstr  != '/' && *fstr  != '\\') ||
     257              (*fcard != '/' && *fcard != '\\')) {
     258            if (toupper( *fstr ) != toupper( *fcard))
     259              return FALSE;
     260          }
     261
     262          fcard++;
     263          fstr++;
     264          break;
     265      }
     266    }
     267
     268    if (!*fstr) {
     269        // remove trailing * and ?
     270      while (*fcard && ( *fcard == '?' || *fcard == '*'))
     271        fcard++;
     272
     273      if (!fNotFileSpec) {
     274        // remove trailing .
     275        while (*fcard && *fcard == '.')
     276          fcard++;
     277      }
     278    }
     279
     280    return (*fstr == *fcard);
     281}
     282
     283
     284/*BOOL wildcard(const PSZ pszBuf, const PSZ pszWildCard,
    208285              const BOOL fNotFileSpec)
    209286{
     
    237314      }
    238315     switch (*fcard) { //fm2 standard forward search for all other cases
    239       case '?':                                /* character substitution */
     316      case '?':                                // character substitution /
    240317        fcard++;
    241318        if (fNotFileSpec || (*fstr != '.' && *fstr != '/' && *fstr != '\\'))
    242           fstr++;                                /* skip (match) next character */
     319          fstr++;                                // skip (match) next character
    243320        break;
    244321
    245322      case '*':
    246         /* find next non-wild character in wildcard */
     323        // find next non-wild character in wildcard
    247324        while (*fcard && (*fcard == '?' || *fcard == '*'))
    248325          fcard++;
    249         if (!*fcard){                        /* if last char of wildcard is *, it matches */
     326        if (!*fcard){                        // if last char of wildcard is *, it matches
    250327          if (reverse){
    251328            fstr = strrev(pszBuf);
     
    254331          return TRUE;
    255332        }
    256         /* skip until partition, match, or eos */
     333        // skip until partition, match, or eos
    257334        while (*fstr && toupper(*fstr) != toupper(*fcard) &&
    258335               (fNotFileSpec || (*fstr != '\\' &&
    259336                                 *fstr != '/' && *fstr != '.')))
    260337          fstr++;
    261         if (!fNotFileSpec && !*fstr)        /* implicit '.' */
     338        if (!fNotFileSpec && !*fstr)        // implicit '.'
    262339          if (*fcard == '.')
    263340            fcard++;
     
    290367    return wmatch;
    291368  }
    292 }
     369} */
    293370
    294371
Note: See TracChangeset for help on using the changeset viewer.