{
int notdone;
stringlist_t *current, *previous, *temp2, *temp3, *temp4;
+ // exit early if there's nothing to sort
+ if (start == NULL || start->next == NULL)
+ return start;
notdone = 1;
while (notdone)
{
{
char pattern[4096], *c;
struct _finddata_t n_file;
- long hFile;
+ long hFile;
stringlist_t *start, *current;
strlcpy (pattern, path, sizeof (pattern));
- strlcat (pattern, "\\*", sizeof (pattern));
+ strlcat (pattern, "*", sizeof (pattern));
// ask for the directory listing handle
hFile = _findfirst(pattern, &n_file);
- if(hFile != -1)
- {
- // start a new chain with the the first name
- start = current = stringlistappend(NULL, n_file.name);
- // iterate through the directory
- while (_findnext(hFile, &n_file) == 0)
- current = stringlistappend(current, n_file.name);
- _findclose(hFile);
+ if(hFile == -1)
+ return NULL;
+ // start a new chain with the the first name
+ start = current = stringlistappend(NULL, n_file.name);
+ // iterate through the directory
+ while (_findnext(hFile, &n_file) == 0)
+ current = stringlistappend(current, n_file.name);
+ _findclose(hFile);
- // convert names to lowercase because windows does not care, but pattern matching code often does
- for (current = start;current;current = current->next)
- for (c = current->text;*c;c++)
- if (*c >= 'A' && *c <= 'Z')
- *c += 'a' - 'A';
+ // convert names to lowercase because windows does not care, but pattern matching code often does
+ for (current = start;current;current = current->next)
+ for (c = current->text;*c;c++)
+ if (*c >= 'A' && *c <= 'Z')
+ *c += 'a' - 'A';
- // sort the list alphanumerically
- start = stringlistsort(start);
- return start;
- }
- else
- return NULL;
+ // sort the list alphanumerically
+ return stringlistsort(start);
}
#else
#include <dirent.h>
dir = opendir(path);
if (!dir)
return NULL;
- ent = readdir(dir);
- if (!ent)
+ start = current = NULL;
+ while ((ent = readdir(dir)))
{
- closedir(dir);
- return NULL;
+ if (strcmp(ent->d_name, ".") && strcmp(ent->d_name, ".."))
+ {
+ current = stringlistappend(current, ent->d_name);
+ if (!start)
+ start = current;
+ }
}
- start = current = stringlistappend(NULL, ent->d_name);
- while((ent = readdir(dir)))
- current = stringlistappend(current, ent->d_name);
closedir(dir);
// sort the list alphanumerically
return stringlistsort(start);
for (s=fs_searchpaths ; s ; s=s->next)
{
if (s->pack)
- {
Con_Printf("%s (%i files)\n", s->pack->filename, s->pack->numfiles);
- }
else
Con_Printf("%s\n", s->filename);
}
{
if (matchpattern(current->text, "*.pak", true))
{
- dpsnprintf (pakfile, sizeof (pakfile), "%s/%s", dir, current->text);
+ dpsnprintf (pakfile, sizeof (pakfile), "%s%s", dir, current->text);
pak = FS_LoadPackPAK (pakfile);
if (pak)
{
{
if (matchpattern(current->text, "*.pk3", true))
{
- dpsnprintf (pakfile, sizeof (pakfile), "%s/%s", dir, current->text);
+ dpsnprintf (pakfile, sizeof (pakfile), "%s%s", dir, current->text);
pak = FS_LoadPackPK3 (pakfile);
if (pak)
{
#endif
// Add the common game directory
- FS_AddGameDirectory (va("%s/%s", fs_basedir, dir));
+ FS_AddGameDirectory (va("%s/%s/", fs_basedir, dir));
#ifndef WIN32
// Add the personal game directory
homedir = getenv ("HOME");
if (homedir != NULL && homedir[0] != '\0')
- FS_AddGameDirectory (va("%s/.%s/%s", homedir, gameuserdirname, dir));
+ FS_AddGameDirectory (va("%s/.%s/%s/", homedir, gameuserdirname, dir));
#endif
}
else
{
char netpath[MAX_OSPATH];
- dpsnprintf(netpath, sizeof(netpath), "%s/%s", search->filename, name);
+ dpsnprintf(netpath, sizeof(netpath), "%s%s", search->filename, name);
if (FS_SysFileExists (netpath))
{
if (!quiet)
if (pack_ind < 0)
{
char path [MAX_OSPATH];
- dpsnprintf (path, sizeof (path), "%s/%s", search->filename, filename);
+ dpsnprintf (path, sizeof (path), "%s%s", search->filename, filename);
return FS_SysOpen (path, "rb", nonblocking);
}
char real_path [MAX_OSPATH];
// Open the file on disk directly
- dpsnprintf (real_path, sizeof (real_path), "%s/%s", fs_gamedir, filepath);
+ dpsnprintf (real_path, sizeof (real_path), "%s%s", fs_gamedir, filepath);
// Create directories up to the file
FS_CreatePath (real_path);
char netpath[MAX_OSPATH];
char temp[MAX_OSPATH];
- while(!strncmp(pattern, "./", 2))
- pattern += 2;
- while(!strncmp(pattern, ".\\", 2))
- pattern += 2;
+ for (i = 0;pattern[i] == '.' || pattern[i] == ':' || pattern[i] == '/' || pattern[i] == '\\';i++)
+ ;
+
+ if (i > 0)
+ {
+ Con_Printf("Don't use punctuation at the beginning of a search pattern!\n");
+ return NULL;
+ }
search = NULL;
liststart = NULL;
slash = strrchr(pattern, '/');
backslash = strrchr(pattern, '\\');
colon = strrchr(pattern, ':');
- separator = pattern;
- if (separator < slash)
- separator = slash;
- if (separator < backslash)
- separator = backslash;
- if (separator < colon)
- separator = colon;
- basepathlength = separator - pattern;
+ separator = max(slash, backslash);
+ separator = max(separator, colon);
+ basepathlength = separator ? (separator + 1 - pattern) : 0;
basepath = Mem_Alloc (tempmempool, basepathlength + 1);
if (basepathlength)
memcpy(basepath, pattern, basepathlength);
else
{
// get a directory listing and look at each name
- dpsnprintf(netpath, sizeof (netpath), "%s/%s", searchpath->filename, basepath);
+ dpsnprintf(netpath, sizeof (netpath), "%s%s", searchpath->filename, basepath);
if ((dir = listdirectory(netpath)))
{
for (dirfile = dir;dirfile;dirfile = dirfile->next)
{
- dpsnprintf(temp, sizeof(temp), "%s/%s", basepath, dirfile->text);
+ dpsnprintf(temp, sizeof(temp), "%s%s", basepath, dirfile->text);
if (matchpattern(temp, (char *)pattern, true))
{
for (listtemp = liststart;listtemp;listtemp = listtemp->next)