From f749d0361f8a2cf8ba7d515c31cec1dcf8fe96a5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 30 Jan 2010 22:33:47 +0000 Subject: - hash characters in the path would confuse the output file name and not add numbers to it (when rendering animations). - added an option to BLI_convertstringframe and BLI_convertstringframe_range to add digits if not found. - removed BLI_convertstringframe where its obviously not needed - such as loading movies and sounds. --- source/blender/blenlib/BLI_path_util.h | 4 ++-- source/blender/blenlib/intern/path_util.c | 29 +++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) (limited to 'source/blender/blenlib') diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index f9ef3d8c828..8e97511f4c5 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -97,8 +97,8 @@ int BLI_has_parent(char *path); * @retval Returns true if the path was relative (started with "//"). */ int BLI_convertstringcode(char *path, const char *basepath); -int BLI_convertstringframe(char *path, int frame); -int BLI_convertstringframe_range(char *path, int sta, int end); +int BLI_convertstringframe(char *path, int frame, int digits); +int BLI_convertstringframe_range(char *path, int sta, int end, int digits); int BLI_convertstringcwd(char *path); void BLI_makestringcode(const char *relfile, char *file); diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 895f2d1ee56..c3ce73df6c6 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -557,9 +557,30 @@ static int stringframe_chars(char *path, int *char_start, int *char_end) } } -int BLI_convertstringframe(char *path, int frame) +static void ensure_digits(char *path, int digits) +{ + char *file= BLI_last_slash(path); + + if(file==NULL) + file= path; + + if(strrchr(file, '#') == NULL) { + int len= strlen(file); + + while(digits--) { + file[len++]= '#'; + } + file[len]= '\0'; + } +} + +int BLI_convertstringframe(char *path, int frame, int digits) { int ch_sta, ch_end; + + if(digits) + ensure_digits(path, digits); + if (stringframe_chars(path, &ch_sta, &ch_end)) { /* warning, ch_end is the last # +1 */ char tmp[FILE_MAX], format[64]; sprintf(format, "%%.%ds%%.%dd%%s", ch_sta, ch_end-ch_sta); /* example result: "%.12s%.5d%s" */ @@ -570,9 +591,13 @@ int BLI_convertstringframe(char *path, int frame) return 0; } -int BLI_convertstringframe_range(char *path, int sta, int end) +int BLI_convertstringframe_range(char *path, int sta, int end, int digits) { int ch_sta, ch_end; + + if(digits) + ensure_digits(path, digits); + if (stringframe_chars(path, &ch_sta, &ch_end)) { /* warning, ch_end is the last # +1 */ char tmp[FILE_MAX], format[64]; sprintf(format, "%%.%ds%%.%dd_%%.%dd%%s", ch_sta, ch_end-ch_sta, ch_end-ch_sta); /* example result: "%.12s%.5d-%.5d%s" */ -- cgit v1.2.3