From 26d2cf7e0179e4b9d42f58391a28a5e23da66854 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Wed, 28 Mar 2012 19:42:32 +0000 Subject: [PATCH] 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 --- polymer/eduke32/source/astub.c | 71 ++-------------------------- polymer/eduke32/source/game.c | 84 ++-------------------------------- 2 files changed, 7 insertions(+), 148 deletions(-) diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index 522205053..34d59f893 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -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); diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index db4f9eee5..ac988b1e5 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -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; iname); - 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; iiname); - 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; iiname); - initprintf("Using file \"%s\" as game data.\n",tempbuf); - initgroupfile(tempbuf); - findfiles = findfiles->next; - } - } - } + G_LoadGroupsInDir(g_modDir); if (getenv("DUKE3DDEF")) {