# HG changeset patch # User jwe # Date 1069182433 0 # Node ID 0e28461651f2d3c8dc25ca80e4eabbcfd9f03714 # Parent cae0b7c46842dc48e150f68743b50d2a21281b52 [project @ 2003-11-18 19:07:13 by jwe] diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,11 @@ 2003-11-18 John W. Eaton + * pr-output.cc (octave_print_internal): Don't indent rows for + plus_format. Use pr_plus_format for Range type with plus_format. + (plus_format_chars): New static variable. + (set_format_style): Allow optional arg for plus format to set it. + (pr_plus_format): Use it. + * ov-bool.h (octave_bool::array_value, octave_bool::complex_array_value): New functions. diff --git a/src/pr-output.cc b/src/pr-output.cc --- a/src/pr-output.cc +++ b/src/pr-output.cc @@ -82,6 +82,9 @@ // TRUE means print plus sign for nonzero, blank for zero. static bool plus_format = false; +// First char for > 0, second for < 0, third for == 0. +static std::string plus_format_chars = "+ "; + // TRUE means always print like dollars and cents. static bool bank_format = false; @@ -1341,12 +1344,12 @@ static inline void pr_plus_format (std::ostream& os, double d) { - if (d == 0.0) - os << " "; + if (d > 0.0) + os << plus_format_chars[0]; else if (d < 0.0) - os << "-"; + os << plus_format_chars[1]; else - os << "+"; + os << plus_format_chars[2]; } void @@ -1383,9 +1386,6 @@ { OCTAVE_QUIT; - if (j == 0) - os << " "; - pr_plus_format (os, m(i,j)); } @@ -1644,9 +1644,6 @@ { OCTAVE_QUIT; - if (j == 0) - os << " "; - pr_plus_format (os, cm(i,j)); } @@ -1794,16 +1791,13 @@ if (plus_format && ! pr_as_read_syntax) { - os << " "; for (int i = 0; i < num_elem; i++) { OCTAVE_QUIT; double val = base + i * increment; - if (val == 0.0) - os << " "; - else - os << "+"; + + pr_plus_format (os, val); } } else @@ -2210,6 +2204,21 @@ } else if (arg == "+" || arg == "plus") { + if (--argc > 0) + { + arg = argv[idx++]; + + if (arg.length () == 3) + plus_format_chars = arg; + else + { + error ("format: invalid option for plus format"); + return; + } + } + else + plus_format_chars = "+ "; + init_format_state (); plus_format = true; } @@ -2336,10 +2345,27 @@ point.\n\ \n\ @item +\n\ +@itemx + @var{chars}\n\ +@itemx plus\n\ +@itemx plus @var{chars}\n\ Print a @samp{+} symbol for nonzero matrix elements and a space for zero\n\ matrix elements. This format can be very useful for examining the\n\ structure of a large matrix.\n\ \n\ +The optional argument @var{chars} specifies a list of 3 characters to use\n\ +for printing values greater than zero, less than zero and equal to zero.\n\ +For example, with the @samp{+ \"+-.\"} format, @code{[1, 0, -1; -1, 0, 1]}\n\ +is displayed as\n\ +\n\ +@example\n\ +@group\n\ +ans =\n\ +\n\ ++.-\n\ +-.+\n\ +@end group\n\ +@end example\n\ +\n\ @item hex\n\ Print the hexadecimal representation numbers as they are stored in\n\ memory. For example, on a workstation which stores 8 byte real values\n\