From bddc7dfc20919105e02181340d54b2faf52c95ac Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 12 May 2012 15:13:06 +0000 Subject: style cleanup: remaining BLI files. --- source/blender/blenlib/intern/BLI_heap.c | 8 +- source/blender/blenlib/intern/BLI_mempool.c | 4 +- source/blender/blenlib/intern/boxpack2d.c | 46 +-- source/blender/blenlib/intern/callbacks.c | 16 +- source/blender/blenlib/intern/cpu.c | 18 +- source/blender/blenlib/intern/dynlib.c | 20 +- source/blender/blenlib/intern/freetypefont.c | 234 +++++++------- source/blender/blenlib/intern/graph.c | 52 +-- source/blender/blenlib/intern/gsqueue.c | 44 +-- source/blender/blenlib/intern/listbase.c | 172 +++++----- source/blender/blenlib/intern/path_util.c | 462 +++++++++++++-------------- source/blender/blenlib/intern/rct.c | 6 +- source/blender/blenlib/intern/scanfill.c | 2 +- source/blender/blenlib/intern/string.c | 118 +++---- source/blender/blenlib/intern/time.c | 36 +-- source/blender/blenlib/intern/uvproject.c | 2 +- source/blender/blenlib/intern/voxel.c | 4 +- source/blender/blenlib/intern/winstuff.c | 99 +++--- 18 files changed, 670 insertions(+), 673 deletions(-) (limited to 'source/blender/blenlib') diff --git a/source/blender/blenlib/intern/BLI_heap.c b/source/blender/blenlib/intern/BLI_heap.c index 4e135805efb..0a281786100 100644 --- a/source/blender/blenlib/intern/BLI_heap.c +++ b/source/blender/blenlib/intern/BLI_heap.c @@ -60,10 +60,10 @@ struct Heap { #define HEAP_COMPARE(a, b) (a->value < b->value) #define HEAP_EQUALS(a, b) (a->value == b->value) #define HEAP_SWAP(heap, i, j) \ -{ \ - SWAP(int, heap->tree[i]->index, heap->tree[j]->index); \ - SWAP(HeapNode *, heap->tree[i], heap->tree[j]); \ -} + { \ + SWAP(int, heap->tree[i]->index, heap->tree[j]->index); \ + SWAP(HeapNode *, heap->tree[i], heap->tree[j]); \ + } /***/ diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index 3d16b3af4de..c7e610edd9e 100644 --- a/source/blender/blenlib/intern/BLI_mempool.c +++ b/source/blender/blenlib/intern/BLI_mempool.c @@ -48,10 +48,10 @@ /* note: copied from BKE_utildefines.h, don't use here because we're in BLI */ #ifdef __BIG_ENDIAN__ /* Big Endian */ -# define MAKE_ID(a,b,c,d) ( (int)(a)<<24 | (int)(b)<<16 | (c)<<8 | (d) ) +# define MAKE_ID(a, b, c, d) ( (int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d) ) #else /* Little Endian */ -# define MAKE_ID(a,b,c,d) ( (int)(d)<<24 | (int)(c)<<16 | (b)<<8 | (a) ) +# define MAKE_ID(a, b, c, d) ( (int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a) ) #endif #define FREEWORD MAKE_ID('f', 'r', 'e', 'e') diff --git a/source/blender/blenlib/intern/boxpack2d.c b/source/blender/blenlib/intern/boxpack2d.c index f1931d35819..bf63517a4c2 100644 --- a/source/blender/blenlib/intern/boxpack2d.c +++ b/source/blender/blenlib/intern/boxpack2d.c @@ -56,7 +56,7 @@ typedef struct boxVert { #define TRF 2 #define TLF 4 #define BRF 8 -#define CORNERFLAGS (BLF|TRF|TLF|BRF) +#define CORNERFLAGS (BLF | TRF | TLF | BRF) #define BL 0 #define TR 1 @@ -93,13 +93,13 @@ typedef struct boxVert { BOXRIGHT(b1) - EPSILON <= BOXLEFT(b2) || \ BOXTOP(b1) - EPSILON <= BOXBOTTOM(b2)) -#define MIN2(x,y) ((x) < (y) ? (x) : (y)) -#define MAX2(x,y) ((x) > (y) ? (x) : (y)) +#define MIN2(x, y) ((x) < (y) ? (x) : (y)) +#define MAX2(x, y) ((x) > (y) ? (x) : (y)) #if 0 #define BOXDEBUG(b) \ printf("\tBox Debug i %i, w:%.3f h:%.3f x:%.3f y:%.3f\n", \ - b->index, b->w, b->h, b->x, b->y) + b->index, b->w, b->h, b->x, b->y) #endif /* qsort function - sort largest to smallest */ @@ -131,11 +131,11 @@ static int vertex_sort(const void *p1, const void *p2) v1 = vertarray + ((int *)p1)[0]; v2 = vertarray + ((int *)p2)[0]; - a1 = MAX2(v1->x+box_width, v1->y+box_height); - a2 = MAX2(v2->x+box_width, v2->y+box_height); + a1 = MAX2(v1->x + box_width, v1->y + box_height); + a2 = MAX2(v2->x + box_width, v2->y + box_height); /* sort largest to smallest */ - if (a1 > a2) return 1; + if (a1 > a2) return 1; else if (a1 < a2) return -1; return 0; } @@ -145,11 +145,11 @@ static int vertex_sort(const void *p1, const void *p2) * tightly into the lower left hand corner (0,0) * * boxarray - a pre allocated array of boxes. - * only the 'box->x' and 'box->y' are set, 'box->w' and 'box->h' are used, - * 'box->index' is not used at all, the only reason its there - * is that the box array is sorted by area and programs need to be able - * to have some way of writing the boxes back to the original data. - * len - the number of boxes in the array. + * only the 'box->x' and 'box->y' are set, 'box->w' and 'box->h' are used, + * 'box->index' is not used at all, the only reason its there + * is that the box array is sorted by area and programs need to be able + * to have some way of writing the boxes back to the original data. + * len - the number of boxes in the array. * tot_width and tot_height are set so you can normalize the data. * */ void BLI_box_pack_2D(BoxPack *boxarray, const int len, float *tot_width, float *tot_height) @@ -178,15 +178,15 @@ void BLI_box_pack_2D(BoxPack *boxarray, const int len, float *tot_width, float * vert->blb = vert->brb = vert->tlb = vert->isect_cache[0] = vert->isect_cache[1] = vert->isect_cache[2] = vert->isect_cache[3] = NULL; - vert->free = CORNERFLAGS &~ TRF; + vert->free = CORNERFLAGS & ~TRF; vert->trb = box; vert->index = i; i++; box->v[BL] = vert; vert++; - vert->trb= vert->brb = vert->tlb = + vert->trb = vert->brb = vert->tlb = vert->isect_cache[0] = vert->isect_cache[1] = vert->isect_cache[2] = vert->isect_cache[3] = NULL; - vert->free = CORNERFLAGS &~ BLF; + vert->free = CORNERFLAGS & ~BLF; vert->blb = box; vert->index = i; i++; box->v[TR] = vert; vert++; @@ -194,7 +194,7 @@ void BLI_box_pack_2D(BoxPack *boxarray, const int len, float *tot_width, float * vert->trb = vert->blb = vert->tlb = vert->isect_cache[0] = vert->isect_cache[1] = vert->isect_cache[2] = vert->isect_cache[3] = NULL; - vert->free = CORNERFLAGS &~ BRF; + vert->free = CORNERFLAGS & ~BRF; vert->brb = box; vert->index = i; i++; box->v[TL] = vert; vert++; @@ -202,7 +202,7 @@ void BLI_box_pack_2D(BoxPack *boxarray, const int len, float *tot_width, float * vert->trb = vert->blb = vert->brb = vert->isect_cache[0] = vert->isect_cache[1] = vert->isect_cache[2] = vert->isect_cache[3] = NULL; - vert->free = CORNERFLAGS &~ TLF; + vert->free = CORNERFLAGS & ~TLF; vert->tlb = box; vert->index = i; i++; box->v[BR] = vert; vert++; @@ -248,7 +248,7 @@ void BLI_box_pack_2D(BoxPack *boxarray, const int len, float *tot_width, float * for (i = 0; i < verts_pack_len && isect; i++) { vert = vertarray + vertex_pack_indices[i]; /* printf("\ttesting vert %i %i %i %f %f\n", i, - * vert->free, verts_pack_len, vert->x, vert->y); */ + * vert->free, verts_pack_len, vert->x, vert->y); */ /* This vert has a free quadrant * Test if we can place the box here @@ -281,11 +281,11 @@ void BLI_box_pack_2D(BoxPack *boxarray, const int len, float *tot_width, float * * Assume no intersection... */ isect = 0; - if (/* Constrain boxes to positive X/Y values */ - BOXLEFT(box) < 0.0f || BOXBOTTOM(box) < 0.0f || - /* check for last intersected */ - ( vert->isect_cache[j] && - BOXINTERSECT(box, vert->isect_cache[j]))) + if ( /* Constrain boxes to positive X/Y values */ + BOXLEFT(box) < 0.0f || BOXBOTTOM(box) < 0.0f || + /* check for last intersected */ + (vert->isect_cache[j] && + BOXINTERSECT(box, vert->isect_cache[j]))) { /* Here we check that the last intersected * box will intersect with this one using diff --git a/source/blender/blenlib/intern/callbacks.c b/source/blender/blenlib/intern/callbacks.c index 876599f7480..614a9a63d90 100644 --- a/source/blender/blenlib/intern/callbacks.c +++ b/source/blender/blenlib/intern/callbacks.c @@ -26,21 +26,21 @@ #include "MEM_guardedalloc.h" -static ListBase callback_slots[BLI_CB_EVT_TOT]= {{NULL}}; +static ListBase callback_slots[BLI_CB_EVT_TOT] = {{NULL}}; void BLI_callback_exec(struct Main *main, struct ID *self, eCbEvent evt) { - ListBase *lb= &callback_slots[evt]; + ListBase *lb = &callback_slots[evt]; bCallbackFuncStore *funcstore; - for (funcstore= (bCallbackFuncStore *)lb->first; funcstore; funcstore= (bCallbackFuncStore *)funcstore->next) { + for (funcstore = (bCallbackFuncStore *)lb->first; funcstore; funcstore = (bCallbackFuncStore *)funcstore->next) { funcstore->func(main, self, funcstore->arg); } } void BLI_callback_add(bCallbackFuncStore *funcstore, eCbEvent evt) { - ListBase *lb= &callback_slots[evt]; + ListBase *lb = &callback_slots[evt]; BLI_addtail(lb, funcstore); } @@ -53,12 +53,12 @@ void BLI_callback_global_init(void) void BLI_callback_global_finalize(void) { eCbEvent evt; - for (evt= 0; evt < BLI_CB_EVT_TOT; evt++) { - ListBase *lb= &callback_slots[evt]; + for (evt = 0; evt < BLI_CB_EVT_TOT; evt++) { + ListBase *lb = &callback_slots[evt]; bCallbackFuncStore *funcstore; bCallbackFuncStore *funcstore_next; - for (funcstore= (bCallbackFuncStore *)lb->first; funcstore; funcstore= funcstore_next) { - funcstore_next= (bCallbackFuncStore *)funcstore->next; + for (funcstore = (bCallbackFuncStore *)lb->first; funcstore; funcstore = funcstore_next) { + funcstore_next = (bCallbackFuncStore *)funcstore->next; BLI_remlink(lb, funcstore); if (funcstore->alloc) { MEM_freeN(funcstore); diff --git a/source/blender/blenlib/intern/cpu.c b/source/blender/blenlib/intern/cpu.c index 4e2003dcbf7..d942ffdf2c9 100644 --- a/source/blender/blenlib/intern/cpu.c +++ b/source/blender/blenlib/intern/cpu.c @@ -34,22 +34,22 @@ int BLI_cpu_support_sse2(void) /* for GCC x86 we check cpuid */ unsigned int d; __asm__( - "pushl %%ebx\n\t" - "cpuid\n\t" - "popl %%ebx\n\t" - : "=d"(d) - : "a"(1)); + "pushl %%ebx\n\t" + "cpuid\n\t" + "popl %%ebx\n\t" + : "=d" (d) + : "a" (1)); return (d & 0x04000000) != 0; #elif (defined(_MSC_VER) && defined(_M_IX86)) /* also check cpuid for MSVC x86 */ unsigned int d; __asm { xor eax, eax - inc eax - push ebx + inc eax + push ebx cpuid - pop ebx - mov d, edx + pop ebx + mov d, edx } return (d & 0x04000000) != 0; #endif diff --git a/source/blender/blenlib/intern/dynlib.c b/source/blender/blenlib/intern/dynlib.c index c80f3e08e3b..b66eda4f141 100644 --- a/source/blender/blenlib/intern/dynlib.c +++ b/source/blender/blenlib/intern/dynlib.c @@ -53,14 +53,14 @@ DynamicLibrary *BLI_dynlib_open(char *name) void *handle; UTF16_ENCODE(name); - handle= LoadLibraryW(name_16); + handle = LoadLibraryW(name_16); UTF16_UN_ENCODE(name); if (!handle) return NULL; - lib= MEM_callocN(sizeof(*lib), "Dynamic Library"); - lib->handle= handle; + lib = MEM_callocN(sizeof(*lib), "Dynamic Library"); + lib->handle = handle; return lib; } @@ -75,16 +75,16 @@ char *BLI_dynlib_get_error_as_string(DynamicLibrary *lib) int err; /* if lib is NULL reset the last error code */ - err= GetLastError(); + err = GetLastError(); if (!lib) SetLastError(ERROR_SUCCESS); if (err) { static char buf[1024]; - if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - buf, sizeof(buf), NULL)) + if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + buf, sizeof(buf), NULL)) { return buf; } @@ -106,13 +106,13 @@ void BLI_dynlib_close(DynamicLibrary *lib) DynamicLibrary *BLI_dynlib_open(char *name) { DynamicLibrary *lib; - void *handle= dlopen(name, RTLD_LAZY); + void *handle = dlopen(name, RTLD_LAZY); if (!handle) return NULL; - lib= MEM_callocN(sizeof(*lib), "Dynamic Library"); - lib->handle= handle; + lib = MEM_callocN(sizeof(*lib), "Dynamic Library"); + lib->handle = handle; return lib; } diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c index d85765d8f56..da07bb156d7 100644 --- a/source/blender/blenlib/intern/freetypefont.c +++ b/source/blender/blenlib/intern/freetypefont.c @@ -61,12 +61,12 @@ #include "DNA_packedFile_types.h" #include "DNA_curve_types.h" -#define myMIN_ASCII 32 -#define myMAX_ASCII 255 +#define myMIN_ASCII 32 +#define myMAX_ASCII 255 /* local variables */ -static FT_Library library; -static FT_Error err; +static FT_Library library; +static FT_Error err; static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vfd) @@ -82,10 +82,10 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf FT_Outline ftoutline; float scale, height; float dx, dy; - int j, k, l, m=0; + int j, k, l, m = 0; // adjust font size - height= ((double) face->bbox.yMax - (double) face->bbox.yMin); + height = ((double) face->bbox.yMax - (double) face->bbox.yMin); if (height != 0.0f) scale = 1.0f / height; else @@ -95,8 +95,8 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf // Generate the character 3D data // // Get the FT Glyph index and load the Glyph - glyph_index= FT_Get_Char_Index(face, charcode); - err= FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP); + glyph_index = FT_Get_Char_Index(face, charcode); + err = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP); // If loading succeeded, convert the FT glyph to the internal format if (!err) { @@ -104,16 +104,16 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf int *onpoints; // First we create entry for the new character to the character list - che= (VChar *) MEM_callocN(sizeof(struct VChar), "objfnt_char"); + che = (VChar *) MEM_callocN(sizeof(struct VChar), "objfnt_char"); BLI_addtail(&vfd->characters, che); // Take some data for modifying purposes - glyph= face->glyph; - ftoutline= glyph->outline; + glyph = face->glyph; + ftoutline = glyph->outline; // Set the width and character code - che->index= charcode; - che->width= glyph->advance.x * scale; + che->index = charcode; + che->width = glyph->advance.x * scale; // Start converting the FT data npoints = (int *)MEM_callocN((ftoutline.n_contours) * sizeof(int), "endpoints"); @@ -135,9 +135,9 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf if (ftoutline.tags[l] == FT_Curve_Tag_On) onpoints[j]++; - if (k < npoints[j] - 1 ) { - if ( ftoutline.tags[l] == FT_Curve_Tag_Conic && - ftoutline.tags[l+1] == FT_Curve_Tag_Conic) + if (k < npoints[j] - 1) { + if (ftoutline.tags[l] == FT_Curve_Tag_Conic && + ftoutline.tags[l + 1] == FT_Curve_Tag_Conic) { onpoints[j]++; } @@ -152,11 +152,11 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf bezt = (BezTriple *)MEM_callocN((onpoints[j]) * sizeof(BezTriple), "objfnt_bezt"); BLI_addtail(&che->nurbsbase, nu); - nu->type= CU_BEZIER; + nu->type = CU_BEZIER; nu->pntsu = onpoints[j]; - nu->resolu= 8; - nu->flag= CU_2D; - nu->flagu= CU_NURB_CYCLIC; + nu->resolu = 8; + nu->flag = CU_2D; + nu->flagu = CU_NURB_CYCLIC; nu->bezt = bezt; //individual curve loop, start-end @@ -166,24 +166,24 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf //virtual conic on-curve points if (k < npoints[j] - 1) { - if (ftoutline.tags[l] == FT_Curve_Tag_Conic && ftoutline.tags[l+1] == FT_Curve_Tag_Conic) { - dx = (ftoutline.points[l].x + ftoutline.points[l+1].x)* scale / 2.0f; - dy = (ftoutline.points[l].y + ftoutline.points[l+1].y)* scale / 2.0f; + if (ftoutline.tags[l] == FT_Curve_Tag_Conic && ftoutline.tags[l + 1] == FT_Curve_Tag_Conic) { + dx = (ftoutline.points[l].x + ftoutline.points[l + 1].x) * scale / 2.0f; + dy = (ftoutline.points[l].y + ftoutline.points[l + 1].y) * scale / 2.0f; //left handle - bezt->vec[0][0] = (dx + (2 * ftoutline.points[l].x)* scale) / 3.0f; - bezt->vec[0][1] = (dy + (2 * ftoutline.points[l].y)* scale) / 3.0f; + bezt->vec[0][0] = (dx + (2 * ftoutline.points[l].x) * scale) / 3.0f; + bezt->vec[0][1] = (dy + (2 * ftoutline.points[l].y) * scale) / 3.0f; //midpoint (virtual on-curve point) bezt->vec[1][0] = dx; bezt->vec[1][1] = dy; //right handle - bezt->vec[2][0] = (dx + (2 * ftoutline.points[l+1].x)* scale) / 3.0f; - bezt->vec[2][1] = (dy + (2 * ftoutline.points[l+1].y)* scale) / 3.0f; + bezt->vec[2][0] = (dx + (2 * ftoutline.points[l + 1].x) * scale) / 3.0f; + bezt->vec[2][1] = (dy + (2 * ftoutline.points[l + 1].y) * scale) / 3.0f; - bezt->h1= bezt->h2= HD_ALIGN; - bezt->radius= 1.0f; + bezt->h1 = bezt->h2 = HD_ALIGN; + bezt->radius = 1.0f; bezt++; } } @@ -193,76 +193,76 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf //left handle if (k > 0) { if (ftoutline.tags[l - 1] == FT_Curve_Tag_Cubic) { - bezt->vec[0][0] = ftoutline.points[l-1].x* scale; - bezt->vec[0][1] = ftoutline.points[l-1].y* scale; - bezt->h1= HD_FREE; + bezt->vec[0][0] = ftoutline.points[l - 1].x * scale; + bezt->vec[0][1] = ftoutline.points[l - 1].y * scale; + bezt->h1 = HD_FREE; } else if (ftoutline.tags[l - 1] == FT_Curve_Tag_Conic) { - bezt->vec[0][0] = (ftoutline.points[l].x + (2 * ftoutline.points[l - 1].x))* scale / 3.0f; - bezt->vec[0][1] = (ftoutline.points[l].y + (2 * ftoutline.points[l - 1].y))* scale / 3.0f; - bezt->h1= HD_FREE; + bezt->vec[0][0] = (ftoutline.points[l].x + (2 * ftoutline.points[l - 1].x)) * scale / 3.0f; + bezt->vec[0][1] = (ftoutline.points[l].y + (2 * ftoutline.points[l - 1].y)) * scale / 3.0f; + bezt->h1 = HD_FREE; } else { - bezt->vec[0][0] = ftoutline.points[l].x* scale - (ftoutline.points[l].x - ftoutline.points[l-1].x)* scale / 3.0f; - bezt->vec[0][1] = ftoutline.points[l].y* scale - (ftoutline.points[l].y - ftoutline.points[l-1].y)* scale / 3.0f; - bezt->h1= HD_VECT; + bezt->vec[0][0] = ftoutline.points[l].x * scale - (ftoutline.points[l].x - ftoutline.points[l - 1].x) * scale / 3.0f; + bezt->vec[0][1] = ftoutline.points[l].y * scale - (ftoutline.points[l].y - ftoutline.points[l - 1].y) * scale / 3.0f; + bezt->h1 = HD_VECT; } } else { //first point on curve if (ftoutline.tags[ftoutline.contours[j]] == FT_Curve_Tag_Cubic) { bezt->vec[0][0] = ftoutline.points[ftoutline.contours[j]].x * scale; bezt->vec[0][1] = ftoutline.points[ftoutline.contours[j]].y * scale; - bezt->h1= HD_FREE; + bezt->h1 = HD_FREE; } else if (ftoutline.tags[ftoutline.contours[j]] == FT_Curve_Tag_Conic) { - bezt->vec[0][0] = (ftoutline.points[l].x + (2 * ftoutline.points[ftoutline.contours[j]].x))* scale / 3.0f; - bezt->vec[0][1] = (ftoutline.points[l].y + (2 * ftoutline.points[ftoutline.contours[j]].y))* scale / 3.0f; - bezt->h1= HD_FREE; + bezt->vec[0][0] = (ftoutline.points[l].x + (2 * ftoutline.points[ftoutline.contours[j]].x)) * scale / 3.0f; + bezt->vec[0][1] = (ftoutline.points[l].y + (2 * ftoutline.points[ftoutline.contours[j]].y)) * scale / 3.0f; + bezt->h1 = HD_FREE; } else { - bezt->vec[0][0] = ftoutline.points[l].x* scale - (ftoutline.points[l].x - ftoutline.points[ftoutline.contours[j]].x)* scale / 3.0f; - bezt->vec[0][1] = ftoutline.points[l].y* scale - (ftoutline.points[l].y - ftoutline.points[ftoutline.contours[j]].y)* scale / 3.0f; - bezt->h1= HD_VECT; + bezt->vec[0][0] = ftoutline.points[l].x * scale - (ftoutline.points[l].x - ftoutline.points[ftoutline.contours[j]].x) * scale / 3.0f; + bezt->vec[0][1] = ftoutline.points[l].y * scale - (ftoutline.points[l].y - ftoutline.points[ftoutline.contours[j]].y) * scale / 3.0f; + bezt->h1 = HD_VECT; } } //midpoint (on-curve point) - bezt->vec[1][0] = ftoutline.points[l].x* scale; - bezt->vec[1][1] = ftoutline.points[l].y* scale; + bezt->vec[1][0] = ftoutline.points[l].x * scale; + bezt->vec[1][1] = ftoutline.points[l].y * scale; //right handle if (k < (npoints[j] - 1)) { - if (ftoutline.tags[l+1] == FT_Curve_Tag_Cubic) { - bezt->vec[2][0] = ftoutline.points[l+1].x* scale; - bezt->vec[2][1] = ftoutline.points[l+1].y* scale; - bezt->h2= HD_FREE; + if (ftoutline.tags[l + 1] == FT_Curve_Tag_Cubic) { + bezt->vec[2][0] = ftoutline.points[l + 1].x * scale; + bezt->vec[2][1] = ftoutline.points[l + 1].y * scale; + bezt->h2 = HD_FREE; } - else if (ftoutline.tags[l+1] == FT_Curve_Tag_Conic) { - bezt->vec[2][0] = (ftoutline.points[l].x + (2 * ftoutline.points[l+1].x))* scale / 3.0f; - bezt->vec[2][1] = (ftoutline.points[l].y + (2 * ftoutline.points[l+1].y))* scale / 3.0f; - bezt->h2= HD_FREE; + else if (ftoutline.tags[l + 1] == FT_Curve_Tag_Conic) { + bezt->vec[2][0] = (ftoutline.points[l].x + (2 * ftoutline.points[l + 1].x)) * scale / 3.0f; + bezt->vec[2][1] = (ftoutline.points[l].y + (2 * ftoutline.points[l + 1].y)) * scale / 3.0f; + bezt->h2 = HD_FREE; } else { - bezt->vec[2][0] = ftoutline.points[l].x* scale - (ftoutline.points[l].x - ftoutline.points[l+1].x)* scale / 3.0f; - bezt->vec[2][1] = ftoutline.points[l].y* scale - (ftoutline.points[l].y - ftoutline.points[l+1].y)* scale / 3.0f; - bezt->h2= HD_VECT; + bezt->vec[2][0] = ftoutline.points[l].x * scale - (ftoutline.points[l].x - ftoutline.points[l + 1].x) * scale / 3.0f; + bezt->vec[2][1] = ftoutline.points[l].y * scale - (ftoutline.points[l].y - ftoutline.points[l + 1].y) * scale / 3.0f; + bezt->h2 = HD_VECT; } } else { //last point on curve if (ftoutline.tags[m] == FT_Curve_Tag_Cubic) { - bezt->vec[2][0] = ftoutline.points[m].x* scale; - bezt->vec[2][1] = ftoutline.points[m].y* scale; - bezt->h2= HD_FREE; + bezt->vec[2][0] = ftoutline.points[m].x * scale; + bezt->vec[2][1] = ftoutline.points[m].y * scale; + bezt->h2 = HD_FREE; } else if (ftoutline.tags[m] == FT_Curve_Tag_Conic) { - bezt->vec[2][0] = (ftoutline.points[l].x + (2 * ftoutline.points[m].x))* scale / 3.0f; - bezt->vec[2][1] = (ftoutline.points[l].y + (2 * ftoutline.points[m].y))* scale / 3.0f; - bezt->h2= HD_FREE; + bezt->vec[2][0] = (ftoutline.points[l].x + (2 * ftoutline.points[m].x)) * scale / 3.0f; + bezt->vec[2][1] = (ftoutline.points[l].y + (2 * ftoutline.points[m].y)) * scale / 3.0f; + bezt->h2 = HD_FREE; } else { - bezt->vec[2][0] = ftoutline.points[l].x* scale - (ftoutline.points[l].x - ftoutline.points[m].x)* scale / 3.0f; - bezt->vec[2][1] = ftoutline.points[l].y* scale - (ftoutline.points[l].y - ftoutline.points[m].y)* scale / 3.0f; - bezt->h2= HD_VECT; + bezt->vec[2][0] = ftoutline.points[l].x * scale - (ftoutline.points[l].x - ftoutline.points[m].x) * scale / 3.0f; + bezt->vec[2][1] = ftoutline.points[l].y * scale - (ftoutline.points[l].y - ftoutline.points[m].y) * scale / 3.0f; + bezt->h2 = HD_VECT; } } @@ -272,15 +272,15 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf // len_squared_v2v2 again, to check the angle between the handles // finally, check if one of them is a vector handle if ((dist_to_line_v2(bezt->vec[0], bezt->vec[1], bezt->vec[2]) < 0.001f) && - (len_squared_v2v2(bezt->vec[0], bezt->vec[1]) > 0.0001f*0.0001f) && - (len_squared_v2v2(bezt->vec[1], bezt->vec[2]) > 0.0001f*0.0001f) && - (len_squared_v2v2(bezt->vec[0], bezt->vec[2]) > 0.0002f*0.0001f) && - (len_squared_v2v2(bezt->vec[0], bezt->vec[2]) > MAX2(len_squared_v2v2(bezt->vec[0], bezt->vec[1]), len_squared_v2v2(bezt->vec[1], bezt->vec[2]))) && - bezt->h1 != HD_VECT && bezt->h2 != HD_VECT) + (len_squared_v2v2(bezt->vec[0], bezt->vec[1]) > 0.0001f * 0.0001f) && + (len_squared_v2v2(bezt->vec[1], bezt->vec[2]) > 0.0001f * 0.0001f) && + (len_squared_v2v2(bezt->vec[0], bezt->vec[2]) > 0.0002f * 0.0001f) && + (len_squared_v2v2(bezt->vec[0], bezt->vec[2]) > MAX2(len_squared_v2v2(bezt->vec[0], bezt->vec[1]), len_squared_v2v2(bezt->vec[1], bezt->vec[2]))) && + bezt->h1 != HD_VECT && bezt->h2 != HD_VECT) { - bezt->h1= bezt->h2= HD_ALIGN; + bezt->h1 = bezt->h2 = HD_ALIGN; } - bezt->radius= 1.0f; + bezt->radius = 1.0f; bezt++; } } @@ -297,18 +297,18 @@ static int objchr_to_ftvfontdata(VFont *vfont, FT_ULong charcode) struct TmpFont *tf; // Find the correct FreeType font - tf= BKE_vfont_find_tmpfont(vfont); + tf = BKE_vfont_find_tmpfont(vfont); // What, no font found. Something strange here if (!tf) return FALSE; // Load the font to memory if (tf->pf) { - err= FT_New_Memory_Face(library, - tf->pf->data, - tf->pf->size, - 0, - &face); + err = FT_New_Memory_Face(library, + tf->pf->data, + tf->pf->size, + 0, + &face); if (err) return FALSE; } else { @@ -324,7 +324,7 @@ static int objchr_to_ftvfontdata(VFont *vfont, FT_ULong charcode) } -static VFontData *objfnt_to_ftvfontdata(PackedFile * pf) +static VFontData *objfnt_to_ftvfontdata(PackedFile *pf) { // Variables FT_Face face; @@ -334,19 +334,19 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile * pf) VFontData *vfd; #if 0 - FT_CharMap found = 0; - FT_CharMap charmap; + FT_CharMap found = 0; + FT_CharMap charmap; FT_UShort my_platform_id = TT_PLATFORM_MICROSOFT; FT_UShort my_encoding_id = TT_MS_ID_UNICODE_CS; - int n; + int n; #endif // load the freetype font err = FT_New_Memory_Face(library, - pf->data, - pf->size, - 0, - &face ); + pf->data, + pf->size, + 0, + &face); if (err) return NULL; @@ -355,14 +355,14 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile * pf) { charmap = face->charmaps[n]; if (charmap->platform_id == my_platform_id && - charmap->encoding_id == my_encoding_id ) + charmap->encoding_id == my_encoding_id) { found = charmap; break; } } - if (!found ) { return NULL; } + if (!found) { return NULL; } // now, select the charmap for the face object err = FT_Set_Charmap(face, found); @@ -370,19 +370,19 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile * pf) #endif // allocate blender font - vfd= MEM_callocN(sizeof(*vfd), "FTVFontData"); + vfd = MEM_callocN(sizeof(*vfd), "FTVFontData"); // get the name fontname = FT_Get_Postscript_Name(face); BLI_strncpy(vfd->name, (fontname == NULL) ? "" : fontname, sizeof(vfd->name)); // Extract the first 256 character from TTF - lcode= charcode= FT_Get_First_Char(face, &glyph_index); + lcode = charcode = FT_Get_First_Char(face, &glyph_index); // No charmap found from the ttf so we need to figure it out if (glyph_index == 0) { - FT_CharMap found = NULL; - FT_CharMap charmap; + FT_CharMap found = NULL; + FT_CharMap charmap; int n; for (n = 0; n < face->num_charmaps; n++) { @@ -395,10 +395,10 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile * pf) err = FT_Set_Charmap(face, found); - if ( err ) + if (err) return NULL; - lcode= charcode= FT_Get_First_Char(face, &glyph_index); + lcode = charcode = FT_Get_First_Char(face, &glyph_index); } // Load characters @@ -419,25 +419,25 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile * pf) } -static int check_freetypefont(PackedFile * pf) +static int check_freetypefont(PackedFile *pf) { - FT_Face face; - FT_GlyphSlot glyph; - FT_UInt glyph_index; + FT_Face face; + FT_GlyphSlot glyph; + FT_UInt glyph_index; #if 0 - FT_CharMap charmap; - FT_CharMap found; + FT_CharMap charmap; + FT_CharMap found; FT_UShort my_platform_id = TT_PLATFORM_MICROSOFT; FT_UShort my_encoding_id = TT_MS_ID_UNICODE_CS; - int n; + int n; #endif int success = 0; - err = FT_New_Memory_Face( library, - pf->data, - pf->size, - 0, - &face ); + err = FT_New_Memory_Face(library, + pf->data, + pf->size, + 0, + &face); if (err) { success = 0; //XXX error("This is not a valid font"); @@ -445,7 +445,7 @@ static int check_freetypefont(PackedFile * pf) else { #if 0 - for ( n = 0; n < face->num_charmaps; n++) { + for (n = 0; n < face->num_charmaps; n++) { charmap = face->charmaps[n]; if (charmap->platform_id == my_platform_id && charmap->encoding_id == my_encoding_id) { found = charmap; @@ -453,19 +453,19 @@ static int check_freetypefont(PackedFile * pf) } } - if (!found ) { return 0; } + if (!found) { return 0; } // now, select the charmap for the face object - err = FT_Set_Charmap( face, found ); - if ( err ) { return 0; } + err = FT_Set_Charmap(face, found); + if (err) { return 0; } #endif - glyph_index = FT_Get_Char_Index( face, 'A' ); + glyph_index = FT_Get_Char_Index(face, 'A'); err = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP); if (err) success = 0; else { glyph = face->glyph; - if (glyph->format == ft_glyph_format_outline ) { + if (glyph->format == ft_glyph_format_outline) { success = 1; } else { @@ -481,11 +481,11 @@ static int check_freetypefont(PackedFile * pf) VFontData *BLI_vfontdata_from_freetypefont(PackedFile *pf) { - VFontData *vfd= NULL; + VFontData *vfd = NULL; int success = 0; //init Freetype - err = FT_Init_FreeType( &library); + err = FT_Init_FreeType(&library); if (err) { //XXX error("Failed to load the Freetype font library"); return NULL; @@ -494,7 +494,7 @@ VFontData *BLI_vfontdata_from_freetypefont(PackedFile *pf) success = check_freetypefont(pf); if (success) { - vfd= objfnt_to_ftvfontdata(pf); + vfd = objfnt_to_ftvfontdata(pf); } //free Freetype diff --git a/source/blender/blenlib/intern/graph.c b/source/blender/blenlib/intern/graph.c index 432a74a5890..8eaf793ad5e 100644 --- a/source/blender/blenlib/intern/graph.c +++ b/source/blender/blenlib/intern/graph.c @@ -38,10 +38,10 @@ -static void testRadialSymmetry(BGraph *graph, BNode* root_node, RadialArc* ring, int total, float axis[3], float limit, int group); +static void testRadialSymmetry(BGraph *graph, BNode *root_node, RadialArc *ring, int total, float axis[3], float limit, int group); static void handleAxialSymmetry(BGraph *graph, BNode *root_node, int depth, float axis[3], float limit); -static void testAxialSymmetry(BGraph *graph, BNode* root_node, BNode* node1, BNode* node2, BArc* arc1, BArc* arc2, float axis[3], float limit, int group); +static void testAxialSymmetry(BGraph *graph, BNode *root_node, BNode *node1, BNode *node2, BArc *arc1, BArc *arc2, float axis[3], float limit, int group); static void flagAxialSymmetry(BNode *root_node, BNode *end_node, BArc *arc, int group); void BLI_freeNode(BGraph *graph, BNode *node) @@ -109,13 +109,13 @@ void BLI_buildAdjacencyList(BGraph *graph) MEM_freeN(node->arcs); } - node->arcs = MEM_callocN((node->degree) * sizeof(BArc*), "adjacency list"); + node->arcs = MEM_callocN((node->degree) * sizeof(BArc *), "adjacency list"); /* temporary use to indicate the first index available in the lists */ node->flag = 0; } - for (arc = graph->arcs.first; arc; arc= arc->next) { + for (arc = graph->arcs.first; arc; arc = arc->next) { addArcToNodeAdjacencyList(arc->head, arc); addArcToNodeAdjacencyList(arc->tail, arc); } @@ -127,7 +127,7 @@ void BLI_buildAdjacencyList(BGraph *graph) } } -void BLI_rebuildAdjacencyListForNode(BGraph* graph, BNode *node) +void BLI_rebuildAdjacencyListForNode(BGraph *graph, BNode *node) { BArc *arc; @@ -135,12 +135,12 @@ void BLI_rebuildAdjacencyListForNode(BGraph* graph, BNode *node) MEM_freeN(node->arcs); } - node->arcs = MEM_callocN((node->degree) * sizeof(BArc*), "adjacency list"); + node->arcs = MEM_callocN((node->degree) * sizeof(BArc *), "adjacency list"); /* temporary use to indicate the first index available in the lists */ node->flag = 0; - for (arc = graph->arcs.first; arc; arc= arc->next) { + for (arc = graph->arcs.first; arc; arc = arc->next) { if (arc->head == node) { addArcToNodeAdjacencyList(arc->head, arc); } @@ -249,7 +249,7 @@ void BLI_removeDoubleNodes(BGraph *graph, float limit) } -BNode * BLI_FindNodeByPosition(BGraph *graph, float *p, float limit) +BNode *BLI_FindNodeByPosition(BGraph *graph, float *p, float limit) { BNode *closest_node = NULL, *node; float min_distance = 0.0f; @@ -343,7 +343,7 @@ static int detectCycle(BNode *node, BArc *src_arc) return value; } -int BLI_isGraphCyclic(BGraph *graph) +int BLI_isGraphCyclic(BGraph *graph) { BNode *node; int value = 0; @@ -364,7 +364,7 @@ int BLI_isGraphCyclic(BGraph *graph) return value; } -BArc * BLI_findConnectedArc(BGraph *graph, BArc *arc, BNode *v) +BArc *BLI_findConnectedArc(BGraph *graph, BArc *arc, BNode *v) { BArc *nextArc; @@ -476,7 +476,7 @@ void BLI_mirrorAlongAxis(float v[3], float center[3], float axis[3]) add_v3_v3(v, pv); } -static void testRadialSymmetry(BGraph *graph, BNode* root_node, RadialArc* ring, int total, float axis[3], float limit, int group) +static void testRadialSymmetry(BGraph *graph, BNode *root_node, RadialArc *ring, int total, float axis[3], float limit, int group) { int symmetric = 1; int i; @@ -707,7 +707,7 @@ static void flagAxialSymmetry(BNode *root_node, BNode *end_node, BArc *arc, int } } -static void testAxialSymmetry(BGraph *graph, BNode* root_node, BNode* node1, BNode* node2, BArc* arc1, BArc* arc2, float axis[3], float limit, int group) +static void testAxialSymmetry(BGraph *graph, BNode *root_node, BNode *node1, BNode *node2, BArc *arc1, BArc *arc2, float axis[3], float limit, int group) { float nor[3], vec[3], p[3]; @@ -962,21 +962,21 @@ void BLI_markdownSymmetry(BGraph *graph, BNode *root_node, float limit) } } -void* IT_head(void* arg) +void *IT_head(void *arg) { - BArcIterator *iter = (BArcIterator*)arg; + BArcIterator *iter = (BArcIterator *)arg; return iter->head(iter); } -void* IT_tail(void* arg) +void *IT_tail(void *arg) { - BArcIterator *iter = (BArcIterator*)arg; + BArcIterator *iter = (BArcIterator *)arg; return iter->tail(iter); } -void* IT_peek(void* arg, int n) +void *IT_peek(void *arg, int n) { - BArcIterator *iter = (BArcIterator*)arg; + BArcIterator *iter = (BArcIterator *)arg; if (iter->index + n < 0) { return iter->head(iter); @@ -989,26 +989,26 @@ void* IT_peek(void* arg, int n) } } -void* IT_next(void* arg) +void *IT_next(void *arg) { - BArcIterator *iter = (BArcIterator*)arg; + BArcIterator *iter = (BArcIterator *)arg; return iter->next(iter); } -void* IT_nextN(void* arg, int n) +void *IT_nextN(void *arg, int n) { - BArcIterator *iter = (BArcIterator*)arg; + BArcIterator *iter = (BArcIterator *)arg; return iter->nextN(iter, n); } -void* IT_previous(void* arg) +void *IT_previous(void *arg) { - BArcIterator *iter = (BArcIterator*)arg; + BArcIterator *iter = (BArcIterator *)arg; return iter->previous(iter); } -int IT_stopped(void* arg) +int IT_stopped(void *arg) { - BArcIterator *iter = (BArcIterator*)arg; + BArcIterator *iter = (BArcIterator *)arg; return iter->stopped(iter); } diff --git a/source/blender/blenlib/intern/gsqueue.c b/source/blender/blenlib/intern/gsqueue.c index 2aa51387c48..d569534f2f3 100644 --- a/source/blender/blenlib/intern/gsqueue.c +++ b/source/blender/blenlib/intern/gsqueue.c @@ -40,31 +40,31 @@ struct _GSQueueElem { }; struct _GSQueue { - GSQueueElem *head; - GSQueueElem *tail; - int elem_size; + GSQueueElem *head; + GSQueueElem *tail; + int elem_size; }; GSQueue *BLI_gsqueue_new(int elem_size) { - GSQueue *gq= MEM_mallocN(sizeof(*gq), "gqueue_new"); - gq->head= gq->tail= NULL; - gq->elem_size= elem_size; + GSQueue *gq = MEM_mallocN(sizeof(*gq), "gqueue_new"); + gq->head = gq->tail = NULL; + gq->elem_size = elem_size; return gq; } int BLI_gsqueue_is_empty(GSQueue *gq) { - return (gq->head==NULL); + return (gq->head == NULL); } int BLI_gsqueue_size(GSQueue *gq) { GSQueueElem *elem; - int size= 0; + int size = 0; - for (elem=gq->head; elem; elem=elem->next) + for (elem = gq->head; elem; elem = elem->next) size++; return size; @@ -76,12 +76,12 @@ void BLI_gsqueue_peek(GSQueue *gq, void *item_r) } void BLI_gsqueue_pop(GSQueue *gq, void *item_r) { - GSQueueElem *elem= gq->head; - if (elem==gq->tail) { - gq->head= gq->tail= NULL; + GSQueueElem *elem = gq->head; + if (elem == gq->tail) { + gq->head = gq->tail = NULL; } else { - gq->head= gq->head->next; + gq->head = gq->head->next; } if (item_r) memcpy(item_r, &elem[1], gq->elem_size); @@ -93,31 +93,31 @@ void BLI_gsqueue_push(GSQueue *gq, void *item) /* compare: prevent events added double in row */ if (!BLI_gsqueue_is_empty(gq)) { - if (0==memcmp(item, &gq->head[1], gq->elem_size)) + if (0 == memcmp(item, &gq->head[1], gq->elem_size)) return; } - elem= MEM_mallocN(sizeof(*elem)+gq->elem_size, "gqueue_push"); + elem = MEM_mallocN(sizeof(*elem) + gq->elem_size, "gqueue_push"); memcpy(&elem[1], item, gq->elem_size); - elem->next= NULL; + elem->next = NULL; if (BLI_gsqueue_is_empty(gq)) { - gq->tail= gq->head= elem; + gq->tail = gq->head = elem; } else { - gq->tail= gq->tail->next= elem; + gq->tail = gq->tail->next = elem; } } void BLI_gsqueue_pushback(GSQueue *gq, void *item) { - GSQueueElem *elem= MEM_mallocN(sizeof(*elem)+gq->elem_size, "gqueue_push"); + GSQueueElem *elem = MEM_mallocN(sizeof(*elem) + gq->elem_size, "gqueue_push"); memcpy(&elem[1], item, gq->elem_size); - elem->next= gq->head; + elem->next = gq->head; if (BLI_gsqueue_is_empty(gq)) { - gq->head= gq->tail= elem; + gq->head = gq->tail = elem; } else { - gq->head= elem; + gq->head = elem; } } diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c index 19cae7456c9..8fe9a94b466 100644 --- a/source/blender/blenlib/intern/listbase.c +++ b/source/blender/blenlib/intern/listbase.c @@ -47,23 +47,23 @@ /* Ripped this from blender.c */ void BLI_movelisttolist(ListBase *dst, ListBase *src) { - if (src->first==NULL) return; + if (src->first == NULL) return; - if (dst->first==NULL) { - dst->first= src->first; - dst->last= src->last; + if (dst->first == NULL) { + dst->first = src->first; + dst->last = src->last; } else { - ((Link *)dst->last)->next= src->first; - ((Link *)src->first)->prev= dst->last; - dst->last= src->last; + ((Link *)dst->last)->next = src->first; + ((Link *)src->first)->prev = dst->last; + dst->last = src->last; } - src->first= src->last= NULL; + src->first = src->last = NULL; } void BLI_addhead(ListBase *listbase, void *vlink) { - Link *link= vlink; + Link *link = vlink; if (link == NULL) return; if (listbase == NULL) return; @@ -79,7 +79,7 @@ void BLI_addhead(ListBase *listbase, void *vlink) void BLI_addtail(ListBase *listbase, void *vlink) { - Link *link= vlink; + Link *link = vlink; if (link == NULL) return; if (listbase == NULL) return; @@ -95,7 +95,7 @@ void BLI_addtail(ListBase *listbase, void *vlink) void BLI_remlink(ListBase *listbase, void *vlink) { - Link *link= vlink; + Link *link = vlink; if (link == NULL) return; if (listbase == NULL) return; @@ -121,7 +121,7 @@ int BLI_remlink_safe(ListBase *listbase, void *vlink) void BLI_freelinkN(ListBase *listbase, void *vlink) { - Link *link= vlink; + Link *link = vlink; if (link == NULL) return; if (listbase == NULL) return; @@ -133,8 +133,8 @@ void BLI_freelinkN(ListBase *listbase, void *vlink) void BLI_insertlink(ListBase *listbase, void *vprevlink, void *vnewlink) { - Link *prevlink= vprevlink; - Link *newlink= vnewlink; + Link *prevlink = vprevlink; + Link *newlink = vnewlink; /* newlink comes after prevlink */ if (newlink == NULL) return; @@ -143,28 +143,28 @@ void BLI_insertlink(ListBase *listbase, void *vprevlink, void *vnewlink) /* empty list */ if (listbase->first == NULL) { - listbase->first= newlink; - listbase->last= newlink; + listbase->first = newlink; + listbase->last = newlink; return; } /* insert before first element */ if (prevlink == NULL) { - newlink->next= listbase->first; - newlink->prev= NULL; - newlink->next->prev= newlink; - listbase->first= newlink; + newlink->next = listbase->first; + newlink->prev = NULL; + newlink->next->prev = newlink; + listbase->first = newlink; return; } /* at end of list */ - if (listbase->last== prevlink) + if (listbase->last == prevlink) listbase->last = newlink; - newlink->next= prevlink->next; - prevlink->next= newlink; - if (newlink->next) newlink->next->prev= newlink; - newlink->prev= prevlink; + 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 */ @@ -195,8 +195,8 @@ void BLI_sortlist(ListBase *listbase, int (*cmp)(void *, void *)) void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink) { - Link *prevlink= vprevlink; - Link *newlink= vnewlink; + Link *prevlink = vprevlink; + Link *newlink = vnewlink; /* newlink before nextlink */ if (newlink == NULL) return; @@ -204,8 +204,8 @@ void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink) /* empty list */ if (listbase->first == NULL) { - listbase->first= newlink; - listbase->last= newlink; + listbase->first = newlink; + listbase->last = newlink; return; } @@ -230,8 +230,8 @@ void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink) void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink) { - Link *nextlink= vnextlink; - Link *newlink= vnewlink; + Link *nextlink = vnextlink; + Link *newlink = vnewlink; /* newlink before nextlink */ if (newlink == NULL) return; @@ -239,28 +239,28 @@ void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink) /* empty list */ if (listbase->first == NULL) { - listbase->first= newlink; - listbase->last= newlink; + listbase->first = newlink; + listbase->last = newlink; return; } /* insert at end of list */ if (nextlink == NULL) { - newlink->prev= listbase->last; - newlink->next= NULL; - ((Link *)listbase->last)->next= newlink; - listbase->last= newlink; + newlink->prev = listbase->last; + newlink->next = NULL; + ((Link *)listbase->last)->next = newlink; + listbase->last = newlink; return; } /* at beginning of list */ - if (listbase->first== nextlink) + if (listbase->first == nextlink) listbase->first = newlink; - newlink->next= nextlink; - newlink->prev= nextlink->prev; - nextlink->prev= newlink; - if (newlink->prev) newlink->prev->next= newlink; + newlink->next = nextlink; + newlink->prev = nextlink->prev; + nextlink->prev = newlink; + if (newlink->prev) newlink->prev->next = newlink; } @@ -271,15 +271,15 @@ void BLI_freelist(ListBase *listbase) if (listbase == NULL) return; - link= listbase->first; + link = listbase->first; while (link) { - next= link->next; + next = link->next; free(link); - link= next; + link = next; } - listbase->first= NULL; - listbase->last= NULL; + listbase->first = NULL; + listbase->last = NULL; } void BLI_freelistN(ListBase *listbase) @@ -288,15 +288,15 @@ void BLI_freelistN(ListBase *listbase) if (listbase == NULL) return; - link= listbase->first; + link = listbase->first; while (link) { - next= link->next; + next = link->next; MEM_freeN(link); - link= next; + link = next; } - listbase->first= NULL; - listbase->last= NULL; + listbase->first = NULL; + listbase->last = NULL; } @@ -309,7 +309,7 @@ int BLI_countlist(const ListBase *listbase) link = listbase->first; while (link) { count++; - link= link->next; + link = link->next; } } return count; @@ -347,19 +347,19 @@ void *BLI_rfindlink(const ListBase *listbase, int number) int BLI_findindex(const ListBase *listbase, void *vlink) { - Link *link= NULL; - int number= 0; + Link *link = NULL; + int number = 0; if (listbase == NULL) return -1; if (vlink == NULL) return -1; - link= listbase->first; + link = listbase->first; while (link) { if (link == vlink) return number; number++; - link= link->next; + link = link->next; } return -1; @@ -367,15 +367,15 @@ int BLI_findindex(const ListBase *listbase, void *vlink) void *BLI_findstring(const ListBase *listbase, const char *id, const int offset) { - Link *link= NULL; + Link *link = NULL; const char *id_iter; if (listbase == NULL) return NULL; - for (link= listbase->first; link; link= link->next) { - id_iter= ((const char *)link) + offset; + for (link = listbase->first; link; link = link->next) { + id_iter = ((const char *)link) + offset; - if (id[0] == id_iter[0] && strcmp(id, id_iter)==0) { + if (id[0] == id_iter[0] && strcmp(id, id_iter) == 0) { return link; } } @@ -385,15 +385,15 @@ void *BLI_findstring(const ListBase *listbase, const char *id, const int offset) /* same as above but find reverse */ void *BLI_rfindstring(const ListBase *listbase, const char *id, const int offset) { - Link *link= NULL; + Link *link = NULL; const char *id_iter; if (listbase == NULL) return NULL; - for (link= listbase->last; link; link= link->prev) { - id_iter= ((const char *)link) + offset; + for (link = listbase->last; link; link = link->prev) { + id_iter = ((const char *)link) + offset; - if (id[0] == id_iter[0] && strcmp(id, id_iter)==0) { + if (id[0] == id_iter[0] && strcmp(id, id_iter) == 0) { return link; } } @@ -403,16 +403,16 @@ void *BLI_rfindstring(const ListBase *listbase, const char *id, const int offset void *BLI_findstring_ptr(const ListBase *listbase, const char *id, const int offset) { - Link *link= NULL; + Link *link = NULL; const char *id_iter; if (listbase == NULL) return NULL; - for (link= listbase->first; link; link= link->next) { + for (link = listbase->first; link; link = link->next) { /* exact copy of BLI_findstring(), except for this line */ - id_iter= *((const char **)(((const char *)link) + offset)); + id_iter = *((const char **)(((const char *)link) + offset)); - if (id[0] == id_iter[0] && strcmp(id, id_iter)==0) { + if (id[0] == id_iter[0] && strcmp(id, id_iter) == 0) { return link; } } @@ -422,16 +422,16 @@ void *BLI_findstring_ptr(const ListBase *listbase, const char *id, const int off /* same as above but find reverse */ void *BLI_rfindstring_ptr(const ListBase *listbase, const char *id, const int offset) { - Link *link= NULL; + Link *link = NULL; const char *id_iter; if (listbase == NULL) return NULL; - for (link= listbase->last; link; link= link->prev) { + for (link = listbase->last; link; link = link->prev) { /* exact copy of BLI_rfindstring(), except for this line */ - id_iter= *((const char **)(((const char *)link) + offset)); + id_iter = *((const char **)(((const char *)link) + offset)); - if (id[0] == id_iter[0] && strcmp(id, id_iter)==0) { + if (id[0] == id_iter[0] && strcmp(id, id_iter) == 0) { return link; } } @@ -441,20 +441,20 @@ void *BLI_rfindstring_ptr(const ListBase *listbase, const char *id, const int of int BLI_findstringindex(const ListBase *listbase, const char *id, const int offset) { - Link *link= NULL; + Link *link = NULL; const char *id_iter; - int i= 0; + int i = 0; if (listbase == NULL) return -1; - link= listbase->first; + link = listbase->first; while (link) { - id_iter= ((const char *)link) + offset; + id_iter = ((const char *)link) + offset; - if (id[0] == id_iter[0] && strcmp(id, id_iter)==0) + if (id[0] == id_iter[0] && strcmp(id, id_iter) == 0) return i; i++; - link= link->next; + link = link->next; } return -1; @@ -465,19 +465,19 @@ void BLI_duplicatelist(ListBase *dst, const ListBase *src) struct Link *dst_link, *src_link; /* in this order, to ensure it works if dst == src */ - src_link= src->first; - dst->first= dst->last= NULL; + src_link = src->first; + dst->first = dst->last = NULL; while (src_link) { - dst_link= MEM_dupallocN(src_link); + dst_link = MEM_dupallocN(src_link); BLI_addtail(dst, dst_link); - src_link= src_link->next; + src_link = src_link->next; } } /* create a generic list node containing link to provided data */ -LinkData *BLI_genericNodeN (void *data) +LinkData *BLI_genericNodeN(void *data) { LinkData *ld; @@ -485,8 +485,8 @@ LinkData *BLI_genericNodeN (void *data) return NULL; /* create new link, and make it hold the given data */ - ld= MEM_callocN(sizeof(LinkData), "BLI_genericNodeN()"); - ld->data= data; + ld = MEM_callocN(sizeof(LinkData), "BLI_genericNodeN()"); + ld->data = data; return ld; } diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index a18c297fdae..59147040fd8 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -48,7 +48,7 @@ #include "BLI_utildefines.h" #include "BKE_utildefines.h" -#include "BKE_blender.h" // BLENDER_VERSION +#include "BKE_blender.h" // BLENDER_VERSION #include "GHOST_Path-api.h" @@ -79,26 +79,26 @@ /* standard paths */ #ifdef WIN32 -# define BLENDER_USER_FORMAT "%s\\Blender Foundation\\Blender\\%s" -# define BLENDER_SYSTEM_FORMAT "%s\\Blender Foundation\\Blender\\%s" +# define BLENDER_USER_FORMAT "%s\\Blender Foundation\\Blender\\%s" +# define BLENDER_SYSTEM_FORMAT "%s\\Blender Foundation\\Blender\\%s" #elif defined(__APPLE__) -# define BLENDER_USER_FORMAT "%s/Blender/%s" -# define BLENDER_SYSTEM_FORMAT "%s/Blender/%s" +# define BLENDER_USER_FORMAT "%s/Blender/%s" +# define BLENDER_SYSTEM_FORMAT "%s/Blender/%s" #else /* UNIX */ # ifndef WITH_XDG_USER_DIRS /* oldschool unix ~/.blender/ */ -# define BLENDER_USER_FORMAT "%s/.blender/%s" +# define BLENDER_USER_FORMAT "%s/.blender/%s" # else /* new XDG ~/blender/.config/ */ -# define BLENDER_USER_FORMAT "%s/blender/%s" +# define BLENDER_USER_FORMAT "%s/blender/%s" # endif // WITH_XDG_USER_DIRS -# define BLENDER_SYSTEM_FORMAT "%s/blender/%s" +# define BLENDER_SYSTEM_FORMAT "%s/blender/%s" #endif /* local */ #define UNIQUE_NAME_MAX 128 -static char bprogname[FILE_MAX]; /* path to program executable */ -static char bprogdir[FILE_MAX]; /* path in which executable is located */ -static char btempdir[FILE_MAX]; /* temporary directory */ +static char bprogname[FILE_MAX]; /* path to program executable */ +static char bprogdir[FILE_MAX]; /* path in which executable is located */ +static char btempdir[FILE_MAX]; /* temporary directory */ static int add_win32_extension(char *name); static char *blender_version_decimal(const int ver); @@ -112,7 +112,7 @@ int BLI_stringdec(const char *string, char *head, char *tail, unsigned short *nu char *lslash = BLI_last_slash(string); len2 = len = strlen(string); if (lslash) - lenlslash= (int)(lslash - string); + lenlslash = (int)(lslash - string); while (len > lenlslash && string[--len] != '.') {}; if (len == lenlslash && string[len] != '.') len = len2; @@ -133,12 +133,12 @@ int BLI_stringdec(const char *string, char *head, char *tail, unsigned short *nu } } if (found) { - if (tail) strcpy(tail, &string[nume+1]); + if (tail) strcpy(tail, &string[nume + 1]); if (head) { strcpy(head, string); - head[nums]=0; + head[nums] = 0; } - if (numlen) *numlen = nume-nums+1; + if (numlen) *numlen = nume - nums + 1; return ((int)atoi(&(string[nums]))); } if (tail) strcpy(tail, string + len); @@ -146,15 +146,15 @@ int BLI_stringdec(const char *string, char *head, char *tail, unsigned short *nu strncpy(head, string, len); head[len] = '\0'; } - if (numlen) *numlen=0; + if (numlen) *numlen = 0; return 0; } void BLI_stringenc(char *string, const char *head, const char *tail, unsigned short numlen, int pic) { - char fmtstr[16]=""; - if (pic < 0) pic= 0; + char fmtstr[16] = ""; + if (pic < 0) pic = 0; sprintf(fmtstr, "%%s%%.%dd%%s", numlen); sprintf(string, fmtstr, head, pic, tail); } @@ -165,28 +165,28 @@ int BLI_split_name_num(char *left, int *nr, const char *name, const char delim) { int a; - *nr= 0; - a= strlen(name); + *nr = 0; + a = strlen(name); memcpy(left, name, (a + 1) * sizeof(char)); - if (a>1 && name[a-1]==delim) return a; + if (a > 1 && name[a - 1] == delim) return a; while (a--) { - if ( name[a]==delim ) { - left[a]= 0; - *nr= atol(name+a+1); + if (name[a] == delim) { + left[a] = 0; + *nr = atol(name + a + 1); /* casting down to an int, can overflow for large numbers */ if (*nr < 0) - *nr= 0; + *nr = 0; return a; } - if ( isdigit(name[a])==0 ) break; + if (isdigit(name[a]) == 0) break; - left[a]= 0; + left[a] = 0; } - for (a= 0; name[a]; a++) - left[a]= name[a]; + for (a = 0; name[a]; a++) + left[a] = name[a]; return a; } @@ -209,7 +209,7 @@ void BLI_newname(char *name, int add) pic += add; - if (digits==4 && pic<0) pic= 0; + if (digits == 4 && pic < 0) pic = 0; BLI_stringenc(name, head, tail, digits, pic); } @@ -222,13 +222,13 @@ int BLI_uniquename_cb(int (*unique_check)(void *, const char *), void *arg, cons } if (unique_check(arg, name)) { - char numstr[16]; - char tempname[UNIQUE_NAME_MAX]; - char left[UNIQUE_NAME_MAX]; - int number; - int len= BLI_split_name_num(left, &number, name, delim); + char numstr[16]; + char tempname[UNIQUE_NAME_MAX]; + char left[UNIQUE_NAME_MAX]; + int number; + int len = BLI_split_name_num(left, &number, name, delim); do { - int numlen= BLI_snprintf(numstr, sizeof(numstr), "%c%03d", delim, ++number); + int numlen = BLI_snprintf(numstr, sizeof(numstr), "%c%03d", delim, ++number); /* highly unlikely the string only has enough room for the number * but support anyway */ @@ -238,7 +238,7 @@ int BLI_uniquename_cb(int (*unique_check)(void *, const char *), void *arg, cons } else { char *tempname_buf; - tempname[0]= '\0'; + tempname[0] = '\0'; tempname_buf = BLI_strncat_utf8(tempname, left, name_len - numlen); memcpy(tempname_buf, numstr, numlen + 1); } @@ -254,7 +254,7 @@ int BLI_uniquename_cb(int (*unique_check)(void *, const char *), void *arg, cons /* little helper macro for BLI_uniquename */ #ifndef GIVE_STRADDR - #define GIVE_STRADDR(data, offset) ( ((char *)data) + offset ) + #define GIVE_STRADDR(data, offset) ( ((char *)data) + offset) #endif /* Generic function to set a unique name. It is only designed to be used in situations @@ -262,16 +262,16 @@ int BLI_uniquename_cb(int (*unique_check)(void *, const char *), void *arg, cons * * For places where this is used, see constraint.c for example... * - * 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 delimiter between parts of the name + * 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 delimiter between parts of the name */ static int uniquename_find_dupe(ListBase *list, void *vlink, const char *name, short name_offs) { Link *link; - for (link = list->first; link; link= link->next) { + for (link = list->first; link; link = link->next) { if (link != vlink) { if (!strcmp(GIVE_STRADDR(link, name_offs), name)) { return 1; @@ -284,16 +284,16 @@ static int uniquename_find_dupe(ListBase *list, void *vlink, const char *name, s static int uniquename_unique_check(void *arg, const char *name) { - struct {ListBase *lb; void *vlink; short name_offs;} *data= arg; + struct {ListBase *lb; void *vlink; short name_offs; } *data = arg; return uniquename_find_dupe(data->lb, data->vlink, name, data->name_offs); } void BLI_uniquename(ListBase *list, void *vlink, const char defname[], char delim, short name_offs, short name_len) { - struct {ListBase *lb; void *vlink; short name_offs;} data; - data.lb= list; - data.vlink= vlink; - data.name_offs= name_offs; + struct {ListBase *lb; void *vlink; short name_offs; } data; + data.lb = list; + data.vlink = vlink; + data.name_offs = name_offs; assert((name_len > 1) && (name_len <= UNIQUE_NAME_MAX)); @@ -324,11 +324,11 @@ void BLI_cleanup_path(const char *relabase, char *dir) BLI_path_abs(dir, relabase); } else { - if (dir[0]=='/' && dir[1]=='/') { - if (dir[2]== '\0') { + if (dir[0] == '/' && dir[1] == '/') { + if (dir[2] == '\0') { return; /* path is "//" - cant clean it */ } - dir = dir+2; /* skip the first // */ + dir = dir + 2; /* skip the first // */ } } @@ -344,19 +344,19 @@ void BLI_cleanup_path(const char *relabase, char *dir) /* Note, this should really be moved to the file selector, * since this function is used in many areas */ - if (strcmp(dir, ".")==0) { /* happens for example in FILE_MAIN */ + if (strcmp(dir, ".") == 0) { /* happens for example in FILE_MAIN */ get_default_root(dir); return; } while ( (start = strstr(dir, "\\..\\")) ) { eind = start + strlen("\\..\\") - 1; - a = start-dir-1; - while (a>0) { + a = start - dir - 1; + while (a > 0) { if (dir[a] == '\\') break; a--; } - if (a<0) { + if (a < 0) { break; } else { @@ -369,36 +369,36 @@ void BLI_cleanup_path(const char *relabase, char *dir) memmove(start, eind, strlen(eind) + 1); } - while ( (start = strstr(dir, "\\\\" )) ) { + while ( (start = strstr(dir, "\\\\")) ) { eind = start + strlen("\\\\") - 1; memmove(start, eind, strlen(eind) + 1); } #else - if (dir[0]=='.') { /* happens, for example in FILE_MAIN */ - dir[0]= '/'; - dir[1]= 0; + if (dir[0] == '.') { /* happens, for example in FILE_MAIN */ + dir[0] = '/'; + dir[1] = 0; return; } /* support for odd paths: eg /../home/me --> /home/me * this is a valid path in blender but we cant handle this the usual way below * simply strip this prefix then evaluate the path as usual. pythons os.path.normpath() does this */ - while ((strncmp(dir, "/../", 4)==0)) { + while ((strncmp(dir, "/../", 4) == 0)) { memmove(dir, dir + 4, strlen(dir + 4) + 1); } while ( (start = strstr(dir, "/../")) ) { eind = start + (4 - 1) /* strlen("/../") - 1 */; - a = start-dir-1; - while (a>0) { + a = start - dir - 1; + while (a > 0) { if (dir[a] == '/') break; a--; } - if (a<0) { + if (a < 0) { break; } else { - memmove(dir+a, eind, strlen(eind) + 1); + memmove(dir + a, eind, strlen(eind) + 1); } } @@ -407,7 +407,7 @@ void BLI_cleanup_path(const char *relabase, char *dir) memmove(start, eind, strlen(eind) + 1); } - while ( (start = strstr(dir, "//" )) ) { + while ( (start = strstr(dir, "//")) ) { eind = start + (2 - 1) /* strlen("//") - 1 */; memmove(start, eind, strlen(eind) + 1); } @@ -429,19 +429,19 @@ void BLI_cleanup_file(const char *relabase, char *dir) void BLI_path_rel(char *file, const char *relfile) { - char * lslash; + char *lslash; char temp[FILE_MAX]; char res[FILE_MAX]; /* if file is already relative, bail out */ - if (file[0]=='/' && file[1]=='/') return; + if (file[0] == '/' && file[1] == '/') return; /* also bail out if relative path is not set */ if (relfile[0] == 0) return; #ifdef WIN32 if (BLI_strnlen(relfile, 3) > 2 && relfile[1] != ':') { - char* ptemp; + char *ptemp; /* fix missing volume name in relative base, * can happen with old recent-files.txt files */ get_default_root(temp); @@ -449,14 +449,14 @@ void BLI_path_rel(char *file, const char *relfile) if (relfile[0] != '\\' && relfile[0] != '/') { ptemp++; } - BLI_strncpy(ptemp, relfile, FILE_MAX-3); + BLI_strncpy(ptemp, relfile, FILE_MAX - 3); } else { BLI_strncpy(temp, relfile, FILE_MAX); } if (BLI_strnlen(file, 3) > 2) { - if ( temp[1] == ':' && file[1] == ':' && temp[0] != file[0] ) + if (temp[1] == ':' && file[1] == ':' && temp[0] != file[0]) return; } #else @@ -476,8 +476,8 @@ void BLI_path_rel(char *file, const char *relfile) if (lslash) { /* find the prefix of the filename that is equal for both filenames. * This is replaced by the two slashes at the beginning */ - char *p= temp; - char *q= file; + char *p = temp; + char *q = file; #ifdef WIN32 while (tolower(*p) == tolower(*q)) @@ -490,7 +490,7 @@ void BLI_path_rel(char *file, const char *relfile) /* don't search beyond the end of the string * in the rare case they match */ - if ((*p=='\0') || (*q=='\0')) { + if ((*p == '\0') || (*q == '\0')) { break; } } @@ -505,23 +505,23 @@ void BLI_path_rel(char *file, const char *relfile) while ( (p >= temp) && (*p != '/') ) { --p; --q; } } - strcpy(res, "//"); + strcpy(res, "//"); /* p now points to the slash that is at the beginning of the part * where the path is different from the relative path. * We count the number of directories we need to go up in the * hierarchy to arrive at the common 'prefix' of the path */ - while (p && p < lslash) { + while (p && p < lslash) { if (*p == '/') - strcat(res, "../"); + strcat(res, "../"); p++; } - strcat(res, q+1); /* don't copy the slash at the beginning */ + strcat(res, q + 1); /* don't copy the slash at the beginning */ -#ifdef WIN32 - BLI_char_switch(res+2, '/', '\\'); +#ifdef WIN32 + BLI_char_switch(res + 2, '/', '\\'); #endif strcpy(file, res); } @@ -534,7 +534,7 @@ int BLI_has_parent(char *path) BLI_clean(path); len = BLI_add_slash(path) - 1; - while (len>=0) { + while (len >= 0) { if ((path[len] == '\\') || (path[len] == '/')) slashes++; len--; @@ -544,9 +544,9 @@ int BLI_has_parent(char *path) int BLI_parent_dir(char *path) { - static char parent_dir[]= {'.', '.', SEP, '\0'}; /* "../" or "..\\" */ - char tmp[FILE_MAX+4]; - BLI_strncpy(tmp, path, sizeof(tmp)-4); + static char parent_dir[] = {'.', '.', SEP, '\0'}; /* "../" or "..\\" */ + char tmp[FILE_MAX + 4]; + BLI_strncpy(tmp, path, sizeof(tmp) - 4); BLI_add_slash(tmp); strcat(tmp, parent_dir); BLI_cleanup_dir(NULL, tmp); @@ -571,42 +571,42 @@ static int stringframe_chars(char *path, int *char_start, int *char_end) } else if (path[i] == '#') { ch_sta = i; - ch_end = ch_sta+1; + ch_end = ch_sta + 1; while (path[ch_end] == '#') { ch_end++; } - i = ch_end-1; /* keep searching */ + i = ch_end - 1; /* keep searching */ /* don't break, there may be a slash after this that invalidates the previous #'s */ } } if (ch_end) { - *char_start= ch_sta; - *char_end= ch_end; + *char_start = ch_sta; + *char_end = ch_end; return 1; } else { - *char_start= -1; - *char_end= -1; + *char_start = -1; + *char_end = -1; return 0; } } static void ensure_digits(char *path, int digits) { - char *file= BLI_last_slash(path); + char *file = BLI_last_slash(path); - if (file==NULL) - file= path; + if (file == NULL) + file = path; if (strrchr(file, '#') == NULL) { - int len= strlen(file); + int len = strlen(file); while (digits--) { - file[len++]= '#'; + file[len++] = '#'; } - file[len]= '\0'; + file[len] = '\0'; } } @@ -619,7 +619,7 @@ int BLI_path_frame(char *path, int frame, int digits) if (stringframe_chars(path, &ch_sta, &ch_end)) { /* warning, ch_end is the last # +1 */ char tmp[FILE_MAX]; - sprintf(tmp, "%.*s%.*d%s", ch_sta, path, ch_end-ch_sta, frame, path+ch_end); + sprintf(tmp, "%.*s%.*d%s", ch_sta, path, ch_end - ch_sta, frame, path + ch_end); strcpy(path, tmp); return 1; } @@ -637,7 +637,7 @@ int BLI_path_frame_range(char *path, int sta, int end, int digits) char tmp[FILE_MAX]; BLI_snprintf(tmp, sizeof(tmp), "%.*s%.*d-%.*d%s", - ch_sta, path, ch_end-ch_sta, sta, ch_end-ch_sta, end, path+ch_end); + ch_sta, path, ch_end - ch_sta, sta, ch_end - ch_sta, end, path + ch_end); BLI_strncpy(path, tmp, FILE_MAX); return 1; } @@ -646,7 +646,7 @@ int BLI_path_frame_range(char *path, int sta, int end, int digits) int BLI_path_abs(char *path, const char *basepath) { - int wasrelative = (strncmp(path, "//", 2)==0); + int wasrelative = (strncmp(path, "//", 2) == 0); char tmp[FILE_MAX]; char base[FILE_MAX]; #ifdef WIN32 @@ -679,7 +679,7 @@ int BLI_path_abs(char *path, const char *basepath) * Add a / prefix and lowercase the driveletter, remove the : * C:\foo.JPG -> /c/foo.JPG */ - if (isalpha(tmp[0]) && tmp[1] == ':' && (tmp[2]=='\\' || tmp[2]=='/') ) { + if (isalpha(tmp[0]) && tmp[1] == ':' && (tmp[2] == '\\' || tmp[2] == '/') ) { tmp[1] = tolower(tmp[0]); /* replace ':' with driveletter */ tmp[0] = '/'; /* '\' the slash will be converted later */ @@ -704,18 +704,18 @@ int BLI_path_abs(char *path, const char *basepath) /* Paths starting with // will get the blend file as their base, * this isn't standard in any os but is used in blender all over the place */ if (wasrelative) { - char *lslash= BLI_last_slash(base); + char *lslash = BLI_last_slash(base); if (lslash) { - int baselen= (int) (lslash-base) + 1; + int baselen = (int) (lslash - base) + 1; /* use path for temp storage here, we copy back over it right away */ - BLI_strncpy(path, tmp+2, FILE_MAX); + BLI_strncpy(path, tmp + 2, FILE_MAX); memcpy(tmp, base, baselen); - BLI_strncpy(tmp+baselen, path, sizeof(tmp)-baselen); + BLI_strncpy(tmp + baselen, path, sizeof(tmp) - baselen); BLI_strncpy(path, tmp, FILE_MAX); } else { - BLI_strncpy(path, tmp+2, FILE_MAX); + BLI_strncpy(path, tmp + 2, FILE_MAX); } } else { @@ -731,7 +731,7 @@ int BLI_path_abs(char *path, const char *basepath) * // will be retained, rest will be nice and * shiny win32 backward slashes :) -jesterKing */ - BLI_char_switch(path+2, '/', '\\'); + BLI_char_switch(path + 2, '/', '\\'); #endif return wasrelative; @@ -755,8 +755,8 @@ int BLI_path_cwd(char *path) wasrelative = 0; #endif - if (wasrelative==1) { - char cwd[FILE_MAX]= ""; + if (wasrelative == 1) { + char cwd[FILE_MAX] = ""; BLI_current_working_dir(cwd, sizeof(cwd)); /* in case the full path to the blend isn't used */ if (cwd[0] == '\0') { @@ -784,19 +784,19 @@ int BLI_path_cwd(char *path) /* 'di's filename component is moved into 'fi', di is made a dir path */ void BLI_splitdirstring(char *di, char *fi) { - char *lslash= BLI_last_slash(di); + char *lslash = BLI_last_slash(di); if (lslash) { - BLI_strncpy(fi, lslash+1, FILE_MAXFILE); - *(lslash+1)=0; + BLI_strncpy(fi, lslash + 1, FILE_MAXFILE); + *(lslash + 1) = 0; } else { BLI_strncpy(fi, di, FILE_MAXFILE); - di[0]= 0; + di[0] = 0; } } -void BLI_getlastdir(const char* dir, char *last, const size_t maxlen) +void BLI_getlastdir(const char *dir, char *last, const size_t maxlen) { const char *s = dir; const char *lslash = NULL; @@ -809,7 +809,7 @@ void BLI_getlastdir(const char* dir, char *last, const size_t maxlen) s++; } if (prevslash) { - BLI_strncpy(last, prevslash+1, maxlen); + BLI_strncpy(last, prevslash + 1, maxlen); } else { BLI_strncpy(last, dir, maxlen); @@ -824,35 +824,35 @@ const char *BLI_getDefaultDocumentFolder(void) #ifndef WIN32 #ifdef WITH_XDG_USER_DIRS - const char *xdg_documents_dir= getenv("XDG_DOCUMENTS_DIR"); - if (xdg_documents_dir) { - return xdg_documents_dir; - } + const char *xdg_documents_dir = getenv("XDG_DOCUMENTS_DIR"); + if (xdg_documents_dir) { + return xdg_documents_dir; + } #endif - return getenv("HOME"); + return getenv("HOME"); #else /* Windows */ - static char documentfolder[MAXPATHLEN]; - HRESULT hResult; + static char documentfolder[MAXPATHLEN]; + HRESULT hResult; - /* Check for %HOME% env var */ - if (uput_getenv("HOME", documentfolder, MAXPATHLEN)) { - if (BLI_is_dir(documentfolder)) return documentfolder; - } + /* Check for %HOME% env var */ + if (uput_getenv("HOME", documentfolder, MAXPATHLEN)) { + if (BLI_is_dir(documentfolder)) return documentfolder; + } - /* add user profile support for WIN 2K / NT. - * This is %APPDATA%, which translates to either - * %USERPROFILE%\Application Data or since Vista - * to %USERPROFILE%\AppData\Roaming - */ - hResult = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, documentfolder); + /* add user profile support for WIN 2K / NT. + * This is %APPDATA%, which translates to either + * %USERPROFILE%\Application Data or since Vista + * to %USERPROFILE%\AppData\Roaming + */ + hResult = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, documentfolder); - if (hResult == S_OK) { - if (BLI_is_dir(documentfolder)) return documentfolder; - } + if (hResult == S_OK) { + if (BLI_is_dir(documentfolder)) return documentfolder; + } - return NULL; + return NULL; #endif /* WIN32 */ } @@ -865,7 +865,7 @@ const char *BLI_getDefaultDocumentFolder(void) static char *blender_version_decimal(const int ver) { static char version_str[5]; - sprintf(version_str, "%d.%02d", ver/100, ver%100); + sprintf(version_str, "%d.%02d", ver / 100, ver % 100); return version_str; } @@ -873,8 +873,8 @@ static int test_path(char *targetpath, const char *path_base, const char *path_s { char tmppath[FILE_MAX]; - if (path_sep) BLI_join_dirfile(tmppath, sizeof(tmppath), path_base, path_sep); - else BLI_strncpy(tmppath, path_base, sizeof(tmppath)); + if (path_sep) BLI_join_dirfile(tmppath, sizeof(tmppath), path_base, path_sep); + else BLI_strncpy(tmppath, path_base, sizeof(tmppath)); /* rare cases folder_name is omitted (when looking for ~/.blender/2.xx dir only) */ if (folder_name) @@ -899,7 +899,7 @@ static int test_path(char *targetpath, const char *path_base, const char *path_s static int test_env_path(char *path, const char *envvar) { - const char *env = envvar?getenv(envvar):NULL; + const char *env = envvar ? getenv(envvar) : NULL; if (!env) return 0; if (BLI_is_dir(env)) { @@ -929,7 +929,7 @@ static int get_path_local(char *targetpath, const char *folder_name, const char } } else { - relfolder[0]= '\0'; + relfolder[0] = '\0'; } /* try EXECUTABLE_DIR/2.5x/folder_name - new default directory for local blender installed files */ @@ -942,7 +942,7 @@ static int get_path_local(char *targetpath, const char *folder_name, const char static int is_portable_install(void) { /* detect portable install by the existance of config folder */ - const int ver= BLENDER_VERSION; + const int ver = BLENDER_VERSION; char path[FILE_MAX]; return get_path_local(path, "config", NULL, ver); @@ -1011,7 +1011,7 @@ static int get_path_system(char *targetpath, const char *folder_name, const char } } else { - relfolder[0]= '\0'; + relfolder[0] = '\0'; } /* try CWD/release/folder_name */ @@ -1066,27 +1066,27 @@ static int get_path_system(char *targetpath, const char *folder_name, const char /* returns the path if found, NULL string if not */ char *BLI_get_folder(int folder_id, const char *subfolder) { - const int ver= BLENDER_VERSION; + const int ver = BLENDER_VERSION; static char path[FILE_MAX] = ""; switch (folder_id) { - case BLENDER_DATAFILES: /* general case */ - if (get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES", ver)) break; + case BLENDER_DATAFILES: /* general case */ + if (get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES", ver)) break; if (get_path_local(path, "datafiles", subfolder, ver)) break; if (get_path_system(path, "datafiles", subfolder, "BLENDER_SYSTEM_DATAFILES", ver)) break; return NULL; case BLENDER_USER_DATAFILES: - if (get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES", ver)) break; + if (get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES", ver)) break; return NULL; case BLENDER_SYSTEM_DATAFILES: if (get_path_local(path, "datafiles", subfolder, ver)) break; - if (get_path_system(path, "datafiles", subfolder, "BLENDER_SYSTEM_DATAFILES", ver)) break; + if (get_path_system(path, "datafiles", subfolder, "BLENDER_SYSTEM_DATAFILES", ver)) break; return NULL; case BLENDER_USER_AUTOSAVE: - if (get_path_user(path, "autosave", subfolder, "BLENDER_USER_DATAFILES", ver)) break; + if (get_path_user(path, "autosave", subfolder, "BLENDER_USER_DATAFILES", ver)) break; return NULL; case BLENDER_USER_CONFIG: @@ -1113,7 +1113,7 @@ char *BLI_get_folder(int folder_id, const char *subfolder) char *BLI_get_user_folder_notest(int folder_id, const char *subfolder) { - const int ver= BLENDER_VERSION; + const int ver = BLENDER_VERSION; static char path[FILE_MAX] = ""; switch (folder_id) { @@ -1159,19 +1159,19 @@ char *BLI_get_folder_version(const int id, const int ver, const int do_check) static char path[FILE_MAX] = ""; int ok; switch (id) { - case BLENDER_RESOURCE_PATH_USER: - ok= get_path_user(path, NULL, NULL, NULL, ver); - break; - case BLENDER_RESOURCE_PATH_LOCAL: - ok= get_path_local(path, NULL, NULL, ver); - break; - case BLENDER_RESOURCE_PATH_SYSTEM: - ok= get_path_system(path, NULL, NULL, NULL, ver); - break; - default: - path[0]= '\0'; /* in case do_check is false */ - ok= FALSE; - BLI_assert(!"incorrect ID"); + case BLENDER_RESOURCE_PATH_USER: + ok = get_path_user(path, NULL, NULL, NULL, ver); + break; + case BLENDER_RESOURCE_PATH_LOCAL: + ok = get_path_local(path, NULL, NULL, ver); + break; + case BLENDER_RESOURCE_PATH_SYSTEM: + ok = get_path_system(path, NULL, NULL, NULL, ver); + break; + default: + path[0] = '\0'; /* in case do_check is false */ + ok = FALSE; + BLI_assert(!"incorrect ID"); } if ((ok == FALSE) && do_check) { @@ -1191,11 +1191,11 @@ char *BLI_get_folder_version(const int id, const int ver, const int do_check) #undef PATH_DEBUG #endif -void BLI_setenv(const char *env, const char*val) +void BLI_setenv(const char *env, const char *val) { /* free windows */ #if (defined(WIN32) || defined(WIN64)) && defined(FREE_WINDOWS) - char *envstr= MEM_mallocN(sizeof(char) * (strlen(env) + strlen(val) + 2), "envstr"); /* one for = another for \0 */ + char *envstr = MEM_mallocN(sizeof(char) * (strlen(env) + strlen(val) + 2), "envstr"); /* one for = another for \0 */ sprintf(envstr, "%s=%s", env, val); putenv(envstr); @@ -1217,7 +1217,7 @@ void BLI_setenv(const char *env, const char*val) * Only set an env var if already not there. * Like Unix setenv(env, val, 0); */ -void BLI_setenv_if_new(const char *env, const char* val) +void BLI_setenv_if_new(const char *env, const char *val) { if (getenv(env) == NULL) BLI_setenv(env, val); @@ -1226,11 +1226,11 @@ void BLI_setenv_if_new(const char *env, const char* val) void BLI_clean(char *path) { - if (path==NULL) return; + if (path == NULL) return; #ifdef WIN32 if (path && BLI_strnlen(path, 3) > 2) { - BLI_char_switch(path+2, '/', '\\'); + BLI_char_switch(path + 2, '/', '\\'); } #else BLI_char_switch(path, '\\', '/'); @@ -1239,7 +1239,7 @@ void BLI_clean(char *path) void BLI_char_switch(char *string, char from, char to) { - if (string==NULL) return; + if (string == NULL) return; while (*string != 0) { if (*string == from) *string = to; string++; @@ -1255,13 +1255,13 @@ void BLI_make_exist(char *dir) a = strlen(dir); while (BLI_is_dir(dir) == 0) { - a --; + a--; while (dir[a] != SEP) { a--; if (a <= 0) break; } if (a >= 0) { - dir[a+1] = '\0'; + dir[a + 1] = '\0'; } else { #ifdef WIN32 @@ -1294,7 +1294,7 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir, if (string) { /* ensure this is always set even if dir/file are NULL */ - string[0]= '\0'; + string[0] = '\0'; if (ELEM(NULL, dir, file)) { return; /* We don't want any NULLs */ @@ -1321,20 +1321,20 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir, /* Get the file name, chop everything past the last slash (ie. the filename) */ strcpy(string, relabase); - lslash= BLI_last_slash(string); - if (lslash) *(lslash+1)= 0; + lslash = BLI_last_slash(string); + if (lslash) *(lslash + 1) = 0; - dir+=2; /* Skip over the relative reference */ + dir += 2; /* Skip over the relative reference */ } #ifdef WIN32 else { - if (BLI_strnlen(dir, 3) >= 2 && dir[1] == ':' ) { + if (BLI_strnlen(dir, 3) >= 2 && dir[1] == ':') { BLI_strncpy(string, dir, 3); dir += 2; } else { /* no drive specified */ - /* first option: get the drive from the relabase if it has one */ - if (relabase && strlen(relabase) >= 2 && relabase[1] == ':' ) { + /* first option: get the drive from the relabase if it has one */ + if (relabase && strlen(relabase) >= 2 && relabase[1] == ':') { BLI_strncpy(string, relabase, 3); string[2] = '\\'; string[3] = '\0'; @@ -1354,8 +1354,8 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir, /* Make sure string ends in one (and only one) slash */ /* first trim all slashes from the end of the string */ sl = strlen(string); - while (sl>0 && ( string[sl-1] == '/' || string[sl-1] == '\\') ) { - string[sl-1] = '\0'; + while (sl > 0 && (string[sl - 1] == '/' || string[sl - 1] == '\\') ) { + string[sl - 1] = '\0'; sl--; } /* since we've now removed all slashes, put back one slash at the end. */ @@ -1364,7 +1364,7 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir, while (*file && (*file == '/' || *file == '\\')) /* Trim slashes from the front of file */ file++; - strcat (string, file); + strcat(string, file); /* Push all slashes to the system preferred direction */ BLI_clean(string); @@ -1375,10 +1375,10 @@ int BLI_testextensie(const char *str, const char *ext) short a, b; int retval; - a= strlen(str); - b= strlen(ext); + a = strlen(str); + b = strlen(ext); - if (a==0 || b==0 || b>=a) { + if (a == 0 || b == 0 || b >= a) { retval = 0; } else if (BLI_strcasecmp(ext, str + a - b)) { @@ -1393,7 +1393,7 @@ int BLI_testextensie(const char *str, const char *ext) int BLI_testextensie_array(const char *str, const char **ext_array) { - int i=0; + int i = 0; while (ext_array[i]) { if (BLI_testextensie(str, ext_array[i])) { return 1; @@ -1408,23 +1408,23 @@ int BLI_testextensie_array(const char *str, const char **ext_array) * '*.zip;*.py;*.exe' */ int BLI_testextensie_glob(const char *str, const char *ext_fnmatch) { - const char *ext_step= ext_fnmatch; + const char *ext_step = ext_fnmatch; char pattern[16]; while (ext_step[0]) { char *ext_next; int len_ext; - if ((ext_next=strchr(ext_step, ';'))) { - len_ext= (int)(ext_next - ext_step) + 1; + if ((ext_next = strchr(ext_step, ';'))) { + len_ext = (int)(ext_next - ext_step) + 1; } else { - len_ext= sizeof(pattern); + len_ext = sizeof(pattern); } BLI_strncpy(pattern, ext_step, len_ext); - if (fnmatch(pattern, str, FNM_CASEFOLD)==0) { + if (fnmatch(pattern, str, FNM_CASEFOLD) == 0) { return 1; } ext_step += len_ext; @@ -1436,32 +1436,32 @@ int BLI_testextensie_glob(const char *str, const char *ext_fnmatch) int BLI_replace_extension(char *path, size_t maxlen, const char *ext) { - size_t path_len= strlen(path); - size_t ext_len= strlen(ext); + size_t path_len = strlen(path); + size_t ext_len = strlen(ext); ssize_t a; - for (a= path_len - 1; a >= 0; a--) { + for (a = path_len - 1; a >= 0; a--) { if (ELEM3(path[a], '.', '/', '\\')) { break; } } if ((a < 0) || (path[a] != '.')) { - a= path_len; + a = path_len; } if (a + ext_len >= maxlen) return 0; - memcpy(path+a, ext, ext_len + 1); + memcpy(path + a, ext, ext_len + 1); return 1; } /* strip's trailing '.'s and adds the extension only when needed */ int BLI_ensure_extension(char *path, size_t maxlen, const char *ext) { - size_t path_len= strlen(path); - size_t ext_len= strlen(ext); + size_t path_len = strlen(path); + size_t ext_len = strlen(ext); ssize_t a; /* first check the extension is alread there */ @@ -1471,9 +1471,9 @@ int BLI_ensure_extension(char *path, size_t maxlen, const char *ext) return 1; } - for (a= path_len - 1; a >= 0; a--) { + for (a = path_len - 1; a >= 0; a--) { if (path[a] == '.') { - path[a]= '\0'; + path[a] = '\0'; } else { break; @@ -1484,7 +1484,7 @@ int BLI_ensure_extension(char *path, size_t maxlen, const char *ext) if (a + ext_len >= maxlen) return 0; - memcpy(path+a, ext, ext_len + 1); + memcpy(path + a, ext, ext_len + 1); return 1; } @@ -1497,7 +1497,7 @@ int BLI_ensure_extension(char *path, size_t maxlen, const char *ext) void BLI_split_dirfile(const char *string, char *dir, char *file, const size_t dirlen, const size_t filelen) { char *lslash_str = BLI_last_slash(string); - size_t lslash= lslash_str ? (size_t)(lslash_str - string) + 1 : 0; + size_t lslash = lslash_str ? (size_t)(lslash_str - string) + 1 : 0; if (dir) { if (lslash) { @@ -1509,7 +1509,7 @@ void BLI_split_dirfile(const char *string, char *dir, char *file, const size_t d } if (file) { - BLI_strncpy(file, string+lslash, filelen); + BLI_strncpy(file, string + lslash, filelen); } } @@ -1526,12 +1526,12 @@ void BLI_split_file_part(const char *string, char *file, const size_t filelen) /* simple appending of filename to dir, does not check for valid path! */ void BLI_join_dirfile(char *dst, const size_t maxlen, const char *dir, const char *file) { - size_t dirlen= BLI_strnlen(dir, maxlen); + size_t dirlen = BLI_strnlen(dir, maxlen); if (dst != dir) { if (dirlen == maxlen) { memcpy(dst, dir, dirlen); - dst[dirlen - 1]= '\0'; + dst[dirlen - 1] = '\0'; return; /* dir fills the path */ } else { @@ -1546,7 +1546,7 @@ void BLI_join_dirfile(char *dst, const size_t maxlen, const char *dir, const cha /* inline BLI_add_slash */ if ((dirlen > 0) && (dst[dirlen - 1] != SEP)) { dst[dirlen++] = SEP; - dst[dirlen ] = '\0'; + dst[dirlen] = '\0'; } if (dirlen >= maxlen) { @@ -1563,7 +1563,7 @@ void BLI_join_dirfile(char *dst, const size_t maxlen, const char *dir, const cha /* like pythons os.path.basename( ) */ char *BLI_path_basename(char *path) { - char *filename= BLI_last_slash(path); + char *filename = BLI_last_slash(path); return filename ? filename + 1 : path; } @@ -1598,20 +1598,20 @@ int BKE_rebase_path(char *abs, size_t abs_len, char *rel, size_t rel_len, const char path[FILE_MAX]; char dir[FILE_MAX]; char base[FILE_MAX]; - char blend_dir[FILE_MAX]; /* directory, where current .blend file resides */ + char blend_dir[FILE_MAX]; /* directory, where current .blend file resides */ char dest_path[FILE_MAX]; char rel_dir[FILE_MAX]; int len; if (abs) - abs[0]= 0; + abs[0] = 0; if (rel) - rel[0]= 0; + rel[0] = 0; BLI_split_dir_part(base_dir, blend_dir, sizeof(blend_dir)); - if (src_dir[0]=='\0') + if (src_dir[0] == '\0') return 0; BLI_strncpy(path, src_dir, sizeof(path)); @@ -1622,7 +1622,7 @@ int BKE_rebase_path(char *abs, size_t abs_len, char *rel, size_t rel_len, const /* get the directory part */ BLI_split_dirfile(path, dir, base, sizeof(dir), sizeof(base)); - len= strlen(blend_dir); + len = strlen(blend_dir); rel_dir[0] = 0; @@ -1669,8 +1669,8 @@ char *BLI_first_slash(char *string) { char *ffslash, *fbslash; - ffslash= strchr(string, '/'); - fbslash= strchr(string, '\\'); + ffslash = strchr(string, '/'); + fbslash = strchr(string, '\\'); if (!ffslash) return fbslash; else if (!fbslash) return ffslash; @@ -1683,8 +1683,8 @@ char *BLI_last_slash(const char *string) { char *lfslash, *lbslash; - lfslash= strrchr(string, '/'); - lbslash= strrchr(string, '\\'); + lfslash = strrchr(string, '/'); + lbslash = strrchr(string, '\\'); if (!lfslash) return lbslash; else if (!lbslash) return lfslash; @@ -1697,10 +1697,10 @@ char *BLI_last_slash(const char *string) int BLI_add_slash(char *string) { int len = strlen(string); - if (len==0 || string[len-1] != SEP) { + if (len == 0 || string[len - 1] != SEP) { string[len] = SEP; - string[len+1] = '\0'; - return len+1; + string[len + 1] = '\0'; + return len + 1; } return len; } @@ -1710,8 +1710,8 @@ void BLI_del_slash(char *string) { int len = strlen(string); while (len) { - if (string[len-1] == SEP) { - string[len-1] = '\0'; + if (string[len - 1] == SEP) { + string[len - 1] = '\0'; len--; } else { @@ -1747,7 +1747,7 @@ static int add_win32_extension(char *name) } type = BLI_exists(filename); - if (type && (! S_ISDIR(type))) { + if (type && (!S_ISDIR(type))) { retval = 1; strcpy(name, filename); break; @@ -1798,7 +1798,7 @@ static void bli_where_am_i(char *fullname, const size_t maxlen, const char *name #endif #ifdef _WIN32 - wchar_t * fullname_16 = MEM_mallocN(maxlen*sizeof(wchar_t), "ProgramPath"); + wchar_t *fullname_16 = MEM_mallocN(maxlen * sizeof(wchar_t), "ProgramPath"); if (GetModuleFileNameW(0, fullname_16, maxlen)) { conv_utf_16_to_8(fullname_16, fullname, maxlen); if (!BLI_exists(fullname)) { @@ -1817,12 +1817,12 @@ static void bli_where_am_i(char *fullname, const size_t maxlen, const char *name BLI_strncpy(fullname, name, maxlen); if (name[0] == '.') { - char wdir[FILE_MAX]= ""; - BLI_current_working_dir(wdir, sizeof(wdir)); /* backup cwd to restore after */ + char wdir[FILE_MAX] = ""; + BLI_current_working_dir(wdir, sizeof(wdir)); /* backup cwd to restore after */ // not needed but avoids annoying /./ in name - if (name[1]==SEP) - BLI_join_dirfile(fullname, maxlen, wdir, name+2); + if (name[1] == SEP) + BLI_join_dirfile(fullname, maxlen, wdir, name + 2); else BLI_join_dirfile(fullname, maxlen, wdir, name); @@ -1955,22 +1955,22 @@ void BLI_system_temporary_dir(char *dir) void BLI_string_to_utf8(char *original, char *utf_8, const char *code) { - size_t inbytesleft=strlen(original); - size_t outbytesleft=512; - size_t rv=0; + size_t inbytesleft = strlen(original); + size_t outbytesleft = 512; + size_t rv = 0; iconv_t cd; if (NULL == code) { code = locale_charset(); } - cd=iconv_open("UTF-8", code); + cd = iconv_open("UTF-8", code); if (cd == (iconv_t)(-1)) { printf("iconv_open Error"); - *utf_8='\0'; + *utf_8 = '\0'; return; } - rv=iconv(cd, &original, &inbytesleft, &utf_8, &outbytesleft); + rv = iconv(cd, &original, &inbytesleft, &utf_8, &outbytesleft); if (rv == (size_t) -1) { printf("iconv Error\n"); return; @@ -1979,5 +1979,3 @@ void BLI_string_to_utf8(char *original, char *utf_8, const char *code) iconv_close(cd); } #endif // WITH_ICONV - - diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c index 81a940e4613..b36c3c717c0 100644 --- a/source/blender/blenlib/intern/rct.c +++ b/source/blender/blenlib/intern/rct.c @@ -38,17 +38,17 @@ #include "DNA_vec_types.h" #include "BLI_rect.h" -int BLI_rcti_is_empty(rcti * rect) +int BLI_rcti_is_empty(rcti *rect) { return ((rect->xmax <= rect->xmin) || (rect->ymax <= rect->ymin)); } -int BLI_rctf_is_empty(rctf * rect) +int BLI_rctf_is_empty(rctf *rect) { return ((rect->xmax <= rect->xmin) || (rect->ymax <= rect->ymin)); } -int BLI_in_rcti(rcti * rect, int x, int y) +int BLI_in_rcti(rcti *rect, int x, int y) { if (x < rect->xmin) return 0; if (x > rect->xmax) return 0; diff --git a/source/blender/blenlib/intern/scanfill.c b/source/blender/blenlib/intern/scanfill.c index 503de31616a..71eb0ec2df7 100644 --- a/source/blender/blenlib/intern/scanfill.c +++ b/source/blender/blenlib/intern/scanfill.c @@ -193,7 +193,7 @@ static void mem_element_reset(ScanFillContext *sf_ctx, int keep_first) void BLI_scanfill_end(ScanFillContext *sf_ctx) { - mem_element_reset(sf_ctx, FALSE); + mem_element_reset(sf_ctx, FALSE); sf_ctx->fillvertbase.first = sf_ctx->fillvertbase.last = NULL; sf_ctx->filledgebase.first = sf_ctx->filledgebase.last = NULL; diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index d880b895ced..53531871aa6 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -43,9 +43,9 @@ char *BLI_strdupn(const char *str, const size_t len) { - char *n= MEM_mallocN(len+1, "strdup"); + char *n = MEM_mallocN(len + 1, "strdup"); memcpy(n, str, len); - n[len]= '\0'; + n[len] = '\0'; return n; } @@ -59,8 +59,8 @@ char *BLI_strdupcat(const char *str1, const char *str2) size_t len; char *n; - len= strlen(str1)+strlen(str2); - n= MEM_mallocN(len+1, "strdupcat"); + len = strlen(str1) + strlen(str2); + n = MEM_mallocN(len + 1, "strdupcat"); strcpy(n, str1); strcat(n, str2); @@ -69,11 +69,11 @@ char *BLI_strdupcat(const char *str1, const char *str2) char *BLI_strncpy(char *dst, const char *src, const size_t maxncpy) { - size_t srclen= strlen(src); - size_t cpylen= (srclen>(maxncpy-1))?(maxncpy-1):srclen; + size_t srclen = strlen(src); + size_t cpylen = (srclen > (maxncpy - 1)) ? (maxncpy - 1) : srclen; memcpy(dst, src, cpylen); - dst[cpylen]= '\0'; + dst[cpylen] = '\0'; return dst; } @@ -90,7 +90,7 @@ size_t BLI_snprintf(char *buffer, size_t count, const char *format, ...) buffer[n] = '\0'; } else { - buffer[count-1] = '\0'; + buffer[count - 1] = '\0'; } va_end(arg); @@ -105,9 +105,9 @@ char *BLI_sprintfN(const char *format, ...) va_start(arg, format); - ds= BLI_dynstr_new(); + ds = BLI_dynstr_new(); BLI_dynstr_vappendf(ds, format, arg); - n= BLI_dynstr_get_cstring(ds); + n = BLI_dynstr_get_cstring(ds); BLI_dynstr_free(ds); va_end(arg); @@ -123,7 +123,7 @@ char *BLI_sprintfN(const char *format, ...) * which is a useful reference. */ size_t BLI_strescape(char *dst, const char *src, const size_t maxlen) { - size_t len= 0; + size_t len = 0; while (len < maxlen) { switch (*src) { case '\0': @@ -131,7 +131,7 @@ size_t BLI_strescape(char *dst, const char *src, const size_t maxlen) case '\\': case '"': - /* less common but should also be support */ + /* less common but should also be support */ case '\t': case '\n': case '\r': @@ -143,7 +143,7 @@ size_t BLI_strescape(char *dst, const char *src, const size_t maxlen) /* not enough space to escape */ break; } - /* intentionally pass through */ + /* intentionally pass through */ default: *dst = *src; } @@ -154,7 +154,7 @@ size_t BLI_strescape(char *dst, const char *src, const size_t maxlen) escape_finish: - *dst= '\0'; + *dst = '\0'; return len; } @@ -163,25 +163,25 @@ escape_finish: /* Makes a copy of the text within the "" that appear after some text 'blahblah' * i.e. for string 'pose["apples"]' with prefix 'pose[', it should grab "apples" * - * - str: is the entire string to chop + * - str: is the entire string to chop * - prefix: is the part of the string to leave out * * Assume that the strings returned must be freed afterwards, and that the inputs will contain * data we want... */ -char *BLI_getQuotedStr (const char *str, const char *prefix) +char *BLI_getQuotedStr(const char *str, const char *prefix) { size_t prefixLen = strlen(prefix); char *startMatch, *endMatch; /* get the starting point (i.e. where prefix starts, and add prefixLen+1 to it to get be after the first " */ - startMatch= strstr(str, prefix) + prefixLen + 1; + startMatch = strstr(str, prefix) + prefixLen + 1; /* get the end point (i.e. where the next occurance of " is after the starting point) */ - endMatch= strchr(startMatch, '"'); // " NOTE: this comment here is just so that my text editor still shows the functions ok... + endMatch = strchr(startMatch, '"'); // " NOTE: this comment here is just so that my text editor still shows the functions ok... /* return the slice indicated */ - return BLI_strdupn(startMatch, (size_t)(endMatch-startMatch)); + return BLI_strdupn(startMatch, (size_t)(endMatch - startMatch)); } /* Replaces all occurrences of oldText with newText in str, returning a new string that doesn't @@ -191,14 +191,14 @@ char *BLI_getQuotedStr (const char *str, const char *prefix) // Feel free to replace this with an even safe + nicer alternative char *BLI_replacestr(char *str, const char *oldText, const char *newText) { - DynStr *ds= NULL; - size_t lenOld= strlen(oldText); + DynStr *ds = NULL; + size_t lenOld = strlen(oldText); char *match; /* sanity checks */ - if ((str == NULL) || (str[0]==0)) + if ((str == NULL) || (str[0] == 0)) return NULL; - else if ((oldText == NULL) || (newText == NULL) || (oldText[0]==0)) + else if ((oldText == NULL) || (newText == NULL) || (oldText[0] == 0)) return BLI_strdup(str); /* while we can still find a match for the old substring that we're searching for, @@ -207,7 +207,7 @@ char *BLI_replacestr(char *str, const char *oldText, const char *newText) while ( (match = strstr(str, oldText)) ) { /* the assembly buffer only gets created when we actually need to rebuild the string */ if (ds == NULL) - ds= BLI_dynstr_new(); + ds = BLI_dynstr_new(); /* if the match position does not match the current position in the string, * copy the text up to this position and advance the current position in the string @@ -216,12 +216,12 @@ char *BLI_replacestr(char *str, const char *oldText, const char *newText) /* replace the token at the 'match' position with \0 so that the copied string will be ok, * add the segment of the string from str to match to the buffer, then restore the value at match */ - match[0]= 0; + match[0] = 0; BLI_dynstr_append(ds, str); - match[0]= oldText[0]; + match[0] = oldText[0]; /* now our current position should be set on the start of the match */ - str= match; + str = match; } /* add the replacement text to the accumulation buffer */ @@ -242,7 +242,7 @@ char *BLI_replacestr(char *str, const char *oldText, const char *newText) BLI_dynstr_append(ds, str); /* convert to new c-string (MEM_malloc'd), and free the buffer */ - newStr= BLI_dynstr_get_cstring(ds); + newStr = BLI_dynstr_get_cstring(ds); BLI_dynstr_free(ds); return newStr; @@ -257,7 +257,7 @@ char *BLI_replacestr(char *str, const char *oldText, const char *newText) int BLI_strcaseeq(const char *a, const char *b) { - return (BLI_strcasecmp(a, b)==0); + return (BLI_strcasecmp(a, b) == 0); } /* strcasestr not available in MSVC */ @@ -267,13 +267,13 @@ char *BLI_strcasestr(const char *s, const char *find) register size_t len; if ((c = *find++) != 0) { - c= tolower(c); + c = tolower(c); len = strlen(find); do { do { if ((sc = *s++) == 0) return (NULL); - sc= tolower(sc); + sc = tolower(sc); } while (sc != c); } while (BLI_strncasecmp(s, find, len) != 0); s--; @@ -286,17 +286,17 @@ int BLI_strcasecmp(const char *s1, const char *s2) { int i; - for (i=0; ; i++) { + for (i = 0;; i++) { char c1 = tolower(s1[i]); char c2 = tolower(s2[i]); - if (c1c2) { + else if (c1 > c2) { return 1; } - else if (c1==0) { + else if (c1 == 0) { break; } } @@ -308,17 +308,17 @@ int BLI_strncasecmp(const char *s1, const char *s2, size_t len) { int i; - for (i=0; ic2) { + else if (c1 > c2) { return 1; } - else if (c1==0) { + else if (c1 == 0) { break; } } @@ -329,7 +329,7 @@ int BLI_strncasecmp(const char *s1, const char *s2, size_t len) /* natural string compare, keeping numbers in order */ int BLI_natstrcmp(const char *s1, const char *s2) { - int d1= 0, d2= 0; + int d1 = 0, d2 = 0; /* if both chars are numeric, to a strtol(). * then increase string deltas as long they are @@ -339,23 +339,23 @@ int BLI_natstrcmp(const char *s1, const char *s2) char c1 = tolower(s1[d1]); char c2 = tolower(s2[d2]); - if ( isdigit(c1) && isdigit(c2) ) { + if (isdigit(c1) && isdigit(c2) ) { int val1, val2; - val1= (int)strtol(s1+d1, (char **)NULL, 10); - val2= (int)strtol(s2+d2, (char **)NULL, 10); + val1 = (int)strtol(s1 + d1, (char **)NULL, 10); + val2 = (int)strtol(s2 + d2, (char **)NULL, 10); - if (val1val2) { + else if (val1 > val2) { return 1; } d1++; - while ( isdigit(s1[d1]) ) + while (isdigit(s1[d1]) ) d1++; d2++; - while ( isdigit(s2[d2]) ) + while (isdigit(s2[d2]) ) d2++; c1 = tolower(s1[d1]); @@ -363,17 +363,17 @@ int BLI_natstrcmp(const char *s1, const char *s2) } /* first check for '.' so "foo.bar" comes before "foo 1.bar" */ - if (c1=='.' && c2!='.') + if (c1 == '.' && c2 != '.') return -1; - if (c1!='.' && c2=='.') + if (c1 != '.' && c2 == '.') return 1; - else if (c1c2) { + else if (c1 > c2) { return 1; } - else if (c1==0) { + else if (c1 == 0) { break; } d1++; @@ -385,10 +385,10 @@ int BLI_natstrcmp(const char *s1, const char *s2) 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; + 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); @@ -397,7 +397,7 @@ void BLI_timestr(double _time, char *str) sprintf(str, "%.2d:%.2d.%.2d", min, sec, hun); } - str[11]=0; + str[11] = 0; } /* determine the length of a fixed-size string */ @@ -411,7 +411,7 @@ void BLI_ascii_strtolower(char *str, int len) { int i; - for (i=0; i= 'A' && str[i] <= 'Z') str[i] += 'a' - 'A'; } @@ -420,7 +420,7 @@ void BLI_ascii_strtoupper(char *str, int len) { int i; - for (i=0; i= 'a' && str[i] <= 'z') str[i] -= 'a' - 'A'; } diff --git a/source/blender/blenlib/intern/time.c b/source/blender/blenlib/intern/time.c index 2f53aa38e77..64f007513ed 100644 --- a/source/blender/blenlib/intern/time.c +++ b/source/blender/blenlib/intern/time.c @@ -37,35 +37,35 @@ double PIL_check_seconds_timer(void) { - static int hasperfcounter= -1; /* -1==unknown */ + static int hasperfcounter = -1; /* -1==unknown */ static double perffreq; - if (hasperfcounter==-1) { + if (hasperfcounter == -1) { __int64 ifreq; - hasperfcounter= QueryPerformanceFrequency((LARGE_INTEGER*) &ifreq); - perffreq= (double) ifreq; + hasperfcounter = QueryPerformanceFrequency((LARGE_INTEGER *) &ifreq); + perffreq = (double) ifreq; } if (hasperfcounter) { __int64 count; - QueryPerformanceCounter((LARGE_INTEGER*) &count); + QueryPerformanceCounter((LARGE_INTEGER *) &count); - return count/perffreq; + return count / perffreq; } else { - static double accum= 0.0; - static int ltick= 0; - int ntick= GetTickCount(); + static double accum = 0.0; + static int ltick = 0; + int ntick = GetTickCount(); - if (ntick=1000) { - sleep(ms/1000); - ms= (ms%1000); + if (ms >= 1000) { + sleep(ms / 1000); + ms = (ms % 1000); } - usleep(ms*1000); + usleep(ms * 1000); } #endif diff --git a/source/blender/blenlib/intern/uvproject.c b/source/blender/blenlib/intern/uvproject.c index a630084e79d..18c69bd2ba8 100644 --- a/source/blender/blenlib/intern/uvproject.c +++ b/source/blender/blenlib/intern/uvproject.c @@ -72,7 +72,7 @@ void BLI_uvproject_from_camera(float target[2], float source[3], ProjCameraInfo } else { if (pv4[2] == 0.0f) - pv4[2] = 0.00001f; /* don't allow div by 0 */ + pv4[2] = 0.00001f; /* don't allow div by 0 */ if (uci->do_persp == 0) { target[0] = (pv4[0] / uci->camsize); diff --git a/source/blender/blenlib/intern/voxel.c b/source/blender/blenlib/intern/voxel.c index 3ad9edd14a3..10eb4e82912 100644 --- a/source/blender/blenlib/intern/voxel.c +++ b/source/blender/blenlib/intern/voxel.c @@ -40,7 +40,7 @@ BLI_INLINE float D(float *data, const int res[3], int x, int y, int z) CLAMP(x, 0, res[0] - 1); CLAMP(y, 0, res[1] - 1); CLAMP(z, 0, res[2] - 1); - return data[ BLI_VOXEL_INDEX(x, y, z, res) ]; + return data[BLI_VOXEL_INDEX(x, y, z, res)]; } /* *** nearest neighbor *** */ @@ -128,7 +128,7 @@ float BLI_voxel_sample_triquadratic(float *data, const int res[3], const float c + v[1] * ( u[0] * data[xc[0] + yc[1] + zc[2]] + u[1] * data[xc[1] + yc[1] + zc[2]] + u[2] * data[xc[2] + yc[1] + zc[2]] ) + v[2] * ( u[0] * data[xc[0] + yc[2] + zc[2]] + u[1] * data[xc[1] + yc[2] + zc[2]] + u[2] * data[xc[2] + yc[2] + zc[2]] ) ); -} + } return 0.f; } diff --git a/source/blender/blenlib/intern/winstuff.c b/source/blender/blenlib/intern/winstuff.c index d853e398adc..3eb62228aad 100644 --- a/source/blender/blenlib/intern/winstuff.c +++ b/source/blender/blenlib/intern/winstuff.c @@ -44,16 +44,16 @@ #include "BKE_utildefines.h" #include "BKE_global.h" -#define WIN32_SKIP_HKEY_PROTECTION // need to use HKEY +#define WIN32_SKIP_HKEY_PROTECTION // need to use HKEY #include "BLI_winstuff.h" #include "BLI_utildefines.h" #include "utf_winfunc.h" #include "utfconv.h" - /* FILE_MAXDIR + FILE_MAXFILE */ +/* FILE_MAXDIR + FILE_MAXFILE */ -int BLI_getInstallationDir(char * str) +int BLI_getInstallationDir(char *str) { char dir[FILE_MAXDIR]; int a; @@ -61,7 +61,7 @@ int BLI_getInstallationDir(char * str) GetModuleFileName(NULL, str, FILE_MAX); BLI_split_dir_part(str, dir, sizeof(dir)); /* shouldn't be relative */ a = strlen(dir); - if (dir[a-1] == '\\') dir[a-1]=0; + if (dir[a - 1] == '\\') dir[a - 1] = 0; strcpy(str, dir); @@ -74,7 +74,7 @@ void RegisterBlendExtension_Fail(HKEY root) if (root) RegCloseKey(root); if (!G.background) - MessageBox(0, "Could not register file extension.", "Blender error", MB_OK|MB_ICONERROR); + MessageBox(0, "Could not register file extension.", "Blender error", MB_OK | MB_ICONERROR); TerminateProcess(GetCurrentProcess(), 1); } @@ -91,7 +91,7 @@ void RegisterBlendExtension(void) char InstallDir[FILE_MAXDIR]; char SysDir[FILE_MAXDIR]; const char *ThumbHandlerDLL; - char RegCmd[MAX_PATH*2]; + char RegCmd[MAX_PATH * 2]; char MBox[256]; BOOL IsWOW64; @@ -109,40 +109,40 @@ void RegisterBlendExtension(void) } lresult = RegCreateKeyEx(root, "blendfile", 0, - NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); + NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); if (lresult == ERROR_SUCCESS) { strcpy(buffer, "Blender File"); - lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE*)buffer, strlen(buffer) + 1); + lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE *)buffer, strlen(buffer) + 1); RegCloseKey(hkey); } if (lresult != ERROR_SUCCESS) RegisterBlendExtension_Fail(root); lresult = RegCreateKeyEx(root, "blendfile\\shell\\open\\command", 0, - NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); + NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); if (lresult == ERROR_SUCCESS) { sprintf(buffer, "\"%s\" \"%%1\"", BlPath); - lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE*)buffer, strlen(buffer) + 1); + lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE *)buffer, strlen(buffer) + 1); RegCloseKey(hkey); } if (lresult != ERROR_SUCCESS) RegisterBlendExtension_Fail(root); lresult = RegCreateKeyEx(root, "blendfile\\DefaultIcon", 0, - NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); + NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); if (lresult == ERROR_SUCCESS) { sprintf(buffer, "\"%s\", 1", BlPath); - lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE*)buffer, strlen(buffer) + 1); + lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE *)buffer, strlen(buffer) + 1); RegCloseKey(hkey); } if (lresult != ERROR_SUCCESS) RegisterBlendExtension_Fail(root); lresult = RegCreateKeyEx(root, ".blend", 0, - NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); + NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); if (lresult == ERROR_SUCCESS) { sprintf(buffer, "%s", "blendfile"); - lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE*)buffer, strlen(buffer) + 1); + lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE *)buffer, strlen(buffer) + 1); RegCloseKey(hkey); } if (lresult != ERROR_SUCCESS) @@ -159,32 +159,32 @@ void RegisterBlendExtension(void) else ThumbHandlerDLL = "BlendThumb.dll"; #endif - snprintf(RegCmd, MAX_PATH*2, "%s\\regsvr32 /s \"%s\\%s\"", SysDir, InstallDir, ThumbHandlerDLL); + snprintf(RegCmd, MAX_PATH * 2, "%s\\regsvr32 /s \"%s\\%s\"", SysDir, InstallDir, ThumbHandlerDLL); system(RegCmd); RegCloseKey(root); printf("success (%s)\n", usr_mode ? "user" : "system"); if (!G.background) { sprintf(MBox, "File extension registered for %s.", usr_mode ? "the current user. To register for all users, run as an administrator" : "all users"); - MessageBox(0, MBox, "Blender", MB_OK|MB_ICONINFORMATION); + MessageBox(0, MBox, "Blender", MB_OK | MB_ICONINFORMATION); } TerminateProcess(GetCurrentProcess(), 0); } -DIR *opendir (const char *path) +DIR *opendir(const char *path) { wchar_t *path_16 = alloc_utf16_from_8(path, 0); if (GetFileAttributesW(path_16) & FILE_ATTRIBUTE_DIRECTORY) { - DIR *newd= MEM_mallocN(sizeof(DIR), "opendir"); + DIR *newd = MEM_mallocN(sizeof(DIR), "opendir"); newd->handle = INVALID_HANDLE_VALUE; sprintf(newd->path, "%s\\*", path); - newd->direntry.d_ino= 0; - newd->direntry.d_off= 0; - newd->direntry.d_reclen= 0; - newd->direntry.d_name= NULL; + newd->direntry.d_ino = 0; + newd->direntry.d_off = 0; + newd->direntry.d_reclen = 0; + newd->direntry.d_name = NULL; free(path_16); return newd; @@ -200,43 +200,42 @@ static char *BLI_alloc_utf_8_from_16(wchar_t *in16, size_t add) size_t bsize = count_utf_8_from_16(in16); char *out8 = NULL; if (!bsize) return NULL; - out8 = (char*)MEM_mallocN(sizeof(char) * (bsize + add), "UTF-8 String"); + out8 = (char *)MEM_mallocN(sizeof(char) * (bsize + add), "UTF-8 String"); conv_utf_16_to_8(in16, out8, bsize); return out8; } -static wchar_t *UNUSED_FUNCTION(BLI_alloc_utf16_from_8)(char *in8, size_t add) +static wchar_t *UNUSED_FUNCTION(BLI_alloc_utf16_from_8) (char *in8, size_t add) { size_t bsize = count_utf_16_from_8(in8); wchar_t *out16 = NULL; if (!bsize) return NULL; - out16 =(wchar_t*) MEM_mallocN(sizeof(wchar_t) * (bsize + add), "UTF-16 String"); + out16 = (wchar_t *) MEM_mallocN(sizeof(wchar_t) * (bsize + add), "UTF-16 String"); conv_utf_8_to_16(in8, out16, bsize); return out16; } -struct dirent *readdir(DIR *dp) -{ +struct dirent *readdir(DIR *dp){ if (dp->direntry.d_name) { MEM_freeN(dp->direntry.d_name); - dp->direntry.d_name= NULL; + dp->direntry.d_name = NULL; } - if (dp->handle==INVALID_HANDLE_VALUE) { - wchar_t *path_16 = alloc_utf16_from_8(dp->path, 0); - dp->handle= FindFirstFileW(path_16, &(dp->data)); + if (dp->handle == INVALID_HANDLE_VALUE) { + wchar_t *path_16 = alloc_utf16_from_8(dp->path, 0); + dp->handle = FindFirstFileW(path_16, &(dp->data)); free(path_16); - if (dp->handle==INVALID_HANDLE_VALUE) + if (dp->handle == INVALID_HANDLE_VALUE) return NULL; - dp->direntry.d_name= BLI_alloc_utf_8_from_16(dp->data.cFileName, 0); + dp->direntry.d_name = BLI_alloc_utf_8_from_16(dp->data.cFileName, 0); return &dp->direntry; } - else if (FindNextFileW (dp->handle, &(dp->data))) { - dp->direntry.d_name= BLI_alloc_utf_8_from_16(dp->data.cFileName, 0); + else if (FindNextFileW(dp->handle, &(dp->data))) { + dp->direntry.d_name = BLI_alloc_utf_8_from_16(dp->data.cFileName, 0); return &dp->direntry; } @@ -248,7 +247,7 @@ struct dirent *readdir(DIR *dp) int closedir(DIR *dp) { if (dp->direntry.d_name) MEM_freeN(dp->direntry.d_name); - if (dp->handle!=INVALID_HANDLE_VALUE) FindClose(dp->handle); + if (dp->handle != INVALID_HANDLE_VALUE) FindClose(dp->handle); MEM_freeN(dp); @@ -257,12 +256,12 @@ int closedir(DIR *dp) void get_default_root(char *root) { - char str[MAX_PATH+1]; + char str[MAX_PATH + 1]; /* the default drive to resolve a directory without a specified drive * should be the Windows installation drive, since this was what the OS * assumes. */ - if (GetWindowsDirectory(str, MAX_PATH+1)) { + if (GetWindowsDirectory(str, MAX_PATH + 1)) { root[0] = str[0]; root[1] = ':'; root[2] = '\\'; @@ -271,7 +270,7 @@ void get_default_root(char *root) else { /* if GetWindowsDirectory fails, something has probably gone wrong, * we are trying the blender install dir though */ - if (GetModuleFileName(NULL, str, MAX_PATH+1)) { + if (GetModuleFileName(NULL, str, MAX_PATH + 1)) { printf("Error! Could not get the Windows Directory - Defaulting to Blender installation Dir!"); root[0] = str[0]; root[1] = ':'; @@ -284,10 +283,10 @@ void get_default_root(char *root) int rc = 0; /* now something has gone really wrong - still trying our best guess */ printf("Error! Could not get the Windows Directory - Defaulting to first valid drive! Path might be invalid!"); - tmp= GetLogicalDrives(); - for (i=2; i < 26; i++) { - if ((tmp>>i) & 1) { - root[0] = 'a'+i; + tmp = GetLogicalDrives(); + for (i = 2; i < 26; i++) { + if ((tmp >> i) & 1) { + root[0] = 'a' + i; root[1] = ':'; root[2] = '\\'; root[3] = '\0'; @@ -338,20 +337,20 @@ int check_file_chars(char *filename) const char *dirname(char *path) { char *p; - if ( path == NULL || *path == '\0' ) + if (path == NULL || *path == '\0') return "."; p = path + strlen(path) - 1; - while ( *p == '/' ) { - if ( p == path ) + while (*p == '/') { + if (p == path) return path; *p-- = '\0'; } - while ( p >= path && *p != '/' ) + while (p >= path && *p != '/') p--; return - p < path ? "." : - p == path ? "/" : - (*p = '\0', path); + p < path ? "." : + p == path ? "/" : + (*p = '\0', path); } /* End of copied part */ -- cgit v1.2.3