Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2015-01-26 18:58:02 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-01-26 18:59:24 +0300
commit7bc6fbf158556331e247b714f874b919b9af9ae7 (patch)
treec5b3c883d6a4243f2f11bbac9306abdee07e1207
parentfca515838e70f8bec7028b840bb921a1be9fabbb (diff)
Cleanup: current/parent paths: add helpers in BLI_path_utils.
Also, avoid calling ugly strcmp with '.' or '..', making direct char checks is much cheaper here!
-rw-r--r--source/blender/blenkernel/intern/bpath.c2
-rw-r--r--source/blender/blenkernel/intern/pointcache.c2
-rw-r--r--source/blender/blenlib/BLI_path_util.h9
-rw-r--r--source/blender/blenlib/intern/fileops.c4
-rw-r--r--source/blender/blenlib/intern/path_util.c4
-rw-r--r--source/blender/blenlib/intern/storage.c8
-rw-r--r--source/blender/editors/space_file/file_draw.c6
-rw-r--r--source/blender/editors/space_file/file_ops.c10
-rw-r--r--source/blender/editors/space_file/filelist.c25
-rw-r--r--source/blender/editors/space_file/filesel.c2
10 files changed, 39 insertions, 33 deletions
diff --git a/source/blender/blenkernel/intern/bpath.c b/source/blender/blenkernel/intern/bpath.c
index 3cd26dacebd..e6bfd5c113c 100644
--- a/source/blender/blenkernel/intern/bpath.c
+++ b/source/blender/blenkernel/intern/bpath.c
@@ -228,7 +228,7 @@ static int findFileRecursive(char *filename_new,
while ((de = readdir(dir)) != NULL) {
- if (STREQ(".", de->d_name) || STREQ("..", de->d_name))
+ if (FILENAME_IS_CURRPAR(de->d_name))
continue;
BLI_join_dirfile(path, sizeof(path), dirname, de->d_name);
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index a8add058590..6d1e6618b87 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -2975,7 +2975,7 @@ void BKE_ptcache_remove(void)
return;
while ((de = readdir(dir)) != NULL) {
- if (STREQ(de->d_name, ".") || STREQ(de->d_name, "..")) {
+ if (FILENAME_IS_CURRPAR(de->d_name)) {
/* do nothing */
}
else if (strstr(de->d_name, PTCACHE_EXT)) { /* do we have the right extension?*/
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h
index 8daaff1cea6..7103f8a7597 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -165,6 +165,15 @@ void BLI_string_to_utf8(char *original, char *utf_8, const char *code);
# define FILE_MAX 1024
#endif
+/* Parent and current dir helpers. */
+#define FILENAME_PARENT ".."
+#define FILENAME_CURRENT "."
+
+/* Avoid calling strcmp on one or two chars! */
+#define FILENAME_IS_PARENT(_n) (((_n)[0] == '.') && ((_n)[1] == '.') && ((_n)[2] == '\0'))
+#define FILENAME_IS_CURRENT(_n) (((_n)[0] == '.') && ((_n)[1] == '\0'))
+#define FILENAME_IS_CURRPAR(_n) (((_n)[0] == '.') && (((_n)[1] == '\0') || (((_n)[1] == '.') && ((_n)[2] == '\0'))))
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c
index 8ae99c0da97..d6fe5e52b95 100644
--- a/source/blender/blenlib/intern/fileops.c
+++ b/source/blender/blenlib/intern/fileops.c
@@ -316,7 +316,7 @@ static bool delete_recursive(const char *dir)
while (i--) {
char file[8];
BLI_split_file_part(fl->path, file, sizeof(file));
- if (STREQ(file, ".") || STREQ(file, "..")) {
+ if (FILENAME_IS_CURRPAR(file)) {
/* Skip! */
}
else if (S_ISDIR(fl->type)) {
@@ -584,7 +584,7 @@ static int recursive_operation(const char *startfrom, const char *startto,
for (i = 0; i < n; i++) {
const struct dirent * const dirent = dirlist[i];
- if (STREQ(dirent->d_name, ".") || STREQ(dirent->d_name, ".."))
+ if (FILENAME_IS_CURRPAR(dirent->d_name))
continue;
join_dirfile_alloc(&from_path, &from_alloc_len, from, dirent->d_name);
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 0cc7524bfb5..cc9fbc85a09 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -1116,9 +1116,9 @@ void BLI_make_exist(char *dir)
a = strlen(dir);
- for (BLI_join_dirfile(par_path, sizeof(par_path), dir, "..");
+ for (BLI_join_dirfile(par_path, sizeof(par_path), dir, FILENAME_PARENT);
!(BLI_is_dir(dir) && BLI_exists(par_path));
- BLI_join_dirfile(par_path, sizeof(par_path), dir, ".."))
+ BLI_join_dirfile(par_path, sizeof(par_path), dir, FILENAME_PARENT))
{
a--;
while (dir[a] != SEP) {
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c
index 0d09b50a52c..38a15ab0a6d 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -135,10 +135,10 @@ static int bli_compare(struct direntry *entry1, struct direntry *entry2)
/* OK, now we know their S_IFMT fields are the same, go on to a name comparison */
/* make sure "." and ".." are always first */
- if (STREQ(entry1->relname, ".")) return (-1);
- if (STREQ(entry2->relname, ".")) return (1);
- if (STREQ(entry1->relname, "..")) return (-1);
- if (STREQ(entry2->relname, "..")) return (1);
+ if (FILENAME_IS_CURRENT(entry1->relname)) return (-1);
+ if (FILENAME_IS_CURRENT(entry2->relname)) return (1);
+ if (FILENAME_IS_PARENT(entry1->relname)) return (-1);
+ if (FILENAME_IS_PARENT(entry2->relname)) return (1);
return (BLI_natstrcmp(entry1->relname, entry2->relname));
}
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 836e1f80765..98e0a176b0e 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -239,7 +239,7 @@ static void draw_tile(int sx, int sy, int width, int height, int colorid, int sh
static int get_file_icon(struct direntry *file)
{
if (file->type & S_IFDIR) {
- if (STREQ(file->relname, "..")) {
+ if (FILENAME_IS_PARENT(file->relname)) {
return ICON_FILE_PARENT;
}
if (file->flags & FILE_TYPE_APPLICATIONBUNDLE) {
@@ -529,7 +529,7 @@ void file_draw_list(const bContext *C, ARegion *ar)
int shade = (params->active_file == i) || (file->selflag & FILE_SEL_HIGHLIGHTED) ? 20 : 0;
/* readonly files (".." and ".") must not be drawn as selected - set color back to normal */
- if (STREQ(file->relname, "..") || STREQ(file->relname, ".")) {
+ if (FILENAME_IS_CURRPAR(file->relname)) {
colorid = TH_BACK;
}
draw_tile(sx, sy - 1, layout->tile_w + 4, sfile->layout->tile_h + layout->tile_border_y, colorid, shade);
@@ -538,7 +538,7 @@ void file_draw_list(const bContext *C, ARegion *ar)
UI_draw_roundbox_corner_set(UI_CNR_NONE);
/* don't drag parent or refresh items */
- do_drag = !(STREQ(file->relname, "..") || STREQ(file->relname, "."));
+ do_drag = !(FILENAME_IS_CURRPAR(file->relname));
if (FILE_IMGDISPLAY == params->display) {
is_icon = 0;
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 697ac23c84d..ba6f91e8301 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -183,11 +183,11 @@ static FileSelect file_select_do(bContext *C, int selected_idx, bool do_diropen)
retval = FILE_SELECT_DIR;
}
/* the path is too long and we are not going up! */
- else if (!STREQ(file->relname, "..") && strlen(params->dir) + strlen(file->relname) >= FILE_MAX) {
+ else if (!FILENAME_IS_PARENT(file->relname) && strlen(params->dir) + strlen(file->relname) >= FILE_MAX) {
// XXX error("Path too long, cannot enter this directory");
}
else {
- if (STREQ(file->relname, "..")) {
+ if (FILENAME_IS_PARENT(file->relname)) {
/* avoids /../../ */
BLI_parent_dir(params->dir);
}
@@ -269,7 +269,7 @@ static int file_border_select_modal(bContext *C, wmOperator *op, const wmEvent *
for (idx = sel.last; idx >= 0; idx--) {
struct direntry *file = filelist_file(sfile->files, idx);
- if (STREQ(file->relname, "..") || STREQ(file->relname, ".")) {
+ if (FILENAME_IS_CURRPAR(file->relname)) {
file->selflag &= ~FILE_SEL_HIGHLIGHTED;
}
@@ -362,7 +362,7 @@ static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
if (idx >= 0) {
struct direntry *file = filelist_file(sfile->files, idx);
- if (STREQ(file->relname, "..") || STREQ(file->relname, ".")) {
+ if (FILENAME_IS_CURRPAR(file->relname)) {
/* skip - If a readonly file (".." or ".") is selected, skip deselect all! */
}
else {
@@ -1531,7 +1531,7 @@ static int file_rename_poll(bContext *C)
if (idx >= 0) {
struct direntry *file = filelist_file(sfile->files, idx);
- if (STREQ(file->relname, "..") || STREQ(file->relname, ".")) {
+ if (FILENAME_IS_CURRPAR(file->relname)) {
poll = 0;
}
}
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index bf9c6626706..edf0bb025c7 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -237,9 +237,6 @@ typedef struct FileList {
bool (*filterf)(struct direntry *, const char *, FileListFilter *);
} FileList;
-#define FILENAME_IS_BREADCRUMBS(_n) \
- ((_n)[0] == '.' && ((_n)[1] == '\0' || ((_n)[1] == '.' && (_n)[2] == '\0')))
-
#define SPECIAL_IMG_SIZE 48
#define SPECIAL_IMG_ROWS 4
#define SPECIAL_IMG_COLS 4
@@ -304,10 +301,10 @@ static int compare_direntry_generic(const struct direntry *entry1, const struct
if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1);
/* make sure "." and ".." are always first */
- if (STREQ(entry1->relname, ".")) return (-1);
- if (STREQ(entry2->relname, ".")) return (1);
- if (STREQ(entry1->relname, "..")) return (-1);
- if (STREQ(entry2->relname, "..")) return (1);
+ if (FILENAME_IS_CURRENT(entry1->relname)) return (-1);
+ if (FILENAME_IS_CURRENT(entry2->relname)) return (1);
+ if (FILENAME_IS_PARENT(entry1->relname)) return (-1);
+ if (FILENAME_IS_PARENT(entry2->relname)) return (1);
return 0;
}
@@ -447,7 +444,7 @@ static bool is_filtered_file(struct direntry *file, const char *UNUSED(root), Fi
{
bool is_filtered = !is_hidden_file(file->relname, filter);
- if (is_filtered && filter->filter && !FILENAME_IS_BREADCRUMBS(file->relname)) {
+ if (is_filtered && filter->filter && !FILENAME_IS_CURRPAR(file->relname)) {
if ((file->type & S_IFDIR) && !(filter->filter & FILE_TYPE_FOLDER)) {
is_filtered = false;
}
@@ -471,7 +468,7 @@ static bool is_filtered_lib(struct direntry *file, const char *root, FileListFil
if (BLO_is_a_library(root, dir, group)) {
is_filtered = !is_hidden_file(file->relname, filter);
- if (is_filtered && filter->filter && !FILENAME_IS_BREADCRUMBS(file->relname)) {
+ if (is_filtered && filter->filter && !FILENAME_IS_CURRPAR(file->relname)) {
if (is_filtered && (filter->filter_search[0] != '\0')) {
if (fnmatch(filter->filter_search, file->relname, FNM_CASEFOLD) != 0) {
is_filtered = false;
@@ -634,10 +631,10 @@ ImBuf *filelist_geticon(struct FileList *filelist, const int index)
fidx = filelist->fidx[index];
file = &filelist->filelist[fidx];
if (file->type & S_IFDIR) {
- if (STREQ(filelist->filelist[fidx].relname, "..")) {
+ if (FILENAME_IS_PARENT(filelist->filelist[fidx].relname)) {
ibuf = gSpecialFileImages[SPECIAL_IMG_PARENT];
}
- else if (STREQ(filelist->filelist[fidx].relname, ".")) {
+ else if (FILENAME_IS_CURRENT(filelist->filelist[fidx].relname)) {
ibuf = gSpecialFileImages[SPECIAL_IMG_REFRESH];
}
else {
@@ -1117,7 +1114,7 @@ static void filelist_from_library(struct FileList *filelist)
filelist->filelist = malloc(filelist->numfiles * sizeof(*filelist->filelist));
memset(filelist->filelist, 0, filelist->numfiles * sizeof(*filelist->filelist));
- filelist->filelist[0].relname = BLI_strdup("..");
+ filelist->filelist[0].relname = BLI_strdup(FILENAME_PARENT);
filelist->filelist[0].type |= S_IFDIR;
for (i = 0, l = names; i < nnames; i++, l = l->next) {
@@ -1192,7 +1189,7 @@ static void filelist_from_main(struct FileList *filelist)
filelist->filelist[a].type |= S_IFDIR;
}
- filelist->filelist[0].relname = BLI_strdup("..");
+ filelist->filelist[0].relname = BLI_strdup(FILENAME_PARENT);
filelist->filelist[1].relname = BLI_strdup("Scene");
filelist->filelist[2].relname = BLI_strdup("Object");
filelist->filelist[3].relname = BLI_strdup("Mesh");
@@ -1245,7 +1242,7 @@ static void filelist_from_main(struct FileList *filelist)
if (!filelist->filter_data.hide_parent) {
memset(&(filelist->filelist[0]), 0, sizeof(struct direntry));
- filelist->filelist[0].relname = BLI_strdup("..");
+ filelist->filelist[0].relname = BLI_strdup(FILENAME_PARENT);
filelist->filelist[0].type |= S_IFDIR;
files++;
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c
index 815faa1c223..c452f2e1ff4 100644
--- a/source/blender/editors/space_file/filesel.c
+++ b/source/blender/editors/space_file/filesel.c
@@ -669,7 +669,7 @@ int autocomplete_directory(struct bContext *C, char *str, void *UNUSED(arg_v))
AutoComplete *autocpl = UI_autocomplete_begin(str, FILE_MAX);
while ((de = readdir(dir)) != NULL) {
- if (STREQ(de->d_name, ".") || STREQ(de->d_name, "..")) {
+ if (FILENAME_IS_CURRPAR(de->d_name)) {
/* pass */
}
else {