X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=filebrowser%2Fdir.c;h=ff317e59abd4aebaa4f9ceb9a854cacab07b3f60;hb=4eec2ced245a4f86a63ca03781250cc6c82cddf2;hp=102187e83e8030158261a6de7ec399e716f62c22;hpb=373488935bf19680e26a3b51e617c9586dd438c6;p=xboard.git diff --git a/filebrowser/dir.c b/filebrowser/dir.c index 102187e..ff317e5 100644 --- a/filebrowser/dir.c +++ b/filebrowser/dir.c @@ -25,25 +25,23 @@ */ #include +#include /* for qsort */ +#include "config.h" /* to check for dirent.h */ #ifdef SEL_FILE_IGNORE_CASE #include #endif /* def SEL_FILE_IGNORE_CASE */ -#include "selfile.h" - -#if defined(SVR4) || defined(SYSV) || defined(USG) || defined(__osf__) +#ifdef HAVE_DIRENT_H #include -#else /* defined(SVR4) || defined(SYSV) || defined(USG) */ +#else #include #define dirent direct -#endif /* defined(SVR4) || defined(SYSV) || defined(USG) */ +#endif #include -#if defined(SVR4) || defined(SYSV) || defined(USG) -extern void qsort(); -#endif /* defined(SVR4) || defined(SYSV) || defined(USG) */ +#include "selfile.h" #ifdef SEL_FILE_IGNORE_CASE int @@ -123,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, @@ -144,14 +142,22 @@ SFgetDir(dir) maxChars = len; } result[i].shown = result[i].real; + if(SFpathFlag) { // [HGM] only show directories + 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++; } -#if defined(SVR4) || defined(SYSV) || defined(USG) - qsort((char *) result, (unsigned) i, sizeof(SFEntry), SFcompareEntries); -#else /* defined(SVR4) || defined(SYSV) || defined(USG) */ - qsort((char *) result, i, sizeof(SFEntry), SFcompareEntries); -#endif /* defined(SVR4) || defined(SYSV) || defined(USG) */ + qsort((char *) result, (size_t) i, sizeof(SFEntry), SFcompareEntries); dir->entries = result; dir->nEntries = i;