changeset 6803:fe19c6cb5bc6

[project @ 2007-07-26 18:04:05 by jwe]
author jwe
date Thu, 26 Jul 2007 18:04:06 +0000
parents 3727149c8da1
children 4d3fa8841006
files src/ChangeLog src/pr-output.cc
diffstat 2 files changed, 53 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Thu Jul 26 13:37:56 2007 +0000
+++ b/src/ChangeLog	Thu Jul 26 18:04:06 2007 +0000
@@ -1,3 +1,8 @@
+2007-07-26  David Bateman  <dbateman@free.fr>
+
+	* pr-output.cc (Frats): Return character array with same number of
+	rows as original value.
+
 2007-07-26  John W. Eaton  <jwe@octave.org>
 
 	* pt-bp.h (MAYBE_DO_BREAKPOINT): Rename cur_fcn to xfcn.
@@ -13,7 +18,7 @@
 	* pt-bp.h (MAYBE_DO_BREAKPOINT): Rename fcn to curr_fcn.
 
 2007-07-25  David Bateman  <dbateman@free.fr>
-	
+
 	* Makefile.in: 	Adjust DISTFILES to allow out of tree "make dist" 
 	to work.
 
--- a/src/pr-output.cc	Thu Jul 26 13:37:56 2007 +0000
+++ b/src/pr-output.cc	Thu Jul 26 18:04:06 2007 +0000
@@ -55,6 +55,7 @@
 #include "pager.h"
 #include "pr-output.h"
 #include "sysdep.h"
+#include "unwind-prot.h"
 #include "utils.h"
 #include "variables.h"
 
@@ -2751,28 +2752,66 @@
 @end deftypefn")
 {
   octave_value retval;
+
   int nargin = args.length ();
 
+  unwind_protect::begin_frame ("Frats");
+
+  unwind_protect_int (rat_string_len);
+
   rat_string_len = 9;
+
   if (nargin == 2)
     rat_string_len = args(1).nint_value ();
 
-  if (!error_state)
+  if (! error_state)
     {
       if (nargin < 3 && nargout < 2)
 	{
-	  bool save_rat_format = rat_format;
-	  rat_format = true;
-	  std::ostringstream buf;
-	  args(0).print (buf);
-	  retval = buf.str ();
-	  rat_format = save_rat_format;
+	  octave_value arg = args(0);
+
+	  if (arg.is_numeric_type ())
+	    {
+	      unwind_protect_bool (rat_format);
+
+	      rat_format = true;
+
+	      std::ostringstream buf;
+	      args(0).print (buf);
+	      std::string s = buf.str ();
+
+	      std::list<std::string> lst;
+
+	      size_t n = 0;
+	      size_t s_len = s.length ();
+
+	      while (n < s_len)
+		{
+		  size_t m = s.find ('\n',  n);
+
+		  if (m == NPOS)
+		    {
+		      lst.push_back (s.substr (n));
+		      break;
+		    }
+		  else
+		    {
+		      lst.push_back (s.substr (n, m - n));
+		      n = m + 1;
+		    }
+		}
+
+	      retval = string_vector (lst);
+	    }
+	  else
+	    error ("rats: expecting numeric input");
 	}
       else
 	print_usage ();
     }
 
-  rat_string_len = -1;
+  unwind_protect::run_frame ("Frats");
+
   return retval;
 }