Skip to content
Permalink
Browse files
Added callback APIs and ripped up the internals everywhere to use them.
  • Loading branch information
icculus committed Sep 29, 2004
1 parent 80535e9 commit c2765f85719f8a523f73631f08a79d1b0e3fe1ad
Showing with 491 additions and 467 deletions.
  1. +7 −0 CHANGELOG
  2. +0 −2 TODO
  3. +11 −12 archivers/dir.c
  4. +15 −17 archivers/grp.c
  5. +15 −17 archivers/hog.c
  6. +19 −18 archivers/mix.c
  7. +15 −17 archivers/mvl.c
  8. +30 −15 archivers/qpak.c
  9. +15 −21 archivers/wad.c
  10. +30 −15 archivers/zip.c
  11. +157 −46 physfs.c
  12. +16 −0 physfs.h
  13. +21 −15 physfs_internal.h
  14. +9 −25 platform/beos.cpp
  15. +25 −28 platform/macclassic.c
  16. +12 −35 platform/os2.c
  17. +50 −65 platform/pocketpc.c
  18. +9 −8 platform/posix.c
  19. +5 −5 platform/skeleton.c
  20. +14 −72 platform/unix.c
  21. +16 −34 platform/win32.c
@@ -2,6 +2,13 @@
* CHANGELOG.
*/

09292004 - Every API that can return a list of strings can now use a
callback mechanism if the application wants to do it's own
allocation or handling on a per-item basis. The guts of those
APIs that create string lists now use the callbacks themselves to
build the lists, too. The callback functionality goes all the way
down to the archivers and platform drivers where appropriate, which
cleans things up and simplifies some internal tasks very nicely.
09262004 - Did the same thing to FileHandles than I did to DirHandles, but
this triggered massive tweaking in physfs.c. A lot of code got
little cleanups, which was nice. Less malloc pressure, too, since
2 TODO
@@ -22,7 +22,6 @@ Some might be dupes, some might be done already.
- Cygwin should use unix/posix and not win32 platform code.
- Add "mount points"
- Expose the archiver registration mechanism to the outside world.
- Set up a mechanism for file enumeration that employs a callback.
- Allow the application to provide allocation services.
- Find some way to relax or remove the security model for external tools.
- Non-blocking I/O
@@ -41,7 +40,6 @@ Some might be dupes, some might be done already.
- Deprecate PHYSFS_setSaneConfig and move it to extras?
- (Re)move the profiling code in physfs.c.
- Why is physfsrwops.c cut-and-pasted into the ruby bindings?
- Get rid of addToLinkedStringList
- Replace code from SDL...
- MIX grabs all archives that no other archivers claim.
- MIX enumerates files as hash values.
@@ -29,9 +29,9 @@ static PHYSFS_sint64 DIR_fileLength(fvoid *opaque);
static int DIR_fileClose(fvoid *opaque);
static int DIR_isArchive(const char *filename, int forWriting);
static void *DIR_openArchive(const char *name, int forWriting);
static LinkedStringList *DIR_enumerateFiles(dvoid *opaque,
const char *dname,
int omitSymLinks);
static void DIR_enumerateFiles(dvoid *opaque, const char *dname,
int omitSymLinks, PHYSFS_StringCallback cb,
void *callbackdata);
static int DIR_exists(dvoid *opaque, const char *name);
static int DIR_isDirectory(dvoid *opaque, const char *name, int *fileExists);
static int DIR_isSymLink(dvoid *opaque, const char *name, int *fileExists);
@@ -165,17 +165,16 @@ static void *DIR_openArchive(const char *name, int forWriting)
} /* DIR_openArchive */


static LinkedStringList *DIR_enumerateFiles(dvoid *opaque,
const char *dname,
int omitSymLinks)
static void DIR_enumerateFiles(dvoid *opaque, const char *dname,
int omitSymLinks, PHYSFS_StringCallback cb,
void *callbackdata)
{
char *d = __PHYSFS_platformCvtToDependent((char *)opaque, dname, NULL);
LinkedStringList *retval;

BAIL_IF_MACRO(d == NULL, NULL, NULL);
retval = __PHYSFS_platformEnumerateFiles(d, omitSymLinks);
free(d);
return(retval);
if (d != NULL)
{
__PHYSFS_platformEnumerateFiles(d, omitSymLinks, cb, callbackdata);
free(d);
} /* if */
} /* DIR_enumerateFiles */


@@ -72,9 +72,9 @@ static PHYSFS_sint64 GRP_fileLength(fvoid *opaque);
static int GRP_fileClose(fvoid *opaque);
static int GRP_isArchive(const char *filename, int forWriting);
static void *GRP_openArchive(const char *name, int forWriting);
static LinkedStringList *GRP_enumerateFiles(dvoid *opaque,
const char *dirname,
int omitSymLinks);
static void GRP_enumerateFiles(dvoid *opaque, const char *dname,
int omitSymLinks, PHYSFS_StringCallback cb,
void *callbackdata);
static int GRP_exists(dvoid *opaque, const char *name);
static int GRP_isDirectory(dvoid *opaque, const char *name, int *fileExists);
static int GRP_isSymLink(dvoid *opaque, const char *name, int *fileExists);
@@ -359,23 +359,21 @@ static void *GRP_openArchive(const char *name, int forWriting)
} /* GRP_openArchive */


static LinkedStringList *GRP_enumerateFiles(dvoid *opaque,
const char *dirname,
int omitSymLinks)
static void GRP_enumerateFiles(dvoid *opaque, const char *dname,
int omitSymLinks, PHYSFS_StringCallback cb,
void *callbackdata)
{
GRPinfo *info = (GRPinfo *) opaque;
GRPentry *entry = info->entries;
LinkedStringList *retval = NULL, *p = NULL;
PHYSFS_uint32 max = info->entryCount;
PHYSFS_uint32 i;

/* no directories in GRP files. */
BAIL_IF_MACRO(*dirname != '\0', ERR_NOT_A_DIR, NULL);

for (i = 0; i < max; i++, entry++)
retval = __PHYSFS_addToLinkedStringList(retval, &p, entry->name, -1);
if (*dname != '\0')
{
GRPinfo *info = (GRPinfo *) opaque;
GRPentry *entry = info->entries;
PHYSFS_uint32 max = info->entryCount;
PHYSFS_uint32 i;

return(retval);
for (i = 0; i < max; i++, entry++)
cb(callbackdata, entry->name);
} /* if */
} /* GRP_enumerateFiles */


@@ -86,9 +86,9 @@ static PHYSFS_sint64 HOG_fileLength(fvoid *opaque);
static int HOG_fileClose(fvoid *opaque);
static int HOG_isArchive(const char *filename, int forWriting);
static void *HOG_openArchive(const char *name, int forWriting);
static LinkedStringList *HOG_enumerateFiles(dvoid *opaque,
const char *dirname,
int omitSymLinks);
static void HOG_enumerateFiles(dvoid *opaque, const char *dname,
int omitSymLinks, PHYSFS_StringCallback cb,
void *callbackdata);
static int HOG_exists(dvoid *opaque, const char *name);
static int HOG_isDirectory(dvoid *opaque, const char *name, int *fileExists);
static int HOG_isSymLink(dvoid *opaque, const char *name, int *fileExists);
@@ -398,23 +398,21 @@ static void *HOG_openArchive(const char *name, int forWriting)
} /* HOG_openArchive */


static LinkedStringList *HOG_enumerateFiles(dvoid *opaque,
const char *dirname,
int omitSymLinks)
static void HOG_enumerateFiles(dvoid *opaque, const char *dname,
int omitSymLinks, PHYSFS_StringCallback cb,
void *callbackdata)
{
HOGinfo *info = ((HOGinfo *) opaque);
HOGentry *entry = info->entries;
LinkedStringList *retval = NULL, *p = NULL;
PHYSFS_uint32 max = info->entryCount;
PHYSFS_uint32 i;

/* no directories in HOG files. */
BAIL_IF_MACRO(*dirname != '\0', ERR_NOT_A_DIR, NULL);

for (i = 0; i < max; i++, entry++)
retval = __PHYSFS_addToLinkedStringList(retval, &p, entry->name, -1);
if (*dname != '\0')
{
HOGinfo *info = (HOGinfo *) opaque;
HOGentry *entry = info->entries;
PHYSFS_uint32 max = info->entryCount;
PHYSFS_uint32 i;

return(retval);
for (i = 0; i < max; i++, entry++)
cb(callbackdata, entry->name);
} /* if */
} /* HOG_enumerateFiles */


@@ -91,9 +91,9 @@ static PHYSFS_sint64 MIX_fileLength(fvoid *opaque);
static int MIX_fileClose(fvoid *opaque);
static int MIX_isArchive(const char *filename, int forWriting);
static void *MIX_openArchive(const char *name, int forWriting);
static LinkedStringList *MIX_enumerateFiles(dvoid *opaque,
const char *dirname,
int omitSymLinks);
static void MIX_enumerateFiles(dvoid *opaque, const char *dname,
int omitSymLinks, PHYSFS_StringCallback cb,
void *callbackdata)
static int MIX_exists(dvoid *opaque, const char *name);
static int MIX_isDirectory(dvoid *opaque, const char *name, int *fileExists);
static int MIX_isSymLink(dvoid *opaque, const char *name, int *fileExists);
@@ -354,23 +354,24 @@ static void *MIX_openArchive(const char *name, int forWriting)
} /* MIX_openArchive */


static LinkedStringList *MIX_enumerateFiles(dvoid *opaque,
const char *dirname,
int omitSymLinks)
static void MIX_enumerateFiles(dvoid *opaque, const char *dname,
int omitSymLinks, PHYSFS_StringCallback cb,
void *callbackdata)
{
LinkedStringList *retval = NULL, *p = NULL;
MIXinfo *info = (MIXinfo*) opaque;
MIXentry *entry = info->entry;
int i;
char buffer[32];

for (i = 0; i < info->header.num_files; i++, entry++)
/* no directories in MIX files. */
if (*dirname != '\0')
{
sprintf(buffer, "%X", entry->hash);
retval = __PHYSFS_addToLinkedStringList(retval, &p, buffer, -1);
} /* for */

return(retval);
MIXinfo *info = (MIXinfo*) opaque;
MIXentry *entry = info->entry;
int i;
char buffer[32];

for (i = 0; i < info->header.num_files; i++, entry++)
{
sprintf(buffer, "%X", entry->hash);
cb(callbackdata, buffer);
} /* for */
} /* if */
} /* MIX_enumerateFiles */


@@ -75,9 +75,9 @@ static PHYSFS_sint64 MVL_fileLength(fvoid *opaque);
static int MVL_fileClose(fvoid *opaque);
static int MVL_isArchive(const char *filename, int forWriting);
static void *MVL_openArchive(const char *name, int forWriting);
static LinkedStringList *MVL_enumerateFiles(dvoid *opaque,
const char *dirname,
int omitSymLinks);
static void MVL_enumerateFiles(dvoid *opaque, const char *dname,
int omitSymLinks, PHYSFS_StringCallback cb,
void *callbackdata);
static int MVL_exists(dvoid *opaque, const char *name);
static int MVL_isDirectory(dvoid *opaque, const char *name, int *fileExists);
static int MVL_isSymLink(dvoid *opaque, const char *name, int *fileExists);
@@ -356,23 +356,21 @@ static void *MVL_openArchive(const char *name, int forWriting)
} /* MVL_openArchive */


static LinkedStringList *MVL_enumerateFiles(dvoid *opaque,
const char *dirname,
int omitSymLinks)
static void MVL_enumerateFiles(dvoid *opaque, const char *dname,
int omitSymLinks, PHYSFS_StringCallback cb,
void *callbackdata)
{
MVLinfo *info = ((MVLinfo *) opaque);
MVLentry *entry = info->entries;
LinkedStringList *retval = NULL, *p = NULL;
PHYSFS_uint32 max = info->entryCount;
PHYSFS_uint32 i;

/* no directories in MVL files. */
BAIL_IF_MACRO(*dirname != '\0', ERR_NOT_A_DIR, NULL);

for (i = 0; i < max; i++, entry++)
retval = __PHYSFS_addToLinkedStringList(retval, &p, entry->name, -1);
if (*dname != '\0')
{
MVLinfo *info = ((MVLinfo *) opaque);
MVLentry *entry = info->entries;
PHYSFS_uint32 max = info->entryCount;
PHYSFS_uint32 i;

return(retval);
for (i = 0; i < max; i++, entry++)
cb(callbackdata, entry->name);
} /* if */
} /* MVL_enumerateFiles */


@@ -89,9 +89,9 @@ static PHYSFS_sint64 QPAK_fileLength(fvoid *opaque);
static int QPAK_fileClose(fvoid *opaque);
static int QPAK_isArchive(const char *filename, int forWriting);
static void *QPAK_openArchive(const char *name, int forWriting);
static LinkedStringList *QPAK_enumerateFiles(dvoid *opaque,
const char *dirname,
int omitSymLinks);
static void QPAK_enumerateFiles(dvoid *opaque, const char *dname,
int omitSymLinks, PHYSFS_StringCallback cb,
void *callbackdata);
static int QPAK_exists(dvoid *opaque, const char *name);
static int QPAK_isDirectory(dvoid *opaque, const char *name, int *fileExists);
static int QPAK_isSymLink(dvoid *opaque, const char *name, int *fileExists);
@@ -443,19 +443,36 @@ static PHYSFS_sint32 qpak_find_start_of_dir(QPAKinfo *info, const char *path,
} /* qpak_find_start_of_dir */


static LinkedStringList *QPAK_enumerateFiles(dvoid *opaque,
const char *dirname,
int omitSymLinks)
/*
* Moved to seperate function so we can use alloca then immediately throw
* away the allocated stack space...
*/
static void doEnumCallback(PHYSFS_StringCallback cb, void *callbackdata,
const char *str, PHYSFS_sint32 ln)
{
char *newstr = alloca(ln + 1);
if (newstr == NULL)
return;

memcpy(newstr, str, ln);
newstr[ln] = '\0';
cb(callbackdata, newstr);
} /* doEnumCallback */


static void QPAK_enumerateFiles(dvoid *opaque, const char *dname,
int omitSymLinks, PHYSFS_StringCallback cb,
void *callbackdata)
{
QPAKinfo *info = ((QPAKinfo *) opaque);
LinkedStringList *retval = NULL, *p = NULL;
PHYSFS_sint32 dlen, dlen_inc, max, i;

i = qpak_find_start_of_dir(info, dirname, 0);
BAIL_IF_MACRO(i == -1, ERR_NO_SUCH_FILE, NULL);
i = qpak_find_start_of_dir(info, dname, 0);
if (i == -1) /* no such directory. */
return;

dlen = strlen(dirname);
if ((dlen > 0) && (dirname[dlen - 1] == '/')) /* ignore trailing slash. */
dlen = strlen(dname);
if ((dlen > 0) && (dname[dlen - 1] == '/')) /* ignore trailing slash. */
dlen--;

dlen_inc = ((dlen > 0) ? 1 : 0) + dlen;
@@ -466,13 +483,13 @@ static LinkedStringList *QPAK_enumerateFiles(dvoid *opaque,
char *ptr;
PHYSFS_sint32 ln;
char *e = info->entries[i].name;
if ((dlen) && ((QPAK_strncmp(e, dirname, dlen)) || (e[dlen] != '/')))
if ((dlen) && ((QPAK_strncmp(e, dname, dlen)) || (e[dlen] != '/')))
break; /* past end of this dir; we're done. */

add = e + dlen_inc;
ptr = strchr(add, '/');
ln = (PHYSFS_sint32) ((ptr) ? ptr-add : strlen(add));
retval = __PHYSFS_addToLinkedStringList(retval, &p, add, ln);
doEnumCallback(cb, callbackdata, add, ln);
ln += dlen_inc; /* point past entry to children... */

/* increment counter and skip children of subdirs... */
@@ -483,8 +500,6 @@ static LinkedStringList *QPAK_enumerateFiles(dvoid *opaque,
break;
} /* while */
} /* while */

return(retval);
} /* QPAK_enumerateFiles */


0 comments on commit c2765f8

Please sign in to comment.