[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32729] trunk/blender/source/blender: Convenience defines SEP and ALTSEP (python has these), move BLI_*_slash function into path_util.h since these are not fileops.

Campbell Barton ideasman42 at gmail.com
Wed Oct 27 08:41:53 CEST 2010


Revision: 32729
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32729
Author:   campbellbarton
Date:     2010-10-27 08:41:48 +0200 (Wed, 27 Oct 2010)

Log Message:
-----------
Convenience defines SEP and ALTSEP (python has these), move BLI_*_slash function into path_util.h since these are not fileops.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_fileops.h
    trunk/blender/source/blender/blenlib/BLI_path_util.h
    trunk/blender/source/blender/blenlib/intern/fileops.c
    trunk/blender/source/blender/blenlib/intern/path_util.c
    trunk/blender/source/blender/editors/space_file/filesel.c
    trunk/blender/source/blender/python/generic/bpy_internal_import.c

Modified: trunk/blender/source/blender/blenlib/BLI_fileops.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_fileops.h	2010-10-27 06:05:22 UTC (rev 32728)
+++ trunk/blender/source/blender/blenlib/BLI_fileops.h	2010-10-27 06:41:48 UTC (rev 32729)
@@ -54,10 +54,6 @@
 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

Modified: trunk/blender/source/blender/blenlib/BLI_path_util.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_path_util.h	2010-10-27 06:05:22 UTC (rev 32728)
+++ trunk/blender/source/blender/blenlib/BLI_path_util.h	2010-10-27 06:41:48 UTC (rev 32729)
@@ -88,6 +88,14 @@
 #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_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);

Modified: trunk/blender/source/blender/blenlib/intern/fileops.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/fileops.c	2010-10-27 06:05:22 UTC (rev 32728)
+++ trunk/blender/source/blender/blenlib/intern/fileops.c	2010-10-27 06:41:48 UTC (rev 32729)
@@ -53,69 +53,7 @@
 
 #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
  note: will remove the "from" file

Modified: trunk/blender/source/blender/blenlib/intern/path_util.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/path_util.c	2010-10-27 06:05:22 UTC (rev 32728)
+++ trunk/blender/source/blender/blenlib/intern/path_util.c	2010-10-27 06:41:48 UTC (rev 32729)
@@ -471,11 +471,7 @@
 
 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_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,7 +1477,68 @@
 	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)
 {
 	int retval = 0;

Modified: trunk/blender/source/blender/editors/space_file/filesel.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/filesel.c	2010-10-27 06:05:22 UTC (rev 32728)
+++ trunk/blender/source/blender/editors/space_file/filesel.c	2010-10-27 06:41:48 UTC (rev 32729)
@@ -59,6 +59,7 @@
 
 #include "BLI_blenlib.h"
 #include "BLI_linklist.h"
+#include "BLI_path_util.h"
 #include "BLI_storage_types.h"
 #include "BLI_dynstr.h"
 

Modified: trunk/blender/source/blender/python/generic/bpy_internal_import.c
===================================================================
--- trunk/blender/source/blender/python/generic/bpy_internal_import.c	2010-10-27 06:05:22 UTC (rev 32728)
+++ trunk/blender/source/blender/python/generic/bpy_internal_import.c	2010-10-27 06:41:48 UTC (rev 32729)
@@ -29,7 +29,6 @@
 #include <Python.h>
 #include "compile.h"	/* for the PyCodeObject */
 #include "eval.h"		/* for PyEval_EvalCode */
-#include "osdefs.h"		/* for 'SEP' */
 
 #include "bpy_internal_import.h"
 





More information about the Bf-blender-cvs mailing list