diff options
author | Gaia Clary <gaia.clary@machinimatrix.org> | 2012-06-22 19:38:49 +0400 |
---|---|---|
committer | Gaia Clary <gaia.clary@machinimatrix.org> | 2012-06-22 19:38:49 +0400 |
commit | 5455cadb3d16685f682516475c0d66e071f386f2 (patch) | |
tree | 60daa48d48ae3424e4594a07fdb6ea23803136fc /source | |
parent | 0b0ac3aa9ee94ad8020639e9d1df4c94a23a3fcf (diff) |
fixed function name: BLI_rebase_path, reworked description, added enum bli_rebase_state for defined return values
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/BLI_path_util.h | 11 | ||||
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 43 |
2 files changed, 36 insertions, 18 deletions
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 74f5e7fc2bd..9b68406cc54 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -89,7 +89,16 @@ void BLI_split_dir_part(const char *string, char *dir, const size_t dirlen); void BLI_split_file_part(const char *string, char *file, const size_t filelen); void BLI_join_dirfile(char *string, const size_t maxlen, const char *dir, const char *file); char *BLI_path_basename(char *path); -int BKE_rebase_path(char *abs, size_t abs_len, char *rel, size_t rel_len, const char *base_dir, const char *src_dir, const char *dest_dir); + +typedef enum bli_rebase_state { + BLI_REBASE_NO_SRCDIR = 0, + BLI_REBASE_OK = 1, + BLI_REBASE_IDENTITY = 2 +} bli_rebase_state; + +int BLI_rebase_path(char *abs, size_t abs_len, char *rel, size_t rel_len, const char *base_dir, const char *src_dir, const char *dest_dir); +#define BKE_rebase_path BLI_rebase_path /* remove after a 2012 */ + char *BLI_last_slash(const char *string); int BLI_add_slash(char *string); void BLI_del_slash(char *string); diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 1bda7b5ee7e..46a0ac630c1 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -1547,31 +1547,40 @@ char *BLI_path_basename(char *path) /** * Produce image export path. - * - * Fails returning 0 if image filename is empty or if destination path - * matches image path (i.e. both are the same file). - * - * Trailing slash in dest_dir is optional. + * + * Returns: + * 0 if image filename is empty or if destination path + * matches image path (i.e. both are the same file). + * 2 if source is identical to destination. + * 1 if rebase was successfull + * ------------------------------------------------------------- + * Hint: Trailing slash in dest_dir is optional. * * Logic: * - * - if an image is "below" current .blend file directory, rebuild the - * same dir structure in dest_dir + * - if an image is "below" current .blend file directory: + * rebuild the same dir structure in dest_dir * - * For example //textures/foo/bar.png becomes - * [dest_dir]/textures/foo/bar.png. + * Example: + * src : //textures/foo/bar.png + * dest: [dest_dir]/textures/foo/bar.png. * * - if an image is not "below" current .blend file directory, - * disregard it's path and copy it in the same directory where 3D file - * goes. + * disregard it's path and copy it into the destination + * directory. * - * For example //../foo/bar.png becomes [dest_dir]/bar.png. + * Example: + * src : //../foo/bar.png becomes + * dest: [dest_dir]/bar.png. * - * This logic will help ensure that all image paths are relative and + * This logic ensures that all image paths are relative and * that a user gets his images in one place. It'll also provide * consistent behavior across exporters. + * IMPORTANT NOTE: If base_dir contains an empty string, then + * this function returns wrong results! + * XXX: test on empty base_dir and return an error ? */ -int BKE_rebase_path(char *abs, size_t abs_len, char *rel, size_t rel_len, const char *base_dir, const char *src_dir, const char *dest_dir) +int BLI_rebase_path(char *abs, size_t abs_len, char *rel, size_t rel_len, const char *base_dir, const char *src_dir, const char *dest_dir) { char path[FILE_MAX]; char dir[FILE_MAX]; @@ -1590,7 +1599,7 @@ int BKE_rebase_path(char *abs, size_t abs_len, char *rel, size_t rel_len, const BLI_split_dir_part(base_dir, blend_dir, sizeof(blend_dir)); if (src_dir[0] == '\0') - return 0; + return BLI_REBASE_NO_SRCDIR; BLI_strncpy(path, src_dir, sizeof(path)); @@ -1637,10 +1646,10 @@ int BKE_rebase_path(char *abs, size_t abs_len, char *rel, size_t rel_len, const /* return 2 if src=dest */ if (BLI_path_cmp(path, dest_path) == 0) { // if (G.debug & G_DEBUG) printf("%s and %s are the same file\n", path, dest_path); - return 2; + return BLI_REBASE_IDENTITY; } - return 1; + return BLI_REBASE_OK; } char *BLI_first_slash(char *string) |