paragui-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[paragui-cvs] CVS: paragui/src/physfs/archivers Makefile.am,1.3,1.4 dir.


From: Alexander Pipelka <address@hidden>
Subject: [paragui-cvs] CVS: paragui/src/physfs/archivers Makefile.am,1.3,1.4 dir.c,1.3,1.4 grp.c,1.3,1.4 zip.c,1.3,1.4 unzip.h,1.1.1.1,NONE
Date: Sun, 18 Aug 2002 04:12:55 -0400

Update of /cvsroot/paragui/paragui/src/physfs/archivers
In directory subversions:/tmp/cvs-serv12482/src/physfs/archivers

Modified Files:
        Makefile.am dir.c grp.c zip.c 
Removed Files:
        unzip.h 
Log Message:
synced with the devel-1-0-x tree.



Index: Makefile.am
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/archivers/Makefile.am,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** Makefile.am 26 Jun 2002 08:30:11 -0000      1.3
--- Makefile.am 18 Aug 2002 08:12:53 -0000      1.4
***************
*** 1,12 ****
  noinst_LTLIBRARIES = libarchivers.la
  
! libarchivers_la_SOURCES = \
!       dir.c \
!       grp.c \
!       unzip.c \
!       zip.c
  
! EXTRA_DIST = \
!       unzip.h
  
- INCLUDES = -I$(top_srcdir)
--- 1,13 ----
  noinst_LTLIBRARIES = libarchivers.la
  
! if BUILD_ZLIB
! INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/zlib114
! else
! INCLUDES = -I$(top_srcdir)
! endif
  
! libarchivers_la_SOURCES =     \
!       dir.c           \
!       grp.c           \
!       zip.c
  

Index: dir.c
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/archivers/dir.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** dir.c       26 Jun 2002 08:30:11 -0000      1.3
--- dir.c       18 Aug 2002 08:12:53 -0000      1.4
***************
*** 47,59 ****
  
  
  static const FileFunctions __PHYSFS_FileFunctions_DIR =
  {
!     DIR_read,       /* read() method      */
!     NULL,           /* write() method     */
!     DIR_eof,        /* eof() method       */
!     DIR_tell,       /* tell() method      */
!     DIR_seek,       /* seek() method      */
      DIR_fileLength, /* fileLength() method */
!     DIR_fileClose   /* fileClose() method */
  };
  
--- 47,68 ----
  
  
+ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_DIR =
+ {
+     "",
+     DIR_ARCHIVE_DESCRIPTION,
+     "Ryan C. Gordon <address@hidden>",
+     "http://icculus.org/physfs/";,
+ };
+ 
+ 
  static const FileFunctions __PHYSFS_FileFunctions_DIR =
  {
!     DIR_read,       /* read() method       */
!     NULL,           /* write() method      */
!     DIR_eof,        /* eof() method        */
!     DIR_tell,       /* tell() method       */
!     DIR_seek,       /* seek() method       */
      DIR_fileLength, /* fileLength() method */
!     DIR_fileClose   /* fileClose() method  */
  };
  
***************
*** 73,76 ****
--- 82,86 ----
  const DirFunctions __PHYSFS_DirFunctions_DIR =
  {
+     &__PHYSFS_ArchiveInfo_DIR,
      DIR_isArchive,          /* isArchive() method      */
      DIR_openArchive,        /* openArchive() method    */
***************
*** 87,102 ****
      DIR_dirClose            /* dirClose() method       */
  };
- 
- 
- /* This doesn't get listed, since it's technically not an archive... */
- #if 0
- const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_DIR =
- {
-     "DIR",
-     "non-archive directory I/O",
-     "Ryan C. Gordon <address@hidden>",
-     "http://www.icculus.org/physfs/";,
- };
- #endif
  
  
--- 97,100 ----

Index: grp.c
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/archivers/grp.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** grp.c       26 Jun 2002 08:30:11 -0000      1.3
--- grp.c       18 Aug 2002 08:12:53 -0000      1.4
***************
*** 20,27 ****
   * (That info is from http://www.advsys.net/ken/build.htm ...)
   *
-  * As it was never a concern in the DOS-based Duke Nukem days, I treat these
-  *  archives as CASE-INSENSITIVE. Opening "myfile.txt" and "MYFILE.TXT" both
-  *  work, and get the same file.
-  *
   * Please see the file LICENSE in the source's root directory.
   *
--- 20,23 ----
***************
*** 46,54 ****
  #include "physfs_internal.h"
  
  typedef struct
  {
-     void *handle;
      char *filename;
!     PHYSFS_uint32 totalEntries;
  } GRPinfo;
  
--- 42,65 ----
  #include "physfs_internal.h"
  
+ /*
+  * When sorting the grp entries in an archive, we use a modified QuickSort.
+  *  When there are less then GRP_QUICKSORT_THRESHOLD entries left to sort,
+  *  we switch over to an InsertionSort for the remainder. Tweak to taste.
+  */
+ #define GRP_QUICKSORT_THRESHOLD 4
+ 
+ typedef struct
+ {
+     char name[13];
+     PHYSFS_uint64 startPos;
+     PHYSFS_uint64 size;
+ } GRPentry;
+ 
  typedef struct
  {
      char *filename;
!     PHYSFS_sint64 last_mod_time;
!     PHYSFS_uint32 entryCount;
!     GRPentry *entries;
  } GRPinfo;
  
***************
*** 56,61 ****
  {
      void *handle;
!     PHYSFS_uint64 startPos;
!     PHYSFS_uint64 size;
  } GRPfileinfo;
  
--- 67,72 ----
  {
      void *handle;
!     GRPentry *entry;
!     PHYSFS_sint64 curPos;
  } GRPfileinfo;
  
***************
*** 80,83 ****
--- 91,103 ----
  static FileHandle *GRP_openRead(DirHandle *h, const char *name);
  
+ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_GRP =
+ {
+     "GRP",
+     GRP_ARCHIVE_DESCRIPTION,
+     "Ryan C. Gordon <address@hidden>",
+     "http://icculus.org/physfs/";,
+ };
+ 
+ 
  static const FileFunctions __PHYSFS_FileFunctions_GRP =
  {
***************
*** 94,97 ****
--- 114,118 ----
  const DirFunctions __PHYSFS_DirFunctions_GRP =
  {
+     &__PHYSFS_ArchiveInfo_GRP,
      GRP_isArchive,          /* isArchive() method      */
      GRP_openArchive,        /* openArchive() method    */
***************
*** 109,127 ****
  };
  
- const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_GRP =
- {
-     "GRP",
-     "Build engine Groupfile format",
-     "Ryan C. Gordon <address@hidden>",
-     "http://www.icculus.org/physfs/";,
- };
- 
  
  
  static void GRP_dirClose(DirHandle *h)
  {
!     __PHYSFS_platformClose( ((GRPinfo *) h->opaque)->handle );
!     free(((GRPinfo *) h->opaque)->filename);
!     free(h->opaque);
      free(h);
  } /* GRP_dirClose */
--- 130,141 ----
  };
  
  
  
  static void GRP_dirClose(DirHandle *h)
  {
!     GRPinfo *info = ((GRPinfo *) h->opaque);
!     free(info->filename);
!     free(info->entries);
!     free(info);
      free(h);
  } /* GRP_dirClose */
***************
*** 132,144 ****
  {
      GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
!     void *fh = finfo->handle;
!     PHYSFS_sint64 curPos = __PHYSFS_platformTell(fh);
!     PHYSFS_uint64 bytesLeft = (finfo->startPos + finfo->size) - curPos;
      PHYSFS_uint64 objsLeft = (bytesLeft / objSize);
  
      if (objsLeft < objCount)
          objCount = (PHYSFS_uint32) objsLeft;
  
!     return(__PHYSFS_platformRead(fh, buffer, objSize, objCount));
  } /* GRP_read */
  
--- 146,162 ----
  {
      GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
!     GRPentry *entry = finfo->entry;
!     PHYSFS_uint64 bytesLeft = entry->size - finfo->curPos;
      PHYSFS_uint64 objsLeft = (bytesLeft / objSize);
+     PHYSFS_sint64 rc;
  
      if (objsLeft < objCount)
          objCount = (PHYSFS_uint32) objsLeft;
  
!     rc = __PHYSFS_platformRead(finfo->handle, buffer, objSize, objCount);
!     if (rc > 0)
!         finfo->curPos += (rc * objSize);
! 
!     return(rc);
  } /* GRP_read */
  
***************
*** 147,154 ****
  {
      GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
!     void *fh = finfo->handle;
!     PHYSFS_sint64 pos = __PHYSFS_platformTell(fh);
!     BAIL_IF_MACRO(pos < 0, NULL, 1);  /* (*shrug*) */
!     return(pos >= (PHYSFS_sint64) (finfo->startPos + finfo->size));
  } /* GRP_eof */
  
--- 165,170 ----
  {
      GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
!     GRPentry *entry = finfo->entry;
!     return(finfo->curPos >= (PHYSFS_sint64) entry->size);
  } /* GRP_eof */
  
***************
*** 156,161 ****
  static PHYSFS_sint64 GRP_tell(FileHandle *handle)
  {
!     GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
!     return(__PHYSFS_platformTell(finfo->handle) - finfo->startPos);
  } /* GRP_tell */
  
--- 172,176 ----
  static PHYSFS_sint64 GRP_tell(FileHandle *handle)
  {
!     return(((GRPfileinfo *) (handle->opaque))->curPos);
  } /* GRP_tell */
  
***************
*** 164,172 ****
  {
      GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
!     PHYSFS_uint64 newPos = (finfo->startPos + offset);
  
      BAIL_IF_MACRO(offset < 0, ERR_INVALID_ARGUMENT, 0);
!     BAIL_IF_MACRO(newPos > finfo->startPos + finfo->size, ERR_PAST_EOF, 0);
!     return(__PHYSFS_platformSeek(finfo->handle, newPos));
  } /* GRP_seek */
  
--- 179,193 ----
  {
      GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
!     GRPentry *entry = finfo->entry;
!     PHYSFS_uint64 newPos = (entry->startPos + offset);
!     int rc;
  
      BAIL_IF_MACRO(offset < 0, ERR_INVALID_ARGUMENT, 0);
!     BAIL_IF_MACRO(newPos > entry->startPos + entry->size, ERR_PAST_EOF, 0);
!     rc = __PHYSFS_platformSeek(finfo->handle, newPos);
!     if (rc)
!         finfo->curPos = offset;
! 
!     return(rc);
  } /* GRP_seek */
  
***************
*** 174,179 ****
  static PHYSFS_sint64 GRP_fileLength(FileHandle *handle)
  {
!     GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
!     return(finfo->size);
  } /* GRP_fileLength */
  
--- 195,199 ----
  static PHYSFS_sint64 GRP_fileLength(FileHandle *handle)
  {
!     return(((GRPfileinfo *) handle->opaque)->entry->size);
  } /* GRP_fileLength */
  
***************
*** 181,188 ****
  static int GRP_fileClose(FileHandle *handle)
  {
!     GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
!     BAIL_IF_MACRO(__PHYSFS_platformClose(finfo->handle), NULL, 0);
! 
!     free(handle->opaque);
      free(handle);
      return(1);
--- 201,207 ----
  static int GRP_fileClose(FileHandle *handle)
  {
!     GRPfileinfo *finfo = ((GRPfileinfo *) handle->opaque);
!     BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
!     free(finfo);
      free(handle);
      return(1);
***************
*** 190,195 ****
  
  
! static int openGrp(const char *filename, int forWriting,
!                     void **fh, PHYSFS_sint32 *count)
  {
      PHYSFS_uint8 buf[12];
--- 209,214 ----
  
  
! static int grp_open(const char *filename, int forWriting,
!                     void **fh, PHYSFS_uint32 *count)
  {
      PHYSFS_uint8 buf[12];
***************
*** 210,217 ****
      } /* if */
  
!     if (__PHYSFS_platformRead(*fh, count, sizeof (PHYSFS_sint32), 1) != 1)
          goto openGrp_failed;
  
!     *count = PHYSFS_swapSLE32(*count);
  
      return(1);
--- 229,236 ----
      } /* if */
  
!     if (__PHYSFS_platformRead(*fh, count, sizeof (PHYSFS_uint32), 1) != 1)
          goto openGrp_failed;
  
!     *count = PHYSFS_swapULE32(*count);
  
      return(1);
***************
*** 224,228 ****
      *fh = NULL;
      return(0);
! } /* openGrp */
  
  
--- 243,247 ----
      *fh = NULL;
      return(0);
! } /* grp_open */
  
  
***************
*** 230,235 ****
  {
      void *fh;
!     int fileCount;
!     int retval = openGrp(filename, forWriting, &fh, &fileCount);
  
      if (fh != NULL)
--- 249,254 ----
  {
      void *fh;
!     PHYSFS_uint32 fileCount;
!     int retval = grp_open(filename, forWriting, &fh, &fileCount);
  
      if (fh != NULL)
***************
*** 240,252 ****
  
  
! static DirHandle *GRP_openArchive(const char *name, int forWriting)
  {
      void *fh = NULL;
!     int fileCount;
      DirHandle *retval = malloc(sizeof (DirHandle));
  
      BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
!     retval->opaque = malloc(sizeof (GRPinfo));
!     if (retval->opaque == NULL)
      {
          __PHYSFS_setError(ERR_OUT_OF_MEMORY);
--- 259,394 ----
  
  
! static void grp_entry_swap(GRPentry *a, PHYSFS_uint32 one, PHYSFS_uint32 two)
! {
!     GRPentry tmp;
!     memcpy(&tmp, &a[one], sizeof (GRPentry));
!     memcpy(&a[one], &a[two], sizeof (GRPentry));
!     memcpy(&a[two], &tmp, sizeof (GRPentry));
! } /* grp_entry_swap */
! 
! 
! static void grp_quick_sort(GRPentry *a, PHYSFS_uint32 lo, PHYSFS_uint32 hi)
! {
!     PHYSFS_uint32 i;
!     PHYSFS_uint32 j;
!     GRPentry *v;
! 
!       if ((hi - lo) > GRP_QUICKSORT_THRESHOLD)
!       {
!               i = (hi + lo) / 2;
! 
!               if (strcmp(a[lo].name, a[i].name) > 0) grp_entry_swap(a, lo, i);
!               if (strcmp(a[lo].name, a[hi].name) > 0) grp_entry_swap(a, lo, 
hi);
!               if (strcmp(a[i].name, a[hi].name) > 0) grp_entry_swap(a, i, hi);
! 
!               j = hi - 1;
!               grp_entry_swap(a, i, j);
!               i = lo;
!               v = &a[j];
!               while (1)
!               {
!                       while(strcmp(a[++i].name, v->name) < 0) {}
!                       while(strcmp(a[--j].name, v->name) > 0) {}
!                       if (j < i)
!                 break;
!                       grp_entry_swap(a, i, j);
!               } /* while */
!               grp_entry_swap(a, i, hi-1);
!               grp_quick_sort(a, lo, j);
!               grp_quick_sort(a, i+1, hi);
!       } /* if */
! } /* grp_quick_sort */
! 
! 
! static void grp_insertion_sort(GRPentry *a, PHYSFS_uint32 lo, PHYSFS_uint32 
hi)
! {
!     PHYSFS_uint32 i;
!     PHYSFS_uint32 j;
!     GRPentry tmp;
! 
!     for (i = lo + 1; i <= hi; i++)
!     {
!         memcpy(&tmp, &a[i], sizeof (GRPentry));
!         j = i;
!         while ((j > lo) && (strcmp(a[j - 1].name, tmp.name) > 0))
!         {
!             memcpy(&a[j], &a[j - 1], sizeof (GRPentry));
!             j--;
!         } /* while */
!         memcpy(&a[j], &tmp, sizeof (GRPentry));
!     } /* for */
! } /* grp_insertion_sort */
! 
! 
! static void grp_sort_entries(GRPentry *entries, PHYSFS_uint32 max)
! {
!     /*
!      * Fast Quicksort algorithm inspired by code from here:
!      *   http://www.cs.ubc.ca/spider/harrison/Java/sorting-demo.html
!      */
!     if (max <= GRP_QUICKSORT_THRESHOLD)
!         grp_quick_sort(entries, 0, max - 1);
!       grp_insertion_sort(entries, 0, max - 1);
! } /* grp_sort_entries */
! 
! 
! static int grp_load_entries(const char *name, int forWriting, GRPinfo *info)
  {
      void *fh = NULL;
!     PHYSFS_uint32 fileCount;
!     PHYSFS_uint32 location = 16;  /* sizeof sig. */
!     GRPentry *entry;
!     char *ptr;
! 
!     BAIL_IF_MACRO(!grp_open(name, forWriting, &fh, &fileCount), NULL, 0);
!     info->entryCount = fileCount;
!     info->entries = (GRPentry *) malloc(sizeof (GRPentry) * fileCount);
!     if (info->entries == NULL)
!     {
!         __PHYSFS_platformClose(fh);
!         BAIL_MACRO(ERR_OUT_OF_MEMORY, 0);
!     } /* if */
! 
!     location += (16 * fileCount);
! 
!     for (entry = info->entries; fileCount > 0; fileCount--, entry++)
!     {
!         if (__PHYSFS_platformRead(fh, &entry->name, 12, 1) != 1)
!         {
!             __PHYSFS_platformClose(fh);
!             return(0);
!         } /* if */
! 
!         entry->name[12] = '\0';  /* name isn't null-terminated in file. */
!         if ((ptr = strchr(entry->name, ' ')) != NULL)
!             *ptr = '\0';  /* trim extra spaces. */
! 
!         if (__PHYSFS_platformRead(fh, &entry->size, 4, 1) != 1)
!         {
!             __PHYSFS_platformClose(fh);
!             return(0);
!         } /* if */
! 
!         entry->size = PHYSFS_swapULE32(entry->size);
!         entry->startPos = location;
!         location += entry->size;
!     } /* for */
! 
!     __PHYSFS_platformClose(fh);
! 
!     grp_sort_entries(info->entries, info->entryCount);
!     return(1);
! } /* grp_load_entries */
! 
! 
! static DirHandle *GRP_openArchive(const char *name, int forWriting)
! {
!     GRPinfo *info;
      DirHandle *retval = malloc(sizeof (DirHandle));
+     PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
  
      BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
!     info = retval->opaque = malloc(sizeof (GRPinfo));
!     if (info == NULL)
      {
          __PHYSFS_setError(ERR_OUT_OF_MEMORY);
***************
*** 254,259 ****
      } /* if */
  
!     ((GRPinfo *) retval->opaque)->filename = (char *) malloc(strlen(name) + 
1);
!     if (((GRPinfo *) retval->opaque)->filename == NULL)
      {
          __PHYSFS_setError(ERR_OUT_OF_MEMORY);
--- 396,403 ----
      } /* if */
  
!     memset(info, '\0', sizeof (GRPinfo));
! 
!     info->filename = (char *) malloc(strlen(name) + 1);
!     if (info->filename == NULL)
      {
          __PHYSFS_setError(ERR_OUT_OF_MEMORY);
***************
*** 261,270 ****
      } /* if */
  
!     if (!openGrp(name, forWriting, &fh, &fileCount))
          goto GRP_openArchive_failed;
  
!     strcpy(((GRPinfo *) retval->opaque)->filename, name);
!     ((GRPinfo *) retval->opaque)->handle = fh;
!     ((GRPinfo *) retval->opaque)->totalEntries = fileCount;
      retval->funcs = &__PHYSFS_DirFunctions_GRP;
      return(retval);
--- 405,413 ----
      } /* if */
  
!     if (!grp_load_entries(name, forWriting, info))
          goto GRP_openArchive_failed;
  
!     strcpy(info->filename, name);
!     info->last_mod_time = modtime;
      retval->funcs = &__PHYSFS_DirFunctions_GRP;
      return(retval);
***************
*** 275,288 ****
          if (retval->opaque != NULL)
          {
!             if ( ((GRPinfo *) retval->opaque)->filename != NULL )
!                 free( ((GRPinfo *) retval->opaque)->filename );
!             free(retval->opaque);
          } /* if */
          free(retval);
      } /* if */
  
-     if (fh != NULL)
-         __PHYSFS_platformClose(fh);
- 
      return(NULL);
  } /* GRP_openArchive */
--- 418,430 ----
          if (retval->opaque != NULL)
          {
!             if (info->filename != NULL)
!                 free(info->filename);
!             if (info->entries != NULL)
!                 free(info->entries);
!             free(info);
          } /* if */
          free(retval);
      } /* if */
  
      return(NULL);
  } /* GRP_openArchive */
***************
*** 293,338 ****
                                              int omitSymLinks)
  {
!     PHYSFS_uint8 buf[16];
!     GRPinfo *g = (GRPinfo *) (h->opaque);
!     void *fh = g->handle;
      PHYSFS_uint32 i;
-     LinkedStringList *retval = NULL;
-     LinkedStringList *l = NULL;
-     LinkedStringList *prev = NULL;
- 
-     /* !!! FIXME: Does this consider "/" ? */
-     if (*dirname != '\0')   /* no directories in GRP files. */
-         return(NULL);
  
!         /* jump to first file entry... */
!     BAIL_IF_MACRO(!__PHYSFS_platformSeek(fh, 16), NULL, NULL);
  
!     for (i = 0; i < g->totalEntries; i++)
!     {
!         BAIL_IF_MACRO(__PHYSFS_platformRead(fh, buf, 16, 1) != 1, NULL, 
retval);
! 
!         buf[12] = '\0';  /* FILENAME.EXT is all you get. */
! 
!         l = (LinkedStringList *) malloc(sizeof (LinkedStringList));
!         if (l == NULL)
!             break;
! 
!         l->str = (char *) malloc(strlen((const char *) buf) + 1);
!         if (l->str == NULL)
!         {
!             free(l);
!             break;
!         } /* if */
! 
!         strcpy(l->str, (const char *) buf);
! 
!         if (retval == NULL)
!             retval = l;
!         else
!             prev->next = l;
! 
!         prev = l;
!         l->next = NULL;
!     } /* for */
  
      return(retval);
--- 435,449 ----
                                              int omitSymLinks)
  {
!     GRPinfo *info = ((GRPinfo *) h->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);
  
      return(retval);
***************
*** 340,394 ****
  
  
! static PHYSFS_sint32 getFileEntry(DirHandle *h, const char *name,
!                                   PHYSFS_uint32 *size)
  {
!     PHYSFS_uint8 buf[16];
!     GRPinfo *g = (GRPinfo *) (h->opaque);
!     void *fh = g->handle;
!     PHYSFS_uint32 i;
!     char *ptr;
!     int retval = (g->totalEntries + 1) * 16; /* offset of raw file data */
  
!     /* Rule out filenames to avoid unneeded file i/o... */
!     if (strchr(name, '/') != NULL)  /* no directories in groupfiles. */
!         return(-1);
! 
!     ptr = strchr(name, '.');
!     if ((ptr) && (strlen(ptr) > 4))   /* 3 char extension at most. */
!         return(-1);
! 
!     if (strlen(name) > 12)
!         return(-1);
! 
!     /* jump to first file entry... */
!     BAIL_IF_MACRO(!__PHYSFS_platformSeek(fh, 16), NULL, -1);
! 
!     for (i = 0; i < g->totalEntries; i++)
      {
!         PHYSFS_sint32 l = 0;
! 
!         BAIL_IF_MACRO(__PHYSFS_platformRead(fh, buf, 12, 1) != 1, NULL, -1);
!         BAIL_IF_MACRO(__PHYSFS_platformRead(fh, &l, sizeof (l), 1) != 1, 
NULL, -1);
!         l = PHYSFS_swapSLE32(l);
! 
!         buf[12] = '\0';  /* FILENAME.EXT is all you get. */
! 
!         if (__PHYSFS_platformStricmp((const char *) buf, name) == 0)
!         {
!             if (size != NULL)
!                 *size = l;
!             return(retval);
!         } /* if */
! 
!         retval += l;
!     } /* for */
  
!     return(-1);  /* not found. */
! } /* getFileEntry */
  
  
  static int GRP_exists(DirHandle *h, const char *name)
  {
!     return(getFileEntry(h, name, NULL) != -1);
  } /* GRP_exists */
  
--- 451,490 ----
  
  
! static GRPentry *grp_find_entry(GRPinfo *info, const char *name)
  {
!     char *ptr = strchr(name, '.');
!     GRPentry *a = info->entries;
!     PHYSFS_sint32 lo = 0;
!     PHYSFS_sint32 hi = (PHYSFS_sint32) (info->entryCount - 1);
!     PHYSFS_sint32 middle;
!     int rc;
! 
!     /*
!      * Rule out filenames to avoid unneeded processing...no dirs,
!      *   big filenames, or extensions > 3 chars.
!      */
!     BAIL_IF_MACRO((ptr) && (strlen(ptr) > 4), ERR_NO_SUCH_FILE, NULL);
!     BAIL_IF_MACRO(strlen(name) > 12, ERR_NO_SUCH_FILE, NULL);
!     BAIL_IF_MACRO(strchr(name, '/') != NULL, ERR_NO_SUCH_FILE, NULL);
  
!     while (lo <= hi)
      {
!         middle = lo + ((hi - lo) / 2);
!         rc = strcmp(name, a[middle].name);
!         if (rc == 0)  /* found it! */
!             return(&a[middle]);
!         else if (rc > 0)
!             lo = middle + 1;
!         else
!             hi = middle - 1;
!     } /* while */
  
!     BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
! } /* grp_find_entry */
  
  
  static int GRP_exists(DirHandle *h, const char *name)
  {
!     return(grp_find_entry(((GRPinfo *) h->opaque), name) != NULL);
  } /* GRP_exists */
  
***************
*** 408,413 ****
  static PHYSFS_sint64 GRP_getLastModTime(DirHandle *h, const char *name)
  {
      /* Just return the time of the GRP itself in the physical filesystem. */
!     return(__PHYSFS_platformGetLastModTime(((GRPinfo *) 
h->opaque)->filename));
  } /* GRP_getLastModTime */
  
--- 504,513 ----
  static PHYSFS_sint64 GRP_getLastModTime(DirHandle *h, const char *name)
  {
+     GRPinfo *info = ((GRPinfo *) h->opaque);
+     if (grp_find_entry(info, name) == NULL)
+         return(-1);  /* no such entry. */
+ 
      /* Just return the time of the GRP itself in the physical filesystem. */
!     return(((GRPinfo *) h->opaque)->last_mod_time);
  } /* GRP_getLastModTime */
  
***************
*** 415,426 ****
  static FileHandle *GRP_openRead(DirHandle *h, const char *name)
  {
!     const char *filename = ((GRPinfo *) h->opaque)->filename;
      FileHandle *retval;
      GRPfileinfo *finfo;
!     PHYSFS_uint32 size;
!     PHYSFS_sint32 offset;
  
!     offset = getFileEntry(h, name, &size);
!     BAIL_IF_MACRO(offset == -1, ERR_NO_SUCH_FILE, NULL);
  
      retval = (FileHandle *) malloc(sizeof (FileHandle));
--- 515,525 ----
  static FileHandle *GRP_openRead(DirHandle *h, const char *name)
  {
!     GRPinfo *info = ((GRPinfo *) h->opaque);
      FileHandle *retval;
      GRPfileinfo *finfo;
!     GRPentry *entry;
  
!     entry = grp_find_entry(info, name);
!     BAIL_IF_MACRO(entry == NULL, NULL, NULL);
  
      retval = (FileHandle *) malloc(sizeof (FileHandle));
***************
*** 430,439 ****
      {
          free(retval);
!         BAIL_IF_MACRO(1, ERR_OUT_OF_MEMORY, NULL);
      } /* if */
  
!     finfo->handle = __PHYSFS_platformOpenRead(filename);
      if ( (finfo->handle == NULL) ||
!          (!__PHYSFS_platformSeek(finfo->handle, offset)) )
      {
          free(finfo);
--- 529,538 ----
      {
          free(retval);
!         BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
      } /* if */
  
!     finfo->handle = __PHYSFS_platformOpenRead(info->filename);
      if ( (finfo->handle == NULL) ||
!          (!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
      {
          free(finfo);
***************
*** 442,447 ****
      } /* if */
  
!     finfo->startPos = offset;
!     finfo->size = size;
      retval->opaque = (void *) finfo;
      retval->funcs = &__PHYSFS_FileFunctions_GRP;
--- 541,546 ----
      } /* if */
  
!     finfo->curPos = 0;
!     finfo->entry = entry;
      retval->opaque = (void *) finfo;
      retval->funcs = &__PHYSFS_FileFunctions_GRP;

Index: zip.c
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/archivers/zip.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** zip.c       26 Jun 2002 08:30:11 -0000      1.3
--- zip.c       18 Aug 2002 08:12:53 -0000      1.4
***************
*** 4,8 ****
   * Please see the file LICENSE in the source's root directory.
   *
!  *  This file written by Ryan C. Gordon.
   */
  
--- 4,9 ----
   * Please see the file LICENSE in the source's root directory.
   *
!  *  This file written by Ryan C. Gordon, with some peeking at "unzip.c"
!  *   by Gilles Vollant.
[...2018 lines suppressed...]
!             ZIP_fileClose(retval);
!             BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
!         } /* if */
      } /* if */
  
      return(retval);
  } /* ZIP_openRead */
***************
*** 696,700 ****
  {
      ZIPinfo *zi = (ZIPinfo *) (h->opaque);
!     freeEntries(zi, zi->global.number_entry, NULL);
      free(zi->archiveName);
      free(zi);
--- 1423,1427 ----
  {
      ZIPinfo *zi = (ZIPinfo *) (h->opaque);
!     zip_free_entries(zi->entries, zi->entryCount);
      free(zi->archiveName);
      free(zi);

--- unzip.h DELETED ---





reply via email to

[Prev in Thread] Current Thread [Next in Thread]