corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [1/2] incubator-corinthia git commit: multi zip file
Date Thu, 01 Jan 2015 12:07:35 GMT
Repository: incubator-corinthia
Updated Branches:
  refs/heads/RTC_platform a84b00b72 -> b159258cf


multi zip file


Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/1a3eaebd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/1a3eaebd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/1a3eaebd

Branch: refs/heads/RTC_platform
Commit: 1a3eaebd30010918827b97f74e27376224a6b6d3
Parents: a84b00b
Author: jani <jani@apache.org>
Authored: Thu Jan 1 12:59:37 2015 +0100
Committer: jani <jani@apache.org>
Committed: Thu Jan 1 12:59:37 2015 +0100

----------------------------------------------------------------------
 DocFormats/platform/headers/DFPlatform.h | 11 ++--
 DocFormats/platform/src/Wrapper.c        | 77 ++++++++++++++-------------
 2 files changed, 47 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/1a3eaebd/DocFormats/platform/headers/DFPlatform.h
----------------------------------------------------------------------
diff --git a/DocFormats/platform/headers/DFPlatform.h b/DocFormats/platform/headers/DFPlatform.h
index 81d8a74..7196906 100755
--- a/DocFormats/platform/headers/DFPlatform.h
+++ b/DocFormats/platform/headers/DFPlatform.h
@@ -35,12 +35,13 @@ typedef void (*DFOnceFunction)(void);
 void DFInitOnce(DFOnce *once, DFOnceFunction fun);
 
 // Zip functions
+#define MAX_ZIP_OPEN 10
 int DFextZipOpen(const char *zipFilename, int doUnzip);
-int DFextZipClose(void);
+int DFextZipClose(int zipId);
 
-int DFextZipOpenNextFile(char *entryName, const int maxName);
-int DFextZipCloseFile(void);
+int DFextZipOpenNextFile(int zipId, char *entryName, const int maxName);
+int DFextZipCloseFile(zipId);
 
-int DFextZipReadCurrentFile(char *buf, const int maxLen);
-int DFextZipWriteCurrentFile(char *buf, const int len);
+int DFextZipReadCurrentFile(int zipId,  char *buf, const int maxLen);
+int DFextZipWriteCurrentFile(int zipId, char *buf, const int len);
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/1a3eaebd/DocFormats/platform/src/Wrapper.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Wrapper.c b/DocFormats/platform/src/Wrapper.c
index f138cbe..fe48a49 100644
--- a/DocFormats/platform/src/Wrapper.c
+++ b/DocFormats/platform/src/Wrapper.c
@@ -18,39 +18,44 @@
 
 
 // This file contains functions to isolate external libraries
-static unzFile myZipFile;
-static int     myZipFlag;
-static int     myZipFirst;
+static struct {
+    unzFile myZipFile;
+    int     myZipFlag;
+    int     myZipFirst;
+} myZipStorage[MAX_ZIP_OPEN];
 
 
 int DFextZipOpen(const char *zipFilename, int doUnzip) {
-    // Check if already in use
-    if (myZipFile)
-        return 0;
+    int zipId;
+
+    // find an empty slot
+    for (zipId = 0; zipId < MAX_ZIP_OPEN && myZipStorage[i].myZipFile; ++i) ;
+    if (zipId >= MAX_ZIP_OPEN)
+        return -1;
 
     // Open file
-    myZipFirst = 1;
-    myZipFlag  = doUnzip;
-    if (myZipFlag)
-      myZipFile = unzOpen(zipFilename);
+    myZipStorage[zipId].myZipFirst = 1;
+    myZipStorage[zipId].myZipFlag = doUnzip;
+    if (doUnzip)
+        myZipStorage[zipId].myZipFile = unzOpen(zipFilename);
     else
-      myZipFile = zipOpen(zipFilename, APPEND_STATUS_CREATE);
+        myZipStorage[zipId].myZipFile = zipOpen(zipFilename, APPEND_STATUS_CREATE);
 
-    return (myZipFile == NULL) ? -1 : 1;
+    return (myZipStorage[zipId].myZipFile) ? zipId : -1;
 }
 
 
 
-int DFextZipClose(void)
+int DFextZipClose(int zipId)
 {
     int rc;
 
-    if (myZipFile) {
-      if (myZipFlag)
-          rc = (unzClose(myZipFile) == UNZ_OK);
-      else
-          rc = (zipClose(myZipFile, NULL) == ZIP_OK);
-      myZipFile = NULL;
+    if (myZipStorage[zipId].myZipFile) {
+        if (myZipStorage[zipId].myZipFlag)
+            rc = (unzClose(myZipStorage[zipId].myZipFile) == UNZ_OK);
+        else
+          rc = (zipClose(myZipStorage[zipId].myZipFile, NULL) == ZIP_OK);
+        myZipStorage[zipId].myZipFile = NULL;
     }
 
     return rc ? 0 : -1;
@@ -58,28 +63,28 @@ int DFextZipClose(void)
 
 
 
-int DFextZipOpenNextFile(char *entryName, const int maxName)
+int DFextZipOpenNextFile(int zipId, char *entryName, const int maxName)
 {
     int rc;
 
 
-    if (myZipFlag) {
+    if (myZipStorage[zipId].myZipFlag) {
         unz_file_info info;
 
         // handling of first file and all others are different
-        if (myZipFirst) {
-            rc = unzGoToFirstFile(myZipFile);
-            myZipFirst = 0;
+        if (myZipStorage[zipId].myZipFirst) {
+            rc = unzGoToFirstFile(myZipStorage[zipId].myZipFile);
+            myZipStorage[zipId].myZipFirst = 0;
         }
         else
-            rc = unzGoToNextFile(myZipFile);
+            rc = unzGoToNextFile(myZipStorage[zipId].myZipFile);
 
         // Error or past last file
         if (rc != UNZ_OK)
             return (rc == UNZ_END_OF_LIST_OF_FILE) ? 0 : -1;
 
         // get file name
-        if (unzGetCurrentFileInfo(myZipFile, &info, entryName, maxName, NULL, 0, NULL,
0) != UNZ_OK)
+        if (unzGetCurrentFileInfo(myZipStorage[zipId].myZipFile, &info, entryName, maxName,
NULL, 0, NULL, 0) != UNZ_OK)
             return -1;
 
         // check for prefix "/" and if present skip file
@@ -87,14 +92,14 @@ int DFextZipOpenNextFile(char *entryName, const int maxName)
             return DFextZipOpenNextFile(entryName, maxName);
 
         // open Regular file
-        if (unzOpenCurrentFile(myZipFile) != UNZ_OK)
+        if (unzOpenCurrentFile(myZipStorage[zipId].myZipFile) != UNZ_OK)
             return -1;
     }
     else {
         zip_fileinfo fileinfo;
         memset(&fileinfo, 0, sizeof(fileinfo));
 
-        if (zipOpenNewFileInZip(myZipFile,
+        if (zipOpenNewFileInZip(myZipStorage[zipId].myZipFile,
             entryName,
             &fileinfo,
             NULL, 0,
@@ -111,25 +116,25 @@ int DFextZipOpenNextFile(char *entryName, const int maxName)
 
 
 
-int DFextZipCloseFile(void)
+int DFextZipCloseFile(int zipId)
 {
-    if (myZipFlag)
-        return (unzCloseCurrentFile(myZipFile) != UNZ_OK) ? -1 : 1;
+    if (myZipStorage[zipId].myZipFlag)
+        return (unzCloseCurrentFile(myZipStorage[zipId].myZipFile) != UNZ_OK) ? -1 : 1;
     else
-        return (zipCloseFileInZip(myZipFile) != UNZ_OK) ? -1 : 1;
+        return (zipCloseFileInZip(myZipStorage[zipId].myZipFile) != UNZ_OK) ? -1 : 1;
 }
 
 
  
 
-int DFextZipReadCurrentFile(char *buf, const int maxLen)
+int DFextZipReadCurrentFile(int zipId, char *buf, const int maxLen)
 {
-    return unzReadCurrentFile(myZipFile, buf, maxLen);
+    return unzReadCurrentFile(myZipStorage[zipId].myZipFile, buf, maxLen);
 }
 
 
 
-int DFextZipWriteCurrentFile(char *buf, const int len)
+int DFextZipWriteCurrentFile(int zipId, char *buf, const int len)
 {
-    return (zipWriteInFileInZip(myZipFile, buf, len) == ZIP_OK) ? 1 : -1;
+    return (zipWriteInFileInZip(myZipStorage[zipId].myZipFile, buf, len) == ZIP_OK) ? 1 :
-1;
 }


Mime
View raw message