diff options
-rw-r--r-- | source/blender/blenlib/BLI_path_util.h | 4 | ||||
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 27 | ||||
-rw-r--r-- | source/blender/imbuf/intern/anim.c | 26 |
3 files changed, 29 insertions, 28 deletions
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 91e0bbb138b..45bbd9f60a2 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -63,8 +63,8 @@ void BLI_getlastdir(const char* dir, char *last, int maxlen); int BLI_testextensie(const char *str, const char *ext); void BLI_uniquename(struct ListBase *list, void *vlink, const char defname[], char delim, short name_offs, short len); void BLI_newname(char * name, int add); -int BLI_stringdec(char *string, char *head, char *start, unsigned short *numlen); -void BLI_stringenc(char *string, char *head, char *start, unsigned short numlen, int pic); +int BLI_stringdec(const char *string, char *head, char *start, unsigned short *numlen); +void BLI_stringenc(char *string, const char *head, const char *tail, unsigned short numlen, int pic); void BLI_splitdirstring(char *di,char *fi); /* make sure path separators conform to system one */ diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 16de81de897..84868915e6b 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -80,7 +80,7 @@ static int add_win32_extension(char *name); /* implementation */ -int BLI_stringdec(char *string, char *head, char *start, unsigned short *numlen) +int BLI_stringdec(const char *string, char *head, char *tail, unsigned short *numlen) { unsigned short len, len2, lenlslash = 0, nums = 0, nume = 0; short i, found = 0; @@ -108,7 +108,7 @@ int BLI_stringdec(char *string, char *head, char *start, unsigned short *numlen) } } if (found){ - if (start) strcpy(start,&string[nume+1]); + if (tail) strcpy(tail, &string[nume+1]); if (head) { strcpy(head,string); head[nums]=0; @@ -116,22 +116,22 @@ int BLI_stringdec(char *string, char *head, char *start, unsigned short *numlen) if (numlen) *numlen = nume-nums+1; return ((int)atoi(&(string[nums]))); } - if (start) strcpy(start, string + len); + if (tail) strcpy(tail, string + len); if (head) { strncpy(head, string, len); - head[len] = 0; + head[len] = '\0'; } if (numlen) *numlen=0; return 0; } -void BLI_stringenc(char *string, char *head, char *start, unsigned short numlen, int pic) +void BLI_stringenc(char *string, const char *head, const char *tail, unsigned short numlen, int pic) { char fmtstr[16]=""; if(pic < 0) pic= 0; sprintf(fmtstr, "%%s%%.%dd%%s", numlen); - sprintf(string, fmtstr, head, pic, start); + sprintf(string, fmtstr, head, pic, tail); } @@ -1109,10 +1109,7 @@ int BLI_testextensie(const char *str, const char *ext) return (retval); } -/* - * This is a simple version of BLI_split_dirfile that has the following advantages... - * - * Converts "/foo/bar.txt" to "/foo/" and "bar.txt" +/* Converts "/foo/bar.txt" to "/foo/" and "bar.txt" * - wont change 'string' * - wont create any directories * - dosnt use CWD, or deal with relative paths. @@ -1120,14 +1117,12 @@ int BLI_testextensie(const char *str, const char *ext) * */ void BLI_split_dirfile(const char *string, char *dir, char *file) { - int lslash=0, i = 0; - for (i=0; string[i]!='\0'; i++) { - if (string[i]=='\\' || string[i]=='/') - lslash = i+1; - } + char *lslash_str = BLI_last_slash(string); + int lslash= lslash_str ? (int)(lslash_str - string) + 1 : 0; + if (dir) { if (lslash) { - BLI_strncpy( dir, string, lslash+1); /* +1 to include the slash and the last char */ + BLI_strncpy( dir, string, lslash + 1); /* +1 to include the slash and the last char */ } else { dir[0] = '\0'; } diff --git a/source/blender/imbuf/intern/anim.c b/source/blender/imbuf/intern/anim.c index a13f426e302..188f3580170 100644 --- a/source/blender/imbuf/intern/anim.c +++ b/source/blender/imbuf/intern/anim.c @@ -225,7 +225,13 @@ static void free_anim_movie(struct anim * anim) { ; } #endif -static int an_stringdec(char *string, char* kop, char *staart,unsigned short *numlen) { +#if defined(_WIN32) +# define PATHSEPERATOR '\\' +#else +# define PATHSEPERATOR '/' +#endif + +static int an_stringdec(const char *string, char* head, char *tail, unsigned short *numlen) { unsigned short len,nume,nums=0; short i,found=FALSE; @@ -233,7 +239,7 @@ static int an_stringdec(char *string, char* kop, char *staart,unsigned short *nu nume = len; for(i=len-1;i>=0;i--){ - if (string[i]=='/') break; + if (string[i]==PATHSEPERATOR) break; if (isdigit(string[i])) { if (found){ nums=i; @@ -247,21 +253,21 @@ static int an_stringdec(char *string, char* kop, char *staart,unsigned short *nu } } if (found){ - strcpy(staart,&string[nume+1]); - strcpy(kop,string); - kop[nums]=0; + strcpy(tail ,&string[nume+1]); + strcpy(head, string); + head[nums]= '\0'; *numlen=nume-nums+1; return ((int)atoi(&(string[nums]))); } - staart[0]=0; - strcpy(kop,string); + tail[0]= '\0'; + strcpy(head, string); *numlen=0; - return (1); + return TRUE; } -static void an_stringenc(char *string, char *head, char *start, unsigned short numlen, int pic) { - BLI_stringenc(string, head, start, numlen, pic); +static void an_stringenc(char *string, const char *head, const char *tail, unsigned short numlen, int pic) { + BLI_stringenc(string, head, tail, numlen, pic); } static void free_anim_avi (struct anim *anim) { |