diff options
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/BLI_ghash.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/Makefile | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/bpath.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/fileops.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/listbase.c | 21 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_color.c | 7 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 30 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom_inline.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_matrix.c | 9 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_rotation.c | 46 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector.c | 6 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector_inline.c | 5 | ||||
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 329 | ||||
-rw-r--r-- | source/blender/blenlib/intern/pbvh.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/scanfill.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/storage.c | 28 | ||||
-rw-r--r-- | source/blender/blenlib/intern/winstuff.c | 1 |
17 files changed, 225 insertions, 271 deletions
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index 456872d6612..32818505e5c 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -28,10 +28,10 @@ * A general (pointer -> pointer) hash table ADT */ +#include "MEM_guardedalloc.h" #include "BLI_ghash.h" #include "BLO_sys_types.h" // for intptr_t support - /***/ unsigned int hashsizes[]= { diff --git a/source/blender/blenlib/intern/Makefile b/source/blender/blenlib/intern/Makefile index 7ef44aff881..018fd3477df 100644 --- a/source/blender/blenlib/intern/Makefile +++ b/source/blender/blenlib/intern/Makefile @@ -15,7 +15,7 @@ # # 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# 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. diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index fbe71019379..d1a8de14181 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -43,6 +43,8 @@ #include "DNA_mesh_types.h" #include "DNA_scene_types.h" /* to get the current frame */ +#include "DNA_image_types.h" +#include "DNA_sound_types.h" #include "DNA_sequence_types.h" #include "DNA_vfont_types.h" #include "DNA_windowmanager_types.h" diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index 7a24d9b36b1..fde770c238c 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -80,7 +80,7 @@ char *BLI_last_slash(const char *string) { else return lfslash; } -/* adds a slash if there isnt one there alredy */ +/* adds a slash if there isnt one there already */ int BLI_add_slash(char *string) { int len = strlen(string); #ifdef WIN32 diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c index 0a6831558d1..776f2d085df 100644 --- a/source/blender/blenlib/intern/listbase.c +++ b/source/blender/blenlib/intern/listbase.c @@ -374,6 +374,27 @@ void *BLI_findstring(ListBase *listbase, const char *id, int offset) return NULL; } +void *BLI_findstring_ptr(ListBase *listbase, const char *id, int offset) +{ + Link *link= NULL; + const char *id_iter; + + if (listbase == NULL) return NULL; + + link= listbase->first; + while (link) { + /* exact copy of BLI_findstring(), except for this line */ + id_iter= *((const char **)(((const char *)link) + offset)); + + if(id[0] == id_iter[0] && strcmp(id, id_iter)==0) + return link; + + link= link->next; + } + + return NULL; +} + int BLI_findstringindex(ListBase *listbase, const char *id, int offset) { Link *link= NULL; diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c index 6637d74dbb1..396f2c52058 100644 --- a/source/blender/blenlib/intern/math_color.c +++ b/source/blender/blenlib/intern/math_color.c @@ -33,17 +33,14 @@ void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b) int i; float f, p, q, t; - h *= 360.0f; - if(s==0.0f) { *r = v; *g = v; *b = v; } else { - if(h== 360.0f) h = 0.0f; - - h /= 60.0f; + h= (h - floor(h))*6.0f; + i = (int)floor(h); f = h - i; p = v*(1.0f-s); diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index e8fb922ce4d..68b1feea632 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -317,7 +317,7 @@ static short IsectLLPt2Df(float x0,float y0,float x1,float y1, return -1; /*m2 = (float) 1e+10;*/ // close enough to infinity if (fabs(m1-m2) < 0.000001) - return -1; /* paralelle lines */ + return -1; /* parallel lines */ // compute constants @@ -841,10 +841,8 @@ int isect_line_line_v3(float v1[3], float v2[3], float v3[3], float v4[3], float sub_v3_v3v3(a, v2, v1); sub_v3_v3v3(b, v4, v3); - copy_v3_v3(dir1, a); - normalize_v3(dir1); - copy_v3_v3(dir2, b); - normalize_v3(dir2); + normalize_v3_v3(dir1, a); + normalize_v3_v3(dir2, b); d = dot_v3v3(dir1, dir2); if (d == 1.0f || d == -1.0f) { /* colinear */ @@ -908,10 +906,8 @@ int isect_line_line_strict_v3(float v1[3], float v2[3], float v3[3], float v4[3] sub_v3_v3v3(a, v2, v1); sub_v3_v3v3(b, v4, v3); - copy_v3_v3(dir1, a); - normalize_v3(dir1); - copy_v3_v3(dir2, b); - normalize_v3(dir2); + normalize_v3_v3(dir1, a); + normalize_v3_v3(dir2, b); d = dot_v3v3(dir1, dir2); if (d == 1.0f || d == -1.0f || d == 0) { /* colinear or one vector is zero-length*/ @@ -993,14 +989,14 @@ void isect_point_quad_uv_v2(float v0[2], float v1[2], float v2[2], float v3[2], { float x0,y0, x1,y1, wtot, v2d[2], w1, w2; - /* used for paralelle lines */ + /* used for parallel lines */ float pt3d[3], l1[3], l2[3], pt_on_line[3]; /* compute 2 edges of the quad intersection point */ if (IsectLLPt2Df(v0[0],v0[1],v1[0],v1[1], v2[0],v2[1],v3[0],v3[1], &x0,&y0) == 1) { /* the intersection point between the quad-edge intersection and the point in the quad we want the uv's for */ /* should never be paralle !! */ - /*printf("\tnot paralelle 1\n");*/ + /*printf("\tnot parallel 1\n");*/ IsectLLPt2Df(pt[0],pt[1],x0,y0, v0[0],v0[1],v3[0],v3[1], &x1,&y1); /* Get the weights from the new intersection point, to each edge */ @@ -1016,8 +1012,8 @@ void isect_point_quad_uv_v2(float v0[2], float v1[2], float v2[2], float v3[2], /*w2 = w2/wtot;*/ uv[0] = w1/wtot; } else { - /* lines are paralelle, lambda_cp_line_ex is 3d grrr */ - /*printf("\tparalelle1\n");*/ + /* lines are parallel, lambda_cp_line_ex is 3d grrr */ + /*printf("\tparallel1\n");*/ pt3d[0] = pt[0]; pt3d[1] = pt[1]; pt3d[2] = l1[2] = l2[2] = 0.0f; @@ -1043,7 +1039,7 @@ void isect_point_quad_uv_v2(float v0[2], float v1[2], float v2[2], float v3[2], if (IsectLLPt2Df(v0[0],v0[1],v3[0],v3[1], v1[0],v1[1],v2[0],v2[1], &x0,&y0) == 1) { /* was v0,v1 v2,v3 now v0,v3 v1,v2*/ /* never paralle if above was not */ - /*printf("\tnot paralelle2\n");*/ + /*printf("\tnot parallel2\n");*/ IsectLLPt2Df(pt[0],pt[1],x0,y0, v0[0],v0[1],v1[0],v1[1], &x1,&y1);/* was v0,v3 now v0,v1*/ v2d[0] = x1-v0[0]; @@ -1056,8 +1052,8 @@ void isect_point_quad_uv_v2(float v0[2], float v1[2], float v2[2], float v3[2], wtot = w1+w2; uv[1] = w1/wtot; } else { - /* lines are paralelle, lambda_cp_line_ex is 3d grrr */ - /*printf("\tparalelle2\n");*/ + /* lines are parallel, lambda_cp_line_ex is 3d grrr */ + /*printf("\tparallel2\n");*/ pt3d[0] = pt[0]; pt3d[1] = pt[1]; pt3d[2] = l1[2] = l2[2] = 0.0f; @@ -1225,7 +1221,7 @@ static int point_in_slice_as(float p[3],float origin[3],float normal[3]) return 1; } -/*mama (knowing the squared lenght of the normal)*/ +/*mama (knowing the squared length of the normal)*/ static int point_in_slice_m(float p[3],float origin[3],float normal[3],float lns) { float h,rp[3]; diff --git a/source/blender/blenlib/intern/math_geom_inline.c b/source/blender/blenlib/intern/math_geom_inline.c index 697ac8dc782..f2d8e27cbd5 100644 --- a/source/blender/blenlib/intern/math_geom_inline.c +++ b/source/blender/blenlib/intern/math_geom_inline.c @@ -15,7 +15,7 @@ * * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * 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. diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c index 6e8f4622488..64c3e746982 100644 --- a/source/blender/blenlib/intern/math_matrix.c +++ b/source/blender/blenlib/intern/math_matrix.c @@ -309,6 +309,7 @@ void mul_v3_m4v3(float *in, float mat[][4], float *vec) in[2]= x*mat[0][2] + y*mat[1][2] + mat[2][2]*vec[2] + mat[3][2]; } +/* same as mul_m4_v3() but doesnt apply translation component */ void mul_mat3_m4_v3(float mat[][4], float *vec) { float x,y; @@ -594,9 +595,7 @@ void transpose_m4(float mat[][4]) void orthogonalize_m3(float mat[][3], int axis) { float size[3]; - size[0] = len_v3(mat[0]); - size[1] = len_v3(mat[1]); - size[2] = len_v3(mat[2]); + mat3_to_size(size, mat); normalize_v3(mat[axis]); switch(axis) { @@ -657,9 +656,7 @@ void orthogonalize_m3(float mat[][3], int axis) void orthogonalize_m4(float mat[][4], int axis) { float size[3]; - size[0] = len_v3(mat[0]); - size[1] = len_v3(mat[1]); - size[2] = len_v3(mat[2]); + mat4_to_size(size, mat); normalize_v3(mat[axis]); switch(axis) { diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index 6b5bf7743ef..f72269f6d7b 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -36,7 +36,7 @@ void unit_qt(float *q) q[1]= q[2]= q[3]= 0.0f; } -void copy_qt_qt(float *q1, float *q2) +void copy_qt_qt(float *q1, const float *q2) { q1[0]= q2[0]; q1[1]= q2[1]; @@ -49,7 +49,7 @@ int is_zero_qt(float *q) return (q[0] == 0 && q[1] == 0 && q[2] == 0 && q[3] == 0); } -void mul_qt_qtqt(float *q, float *q1, float *q2) +void mul_qt_qtqt(float *q, const float *q1, const float *q2) { float t0,t1,t2; @@ -63,7 +63,7 @@ void mul_qt_qtqt(float *q, float *q1, float *q2) } /* Assumes a unit quaternion */ -void mul_qt_v3(float *q, float *v) +void mul_qt_v3(const float *q, float *v) { float t0, t1, t2; @@ -104,8 +104,14 @@ void invert_qt(float *q) mul_qt_fl(q, 1.0f/f); } +void invert_qt_qt(float *q1, const float *q2) +{ + copy_qt_qt(q1, q2); + invert_qt(q1); +} + /* simple mult */ -void mul_qt_fl(float *q, float f) +void mul_qt_fl(float *q, const float f) { q[0] *= f; q[1] *= f; @@ -121,7 +127,7 @@ void sub_qt_qtqt(float *q, float *q1, float *q2) } /* angular mult factor */ -void mul_fac_qt_fl(float *q, float fac) +void mul_fac_qt_fl(float *q, const float fac) { float angle= fac*saacos(q[0]); /* quat[0]= cos(0.5*angle), but now the 0.5 and 2.0 rule out */ @@ -129,10 +135,7 @@ void mul_fac_qt_fl(float *q, float fac) float si= (float)sin(angle); q[0]= co; normalize_v3(q+1); - q[1]*= si; - q[2]*= si; - q[3]*= si; - + mul_v3_fl(q+1, si); } void quat_to_mat3(float m[][3], float *q) @@ -336,6 +339,23 @@ void rotation_between_vecs_to_quat(float *q, const float v1[3], const float v2[3 axis_angle_to_quat(q, axis, angle); } +void rotation_between_quats_to_quat(float *q, const float q1[4], const float q2[4]) +{ + float tquat[4]; + double dot = 0.0f; + int x; + + copy_qt_qt(tquat, q1); + conjugate_qt(tquat); + dot = 1.0f / dot_qtqt(tquat, tquat); + + for(x = 0; x < 4; x++) + tquat[x] *= dot; + + mul_qt_qtqt(q, tquat, q2); +} + + void vec_to_quat(float *q,float *vec, short axis, short upflag) { float q2[4], nor[3], *fp, mat[3][3], angle, si, co, x2, y2, z2, len1; @@ -572,9 +592,8 @@ void axis_angle_to_quat(float q[4], float axis[3], float angle) { float nor[3]; float si; - - copy_v3_v3(nor, axis); - normalize_v3(nor); + + normalize_v3_v3(nor, axis); angle /= 2; si = (float)sin(angle); @@ -631,8 +650,7 @@ void axis_angle_to_mat3(float mat[3][3],float axis[3], float angle) float nor[3], nsi[3], co, si, ico; /* normalise the axis first (to remove unwanted scaling) */ - copy_v3_v3(nor, axis); - normalize_v3(nor); + normalize_v3_v3(nor, axis); /* now convert this to a 3x3 matrix */ co= (float)cos(angle); diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index 9baf897c830..b1cea9ab3c4 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -120,10 +120,8 @@ float angle_v3v3(float *v1, float *v2) { float vec1[3], vec2[3]; - copy_v3_v3(vec1, v1); - copy_v3_v3(vec2, v2); - normalize_v3(vec1); - normalize_v3(vec2); + normalize_v3_v3(vec1, v1); + normalize_v3_v3(vec2, v2); return angle_normalized_v3v3(vec1, vec2); } diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 33d7f7cdd6d..76173312b67 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -432,6 +432,11 @@ MINLINE int equals_v3v3(float *v1, float *v2) return ((v1[0]==v2[0]) && (v1[1]==v2[1]) && (v1[2]==v2[2])); } +MINLINE int equals_v4v4(float *v1, float *v2) +{ + return ((v1[0]==v2[0]) && (v1[1]==v2[1]) && (v1[2]==v2[2]) && (v1[3]==v2[3])); +} + MINLINE int compare_v3v3(float *v1, float *v2, float limit) { if(fabs(v1[0]-v2[0])<limit) diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 423bf452a4d..cf773d575e5 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -364,7 +364,7 @@ void BLI_path_rel(char *file, const char *relfile) if (strlen(relfile) > 2 && relfile[1] != ':') { char* ptemp; /* fix missing volume name in relative base, - can happen with old .Blog files */ + can happen with old recent-files.txt files */ get_default_root(temp); ptemp = &temp[2]; if (relfile[0] != '\\' && relfile[0] != '/') { @@ -586,7 +586,7 @@ int BLI_path_abs(char *path, const char *basepath) BLI_strncpy(tmp, path, FILE_MAX); } #else - BLI_strncpy(tmp, path, FILE_MAX); + BLI_strncpy(tmp, path, sizeof(tmp)); /* Check for loading a windows path on a posix system * in this case, there is no use in trying C:/ since it @@ -603,7 +603,7 @@ int BLI_path_abs(char *path, const char *basepath) #endif - BLI_strncpy(base, basepath, FILE_MAX); + BLI_strncpy(base, basepath, sizeof(base)); BLI_cleanup_file(NULL, base); @@ -626,17 +626,19 @@ int BLI_path_abs(char *path, const char *basepath) BLI_strncpy(path, tmp+2, FILE_MAX); memcpy(tmp, base, baselen); - strcpy(tmp+baselen, path); - strcpy(path, tmp); + BLI_strncpy(tmp+baselen, path, sizeof(tmp)-baselen); + BLI_strncpy(path, tmp, FILE_MAX); } else { - strcpy(path, tmp+2); + BLI_strncpy(path, tmp+2, FILE_MAX); } } else { - strcpy(path, tmp); + BLI_strncpy(path, tmp, FILE_MAX); } if (path[0]!='\0') { if ( path[strlen(path)-1]=='/') { + /* remove the '/' so we avoid BLI_cleanup_dir adding an extra \ in WIN32 */ + path[strlen(path)-1] = '\0'; BLI_cleanup_dir(NULL, path); } else { BLI_cleanup_file(NULL, path); @@ -732,184 +734,41 @@ void BLI_getlastdir(const char* dir, char *last, int maxlen) } } -char *BLI_gethome(void) { +/* This is now only used to really get the user's default document folder */ +/* On Windows I chose the 'Users/<MyUserName>/Documents' since it's used + as default location to save documents */ +char *BLI_getDefaultDocumentFolder(void) { #if !defined(WIN32) return getenv("HOME"); #else /* Windows */ char * ret; - static char dir[512]; - static char appdatapath[MAXPATHLEN]; + static char documentfolder[MAXPATHLEN]; HRESULT hResult; /* Check for %HOME% env var */ ret = getenv("HOME"); if(ret) { - sprintf(dir, "%s\\%s", ret, blender_version_decimal()); - if (BLI_is_dir(dir)) return dir; - } - - /* else, check install dir (path containing blender.exe) */ - - if(BLI_getInstallationDir(dir)) - { - sprintf(dir, "%s", dir, blender_version_decimal()); - if (BLI_is_dir(dir)) return(dir); + if (BLI_is_dir(ret)) return ret; } - /* add user profile support for WIN 2K / NT. * This is %APPDATA%, which translates to either * %USERPROFILE%\Application Data or since Vista * to %USERPROFILE%\AppData\Roaming */ - hResult = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appdatapath); + hResult = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, documentfolder); if (hResult == S_OK) { - if (BLI_is_dir(appdatapath)) { /* from fop, also below... */ - sprintf(dir, "%s\\Blender Foundation\\Blender", appdatapath); - BLI_recurdir_fileops(dir); - if (BLI_is_dir(dir)) { - sprintf(dir,"%s\\%s", dir, blender_version_decimal()); - if(BLI_is_dir(dir)) return(dir); - } - } - hResult = SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, appdatapath); - if (hResult == S_OK) - { - if (BLI_is_dir(appdatapath)) - { /* from fop, also below... */ - sprintf(dir, "%s\\Blender Foundation\\Blender", appdatapath); - BLI_recurdir_fileops(dir); - if (BLI_is_dir(dir)) { - sprintf(dir,"%s\\%s", dir, blender_version_decimal()); - if(BLI_is_dir(dir)) return(dir); - } - } - } + if (BLI_is_dir(documentfolder)) return documentfolder; } - return "C:\\Temp"; /* sheesh! bad, bad, bad! (aphex) */ + return NULL; #endif } -/* this function returns the path to a blender folder, if it exists - * utility functions for BLI_gethome_folder */ - -// #define PATH_DEBUG /* for testing paths that are checked */ - -static int test_data_path(char *targetpath, char *path_base, char *path_sep, char *folder_name) -{ - char tmppath[FILE_MAXDIR]; - - if(path_sep) BLI_join_dirfile(tmppath, path_base, path_sep); - else BLI_strncpy(tmppath, path_base, sizeof(tmppath)); - - BLI_make_file_string("/", targetpath, tmppath, folder_name); - - if (BLI_is_dir(targetpath)) { -#ifdef PATH_DEBUG - printf("\tpath found: %s\n", targetpath); -#endif - return 1; - } - else { -#ifdef PATH_DEBUG - printf("\tpath missing: %s\n", targetpath); -#endif - targetpath[0] = '\0'; - return 0; - } -} - -static int gethome_path_local(char *targetpath, char *folder_name) -{ - extern char bprogname[]; /* argv[0] from creator.c */ - char bprogdir[FILE_MAXDIR]; - char cwd[FILE_MAXDIR]; - char *s; - int i; - -#ifdef PATH_DEBUG - printf("gethome_path_local...\n"); -#endif - - /* try release/folder_name (binary relative) */ - /* use argv[0] (bprogname) to get the path to the executable */ - s = BLI_last_slash(bprogname); - i = s - bprogname + 1; - BLI_strncpy(bprogdir, bprogname, i); - - /* try release/folder_name (BIN relative) */ - if(test_data_path(targetpath, bprogdir, "release", folder_name)) - return 1; - - /* try release/folder_name (CWD relative) */ - if(test_data_path(targetpath, BLI_getwdN(cwd), "release", folder_name)) - return 1; - - /* try ./.blender/folder_name */ - if(test_data_path(targetpath, bprogdir, ".blender", folder_name)) - return 1; - - return 0; -} - -static int gethome_path_user(char *targetpath, char *folder_name) -{ - char *home_path= BLI_gethome(); - -#ifdef PATH_DEBUG - printf("gethome_path_user...\n"); -#endif - - /* try $HOME/folder_name */ - return test_data_path(targetpath, home_path, ".blender", folder_name); -} - -static int gethome_path_system(char *targetpath, char *folder_name) -{ - extern char blender_path[]; /* unix prefix eg. /usr/share/blender/2.5 creator.c */ - - if(!blender_path[0]) - return 0; - -#ifdef PATH_DEBUG - printf("gethome_path_system...\n"); -#endif - - /* try $BLENDERPATH/folder_name */ - return test_data_path(targetpath, blender_path, NULL, folder_name); -} - -char *BLI_gethome_folder(char *folder_name, int flag) -{ - static char fulldir[FILE_MAXDIR] = ""; - - /* first check if this is a redistributable bundle */ - if(flag & BLI_GETHOME_LOCAL) { - if (gethome_path_local(fulldir, folder_name)) - return fulldir; - } - - /* then check if the OS has blender data files installed in a global location */ - if(flag & BLI_GETHOME_SYSTEM) { - if (gethome_path_system(fulldir, folder_name)) - return fulldir; - } - - /* now check the users home dir for data files */ - if(flag & BLI_GETHOME_USER) { - if (gethome_path_user(fulldir, folder_name)) - return fulldir; - } - - return NULL; -} - - /* NEW stuff, to be cleaned up when fully migrated */ /* ************************************************************* */ /* ************************************************************* */ @@ -961,10 +820,11 @@ static int test_env_path(char *path, char *envvar) } } -static int get_path_local(char *targetpath, char *folder_name) +static int get_path_local(char *targetpath, char *folder_name, char *subfolder_name) { extern char bprogname[]; /* argv[0] from creator.c */ char bprogdir[FILE_MAX]; + char relfolder[FILE_MAX]; char cwd[FILE_MAX]; char *s; int i; @@ -973,6 +833,11 @@ static int get_path_local(char *targetpath, char *folder_name) printf("get_path_local...\n"); #endif + if (subfolder_name) { + BLI_join_dirfile(relfolder, folder_name, subfolder_name); + } else { + BLI_strncpy(relfolder, folder_name, FILE_MAX); + } /* use argv[0] (bprogname) to get the path to the executable */ s = BLI_last_slash(bprogname); @@ -980,38 +845,44 @@ static int get_path_local(char *targetpath, char *folder_name) BLI_strncpy(bprogdir, bprogname, i); /* try EXECUTABLE_DIR/folder_name */ - if(test_path(targetpath, bprogdir, "", folder_name)) + if(test_path(targetpath, bprogdir, "", relfolder)) return 1; /* try CWD/release/folder_name */ - if(test_path(targetpath, BLI_getwdN(cwd), "release", folder_name)) + if(test_path(targetpath, BLI_getwdN(cwd), "release", relfolder)) return 1; /* try EXECUTABLE_DIR/release/folder_name */ - if(test_path(targetpath, bprogdir, "release", folder_name)) + if(test_path(targetpath, bprogdir, "release", relfolder)) return 1; /* try EXECUTABLE_DIR/2.5/folder_name - new default directory for local blender installed files */ - if(test_path(targetpath, bprogdir, blender_version_decimal(), folder_name)) + if(test_path(targetpath, bprogdir, blender_version_decimal(), relfolder)) return 1; /* try ./.blender/folder_name -- DEPRECATED, need to update build systems */ - if(test_path(targetpath, bprogdir, ".blender", folder_name)) + if(test_path(targetpath, bprogdir, ".blender", relfolder)) return 1; return 0; } -static int get_path_user(char *targetpath, char *folder_name, char *envvar) +static int get_path_user(char *targetpath, char *folder_name, char *subfolder_name, char *envvar) { char user_path[FILE_MAX]; const char *user_base_path; user_path[0] = '\0'; - if (test_env_path(targetpath, envvar)) - return 1; - + if (test_env_path(user_path, envvar)) { + if (subfolder_name) { + return test_path(targetpath, user_path, NULL, subfolder_name); + } else { + BLI_strncpy(targetpath, user_path, FILE_MAX); + return 1; + } + } + user_base_path = (const char *)GHOST_getUserDir(); if (user_base_path) { BLI_snprintf(user_path, FILE_MAX, BLENDER_USER_FORMAT, user_base_path, blender_version_decimal()); @@ -1024,19 +895,30 @@ static int get_path_user(char *targetpath, char *folder_name, char *envvar) printf("get_path_user: %s\n", user_path); #endif - /* try $HOME/folder_name */ - return test_path(targetpath, user_path, NULL, folder_name); + if (subfolder_name) { + /* try $HOME/folder_name/subfolder_name */ + return test_path(targetpath, user_path, folder_name, subfolder_name); + } else { + /* try $HOME/folder_name */ + return test_path(targetpath, user_path, NULL, folder_name); + } } -static int get_path_system(char *targetpath, char *folder_name, char *envvar) +static int get_path_system(char *targetpath, char *folder_name, char *subfolder_name, char *envvar) { char system_path[FILE_MAX]; const char *system_base_path; system_path[0] = '\0'; - if (test_env_path(targetpath, envvar)) - return 1; + if (test_env_path(system_path, envvar)) { + if (subfolder_name) { + return test_path(targetpath, system_path, NULL, subfolder_name); + } else { + BLI_strncpy(targetpath, system_path, FILE_MAX); + return 1; + } + } system_base_path = (const char *)GHOST_getSystemDir(); if (system_base_path) { @@ -1050,8 +932,13 @@ static int get_path_system(char *targetpath, char *folder_name, char *envvar) printf("get_path_system: %s\n", system_path); #endif - /* try $BLENDERPATH/folder_name */ - return test_path(targetpath, system_path, NULL, folder_name); + if (subfolder_name) { + /* try $BLENDERPATH/folder_name/subfolder_name */ + return test_path(targetpath, system_path, folder_name, subfolder_name); + } else { + /* try $BLENDERPATH/folder_name */ + return test_path(targetpath, system_path, NULL, folder_name); + } } /* get a folder out of the 'folder_id' presets for paths */ @@ -1059,72 +946,69 @@ static int get_path_system(char *targetpath, char *folder_name, char *envvar) char *BLI_get_folder(int folder_id, char *subfolder) { static char path[FILE_MAX] = ""; - char search_path[FILE_MAX]; switch (folder_id) { case BLENDER_DATAFILES: /* general case */ - BLI_join_dirfile(search_path, "datafiles", subfolder); - if (get_path_local(path, search_path)) break; - if (get_path_user(path, search_path, "BLENDER_USER_DATAFILES")) break; - if (get_path_system(path, search_path, "BLENDER_SYSTEM_DATAFILES")) break; + if (get_path_local(path, "datafiles", subfolder)) break; + if (get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES")) break; + if (get_path_system(path, "datafiles", subfolder, "BLENDER_SYSTEM_DATAFILES")) break; return NULL; case BLENDER_USER_DATAFILES: - BLI_join_dirfile(search_path, "datafiles", subfolder); - if (get_path_local(path, search_path)) break; - if (get_path_user(path, search_path, "BLENDER_USER_DATAFILES")) break; + if (get_path_local(path, "datafiles", subfolder)) break; + if (get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES")) break; return NULL; case BLENDER_SYSTEM_DATAFILES: - BLI_join_dirfile(search_path, "datafiles", subfolder); - if (get_path_system(path, search_path, "BLENDER_SYSTEM_DATAFILES")) break; + if (get_path_local(path, "datafiles", subfolder)) break; + if (get_path_system(path, "datafiles", subfolder, "BLENDER_SYSTEM_DATAFILES")) break; return NULL; + case BLENDER_USER_AUTOSAVE: + if (get_path_local(path, "autosave", subfolder)) break; + if (get_path_user(path, "autosave", subfolder, "BLENDER_USER_DATAFILES")) break; + return NULL; + case BLENDER_CONFIG: /* general case */ - BLI_join_dirfile(search_path, "config", subfolder); - if (get_path_local(path, search_path)) break; - if (get_path_user(path, search_path, "BLENDER_USER_CONFIG")) break; - if (get_path_system(path, search_path, "BLENDER_SYSTEM_CONFIG")) break; + if (get_path_local(path, "config", subfolder)) break; + if (get_path_user(path, "config", subfolder, "BLENDER_USER_CONFIG")) break; + if (get_path_system(path, "config", subfolder, "BLENDER_SYSTEM_CONFIG")) break; return NULL; case BLENDER_USER_CONFIG: - BLI_join_dirfile(search_path, "config", subfolder); - if (get_path_local(path, search_path)) break; - if (get_path_user(path, search_path, "BLENDER_USER_CONFIG")) break; + if (get_path_local(path, "config", subfolder)) break; + if (get_path_user(path, "config", subfolder, "BLENDER_USER_CONFIG")) break; return NULL; case BLENDER_SYSTEM_CONFIG: - BLI_join_dirfile(search_path, "config", subfolder); - if (get_path_system(path, search_path, "BLENDER_SYSTEM_CONFIG")) break; + if (get_path_local(path, "config", subfolder)) break; + if (get_path_system(path, "config", subfolder, "BLENDER_SYSTEM_CONFIG")) break; return NULL; case BLENDER_SCRIPTS: /* general case */ - BLI_join_dirfile(search_path, "scripts", subfolder); - if (get_path_local(path, search_path)) break; - if (get_path_user(path, search_path, "BLENDER_USER_SCRIPTS")) break; - if (get_path_system(path, search_path, "BLENDER_SYSTEM_SCRIPTS")) break; + if (get_path_local(path, "scripts", subfolder)) break; + if (get_path_user(path, "scripts", subfolder, "BLENDER_USER_SCRIPTS")) break; + if (get_path_system(path, "scripts", subfolder, "BLENDER_SYSTEM_SCRIPTS")) break; return NULL; case BLENDER_USER_SCRIPTS: - BLI_join_dirfile(search_path, "scripts", subfolder); - if (get_path_local(path, search_path)) break; - if (get_path_user(path, search_path, "BLENDER_USER_SCRIPTS")) break; + if (get_path_local(path, "scripts", subfolder)) break; + if (get_path_user(path, "scripts", subfolder, "BLENDER_USER_SCRIPTS")) break; return NULL; case BLENDER_SYSTEM_SCRIPTS: - BLI_join_dirfile(search_path, "scripts", subfolder); - if (get_path_system(path, search_path, "BLENDER_SYSTEM_SCRIPTS")) break; + if (get_path_local(path, "scripts", subfolder)) break; + if (get_path_system(path, "scripts", subfolder, "BLENDER_SYSTEM_SCRIPTS")) break; return NULL; case BLENDER_PYTHON: /* general case */ - BLI_join_dirfile(search_path, "python", subfolder); - if (get_path_local(path, search_path)) break; - if (get_path_system(path, search_path, "BLENDER_SYSTEM_PYTHON")) break; + if (get_path_local(path, "python", subfolder)) break; + if (get_path_system(path, "python", subfolder, "BLENDER_SYSTEM_PYTHON")) break; return NULL; case BLENDER_SYSTEM_PYTHON: - BLI_join_dirfile(search_path, "python", subfolder); - if (get_path_system(path, search_path, "BLENDER_SYSTEM_PYTHON")) break; + if (get_path_local(path, "python", subfolder)) break; + if (get_path_system(path, "python", subfolder, "BLENDER_SYSTEM_PYTHON")) break; return NULL; } @@ -1134,16 +1018,16 @@ char *BLI_get_folder(int folder_id, char *subfolder) static char *BLI_get_user_folder_notest(int folder_id, char *subfolder) { static char path[FILE_MAX] = ""; - char search_path[FILE_MAX]; switch (folder_id) { case BLENDER_USER_DATAFILES: - BLI_join_dirfile(search_path, "datafiles", subfolder); - get_path_user(path, search_path, "BLENDER_USER_DATAFILES"); + get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES"); break; case BLENDER_USER_CONFIG: - BLI_join_dirfile(search_path, "config", subfolder); - get_path_user(path, search_path, "BLENDER_USER_CONFIG"); + get_path_user(path, "config", subfolder, "BLENDER_USER_CONFIG"); + break; + case BLENDER_USER_AUTOSAVE: + get_path_user(path, "autosave", subfolder, "BLENDER_USER_AUTOSAVE"); break; } if ('\0' == path[0]) { @@ -1157,7 +1041,7 @@ char *BLI_get_folder_create(int folder_id, char *subfolder) char *path; /* only for user folders */ - if (!ELEM(folder_id, BLENDER_USER_DATAFILES, BLENDER_USER_CONFIG)) + if (!ELEM3(folder_id, BLENDER_USER_DATAFILES, BLENDER_USER_CONFIG, BLENDER_USER_AUTOSAVE)) return NULL; path = BLI_get_folder(folder_id, subfolder); @@ -1278,7 +1162,7 @@ void BLI_make_existing_file(char *name) { char di[FILE_MAXDIR+FILE_MAXFILE], fi[FILE_MAXFILE]; - strcpy(di, name); + BLI_strncpy(di, name, sizeof(di)); BLI_splitdirstring(di, fi); /* test exist */ @@ -1381,6 +1265,19 @@ int BLI_testextensie(const char *str, const char *ext) return (retval); } +int BLI_testextensie_array(const char *str, const char **ext_array) +{ + int i=0; + while(ext_array[i]) { + if(BLI_testextensie(str, ext_array[i])) { + return 1; + } + + i++; + } + return 0; +} + int BLI_replace_extension(char *path, int maxlen, const char *ext) { int a; diff --git a/source/blender/blenlib/intern/pbvh.c b/source/blender/blenlib/intern/pbvh.c index 4c5177a403e..9bce8bb4e37 100644 --- a/source/blender/blenlib/intern/pbvh.c +++ b/source/blender/blenlib/intern/pbvh.c @@ -24,6 +24,8 @@ #include "DNA_meshdata_types.h" +#include "MEM_guardedalloc.h" + #include "BLI_math.h" #include "BLI_ghash.h" #include "BLI_pbvh.h" diff --git a/source/blender/blenlib/intern/scanfill.c b/source/blender/blenlib/intern/scanfill.c index d1150748dff..7ca7dba2746 100644 --- a/source/blender/blenlib/intern/scanfill.c +++ b/source/blender/blenlib/intern/scanfill.c @@ -145,7 +145,7 @@ struct mem_elements { static void *new_mem_element(int size) { int blocksize= 16384; - static int offs= 0; /* the current free adress */ + static int offs= 0; /* the current free address */ static struct mem_elements *cur= 0, *first; static ListBase lb= {0, 0}; void *adr; diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index 3315e9645d4..80310b1ef8a 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -237,8 +237,19 @@ void BLI_builddir(char *dirname, char *relname) if (newnum){ - if (files) files=(struct direntry *)realloc(files,(totnum+newnum) * sizeof(struct direntry)); - else files=(struct direntry *)malloc(newnum * sizeof(struct direntry)); + if(files) { + void *tmp= realloc(files, (totnum+newnum) * sizeof(struct direntry)); + if(tmp) { + files= (struct direntry *)tmp; + } + else { /* realloc fail */ + free(files); + files= NULL; + } + } + + if(files==NULL) + files=(struct direntry *)malloc(newnum * sizeof(struct direntry)); if (files){ dlink = (struct dirlink *) dirbase->first; @@ -250,6 +261,8 @@ void BLI_builddir(char *dirname, char *relname) // Excluding other than current MSVC compiler until able to test. #if (defined(WIN32) || defined(WIN64)) && (_MSC_VER>=1500) _stat64(dlink->name,&files[actnum].s); +#elif defined(__MINGW32__) + _stati64(dlink->name,&files[actnum].s); #else stat(dlink->name,&files[actnum].s); #endif @@ -432,7 +445,7 @@ int BLI_filepathsize(const char *path) int BLI_exist(char *name) { -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) struct _stat64i32 st; /* in Windows stat doesn't recognize dir ending on a slash To not break code where the ending slash is expected we @@ -444,6 +457,15 @@ int BLI_exist(char *name) if (len > 3 && ( tmp[len-1]=='\\' || tmp[len-1]=='/') ) tmp[len-1] = '\0'; res = _stat(tmp, &st); if (res == -1) return(0); +#elif defined(__MINGW32__) + struct _stati64 st; + char tmp[FILE_MAXDIR+FILE_MAXFILE]; + int len, res; + BLI_strncpy(tmp, name, FILE_MAXDIR+FILE_MAXFILE); + len = strlen(tmp); + if (len > 3 && ( tmp[len-1]=='\\' || tmp[len-1]=='/') ) tmp[len-1] = '\0'; + res = _stati64(tmp, &st); + if (res) return(0); #else struct stat st; if (stat(name,&st)) return(0); diff --git a/source/blender/blenlib/intern/winstuff.c b/source/blender/blenlib/intern/winstuff.c index f2261546f5c..81a635205f9 100644 --- a/source/blender/blenlib/intern/winstuff.c +++ b/source/blender/blenlib/intern/winstuff.c @@ -33,7 +33,6 @@ #include <stdlib.h> #include <stdio.h> -#include "MEM_guardedalloc.h" #include "BLI_path_util.h" #include "BLI_string.h" |