Skip to content

Commit

Permalink
Get rid of array of static archivers.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Nov 30, 2012
1 parent 2dd99cc commit 4eafb44
Showing 1 changed file with 37 additions and 56 deletions.
93 changes: 37 additions & 56 deletions src/physfs.c
Expand Up @@ -46,52 +46,6 @@ typedef struct __PHYSFS_ERRSTATETYPE__
} ErrState;


/* The various i/o drivers...some of these may not be compiled in. */
extern const PHYSFS_Archiver __PHYSFS_Archiver_ZIP;
extern const PHYSFS_Archiver __PHYSFS_Archiver_LZMA;
extern const PHYSFS_Archiver __PHYSFS_Archiver_GRP;
extern const PHYSFS_Archiver __PHYSFS_Archiver_QPAK;
extern const PHYSFS_Archiver __PHYSFS_Archiver_HOG;
extern const PHYSFS_Archiver __PHYSFS_Archiver_MVL;
extern const PHYSFS_Archiver __PHYSFS_Archiver_WAD;
extern const PHYSFS_Archiver __PHYSFS_Archiver_SLB;
extern const PHYSFS_Archiver __PHYSFS_Archiver_DIR;
extern const PHYSFS_Archiver __PHYSFS_Archiver_ISO9660;

static const PHYSFS_Archiver * const staticArchivers[] =
{
#if PHYSFS_SUPPORTS_ZIP
&__PHYSFS_Archiver_ZIP,
#endif
#if PHYSFS_SUPPORTS_7Z
&__PHYSFS_Archiver_LZMA,
#endif
#if PHYSFS_SUPPORTS_GRP
&__PHYSFS_Archiver_GRP,
#endif
#if PHYSFS_SUPPORTS_QPAK
&__PHYSFS_Archiver_QPAK,
#endif
#if PHYSFS_SUPPORTS_HOG
&__PHYSFS_Archiver_HOG,
#endif
#if PHYSFS_SUPPORTS_MVL
&__PHYSFS_Archiver_MVL,
#endif
#if PHYSFS_SUPPORTS_WAD
&__PHYSFS_Archiver_WAD,
#endif
#if PHYSFS_SUPPORTS_SLB
&__PHYSFS_Archiver_SLB,
#endif
#if PHYSFS_SUPPORTS_ISO9660
&__PHYSFS_Archiver_ISO9660,
#endif
NULL
};



/* General PhysicsFS state ... */
static int initialized = 0;
static ErrState *errorStates = NULL;
Expand Down Expand Up @@ -880,6 +834,7 @@ static DirHandle *openDirectory(PHYSFS_Io *io, const char *d, int forWriting)
if (io == NULL)
{
/* DIR gets first shot (unlike the rest, it doesn't deal with files). */
extern const PHYSFS_Archiver __PHYSFS_Archiver_DIR;
retval = tryOpenDir(io, &__PHYSFS_Archiver_DIR, d, forWriting);
if (retval != NULL)
return retval;
Expand Down Expand Up @@ -1133,16 +1088,42 @@ static int doRegisterArchiver(const PHYSFS_Archiver *_archiver);

static int initStaticArchivers(void)
{
const PHYSFS_Archiver * const *i;

assert(__PHYSFS_ARRAYLEN(staticArchivers) > 0); /* at least a NULL. */
assert(staticArchivers[__PHYSFS_ARRAYLEN(staticArchivers) - 1] == NULL);

for (i = staticArchivers; *i != NULL; i++)
{
if (!doRegisterArchiver(*i))
return 0;
} /* for */
#define REGISTER_STATIC_ARCHIVER(arc) { \
extern const PHYSFS_Archiver __PHYSFS_Archiver_##arc; \
if (!doRegisterArchiver(&__PHYSFS_Archiver_##arc)) { \
return 0; \
} \
}

#if PHYSFS_SUPPORTS_ZIP
REGISTER_STATIC_ARCHIVER(ZIP);
#endif
#if PHYSFS_SUPPORTS_7Z
REGISTER_STATIC_ARCHIVER(LZMA);
#endif
#if PHYSFS_SUPPORTS_GRP
REGISTER_STATIC_ARCHIVER(GRP);
#endif
#if PHYSFS_SUPPORTS_QPAK
REGISTER_STATIC_ARCHIVER(QPAK);
#endif
#if PHYSFS_SUPPORTS_HOG
REGISTER_STATIC_ARCHIVER(HOG);
#endif
#if PHYSFS_SUPPORTS_MVL
REGISTER_STATIC_ARCHIVER(MVL);
#endif
#if PHYSFS_SUPPORTS_WAD
REGISTER_STATIC_ARCHIVER(WAD);
#endif
#if PHYSFS_SUPPORTS_SLB
REGISTER_STATIC_ARCHIVER(SLB);
#endif
#if PHYSFS_SUPPORTS_ISO9660
REGISTER_STATIC_ARCHIVER(ISO9660);
#endif

#undef REGISTER_STATIC_ARCHIVER

return 1;
} /* initStaticArchivers */
Expand Down

0 comments on commit 4eafb44

Please sign in to comment.