Example #1
0
bool CmpName(const char* Wildcard, const char* Name, int CmpMode)
{
    bool ForceCase = (CmpMode & MATCH_FORCECASESENSITIVE) != 0;
    CmpMode &= MATCH_MODEMASK;

    if (CmpMode != MATCH_NAMES)
    {
        size_t WildLength = strlen(Wildcard);

        if (CmpMode != MATCH_EXACT && CmpMode != MATCH_EXACTPATH &&
                mstrnicompc(Wildcard, Name, WildLength, ForceCase) == 0)
        {
            // For all modes except MATCH_NAMES, MATCH_EXACT and MATCH_EXACTPATH
            // "path1" mask must match "path1\path2\filename.ext" and "path1" names.
            char NextCh = Name[WildLength];

            if (NextCh == '\\' || NextCh == '/' || NextCh == 0)
                return(true);
        }

        // Nothing more to compare for MATCH_SUBPATHONLY.
        if (CmpMode == MATCH_SUBPATHONLY)
            return(false);

        char Path1[NM], Path2[NM];
        GetFilePath(Wildcard, Path1, ASIZE(Path1));
        GetFilePath(Name, Path2, ASIZE(Path1));

        if ((CmpMode == MATCH_EXACT || CmpMode == MATCH_EXACTPATH) &&
                mstricompc(Path1, Path2, ForceCase) != 0)
            return(false);

        if (CmpMode == MATCH_SUBPATH || CmpMode == MATCH_WILDSUBPATH)
            if (IsWildcard(Path1))
                return(match(Wildcard, Name, ForceCase));

            else if (CmpMode == MATCH_SUBPATH || IsWildcard(Wildcard))
            {
                if (*Path1 && mstrnicompc(Path1, Path2, strlen(Path1), ForceCase) != 0)
                    return(false);
            }

            else if (mstricompc(Path1, Path2, ForceCase) != 0)
                return(false);
    }

    char* Name1 = PointToName(Wildcard);
    char* Name2 = PointToName(Name);

    // Always return false for RAR temporary files to exclude them
    // from archiving operations.
    if (mstrnicompc("__rar_", Name2, 6, false) == 0)
        return(false);

    if (CmpMode == MATCH_EXACT)
        return(mstricompc(Name1, Name2, ForceCase) == 0);

    return(match(Name1, Name2, ForceCase));
}
Example #2
0
bool match(const char *pattern,const char *string,bool ForceCase)
{
  for (;; ++string)
  {
    char stringc=toupperc(*string,ForceCase);
    char patternc=toupperc(*pattern++,ForceCase);
    switch (patternc)
    {
      case 0:
        return(stringc==0);
      case '?':
        if (stringc == 0)
          return(false);
        break;
      case '*':
        if (*pattern==0)
          return(true);
        if (*pattern=='.')
        {
          if (pattern[1]=='*' && pattern[2]==0)
            return(true);
          const char *dot=strchr(string,'.');
          if (pattern[1]==0)
            return (dot==NULL || dot[1]==0);
          if (dot!=NULL)
          {
            string=dot;
            if (strpbrk(pattern,"*?")==NULL && strchr(string+1,'.')==NULL)
              return(mstricompc(pattern+1,string+1,ForceCase)==0);
          }
        }

        while (*string)
          if (match(pattern,string++,ForceCase))
            return(true);
        return(false);
      default:
        if (patternc != stringc)
        {
          // Allow "name." mask match "name" and "name.\" match "name\".
          if (patternc=='.' && (stringc==0 || stringc=='\\' || stringc=='.'))
            return(match(pattern,string,ForceCase));
          else
            return(false);
        }
        break;
    }
  }
}