diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-03-05 08:35:14 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-03-05 08:35:14 +0400 |
commit | 34233e7fd661dbd378c4e11a1e0d29ed639fbffa (patch) | |
tree | a1c692000a85db48a7484184653e9113d5a4aad6 /source/blender | |
parent | 65d6cecd68a22f140d2acc0d8dd5abf68723ed2e (diff) |
patch [#34103] path_util_cleanups.patch
from Lawrence D'Oliveiro (ldo)
- Better argument name for BLI_cleanup_path and BLI_cleanup_file
- remove redundant BLI_add_slash already done by BLI_cleanup_dir
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenlib/BLI_path_util.h | 4 | ||||
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 54 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_ops.c | 1 |
3 files changed, 29 insertions, 30 deletions
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 301e2c02018..92c68dee24d 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -132,9 +132,9 @@ __attribute__((nonnull(1))) * converts it to a regular full path. * Also removes garbage from directory paths, like /../ or double slashes etc */ -void BLI_cleanup_file(const char *relabase, char *dir); /* removes trailing slash */ +void BLI_cleanup_file(const char *relabase, char *path); /* removes trailing slash */ void BLI_cleanup_dir(const char *relabase, char *dir); /* same as above but adds a trailing slash */ -void BLI_cleanup_path(const char *relabase, char *dir); /* doesn't touch trailing slash */ +void BLI_cleanup_path(const char *relabase, char *path); /* doesn't touch trailing slash */ /* go back one directory */ bool BLI_parent_dir(char *path); diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 7399a355664..045572ca69d 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -350,19 +350,19 @@ void BLI_uniquename(ListBase *list, void *vlink, const char *defname, char delim * If relbase is NULL then its ignored */ -void BLI_cleanup_path(const char *relabase, char *dir) +void BLI_cleanup_path(const char *relabase, char *path) { ptrdiff_t a; char *start, *eind; if (relabase) { - BLI_path_abs(dir, relabase); + BLI_path_abs(path, relabase); } else { - if (dir[0] == '/' && dir[1] == '/') { - if (dir[2] == '\0') { + if (path[0] == '/' && path[1] == '/') { + if (path[2] == '\0') { return; /* path is "//" - cant clean it */ } - dir = dir + 2; /* skip the first // */ + path = path + 2; /* skip the first // */ } } @@ -378,70 +378,70 @@ void BLI_cleanup_path(const char *relabase, char *dir) /* Note, this should really be moved to the file selector, * since this function is used in many areas */ - if (strcmp(dir, ".") == 0) { /* happens for example in FILE_MAIN */ - get_default_root(dir); + if (strcmp(path, ".") == 0) { /* happens for example in FILE_MAIN */ + get_default_root(path); return; } - while ( (start = strstr(dir, "\\..\\")) ) { + while ( (start = strstr(path, "\\..\\")) ) { eind = start + strlen("\\..\\") - 1; - a = start - dir - 1; + a = start - path - 1; while (a > 0) { - if (dir[a] == '\\') break; + if (path[a] == '\\') break; a--; } if (a < 0) { break; } else { - memmove(dir + a, eind, strlen(eind) + 1); + memmove(path + a, eind, strlen(eind) + 1); } } - while ( (start = strstr(dir, "\\.\\")) ) { + while ( (start = strstr(path, "\\.\\")) ) { eind = start + strlen("\\.\\") - 1; memmove(start, eind, strlen(eind) + 1); } - while ( (start = strstr(dir, "\\\\")) ) { + while ( (start = strstr(path, "\\\\")) ) { eind = start + strlen("\\\\") - 1; memmove(start, eind, strlen(eind) + 1); } #else - if (dir[0] == '.') { /* happens, for example in FILE_MAIN */ - dir[0] = '/'; - dir[1] = 0; + if (path[0] == '.') { /* happens, for example in FILE_MAIN */ + path[0] = '/'; + path[1] = 0; return; } /* support for odd paths: eg /../home/me --> /home/me * this is a valid path in blender but we cant handle this the usual way below * simply strip this prefix then evaluate the path as usual. pythons os.path.normpath() does this */ - while ((strncmp(dir, "/../", 4) == 0)) { - memmove(dir, dir + 4, strlen(dir + 4) + 1); + while ((strncmp(path, "/../", 4) == 0)) { + memmove(path, path + 4, strlen(path + 4) + 1); } - while ( (start = strstr(dir, "/../")) ) { + while ( (start = strstr(path, "/../")) ) { eind = start + (4 - 1) /* strlen("/../") - 1 */; - a = start - dir - 1; + a = start - path - 1; while (a > 0) { - if (dir[a] == '/') break; + if (path[a] == '/') break; a--; } if (a < 0) { break; } else { - memmove(dir + a, eind, strlen(eind) + 1); + memmove(path + a, eind, strlen(eind) + 1); } } - while ( (start = strstr(dir, "/./")) ) { + while ( (start = strstr(path, "/./")) ) { eind = start + (3 - 1) /* strlen("/./") - 1 */; memmove(start, eind, strlen(eind) + 1); } - while ( (start = strstr(dir, "//")) ) { + while ( (start = strstr(path, "//")) ) { eind = start + (2 - 1) /* strlen("//") - 1 */; memmove(start, eind, strlen(eind) + 1); } @@ -455,10 +455,10 @@ void BLI_cleanup_dir(const char *relabase, char *dir) } -void BLI_cleanup_file(const char *relabase, char *dir) +void BLI_cleanup_file(const char *relabase, char *path) { - BLI_cleanup_path(relabase, dir); - BLI_del_slash(dir); + BLI_cleanup_path(relabase, path); + BLI_del_slash(path); } /** diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 0d06e235669..2f2ae78f60b 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -1228,7 +1228,6 @@ int file_directory_exec(bContext *C, wmOperator *UNUSED(unused)) } BLI_cleanup_dir(G.main->name, sfile->params->dir); - BLI_add_slash(sfile->params->dir); file_change_dir(C, 1); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); |