Replace {get,clear}filenames and duplicate autoload code in astub.c/game.c.

This additionally fixes leaks that were caused by traversing the file name
list with the 'findfiles' pointer and not clearing them afterwards (even if
there was a handle to the list head via 'findfileshigh').

git-svn-id: https://svn.eduke32.com/eduke32@2557 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-03-28 19:42:32 +00:00
parent 0c5c58cbbb
commit 26d2cf7e01
2 changed files with 7 additions and 148 deletions

View file

@ -201,9 +201,6 @@ static const char *ONOFF_[] = {"OFF","ON"};
# define OURNEWL "\r\n"
#endif
static CACHE1D_FIND_REC *finddirs=NULL, *findfiles=NULL, *finddirshigh=NULL, *findfileshigh=NULL;
static int32_t numdirs=0, numfiles=0;
static int32_t currentlist=0;
static int32_t tsign, mouseaction=0, mouseax=0, mouseay=0;
static int32_t repeatcountx, repeatcounty;
static int32_t infobox=3; // bit0: current window, bit1: mouse pointer, the variable should be renamed
@ -718,32 +715,6 @@ int32_t kopen4loadfrommod(const char *filename, char searchfirst)
return r;
}
static void clearfilenames(void)
{
klistfree(finddirs);
klistfree(findfiles);
finddirs = findfiles = NULL;
numfiles = numdirs = 0;
}
static int32_t getfilenames(const char *path, const char *kind)
{
CACHE1D_FIND_REC *r;
clearfilenames();
finddirs = klistpath(path,"*",CACHE1D_FIND_DIR);
findfiles = klistpath(path,kind,CACHE1D_FIND_FILE);
for (r = finddirs; r; r=r->next) numdirs++;
for (r = findfiles; r; r=r->next) numfiles++;
finddirshigh = finddirs;
findfileshigh = findfiles;
currentlist = 0;
if (findfileshigh) currentlist = 1;
return(0);
}
const char *ExtGetVer(void)
{
return s_buildRev;
@ -8744,7 +8715,6 @@ static int32_t osdcmd_quit(const osdfuncparm_t *parm)
UNREFERENCED_PARAMETER(parm);
ExtUnInit();
// clearfilenames();
uninitengine();
exit(0);
@ -9499,26 +9469,6 @@ enum
T_INCLUDEDEFAULT,
};
static void DoAutoload(const char *fn)
{
static const char *extensions[3] = { "*.grp", "*.zip", "*.pk3" };
int32_t i;
for (i=0; i<3; i++)
{
Bsprintf(tempbuf, "autoload/%s", fn);
getfilenames(tempbuf, extensions[i]);
while (findfiles)
{
Bsprintf(tempbuf, "autoload/%s/%s", fn, findfiles->name);
initprintf("Using group file \"%s\".\n", tempbuf);
initgroupfile(tempbuf);
findfiles = findfiles->next;
}
}
}
int32_t parsegroupfiles(scriptfile *script);
void parsegroupfiles_include(const char *fn, scriptfile *script, char *cmdtokptr)
@ -9577,7 +9527,7 @@ int32_t parsegroupfiles(scriptfile *script)
{
initprintf("Using group file \"%s\".\n",fn);
if (!NoAutoLoad)
DoAutoload(fn);
G_DoAutoload(fn);
}
}
@ -10291,23 +10241,10 @@ int32_t ExtInit(void)
if (!NoAutoLoad)
{
static const char *extensions[3] = { "*.grp", "*.zip", "*.pk3" };
int32_t exti;
for (exti=0; exti<3; exti++)
{
getfilenames("autoload", extensions[exti]);
while (findfiles)
{
Bsprintf(tempbuf,"autoload/%s",findfiles->name);
initprintf("Using group file \"%s\".\n",tempbuf);
initgroupfile(tempbuf);
findfiles = findfiles->next;
}
}
G_LoadGroupsInDir("autoload");
if (i != -1)
DoAutoload(g_grpNamePtr);
G_DoAutoload(g_grpNamePtr);
}
if (getenv("DUKE3DDEF"))
@ -10336,7 +10273,7 @@ int32_t ExtInit(void)
{
initprintf("Using group file \"%s\".\n",CommandGrps->str);
if (!NoAutoLoad)
DoAutoload(CommandGrps->str);
G_DoAutoload(CommandGrps->str);
}
Bfree(CommandGrps->str);

View file

@ -8034,57 +8034,6 @@ static void G_ShowDebugHelp(void)
#endif
}
static CACHE1D_FIND_REC *finddirs=NULL, *findfiles=NULL, *finddirshigh=NULL, *findfileshigh=NULL;
static int32_t numdirs=0, numfiles=0;
static int32_t currentlist=0;
static void clearfilenames(void)
{
klistfree(finddirs);
klistfree(findfiles);
finddirs = findfiles = NULL;
numfiles = numdirs = 0;
}
static int32_t getfilenames(const char *path, char kind[])
{
CACHE1D_FIND_REC *r;
clearfilenames();
finddirs = klistpath(path,"*",CACHE1D_FIND_DIR);
findfiles = klistpath(path,kind,CACHE1D_FIND_FILE);
for (r = finddirs; r; r=r->next) numdirs++;
for (r = findfiles; r; r=r->next) numfiles++;
finddirshigh = finddirs;
findfileshigh = findfiles;
currentlist = 0;
if (findfileshigh) currentlist = 1;
return(0);
}
static char *autoloadmasks[] = { "*.grp", "*.zip", "*.pk3" };
#define NUMAUTOLOADMASKS (int32_t)(sizeof(autoloadmasks)/sizeof(autoloadmasks[0]))
static void G_DoAutoload(const char *fn)
{
int32_t i;
for (i=0; i<NUMAUTOLOADMASKS; i++)
{
Bsprintf(tempbuf,"autoload/%s",fn);
getfilenames(tempbuf,autoloadmasks[i]);
while (findfiles)
{
Bsprintf(tempbuf,"autoload/%s/%s",fn,findfiles->name);
initprintf("Using file \"%s\" as game data.\n",tempbuf);
initgroupfile(tempbuf);
findfiles = findfiles->next;
}
}
}
static char *S_OggifyFilename(char *destname, char *OGGname, const char *origname)
{
if (!origname)
@ -10033,7 +9982,7 @@ int32_t app_main(int32_t argc,const char **argv)
}
// shitcan the old cache directory
#if 0 && defined(USE_OPENGL)
#if 0 && defined(USE_OPENGL) // NOTE: CODE IS STALE, getfilenames() is no longer!
{
struct stat st;
char dir[BMAX_PATH];
@ -10119,41 +10068,14 @@ CLEAN_DIRECTORY:
if (!g_noAutoLoad && !ud.config.NoAutoLoad)
{
int32_t ii;
for (ii=0; ii<NUMAUTOLOADMASKS; ii++)
{
getfilenames("autoload",autoloadmasks[ii]);
while (findfiles)
{
Bsprintf(tempbuf,"autoload/%s",findfiles->name);
initprintf("Using file \"%s\" as game data.\n",tempbuf);
initgroupfile(tempbuf);
findfiles = findfiles->next;
}
}
G_LoadGroupsInDir("autoload");
if (i != -1)
G_DoAutoload(g_grpNamePtr);
}
if (g_modDir[0] != '/')
{
int32_t ii;
for (ii=0; ii<NUMAUTOLOADMASKS; ii++)
{
Bsprintf(tempbuf,"%s/",g_modDir);
getfilenames(tempbuf,autoloadmasks[ii]);
while (findfiles)
{
Bsprintf(tempbuf,"%s/%s",g_modDir,findfiles->name);
initprintf("Using file \"%s\" as game data.\n",tempbuf);
initgroupfile(tempbuf);
findfiles = findfiles->next;
}
}
}
G_LoadGroupsInDir(g_modDir);
if (getenv("DUKE3DDEF"))
{