return matchpattern_with_separator(in, pattern, caseinsensitive, "/\\:", false);
}
+// wildcard_least_one: if true * matches 1 or more characters
+// if false * matches 0 or more characters
int matchpattern_with_separator(const char *in, const char *pattern, int caseinsensitive, const char *separators, qboolean wildcard_least_one)
{
int c1, c2;
break;
case '*': // match anything until following string
if(wildcard_least_one)
+ {
if (*in == 0 || strchr(separators, *in))
return 0; // no match
- if (!*in)
- return 1; // match
+ in++;
+ }
pattern++;
while (*in)
{
if (strchr(separators, *in))
break;
// see if pattern matches at this offset
- if (matchpattern(in, pattern, caseinsensitive))
+ if (matchpattern_with_separator(in, pattern, caseinsensitive, separators, wildcard_least_one))
return 1;
// nope, advance to next offset
in++;
}
}
#ifdef WIN32
-#include <io.h>
+#include <windows.h>
void listdirectory(stringlist_t *list, const char *basepath, const char *path)
{
int i;
char pattern[4096], *c;
- struct _finddata_t n_file;
- long hFile;
+ WIN32_FIND_DATA n_file;
+ HANDLE hFile;
strlcpy (pattern, basepath, sizeof(pattern));
strlcat (pattern, path, sizeof (pattern));
strlcat (pattern, "*", sizeof (pattern));
// ask for the directory listing handle
- hFile = _findfirst(pattern, &n_file);
- if(hFile == -1)
+ hFile = FindFirstFile(pattern, &n_file);
+ if(hFile == INVALID_HANDLE_VALUE)
return;
do {
- adddirentry(list, path, n_file.name );
- } while (_findnext(hFile, &n_file) == 0);
- _findclose(hFile);
+ adddirentry(list, path, n_file.cFileName);
+ } while (FindNextFile(hFile, &n_file) != 0);
+ FindClose(hFile);
// convert names to lowercase because windows does not care, but pattern matching code often does
for (i = 0;i < list->numstrings;i++)