diff src/parse.y @ 5975:e64059303a6f

[project @ 2006-08-29 16:37:39 by jwe]
author jwe
date Tue, 29 Aug 2006 16:37:40 +0000
parents 51cbaa2539f4
children 516d3071b34c
line wrap: on
line diff
--- 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");
     }