diff options
author | Miika Hamalainen <blender@miikah.org> | 2011-10-31 17:18:14 +0400 |
---|---|---|
committer | Miika Hamalainen <blender@miikah.org> | 2011-10-31 17:18:14 +0400 |
commit | cd338a4130011ed9eccc7b131b11e4261b9dc269 (patch) | |
tree | 767bb3edaa08fef0bb6ff039fced376f9a00e9c3 /source/blender/blenlib | |
parent | 0a37e6ab976344818483df899b4fc44aedb30613 (diff) | |
parent | a664e779ac8be0f926221d4c064394f9b3b6a801 (diff) |
Merge with trunk r41411
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_path_util.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_string.h | 23 | ||||
-rw-r--r-- | source/blender/blenlib/intern/bpath.c | 3 | ||||
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 47 | ||||
-rw-r--r-- | source/blender/blenlib/intern/string.c | 29 |
5 files changed, 40 insertions, 63 deletions
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index dd4bc868ab0..68bb1a7280d 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -102,6 +102,7 @@ int BLI_testextensie(const char *str, const char *ext); int BLI_testextensie_array(const char *str, const char **ext_array); int BLI_testextensie_glob(const char *str, const char *ext_fnmatch); int BLI_replace_extension(char *path, size_t maxlen, const char *ext); +int BLI_ensure_extension(char *path, size_t maxlen, const char *ext); void BLI_uniquename(struct ListBase *list, void *vlink, const char defname[], char delim, short name_offs, short len); int BLI_uniquename_cb(int (*unique_check)(void *, const char *), void *arg, const char defname[], char delim, char *name, short name_len); void BLI_newname(char * name, int add); diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index 9a7fa521af1..46389a9259e 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -132,29 +132,6 @@ int BLI_strcasecmp(const char *s1, const char *s2); int BLI_strncasecmp(const char *s1, const char *s2, size_t len); int BLI_natstrcmp(const char *s1, const char *s2); size_t BLI_strnlen(const char *str, size_t maxlen); - - /** - * Split str on the first occurence of delimiter, returns the first - * part as a mallocN'd string, and stores the second part into - * ctx (also mallocN'd). - * If str is NULL, split on ctx instead. - * This allows to iterate over this "generator" function: - * - * char *ctx = NULL; - * char *res = NULL; - * for(res = BLI_strtok_r("a;dummy;csv;line", ";", &ctx); res; res = BLI_strtok_r(NULL, ";", &ctx)) { - * printf(res); - * MEM_freeN(res); - * } - * - * @param str The string to be split. - * @param delimiter The char used to split str apart. - * @param ctx The "context" string. It’s a pointer inside the org passed @str, - * so it has no specific mem management. - * @retval Returns the mallocN'd first element from split str (or ctx). - */ -char *BLI_strtok_r(char *str, const char *delimiter, char **ctx); - void BLI_timestr(double _time, char *str); /* time var is global */ void BLI_ascii_strtolower(char *str, int len); diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index e42e02fb24f..b7fe7ef5efd 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -325,8 +325,7 @@ static int rewrite_path_fixed_dirfile(char path_dir[FILE_MAXDIR], char path_file } if (visit_cb(userdata, path_dst, (const char *)path_src)) { - BLI_split_dirfile(path_dst, path_dir, path_file, - sizeof(path_dir), sizeof(path_file)); + BLI_split_dirfile(path_dst, path_dir, path_file, FILE_MAXDIR, FILE_MAXFILE); return TRUE; } else { diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index bc24415fd3f..bbb62db58f2 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -1397,22 +1397,51 @@ 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 a; - for(a=strlen(path); a>0; a--) { - if(path[a-1] == '.' || path[a-1] == '/' || path[a-1] == '\\') { - a--; + for(a= path_len - 1; a >= 0; a--) { + if (ELEM3(path[a], '.', '/', '\\')) { break; } } - - if(path[a] != '.') - a= strlen(path); - if(a + strlen(ext) >= maxlen) + if(a + ext_len >= maxlen) + return 0; + + 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 a; + + /* first check the extension is alread there */ + if ( (ext_len <= path_len) && + (strcmp(path + (path_len - ext_len), ext) == 0)) + { + return 1; + } + + for(a= path_len - 1; a >= 0; a--) { + if (path[a] == '.') { + path[a]= '\0'; + } + else { + break; + } + } + a++; + + if(a + ext_len >= maxlen) return 0; - strcpy(path+a, ext); + memcpy(path+a, ext, ext_len + 1); return 1; } @@ -1844,7 +1873,7 @@ void BLI_where_is_temp(char *fullname, const size_t maxlen, char *userdir) /* add a trailing slash if needed */ BLI_add_slash(fullname); #ifdef WIN32 - if(userdir != fullname) { + if(userdir && userdir != fullname) { BLI_strncpy(userdir, fullname, maxlen); /* also set user pref to show %TEMP%. /tmp/ is just plain confusing for Windows users. */ } #endif diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index 3ec84e0b593..3a66425a5de 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -375,35 +375,6 @@ int BLI_natstrcmp(const char *s1, const char *s2) return 0; } -/* As unfortunately strtok_r is not available everywhere... */ -char *BLI_strtok_r(char *str, const char *delimiter, char **ctx) -{ - char *cut = NULL, *ret = NULL; - char *split = str ? str : *ctx; - - if(!split) { - return ret; - } - - cut = strchr(split, *delimiter); - if(cut) { - size_t len_ret = cut - split; - size_t len_ctx = strlen(split) - len_ret - 1; - ret = BLI_strdupn(split, len_ret); - if(len_ctx > 0) { - *ctx = split+len_ret+1; - } - else { - *ctx = NULL; - } - } - else { - ret = BLI_strdup(split); - *ctx = NULL; - } - return ret; -} - void BLI_timestr(double _time, char *str) { /* format 00:00:00.00 (hr:min:sec) string has to be 12 long */ |