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:
authorCampbell Barton <ideasman42@gmail.com>2010-10-27 10:41:48 +0400
committerCampbell Barton <ideasman42@gmail.com>2010-10-27 10:41:48 +0400
commita49d1c20f1804eae46ee2f60c82114363b47e3ea (patch)
tree3b4588fa05108e0b7df67d1bdc1cbd1de74e7466 /source/blender/blenlib
parent676829ccba10da1d83f809ad243685707bb7543d (diff)
Convenience defines SEP and ALTSEP (python has these), move BLI_*_slash function into path_util.h since these are not fileops.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_fileops.h4
-rw-r--r--source/blender/blenlib/BLI_path_util.h13
-rw-r--r--source/blender/blenlib/intern/fileops.c62
-rw-r--r--source/blender/blenlib/intern/path_util.c99
4 files changed, 84 insertions, 94 deletions
diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h
index b721a21b1b9..552de7b170c 100644
--- a/source/blender/blenlib/BLI_fileops.h
+++ b/source/blender/blenlib/BLI_fileops.h
@@ -54,10 +54,6 @@ int BLI_gzip(char *from, char *to);
int BLI_delete(char *file, int dir, int recursive);
int BLI_move(char *file, char *to);
int BLI_touch(const char *file);
-char *BLI_last_slash(const char *string);
-int BLI_add_slash(char *string);
-void BLI_del_slash(char *string);
-char *first_slash(char *string);
/* only for the sane unix world: direct calls to system functions :( */
#ifndef WIN32
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h
index b9a4468fe57..5dbb137ec07 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -88,6 +88,14 @@ char *BLI_get_user_folder_notest(int folder_id, char *subfolder);
#define BLENDER_SYSTEM_FORMAT "%s/blender/%s"
#endif
+#ifdef WIN32
+#define SEP '\\'
+#define ALTSEP '/'
+#else
+#define SEP '/'
+#define ALTSEP '\\'
+#endif
+
void BLI_setenv(const char *env, const char *val);
void BLI_setenv_if_new(const char *env, const char* val);
@@ -98,6 +106,11 @@ void BLI_split_dirfile(const char *string, char *dir, char *file);
void BLI_join_dirfile(char *string, const char *dir, const char *file);
char *BLI_path_basename(char *path);
int BKE_rebase_path(char *abs, int abs_size, char *rel, int rel_size, const char *base_dir, const char *src_dir, const char *dest_dir);
+char *BLI_last_slash(const char *string);
+int BLI_add_slash(char *string);
+void BLI_del_slash(char *string);
+char *BLI_first_slash(char *string);
+
void BLI_getlastdir(const char* dir, char *last, int maxlen);
int BLI_testextensie(const char *str, const char *ext);
int BLI_testextensie_array(const char *str, const char **ext_array);
diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c
index 06b427240ba..180cfdbbc5a 100644
--- a/source/blender/blenlib/intern/fileops.c
+++ b/source/blender/blenlib/intern/fileops.c
@@ -53,68 +53,6 @@
#include "BLO_sys_types.h" // for intptr_t support
-/* implementations: */
-char *first_slash(char *string) {
- char *ffslash, *fbslash;
-
- ffslash= strchr(string, '/');
- fbslash= strchr(string, '\\');
-
- if (!ffslash) return fbslash;
- else if (!fbslash) return ffslash;
-
- if ((intptr_t)ffslash < (intptr_t)fbslash) return ffslash;
- else return fbslash;
-}
-
-char *BLI_last_slash(const char *string) {
- char *lfslash, *lbslash;
-
- lfslash= strrchr(string, '/');
- lbslash= strrchr(string, '\\');
-
- if (!lfslash) return lbslash;
- else if (!lbslash) return lfslash;
-
- if ((intptr_t)lfslash < (intptr_t)lbslash) return lbslash;
- else return lfslash;
-}
-
-/* adds a slash if there isnt one there already */
-int BLI_add_slash(char *string) {
- int len = strlen(string);
-#ifdef WIN32
- if (len==0 || string[len-1]!='\\') {
- string[len] = '\\';
- string[len+1] = '\0';
- return len+1;
- }
-#else
- if (len==0 || string[len-1]!='/') {
- string[len] = '/';
- string[len+1] = '\0';
- return len+1;
- }
-#endif
- return len;
-}
-
-/* removes a slash if there is one */
-void BLI_del_slash(char *string) {
- int len = strlen(string);
- while (len) {
-#ifdef WIN32
- if (string[len-1]=='\\') {
-#else
- if (string[len-1]=='/') {
-#endif
- string[len-1] = '\0';
- len--;
- } else {
- break;
- }
- }
-}
/* gzip the file in from and write it to "to".
return -1 if zlib fails, -2 if the originating file does not exist
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 61b525d50af..8a6f6205eac 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -471,11 +471,7 @@ int BLI_has_parent(char *path)
int BLI_parent_dir(char *path)
{
-#ifdef WIN32
- static char *parent_dir="..\\";
-#else
- static char *parent_dir="../";
-#endif
+ static char parent_dir[]= {'.', '.', SEP, '\0'}; /* "../" or "..\\" */
char tmp[FILE_MAXDIR+FILE_MAXFILE+4];
BLI_strncpy(tmp, path, sizeof(tmp)-4);
BLI_add_slash(tmp);
@@ -1143,42 +1139,28 @@ void BLI_char_switch(char *string, char from, char to)
void BLI_make_exist(char *dir) {
int a;
- #ifdef WIN32
- BLI_char_switch(dir, '/', '\\');
- #else
- BLI_char_switch(dir, '\\', '/');
- #endif
-
+ BLI_char_switch(dir, ALTSEP, SEP);
+
a = strlen(dir);
-
-#ifdef WIN32
+
while(BLI_is_dir(dir) == 0){
a --;
- while(dir[a] != '\\'){
+ while(dir[a] != SEP){
a--;
if (a <= 0) break;
}
- if (a >= 0) dir[a+1] = 0;
+ if (a >= 0) {
+ dir[a+1] = '\0';
+ }
else {
- /* defaulting to drive (usually 'C:') of Windows installation */
+#ifdef WIN32
get_default_root(dir);
- break;
- }
- }
#else
- while(BLI_is_dir(dir) == 0){
- a --;
- while(dir[a] != '/'){
- a--;
- if (a <= 0) break;
- }
- if (a >= 0) dir[a+1] = 0;
- else {
strcpy(dir,"/");
+#endif
break;
}
}
-#endif
}
void BLI_make_existing_file(char *name)
@@ -1495,6 +1477,67 @@ int BKE_rebase_path(char *abs, int abs_size, char *rel, int rel_size, const char
return 1;
}
+char *BLI_first_slash(char *string) {
+ char *ffslash, *fbslash;
+
+ ffslash= strchr(string, '/');
+ fbslash= strchr(string, '\\');
+
+ if (!ffslash) return fbslash;
+ else if (!fbslash) return ffslash;
+
+ if ((intptr_t)ffslash < (intptr_t)fbslash) return ffslash;
+ else return fbslash;
+}
+
+char *BLI_last_slash(const char *string) {
+ char *lfslash, *lbslash;
+
+ lfslash= strrchr(string, '/');
+ lbslash= strrchr(string, '\\');
+
+ if (!lfslash) return lbslash;
+ else if (!lbslash) return lfslash;
+
+ if ((intptr_t)lfslash < (intptr_t)lbslash) return lbslash;
+ else return lfslash;
+}
+
+/* adds a slash if there isnt one there already */
+int BLI_add_slash(char *string) {
+ int len = strlen(string);
+#ifdef WIN32
+ if (len==0 || string[len-1]!='\\') {
+ string[len] = '\\';
+ string[len+1] = '\0';
+ return len+1;
+ }
+#else
+ if (len==0 || string[len-1]!='/') {
+ string[len] = '/';
+ string[len+1] = '\0';
+ return len+1;
+ }
+#endif
+ return len;
+}
+
+/* removes a slash if there is one */
+void BLI_del_slash(char *string) {
+ int len = strlen(string);
+ while (len) {
+#ifdef WIN32
+ if (string[len-1]=='\\') {
+#else
+ if (string[len-1]=='/') {
+#endif
+ string[len-1] = '\0';
+ len--;
+ } else {
+ break;
+ }
+ }
+}
static int add_win32_extension(char *name)
{