Index: /trunk/dll/filter.c
===================================================================
--- /trunk/dll/filter.c	(revision 1565)
+++ /trunk/dll/filter.c	(revision 1566)
@@ -4,8 +4,8 @@
   $Id$
 
-  Filter mask select dialog
+  Filter mask check and select dialog
 
   Copyright (c) 1993-98 M. Kimes
-  Copyright (c) 2004, 2010 Steven H.Levine
+  Copyright (c) 2004, 2011 Steven H.Levine
 
   01 Aug 04 SHL Rework lstrip/rstrip usage
@@ -20,4 +20,5 @@
   07 Feb 09 GKY Allow user to turn off alert and/or error beeps in settings notebook.
   17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
+  31 May 11 SHL Rework Filter() for speed
 
 ***********************************************************************/
@@ -40,5 +41,5 @@
 #include "errutil.h"			// Dos_Error...
 #include "strutil.h"			// GetPString
-#include "pathutil.h"                   // BldFullPathName
+#include "pathutil.h"			// BldFullPathName
 #include "filter.h"
 #include "select.h"			// SetMask
@@ -68,78 +69,89 @@
 /**
  * Filter callback
+ * @return TRUE if filter condition matched and item will be visible
  */
 
 INT APIENTRY Filter(PMINIRECORDCORE rmini, PVOID arg)
 {
-
-  MASK *mask = (MASK *) arg;
-  PCNRITEM r;
+  MASK *mask = (MASK *)arg;
+  PCNRITEM pci;
   INT x;
-  INT ret = FALSE;
+  INT matched;
   CHAR *file;
 
-  if (mask) {
-    r = (PCNRITEM) rmini;
-    if (!(*(r->pszFileName + 3))
-	|| (mask->fShowDirs && (r->attrFile & FILE_DIRECTORY)))
-      return TRUE;
-    if ((!(mask->attrFile & FILE_HIDDEN) && (r->attrFile & FILE_HIDDEN)) ||
-	(!(mask->attrFile & FILE_SYSTEM) && (r->attrFile & FILE_SYSTEM)) ||
-	(!(mask->attrFile & FILE_READONLY) && (r->attrFile & FILE_READONLY))
-	|| (!(mask->attrFile & FILE_ARCHIVED)
-	    && (r->attrFile & FILE_ARCHIVED))
-	|| (!(mask->attrFile & FILE_DIRECTORY)
-	    && (r->attrFile & FILE_DIRECTORY)))
-      return FALSE;
-    if (((mask->antiattr & FILE_HIDDEN) && !(r->attrFile & FILE_HIDDEN)) ||
-	((mask->antiattr & FILE_SYSTEM) && !(r->attrFile & FILE_SYSTEM)) ||
-	((mask->antiattr & FILE_READONLY) && !(r->attrFile & FILE_READONLY))
-	|| ((mask->antiattr & FILE_ARCHIVED)
-	    && !(r->attrFile & FILE_ARCHIVED))
-	|| ((mask->antiattr & FILE_DIRECTORY)
-	    && !(r->attrFile & FILE_DIRECTORY)))
-        return FALSE;
-    if (*mask->szMask) {
-      file = strrchr(r->pszFileName, '\\');
-      if (!file)
-        file = strrchr(r->pszFileName, ':');
-      if (file)
-        file++;
-      else
-        file = r->pszFileName;
-      if (mask->pszMasks[1]) {
-        for (x = 0; mask->pszMasks[x]; x++) {
-          if (*mask->pszMasks[x]) {
-            if (*mask->pszMasks[x] != '/') {
-              if (wildcard((strchr(mask->pszMasks[x], '\\') ||
-                            strchr(mask->pszMasks[x], ':')) ?
-                           r->pszFileName : file, mask->pszMasks[x], FALSE))
-                ret = TRUE;
-            }
-            else {
-              if (wildcard((strchr(mask->pszMasks[x], '\\') ||
-                            strchr(mask->pszMasks[x], ':')) ?
-                           r->pszFileName : file, mask->pszMasks[x] + 1,
-                           FALSE)) {
-                ret = FALSE;
-                break;
-              }
-            }
-          }
-        }
+  if (!mask)
+    return TRUE;			// No mask data
+
+  pci = (PCNRITEM) rmini;
+  // Always show root directory
+  // 2011-05-31 SHL fixme to know if this is correct
+  if (!(*(pci->pszFileName + 3))
+      || mask->fShowDirs && (pci->attrFile & FILE_DIRECTORY))
+    return TRUE;
+
+  if ((~mask->attrFile & FILE_HIDDEN && pci->attrFile & FILE_HIDDEN) ||
+      (~mask->attrFile & FILE_SYSTEM && pci->attrFile & FILE_SYSTEM) ||
+      (~mask->attrFile & FILE_READONLY && pci->attrFile & FILE_READONLY) ||
+      (~mask->attrFile & FILE_ARCHIVED && pci->attrFile & FILE_ARCHIVED) ||
+      (~mask->attrFile & FILE_DIRECTORY && pci->attrFile & FILE_DIRECTORY))
+    return FALSE;
+
+  if ((mask->antiattr & FILE_HIDDEN && ~pci->attrFile & FILE_HIDDEN) ||
+      (mask->antiattr & FILE_SYSTEM && ~pci->attrFile & FILE_SYSTEM) ||
+      (mask->antiattr & FILE_READONLY && ~pci->attrFile & FILE_READONLY) ||
+      (mask->antiattr & FILE_ARCHIVED && ~pci->attrFile & FILE_ARCHIVED) ||
+      (mask->antiattr & FILE_DIRECTORY && ~pci->attrFile & FILE_DIRECTORY))
+    return FALSE;
+
+  if (!*mask->szMask)
+    return TRUE;			// No masks
+
+  // Have mask string
+  file = strrchr(pci->pszFileName, '\\');
+  if (!file)
+    file = strrchr(pci->pszFileName, ':');
+  if (file)
+    file++;				// Point after drive spec
+  else
+    file = pci->pszFileName;
+
+  if (!mask->pszMasks[1]) {
+    // Just one mask string
+    return wildcard(strchr(mask->szMask, '\\') ||
+		      strchr(mask->szMask, ':') ?
+			pci->pszFileName : file,
+		    mask->szMask,
+		    FALSE);
+  }
+
+  // Have multiple mask strings
+  matched = FALSE;
+  for (x = 0; mask->pszMasks[x]; x++) {
+    if (*mask->pszMasks[x]) {
+      if (*mask->pszMasks[x] != '/') {
+	if (wildcard((strchr(mask->pszMasks[x], '\\') ||
+		      strchr(mask->pszMasks[x], ':')) ?
+		       pci->pszFileName : file,
+		     mask->pszMasks[x],
+		     FALSE))
+	{
+	  matched = TRUE;
+	}
       }
       else {
-        if (wildcard((strchr(mask->szMask, '\\') ||
-                      strchr(mask->szMask, ':')) ?
-                     r->pszFileName : file, mask->szMask, FALSE))
-          ret = TRUE;
-      }
-    }
-    else
-      ret = TRUE;
-  }
-  else
-    ret = TRUE;
-  return ret;
+	// Check for non-match
+	if (wildcard(strchr(mask->pszMasks[x], '\\') ||
+		      strchr(mask->pszMasks[x], ':') ?
+		       pci->pszFileName : file, mask->pszMasks[x] + 1,
+		     FALSE))
+	{
+	  matched = FALSE;
+	  break;
+	}
+      }
+    }
+  } // for
+
+  return matched;
 }
 
@@ -179,5 +191,5 @@
 	}
       }
-    }  //while
+    } //while
     fclose(fp);
   }
@@ -327,33 +339,33 @@
       WinCheckButton(hwnd, MSK_HIDDEN, (mask->attrFile & FILE_HIDDEN) != 0);
       WinCheckButton(hwnd, MSK_READONLY,
-                     (mask->attrFile & FILE_READONLY) != 0);
+		     (mask->attrFile & FILE_READONLY) != 0);
       WinCheckButton(hwnd, MSK_ARCHIVED,
-                     (mask->attrFile & FILE_ARCHIVED) != 0);
+		     (mask->attrFile & FILE_ARCHIVED) != 0);
       WinCheckButton(hwnd, MSK_DIRECTORY,
-                     (mask->attrFile & FILE_DIRECTORY) != 0);
+		     (mask->attrFile & FILE_DIRECTORY) != 0);
       WinCheckButton(hwnd, MSK_MUSTSYSTEM,
-                     (mask->antiattr & FILE_SYSTEM) != 0);
+		     (mask->antiattr & FILE_SYSTEM) != 0);
       WinCheckButton(hwnd, MSK_MUSTHIDDEN,
-                     (mask->antiattr & FILE_HIDDEN) != 0);
+		     (mask->antiattr & FILE_HIDDEN) != 0);
       WinCheckButton(hwnd, MSK_MUSTREADONLY,
-                     (mask->antiattr & FILE_READONLY) != 0);
+		     (mask->antiattr & FILE_READONLY) != 0);
       WinCheckButton(hwnd, MSK_MUSTARCHIVED,
-                     (mask->antiattr & FILE_ARCHIVED) != 0);
+		     (mask->antiattr & FILE_ARCHIVED) != 0);
       WinCheckButton(hwnd, MSK_MUSTDIRECTORY,
-                     (mask->antiattr & FILE_DIRECTORY) != 0);
+		     (mask->antiattr & FILE_DIRECTORY) != 0);
       if (mask->fNoDirs)
-        WinEnableWindow(WinWindowFromID(hwnd, MSK_SHOWDIRS), FALSE);
+	WinEnableWindow(WinWindowFromID(hwnd, MSK_SHOWDIRS), FALSE);
       else
-        WinCheckButton(hwnd, MSK_SHOWDIRS, (mask->fShowDirs != FALSE));
+	WinCheckButton(hwnd, MSK_SHOWDIRS, (mask->fShowDirs != FALSE));
       WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTSYSTEM),
-                      (mask->attrFile & FILE_SYSTEM) != 0);
+		      (mask->attrFile & FILE_SYSTEM) != 0);
       WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTHIDDEN),
-                      (mask->attrFile & FILE_HIDDEN) != 0);
+		      (mask->attrFile & FILE_HIDDEN) != 0);
       WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTARCHIVED),
-                      (mask->attrFile & FILE_ARCHIVED) != 0);
+		      (mask->attrFile & FILE_ARCHIVED) != 0);
       WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTREADONLY),
-                      (mask->attrFile & FILE_READONLY) != 0);
+		      (mask->attrFile & FILE_READONLY) != 0);
       WinEnableWindow(WinWindowFromID(hwnd, MSK_MUSTDIRECTORY),
-                    (mask->attrFile & FILE_DIRECTORY) != 0);
+		    (mask->attrFile & FILE_DIRECTORY) != 0);
     }
     if (*mask->szMask) {
@@ -362,13 +374,13 @@
       strcpy(s, mask->szMask);
       if (!strchr(mask->szMask, '?') && !strchr(mask->szMask, '*')) {
-        p = strrchr(mask->szMask, '.');
-        if (p && *(p + 1)) {
-          *s = '*';
-          strcpy(s + 1, p);
-        }
+	p = strrchr(mask->szMask, '.');
+	if (p && *(p + 1)) {
+	  *s = '*';
+	  strcpy(s + 1, p);
+	}
       }
       WinSetDlgItemText(hwnd, MSK_MASK, s);
       WinSendDlgItemMsg(hwnd, MSK_MASK, EM_SETSEL,
-                        MPFROM2SHORT(0, CCHMAXPATH), MPVOID);
+			MPFROM2SHORT(0, CCHMAXPATH), MPVOID);
       PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
     }
@@ -425,6 +437,6 @@
 			     50,
 			     swpE.cy, hwnd, HWND_TOP, 65535, NULL, NULL)) {
-          Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
-                    PCSZ_WINCREATEWINDOW);
+	  Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
+		    PCSZ_WINCREATEWINDOW);
 	}
 	if (!WinCreateWindow(hwnd,
@@ -437,6 +449,6 @@
 			     swpL.cx - 54,
 			     swpE.cy, hwnd, HWND_TOP, MSK_TEXT, NULL, NULL)) {
-          Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
-                    PCSZ_WINCREATEWINDOW);
+	  Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
+		    PCSZ_WINCREATEWINDOW);
 	}
 	WinSendDlgItemMsg(hwnd,	MSK_TEXT,
@@ -521,5 +533,5 @@
       case LN_SELECT:
 	{
-          sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
+	  sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
 					      MSK_LISTBOX,
 					      LM_QUERYSELECTION,
@@ -584,5 +596,5 @@
 	}
       }
-      /* intentional fallthru */
+      // intentional fallthru
     case MSK_CLEAR:
       WinSetDlgItemText(hwnd, MSK_MASK, NullStr);
@@ -592,5 +604,4 @@
     case DID_OK:
       {
-
 	mask = INSTDATA(hwnd);
 	*s = 0;
@@ -600,33 +611,21 @@
 	if (SHORT1FROMMP(mp1) == DID_OK) {
 	  mask->attrFile =
-	    (WinQueryButtonCheckstate(hwnd, MSK_SYSTEM) *
-	     FILE_SYSTEM) | (WinQueryButtonCheckstate(hwnd,
-						      MSK_HIDDEN) *
-			     FILE_HIDDEN) | (WinQueryButtonCheckstate(hwnd,
-								      MSK_READONLY)
-					     *
-					     FILE_READONLY) |
-	    (WinQueryButtonCheckstate(hwnd, MSK_ARCHIVED) *
-	     FILE_ARCHIVED) | (WinQueryButtonCheckstate(hwnd,
-							MSK_DIRECTORY) *
-			       FILE_DIRECTORY);
+	    (WinQueryButtonCheckstate(hwnd, MSK_SYSTEM) * FILE_SYSTEM) |
+	    (WinQueryButtonCheckstate(hwnd, MSK_HIDDEN) * FILE_HIDDEN) |
+	    (WinQueryButtonCheckstate(hwnd, MSK_READONLY) * FILE_READONLY) |
+	    (WinQueryButtonCheckstate(hwnd, MSK_ARCHIVED) * FILE_ARCHIVED) |
+	    (WinQueryButtonCheckstate(hwnd, MSK_DIRECTORY) * FILE_DIRECTORY);
 	  mask->antiattr =
-	    (WinQueryButtonCheckstate(hwnd, MSK_MUSTSYSTEM) *
-	     FILE_SYSTEM) | (WinQueryButtonCheckstate(hwnd,
-						      MSK_MUSTHIDDEN) *
-			     FILE_HIDDEN) | (WinQueryButtonCheckstate(hwnd,
-								      MSK_MUSTREADONLY)
-					     *
-					     FILE_READONLY) |
-	    (WinQueryButtonCheckstate(hwnd, MSK_MUSTARCHIVED) *
-	     FILE_ARCHIVED) | (WinQueryButtonCheckstate(hwnd,
-							MSK_MUSTDIRECTORY) *
-			       FILE_DIRECTORY);
-	  mask->fShowDirs =
-	    (WinQueryButtonCheckstate(hwnd, MSK_SHOWDIRS) != FALSE);
+	    (WinQueryButtonCheckstate(hwnd, MSK_MUSTSYSTEM) * FILE_SYSTEM) |
+	    (WinQueryButtonCheckstate(hwnd, MSK_MUSTHIDDEN) * FILE_HIDDEN) |
+	    (WinQueryButtonCheckstate(hwnd, MSK_MUSTREADONLY) *	FILE_READONLY) |
+	    (WinQueryButtonCheckstate(hwnd, MSK_MUSTARCHIVED) *	FILE_ARCHIVED) |
+	    (WinQueryButtonCheckstate(hwnd, MSK_MUSTDIRECTORY) * FILE_DIRECTORY);
+	  mask->fShowDirs = WinQueryButtonCheckstate(hwnd, MSK_SHOWDIRS) != FALSE;
 	  if (mask->fText)
 	    WinQueryDlgItemText(hwnd, MSK_TEXT, 256, mask->szText);
 	}
 	if (*s) {
+	  // Got mask string
 	  if (SHORT1FROMMP(mp1) == DID_OK) {
 	    strcpy(mask->szMask, s);
@@ -636,6 +635,6 @@
 	    WinDismissDlg(hwnd, 1);
 	  }
-          else {
-            // MSK_DELETE
+	  else {
+	    // MSK_DELETE
 	    WinSetDlgItemText(hwnd, MSK_MASK, NullStr);
 	    remove_mask(s);
@@ -649,4 +648,5 @@
 	}
 	else {
+	  // No mask string
 	  if (SHORT1FROMMP(mp1) == DID_OK) {
 	    *mask->szMask = 0;
@@ -655,5 +655,5 @@
 	  }
 	  else if (!fAlertBeepOff)
-	    DosBeep(50, 100);		// MSK_DELETE
+	    DosBeep(50, 100);		// MSK_DELETE not allowed here
 	}
       }
