changeset 1281:fcdf6c5d0302

[project @ 1995-04-27 19:21:47 by jwe]
author jwe
date Thu, 27 Apr 1995 19:23:54 +0000
parents b01f9577b0da
children dac3c9c58b1a
files src/help.cc src/variables.cc
diffstat 2 files changed, 55 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/help.cc	Wed Apr 26 17:49:19 1995 +0000
+++ b/src/help.cc	Thu Apr 27 19:23:54 1995 +0000
@@ -771,7 +771,22 @@
 	  if (! *argv || ! **argv)
 	    continue;
 
-	  symbol_record *sym_rec = lookup_by_name (*argv, 0);
+	  char *id = strsave (*argv);
+	  char *elts = 0;
+	  char *ptr = strchr (id, '.');
+	  if (ptr)
+	    {
+	      *ptr = '\0';
+
+	      elts = ptr + 1;
+	      ptr = strrchr (elts, '.');
+	      if (ptr)
+		*ptr = '\0';
+	      else
+		elts = 0;
+	    }
+
+	  symbol_record *sym_rec = lookup_by_name (id, 0);
 
 	  if (sym_rec)
 	    {
@@ -791,35 +806,52 @@
 		output_buf << *argv << " is a builtin text-function\n";
 	      else if (sym_rec->is_builtin_function ())
 		output_buf << *argv << " is a builtin function\n";
-	      else if (sym_rec->is_user_variable ())
+	      else if (sym_rec->is_user_variable ()
+		       || sym_rec->is_builtin_variable ())
 		{
 		  tree_fvc *defn = sym_rec->def ();
 
-		  if (nargout == 0 && ! quiet)
-		    output_buf << *argv << " is a user-defined variable\n";
+		  assert (defn->is_constant ());
+
+		  tree_constant *tmp = (tree_constant *) defn;
 
-		  defn->print_code (output_buf);
+		  int var_ok = 1;
+		  if (tmp && tmp->is_map ())
+		    {
+		      if (elts && *elts)
+			{
+			  tree_constant ult;
+			  ult = tmp->lookup_map_element (elts, 0, 1);
 
-		  if (nargout == 0)
-		    output_buf << "\n";
-		}
-	      else if (sym_rec->is_builtin_variable ())
-		{
-		  tree_fvc *defn = sym_rec->def ();
+			  if (! ult.is_defined ())
+			    var_ok = 0;			    
+			}
+		    }
+		  
+		  if (nargout == 0 && ! quiet)
+		    {
+		      output_buf << *argv;
+		      if (sym_rec->is_user_variable ())
+			output_buf << " is a user-defined variable\n";
+		      else
+			output_buf << " is a built-in variable\n";
+		    }
 
-		  if (nargout == 0 && ! quiet)
-		    output_buf << *argv << " is a builtin variable\n";
+		  if (! tmp->is_map ())
+		    {
+		      tmp->print_code (output_buf);
 
-		  defn->print_code (output_buf);
-
-		  if (nargout == 0)
-		    output_buf << "\n";
+		      if (nargout == 0)
+			output_buf << "\n";
+		    }
 		}
 	      else
 		output_buf << "type: `" << *argv << "' has unknown type!\n";
 	    }
 	  else
 	    output_buf << "type: `" << *argv << "' undefined\n";
+
+	  delete [] id;
 	}
 
       output_buf << ends;
--- a/src/variables.cc	Wed Apr 26 17:49:19 1995 +0000
+++ b/src/variables.cc	Thu Apr 27 19:23:54 1995 +0000
@@ -1440,11 +1440,15 @@
 bind_ans (const tree_constant& val, int print)
 {
   static symbol_record *sr = global_sym_tab->lookup ("ans", 1, 0);
-  static tree_identifier ans_id (sr);
 
+  tree_identifier *ans_id = new tree_identifier (sr);
   tree_constant *tmp = new tree_constant (val);
 
-  tree_simple_assignment_expression tmp_ass (&ans_id, tmp, 1, 1);
+  // XXX FIXME XXX -- making ans_id static, passing its address to
+  // tree_simple_assignment_expression along with a flag to not delete
+  // it seems to create a memory leak.  Hmm.
+
+  tree_simple_assignment_expression tmp_ass (ans_id, tmp, 0, 1);
 
   tmp_ass.eval (print);
 }