diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-04-07 05:02:21 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-04-07 05:10:36 +0300 |
commit | d14e76806921f9a4d686ea731364242ededb735d (patch) | |
tree | 0d43db74bc544798eca32f1a46deb2705d87a1a3 /source/blender/blenlib/intern/path_util.c | |
parent | d54757e389862a081deb3d2064e95fdaddb1880a (diff) |
Cleanup: BLI_path.h function renaming
Use BLI_path_ prefix, more consistent names:
BLI_parent_dir -> BLI_path_parent_dir
BLI_parent_dir_until_exists -> BLI_path_parent_dir_until_exists
BLI_ensure_filename -> BLI_path_filename_ensure
BLI_first_slash -> BLI_path_slash_find
BLI_last_slash -> BLI_path_slash_rfind
BLI_add_slash -> BLI_path_slash_ensure
BLI_del_slash -> BLI_path_slash_rstrip
BLI_path_native_slash -> BLI_path_slash_native
Rename 'cleanup' to 'normalize', similar to Python's `os.path.normpath`.
BLI_cleanup_path -> BLI_path_normalize
BLI_cleanup_dir -> BLI_path_normalize_dir
BLI_cleanup_unc -> BLI_path_normalize_unc
BLI_cleanup_unc16 -> BLI_path_normalize_unc16
Clarify naming for extracting, creating numbered paths:
BLI_stringenc -> BLI_path_sequence_encode
BLI_stringdec -> BLI_path_sequence_decode
Part of T74506 proposal.
Diffstat (limited to 'source/blender/blenlib/intern/path_util.c')
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 0bb2ba5859b..ad93b643c5e 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -80,12 +80,12 @@ static bool BLI_path_is_abs(const char *name); * or from dot if no digits. * \param r_num_len: Optional to return number of digits found. */ -int BLI_stringdec(const char *string, char *head, char *tail, ushort *r_num_len) +int BLI_path_sequence_decode(const char *string, char *head, char *tail, ushort *r_num_len) { uint nums = 0, nume = 0; int i; bool found_digit = false; - const char *const lslash = BLI_last_slash(string); + const char *const lslash = BLI_path_slash_rfind(string); const uint string_len = strlen(string); const uint lslash_len = lslash != NULL ? (int)(lslash - string) : 0; uint name_end = string_len; @@ -151,7 +151,7 @@ int BLI_stringdec(const char *string, char *head, char *tail, ushort *r_num_len) * Returns in area pointed to by string a string of the form "<head><pic><tail>", where pic * is formatted as numlen digits with leading zeroes. */ -void BLI_stringenc( +void BLI_path_sequence_encode( char *string, const char *head, const char *tail, unsigned short numlen, int pic) { sprintf(string, "%s%.*d%s", head, numlen, MAX2(0, pic), tail); @@ -170,7 +170,7 @@ static int BLI_path_unc_prefix_len(const char *path); /* defined below in same f * * \note \a path isn't protected for max string names... */ -void BLI_cleanup_path(const char *relabase, char *path) +void BLI_path_normalize(const char *relabase, char *path) { ptrdiff_t a; char *start, *eind; @@ -263,10 +263,10 @@ void BLI_cleanup_path(const char *relabase, char *path) /** * Cleanup filepath ensuring a trailing slash. */ -void BLI_cleanup_dir(const char *relabase, char *dir) +void BLI_path_normalize_dir(const char *relabase, char *dir) { - BLI_cleanup_path(relabase, dir); - BLI_add_slash(dir); + BLI_path_normalize(relabase, dir); + BLI_path_slash_ensure(dir); } /** @@ -381,8 +381,8 @@ bool BLI_path_make_safe(char *path) } #endif - for (curr_slash = (char *)BLI_first_slash(curr_path); curr_slash; - curr_slash = (char *)BLI_first_slash(curr_path)) { + for (curr_slash = (char *)BLI_path_slash_find(curr_path); curr_slash; + curr_slash = (char *)BLI_path_slash_find(curr_path)) { const char backup = *curr_slash; *curr_slash = '\0'; if (!skip_first && (*curr_path != '\0') && BLI_filename_make_safe(curr_path)) { @@ -494,7 +494,7 @@ static void BLI_path_unc_to_short(wchar_t *unc) } } -void BLI_cleanup_unc(char *path, int maxlen) +void BLI_path_normalize_unc(char *path, int maxlen) { wchar_t *tmp_16 = alloc_utf16_from_8(path, 1); BLI_cleanup_unc_16(tmp_16); @@ -578,11 +578,11 @@ void BLI_path_rel(char *file, const char *relfile) BLI_str_replace_char(file + BLI_path_unc_prefix_len(file), '\\', '/'); /* remove /./ which confuse the following slash counting... */ - BLI_cleanup_path(NULL, file); - BLI_cleanup_path(NULL, temp); + BLI_path_normalize(NULL, file); + BLI_path_normalize(NULL, temp); /* the last slash in the file indicates where the path part ends */ - lslash = BLI_last_slash(temp); + lslash = BLI_path_slash_rfind(temp); if (lslash) { /* find the prefix of the filename that is equal for both filenames. @@ -701,13 +701,13 @@ bool BLI_path_suffix(char *string, size_t maxlen, const char *suffix, const char * Replaces path with the path of its parent directory, returning true if * it was able to find a parent directory within the pathname. */ -bool BLI_parent_dir(char *path) +bool BLI_path_parent_dir(char *path) { const char parent_dir[] = {'.', '.', SEP, '\0'}; /* "../" or "..\\" */ char tmp[FILE_MAX + 4]; BLI_join_dirfile(tmp, sizeof(tmp), path, parent_dir); - BLI_cleanup_path(NULL, tmp); /* does all the work of normalizing the path for us */ + BLI_path_normalize(NULL, tmp); /* does all the work of normalizing the path for us */ if (!BLI_path_extension_check(tmp, parent_dir)) { strcpy(path, tmp); /* We assume pardir is always shorter... */ @@ -722,12 +722,12 @@ bool BLI_parent_dir(char *path) * Strips off nonexistent (or non-accessible) subdirectories from the end of *dir, * leaving the path of the lowest-level directory that does exist and we can read. */ -bool BLI_parent_dir_until_exists(char *dir) +bool BLI_path_parent_dir_until_exists(char *dir) { bool valid_path = true; /* Loop as long as cur path is not a dir, and we can get a parent path. */ - while ((BLI_access(dir, R_OK) != 0) && (valid_path = BLI_parent_dir(dir))) { + while ((BLI_access(dir, R_OK) != 0) && (valid_path = BLI_path_parent_dir(dir))) { /* pass */ } return (valid_path && dir[0]); @@ -777,7 +777,7 @@ static bool stringframe_chars(const char *path, int *char_start, int *char_end) */ static void ensure_digits(char *path, int digits) { - char *file = (char *)BLI_last_slash(path); + char *file = (char *)BLI_path_slash_rfind(path); if (file == NULL) { file = path; @@ -852,7 +852,7 @@ bool BLI_path_frame_range(char *path, int sta, int end, int digits) bool BLI_path_frame_get(char *path, int *r_frame, int *r_numdigits) { if (*path) { - char *file = (char *)BLI_last_slash(path); + char *file = (char *)BLI_path_slash_rfind(path); char *c; int len, numdigits; @@ -908,7 +908,7 @@ void BLI_path_frame_strip(char *path, char *r_ext) return; } - char *file = (char *)BLI_last_slash(path); + char *file = (char *)BLI_path_slash_rfind(path); char *c, *suffix; int len; int numdigits = 0; @@ -1075,8 +1075,8 @@ bool BLI_path_abs(char *path, const char *basepath) BLI_strncpy(base, basepath, sizeof(base)); /* file component is ignored, so don't bother with the trailing slash */ - BLI_cleanup_path(NULL, base); - lslash = BLI_last_slash(base); + BLI_path_normalize(NULL, base); + lslash = BLI_path_slash_rfind(base); BLI_str_replace_char(base + BLI_path_unc_prefix_len(base), '\\', '/'); if (lslash) { @@ -1110,7 +1110,7 @@ bool BLI_path_abs(char *path, const char *basepath) #endif /* ensure this is after correcting for path switch */ - BLI_cleanup_path(NULL, path); + BLI_path_normalize(NULL, path); return wasrelative; } @@ -1363,7 +1363,7 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir, c /* Get the file name, chop everything past the last slash (ie. the filename) */ strcpy(string, relabase); - lslash = (char *)BLI_last_slash(string); + lslash = (char *)BLI_path_slash_rfind(string); if (lslash) { *(lslash + 1) = 0; } @@ -1418,7 +1418,7 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir, c strcat(string, file); /* Push all slashes to the system preferred direction */ - BLI_path_native_slash(string); + BLI_path_slash_native(string); } static bool path_extension_check_ex(const char *str, @@ -1608,12 +1608,12 @@ bool BLI_path_extension_ensure(char *path, size_t maxlen, const char *ext) return true; } -bool BLI_ensure_filename(char *filepath, size_t maxlen, const char *filename) +bool BLI_path_filename_ensure(char *filepath, size_t maxlen, const char *filename) { #ifdef DEBUG_STRSIZE memset(filepath, 0xff, sizeof(*filepath) * maxlen); #endif - char *c = (char *)BLI_last_slash(filepath); + char *c = (char *)BLI_path_slash_rfind(filepath); if (!c || ((c - filepath) < maxlen - (strlen(filename) + 1))) { strcpy(c ? &c[1] : filepath, filename); return true; @@ -1636,7 +1636,7 @@ void BLI_split_dirfile( memset(dir, 0xff, sizeof(*dir) * dirlen); memset(file, 0xff, sizeof(*file) * filelen); #endif - const char *lslash_str = BLI_last_slash(string); + const char *lslash_str = BLI_path_slash_rfind(string); const size_t lslash = lslash_str ? (size_t)(lslash_str - string) + 1 : 0; if (dir) { @@ -1680,7 +1680,7 @@ const char *BLI_path_extension(const char *filepath) if (extension == NULL) { return NULL; } - if (BLI_first_slash(extension) != NULL) { + if (BLI_path_slash_find(extension) != NULL) { /* There is a path separator in the extension, so the '.' was found in a * directory component and not in the filename. */ return NULL; @@ -1695,7 +1695,7 @@ void BLI_path_append(char *__restrict dst, const size_t maxlen, const char *__re { size_t dirlen = BLI_strnlen(dst, maxlen); - /* inline BLI_add_slash */ + /* inline BLI_path_slash_ensure */ if ((dirlen > 0) && (dst[dirlen - 1] != SEP)) { dst[dirlen++] = SEP; dst[dirlen] = '\0'; @@ -1738,7 +1738,7 @@ void BLI_join_dirfile(char *__restrict dst, return; /* fills the path */ } - /* inline BLI_add_slash */ + /* inline BLI_path_slash_ensure */ if ((dirlen > 0) && !ELEM(dst[dirlen - 1], SEP, ALTSEP)) { dst[dirlen++] = SEP; dst[dirlen] = '\0'; @@ -1846,7 +1846,7 @@ size_t BLI_path_join(char *__restrict dst, const size_t dst_len, const char *pat */ const char *BLI_path_basename(const char *path) { - const char *const filename = BLI_last_slash(path); + const char *const filename = BLI_path_slash_rfind(path); return filename ? filename + 1 : path; } @@ -1921,7 +1921,7 @@ bool BLI_path_name_at_index(const char *__restrict path, /** * Returns pointer to the leftmost path separator in string. Not actually used anywhere. */ -const char *BLI_first_slash(const char *string) +const char *BLI_path_slash_find(const char *string) { const char *const ffslash = strchr(string, '/'); const char *const fbslash = strchr(string, '\\'); @@ -1939,7 +1939,7 @@ const char *BLI_first_slash(const char *string) /** * Returns pointer to the rightmost path separator in string. */ -const char *BLI_last_slash(const char *string) +const char *BLI_path_slash_rfind(const char *string) { const char *const lfslash = strrchr(string, '/'); const char *const lbslash = strrchr(string, '\\'); @@ -1958,7 +1958,7 @@ const char *BLI_last_slash(const char *string) * Appends a slash to string if there isn't one there already. * Returns the new length of the string. */ -int BLI_add_slash(char *string) +int BLI_path_slash_ensure(char *string) { int len = strlen(string); if (len == 0 || string[len - 1] != SEP) { @@ -1972,7 +1972,7 @@ int BLI_add_slash(char *string) /** * Removes the last slash and everything after it to the end of string, if there is one. */ -void BLI_del_slash(char *string) +void BLI_path_slash_rstrip(char *string) { int len = strlen(string); while (len) { @@ -1989,7 +1989,7 @@ void BLI_del_slash(char *string) /** * Changes to the path separators to the native ones for this OS. */ -void BLI_path_native_slash(char *path) +void BLI_path_slash_native(char *path) { #ifdef WIN32 if (path && BLI_strnlen(path, 3) > 2) { |