diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2015-06-04 21:40:11 +0300 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2015-06-04 21:40:44 +0300 |
commit | 2cbe60b47672acd67b6ec2c15f13f196247ecfe3 (patch) | |
tree | d6416970a8269a13942a0f8dde1d017669b7f725 /source/blender/blenlib/intern/path_util.c | |
parent | 455ca1b28f140482f2834c9bba0adc730aff6637 (diff) |
New "use placeholders" feature of the sequencer did not detect correct
filenames.
Added BLI_path utility functions to decompose a path name and
extract the frame number. It should be useful in autocollapse
feature as well
Diffstat (limited to 'source/blender/blenlib/intern/path_util.c')
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 9cf360a77e3..d3352e24722 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -859,6 +859,111 @@ bool BLI_path_frame_range(char *path, int sta, int end, int digits) } /** + * Get the frame from a filename formatted by blender's frame scheme + */ +bool BLI_path_frame_get(char *path, int *r_frame, int *r_numdigits) +{ + if (path && *path) { + char *file = (char *)BLI_last_slash(path); + char *c; + int len, numdigits; + + numdigits = *r_numdigits = 0; + + if (file == NULL) + file = path; + + /* first get the extension part */ + len = strlen(file); + + c = file + len; + + /* isolate extension */ + while (--c != file) { + if (*c == '.') { + c--; + break; + } + } + + /* find start of number */ + while (c != (file - 1) && isdigit(*c)) { + c--; + numdigits++; + } + + if (numdigits) { + char prevchar; + + c++; + prevchar = c[numdigits]; + c[numdigits] = 0; + + /* was the number really an extension? */ + *r_frame = atoi(c); + c[numdigits] = prevchar; + + *r_numdigits = numdigits; + + return true; + } + } + + return false; +} + +void BLI_path_frame_strip(char *path, bool setsharp, char *ext) +{ + if (path && *path) { + char *file = (char *)BLI_last_slash(path); + char *c, *suffix; + int len; + int numdigits = 0; + + if (file == NULL) + file = path; + + /* first get the extension part */ + len = strlen(file); + + c = file + len; + + /* isolate extension */ + while (--c != file) { + if (*c == '.') { + c--; + break; + } + } + + suffix = c + 1; + + /* find start of number */ + while (c != (file - 1) && isdigit(*c)) { + c--; + numdigits++; + } + + c++; + + if(numdigits) { + /* replace the number with the suffix and terminate the string */ + while (numdigits--) { + if (ext) *ext++ = *suffix; + + if (setsharp) *c++ = '#'; + else *c++ = *suffix; + + suffix++; + } + *c = 0; + if (ext) *ext = 0; + } + } +} + + +/** * Check if we have '#' chars, usable for #BLI_path_frame, #BLI_path_frame_range */ bool BLI_path_frame_check_chars(const char *path) |