mirror of
https://github.com/ZDoom/raze-gles.git
synced 2025-01-12 19:20:38 +00:00
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:
parent
0c5c58cbbb
commit
26d2cf7e01
2 changed files with 7 additions and 148 deletions
|
@ -201,9 +201,6 @@ static const char *ONOFF_[] = {"OFF","ON"};
|
||||||
# define OURNEWL "\r\n"
|
# define OURNEWL "\r\n"
|
||||||
#endif
|
#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 tsign, mouseaction=0, mouseax=0, mouseay=0;
|
||||||
static int32_t repeatcountx, repeatcounty;
|
static int32_t repeatcountx, repeatcounty;
|
||||||
static int32_t infobox=3; // bit0: current window, bit1: mouse pointer, the variable should be renamed
|
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;
|
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)
|
const char *ExtGetVer(void)
|
||||||
{
|
{
|
||||||
return s_buildRev;
|
return s_buildRev;
|
||||||
|
@ -8744,7 +8715,6 @@ static int32_t osdcmd_quit(const osdfuncparm_t *parm)
|
||||||
UNREFERENCED_PARAMETER(parm);
|
UNREFERENCED_PARAMETER(parm);
|
||||||
|
|
||||||
ExtUnInit();
|
ExtUnInit();
|
||||||
// clearfilenames();
|
|
||||||
uninitengine();
|
uninitengine();
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -9499,26 +9469,6 @@ enum
|
||||||
T_INCLUDEDEFAULT,
|
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);
|
int32_t parsegroupfiles(scriptfile *script);
|
||||||
|
|
||||||
void parsegroupfiles_include(const char *fn, scriptfile *script, char *cmdtokptr)
|
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);
|
initprintf("Using group file \"%s\".\n",fn);
|
||||||
if (!NoAutoLoad)
|
if (!NoAutoLoad)
|
||||||
DoAutoload(fn);
|
G_DoAutoload(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10291,23 +10241,10 @@ int32_t ExtInit(void)
|
||||||
|
|
||||||
if (!NoAutoLoad)
|
if (!NoAutoLoad)
|
||||||
{
|
{
|
||||||
static const char *extensions[3] = { "*.grp", "*.zip", "*.pk3" };
|
G_LoadGroupsInDir("autoload");
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i != -1)
|
if (i != -1)
|
||||||
DoAutoload(g_grpNamePtr);
|
G_DoAutoload(g_grpNamePtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getenv("DUKE3DDEF"))
|
if (getenv("DUKE3DDEF"))
|
||||||
|
@ -10336,7 +10273,7 @@ int32_t ExtInit(void)
|
||||||
{
|
{
|
||||||
initprintf("Using group file \"%s\".\n",CommandGrps->str);
|
initprintf("Using group file \"%s\".\n",CommandGrps->str);
|
||||||
if (!NoAutoLoad)
|
if (!NoAutoLoad)
|
||||||
DoAutoload(CommandGrps->str);
|
G_DoAutoload(CommandGrps->str);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bfree(CommandGrps->str);
|
Bfree(CommandGrps->str);
|
||||||
|
|
|
@ -8034,57 +8034,6 @@ static void G_ShowDebugHelp(void)
|
||||||
#endif
|
#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)
|
static char *S_OggifyFilename(char *destname, char *OGGname, const char *origname)
|
||||||
{
|
{
|
||||||
if (!origname)
|
if (!origname)
|
||||||
|
@ -10033,7 +9982,7 @@ int32_t app_main(int32_t argc,const char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// shitcan the old cache directory
|
// 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;
|
struct stat st;
|
||||||
char dir[BMAX_PATH];
|
char dir[BMAX_PATH];
|
||||||
|
@ -10119,41 +10068,14 @@ CLEAN_DIRECTORY:
|
||||||
|
|
||||||
if (!g_noAutoLoad && !ud.config.NoAutoLoad)
|
if (!g_noAutoLoad && !ud.config.NoAutoLoad)
|
||||||
{
|
{
|
||||||
int32_t ii;
|
G_LoadGroupsInDir("autoload");
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i != -1)
|
if (i != -1)
|
||||||
G_DoAutoload(g_grpNamePtr);
|
G_DoAutoload(g_grpNamePtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_modDir[0] != '/')
|
if (g_modDir[0] != '/')
|
||||||
{
|
G_LoadGroupsInDir(g_modDir);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getenv("DUKE3DDEF"))
|
if (getenv("DUKE3DDEF"))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue