Mercurial > hg > octave-lyh
comparison src/pr-output.cc @ 2165:83d91aa3759b
[project @ 1996-05-13 13:28:10 by jwe]
author | jwe |
---|---|
date | Mon, 13 May 1996 13:29:05 +0000 |
parents | bfb775fb6fe8 |
children | 6abec42e52f6 |
comparison
equal
deleted
inserted
replaced
2164:269db7306980 | 2165:83d91aa3759b |
---|---|
41 #include "oct-term.h" | 41 #include "oct-term.h" |
42 #include "str-vec.h" | 42 #include "str-vec.h" |
43 | 43 |
44 #include "defun.h" | 44 #include "defun.h" |
45 #include "error.h" | 45 #include "error.h" |
46 #include "gripes.h" | |
46 #include "help.h" | 47 #include "help.h" |
47 #include "mappers.h" | 48 #include "mappers.h" |
48 #include "oct-obj.h" | 49 #include "oct-obj.h" |
49 #include "pager.h" | 50 #include "pager.h" |
50 #include "pr-output.h" | 51 #include "pr-output.h" |
51 #include "pt-const.h" | 52 #include "pt-const.h" |
52 #include "sysdep.h" | 53 #include "sysdep.h" |
53 #include "user-prefs.h" | 54 #include "user-prefs.h" |
54 #include "utils.h" | 55 #include "utils.h" |
55 #include "variables.h" | 56 #include "variables.h" |
57 | |
58 // The maximum field width for a number printed by the default output | |
59 // routines. | |
60 static int Voutput_max_field_width; | |
61 | |
62 // The precision of the numbers printed by the default output | |
63 // routines. | |
64 static int Voutput_precision; | |
65 | |
66 // TRUE means that the dimensions of empty matrices should be printed | |
67 // like this: x = [](2x0). | |
68 static bool Vprint_empty_dimensions; | |
69 | |
70 // TRUE means that the rows of big matrices should be split into | |
71 // smaller slices that fit on the screen. | |
72 static bool Vsplit_long_rows; | |
56 | 73 |
57 // Current format string for real numbers and the real part of complex | 74 // Current format string for real numbers and the real part of complex |
58 // numbers. | 75 // numbers. |
59 static char *curr_real_fmt = 0; | 76 static char *curr_real_fmt = 0; |
60 | 77 |
207 set_real_format (int sign, int digits, int inf_or_nan, int nan_or_int, | 224 set_real_format (int sign, int digits, int inf_or_nan, int nan_or_int, |
208 int &fw) | 225 int &fw) |
209 { | 226 { |
210 static char fmt_buf[128]; | 227 static char fmt_buf[128]; |
211 | 228 |
212 int prec = user_pref.output_precision; | 229 int prec = Voutput_precision; |
213 | 230 |
214 int ld, rd; | 231 int ld, rd; |
215 | 232 |
216 if (bank_format) | 233 if (bank_format) |
217 { | 234 { |
259 fw = 3; | 276 fw = 3; |
260 fw += sign; | 277 fw += sign; |
261 } | 278 } |
262 | 279 |
263 if (! (bank_format || hex_format || bit_format) | 280 if (! (bank_format || hex_format || bit_format) |
264 && (fw > user_pref.output_max_field_width || print_e)) | 281 && (fw > Voutput_max_field_width || print_e)) |
265 { | 282 { |
266 int exp_field = 4; | 283 int exp_field = 4; |
267 if (digits > 100) | 284 if (digits > 100) |
268 exp_field++; | 285 exp_field++; |
269 | 286 |
319 set_real_matrix_format (int sign, int x_max, int x_min, | 336 set_real_matrix_format (int sign, int x_max, int x_min, |
320 int inf_or_nan, int int_or_inf_or_nan, int& fw) | 337 int inf_or_nan, int int_or_inf_or_nan, int& fw) |
321 { | 338 { |
322 static char fmt_buf[128]; | 339 static char fmt_buf[128]; |
323 | 340 |
324 int prec = user_pref.output_precision; | 341 int prec = Voutput_precision; |
325 | 342 |
326 int ld, rd; | 343 int ld, rd; |
327 | 344 |
328 if (bank_format) | 345 if (bank_format) |
329 { | 346 { |
391 fw = 3; | 408 fw = 3; |
392 fw += sign; | 409 fw += sign; |
393 } | 410 } |
394 | 411 |
395 if (! (bank_format || hex_format || bit_format) | 412 if (! (bank_format || hex_format || bit_format) |
396 && (fw > user_pref.output_max_field_width || print_e)) | 413 && (fw > Voutput_max_field_width || print_e)) |
397 { | 414 { |
398 int exp_field = 4; | 415 int exp_field = 4; |
399 if (x_max > 100 || x_min > 100) | 416 if (x_max > 100 || x_min > 100) |
400 exp_field++; | 417 exp_field++; |
401 | 418 |
455 int inf_or_nan, int int_only, int& r_fw, int& i_fw) | 472 int inf_or_nan, int int_only, int& r_fw, int& i_fw) |
456 { | 473 { |
457 static char r_fmt_buf[128]; | 474 static char r_fmt_buf[128]; |
458 static char i_fmt_buf[128]; | 475 static char i_fmt_buf[128]; |
459 | 476 |
460 int prec = user_pref.output_precision; | 477 int prec = Voutput_precision; |
461 | 478 |
462 int ld, rd; | 479 int ld, rd; |
463 | 480 |
464 if (bank_format) | 481 if (bank_format) |
465 { | 482 { |
530 i_fw = r_fw = 3; | 547 i_fw = r_fw = 3; |
531 r_fw += sign; | 548 r_fw += sign; |
532 } | 549 } |
533 | 550 |
534 if (! (bank_format || hex_format || bit_format) | 551 if (! (bank_format || hex_format || bit_format) |
535 && (r_fw > user_pref.output_max_field_width || print_e)) | 552 && (r_fw > Voutput_max_field_width || print_e)) |
536 { | 553 { |
537 int exp_field = 4; | 554 int exp_field = 4; |
538 if (x_max > 100 || x_min > 100) | 555 if (x_max > 100 || x_min > 100) |
539 exp_field++; | 556 exp_field++; |
540 | 557 |
618 int int_or_inf_or_nan, int& r_fw, int& i_fw) | 635 int int_or_inf_or_nan, int& r_fw, int& i_fw) |
619 { | 636 { |
620 static char r_fmt_buf[128]; | 637 static char r_fmt_buf[128]; |
621 static char i_fmt_buf[128]; | 638 static char i_fmt_buf[128]; |
622 | 639 |
623 int prec = user_pref.output_precision; | 640 int prec = Voutput_precision; |
624 | 641 |
625 int ld, rd; | 642 int ld, rd; |
626 | 643 |
627 if (bank_format) | 644 if (bank_format) |
628 { | 645 { |
693 i_fw = r_fw = 3; | 710 i_fw = r_fw = 3; |
694 r_fw += sign; | 711 r_fw += sign; |
695 } | 712 } |
696 | 713 |
697 if (! (bank_format || hex_format || bit_format) | 714 if (! (bank_format || hex_format || bit_format) |
698 && (r_fw > user_pref.output_max_field_width || print_e)) | 715 && (r_fw > Voutput_max_field_width || print_e)) |
699 { | 716 { |
700 int exp_field = 4; | 717 int exp_field = 4; |
701 if (x_max > 100 || x_min > 100) | 718 if (x_max > 100 || x_min > 100) |
702 exp_field++; | 719 exp_field++; |
703 | 720 |
790 static void | 807 static void |
791 set_range_format (int sign, int x_max, int x_min, int all_ints, int& fw) | 808 set_range_format (int sign, int x_max, int x_min, int all_ints, int& fw) |
792 { | 809 { |
793 static char fmt_buf[128]; | 810 static char fmt_buf[128]; |
794 | 811 |
795 int prec = user_pref.output_precision; | 812 int prec = Voutput_precision; |
796 | 813 |
797 int ld, rd; | 814 int ld, rd; |
798 | 815 |
799 if (bank_format) | 816 if (bank_format) |
800 { | 817 { |
853 | 870 |
854 fw = sign + ld + 1 + rd; | 871 fw = sign + ld + 1 + rd; |
855 } | 872 } |
856 | 873 |
857 if (! (bank_format || hex_format || bit_format) | 874 if (! (bank_format || hex_format || bit_format) |
858 && (fw > user_pref.output_max_field_width || print_e)) | 875 && (fw > Voutput_max_field_width || print_e)) |
859 { | 876 { |
860 int exp_field = 4; | 877 int exp_field = 4; |
861 if (x_max > 100 || x_min > 100) | 878 if (x_max > 100 || x_min > 100) |
862 exp_field++; | 879 exp_field++; |
863 | 880 |
1101 os << "zeros (" << nr << ", " << nc << ")"; | 1118 os << "zeros (" << nr << ", " << nc << ")"; |
1102 } | 1119 } |
1103 else | 1120 else |
1104 { | 1121 { |
1105 os << "[]"; | 1122 os << "[]"; |
1106 if (user_pref.print_empty_dimensions) | 1123 if (Vprint_empty_dimensions) |
1107 os << "(" << nr << "x" << nc << ")"; | 1124 os << "(" << nr << "x" << nc << ")"; |
1108 os << "\n"; | 1125 os << "\n"; |
1109 } | 1126 } |
1110 } | 1127 } |
1111 | 1128 |
1112 static void | 1129 static void |
1113 pr_col_num_header (ostream& os, int total_width, int max_width, | 1130 pr_col_num_header (ostream& os, int total_width, int max_width, |
1114 int lim, int col, int extra_indent) | 1131 int lim, int col, int extra_indent) |
1115 { | 1132 { |
1116 if (total_width > max_width && user_pref.split_long_rows) | 1133 if (total_width > max_width && Vsplit_long_rows) |
1117 { | 1134 { |
1118 if (col != 0 && ! compact_format) | 1135 if (col != 0 && ! compact_format) |
1119 os << "\n"; | 1136 os << "\n"; |
1120 | 1137 |
1121 int num_cols = lim - col; | 1138 int num_cols = lim - col; |
1211 | 1228 |
1212 return; | 1229 return; |
1213 } | 1230 } |
1214 | 1231 |
1215 int inc = nc; | 1232 int inc = nc; |
1216 if (total_width > max_width && user_pref.split_long_rows) | 1233 if (total_width > max_width && Vsplit_long_rows) |
1217 { | 1234 { |
1218 inc = max_width / column_width; | 1235 inc = max_width / column_width; |
1219 if (inc == 0) | 1236 if (inc == 0) |
1220 inc++; | 1237 inc++; |
1221 } | 1238 } |
1364 | 1381 |
1365 return; | 1382 return; |
1366 } | 1383 } |
1367 | 1384 |
1368 int inc = nc; | 1385 int inc = nc; |
1369 if (total_width > max_width && user_pref.split_long_rows) | 1386 if (total_width > max_width && Vsplit_long_rows) |
1370 { | 1387 { |
1371 inc = max_width / column_width; | 1388 inc = max_width / column_width; |
1372 if (inc == 0) | 1389 if (inc == 0) |
1373 inc++; | 1390 inc++; |
1374 } | 1391 } |
1495 os << r; | 1512 os << r; |
1496 return; | 1513 return; |
1497 } | 1514 } |
1498 | 1515 |
1499 int inc = num_elem; | 1516 int inc = num_elem; |
1500 if (total_width > max_width && user_pref.split_long_rows) | 1517 if (total_width > max_width && Vsplit_long_rows) |
1501 { | 1518 { |
1502 inc = max_width / column_width; | 1519 inc = max_width / column_width; |
1503 if (inc == 0) | 1520 if (inc == 0) |
1504 inc++; | 1521 inc++; |
1505 } | 1522 } |
1750 set_format_style (argc, argv); | 1767 set_format_style (argc, argv); |
1751 | 1768 |
1752 return retval; | 1769 return retval; |
1753 } | 1770 } |
1754 | 1771 |
1772 static int | |
1773 output_max_field_width (void) | |
1774 { | |
1775 double val; | |
1776 if (builtin_real_scalar_variable ("output_max_field_width", val) | |
1777 && ! xisnan (val)) | |
1778 { | |
1779 int ival = NINT (val); | |
1780 if (ival > 0 && (double) ival == val) | |
1781 { | |
1782 Voutput_max_field_width = ival; | |
1783 return 0; | |
1784 } | |
1785 } | |
1786 gripe_invalid_value_specified ("output_max_field_width"); | |
1787 return -1; | |
1788 } | |
1789 | |
1790 static int | |
1791 output_precision (void) | |
1792 { | |
1793 double val; | |
1794 if (builtin_real_scalar_variable ("output_precision", val) | |
1795 && ! xisnan (val)) | |
1796 { | |
1797 int ival = NINT (val); | |
1798 if (ival >= 0 && (double) ival == val) | |
1799 { | |
1800 Voutput_precision = ival; | |
1801 return 0; | |
1802 } | |
1803 } | |
1804 gripe_invalid_value_specified ("output_precision"); | |
1805 return -1; | |
1806 } | |
1807 | |
1808 static int | |
1809 print_empty_dimensions (void) | |
1810 { | |
1811 Vprint_empty_dimensions = check_preference ("print_empty_dimensions"); | |
1812 | |
1813 return 0; | |
1814 } | |
1815 | |
1816 static int | |
1817 split_long_rows (void) | |
1818 { | |
1819 Vsplit_long_rows = check_preference ("split_long_rows"); | |
1820 | |
1821 return 0; | |
1822 } | |
1823 | |
1824 void | |
1825 symbols_of_pr_output (void) | |
1826 { | |
1827 DEFVAR (output_max_field_width, 10.0, 0, output_max_field_width, | |
1828 "maximum width of an output field for numeric output"); | |
1829 | |
1830 DEFVAR (output_precision, 5.0, 0, output_precision, | |
1831 "number of significant figures to display for numeric output"); | |
1832 | |
1833 DEFVAR (print_empty_dimensions, 1.0, 0, print_empty_dimensions, | |
1834 "also print dimensions of empty matrices"); | |
1835 | |
1836 DEFVAR (split_long_rows, 1.0, 0, split_long_rows, | |
1837 "split long matrix rows instead of wrapping"); | |
1838 } | |
1839 | |
1755 /* | 1840 /* |
1756 ;;; Local Variables: *** | 1841 ;;; Local Variables: *** |
1757 ;;; mode: C++ *** | 1842 ;;; mode: C++ *** |
1758 ;;; End: *** | 1843 ;;; End: *** |
1759 */ | 1844 */ |