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/editors | |
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/editors')
-rw-r--r-- | source/blender/editors/space_buttons/buttons_ops.c | 6 | ||||
-rw-r--r-- | source/blender/editors/space_clip/clip_buttons.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_clip/clip_ops.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_ops.c | 32 | ||||
-rw-r--r-- | source/blender/editors/space_file/filelist.c | 18 | ||||
-rw-r--r-- | source/blender/editors/space_file/filesel.c | 4 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_buttons.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_ops.c | 3 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_sequence.c | 8 |
9 files changed, 39 insertions, 38 deletions
diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c index e2affa7bc36..9af623d8065 100644 --- a/source/blender/editors/space_buttons/buttons_ops.c +++ b/source/blender/editors/space_buttons/buttons_ops.c @@ -110,7 +110,7 @@ static int file_browse_exec(bContext *C, wmOperator *op) if (BLI_is_dir(path)) { /* do this first so '//' isnt converted to '//\' on windows */ - BLI_add_slash(path); + BLI_path_slash_ensure(path); if (is_relative) { BLI_strncpy(path, str, FILE_MAX); BLI_path_rel(path, BKE_main_blendfile_path(bmain)); @@ -122,7 +122,7 @@ static int file_browse_exec(bContext *C, wmOperator *op) } } else { - char *const lslash = (char *)BLI_last_slash(str); + char *const lslash = (char *)BLI_path_slash_rfind(str); if (lslash) { lslash[1] = '\0'; } @@ -187,7 +187,7 @@ static int file_browse_invoke(bContext *C, wmOperator *op, const wmEvent *event) PointerRNA props_ptr; if (event->alt) { - char *lslash = (char *)BLI_last_slash(str); + char *lslash = (char *)BLI_path_slash_rfind(str); if (lslash) { *lslash = '\0'; } diff --git a/source/blender/editors/space_clip/clip_buttons.c b/source/blender/editors/space_clip/clip_buttons.c index dc85b3959e1..3b1cc6fcab0 100644 --- a/source/blender/editors/space_clip/clip_buttons.c +++ b/source/blender/editors/space_clip/clip_buttons.c @@ -872,7 +872,7 @@ void uiTemplateMovieclipInformation(uiLayout *layout, if (framenr <= clip->len) { BKE_movieclip_filename_for_frame(clip, user, filepath); - file = BLI_last_slash(filepath); + file = BLI_path_slash_rfind(filepath); } else { file = "-"; diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c index 48bc885405d..266212fdfd7 100644 --- a/source/blender/editors/space_clip/clip_ops.c +++ b/source/blender/editors/space_clip/clip_ops.c @@ -286,7 +286,7 @@ static int open_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event) BLI_strncpy(path, clip->name, sizeof(path)); BLI_path_abs(path, CTX_data_main(C)->name); - BLI_parent_dir(path); + BLI_path_parent_dir(path); } else { BLI_strncpy(path, U.textudir, sizeof(path)); diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 7cce243696d..a5263378850 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -211,7 +211,7 @@ static FileSelect file_select_do(bContext *C, int selected_idx, bool do_diropen) else { if (is_parent_dir) { /* avoids /../../ */ - BLI_parent_dir(params->dir); + BLI_path_parent_dir(params->dir); if (params->recursion_level > 1) { /* Disable 'dirtree' recursion when going up in tree. */ @@ -220,9 +220,9 @@ static FileSelect file_select_do(bContext *C, int selected_idx, bool do_diropen) } } else { - BLI_cleanup_dir(BKE_main_blendfile_path(bmain), params->dir); + BLI_path_normalize_dir(BKE_main_blendfile_path(bmain), params->dir); strcat(params->dir, file->relpath); - BLI_add_slash(params->dir); + BLI_path_slash_ensure(params->dir); } ED_file_change_dir(C); @@ -940,7 +940,7 @@ static int bookmark_select_exec(bContext *C, wmOperator *op) RNA_property_string_get(op->ptr, prop, entry); BLI_strncpy(params->dir, entry, sizeof(params->dir)); - BLI_cleanup_dir(BKE_main_blendfile_path(bmain), params->dir); + BLI_path_normalize_dir(BKE_main_blendfile_path(bmain), params->dir); ED_file_change_dir(C); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); @@ -1627,12 +1627,12 @@ static int file_exec(bContext *C, wmOperator *exec_op) } if (FILENAME_IS_PARENT(file->relpath)) { - BLI_parent_dir(sfile->params->dir); + BLI_path_parent_dir(sfile->params->dir); } else { - BLI_cleanup_path(BKE_main_blendfile_path(bmain), sfile->params->dir); + BLI_path_normalize(BKE_main_blendfile_path(bmain), sfile->params->dir); BLI_path_append(sfile->params->dir, sizeof(sfile->params->dir) - 1, file->relpath); - BLI_add_slash(sfile->params->dir); + BLI_path_slash_ensure(sfile->params->dir); } if (file->redirection_path) { STRNCPY(sfile->params->dir, file->redirection_path); @@ -1754,8 +1754,8 @@ static int file_parent_exec(bContext *C, wmOperator *UNUSED(unused)) SpaceFile *sfile = CTX_wm_space_file(C); if (sfile->params) { - if (BLI_parent_dir(sfile->params->dir)) { - BLI_cleanup_dir(BKE_main_blendfile_path(bmain), sfile->params->dir); + if (BLI_path_parent_dir(sfile->params->dir)) { + BLI_path_normalize_dir(BKE_main_blendfile_path(bmain), sfile->params->dir); ED_file_change_dir(C); if (sfile->params->recursion_level > 1) { /* Disable 'dirtree' recursion when going up in tree. */ @@ -2274,7 +2274,7 @@ static void file_expand_directory(bContext *C) sfile->params->dir[3] = '\0'; } else if (BLI_path_is_unc(sfile->params->dir)) { - BLI_cleanup_unc(sfile->params->dir, FILE_MAX_LIBEXTRA); + BLI_path_normalize_unc(sfile->params->dir, FILE_MAX_LIBEXTRA); } #endif } @@ -2291,7 +2291,7 @@ static bool can_create_dir(const char *dir) if (BLI_path_is_unc(dir)) { char parent[PATH_MAX]; BLI_strncpy(parent, dir, PATH_MAX); - BLI_parent_dir(parent); + BLI_path_parent_dir(parent); return BLI_is_dir(parent); } return true; @@ -2338,7 +2338,7 @@ void file_directory_enter_handle(bContext *C, void *UNUSED(arg_unused), void *UN } } - BLI_cleanup_dir(BKE_main_blendfile_path(bmain), sfile->params->dir); + BLI_path_normalize_dir(BKE_main_blendfile_path(bmain), sfile->params->dir); if (filelist_is_dir(sfile->files, sfile->params->dir)) { if (!STREQ(sfile->params->dir, old_dir)) { /* Avoids flickering when nothing's changed. */ @@ -2423,7 +2423,7 @@ void file_filename_enter_handle(bContext *C, void *UNUSED(arg_unused), void *arg /* if directory, open it and empty filename field */ if (filelist_is_dir(sfile->files, filepath)) { - BLI_cleanup_dir(BKE_main_blendfile_path(bmain), filepath); + BLI_path_normalize_dir(BKE_main_blendfile_path(bmain), filepath); BLI_strncpy(sfile->params->dir, filepath, sizeof(sfile->params->dir)); sfile->params->file[0] = '\0'; ED_file_change_dir(C); @@ -2487,7 +2487,7 @@ static bool file_filenum_poll(bContext *C) } /** - * Looks for a string of digits within name (using BLI_stringdec) and adjusts it by add. + * Looks for a string of digits within name (using BLI_path_sequence_decode) and adjusts it by add. */ static void filenum_newname(char *name, size_t name_size, int add) { @@ -2496,7 +2496,7 @@ static void filenum_newname(char *name, size_t name_size, int add) int pic; ushort digits; - pic = BLI_stringdec(name, head, tail, &digits); + pic = BLI_path_sequence_decode(name, head, tail, &digits); /* are we going from 100 -> 99 or from 10 -> 9 */ if (add < 0 && digits > 0) { @@ -2514,7 +2514,7 @@ static void filenum_newname(char *name, size_t name_size, int add) if (pic < 0) { pic = 0; } - BLI_stringenc(name_temp, head, tail, digits, pic); + BLI_path_sequence_encode(name_temp, head, tail, digits, pic); BLI_strncpy(name, name_temp, name_size); } diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 126430986a5..778c27e1a17 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -635,7 +635,7 @@ static bool is_hidden_dot_filename(const char *filename, FileListInternEntry *fi /* filename might actually be a piece of path, in which case we have to check all its parts. */ bool hidden = false; - char *sep = (char *)BLI_last_slash(filename); + char *sep = (char *)BLI_path_slash_rfind(filename); if (!hidden && sep) { char tmp_filename[FILE_MAX_LIBEXTRA]; @@ -654,7 +654,7 @@ static bool is_hidden_dot_filename(const char *filename, FileListInternEntry *fi break; } *sep = '\0'; - sep = (char *)BLI_last_slash(tmp_filename); + sep = (char *)BLI_path_slash_rfind(tmp_filename); } } return hidden; @@ -1023,7 +1023,7 @@ static int filelist_geticon_ex(FileDirEntry *file, FSMenuEntry *tfsm = ED_fsmenu_get_category(fsmenu, categories[i]); char fullpath[FILE_MAX_LIBEXTRA]; BLI_join_dirfile(fullpath, sizeof(fullpath), root, file->relpath); - BLI_add_slash(fullpath); + BLI_path_slash_ensure(fullpath); for (; tfsm; tfsm = tfsm->next) { if (STREQ(tfsm->path, fullpath)) { /* Never want a little folder inside a large one. */ @@ -1112,7 +1112,7 @@ int filelist_geticon(struct FileList *filelist, const int index, const bool is_m static void parent_dir_until_exists_or_default_root(char *dir) { - if (!BLI_parent_dir_until_exists(dir)) { + if (!BLI_path_parent_dir_until_exists(dir)) { #ifdef WIN32 get_default_root(dir); #else @@ -1624,7 +1624,7 @@ void filelist_setdir(struct FileList *filelist, char *r_dir) { BLI_assert(strlen(r_dir) < FILE_MAX_LIBEXTRA); - BLI_cleanup_dir(BKE_main_blendfile_path_from_global(), r_dir); + BLI_path_normalize_dir(BKE_main_blendfile_path_from_global(), r_dir); const bool is_valid_path = filelist->checkdirf(filelist, r_dir, true); BLI_assert(is_valid_path); UNUSED_VARS_NDEBUG(is_valid_path); @@ -2448,7 +2448,7 @@ static int groupname_to_code(const char *group) BLI_assert(group); BLI_strncpy(buf, group, sizeof(buf)); - lslash = (char *)BLI_last_slash(buf); + lslash = (char *)BLI_path_slash_rfind(buf); if (lslash) { lslash[0] = '\0'; } @@ -2816,7 +2816,7 @@ static void filelist_readjob_do(const bool do_lib, BLI_strncpy(dir, filelist->filelist.root, sizeof(dir)); BLI_strncpy(filter_glob, filelist->filter_data.filter_glob, sizeof(filter_glob)); - BLI_cleanup_dir(main_name, dir); + BLI_path_normalize_dir(main_name, dir); td_dir->dir = BLI_strdup(dir); while (!BLI_stack_is_empty(todo_dirs) && !(*stop)) { @@ -2842,7 +2842,7 @@ static void filelist_readjob_do(const bool do_lib, * Note that in the end, this means we 'cache' valid relative subdir once here, * this is actually better. */ BLI_strncpy(rel_subdir, subdir, sizeof(rel_subdir)); - BLI_cleanup_dir(root, rel_subdir); + BLI_path_normalize_dir(root, rel_subdir); BLI_path_rel(rel_subdir, root); if (do_lib) { @@ -2884,7 +2884,7 @@ static void filelist_readjob_do(const bool do_lib, else { /* We have a directory we want to list, add it to todo list! */ BLI_join_dirfile(dir, sizeof(dir), root, entry->relpath); - BLI_cleanup_dir(main_name, dir); + BLI_path_normalize_dir(main_name, dir); td_dir = BLI_stack_push_r(todo_dirs); td_dir->level = recursion_level + 1; td_dir->dir = BLI_strdup(dir); diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index 67c0fae3565..6b594c02c15 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -156,7 +156,7 @@ short ED_fileselect_set_params(SpaceFile *sfile) } if (params->dir[0]) { - BLI_cleanup_dir(blendfile_path, params->dir); + BLI_path_normalize_dir(blendfile_path, params->dir); BLI_path_abs(params->dir, blendfile_path); } @@ -924,7 +924,7 @@ int autocomplete_directory(struct bContext *C, char *str, void *UNUSED(arg_v)) match = UI_autocomplete_end(autocpl, str); if (match == AUTOCOMPLETE_FULL_MATCH) { - BLI_add_slash(str); + BLI_path_slash_ensure(str); } } } diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c index 873091bd68d..3658ebae3a2 100644 --- a/source/blender/editors/space_image/image_buttons.c +++ b/source/blender/editors/space_image/image_buttons.c @@ -1276,7 +1276,7 @@ void uiTemplateImageInfo(uiLayout *layout, bContext *C, Image *ima, ImageUser *i } else if (ima->source == IMA_SRC_SEQUENCE && ibuf) { /* Image sequence frame number + filename */ - const char *filename = BLI_last_slash(ibuf->name); + const char *filename = BLI_path_slash_rfind(ibuf->name); filename = (filename == NULL) ? ibuf->name : filename + 1; BLI_snprintf(str, MAX_IMAGE_INFO_LEN, TIP_("Frame %d: %s"), framenr, filename); } diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 67e64c52051..14245327bdd 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -1794,7 +1794,8 @@ static int image_save_options_init(Main *bmain, } /* append UDIM numbering if not present */ - if (ima->source == IMA_SRC_TILED && (BLI_stringdec(ima->name, NULL, NULL, NULL) != 1001)) { + if (ima->source == IMA_SRC_TILED && + (BLI_path_sequence_decode(ima->name, NULL, NULL, NULL) != 1001)) { int len = strlen(opts->filepath); STR_CONCAT(opts->filepath, len, ".1001"); } diff --git a/source/blender/editors/space_image/image_sequence.c b/source/blender/editors/space_image/image_sequence.c index 8b298045597..e65924d0eb9 100644 --- a/source/blender/editors/space_image/image_sequence.c +++ b/source/blender/editors/space_image/image_sequence.c @@ -74,7 +74,7 @@ static void image_sequence_get_frame_ranges(wmOperator *op, ListBase *ranges) ImageFrame *frame = MEM_callocN(sizeof(ImageFrame), "image_frame"); /* use the first file in the list as base filename */ - frame->framenr = BLI_stringdec(filename, head, tail, &digits); + frame->framenr = BLI_path_sequence_decode(filename, head, tail, &digits); /* still in the same sequence */ if (do_frame_range && (range != NULL) && (STREQLEN(base_head, head, FILE_MAX)) && @@ -127,7 +127,7 @@ static int image_get_udim(char *filepath, ListBase *udim_tiles) ushort digits; char base_head[FILE_MAX], base_tail[FILE_MAX]; - int id = BLI_stringdec(filename, base_head, base_tail, &digits); + int id = BLI_path_sequence_decode(filename, base_head, base_tail, &digits); if (id < 1001 || id >= IMA_UDIM_MAX) { return 0; @@ -144,7 +144,7 @@ static int image_get_udim(char *filepath, ListBase *udim_tiles) continue; } char head[FILE_MAX], tail[FILE_MAX]; - id = BLI_stringdec(dir[i].relname, head, tail, &digits); + id = BLI_path_sequence_decode(dir[i].relname, head, tail, &digits); if (digits > 4 || !(STREQLEN(base_head, head, FILE_MAX)) || !(STREQLEN(base_tail, tail, FILE_MAX))) { @@ -166,7 +166,7 @@ static int image_get_udim(char *filepath, ListBase *udim_tiles) if (is_udim && has_primary) { char primary_filename[FILE_MAX]; - BLI_stringenc(primary_filename, base_head, base_tail, digits, 1001); + BLI_path_sequence_encode(primary_filename, base_head, base_tail, digits, 1001); BLI_join_dirfile(filepath, FILE_MAX, dirname, primary_filename); return max_udim - 1000; } |