Fix for icon generation with MSVC
authorCampbell Barton <ideasman42@gmail.com>
Tue, 14 Jan 2014 21:38:00 +0000 (08:38 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 14 Jan 2014 21:40:56 +0000 (08:40 +1100)
Big thanks to Gaia for getting this working!

source/blender/blenlib/CMakeLists.txt
source/blender/blenlib/intern/winstuff.c
source/blender/blenlib/intern/winstuff_dir.c [new file with mode: 0644]
source/blender/datatoc/CMakeLists.txt
source/blender/datatoc/datatoc_icon.c

index 00adb375c417ee5d5df811a1973fe1fadb2c00cd..2a920a2e5fd54b67a1c2a483589e4d1f216f6c7b 100644 (file)
@@ -102,6 +102,7 @@ set(SRC
        intern/voronoi.c
        intern/voxel.c
        intern/winstuff.c
+       intern/winstuff_dir.c
 
        BLI_alloca.h
        BLI_args.h
index b0572156d00abbc4fe3305f9e191c0f526072260..af0ab1937d5035235ea2f18d4ac200d6d76cd644 100644 (file)
@@ -172,90 +172,6 @@ void RegisterBlendExtension(void)
        TerminateProcess(GetCurrentProcess(), 0);
 }
 
-DIR *opendir(const char *path)
-{
-       wchar_t *path_16 = alloc_utf16_from_8(path, 0);
-
-       if (GetFileAttributesW(path_16) & FILE_ATTRIBUTE_DIRECTORY) {
-               DIR *newd = MEM_mallocN(sizeof(DIR), "opendir");
-
-               newd->handle = INVALID_HANDLE_VALUE;
-               sprintf(newd->path, "%s\\*", path);
-               
-               newd->direntry.d_ino = 0;
-               newd->direntry.d_off = 0;
-               newd->direntry.d_reclen = 0;
-               newd->direntry.d_name = NULL;
-               
-               free(path_16);
-               return newd;
-       }
-       else {
-               free(path_16);
-               return NULL;
-       }
-}
-
-static char *BLI_alloc_utf_8_from_16(wchar_t *in16, size_t add)
-{
-       size_t bsize = count_utf_8_from_16(in16);
-       char *out8 = NULL;
-       if (!bsize) return NULL;
-       out8 = (char *)MEM_mallocN(sizeof(char) * (bsize + add), "UTF-8 String");
-       conv_utf_16_to_8(in16, out8, bsize);
-       return out8;
-}
-
-static wchar_t *UNUSED_FUNCTION(BLI_alloc_utf16_from_8) (char *in8, size_t add)
-{
-       size_t bsize = count_utf_16_from_8(in8);
-       wchar_t *out16 = NULL;
-       if (!bsize) return NULL;
-       out16 = (wchar_t *) MEM_mallocN(sizeof(wchar_t) * (bsize + add), "UTF-16 String");
-       conv_utf_8_to_16(in8, out16, bsize);
-       return out16;
-}
-
-
-
-struct dirent *readdir(DIR *dp)
-{
-       if (dp->direntry.d_name) {
-               MEM_freeN(dp->direntry.d_name);
-               dp->direntry.d_name = NULL;
-       }
-               
-       if (dp->handle == INVALID_HANDLE_VALUE) {
-               wchar_t *path_16 = alloc_utf16_from_8(dp->path, 0);
-               dp->handle = FindFirstFileW(path_16, &(dp->data));
-               free(path_16);
-               if (dp->handle == INVALID_HANDLE_VALUE)
-                       return NULL;
-                       
-               dp->direntry.d_name = BLI_alloc_utf_8_from_16(dp->data.cFileName, 0);
-               
-               return &dp->direntry;
-       }
-       else if (FindNextFileW(dp->handle, &(dp->data))) {
-               dp->direntry.d_name = BLI_alloc_utf_8_from_16(dp->data.cFileName, 0);
-
-               return &dp->direntry;
-       }
-       else {
-               return NULL;
-       }
-}
-
-int closedir(DIR *dp)
-{
-       if (dp->direntry.d_name) MEM_freeN(dp->direntry.d_name);
-       if (dp->handle != INVALID_HANDLE_VALUE) FindClose(dp->handle);
-
-       MEM_freeN(dp);
-       
-       return 0;
-}
-
 void get_default_root(char *root)
 {
        char str[MAX_PATH + 1];
@@ -330,32 +246,6 @@ int check_file_chars(char *filename)
        return 1;
 }
 
-/* Copied from http://sourceware.org/ml/newlib/2005/msg00248.html */
-/* Copyright 2005 Shaun Jackman
- * Permission to use, copy, modify, and distribute this software
- * is freely granted, provided that this notice is preserved.
- */
-#include <string.h>
-const char *dirname(char *path)
-{
-       char *p;
-       if (path == NULL || *path == '\0')
-               return ".";
-       p = path + strlen(path) - 1;
-       while (*p == '/') {
-               if (p == path)
-                       return path;
-               *p-- = '\0';
-       }
-       while (p >= path && *p != '/')
-               p--;
-       return
-           p < path ? "." :
-           p == path ? "/" :
-           (*p = '\0', path);
-}
-/* End of copied part */
-
 #else
 
 /* intentionally empty for UNIX */
diff --git a/source/blender/blenlib/intern/winstuff_dir.c b/source/blender/blenlib/intern/winstuff_dir.c
new file mode 100644 (file)
index 0000000..5ca6cfe
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ * Windows-posix compatibility layer for opendir/readdir/closedir
+ */
+
+/** \file blender/blenlib/intern/winstuff.c
+ *  \ingroup bli
+ */
+
+#ifdef WIN32
+
+#  ifdef USE_STANDALONE
+#    define MEM_mallocN(size, str) ((void)str, malloc(size))
+#    define MEM_callocN(size, str) ((void)str, calloc(size, 1))
+#    define MEM_freeN(ptr) free(ptr)
+#  else
+#    include "MEM_guardedalloc.h"
+#  endif
+
+#define WIN32_SKIP_HKEY_PROTECTION      // need to use HKEY
+#include "BLI_winstuff.h"
+#include "utfconv.h"
+
+DIR *opendir(const char *path)
+{
+       wchar_t *path_16 = alloc_utf16_from_8(path, 0);
+
+       if (GetFileAttributesW(path_16) & FILE_ATTRIBUTE_DIRECTORY) {
+               DIR *newd = MEM_mallocN(sizeof(DIR), "opendir");
+
+               newd->handle = INVALID_HANDLE_VALUE;
+               sprintf(newd->path, "%s\\*", path);
+               
+               newd->direntry.d_ino = 0;
+               newd->direntry.d_off = 0;
+               newd->direntry.d_reclen = 0;
+               newd->direntry.d_name = NULL;
+               
+               free(path_16);
+               return newd;
+       }
+       else {
+               free(path_16);
+               return NULL;
+       }
+}
+
+static char *BLI_alloc_utf_8_from_16(wchar_t *in16, size_t add)
+{
+       size_t bsize = count_utf_8_from_16(in16);
+       char *out8 = NULL;
+       if (!bsize) return NULL;
+       out8 = (char *)MEM_mallocN(sizeof(char) * (bsize + add), "UTF-8 String");
+       conv_utf_16_to_8(in16, out8, bsize);
+       return out8;
+}
+
+static wchar_t *UNUSED_FUNCTION(BLI_alloc_utf16_from_8) (char *in8, size_t add)
+{
+       size_t bsize = count_utf_16_from_8(in8);
+       wchar_t *out16 = NULL;
+       if (!bsize) return NULL;
+       out16 = (wchar_t *) MEM_mallocN(sizeof(wchar_t) * (bsize + add), "UTF-16 String");
+       conv_utf_8_to_16(in8, out16, bsize);
+       return out16;
+}
+
+
+
+struct dirent *readdir(DIR *dp)
+{
+       if (dp->direntry.d_name) {
+               MEM_freeN(dp->direntry.d_name);
+               dp->direntry.d_name = NULL;
+       }
+               
+       if (dp->handle == INVALID_HANDLE_VALUE) {
+               wchar_t *path_16 = alloc_utf16_from_8(dp->path, 0);
+               dp->handle = FindFirstFileW(path_16, &(dp->data));
+               free(path_16);
+               if (dp->handle == INVALID_HANDLE_VALUE)
+                       return NULL;
+                       
+               dp->direntry.d_name = BLI_alloc_utf_8_from_16(dp->data.cFileName, 0);
+               
+               return &dp->direntry;
+       }
+       else if (FindNextFileW(dp->handle, &(dp->data))) {
+               dp->direntry.d_name = BLI_alloc_utf_8_from_16(dp->data.cFileName, 0);
+
+               return &dp->direntry;
+       }
+       else {
+               return NULL;
+       }
+}
+
+int closedir(DIR *dp)
+{
+       if (dp->direntry.d_name) MEM_freeN(dp->direntry.d_name);
+       if (dp->handle != INVALID_HANDLE_VALUE) FindClose(dp->handle);
+
+       MEM_freeN(dp);
+       
+       return 0;
+}
+
+/* End of copied part */
+
+#else
+
+/* intentionally empty for UNIX */
+
+#endif
index a1776c312f4e962a9f5204f7fb6c6e76c548806c..53fe8c32e9c0d542d5cd6985529e04564bb9210b 100644 (file)
@@ -38,6 +38,21 @@ if(NOT WITH_HEADLESS)
                datatoc_icon.c
        )
 
+       if(WIN32)
+               include_directories(
+                       ../blenlib
+                       ../../../intern/utfconv
+               )
+
+               # for winstuff_dir.c
+               add_definitions(-DUSE_STANDALONE)
+
+               list(APPEND SRC
+                       ../blenlib/intern/winstuff_dir.c
+                       ../../../intern/utfconv/utfconv.c
+               )
+       endif()
+
        include_directories(${PNG_INCLUDE_DIR})
        link_directories(${PNG_LIBPATH} ${ZLIB_LIBPATH})
 
index 1569e554f9f294d7b8795d1dbd4704f615e4fe26..e4b00388dbac28c9cb7b505d7aea22e1a936c769 100644 (file)
 
 #include "png.h"
 
+
+/* for Win32 DIR functions */
+#ifdef WIN32
+#  include "../blenlib/BLI_winstuff.h"
+#endif
+
 #ifdef WIN32
 #  define SEP '\\'
 #else