Use ListBox in stead of ComboBox in Match-Options dialog
[xboard.git] / filebrowser / dir.c
index 123d329..ff317e5 100644 (file)
 
 #include <stdio.h>
 #include <stdlib.h> /* for qsort */
-#include "../config.h" /* to check for dirent.h */
+#include "config.h" /* to check for dirent.h */
 
 #ifdef SEL_FILE_IGNORE_CASE
 #include <ctype.h>
 #endif /* def SEL_FILE_IGNORE_CASE */
 
-#include "selfile.h"
-
 #ifdef HAVE_DIRENT_H
 #include <dirent.h>
 #else
@@ -43,6 +41,8 @@
 
 #include <sys/stat.h>
 
+#include "selfile.h"
+
 #ifdef SEL_FILE_IGNORE_CASE
 int
 SFcompareEntries(p, q)
@@ -121,13 +121,13 @@ SFgetDir(dir)
        (void) stat(".", &statBuf);
        dir->mtime = statBuf.st_mtime;
 
-       (void) readdir(dirp);   /* throw away "." */
+       while (dp = readdir(dirp)) {
 
+               struct stat statBuf;
+               if(!strcmp(dp->d_name, ".")) continue; /* Throw away "." */
+               if(!strcmp(dp->d_name, "..")) continue; /* Throw away ".." */
 #ifndef S_IFLNK
-       (void) readdir(dirp);   /* throw away ".." */
 #endif /* ndef S_IFLNK */
-
-       while (dp = readdir(dirp)) {
                if (i >= alloc) {
                        alloc = 2 * (alloc + 1);
                        result = (SFEntry *) XtRealloc((char *) result,
@@ -143,8 +143,16 @@ SFgetDir(dir)
                }
                result[i].shown = result[i].real;
                if(SFpathFlag) { // [HGM] only show directories
-                       struct stat statBuf;
                        if (stat(str, &statBuf) || SFstatChar(&statBuf) != '/') continue;
+               } else if(SFfilterBuffer[0]) { // [HGM] filter on extension
+                   char *p = SFfilterBuffer, match, *q;
+                   match = !(stat(str, &statBuf) || SFstatChar(&statBuf) != '/');
+                   do {
+                       if(q = strchr(p, ' ')) *q = 0;
+                       if(strstr(str, p)) match++;
+                       if(q) *q = ' ';
+                   } while(q && (p = q+1));
+                   if(!match) continue;
                }
                i++;
        }