[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14770] trunk/blender/source/blender/ python/BPY_interface.c: fix for [#6104] CR generates space at String Creation

Campbell Barton ideasman42 at gmail.com
Fri May 9 19:37:01 CEST 2008


Revision: 14770
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14770
Author:   campbellbarton
Date:     2008-05-09 19:37:01 +0200 (Fri, 09 May 2008)

Log Message:
-----------
fix for [#6104] CR generates space at String Creation
replace windows line endings (\r\n) with \n rather then inserting spaces.

Modified Paths:
--------------
    trunk/blender/source/blender/python/BPY_interface.c

Modified: trunk/blender/source/blender/python/BPY_interface.c
===================================================================
--- trunk/blender/source/blender/python/BPY_interface.c	2008-05-09 17:13:03 UTC (rev 14769)
+++ trunk/blender/source/blender/python/BPY_interface.c	2008-05-09 17:37:01 UTC (rev 14770)
@@ -442,7 +442,7 @@
 		 * not like it) */
 #ifdef WIN32
 		if (upyslen > 3) {
-#else if
+#else
 		if (upyslen > 1) {
 #endif
 			if (dirpath[upyslen-1] == '\\' || dirpath[upyslen-1] == '/') {
@@ -788,7 +788,6 @@
 	Text *text = NULL;
 	BPy_constant *info;
 	int len;
-	char *buffer=NULL, *s;
 	
 	FILE *fp = NULL;
 	
@@ -869,7 +868,6 @@
 		printf("Oops - weakref dict\n");
 		free_libblock( &G.main->script, script );
 		ReleaseGlobalDictionary( py_dict );
-		MEM_freeN( buffer );
 		PyGILState_Release(gilstate);
 		return 0;
 	}
@@ -891,41 +889,41 @@
 		* 'FILE structs for different C libraries can be different and 
 		* incompatible'.
 		* So now we load the script file data to a buffer */
-	
+		char *buffer=NULL, *buffer_ofs=NULL, *b_to, *b_from;
+		
 		fseek( fp, 0L, SEEK_END );
 		len = ftell( fp );
 		fseek( fp, 0L, SEEK_SET );
 	
-		buffer = MEM_mallocN( len + 2, "pyfilebuf" );	/* len+2 to add '\n\0' */
+		buffer = buffer_ofs = MEM_mallocN( len + 2, "pyfilebuf" );	/* len+2 to add '\n\0' */
 		len = fread( buffer, 1, len, fp );
 	
 		buffer[len] = '\n';	/* fix syntax error in files w/o eol */
 		buffer[len + 1] = '\0';
-	
-		/* fast clean-up of dos cr/lf line endings: change '\r' to space */
-	
-		/* we also have to check for line splitters: '\\' */
-		/* to avoid possible syntax errors on dos files on win */
-		/**/
-			/* but first make sure we won't disturb memory below &buffer[0]: */
-			if( *buffer == '\r' )
-			*buffer = ' ';
-	
-		/* now handle the whole buffer */
-		for( s = buffer + 1; *s != '\0'; s++ ) {
-			if( *s == '\r' ) {
-				if( *( s - 1 ) == '\\' ) {	/* special case: long lines split with '\': */
-					*( s - 1 ) = ' ';	/* we write ' \', because '\ ' is a syntax error */
-					*s = '\\';
-				} else
-					*s = ' ';	/* not a split line, just replace '\r' with ' ' */
+		
+		
+		/* fast clean-up of dos cr/lf line endings, remove convert '\r\n's to '\n' */
+		if (*buffer_ofs == '\r' && *(buffer_ofs+1) == '\n') {
+			buffer_ofs++;
+		}
+		b_from = b_to = buffer_ofs;
+		
+		while(*b_from != '\0') {
+			if (*b_from == '\r' && *( b_from+1 ) == '\n') {
+				b_from++;
 			}
+			if (b_from != b_to) {
+				*b_to = *b_from;
+			}
+			b_to++;
+			b_from++;
 		}
-	
+		*b_to = '\0';
+		/* done cleaning the string */
+		
 		fclose( fp );
 		
-		
-		py_res = PyRun_String( buffer, Py_file_input, py_dict, py_dict );
+		py_res = PyRun_String( buffer_ofs, Py_file_input, py_dict, py_dict );
 		MEM_freeN( buffer );
 	}
 





More information about the Bf-blender-cvs mailing list