[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14555] trunk/blender/source/blender: BLI_split_dirfile was being used in cases it should not have been,

Campbell Barton ideasman42 at gmail.com
Sat Apr 26 15:09:52 CEST 2008


Revision: 14555
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14555
Author:   campbellbarton
Date:     2008-04-26 15:08:57 +0200 (Sat, 26 Apr 2008)

Log Message:
-----------
BLI_split_dirfile was being used in cases it should not have been,
Added BLI_split_dirfile_basic, that only splits the path into directory and file. without checking the dir exists or creating it, without changing the original string that is passed to it.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/pointcache.c
    trunk/blender/source/blender/blenkernel/intern/text.c
    trunk/blender/source/blender/blenlib/BLI_blenlib.h
    trunk/blender/source/blender/blenlib/intern/bpath.c
    trunk/blender/source/blender/blenlib/intern/util.c
    trunk/blender/source/blender/python/BPY_interface.c
    trunk/blender/source/blender/src/editscreen.c
    trunk/blender/source/blender/src/usiblender.c

Modified: trunk/blender/source/blender/blenkernel/intern/pointcache.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/pointcache.c	2008-04-25 20:52:40 UTC (rev 14554)
+++ trunk/blender/source/blender/blenkernel/intern/pointcache.c	2008-04-26 13:08:57 UTC (rev 14555)
@@ -177,7 +177,7 @@
 
 		blendfilename= (lib)? lib->filename: G.sce;
 
-		BLI_split_dirfile(blendfilename, dir, file);
+		BLI_split_dirfile_basic(blendfilename, NULL, file);
 		i = strlen(file);
 		
 		/* remove .blend */

Modified: trunk/blender/source/blender/blenkernel/intern/text.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/text.c	2008-04-25 20:52:40 UTC (rev 14554)
+++ trunk/blender/source/blender/blenkernel/intern/text.c	2008-04-26 13:08:57 UTC (rev 14555)
@@ -212,7 +212,6 @@
 	int i, llen, len;
 	unsigned char *buffer;
 	TextLine *tmp;
-	char sdir[FILE_MAXDIR];
 	char sfile[FILE_MAXFILE];
 	char str[FILE_MAXDIR+FILE_MAXFILE];
 
@@ -220,7 +219,7 @@
 	
 	BLI_strncpy(str, text->name, FILE_MAXDIR+FILE_MAXFILE);
 	BLI_convertstringcode(str, G.sce, G.scene->r.cfra);
-	BLI_split_dirfile(str, sdir, sfile);
+	BLI_split_dirfile_basic(str, NULL, sfile);
 	
 	fp= fopen(str, "r");
 	if(fp==NULL) return 0;
@@ -312,14 +311,13 @@
 	unsigned char *buffer;
 	TextLine *tmp;
 	Text *ta;
-	char sdir[FILE_MAXDIR];
 	char sfile[FILE_MAXFILE];
 	char str[FILE_MAXDIR+FILE_MAXFILE];
 
 	BLI_strncpy(str, file, FILE_MAXDIR+FILE_MAXFILE);
 	if (G.scene) /* can be NULL (bg mode) */
 		BLI_convertstringcode(str, G.sce, G.scene->r.cfra);
-	BLI_split_dirfile(str, sdir, sfile);
+	BLI_split_dirfile_basic(str, NULL, sfile);
 	
 	fp= fopen(str, "r");
 	if(fp==NULL) return NULL;

Modified: trunk/blender/source/blender/blenlib/BLI_blenlib.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_blenlib.h	2008-04-25 20:52:40 UTC (rev 14554)
+++ trunk/blender/source/blender/blenlib/BLI_blenlib.h	2008-04-26 13:08:57 UTC (rev 14555)
@@ -96,6 +96,7 @@
 void BLI_make_exist(char *dir);
 void BLI_make_existing_file(char *name);
 void BLI_split_dirfile(char *string, char *dir, char *file);
+void BLI_split_dirfile_basic(const char *string, char *dir, char *file);
 void BLI_join_dirfile(char *string, const char *dir, const char *file);
 int BLI_testextensie(const char *str, const char *ext);
 void addlisttolist(ListBase *list1, ListBase *list2);

Modified: trunk/blender/source/blender/blenlib/intern/bpath.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/bpath.c	2008-04-25 20:52:40 UTC (rev 14554)
+++ trunk/blender/source/blender/blenlib/intern/bpath.c	2008-04-26 13:08:57 UTC (rev 14555)
@@ -259,22 +259,7 @@
 	
 	if (SEQ_HAS_PATH(seq)) {
 		if (seq->type == SEQ_IMAGE || seq->type == SEQ_MOVIE) {
-			
-			int lslash, i = 0;
-			for (i=0; path[i]!='\0'; i++) {
-				if (path[i]=='\\' || path[i]=='/')
-					lslash = i+1;
-			}
-			
-			if (lslash) {
-				BLI_strncpy( seq->strip->dir, path, lslash+1); /* +1 to include the slash and the last char */
-			} else {
-				path[0] = '\0';
-			}
-			
-			if (seq->strip->stripdata) { /* should always be true! */
-				BLI_strncpy( seq->strip->stripdata->name, path+lslash, sizeof(seq->strip->stripdata->name));
-			}
+			BLI_split_dirfile_basic(path, seq->strip->dir, seq->strip->stripdata->name);
 		} else {
 			/* simple case */
 			BLI_strncpy(seq->strip->dir, path, sizeof(seq->strip->dir));
@@ -657,7 +642,7 @@
 	
 	waitcursor( 1 );
 	
-	BLI_split_dirfile(str, dirname, dummyname);
+	BLI_split_dirfile_basic(str, dirname, NULL);
 	
 	BLI_bpathIterator_init(&bpi);
 	
@@ -678,7 +663,7 @@
 				/* can the dir be opened? */
 				filesize = -1;
 				recur_depth = 0;
-				BLI_split_dirfile(filepath, dummyname, filename); /* the file to find */
+				BLI_split_dirfile_basic(filepath, NULL, filename); /* the file to find */
 				
 				findFileRecursive(filename_new, dirname, filename, &filesize, &recur_depth);
 				if (filesize == -1) { /* could not open dir */

Modified: trunk/blender/source/blender/blenlib/intern/util.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/util.c	2008-04-25 20:52:40 UTC (rev 14554)
+++ trunk/blender/source/blender/blenlib/intern/util.c	2008-04-26 13:08:57 UTC (rev 14555)
@@ -1426,8 +1426,41 @@
 	return (retval);
 }
 
+/*
+ * This is a simple version of BLI_split_dirfile that has the following advantages...
+ * 
+ * Converts "/foo/bar.txt" to "/foo/" and "bar.txt"
+ * - wont change 'string'
+ * - wont create any directories
+ * - dosnt use CWD, or deal with relative paths.
+ * - Only fill's in *dir and *file when they are non NULL
+ * */
+void BLI_split_dirfile_basic(const char *string, char *dir, char *file)
+{
+	int lslash=0, i = 0;
+	for (i=0; string[i]!='\0'; i++) {
+		if (string[i]=='\\' || string[i]=='/')
+			lslash = i+1;
+	}
+	if (dir) {
+		if (lslash) {
+			BLI_strncpy( dir, string, lslash+1); /* +1 to include the slash and the last char */
+		} else {
+			dir[0] = '\0';
+		}
+	}
+	
+	if (file) {
+		strcpy( file, string+lslash);
+	}
+}
 
-/* warning, can modify 'string' */
+
+/* Warning,
+ * - May modify 'string' variable
+ * - May create the directory if it dosnt exist
+ * if this is not needed use BLI_split_dirfile_basic(...)
+ */
 void BLI_split_dirfile(char *string, char *dir, char *file)
 {
 	int a;

Modified: trunk/blender/source/blender/python/BPY_interface.c
===================================================================
--- trunk/blender/source/blender/python/BPY_interface.c	2008-04-25 20:52:40 UTC (rev 14554)
+++ trunk/blender/source/blender/python/BPY_interface.c	2008-04-26 13:08:57 UTC (rev 14555)
@@ -796,7 +796,7 @@
 		
 		if (bpyhome) {
 			BLI_strncpy(ftmp, script->scriptname, sizeof(ftmp));
-			BLI_split_dirfile(ftmp, fpath, fname); /* get the filename only - fname */
+			BLI_split_dirfile_basic(ftmp, NULL, fname); /* get the filename only - fname */
 			BLI_strncpy(fpath, bpy_gethome(1), sizeof(fpath));
 			BLI_add_slash(fpath);
 			strcat(fpath, fname);

Modified: trunk/blender/source/blender/src/editscreen.c
===================================================================
--- trunk/blender/source/blender/src/editscreen.c	2008-04-25 20:52:40 UTC (rev 14554)
+++ trunk/blender/source/blender/src/editscreen.c	2008-04-26 13:08:57 UTC (rev 14555)
@@ -1589,7 +1589,7 @@
 	char dir[FILE_MAXDIR];
 	char file[FILE_MAXFILE];
 
-	BLI_split_dirfile(filename, dir, file);
+	BLI_split_dirfile_basic(filename, dir, file);
 
 	if(BLI_streq(file, ".B.blend") || filename[0] =='\0')
 		sprintf(str, "Blender");

Modified: trunk/blender/source/blender/src/usiblender.c
===================================================================
--- trunk/blender/source/blender/src/usiblender.c	2008-04-25 20:52:40 UTC (rev 14554)
+++ trunk/blender/source/blender/src/usiblender.c	2008-04-26 13:08:57 UTC (rev 14555)
@@ -786,7 +786,7 @@
 	fsmenu_append_separator();
 	
 	/* add last saved file */
-	BLI_split_dirfile(G.sce, name, filename); /* G.sce shouldn't be relative */
+	BLI_split_dirfile_basic(G.sce, name, filename); /* G.sce shouldn't be relative */
 	
 	fsmenu_insert_entry(name, 0, 0);
 	





More information about the Bf-blender-cvs mailing list