corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmke...@apache.org
Subject incubator-corinthia git commit: Make platform completely independent of core
Date Sat, 20 Dec 2014 10:39:27 GMT
Repository: incubator-corinthia
Updated Branches:
  refs/heads/master 614eabac2 -> 488f53b0b


Make platform completely independent of core

Remove the remaining uses of DFError from platform, as well as other
helper functions like DFAppendPathComponent. This has the (minor)
disadvantage that we have to do things like path appending manually -
and potentially other things in the future if they're added to platform
- but does mean that platform can be compiled & tested independently.

In place of DFError, we now just pass a pointer to a string which, if an
error occurs, will be set by a given function to the text of the error
message.


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

Branch: refs/heads/master
Commit: 488f53b0b77374df842f433dbded790616d4a78b
Parents: 614eaba
Author: Peter Kelly <peter@uxproductivity.com>
Authored: Sat Dec 20 17:36:49 2014 +0700
Committer: Peter Kelly <peter@uxproductivity.com>
Committed: Sat Dec 20 17:38:42 2014 +0700

----------------------------------------------------------------------
 DocFormats/core/src/lib/DFFilesystem.c          |  8 ++-
 .../filters/ooxml/src/word/lenses/WordDrawing.c |  8 ++-
 DocFormats/platform/CMakeLists.txt              | 21 +-------
 DocFormats/platform/headers/DFPlatform.h        |  6 +--
 DocFormats/platform/src/Apple.c                 |  3 +-
 DocFormats/platform/src/Linux.c                 |  6 +--
 DocFormats/platform/src/Unix.c                  | 22 ++++++---
 DocFormats/platform/src/Win32.c                 | 51 ++++++++------------
 8 files changed, 54 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/488f53b0/DocFormats/core/src/lib/DFFilesystem.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/lib/DFFilesystem.c b/DocFormats/core/src/lib/DFFilesystem.c
index b5da8ec..e4d4ab7 100644
--- a/DocFormats/core/src/lib/DFFilesystem.c
+++ b/DocFormats/core/src/lib/DFFilesystem.c
@@ -52,10 +52,14 @@ int DFCreateDirectory(const char *path, int intermediates, DFError **error)
             if (pos == 0)
                 continue;
             char *partial = DFSubstring(path,0,pos);
-            int ok = DFMkdirIfAbsent(partial,error);
+            char *errmsg = NULL;
+            int ok = DFMkdirIfAbsent(partial,&errmsg);
             free(partial);
-            if (!ok)
+            if (!ok) {
+                DFErrorFormat(error,"%s",errmsg);
+                free(errmsg);
                 return 0;
+            }
         }
     }
     return 1;

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/488f53b0/DocFormats/filters/ooxml/src/word/lenses/WordDrawing.c
----------------------------------------------------------------------
diff --git a/DocFormats/filters/ooxml/src/word/lenses/WordDrawing.c b/DocFormats/filters/ooxml/src/word/lenses/WordDrawing.c
index f48f5a3..83de7c1 100644
--- a/DocFormats/filters/ooxml/src/word/lenses/WordDrawing.c
+++ b/DocFormats/filters/ooxml/src/word/lenses/WordDrawing.c
@@ -404,7 +404,13 @@ static int getImageFile(WordConverter *converter, const char *unescapedSrc,
Pixe
     if (imageData == NULL)
         goto end;
 
-    ok = DFGetImageDimensions(imageData->data,imageData->len,ext,&size->widthPx,&size->heightPx,error);
+    char *errmsg = NULL;
+    ok = DFGetImageDimensions(imageData->data,imageData->len,ext,&size->widthPx,&size->heightPx,&errmsg);
+    if (!ok) {
+        DFErrorFormat(error,"%s",errmsg);
+        free(errmsg);
+    }
+
 end:
     DFBufferRelease(imageData);
     free(ext);

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/488f53b0/DocFormats/platform/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/DocFormats/platform/CMakeLists.txt b/DocFormats/platform/CMakeLists.txt
index 1b8101f..caf7df8 100644
--- a/DocFormats/platform/CMakeLists.txt
+++ b/DocFormats/platform/CMakeLists.txt
@@ -1,24 +1,5 @@
-include_directories(/usr/include/libxml2)
-include_directories(../../DocFormats/3rdparty/external/w3c-tidy-html5/include)
-include_directories(../../DocFormats/3rdparty/external/w3c-tidy-html5/src)
-include_directories(../../DocFormats/3rdparty/external/minizip)
-
 include_directories(SYSTEM ${INCLUDE_DIRS})
-include_directories(SYSTEM ../api/headers)
-include_directories(..)
-include_directories(../platform/headers)
-include_directories(../core/src/common)
-include_directories(../core/src/css)
-include_directories(../core/src/html)
-include_directories(../core/src/lib)
-include_directories(../core/src/names)
-include_directories(../core/src/xml)
-include_directories(../filters/latex/src)
-include_directories(../filters/odf/src)
-include_directories(../filters/ooxml/src/common)
-include_directories(../filters/ooxml/src/word)
-include_directories(../filters/ooxml/src/word/formatting)
-include_directories(../filters/ooxml/src/word/lenses)
+include_directories(headers)
 include_directories(../unittest)
 
 set(GroupHeaders

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/488f53b0/DocFormats/platform/headers/DFPlatform.h
----------------------------------------------------------------------
diff --git a/DocFormats/platform/headers/DFPlatform.h b/DocFormats/platform/headers/DFPlatform.h
index 8f858cc..a14350d 100755
--- a/DocFormats/platform/headers/DFPlatform.h
+++ b/DocFormats/platform/headers/DFPlatform.h
@@ -15,8 +15,6 @@
 #ifndef DocFormats_DFPlatform_h
 #define DocFormats_DFPlatform_h
 
-#include <DocFormats/DFError.h>
-#include "DFArray.h"
 #include <stddef.h>
 
 typedef struct DFDirEntryList DFDirEntryList;
@@ -26,10 +24,10 @@ struct DFDirEntryList {
     DFDirEntryList *next;
 };
 
-int DFMkdirIfAbsent(const char *path, DFError **error);
+int DFMkdirIfAbsent(const char *path, char **errmsg);
 int DFAddDirContents(const char *absPath, const char *relPath, int recursive, DFDirEntryList
***list, char **errmsg);
 int DFGetImageDimensions(const void *data, size_t len, const char *ext,
-                         unsigned int *width, unsigned int *height, DFError **error);
+                         unsigned int *width, unsigned int *height, char **errmsg);
 
 #define DF_ONCE_INIT 0
 typedef int DFOnce;

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/488f53b0/DocFormats/platform/src/Apple.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Apple.c b/DocFormats/platform/src/Apple.c
index 6de1b38..3c9d130 100644
--- a/DocFormats/platform/src/Apple.c
+++ b/DocFormats/platform/src/Apple.c
@@ -12,7 +12,6 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#include "DFCommon.h"
 #include "DFPlatform.h"
 
 // This file contains functions that are applicable to iOS and OS X
@@ -22,7 +21,7 @@
 #include <ImageIO/ImageIO.h>
 
 int DFGetImageDimensions(const void *data, size_t len, const char *ext,
-                         unsigned int *width, unsigned int *height, DFError **error)
+                         unsigned int *width, unsigned int *height, char **errmsg)
 {
     // FIXME: Should use ext here to determine the UTI, and pass that in the options directory
     // (the second parameter to CGImageSourceCreateWithData)

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/488f53b0/DocFormats/platform/src/Linux.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Linux.c b/DocFormats/platform/src/Linux.c
index 774908d..5d93518 100644
--- a/DocFormats/platform/src/Linux.c
+++ b/DocFormats/platform/src/Linux.c
@@ -12,7 +12,6 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#include "DFCommon.h"
 #include "DFPlatform.h"
 
 // This file contains functions that are applicable to Linux (or more generally, any non-Apple
Unix platform)
@@ -23,11 +22,12 @@
 #include <SDL2/SDL_image.h>
 
 int DFGetImageDimensions(const void *data, size_t len, const char *ext,
-                         unsigned int *width, unsigned int *height, DFError **error)
+                         unsigned int *width, unsigned int *height, char **errmsg)
 {
     SDL_Surface *image = IMG_Load_RW(SDL_RWFromMem((void *)data,len),1);
     if (image == NULL) {
-        DFErrorFormat(error,"%s",IMG_GetError());
+        if (errmsg != NULL)
+            *errmsg = strdup(IMG_GetError());
         return 0;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/488f53b0/DocFormats/platform/src/Unix.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Unix.c b/DocFormats/platform/src/Unix.c
index 27c7019..00c8438 100644
--- a/DocFormats/platform/src/Unix.c
+++ b/DocFormats/platform/src/Unix.c
@@ -12,10 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#include "DFCommon.h"
 #include "DFPlatform.h"
-#include "DFFilesystem.h"
-#include "DFString.h"
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
@@ -45,10 +42,12 @@ void DFInitOnce(DFOnce *once, DFOnceFunction fun)
         fun();
 }
 
-int DFMkdirIfAbsent(const char *path, DFError **error)
+int DFMkdirIfAbsent(const char *path, char **errmsg)
 {
     if ((mkdir(path,0777) != 0) && (errno != EEXIST)) {
-        DFErrorSetPosix(error,errno);
+        printf("DFMkdirIfAbsent: errno = %d (%s)\n",errno,strerror(errno));
+        if (errmsg != NULL)
+            *errmsg = strdup(strerror(errno));
         return 0;
     }
     return 1;
@@ -75,8 +74,14 @@ int DFAddDirContents(const char *absPath, const char *relPath, int recursive,
DF
         if (!strcmp(result->d_name,".") || !strcmp(result->d_name,".."))
             continue;
 
-        char *absSubPath = DFAppendPathComponent(absPath,result->d_name);
-        char *relSubPath = DFAppendPathComponent(relPath,result->d_name);
+        size_t absSubPathLen = strlen(absPath) + 1 + strlen(result->d_name);
+        size_t relSubPathLen = strlen(relPath) + 1 + strlen(result->d_name);
+
+        char *absSubPath = (char *)malloc(absSubPathLen+1);
+        char *relSubPath = (char *)malloc(relSubPathLen+1);
+
+        snprintf(absSubPath,absSubPathLen+1,"%s/%s",absPath,result->d_name);
+        snprintf(relSubPath,relSubPathLen+1,"%s/%s",relPath,result->d_name);
 
         char *entryName;
         if (relSubPath[0] == '/')
@@ -88,7 +93,8 @@ int DFAddDirContents(const char *absPath, const char *relPath, int recursive,
DF
         (*listptr)->name = strdup(entryName);
         listptr = &(*listptr)->next;
 
-        if (recursive && DFIsDirectory(absSubPath))
+        struct stat statbuf;
+        if (recursive && (0 == stat(absSubPath,&statbuf)) && S_ISDIR(statbuf.st_mode))
             ok = DFAddDirContents(absSubPath,relSubPath,recursive,&listptr,errmsg);
 
         free(absSubPath);

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/488f53b0/DocFormats/platform/src/Win32.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Win32.c b/DocFormats/platform/src/Win32.c
index 9aeda88..aa918da 100755
--- a/DocFormats/platform/src/Win32.c
+++ b/DocFormats/platform/src/Win32.c
@@ -12,10 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#include "DFCommon.h"
 #include "DFPlatform.h"
-#include "DFFilesystem.h"
-#include "DFString.h"
 
 // This file contains functions that are applicable to Windows
 
@@ -25,27 +22,9 @@
 #include <SDL_image.h>
 #include <stdio.h>
 
-void DFErrorSetWin32(DFError **error, DWORD code)
-{
-    char *lpMsgBuf;
-    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
-                  FORMAT_MESSAGE_FROM_SYSTEM |
-                  FORMAT_MESSAGE_IGNORE_INSERTS,
-                  NULL,
-                  code,
-                  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                  (LPTSTR)&lpMsgBuf,
-                  0, NULL);
-    size_t len = strlen(lpMsgBuf);
-    while ((len > 0) &&
-           ((lpMsgBuf[len - 1] == '\n') ||
-            (lpMsgBuf[len - 1] == '\r') ||
-            (lpMsgBuf[len - 1] == '.')))
-        len--;
-    lpMsgBuf[len] = '\0';
-    DFErrorFormat(error, "%s", lpMsgBuf);
-    LocalFree(lpMsgBuf);
-}
+#ifndef snprintf
+#define snprintf _snprintf
+#endif
 
 void DFErrorMsgSetWin32(char **errmsg, DWORD code)
 {
@@ -97,10 +76,10 @@ void DFInitOnce(DFOnce *once, DFOnceFunction fun)
         fun();
 }
 
-int DFMkdirIfAbsent(const char *path,DFError **error)
+int DFMkdirIfAbsent(const char *path, char **errmsg)
 {
     if (!CreateDirectory(path,NULL) && (GetLastError() != ERROR_ALREADY_EXISTS))
{
-        DFErrorSetWin32(error,GetLastError());
+        DFErrorMsgSetWin32(errmsg,GetLastError());
         return 0;
     }
     return 1;
@@ -111,7 +90,10 @@ int DFAddDirContents(const char *absPath, const char *relPath, int recursive,
DF
     DFDirEntryList **listptr = *list;
     WIN32_FIND_DATA ffd;
     HANDLE hFind = INVALID_HANDLE_VALUE;
-    char *pattern = DFFormatString("%s/*",absPath);
+
+    size_t patternLen = strlen(absPath) + 2;
+    char *pattern = (char *)malloc(patternLen+1);
+    snprintf(pattern,patternLen+1,"%s/*",absPath);
     hFind = FindFirstFile(pattern,&ffd);
     if (hFind == INVALID_HANDLE_VALUE) {
         DFErrorMsgSetWin32(errmsg,GetLastError());
@@ -124,8 +106,14 @@ int DFAddDirContents(const char *absPath, const char *relPath, int recursive,
DF
         if (!strcmp(ffd.cFileName,".") || !strcmp(ffd.cFileName,".."))
             continue;
 
-        char *absSubPath = DFAppendPathComponent(absPath,ffd.cFileName);
-        char *relSubPath = DFAppendPathComponent(relPath,ffd.cFileName);
+        size_t absSubPathLen = strlen(absPath) + 1 + strlen(ffd.cFileName);
+        size_t relSubPathLen = strlen(relPath) + 1 + strlen(ffd.cFileName);
+
+        char *absSubPath = (char *)malloc(absSubPathLen+1);
+        char *relSubPath = (char *)malloc(relSubPathLen+1);
+
+        snprintf(absSubPath,absSubPathLen+1,"%s/%s",absPath,ffd.cFileName);
+        snprintf(relSubPath,relSubPathLen+1,"%s/%s",relPath,ffd.cFileName);
 
         char *entryName;
         if (relSubPath[0] == '/')
@@ -151,11 +139,12 @@ int DFAddDirContents(const char *absPath, const char *relPath, int recursive,
DF
 }
 
 int DFGetImageDimensions(const void *data, size_t len, const char *ext,
-                         unsigned int *width, unsigned int *height, DFError **error)
+                         unsigned int *width, unsigned int *height, char **errmsg)
 {
     SDL_Surface *image = IMG_Load_RW(SDL_RWFromMem((void *)data,len),1);
     if (image == NULL) {
-        DFErrorFormat(error,"%s",IMG_GetError());
+        if (errmsg != NULL)
+            *errmsg = strdup(IMG_GetError());
         return 0;
     }
 


Mime
View raw message