1 /** \file globbing.c */
12 * Please see globbing.h for details.
14 * License: this code is public domain. I make no warranty that it is useful,
15 * correct, harmless, or environmentally safe.
17 * This particular file may be used however you like, including copying it
18 * verbatim into a closed-source project, exploiting it commercially, and
19 * removing any trace of my name from the source (although I hope you won't
20 * do that). I welcome enhancements and corrections to this file, but I do
21 * not require you to send me patches if you make changes. This code has
24 * Unless otherwise stated, the rest of PhysicsFS falls under the zlib license.
25 * Please see LICENSE.txt in the root of the source tree.
27 * \author Ryan C. Gordon.
31 static int matchesPattern(const char *fname, const char *wildcard,
35 const char *fnameptr = fname;
36 const char *wildptr = wildcard;
38 while ((*wildptr) && (*fnameptr))
45 wildptr++; /* skip multiple '*' in a row... */
46 } while (*wildptr == '*');
48 y = (caseSensitive) ? *wildptr : (char) tolower(*wildptr);
52 x = (caseSensitive) ? *fnameptr : (char) tolower(*fnameptr);
72 x = tolower(*fnameptr);
84 while (*wildptr == '*')
87 return(*fnameptr == *wildptr);
88 } /* matchesPattern */
91 char **PHYSFSEXT_enumerateFilesWildcard(const char *dir, const char *wildcard,
94 char **rc = PHYSFS_enumerateFiles(dir);
100 if (matchesPattern(*i, wildcard, caseSensitive))
104 /* FIXME: This counts on physfs's allocation method not changing! */
106 for (j = i; *j != NULL; j++)
112 } /* PHYSFSEXT_enumerateFilesWildcard */
115 #ifdef TEST_PHYSFSEXT_ENUMERATEFILESWILDCARD
116 int main(int argc, char **argv)
124 printf("USAGE: %s <pattern> <caseSen>\n"
125 " where <caseSen> is 1 or 0.\n", argv[0]);
129 if (!PHYSFS_init(argv[0]))
131 fprintf(stderr, "PHYSFS_init(): %s\n", PHYSFS_getLastError());
135 if (!PHYSFS_addToSearchPath(".", 1))
137 fprintf(stderr, "PHYSFS_addToSearchPath(): %s\n", PHYSFS_getLastError());
142 flist = PHYSFSEXT_enumerateFilesWildcard("/", argv[1], atoi(argv[2]));
144 for (i = flist; *i; i++)
149 printf("\n total %d files.\n\n", rc);
151 PHYSFS_freeList(flist);
158 /* end of globbing.c ... */