2 * Copyright 1989 Software Research Associates, Inc., Tokyo, Japan
4 * Permission to use, copy, modify, and distribute this software and its
5 * documentation for any purpose and without fee is hereby granted, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Software Research Associates not be used
9 * in advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. Software Research Associates
11 * makes no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
14 * SOFTWARE RESEARCH ASSOCIATES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
16 * IN NO EVENT SHALL SOFTWARE RESEARCH ASSOCIATES BE LIABLE FOR ANY SPECIAL,
17 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
18 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
19 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
22 * Author: Erik M. van der Poel
23 * Software Research Associates, Inc., Tokyo, Japan
28 #include <stdlib.h> /* for qsort */
29 #include "../config.h" /* to check for dirent.h */
31 #ifdef SEL_FILE_IGNORE_CASE
33 #endif /* def SEL_FILE_IGNORE_CASE */
46 #ifdef SEL_FILE_IGNORE_CASE
48 SFcompareEntries(p, q)
69 return strcmp(p->real, q->real);
83 #else /* def SEL_FILE_IGNORE_CASE */
85 SFcompareEntries(p, q)
89 return strcmp(p->real, q->real);
91 #endif /* def SEL_FILE_IGNORE_CASE */
97 SFEntry *result = NULL;
107 maxChars = strlen(dir->dir) - 1;
121 (void) stat(".", &statBuf);
122 dir->mtime = statBuf.st_mtime;
124 (void) readdir(dirp); /* throw away "." */
127 (void) readdir(dirp); /* throw away ".." */
128 #endif /* ndef S_IFLNK */
130 while (dp = readdir(dirp)) {
133 alloc = 2 * (alloc + 1);
134 result = (SFEntry *) XtRealloc((char *) result,
135 (unsigned) (alloc * sizeof(SFEntry)));
137 result[i].statDone = 0;
140 result[i].real = XtMalloc((unsigned) (len + 2));
141 (void) strcat(strcpy(result[i].real, str), " ");
142 if (len > maxChars) {
145 result[i].shown = result[i].real;
146 if(SFpathFlag) { // [HGM] only show directories
147 if (stat(str, &statBuf) || SFstatChar(&statBuf) != '/') continue;
148 } else if(SFfilterBuffer[0]) { // [HGM] filter on extension
149 char *p = SFfilterBuffer, match, *q;
150 match = !(stat(str, &statBuf) || SFstatChar(&statBuf) != '/');
152 if(q = strchr(p, ' ')) *q = 0;
153 if(strstr(str, p)) match++;
155 } while(q && (p = q+1));
161 qsort((char *) result, (size_t) i, sizeof(SFEntry), SFcompareEntries);
163 dir->entries = result;
165 dir->nChars = maxChars + 1;