[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12207] trunk/blender/source/blender: Some code cleanups:
Joshua Leung
aligorith at gmail.com
Thu Oct 4 12:50:16 CEST 2007
Revision: 12207
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12207
Author: aligorith
Date: 2007-10-04 12:50:15 +0200 (Thu, 04 Oct 2007)
Log Message:
-----------
Some code cleanups:
* editaction.c - merged the functions for channel properties (renaming, slider limits, protect/mute, etc.)
* blenlib
- added a new function BLI_findindex which finds the index position of a given item in a list. It will return -1 if it can't find the item
- tidied up code formatting so that (the bits I have checked) have a single formatting style instead of a few different ones
- added a few paranoia checks for NULL in one of the listbase-related functions
- removed some half-dutch variable names still lurking around
- culled a few compiler warnings... there are still two in util.c related to (const char *) and (char *) type things
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_blenlib.h
trunk/blender/source/blender/blenlib/intern/util.c
trunk/blender/source/blender/src/editaction.c
Modified: trunk/blender/source/blender/blenlib/BLI_blenlib.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_blenlib.h 2007-10-04 09:30:52 UTC (rev 12206)
+++ trunk/blender/source/blender/blenlib/BLI_blenlib.h 2007-10-04 10:50:15 UTC (rev 12207)
@@ -102,13 +102,14 @@
int BLI_testextensie(const char *str, const char *ext);
void addlisttolist(ListBase *list1, ListBase *list2);
void BLI_insertlink(struct ListBase *listbase, void *vprevlink, void *vnewlink);
-void * BLI_findlink(struct ListBase *listbase, int number);
+void *BLI_findlink(struct ListBase *listbase, int number);
+int BLI_findindex(struct ListBase *listbase, void *vlink);
void BLI_freelistN(struct ListBase *listbase);
void BLI_addtail(struct ListBase *listbase, void *vlink);
void BLI_remlink(struct ListBase *listbase, void *vlink);
void BLI_newname(char * name, int add);
-int BLI_stringdec(char *string, char *kop, char *staart, unsigned short *numlen);
-void BLI_stringenc(char *string, char *kop, char *staart, unsigned short numlen, int pic);
+int BLI_stringdec(char *string, char *kop, char *start, unsigned short *numlen);
+void BLI_stringenc(char *string, char *kop, char *start, unsigned short numlen, int pic);
void BLI_addhead(struct ListBase *listbase, void *vlink);
void BLI_insertlinkbefore(struct ListBase *listbase, void *vnextlink, void *vnewlink);
void BLI_freelist(struct ListBase *listbase);
@@ -173,7 +174,7 @@
* @param str The string to be duplicated
* @retval Returns the duplicated string
*/
-char* BLI_strdup(const char *str);
+char *BLI_strdup(const char *str);
/**
* Duplicates the first @a len bytes of cstring @a str
@@ -184,7 +185,7 @@
* @param len The number of bytes to duplicate
* @retval Returns the duplicated string
*/
-char* BLI_strdupn(const char *str, int len);
+char *BLI_strdupn(const char *str, int len);
/**
* Like strncpy but ensures dst is always
@@ -196,7 +197,7 @@
* the size of dst)
* @retval Returns dst
*/
-char* BLI_strncpy(char *dst, const char *src, int maxncpy);
+char *BLI_strncpy(char *dst, const char *src, int maxncpy);
/*
* Replacement for snprintf
@@ -262,15 +263,15 @@
#endif
#ifdef WIN32
-int BLI_getInstallationDir( char * str );
+int BLI_getInstallationDir(char *str);
#endif
/* BLI_storage.h */
int BLI_filesize(int file);
double BLI_diskfree(char *dir);
-char * BLI_getwdN(char * dir);
+char *BLI_getwdN(char *dir);
void BLI_hide_dot_files(int set);
-unsigned int BLI_getdir(char *dirname, struct direntry **filelist);
+unsigned int BLI_getdir(char *dirname, struct direntry **filelist);
/**
* @attention Do not confuse with BLI_exists
@@ -303,12 +304,12 @@
*
* @return True if @a rect is empty.
*/
-int BLI_rcti_is_empty(struct rcti * rect);
+int BLI_rcti_is_empty(struct rcti *rect);
void BLI_init_rctf(struct rctf *rect, float xmin, float xmax, float ymin, float ymax);
void BLI_init_rcti(struct rcti *rect, int xmin, int xmax, int ymin, int ymax);
void BLI_translate_rctf(struct rctf *rect, float x, float y);
void BLI_translate_rcti(struct rcti *rect, int x, int y);
-int BLI_in_rcti(struct rcti * rect, int x, int y);
+int BLI_in_rcti(struct rcti *rect, int x, int y);
int BLI_in_rctf(struct rctf *rect, float x, float y);
int BLI_isect_rctf(struct rctf *src1, struct rctf *src2, struct rctf *dest);
int BLI_isect_rcti(struct rcti *src1, struct rcti *src2, struct rcti *dest);
Modified: trunk/blender/source/blender/blenlib/intern/util.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/util.c 2007-10-04 09:30:52 UTC (rev 12206)
+++ trunk/blender/source/blender/blenlib/intern/util.c 2007-10-04 10:50:15 UTC (rev 12207)
@@ -90,31 +90,29 @@
/* implementation */
-/* Ripped this from blender.c
- */
+/* Ripped this from blender.c */
void addlisttolist(ListBase *list1, ListBase *list2)
{
+ if (list2->first==0) return;
- if(list2->first==0) return;
-
- if(list1->first==0) {
+ if (list1->first==0) {
list1->first= list2->first;
list1->last= list2->last;
}
else {
- ((struct Link *)list1->last)->next= list2->first;
- ((struct Link *)list2->first)->prev= list1->last;
+ ((Link *)list1->last)->next= list2->first;
+ ((Link *)list2->first)->prev= list1->last;
list1->last= list2->last;
}
list2->first= list2->last= 0;
}
-int BLI_stringdec(char *string, char *kop, char *staart, unsigned short *numlen)
+int BLI_stringdec(char *string, char *kop, char *start, unsigned short *numlen)
{
unsigned short len, len2, nums = 0, nume = 0;
short i, found = 0;
- len2 = len = strlen( string);
+ len2 = len = strlen(string);
if (len > 6) {
if (BLI_strncasecmp(string + len - 6, ".blend", 6) == 0) len -= 6;
@@ -125,7 +123,6 @@
if (BLI_strncasecmp(string + len - 9, ".blend.gz", 9) == 0) len -= 9;
}
-
if (len == len2) {
if (len > 4) {
/* handle .jf0 en .jf1 for jstreams */
@@ -143,7 +140,7 @@
}
}
- for (i = len - 1; i >= 0; i--){
+ for (i = len - 1; i >= 0; i--) {
if (string[i] == '/') break;
if (isdigit(string[i])) {
if (found){
@@ -155,12 +152,12 @@
found = 1;
}
}
- else{
+ else {
if (found) break;
}
}
if (found){
- if (staart) strcpy(staart,&string[nume+1]);
+ if (start) strcpy(start,&string[nume+1]);
if (kop) {
strcpy(kop,string);
kop[nums]=0;
@@ -168,7 +165,7 @@
if (numlen) *numlen = nume-nums+1;
return ((int)atoi(&(string[nums])));
}
- if (staart) strcpy(staart, string + len);
+ if (start) strcpy(start, string + len);
if (kop) {
strncpy(kop, string, len);
kop[len] = 0;
@@ -178,7 +175,7 @@
}
-void BLI_stringenc(char *string, char *kop, char *staart, unsigned short numlen, int pic)
+void BLI_stringenc(char *string, char *kop, char *start, unsigned short numlen, int pic)
{
char numstr[10]="";
unsigned short len,i;
@@ -187,17 +184,17 @@
if (pic>0 || numlen==4) {
len= sprintf(numstr,"%d",pic);
-
+
for(i=len;i<numlen;i++){
strcat(string,"0");
}
strcat(string,numstr);
}
- strcat(string,staart);
+ strcat(string, start);
}
-void BLI_newname(char * name, int add)
+void BLI_newname(char *name, int add)
{
char head[128], tail[128];
int pic;
@@ -215,38 +212,38 @@
pic += add;
- if(digits==4 && pic<0) pic= 0;
+ if (digits==4 && pic<0) pic= 0;
BLI_stringenc(name, head, tail, digits, pic);
}
void BLI_addhead(ListBase *listbase, void *vlink)
{
- struct Link *link= vlink;
+ Link *link= vlink;
- if (link == 0) return;
- if (listbase == 0) return;
+ if (link == NULL) return;
+ if (listbase == NULL) return;
link->next = listbase->first;
- link->prev = 0;
+ link->prev = NULL;
- if (listbase->first) ((struct Link *)listbase->first)->prev = link;
- if (listbase->last == 0) listbase->last = link;
+ if (listbase->first) ((Link *)listbase->first)->prev = link;
+ if (listbase->last == NULL) listbase->last = link;
listbase->first = link;
}
void BLI_addtail(ListBase *listbase, void *vlink)
{
- struct Link *link= vlink;
+ Link *link= vlink;
- if (link == 0) return;
- if (listbase == 0) return;
+ if (link == NULL) return;
+ if (listbase == NULL) return;
- link->next = 0;
+ link->next = NULL;
link->prev = listbase->last;
- if (listbase->last) ((struct Link *)listbase->last)->next = link;
+ if (listbase->last) ((Link *)listbase->last)->next = link;
if (listbase->first == 0) listbase->first = link;
listbase->last = link;
}
@@ -254,10 +251,10 @@
void BLI_remlink(ListBase *listbase, void *vlink)
{
- struct Link *link= vlink;
+ Link *link= vlink;
- if (link == 0) return;
- if (listbase == 0) return;
+ if (link == NULL) return;
+ if (listbase == NULL) return;
if (link->next) link->next->prev = link->prev;
if (link->prev) link->prev->next = link->next;
@@ -269,10 +266,10 @@
void BLI_freelinkN(ListBase *listbase, void *vlink)
{
- struct Link *link= vlink;
+ Link *link= vlink;
- if (link == 0) return;
- if (listbase == 0) return;
+ if (link == NULL) return;
+ if (listbase == NULL) return;
BLI_remlink(listbase,link);
MEM_freeN(link);
@@ -281,19 +278,23 @@
void BLI_insertlink(ListBase *listbase, void *vprevlink, void *vnewlink)
{
- struct Link *prevlink= vprevlink, *newlink= vnewlink;
+ Link *prevlink= vprevlink;
+ Link *newlink= vnewlink;
/* newlink comes after prevlink */
-
- if (newlink == 0) return;
- if (listbase == 0) return;
-
- if(listbase->first==0) { /* empty list */
+ if (newlink == NULL) return;
+ if (listbase == NULL) return;
+
+ /* empty list */
+ if (listbase->first == NULL) {
+
listbase->first= newlink;
listbase->last= newlink;
return;
}
- if (prevlink== 0) { /* insert before first element */
+
+ /* insert before first element */
+ if (prevlink == NULL) {
newlink->next= listbase->first;
newlink->prev= 0;
newlink->next->prev= newlink;
@@ -301,96 +302,106 @@
return;
}
- if (listbase->last== prevlink) /* at end of list */
+ /* at end of list */
+ if (listbase->last== prevlink)
listbase->last = newlink;
newlink->next= prevlink->next;
prevlink->next= newlink;
- if(newlink->next) newlink->next->prev= newlink;
+ if (newlink->next) newlink->next->prev= newlink;
newlink->prev= prevlink;
}
void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink)
{
- struct Link *nextlink= vnextlink, *newlink= vnewlink;
+ Link *nextlink= vnextlink;
+ Link *newlink= vnewlink;
/* newlink before nextlink */
+ if (newlink == NULL) return;
+ if (listbase == NULL) return;
- if (newlink == 0) return;
- if (listbase == 0) return;
-
- if(listbase->first==0) { /* empty list */
+ /* empty list */
+ if (listbase->first == NULL) {
listbase->first= newlink;
listbase->last= newlink;
return;
}
- if (nextlink== 0) { /* insert at end of list */
+
+ /* insert at end of list */
+ if (nextlink == NULL) {
newlink->prev= listbase->last;
newlink->next= 0;
- ((struct Link *)listbase->last)->next= newlink;
+ ((Link *)listbase->last)->next= newlink;
listbase->last= newlink;
return;
}
- if (listbase->first== nextlink) /* at beginning of list */
+ /* at beginning of list */
+ if (listbase->first== nextlink)
listbase->first = newlink;
newlink->next= nextlink;
newlink->prev= nextlink->prev;
nextlink->prev= newlink;
- if(newlink->prev) newlink->prev->next= newlink;
+ if (newlink->prev) newlink->prev->next= newlink;
}
void BLI_freelist(ListBase *listbase)
{
- struct Link *link,*next;
+ Link *link, *next;
- if (listbase == 0) return;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list