diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-09-15 05:32:53 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-09-15 05:32:53 +0400 |
commit | ac86c04401686a9d119ea84ad489ca3db7403e5c (patch) | |
tree | 123807fb6ccd3325c9d5b348992be9176eadf688 /source/blender/python | |
parent | 2c31cc4503ee4de8e8c4ff5665ed1e7dbabfb832 (diff) |
added BLI_convertstringcwd, used so command line blendfiles and python scripts can be relative to the current path.
- was alredy doing this for blendfiles, but better to have in its own function.
header_text.c - renamed PATH_MAX, was defined by system includes.
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/BPY_extern.h | 2 | ||||
-rw-r--r-- | source/blender/python/BPY_interface.c | 34 |
2 files changed, 22 insertions, 14 deletions
diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h index 3d9b45051fb..4b96ef3fdf0 100644 --- a/source/blender/python/BPY_extern.h +++ b/source/blender/python/BPY_extern.h @@ -94,7 +94,7 @@ extern "C" { int BPY_menu_do_python( short menutype, int event ); int BPY_menu_do_shortcut( short menutype, unsigned short key, unsigned short modifiers ); int BPY_menu_invoke( struct BPyMenu *pym, short menutype ); - void BPY_run_python_script( char *filename ); + void BPY_run_python_script( const char *filename ); int BPY_run_script(struct Script *script); void BPY_free_compiled_text( struct Text *text ); diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c index c91aabc4a02..041ba069928 100644 --- a/source/blender/python/BPY_interface.c +++ b/source/blender/python/BPY_interface.c @@ -720,13 +720,23 @@ int BPY_txt_do_python_Text( struct Text *text ) * automatically. The script can be a file or a Blender Text in the current * .blend. ****************************************************************************/ -void BPY_run_python_script( char *fn ) +void BPY_run_python_script( const char *fn ) { + char filename[FILE_MAXDIR + FILE_MAXFILE]; Text *text = NULL; int is_blender_text = 0; - - if (!BLI_exists(fn)) { /* if there's no such filename ... */ - text = G.main->text.first; /* try an already existing Blender Text */ + + BLI_strncpy(filename, fn, FILE_MAXDIR + FILE_MAXFILE); + + if (!BLI_exists(filename)) + BLI_convertstringcwd(filename); + + if (!BLI_exists(filename)) { /* if there's no such filename ... */ + /* try an already existing Blender Text. + * use 'fn' rather then filename for this since were looking for + * internal text + */ + text = G.main->text.first; while (text) { if (!strcmp(fn, text->id.name + 2)) break; @@ -741,11 +751,14 @@ void BPY_run_python_script( char *fn ) } else { - text = add_text(fn); + /* use filename here since we know it exists, + * 'fn' may have been a relative path + */ + text = add_text(filename); if (text == NULL) { printf("\nError in BPY_run_python_script:\n" - "couldn't create Blender text from %s\n", fn); + "couldn't create Blender text from \"%s\"\n", filename); /* Chris: On Windows if I continue I just get a segmentation * violation. To get a baseline file I exit here. */ exit(2); @@ -762,13 +775,8 @@ void BPY_run_python_script( char *fn ) /* We can't simply free the text, since the script might have called * Blender.Load() to load a new .blend, freeing previous data. * So we check if the pointer is still valid. */ - Text *txtptr = G.main->text.first; - while (txtptr) { - if (txtptr == text) { - free_libblock(&G.main->text, text); - break; - } - txtptr = txtptr->id.next; + if (BLI_findindex(&G.main->text, text) != -1) { + free_libblock(&G.main->text, text); } } } |