diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-05-09 21:37:01 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-05-09 21:37:01 +0400 |
commit | f115a5f789056a08ca194ada67380ba06350a3bb (patch) | |
tree | 344768a22dd6bad9a7e559c8c33504ecbaadcd82 /source/blender/python | |
parent | 694dce0e632b032117f311db1d9765f24c61c372 (diff) |
fix for [#6104] CR generates space at String Creation
replace windows line endings (\r\n) with \n rather then inserting spaces.
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/BPY_interface.c | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c index 1496495e5aa..257203908b1 100644 --- a/source/blender/python/BPY_interface.c +++ b/source/blender/python/BPY_interface.c @@ -442,7 +442,7 @@ void BPY_rebuild_syspath( void ) * 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 @@ int BPY_run_script(Script *script) Text *text = NULL; BPy_constant *info; int len; - char *buffer=NULL, *s; FILE *fp = NULL; @@ -869,7 +868,6 @@ int BPY_run_script(Script *script) 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 @@ int BPY_run_script(Script *script) * '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++; } - - fclose( fp ); + *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 ); } |