Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-10-24 11:56:42 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-10-24 11:56:42 +0400
commitad1d3dd30fa5f4c33279679e3824899fd18801b8 (patch)
treecef4de1e42c5a8a2a1f68719452891c19a065ab7 /source/blender/blenlib
parent77a7ec7c61965efa9e2e82894c821fe5c937b989 (diff)
parent1bdf652b89871614c38bf2146cf94522c3347e06 (diff)
svn merge ^/trunk/blender -r41175:41200 --- will need to apply fix after
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_blenlib.h11
-rw-r--r--source/blender/blenlib/BLI_edgehash.h2
-rw-r--r--source/blender/blenlib/BLI_fileops.h65
-rw-r--r--source/blender/blenlib/BLI_fileops_types.h (renamed from source/blender/blenlib/BLI_storage_types.h)9
-rw-r--r--source/blender/blenlib/BLI_path_util.h52
-rw-r--r--source/blender/blenlib/BLI_scanfill.h2
-rw-r--r--source/blender/blenlib/BLI_storage.h82
-rw-r--r--source/blender/blenlib/BLI_utildefines.h227
-rw-r--r--source/blender/blenlib/CMakeLists.txt3
-rw-r--r--source/blender/blenlib/intern/fileops.c51
-rw-r--r--source/blender/blenlib/intern/path_util.c100
-rw-r--r--source/blender/blenlib/intern/storage.c35
12 files changed, 334 insertions, 305 deletions
diff --git a/source/blender/blenlib/BLI_blenlib.h b/source/blender/blenlib/BLI_blenlib.h
index cda7a51c47f..356709d5ccd 100644
--- a/source/blender/blenlib/BLI_blenlib.h
+++ b/source/blender/blenlib/BLI_blenlib.h
@@ -64,8 +64,6 @@ struct ListBase;
#include <stdlib.h>
-extern char btempdir[]; /* creator.c temp dir used instead of U.tempdir, set with BLI_where_is_temp( btempdir, 1 ); */
-
#ifdef __cplusplus
extern "C" {
#endif
@@ -78,21 +76,12 @@ extern "C" {
#include "BLI_path_util.h"
-#include "BLI_storage.h"
-
#include "BLI_fileops.h"
#include "BLI_rect.h"
#include "BLI_noise.h"
-/**
- * @param strct The structure of interest
- * @param member The name of a member field of @a strct
- * @retval The offset in bytes of @a member within @a strct
- */
-#define BLI_STRUCT_OFFSET(strct, member) ((int)(intptr_t) &((strct*) 0)->member)
-
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenlib/BLI_edgehash.h b/source/blender/blenlib/BLI_edgehash.h
index 4cb65b8dd12..5108c48c0c6 100644
--- a/source/blender/blenlib/BLI_edgehash.h
+++ b/source/blender/blenlib/BLI_edgehash.h
@@ -30,7 +30,7 @@
#ifndef BLI_EDGEHASH_H
#define BLI_EDGEHASH_H
-/** \file BLI_storage.h
+/** \file BLI_edgehash.h
* \ingroup bli
* \author Daniel Dunbar
* \brief A general unordered 2-int pair hash table ADT.
diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h
index e94e2693844..ebe231e2973 100644
--- a/source/blender/blenlib/BLI_fileops.h
+++ b/source/blender/blenlib/BLI_fileops.h
@@ -29,10 +29,7 @@
/** \file BLI_fileops.h
* \ingroup bli
- * \author Daniel Dunbar
- * \brief More low-level fileops from Daniel Dunbar. Two functions were also
- * defined in storage.c. These are the old fop_ prefixes. There is
- * definitely some redundancy here!
+ * \brief File and directory operations.
* */
#ifndef BLI_FILEOPS_H
@@ -42,26 +39,48 @@
extern "C" {
#endif
-void BLI_recurdir_fileops(const char *dirname);
-int BLI_link(const char *file, const char *to);
-int BLI_is_writable(const char *filename);
+#include "BLI_fileops_types.h"
-/**
- * @attention Do not confuse with BLI_exist [joeedh--yet, it calls BLI_exist?]
- */
-int BLI_exists(const char *file);
-int BLI_copy_fileops(const char *file, const char *to);
-int BLI_rename(const char *from, const char *to);
-int BLI_gzip(const char *from, const char *to);
-char *BLI_ungzip_to_mem(const char *from_file, int *size_r);
-int BLI_delete(const char *file, int dir, int recursive);
-int BLI_move(const char *file, const char *to);
-int BLI_touch(const char *file);
-
-/* only for the sane unix world: direct calls to system functions :( */
-#ifndef WIN32
-void BLI_setCmdCallBack(int (*f)(char*));
-#endif
+/* for size_t (needed on windows) */
+#include <stddef.h>
+
+/* Common */
+
+int BLI_exists(const char *path);
+int BLI_copy(const char *path, const char *to);
+int BLI_rename(const char *from, const char *to);
+int BLI_delete(const char *path, int dir, int recursive);
+int BLI_move(const char *path, const char *to);
+int BLI_create_symlink(const char *path, const char *to);
+
+/* Directories */
+
+struct direntry;
+
+int BLI_is_dir(const char *path);
+void BLI_dir_create_recursive(const char *dir);
+double BLI_dir_free_space(const char *dir);
+char *BLI_current_working_dir(char *dir, const int maxlen);
+
+unsigned int BLI_dir_contents(const char *dir, struct direntry **filelist);
+
+/* Files */
+
+int BLI_file_is_writable(const char *file);
+int BLI_file_touch(const char *file);
+
+int BLI_file_gzip(const char *from, const char *to);
+char *BLI_file_ungzip_to_mem(const char *from_file, int *size_r);
+
+size_t BLI_file_descriptor_size(int file);
+size_t BLI_file_size(const char *file);
+
+ /* compare if one was last modified before the other */
+int BLI_file_older(const char *file1, const char *file2);
+
+ /* read ascii file as lines, empty list if reading fails */
+struct LinkNode *BLI_file_read_as_lines(const char *file);
+void BLI_file_free_lines(struct LinkNode *lines);
#ifdef __cplusplus
}
diff --git a/source/blender/blenlib/BLI_storage_types.h b/source/blender/blenlib/BLI_fileops_types.h
index 07c0ceffeb5..58dcf1a5441 100644
--- a/source/blender/blenlib/BLI_storage_types.h
+++ b/source/blender/blenlib/BLI_fileops_types.h
@@ -26,10 +26,11 @@
*
* ***** END GPL LICENSE BLOCK *****
*/
-#ifndef BLI_STORAGE_TYPES_H
-#define BLI_STORAGE_TYPES_H
-/** \file BLI_storage_types.h
+#ifndef BLI_FILEOPS_TYPES_H
+#define BLI_FILEOPS_TYPES_H
+
+/** \file BLI_fileops_types.h
* \ingroup bli
* \brief Some types for dealing with directories.
*/
@@ -75,5 +76,5 @@ struct dirlink
char *name;
};
-#endif /* BLI_STORAGE_TYPES_H */
+#endif /* BLI_FILEOPS_TYPES_H */
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h
index 9ccdc37c353..82794e08fa0 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -65,10 +65,6 @@ char *BLI_get_folder_version(const int id, const int ver, const int do_check);
#define BLENDER_SYSTEM_PLUGINS 54
#define BLENDER_SYSTEM_PYTHON 54
-#define BLENDER_TEMP 80
-
-#define BLENDER_USERFOLDER(id) (id >= BLENDER_USER_CONFIG && id <= BLENDER_USER_PLUGINS)
-
/* for BLI_get_folder_version only */
#define BLENDER_RESOURCE_PATH_USER 0
#define BLENDER_RESOURCE_PATH_LOCAL 1
@@ -79,17 +75,6 @@ char *BLI_get_folder_version(const int id, const int ver, const int do_check);
#define BLENDER_HISTORY_FILE "recent-files.txt"
#ifdef WIN32
-#define BLENDER_USER_FORMAT "%s\\Blender Foundation\\Blender\\%s"
-#define BLENDER_SYSTEM_FORMAT "%s\\Blender Foundation\\Blender\\%s"
-#elif defined(__APPLE__)
-#define BLENDER_USER_FORMAT "%s/Blender/%s"
-#define BLENDER_SYSTEM_FORMAT "%s/Blender/%s"
-#else
-#define BLENDER_USER_FORMAT "%s/.blender/%s"
-#define BLENDER_SYSTEM_FORMAT "%s/blender/%s"
-#endif
-
-#ifdef WIN32
#define SEP '\\'
#define ALTSEP '/'
#else
@@ -181,29 +166,20 @@ void BLI_path_rel(char *file, const char *relfile);
*/
void BLI_char_switch(char *string, char from, char to);
-/**
- * Checks if name is a fully qualified filename to an executable.
- * If not it searches $PATH for the file. On Windows it also
- * adds the correct extension (.com .exe etc) from
- * $PATHEXT if necessary. Also on Windows it translates
- * the name to its 8.3 version to prevent problems with
- * spaces and stuff. Final result is returned in fullname.
- *
- * @param fullname The full path and full name of the executable
- * @param name The name of the executable (usually argv[0]) to be checked
- */
-void BLI_where_am_i(char *fullname, const size_t maxlen, const char *name);
-
- /**
- * Gets the temp directory when blender first runs.
- * If the default path is not found, use try $TEMP
- *
- * Also make sure the temp dir has a trailing slash
- *
- * @param fullname The full path to the temp directory
- */
-void BLI_where_is_temp(char *fullname, const size_t maxlen, int usertemp);
-
+ /* Initialize path to program executable */
+void BLI_init_program_path(const char *argv0);
+ /* Initialize path to temporary directory.
+ * NOTE: On Window userdir will be set to the temporary directory! */
+void BLI_init_temporary_dir(char *userdir);
+
+ /* Path to executable */
+const char *BLI_program_path(void);
+ /* Path to directory of executable */
+const char *BLI_program_dir(void);
+ /* Path to temporary directory (with trailing slash) */
+const char *BLI_temporary_dir(void);
+ /* Path to the system temporary directory (with trailing slash) */
+void BLI_system_temporary_dir(char *dir);
#ifdef WITH_ICONV
void BLI_string_to_utf8(char *original, char *utf_8, const char *code);
diff --git a/source/blender/blenlib/BLI_scanfill.h b/source/blender/blenlib/BLI_scanfill.h
index 0c5e6db1826..ceffedc2d37 100644
--- a/source/blender/blenlib/BLI_scanfill.h
+++ b/source/blender/blenlib/BLI_scanfill.h
@@ -30,7 +30,7 @@
#ifndef BLI_SCANFILL_H
#define BLI_SCANFILL_H
-/** \file BLI_storage.h
+/** \file BLI_scanfill.h
* \ingroup bli
* \since March 2001
* \author nzc
diff --git a/source/blender/blenlib/BLI_storage.h b/source/blender/blenlib/BLI_storage.h
deleted file mode 100644
index 017f9877baf..00000000000
--- a/source/blender/blenlib/BLI_storage.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/* $Id$
- *
- * ***** 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.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef BLI_STORAGE_H
-#define BLI_STORAGE_H
-
-/** \file BLI_storage.h
- * \ingroup bli
- */
-
-#ifdef WIN32
-/* for size_t, only needed on win32 for some reason */
-#include <stddef.h>
-#endif
-
-struct direntry;
-
-
-void BLI_adddirstrings(void);
-void BLI_builddir(const char *dirname, const char *relname);
-int BLI_compare(struct direntry *entry1, struct direntry *entry2);
-
-size_t BLI_filesize(int file);
-size_t BLI_filepathsize(const char *path);
-double BLI_diskfree(const char *dir);
-char *BLI_getwdN(char *dir, const int maxncpy);
-
-unsigned int BLI_getdir(const char *dirname, struct direntry **filelist);
-/**
- * @attention Do not confuse with BLI_exists
- */
-int BLI_exist(const char *name);
-/**
- * Read a file as ASCII lines. An empty list is
- * returned if the file cannot be opened or read.
- *
- * @attention The returned list should be free'd with
- * BLI_free_file_lines.
- *
- * @param name The name of the file to read.
- * @retval A list of strings representing the file lines.
- */
-
-int BLI_is_dir(const char *file);
-
-struct LinkNode *BLI_read_file_as_lines(const char *name);
-
- /**
- * Free the list returned by BLI_read_file_as_lines.
- */
-void BLI_free_file_lines(struct LinkNode *lines);
-
- /* Compare if one was last modified before the other */
-int BLI_file_older(const char *file1, const char *file2);
-
-#endif /* BLI_STORAGE_H */
-
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h
index f427be6baf5..ed750fe04d8 100644
--- a/source/blender/blenlib/BLI_utildefines.h
+++ b/source/blender/blenlib/BLI_utildefines.h
@@ -67,64 +67,113 @@
#define MAX3(x,y,z) MAX2( MAX2((x),(y)) , (z) )
#define MAX4(x,y,z,a) MAX2( MAX2((x),(y)) , MAX2((z),(a)) )
-#define INIT_MINMAX(min, max) { (min)[0]= (min)[1]= (min)[2]= 1.0e30f; (max)[0]= (max)[1]= (max)[2]= -1.0e30f; }
-
-#define INIT_MINMAX2(min, max) { (min)[0]= (min)[1]= 1.0e30f; (max)[0]= (max)[1]= -1.0e30f; }
-
-#define DO_MIN(vec, min) { if( (min)[0]>(vec)[0] ) (min)[0]= (vec)[0]; \
- if( (min)[1]>(vec)[1] ) (min)[1]= (vec)[1]; \
- if( (min)[2]>(vec)[2] ) (min)[2]= (vec)[2]; } \
-
-#define DO_MAX(vec, max) { if( (max)[0]<(vec)[0] ) (max)[0]= (vec)[0]; \
- if( (max)[1]<(vec)[1] ) (max)[1]= (vec)[1]; \
- if( (max)[2]<(vec)[2] ) (max)[2]= (vec)[2]; } \
-
-#define DO_MINMAX(vec, min, max) { if( (min)[0]>(vec)[0] ) (min)[0]= (vec)[0]; \
- if( (min)[1]>(vec)[1] ) (min)[1]= (vec)[1]; \
- if( (min)[2]>(vec)[2] ) (min)[2]= (vec)[2]; \
- if( (max)[0]<(vec)[0] ) (max)[0]= (vec)[0]; \
- if( (max)[1]<(vec)[1] ) (max)[1]= (vec)[1]; \
- if( (max)[2]<(vec)[2] ) (max)[2]= (vec)[2]; } \
-
-#define DO_MINMAX2(vec, min, max) { if( (min)[0]>(vec)[0] ) (min)[0]= (vec)[0]; \
- if( (min)[1]>(vec)[1] ) (min)[1]= (vec)[1]; \
- if( (max)[0]<(vec)[0] ) (max)[0]= (vec)[0]; \
- if( (max)[1]<(vec)[1] ) (max)[1]= (vec)[1]; }
+#define INIT_MINMAX(min, max) { \
+ (min)[0]= (min)[1]= (min)[2]= 1.0e30f; \
+ (max)[0]= (max)[1]= (max)[2]= -1.0e30f; \
+ }
+#define INIT_MINMAX2(min, max) { \
+ (min)[0]= (min)[1]= 1.0e30f; \
+ (max)[0]= (max)[1]= -1.0e30f; \
+ }
+#define DO_MIN(vec, min) { \
+ if( (min)[0]>(vec)[0] ) (min)[0]= (vec)[0]; \
+ if( (min)[1]>(vec)[1] ) (min)[1]= (vec)[1]; \
+ if( (min)[2]>(vec)[2] ) (min)[2]= (vec)[2]; \
+ }
+#define DO_MAX(vec, max) { \
+ if( (max)[0]<(vec)[0] ) (max)[0]= (vec)[0]; \
+ if( (max)[1]<(vec)[1] ) (max)[1]= (vec)[1]; \
+ if( (max)[2]<(vec)[2] ) (max)[2]= (vec)[2]; \
+ }
+#define DO_MINMAX(vec, min, max) { \
+ if( (min)[0]>(vec)[0] ) (min)[0]= (vec)[0]; \
+ if( (min)[1]>(vec)[1] ) (min)[1]= (vec)[1]; \
+ if( (min)[2]>(vec)[2] ) (min)[2]= (vec)[2]; \
+ if( (max)[0]<(vec)[0] ) (max)[0]= (vec)[0]; \
+ if( (max)[1]<(vec)[1] ) (max)[1]= (vec)[1]; \
+ if( (max)[2]<(vec)[2] ) (max)[2]= (vec)[2]; \
+ }
+#define DO_MINMAX2(vec, min, max) { \
+ if( (min)[0]>(vec)[0] ) (min)[0]= (vec)[0]; \
+ if( (min)[1]>(vec)[1] ) (min)[1]= (vec)[1]; \
+ if( (max)[0]<(vec)[0] ) (max)[0]= (vec)[0]; \
+ if( (max)[1]<(vec)[1] ) (max)[1]= (vec)[1]; \
+ }
/* some math and copy defines */
#ifndef SWAP
-# define SWAP(type, a, b) { type sw_ap; sw_ap=(a); (a)=(b); (b)=sw_ap; }
+# define SWAP(type, a, b) { type sw_ap; sw_ap=(a); (a)=(b); (b)=sw_ap; }
#endif
-#define ABS(a) ( (a)<0 ? (-(a)) : (a) )
-
-#define AVG2(x, y) ( 0.5 * ((x) + (y)) )
+#define ABS(a) ( (a)<0 ? (-(a)) : (a) )
#define FTOCHAR(val) ((val)<=0.0f)? 0 : (((val)>(1.0f-0.5f/255.0f))? 255 : (char)((255.0f*(val))+0.5f))
#define FTOUSHORT(val) ((val >= 1.0f-0.5f/65535)? 65535: (val <= 0.0f)? 0: (unsigned short)(val*65535.0f + 0.5f))
-#define F3TOCHAR3(v2,v1) (v1)[0]=FTOCHAR((v2[0])); (v1)[1]=FTOCHAR((v2[1])); (v1)[2]=FTOCHAR((v2[2]))
-#define F3TOCHAR4(v2,v1) { (v1)[0]=FTOCHAR((v2[0])); (v1)[1]=FTOCHAR((v2[1])); (v1)[2]=FTOCHAR((v2[2])); \
- (v1)[3] = 255; }
-#define F4TOCHAR4(v2,v1) { (v1)[0]=FTOCHAR((v2[0])); (v1)[1]=FTOCHAR((v2[1])); (v1)[2]=FTOCHAR((v2[2])); \
- (v1)[3]=FTOCHAR((v2[3])); }
-
-
-#define VECCOPY(v1,v2) {*(v1)= *(v2); *(v1+1)= *(v2+1); *(v1+2)= *(v2+2);}
-#define VECCOPY2D(v1,v2) {*(v1)= *(v2); *(v1+1)= *(v2+1);}
-#define QUATCOPY(v1,v2) {*(v1)= *(v2); *(v1+1)= *(v2+1); *(v1+2)= *(v2+2); *(v1+3)= *(v2+3);}
-#define LONGCOPY(a, b, c) {int lcpc=c, *lcpa=(int *)a, *lcpb=(int *)b; while(lcpc-->0) *(lcpa++)= *(lcpb++);}
-
-
-#define VECADD(v1,v2,v3) {*(v1)= *(v2) + *(v3); *(v1+1)= *(v2+1) + *(v3+1); *(v1+2)= *(v2+2) + *(v3+2);}
-#define VECSUB(v1,v2,v3) {*(v1)= *(v2) - *(v3); *(v1+1)= *(v2+1) - *(v3+1); *(v1+2)= *(v2+2) - *(v3+2);}
-#define VECSUB2D(v1,v2,v3) {*(v1)= *(v2) - *(v3); *(v1+1)= *(v2+1) - *(v3+1);}
-#define VECINTERP(v1,v2,v3, fac) {*(v1) = *(v2) + (*(v3)-*(v2))*(fac); *(v1+1) = *(v2+1) + (*(v3+1)-*(v2+1))*(fac); *(v1+2) = *(v2+2) + (*(v3+2)-*(v2+2))*(fac);}
-#define VECADDFAC(v1,v2,v3,fac) {*(v1)= *(v2) + *(v3)*(fac); *(v1+1)= *(v2+1) + *(v3+1)*(fac); *(v1+2)= *(v2+2) + *(v3+2)*(fac);}
-#define VECSUBFAC(v1,v2,v3,fac) {*(v1)= *(v2) - *(v3)*(fac); *(v1+1)= *(v2+1) - *(v3+1)*(fac); *(v1+2)= *(v2+2) - *(v3+2)*(fac);}
-#define QUATADDFAC(v1,v2,v3,fac) {*(v1)= *(v2) + *(v3)*(fac); *(v1+1)= *(v2+1) + *(v3+1)*(fac); *(v1+2)= *(v2+2) + *(v3+2)*(fac); *(v1+3)= *(v2+3) + *(v3+3)*(fac);}
-
-#define INPR(v1, v2) ( (v1)[0]*(v2)[0] + (v1)[1]*(v2)[1] + (v1)[2]*(v2)[2] )
+#define F3TOCHAR3(v2, v1) { \
+ (v1)[0]= FTOCHAR((v2[0])); \
+ (v1)[1]= FTOCHAR((v2[1])); \
+ (v1)[2]= FTOCHAR((v2[2])); \
+ }
+#define F3TOCHAR4(v2, v1) { \
+ (v1)[0]= FTOCHAR((v2[0])); \
+ (v1)[1]= FTOCHAR((v2[1])); \
+ (v1)[2]= FTOCHAR((v2[2])); \
+ (v1)[3]= 255; \
+ }
+#define F4TOCHAR4(v2, v1) { \
+ (v1)[0]= FTOCHAR((v2[0])); \
+ (v1)[1]= FTOCHAR((v2[1])); \
+ (v1)[2]= FTOCHAR((v2[2])); \
+ (v1)[3]= FTOCHAR((v2[3])); \
+ }
+#define VECCOPY(v1, v2) { \
+ *(v1)= *(v2); \
+ *(v1+1)= *(v2+1); \
+ *(v1+2)= *(v2+2); \
+ }
+#define VECCOPY2D(v1, v2) { \
+ *(v1)= *(v2); \
+ *(v1+1)= *(v2+1); \
+ }
+#define QUATCOPY(v1, v2) { \
+ *(v1)= *(v2); \
+ *(v1+1)= *(v2+1); \
+ *(v1+2)= *(v2+2); \
+ *(v1+3)= *(v2+3); \
+ }
+#define VECADD(v1,v2,v3) { \
+ *(v1)= *(v2) + *(v3); \
+ *(v1+1)= *(v2+1) + *(v3+1); \
+ *(v1+2)= *(v2+2) + *(v3+2); \
+ }
+#define VECSUB(v1,v2,v3) { \
+ *(v1)= *(v2) - *(v3); \
+ *(v1+1)= *(v2+1) - *(v3+1); \
+ *(v1+2)= *(v2+2) - *(v3+2); \
+ }
+#define VECSUB2D(v1,v2,v3) { \
+ *(v1)= *(v2) - *(v3); \
+ *(v1+1)= *(v2+1) - *(v3+1); \
+ }
+#define VECADDFAC(v1,v2,v3,fac) { \
+ *(v1)= *(v2) + *(v3)*(fac); \
+ *(v1+1)= *(v2+1) + *(v3+1)*(fac); \
+ *(v1+2)= *(v2+2) + *(v3+2)*(fac); \
+ }
+#define VECSUBFAC(v1,v2,v3,fac) { \
+ *(v1)= *(v2) - *(v3)*(fac); \
+ *(v1+1)= *(v2+1) - *(v3+1)*(fac); \
+ *(v1+2)= *(v2+2) - *(v3+2)*(fac); \
+ }
+#define QUATADDFAC(v1,v2,v3,fac) { \
+ *(v1)= *(v2) + *(v3)*(fac); \
+ *(v1+1)= *(v2+1) + *(v3+1)*(fac); \
+ *(v1+2)= *(v2+2) + *(v3+2)*(fac); \
+ *(v1+3)= *(v2+3) + *(v3+3)*(fac); \
+ }
+
+#define INPR(v1, v2) ( (v1)[0]*(v2)[0] + (v1)[1]*(v2)[1] + (v1)[2]*(v2)[2] )
/* some misc stuff.... */
#define CLAMP(a, b, c) if((a)<(b)) (a)=(b); else if((a)>(c)) (a)=(c)
@@ -139,28 +188,36 @@
#define IN_RANGE_INCL(a, b, c) ((b < c)? ((b<=a && a<=c)? 1:0) : ((c<=a && a<=b)? 1:0))
/* array helpers */
-#define ARRAY_LAST_ITEM(arr_start, arr_dtype, elem_size, tot) (arr_dtype *)((char*)arr_start + (elem_size*(tot - 1)))
-#define ARRAY_HAS_ITEM(item, arr_start, arr_dtype, elem_size, tot) ((item >= arr_start) && (item <= ARRAY_LAST_ITEM(arr_start, arr_dtype, elem_size, tot)))
+#define ARRAY_LAST_ITEM(arr_start, arr_dtype, elem_size, tot) \
+ (arr_dtype *)((char*)arr_start + (elem_size*(tot - 1)))
+
+#define ARRAY_HAS_ITEM(item, arr_start, arr_dtype, elem_size, tot) ( \
+ (item >= arr_start) && \
+ (item <= ARRAY_LAST_ITEM(arr_start, arr_dtype, elem_size, tot)) \
+ )
/* This one rotates the bytes in an int64, int (32) and short (16) */
-#define SWITCH_INT64(a) { \
- char s_i, *p_i; \
- p_i= (char *)&(a); \
- s_i=p_i[0]; p_i[0]=p_i[7]; p_i[7]=s_i; \
- s_i=p_i[1]; p_i[1]=p_i[6]; p_i[6]=s_i; \
- s_i=p_i[2]; p_i[2]=p_i[5]; p_i[5]=s_i; \
- s_i=p_i[3]; p_i[3]=p_i[4]; p_i[4]=s_i; }
-
- #define SWITCH_INT(a) { \
- char s_i, *p_i; \
- p_i= (char *)&(a); \
- s_i=p_i[0]; p_i[0]=p_i[3]; p_i[3]=s_i; \
- s_i=p_i[1]; p_i[1]=p_i[2]; p_i[2]=s_i; }
-
-#define SWITCH_SHORT(a) { \
- char s_i, *p_i; \
- p_i= (char *)&(a); \
- s_i=p_i[0]; p_i[0]=p_i[1]; p_i[1]=s_i; }
+#define SWITCH_INT64(a) { \
+ char s_i, *p_i; \
+ p_i= (char *)&(a); \
+ s_i= p_i[0]; p_i[0]= p_i[7]; p_i[7]= s_i; \
+ s_i= p_i[1]; p_i[1]= p_i[6]; p_i[6]= s_i; \
+ s_i= p_i[2]; p_i[2]= p_i[5]; p_i[5]= s_i; \
+ s_i= p_i[3]; p_i[3]= p_i[4]; p_i[4]= s_i; \
+ }
+
+#define SWITCH_INT(a) { \
+ char s_i, *p_i; \
+ p_i= (char *)&(a); \
+ s_i= p_i[0]; p_i[0]= p_i[3]; p_i[3]= s_i; \
+ s_i= p_i[1]; p_i[1]= p_i[2]; p_i[2]= s_i; \
+ }
+
+#define SWITCH_SHORT(a) { \
+ char s_i, *p_i; \
+ p_i= (char *)&(a); \
+ s_i=p_i[0]; p_i[0]=p_i[1]; p_i[1]=s_i; \
+ }
/* Warning-free macros for storing ints in pointers. Use these _only_
@@ -222,25 +279,25 @@
# else
# define _dummy_abort() (void)0
# endif
-# if defined(__GNUC__) || defined(_MSC_VER) /* just want to check if __func__ is available */
-# define BLI_assert(a) \
-do { \
- if (!(a)) { \
- fprintf(stderr, \
- "BLI_assert failed: %s, %s(), %d at \'%s\'\n", \
- __FILE__, __func__, __LINE__, STRINGIFY(a)); \
- _dummy_abort(); \
- } \
+# if defined(__GNUC__) || defined(_MSC_VER) /* check __func__ is available */
+# define BLI_assert(a) \
+do { \
+ if (!(a)) { \
+ fprintf(stderr, \
+ "BLI_assert failed: %s, %s(), %d at \'%s\'\n", \
+ __FILE__, __func__, __LINE__, STRINGIFY(a)); \
+ _dummy_abort(); \
+ } \
} while (0)
# else
# define BLI_assert(a) \
-do { \
- if (0 == (a)) { \
- fprintf(stderr, \
- "BLI_assert failed: %s, %d at \'%s\'\n", \
- __FILE__, __LINE__, STRINGIFY(a)); \
- _dummy_abort(); \
- } \
+do { \
+ if (0 == (a)) { \
+ fprintf(stderr, \
+ "BLI_assert failed: %s, %d at \'%s\'\n", \
+ __FILE__, __LINE__, STRINGIFY(a)); \
+ _dummy_abort(); \
+ } \
} while (0)
# endif
#else
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index 3620abf41ad..f1ae94de476 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -105,6 +105,7 @@ set(SRC
BLI_edgehash.h
BLI_editVert.h
BLI_fileops.h
+ BLI_fileops_types.h
BLI_fnmatch.h
BLI_ghash.h
BLI_graph.h
@@ -131,8 +132,6 @@ set(SRC
BLI_rand.h
BLI_rect.h
BLI_scanfill.h
- BLI_storage.h
- BLI_storage_types.h
BLI_string.h
BLI_string_utf8.h
BLI_threads.h
diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c
index e848ad8d0d3..fef102d8267 100644
--- a/source/blender/blenlib/intern/fileops.c
+++ b/source/blender/blenlib/intern/fileops.c
@@ -65,7 +65,8 @@
return -1 if zlib fails, -2 if the originating file does not exist
note: will remove the "from" file
*/
-int BLI_gzip(const char *from, const char *to) {
+int BLI_file_gzip(const char *from, const char *to)
+{
char buffer[10240];
int file;
int readsize = 0;
@@ -109,7 +110,7 @@ int BLI_gzip(const char *from, const char *to) {
/* gzip the file in from_file and write it to memery to_mem, at most size bytes.
return the unziped size
*/
-char *BLI_ungzip_to_mem(const char *from_file, int *size_r)
+char *BLI_file_ungzip_to_mem(const char *from_file, int *size_r)
{
gzFile gzfile;
int readsize, size, alloc_size=0;
@@ -150,7 +151,7 @@ char *BLI_ungzip_to_mem(const char *from_file, int *size_r)
/* return 1 when file can be written */
-int BLI_is_writable(const char *filename)
+int BLI_file_is_writable(const char *filename)
{
int file;
@@ -178,7 +179,7 @@ int BLI_is_writable(const char *filename)
}
}
-int BLI_touch(const char *file)
+int BLI_file_touch(const char *file)
{
FILE *f = fopen(file,"r+b");
if (f != NULL) {
@@ -195,15 +196,12 @@ int BLI_touch(const char *file)
return 0;
}
-int BLI_exists(const char *file) {
- return BLI_exist(file);
-}
-
#ifdef WIN32
static char str[MAXPATHLEN+12];
-int BLI_delete(const char *file, int dir, int recursive) {
+int BLI_delete(const char *file, int dir, int recursive)
+{
int err;
if (recursive) {
@@ -220,7 +218,8 @@ int BLI_delete(const char *file, int dir, int recursive) {
return err;
}
-int BLI_move(const char *file, const char *to) {
+int BLI_move(const char *file, const char *to)
+{
int err;
// windows doesn't support moveing to a directory
@@ -245,7 +244,8 @@ int BLI_move(const char *file, const char *to) {
}
-int BLI_copy_fileops(const char *file, const char *to) {
+int BLI_copy(const char *file, const char *to)
+{
int err;
// windows doesn't support copying to a directory
@@ -270,14 +270,16 @@ int BLI_copy_fileops(const char *file, const char *to) {
return err;
}
-int BLI_link(const char *file, const char *to) {
+int BLI_create_symlink(const char *file, const char *to)
+{
callLocalErrorCallBack("Linking files is unsupported on Windows");
(void)file;
(void)to;
return 1;
}
-void BLI_recurdir_fileops(const char *dirname) {
+void BLI_dir_create_recursive(const char *dirname)
+{
char *lslash;
char tmp[MAXPATHLEN];
@@ -299,7 +301,7 @@ void BLI_recurdir_fileops(const char *dirname) {
if (lslash) {
/* Split about the last slash and recurse */
*lslash = 0;
- BLI_recurdir_fileops(tmp);
+ BLI_dir_create_recursive(tmp);
}
if(dirname[0]) /* patch, this recursive loop tries to create a nameless directory */
@@ -307,7 +309,8 @@ void BLI_recurdir_fileops(const char *dirname) {
callLocalErrorCallBack("Unable to create directory\n");
}
-int BLI_rename(const char *from, const char *to) {
+int BLI_rename(const char *from, const char *to)
+{
if (!BLI_exists(from)) return 0;
/* make sure the filenames are different (case insensitive) before removing */
@@ -347,25 +350,29 @@ int BLI_delete(const char *file, int dir, int recursive)
return -1;
}
-int BLI_move(const char *file, const char *to) {
+int BLI_move(const char *file, const char *to)
+{
BLI_snprintf(str, sizeof(str), "/bin/mv -f \"%s\" \"%s\"", file, to);
return system(str);
}
-int BLI_copy_fileops(const char *file, const char *to) {
+int BLI_copy(const char *file, const char *to)
+{
BLI_snprintf(str, sizeof(str), "/bin/cp -rf \"%s\" \"%s\"", file, to);
return system(str);
}
-int BLI_link(const char *file, const char *to) {
+int BLI_create_symlink(const char *file, const char *to)
+{
BLI_snprintf(str, sizeof(str), "/bin/ln -f \"%s\" \"%s\"", file, to);
return system(str);
}
-void BLI_recurdir_fileops(const char *dirname) {
+void BLI_dir_create_recursive(const char *dirname)
+{
char *lslash;
char tmp[MAXPATHLEN];
@@ -377,13 +384,14 @@ void BLI_recurdir_fileops(const char *dirname) {
if (lslash) {
/* Split about the last slash and recurse */
*lslash = 0;
- BLI_recurdir_fileops(tmp);
+ BLI_dir_create_recursive(tmp);
}
mkdir(dirname, 0777);
}
-int BLI_rename(const char *from, const char *to) {
+int BLI_rename(const char *from, const char *to)
+{
if (!BLI_exists(from)) return 0;
if (BLI_exists(to)) if(BLI_delete(to, 0, 0)) return 1;
@@ -392,3 +400,4 @@ int BLI_rename(const char *from, const char *to) {
}
#endif
+
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index d03c45e7db9..47afb60761f 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -42,13 +42,11 @@
#include "MEM_guardedalloc.h"
-#include "DNA_userdef_types.h"
+#include "DNA_listBase.h"
#include "BLI_fileops.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
-#include "BLI_storage.h"
-#include "BLI_storage_types.h"
#include "BLI_utildefines.h"
#include "BKE_utildefines.h"
@@ -85,11 +83,24 @@
#endif /* WIN32 */
+/* standard paths */
+#ifdef WIN32
+#define BLENDER_USER_FORMAT "%s\\Blender Foundation\\Blender\\%s"
+#define BLENDER_SYSTEM_FORMAT "%s\\Blender Foundation\\Blender\\%s"
+#elif defined(__APPLE__)
+#define BLENDER_USER_FORMAT "%s/Blender/%s"
+#define BLENDER_SYSTEM_FORMAT "%s/Blender/%s"
+#else
+#define BLENDER_USER_FORMAT "%s/.blender/%s"
+#define BLENDER_SYSTEM_FORMAT "%s/blender/%s"
+#endif
+
/* local */
#define UNIQUE_NAME_MAX 128
-extern char bprogname[];
-extern char bprogdir[];
+static char bprogname[FILE_MAX]; /* path to program executable */
+static char bprogdir[FILE_MAX]; /* path in which executable is located */
+static char btempdir[FILE_MAX]; /* temporary directory */
static int add_win32_extension(char *name);
static char *blender_version_decimal(const int ver);
@@ -728,7 +739,7 @@ int BLI_path_cwd(char *path)
if (wasrelative==1) {
char cwd[FILE_MAXDIR + FILE_MAXFILE]= "";
- BLI_getwdN(cwd, sizeof(cwd)); /* incase the full path to the blend isnt used */
+ BLI_current_working_dir(cwd, sizeof(cwd)); /* incase the full path to the blend isnt used */
if (cwd[0] == '\0') {
printf( "Could not get the current working directory - $PWD for an unknown reason.");
@@ -974,7 +985,7 @@ static int get_path_system(char *targetpath, const char *folder_name, const char
}
/* try CWD/release/folder_name */
- if(BLI_getwdN(cwd, sizeof(cwd))) {
+ if(BLI_current_working_dir(cwd, sizeof(cwd))) {
if(test_path(targetpath, cwd, "release", relfolder)) {
return 1;
}
@@ -1105,7 +1116,7 @@ char *BLI_get_folder_create(int folder_id, const char *subfolder)
if (!path) {
path = BLI_get_user_folder_notest(folder_id, subfolder);
- if (path) BLI_recurdir_fileops(path);
+ if (path) BLI_dir_create_recursive(path);
}
return path;
@@ -1238,7 +1249,7 @@ void BLI_make_existing_file(const char *name)
/* test exist */
if (BLI_exists(di) == 0) {
- BLI_recurdir_fileops(di);
+ BLI_dir_create_recursive(di);
}
}
@@ -1635,7 +1646,7 @@ static int add_win32_extension(char *name)
int retval = 0;
int type;
- type = BLI_exist(name);
+ type = BLI_exists(name);
if ((type == 0) || S_ISDIR(type)) {
#ifdef _WIN32
char filename[FILE_MAXDIR+FILE_MAXFILE];
@@ -1655,7 +1666,7 @@ static int add_win32_extension(char *name)
strcat(filename, extensions);
}
- type = BLI_exist(filename);
+ type = BLI_exists(filename);
if (type && (! S_ISDIR(type))) {
retval = 1;
strcpy(name, filename);
@@ -1671,8 +1682,19 @@ static int add_win32_extension(char *name)
return (retval);
}
-/* filename must be FILE_MAX length minimum */
-void BLI_where_am_i(char *fullname, const size_t maxlen, const char *name)
+/*
+* Checks if name is a fully qualified filename to an executable.
+* If not it searches $PATH for the file. On Windows it also
+* adds the correct extension (.com .exe etc) from
+* $PATHEXT if necessary. Also on Windows it translates
+* the name to its 8.3 version to prevent problems with
+* spaces and stuff. Final result is returned in fullname.
+*
+* @param fullname The full path and full name of the executable
+* (must be FILE_MAX minimum)
+* @param name The name of the executable (usually argv[0]) to be checked
+*/
+static void bli_where_am_i(char *fullname, const size_t maxlen, const char *name)
{
char filename[FILE_MAXDIR+FILE_MAXFILE];
const char *path = NULL, *temp;
@@ -1709,7 +1731,7 @@ void BLI_where_am_i(char *fullname, const size_t maxlen, const char *name)
BLI_strncpy(fullname, name, maxlen);
if (name[0] == '.') {
char wdir[FILE_MAX]= "";
- BLI_getwdN(wdir, sizeof(wdir)); /* backup cwd to restore after */
+ BLI_current_working_dir(wdir, sizeof(wdir)); /* backup cwd to restore after */
// not needed but avoids annoying /./ in name
if(name[1]==SEP)
@@ -1752,12 +1774,37 @@ void BLI_where_am_i(char *fullname, const size_t maxlen, const char *name)
}
}
-void BLI_where_is_temp(char *fullname, const size_t maxlen, int usertemp)
+void BLI_init_program_path(const char *argv0)
+{
+ bli_where_am_i(bprogname, sizeof(bprogname), argv0);
+ BLI_split_dir_part(bprogname, bprogdir, sizeof(bprogdir));
+}
+
+const char *BLI_program_path(void)
+{
+ return bprogname;
+}
+
+const char *BLI_program_dir(void)
+{
+ return bprogdir;
+}
+
+/**
+* Gets the temp directory when blender first runs.
+* If the default path is not found, use try $TEMP
+*
+* Also make sure the temp dir has a trailing slash
+*
+* @param fullname The full path to the temp directory
+* @param userdir Directory specified in user preferences
+*/
+void BLI_where_is_temp(char *fullname, const size_t maxlen, char *userdir)
{
fullname[0] = '\0';
- if (usertemp && BLI_is_dir(U.tempdir)) {
- BLI_strncpy(fullname, U.tempdir, maxlen);
+ if (userdir && BLI_is_dir(userdir)) {
+ BLI_strncpy(fullname, userdir, maxlen);
}
@@ -1791,13 +1838,28 @@ void BLI_where_is_temp(char *fullname, const size_t maxlen, int usertemp)
/* add a trailing slash if needed */
BLI_add_slash(fullname);
#ifdef WIN32
- if(U.tempdir != fullname) {
- BLI_strncpy(U.tempdir, fullname, maxlen); /* also set user pref to show %TEMP%. /tmp/ is just plain confusing for Windows users. */
+ if(userdir != fullname) {
+ BLI_strncpy(userdir, fullname, maxlen); /* also set user pref to show %TEMP%. /tmp/ is just plain confusing for Windows users. */
}
#endif
}
}
+void BLI_init_temporary_dir(char *userdir)
+{
+ BLI_where_is_temp(btempdir, FILE_MAX, userdir);
+}
+
+const char *BLI_temporary_dir(void)
+{
+ return btempdir;
+}
+
+void BLI_system_temporary_dir(char *dir)
+{
+ BLI_where_is_temp(dir, FILE_MAX, NULL);
+}
+
#ifdef WITH_ICONV
void BLI_string_to_utf8(char *original, char *utf_8, const char *code)
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c
index 7638e95b4ec..b3caeb71822 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -88,10 +88,9 @@
#include "DNA_listBase.h"
+#include "BLI_fileops.h"
#include "BLI_listbase.h"
#include "BLI_linklist.h"
-#include "BLI_storage.h"
-#include "BLI_storage_types.h"
#include "BLI_string.h"
#include "BKE_utildefines.h"
@@ -104,7 +103,7 @@ static struct ListBase dirbase_={NULL, NULL};
static struct ListBase *dirbase = &dirbase_;
/* can return NULL when the size is not big enough */
-char *BLI_getwdN(char *dir, const int maxncpy)
+char *BLI_current_working_dir(char *dir, const int maxncpy)
{
const char *pwd= getenv("PWD");
if (pwd){
@@ -116,7 +115,7 @@ char *BLI_getwdN(char *dir, const int maxncpy)
}
-int BLI_compare(struct direntry *entry1, struct direntry *entry2)
+static int bli_compare(struct direntry *entry1, struct direntry *entry2)
{
/* type is equal to stat.st_mode */
@@ -143,7 +142,7 @@ int BLI_compare(struct direntry *entry1, struct direntry *entry2)
}
-double BLI_diskfree(const char *dir)
+double BLI_dir_free_space(const char *dir)
{
#ifdef WIN32
DWORD sectorspc, bytesps, freec, clusters;
@@ -198,7 +197,7 @@ double BLI_diskfree(const char *dir)
#endif
}
-void BLI_builddir(const char *dirname, const char *relname)
+static void bli_builddir(const char *dirname, const char *relname)
{
struct dirent *fname;
struct dirlink *dlink;
@@ -273,7 +272,7 @@ void BLI_builddir(const char *dirname, const char *relname)
}
BLI_freelist(dirbase);
- if (files) qsort(files, actnum, sizeof(struct direntry), (int (*)(const void *,const void*))BLI_compare);
+ if (files) qsort(files, actnum, sizeof(struct direntry), (int (*)(const void *,const void*))bli_compare);
} else {
printf("%s empty directory\n",dirname);
}
@@ -284,7 +283,7 @@ void BLI_builddir(const char *dirname, const char *relname)
}
}
-void BLI_adddirstrings(void)
+static void bli_adddirstrings(void)
{
char datum[100];
char buf[512];
@@ -392,7 +391,7 @@ void BLI_adddirstrings(void)
}
}
-unsigned int BLI_getdir(const char *dirname, struct direntry **filelist)
+unsigned int BLI_dir_contents(const char *dirname, struct direntry **filelist)
{
// reset global variables
// memory stored in files is free()'d in
@@ -401,8 +400,8 @@ unsigned int BLI_getdir(const char *dirname, struct direntry **filelist)
actnum = totnum = 0;
files = NULL;
- BLI_builddir(dirname,"");
- BLI_adddirstrings();
+ bli_builddir(dirname,"");
+ bli_adddirstrings();
if (files) {
*(filelist) = files;
@@ -416,7 +415,7 @@ unsigned int BLI_getdir(const char *dirname, struct direntry **filelist)
}
-size_t BLI_filesize(int file)
+size_t BLI_file_descriptor_size(int file)
{
struct stat buf;
@@ -425,20 +424,20 @@ size_t BLI_filesize(int file)
return (buf.st_size);
}
-size_t BLI_filepathsize(const char *path)
+size_t BLI_file_size(const char *path)
{
int size, file = open(path, O_BINARY|O_RDONLY);
if (file == -1)
return -1;
- size = BLI_filesize(file);
+ size = BLI_file_descriptor_size(file);
close(file);
return size;
}
-int BLI_exist(const char *name)
+int BLI_exists(const char *name)
{
#if defined(WIN32) && !defined(__MINGW32__)
struct _stat64i32 st;
@@ -471,10 +470,10 @@ int BLI_exist(const char *name)
/* would be better in fileops.c except that it needs stat.h so add here */
int BLI_is_dir(const char *file)
{
- return S_ISDIR(BLI_exist(file));
+ return S_ISDIR(BLI_exists(file));
}
-LinkNode *BLI_read_file_as_lines(const char *name)
+LinkNode *BLI_file_read_as_lines(const char *name)
{
FILE *fp= fopen(name, "r");
LinkNode *lines= NULL;
@@ -515,7 +514,7 @@ LinkNode *BLI_read_file_as_lines(const char *name)
return lines;
}
-void BLI_free_file_lines(LinkNode *lines)
+void BLI_file_free_lines(LinkNode *lines)
{
BLI_linklist_free(lines, (void(*)(void*)) MEM_freeN);
}