Mercurial > hg > octave-nkf
diff src/pr-output.cc @ 6803:fe19c6cb5bc6
[project @ 2007-07-26 18:04:05 by jwe]
author | jwe |
---|---|
date | Thu, 26 Jul 2007 18:04:06 +0000 |
parents | c81a0f3f5a82 |
children | 47f4f4e88166 |
line wrap: on
line diff
--- a/src/pr-output.cc +++ b/src/pr-output.cc @@ -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; }