Convenience defines SEP and ALTSEP (python has these), move BLI_*_slash function into path_util.h since these are not fileops.
This commit is contained in:
parent
676829ccba
commit
a49d1c20f1
@ -54,10 +54,6 @@ int BLI_gzip(char *from, char *to);
|
|||||||
int BLI_delete(char *file, int dir, int recursive);
|
int BLI_delete(char *file, int dir, int recursive);
|
||||||
int BLI_move(char *file, char *to);
|
int BLI_move(char *file, char *to);
|
||||||
int BLI_touch(const char *file);
|
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 :( */
|
/* only for the sane unix world: direct calls to system functions :( */
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
|
@ -88,6 +88,14 @@ char *BLI_get_user_folder_notest(int folder_id, char *subfolder);
|
|||||||
#define BLENDER_SYSTEM_FORMAT "%s/blender/%s"
|
#define BLENDER_SYSTEM_FORMAT "%s/blender/%s"
|
||||||
#endif
|
#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(const char *env, const char *val);
|
||||||
void BLI_setenv_if_new(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);
|
void BLI_join_dirfile(char *string, const char *dir, const char *file);
|
||||||
char *BLI_path_basename(char *path);
|
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);
|
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);
|
void BLI_getlastdir(const char* dir, char *last, int maxlen);
|
||||||
int BLI_testextensie(const char *str, const char *ext);
|
int BLI_testextensie(const char *str, const char *ext);
|
||||||
int BLI_testextensie_array(const char *str, const char **ext_array);
|
int BLI_testextensie_array(const char *str, const char **ext_array);
|
||||||
|
@ -53,68 +53,6 @@
|
|||||||
|
|
||||||
#include "BLO_sys_types.h" // for intptr_t support
|
#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".
|
/* gzip the file in from and write it to "to".
|
||||||
return -1 if zlib fails, -2 if the originating file does not exist
|
return -1 if zlib fails, -2 if the originating file does not exist
|
||||||
|
@ -471,11 +471,7 @@ int BLI_has_parent(char *path)
|
|||||||
|
|
||||||
int BLI_parent_dir(char *path)
|
int BLI_parent_dir(char *path)
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
static char parent_dir[]= {'.', '.', SEP, '\0'}; /* "../" or "..\\" */
|
||||||
static char *parent_dir="..\\";
|
|
||||||
#else
|
|
||||||
static char *parent_dir="../";
|
|
||||||
#endif
|
|
||||||
char tmp[FILE_MAXDIR+FILE_MAXFILE+4];
|
char tmp[FILE_MAXDIR+FILE_MAXFILE+4];
|
||||||
BLI_strncpy(tmp, path, sizeof(tmp)-4);
|
BLI_strncpy(tmp, path, sizeof(tmp)-4);
|
||||||
BLI_add_slash(tmp);
|
BLI_add_slash(tmp);
|
||||||
@ -1143,42 +1139,28 @@ void BLI_char_switch(char *string, char from, char to)
|
|||||||
void BLI_make_exist(char *dir) {
|
void BLI_make_exist(char *dir) {
|
||||||
int a;
|
int a;
|
||||||
|
|
||||||
#ifdef WIN32
|
BLI_char_switch(dir, ALTSEP, SEP);
|
||||||
BLI_char_switch(dir, '/', '\\');
|
|
||||||
#else
|
|
||||||
BLI_char_switch(dir, '\\', '/');
|
|
||||||
#endif
|
|
||||||
|
|
||||||
a = strlen(dir);
|
a = strlen(dir);
|
||||||
|
|
||||||
|
while(BLI_is_dir(dir) == 0){
|
||||||
|
a --;
|
||||||
|
while(dir[a] != SEP){
|
||||||
|
a--;
|
||||||
|
if (a <= 0) break;
|
||||||
|
}
|
||||||
|
if (a >= 0) {
|
||||||
|
dir[a+1] = '\0';
|
||||||
|
}
|
||||||
|
else {
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
while(BLI_is_dir(dir) == 0){
|
|
||||||
a --;
|
|
||||||
while(dir[a] != '\\'){
|
|
||||||
a--;
|
|
||||||
if (a <= 0) break;
|
|
||||||
}
|
|
||||||
if (a >= 0) dir[a+1] = 0;
|
|
||||||
else {
|
|
||||||
/* defaulting to drive (usually 'C:') of Windows installation */
|
|
||||||
get_default_root(dir);
|
get_default_root(dir);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
#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,"/");
|
strcpy(dir,"/");
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BLI_make_existing_file(char *name)
|
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;
|
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)
|
static int add_win32_extension(char *name)
|
||||||
{
|
{
|
||||||
|
@ -59,6 +59,7 @@
|
|||||||
|
|
||||||
#include "BLI_blenlib.h"
|
#include "BLI_blenlib.h"
|
||||||
#include "BLI_linklist.h"
|
#include "BLI_linklist.h"
|
||||||
|
#include "BLI_path_util.h"
|
||||||
#include "BLI_storage_types.h"
|
#include "BLI_storage_types.h"
|
||||||
#include "BLI_dynstr.h"
|
#include "BLI_dynstr.h"
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include "compile.h" /* for the PyCodeObject */
|
#include "compile.h" /* for the PyCodeObject */
|
||||||
#include "eval.h" /* for PyEval_EvalCode */
|
#include "eval.h" /* for PyEval_EvalCode */
|
||||||
#include "osdefs.h" /* for 'SEP' */
|
|
||||||
|
|
||||||
#include "bpy_internal_import.h"
|
#include "bpy_internal_import.h"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user