Changeset 834


Ignore:
Timestamp:
Sep 12, 2007, 9:20:07 PM (18 years ago)
Author:
Gregg Young
Message:

Improved file filtering logic to match last extention for file associations (types) (reverse character by character matching) and optionally search for complete strings within a file name (strstr matching).

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/HISTORY

    r824 r834  
    11New stuff's at the top.  This list is not necessarily complete.
    22
    3 3.07 (pending)
     33.08 (pending)
     4 o Rework filemask logic to match last extension and allow for string matching (Gregg)
     5
     63.07
    47 o Tweak build process (Steven)
    58 o Rework internals to increase file and directory limits (Steven, Gregg)
  • trunk/README

    r811 r834  
    66 ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    77
    8 FM/2 3.07 has had changes made to its ini file structure.
     8FM/2 3.08 has had changes to its file filtering logic.
     9It now searches for the last extension if a mask like *.zip
     10is used. This change was made to over come the problem with
     11associations failing on files with multiple ".". You can
     12also seach for a complete string within the file names by
     13using the pattern *stuff* (stuff can't contain an * or ?).
     14If "stuff" contains an * or ? the old method of searching
     15(character by character)is used.
     16
     17FM/2 3.07 had changes made to its ini file structure.
    918These changes mean that the ini file is not backward
    1019compatible. Please backup you FM3.INI file before installing
  • trunk/dll/assoc.c

    r832 r834  
    361361      }
    362362      else
    363           exclude = FALSE;
    364       if ((*p == '*') &&
    365           !((p[strlen(p) - 1]) == '*'))
     363        exclude = FALSE;
    366364        didmatch = wildcard((strchr(p, '\\') ||
    367                              strchr(p, ':')) ? datafile : file, p, FALSE);
    368       else
    369         didmatch = wildcard2((strchr(p, '\\') ||
    370365                             strchr(p, ':')) ? datafile : file, p, FALSE);
    371366      if (exclude && didmatch)
  • trunk/dll/filter.c

    r832 r834  
    7575        return FALSE;
    7676    if (*mask->szMask) {
    77       if ((*mask->szMask == '*') &&
    78           !((mask->szMask[strlen(mask->szMask)-1]) == '*')){
    79         file = strrchr(r->pszFileName, '\\');
    80         if (!file)
    81           file = strrchr(r->pszFileName, ':');
    82         if (file)
    83           file++;
    84         else
    85           file = r->pszFileName;
    86         if (mask->pszMasks[1]) {
    87           for (x = 0; mask->pszMasks[x]; x++) {
    88             if (*mask->pszMasks[x]) {
    89               if (*mask->pszMasks[x] != '/') {
    90                 if (wildcard((strchr(mask->pszMasks[x], '\\') ||
    91                               strchr(mask->pszMasks[x], ':')) ?
    92                              r->pszFileName : file, mask->pszMasks[x], FALSE))
    93                   ret = TRUE;
    94               }
    95               else {
    96                 if (wildcard((strchr(mask->pszMasks[x], '\\') ||
    97                               strchr(mask->pszMasks[x], ':')) ?
    98                              r->pszFileName : file, mask->pszMasks[x] + 1,
    99                              FALSE)) {
    100                   ret = FALSE;
    101                   break;
    102                 }
     77      file = strrchr(r->pszFileName, '\\');
     78      if (!file)
     79        file = strrchr(r->pszFileName, ':');
     80      if (file)
     81        file++;
     82      else
     83        file = r->pszFileName;
     84      if (mask->pszMasks[1]) {
     85        for (x = 0; mask->pszMasks[x]; x++) {
     86          if (*mask->pszMasks[x]) {
     87            if (*mask->pszMasks[x] != '/') {
     88              if (wildcard((strchr(mask->pszMasks[x], '\\') ||
     89                            strchr(mask->pszMasks[x], ':')) ?
     90                           r->pszFileName : file, mask->pszMasks[x], FALSE))
     91                ret = TRUE;
     92            }
     93            else {
     94              if (wildcard((strchr(mask->pszMasks[x], '\\') ||
     95                            strchr(mask->pszMasks[x], ':')) ?
     96                           r->pszFileName : file, mask->pszMasks[x] + 1,
     97                           FALSE)) {
     98                ret = FALSE;
     99                break;
    103100              }
    104101            }
    105102          }
    106103        }
    107         else {
    108           if (wildcard((strchr(mask->szMask, '\\') ||
    109                         strchr(mask->szMask, ':')) ?
    110                        r->pszFileName : file, mask->szMask, FALSE))
    111             ret = TRUE;
    112         }
    113       }
    114       else{
    115       file = strrchr(r->pszFileName, '\\');
    116         if (!file)
    117           file = strrchr(r->pszFileName, ':');
    118         if (file)
    119           file++;
    120         else
    121           file = r->pszFileName;
    122         if (mask->pszMasks[1]) {
    123           for (x = 0; mask->pszMasks[x]; x++) {
    124             if (*mask->pszMasks[x]) {
    125               if (*mask->pszMasks[x] != '/') {
    126                 if (wildcard2((strchr(mask->pszMasks[x], '\\') ||
    127                               strchr(mask->pszMasks[x], ':')) ?
    128                              r->pszFileName : file, mask->pszMasks[x], FALSE))
    129                   ret = TRUE;
    130               }
    131               else {
    132                 if (wildcard2((strchr(mask->pszMasks[x], '\\') ||
    133                               strchr(mask->pszMasks[x], ':')) ?
    134                              r->pszFileName : file, mask->pszMasks[x] + 1,
    135                              FALSE)) {
    136                   ret = FALSE;
    137                   break;
    138                 }
    139               }
    140             }
    141           }
    142         }
    143         else {
    144           if (wildcard2((strchr(mask->szMask, '\\') ||
    145                         strchr(mask->szMask, ':')) ?
    146                        r->pszFileName : file, mask->szMask, FALSE))
    147             ret = TRUE;
    148         }
    149       }
    150   }
     104      }
     105      else {
     106        if (wildcard((strchr(mask->szMask, '\\') ||
     107                      strchr(mask->szMask, ':')) ?
     108                     r->pszFileName : file, mask->szMask, FALSE))
     109          ret = TRUE;
     110      }
     111    }
    151112    else
    152113      ret = TRUE;
  • trunk/dll/fm3dll.h

    r832 r834  
    873873BOOL wildcard(const PSZ pszBuf, const PSZ pszWildCard,
    874874              const BOOL fNotFileSpec);
    875 BOOL wildcard2(const PSZ pszBuf, const PSZ pszWildCard,
    876               const BOOL fNotFileSpec);
     875/*BOOL wildcard2(const PSZ pszBuf, const PSZ pszWildCard,
     876              const BOOL fNotFileSpec);*/
    877877PSZ fixup(const PCH pachInBuf, PSZ pszOutBuf, const UINT cBufBytes,
    878878          const UINT cInBytes);
  • trunk/dll/ipf/filter.ipf

    r268 r834  
    4242until it finds a filename character that matches the non-wild character
    4343following it in the filemask, or a period, slash, backslash or
    44 the end of the filename and/or filemask.
     44the end of the filename and/or filemask. The pattern *stuff* where "stuff"
     45doesn't contain an * or ? will match based on a search for "stuff" in the
     46file name so it will match even is the first letter occurs mutliple times
     47prior to the sring being matched. The pattern *stuff (stuff can contain an
     48* or ?) is search backwards on the assumption that for most situations the
     49final extension is the marker for the file type.
    4550:p.
    46 Therefore, "*.f?o" matches "anything.foo" but not "anything.foe".
     51Therefore, "*.f?o" matches "anything.foo" but not "anything.foe". While read*
     52will fail to match rreadme.txt *read* will result in it being matched. Additionally,
     53*.zip will match any file with the last extension of .zip (ie it will match myfile.zip
     54and myfile.1.zip but not myfile.zip.bak). While *.zip* will match all 3 of the files
     55from the preceeding example.
    4756:p.
    4857Up to 24 masks may be "cascaded" by separation with semicolons.
     
    5564:parml compact tsize=37 break=none.
    5665:pt./*.obj;/*.res;*
    57 :pd.(Show all but *.obj and *.res files)
     66:pd.(Show all but *.obj and *.res files where .obj and .res are the last file extension)
     67:pt./*.obj*;/*.res*;*
     68:pd.(Show all but *.obj and *.res files where .obj and .res are any file extension)
    5869:pt.*.c;*.h
    5970:pd.(Show only C source and header files)
  • trunk/dll/literal.c

    r832 r834  
    204204              const BOOL fNotFileSpec)
    205205{
    206 
    207   const CHAR *fstr = strrev(pszBuf);
    208   PSZ fcard = strrev(pszWildCard);
     206  const CHAR *fstr = pszBuf;
     207  PSZ fcard = pszWildCard;
     208  CHAR *tcard;
    209209  INT wmatch = TRUE;
     210  BOOL reverse = FALSE;
     211
    210212  while (wmatch && *fcard && *fstr) {
    211   switch (*fcard) {
    212     case '?':                                /* character substitution */
    213       fcard++;
    214       if (fNotFileSpec || (*fstr != '.' && *fstr != '/' && *fstr != '\\'))
    215         fstr++;                                /* skip (match) next character */
    216       break;
    217 
    218     case '*':
    219       /* find next non-wild character in wildcard */
    220       while (*fcard && (*fcard == '?' || *fcard == '*'))
    221        fcard++;
    222       if (!*fcard){                        /* if last char of wildcard is *, it matches */
     213    if (*fcard == '*' && fcard[strlen(fcard) - 1] == '*' && !reverse){
     214      tcard  = xstrdup(fcard + 1, __FILE__, __LINE__);
     215      tcard[strlen(tcard) - 1] = 0;
     216      if (!(strchr(tcard, '?')) && !(strchr(tcard, '*'))){
     217        if (strstr(fstr, tcard)){ //strstr match for *stuff* pattern no wildcards in "stuff"
     218          xfree(tcard);
     219          return TRUE;
     220        }
     221        else{
     222          xfree(tcard);
     223          return FALSE;
     224        }
     225      }
     226      xfree(tcard);
     227    }
     228    else   //reverse search for *stuff pattern "stuff" can contain wildcards
     229      if (*fcard == '*' && fcard[strlen(fcard) - 1] != '*'){
    223230        fstr = strrev(pszBuf);
    224231        fcard = strrev(pszWildCard);
    225         return TRUE;
    226       }
    227       /* skip until partition, match, or eos */
    228       while (*fstr && toupper(*fstr) != toupper(*fcard) &&
    229              (fNotFileSpec || (*fstr != '\\' &&
    230                              *fstr != '/' && *fstr != '.')))
     232        reverse = TRUE;
     233      }
     234     switch (*fcard) { //fm2 standard forward search for all other cases
     235      case '?':                                /* character substitution */
     236        fcard++;
     237        if (fNotFileSpec || (*fstr != '.' && *fstr != '/' && *fstr != '\\'))
     238          fstr++;                                /* skip (match) next character */
     239        break;
     240
     241      case '*':
     242        /* find next non-wild character in wildcard */
     243        while (*fcard && (*fcard == '?' || *fcard == '*'))
     244          fcard++;
     245        if (!*fcard){                        /* if last char of wildcard is *, it matches */
     246          if (reverse){
     247            fstr = strrev(pszBuf);
     248            fcard = strrev(pszWildCard);
     249          }
     250          return TRUE;
     251        }
     252        /* skip until partition, match, or eos */
     253        while (*fstr && toupper(*fstr) != toupper(*fcard) &&
     254               (fNotFileSpec || (*fstr != '\\' &&
     255                                 *fstr != '/' && *fstr != '.')))
     256          fstr++;
     257        if (!fNotFileSpec && !*fstr)        /* implicit '.' */
     258          if (*fcard == '.')
     259            fcard++;
     260        break;
     261
     262      default:
     263        if (!fNotFileSpec && ((*fstr == '/' || *fstr == '\\') &&
     264                              (*fcard == '/' || *fcard == '\\')))
     265          wmatch = TRUE;
     266        else
     267          wmatch = (toupper(*fstr) == toupper(*fcard));
    231268        fstr++;
    232       if (!fNotFileSpec && !*fstr)        /* implicit '.' */
    233         if (*fcard == '.')
    234           fcard++;
    235       break;
    236 
    237     default:
    238       if (!fNotFileSpec && ((*fstr == '/' || *fstr == '\\') &&
    239                           (*fcard == '/' || *fcard == '\\')))
    240         wmatch = TRUE;
    241       else
    242         wmatch = (toupper(*fstr) == toupper(*fcard));
    243       fstr++;
    244       fcard++;
    245       break;
     269        fcard++;
     270        break;
     271      }
     272  }  //while
     273
     274  if ((*fcard && *fcard != '*') || *fstr){
     275    if (reverse){
     276      fstr = strrev(pszBuf);
     277      fcard = strrev(pszWildCard);
    246278    }
    247   }
    248   if ((*fcard && *fcard != '*') || *fstr){
    249     fstr = strrev(pszBuf);
    250     fcard = strrev(pszWildCard);
    251279    return 0;
    252280  }
    253   else{
    254     fstr = strrev(pszBuf);
    255     fcard = strrev(pszWildCard);
     281  else {
     282    if (reverse){
     283      fstr = strrev(pszBuf);
     284      fcard = strrev(pszWildCard);
     285    }
    256286    return wmatch;
    257287  }
    258 }
    259 
    260 BOOL wildcard2(const PSZ pszBuf, const PSZ pszWildCard,
    261               const BOOL fNotFileSpec)
    262 {
    263   const CHAR *fstr = pszBuf;
    264   PSZ fcard = pszWildCard;
    265   CHAR tcard[50];
    266   INT wmatch = TRUE;
    267 
    268     while (wmatch && *fcard && *fstr) {
    269       switch (*fcard) {
    270        case '?':                                /* character substitution */
    271          fcard++;
    272          if (fNotFileSpec || (*fstr != '.' && *fstr != '/' && *fstr != '\\'))
    273            fstr++;                                /* skip (match) next character */
    274          break;
    275 
    276        case '*':
    277          /* find next non-wild character in wildcard */
    278          while (*fcard && (*fcard == '?' || *fcard == '*'))
    279            fcard++;
    280          if (!*fcard)                        /* if last char of wildcard is *, it matches */
    281            return TRUE;
    282          /* skip until partition, match, or eos */
    283          while (*fstr && toupper(*fstr) != toupper(*fcard) &&
    284                 (fNotFileSpec || (*fstr != '\\' &&
    285                                   *fstr != '/' && *fstr != '.')))
    286            fstr++;
    287          if (!fNotFileSpec && !*fstr)        /* implicit '.' */
    288            if (*fcard == '.')
    289              fcard++;
    290          break;
    291 
    292        default:
    293          if (!fNotFileSpec && ((*fstr == '/' || *fstr == '\\') &&
    294                                (*fcard == '/' || *fcard == '\\')))
    295            wmatch = TRUE;
    296          else
    297            wmatch = (toupper(*fstr) == toupper(*fcard));
    298          fstr++;
    299          fcard++;
    300          break;
    301        }
    302   }  //while
    303 
    304   if ((*fcard && *fcard != '*') || *fstr)
    305     return 0;
    306   else
    307     return wmatch;
    308288}
    309289
     
    357337}
    358338
    359 #pragma alloc_text(LITERAL,literal,index,fixup,wildcard, wildcard2)
    360 
     339#pragma alloc_text(LITERAL,literal,index,fixup,wildcard)
     340
Note: See TracChangeset for help on using the changeset viewer.