mirror of
https://github.com/ZDoom/raze-gles.git
synced 2025-01-12 19:20:38 +00:00
Factor out different {clear,get}filenames definitions into fnlist_t + functions.
Don't actually replace the instances in the code now. Additions in common.h: - fnlist_t, which combines CACHE1D_FIND_REC *finddirs, *findfiles and int32_t numdirs, numfiles - the FNLIST_INITIALIZER macro, which MUST be used for automatic variables - fnlist_clearnames, fnlist_getnames functions - G_LoadGroupsInDir, G_DoAutoload, two often-occurring uses of these git-svn-id: https://svn.eduke32.com/eduke32@2555 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
d77e388522
commit
a7f6f3bacc
2 changed files with 87 additions and 0 deletions
|
@ -8,6 +8,7 @@
|
||||||
#define EDUKE32_COMMON_H_
|
#define EDUKE32_COMMON_H_
|
||||||
|
|
||||||
#include "scriptfile.h"
|
#include "scriptfile.h"
|
||||||
|
#include "cache1d.h"
|
||||||
|
|
||||||
|
|
||||||
//// TYPES
|
//// TYPES
|
||||||
|
@ -24,6 +25,15 @@ typedef struct
|
||||||
}
|
}
|
||||||
tokenlist;
|
tokenlist;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
CACHE1D_FIND_REC *finddirs, *findfiles;
|
||||||
|
int32_t numdirs, numfiles;
|
||||||
|
}
|
||||||
|
fnlist_t;
|
||||||
|
|
||||||
|
#define FNLIST_INITIALIZER { NULL, NULL, 0, 0 }
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
T_EOF = -2,
|
T_EOF = -2,
|
||||||
|
@ -43,4 +53,11 @@ int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens);
|
||||||
|
|
||||||
int32_t check_file_exist(const char *fn);
|
int32_t check_file_exist(const char *fn);
|
||||||
|
|
||||||
|
void fnlist_clearnames(fnlist_t *fnl);
|
||||||
|
int32_t fnlist_getnames(fnlist_t *fnl, const char *dirname, const char *pattern,
|
||||||
|
int32_t dirflags, int32_t fileflags);
|
||||||
|
|
||||||
|
void G_LoadGroupsInDir(const char *dirname);
|
||||||
|
void G_DoAutoload(const char *dirname);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -97,3 +97,73 @@ int32_t check_file_exist(const char *fn)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//// FILE NAME / DIRECTORY LISTS ////
|
||||||
|
void fnlist_clearnames(fnlist_t *fnl)
|
||||||
|
{
|
||||||
|
klistfree(fnl->finddirs);
|
||||||
|
klistfree(fnl->findfiles);
|
||||||
|
|
||||||
|
fnl->finddirs = fnl->findfiles = NULL;
|
||||||
|
fnl->numfiles = fnl->numdirs = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// dirflags, fileflags:
|
||||||
|
// -1 means "don't get dirs/files",
|
||||||
|
// otherwise ORed to flags for respective klistpath
|
||||||
|
int32_t fnlist_getnames(fnlist_t *fnl, const char *dirname, const char *pattern,
|
||||||
|
int32_t dirflags, int32_t fileflags)
|
||||||
|
{
|
||||||
|
CACHE1D_FIND_REC *r;
|
||||||
|
|
||||||
|
fnlist_clearnames(fnl);
|
||||||
|
|
||||||
|
if (dirflags != -1)
|
||||||
|
fnl->finddirs = klistpath(dirname, "*", CACHE1D_FIND_DIR|dirflags);
|
||||||
|
if (fileflags != -1)
|
||||||
|
fnl->findfiles = klistpath(dirname, pattern, CACHE1D_FIND_FILE|fileflags);
|
||||||
|
|
||||||
|
for (r=fnl->finddirs; r; r=r->next)
|
||||||
|
fnl->numdirs++;
|
||||||
|
for (r=fnl->findfiles; r; r=r->next)
|
||||||
|
fnl->numfiles++;
|
||||||
|
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// loads all group (grp, zip, pk3) files in the given directory
|
||||||
|
void G_LoadGroupsInDir(const char *dirname)
|
||||||
|
{
|
||||||
|
static const char *extensions[3] = { "*.grp", "*.zip", "*.pk3" };
|
||||||
|
|
||||||
|
char buf[BMAX_PATH];
|
||||||
|
int32_t i;
|
||||||
|
|
||||||
|
fnlist_t fnlist = FNLIST_INITIALIZER;
|
||||||
|
|
||||||
|
for (i=0; i<3; i++)
|
||||||
|
{
|
||||||
|
CACHE1D_FIND_REC *rec;
|
||||||
|
|
||||||
|
fnlist_getnames(&fnlist, dirname, extensions[i], -1, 0);
|
||||||
|
|
||||||
|
for (rec=fnlist.findfiles; rec; rec=rec->next)
|
||||||
|
{
|
||||||
|
Bsnprintf(buf, sizeof(buf), "%s/%s", dirname, rec->name);
|
||||||
|
initprintf("Using group file \"%s\".\n", buf);
|
||||||
|
initgroupfile(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
fnlist_clearnames(&fnlist);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void G_DoAutoload(const char *dirname)
|
||||||
|
{
|
||||||
|
char buf[BMAX_PATH];
|
||||||
|
|
||||||
|
Bsnprintf(buf, sizeof(buf), "autoload/%s", dirname);
|
||||||
|
G_LoadGroupsInDir(buf);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue