Mercurial > hg > octave-lojdl
changeset 4420:3dfdbcaf4582
[project @ 2003-05-28 18:24:42 by jwe]
author | jwe |
---|---|
date | Wed, 28 May 2003 18:24:42 +0000 |
parents | 8eb47d7ff594 |
children | 747e1e895f7c |
files | src/ChangeLog src/load-save.cc src/oct-stream.cc |
diffstat | 3 files changed, 80 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2003-05-28 Teemu Ikonen <tpikonen@pcu.helsinki.fi> + + * load-save.cc (save_mat5_binary_element, save_mat_binary_data): + Allow saving of non-7-bit ASCII characters. + +2003-05-28 John W. Eaton <jwe@bevo.che.wisc.edu> + + * oct-stream.cc (FINISH_CHARACTER_CONVERSION, + octave_base_stream::do_scanf): Do a better job of resizing for + charachter conversions. + 2003-05-25 John W. Eaton <jwe@bevo.che.wisc.edu> * ov-cx-mat.cc (octave_complex_matrix::assign): Move definition here.
--- a/src/load-save.cc +++ b/src/load-save.cc @@ -4316,7 +4316,7 @@ const char *s = tstr.data (); for (int j = 0; j < nc; j++) - buf[j*nr+i] = *s++; + buf[j*nr+i] = *s++ & 0x00FF; } os.write ((char *)buf, nr*nc*2); @@ -4450,10 +4450,24 @@ if (tc.is_string ()) { unwind_protect::begin_frame ("save_mat_binary_data"); - unwind_protect_int (Vimplicit_str_to_num_ok); - Vimplicit_str_to_num_ok = true; - Matrix m = tc.matrix_value (); - os.write (X_CAST (char *, m.data ()), 8 * len); + + charMatrix chm = tc.char_matrix_value (); + + int nr = chm.rows (); + int nc = chm.cols (); + + OCTAVE_LOCAL_BUFFER (double, buf, nc*nr); + + for (int i = 0; i < nr; i++) + { + std::string tstr = chm.row_as_string (i); + const char *s = tstr.data (); + + for (int j = 0; j < nc; j++) + buf[j*nr+i] = static_cast<double> (*s++ & 0x00FF); + } + os.write ((char *)buf, nr*nc*sizeof(double)); + unwind_protect::run_frame ("save_mat_binary_data"); } else if (tc.is_range ())
--- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -1341,15 +1341,24 @@ { \ max_size *= 2; \ \ - if (nr > 0) \ - mval.resize (nr, max_size / nr, 0.0); \ - else \ + if (all_char_conv) \ { \ - if (all_char_conv && one_elt_size_spec) \ + if (one_elt_size_spec) \ mval.resize (1, max_size, 0.0); \ + else if (nr > 0) \ + mval.resize (nr, max_size / nr, 0.0); \ else \ - mval.resize (max_size, 1, 0.0); \ + panic_impossible (); \ } \ + else if (nr > 0) \ + { \ + if (nc <= 0) \ + mval.resize (nr, max_size / nr, 0.0); \ + else \ + panic_impossible (); \ + } \ + else \ + mval.resize (max_size, 1, 0.0); \ \ data = mval.fortran_vec (); \ } \ @@ -1396,46 +1405,59 @@ if (all_char_conv) { + // Any of these could be resized later (if we have %s + // conversions, we may read more than one element for each + // conversion). + if (one_elt_size_spec) { max_size = 512; mval.resize (1, max_size, 0.0); - data = mval.fortran_vec (); if (nr > 0) max_conv = nr; } - else if (nr > 0 && nc > 0) + else if (nr > 0) { - mval.resize (nr, nc, 0.0); - data = mval.fortran_vec (); - max_size = max_conv = nr * nc; + if (nc > 0) + { + mval.resize (nr, nc, 0.0); + max_size = max_conv = nr * nc; + } + else + { + mval.resize (nr, 32, 0.0); + max_size = nr * 32; + } } + else + panic_impossible (); } else if (nr > 0) { if (nc > 0) { + // Will not resize later. mval.resize (nr, nc, 0.0); - data = mval.fortran_vec (); max_size = nr * nc; - max_conv = max_size; } else { + // Maybe resize later. mval.resize (nr, 32, 0.0); - data = mval.fortran_vec (); max_size = nr * 32; } } else { + // Maybe resize later. mval.resize (32, 1, 0.0); - data = mval.fortran_vec (); max_size = 32; } + data = mval.fortran_vec (); + if (isp) { std::istream& is = *isp; @@ -1469,15 +1491,24 @@ { max_size *= 2; - if (nr > 0) - mval.resize (nr, max_size / nr, 0.0); - else + if (all_char_conv) { - if (all_char_conv && one_elt_size_spec) + if (one_elt_size_spec) mval.resize (1, max_size, 0.0); + else if (nr > 0) + mval.resize (nr, max_size / nr, 0.0); else - mval.resize (max_size, 1, 0.0); + panic_impossible (); } + else if (nr > 0) + { + if (nc <= 0) + mval.resize (nr, max_size / nr, 0.0); + else + panic_impossible (); + } + else + mval.resize (max_size, 1, 0.0); data = mval.fortran_vec (); }