# HG changeset patch # User jwe # Date 1156869460 0 # Node ID e64059303a6f78a6fa97b16d1fd8960a2d2887cf # Parent 51684d05b4bf7f449ba7f423fa79fd1cb6e555db [project @ 2006-08-29 16:37:39 by jwe] diff -r 51684d05b4bf -r e64059303a6f src/ChangeLog --- a/src/ChangeLog Sat Aug 26 09:38:53 2006 +0000 +++ b/src/ChangeLog Tue Aug 29 16:37:40 2006 +0000 @@ -1,3 +1,10 @@ +2006-08-29 John W. Eaton + + * load-path.cc (execute_pkg_add_or_del): + Source PKG_ADD or PKG_DEL in base workspace. + * parse.y (source_file): New optional arg, context. + * parse.h (source_file): Fix decl. + 2006-08-25 John W. Eaton * version.h (OCTAVE_VERSION): Now 2.9.8+. diff -r 51684d05b4bf -r e64059303a6f src/load-path.cc --- a/src/load-path.cc Sat Aug 26 09:38:53 2006 +0000 +++ b/src/load-path.cc Tue Aug 29 16:37:40 2006 +0000 @@ -1211,7 +1211,7 @@ file_stat fs = file_stat (file); if (fs.exists ()) - source_file (file); + source_file (file, "base"); unwind_protect::run_frame ("execute_pkg_add_or_del"); } diff -r 51684d05b4bf -r e64059303a6f src/parse.h --- a/src/parse.h Sat Aug 26 09:38:53 2006 +0000 +++ b/src/parse.h Tue Aug 29 16:37:40 2006 +0000 @@ -109,7 +109,8 @@ load_fcn_from_file (symbol_record *sym_rec, bool exec_script); extern void -source_file (const std::string file_name); +source_file (const std::string& file_name, + const std::string& context = std::string ()); extern octave_value_list feval (const std::string& name, diff -r 51684d05b4bf -r e64059303a6f src/parse.y --- a/src/parse.y Sat Aug 26 09:38:53 2006 +0000 +++ b/src/parse.y Tue Aug 29 16:37:40 2006 +0000 @@ -3527,7 +3527,7 @@ } void -source_file (const std::string file_name) +source_file (const std::string& file_name, const std::string& context) { std::string file_full_name = file_ops::tilde_expand (file_name); @@ -3539,11 +3539,26 @@ curr_fcn_file_name = file_name; curr_fcn_file_full_name = file_full_name; - parse_fcn_file (file_full_name, true, true); - - if (error_state) - error ("source: error sourcing file `%s'", - file_full_name.c_str ()); + if (! context.empty ()) + { + unwind_protect_ptr (curr_sym_tab); + + if (context == "caller") + curr_sym_tab = curr_caller_sym_tab; + else if (context == "base") + curr_sym_tab = top_level_sym_tab; + else + error ("source: context must be \"caller\" or \"base\""); + } + + if (! error_state) + { + parse_fcn_file (file_full_name, true, true); + + if (error_state) + error ("source: error sourcing file `%s'", + file_full_name.c_str ()); + } unwind_protect::run_frame ("source_file"); } @@ -3629,12 +3644,22 @@ int nargin = args.length (); - if (nargin == 1) + if (nargin == 1 || nargin == 2) { std::string file_name = args(0).string_value (); if (! error_state) - source_file (file_name); + { + std::string context; + + if (nargin == 2) + context = args(1).string_value (); + + if (! error_state) + source_file (file_name, context); + else + error ("source: expecting context to be character string"); + } else error ("source: expecting file name as argument"); }