changeset 3259:fa345875edea

[project @ 1999-07-22 04:30:18 by jwe]
author jwe
date Thu, 22 Jul 1999 04:30:25 +0000
parents 4964d5391acc
children cd454a6fa1a4
files src/ChangeLog src/defun.cc src/error.cc src/help.cc src/octave.cc src/variables.cc src/variables.h
diffstat 7 files changed, 98 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,25 @@
 Wed Jul 21 15:38:52 1999  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
+	* help.cc (display_names_from_help_list): Sort names before
+	listing them.
+	(print_symbol_type, Ftype): Also handle built-in constants.
+	(LIST_SYMBOLS): Correct call to symbol_table::name_list.
+	(simple_help): List constants here too.  List constants and
+	variables before functions, not after.  Sort names before listing
+	them.
+
+	* variables.cc (do_who): Display built-in constants in a separate
+	section.
+
+	* error.cc (bind_global_error_variable, clear_global_error_variable): 
+	Call bind_builtin_constant, not bind_builtin_variable to set
+	__error_text__.
+	* octave.cc (intern_argv): Likewise, for argv and __argv__.
+
+	* defun.cc (install_builtin_constant): Move function guts to
+	bind_builtin_constant in variables.cc.
+	* variables.cc (bind_builtin_constant): New function.
+
 	* symtab.cc (symbol_record::define, symbol_record::variable_reference):
 	Handle constants the same as functions.
 	(symbol_record::link_to_builtin_variable): New function.
--- a/src/defun.cc
+++ b/src/defun.cc
@@ -105,21 +105,7 @@
 install_builtin_constant (const string& name, const octave_value& val,
 			  bool protect, const string& help)
 {
-  symbol_record *sym_rec = global_sym_tab->lookup (name, true);
-  sym_rec->unprotect ();
-
-  string tmp_help = help.empty () ? sym_rec->help () : help;
-
-  sym_rec->define_builtin_const (val);
-
-  sym_rec->document (tmp_help);
-
-  if (protect)
-    sym_rec->protect ();
-
-  // XXX FIXME XXX -- shouldn't constants be eternal?
-  //  if (eternal)
-  //    sym_rec->make_eternal ();
+  bind_builtin_constant (name, val, protect, false, help);
 }
 
 void
--- a/src/error.cc
+++ b/src/error.cc
@@ -301,7 +301,7 @@
 
   char *error_text = error_message_buffer->str ();
 
-  bind_builtin_variable ("__error_text__", error_text, 1);
+  bind_builtin_constant ("__error_text__", error_text, true);
 
   delete [] error_text;
 
@@ -316,7 +316,7 @@
   delete error_message_buffer;
   error_message_buffer = 0;
 
-  bind_builtin_variable ("__error_text__", "", 1);
+  bind_builtin_constant ("__error_text__", "", true);
 }
 
 static int
--- a/src/help.cc
+++ b/src/help.cc
@@ -398,7 +398,7 @@
 {
   if (! Vsuppress_verbose_help_message)
     os << "\n\
-Additional help for builtin functions, operators, and variables\n\
+Additional help for built-in functions, operators, and variables\n\
 is available in the on-line version of the manual.  Use the command\n\
 `help -i <topic>' to search the manual index.\n";
 
@@ -418,10 +418,15 @@
 			      const char *desc)
 {
   int count = 0;
+
   string_vector symbols = names (list, count);
+
   if (! symbols.empty ())
     {
       os << "\n*** " << desc << ":\n\n";
+
+      symbols.qsort ();
+
       symbols.list_in_columns (os);
     }
 }
@@ -464,16 +469,16 @@
   else if (sym_rec->is_text_function ())
     {
       if (print)
-	os << name << " is a builtin text-function\n";
+	os << name << " is a built-in text-function\n";
       else
-	retval = "builtin text-function";
+	retval = "built-in text-function";
     }
   else if (sym_rec->is_builtin_function ())
     {
       if (print)
-	os << name << " is a builtin function\n";
+	os << name << " is a built-in function\n";
       else
-	retval = "builtin function";
+	retval = "built-in function";
     }
   else if (sym_rec->is_user_variable ())
     {
@@ -485,9 +490,16 @@
   else if (sym_rec->is_builtin_variable ())
     {
       if (print)
-	os << name << " is a builtin variable\n";
+	os << name << " is a built-in variable\n";
       else
-	retval = "builtin variable";
+	retval = "built-in variable";
+    }
+  else if (sym_rec->is_builtin_constant ())
+    {
+      if (print)
+	os << name << " is a built-in constant\n";
+      else
+	retval = "built-in variable";
     }
   else
     {
@@ -518,7 +530,8 @@
   do \
     { \
       int count; \
-      string_vector names = global_sym_tab->name_list (count, 0, 0, 1, type); \
+      string_vector names \
+	= global_sym_tab->name_list (count, string_vector (), true, type); \
       display_symtab_names (octave_stdout, names, count, msg); \
     } \
   while (0)
@@ -538,6 +551,10 @@
 
   // XXX FIXME XXX -- is this distinction needed?
 
+  LIST_SYMBOLS (symbol_record::BUILTIN_CONSTANT, "built-in constants");
+
+  LIST_SYMBOLS (symbol_record::BUILTIN_VARIABLE, "built-in variables");
+
   LIST_SYMBOLS (symbol_record::TEXT_FUNCTION,
 		"text functions (these names are also reserved)");
 
@@ -545,8 +562,6 @@
 
   LIST_SYMBOLS (symbol_record::BUILTIN_FUNCTION, "general functions");
 
-  LIST_SYMBOLS (symbol_record::BUILTIN_VARIABLE, "builtin variables");
-
   // Also need to list variables and currently compiled functions from
   // the symbol table, if there are any.
 
@@ -567,6 +582,8 @@
 
 	  octave_stdout << "\n*** function files in " << dir << ":\n\n";
 
+	  names.qsort ();
+
 	  names.list_in_columns (octave_stdout);
 	}
     }
@@ -857,11 +874,12 @@
 	      // Fwhich.
 
 	      else if (sym_rec->is_text_function ())
-		output_buf << argv[i] << " is a builtin text-function\n";
+		output_buf << argv[i] << " is a built-in text-function\n";
 	      else if (sym_rec->is_builtin_function ())
-		output_buf << argv[i] << " is a builtin function\n";
+		output_buf << argv[i] << " is a built-in function\n";
 	      else if (sym_rec->is_user_variable ()
-		       || sym_rec->is_builtin_variable ())
+		       || sym_rec->is_builtin_variable ()
+		       || sym_rec->is_builtin_constant ())
 		{
 		  octave_value defn = sym_rec->def ();
 
@@ -883,8 +901,12 @@
 
 			      if (sym_rec->is_user_variable ())
 				output_buf << " is a user-defined variable\n";
+			      else if (sym_rec->is_builtin_variable ())
+				output_buf << " is a built-in variable\n";
+			      else if (sym_rec->is_builtin_constant ())
+				output_buf << " is a built-in constant\n";
 			      else
-				output_buf << " is a built-in variable\n";
+				panic_impossible ();
 			    }
 			  else
 			    {
--- a/src/octave.cc
+++ b/src/octave.cc
@@ -154,7 +154,8 @@
 static void
 intern_argv (int argc, char **argv)
 {
-  bind_builtin_variable ("nargin", static_cast<double> (argc-1), 1, 1, 0);
+  bind_builtin_variable ("nargin", static_cast<double> (argc-1),
+			 true, true, 0);
 
   octave_value_list octave_argv;
 
@@ -166,8 +167,8 @@
 
     }
 
-  bind_builtin_variable ("argv", octave_argv, 1, 1, 0);
-  bind_builtin_variable ("__argv__", octave_argv, 1, 1, 0);
+  bind_builtin_constant ("argv", octave_argv, true, true);
+  bind_builtin_constant ("__argv__", octave_argv, true, true);
 }
 
 static void
--- a/src/variables.cc
+++ b/src/variables.cc
@@ -857,6 +857,10 @@
   if (show_builtins)
     {
       pad_after += global_sym_tab->maybe_list
+	("*** built-in constants:", pats, octave_stdout,
+	 show_verbose, symbol_record::BUILTIN_CONSTANT, SYMTAB_ALL_SCOPES);
+
+      pad_after += global_sym_tab->maybe_list
 	("*** built-in variables:", pats, octave_stdout,
 	 show_verbose, symbol_record::BUILTIN_VARIABLE, SYMTAB_ALL_SCOPES);
 
@@ -954,6 +958,32 @@
     }
 }
 
+// Give a global constant a definition.  This will insert the symbol
+// in the global table if necessary.
+
+// How is this different than install_builtin_constant?  Are both
+// functions needed?
+
+void
+bind_builtin_constant (const string& name, const octave_value& val,
+		       bool protect, bool eternal, const string& help)
+{
+  symbol_record *sym_rec = global_sym_tab->lookup (name, true);
+  sym_rec->unprotect ();
+
+  string tmp_help = help.empty () ? sym_rec->help () : help;
+
+  sym_rec->define_builtin_const (val);
+
+  sym_rec->document (tmp_help);
+
+  if (protect)
+    sym_rec->protect ();
+
+  if (eternal)
+    sym_rec->make_eternal ();
+}
+
 // Give a global variable a definition.  This will insert the symbol
 // in the global table if necessary.
 
--- a/src/variables.h
+++ b/src/variables.h
@@ -95,6 +95,11 @@
 extern void clear_global_error_variable (void *);
 
 extern void
+bind_builtin_constant (const string&, const octave_value&,
+		       bool protect = false, bool eternal = false,
+		       const string& help = string ());
+
+extern void
 bind_builtin_variable (const string&, const octave_value&,
 		       bool protect = false, bool eternal = false,
 		       symbol_record::change_function f = 0,