2.5 BLI_blenlib cleanup

DONE:
* moved almost all declarations from BLI_blenlib.h into their own proper header files.
* BLI_blenlib.h still includes all the declarations for convenience and to avoid changes in existing code
* split util.c into several files, where it wasn't done already
*    DynamicList -> dynamiclist, 
*    ListBase    -> listbase, 
*    String utility functions -> string.c
* removed a few unused macros and functions, if they're needed back, they're still in svn ;)
TODO:
* btempdir global
* further cleanup in the code of the different modules (especially util.c)
This commit is contained in:
2008-12-20 10:02:00 +00:00
parent 6343d4e233
commit ebb6628a01
23 changed files with 1483 additions and 1153 deletions

View File

@@ -62,357 +62,33 @@
#ifndef BLI_BLENLIB_H
#define BLI_BLENLIB_H
/* braindamage for the masses... needed
because fillfacebase and fillvertbase are used outside */
#include "DNA_listBase.h"
struct ListBase;
#include <stdlib.h>
extern ListBase fillfacebase;
extern ListBase fillvertbase;
/**
* @attention Defined in scanfill.c
*/
extern ListBase filledgebase;
extern char btempdir[]; /* creator.c temp dir used instead of U.tempdir, set with BLI_where_is_temp( btempdir, 1 ); */
struct chardesc;
struct direntry;
struct rctf;
struct rcti;
struct EditVert;
struct PackedFile;
struct LinkNode;
struct DynamicList;
#ifdef __cplusplus
extern "C" {
#endif
/* BLI_util.h */
char *BLI_gethome(void);
void BLI_make_file_string(const char *relabase, char *string, const char *dir, const char *file);
void BLI_make_exist(char *dir);
void BLI_make_existing_file(char *name);
void BLI_split_dirfile(char *string, char *dir, char *file);
void BLI_split_dirfile_basic(const char *string, char *dir, char *file);
void BLI_join_dirfile(char *string, const char *dir, const char *file);
int BLI_testextensie(const char *str, const char *ext);
void addlisttolist(ListBase *list1, ListBase *list2);
void BLI_insertlink(struct ListBase *listbase, void *vprevlink, void *vnewlink);
void *BLI_findlink(struct ListBase *listbase, int number);
int BLI_findindex(struct ListBase *listbase, void *vlink);
void BLI_freelistN(struct ListBase *listbase);
void BLI_addtail(struct ListBase *listbase, void *vlink);
void BLI_remlink(struct ListBase *listbase, void *vlink);
void BLI_uniquename(struct ListBase *list, void *vlink, char defname[], short name_offs, short len);
void BLI_newname(char * name, int add);
int BLI_stringdec(char *string, char *kop, char *start, unsigned short *numlen);
void BLI_stringenc(char *string, char *kop, char *start, unsigned short numlen, int pic);
void BLI_addhead(struct ListBase *listbase, void *vlink);
void BLI_insertlinkbefore(struct ListBase *listbase, void *vnextlink, void *vnewlink);
void BLI_insertlinkafter(struct ListBase *listbase, void *vprevlink, void *vnewlink);
void BLI_sortlist(struct ListBase *listbase, int (*cmp)(void *, void *));
void BLI_freelist(struct ListBase *listbase);
int BLI_countlist(struct ListBase *listbase);
void BLI_freelinkN(ListBase *listbase, void *vlink);
void BLI_duplicatelist(ListBase *list1, ListBase *list2); /* copy from 2 to 1 */
#include "BLI_listbase.h"
#include "BLI_dynamiclist.h"
void BLI_splitdirstring(char *di,char *fi);
#include "BLI_string.h"
struct DynamicList *BLI_dlist_from_listbase(struct ListBase *lb);
struct ListBase *BLI_listbase_from_dlist(struct DynamicList *dlist, struct ListBase *lb);
void * BLI_dlist_find_link(struct DynamicList *dlist, unsigned int index);
unsigned int BLI_count_items(struct DynamicList *dlist);
void BLI_dlist_free_item(struct DynamicList *dlist, unsigned int index);
void BLI_dlist_rem_item(struct DynamicList *dlist, unsigned int index);
void * BLI_dlist_add_item_index(struct DynamicList *dlist, void *item, unsigned int index);
void BLI_dlist_destroy(struct DynamicList *dlist);
void BLI_dlist_init(struct DynamicList *dlist);
void BLI_dlist_reinit(struct DynamicList *dlist);
#include "BLI_util.h"
/**
* dir can be any input, like from buttons, and this function
* converts it to a regular full path.
* Also removes garbage from directory paths, like /../ or double slashes etc
*/
void BLI_cleanup_file(const char *relabase, char *dir);
void BLI_cleanup_dir(const char *relabase, char *dir); /* same as above but adds a trailing slash */
#include "BLI_storage.h"
/* go back one directory */
int BLI_parent_dir(char *path);
#include "BLI_fileops.h"
/**
* Blender's path code replacement function.
* Bases @a path strings leading with "//" by the
* directory @a basepath, and replaces instances of
* '#' with the @a framenum. Results are written
* back into @a path.
*
* @a path The path to convert
* @a basepath The directory to base relative paths with.
* @a framenum The framenumber to replace the frame code with.
* @retval Returns true if the path was relative (started with "//").
*/
int BLI_convertstringcode(char *path, const char *basepath);
int BLI_convertstringframe(char *path, int frame);
int BLI_convertstringcwd(char *path);
#include "BLI_rect.h"
void BLI_makestringcode(const char *relfile, char *file);
#include "BLI_scanfill.h"
/**
* Change every @a from in @a string into @a to. The
* result will be in @a string
*
* @a string The string to work on
* @a from The character to replace
* @a to The character to replace with
*/
void BLI_char_switch(char *string, char from, char to);
/**
* Makes sure @a path has platform-specific slashes.
*
* @a path The path to 'clean'
*/
void BLI_clean(char *path);
/**
* Duplicates the cstring @a str into a newly mallocN'd
* string and returns it.
*
* @param str The string to be duplicated
* @retval Returns the duplicated string
*/
char *BLI_strdup(const char *str);
/**
* Duplicates the first @a len bytes of cstring @a str
* into a newly mallocN'd string and returns it. @a str
* is assumed to be at least len bytes long.
*
* @param str The string to be duplicated
* @param len The number of bytes to duplicate
* @retval Returns the duplicated string
*/
char *BLI_strdupn(const char *str, int len);
/**
* Like strncpy but ensures dst is always
* '\0' terminated.
*
* @param dst Destination for copy
* @param src Source string to copy
* @param maxncpy Maximum number of characters to copy (generally
* the size of dst)
* @retval Returns dst
*/
char *BLI_strncpy(char *dst, const char *src, int maxncpy);
/*
* Replacement for snprintf
*/
int BLI_snprintf(char *buffer, size_t count, const char *format, ...);
/**
* Compare two strings
*
* @retval True if the strings are equal, false otherwise.
*/
int BLI_streq(char *a, char *b);
/**
* Compare two strings without regard to case.
*
* @retval True if the strings are equal, false otherwise.
*/
int BLI_strcaseeq(char *a, char *b);
/* in util.c */
#ifdef WITH_ICONV
void BLI_string_to_utf8(char *original, char *utf_8, const char *code);
#endif
/**
* Read a file as ASCII lines. An empty list is
* returned if the file cannot be opened or read.
*
* @attention The returned list should be free'd with
* BLI_free_file_lines.
*
* @param name The name of the file to read.
* @retval A list of strings representing the file lines.
*/
struct LinkNode *BLI_read_file_as_lines(char *name);
/**
* Free the list returned by BLI_read_file_as_lines.
*/
void BLI_free_file_lines(struct LinkNode *lines);
/**
* Checks if name is a fully qualified filename to an executable.
* If not it searches $PATH for the file. On Windows it also
* adds the correct extension (.com .exe etc) from
* $PATHEXT if necessary. Also on Windows it translates
* the name to its 8.3 version to prevent problems with
* spaces and stuff. Final result is returned in fullname.
*
* @param fullname The full path and full name of the executable
* @param name The name of the executable (usually argv[0]) to be checked
*/
void BLI_where_am_i(char *fullname, const char *name);
char *get_install_dir(void);
/**
* Gets the temp directory when blender first runs.
* If the default path is not found, use try $TEMP
*
* Also make sure the temp dir has a trailing slash
*
* @param fullname The full path to the temp directory
*/
void BLI_where_is_temp(char *fullname, int usertemp);
/**
* determines the full path to the application bundle on OS X
*
* @return path to application bundle
*/
#ifdef __APPLE__
char* BLI_getbundle(void);
#endif
#ifdef WIN32
int BLI_getInstallationDir(char *str);
#endif
/* BLI_storage.h */
int BLI_filesize(int file);
int BLI_filepathsize(const char *path);
double BLI_diskfree(char *dir);
char *BLI_getwdN(char *dir);
void BLI_hide_dot_files(int set);
unsigned int BLI_getdir(char *dirname, struct direntry **filelist);
/**
* @attention Do not confuse with BLI_exists
*/
int BLI_exist(char *name);
/* BLI_fileops.h */
void BLI_recurdir_fileops(char *dirname);
int BLI_link(char *file, char *to);
int BLI_is_writable(char *filename);
/**
* @attention Do not confuse with BLI_exist
*/
int BLI_exists(char *file);
int BLI_copy_fileops(char *file, char *to);
int BLI_rename(char *from, char *to);
int BLI_gzip(char *from, char *to);
int BLI_delete(char *file, int dir, int recursive);
int BLI_move(char *file, char *to);
int BLI_touch(const char *file);
char *BLI_last_slash(const char *string);
void BLI_add_slash(char *string);
void BLI_del_slash(char *string);
/* BLI_rct.c */
/**
* Determine if a rect is empty. An empty
* rect is one with a zero (or negative)
* width or height.
*
* @return True if @a rect is empty.
*/
int BLI_rcti_is_empty(struct rcti *rect);
void BLI_init_rctf(struct rctf *rect, float xmin, float xmax, float ymin, float ymax);
void BLI_init_rcti(struct rcti *rect, int xmin, int xmax, int ymin, int ymax);
void BLI_translate_rctf(struct rctf *rect, float x, float y);
void BLI_translate_rcti(struct rcti *rect, int x, int y);
int BLI_in_rcti(struct rcti *rect, int x, int y);
int BLI_in_rctf(struct rctf *rect, float x, float y);
int BLI_isect_rctf(struct rctf *src1, struct rctf *src2, struct rctf *dest);
int BLI_isect_rcti(struct rcti *src1, struct rcti *src2, struct rcti *dest);
void BLI_union_rctf(struct rctf *rcta, struct rctf *rctb);
/* scanfill.c: used in displist only... */
struct EditVert *BLI_addfillvert(float *vec);
struct EditEdge *BLI_addfilledge(struct EditVert *v1, struct EditVert *v2);
int BLI_edgefill(int mode, int mat_nr);
void BLI_end_edgefill(void);
/* noise.h: */
float BLI_hnoise(float noisesize, float x, float y, float z);
float BLI_hnoisep(float noisesize, float x, float y, float z);
float BLI_turbulence(float noisesize, float x, float y, float z, int nr);
float BLI_turbulence1(float noisesize, float x, float y, float z, int nr);
/* newnoise: generic noise & turbulence functions to replace the above BLI_hnoise/p & BLI_turbulence/1.
* This is done so different noise basis functions can be used */
float BLI_gNoise(float noisesize, float x, float y, float z, int hard, int noisebasis);
float BLI_gTurbulence(float noisesize, float x, float y, float z, int oct, int hard, int noisebasis);
/* newnoise: musgrave functions */
float mg_fBm(float x, float y, float z, float H, float lacunarity, float octaves, int noisebasis);
float mg_MultiFractal(float x, float y, float z, float H, float lacunarity, float octaves, int noisebasis);
float mg_VLNoise(float x, float y, float z, float distortion, int nbas1, int nbas2);
float mg_HeteroTerrain(float x, float y, float z, float H, float lacunarity, float octaves, float offset, int noisebasis);
float mg_HybridMultiFractal(float x, float y, float z, float H, float lacunarity, float octaves, float offset, float gain, int noisebasis);
float mg_RidgedMultiFractal(float x, float y, float z, float H, float lacunarity, float octaves, float offset, float gain, int noisebasis);
/* newnoise: voronoi */
void voronoi(float x, float y, float z, float* da, float* pa, float me, int dtype);
/* newnoise: cellNoise & cellNoiseV (for vector/point/color) */
float cellNoise(float x, float y, float z);
void cellNoiseV(float x, float y, float z, float *ca);
/* These callbacks are needed to make the lib finction properly */
/**
* Set a function taking a char* as argument to flag errors. If the
* callback is not set, the error is discarded.
* @param f The function to use as callback
* @attention used in creator.c
*/
void BLI_setErrorCallBack(void (*f)(char*));
/**
* Set a function to be able to interrupt the execution of processing
* in this module. If the function returns true, the execution will
* terminate gracefully. If the callback is not set, interruption is
* not possible.
* @param f The function to use as callback
* @attention used in creator.c
*/
void BLI_setInterruptCallBack(int (*f)(void));
char *BLI_strcasestr(const char *s, const char *find);
int BLI_strcasecmp(const char *s1, const char *s2);
int BLI_strncasecmp(const char *s1, const char *s2, int n);
void BLI_timestr(double _time, char *str); /* time var is global */
/**
* Trick to address 32 GB with an int (only for malloced pointers)
*/
int BLI_int_from_pointer(void *poin);
void *BLI_pointer_from_int(int val);
#define PRNTSUB(type,arg) printf(#arg ": %" #type " ", arg)
#ifndef PRINT
#define PRINT(t,v) {PRNTSUB(t,v); printf("\n");}
#define PRINT2(t1,v1,t2,v2) {PRNTSUB(t1,v1); PRNTSUB(t2,v2); printf("\n");}
#define PRINT3(t1,v1,t2,v2,t3,v3) {PRNTSUB(t1,v1); PRNTSUB(t2,v2); PRNTSUB(t3,v3); printf("\n");}
#define PRINT4(t1,v1,t2,v2,t3,v3,t4,v4) {PRNTSUB(t1,v1); PRNTSUB(t2,v2); PRNTSUB(t3,v3); PRNTSUB(t4,v4); printf("\n");}
#endif
/**
* @param array The array in question
* @retval The number of elements in the array.
*/
#define BLI_ARRAY_NELEMS(array) (sizeof((array))/sizeof((array)[0]))
#include "BLI_noise.h"
/**
* @param strct The structure of interest

View File

@@ -26,12 +26,10 @@
* ***** END GPL LICENSE BLOCK *****
*/
#ifndef B_DYNAMIC_LIST_H
#define B_DYNAMIC_LIST_H
#ifndef BLI_DYNAMIC_LIST_H
#define BLI_DYNAMIC_LIST_H
#define PAGE_SIZE 4
struct ListBase;
#include "DNA_listBase.h"
/*
* Access array using realloc
@@ -52,4 +50,15 @@ typedef struct DynamicList {
struct ListBase lb; /* two way linked dynamic list */
} DynamicList;
struct DynamicList *BLI_dlist_from_listbase(struct ListBase *lb);
struct ListBase *BLI_listbase_from_dlist(struct DynamicList *dlist, struct ListBase *lb);
void * BLI_dlist_find_link(struct DynamicList *dlist, unsigned int index);
unsigned int BLI_count_items(struct DynamicList *dlist);
void BLI_dlist_free_item(struct DynamicList *dlist, unsigned int index);
void BLI_dlist_rem_item(struct DynamicList *dlist, unsigned int index);
void * BLI_dlist_add_item_index(struct DynamicList *dlist, void *item, unsigned int index);
void BLI_dlist_destroy(struct DynamicList *dlist);
void BLI_dlist_init(struct DynamicList *dlist);
void BLI_dlist_reinit(struct DynamicList *dlist);
#endif

View File

@@ -36,6 +36,25 @@
#ifndef BLI_FILEOPS_H
#define BLI_FILEOPS_H
void BLI_recurdir_fileops(char *dirname);
int BLI_link(char *file, char *to);
int BLI_is_writable(char *filename);
/**
* @attention Do not confuse with BLI_exist
*/
int BLI_exists(char *file);
int BLI_copy_fileops(char *file, char *to);
int BLI_rename(char *from, char *to);
int BLI_gzip(char *from, char *to);
int BLI_delete(char *file, int dir, int recursive);
int BLI_move(char *file, char *to);
int BLI_touch(const char *file);
char *BLI_last_slash(const char *string);
void BLI_add_slash(char *string);
void BLI_del_slash(char *string);
char *first_slash(char *string);
/* only for the sane unix world: direct calls to system functions :( */

View File

@@ -0,0 +1,64 @@
/*
* $Id: BLI_blenlib.h 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 *****
*
* $Id: $
*/
#ifndef BLI_LISTBASE_H
#define BLI_LISTBASE_H
//#include "DNA_listbase.h"
struct ListBase;
#ifdef __cplusplus
extern "C" {
#endif
void addlisttolist(struct ListBase *list1, struct ListBase *list2);
void BLI_insertlink(struct ListBase *listbase, void *vprevlink, void *vnewlink);
void *BLI_findlink(struct ListBase *listbase, int number);
int BLI_findindex(struct ListBase *listbase, void *vlink);
void BLI_freelistN(struct ListBase *listbase);
void BLI_addtail(struct ListBase *listbase, void *vlink);
void BLI_remlink(struct ListBase *listbase, void *vlink);
void BLI_uniquename(struct ListBase *list, void *vlink, char defname[], short name_offs, short len);
void BLI_addhead(struct ListBase *listbase, void *vlink);
void BLI_insertlinkbefore(struct ListBase *listbase, void *vnextlink, void *vnewlink);
void BLI_insertlinkafter(struct ListBase *listbase, void *vprevlink, void *vnewlink);
void BLI_sortlist(struct ListBase *listbase, int (*cmp)(void *, void *));
void BLI_freelist(struct ListBase *listbase);
int BLI_countlist(struct ListBase *listbase);
void BLI_freelinkN(struct ListBase *listbase, void *vlink);
void BLI_duplicatelist(struct ListBase *list1, struct ListBase *list2); /* copy from 2 to 1 */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,66 @@
/*
* $Id: BLI_blenlib.h 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 *****
*
* $Id: $
*/
#ifndef BLI_NOISE_H
#define BLI_NOISE_H
#ifdef __cplusplus
extern "C" {
#endif
/* noise.h: */
float BLI_hnoise(float noisesize, float x, float y, float z);
float BLI_hnoisep(float noisesize, float x, float y, float z);
float BLI_turbulence(float noisesize, float x, float y, float z, int nr);
float BLI_turbulence1(float noisesize, float x, float y, float z, int nr);
/* newnoise: generic noise & turbulence functions to replace the above BLI_hnoise/p & BLI_turbulence/1.
* This is done so different noise basis functions can be used */
float BLI_gNoise(float noisesize, float x, float y, float z, int hard, int noisebasis);
float BLI_gTurbulence(float noisesize, float x, float y, float z, int oct, int hard, int noisebasis);
/* newnoise: musgrave functions */
float mg_fBm(float x, float y, float z, float H, float lacunarity, float octaves, int noisebasis);
float mg_MultiFractal(float x, float y, float z, float H, float lacunarity, float octaves, int noisebasis);
float mg_VLNoise(float x, float y, float z, float distortion, int nbas1, int nbas2);
float mg_HeteroTerrain(float x, float y, float z, float H, float lacunarity, float octaves, float offset, int noisebasis);
float mg_HybridMultiFractal(float x, float y, float z, float H, float lacunarity, float octaves, float offset, float gain, int noisebasis);
float mg_RidgedMultiFractal(float x, float y, float z, float H, float lacunarity, float octaves, float offset, float gain, int noisebasis);
/* newnoise: voronoi */
void voronoi(float x, float y, float z, float* da, float* pa, float me, int dtype);
/* newnoise: cellNoise & cellNoiseV (for vector/point/color) */
float cellNoise(float x, float y, float z);
void cellNoiseV(float x, float y, float z, float *ca);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,65 @@
/*
* $Id: BLI_blenlib.h 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 *****
*
* $Id: $
*/
#ifndef BLI_RECT_H
#define BLI_RECT_H
struct rctf;
struct rcti;
#ifdef __cplusplus
extern "C" {
#endif
/* BLI_rct.c */
/**
* Determine if a rect is empty. An empty
* rect is one with a zero (or negative)
* width or height.
*
* @return True if @a rect is empty.
*/
int BLI_rcti_is_empty(struct rcti *rect);
void BLI_init_rctf(struct rctf *rect, float xmin, float xmax, float ymin, float ymax);
void BLI_init_rcti(struct rcti *rect, int xmin, int xmax, int ymin, int ymax);
void BLI_translate_rctf(struct rctf *rect, float x, float y);
void BLI_translate_rcti(struct rcti *rect, int x, int y);
int BLI_in_rcti(struct rcti *rect, int x, int y);
int BLI_in_rctf(struct rctf *rect, float x, float y);
int BLI_isect_rctf(struct rctf *src1, struct rctf *src2, struct rctf *dest);
int BLI_isect_rcti(struct rcti *src1, struct rcti *src2, struct rcti *dest);
void BLI_union_rctf(struct rctf *rcta, struct rctf *rctb);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,81 @@
/**
* 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
/**
* @attention Defined in scanfill.c
*/
extern struct ListBase fillvertbase;
extern struct ListBase filledgebase;
extern struct ListBase fillfacebase;
struct EditVert;
#ifdef __cplusplus
extern "C" {
#endif
/* scanfill.c: used in displist only... */
struct EditVert *BLI_addfillvert(float *vec);
struct EditEdge *BLI_addfilledge(struct EditVert *v1, struct EditVert *v2);
int BLI_edgefill(int mode, int mat_nr);
void BLI_end_edgefill(void);
/* These callbacks are needed to make the lib finction properly */
/**
* Set a function taking a char* as argument to flag errors. If the
* callback is not set, the error is discarded.
* @param f The function to use as callback
* @attention used in creator.c
*/
void BLI_setErrorCallBack(void (*f)(char*));
/**
* Set a function to be able to interrupt the execution of processing
* in this module. If the function returns true, the execution will
* terminate gracefully. If the callback is not set, interruption is
* not possible.
* @param f The function to use as callback
* @attention used in creator.c
*/
void BLI_setInterruptCallBack(int (*f)(void));
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -35,11 +35,38 @@
#endif
#endif
#include "BLI_storage_types.h"
struct direntry;
void BLI_adddirstrings(void);
void BLI_builddir(char *dirname, char *relname);
int BLI_compare(struct direntry *entry1, struct direntry *entry2);
int BLI_filesize(int file);
int BLI_filepathsize(const char *path);
double BLI_diskfree(char *dir);
char *BLI_getwdN(char *dir);
void BLI_hide_dot_files(int set);
unsigned int BLI_getdir(char *dirname, struct direntry **filelist);
/**
* @attention Do not confuse with BLI_exists
*/
int BLI_exist(char *name);
/**
* Read a file as ASCII lines. An empty list is
* returned if the file cannot be opened or read.
*
* @attention The returned list should be free'd with
* BLI_free_file_lines.
*
* @param name The name of the file to read.
* @retval A list of strings representing the file lines.
*/
struct LinkNode *BLI_read_file_as_lines(char *name);
/**
* Free the list returned by BLI_read_file_as_lines.
*/
void BLI_free_file_lines(struct LinkNode *lines);
#endif /* BLI_STORAGE_H */

View File

@@ -0,0 +1,100 @@
/*
* $Id: BLI_blenlib.h 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 *****
*
* $Id: $
*/
#ifndef BLI_STRING_H
#define BLI_STRING_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* Duplicates the cstring @a str into a newly mallocN'd
* string and returns it.
*
* @param str The string to be duplicated
* @retval Returns the duplicated string
*/
char *BLI_strdup(const char *str);
/**
* Duplicates the first @a len bytes of cstring @a str
* into a newly mallocN'd string and returns it. @a str
* is assumed to be at least len bytes long.
*
* @param str The string to be duplicated
* @param len The number of bytes to duplicate
* @retval Returns the duplicated string
*/
char *BLI_strdupn(const char *str, int len);
/**
* Like strncpy but ensures dst is always
* '\0' terminated.
*
* @param dst Destination for copy
* @param src Source string to copy
* @param maxncpy Maximum number of characters to copy (generally
* the size of dst)
* @retval Returns dst
*/
char *BLI_strncpy(char *dst, const char *src, int maxncpy);
/*
* Replacement for snprintf
*/
int BLI_snprintf(char *buffer, size_t count, const char *format, ...);
/**
* Compare two strings
*
* @retval True if the strings are equal, false otherwise.
*/
int BLI_streq(char *a, char *b);
/**
* Compare two strings without regard to case.
*
* @retval True if the strings are equal, false otherwise.
*/
int BLI_strcaseeq(char *a, char *b);
char *BLI_strcasestr(const char *s, const char *find);
int BLI_strcasecmp(const char *s1, const char *s2);
int BLI_strncasecmp(const char *s1, const char *s2, int n);
void BLI_timestr(double _time, char *str); /* time var is global */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,136 @@
/**
* 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
/* XXX doesn't seem to be used, marded for removal
#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;
struct direntry;
char *BLI_gethome(void);
void BLI_make_file_string(const char *relabase, char *string, const char *dir, const char *file);
void BLI_make_exist(char *dir);
void BLI_make_existing_file(char *name);
void BLI_split_dirfile(char *string, char *dir, char *file);
void BLI_split_dirfile_basic(const char *string, char *dir, char *file);
void BLI_join_dirfile(char *string, const char *dir, const char *file);
int BLI_testextensie(const char *str, const char *ext);
void BLI_uniquename(struct ListBase *list, void *vlink, char defname[], short name_offs, short len);
void BLI_newname(char * name, int add);
int BLI_stringdec(char *string, char *kop, char *start, unsigned short *numlen);
void BLI_stringenc(char *string, char *kop, char *start, unsigned short numlen, int pic);
void BLI_splitdirstring(char *di,char *fi);
/**
* dir can be any input, like from buttons, and this function
* converts it to a regular full path.
* Also removes garbage from directory paths, like /../ or double slashes etc
*/
void BLI_cleanup_file(const char *relabase, char *dir);
void BLI_cleanup_dir(const char *relabase, char *dir); /* same as above but adds a trailing slash */
/* go back one directory */
int BLI_parent_dir(char *path);
/**
* Blender's path code replacement function.
* Bases @a path strings leading with "//" by the
* directory @a basepath, and replaces instances of
* '#' with the @a framenum. Results are written
* back into @a path.
*
* @a path The path to convert
* @a basepath The directory to base relative paths with.
* @a framenum The framenumber to replace the frame code with.
* @retval Returns true if the path was relative (started with "//").
*/
int BLI_convertstringcode(char *path, const char *basepath);
int BLI_convertstringframe(char *path, int frame);
int BLI_convertstringcwd(char *path);
void BLI_makestringcode(const char *relfile, char *file);
/**
* Change every @a from in @a string into @a to. The
* result will be in @a string
*
* @a string The string to work on
* @a from The character to replace
* @a to The character to replace with
*/
void BLI_char_switch(char *string, char from, char to);
/**
* Checks if name is a fully qualified filename to an executable.
* If not it searches $PATH for the file. On Windows it also
* adds the correct extension (.com .exe etc) from
* $PATHEXT if necessary. Also on Windows it translates
* the name to its 8.3 version to prevent problems with
* spaces and stuff. Final result is returned in fullname.
*
* @param fullname The full path and full name of the executable
* @param name The name of the executable (usually argv[0]) to be checked
*/
void BLI_where_am_i(char *fullname, const char *name);
char *get_install_dir(void);
/**
* Gets the temp directory when blender first runs.
* If the default path is not found, use try $TEMP
*
* Also make sure the temp dir has a trailing slash
*
* @param fullname The full path to the temp directory
*/
void BLI_where_is_temp(char *fullname, int usertemp);
/**
* determines the full path to the application bundle on OS X
*
* @return path to application bundle
*/
#ifdef __APPLE__
char* BLI_getbundle(void);
#endif
#ifdef WITH_ICONV
void BLI_string_to_utf8(char *original, char *utf_8, const char *code);
#endif
#endif

View File

@@ -120,6 +120,10 @@ int closedir (DIR *dp);
void get_default_root(char *root);
int check_file_chars(char *filename);
#ifdef WIN32
int BLI_getInstallationDir(char *str);
#endif
#ifdef __cplusplus
}
#endif

View File

@@ -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

View File

@@ -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

View File

@@ -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));
}
/*=====================================================================================*/

View File

@@ -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

View File

@@ -0,0 +1,363 @@
/* 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"
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;
}
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;
}
}

View File

@@ -0,0 +1,163 @@
/* 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 "MEM_guardedalloc.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;
}
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);
}
/* 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;
}
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;
}

View File

@@ -35,6 +35,8 @@
#include "MEM_guardedalloc.h"
#include "DNA_listBase.h"
#include "BLI_blenlib.h"
#include "BLI_threads.h"

View File

@@ -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;
@@ -301,574 +284,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;
}
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;
}
}
/*=====================================================================================*/
/* 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
@@ -1924,6 +1339,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
@@ -1942,66 +1378,8 @@ 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"
@@ -2034,68 +1412,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

View File

@@ -2201,27 +2201,6 @@ int BLO_write_file_mem(Main *mainvar, MemFile *compare, MemFile *current, int wr
#define PATHSEPERATOR "/"
#endif
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;
}
}
static char *get_runtime_path(char *exename) {
char *installpath= get_install_dir();

View File

@@ -42,7 +42,7 @@
#include <string.h>
#include <stdio.h>
#include "DNA_listbase.h"
#include "DNA_listBase.h"
#include "DNA_ID.h"
#include "DNA_action_types.h"
#include "DNA_camera_types.h"

View File

@@ -30,6 +30,7 @@
#define DNA_MESHDATA_TYPES_H
#include "DNA_customdata_types.h"
#include "DNA_listBase.h"
struct Bone;
struct Image;