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:
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r--source/blender/blenlib/intern/BLI_dynstr.c65
-rw-r--r--source/blender/blenlib/intern/BLI_fileops.h47
-rw-r--r--source/blender/blenlib/intern/BLI_ghash.c2
-rw-r--r--source/blender/blenlib/intern/BLI_kdopbvh.c9
-rw-r--r--source/blender/blenlib/intern/BLI_scanfill.h38
-rw-r--r--source/blender/blenlib/intern/BLI_storage.h45
-rw-r--r--source/blender/blenlib/intern/BLI_util.h42
-rw-r--r--source/blender/blenlib/intern/Makefile9
-rw-r--r--source/blender/blenlib/intern/arithb.c351
-rw-r--r--source/blender/blenlib/intern/bpath.c50
-rw-r--r--source/blender/blenlib/intern/dynamiclist.c265
-rw-r--r--source/blender/blenlib/intern/dynamiclist.h55
-rw-r--r--source/blender/blenlib/intern/fileops.c13
-rw-r--r--source/blender/blenlib/intern/fnmatch.c5
-rw-r--r--source/blender/blenlib/intern/freetypefont.c25
-rw-r--r--source/blender/blenlib/intern/graph.c2
-rw-r--r--source/blender/blenlib/intern/listbase.c361
-rw-r--r--source/blender/blenlib/intern/rct.c50
-rw-r--r--source/blender/blenlib/intern/storage.c42
-rw-r--r--source/blender/blenlib/intern/string.c236
-rw-r--r--source/blender/blenlib/intern/threads.c6
-rw-r--r--source/blender/blenlib/intern/util.c814
-rw-r--r--source/blender/blenlib/intern/winstuff.c5
23 files changed, 1422 insertions, 1115 deletions
diff --git a/source/blender/blenlib/intern/BLI_dynstr.c b/source/blender/blenlib/intern/BLI_dynstr.c
index 43c80dd24f0..04388ea946f 100644
--- a/source/blender/blenlib/intern/BLI_dynstr.c
+++ b/source/blender/blenlib/intern/BLI_dynstr.c
@@ -28,6 +28,8 @@
* Dynamically sized string ADT
*/
+#include <stdarg.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -35,8 +37,10 @@
#include "BLI_blenlib.h"
#include "BLI_dynstr.h"
-#ifdef HAVE_CONFIG_H
-#include <config.h>
+#ifdef _WIN32
+#ifndef vsnprintf
+#define vsnprintf _vsnprintf
+#endif
#endif
/***/
@@ -63,7 +67,7 @@ DynStr *BLI_dynstr_new(void) {
return ds;
}
-void BLI_dynstr_append(DynStr *ds, char *cstr) {
+void BLI_dynstr_append(DynStr *ds, const char *cstr) {
DynStrElem *dse= malloc(sizeof(*dse));
int cstrlen= strlen(cstr);
@@ -79,6 +83,61 @@ void BLI_dynstr_append(DynStr *ds, char *cstr) {
ds->curlen+= cstrlen;
}
+void BLI_dynstr_vappendf(DynStr *ds, const char *format, va_list args)
+{
+ char *message, fixedmessage[256];
+ int len= 256, maxlen= 65536, retval;
+
+ while(1) {
+ if(len == sizeof(fixedmessage))
+ message= fixedmessage;
+ else
+ message= MEM_callocN(sizeof(char)*len+1, "BLI_dynstr_appendf");
+
+ retval= vsnprintf(message, len, format, args);
+
+ if(retval == -1) {
+ /* -1 means not enough space, but on windows it may also mean
+ * there is a formatting error, so we impose a maximum length */
+ if(message != fixedmessage)
+ MEM_freeN(message);
+ message= NULL;
+
+ len *= 2;
+ if(len > maxlen) {
+ fprintf(stderr, "BLI_dynstr_append text too long or format error.\n");
+ break;
+ }
+ }
+ else if(retval > len) {
+ /* in C99 the actual length required is returned */
+ if(message != fixedmessage)
+ MEM_freeN(message);
+ message= NULL;
+
+ len= retval;
+ }
+ else
+ break;
+ }
+
+ if(message) {
+ BLI_dynstr_append(ds, message);
+
+ if(message != fixedmessage)
+ MEM_freeN(message);
+ }
+}
+
+void BLI_dynstr_appendf(DynStr *ds, const char *format, ...)
+{
+ va_list args;
+
+ va_start(args, format);
+ BLI_dynstr_vappendf(ds, format, args);
+ va_end(args);
+}
+
int BLI_dynstr_get_len(DynStr *ds) {
return ds->curlen;
}
diff --git a/source/blender/blenlib/intern/BLI_fileops.h b/source/blender/blenlib/intern/BLI_fileops.h
deleted file mode 100644
index bc42030e475..00000000000
--- a/source/blender/blenlib/intern/BLI_fileops.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * blenlib/BLI_listBase.h mar 2001 Nzc
- *
- * $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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 *****
- *
- * 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!
- * */
-
-#ifndef BLI_FILEOPS_H
-#define BLI_FILEOPS_H
-
-char *first_slash(char *string);
-
-/* only for the sane unix world: direct calls to system functions :( */
-#ifndef WIN32
-void BLI_setCmdCallBack(int (*f)(char*));
-#endif
-
-#endif
-
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index 1967b8a88e2..80cd507520c 100644
--- a/source/blender/blenlib/intern/BLI_ghash.c
+++ b/source/blender/blenlib/intern/BLI_ghash.c
@@ -253,7 +253,7 @@ int BLI_ghashIterator_isDone(GHashIterator *ghi) {
/***/
unsigned int BLI_ghashutil_ptrhash(void *key) {
- return (unsigned int) key;
+ return (unsigned int)(intptr_t)key;
}
int BLI_ghashutil_ptrcmp(void *a, void *b) {
if (a==b)
diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c
index 30472beb3e6..0f8194362c9 100644
--- a/source/blender/blenlib/intern/BLI_kdopbvh.c
+++ b/source/blender/blenlib/intern/BLI_kdopbvh.c
@@ -478,6 +478,7 @@ static void node_join(BVHTree *tree, BVHNode *node)
/*
* Debug and information functions
*/
+#if 0
static void bvhtree_print_tree(BVHTree *tree, BVHNode *node, int depth)
{
int i;
@@ -509,6 +510,7 @@ static void bvhtree_info(BVHTree *tree)
// bvhtree_print_tree(tree, tree->nodes[tree->totleaf], 0);
}
+#endif
#if 0
@@ -1238,7 +1240,7 @@ static void dfs_find_nearest_dfs(BVHNearestData *data, BVHNode *node)
int i;
float nearest[3];
- if(data->proj[ node->main_axis ] <= node->children[0]->bv[node->main_axis*2+1])
+ if(data->proj[ (int)node->main_axis ] <= node->children[0]->bv[(int)node->main_axis*2+1])
{
for(i=0; i != node->totnode; i++)
@@ -1267,6 +1269,7 @@ static void dfs_find_nearest_begin(BVHNearestData *data, BVHNode *node)
}
+#if 0
static void NodeDistance_push_heap(NodeDistance *heap, int heap_size)
PUSH_HEAP_BODY(NodeDistance, NodeDistance_priority, heap, heap_size)
@@ -1350,7 +1353,7 @@ static void bfs_find_nearest(BVHNearestData *data, BVHNode *node)
if(heap != default_heap)
free(heap);
}
-
+#endif
int BLI_bvhtree_find_nearest(BVHTree *tree, const float *co, BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata)
{
@@ -1463,7 +1466,7 @@ static void dfs_raycast(BVHRayCastData *data, BVHNode *node)
else
{
//pick loop direction to dive into the tree (based on ray direction and split axis)
- if(data->ray_dot_axis[ node->main_axis ] > 0.0f)
+ if(data->ray_dot_axis[ (int)node->main_axis ] > 0.0f)
{
for(i=0; i != node->totnode; i++)
{
diff --git a/source/blender/blenlib/intern/BLI_scanfill.h b/source/blender/blenlib/intern/BLI_scanfill.h
deleted file mode 100644
index 43431dd5087..00000000000
--- a/source/blender/blenlib/intern/BLI_scanfill.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * blenlib/BLI_scanfill.h mar 2001 Nzc
- *
- * Filling meshes.
- *
- * $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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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_SCANFILL_H
-#define BLI_SCANFILL_H
-
-#endif
-
diff --git a/source/blender/blenlib/intern/BLI_storage.h b/source/blender/blenlib/intern/BLI_storage.h
deleted file mode 100644
index 3e0dec367da..00000000000
--- a/source/blender/blenlib/intern/BLI_storage.h
+++ /dev/null
@@ -1,45 +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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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
-
-#ifndef __APPLE__
-#ifndef WIN32
-#define _LARGEFILE_SOURCE 1
-#define _FILE_OFFSET_BITS 64
-#endif
-#endif
-
-#include "BLI_storage_types.h"
-
-void BLI_adddirstrings(void);
-void BLI_builddir(char *dirname, char *relname);
-int BLI_compare(struct direntry *entry1, struct direntry *entry2);
-
-#endif /* BLI_STORAGE_H */
-
diff --git a/source/blender/blenlib/intern/BLI_util.h b/source/blender/blenlib/intern/BLI_util.h
deleted file mode 100644
index c37a7fd803b..00000000000
--- a/source/blender/blenlib/intern/BLI_util.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * blenlib/BLI_storage_types.h
- *
- * Some types for dealing with directories
- *
- * $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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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_UTIL_H
-#define BLI_UTIL_H
-
-#define mallocstructN(x,y,name) (x*)MEM_mallocN((y)* sizeof(x),name)
-#define callocstructN(x,y,name) (x*)MEM_callocN((y)* sizeof(x),name)
-
-struct ListBase;
-
-#endif
-
diff --git a/source/blender/blenlib/intern/Makefile b/source/blender/blenlib/intern/Makefile
index 10e032ac654..f729a4e3fe0 100644
--- a/source/blender/blenlib/intern/Makefile
+++ b/source/blender/blenlib/intern/Makefile
@@ -33,7 +33,7 @@ DIR = $(OCGDIR)/blender/$(LIBNAME)
include nan_compile.mk
-# CPPFLAGS += $(LEVEL_2_CPP_WARNINGS)
+CFLAGS += $(LEVEL_1_C_WARNINGS)
# path to SDNA types
CPPFLAGS += -I../../makesdna
@@ -46,16 +46,13 @@ CPPFLAGS += -I$(NAN_FREETYPE)/include
CPPFLAGS += -I$(NAN_FREETYPE)/include/freetype2
# path to blenkernel
CPPFLAGS += -I$(SRCHOME)/blender/blenkernel
-CPPFLAGS += -I../../include/
+CPPFLAGS += -I../../editors/include/
# path to zlib
CPPFLAGS += -I$(NAN_ZLIB)/include
ifdef NAN_PTHREADS
CPPFLAGS += -I$(NAN_PTHREADS)/include
endif
-ifeq ($(WITH_FREETYPE2), true)
- CPPFLAGS += -DWITH_FREETYPE2
-endif
ifeq ($(OS),linux)
CPPFLAGS += -I$(OCGDIR)/extern/binreloc/include
-endif \ No newline at end of file
+endif
diff --git a/source/blender/blenlib/intern/arithb.c b/source/blender/blenlib/intern/arithb.c
index ad1dc1ca12c..f111e94a141 100644
--- a/source/blender/blenlib/intern/arithb.c
+++ b/source/blender/blenlib/intern/arithb.c
@@ -34,6 +34,7 @@
/* ************************ FUNKTIES **************************** */
+#include <stdlib.h>
#include <math.h>
#include <sys/types.h>
#include <string.h>
@@ -62,13 +63,13 @@
#define SWAP(type, a, b) { type sw_ap; sw_ap=(a); (a)=(b); (b)=sw_ap; }
#define CLAMP(a, b, c) if((a)<(b)) (a)=(b); else if((a)>(c)) (a)=(c)
-
-#if defined(WIN32) || defined(__APPLE__)
-#include <stdlib.h>
+#ifndef M_PI
#define M_PI 3.14159265358979323846
-#define M_SQRT2 1.41421356237309504880
+#endif
-#endif /* defined(WIN32) || defined(__APPLE__) */
+#ifndef M_SQRT2
+#define M_SQRT2 1.41421356237309504880
+#endif
float saacos(float fac)
@@ -1087,6 +1088,10 @@ void printmatrix3( char *str, float m[][3])
/* **************** QUATERNIONS ********** */
+int QuatIsNul(float *q)
+{
+ return (q[0] == 0 && q[1] == 0 && q[2] == 0 && q[3] == 0);
+}
void QuatMul(float *q, float *q1, float *q2)
{
@@ -1594,16 +1599,16 @@ void QuatInterpolW(float *result, float *quat1, float *quat2, float t)
cosom = quat1[0]*quat2[0] + quat1[1]*quat2[1] + quat1[2]*quat2[2] + quat1[3]*quat2[3] ;
/* rotate around shortest angle */
- if ((1.0 + cosom) > 0.0001) {
+ if ((1.0f + cosom) > 0.0001f) {
- if ((1.0 - cosom) > 0.0001) {
- omega = acos(cosom);
- sinom = sin(omega);
- sc1 = sin((1.0 - t) * omega) / sinom;
- sc2 = sin(t * omega) / sinom;
+ if ((1.0f - cosom) > 0.0001f) {
+ omega = (float)acos(cosom);
+ sinom = (float)sin(omega);
+ sc1 = (float)sin((1.0 - t) * omega) / sinom;
+ sc2 = (float)sin(t * omega) / sinom;
}
else {
- sc1 = 1.0 - t;
+ sc1 = 1.0f - t;
sc2 = t;
}
result[0] = sc1*quat1[0] + sc2*quat2[0];
@@ -1617,9 +1622,9 @@ void QuatInterpolW(float *result, float *quat1, float *quat2, float t)
result[2] = quat2[1];
result[3] = -quat2[0];
- sc1 = sin((1.0 - t)*M_PI_2);
- sc2 = sin(t*M_PI_2);
-
+ sc1 = (float)sin((1.0 - t)*M_PI_2);
+ sc2 = (float)sin(t*M_PI_2);
+
result[0] = sc1*quat1[0] + sc2*result[0];
result[1] = sc1*quat1[1] + sc2*result[1];
result[2] = sc1*quat1[2] + sc2*result[2];
@@ -1634,7 +1639,7 @@ void QuatInterpol(float *result, float *quat1, float *quat2, float t)
cosom = quat1[0]*quat2[0] + quat1[1]*quat2[1] + quat1[2]*quat2[2] + quat1[3]*quat2[3] ;
/* rotate around shortest angle */
- if (cosom < 0.0) {
+ if (cosom < 0.0f) {
cosom = -cosom;
quat[0]= -quat1[0];
quat[1]= -quat1[1];
@@ -1648,13 +1653,13 @@ void QuatInterpol(float *result, float *quat1, float *quat2, float t)
quat[3]= quat1[3];
}
- if ((1.0 - cosom) > 0.0001) {
- omega = acos(cosom);
- sinom = sin(omega);
- sc1 = sin((1 - t) * omega) / sinom;
- sc2 = sin(t * omega) / sinom;
+ if ((1.0f - cosom) > 0.0001f) {
+ omega = (float)acos(cosom);
+ sinom = (float)sin(omega);
+ sc1 = (float)sin((1 - t) * omega) / sinom;
+ sc2 = (float)sin(t * omega) / sinom;
} else {
- sc1= 1.0 - t;
+ sc1= 1.0f - t;
sc2= t;
}
@@ -1770,7 +1775,7 @@ void DQuatToMat4(DualQuat *dq, float mat[][4])
QuatCopy(q0, dq->quat);
/* normalize */
- len= sqrt(QuatDot(q0, q0));
+ len= (float)sqrt(QuatDot(q0, q0));
if(len != 0.0f)
QuatMulf(q0, 1.0f/len);
@@ -1779,9 +1784,9 @@ void DQuatToMat4(DualQuat *dq, float mat[][4])
/* translation */
t= dq->trans;
- mat[3][0]= 2.0*(-t[0]*q0[1] + t[1]*q0[0] - t[2]*q0[3] + t[3]*q0[2]);
- mat[3][1]= 2.0*(-t[0]*q0[2] + t[1]*q0[3] + t[2]*q0[0] - t[3]*q0[1]);
- mat[3][2]= 2.0*(-t[0]*q0[3] - t[1]*q0[2] + t[2]*q0[1] + t[3]*q0[0]);
+ mat[3][0]= 2.0f*(-t[0]*q0[1] + t[1]*q0[0] - t[2]*q0[3] + t[3]*q0[2]);
+ mat[3][1]= 2.0f*(-t[0]*q0[2] + t[1]*q0[3] + t[2]*q0[0] - t[3]*q0[1]);
+ mat[3][2]= 2.0f*(-t[0]*q0[3] - t[1]*q0[2] + t[2]*q0[1] + t[3]*q0[0]);
/* note: this does not handle scaling */
}
@@ -1810,10 +1815,10 @@ void DQuatAddWeighted(DualQuat *dqsum, DualQuat *dq, float weight)
/* interpolate scale - but only if needed */
if (dq->scale_weight) {
float wmat[4][4];
-
+
if(flipped) /* we don't want negative weights for scaling */
weight= -weight;
-
+
Mat4CpyMat4(wmat, dq->scale);
Mat4MulFloat((float*)wmat, weight);
Mat4AddMat4(dqsum->scale, dqsum->scale, wmat);
@@ -1830,7 +1835,7 @@ void DQuatNormalize(DualQuat *dq, float totweight)
if(dq->scale_weight) {
float addweight= totweight - dq->scale_weight;
-
+
if(addweight) {
dq->scale[0][0] += addweight;
dq->scale[1][1] += addweight;
@@ -2192,7 +2197,7 @@ void VecNegf(float *v1)
void VecOrthoBasisf(float *v, float *v1, float *v2)
{
- float f = sqrt(v[0]*v[0] + v[1]*v[1]);
+ float f = (float)sqrt(v[0]*v[0] + v[1]*v[1]);
if (f < 1e-35f) {
// degenerate case
@@ -2344,9 +2349,9 @@ double Sqrt3d(double d)
void NormalShortToFloat(float *out, short *in)
{
- out[0] = in[0] / 32767.0;
- out[1] = in[1] / 32767.0;
- out[2] = in[2] / 32767.0;
+ out[0] = in[0] / 32767.0f;
+ out[1] = in[1] / 32767.0f;
+ out[2] = in[2] / 32767.0f;
}
void NormalFloatToShort(short *out, float *in)
@@ -2483,15 +2488,15 @@ short IsectLL2Ds(short *v1, short *v2, short *v3, short *v4)
*/
float div, labda, mu;
- div= (v2[0]-v1[0])*(v4[1]-v3[1])-(v2[1]-v1[1])*(v4[0]-v3[0]);
- if(div==0.0) return -1;
+ div= (float)((v2[0]-v1[0])*(v4[1]-v3[1])-(v2[1]-v1[1])*(v4[0]-v3[0]));
+ if(div==0.0f) return -1;
labda= ((float)(v1[1]-v3[1])*(v4[0]-v3[0])-(v1[0]-v3[0])*(v4[1]-v3[1]))/div;
mu= ((float)(v1[1]-v3[1])*(v2[0]-v1[0])-(v1[0]-v3[0])*(v2[1]-v1[1]))/div;
- if(labda>=0.0 && labda<=1.0 && mu>=0.0 && mu<=1.0) {
- if(labda==0.0 || labda==1.0 || mu==0.0 || mu==1.0) return 1;
+ if(labda>=0.0f && labda<=1.0f && mu>=0.0f && mu<=1.0f) {
+ if(labda==0.0f || labda==1.0f || mu==0.0f || mu==1.0f) return 1;
return 2;
}
return 0;
@@ -2650,9 +2655,9 @@ static int BarycentricWeights(float *v1, float *v2, float *v3, float *co, float
/* find best projection of face XY, XZ or YZ: barycentric weights of
the 2d projected coords are the same and faster to compute */
- xn= fabs(n[0]);
- yn= fabs(n[1]);
- zn= fabs(n[2]);
+ xn= (float)fabs(n[0]);
+ yn= (float)fabs(n[1]);
+ zn= (float)fabs(n[2]);
if(zn>=xn && zn>=yn) {i= 0; j= 1;}
else if(yn>=xn && yn>=zn) {i= 0; j= 2;}
else {i= 1; j= 2;}
@@ -2884,12 +2889,12 @@ void Mat4ToEul(float tmat[][4], float *eul)
{
float tempMat[3][3];
- Mat3CpyMat4 (tempMat, tmat);
+ Mat3CpyMat4(tempMat, tmat);
Mat3Ortho(tempMat);
Mat3ToEul(tempMat, eul);
}
-void QuatToEul( float *quat, float *eul)
+void QuatToEul(float *quat, float *eul)
{
float mat[3][3];
@@ -2898,7 +2903,7 @@ void QuatToEul( float *quat, float *eul)
}
-void EulToQuat( float *eul, float *quat)
+void EulToQuat(float *eul, float *quat)
{
float ti, tj, th, ci, cj, ch, si, sj, sh, cc, cs, sc, ss;
@@ -2913,7 +2918,7 @@ void EulToQuat( float *eul, float *quat)
quat[3] = cj*cs - sj*sc;
}
-void VecRotToMat3( float *vec, float phi, float mat[][3])
+void VecRotToMat3(float *vec, float phi, float mat[][3])
{
/* rotation of phi radials around vec */
float vx, vx2, vy, vy2, vz, vz2, co, si;
@@ -2939,7 +2944,7 @@ void VecRotToMat3( float *vec, float phi, float mat[][3])
}
-void VecRotToMat4( float *vec, float phi, float mat[][4])
+void VecRotToMat4(float *vec, float phi, float mat[][4])
{
float tmat[3][3];
@@ -2948,7 +2953,7 @@ void VecRotToMat4( float *vec, float phi, float mat[][4])
Mat4CpyMat3(mat, tmat);
}
-void VecRotToQuat( float *vec, float phi, float *quat)
+void VecRotToQuat(float *vec, float phi, float *quat)
{
/* rotation of phi radials around vec */
float si;
@@ -2957,7 +2962,7 @@ void VecRotToQuat( float *vec, float phi, float *quat)
quat[2]= vec[1];
quat[3]= vec[2];
- if( Normalize(quat+1) == 0.0) {
+ if( Normalize(quat+1) == 0.0f) {
QuatOne(quat);
}
else {
@@ -2981,7 +2986,7 @@ float VecAngle3(float *v1, float *v2, float *v3)
Normalize(vec1);
Normalize(vec2);
- return NormalizedVecAngle2(vec1, vec2) * 180.0/M_PI;
+ return NormalizedVecAngle2(vec1, vec2) * (float)(180.0/M_PI);
}
float VecAngle3_2D(float *v1, float *v2, float *v3)
@@ -2997,7 +3002,7 @@ float VecAngle3_2D(float *v1, float *v2, float *v3)
Normalize2(vec1);
Normalize2(vec2);
- return NormalizedVecAngle2_2D(vec1, vec2) * 180.0/M_PI;
+ return NormalizedVecAngle2_2D(vec1, vec2) * (float)(180.0/M_PI);
}
/* Return the shortest angle in degrees between the 2 vectors */
@@ -3010,7 +3015,7 @@ float VecAngle2(float *v1, float *v2)
Normalize(vec1);
Normalize(vec2);
- return NormalizedVecAngle2(vec1, vec2)* 180.0/M_PI;
+ return NormalizedVecAngle2(vec1, vec2)* (float)(180.0/M_PI);
}
float NormalizedVecAngle2(float *v1, float *v2)
@@ -3022,11 +3027,11 @@ float NormalizedVecAngle2(float *v1, float *v2)
vec[0]= -v2[0];
vec[1]= -v2[1];
vec[2]= -v2[2];
-
- return (float)M_PI - 2.0f*saasin(VecLenf(vec, v1)/2.0f);
+
+ return (float)M_PI - 2.0f*(float)saasin(VecLenf(vec, v1)/2.0f);
}
else
- return 2.0f*saasin(VecLenf(v2, v1)/2.0);
+ return 2.0f*(float)saasin(VecLenf(v2, v1)/2.0f);
}
float NormalizedVecAngle2_2D(float *v1, float *v2)
@@ -3037,18 +3042,18 @@ float NormalizedVecAngle2_2D(float *v1, float *v2)
vec[0]= -v2[0];
vec[1]= -v2[1];
-
+
return (float)M_PI - 2.0f*saasin(Vec2Lenf(vec, v1)/2.0f);
}
else
- return 2.0f*saasin(Vec2Lenf(v2, v1)/2.0);
+ return 2.0f*(float)saasin(Vec2Lenf(v2, v1)/2.0f);
}
void euler_rot(float *beul, float ang, char axis)
{
float eul[3], mat1[3][3], mat2[3][3], totmat[3][3];
- eul[0]= eul[1]= eul[2]= 0.0;
+ eul[0]= eul[1]= eul[2]= 0.0f;
if(axis=='x') eul[0]= ang;
else if(axis=='y') eul[1]= ang;
else eul[2]= ang;
@@ -3068,33 +3073,32 @@ void compatible_eul(float *eul, float *oldrot)
float dx, dy, dz;
/* correct differences of about 360 degrees first */
-
dx= eul[0] - oldrot[0];
dy= eul[1] - oldrot[1];
dz= eul[2] - oldrot[2];
- while( fabs(dx) > 5.1) {
- if(dx > 0.0) eul[0] -= 2.0*M_PI; else eul[0]+= 2.0*M_PI;
+ while(fabs(dx) > 5.1) {
+ if(dx > 0.0f) eul[0] -= 2.0f*(float)M_PI; else eul[0]+= 2.0f*(float)M_PI;
dx= eul[0] - oldrot[0];
}
- while( fabs(dy) > 5.1) {
- if(dy > 0.0) eul[1] -= 2.0*M_PI; else eul[1]+= 2.0*M_PI;
+ while(fabs(dy) > 5.1) {
+ if(dy > 0.0f) eul[1] -= 2.0f*(float)M_PI; else eul[1]+= 2.0f*(float)M_PI;
dy= eul[1] - oldrot[1];
}
- while( fabs(dz) > 5.1 ) {
- if(dz > 0.0) eul[2] -= 2.0*M_PI; else eul[2]+= 2.0*M_PI;
+ while(fabs(dz) > 5.1) {
+ if(dz > 0.0f) eul[2] -= 2.0f*(float)M_PI; else eul[2]+= 2.0f*(float)M_PI;
dz= eul[2] - oldrot[2];
}
/* is 1 of the axis rotations larger than 180 degrees and the other small? NO ELSE IF!! */
if( fabs(dx) > 3.2 && fabs(dy)<1.6 && fabs(dz)<1.6 ) {
- if(dx > 0.0) eul[0] -= 2.0*M_PI; else eul[0]+= 2.0*M_PI;
+ if(dx > 0.0) eul[0] -= 2.0f*(float)M_PI; else eul[0]+= 2.0f*(float)M_PI;
}
if( fabs(dy) > 3.2 && fabs(dz)<1.6 && fabs(dx)<1.6 ) {
- if(dy > 0.0) eul[1] -= 2.0*M_PI; else eul[1]+= 2.0*M_PI;
+ if(dy > 0.0) eul[1] -= 2.0f*(float)M_PI; else eul[1]+= 2.0f*(float)M_PI;
}
if( fabs(dz) > 3.2 && fabs(dx)<1.6 && fabs(dy)<1.6 ) {
- if(dz > 0.0) eul[2] -= 2.0*M_PI; else eul[2]+= 2.0*M_PI;
+ if(dz > 0.0) eul[2] -= 2.0f*(float)M_PI; else eul[2]+= 2.0f*(float)M_PI;
}
/* the method below was there from ancient days... but why! probably because the code sucks :)
@@ -3137,8 +3141,8 @@ void Mat3ToCompatibleEul(float mat[][3], float *eul, float *oldrot)
compatible_eul(eul1, oldrot);
compatible_eul(eul2, oldrot);
- d1= fabs(eul1[0]-oldrot[0]) + fabs(eul1[1]-oldrot[1]) + fabs(eul1[2]-oldrot[2]);
- d2= fabs(eul2[0]-oldrot[0]) + fabs(eul2[1]-oldrot[1]) + fabs(eul2[2]-oldrot[2]);
+ d1= (float)fabs(eul1[0]-oldrot[0]) + (float)fabs(eul1[1]-oldrot[1]) + (float)fabs(eul1[2]-oldrot[2]);
+ d2= (float)fabs(eul2[0]-oldrot[0]) + (float)fabs(eul2[1]-oldrot[1]) + (float)fabs(eul2[2]-oldrot[2]);
/* return best, which is just the one with lowest difference */
if( d1 > d2) {
@@ -3155,14 +3159,14 @@ void Mat3ToCompatibleEul(float mat[][3], float *eul, float *oldrot)
void SizeToMat3( float *size, float mat[][3])
{
mat[0][0]= size[0];
- mat[0][1]= 0.0;
- mat[0][2]= 0.0;
+ mat[0][1]= 0.0f;
+ mat[0][2]= 0.0f;
mat[1][1]= size[1];
- mat[1][0]= 0.0;
- mat[1][2]= 0.0;
+ mat[1][0]= 0.0f;
+ mat[1][2]= 0.0f;
mat[2][2]= size[2];
- mat[2][1]= 0.0;
- mat[2][0]= 0.0;
+ mat[2][1]= 0.0f;
+ mat[2][0]= 0.0f;
}
void SizeToMat4( float *size, float mat[][4])
@@ -3194,7 +3198,7 @@ void Mat4ToSize( float mat[][4], float *size)
float Mat3ToScalef(float mat[][3])
{
/* unit length vector */
- float unit_vec[3] = {0.577350269189626, 0.577350269189626, 0.577350269189626};
+ float unit_vec[3] = {0.577350269189626f, 0.577350269189626f, 0.577350269189626f};
Mat3MulVecfl(mat, unit_vec);
return VecLength(unit_vec);
}
@@ -3219,12 +3223,12 @@ void triatoquat( float *v1, float *v2, float *v3, float *quat)
n[0]= vec[1];
n[1]= -vec[0];
- n[2]= 0.0;
+ n[2]= 0.0f;
Normalize(n);
- if(n[0]==0.0 && n[1]==0.0) n[0]= 1.0;
+ if(n[0]==0.0f && n[1]==0.0f) n[0]= 1.0f;
- angle= -0.5f*saacos(vec[2]);
+ angle= -0.5f*(float)saacos(vec[2]);
co= (float)cos(angle);
si= (float)sin(angle);
q1[0]= co;
@@ -3239,7 +3243,7 @@ void triatoquat( float *v1, float *v2, float *v3, float *quat)
Mat3MulVecfl(imat, vec);
/* what angle has this line with x-axis? */
- vec[2]= 0.0;
+ vec[2]= 0.0f;
Normalize(vec);
angle= (float)(0.5*atan2(vec[1], vec[0]));
@@ -3314,12 +3318,11 @@ float Normalize2(float *n)
if(d>1.0e-35F) {
d= (float)sqrt(d);
-
n[0]/=d;
n[1]/=d;
} else {
- n[0]=n[1]= 0.0;
- d= 0.0;
+ n[0]=n[1]= 0.0f;
+ d= 0.0f;
}
return d;
}
@@ -3384,9 +3387,9 @@ void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b)
void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv)
{
float y, u, v;
- y= 0.299*r + 0.587*g + 0.114*b;
- u=-0.147*r - 0.289*g + 0.436*b;
- v= 0.615*r - 0.515*g - 0.100*b;
+ y= 0.299f*r + 0.587f*g + 0.114f*b;
+ u=-0.147f*r - 0.289f*g + 0.436f*b;
+ v= 0.615f*r - 0.515f*g - 0.100f*b;
*ly=y;
*lu=u;
@@ -3396,9 +3399,9 @@ void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv)
void yuv_to_rgb(float y, float u, float v, float *lr, float *lg, float *lb)
{
float r, g, b;
- r=y+1.140*v;
- g=y-0.394*u - 0.581*v;
- b=y+2.032*u;
+ r=y+1.140f*v;
+ g=y-0.394f*u - 0.581f*v;
+ b=y+2.032f*u;
*lr=r;
*lg=g;
@@ -3410,14 +3413,14 @@ void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr)
float sr,sg, sb;
float y, cr, cb;
- sr=255.0*r;
- sg=255.0*g;
- sb=255.0*b;
+ sr=255.0f*r;
+ sg=255.0f*g;
+ sb=255.0f*b;
- y=(0.257*sr)+(0.504*sg)+(0.098*sb)+16.0;
- cb=(-0.148*sr)-(0.291*sg)+(0.439*sb)+128.0;
- cr=(0.439*sr)-(0.368*sg)-(0.071*sb)+128.0;
+ y=(0.257f*sr)+(0.504f*sg)+(0.098f*sb)+16.0f;
+ cb=(-0.148f*sr)-(0.291f*sg)+(0.439f*sb)+128.0f;
+ cr=(0.439f*sr)-(0.368f*sg)-(0.071f*sb)+128.0f;
*ly=y;
*lcb=cb;
@@ -3428,13 +3431,13 @@ void ycc_to_rgb(float y, float cb, float cr, float *lr, float *lg, float *lb)
{
float r,g,b;
- r=1.164*(y-16)+1.596*(cr-128);
- g=1.164*(y-16)-0.813*(cr-128)-0.392*(cb-128);
- b=1.164*(y-16)+2.017*(cb-128);
+ r=1.164f*(y-16.0f)+1.596f*(cr-128.0f);
+ g=1.164f*(y-16.0f)-0.813f*(cr-128.0f)-0.392f*(cb-128.0f);
+ b=1.164f*(y-16.0f)+2.017f*(cb-128.0f);
- *lr=r/255.0;
- *lg=g/255.0;
- *lb=b/255.0;
+ *lr=r/255.0f;
+ *lg=g/255.0f;
+ *lb=b/255.0f;
}
void hex_to_rgb(char *hexcol, float *r, float *g, float *b)
@@ -3444,9 +3447,9 @@ void hex_to_rgb(char *hexcol, float *r, float *g, float *b)
if (hexcol[0] == '#') hexcol++;
if (sscanf(hexcol, "%02x%02x%02x", &ri, &gi, &bi)) {
- *r = ri / 255.0;
- *g = gi / 255.0;
- *b = bi / 255.0;
+ *r = ri / 255.0f;
+ *g = gi / 255.0f;
+ *b = bi / 255.0f;
}
}
@@ -3464,14 +3467,14 @@ void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv)
cmin = (b<cmin ? b:cmin);
v = cmax; /* value */
- if (cmax!=0.0)
+ if (cmax != 0.0f)
s = (cmax - cmin)/cmax;
else {
- s = 0.0;
- h = 0.0;
+ s = 0.0f;
+ h = 0.0f;
}
- if (s == 0.0)
- h = -1.0;
+ if (s == 0.0f)
+ h = -1.0f;
else {
cdelta = cmax-cmin;
rc = (cmax-r)/cdelta;
@@ -3485,13 +3488,13 @@ void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv)
else
h = 4.0f+gc-rc;
h = h*60.0f;
- if (h<0.0f)
+ if (h < 0.0f)
h += 360.0f;
}
*ls = s;
- *lh = h/360.0f;
- if( *lh < 0.0) *lh= 0.0;
+ *lh = h / 360.0f;
+ if(*lh < 0.0f) *lh= 0.0f;
*lv = v;
}
@@ -3501,14 +3504,14 @@ void xyz_to_rgb(float xc, float yc, float zc, float *r, float *g, float *b, int
{
switch (colorspace) {
case BLI_CS_SMPTE:
- *r = (3.50570 * xc) + (-1.73964 * yc) + (-0.544011 * zc);
- *g = (-1.06906 * xc) + (1.97781 * yc) + (0.0351720 * zc);
- *b = (0.0563117 * xc) + (-0.196994 * yc) + (1.05005 * zc);
+ *r = (3.50570f * xc) + (-1.73964f * yc) + (-0.544011f * zc);
+ *g = (-1.06906f * xc) + (1.97781f * yc) + (0.0351720f * zc);
+ *b = (0.0563117f * xc) + (-0.196994f * yc) + (1.05005f * zc);
break;
case BLI_CS_REC709:
- *r = (3.240476 * xc) + (-1.537150 * yc) + (-0.498535 * zc);
- *g = (-0.969256 * xc) + (1.875992 * yc) + (0.041556 * zc);
- *b = (0.055648 * xc) + (-0.204043 * yc) + (1.057311 * zc);
+ *r = (3.240476f * xc) + (-1.537150f * yc) + (-0.498535f * zc);
+ *g = (-0.969256f * xc) + (1.875992f * yc) + (0.041556f * zc);
+ *b = (0.055648f * xc) + (-0.204043f * yc) + (1.057311f * zc);
break;
case BLI_CS_CIE:
*r = (2.28783848734076f * xc) + (-0.833367677835217f * yc) + (-0.454470795871421f * zc);
@@ -3553,13 +3556,12 @@ int constrain_rgb(float *r, float *g, float *b)
static void gamma_correct(float *c)
{
/* Rec. 709 gamma correction. */
- float cc = 0.018;
+ float cc = 0.018f;
- if (*c < cc) {
- *c *= ((1.099 * pow(cc, 0.45)) - 0.099) / cc;
- } else {
- *c = (1.099 * pow(*c, 0.45)) - 0.099;
- }
+ if (*c < cc)
+ *c *= ((1.099f * (float)pow(cc, 0.45)) - 0.099f) / cc;
+ else
+ *c = (1.099f * (float)pow(*c, 0.45)) - 0.099f;
}
void gamma_correct_rgb(float *r, float *g, float *b)
@@ -3625,14 +3627,13 @@ void tubemap(float x, float y, float z, float *u, float *v)
{
float len;
- *v = (z + 1.0) / 2.0;
+ *v = (z + 1.0f) / 2.0f;
- len= sqrt(x*x+y*y);
- if(len>0) {
- *u = (1.0 - (atan2(x/len,y/len) / M_PI)) / 2.0;
- } else {
+ len= (float)sqrt(x*x+y*y);
+ if(len > 0.0f)
+ *u = (float)((1.0 - (atan2(x/len,y/len) / M_PI)) / 2.0);
+ else
*v = *u = 0.0f; /* to avoid un-initialized variables */
- }
}
/* ------------------------------------------------------------------------- */
@@ -3641,14 +3642,13 @@ void spheremap(float x, float y, float z, float *u, float *v)
{
float len;
- len= sqrt(x*x+y*y+z*z);
- if(len>0.0) {
-
- if(x==0.0 && y==0.0) *u= 0.0; /* othwise domain error */
- else *u = (1.0 - atan2(x,y)/M_PI )/2.0;
+ len= (float)sqrt(x*x+y*y+z*z);
+ if(len > 0.0f) {
+ if(x==0.0f && y==0.0f) *u= 0.0f; /* othwise domain error */
+ else *u = (float)((1.0 - (float)atan2(x,y) / M_PI) / 2.0);
z/=len;
- *v = 1.0- saacos(z)/M_PI;
+ *v = 1.0f - (float)saacos(z)/(float)M_PI;
} else {
*v = *u = 0.0f; /* to avoid un-initialized variables */
}
@@ -3959,7 +3959,7 @@ static int getLowestRoot(float a, float b, float c, float maxR, float* root)
{
// calculate the two roots: (if determinant == 0 then
// x1==x2 but let’s disregard that slight optimization)
- float sqrtD = sqrt(determinant);
+ float sqrtD = (float)sqrt(determinant);
float r1 = (-b - sqrtD) / (2.0f*a);
float r2 = (-b + sqrtD) / (2.0f*a);
@@ -4378,6 +4378,7 @@ float lambda_cp_line_ex(float p[3], float l1[3], float l2[3], float cp[3])
return lambda;
}
+#if 0
/* little sister we only need to know lambda */
static float lambda_cp_line(float p[3], float l1[3], float l2[3])
{
@@ -4386,6 +4387,7 @@ static float lambda_cp_line(float p[3], float l1[3], float l2[3])
VecSubf(h, p, l1);
return(Inpf(u,h)/Inpf(u,u));
}
+#endif
/* Similar to LineIntersectsTriangleUV, except it operates on a quad and in 2d, assumes point is in quad */
void PointInQuad2DUV(float v0[2], float v1[2], float v2[2], float v3[2], float pt[2], float *uv)
@@ -4513,6 +4515,79 @@ void PointInFace2DUV(int isquad, float v0[2], float v1[2], float v2[2], float v3
}
}
+int IsPointInTri2D(float v1[2], float v2[2], float v3[2], float pt[2])
+{
+ float inp1, inp2, inp3;
+
+ inp1= (v2[0]-v1[0])*(v1[1]-pt[1]) + (v1[1]-v2[1])*(v1[0]-pt[0]);
+ inp2= (v3[0]-v2[0])*(v2[1]-pt[1]) + (v2[1]-v3[1])*(v2[0]-pt[0]);
+ inp3= (v1[0]-v3[0])*(v3[1]-pt[1]) + (v3[1]-v1[1])*(v3[0]-pt[0]);
+
+ if(inp1<=0.0f && inp2<=0.0f && inp3<=0.0f) return 1;
+ if(inp1>=0.0f && inp2>=0.0f && inp3>=0.0f) return 1;
+
+ return 0;
+}
+
+#if 0
+int IsPointInTri2D(float v0[2], float v1[2], float v2[2], float pt[2])
+{
+ /* not for quads, use for our abuse of LineIntersectsTriangleUV */
+ float p1_3d[3], p2_3d[3], v0_3d[3], v1_3d[3], v2_3d[3];
+ /* not used */
+ float lambda, uv[3];
+
+ p1_3d[0] = p2_3d[0] = uv[0]= pt[0];
+ p1_3d[1] = p2_3d[1] = uv[1]= uv[2]= pt[1];
+ p1_3d[2] = 1.0f;
+ p2_3d[2] = -1.0f;
+ v0_3d[2] = v1_3d[2] = v2_3d[2] = 0.0;
+
+ /* generate a new fuv, (this is possibly a non optimal solution,
+ * since we only need 2d calculation but use 3d func's)
+ *
+ * this method makes an imaginary triangle in 2d space using the UV's from the derived mesh face
+ * Then find new uv coords using the fuv and this face with LineIntersectsTriangleUV.
+ * This means the new values will be correct in relation to the derived meshes face.
+ */
+ Vec2Copyf(v0_3d, v0);
+ Vec2Copyf(v1_3d, v1);
+ Vec2Copyf(v2_3d, v2);
+
+ /* Doing this in 3D is not nice */
+ return LineIntersectsTriangle(p1_3d, p2_3d, v0_3d, v1_3d, v2_3d, &lambda, uv);
+}
+#endif
+
+/*
+
+ x1,y2
+ | \
+ | \ .(a,b)
+ | \
+ x1,y1-- x2,y1
+
+*/
+int IsPointInTri2DInts(int x1, int y1, int x2, int y2, int a, int b)
+{
+ float v1[2], v2[2], v3[2], p[2];
+
+ v1[0]= (float)x1;
+ v1[1]= (float)y1;
+
+ v2[0]= (float)x1;
+ v2[1]= (float)y2;
+
+ v3[0]= (float)x2;
+ v3[1]= (float)y1;
+
+ p[0]= (float)a;
+ p[1]= (float)b;
+
+ return IsPointInTri2D(v1, v2, v3, p);
+
+}
+
/* (x1,v1)(t1=0)------(x2,v2)(t2=1), 0<t<1 --> (x,v)(t) */
void VecfCubicInterpol(float *x1, float *v1, float *x2, float *v2, float t, float *x, float *v)
{
@@ -4563,6 +4638,7 @@ but see a 'spat' which is a deformed cube with paired parallel planes needs only
return 1;
}
+#if 0
/*adult sister defining the slice planes by the origin and the normal
NOTE |normal| may not be 1 but defining the thickness of the slice*/
static int point_in_slice_as(float p[3],float origin[3],float normal[3])
@@ -4583,6 +4659,7 @@ static int point_in_slice_m(float p[3],float origin[3],float normal[3],float lns
if (h < 0.0f || h > 1.0f) return 0;
return 1;
}
+#endif
int point_in_tri_prism(float p[3], float v1[3], float v2[3], float v3[3])
@@ -4740,5 +4817,5 @@ void tangent_from_uv(float *uv1, float *uv2, float *uv3, float *co1, float *co2,
/* used for zoom values*/
float power_of_2(float val) {
- return pow(2, ceil(log(val) / log(2)));
+ return (float)pow(2, ceil(log(val) / log(2)));
}
diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c
index ac0c4bf4efd..85a95fa6e66 100644
--- a/source/blender/blenlib/intern/bpath.c
+++ b/source/blender/blenlib/intern/bpath.c
@@ -26,32 +26,32 @@
* ***** END GPL LICENSE BLOCK *****
*/
-#include "BLI_bpath.h"
-#include "BKE_global.h"
-#include "BIF_screen.h" /* only for wait cursor */
+#include "MEM_guardedalloc.h"
+
#include "DNA_ID.h" /* Library */
#include "DNA_vfont_types.h"
#include "DNA_image_types.h"
#include "DNA_sound_types.h"
#include "DNA_scene_types.h" /* to get the current frame */
#include "DNA_sequence_types.h"
-#include <stdlib.h>
-#include <string.h>
+#include "DNA_text_types.h"
-#include "BKE_main.h" /* so we can access G.main->*.first */
-#include "BKE_image.h" /* so we can check the image's type */
+#include "BLI_blenlib.h"
+#include "BLI_bpath.h"
-#include "blendef.h"
+#include "BKE_global.h"
+#include "BKE_image.h" /* so we can check the image's type */
+#include "BKE_main.h" /* so we can access G.main->*.first */
+#include "BKE_sequence.h"
+#include "BKE_text.h" /* for writing to a textblock */
#include "BKE_utildefines.h"
-#include "MEM_guardedalloc.h"
+//XXX #include "BIF_screen.h" /* only for wait cursor */
+//
/* for sequence */
-#include "BSE_sequence.h"
-
-/* for writing to a textblock */
-#include "BKE_text.h"
-#include "BLI_blenlib.h"
-#include "DNA_text_types.h"
+//XXX #include "BSE_sequence.h"
+//XXX define below from BSE_sequence.h - otherwise potentially odd behaviour
+#define SEQ_HAS_PATH(seq) (seq->type==SEQ_MOVIE || seq->type==SEQ_HD_SOUND || seq->type==SEQ_RAM_SOUND || seq->type==SEQ_IMAGE)
/* path/file handeling stuff */
#ifndef WIN32
@@ -69,7 +69,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-
+#include <string.h>
#define FILE_MAX 240
@@ -201,7 +201,9 @@ static struct bSound *snd_stepdata__internal(struct bSound *snd, int step_next)
return snd;
}
-static struct Sequence *seq_stepdata__internal(struct BPathIterator *bpi, int step_next) {
+static struct Sequence *seq_stepdata__internal(struct BPathIterator *bpi, int step_next)
+{
+ Editing *ed;
Sequence *seq;
/* Initializing */
@@ -214,11 +216,11 @@ static struct Sequence *seq_stepdata__internal(struct BPathIterator *bpi, int st
}
while (bpi->seqdata.scene) {
-
- if (bpi->seqdata.scene->ed) {
+ ed= seq_give_editing(bpi->seqdata.scene, 0);
+ if (ed) {
if (bpi->seqdata.seqar == NULL) {
/* allocate the sequencer array */
- build_seqar( &(((Editing *)bpi->seqdata.scene->ed)->seqbase), &bpi->seqdata.seqar, &bpi->seqdata.totseq);
+ seq_array(ed, &bpi->seqdata.seqar, &bpi->seqdata.totseq, 0);
bpi->seqdata.seq = 0;
}
@@ -657,7 +659,7 @@ void findMissingFiles(char *str) {
char dirname[FILE_MAX], filename[FILE_MAX], filename_new[FILE_MAX];
- waitcursor( 1 );
+ //XXX waitcursor( 1 );
BLI_split_dirfile_basic(str, dirname, NULL);
@@ -668,9 +670,9 @@ void findMissingFiles(char *str) {
libpath = BLI_bpathIterator_getLib(&bpi);
/* Check if esc was pressed because searching files can be slow */
- if (blender_test_break()) {
+ /*XXX if (blender_test_break()) {
break;
- }
+ }*/
if (libpath==NULL) {
@@ -706,5 +708,5 @@ void findMissingFiles(char *str) {
}
BLI_bpathIterator_free(&bpi);
- waitcursor( 0 );
+ //XXX waitcursor( 0 );
}
diff --git a/source/blender/blenlib/intern/dynamiclist.c b/source/blender/blenlib/intern/dynamiclist.c
new file mode 100644
index 00000000000..fbb87124bba
--- /dev/null
+++ b/source/blender/blenlib/intern/dynamiclist.c
@@ -0,0 +1,265 @@
+/* util.c
+ *
+ * various string, file, list operations.
+ *
+ *
+ * $Id: util.c 17433 2008-11-12 21:16:53Z blendix $
+ *
+ * ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 *****
+ *
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_listBase.h"
+
+#include "BLI_listbase.h"
+#include "BLI_dynamiclist.h"
+
+#define PAGE_SIZE 4
+
+/*=====================================================================================*/
+/* Methods for access array (realloc) */
+/*=====================================================================================*/
+
+/* remove item with index */
+static void rem_array_item(struct DynamicArray *da, unsigned int index)
+{
+ da->items[index]=NULL;
+ da->count--;
+ if(index==da->last_item_index){
+ while((!da->items[da->last_item_index]) && (da->last_item_index>0)){
+ da->last_item_index--;
+ }
+ }
+}
+
+/* add array (if needed, then realloc) */
+static void add_array_item(struct DynamicArray *da, void *item, unsigned int index)
+{
+ /* realloc of access array */
+ if(da->max_item_index < index){
+ unsigned int i, max = da->max_item_index;
+ void **nitems;
+
+ do {
+ da->max_item_index += PAGE_SIZE; /* OS can allocate only PAGE_SIZE Bytes */
+ } while(da->max_item_index<=index);
+
+ nitems = (void**)MEM_mallocN(sizeof(void*)*(da->max_item_index+1), "dlist access array");
+ for(i=0;i<=max;i++)
+ nitems[i] = da->items[i];
+
+ /* set rest pointers to the NULL */
+ for(i=max+1; i<=da->max_item_index; i++)
+ nitems[i]=NULL;
+
+ MEM_freeN(da->items); /* free old access array */
+ da->items = nitems;
+ }
+
+ da->items[index] = item;
+ da->count++;
+ if(index > da->last_item_index) da->last_item_index = index;
+}
+
+/* free access array */
+static void destroy_array(DynamicArray *da)
+{
+ da->count=0;
+ da->last_item_index=0;
+ da->max_item_index=0;
+ MEM_freeN(da->items);
+ da->items = NULL;
+}
+
+/* initialize dynamic array */
+static void init_array(DynamicArray *da)
+{
+ unsigned int i;
+
+ da->count=0;
+ da->last_item_index=0;
+ da->max_item_index = PAGE_SIZE-1;
+ da->items = (void*)MEM_mallocN(sizeof(void*)*(da->max_item_index+1), "dlist access array");
+ for(i=0; i<=da->max_item_index; i++) da->items[i]=NULL;
+}
+
+/* reinitialize dynamic array */
+static void reinit_array(DynamicArray *da)
+{
+ destroy_array(da);
+ init_array(da);
+}
+
+/*=====================================================================================*/
+/* Methods for two way dynamic list with access array */
+/*=====================================================================================*/
+
+/* create new two way dynamic list with access array from two way dynamic list
+ * it doesn't copy any items to new array or something like this It is strongly
+ * recomended to use BLI_dlist_ methods for adding/removing items from dynamic list
+ * unless you can end with inconsistence system !!! */
+DynamicList *BLI_dlist_from_listbase(ListBase *lb)
+{
+ DynamicList *dlist;
+ Link *item;
+ int i=0, count;
+
+ if(!lb) return NULL;
+
+ count = BLI_countlist(lb);
+
+ dlist = MEM_mallocN(sizeof(DynamicList), "temp dynamic list");
+ /* ListBase stuff */
+ dlist->lb.first = lb->first;
+ dlist->lb.last = lb->last;
+ /* access array stuff */
+ dlist->da.count=count;
+ dlist->da.max_item_index = count-1;
+ dlist->da.last_item_index = count -1;
+ dlist->da.items = (void*)MEM_mallocN(sizeof(void*)*count, "temp dlist access array");
+
+ item = (Link*)lb->first;
+ while(item){
+ dlist->da.items[i] = (void*)item;
+ item = item->next;
+ i++;
+ }
+
+ /* to prevent you of using original ListBase :-) */
+ lb->first = lb->last = NULL;
+
+ return dlist;
+}
+
+/* take out ListBase from DynamicList and destroy all temporary structures of DynamicList */
+ListBase *BLI_listbase_from_dlist(DynamicList *dlist, ListBase *lb)
+{
+ if(!dlist) return NULL;
+
+ if(!lb) lb = (ListBase*)MEM_mallocN(sizeof(ListBase), "ListBase");
+
+ lb->first = dlist->lb.first;
+ lb->last = dlist->lb.last;
+
+ /* free all items of access array */
+ MEM_freeN(dlist->da.items);
+ /* free DynamicList*/
+ MEM_freeN(dlist);
+
+ return lb;
+}
+
+/* return pointer at item from th dynamic list with access array */
+void *BLI_dlist_find_link(DynamicList *dlist, unsigned int index)
+{
+ if(!dlist || !dlist->da.items) return NULL;
+
+ if((index <= dlist->da.last_item_index) && (index >= 0) && (dlist->da.count>0)){
+ return dlist->da.items[index];
+ }
+ else {
+ return NULL;
+ }
+}
+
+/* return count of items in the dynamic list with access array */
+unsigned int BLI_count_items(DynamicList *dlist)
+{
+ if(!dlist) return 0;
+
+ return dlist->da.count;
+}
+
+/* free item from the dynamic list with access array */
+void BLI_dlist_free_item(DynamicList *dlist, unsigned int index)
+{
+ if(!dlist || !dlist->da.items) return;
+
+ if((index <= dlist->da.last_item_index) && (dlist->da.items[index])){
+ BLI_freelinkN(&(dlist->lb), dlist->da.items[index]);
+ rem_array_item(&(dlist->da), index);
+ }
+}
+
+/* remove item from the dynamic list with access array */
+void BLI_dlist_rem_item(DynamicList *dlist, unsigned int index)
+{
+ if(!dlist || !dlist->da.items) return;
+
+ if((index <= dlist->da.last_item_index) && (dlist->da.items[index])){
+ BLI_remlink(&(dlist->lb), dlist->da.items[index]);
+ rem_array_item(&(dlist->da), index);
+ }
+}
+
+/* add item to the dynamic list with access array (index) */
+void* BLI_dlist_add_item_index(DynamicList *dlist, void *item, unsigned int index)
+{
+ if(!dlist || !dlist->da.items) return NULL;
+
+ if((index <= dlist->da.max_item_index) && (dlist->da.items[index])) {
+ /* you can't place item at used index */
+ return NULL;
+ }
+ else {
+ add_array_item(&(dlist->da), item, index);
+ BLI_addtail(&(dlist->lb), item);
+ return item;
+ }
+}
+
+/* destroy dynamic list with access array */
+void BLI_dlist_destroy(DynamicList *dlist)
+{
+ if(!dlist) return;
+
+ BLI_freelistN(&(dlist->lb));
+ destroy_array(&(dlist->da));
+}
+
+/* initialize dynamic list with access array */
+void BLI_dlist_init(DynamicList *dlist)
+{
+ if(!dlist) return;
+
+ dlist->lb.first = NULL;
+ dlist->lb.last = NULL;
+
+ init_array(&(dlist->da));
+}
+
+/* reinitialize dynamic list with acces array */
+void BLI_dlist_reinit(DynamicList *dlist)
+{
+ if(!dlist) return;
+
+ BLI_freelistN(&(dlist->lb));
+ reinit_array(&(dlist->da));
+}
+
+/*=====================================================================================*/
diff --git a/source/blender/blenlib/intern/dynamiclist.h b/source/blender/blenlib/intern/dynamiclist.h
new file mode 100644
index 00000000000..aba3eda0696
--- /dev/null
+++ b/source/blender/blenlib/intern/dynamiclist.h
@@ -0,0 +1,55 @@
+/**
+ * $Id: BLI_dynamiclist.h 13161 2008-01-07 19:13:47Z hos $
+ *
+ * ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Contributor(s): Jiri Hnidek.
+ *
+ * Documentation of Two way dynamic list with access array can be found at:
+ *
+ * http://wiki.blender.org/bin/view.pl/Blenderwiki/DynamicListWithAccessArray
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef B_DYNAMIC_LIST_H
+#define B_DYNAMIC_LIST_H
+
+#define PAGE_SIZE 4
+
+struct ListBase;
+
+/*
+ * Access array using realloc
+ */
+typedef struct DynamicArray{
+ unsigned int count; /* count of items in list */
+ unsigned int max_item_index; /* max available index */
+ unsigned int last_item_index; /* max used index */
+ void **items; /* dynamicaly allocated array of pointers
+ pointing at items in list */
+} DynamicArray;
+
+/*
+ * Two way dynamic list with access array
+ */
+typedef struct DynamicList {
+ struct DynamicArray da; /* access array */
+ struct ListBase lb; /* two way linked dynamic list */
+} DynamicList;
+
+#endif
diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c
index ebd8f4be1cf..ffebd05f2f6 100644
--- a/source/blender/blenlib/intern/fileops.c
+++ b/source/blender/blenlib/intern/fileops.c
@@ -1,10 +1,4 @@
/*
- * blenlib/fileops.h
- *
- * cleaned up (a bit) mar-01 nzc
- *
- * More low-level file things.
- *
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -37,16 +31,13 @@
#include <stdio.h>
#include <stdlib.h>
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
#include "zlib.h"
#ifdef WIN32
#include "BLI_winstuff.h"
#include <io.h>
#else
+#include <unistd.h> // for read close
#include <sys/param.h>
#endif
@@ -162,7 +153,7 @@ int BLI_is_writable(char *filename)
{
int file;
- file = open(filename, O_BINARY | O_RDWR | O_CREAT | O_TRUNC, 0666);
+ file = open(filename, O_BINARY | O_RDWR, 0666);
if (file < 0)
return 0;
diff --git a/source/blender/blenlib/intern/fnmatch.c b/source/blender/blenlib/intern/fnmatch.c
index 54114ad3448..32065283bd0 100644
--- a/source/blender/blenlib/intern/fnmatch.c
+++ b/source/blender/blenlib/intern/fnmatch.c
@@ -240,10 +240,7 @@ fnmatch (const char *pattern, const char *string, int flags)
#else
-static void BLI_FNMATCH_C_IS_EMPTY_FOR_UNIX(void)
-{
- /*intentionally empty*/
-}
+/* intentionally empty for UNIX */
#endif /* WIN32 */
diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c
index a97f2460ba1..0f2a6179964 100644
--- a/source/blender/blenlib/intern/freetypefont.c
+++ b/source/blender/blenlib/intern/freetypefont.c
@@ -30,8 +30,6 @@
* Code that uses exotic character maps is present but commented out.
*/
-#ifdef WITH_FREETYPE2
-
#ifdef WIN32
#pragma warning (disable:4244)
#endif
@@ -49,9 +47,10 @@
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
-#include "BIF_toolbox.h"
+//XXX #include "BIF_toolbox.h"
#include "BKE_global.h"
+#include "BKE_font.h"
#include "BKE_utildefines.h"
#include "DNA_vfont_types.h"
@@ -282,13 +281,7 @@ int objchr_to_ftvfontdata(VFont *vfont, FT_ULong charcode)
struct TmpFont *tf;
// Find the correct FreeType font
- tf= G.ttfdata.first;
- while(tf)
- {
- if(tf->vfont == vfont)
- break;
- tf= tf->next;
- }
+ tf= vfont_find_tmpfont(vfont);
// What, no font found. Something strange here
if(!tf) return FALSE;
@@ -432,7 +425,7 @@ static int check_freetypefont(PackedFile * pf)
&face );
if(err) {
success = 0;
- error("This is not a valid font");
+ //XXX error("This is not a valid font");
}
else {
/*
@@ -461,7 +454,7 @@ static int check_freetypefont(PackedFile * pf)
if (glyph->format == ft_glyph_format_outline ) {
success = 1;
} else {
- error("Selected Font has no outline data");
+ //XXX error("Selected Font has no outline data");
success = 0;
}
}
@@ -479,7 +472,7 @@ VFontData *BLI_vfontdata_from_freetypefont(PackedFile *pf)
//init Freetype
err = FT_Init_FreeType( &library);
if(err) {
- error("Failed to load the Freetype font library");
+ //XXX error("Failed to load the Freetype font library");
return 0;
}
@@ -504,7 +497,7 @@ int BLI_vfontchar_from_freetypefont(VFont *vfont, unsigned long character)
// Init Freetype
err = FT_Init_FreeType(&library);
if(err) {
- error("Failed to load the Freetype font library");
+ //XXX error("Failed to load the Freetype font library");
return 0;
}
@@ -519,10 +512,6 @@ int BLI_vfontchar_from_freetypefont(VFont *vfont, unsigned long character)
return TRUE;
}
-#endif // WITH_FREETYPE2
-
-
-
#if 0
// Freetype2 Outline struct
diff --git a/source/blender/blenlib/intern/graph.c b/source/blender/blenlib/intern/graph.c
index 52277063a8f..cc15c499290 100644
--- a/source/blender/blenlib/intern/graph.c
+++ b/source/blender/blenlib/intern/graph.c
@@ -279,7 +279,7 @@ void BLI_removeDoubleNodes(BGraph *graph, float limit)
BNode * BLI_FindNodeByPosition(BGraph *graph, float *p, float limit)
{
BNode *closest_node = NULL, *node;
- float min_distance;
+ float min_distance = 0.0f;
for(node = graph->nodes.first; node; node = node->next)
{
diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c
new file mode 100644
index 00000000000..e0fd5c37494
--- /dev/null
+++ b/source/blender/blenlib/intern/listbase.c
@@ -0,0 +1,361 @@
+/* util.c
+ *
+ * various string, file, list operations.
+ *
+ *
+ * $Id: util.c 17433 2008-11-12 21:16:53Z blendix $
+ *
+ * ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 *****
+ *
+ */
+
+#include <string.h>
+#include <stdlib.h>
+
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_listBase.h"
+
+#include "BLI_listbase.h"
+
+
+/* implementation */
+
+/* Ripped this from blender.c */
+void addlisttolist(ListBase *list1, ListBase *list2)
+{
+ if (list2->first==0) return;
+
+ if (list1->first==0) {
+ list1->first= list2->first;
+ list1->last= list2->last;
+ }
+ else {
+ ((Link *)list1->last)->next= list2->first;
+ ((Link *)list2->first)->prev= list1->last;
+ list1->last= list2->last;
+ }
+ list2->first= list2->last= 0;
+}
+
+void BLI_addhead(ListBase *listbase, void *vlink)
+{
+ Link *link= vlink;
+
+ if (link == NULL) return;
+ if (listbase == NULL) return;
+
+ link->next = listbase->first;
+ link->prev = NULL;
+
+ if (listbase->first) ((Link *)listbase->first)->prev = link;
+ if (listbase->last == NULL) listbase->last = link;
+ listbase->first = link;
+}
+
+
+void BLI_addtail(ListBase *listbase, void *vlink)
+{
+ Link *link= vlink;
+
+ if (link == NULL) return;
+ if (listbase == NULL) return;
+
+ link->next = NULL;
+ link->prev = listbase->last;
+
+ if (listbase->last) ((Link *)listbase->last)->next = link;
+ if (listbase->first == 0) listbase->first = link;
+ listbase->last = link;
+}
+
+
+void BLI_remlink(ListBase *listbase, void *vlink)
+{
+ Link *link= vlink;
+
+ if (link == NULL) return;
+ if (listbase == NULL) return;
+
+ if (link->next) link->next->prev = link->prev;
+ if (link->prev) link->prev->next = link->next;
+
+ if (listbase->last == link) listbase->last = link->prev;
+ if (listbase->first == link) listbase->first = link->next;
+}
+
+
+void BLI_freelinkN(ListBase *listbase, void *vlink)
+{
+ Link *link= vlink;
+
+ if (link == NULL) return;
+ if (listbase == NULL) return;
+
+ BLI_remlink(listbase,link);
+ MEM_freeN(link);
+}
+
+
+void BLI_insertlink(ListBase *listbase, void *vprevlink, void *vnewlink)
+{
+ Link *prevlink= vprevlink;
+ Link *newlink= vnewlink;
+
+ /* newlink comes after prevlink */
+ if (newlink == NULL) return;
+ if (listbase == NULL) return;
+
+ /* empty list */
+ if (listbase->first == NULL) {
+
+ listbase->first= newlink;
+ listbase->last= newlink;
+ return;
+ }
+
+ /* insert before first element */
+ if (prevlink == NULL) {
+ newlink->next= listbase->first;
+ newlink->prev= 0;
+ newlink->next->prev= newlink;
+ listbase->first= newlink;
+ return;
+ }
+
+ /* at end of list */
+ if (listbase->last== prevlink)
+ listbase->last = newlink;
+
+ newlink->next= prevlink->next;
+ prevlink->next= newlink;
+ if (newlink->next) newlink->next->prev= newlink;
+ newlink->prev= prevlink;
+}
+
+/* This uses insertion sort, so NOT ok for large list */
+void BLI_sortlist(ListBase *listbase, int (*cmp)(void *, void *))
+{
+ Link *current = NULL;
+ Link *previous = NULL;
+ Link *next = NULL;
+
+ if (cmp == NULL) return;
+ if (listbase == NULL) return;
+
+ if (listbase->first != listbase->last)
+ {
+ for( previous = listbase->first, current = previous->next; current; current = next )
+ {
+ next = current->next;
+ previous = current->prev;
+
+ BLI_remlink(listbase, current);
+
+ while(previous && cmp(previous, current) == 1)
+ {
+ previous = previous->prev;
+ }
+
+ BLI_insertlinkafter(listbase, previous, current);
+ }
+ }
+}
+
+void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink)
+{
+ Link *prevlink= vprevlink;
+ Link *newlink= vnewlink;
+
+ /* newlink before nextlink */
+ if (newlink == NULL) return;
+ if (listbase == NULL) return;
+
+ /* empty list */
+ if (listbase->first == NULL) {
+ listbase->first= newlink;
+ listbase->last= newlink;
+ return;
+ }
+
+ /* insert at head of list */
+ if (prevlink == NULL) {
+ newlink->prev = NULL;
+ newlink->next = listbase->first;
+ ((Link *)listbase->first)->prev = newlink;
+ listbase->first = newlink;
+ return;
+ }
+
+ /* at end of list */
+ if (listbase->last == prevlink)
+ listbase->last = newlink;
+
+ newlink->next = prevlink->next;
+ newlink->prev = prevlink;
+ prevlink->next = newlink;
+ if (newlink->next) newlink->next->prev = newlink;
+}
+
+void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink)
+{
+ Link *nextlink= vnextlink;
+ Link *newlink= vnewlink;
+
+ /* newlink before nextlink */
+ if (newlink == NULL) return;
+ if (listbase == NULL) return;
+
+ /* empty list */
+ if (listbase->first == NULL) {
+ listbase->first= newlink;
+ listbase->last= newlink;
+ return;
+ }
+
+ /* insert at end of list */
+ if (nextlink == NULL) {
+ newlink->prev= listbase->last;
+ newlink->next= 0;
+ ((Link *)listbase->last)->next= newlink;
+ listbase->last= newlink;
+ return;
+ }
+
+ /* at beginning of list */
+ if (listbase->first== nextlink)
+ listbase->first = newlink;
+
+ newlink->next= nextlink;
+ newlink->prev= nextlink->prev;
+ nextlink->prev= newlink;
+ if (newlink->prev) newlink->prev->next= newlink;
+}
+
+
+void BLI_freelist(ListBase *listbase)
+{
+ Link *link, *next;
+
+ if (listbase == NULL)
+ return;
+
+ link= listbase->first;
+ while (link) {
+ next= link->next;
+ free(link);
+ link= next;
+ }
+
+ listbase->first= NULL;
+ listbase->last= NULL;
+}
+
+void BLI_freelistN(ListBase *listbase)
+{
+ Link *link, *next;
+
+ if (listbase == NULL) return;
+
+ link= listbase->first;
+ while (link) {
+ next= link->next;
+ MEM_freeN(link);
+ link= next;
+ }
+
+ listbase->first= NULL;
+ listbase->last= NULL;
+}
+
+
+int BLI_countlist(ListBase *listbase)
+{
+ Link *link;
+ int count = 0;
+
+ if (listbase) {
+ link = listbase->first;
+ while (link) {
+ count++;
+ link= link->next;
+ }
+ }
+ return count;
+}
+
+void *BLI_findlink(ListBase *listbase, int number)
+{
+ Link *link = NULL;
+
+ if (number >= 0) {
+ link = listbase->first;
+ while (link != NULL && number != 0) {
+ number--;
+ link = link->next;
+ }
+ }
+
+ return link;
+}
+
+int BLI_findindex(ListBase *listbase, void *vlink)
+{
+ Link *link= NULL;
+ int number= 0;
+
+ if (listbase == NULL) return -1;
+ if (vlink == NULL) return -1;
+
+ link= listbase->first;
+ while (link) {
+ if (link == vlink)
+ return number;
+
+ number++;
+ link= link->next;
+ }
+
+ return -1;
+}
+
+void BLI_duplicatelist(ListBase *list1, ListBase *list2) /* copy from 2 to 1 */
+{
+ struct Link *link1, *link2;
+
+ list1->first= list1->last= 0;
+
+ link2= list2->first;
+ while(link2) {
+
+ link1= MEM_dupallocN(link2);
+ BLI_addtail(list1, link1);
+
+ link2= link2->next;
+ }
+}
+
diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c
index 0dc61db2342..915a93e8e0b 100644
--- a/source/blender/blenlib/intern/rct.c
+++ b/source/blender/blenlib/intern/rct.c
@@ -70,7 +70,16 @@ int BLI_in_rctf(rctf *rect, float x, float y)
void BLI_union_rctf(rctf *rct1, rctf *rct2)
{
+
+ if(rct1->xmin>rct2->xmin) rct1->xmin= rct2->xmin;
+ if(rct1->xmax<rct2->xmax) rct1->xmax= rct2->xmax;
+ if(rct1->ymin>rct2->ymin) rct1->ymin= rct2->ymin;
+ if(rct1->ymax<rct2->ymax) rct1->ymax= rct2->ymax;
+}
+void BLI_union_rcti(rcti *rct1, rcti *rct2)
+{
+
if(rct1->xmin>rct2->xmin) rct1->xmin= rct2->xmin;
if(rct1->xmax<rct2->xmax) rct1->xmax= rct2->xmax;
if(rct1->ymin>rct2->ymin) rct1->ymin= rct2->ymin;
@@ -79,17 +88,42 @@ void BLI_union_rctf(rctf *rct1, rctf *rct2)
void BLI_init_rctf(rctf *rect, float xmin, float xmax, float ymin, float ymax)
{
- rect->xmin= xmin;
- rect->xmax= xmax;
- rect->ymin= ymin;
- rect->ymax= ymax;
+ if(xmin <= xmax) {
+ rect->xmin= xmin;
+ rect->xmax= xmax;
+ }
+ else {
+ rect->xmax= xmin;
+ rect->xmin= xmax;
+ }
+ if(ymin <= ymax) {
+ rect->ymin= ymin;
+ rect->ymax= ymax;
+ }
+ else {
+ rect->ymax= ymin;
+ rect->ymin= ymax;
+ }
}
+
void BLI_init_rcti(rcti *rect, int xmin, int xmax, int ymin, int ymax)
{
- rect->xmin= xmin;
- rect->xmax= xmax;
- rect->ymin= ymin;
- rect->ymax= ymax;
+ if(xmin <= xmax) {
+ rect->xmin= xmin;
+ rect->xmax= xmax;
+ }
+ else {
+ rect->xmax= xmin;
+ rect->xmin= xmax;
+ }
+ if(ymin <= ymax) {
+ rect->ymin= ymin;
+ rect->ymax= ymax;
+ }
+ else {
+ rect->ymax= ymin;
+ rect->ymin= ymax;
+ }
}
void BLI_translate_rcti(rcti *rect, int x, int y)
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c
index 8ba03ad1343..688a4ab901b 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -152,8 +152,9 @@ int BLI_compare(struct direntry *entry1, struct direntry *entry2)
if( strcmp(entry1->relname, ".")==0 ) return (-1);
if( strcmp(entry2->relname, ".")==0 ) return (1);
if( strcmp(entry1->relname, "..")==0 ) return (-1);
-
- return (BLI_strcasecmp(entry1->relname,entry2->relname));
+ if( strcmp(entry2->relname, "..")==0 ) return (1);
+
+ return (BLI_natstrcmp(entry1->relname,entry2->relname));
}
@@ -329,11 +330,10 @@ void BLI_builddir(char *dirname, char *relname)
void BLI_adddirstrings()
{
char datum[100];
- char buf[250];
+ char buf[512];
char size[250];
static char * types[8] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"};
int num, mode;
- off_t num1, num2, num3, num4, num5;
#ifdef WIN32
__int64 st_size;
#else
@@ -400,24 +400,19 @@ void BLI_adddirstrings()
* everyone starts using __USE_FILE_OFFSET64 or equivalent.
*/
st_size= (off_t)files[num].s.st_size;
-
- num1= st_size % 1000;
- num2= st_size/1000;
- num2= num2 % 1000;
- num3= st_size/(1000*1000);
- num3= num3 % 1000;
- num4= st_size/(1000*1000*1000);
- num4= num4 % 1000;
- num5= st_size/(1000000000000LL);
- num5= num5 % 1000;
-
- if(num5)
- sprintf(files[num].size, "%1d %03d %03d %03d K", (int)num5, (int)num4, (int)num3, (int)num2);
- else if(num4) sprintf(files[num].size, "%3d %03d %03d %03d", (int)num4, (int)num3, (int)num2, (int)num1);
- else if(num3) sprintf(files[num].size, "%7d %03d %03d", (int)num3, (int)num2, (int)num1);
- else if(num2) sprintf(files[num].size, "%11d %03d", (int)num2, (int)num1);
- else if(num1) sprintf(files[num].size, "%15d", (int)num1);
- else sprintf(files[num].size, "0");
+
+ if (st_size > 1024*1024*1024) {
+ sprintf(files[num].size, "%.2f GB", ((double)st_size)/(1024*1024*1024));
+ }
+ else if (st_size > 1024*1024) {
+ sprintf(files[num].size, "%.1f MB", ((double)st_size)/(1024*1024));
+ }
+ else if (st_size > 1024) {
+ sprintf(files[num].size, "%d KB", (int)(st_size/1024));
+ }
+ else {
+ sprintf(files[num].size, "%d B", (int)st_size);
+ }
strftime(datum, 32, "%d-%b-%y %H:%M", tm);
@@ -432,9 +427,6 @@ void BLI_adddirstrings()
sprintf(size, "%10d", (int) st_size);
}
- sprintf(buf,"%s %s %10s %s", files[num].date, files[num].time, size,
- files[num].relname);
-
sprintf(buf,"%s %s %s %7s %s %s %10s %s", file->mode1, file->mode2, file->mode3, files[num].owner, files[num].date, files[num].time, size,
files[num].relname);
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c
new file mode 100644
index 00000000000..fa4bcbc26bc
--- /dev/null
+++ b/source/blender/blenlib/intern/string.c
@@ -0,0 +1,236 @@
+/* util.c
+ *
+ * various string, file, list operations.
+ *
+ *
+ * $Id: util.c 17433 2008-11-12 21:16:53Z blendix $
+ *
+ * ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 *****
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <ctype.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_dynstr.h"
+#include "BLI_string.h"
+
+char *BLI_strdupn(const char *str, int len) {
+ char *n= MEM_mallocN(len+1, "strdup");
+ memcpy(n, str, len);
+ n[len]= '\0';
+
+ return n;
+}
+char *BLI_strdup(const char *str) {
+ return BLI_strdupn(str, strlen(str));
+}
+
+char *BLI_strncpy(char *dst, const char *src, int maxncpy) {
+ int srclen= strlen(src);
+ int cpylen= (srclen>(maxncpy-1))?(maxncpy-1):srclen;
+
+ memcpy(dst, src, cpylen);
+ dst[cpylen]= '\0';
+
+ return dst;
+}
+
+int BLI_snprintf(char *buffer, size_t count, const char *format, ...)
+{
+ int n;
+ va_list arg;
+
+ va_start(arg, format);
+ n = vsnprintf(buffer, count, format, arg);
+
+ if (n != -1 && n < count) {
+ buffer[n] = '\0';
+ } else {
+ buffer[count-1] = '\0';
+ }
+
+ va_end(arg);
+ return n;
+}
+
+char *BLI_sprintfN(const char *format, ...)
+{
+ DynStr *ds;
+ va_list arg;
+ char *n;
+
+ va_start(arg, format);
+
+ ds= BLI_dynstr_new();
+ BLI_dynstr_vappendf(ds, format, arg);
+ n= BLI_dynstr_get_cstring(ds);
+ BLI_dynstr_free(ds);
+
+ va_end(arg);
+
+ return n;
+}
+
+int BLI_streq(const char *a, const char *b)
+{
+ return (strcmp(a, b)==0);
+}
+
+int BLI_strcaseeq(const char *a, const char *b)
+{
+ return (BLI_strcasecmp(a, b)==0);
+}
+
+/* strcasestr not available in MSVC */
+char *BLI_strcasestr(const char *s, const char *find)
+{
+ register char c, sc;
+ register size_t len;
+
+ if ((c = *find++) != 0) {
+ c= tolower(c);
+ len = strlen(find);
+ do {
+ do {
+ if ((sc = *s++) == 0)
+ return (NULL);
+ sc= tolower(sc);
+ } while (sc != c);
+ } while (BLI_strncasecmp(s, find, len) != 0);
+ s--;
+ }
+ return ((char *) s);
+}
+
+
+int BLI_strcasecmp(const char *s1, const char *s2) {
+ int i;
+
+ for (i=0; ; i++) {
+ char c1 = tolower(s1[i]);
+ char c2 = tolower(s2[i]);
+
+ if (c1<c2) {
+ return -1;
+ } else if (c1>c2) {
+ return 1;
+ } else if (c1==0) {
+ break;
+ }
+ }
+
+ return 0;
+}
+
+int BLI_strncasecmp(const char *s1, const char *s2, int n) {
+ int i;
+
+ for (i=0; i<n; i++) {
+ char c1 = tolower(s1[i]);
+ char c2 = tolower(s2[i]);
+
+ if (c1<c2) {
+ return -1;
+ } else if (c1>c2) {
+ return 1;
+ } else if (c1==0) {
+ break;
+ }
+ }
+
+ return 0;
+}
+
+/* natural string compare, keeping numbers in order */
+int BLI_natstrcmp(const char *s1, const char *s2)
+{
+ int d1= 0, d2= 0;
+
+ /* if both chars are numeric, to a strtol().
+ then increase string deltas as long they are
+ numeric, else do a tolower and char compare */
+
+ while(1) {
+ char c1 = tolower(s1[d1]);
+ char c2 = tolower(s2[d2]);
+
+ if( isdigit(c1) && isdigit(c2) ) {
+ int val1, val2;
+
+ val1= (int)strtol(s1+d1, (char **)NULL, 10);
+ val2= (int)strtol(s2+d2, (char **)NULL, 10);
+
+ if (val1<val2) {
+ return -1;
+ } else if (val1>val2) {
+ return 1;
+ }
+ d1++;
+ while( isdigit(s1[d1]) )
+ d1++;
+ d2++;
+ while( isdigit(s2[d2]) )
+ d2++;
+
+ c1 = tolower(s1[d1]);
+ c2 = tolower(s2[d2]);
+ }
+
+ if (c1<c2) {
+ return -1;
+ } else if (c1>c2) {
+ return 1;
+ } else if (c1==0) {
+ break;
+ }
+ d1++;
+ d2++;
+ }
+ return 0;
+}
+
+void BLI_timestr(double _time, char *str)
+{
+ /* format 00:00:00.00 (hr:min:sec) string has to be 12 long */
+ int hr= ( (int) _time) / (60*60);
+ int min= (((int) _time) / 60 ) % 60;
+ int sec= ( (int) (_time)) % 60;
+ int hun= ( (int) (_time * 100.0)) % 100;
+
+ if (hr) {
+ sprintf(str, "%.2d:%.2d:%.2d.%.2d",hr,min,sec,hun);
+ } else {
+ sprintf(str, "%.2d:%.2d.%.2d",min,sec,hun);
+ }
+
+ str[11]=0;
+}
diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c
index 07c02b8024f..2812f17d58f 100644
--- a/source/blender/blenlib/intern/threads.c
+++ b/source/blender/blenlib/intern/threads.c
@@ -35,6 +35,8 @@
#include "MEM_guardedalloc.h"
+#include "DNA_listBase.h"
+
#include "BLI_blenlib.h"
#include "BLI_threads.h"
@@ -110,12 +112,12 @@ typedef struct ThreadSlot {
int avail;
} ThreadSlot;
-static void BLI_lock_malloc_thread(void)
+void BLI_lock_malloc_thread(void)
{
pthread_mutex_lock(&_malloc_lock);
}
-static void BLI_unlock_malloc_thread(void)
+void BLI_unlock_malloc_thread(void)
{
pthread_mutex_unlock(&_malloc_lock);
}
diff --git a/source/blender/blenlib/intern/util.c b/source/blender/blenlib/intern/util.c
index 013b9e0bb1b..df4ad4e7c75 100644
--- a/source/blender/blenlib/intern/util.c
+++ b/source/blender/blenlib/intern/util.c
@@ -102,23 +102,6 @@ static int add_win32_extension(char *name);
/* implementation */
-/* Ripped this from blender.c */
-void addlisttolist(ListBase *list1, ListBase *list2)
-{
- if (list2->first==0) return;
-
- if (list1->first==0) {
- list1->first= list2->first;
- list1->last= list2->last;
- }
- else {
- ((Link *)list1->last)->next= list2->first;
- ((Link *)list2->first)->prev= list1->last;
- list1->last= list2->last;
- }
- list2->first= list2->last= 0;
-}
-
int BLI_stringdec(char *string, char *kop, char *start, unsigned short *numlen)
{
unsigned short len, len2, nums = 0, nume = 0;
@@ -241,8 +224,9 @@ void BLI_newname(char *name, int add)
* name_offs: should be calculated using offsetof(structname, membername) macro from stddef.h
* len: maximum length of string (to prevent overflows, etc.)
* defname: the name that should be used by default if none is specified already
+ * delim: the character which acts as a delimeter between parts of the name
*/
-void BLI_uniquename(ListBase *list, void *vlink, char defname[], short name_offs, short len)
+void BLI_uniquename(ListBase *list, void *vlink, char defname[], char delim, short name_offs, short len)
{
Link *link;
char tempname[128];
@@ -278,12 +262,12 @@ void BLI_uniquename(ListBase *list, void *vlink, char defname[], short name_offs
return;
/* Strip off the suffix */
- dot = strchr(GIVE_STRADDR(vlink, name_offs), '.');
+ dot = strchr(GIVE_STRADDR(vlink, name_offs), delim);
if (dot)
*dot=0;
for (number = 1; number <= 999; number++) {
- BLI_snprintf(tempname, 128, "%s.%03d", GIVE_STRADDR(vlink, name_offs), number);
+ BLI_snprintf(tempname, 128, "%s%c%03d", GIVE_STRADDR(vlink, name_offs), delim, number);
exists = 0;
for (link= list->first; link; link= link->next) {
@@ -301,557 +285,6 @@ void BLI_uniquename(ListBase *list, void *vlink, char defname[], short name_offs
}
}
-
-void BLI_addhead(ListBase *listbase, void *vlink)
-{
- Link *link= vlink;
-
- if (link == NULL) return;
- if (listbase == NULL) return;
-
- link->next = listbase->first;
- link->prev = NULL;
-
- if (listbase->first) ((Link *)listbase->first)->prev = link;
- if (listbase->last == NULL) listbase->last = link;
- listbase->first = link;
-}
-
-
-void BLI_addtail(ListBase *listbase, void *vlink)
-{
- Link *link= vlink;
-
- if (link == NULL) return;
- if (listbase == NULL) return;
-
- link->next = NULL;
- link->prev = listbase->last;
-
- if (listbase->last) ((Link *)listbase->last)->next = link;
- if (listbase->first == 0) listbase->first = link;
- listbase->last = link;
-}
-
-
-void BLI_remlink(ListBase *listbase, void *vlink)
-{
- Link *link= vlink;
-
- if (link == NULL) return;
- if (listbase == NULL) return;
-
- if (link->next) link->next->prev = link->prev;
- if (link->prev) link->prev->next = link->next;
-
- if (listbase->last == link) listbase->last = link->prev;
- if (listbase->first == link) listbase->first = link->next;
-}
-
-
-void BLI_freelinkN(ListBase *listbase, void *vlink)
-{
- Link *link= vlink;
-
- if (link == NULL) return;
- if (listbase == NULL) return;
-
- BLI_remlink(listbase,link);
- MEM_freeN(link);
-}
-
-
-void BLI_insertlink(ListBase *listbase, void *vprevlink, void *vnewlink)
-{
- Link *prevlink= vprevlink;
- Link *newlink= vnewlink;
-
- /* newlink comes after prevlink */
- if (newlink == NULL) return;
- if (listbase == NULL) return;
-
- /* empty list */
- if (listbase->first == NULL) {
-
- listbase->first= newlink;
- listbase->last= newlink;
- return;
- }
-
- /* insert before first element */
- if (prevlink == NULL) {
- newlink->next= listbase->first;
- newlink->prev= 0;
- newlink->next->prev= newlink;
- listbase->first= newlink;
- return;
- }
-
- /* at end of list */
- if (listbase->last== prevlink)
- listbase->last = newlink;
-
- newlink->next= prevlink->next;
- prevlink->next= newlink;
- if (newlink->next) newlink->next->prev= newlink;
- newlink->prev= prevlink;
-}
-
-/* This uses insertion sort, so NOT ok for large list */
-void BLI_sortlist(ListBase *listbase, int (*cmp)(void *, void *))
-{
- Link *current = NULL;
- Link *previous = NULL;
- Link *next = NULL;
-
- if (cmp == NULL) return;
- if (listbase == NULL) return;
-
- if (listbase->first != listbase->last)
- {
- for( previous = listbase->first, current = previous->next; current; current = next )
- {
- next = current->next;
- previous = current->prev;
-
- BLI_remlink(listbase, current);
-
- while(previous && cmp(previous, current) == 1)
- {
- previous = previous->prev;
- }
-
- BLI_insertlinkafter(listbase, previous, current);
- }
- }
-}
-
-void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink)
-{
- Link *prevlink= vprevlink;
- Link *newlink= vnewlink;
-
- /* newlink before nextlink */
- if (newlink == NULL) return;
- if (listbase == NULL) return;
-
- /* empty list */
- if (listbase->first == NULL) {
- listbase->first= newlink;
- listbase->last= newlink;
- return;
- }
-
- /* insert at head of list */
- if (prevlink == NULL) {
- newlink->prev = NULL;
- newlink->next = listbase->first;
- ((Link *)listbase->first)->prev = newlink;
- listbase->first = newlink;
- return;
- }
-
- /* at end of list */
- if (listbase->last == prevlink)
- listbase->last = newlink;
-
- newlink->next = prevlink->next;
- newlink->prev = prevlink;
- prevlink->next = newlink;
- if (newlink->next) newlink->next->prev = newlink;
-}
-
-void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink)
-{
- Link *nextlink= vnextlink;
- Link *newlink= vnewlink;
-
- /* newlink before nextlink */
- if (newlink == NULL) return;
- if (listbase == NULL) return;
-
- /* empty list */
- if (listbase->first == NULL) {
- listbase->first= newlink;
- listbase->last= newlink;
- return;
- }
-
- /* insert at end of list */
- if (nextlink == NULL) {
- newlink->prev= listbase->last;
- newlink->next= 0;
- ((Link *)listbase->last)->next= newlink;
- listbase->last= newlink;
- return;
- }
-
- /* at beginning of list */
- if (listbase->first== nextlink)
- listbase->first = newlink;
-
- newlink->next= nextlink;
- newlink->prev= nextlink->prev;
- nextlink->prev= newlink;
- if (newlink->prev) newlink->prev->next= newlink;
-}
-
-
-void BLI_freelist(ListBase *listbase)
-{
- Link *link, *next;
-
- if (listbase == NULL)
- return;
-
- link= listbase->first;
- while (link) {
- next= link->next;
- free(link);
- link= next;
- }
-
- listbase->first= NULL;
- listbase->last= NULL;
-}
-
-void BLI_freelistN(ListBase *listbase)
-{
- Link *link, *next;
-
- if (listbase == NULL) return;
-
- link= listbase->first;
- while (link) {
- next= link->next;
- MEM_freeN(link);
- link= next;
- }
-
- listbase->first= NULL;
- listbase->last= NULL;
-}
-
-
-int BLI_countlist(ListBase *listbase)
-{
- Link *link;
- int count = 0;
-
- if (listbase) {
- link = listbase->first;
- while (link) {
- count++;
- link= link->next;
- }
- }
- return count;
-}
-
-void *BLI_findlink(ListBase *listbase, int number)
-{
- Link *link = NULL;
-
- if (number >= 0) {
- link = listbase->first;
- while (link != NULL && number != 0) {
- number--;
- link = link->next;
- }
- }
-
- return link;
-}
-
-int BLI_findindex(ListBase *listbase, void *vlink)
-{
- Link *link= NULL;
- int number= 0;
-
- if (listbase == NULL) return -1;
- if (vlink == NULL) return -1;
-
- link= listbase->first;
- while (link) {
- if (link == vlink)
- return number;
-
- number++;
- link= link->next;
- }
-
- return -1;
-}
-
-/*=====================================================================================*/
-/* Methods for access array (realloc) */
-/*=====================================================================================*/
-
-/* remove item with index */
-static void rem_array_item(struct DynamicArray *da, unsigned int index)
-{
- da->items[index]=NULL;
- da->count--;
- if(index==da->last_item_index){
- while((!da->items[da->last_item_index]) && (da->last_item_index>0)){
- da->last_item_index--;
- }
- }
-}
-
-/* add array (if needed, then realloc) */
-static void add_array_item(struct DynamicArray *da, void *item, unsigned int index)
-{
- /* realloc of access array */
- if(da->max_item_index < index){
- unsigned int i, max = da->max_item_index;
- void **nitems;
-
- do {
- da->max_item_index += PAGE_SIZE; /* OS can allocate only PAGE_SIZE Bytes */
- } while(da->max_item_index<=index);
-
- nitems = (void**)MEM_mallocN(sizeof(void*)*(da->max_item_index+1), "dlist access array");
- for(i=0;i<=max;i++)
- nitems[i] = da->items[i];
-
- /* set rest pointers to the NULL */
- for(i=max+1; i<=da->max_item_index; i++)
- nitems[i]=NULL;
-
- MEM_freeN(da->items); /* free old access array */
- da->items = nitems;
- }
-
- da->items[index] = item;
- da->count++;
- if(index > da->last_item_index) da->last_item_index = index;
-}
-
-/* free access array */
-static void destroy_array(DynamicArray *da)
-{
- da->count=0;
- da->last_item_index=0;
- da->max_item_index=0;
- MEM_freeN(da->items);
- da->items = NULL;
-}
-
-/* initialize dynamic array */
-static void init_array(DynamicArray *da)
-{
- unsigned int i;
-
- da->count=0;
- da->last_item_index=0;
- da->max_item_index = PAGE_SIZE-1;
- da->items = (void*)MEM_mallocN(sizeof(void*)*(da->max_item_index+1), "dlist access array");
- for(i=0; i<=da->max_item_index; i++) da->items[i]=NULL;
-}
-
-/* reinitialize dynamic array */
-static void reinit_array(DynamicArray *da)
-{
- destroy_array(da);
- init_array(da);
-}
-
-/*=====================================================================================*/
-/* Methods for two way dynamic list with access array */
-/*=====================================================================================*/
-
-/* create new two way dynamic list with access array from two way dynamic list
- * it doesn't copy any items to new array or something like this It is strongly
- * recomended to use BLI_dlist_ methods for adding/removing items from dynamic list
- * unless you can end with inconsistence system !!! */
-DynamicList *BLI_dlist_from_listbase(ListBase *lb)
-{
- DynamicList *dlist;
- Link *item;
- int i=0, count;
-
- if(!lb) return NULL;
-
- count = BLI_countlist(lb);
-
- dlist = MEM_mallocN(sizeof(DynamicList), "temp dynamic list");
- /* ListBase stuff */
- dlist->lb.first = lb->first;
- dlist->lb.last = lb->last;
- /* access array stuff */
- dlist->da.count=count;
- dlist->da.max_item_index = count-1;
- dlist->da.last_item_index = count -1;
- dlist->da.items = (void*)MEM_mallocN(sizeof(void*)*count, "temp dlist access array");
-
- item = (Link*)lb->first;
- while(item){
- dlist->da.items[i] = (void*)item;
- item = item->next;
- i++;
- }
-
- /* to prevent you of using original ListBase :-) */
- lb->first = lb->last = NULL;
-
- return dlist;
-}
-
-/* take out ListBase from DynamicList and destroy all temporary structures of DynamicList */
-ListBase *BLI_listbase_from_dlist(DynamicList *dlist, ListBase *lb)
-{
- if(!dlist) return NULL;
-
- if(!lb) lb = (ListBase*)MEM_mallocN(sizeof(ListBase), "ListBase");
-
- lb->first = dlist->lb.first;
- lb->last = dlist->lb.last;
-
- /* free all items of access array */
- MEM_freeN(dlist->da.items);
- /* free DynamicList*/
- MEM_freeN(dlist);
-
- return lb;
-}
-
-/* return pointer at item from th dynamic list with access array */
-void *BLI_dlist_find_link(DynamicList *dlist, unsigned int index)
-{
- if(!dlist || !dlist->da.items) return NULL;
-
- if((index <= dlist->da.last_item_index) && (index >= 0) && (dlist->da.count>0)){
- return dlist->da.items[index];
- }
- else {
- return NULL;
- }
-}
-
-/* return count of items in the dynamic list with access array */
-unsigned int BLI_count_items(DynamicList *dlist)
-{
- if(!dlist) return 0;
-
- return dlist->da.count;
-}
-
-/* free item from the dynamic list with access array */
-void BLI_dlist_free_item(DynamicList *dlist, unsigned int index)
-{
- if(!dlist || !dlist->da.items) return;
-
- if((index <= dlist->da.last_item_index) && (dlist->da.items[index])){
- BLI_freelinkN(&(dlist->lb), dlist->da.items[index]);
- rem_array_item(&(dlist->da), index);
- }
-}
-
-/* remove item from the dynamic list with access array */
-void BLI_dlist_rem_item(DynamicList *dlist, unsigned int index)
-{
- if(!dlist || !dlist->da.items) return;
-
- if((index <= dlist->da.last_item_index) && (dlist->da.items[index])){
- BLI_remlink(&(dlist->lb), dlist->da.items[index]);
- rem_array_item(&(dlist->da), index);
- }
-}
-
-/* add item to the dynamic list with access array (index) */
-void* BLI_dlist_add_item_index(DynamicList *dlist, void *item, unsigned int index)
-{
- if(!dlist || !dlist->da.items) return NULL;
-
- if((index <= dlist->da.max_item_index) && (dlist->da.items[index])) {
- /* you can't place item at used index */
- return NULL;
- }
- else {
- add_array_item(&(dlist->da), item, index);
- BLI_addtail(&(dlist->lb), item);
- return item;
- }
-}
-
-/* destroy dynamic list with access array */
-void BLI_dlist_destroy(DynamicList *dlist)
-{
- if(!dlist) return;
-
- BLI_freelistN(&(dlist->lb));
- destroy_array(&(dlist->da));
-}
-
-/* initialize dynamic list with access array */
-void BLI_dlist_init(DynamicList *dlist)
-{
- if(!dlist) return;
-
- dlist->lb.first = NULL;
- dlist->lb.last = NULL;
-
- init_array(&(dlist->da));
-}
-
-/* reinitialize dynamic list with acces array */
-void BLI_dlist_reinit(DynamicList *dlist)
-{
- if(!dlist) return;
-
- BLI_freelistN(&(dlist->lb));
- reinit_array(&(dlist->da));
-}
-
-/*=====================================================================================*/
-
-char *BLI_strdupn(const char *str, int len) {
- char *n= MEM_mallocN(len+1, "strdup");
- memcpy(n, str, len);
- n[len]= '\0';
-
- return n;
-}
-char *BLI_strdup(const char *str) {
- return BLI_strdupn(str, strlen(str));
-}
-
-char *BLI_strncpy(char *dst, const char *src, int maxncpy) {
- int srclen= strlen(src);
- int cpylen= (srclen>(maxncpy-1))?(maxncpy-1):srclen;
-
- memcpy(dst, src, cpylen);
- dst[cpylen]= '\0';
-
- return dst;
-}
-
-int BLI_snprintf(char *buffer, size_t count, const char *format, ...)
-{
- int n;
- va_list arg;
-
- va_start(arg, format);
- n = vsnprintf(buffer, count, format, arg);
-
- if (n != -1 && n < count) {
- buffer[n] = '\0';
- } else {
- buffer[count-1] = '\0';
- }
-
- va_end(arg);
- return n;
-}
-
-int BLI_streq(char *a, char *b) {
- return (strcmp(a, b)==0);
-}
-int BLI_strcaseeq(char *a, char *b) {
- return (BLI_strcasecmp(a, b)==0);
-}
-
/* ******************** string encoding ***************** */
/* This is quite an ugly function... its purpose is to
@@ -1395,6 +828,99 @@ char *BLI_gethome(void) {
#endif
}
+/* this function returns the path to a blender folder, if it exists,
+ * trying in this order:
+ *
+ * path_to_executable/release/folder_name (in svn)
+ * ./release/folder_name (in svn)
+ * $HOME/.blender/folder_name
+ * path_to_executable/.blender/folder_name
+ *
+ * returns NULL if none is found. */
+
+char *BLI_gethome_folder(char *folder_name)
+{
+ extern char bprogname[]; /* argv[0] from creator.c */
+ static char homedir[FILE_MAXDIR] = "";
+ static char fulldir[FILE_MAXDIR] = "";
+ char tmpdir[FILE_MAXDIR];
+ char bprogdir[FILE_MAXDIR];
+ char *s;
+ int i;
+
+ /* 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 path_to_executable/release/folder_name (in svn) */
+ if (folder_name) {
+ BLI_snprintf(tmpdir, sizeof(tmpdir), "release/%s", folder_name);
+ BLI_make_file_string("/", fulldir, bprogdir, tmpdir);
+ if (BLI_exists(fulldir)) return fulldir;
+ else fulldir[0] = '\0';
+ }
+
+ /* try ./release/folder_name (in svn) */
+ if(folder_name) {
+ BLI_snprintf(fulldir, sizeof(fulldir), "./release/%s", folder_name);
+ if (BLI_exists(fulldir)) return fulldir;
+ else fulldir[0] = '\0';
+ }
+
+ /* BLI_gethome() can return NULL if env vars are not set */
+ s = BLI_gethome();
+
+ if(!s) { /* bail if no $HOME */
+ printf("$HOME is NOT set\n");
+ return NULL;
+ }
+
+ if(strstr(s, ".blender"))
+ BLI_strncpy(homedir, s, FILE_MAXDIR);
+ else
+ BLI_make_file_string("/", homedir, s, ".blender");
+
+ /* if $HOME/.blender/folder_name exists, return it */
+ if(BLI_exists(homedir)) {
+ if (folder_name) {
+ BLI_make_file_string("/", fulldir, homedir, folder_name);
+ if(BLI_exists(fulldir))
+ return fulldir;
+ }
+ else
+ return homedir;
+ }
+ else
+ homedir[0] = '\0';
+
+ /* using tmpdir to preserve homedir (if) found above:
+ * the ideal is to have a home dir with folder_name dir inside
+ * it, but if that isn't available, it's possible to
+ * have a 'broken' home dir somewhere and a folder_name dir in the
+ * svn sources */
+ BLI_make_file_string("/", tmpdir, bprogdir, ".blender");
+
+ if(BLI_exists(tmpdir)) {
+ if(folder_name) {
+ BLI_make_file_string("/", fulldir, tmpdir, folder_name);
+ if(BLI_exists(fulldir)) {
+ BLI_strncpy(homedir, tmpdir, FILE_MAXDIR);
+ return fulldir;
+ }
+ else {
+ homedir[0] = '\0';
+ fulldir[0] = '\0';
+ }
+ }
+ else return homedir;
+ }
+
+ return NULL;
+}
+
+
void BLI_clean(char *path)
{
if(path==0) return;
@@ -1907,6 +1433,27 @@ void BLI_where_is_temp(char *fullname, int usertemp)
}
}
+char *get_install_dir(void) {
+ extern char bprogname[];
+ char *tmpname = BLI_strdup(bprogname);
+ char *cut;
+
+#ifdef __APPLE__
+ cut = strstr(tmpname, ".app");
+ if (cut) cut[0] = 0;
+#endif
+
+ cut = BLI_last_slash(tmpname);
+
+ if (cut) {
+ cut[0] = 0;
+ return tmpname;
+ } else {
+ MEM_freeN(tmpname);
+ return NULL;
+ }
+}
+
/*
* returns absolute path to the app bundle
* only useful on OS X
@@ -1925,67 +1472,6 @@ char* BLI_getbundle(void) {
}
#endif
-/* strcasestr not available in MSVC */
-char *BLI_strcasestr(const char *s, const char *find)
-{
- register char c, sc;
- register size_t len;
-
- if ((c = *find++) != 0) {
- c= tolower(c);
- len = strlen(find);
- do {
- do {
- if ((sc = *s++) == 0)
- return (NULL);
- sc= tolower(sc);
- } while (sc != c);
- } while (BLI_strncasecmp(s, find, len) != 0);
- s--;
- }
- return ((char *) s);
-}
-
-
-int BLI_strcasecmp(const char *s1, const char *s2) {
- int i;
-
- for (i=0; ; i++) {
- char c1 = tolower(s1[i]);
- char c2 = tolower(s2[i]);
-
- if (c1<c2) {
- return -1;
- } else if (c1>c2) {
- return 1;
- } else if (c1==0) {
- break;
- }
- }
-
- return 0;
-}
-
-int BLI_strncasecmp(const char *s1, const char *s2, int n) {
- int i;
-
- for (i=0; i<n; i++) {
- char c1 = tolower(s1[i]);
- char c2 = tolower(s2[i]);
-
- if (c1<c2) {
- return -1;
- } else if (c1>c2) {
- return 1;
- } else if (c1==0) {
- break;
- }
- }
-
- return 0;
-}
-
-
#ifdef WITH_ICONV
#include "iconv.h"
#include "localcharset.h"
@@ -2017,68 +1503,4 @@ void BLI_string_to_utf8(char *original, char *utf_8, const char *code)
}
#endif // WITH_ICONV
-void BLI_timestr(double _time, char *str)
-{
- /* format 00:00:00.00 (hr:min:sec) string has to be 12 long */
- int hr= ( (int) _time) / (60*60);
- int min= (((int) _time) / 60 ) % 60;
- int sec= ( (int) (_time)) % 60;
- int hun= ( (int) (_time * 100.0)) % 100;
-
- if (hr) {
- sprintf(str, "%.2d:%.2d:%.2d.%.2d",hr,min,sec,hun);
- } else {
- sprintf(str, "%.2d:%.2d.%.2d",min,sec,hun);
- }
-
- str[11]=0;
-}
-
-/* ************** 64 bits magic, trick to support up to 32 gig of address space *************** */
-/* only works for malloced pointers (8 aligned) */
-
-#ifdef __LP64__
-
-#if defined(WIN32) && !defined(FREE_WINDOWS)
-#define PMASK 0x07FFFFFFFFi64
-#else
-#define PMASK 0x07FFFFFFFFll
-#endif
-
-
-int BLI_int_from_pointer(void *poin)
-{
- intptr_t lval= (intptr_t)poin;
-
- return (int)(lval>>3);
-}
-
-void *BLI_pointer_from_int(int val)
-{
- static int firsttime= 1;
- static intptr_t basevalue= 0;
-
- if(firsttime) {
- void *poin= malloc(10000);
- basevalue= (intptr_t)poin;
- basevalue &= ~PMASK;
- printf("base: %d pointer %p\n", basevalue, poin); /* debug */
- firsttime= 0;
- free(poin);
- }
- return (void *)(basevalue | (((intptr_t)val)<<3));
-}
-
-#else
-
-int BLI_int_from_pointer(void *poin)
-{
- return (int)poin;
-}
-void *BLI_pointer_from_int(int val)
-{
- return (void *)val;
-}
-
-#endif
diff --git a/source/blender/blenlib/intern/winstuff.c b/source/blender/blenlib/intern/winstuff.c
index 666a54b54cc..2f96f7b6af1 100644
--- a/source/blender/blenlib/intern/winstuff.c
+++ b/source/blender/blenlib/intern/winstuff.c
@@ -219,9 +219,6 @@ int check_file_chars(char *filename)
#else
-static void BLI_WINSTUFF_C_IS_EMPTY_FOR_UNIX(void)
-{
- /*intentionally empty*/
-}
+/* intentionally empty for UNIX */
#endif