*** src/pr-output.cc.orig4 2004-08-06 11:44:02.000000000 +0200 --- src/pr-output.cc 2004-08-27 16:25:13.000000000 +0200 *************** *** 2113,2127 **** typedef T2 print_conv_type; \ } ! PRINT_CONV (octave_int8, octave_int16); ! PRINT_CONV (octave_uint8, octave_uint16); #undef PRINT_CONV template void octave_print_internal (std::ostream& os, const intNDArray& nda, ! bool pr_as_read_syntax, int) { // XXX FIXME XXX -- this mostly duplicates the code in the // PRINT_ND_ARRAY macro. --- 2113,2172 ---- typedef T2 print_conv_type; \ } ! PRINT_CONV (octave_int8_t, octave_int16_t); ! PRINT_CONV (octave_uint8_t, octave_uint16_t); #undef PRINT_CONV template + static inline void + pr_int (std::ostream& os, T d, int fw = 0) + { + unsigned char * tmpi = (unsigned char *) &d; + + if (hex_format) + { + char ofill = os.fill ('0'); + + std::ios::fmtflags oflags + = os.flags (std::ios::right | std::ios::hex); + + //if (hex_format > 1 || oct_mach_info::big_chief) + if (hex_format > 1) + { + for (size_t i = 0; i < sizeof (T); i++) + os << std::setw (2) << static_cast (tmpi[i]); + } + else + { + for (int i = sizeof (T) - 1; i >= 0; i--) + os << std::setw (2) << static_cast (tmpi[i]); + } + + os.fill (ofill); + os.setf (oflags); + } + else if (bit_format) + { + if (bit_format > 1) + { + for (size_t i = 0; i < sizeof (T); i++) + PRINT_CHAR_BITS_SWAPPED (os, tmpi[i]); + } + else + { + for (int i = sizeof (T) - 1; i >= 0; i--) + PRINT_CHAR_BITS (os, tmpi[i]); + } + } + else + os << std::setw (fw) << typename octave_print_conv::print_conv_type (d); + } + + template void octave_print_internal (std::ostream& os, const intNDArray& nda, ! bool pr_as_read_syntax, int extra_indent) { // XXX FIXME XXX -- this mostly duplicates the code in the // PRINT_ND_ARRAY macro. *************** *** 2130,2136 **** print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); else if (nda.length () == 1) { ! os << typename octave_print_conv::print_conv_type (nda(0)); } else { --- 2175,2181 ---- print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); else if (nda.length () == 1) { ! pr_int (os, nda(0).value()); } else { *************** *** 2148,2160 **** int nr = dims(0); int nc = dims(1); ! for (int i = 0; i < m; i++) { ! std::string nm = "ans"; if (m > 1) { ! nm += "(:,:,"; OSSTREAM buf; --- 2193,2238 ---- int nr = dims(0); int nc = dims(1); ! int fw = 0; ! if (hex_format) ! fw = nda(0).nbits() >> 2; ! else if (bit_format) ! fw = nda(0).nbits(); ! else { ! bool sign = false; ! int digits = 0; ! ! for (int i = 0; i < dims.numel(); i++) ! { ! int new_digits = static_cast ! (floor (log10 (double (abs (nda(i).value()))) + 1.0)); + if (new_digits > digits) + digits = new_digits; + + sign = (sign || (abs (nda(i).value()) != nda(i).value()) + ? true : false); + } + fw = digits + (sign ? 1 : 0); + } + + int column_width = fw + 2; + int total_width = nc * column_width; + int max_width = command_editor::terminal_cols () - extra_indent; + int inc = nc; + if (total_width > max_width && Vsplit_long_rows) + { + inc = max_width / column_width; + if (inc == 0) + inc++; + } + + for (int i = 0; i < m; i++) + { if (m > 1) { ! std::string nm = "ans(:,:,"; OSSTREAM buf; *************** *** 2173,2178 **** --- 2251,2258 ---- nm += OSSTREAM_STR (buf); OSSTREAM_FREEZE (buf); + + os << nm << " =\n\n"; } Array idx (ndims); *************** *** 2185,2204 **** Array2 page (nda.index (idx), nr, nc); - // XXX FIXME XXX -- need to do some more work to put these - // in neatly aligned columns... - int n_rows = page.rows (); int n_cols = page.cols (); ! os << nm << " =\n\n"; ! ! for (int ii = 0; ii < n_rows; ii++) { ! for (int jj = 0; jj < n_cols; jj++) ! os << " " << typename octave_print_conv::print_conv_type (page(ii,jj)); ! os << "\n"; } if (i < m - 1) --- 2265,2293 ---- Array2 page (nda.index (idx), nr, nc); int n_rows = page.rows (); int n_cols = page.cols (); ! for (int col = 0; col < n_cols; col += inc) { ! int lim = col + inc < n_cols ? col + inc : n_cols; ! pr_col_num_header (os, total_width, max_width, lim, col, ! extra_indent); ! ! for (int ii = 0; ii < n_rows; ii++) ! { ! os << std::setw (extra_indent) << ""; ! ! for (int jj = col; jj < lim; jj++) ! { ! OCTAVE_QUIT; ! os << " "; ! pr_int (os, (page(ii,jj)).value(), fw); ! } ! if ((ii < n_rows - 1) || (i < m -1)) ! os << "\n"; ! } } if (i < m - 1) *************** *** 2213,2218 **** --- 2302,2331 ---- // XXX FIXME XXX -- this is not the right spot for this... template void + pr_int (std::ostream&, octave_int8_t, int); + + template void + pr_int (std::ostream&, octave_int16_t, int); + + template void + pr_int (std::ostream&, octave_int32_t, int); + + template void + pr_int (std::ostream&, octave_int64_t, int); + + template void + pr_int (std::ostream&, octave_uint8_t, int); + + template void + pr_int (std::ostream&, octave_uint16_t, int); + + template void + pr_int (std::ostream&, octave_uint32_t, int); + + template void + pr_int (std::ostream&, octave_uint64_t, int); + + template void octave_print_internal (std::ostream&, const intNDArray&, bool, int); *************** *** 2248,2256 **** void octave_print_internal (std::ostream& os, const octave_int& val, bool) { ! // XXX FIXME XXX -- we need to handle various formats here... ! ! os << typename octave_print_conv >::print_conv_type (val); } // XXX FIXME XXX -- this is not the right spot for this... --- 2361,2367 ---- void octave_print_internal (std::ostream& os, const octave_int& val, bool) { ! pr_int (os, val.value()); } // XXX FIXME XXX -- this is not the right spot for this...