changeset 3935:1ea29376e43e

[project @ 2002-05-16 05:30:51 by jwe]
author jwe
date Thu, 16 May 2002 05:30:51 +0000
parents 31393822395b
children f1500121e2e9
files src/ChangeLog src/error.cc src/error.h src/input.cc src/variables.cc test/octave.test/error/error.exp
diffstat 6 files changed, 148 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Wed May 15 19:18:09 2002 +0000
+++ b/src/ChangeLog	Thu May 16 05:30:51 2002 +0000
@@ -1,15 +1,22 @@
 2002-05-15  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
+	* input.cc (generate_completion): If it looks like we are
+	completing a struct, set completion append char to '\0'.
+
+	* variables.cc (generate_struct_completions): Temporarily set
+	warnings off here.
+
 	* error.cc (warning): Don't do anything if Vdebug_option == "off".
 	Only print backtrace if Vdebug_option == "backtrace".
 	(handle_message): Now returns a string containing the text of the
 	formatted message.  Change all callers.
 	(Fwarning): Now a text-style function.  Handle Matlab-compatible
 	warning options.
-	(Flastwarn, set_warning_option): New functions.
-	(Vlast_warning_message, Vwarning_frequency, Vwarning_option):
-	New static variables.
+	(Flasterr, Flastwarn, set_warning_option): New functions.
+	(Vlast_error_message, Vlast_warning_message, Vwarning_frequency,
+	Vwarning_option): New static variables.
 	(vwarning): Set Vlast_warning_message here too.
+	(verror): Set Vlast_error_message here too.
 
 2002-05-14  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
--- a/src/error.cc	Wed May 15 19:18:09 2002 +0000
+++ b/src/error.cc	Thu May 16 05:30:51 2002 +0000
@@ -57,6 +57,9 @@
 // is encountered.
 static bool Vdebug_on_warning;
 
+// The text of the last error message.
+static std::string Vlast_error_message;
+
 // The text of the last warning message.
 static std::string Vlast_warning_message;
 
@@ -66,12 +69,26 @@
 
 // The current warning state.  Valid values are "on", "off",
 // "backtrace", or "debug".
-static std::string Vwarning_option = "backtrace";
+std::string Vwarning_option = "backtrace";
 
 // Current error state.
+//
+// Valid values:
+//
+//   -2: an error has occurred, but don't print any messages.
+//   -1: an error has occurred, we are printing a traceback
+//    0: no error
+//    1: an error has occurred
+//
 int error_state = 0;
 
 // Current warning state.
+//
+//  Valid values:
+//
+//    0: no warning
+//    1: a warning has occurred
+//
 int warning_state = 0;
 
 // Tell the error handler whether to print messages, or just store
@@ -86,7 +103,6 @@
 static std::ostrstream *error_message_buffer = 0;
 
 // Warning messages are never buffered.
-// XXX FIXME XXX -- we should provide another way to turn them off...
 
 static void
 vwarning (const char *name, const char *fmt, va_list args)
@@ -104,13 +120,23 @@
 
   char *msg = output_buf.str ();
 
-  Vlast_warning_message = msg;
+  // XXX FIXME XXX -- we really want to capture the message before it
+  // has all the formatting goop attached to it.  We probably also
+  // want just the message, not the traceback information.
+
+  std::string msg_string = msg;
 
   delete [] msg;
 
-  octave_diary << Vlast_warning_message;
+  if (! warning_state)
+    {
+      // This is the first warning in a possible series.
+      Vlast_warning_message = msg_string;
+    }
 
-  std::cerr << Vlast_warning_message;
+  octave_diary << msg_string;
+
+  std::cerr << msg_string;
 }
 
 static void
@@ -138,9 +164,23 @@
 
   char *msg = output_buf.str ();
 
+  // XXX FIXME XXX -- we really want to capture the message before it
+  // has all the formatting goop attached to it.  We probably also
+  // want just the message, not the traceback information.
+
+  std::string msg_string = msg;
+
+  delete [] msg;
+
+  if (! error_state && name && ! strcmp (name, "error"))
+    {
+      // This is the first error in a possible series.
+      Vlast_error_message = msg_string;
+    }
+
   if (buffer_error_messages)
     {
-      char *ptr = msg;
+      string tmp = msg_string;
 
       if (! error_message_buffer)
 	{
@@ -153,26 +193,19 @@
 	  // from printing `error: ' twice.  Assumes that the NAME we
 	  // have been given doesn't contain `:'.
 
-	  ptr = strchr (msg, ':');
+	  size_t pos = msg_string.find (':');
 
-	  if (ptr)
-	    {
-	      if (*++ptr != '\0')
-		++ptr;
-	    }
-	  else
-	    ptr = msg;
+	  if (pos != NPOS && pos < Vlast_error_message.length () - 2)
+	    tmp = msg_string.substr (pos+2);
 	}
 
-      *error_message_buffer << ptr;
+      *error_message_buffer << tmp;
     }
   else
     {
-      octave_diary << msg;
-      std::cerr << msg;
+      octave_diary << msg_string;
+      std::cerr << msg_string;
     }
-
-  delete [] msg;
 }
 
 // Note that we don't actually print any message if the error string
@@ -321,10 +354,11 @@
     {
       va_list args;
       va_start (args, fmt);
-      warning_state = 1;
       vwarning ("warning", fmt, args);
       va_end (args);
 
+      warning_state = 1;
+
       if (Vwarning_option == "backtrace")
 	pr_where ("warning");
 
@@ -514,14 +548,14 @@
 
 static inline octave_value_list
 set_warning_option (const std::string& state,
-		   const std::string& frequency, int nargout)
+		    const std::string& frequency, int nargout)
 {
   octave_value_list retval;
 
   if (nargout > 1)
     retval(1) = Vwarning_frequency;
 
-  if (nargout > 0)
+  if (nargout >= 0)
     retval(0) = Vwarning_option;
 
   if (! state.empty ())
@@ -533,7 +567,7 @@
   return retval;
 }
 
-DEFUN_TEXT (warning, args, nargout,
+DEFUN (warning, args, nargout,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {} warning (@var{msg})\n\
 Print a warning message @var{msg} prefixed by the string @samp{warning: }.  \n\
@@ -547,60 +581,87 @@
 
   int argc = args.length () + 1;
 
-  string_vector argv = args.make_argv ("warning");
-
-  if (! error_state)
-    {
-      bool done = false;
+  bool done = false;
 
-      if (argc == 1)
-	{
-	  retval = set_warning_option ("", "", nargout);
-	  done = true;
-	}
-      else if (argc == 2)
+  if (args.all_strings_p ())
+    {
+      string_vector argv = args.make_argv ("warning");
+
+      if (! error_state)
 	{
-	  std::string arg = argv(1);
-
-	  if (arg == "on" || arg == "off" || arg == "backtrace")
+	  if (argc == 1)
 	    {
-	      retval = set_warning_option (arg, "", nargout);
-	      done = true;
-	    }
-	  else if (arg == "once" || arg == "always")
-	    {
-	      retval = set_warning_option ("", arg, nargout);
-	      done = true;
-	    }
-	  else if (arg == "debug")
-	    {
-	      bind_builtin_variable ("debug_on_warning", 1.0);
 	      retval = set_warning_option ("", "", nargout);
 	      done = true;
 	    }
-	}
+	  else if (argc == 2)
+	    {
+	      std::string arg = argv(1);
 
-      if (! done)
-	{
-	  std::string curr_msg
-	    = handle_message (warning, "unspecified warning", args);
-
-	  if (nargout > 0)
-	    retval(0) = Vlast_warning_message;
-
-	  Vlast_warning_message = curr_msg;
+	      if (arg == "on" || arg == "off" || arg == "backtrace")
+		{
+		  retval = set_warning_option (arg, "", nargout);
+		  done = true;
+		}
+	      else if (arg == "once" || arg == "always")
+		{
+		  retval = set_warning_option ("", arg, nargout);
+		  done = true;
+		}
+	      else if (arg == "debug")
+		{
+		  bind_builtin_variable ("debug_on_warning", 1.0);
+		  retval = set_warning_option ("", "", nargout);
+		  done = true;
+		}
+	    }
 	}
     }
 
+  if (! done)
+    {
+      std::string prev_msg = Vlast_warning_message;
+
+      std::string curr_msg
+	= handle_message (warning, "unspecified warning", args);
+
+      if (nargout > 0)
+	retval(0) = Vlast_warning_message;
+    }
+
   return retval;
 }
 
+DEFUN (lasterr, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} lasterr ()\n\
+@deftypefnx {Built-in Function} {} lasterr (@var{msg})\n\
+Without any arguments, return the last error message.  With one\n\
+argument, set the last warning message to @var{msg}.\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  int argc = args.length () + 1;
+
+  string_vector argv = args.make_argv ("lasterr");
+
+  if (argc == 1)
+    retval(0) = Vlast_error_message;
+  else if (argc == 2)
+    Vlast_error_message = argv(1);
+  else
+    print_usage ("lasterr");
+
+  return retval;  
+}
+
 DEFUN (lastwarn, args, ,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {} lastwarn ()\n\
 @deftypefnx {Built-in Function} {} lastwarn (@var{msg})\n\
-Without any arguments, return the last error message.  With one\n\
-argument, set the last warning message to @var{msg}.\n\
+Without any arguments, return the last warning message.  With one\n\
+argument, set the last error message to @var{msg}.\n\
 @end deftypefn")
 {
   octave_value_list retval;
--- a/src/error.h	Wed May 15 19:18:09 2002 +0000
+++ b/src/error.h	Thu May 16 05:30:51 2002 +0000
@@ -23,6 +23,7 @@
 #if !defined (octave_error_h)
 #define octave_error_h 1
 
+#include <string>
 #include <strstream>
 
 #define panic_impossible() \
@@ -50,6 +51,10 @@
 // TRUE means error messages are turned off.
 extern bool discard_error_messages;
 
+// The current warning state.  Valid values are "on", "off",
+// "backtrace", or "debug".
+extern std::string Vwarning_option;
+
 #endif
 
 /*
--- a/src/input.cc	Wed May 15 19:18:09 2002 +0000
+++ b/src/input.cc	Thu May 16 05:30:51 2002 +0000
@@ -455,7 +455,11 @@
 		retval = name;
 
 	      if (matches == 1 && looks_like_struct (retval))
-		command_editor::set_completion_append_character ('.');
+		{
+		  // Don't append anything, since we don't know
+		  // whether it should be '(' or '.'.
+		  command_editor::set_completion_append_character ('\0');
+		}
 	      else
 		command_editor::set_completion_append_character
 		  (Vcompletion_append_char);
--- a/src/variables.cc	Wed May 15 19:18:09 2002 +0000
+++ b/src/variables.cc	Thu May 16 05:30:51 2002 +0000
@@ -285,8 +285,14 @@
 
   int parse_status;
 
+  unwind_protect_str (Vwarning_option);
+
+  Vwarning_option = "off";
+
   octave_value tmp = eval_string (prefix, true, parse_status);
 
+  unwind_protect::run ();
+
   if (tmp.is_defined () && tmp.is_map ())
     names = tmp.map_keys ();
 
--- a/test/octave.test/error/error.exp	Wed May 15 19:18:09 2002 +0000
+++ b/test/octave.test/error/error.exp	Thu May 16 05:30:51 2002 +0000
@@ -19,7 +19,7 @@
 do_test warning-1.m
 
 set test warning-2
-set prog_output "warning: unspecified warning"
+set prog_output "ans = backtrace"
 do_test warning-2.m
 
 set test warning-3