# HG changeset patch # User John W. Eaton # Date 1265910106 18000 # Node ID 57a59eae83cc631f1d74adad1bffc74ca0c37573 # Parent 07ebe522dac2276527d2a31e8704cd28acd430e5 untabify src C++ source files diff --git a/src/Cell.cc b/src/Cell.cc --- a/src/Cell.cc +++ b/src/Cell.cc @@ -47,18 +47,18 @@ resize (dim_vector (n, 1)); for (octave_idx_type i = 0; i < n; i++) - { - std::string s = sv[i]; + { + std::string s = sv[i]; - if (trim) - { - size_t pos = s.find_last_not_of (' '); + if (trim) + { + size_t pos = s.find_last_not_of (' '); - s = (pos == std::string::npos) ? "" : s.substr (0, pos+1); - } + s = (pos == std::string::npos) ? "" : s.substr (0, pos+1); + } - elem(i,0) = s; - } + elem(i,0) = s; + } } } @@ -89,18 +89,18 @@ octave_idx_type len = n > m ? m : n; for (octave_idx_type i = 0; i < len; i++) - { - std::string s = sv[i]; + { + std::string s = sv[i]; - if (trim) - { - size_t pos = s.find_last_not_of (' '); + if (trim) + { + size_t pos = s.find_last_not_of (' '); - s = (pos == std::string::npos) ? "" : s.substr (0, pos+1); - } + s = (pos == std::string::npos) ? "" : s.substr (0, pos+1); + } - elem(i) = s; - } + elem(i) = s; + } } } @@ -114,10 +114,10 @@ for (octave_idx_type i = 0; i < n; i++) { if (! elem(i).is_string ()) - { - retval = false; - break; - } + { + retval = false; + break; + } } return retval; @@ -151,42 +151,42 @@ case 1: { - idx_vector i = idx_arg(0).index_vector (); + idx_vector i = idx_arg(0).index_vector (); - if (! error_state) - retval = Array::index (i, resize_ok, resize_fill_value ()); + if (! error_state) + retval = Array::index (i, resize_ok, resize_fill_value ()); } break; case 2: { - idx_vector i = idx_arg(0).index_vector (); + idx_vector i = idx_arg(0).index_vector (); - if (! error_state) - { - idx_vector j = idx_arg(1).index_vector (); + if (! error_state) + { + idx_vector j = idx_arg(1).index_vector (); - if (! error_state) - retval = Array::index (i, j, resize_ok, + if (! error_state) + retval = Array::index (i, j, resize_ok, resize_fill_value ()); - } + } } break; default: { - Array iv (n); + Array iv (n); - for (octave_idx_type i = 0; i < n; i++) - { - iv(i) = idx_arg(i).index_vector (); + for (octave_idx_type i = 0; i < n; i++) + { + iv(i) = idx_arg(i).index_vector (); - if (error_state) - break; - } + if (error_state) + break; + } - if (!error_state) - retval = Array::index (iv, resize_ok, + if (!error_state) + retval = Array::index (iv, resize_ok, resize_fill_value ()); } break; @@ -197,7 +197,7 @@ Cell& Cell::assign (const octave_value_list& idx_arg, const Cell& rhs, - const octave_value& fill_val) + const octave_value& fill_val) { octave_idx_type len = idx_arg.length (); @@ -243,16 +243,16 @@ if (ndims () < 3) { if (i < 0 || i >= cols ()) - error ("invalid column selection"); + error ("invalid column selection"); else - { - octave_idx_type nr = rows (); + { + octave_idx_type nr = rows (); - retval.resize (dim_vector (nr, 1)); + retval.resize (dim_vector (nr, 1)); - for (octave_idx_type j = 0; j < nr; j++) - retval.xelem (j) = elem (j, i); - } + for (octave_idx_type j = 0; j < nr; j++) + retval.xelem (j) = elem (j, i); + } } else error ("Cell::column: requires 2-d cell array"); diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,37 @@ +2010-02-11 John W. Eaton + + * Cell.cc, bitfcns.cc, c-file-ptr-stream.cc, comment-list.cc, + data.cc, debug.cc, defaults.cc, defun.cc, dirfns.cc, display.cc, + dynamic-ld.cc, error.cc, file-io.cc, gl-render.cc, + gl2ps-renderer.cc, graphics.cc, gripes.cc, help.cc, input.cc, + load-path.cc, load-save.cc, ls-ascii-helper.cc, ls-hdf5.cc, + ls-mat-ascii.cc, ls-mat4.cc, ls-mat5.cc, ls-oct-ascii.cc, + ls-oct-binary.cc, mex.cc, oct-fstrm.cc, oct-hist.cc, + oct-lvalue.cc, oct-map.cc, oct-obj.cc, oct-prcstrm.cc, + oct-procbuf.cc, oct-stream.cc, oct-strstrm.cc, octave.cc, + ov-base-diag.cc, ov-base-int.cc, ov-base-mat.cc, + ov-base-scalar.cc, ov-base-sparse.cc, ov-base.cc, + ov-bool-mat.cc, ov-bool-sparse.cc, ov-bool.cc, ov-builtin.cc, + ov-cell.cc, ov-ch-mat.cc, ov-class.cc, ov-colon.cc, + ov-complex.cc, ov-cx-diag.cc, ov-cx-mat.cc, ov-cx-sparse.cc, + ov-dld-fcn.cc, ov-fcn-handle.cc, ov-fcn-inline.cc, ov-float.cc, + ov-flt-complex.cc, ov-flt-cx-diag.cc, ov-flt-cx-mat.cc, + ov-flt-re-diag.cc, ov-flt-re-mat.cc, ov-int16.cc, ov-int32.cc, + ov-int64.cc, ov-int8.cc, ov-mex-fcn.cc, ov-perm.cc, ov-range.cc, + ov-re-diag.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, + ov-str-mat.cc, ov-struct.cc, ov-typeinfo.cc, ov-uint16.cc, + ov-uint32.cc, ov-uint64.cc, ov-uint8.cc, ov-usr-fcn.cc, ov.cc, + pager.cc, pr-output.cc, procstream.cc, pt-arg-list.cc, + pt-assign.cc, pt-binop.cc, pt-bp.cc, pt-cbinop.cc, pt-cell.cc, + pt-check.cc, pt-cmd.cc, pt-colon.cc, pt-const.cc, pt-decl.cc, + pt-eval.cc, pt-except.cc, pt-exp.cc, pt-fcn-handle.cc, pt-id.cc, + pt-idx.cc, pt-jump.cc, pt-loop.cc, pt-mat.cc, pt-misc.cc, + pt-pr-code.cc, pt-select.cc, pt-stmt.cc, pt-unop.cc, + sighandlers.cc, sparse-xdiv.cc, sparse-xpow.cc, strfns.cc, + symtab.cc, syscalls.cc, sysdep.cc, toplev.cc, txt-eng-ft.cc, + utils.cc, variables.cc, xdiv.cc, xpow.cc, oct-parse.yy, lex.ll: + Untabify. + 2010-02-11 John W. Eaton * Cell.h, base-list.h, c-file-ptr-stream.h, comment-list.h, diff --git a/src/bitfcns.cc b/src/bitfcns.cc --- a/src/bitfcns.cc +++ b/src/bitfcns.cc @@ -47,36 +47,36 @@ #define BITOPX(OP, FNAME, RET) \ { \ - int nelx = x.numel (); \ - int nely = y.numel (); \ + int nelx = x.numel (); \ + int nely = y.numel (); \ \ - bool is_scalar_op = (nelx == 1 || nely == 1); \ + bool is_scalar_op = (nelx == 1 || nely == 1); \ \ - dim_vector dvx = x.dims (); \ - dim_vector dvy = y.dims (); \ + dim_vector dvx = x.dims (); \ + dim_vector dvy = y.dims (); \ \ - bool is_array_op = (dvx == dvy); \ + bool is_array_op = (dvx == dvy); \ \ - if (is_array_op || is_scalar_op) \ - { \ - RET result; \ + if (is_array_op || is_scalar_op) \ + { \ + RET result; \ \ - if (nelx != 1) \ - result.resize (dvx); \ - else \ - result.resize (dvy); \ + if (nelx != 1) \ + result.resize (dvx); \ + else \ + result.resize (dvy); \ \ - for (int i = 0; i < nelx; i++) \ - if (is_scalar_op) \ - for (int k = 0; k < nely; k++) \ - result(i+k) = x(i) OP y(k); \ - else \ - result(i) = x(i) OP y(i); \ + for (int i = 0; i < nelx; i++) \ + if (is_scalar_op) \ + for (int k = 0; k < nely; k++) \ + result(i+k) = x(i) OP y(k); \ + else \ + result(i) = x(i) OP y(i); \ \ - retval = result; \ - } \ - else \ - error ("%s: size of x and y must match, or one operand must be a scalar", FNAME); \ + retval = result; \ + } \ + else \ + error ("%s: size of x and y must match, or one operand must be a scalar", FNAME); \ } #define BITOP(OP, FNAME) \ @@ -88,173 +88,173 @@ if (nargin == 2) \ { \ if ((args(0).class_name () == octave_scalar::static_class_name ()) \ - || (args(0).class_name () == octave_bool::static_class_name ()) \ - || (args(1).class_name () == octave_scalar::static_class_name ()) \ - || (args(1).class_name () == octave_bool::static_class_name ())) \ - { \ - bool arg0_is_int = (args(0).class_name () != \ - octave_scalar::static_class_name () && \ - args(0).class_name () != \ - octave_bool::static_class_name ()); \ - bool arg1_is_int = (args(1).class_name () != \ - octave_scalar::static_class_name () && \ - args(1).class_name () != \ - octave_bool::static_class_name ()); \ - \ - if (! (arg0_is_int || arg1_is_int)) \ - { \ - uint64NDArray x (args(0).array_value ()); \ - uint64NDArray y (args(1).array_value ()); \ - if (! error_state) \ - BITOPX (OP, FNAME, uint64NDArray); \ - retval = retval.array_value (); \ - } \ - else \ - { \ - int p = (arg0_is_int ? 1 : 0); \ - int q = (arg0_is_int ? 0 : 1); \ + || (args(0).class_name () == octave_bool::static_class_name ()) \ + || (args(1).class_name () == octave_scalar::static_class_name ()) \ + || (args(1).class_name () == octave_bool::static_class_name ())) \ + { \ + bool arg0_is_int = (args(0).class_name () != \ + octave_scalar::static_class_name () && \ + args(0).class_name () != \ + octave_bool::static_class_name ()); \ + bool arg1_is_int = (args(1).class_name () != \ + octave_scalar::static_class_name () && \ + args(1).class_name () != \ + octave_bool::static_class_name ()); \ + \ + if (! (arg0_is_int || arg1_is_int)) \ + { \ + uint64NDArray x (args(0).array_value ()); \ + uint64NDArray y (args(1).array_value ()); \ + if (! error_state) \ + BITOPX (OP, FNAME, uint64NDArray); \ + retval = retval.array_value (); \ + } \ + else \ + { \ + int p = (arg0_is_int ? 1 : 0); \ + int q = (arg0_is_int ? 0 : 1); \ \ - NDArray dx = args(p).array_value (); \ + NDArray dx = args(p).array_value (); \ \ - if (args(q).type_id () == octave_uint64_matrix::static_type_id () \ - || args(q).type_id () == octave_uint64_scalar::static_type_id ()) \ - { \ - uint64NDArray x (dx); \ - uint64NDArray y = args(q).uint64_array_value (); \ - if (! error_state) \ - BITOPX (OP, FNAME, uint64NDArray); \ - } \ - else if (args(q).type_id () == octave_uint32_matrix::static_type_id () \ - || args(q).type_id () == octave_uint32_scalar::static_type_id ()) \ - { \ - uint32NDArray x (dx); \ - uint32NDArray y = args(q).uint32_array_value (); \ - if (! error_state) \ - BITOPX (OP, FNAME, uint32NDArray); \ - } \ - else if (args(q).type_id () == octave_uint16_matrix::static_type_id () \ - || args(q).type_id () == octave_uint16_scalar::static_type_id ()) \ - { \ - uint16NDArray x (dx); \ - uint16NDArray y = args(q).uint16_array_value (); \ - if (! error_state) \ - BITOPX (OP, FNAME, uint16NDArray); \ - } \ - else if (args(q).type_id () == octave_uint8_matrix::static_type_id () \ - || args(q).type_id () == octave_uint8_scalar::static_type_id ()) \ - { \ - uint8NDArray x (dx); \ - uint8NDArray y = args(q).uint8_array_value (); \ - if (! error_state) \ - BITOPX (OP, FNAME, uint8NDArray); \ - } \ - else if (args(q).type_id () == octave_int64_matrix::static_type_id () \ - || args(q).type_id () == octave_int64_scalar::static_type_id ()) \ - { \ - int64NDArray x (dx); \ - int64NDArray y = args(q).int64_array_value (); \ - if (! error_state) \ - BITOPX (OP, FNAME, int64NDArray); \ - } \ - else if (args(q).type_id () == octave_int32_matrix::static_type_id () \ - || args(q).type_id () == octave_int32_scalar::static_type_id ()) \ - { \ - int32NDArray x (dx); \ - int32NDArray y = args(q).int32_array_value (); \ - if (! error_state) \ - BITOPX (OP, FNAME, int32NDArray); \ - } \ - else if (args(q).type_id () == octave_int16_matrix::static_type_id () \ - || args(q).type_id () == octave_int16_scalar::static_type_id ()) \ - { \ - int16NDArray x (dx); \ - int16NDArray y = args(q).int16_array_value (); \ - if (! error_state) \ - BITOPX (OP, FNAME, int16NDArray); \ - } \ - else if (args(q).type_id () == octave_int8_matrix::static_type_id () \ - || args(q).type_id () == octave_int8_scalar::static_type_id ()) \ - { \ - int8NDArray x (dx); \ - int8NDArray y = args(q).int8_array_value (); \ - if (! error_state) \ - BITOPX (OP, FNAME, int8NDArray); \ - } \ - else \ - error ("%s: invalid operand type", FNAME); \ - } \ - } \ + if (args(q).type_id () == octave_uint64_matrix::static_type_id () \ + || args(q).type_id () == octave_uint64_scalar::static_type_id ()) \ + { \ + uint64NDArray x (dx); \ + uint64NDArray y = args(q).uint64_array_value (); \ + if (! error_state) \ + BITOPX (OP, FNAME, uint64NDArray); \ + } \ + else if (args(q).type_id () == octave_uint32_matrix::static_type_id () \ + || args(q).type_id () == octave_uint32_scalar::static_type_id ()) \ + { \ + uint32NDArray x (dx); \ + uint32NDArray y = args(q).uint32_array_value (); \ + if (! error_state) \ + BITOPX (OP, FNAME, uint32NDArray); \ + } \ + else if (args(q).type_id () == octave_uint16_matrix::static_type_id () \ + || args(q).type_id () == octave_uint16_scalar::static_type_id ()) \ + { \ + uint16NDArray x (dx); \ + uint16NDArray y = args(q).uint16_array_value (); \ + if (! error_state) \ + BITOPX (OP, FNAME, uint16NDArray); \ + } \ + else if (args(q).type_id () == octave_uint8_matrix::static_type_id () \ + || args(q).type_id () == octave_uint8_scalar::static_type_id ()) \ + { \ + uint8NDArray x (dx); \ + uint8NDArray y = args(q).uint8_array_value (); \ + if (! error_state) \ + BITOPX (OP, FNAME, uint8NDArray); \ + } \ + else if (args(q).type_id () == octave_int64_matrix::static_type_id () \ + || args(q).type_id () == octave_int64_scalar::static_type_id ()) \ + { \ + int64NDArray x (dx); \ + int64NDArray y = args(q).int64_array_value (); \ + if (! error_state) \ + BITOPX (OP, FNAME, int64NDArray); \ + } \ + else if (args(q).type_id () == octave_int32_matrix::static_type_id () \ + || args(q).type_id () == octave_int32_scalar::static_type_id ()) \ + { \ + int32NDArray x (dx); \ + int32NDArray y = args(q).int32_array_value (); \ + if (! error_state) \ + BITOPX (OP, FNAME, int32NDArray); \ + } \ + else if (args(q).type_id () == octave_int16_matrix::static_type_id () \ + || args(q).type_id () == octave_int16_scalar::static_type_id ()) \ + { \ + int16NDArray x (dx); \ + int16NDArray y = args(q).int16_array_value (); \ + if (! error_state) \ + BITOPX (OP, FNAME, int16NDArray); \ + } \ + else if (args(q).type_id () == octave_int8_matrix::static_type_id () \ + || args(q).type_id () == octave_int8_scalar::static_type_id ()) \ + { \ + int8NDArray x (dx); \ + int8NDArray y = args(q).int8_array_value (); \ + if (! error_state) \ + BITOPX (OP, FNAME, int8NDArray); \ + } \ + else \ + error ("%s: invalid operand type", FNAME); \ + } \ + } \ else if (args(0).class_name () == args(1).class_name ()) \ - { \ - if (args(0).type_id () == octave_uint64_matrix::static_type_id () \ - || args(0).type_id () == octave_uint64_scalar::static_type_id ()) \ - { \ - uint64NDArray x = args(0).uint64_array_value (); \ - uint64NDArray y = args(1).uint64_array_value (); \ - if (! error_state) \ - BITOPX (OP, FNAME, uint64NDArray); \ - } \ - else if (args(0).type_id () == octave_uint32_matrix::static_type_id () \ - || args(0).type_id () == octave_uint32_scalar::static_type_id ()) \ - { \ - uint32NDArray x = args(0).uint32_array_value (); \ - uint32NDArray y = args(1).uint32_array_value (); \ - if (! error_state) \ - BITOPX (OP, FNAME, uint32NDArray); \ - } \ - else if (args(0).type_id () == octave_uint16_matrix::static_type_id () \ - || args(0).type_id () == octave_uint16_scalar::static_type_id ()) \ - { \ - uint16NDArray x = args(0).uint16_array_value (); \ - uint16NDArray y = args(1).uint16_array_value (); \ - if (! error_state) \ - BITOPX (OP, FNAME, uint16NDArray); \ - } \ - else if (args(0).type_id () == octave_uint8_matrix::static_type_id () \ - || args(0).type_id () == octave_uint8_scalar::static_type_id ()) \ - { \ - uint8NDArray x = args(0).uint8_array_value (); \ - uint8NDArray y = args(1).uint8_array_value (); \ - if (! error_state) \ - BITOPX (OP, FNAME, uint8NDArray); \ - } \ - else if (args(0).type_id () == octave_int64_matrix::static_type_id () \ - || args(0).type_id () == octave_int64_scalar::static_type_id ()) \ - { \ - int64NDArray x = args(0).int64_array_value (); \ - int64NDArray y = args(1).int64_array_value (); \ - if (! error_state) \ - BITOPX (OP, FNAME, int64NDArray); \ - } \ - else if (args(0).type_id () == octave_int32_matrix::static_type_id () \ - || args(0).type_id () == octave_int32_scalar::static_type_id ()) \ - { \ - int32NDArray x = args(0).int32_array_value (); \ - int32NDArray y = args(1).int32_array_value (); \ - if (! error_state) \ - BITOPX (OP, FNAME, int32NDArray); \ - } \ - else if (args(0).type_id () == octave_int16_matrix::static_type_id () \ - || args(0).type_id () == octave_int16_scalar::static_type_id ()) \ - { \ - int16NDArray x = args(0).int16_array_value (); \ - int16NDArray y = args(1).int16_array_value (); \ - if (! error_state) \ - BITOPX (OP, FNAME, int16NDArray); \ - } \ - else if (args(0).type_id () == octave_int8_matrix::static_type_id () \ - || args(0).type_id () == octave_int8_scalar::static_type_id ()) \ - { \ - int8NDArray x = args(0).int8_array_value (); \ - int8NDArray y = args(1).int8_array_value (); \ - if (! error_state) \ - BITOPX (OP, FNAME, int8NDArray); \ - } \ - else \ - error ("%s: invalid operand type", FNAME); \ - } \ + { \ + if (args(0).type_id () == octave_uint64_matrix::static_type_id () \ + || args(0).type_id () == octave_uint64_scalar::static_type_id ()) \ + { \ + uint64NDArray x = args(0).uint64_array_value (); \ + uint64NDArray y = args(1).uint64_array_value (); \ + if (! error_state) \ + BITOPX (OP, FNAME, uint64NDArray); \ + } \ + else if (args(0).type_id () == octave_uint32_matrix::static_type_id () \ + || args(0).type_id () == octave_uint32_scalar::static_type_id ()) \ + { \ + uint32NDArray x = args(0).uint32_array_value (); \ + uint32NDArray y = args(1).uint32_array_value (); \ + if (! error_state) \ + BITOPX (OP, FNAME, uint32NDArray); \ + } \ + else if (args(0).type_id () == octave_uint16_matrix::static_type_id () \ + || args(0).type_id () == octave_uint16_scalar::static_type_id ()) \ + { \ + uint16NDArray x = args(0).uint16_array_value (); \ + uint16NDArray y = args(1).uint16_array_value (); \ + if (! error_state) \ + BITOPX (OP, FNAME, uint16NDArray); \ + } \ + else if (args(0).type_id () == octave_uint8_matrix::static_type_id () \ + || args(0).type_id () == octave_uint8_scalar::static_type_id ()) \ + { \ + uint8NDArray x = args(0).uint8_array_value (); \ + uint8NDArray y = args(1).uint8_array_value (); \ + if (! error_state) \ + BITOPX (OP, FNAME, uint8NDArray); \ + } \ + else if (args(0).type_id () == octave_int64_matrix::static_type_id () \ + || args(0).type_id () == octave_int64_scalar::static_type_id ()) \ + { \ + int64NDArray x = args(0).int64_array_value (); \ + int64NDArray y = args(1).int64_array_value (); \ + if (! error_state) \ + BITOPX (OP, FNAME, int64NDArray); \ + } \ + else if (args(0).type_id () == octave_int32_matrix::static_type_id () \ + || args(0).type_id () == octave_int32_scalar::static_type_id ()) \ + { \ + int32NDArray x = args(0).int32_array_value (); \ + int32NDArray y = args(1).int32_array_value (); \ + if (! error_state) \ + BITOPX (OP, FNAME, int32NDArray); \ + } \ + else if (args(0).type_id () == octave_int16_matrix::static_type_id () \ + || args(0).type_id () == octave_int16_scalar::static_type_id ()) \ + { \ + int16NDArray x = args(0).int16_array_value (); \ + int16NDArray y = args(1).int16_array_value (); \ + if (! error_state) \ + BITOPX (OP, FNAME, int16NDArray); \ + } \ + else if (args(0).type_id () == octave_int8_matrix::static_type_id () \ + || args(0).type_id () == octave_int8_scalar::static_type_id ()) \ + { \ + int8NDArray x = args(0).int8_array_value (); \ + int8NDArray y = args(1).int8_array_value (); \ + if (! error_state) \ + BITOPX (OP, FNAME, int8NDArray); \ + } \ + else \ + error ("%s: invalid operand type", FNAME); \ + } \ else \ - error ("%s: must have matching operand types", FNAME); \ + error ("%s: must have matching operand types", FNAME); \ } \ else \ print_usage (); \ @@ -334,46 +334,46 @@ double d1, d2; \ \ if (n.all_integers (d1, d2)) \ - { \ - int m_nel = m.numel (); \ - int n_nel = n.numel (); \ + { \ + int m_nel = m.numel (); \ + int n_nel = n.numel (); \ \ - bool is_scalar_op = (m_nel == 1 || n_nel == 1); \ + bool is_scalar_op = (m_nel == 1 || n_nel == 1); \ \ - dim_vector m_dv = m.dims (); \ - dim_vector n_dv = n.dims (); \ + dim_vector m_dv = m.dims (); \ + dim_vector n_dv = n.dims (); \ \ - bool is_array_op = (m_dv == n_dv); \ + bool is_array_op = (m_dv == n_dv); \ \ - if (is_array_op || is_scalar_op) \ - { \ - T ## NDArray result; \ + if (is_array_op || is_scalar_op) \ + { \ + T ## NDArray result; \ \ - if (m_nel != 1) \ - result.resize (m_dv); \ - else \ - result.resize (n_dv); \ + if (m_nel != 1) \ + result.resize (m_dv); \ + else \ + result.resize (n_dv); \ \ - for (int i = 0; i < m_nel; i++) \ - if (is_scalar_op) \ - for (int k = 0; k < n_nel; k++) \ - if (static_cast (n(k)) >= bits_in_type) \ - result(i+k) = 0; \ - else \ - result(i+k) = bitshift (m(i), static_cast (n(k)), mask); \ - else \ - if (static_cast (n(i)) >= bits_in_type) \ - result(i) = 0; \ - else \ - result(i) = bitshift (m(i), static_cast (n(i)), mask); \ + for (int i = 0; i < m_nel; i++) \ + if (is_scalar_op) \ + for (int k = 0; k < n_nel; k++) \ + if (static_cast (n(k)) >= bits_in_type) \ + result(i+k) = 0; \ + else \ + result(i+k) = bitshift (m(i), static_cast (n(k)), mask); \ + else \ + if (static_cast (n(i)) >= bits_in_type) \ + result(i) = 0; \ + else \ + result(i) = bitshift (m(i), static_cast (n(i)), mask); \ \ - retval = result; \ - } \ - else \ - error ("bitshift: size of A and N must match, or one operand must be a scalar"); \ - } \ + retval = result; \ + } \ + else \ + error ("bitshift: size of A and N must match, or one operand must be a scalar"); \ + } \ else \ - error ("bitshift: expecting second argument to be integer"); \ + error ("bitshift: expecting second argument to be integer"); \ } #define DO_UBITSHIFT(T, N) \ @@ -381,11 +381,11 @@ { \ int bits_in_type = octave_ ## T :: nbits (); \ T ## NDArray m = m_arg.T ## _array_value (); \ - octave_ ## T mask = octave_ ## T::max (); \ + octave_ ## T mask = octave_ ## T::max (); \ if ((N) < bits_in_type) \ - mask = bitshift (mask, (N) - bits_in_type); \ + mask = bitshift (mask, (N) - bits_in_type); \ else if ((N) < 1) \ - mask = 0; \ + mask = 0; \ DO_BITSHIFT (T); \ } \ while (0) @@ -395,11 +395,11 @@ { \ int bits_in_type = octave_ ## T :: nbits (); \ T ## NDArray m = m_arg.T ## _array_value (); \ - octave_ ## T mask = octave_ ## T::max (); \ + octave_ ## T mask = octave_ ## T::max (); \ if ((N) < bits_in_type) \ - mask = bitshift (mask, (N) - bits_in_type); \ + mask = bitshift (mask, (N) - bits_in_type); \ else if ((N) < 1) \ - mask = 0; \ + mask = 0; \ mask = mask | octave_ ## T :: min (); /* FIXME: 2's complement only? */ \ DO_BITSHIFT (T); \ } \ @@ -448,63 +448,63 @@ NDArray n = args(1).array_value (); if (error_state) - error ("bitshift: expecting integer as second argument"); + error ("bitshift: expecting integer as second argument"); else - { - if (nargin == 3) - { - // FIXME -- for compatibility, we should accept an array - // or a scalar as the third argument. - if (args(2).numel () > 1) - error ("bitshift: expecting scalar integer as third argument"); - else - { - nbits = args(2).int_value (); - - if (error_state) - error ("bitshift: expecting integer as third argument"); - else if (nbits < 0) - error ("bitshift: number of bits to mask must be positive"); - } - } - } + { + if (nargin == 3) + { + // FIXME -- for compatibility, we should accept an array + // or a scalar as the third argument. + if (args(2).numel () > 1) + error ("bitshift: expecting scalar integer as third argument"); + else + { + nbits = args(2).int_value (); + + if (error_state) + error ("bitshift: expecting integer as third argument"); + else if (nbits < 0) + error ("bitshift: number of bits to mask must be positive"); + } + } + } if (error_state) - return retval; + return retval; octave_value m_arg = args(0); std::string cname = m_arg.class_name (); if (cname == "uint8") - DO_UBITSHIFT (uint8, nbits < 8 ? nbits : 8); + DO_UBITSHIFT (uint8, nbits < 8 ? nbits : 8); else if (cname == "uint16") - DO_UBITSHIFT (uint16, nbits < 16 ? nbits : 16); + DO_UBITSHIFT (uint16, nbits < 16 ? nbits : 16); else if (cname == "uint32") - DO_UBITSHIFT (uint32, nbits < 32 ? nbits : 32); + DO_UBITSHIFT (uint32, nbits < 32 ? nbits : 32); else if (cname == "uint64") - DO_UBITSHIFT (uint64, nbits < 64 ? nbits : 64); + DO_UBITSHIFT (uint64, nbits < 64 ? nbits : 64); else if (cname == "int8") - DO_SBITSHIFT (int8, nbits < 8 ? nbits : 8); + DO_SBITSHIFT (int8, nbits < 8 ? nbits : 8); else if (cname == "int16") - DO_SBITSHIFT (int16, nbits < 16 ? nbits : 16); + DO_SBITSHIFT (int16, nbits < 16 ? nbits : 16); else if (cname == "int32") - DO_SBITSHIFT (int32, nbits < 32 ? nbits : 32); + DO_SBITSHIFT (int32, nbits < 32 ? nbits : 32); else if (cname == "int64") - DO_SBITSHIFT (int64, nbits < 64 ? nbits : 64); + DO_SBITSHIFT (int64, nbits < 64 ? nbits : 64); else if (cname == "double") - { - nbits = (nbits < 53 ? nbits : 53); - int64_t mask = 0x1FFFFFFFFFFFFFLL; - if (nbits < 53) - mask = mask >> (53 - nbits); - else if (nbits < 1) - mask = 0; - int bits_in_type = 64; - NDArray m = m_arg.array_value (); - DO_BITSHIFT ( ); - } + { + nbits = (nbits < 53 ? nbits : 53); + int64_t mask = 0x1FFFFFFFFFFFFFLL; + if (nbits < 53) + mask = mask >> (53 - nbits); + else if (nbits < 1) + mask = 0; + int bits_in_type = 64; + NDArray m = m_arg.array_value (); + DO_BITSHIFT ( ); + } else - error ("bitshift: not defined for %s objects", cname.c_str ()); + error ("bitshift: not defined for %s objects", cname.c_str ()); } else print_usage (); diff --git a/src/c-file-ptr-stream.cc b/src/c-file-ptr-stream.cc --- a/src/c-file-ptr-stream.cc +++ b/src/c-file-ptr-stream.cc @@ -73,11 +73,11 @@ if (! bump #if defined (CXX_ISO_COMPLIANT_LIBRARY) - && c != traits_type::eof ()) + && c != traits_type::eof ()) #else - && c != EOF) + && c != EOF) #endif - ungetc (c, f); + ungetc (c, f); return c; } @@ -122,15 +122,15 @@ seekdir_to_whence (std::ios::seekdir dir) { return ((dir == std::ios::beg) ? SEEK_SET : - (dir == std::ios::cur) ? SEEK_CUR : - (dir == std::ios::end) ? SEEK_END : - dir); + (dir == std::ios::cur) ? SEEK_CUR : + (dir == std::ios::end) ? SEEK_END : + dir); } std::streampos c_file_ptr_buf::seekoff (std::streamoff /* offset */, - std::ios::seekdir /* dir */, - std::ios::openmode) + std::ios::seekdir /* dir */, + std::ios::openmode) { // FIXME #if 0 @@ -227,11 +227,11 @@ if (! bump #if defined (CXX_ISO_COMPLIANT_LIBRARY) - && c != traits_type::eof ()) + && c != traits_type::eof ()) #else - && c != EOF) + && c != EOF) #endif - gzungetc (c, f); + gzungetc (c, f); return c; } @@ -274,8 +274,8 @@ std::streampos c_zfile_ptr_buf::seekoff (std::streamoff /* offset */, - std::ios::seekdir /* dir */, - std::ios::openmode) + std::ios::seekdir /* dir */, + std::ios::openmode) { // FIXME #if 0 diff --git a/src/comment-list.cc b/src/comment-list.cc --- a/src/comment-list.cc +++ b/src/comment-list.cc @@ -66,7 +66,7 @@ void octave_comment_buffer::append (const std::string& s, - octave_comment_elt::comment_type t) + octave_comment_elt::comment_type t) { if (instance_ok ()) instance->do_append (s, t); @@ -80,7 +80,7 @@ void octave_comment_buffer::do_append (const std::string& s, - octave_comment_elt::comment_type t) + octave_comment_elt::comment_type t) { comment_list->append(s, t); } diff --git a/src/data.cc b/src/data.cc --- a/src/data.cc +++ b/src/data.cc @@ -92,9 +92,9 @@ if (! error_state) \ { \ if (dim >= -1) \ - retval = args(0).FCN (dim); \ + retval = args(0).FCN (dim); \ else \ - error (#FCN ": invalid dimension argument = %d", dim + 1); \ + error (#FCN ": invalid dimension argument = %d", dim + 1); \ } \ else \ error (#FCN ": expecting dimension argument to be an integer"); \ @@ -330,11 +330,11 @@ retval = SparseMatrix (nr, nc, f_zero); for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = y.cidx (j); i < y.cidx (j+1); i++) - { - octave_quit (); - retval.data (y.ridx(i) + j * nr) = f (x, y.data (i)); - } + for (octave_idx_type i = y.cidx (j); i < y.cidx (j+1); i++) + { + octave_quit (); + retval.data (y.ridx(i) + j * nr) = f (x, y.data (i)); + } retval.maybe_compress (true); } @@ -346,20 +346,20 @@ retval.cidx (ii) = 0; for (octave_idx_type j = 0; j < nc; j++) - { - for (octave_idx_type i = y.cidx (j); i < y.cidx (j+1); i++) - { - octave_quit (); - double val = f (x, y.data (i)); - - if (val != 0.0) - { - retval.data (ii) = val; - retval.ridx (ii++) = y.ridx (i); - } - } - retval.cidx (j + 1) = ii; - } + { + for (octave_idx_type i = y.cidx (j); i < y.cidx (j+1); i++) + { + octave_quit (); + double val = f (x, y.data (i)); + + if (val != 0.0) + { + retval.data (ii) = val; + retval.ridx (ii++) = y.ridx (i); + } + } + retval.cidx (j + 1) = ii; + } retval.maybe_compress (false); } @@ -380,11 +380,11 @@ retval = SparseMatrix (nr, nc, f_zero); for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = x.cidx (j); i < x.cidx (j+1); i++) - { - octave_quit (); - retval.data (x.ridx(i) + j * nr) = f (x.data (i), y); - } + for (octave_idx_type i = x.cidx (j); i < x.cidx (j+1); i++) + { + octave_quit (); + retval.data (x.ridx(i) + j * nr) = f (x.data (i), y); + } retval.maybe_compress (true); } @@ -396,20 +396,20 @@ retval.cidx (ii) = 0; for (octave_idx_type j = 0; j < nc; j++) - { - for (octave_idx_type i = x.cidx (j); i < x.cidx (j+1); i++) - { - octave_quit (); - double val = f (x.data (i), y); - - if (val != 0.0) - { - retval.data (ii) = val; - retval.ridx (ii++) = x.ridx (i); - } - } - retval.cidx (j + 1) = ii; - } + { + for (octave_idx_type i = x.cidx (j); i < x.cidx (j+1); i++) + { + octave_quit (); + double val = f (x.data (i), y); + + if (val != 0.0) + { + retval.data (ii) = val; + retval.ridx (ii++) = x.ridx (i); + } + } + retval.cidx (j + 1) = ii; + } retval.maybe_compress (false); } @@ -437,44 +437,44 @@ octave_idx_type k1 = 0, k2 = 0; for (octave_idx_type j = 0; j < nc; j++) - { - while (k1 < x.cidx(j+1) && k2 < y.cidx(j+1)) - { - octave_quit (); - if (k1 >= x.cidx(j+1)) - { - retval.data (y.ridx(k2) + j * nr) = f (0.0, y.data (k2)); - k2++; - } - else if (k2 >= y.cidx(j+1)) - { - retval.data (x.ridx(k1) + j * nr) = f (x.data (k1), 0.0); - k1++; - } - else - { - octave_idx_type rx = x.ridx(k1); - octave_idx_type ry = y.ridx(k2); - - if (rx < ry) - { - retval.data (rx + j * nr) = f (x.data (k1), 0.0); - k1++; - } - else if (rx > ry) - { - retval.data (ry + j * nr) = f (0.0, y.data (k2)); - k2++; - } - else - { - retval.data (ry + j * nr) = f (x.data (k1), y.data (k2)); - k1++; - k2++; - } - } - } - } + { + while (k1 < x.cidx(j+1) && k2 < y.cidx(j+1)) + { + octave_quit (); + if (k1 >= x.cidx(j+1)) + { + retval.data (y.ridx(k2) + j * nr) = f (0.0, y.data (k2)); + k2++; + } + else if (k2 >= y.cidx(j+1)) + { + retval.data (x.ridx(k1) + j * nr) = f (x.data (k1), 0.0); + k1++; + } + else + { + octave_idx_type rx = x.ridx(k1); + octave_idx_type ry = y.ridx(k2); + + if (rx < ry) + { + retval.data (rx + j * nr) = f (x.data (k1), 0.0); + k1++; + } + else if (rx > ry) + { + retval.data (ry + j * nr) = f (0.0, y.data (k2)); + k2++; + } + else + { + retval.data (ry + j * nr) = f (x.data (k1), y.data (k2)); + k1++; + k2++; + } + } + } + } retval.maybe_compress (true); } @@ -487,51 +487,51 @@ octave_idx_type k1 = 0, k2 = 0; for (octave_idx_type j = 0; j < nc; j++) - { - while (k1 < x.cidx(j+1) && k2 < y.cidx(j+1)) - { - octave_quit (); - double val; - octave_idx_type r; - if (k1 >= x.cidx(j+1)) - { - r = y.ridx (k2); - val = f (0.0, y.data (k2++)); - } - else if (k2 >= y.cidx(j+1)) - { - r = x.ridx (k1); - val = f (x.data (k1++), 0.0); - } - else - { - octave_idx_type rx = x.ridx(k1); - octave_idx_type ry = y.ridx(k2); - - if (rx < ry) - { - r = x.ridx (k1); - val = f (x.data (k1++), 0.0); - } - else if (rx > ry) - { - r = y.ridx (k2); - val = f (0.0, y.data (k2++)); - } - else - { - r = y.ridx (k2); - val = f (x.data (k1++), y.data (k2++)); - } - } - if (val != 0.0) - { - retval.data (ii) = val; - retval.ridx (ii++) = r; - } - } - retval.cidx (j + 1) = ii; - } + { + while (k1 < x.cidx(j+1) && k2 < y.cidx(j+1)) + { + octave_quit (); + double val; + octave_idx_type r; + if (k1 >= x.cidx(j+1)) + { + r = y.ridx (k2); + val = f (0.0, y.data (k2++)); + } + else if (k2 >= y.cidx(j+1)) + { + r = x.ridx (k1); + val = f (x.data (k1++), 0.0); + } + else + { + octave_idx_type rx = x.ridx(k1); + octave_idx_type ry = y.ridx(k2); + + if (rx < ry) + { + r = x.ridx (k1); + val = f (x.data (k1++), 0.0); + } + else if (rx > ry) + { + r = y.ridx (k2); + val = f (0.0, y.data (k2++)); + } + else + { + r = y.ridx (k2); + val = f (x.data (k1++), y.data (k2++)); + } + } + if (val != 0.0) + { + retval.data (ii) = val; + retval.ridx (ii++) = r; + } + } + retval.cidx (j + 1) = ii; + } retval.maybe_compress (false); } @@ -554,158 +554,158 @@ if (nargin == 2 && args(0).is_defined () && args(1).is_defined ()) { if (args(0).is_integer_type () || args(1).is_integer_type ()) - error ("atan2: not defined for integer types"); + error ("atan2: not defined for integer types"); else - { - octave_value arg_y = args(0); - octave_value arg_x = args(1); - - dim_vector y_dims = arg_y.dims (); - dim_vector x_dims = arg_x.dims (); - - bool y_is_scalar = y_dims.all_ones (); - bool x_is_scalar = x_dims.all_ones (); - - bool is_float = arg_y.is_single_type () || arg_x.is_single_type (); - - if (y_is_scalar && x_is_scalar) - { - if (is_float) - { - float y = arg_y.float_value (); - - if (! error_state) - { - float x = arg_x.float_value (); - - if (! error_state) - retval = atan2f (y, x); - } - } - else - { - double y = arg_y.double_value (); - - if (! error_state) - { - double x = arg_x.double_value (); - - if (! error_state) - retval = atan2 (y, x); - } - } - } - else if (y_is_scalar) - { - if (is_float) - { - float y = arg_y.float_value (); - - if (! error_state) - { - // Even if x is sparse return a full matrix here - FloatNDArray x = arg_x.float_array_value (); - - if (! error_state) - retval = map_f_fm (atan2f, y, x); - } - } - else - { - double y = arg_y.double_value (); - - if (! error_state) - { - // Even if x is sparse return a full matrix here - NDArray x = arg_x.array_value (); - - if (! error_state) - retval = map_d_m (atan2, y, x); - } - } - } - else if (x_is_scalar) - { - if (arg_y.is_sparse_type ()) - { - SparseMatrix y = arg_y.sparse_matrix_value (); - - if (! error_state) - { - double x = arg_x.double_value (); - - if (! error_state) - retval = map_s_d (atan2, y, x); - } - } - else if (is_float) - { - FloatNDArray y = arg_y.float_array_value (); - - if (! error_state) - { - float x = arg_x.float_value (); - - if (! error_state) - retval = map_fm_f (atan2f, y, x); - } - } - else - { - NDArray y = arg_y.array_value (); - - if (! error_state) - { - double x = arg_x.double_value (); - - if (! error_state) - retval = map_m_d (atan2, y, x); - } - } - } - else if (y_dims == x_dims) - { - // Even if y is sparse return a full matrix here - if (arg_x.is_sparse_type ()) - { - SparseMatrix y = arg_y.sparse_matrix_value (); - - if (! error_state) - { - SparseMatrix x = arg_x.sparse_matrix_value (); - - if (! error_state) - retval = map_s_s (atan2, y, x); - } - } - else if (is_float) - { - FloatNDArray y = arg_y.array_value (); - - if (! error_state) - { - FloatNDArray x = arg_x.array_value (); - - if (! error_state) - retval = map_fm_fm (atan2f, y, x); - } - } - else - { - NDArray y = arg_y.array_value (); - - if (! error_state) - { - NDArray x = arg_x.array_value (); - - if (! error_state) - retval = map_m_m (atan2, y, x); - } - } - } - else - error ("atan2: nonconformant matrices"); - } + { + octave_value arg_y = args(0); + octave_value arg_x = args(1); + + dim_vector y_dims = arg_y.dims (); + dim_vector x_dims = arg_x.dims (); + + bool y_is_scalar = y_dims.all_ones (); + bool x_is_scalar = x_dims.all_ones (); + + bool is_float = arg_y.is_single_type () || arg_x.is_single_type (); + + if (y_is_scalar && x_is_scalar) + { + if (is_float) + { + float y = arg_y.float_value (); + + if (! error_state) + { + float x = arg_x.float_value (); + + if (! error_state) + retval = atan2f (y, x); + } + } + else + { + double y = arg_y.double_value (); + + if (! error_state) + { + double x = arg_x.double_value (); + + if (! error_state) + retval = atan2 (y, x); + } + } + } + else if (y_is_scalar) + { + if (is_float) + { + float y = arg_y.float_value (); + + if (! error_state) + { + // Even if x is sparse return a full matrix here + FloatNDArray x = arg_x.float_array_value (); + + if (! error_state) + retval = map_f_fm (atan2f, y, x); + } + } + else + { + double y = arg_y.double_value (); + + if (! error_state) + { + // Even if x is sparse return a full matrix here + NDArray x = arg_x.array_value (); + + if (! error_state) + retval = map_d_m (atan2, y, x); + } + } + } + else if (x_is_scalar) + { + if (arg_y.is_sparse_type ()) + { + SparseMatrix y = arg_y.sparse_matrix_value (); + + if (! error_state) + { + double x = arg_x.double_value (); + + if (! error_state) + retval = map_s_d (atan2, y, x); + } + } + else if (is_float) + { + FloatNDArray y = arg_y.float_array_value (); + + if (! error_state) + { + float x = arg_x.float_value (); + + if (! error_state) + retval = map_fm_f (atan2f, y, x); + } + } + else + { + NDArray y = arg_y.array_value (); + + if (! error_state) + { + double x = arg_x.double_value (); + + if (! error_state) + retval = map_m_d (atan2, y, x); + } + } + } + else if (y_dims == x_dims) + { + // Even if y is sparse return a full matrix here + if (arg_x.is_sparse_type ()) + { + SparseMatrix y = arg_y.sparse_matrix_value (); + + if (! error_state) + { + SparseMatrix x = arg_x.sparse_matrix_value (); + + if (! error_state) + retval = map_s_s (atan2, y, x); + } + } + else if (is_float) + { + FloatNDArray y = arg_y.array_value (); + + if (! error_state) + { + FloatNDArray x = arg_x.array_value (); + + if (! error_state) + retval = map_fm_fm (atan2f, y, x); + } + } + else + { + NDArray y = arg_y.array_value (); + + if (! error_state) + { + NDArray x = arg_x.array_value (); + + if (! error_state) + retval = map_m_m (atan2, y, x); + } + } + } + else + error ("atan2: nonconformant matrices"); + } } else print_usage (); @@ -759,215 +759,215 @@ if (nargin == 2 && args(0).is_defined () && args(1).is_defined ()) { if (args(0).is_integer_type () || args(1).is_integer_type ()) - error ("hypot: not defined for integer types"); + error ("hypot: not defined for integer types"); else - { - octave_value arg_x = args(0); - octave_value arg_y = args(1); - - dim_vector x_dims = arg_x.dims (); - dim_vector y_dims = arg_y.dims (); - - bool x_is_scalar = x_dims.all_ones (); - bool y_is_scalar = y_dims.all_ones (); - - bool is_float = arg_y.is_single_type () || arg_x.is_single_type (); - - if (y_is_scalar && x_is_scalar) - { - if (is_float) - { - float x; - if (arg_x.is_complex_type ()) - x = abs (arg_x.float_complex_value ()); - else - x = arg_x.float_value (); - - if (! error_state) - { - float y; - if (arg_y.is_complex_type ()) - y = abs (arg_y.float_complex_value ()); - else - y = arg_y.float_value (); - - if (! error_state) - retval = hypotf (x, y); - } - } - else - { - double x; - if (arg_x.is_complex_type ()) - x = abs (arg_x.complex_value ()); - else - x = arg_x.double_value (); - - if (! error_state) - { - double y; - if (arg_y.is_complex_type ()) - y = abs (arg_y.complex_value ()); - else - y = arg_y.double_value (); - - if (! error_state) - retval = hypot (x, y); - } - } - } - else if (y_is_scalar) - { - if (is_float) - { - FloatNDArray x; - if (arg_x.is_complex_type ()) - x = arg_x.float_complex_array_value ().abs (); - else - x = arg_x.float_array_value (); - - if (! error_state) - { - float y; - if (arg_y.is_complex_type ()) - y = abs (arg_y.float_complex_value ()); - else - y = arg_y.float_value (); - - if (! error_state) - retval = map_fm_f (hypotf, x, y); - } - } - else - { - NDArray x; - if (arg_x.is_complex_type ()) - x = arg_x.complex_array_value ().abs (); - else - x = arg_x.array_value (); - - if (! error_state) - { - double y; - if (arg_y.is_complex_type ()) - y = abs (arg_y.complex_value ()); - else - y = arg_y.double_value (); - - if (! error_state) - retval = map_m_d (hypot, x, y); - } - } - } - else if (x_is_scalar) - { - if (is_float) - { - float x; - if (arg_x.is_complex_type ()) - x = abs (arg_x.float_complex_value ()); - else - x = arg_x.float_value (); - - if (! error_state) - { - FloatNDArray y; - if (arg_y.is_complex_type ()) - y = arg_y.float_complex_array_value ().abs (); - else - y = arg_y.float_array_value (); - - if (! error_state) - retval = map_f_fm (hypotf, x, y); - } - } - else - { - double x; - if (arg_x.is_complex_type ()) - x = abs (arg_x.complex_value ()); - else - x = arg_x.double_value (); - - if (! error_state) - { - NDArray y; - if (arg_y.is_complex_type ()) - y = arg_y.complex_array_value ().abs (); - else - y = arg_y.array_value (); - - if (! error_state) - retval = map_d_m (hypot, x, y); - } - } - } - else if (y_dims == x_dims) - { - if (arg_x.is_sparse_type () && arg_y.is_sparse_type ()) - { - SparseMatrix x; - if (arg_x.is_complex_type ()) - x = arg_x.sparse_complex_matrix_value ().abs (); - else - x = arg_x.sparse_matrix_value (); - - if (! error_state) - { - SparseMatrix y; - if (arg_y.is_complex_type ()) - y = arg_y.sparse_complex_matrix_value ().abs (); - else - y = arg_y.sparse_matrix_value (); - - if (! error_state) - retval = map_s_s (hypot, x, y); - } - } - else if (is_float) - { - FloatNDArray x; - if (arg_x.is_complex_type ()) - x = arg_x.float_complex_array_value ().abs (); - else - x = arg_x.float_array_value (); - - if (! error_state) - { - FloatNDArray y; - if (arg_y.is_complex_type ()) - y = arg_y.float_complex_array_value ().abs (); - else - y = arg_y.float_array_value (); - - if (! error_state) - retval = map_fm_fm (hypotf, x, y); - } - } - else - { - NDArray x; - if (arg_x.is_complex_type ()) - x = arg_x.complex_array_value ().abs (); - else - x = arg_x.array_value (); - - if (! error_state) - { - NDArray y; - if (arg_y.is_complex_type ()) - y = arg_y.complex_array_value ().abs (); - else - y = arg_y.array_value (); - - if (! error_state) - retval = map_m_m (hypot, x, y); - } - } - } - else - error ("hypot: nonconformant matrices"); - } + { + octave_value arg_x = args(0); + octave_value arg_y = args(1); + + dim_vector x_dims = arg_x.dims (); + dim_vector y_dims = arg_y.dims (); + + bool x_is_scalar = x_dims.all_ones (); + bool y_is_scalar = y_dims.all_ones (); + + bool is_float = arg_y.is_single_type () || arg_x.is_single_type (); + + if (y_is_scalar && x_is_scalar) + { + if (is_float) + { + float x; + if (arg_x.is_complex_type ()) + x = abs (arg_x.float_complex_value ()); + else + x = arg_x.float_value (); + + if (! error_state) + { + float y; + if (arg_y.is_complex_type ()) + y = abs (arg_y.float_complex_value ()); + else + y = arg_y.float_value (); + + if (! error_state) + retval = hypotf (x, y); + } + } + else + { + double x; + if (arg_x.is_complex_type ()) + x = abs (arg_x.complex_value ()); + else + x = arg_x.double_value (); + + if (! error_state) + { + double y; + if (arg_y.is_complex_type ()) + y = abs (arg_y.complex_value ()); + else + y = arg_y.double_value (); + + if (! error_state) + retval = hypot (x, y); + } + } + } + else if (y_is_scalar) + { + if (is_float) + { + FloatNDArray x; + if (arg_x.is_complex_type ()) + x = arg_x.float_complex_array_value ().abs (); + else + x = arg_x.float_array_value (); + + if (! error_state) + { + float y; + if (arg_y.is_complex_type ()) + y = abs (arg_y.float_complex_value ()); + else + y = arg_y.float_value (); + + if (! error_state) + retval = map_fm_f (hypotf, x, y); + } + } + else + { + NDArray x; + if (arg_x.is_complex_type ()) + x = arg_x.complex_array_value ().abs (); + else + x = arg_x.array_value (); + + if (! error_state) + { + double y; + if (arg_y.is_complex_type ()) + y = abs (arg_y.complex_value ()); + else + y = arg_y.double_value (); + + if (! error_state) + retval = map_m_d (hypot, x, y); + } + } + } + else if (x_is_scalar) + { + if (is_float) + { + float x; + if (arg_x.is_complex_type ()) + x = abs (arg_x.float_complex_value ()); + else + x = arg_x.float_value (); + + if (! error_state) + { + FloatNDArray y; + if (arg_y.is_complex_type ()) + y = arg_y.float_complex_array_value ().abs (); + else + y = arg_y.float_array_value (); + + if (! error_state) + retval = map_f_fm (hypotf, x, y); + } + } + else + { + double x; + if (arg_x.is_complex_type ()) + x = abs (arg_x.complex_value ()); + else + x = arg_x.double_value (); + + if (! error_state) + { + NDArray y; + if (arg_y.is_complex_type ()) + y = arg_y.complex_array_value ().abs (); + else + y = arg_y.array_value (); + + if (! error_state) + retval = map_d_m (hypot, x, y); + } + } + } + else if (y_dims == x_dims) + { + if (arg_x.is_sparse_type () && arg_y.is_sparse_type ()) + { + SparseMatrix x; + if (arg_x.is_complex_type ()) + x = arg_x.sparse_complex_matrix_value ().abs (); + else + x = arg_x.sparse_matrix_value (); + + if (! error_state) + { + SparseMatrix y; + if (arg_y.is_complex_type ()) + y = arg_y.sparse_complex_matrix_value ().abs (); + else + y = arg_y.sparse_matrix_value (); + + if (! error_state) + retval = map_s_s (hypot, x, y); + } + } + else if (is_float) + { + FloatNDArray x; + if (arg_x.is_complex_type ()) + x = arg_x.float_complex_array_value ().abs (); + else + x = arg_x.float_array_value (); + + if (! error_state) + { + FloatNDArray y; + if (arg_y.is_complex_type ()) + y = arg_y.float_complex_array_value ().abs (); + else + y = arg_y.float_array_value (); + + if (! error_state) + retval = map_fm_fm (hypotf, x, y); + } + } + else + { + NDArray x; + if (arg_x.is_complex_type ()) + x = arg_x.complex_array_value ().abs (); + else + x = arg_x.array_value (); + + if (! error_state) + { + NDArray y; + if (arg_y.is_complex_type ()) + y = arg_y.complex_array_value ().abs (); + else + y = arg_y.array_value (); + + if (! error_state) + retval = map_m_m (hypot, x, y); + } + } + } + else + error ("hypot: nonconformant matrices"); + } } else print_usage (); @@ -1030,28 +1030,28 @@ if (nargout < 2) retval(0) = args(0).log2 (); else if (args(0).is_single_type ()) - { - if (args(0).is_real_type ()) - { - FloatNDArray f; - FloatNDArray x = args(0).float_array_value (); - // FIXME -- should E be an int value? - FloatMatrix e; - map_2_xlog2 (x, f, e); - retval (1) = e; - retval (0) = f; - } - else if (args(0).is_complex_type ()) - { - FloatComplexNDArray f; - FloatComplexNDArray x = args(0).float_complex_array_value (); - // FIXME -- should E be an int value? - FloatNDArray e; - map_2_xlog2 (x, f, e); - retval (1) = e; - retval (0) = f; - } - } + { + if (args(0).is_real_type ()) + { + FloatNDArray f; + FloatNDArray x = args(0).float_array_value (); + // FIXME -- should E be an int value? + FloatMatrix e; + map_2_xlog2 (x, f, e); + retval (1) = e; + retval (0) = f; + } + else if (args(0).is_complex_type ()) + { + FloatComplexNDArray f; + FloatComplexNDArray x = args(0).float_complex_array_value (); + // FIXME -- should E be an int value? + FloatNDArray e; + map_2_xlog2 (x, f, e); + retval (1) = e; + retval (0) = f; + } + } else if (args(0).is_real_type ()) { NDArray f; @@ -1126,149 +1126,149 @@ bool is_float = arg_y.is_single_type () || arg_x.is_single_type (); if (y_is_scalar && x_is_scalar) - { - if (is_float) - { - float y = arg_y.float_value (); - - if (! error_state) - { - float x = arg_x.float_value (); - - if (! error_state) - retval = fmod (x, y); - } - } - else - { - double y = arg_y.double_value (); - - if (! error_state) - { - double x = arg_x.double_value (); - - if (! error_state) - retval = fmod (x, y); - } - } - } + { + if (is_float) + { + float y = arg_y.float_value (); + + if (! error_state) + { + float x = arg_x.float_value (); + + if (! error_state) + retval = fmod (x, y); + } + } + else + { + double y = arg_y.double_value (); + + if (! error_state) + { + double x = arg_x.double_value (); + + if (! error_state) + retval = fmod (x, y); + } + } + } else if (y_is_scalar) - { - if (is_float) - { - float y = arg_y.float_value (); - - if (! error_state) - { - FloatNDArray x = arg_x.float_array_value (); - - if (! error_state) - retval = map_fm_f (fmodf, x, y); - } - } - else - { - double y = arg_y.double_value (); - - if (! error_state) - { - if (arg_x.is_sparse_type ()) - { - SparseMatrix x = arg_x.sparse_matrix_value (); - - if (! error_state) - retval = map_s_d (fmod, x, y); - } - else - { - NDArray x = arg_x.array_value (); - - if (! error_state) - retval = map_m_d (fmod, x, y); - } - } - } - } + { + if (is_float) + { + float y = arg_y.float_value (); + + if (! error_state) + { + FloatNDArray x = arg_x.float_array_value (); + + if (! error_state) + retval = map_fm_f (fmodf, x, y); + } + } + else + { + double y = arg_y.double_value (); + + if (! error_state) + { + if (arg_x.is_sparse_type ()) + { + SparseMatrix x = arg_x.sparse_matrix_value (); + + if (! error_state) + retval = map_s_d (fmod, x, y); + } + else + { + NDArray x = arg_x.array_value (); + + if (! error_state) + retval = map_m_d (fmod, x, y); + } + } + } + } else if (x_is_scalar) - { - if (arg_y.is_sparse_type ()) - { - SparseMatrix y = arg_y.sparse_matrix_value (); - - if (! error_state) - { - double x = arg_x.double_value (); - - if (! error_state) - retval = map_d_s (fmod, x, y); - } - } - else if (is_float) - { - FloatNDArray y = arg_y.float_array_value (); - - if (! error_state) - { - float x = arg_x.float_value (); - - if (! error_state) - retval = map_f_fm (fmodf, x, y); - } - } - else - { - NDArray y = arg_y.array_value (); - - if (! error_state) - { - double x = arg_x.double_value (); - - if (! error_state) - retval = map_d_m (fmod, x, y); - } - } - } + { + if (arg_y.is_sparse_type ()) + { + SparseMatrix y = arg_y.sparse_matrix_value (); + + if (! error_state) + { + double x = arg_x.double_value (); + + if (! error_state) + retval = map_d_s (fmod, x, y); + } + } + else if (is_float) + { + FloatNDArray y = arg_y.float_array_value (); + + if (! error_state) + { + float x = arg_x.float_value (); + + if (! error_state) + retval = map_f_fm (fmodf, x, y); + } + } + else + { + NDArray y = arg_y.array_value (); + + if (! error_state) + { + double x = arg_x.double_value (); + + if (! error_state) + retval = map_d_m (fmod, x, y); + } + } + } else if (y_dims == x_dims) - { - if (arg_y.is_sparse_type () || arg_x.is_sparse_type ()) - { - SparseMatrix y = arg_y.sparse_matrix_value (); - - if (! error_state) - { - SparseMatrix x = arg_x.sparse_matrix_value (); - - if (! error_state) - retval = map_s_s (fmod, x, y); - } - } - else if (is_float) - { - FloatNDArray y = arg_y.float_array_value (); - - if (! error_state) - { - FloatNDArray x = arg_x.float_array_value (); - - if (! error_state) - retval = map_fm_fm (fmodf, x, y); - } - } - else - { - NDArray y = arg_y.array_value (); - - if (! error_state) - { - NDArray x = arg_x.array_value (); - - if (! error_state) - retval = map_m_m (fmod, x, y); - } - } - } + { + if (arg_y.is_sparse_type () || arg_x.is_sparse_type ()) + { + SparseMatrix y = arg_y.sparse_matrix_value (); + + if (! error_state) + { + SparseMatrix x = arg_x.sparse_matrix_value (); + + if (! error_state) + retval = map_s_s (fmod, x, y); + } + } + else if (is_float) + { + FloatNDArray y = arg_y.float_array_value (); + + if (! error_state) + { + FloatNDArray x = arg_x.float_array_value (); + + if (! error_state) + retval = map_fm_fm (fmodf, x, y); + } + } + else + { + NDArray y = arg_y.array_value (); + + if (! error_state) + { + NDArray x = arg_x.array_value (); + + if (! error_state) + retval = map_m_m (fmod, x, y); + } + } + } else - error ("fmod: nonconformant matrices"); + error ("fmod: nonconformant matrices"); } else print_usage (); @@ -1318,15 +1318,15 @@ std::string str = args(nargin - 1).string_value (); \ \ if (! error_state) \ - { \ - if (str == "native") \ - isnative = true; \ - else if (str == "double") \ + { \ + if (str == "native") \ + isnative = true; \ + else if (str == "double") \ isdouble = true; \ else \ - error ("sum: unrecognized string argument"); \ + error ("sum: unrecognized string argument"); \ nargin --; \ - } \ + } \ } \ \ if (nargin == 1 || nargin == 2) \ @@ -1336,32 +1336,32 @@ int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \ \ if (! error_state) \ - { \ - if (dim >= -1) \ - { \ - if (arg.is_sparse_type ()) \ - { \ - if (arg.is_real_type ()) \ - { \ - SparseMatrix tmp = arg.sparse_matrix_value (); \ - \ - if (! error_state) \ - retval = tmp.FCN (dim); \ - } \ - else \ - { \ - SparseComplexMatrix tmp = arg.sparse_complex_matrix_value (); \ + { \ + if (dim >= -1) \ + { \ + if (arg.is_sparse_type ()) \ + { \ + if (arg.is_real_type ()) \ + { \ + SparseMatrix tmp = arg.sparse_matrix_value (); \ \ - if (! error_state) \ - retval = tmp.FCN (dim); \ - } \ - } \ - else \ - { \ - if (isnative) \ - { \ - if NATIVE_REDUCTION_1 (FCN, uint8, dim) \ - else if NATIVE_REDUCTION_1 (FCN, uint16, dim) \ + if (! error_state) \ + retval = tmp.FCN (dim); \ + } \ + else \ + { \ + SparseComplexMatrix tmp = arg.sparse_complex_matrix_value (); \ + \ + if (! error_state) \ + retval = tmp.FCN (dim); \ + } \ + } \ + else \ + { \ + if (isnative) \ + { \ + if NATIVE_REDUCTION_1 (FCN, uint8, dim) \ + else if NATIVE_REDUCTION_1 (FCN, uint16, dim) \ else if NATIVE_REDUCTION_1 (FCN, uint32, dim) \ else if NATIVE_REDUCTION_1 (FCN, uint64, dim) \ else if NATIVE_REDUCTION_1 (FCN, int8, dim) \ @@ -1376,45 +1376,45 @@ } \ else if (arg.is_char_matrix ()) \ { \ - error (#FCN, ": invalid char type"); \ - } \ - else if (!isdouble && arg.is_single_type ()) \ + error (#FCN, ": invalid char type"); \ + } \ + else if (!isdouble && arg.is_single_type ()) \ { \ - if (arg.is_complex_type ()) \ - { \ - FloatComplexNDArray tmp = \ - arg.float_complex_array_value (); \ + if (arg.is_complex_type ()) \ + { \ + FloatComplexNDArray tmp = \ + arg.float_complex_array_value (); \ \ - if (! error_state) \ - retval = tmp.FCN (dim); \ - } \ - else if (arg.is_real_type ()) \ - { \ - FloatNDArray tmp = arg.float_array_value (); \ + if (! error_state) \ + retval = tmp.FCN (dim); \ + } \ + else if (arg.is_real_type ()) \ + { \ + FloatNDArray tmp = arg.float_array_value (); \ \ - if (! error_state) \ - retval = tmp.FCN (dim); \ - } \ - } \ - else if (arg.is_complex_type ()) \ - { \ - ComplexNDArray tmp = arg.complex_array_value (); \ + if (! error_state) \ + retval = tmp.FCN (dim); \ + } \ + } \ + else if (arg.is_complex_type ()) \ + { \ + ComplexNDArray tmp = arg.complex_array_value (); \ \ - if (! error_state) \ - retval = tmp.FCN (dim); \ - } \ - else if (arg.is_real_type ()) \ - { \ - NDArray tmp = arg.array_value (); \ + if (! error_state) \ + retval = tmp.FCN (dim); \ + } \ + else if (arg.is_real_type ()) \ + { \ + NDArray tmp = arg.array_value (); \ \ - if (! error_state) \ - retval = tmp.FCN (dim); \ - } \ + if (! error_state) \ + retval = tmp.FCN (dim); \ + } \ else \ - { \ - gripe_wrong_type_arg (#FCN, arg); \ - return retval; \ - } \ + { \ + gripe_wrong_type_arg (#FCN, arg); \ + return retval; \ + } \ } \ else if (arg.is_bool_type ()) \ { \ @@ -1422,48 +1422,48 @@ if (! error_state) \ retval = tmp.FCN (dim); \ } \ - else if (!isdouble && arg.is_single_type ()) \ - { \ - if (arg.is_real_type ()) \ - { \ - FloatNDArray tmp = arg.float_array_value (); \ + else if (!isdouble && arg.is_single_type ()) \ + { \ + if (arg.is_real_type ()) \ + { \ + FloatNDArray tmp = arg.float_array_value (); \ \ - if (! error_state) \ - retval = tmp.FCN (dim); \ - } \ - else if (arg.is_complex_type ()) \ - { \ - FloatComplexNDArray tmp = \ - arg.float_complex_array_value (); \ + if (! error_state) \ + retval = tmp.FCN (dim); \ + } \ + else if (arg.is_complex_type ()) \ + { \ + FloatComplexNDArray tmp = \ + arg.float_complex_array_value (); \ \ - if (! error_state) \ - retval = tmp.FCN (dim); \ - } \ - } \ - else if (arg.is_real_type ()) \ - { \ - NDArray tmp = arg.array_value (); \ + if (! error_state) \ + retval = tmp.FCN (dim); \ + } \ + } \ + else if (arg.is_real_type ()) \ + { \ + NDArray tmp = arg.array_value (); \ \ - if (! error_state) \ - retval = tmp.FCN (dim); \ - } \ - else if (arg.is_complex_type ()) \ - { \ - ComplexNDArray tmp = arg.complex_array_value (); \ + if (! error_state) \ + retval = tmp.FCN (dim); \ + } \ + else if (arg.is_complex_type ()) \ + { \ + ComplexNDArray tmp = arg.complex_array_value (); \ \ - if (! error_state) \ - retval = tmp.FCN (dim); \ - } \ - else \ - { \ - gripe_wrong_type_arg (#FCN, arg); \ - return retval; \ - } \ - } \ - } \ - else \ - error (#FCN ": invalid dimension argument = %d", dim + 1); \ - } \ + if (! error_state) \ + retval = tmp.FCN (dim); \ + } \ + else \ + { \ + gripe_wrong_type_arg (#FCN, arg); \ + return retval; \ + } \ + } \ + } \ + else \ + error (#FCN ": invalid dimension argument = %d", dim + 1); \ + } \ \ } \ else \ @@ -1484,66 +1484,66 @@ int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \ \ if (! error_state) \ - { \ - if (dim >= -1) \ - { \ - if (arg.is_real_type ()) \ - { \ - if (arg.is_sparse_type ()) \ - { \ - SparseMatrix tmp = arg.sparse_matrix_value (); \ + { \ + if (dim >= -1) \ + { \ + if (arg.is_real_type ()) \ + { \ + if (arg.is_sparse_type ()) \ + { \ + SparseMatrix tmp = arg.sparse_matrix_value (); \ \ - if (! error_state) \ - retval = tmp.FCN (dim); \ - } \ - else if (arg.is_single_type ()) \ - { \ - FloatNDArray tmp = arg.float_array_value (); \ + if (! error_state) \ + retval = tmp.FCN (dim); \ + } \ + else if (arg.is_single_type ()) \ + { \ + FloatNDArray tmp = arg.float_array_value (); \ \ - if (! error_state) \ - retval = tmp.FCN (dim); \ - } \ - else \ - { \ - NDArray tmp = arg.array_value (); \ + if (! error_state) \ + retval = tmp.FCN (dim); \ + } \ + else \ + { \ + NDArray tmp = arg.array_value (); \ \ - if (! error_state) \ - retval = tmp.FCN (dim); \ - } \ - } \ - else if (arg.is_complex_type ()) \ - { \ - if (arg.is_sparse_type ()) \ - { \ - SparseComplexMatrix tmp = arg.sparse_complex_matrix_value (); \ + if (! error_state) \ + retval = tmp.FCN (dim); \ + } \ + } \ + else if (arg.is_complex_type ()) \ + { \ + if (arg.is_sparse_type ()) \ + { \ + SparseComplexMatrix tmp = arg.sparse_complex_matrix_value (); \ \ - if (! error_state) \ - retval = tmp.FCN (dim); \ - } \ - else if (arg.is_single_type ()) \ - { \ - FloatComplexNDArray tmp = arg.float_complex_array_value (); \ + if (! error_state) \ + retval = tmp.FCN (dim); \ + } \ + else if (arg.is_single_type ()) \ + { \ + FloatComplexNDArray tmp = arg.float_complex_array_value (); \ \ - if (! error_state) \ - retval = tmp.FCN (dim); \ - } \ - else \ - { \ - ComplexNDArray tmp = arg.complex_array_value (); \ + if (! error_state) \ + retval = tmp.FCN (dim); \ + } \ + else \ + { \ + ComplexNDArray tmp = arg.complex_array_value (); \ \ - if (! error_state) \ - retval = tmp.FCN (dim); \ - } \ - } \ - else \ - { \ - gripe_wrong_type_arg (#FCN, arg); \ - return retval; \ - } \ - } \ - else \ - error (#FCN ": invalid dimension argument = %d", dim + 1); \ - } \ + if (! error_state) \ + retval = tmp.FCN (dim); \ + } \ + } \ + else \ + { \ + gripe_wrong_type_arg (#FCN, arg); \ + return retval; \ + } \ + } \ + else \ + error (#FCN ": invalid dimension argument = %d", dim + 1); \ + } \ } \ else \ print_usage (); \ @@ -1611,15 +1611,15 @@ std::string str = args(nargin - 1).string_value (); if (! error_state) - { - if (str == "native") - isnative = true; - else if (str == "double") + { + if (str == "native") + isnative = true; + else if (str == "double") isdouble = true; else - error ("sum: unrecognized string argument"); + error ("sum: unrecognized string argument"); nargin --; - } + } } if (error_state) @@ -1634,11 +1634,11 @@ { dim = args(1).int_value () - 1; if (dim < 0) - error ("cumsum: invalid dimension argument = %d", dim + 1); + error ("cumsum: invalid dimension argument = %d", dim + 1); } if (! error_state) - { + { switch (arg.builtin_type ()) { case btyp_double: @@ -1705,7 +1705,7 @@ default: gripe_wrong_type_arg ("cumsum", arg); } - } + } } else print_usage (); @@ -1770,9 +1770,9 @@ octave_idx_type k = args(1).int_value (); if (error_state) - error ("diag: invalid second argument"); + error ("diag: invalid second argument"); else - retval = args(0).diag(k); + retval = args(0).diag(k); } else if (nargin == 3) { @@ -1895,30 +1895,30 @@ Array ra_idx (dv_len > 1 ? dv_len : 2, 0); \ \ for (int j = 1; j < n_args; j++) \ - { \ - octave_quit (); \ - \ - TYPE ra = args(j).EXTRACTOR (); \ - \ - if (! error_state) \ - { \ - result.insert (ra, ra_idx); \ - \ - if (error_state) \ - return retval; \ - \ - dim_vector dv_tmp = args (j).dims (); \ - \ - if (dim >= dv_len) \ - { \ - if (j > 1) \ - error ("%s: indexing error", fname.c_str ()); \ - break; \ - } \ - else \ - ra_idx (dim) += (dim < dv_tmp.length () ? dv_tmp (dim) : 1); \ - } \ - } \ + { \ + octave_quit (); \ + \ + TYPE ra = args(j).EXTRACTOR (); \ + \ + if (! error_state) \ + { \ + result.insert (ra, ra_idx); \ + \ + if (error_state) \ + return retval; \ + \ + dim_vector dv_tmp = args (j).dims (); \ + \ + if (dim >= dv_len) \ + { \ + if (j > 1) \ + error ("%s: indexing error", fname.c_str ()); \ + break; \ + } \ + else \ + ra_idx (dim) += (dim < dv_tmp.length () ? dv_tmp (dim) : 1); \ + } \ + } \ } \ while (0) @@ -1949,166 +1949,166 @@ octave_idx_type dim = args(0).int_value () - 1; if (error_state) - { - error ("cat: expecting first argument to be a integer"); - return retval; - } + { + error ("cat: expecting first argument to be a integer"); + return retval; + } if (dim >= 0) - { - - dim_vector dv = args(1).dims (); - std::string result_type = args(1).class_name (); - - bool all_sq_strings_p = args(1).is_sq_string (); - bool all_dq_strings_p = args(1).is_dq_string (); - bool all_real_p = args(1).is_real_type (); - bool any_sparse_p = args(1).is_sparse_type(); - - for (int i = 2; i < args.length (); i++) - { - // add_dims constructs a dimension vector which holds the - // dimensions of the final array after concatenation. - - if (! dv.concat (args(i).dims (), dim)) - { - // Dimensions do not match. - error ("cat: dimension mismatch"); - return retval; - } - - result_type = - get_concat_class (result_type, args(i).class_name ()); - - if (all_sq_strings_p && ! args(i).is_sq_string ()) - all_sq_strings_p = false; - if (all_dq_strings_p && ! args(i).is_dq_string ()) - all_dq_strings_p = false; - if (all_real_p && ! args(i).is_real_type ()) - all_real_p = false; - if (!any_sparse_p && args(i).is_sparse_type ()) - any_sparse_p = true; - } - - if (result_type == "double") - { - if (any_sparse_p) - { - if (all_real_p) - DO_SINGLE_TYPE_CONCAT (SparseMatrix, sparse_matrix_value); - else - DO_SINGLE_TYPE_CONCAT (SparseComplexMatrix, sparse_complex_matrix_value); - } - else - { - if (all_real_p) - DO_SINGLE_TYPE_CONCAT (NDArray, array_value); - else - DO_SINGLE_TYPE_CONCAT (ComplexNDArray, complex_array_value); - } - } - else if (result_type == "single") - { - if (all_real_p) - DO_SINGLE_TYPE_CONCAT (FloatNDArray, float_array_value); - else - DO_SINGLE_TYPE_CONCAT (FloatComplexNDArray, - float_complex_array_value); - } - else if (result_type == "char") - { - char type = all_dq_strings_p ? '"' : '\''; - - maybe_warn_string_concat (all_dq_strings_p, all_sq_strings_p); - - charNDArray result (dv, Vstring_fill_char); - - SINGLE_TYPE_CONCAT (charNDArray, char_array_value); - - retval = octave_value (result, type); - } - else if (result_type == "logical") - { - if (any_sparse_p) - DO_SINGLE_TYPE_CONCAT (SparseBoolMatrix, sparse_bool_matrix_value); - else - DO_SINGLE_TYPE_CONCAT (boolNDArray, bool_array_value); - } - else if (result_type == "int8") - DO_SINGLE_TYPE_CONCAT (int8NDArray, int8_array_value); - else if (result_type == "int16") - DO_SINGLE_TYPE_CONCAT (int16NDArray, int16_array_value); - else if (result_type == "int32") - DO_SINGLE_TYPE_CONCAT (int32NDArray, int32_array_value); - else if (result_type == "int64") - DO_SINGLE_TYPE_CONCAT (int64NDArray, int64_array_value); - else if (result_type == "uint8") - DO_SINGLE_TYPE_CONCAT (uint8NDArray, uint8_array_value); - else if (result_type == "uint16") - DO_SINGLE_TYPE_CONCAT (uint16NDArray, uint16_array_value); - else if (result_type == "uint32") - DO_SINGLE_TYPE_CONCAT (uint32NDArray, uint32_array_value); - else if (result_type == "uint64") - DO_SINGLE_TYPE_CONCAT (uint64NDArray, uint64_array_value); - else - { - // The lines below might seem crazy, since we take a copy - // of the first argument, resize it to be empty and then resize - // it to be full. This is done since it means that there is no - // recopying of data, as would happen if we used a single resize. - // It should be noted that resize operation is also significantly - // slower than the do_cat_op function, so it makes sense to have - // an empty matrix and copy all data. - // - // We might also start with a empty octave_value using - // tmp = octave_value_typeinfo::lookup_type - // (args(1).type_name()); - // and then directly resize. However, for some types there might - // be some additional setup needed, and so this should be avoided. - - octave_value tmp = args (1); - tmp = tmp.resize (dim_vector (0,0)).resize (dv); - - if (error_state) - return retval; - - int dv_len = dv.length (); - Array ra_idx (dv_len, 0); - - for (int j = 1; j < n_args; j++) - { - // Can't fast return here to skip empty matrices as something - // like cat(1,[],single([])) must return an empty matrix of - // the right type. - tmp = do_cat_op (tmp, args (j), ra_idx); - - if (error_state) - return retval; - - dim_vector dv_tmp = args (j).dims (); - - if (dim >= dv_len) - { - if (j > 1) - error ("%s: indexing error", fname.c_str ()); - break; - } - else - ra_idx (dim) += (dim < dv_tmp.length () ? - dv_tmp (dim) : 1); - } - retval = tmp; - } - - if (! error_state) - { - // Reshape, chopping trailing singleton dimensions - dv.chop_trailing_singletons (); - retval = retval.reshape (dv); - } - } + { + + dim_vector dv = args(1).dims (); + std::string result_type = args(1).class_name (); + + bool all_sq_strings_p = args(1).is_sq_string (); + bool all_dq_strings_p = args(1).is_dq_string (); + bool all_real_p = args(1).is_real_type (); + bool any_sparse_p = args(1).is_sparse_type(); + + for (int i = 2; i < args.length (); i++) + { + // add_dims constructs a dimension vector which holds the + // dimensions of the final array after concatenation. + + if (! dv.concat (args(i).dims (), dim)) + { + // Dimensions do not match. + error ("cat: dimension mismatch"); + return retval; + } + + result_type = + get_concat_class (result_type, args(i).class_name ()); + + if (all_sq_strings_p && ! args(i).is_sq_string ()) + all_sq_strings_p = false; + if (all_dq_strings_p && ! args(i).is_dq_string ()) + all_dq_strings_p = false; + if (all_real_p && ! args(i).is_real_type ()) + all_real_p = false; + if (!any_sparse_p && args(i).is_sparse_type ()) + any_sparse_p = true; + } + + if (result_type == "double") + { + if (any_sparse_p) + { + if (all_real_p) + DO_SINGLE_TYPE_CONCAT (SparseMatrix, sparse_matrix_value); + else + DO_SINGLE_TYPE_CONCAT (SparseComplexMatrix, sparse_complex_matrix_value); + } + else + { + if (all_real_p) + DO_SINGLE_TYPE_CONCAT (NDArray, array_value); + else + DO_SINGLE_TYPE_CONCAT (ComplexNDArray, complex_array_value); + } + } + else if (result_type == "single") + { + if (all_real_p) + DO_SINGLE_TYPE_CONCAT (FloatNDArray, float_array_value); + else + DO_SINGLE_TYPE_CONCAT (FloatComplexNDArray, + float_complex_array_value); + } + else if (result_type == "char") + { + char type = all_dq_strings_p ? '"' : '\''; + + maybe_warn_string_concat (all_dq_strings_p, all_sq_strings_p); + + charNDArray result (dv, Vstring_fill_char); + + SINGLE_TYPE_CONCAT (charNDArray, char_array_value); + + retval = octave_value (result, type); + } + else if (result_type == "logical") + { + if (any_sparse_p) + DO_SINGLE_TYPE_CONCAT (SparseBoolMatrix, sparse_bool_matrix_value); + else + DO_SINGLE_TYPE_CONCAT (boolNDArray, bool_array_value); + } + else if (result_type == "int8") + DO_SINGLE_TYPE_CONCAT (int8NDArray, int8_array_value); + else if (result_type == "int16") + DO_SINGLE_TYPE_CONCAT (int16NDArray, int16_array_value); + else if (result_type == "int32") + DO_SINGLE_TYPE_CONCAT (int32NDArray, int32_array_value); + else if (result_type == "int64") + DO_SINGLE_TYPE_CONCAT (int64NDArray, int64_array_value); + else if (result_type == "uint8") + DO_SINGLE_TYPE_CONCAT (uint8NDArray, uint8_array_value); + else if (result_type == "uint16") + DO_SINGLE_TYPE_CONCAT (uint16NDArray, uint16_array_value); + else if (result_type == "uint32") + DO_SINGLE_TYPE_CONCAT (uint32NDArray, uint32_array_value); + else if (result_type == "uint64") + DO_SINGLE_TYPE_CONCAT (uint64NDArray, uint64_array_value); + else + { + // The lines below might seem crazy, since we take a copy + // of the first argument, resize it to be empty and then resize + // it to be full. This is done since it means that there is no + // recopying of data, as would happen if we used a single resize. + // It should be noted that resize operation is also significantly + // slower than the do_cat_op function, so it makes sense to have + // an empty matrix and copy all data. + // + // We might also start with a empty octave_value using + // tmp = octave_value_typeinfo::lookup_type + // (args(1).type_name()); + // and then directly resize. However, for some types there might + // be some additional setup needed, and so this should be avoided. + + octave_value tmp = args (1); + tmp = tmp.resize (dim_vector (0,0)).resize (dv); + + if (error_state) + return retval; + + int dv_len = dv.length (); + Array ra_idx (dv_len, 0); + + for (int j = 1; j < n_args; j++) + { + // Can't fast return here to skip empty matrices as something + // like cat(1,[],single([])) must return an empty matrix of + // the right type. + tmp = do_cat_op (tmp, args (j), ra_idx); + + if (error_state) + return retval; + + dim_vector dv_tmp = args (j).dims (); + + if (dim >= dv_len) + { + if (j > 1) + error ("%s: indexing error", fname.c_str ()); + break; + } + else + ra_idx (dim) += (dim < dv_tmp.length () ? + dv_tmp (dim) : 1); + } + retval = tmp; + } + + if (! error_state) + { + // Reshape, chopping trailing singleton dimensions + dv.chop_trailing_singletons (); + retval = retval.reshape (dv); + } + } else - error ("%s: invalid dimension argument", fname.c_str ()); + error ("%s: invalid dimension argument", fname.c_str ()); } else print_usage (); @@ -2349,12 +2349,12 @@ int n = vec.length (); for (int i = 0; i < n; i++) - vec(i)--; + vec(i)--; octave_value ret = args(0).permute (vec, inv); if (! error_state) - retval = ret; + retval = ret; } else print_usage (); @@ -2502,44 +2502,44 @@ const dim_vector dimensions = args(0).dims (); if (nargout > 1) - { + { const dim_vector rdims = dimensions.redim (nargout); retval.resize (nargout); for (int i = 0; i < nargout; i++) retval(i) = rdims(i); - } + } else - { + { int ndims = dimensions.length (); NoAlias m (1, ndims); - for (int i = 0; i < ndims; i++) - m(i) = dimensions(i); - - retval(0) = m; - } + for (int i = 0; i < ndims; i++) + m(i) = dimensions(i); + + retval(0) = m; + } } else if (nargin == 2 && nargout < 2) { octave_idx_type nd = args(1).int_value (true); if (error_state) - error ("size: expecting scalar as second argument"); + error ("size: expecting scalar as second argument"); else - { - const dim_vector dv = args(0).dims (); - - if (nd > 0) - { - if (nd <= dv.length ()) - retval(0) = dv(nd-1); - else - retval(0) = 1; - } - else - error ("size: requested dimension (= %d) out of range", nd); - } + { + const dim_vector dv = args(0).dims (); + + if (nd > 0) + { + if (nd <= dv.length ()) + retval(0) = dv(nd-1); + else + retval(0) = 1; + } + else + error ("size: requested dimension (= %d) out of range", nd); + } } else print_usage (); @@ -2571,10 +2571,10 @@ dim_vector b_dims = args(i).dims (); if (a_dims != b_dims) - { - retval = false; - break; - } + { + retval = false; + break; + } } } @@ -2698,17 +2698,17 @@ std::string str = args(nargin - 1).string_value (); if (! error_state) - { - if (str == "native") - isnative = true; - else if (str == "double") + { + if (str == "native") + isnative = true; + else if (str == "double") isdouble = true; else if (str == "extra") isextra = true; else - error ("sum: unrecognized string argument"); + error ("sum: unrecognized string argument"); nargin --; - } + } } if (error_state) @@ -2723,11 +2723,11 @@ { dim = args(1).int_value () - 1; if (dim < 0) - error ("sum: invalid dimension argument = %d", dim + 1); + error ("sum: invalid dimension argument = %d", dim + 1); } if (! error_state) - { + { switch (arg.builtin_type ()) { case btyp_double: @@ -2801,7 +2801,7 @@ default: gripe_wrong_type_arg ("sum", arg); } - } + } } else print_usage (); @@ -3023,54 +3023,54 @@ octave_value arg = args(0); if (arg.is_complex_type ()) - retval = arg; + retval = arg; else - { - if (arg.is_sparse_type ()) - { - SparseComplexMatrix val = arg.sparse_complex_matrix_value (); - - if (! error_state) - retval = octave_value (new octave_sparse_complex_matrix (val)); - } - else if (arg.is_single_type ()) - { - if (arg.numel () == 1) - { - FloatComplex val = arg.float_complex_value (); - - if (! error_state) - retval = octave_value (new octave_float_complex (val)); - } - else - { - FloatComplexNDArray val = arg.float_complex_array_value (); - - if (! error_state) - retval = octave_value (new octave_float_complex_matrix (val)); - } - } - else - { - if (arg.numel () == 1) - { - Complex val = arg.complex_value (); - - if (! error_state) - retval = octave_value (new octave_complex (val)); - } - else - { - ComplexNDArray val = arg.complex_array_value (); - - if (! error_state) - retval = octave_value (new octave_complex_matrix (val)); - } - } - - if (error_state) - error ("complex: invalid conversion"); - } + { + if (arg.is_sparse_type ()) + { + SparseComplexMatrix val = arg.sparse_complex_matrix_value (); + + if (! error_state) + retval = octave_value (new octave_sparse_complex_matrix (val)); + } + else if (arg.is_single_type ()) + { + if (arg.numel () == 1) + { + FloatComplex val = arg.float_complex_value (); + + if (! error_state) + retval = octave_value (new octave_float_complex (val)); + } + else + { + FloatComplexNDArray val = arg.float_complex_array_value (); + + if (! error_state) + retval = octave_value (new octave_float_complex_matrix (val)); + } + } + else + { + if (arg.numel () == 1) + { + Complex val = arg.complex_value (); + + if (! error_state) + retval = octave_value (new octave_complex (val)); + } + else + { + ComplexNDArray val = arg.complex_array_value (); + + if (! error_state) + retval = octave_value (new octave_complex_matrix (val)); + } + } + + if (error_state) + error ("complex: invalid conversion"); + } } else if (nargin == 2) { @@ -3078,205 +3078,205 @@ octave_value im = args(1); if (re.is_sparse_type () && im.is_sparse_type ()) - { - const SparseMatrix re_val = re.sparse_matrix_value (); - const SparseMatrix im_val = im.sparse_matrix_value (); - - if (!error_state) - { - if (re.numel () == 1) - { - SparseComplexMatrix result; - if (re_val.nnz () == 0) - result = Complex(0, 1) * SparseComplexMatrix (im_val); - else - { - result = SparseComplexMatrix (im_val.dims (), re_val (0)); - octave_idx_type nr = im_val.rows (); - octave_idx_type nc = im_val.cols (); - - for (octave_idx_type j = 0; j < nc; j++) - { - octave_idx_type off = j * nr; - for (octave_idx_type i = im_val.cidx(j); - i < im_val.cidx(j + 1); i++) - result.data (im_val.ridx(i) + off) = - result.data (im_val.ridx(i) + off) + - Complex (0, im_val.data (i)); - } - } - retval = octave_value (new octave_sparse_complex_matrix (result)); - } - else if (im.numel () == 1) - { - SparseComplexMatrix result; - if (im_val.nnz () == 0) - result = SparseComplexMatrix (re_val); - else - { - result = SparseComplexMatrix (re_val.rows(), re_val.cols(), Complex(0, im_val (0))); - octave_idx_type nr = re_val.rows (); - octave_idx_type nc = re_val.cols (); - - for (octave_idx_type j = 0; j < nc; j++) - { - octave_idx_type off = j * nr; - for (octave_idx_type i = re_val.cidx(j); - i < re_val.cidx(j + 1); i++) - result.data (re_val.ridx(i) + off) = - result.data (re_val.ridx(i) + off) + - re_val.data (i); - } - } - retval = octave_value (new octave_sparse_complex_matrix (result)); - } - else - { - if (re_val.dims () == im_val.dims ()) - { - SparseComplexMatrix result = SparseComplexMatrix(re_val) - + Complex(0, 1) * SparseComplexMatrix (im_val); - retval = octave_value (new octave_sparse_complex_matrix (result)); - } - else - error ("complex: dimension mismatch"); - } - } - } + { + const SparseMatrix re_val = re.sparse_matrix_value (); + const SparseMatrix im_val = im.sparse_matrix_value (); + + if (!error_state) + { + if (re.numel () == 1) + { + SparseComplexMatrix result; + if (re_val.nnz () == 0) + result = Complex(0, 1) * SparseComplexMatrix (im_val); + else + { + result = SparseComplexMatrix (im_val.dims (), re_val (0)); + octave_idx_type nr = im_val.rows (); + octave_idx_type nc = im_val.cols (); + + for (octave_idx_type j = 0; j < nc; j++) + { + octave_idx_type off = j * nr; + for (octave_idx_type i = im_val.cidx(j); + i < im_val.cidx(j + 1); i++) + result.data (im_val.ridx(i) + off) = + result.data (im_val.ridx(i) + off) + + Complex (0, im_val.data (i)); + } + } + retval = octave_value (new octave_sparse_complex_matrix (result)); + } + else if (im.numel () == 1) + { + SparseComplexMatrix result; + if (im_val.nnz () == 0) + result = SparseComplexMatrix (re_val); + else + { + result = SparseComplexMatrix (re_val.rows(), re_val.cols(), Complex(0, im_val (0))); + octave_idx_type nr = re_val.rows (); + octave_idx_type nc = re_val.cols (); + + for (octave_idx_type j = 0; j < nc; j++) + { + octave_idx_type off = j * nr; + for (octave_idx_type i = re_val.cidx(j); + i < re_val.cidx(j + 1); i++) + result.data (re_val.ridx(i) + off) = + result.data (re_val.ridx(i) + off) + + re_val.data (i); + } + } + retval = octave_value (new octave_sparse_complex_matrix (result)); + } + else + { + if (re_val.dims () == im_val.dims ()) + { + SparseComplexMatrix result = SparseComplexMatrix(re_val) + + Complex(0, 1) * SparseComplexMatrix (im_val); + retval = octave_value (new octave_sparse_complex_matrix (result)); + } + else + error ("complex: dimension mismatch"); + } + } + } else if (re.is_single_type () || im.is_single_type ()) - { - if (re.numel () == 1) - { - float re_val = re.float_value (); - - if (im.numel () == 1) - { - float im_val = im.double_value (); - - if (! error_state) - retval = octave_value (new octave_float_complex (FloatComplex (re_val, im_val))); - } - else - { - const FloatNDArray im_val = im.float_array_value (); - - if (! error_state) - { - FloatComplexNDArray result (im_val.dims (), FloatComplex ()); - - for (octave_idx_type i = 0; i < im_val.numel (); i++) - result.xelem (i) = FloatComplex (re_val, im_val(i)); - - retval = octave_value (new octave_float_complex_matrix (result)); - } - } - } - else - { - const FloatNDArray re_val = re.float_array_value (); - - if (im.numel () == 1) - { - float im_val = im.float_value (); - - if (! error_state) - { - FloatComplexNDArray result (re_val.dims (), FloatComplex ()); - - for (octave_idx_type i = 0; i < re_val.numel (); i++) - result.xelem (i) = FloatComplex (re_val(i), im_val); - - retval = octave_value (new octave_float_complex_matrix (result)); - } - } - else - { - const FloatNDArray im_val = im.float_array_value (); - - if (! error_state) - { - if (re_val.dims () == im_val.dims ()) - { - FloatComplexNDArray result (re_val.dims (), FloatComplex ()); - - for (octave_idx_type i = 0; i < re_val.numel (); i++) - result.xelem (i) = FloatComplex (re_val(i), im_val(i)); - - retval = octave_value (new octave_float_complex_matrix (result)); - } - else - error ("complex: dimension mismatch"); - } - } - } - } + { + if (re.numel () == 1) + { + float re_val = re.float_value (); + + if (im.numel () == 1) + { + float im_val = im.double_value (); + + if (! error_state) + retval = octave_value (new octave_float_complex (FloatComplex (re_val, im_val))); + } + else + { + const FloatNDArray im_val = im.float_array_value (); + + if (! error_state) + { + FloatComplexNDArray result (im_val.dims (), FloatComplex ()); + + for (octave_idx_type i = 0; i < im_val.numel (); i++) + result.xelem (i) = FloatComplex (re_val, im_val(i)); + + retval = octave_value (new octave_float_complex_matrix (result)); + } + } + } + else + { + const FloatNDArray re_val = re.float_array_value (); + + if (im.numel () == 1) + { + float im_val = im.float_value (); + + if (! error_state) + { + FloatComplexNDArray result (re_val.dims (), FloatComplex ()); + + for (octave_idx_type i = 0; i < re_val.numel (); i++) + result.xelem (i) = FloatComplex (re_val(i), im_val); + + retval = octave_value (new octave_float_complex_matrix (result)); + } + } + else + { + const FloatNDArray im_val = im.float_array_value (); + + if (! error_state) + { + if (re_val.dims () == im_val.dims ()) + { + FloatComplexNDArray result (re_val.dims (), FloatComplex ()); + + for (octave_idx_type i = 0; i < re_val.numel (); i++) + result.xelem (i) = FloatComplex (re_val(i), im_val(i)); + + retval = octave_value (new octave_float_complex_matrix (result)); + } + else + error ("complex: dimension mismatch"); + } + } + } + } else if (re.numel () == 1) - { - double re_val = re.double_value (); - - if (im.numel () == 1) - { - double im_val = im.double_value (); - - if (! error_state) - retval = octave_value (new octave_complex (Complex (re_val, im_val))); - } - else - { - const NDArray im_val = im.array_value (); - - if (! error_state) - { - ComplexNDArray result (im_val.dims (), Complex ()); - - for (octave_idx_type i = 0; i < im_val.numel (); i++) - result.xelem (i) = Complex (re_val, im_val(i)); - - retval = octave_value (new octave_complex_matrix (result)); - } - } - } + { + double re_val = re.double_value (); + + if (im.numel () == 1) + { + double im_val = im.double_value (); + + if (! error_state) + retval = octave_value (new octave_complex (Complex (re_val, im_val))); + } + else + { + const NDArray im_val = im.array_value (); + + if (! error_state) + { + ComplexNDArray result (im_val.dims (), Complex ()); + + for (octave_idx_type i = 0; i < im_val.numel (); i++) + result.xelem (i) = Complex (re_val, im_val(i)); + + retval = octave_value (new octave_complex_matrix (result)); + } + } + } else - { - const NDArray re_val = re.array_value (); - - if (im.numel () == 1) - { - double im_val = im.double_value (); - - if (! error_state) - { - ComplexNDArray result (re_val.dims (), Complex ()); - - for (octave_idx_type i = 0; i < re_val.numel (); i++) - result.xelem (i) = Complex (re_val(i), im_val); - - retval = octave_value (new octave_complex_matrix (result)); - } - } - else - { - const NDArray im_val = im.array_value (); - - if (! error_state) - { - if (re_val.dims () == im_val.dims ()) - { - ComplexNDArray result (re_val.dims (), Complex ()); - - for (octave_idx_type i = 0; i < re_val.numel (); i++) - result.xelem (i) = Complex (re_val(i), im_val(i)); - - retval = octave_value (new octave_complex_matrix (result)); - } - else - error ("complex: dimension mismatch"); - } - } - } + { + const NDArray re_val = re.array_value (); + + if (im.numel () == 1) + { + double im_val = im.double_value (); + + if (! error_state) + { + ComplexNDArray result (re_val.dims (), Complex ()); + + for (octave_idx_type i = 0; i < re_val.numel (); i++) + result.xelem (i) = Complex (re_val(i), im_val); + + retval = octave_value (new octave_complex_matrix (result)); + } + } + else + { + const NDArray im_val = im.array_value (); + + if (! error_state) + { + if (re_val.dims () == im_val.dims ()) + { + ComplexNDArray result (re_val.dims (), Complex ()); + + for (octave_idx_type i = 0; i < re_val.numel (); i++) + result.xelem (i) = Complex (re_val(i), im_val(i)); + + retval = octave_value (new octave_complex_matrix (result)); + } + else + error ("complex: dimension mismatch"); + } + } + } if (error_state) - error ("complex: invalid conversion"); + error ("complex: invalid conversion"); } else print_usage (); @@ -3403,7 +3403,7 @@ dt = oct_data_conv::string_to_data_type (nm); if (error_state) - return retval; + return retval; } switch (nargin) @@ -3417,18 +3417,18 @@ default: { - dims.resize (nargin); - - for (int i = 0; i < nargin; i++) - { - dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value (); - - if (error_state) - { - error ("%s: expecting scalar integer arguments", fcn); - break; - } - } + dims.resize (nargin); + + for (int i = 0; i < nargin; i++) + { + dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value (); + + if (error_state) + { + error ("%s: expecting scalar integer arguments", fcn); + break; + } + } } break; } @@ -3447,63 +3447,63 @@ // NDArray to scalar. if (! error_state) - { - switch (dt) - { - case oct_data_conv::dt_int8: - retval = int8NDArray (dims, val); - break; - - case oct_data_conv::dt_uint8: - retval = uint8NDArray (dims, val); - break; - - case oct_data_conv::dt_int16: - retval = int16NDArray (dims, val); - break; - - case oct_data_conv::dt_uint16: - retval = uint16NDArray (dims, val); - break; - - case oct_data_conv::dt_int32: - retval = int32NDArray (dims, val); - break; - - case oct_data_conv::dt_uint32: - retval = uint32NDArray (dims, val); - break; - - case oct_data_conv::dt_int64: - retval = int64NDArray (dims, val); - break; - - case oct_data_conv::dt_uint64: - retval = uint64NDArray (dims, val); - break; - - case oct_data_conv::dt_single: - retval = FloatNDArray (dims, val); - break; - - case oct_data_conv::dt_double: + { + switch (dt) + { + case oct_data_conv::dt_int8: + retval = int8NDArray (dims, val); + break; + + case oct_data_conv::dt_uint8: + retval = uint8NDArray (dims, val); + break; + + case oct_data_conv::dt_int16: + retval = int16NDArray (dims, val); + break; + + case oct_data_conv::dt_uint16: + retval = uint16NDArray (dims, val); + break; + + case oct_data_conv::dt_int32: + retval = int32NDArray (dims, val); + break; + + case oct_data_conv::dt_uint32: + retval = uint32NDArray (dims, val); + break; + + case oct_data_conv::dt_int64: + retval = int64NDArray (dims, val); + break; + + case oct_data_conv::dt_uint64: + retval = uint64NDArray (dims, val); + break; + + case oct_data_conv::dt_single: + retval = FloatNDArray (dims, val); + break; + + case oct_data_conv::dt_double: { if (val == 1 && dims.length () == 2 && dims (0) == 1) retval = Range (1.0, 0.0, dims (1)); // packed form else retval = NDArray (dims, val); } - break; - - case oct_data_conv::dt_logical: - retval = boolNDArray (dims, val); - break; - - default: - error ("%s: invalid class name", fcn); - break; - } - } + break; + + case oct_data_conv::dt_logical: + retval = boolNDArray (dims, val); + break; + + default: + error ("%s: invalid class name", fcn); + break; + } + } } return retval; @@ -3511,7 +3511,7 @@ static octave_value fill_matrix (const octave_value_list& args, double val, float fval, - const char *fcn) + const char *fcn) { octave_value retval; @@ -3529,7 +3529,7 @@ dt = oct_data_conv::string_to_data_type (nm); if (error_state) - return retval; + return retval; } switch (nargin) @@ -3543,18 +3543,18 @@ default: { - dims.resize (nargin); - - for (int i = 0; i < nargin; i++) - { - dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value (); - - if (error_state) - { - error ("%s: expecting scalar integer arguments", fcn); - break; - } - } + dims.resize (nargin); + + for (int i = 0; i < nargin; i++) + { + dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value (); + + if (error_state) + { + error ("%s: expecting scalar integer arguments", fcn); + break; + } + } } break; } @@ -3569,22 +3569,22 @@ // NDArray to scalar. if (! error_state) - { - switch (dt) - { - case oct_data_conv::dt_single: - retval = FloatNDArray (dims, fval); - break; - - case oct_data_conv::dt_double: - retval = NDArray (dims, val); - break; - - default: - error ("%s: invalid class name", fcn); - break; - } - } + { + switch (dt) + { + case oct_data_conv::dt_single: + retval = FloatNDArray (dims, fval); + break; + + case oct_data_conv::dt_double: + retval = NDArray (dims, val); + break; + + default: + error ("%s: invalid class name", fcn); + break; + } + } } return retval; @@ -3609,7 +3609,7 @@ dt = oct_data_conv::string_to_data_type (nm); if (error_state) - return retval; + return retval; } switch (nargin) @@ -3623,18 +3623,18 @@ default: { - dims.resize (nargin); - - for (int i = 0; i < nargin; i++) - { - dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value (); - - if (error_state) - { - error ("%s: expecting scalar integer arguments", fcn); - break; - } - } + dims.resize (nargin); + + for (int i = 0; i < nargin; i++) + { + dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value (); + + if (error_state) + { + error ("%s: expecting scalar integer arguments", fcn); + break; + } + } } break; } @@ -3649,22 +3649,22 @@ // NDArray to scalar. if (! error_state) - { - switch (dt) - { - case oct_data_conv::dt_single: - retval = FloatNDArray (dims, static_cast (val)); - break; - - case oct_data_conv::dt_double: - retval = NDArray (dims, val); - break; - - default: - error ("%s: invalid class name", fcn); - break; - } - } + { + switch (dt) + { + case oct_data_conv::dt_single: + retval = FloatNDArray (dims, static_cast (val)); + break; + + case oct_data_conv::dt_double: + retval = NDArray (dims, val); + break; + + default: + error ("%s: invalid class name", fcn); + break; + } + } } return retval; @@ -3672,7 +3672,7 @@ static octave_value fill_matrix (const octave_value_list& args, const Complex& val, - const char *fcn) + const char *fcn) { octave_value retval; @@ -3690,7 +3690,7 @@ dt = oct_data_conv::string_to_data_type (nm); if (error_state) - return retval; + return retval; } switch (nargin) @@ -3704,18 +3704,18 @@ default: { - dims.resize (nargin); - - for (int i = 0; i < nargin; i++) - { - dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value (); - - if (error_state) - { - error ("%s: expecting scalar integer arguments", fcn); - break; - } - } + dims.resize (nargin); + + for (int i = 0; i < nargin; i++) + { + dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value (); + + if (error_state) + { + error ("%s: expecting scalar integer arguments", fcn); + break; + } + } } break; } @@ -3730,22 +3730,22 @@ // NDArray to scalar. if (! error_state) - { - switch (dt) - { - case oct_data_conv::dt_single: - retval = FloatComplexNDArray (dims, static_cast (val)); - break; - - case oct_data_conv::dt_double: - retval = ComplexNDArray (dims, val); - break; - - default: - error ("%s: invalid class name", fcn); - break; - } - } + { + switch (dt) + { + case oct_data_conv::dt_single: + retval = FloatComplexNDArray (dims, static_cast (val)); + break; + + case oct_data_conv::dt_double: + retval = ComplexNDArray (dims, val); + break; + + default: + error ("%s: invalid class name", fcn); + break; + } + } } return retval; @@ -3771,18 +3771,18 @@ default: { - dims.resize (nargin); - - for (int i = 0; i < nargin; i++) - { - dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value (); - - if (error_state) - { - error ("%s: expecting scalar integer arguments", fcn); - break; - } - } + dims.resize (nargin); + + for (int i = 0; i < nargin; i++) + { + dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value (); + + if (error_state) + { + error ("%s: expecting scalar integer arguments", fcn); + break; + } + } } break; } @@ -3797,7 +3797,7 @@ // NDArray to scalar. if (! error_state) - retval = boolNDArray (dims, val); + retval = boolNDArray (dims, val); } return retval; @@ -3923,7 +3923,7 @@ @end deftypefn") { return fill_matrix (args, lo_ieee_inf_value (), - lo_ieee_float_inf_value (), "Inf"); + lo_ieee_float_inf_value (), "Inf"); } DEFALIAS (inf, Inf); @@ -3981,7 +3981,7 @@ @end deftypefn") { return fill_matrix (args, lo_ieee_nan_value (), - lo_ieee_float_nan_value (), "NaN"); + lo_ieee_float_nan_value (), "NaN"); } DEFALIAS (nan, NaN); @@ -4075,55 +4075,55 @@ if (nargin == 1 && ! args(0).is_string ()) { if (args(0).is_single_type ()) - { - float val = args(0).float_value (); - - if (! error_state) - { - val = ::fabsf(val); - if (xisnan (val) || xisinf (val)) - retval = fill_matrix (octave_value ("single"), - lo_ieee_nan_value (), - lo_ieee_float_nan_value (), "eps"); - else if (val < FLT_MIN) - retval = fill_matrix (octave_value ("single"), 0e0, - powf (2.0, -149e0), "eps"); - else - { - int expon; - frexpf (val, &expon); - val = std::pow (static_cast (2.0), - static_cast (expon - 24)); - retval = fill_matrix (octave_value ("single"), DBL_EPSILON, - val, "eps"); - } - } - } + { + float val = args(0).float_value (); + + if (! error_state) + { + val = ::fabsf(val); + if (xisnan (val) || xisinf (val)) + retval = fill_matrix (octave_value ("single"), + lo_ieee_nan_value (), + lo_ieee_float_nan_value (), "eps"); + else if (val < FLT_MIN) + retval = fill_matrix (octave_value ("single"), 0e0, + powf (2.0, -149e0), "eps"); + else + { + int expon; + frexpf (val, &expon); + val = std::pow (static_cast (2.0), + static_cast (expon - 24)); + retval = fill_matrix (octave_value ("single"), DBL_EPSILON, + val, "eps"); + } + } + } else - { - double val = args(0).double_value (); - - if (! error_state) - { - val = ::fabs(val); - if (xisnan (val) || xisinf (val)) - retval = fill_matrix (octave_value_list (), - lo_ieee_nan_value (), - lo_ieee_float_nan_value (), "eps"); - else if (val < DBL_MIN) - retval = fill_matrix (octave_value_list (), - pow (2.0, -1074e0), 0e0, "eps"); - else - { - int expon; - frexp (val, &expon); - val = std::pow (static_cast (2.0), - static_cast (expon - 53)); - retval = fill_matrix (octave_value_list (), val, - FLT_EPSILON, "eps"); - } - } - } + { + double val = args(0).double_value (); + + if (! error_state) + { + val = ::fabs(val); + if (xisnan (val) || xisinf (val)) + retval = fill_matrix (octave_value_list (), + lo_ieee_nan_value (), + lo_ieee_float_nan_value (), "eps"); + else if (val < DBL_MIN) + retval = fill_matrix (octave_value_list (), + pow (2.0, -1074e0), 0e0, "eps"); + else + { + int expon; + frexp (val, &expon); + val = std::pow (static_cast (2.0), + static_cast (expon - 53)); + retval = fill_matrix (octave_value_list (), val, + FLT_EPSILON, "eps"); + } + } + } } else retval = fill_matrix (args, DBL_EPSILON, FLT_EPSILON, "eps"); @@ -4320,7 +4320,7 @@ @end deftypefn") { return fill_matrix (args, lo_ieee_na_value (), - lo_ieee_float_na_value (), "NA"); + lo_ieee_float_na_value (), "NA"); } /* @@ -4373,12 +4373,12 @@ MT m (dims, zero); if (nr > 0 && nc > 0) - { - int n = std::min (nr, nc); - - for (int i = 0; i < n; i++) - m(i,i) = one; - } + { + int n = std::min (nr, nc); + + for (int i = 0; i < n; i++) + m(i,i) = one; + } retval = m; } @@ -4413,55 +4413,55 @@ if (! error_state) { switch (dt) - { - case oct_data_conv::dt_int8: - retval = identity_matrix (nr, nc); - break; - - case oct_data_conv::dt_uint8: - retval = identity_matrix (nr, nc); - break; - - case oct_data_conv::dt_int16: - retval = identity_matrix (nr, nc); - break; - - case oct_data_conv::dt_uint16: - retval = identity_matrix (nr, nc); - break; - - case oct_data_conv::dt_int32: - retval = identity_matrix (nr, nc); - break; - - case oct_data_conv::dt_uint32: - retval = identity_matrix (nr, nc); - break; - - case oct_data_conv::dt_int64: - retval = identity_matrix (nr, nc); - break; - - case oct_data_conv::dt_uint64: - retval = identity_matrix (nr, nc); - break; - - case oct_data_conv::dt_single: - retval = FloatDiagMatrix (nr, nc, 1.0f); - break; - - case oct_data_conv::dt_double: - retval = DiagMatrix (nr, nc, 1.0); - break; - - case oct_data_conv::dt_logical: - retval = identity_matrix (nr, nc); - break; - - default: - error ("eye: invalid class name"); - break; - } + { + case oct_data_conv::dt_int8: + retval = identity_matrix (nr, nc); + break; + + case oct_data_conv::dt_uint8: + retval = identity_matrix (nr, nc); + break; + + case oct_data_conv::dt_int16: + retval = identity_matrix (nr, nc); + break; + + case oct_data_conv::dt_uint16: + retval = identity_matrix (nr, nc); + break; + + case oct_data_conv::dt_int32: + retval = identity_matrix (nr, nc); + break; + + case oct_data_conv::dt_uint32: + retval = identity_matrix (nr, nc); + break; + + case oct_data_conv::dt_int64: + retval = identity_matrix (nr, nc); + break; + + case oct_data_conv::dt_uint64: + retval = identity_matrix (nr, nc); + break; + + case oct_data_conv::dt_single: + retval = FloatDiagMatrix (nr, nc, 1.0f); + break; + + case oct_data_conv::dt_double: + retval = DiagMatrix (nr, nc, 1.0); + break; + + case oct_data_conv::dt_logical: + retval = identity_matrix (nr, nc); + break; + + default: + error ("eye: invalid class name"); + break; + } } return retval; @@ -4530,7 +4530,7 @@ dt = oct_data_conv::string_to_data_type (nm); if (error_state) - return retval; + return retval; } switch (nargin) @@ -4541,21 +4541,21 @@ case 1: { - octave_idx_type nr, nc; - get_dimensions (args(0), "eye", nr, nc); - - if (! error_state) - retval = identity_matrix (nr, nc, dt); + octave_idx_type nr, nc; + get_dimensions (args(0), "eye", nr, nc); + + if (! error_state) + retval = identity_matrix (nr, nc, dt); } break; case 2: { - octave_idx_type nr, nc; - get_dimensions (args(0), args(1), "eye", nr, nc); - - if (! error_state) - retval = identity_matrix (nr, nc, dt); + octave_idx_type nr, nc; + get_dimensions (args(0), args(1), "eye", nr, nc); + + if (! error_state) + retval = identity_matrix (nr, nc, dt); } break; @@ -4666,20 +4666,20 @@ octave_value arg_2 = args(1); if (arg_1.is_single_type () || arg_2.is_single_type ()) - { - if (arg_1.is_complex_type () || arg_2.is_complex_type ()) + { + if (arg_1.is_complex_type () || arg_2.is_complex_type ()) retval = do_linspace (arg_1, arg_2, npoints); - else + else retval = do_linspace (arg_1, arg_2, npoints); - - } + + } else - { - if (arg_1.is_complex_type () || arg_2.is_complex_type ()) + { + if (arg_1.is_complex_type () || arg_2.is_complex_type ()) retval = do_linspace (arg_1, arg_2, npoints); - else + else retval = do_linspace (arg_1, arg_2, npoints); - } + } } else error ("linspace: expecting third argument to be an integer"); @@ -4764,20 +4764,20 @@ Array vec = args(1).vector_value (); int ndim = vec.length (); if (ndim == 1) - { - octave_idx_type m = static_cast (vec(0)); - retval = args(0); - retval = retval.resize (dim_vector (m, m), true); - } + { + octave_idx_type m = static_cast (vec(0)); + retval = args(0); + retval = retval.resize (dim_vector (m, m), true); + } else - { - dim_vector dv; - dv.resize (ndim); - for (int i = 0; i < ndim; i++) - dv(i) = static_cast (vec(i)); - retval = args(0); - retval = retval.resize (dv, true); - } + { + dim_vector dv; + dv.resize (ndim); + for (int i = 0; i < ndim; i++) + dv(i) = static_cast (vec(i)); + retval = args(0); + retval = retval.resize (dv, true); + } } else if (nargin > 2) { @@ -4786,10 +4786,10 @@ for (octave_idx_type i = 1; i < nargin; i++) dv(i-1) = static_cast (args(i).scalar_value ()); if (!error_state) - { - retval = args(0); - retval = retval.resize (dv, true); - } + { + retval = args(0); + retval = retval.resize (dv, true); + } } else @@ -4839,45 +4839,45 @@ int empty_dim = -1; for (int i = 1; i < nargin; i++) - { - if (args(i).is_empty ()) - if (empty_dim > 0) - { - error ("reshape: only a single dimension can be unknown"); - break; - } - else - { - empty_dim = i; - new_size(i-1) = 1; - } - else - { - new_size(i-1) = args(i).idx_type_value (); - - if (error_state) - break; - } - } + { + if (args(i).is_empty ()) + if (empty_dim > 0) + { + error ("reshape: only a single dimension can be unknown"); + break; + } + else + { + empty_dim = i; + new_size(i-1) = 1; + } + else + { + new_size(i-1) = args(i).idx_type_value (); + + if (error_state) + break; + } + } if (! error_state && (empty_dim > 0)) - { - int nel = 1; - for (int i = 0; i < nargin - 1; i++) - nel *= new_size(i); - - if (nel == 0) - new_size(empty_dim-1) = 0; - else - { - int size_empty_dim = args(0).numel () / nel; - - if (args(0).numel () != size_empty_dim * nel) - error ("reshape: size is not divisble by the product of known dimensions (= %d)", nel); - else - new_size(empty_dim-1) = size_empty_dim; - } - } + { + int nel = 1; + for (int i = 0; i < nargin - 1; i++) + nel *= new_size(i); + + if (nel == 0) + new_size(empty_dim-1) = 0; + else + { + int size_empty_dim = args(0).numel () / nel; + + if (args(0).numel () != size_empty_dim * nel) + error ("reshape: size is not divisble by the product of known dimensions (= %d)", nel); + else + new_size(empty_dim-1) = size_empty_dim; + } + } } else { @@ -4899,9 +4899,9 @@ while (n > 2) { if (new_size(n-1) == 1) - n--; + n--; else - break; + break; } new_size.resize (n); @@ -4931,7 +4931,7 @@ std::string new_dims_str = new_dims.str (); error ("reshape: can't reshape %s array to %s array", - dims_str.c_str (), new_dims_str.c_str ()); + dims_str.c_str (), new_dims_str.c_str ()); } return retval; @@ -5060,7 +5060,7 @@ octave_value x_arg = args(0); if (x_arg.ndims () == 2) - { + { enum { sfmatrix, sfcols, sfrows, sffrob, sfinf } strflag = sfmatrix; if (nargin > 1 && args(nargin-1).is_string ()) { @@ -5103,9 +5103,9 @@ break; } } - } + } else - error ("norm: only valid for 2-D objects"); + error ("norm: only valid for 2-D objects"); } else print_usage (); @@ -5614,7 +5614,7 @@ { warning ("toc called before timer set"); if (nargout > 0) - retval = Matrix (); + retval = Matrix (); } else { @@ -5623,9 +5623,9 @@ double tmp = now.double_value () - tic_toc_timestamp; if (nargout > 0) - retval = tmp; + retval = tmp; else - octave_stdout << "Elapsed time is " << tmp << " seconds.\n"; + octave_stdout << "Elapsed time is " << tmp << " seconds.\n"; } return retval; @@ -5768,45 +5768,45 @@ if (nargin > 1) { if (args(1).is_string ()) - { - std::string mode = args(1).string_value(); - if (mode == "ascend") - smode = ASCENDING; - else if (mode == "descend") - smode = DESCENDING; - else - { - error ("sort: mode must be either \"ascend\" or \"descend\""); - return retval; - } - } + { + std::string mode = args(1).string_value(); + if (mode == "ascend") + smode = ASCENDING; + else if (mode == "descend") + smode = DESCENDING; + else + { + error ("sort: mode must be either \"ascend\" or \"descend\""); + return retval; + } + } else - dim = args(1).nint_value () - 1; + dim = args(1).nint_value () - 1; } if (nargin > 2) { if (args(1).is_string ()) - { - print_usage (); - return retval; - } + { + print_usage (); + return retval; + } if (! args(2).is_string ()) - { - error ("sort: mode must be a string"); - return retval; - } + { + error ("sort: mode must be a string"); + return retval; + } std::string mode = args(2).string_value(); if (mode == "ascend") - smode = ASCENDING; + smode = ASCENDING; else if (mode == "descend") - smode = DESCENDING; + smode = DESCENDING; else - { - error ("sort: mode must be either \"ascend\" or \"descend\""); - return retval; - } + { + error ("sort: mode must be either \"ascend\" or \"descend\""); + return retval; + } } const dim_vector dv = arg.dims (); @@ -5818,10 +5818,10 @@ else { if (dim < 0 || dim > dv.length () - 1) - { - error ("sort: dim must be a valid dimension"); - return retval; - } + { + error ("sort: dim must be a valid dimension"); + return retval; + } } if (return_idx) @@ -6125,22 +6125,22 @@ octave_value mode_arg; if (nargin == 3) - smode = get_sort_mode_option (args(2), "third"); + smode = get_sort_mode_option (args(2), "third"); std::string tmp = args(1).string_value (); if (! error_state) - { - if (tmp == "rows") - by_rows = true; - else - smode = get_sort_mode_option (args(1), "second"); - } + { + if (tmp == "rows") + by_rows = true; + else + smode = get_sort_mode_option (args(1), "second"); + } else - error ("expecting second argument to be character string"); + error ("expecting second argument to be character string"); if (error_state) - return retval; + return retval; } octave_value arg = args(0); @@ -6148,16 +6148,16 @@ if (by_rows) { if (arg.is_sparse_type ()) - error ("issorted: sparse matrices not yet supported"); + error ("issorted: sparse matrices not yet supported"); if (arg.ndims () == 2) - retval = arg.is_sorted_rows (smode) != UNSORTED; + retval = arg.is_sorted_rows (smode) != UNSORTED; else - error ("issorted: needs a 2-dimensional object"); + error ("issorted: needs a 2-dimensional object"); } else { if (arg.dims ().is_vector ()) - retval = args(0).is_sorted (smode) != UNSORTED; + retval = args(0).is_sorted (smode) != UNSORTED; else error ("issorted: needs a vector"); } diff --git a/src/debug.cc b/src/debug.cc --- a/src/debug.cc +++ b/src/debug.cc @@ -73,20 +73,20 @@ std::ifstream file (fname.c_str (), std::ios::in|std::ios::binary); if (file) - { - std::string buf (sz+1, 0); + { + std::string buf (sz+1, 0); - file.read (&buf[0], sz+1); + file.read (&buf[0], sz+1); - if (file.eof ()) - { - // Expected to read the entire file. + if (file.eof ()) + { + // Expected to read the entire file. - retval = buf; - } - else - error ("error reading file %s", fname.c_str ()); - } + retval = buf; + } + else + error ("error reading file %s", fname.c_str ()); + } } return retval; @@ -109,16 +109,16 @@ char c = buf[i]; if (c == '\r' && ++i < len) - { - c = buf[i]; + { + c = buf[i]; - if (c == '\n') - offsets.push_back (i+1); - else - offsets.push_back (i); - } + if (c == '\n') + offsets.push_back (i+1); + else + offsets.push_back (i); + } else if (c == '\n') - offsets.push_back (i+1); + offsets.push_back (i+1); } offsets.push_back (len); @@ -153,7 +153,7 @@ size_t eol = offsets[line+1]; while (eol > 0 && (buf[eol-1] == '\n' || buf[eol-1] == '\r')) - eol--; + eol--; retval = buf.substr (bol, eol - bol); } @@ -177,7 +177,7 @@ octave_value fcn = symbol_table::find_function (fname); if (fcn.is_defined () && fcn.is_user_code ()) - dbg_fcn = fcn.user_code_value (); + dbg_fcn = fcn.user_code_value (); } return dbg_fcn; @@ -185,7 +185,7 @@ static void parse_dbfunction_params (const char *who, const octave_value_list& args, - std::string& symbol_name, bp_table::intmap& lines) + std::string& symbol_name, bp_table::intmap& lines) { int nargin = args.length (); int idx = 0; @@ -211,7 +211,7 @@ { symbol_name = args(0).string_value (); if (error_state) - return; + return; idx = 1; } else @@ -220,38 +220,38 @@ for (int i = idx; i < nargin; i++ ) { if (args(i).is_string ()) - { - int line = atoi (args(i).string_value().c_str ()); - if (error_state) - break; - lines[list_idx++] = line; - } + { + int line = atoi (args(i).string_value().c_str ()); + if (error_state) + break; + lines[list_idx++] = line; + } else if (args(i).is_map ()) - octave_stdout << who << ": accepting a struct" << std::endl; + octave_stdout << who << ": accepting a struct" << std::endl; else - { - const NDArray arg = args(i).array_value (); - - if (error_state) - break; - - for (octave_idx_type j = 0; j < arg.nelem (); j++) - { - int line = static_cast (arg.elem (j)); - if (error_state) - break; - lines[list_idx++] = line; - } - - if (error_state) - break; - } + { + const NDArray arg = args(i).array_value (); + + if (error_state) + break; + + for (octave_idx_type j = 0; j < arg.nelem (); j++) + { + int line = static_cast (arg.elem (j)); + if (error_state) + break; + lines[list_idx++] = line; + } + + if (error_state) + break; + } } } bp_table::intmap bp_table::do_add_breakpoint (const std::string& fname, - const bp_table::intmap& line) + const bp_table::intmap& line) { intmap retval; @@ -264,24 +264,24 @@ tree_statement_list *cmds = dbg_fcn->body (); if (cmds) - { - for (int i = 0; i < len; i++) - { - const_intmap_iterator p = line.find (i); + { + for (int i = 0; i < len; i++) + { + const_intmap_iterator p = line.find (i); - if (p != line.end ()) - { - int lineno = p->second; + if (p != line.end ()) + { + int lineno = p->second; - retval[i] = cmds->set_breakpoint (lineno); + retval[i] = cmds->set_breakpoint (lineno); - if (retval[i] != 0) - { - bp_set.insert (fname); - } - } - } - } + if (retval[i] != 0) + { + bp_set.insert (fname); + } + } + } + } } else error ("add_breakpoint: unable to find the function requested\n"); @@ -294,7 +294,7 @@ int bp_table::do_remove_breakpoint (const std::string& fname, - const bp_table::intmap& line) + const bp_table::intmap& line) { int retval = 0; @@ -310,36 +310,36 @@ octave_user_code *dbg_fcn = get_user_code (fname); if (dbg_fcn) - { - tree_statement_list *cmds = dbg_fcn->body (); + { + tree_statement_list *cmds = dbg_fcn->body (); - if (cmds) - { - octave_value_list results = cmds->list_breakpoints (); + if (cmds) + { + octave_value_list results = cmds->list_breakpoints (); - if (results.length () > 0) - { - for (int i = 0; i < len; i++) - { - const_intmap_iterator p = line.find (i); + if (results.length () > 0) + { + for (int i = 0; i < len; i++) + { + const_intmap_iterator p = line.find (i); - if (p != line.end ()) - cmds->delete_breakpoint (p->second); - } + if (p != line.end ()) + cmds->delete_breakpoint (p->second); + } - results = cmds->list_breakpoints (); + results = cmds->list_breakpoints (); - bp_set_iterator it = bp_set.find (fname); - if (results.length () == 0 && it != bp_set.end ()) - bp_set.erase (it); + bp_set_iterator it = bp_set.find (fname); + if (results.length () == 0 && it != bp_set.end ()) + bp_set.erase (it); - } + } - retval = results.length (); - } - } + retval = results.length (); + } + } else - error ("remove_breakpoint: unable to find the function requested\n"); + error ("remove_breakpoint: unable to find the function requested\n"); } tree_evaluator::debug_mode = bp_table::have_breakpoints () || Vdebugging; @@ -350,7 +350,7 @@ bp_table::intmap bp_table::do_remove_all_breakpoints_in_file (const std::string& fname, - bool silent) + bool silent) { intmap retval; @@ -361,25 +361,25 @@ tree_statement_list *cmds = dbg_fcn->body (); if (cmds) - { - octave_value_list bkpts = cmds->list_breakpoints (); + { + octave_value_list bkpts = cmds->list_breakpoints (); - for (int i = 0; i < bkpts.length (); i++) - { - int lineno = static_cast (bkpts(i).int_value ()); - cmds->delete_breakpoint (lineno); - retval[i] = lineno; - } + for (int i = 0; i < bkpts.length (); i++) + { + int lineno = static_cast (bkpts(i).int_value ()); + cmds->delete_breakpoint (lineno); + retval[i] = lineno; + } - bp_set_iterator it = bp_set.find (fname); - if (it != bp_set.end ()) - bp_set.erase (it); + bp_set_iterator it = bp_set.find (fname); + if (it != bp_set.end ()) + bp_set.erase (it); - } + } } else if (! silent) error ("remove_all_breakpoint_in_file: " - "unable to find the function requested\n"); + "unable to find the function requested\n"); tree_evaluator::debug_mode = bp_table::have_breakpoints () || Vdebugging; @@ -398,17 +398,17 @@ std::string do_find_bkpt_list (octave_value_list slist, - std::string match) + std::string match) { std::string retval; for (int i = 0; i < slist.length (); i++) { if (slist (i).string_value () == match) - { - retval = slist(i).string_value (); - break; - } + { + retval = slist(i).string_value (); + break; + } } return retval; @@ -423,33 +423,33 @@ for (bp_set_iterator it = bp_set.begin (); it != bp_set.end (); it++) { if (fname_list.length () == 0 - || do_find_bkpt_list (fname_list, *it) != "") - { - octave_user_code *f = get_user_code (*it); + || do_find_bkpt_list (fname_list, *it) != "") + { + octave_user_code *f = get_user_code (*it); - if (f) - { - tree_statement_list *cmds = f->body (); + if (f) + { + tree_statement_list *cmds = f->body (); - if (cmds) - { - octave_value_list bkpts = cmds->list_breakpoints (); - octave_idx_type len = bkpts.length (); + if (cmds) + { + octave_value_list bkpts = cmds->list_breakpoints (); + octave_idx_type len = bkpts.length (); - if (len > 0) - { - bp_table::intmap bkpts_vec; - - for (int i = 0; i < len; i++) - bkpts_vec[i] = bkpts (i).double_value (); - - std::string symbol_name = f->name (); + if (len > 0) + { + bp_table::intmap bkpts_vec; + + for (int i = 0; i < len; i++) + bkpts_vec[i] = bkpts (i).double_value (); + + std::string symbol_name = f->name (); - retval[symbol_name] = bkpts_vec; - } - } - } - } + retval[symbol_name] = bkpts_vec; + } + } + } + } } return retval; @@ -467,10 +467,10 @@ bp_table::const_intmap_iterator p = line.find (i); if (p != line.end ()) - { - int lineno = p->second; - retval(idx++) = lineno; - } + { + int lineno = p->second; + retval(idx++) = lineno; + } } retval.resize (dim_vector (1, idx)); @@ -567,22 +567,22 @@ if (nargin == 1) { if (args(0).is_string ()) - { - symbol_name = args(0).string_value (); - fcn_list(0) = symbol_name; - bp_list = bp_table::get_breakpoint_list (fcn_list); - } + { + symbol_name = args(0).string_value (); + fcn_list(0) = symbol_name; + bp_list = bp_table::get_breakpoint_list (fcn_list); + } else - gripe_wrong_type_arg ("dbstatus", args(0)); + gripe_wrong_type_arg ("dbstatus", args(0)); } else { octave_user_code *dbg_fcn = get_user_code (); if (dbg_fcn) - { - symbol_name = dbg_fcn->name (); - fcn_list(0) = symbol_name; - } + { + symbol_name = dbg_fcn->name (); + fcn_list(0) = symbol_name; + } bp_list = bp_table::get_breakpoint_list (fcn_list); } @@ -592,20 +592,20 @@ // Print out the breakpoint information. for (bp_table::fname_line_map_iterator it = bp_list.begin (); - it != bp_list.end (); it++) - { - octave_stdout << "Breakpoint in " << it->first << " at line(s) "; + it != bp_list.end (); it++) + { + octave_stdout << "Breakpoint in " << it->first << " at line(s) "; - bp_table::intmap m = it->second; + bp_table::intmap m = it->second; - size_t nel = m.size (); + size_t nel = m.size (); - for (size_t j = 0; j < nel; j++) - octave_stdout << m[j] << ((j < nel - 1) ? ", " : "."); + for (size_t j = 0; j < nel; j++) + octave_stdout << m[j] << ((j < nel - 1) ? ", " : "."); - if (nel > 0) - octave_stdout << std::endl; - } + if (nel > 0) + octave_stdout << std::endl; + } return octave_value (); } else @@ -618,13 +618,13 @@ Cell line (dim_vector (bp_list.size (), 1)); for (bp_table::const_fname_line_map_iterator it = bp_list.begin (); - it != bp_list.end (); it++) - { - names(i) = it->first; - line(i) = intmap_to_ov (it->second); - file(i) = do_which (it->first); - i++; - } + it != bp_list.end (); it++) + { + names(i) = it->first; + line(i) = intmap_to_ov (it->second); + file(i) = do_which (it->first); + i++; + } retval.assign ("name", names); retval.assign ("file", file); @@ -652,11 +652,11 @@ std::string name = dbg_fcn->fcn_file_name (); if (name.empty ()) - { - have_file = false; + { + have_file = false; - name = dbg_fcn->name (); - } + name = dbg_fcn->name (); + } octave_stdout << name << ":"; @@ -671,26 +671,26 @@ int l = octave_call_stack::current_line (); if (l > 0) - { - octave_stdout << " line " << l; + { + octave_stdout << " line " << l; - int c = octave_call_stack::current_column (); + int c = octave_call_stack::current_column (); - if (c > 0) - octave_stdout << ", column " << c; + if (c > 0) + octave_stdout << ", column " << c; - octave_stdout << std::endl; + octave_stdout << std::endl; - if (have_file) - { - std::string line = get_file_line (name, l); + if (have_file) + { + std::string line = get_file_line (name, l); - if (! line.empty ()) - octave_stdout << l << ": " << line << std::endl; - } - } + if (! line.empty ()) + octave_stdout << l << ": " << line << std::endl; + } + } else - octave_stdout << " (unknown line)\n"; + octave_stdout << " (unknown line)\n"; } else error ("dbwhere: must be inside of a user function to use dbwhere\n"); @@ -710,30 +710,30 @@ std::ifstream fs (ff.c_str (), std::ios::in); if (fs) - { - char ch; - int line = 1; - - if (line >= start && line <= end) - os << line << "\t"; - - while (fs.get (ch)) - { - if (line >= start && line <= end) - { - os << ch; - } + { + char ch; + int line = 1; + + if (line >= start && line <= end) + os << line << "\t"; + + while (fs.get (ch)) + { + if (line >= start && line <= end) + { + os << ch; + } - if (ch == '\n') - { - line++; - if (line >= start && line <= end) - os << line << "\t"; - } - } - } + if (ch == '\n') + { + line++; + if (line >= start && line <= end) + os << line << "\t"; + } + } + } else - os << "dbtype: unable to open `" << ff << "' for reading!\n"; + os << "dbtype: unable to open `" << ff << "' for reading!\n"; } else os << "dbtype: unknown function " << name << "\n"; @@ -757,91 +757,91 @@ if (! error_state) { switch (nargin) - { - case 0: // dbtype - dbg_fcn = get_user_code (); + { + case 0: // dbtype + dbg_fcn = get_user_code (); - if (dbg_fcn) - do_dbtype (octave_stdout, dbg_fcn->name (), 0, INT_MAX); - else - error ("dbtype: must be in a user function to give no arguments to dbtype\n"); - break; + if (dbg_fcn) + do_dbtype (octave_stdout, dbg_fcn->name (), 0, INT_MAX); + else + error ("dbtype: must be in a user function to give no arguments to dbtype\n"); + break; - case 1: // (dbtype func) || (dbtype start:end) - dbg_fcn = get_user_code (argv[1]); + case 1: // (dbtype func) || (dbtype start:end) + dbg_fcn = get_user_code (argv[1]); - if (dbg_fcn) - do_dbtype (octave_stdout, dbg_fcn->name (), 0, INT_MAX); - else - { - dbg_fcn = get_user_code (); + if (dbg_fcn) + do_dbtype (octave_stdout, dbg_fcn->name (), 0, INT_MAX); + else + { + dbg_fcn = get_user_code (); - if (dbg_fcn) - { - std::string arg = argv[1]; + if (dbg_fcn) + { + std::string arg = argv[1]; - size_t ind = arg.find (':'); + size_t ind = arg.find (':'); - if (ind != std::string::npos) - { - std::string start_str = arg.substr (0, ind); - std::string end_str = arg.substr (ind + 1); + if (ind != std::string::npos) + { + std::string start_str = arg.substr (0, ind); + std::string end_str = arg.substr (ind + 1); - int start = atoi (start_str.c_str ()); - int end = atoi (end_str.c_str ()); - - if (std::min (start, end) <= 0) - error ("dbtype: start and end lines must be >= 1\n"); + int start = atoi (start_str.c_str ()); + int end = atoi (end_str.c_str ()); + + if (std::min (start, end) <= 0) + error ("dbtype: start and end lines must be >= 1\n"); - if (start <= end) - do_dbtype (octave_stdout, dbg_fcn->name (), start, end); - else - error ("dbtype: start line must be less than end line\n"); - } - else - error ("dbtype: line specification must be `start:end'"); - } - } - break; + if (start <= end) + do_dbtype (octave_stdout, dbg_fcn->name (), start, end); + else + error ("dbtype: start line must be less than end line\n"); + } + else + error ("dbtype: line specification must be `start:end'"); + } + } + break; - case 2: // (dbtype func start:end) , (dbtype func start) - dbg_fcn = get_user_code (argv[1]); + case 2: // (dbtype func start:end) , (dbtype func start) + dbg_fcn = get_user_code (argv[1]); - if (dbg_fcn) - { - std::string arg = argv[2]; - int start = 0; - int end = 0; - size_t ind = arg.find (':'); + if (dbg_fcn) + { + std::string arg = argv[2]; + int start = 0; + int end = 0; + size_t ind = arg.find (':'); - if (ind != std::string::npos) - { - std::string start_str = arg.substr (0, ind); - std::string end_str = arg.substr (ind + 1); + if (ind != std::string::npos) + { + std::string start_str = arg.substr (0, ind); + std::string end_str = arg.substr (ind + 1); - start = atoi (start_str.c_str ()); - end = atoi (end_str.c_str ()); - - } - else - { - start = atoi (arg.c_str ()); - end = start; - } + start = atoi (start_str.c_str ()); + end = atoi (end_str.c_str ()); + + } + else + { + start = atoi (arg.c_str ()); + end = start; + } - if (std::min (start, end) <= 0) - error ("dbtype: start and end lines must be >= 1\n"); - - if (start <= end) - do_dbtype (octave_stdout, dbg_fcn->name (), start, end); - else - error ("dbtype: start line must be less than end line\n"); - } - break; + if (std::min (start, end) <= 0) + error ("dbtype: start and end lines must be >= 1\n"); + + if (start <= end) + do_dbtype (octave_stdout, dbg_fcn->name (), start, end); + else + error ("dbtype: start line must be less than end line\n"); + } + break; - default: - error ("dbtype: expecting zero, one, or two arguments\n"); - } + default: + error ("dbtype: expecting zero, one, or two arguments\n"); + } } return retval; @@ -870,18 +870,18 @@ octave_value arg = args(0); if (arg.is_string ()) - { - std::string s_arg = arg.string_value (); + { + std::string s_arg = arg.string_value (); - n = atoi (s_arg.c_str ()); - } + n = atoi (s_arg.c_str ()); + } else - n = args(0).int_value (); + n = args(0).int_value (); if (n > 0) - nskip = n; + nskip = n; else - error ("dbstack: expecting N to be a nonnegative integer"); + error ("dbstack: expecting N to be a nonnegative integer"); } if (! error_state) @@ -889,36 +889,36 @@ Octave_map stk = octave_call_stack::backtrace (nskip, curr_frame); if (nargout == 0) - { - octave_idx_type nframes_to_display = stk.numel (); + { + octave_idx_type nframes_to_display = stk.numel (); - if (nframes_to_display > 0) - { - octave_stdout << "Stopped in:\n\n"; + if (nframes_to_display > 0) + { + octave_stdout << "Stopped in:\n\n"; - Cell names = stk.contents ("name"); - Cell lines = stk.contents ("line"); - Cell columns = stk.contents ("column"); + Cell names = stk.contents ("name"); + Cell lines = stk.contents ("line"); + Cell columns = stk.contents ("column"); - for (octave_idx_type i = 0; i < nframes_to_display; i++) - { - octave_value name = names(i); - octave_value line = lines(i); - octave_value column = columns(i); + for (octave_idx_type i = 0; i < nframes_to_display; i++) + { + octave_value name = names(i); + octave_value line = lines(i); + octave_value column = columns(i); - octave_stdout << (i == curr_frame ? "--> " : " ") - << name.string_value () - << " at line " << line.int_value () - << " column " << column.int_value () - << std::endl; - } - } - } + octave_stdout << (i == curr_frame ? "--> " : " ") + << name.string_value () + << " at line " << line.int_value () + << " column " << column.int_value () + << std::endl; + } + } + } else - { - retval(1) = curr_frame < 0 ? 1 : curr_frame + 1; - retval(0) = stk; - } + { + retval(1) = curr_frame < 0 ? 1 : curr_frame + 1; + retval(0) = stk; + } } return retval; @@ -934,22 +934,22 @@ octave_value arg = args(0); if (arg.is_string ()) - { - std::string s_arg = arg.string_value (); + { + std::string s_arg = arg.string_value (); - n = atoi (s_arg.c_str ()); - } + n = atoi (s_arg.c_str ()); + } else - n = args(0).int_value (); + n = args(0).int_value (); } if (! error_state) { if (who == "dbup") - n = -n; + n = -n; if (! octave_call_stack::goto_frame_relative (n, true)) - error ("%s: invalid stack frame", who.c_str ()); + error ("%s: invalid stack frame", who.c_str ()); } } @@ -1007,51 +1007,51 @@ int nargin = args.length (); if (nargin > 1) - print_usage (); + print_usage (); else if (nargin == 1) - { - if (args(0).is_string ()) - { - std::string arg = args(0).string_value (); + { + if (args(0).is_string ()) + { + std::string arg = args(0).string_value (); - if (! error_state) - { - if (arg == "in") - { - Vdebugging = false; + if (! error_state) + { + if (arg == "in") + { + Vdebugging = false; - tree_evaluator::dbstep_flag = -1; - } - else if (arg == "out") - { - Vdebugging = false; + tree_evaluator::dbstep_flag = -1; + } + else if (arg == "out") + { + Vdebugging = false; - tree_evaluator::dbstep_flag = -2; - } - else - { - int n = atoi (arg.c_str ()); + tree_evaluator::dbstep_flag = -2; + } + else + { + int n = atoi (arg.c_str ()); - if (n > 0) - { - Vdebugging = false; + if (n > 0) + { + Vdebugging = false; - tree_evaluator::dbstep_flag = n; - } - else - error ("dbstep: invalid argument"); - } - } - } - else - error ("dbstep: expecting character string as argument"); - } + tree_evaluator::dbstep_flag = n; + } + else + error ("dbstep: invalid argument"); + } + } + } + else + error ("dbstep: expecting character string as argument"); + } else - { - Vdebugging = false; + { + Vdebugging = false; - tree_evaluator::dbstep_flag = 1; - } + tree_evaluator::dbstep_flag = 1; + } } else error ("dbstep: can only be called in debug mode"); @@ -1071,13 +1071,13 @@ if (Vdebugging) { if (args.length () == 0) - { - Vdebugging = false; + { + Vdebugging = false; tree_evaluator::reset_debug_state (); - } + } else - print_usage (); + print_usage (); } else error ("dbcont: can only be called in debug mode"); @@ -1095,15 +1095,15 @@ if (Vdebugging) { if (args.length () == 0) - { - Vdebugging = false; + { + Vdebugging = false; tree_evaluator::reset_debug_state (); - octave_throw_interrupt_exception (); - } + octave_throw_interrupt_exception (); + } else - print_usage (); + print_usage (); } else error ("dbquit: can only be called in debug mode"); diff --git a/src/defaults.cc b/src/defaults.cc --- a/src/defaults.cc +++ b/src/defaults.cc @@ -106,12 +106,12 @@ octave_idx_type len = prefix.length (); if (s.substr (0, len) == prefix) - retval.replace (0, len, Voctave_home); + retval.replace (0, len, Voctave_home); } if (file_ops::dir_sep_char () != '/') std::replace (retval.begin (), retval.end (), '/', - file_ops::dir_sep_char ()); + file_ops::dir_sep_char ()); return retval; } diff --git a/src/defun.cc b/src/defun.cc --- a/src/defun.cc +++ b/src/defun.cc @@ -69,10 +69,10 @@ if (version != OCTAVE_API_VERSION) { error ("API version %s found in .oct file function `%s'\n" - " does not match the running Octave (API version %s)\n" - " this can lead to incorrect results or other failures\n" - " you can fix this problem by recompiling this .oct file", - version.c_str (), fcn.c_str (), OCTAVE_API_VERSION); + " does not match the running Octave (API version %s)\n" + " this can lead to incorrect results or other failures\n" + " you can fix this problem by recompiling this .oct file", + version.c_str (), fcn.c_str (), OCTAVE_API_VERSION); } } @@ -80,8 +80,8 @@ void install_builtin_function (octave_builtin::fcn f, const std::string& name, - const std::string& doc, - bool /* can_hide_function -- not yet implemented */) + const std::string& doc, + bool /* can_hide_function -- not yet implemented */) { octave_value fcn (new octave_builtin (f, name, doc)); @@ -90,8 +90,8 @@ void install_dld_function (octave_dld_function::fcn f, const std::string& name, - const octave_shlib& shl, const std::string& doc, - bool relative) + const octave_shlib& shl, const std::string& doc, + bool relative) { octave_dld_function *fcn = new octave_dld_function (f, shl, name, doc); @@ -105,7 +105,7 @@ void install_mex_function (void *fptr, bool fmex, const std::string& name, - const octave_shlib& shl, bool relative) + const octave_shlib& shl, bool relative) { octave_mex_function *fcn = new octave_mex_function (fptr, fmex, shl, name); diff --git a/src/dirfns.cc b/src/dirfns.cc --- a/src/dirfns.cc +++ b/src/dirfns.cc @@ -125,17 +125,17 @@ std::string dirname = argv[1]; if (dirname.length () > 0 - && ! octave_change_to_directory (dirname)) - { - return retval; - } + && ! octave_change_to_directory (dirname)) + { + return retval; + } } else { std::string home_dir = octave_env::get_home_directory (); if (home_dir.empty () || ! octave_change_to_directory (home_dir)) - return retval; + return retval; } return retval; @@ -176,22 +176,22 @@ std::string dirname = args(0).string_value (); if (error_state) - gripe_wrong_type_arg ("readdir", args(0)); + gripe_wrong_type_arg ("readdir", args(0)); else - { - dir_entry dir (dirname); + { + dir_entry dir (dirname); - if (dir) - { - string_vector dirlist = dir.read (); - retval(0) = Cell (dirlist.sort ()); - retval(1) = 0.0; - } - else - { - retval(2) = dir.error (); - } - } + if (dir) + { + string_vector dirlist = dir.read (); + retval(0) = Cell (dirlist.sort ()); + retval(1) = 0.0; + } + else + { + retval(2) = dir.error (); + } + } } else print_usage (); @@ -231,22 +231,22 @@ std::string dir = args(1).string_value (); if (error_state) - { - gripe_wrong_type_arg ("mkdir", args(0)); - return retval; - } + { + gripe_wrong_type_arg ("mkdir", args(0)); + return retval; + } else - dirname = file_ops::concat (parent, dir); + dirname = file_ops::concat (parent, dir); } else if (nargin == 1) { dirname = args(0).string_value (); if (error_state) - { - gripe_wrong_type_arg ("mkdir", args(0)); - return retval; - } + { + gripe_wrong_type_arg ("mkdir", args(0)); + return retval; + } } if (nargin == 1 || nargin == 2) @@ -258,26 +258,26 @@ file_stat fs (dirname); if (fs && fs.is_dir ()) - { - // For compatibility with Matlab, we return true when the - // directory already exists. + { + // For compatibility with Matlab, we return true when the + // directory already exists. - retval(2) = "mkdir"; - retval(1) = "directory exists"; - retval(0) = true; - } + retval(2) = "mkdir"; + retval(1) = "directory exists"; + retval(0) = true; + } else - { - int status = octave_mkdir (dirname, 0777, msg); + { + int status = octave_mkdir (dirname, 0777, msg); - if (status < 0) - { - retval(2) = "mkdir"; - retval(1) = msg; - } - else - retval(0) = true; - } + if (status < 0) + { + retval(2) = "mkdir"; + retval(1) = msg; + } + else + retval(0) = true; + } } else print_usage (); @@ -314,44 +314,44 @@ std::string dirname = args(0).string_value (); if (error_state) - gripe_wrong_type_arg ("rmdir", args(0)); + gripe_wrong_type_arg ("rmdir", args(0)); else - { - std::string fulldir = file_ops::tilde_expand (dirname); - int status = -1; - std::string msg; + { + std::string fulldir = file_ops::tilde_expand (dirname); + int status = -1; + std::string msg; - if (nargin == 2) - { - if (args(1).string_value () == "s") - { - bool doit = true; + if (nargin == 2) + { + if (args(1).string_value () == "s") + { + bool doit = true; - if (interactive && Vconfirm_recursive_rmdir) - { - std::string prompt - = "remove entire contents of " + fulldir + "? "; + if (interactive && Vconfirm_recursive_rmdir) + { + std::string prompt + = "remove entire contents of " + fulldir + "? "; - doit = octave_yes_or_no (prompt); - } + doit = octave_yes_or_no (prompt); + } - if (doit) - status = octave_recursive_rmdir (fulldir, msg); - } - else - error ("rmdir: expecting second argument to be \"s\""); - } - else - status = octave_rmdir (fulldir, msg); + if (doit) + status = octave_recursive_rmdir (fulldir, msg); + } + else + error ("rmdir: expecting second argument to be \"s\""); + } + else + status = octave_rmdir (fulldir, msg); - if (status < 0) - { - retval(2) = "rmdir"; - retval(1) = msg; - } - else - retval(0) = true; - } + if (status < 0) + { + retval(2) = "rmdir"; + retval(1) = msg; + } + else + retval(0) = true; + } } else print_usage (); @@ -380,25 +380,25 @@ std::string from = args(0).string_value (); if (error_state) - gripe_wrong_type_arg ("link", args(0)); + gripe_wrong_type_arg ("link", args(0)); else - { - std::string to = args(1).string_value (); + { + std::string to = args(1).string_value (); - if (error_state) - gripe_wrong_type_arg ("link", args(1)); - else - { - std::string msg; + if (error_state) + gripe_wrong_type_arg ("link", args(1)); + else + { + std::string msg; - int status = octave_link (from, to, msg); + int status = octave_link (from, to, msg); - retval(0) = status; + retval(0) = status; - if (status < 0) - retval(1) = msg; - } - } + if (status < 0) + retval(1) = msg; + } + } } else print_usage (); @@ -427,25 +427,25 @@ std::string from = args(0).string_value (); if (error_state) - gripe_wrong_type_arg ("symlink", args(0)); + gripe_wrong_type_arg ("symlink", args(0)); else - { - std::string to = args(1).string_value (); + { + std::string to = args(1).string_value (); - if (error_state) - gripe_wrong_type_arg ("symlink", args(1)); - else - { - std::string msg; + if (error_state) + gripe_wrong_type_arg ("symlink", args(1)); + else + { + std::string msg; - int status = octave_symlink (from, to, msg); + int status = octave_symlink (from, to, msg); - retval(0) = status; + retval(0) = status; - if (status < 0) - retval(1) = msg; - } - } + if (status < 0) + retval(1) = msg; + } + } } else print_usage (); @@ -476,21 +476,21 @@ std::string symlink = args(0).string_value (); if (error_state) - gripe_wrong_type_arg ("readlink", args(0)); + gripe_wrong_type_arg ("readlink", args(0)); else - { - std::string result; - std::string msg; + { + std::string result; + std::string msg; - int status = octave_readlink (symlink, result, msg); + int status = octave_readlink (symlink, result, msg); - retval(0) = result; + retval(0) = result; - retval(1) = status; + retval(1) = status; - if (status < 0) - retval(2) = msg; - } + if (status < 0) + retval(2) = msg; + } } else print_usage (); @@ -519,25 +519,25 @@ std::string from = args(0).string_value (); if (error_state) - gripe_wrong_type_arg ("rename", args(0)); + gripe_wrong_type_arg ("rename", args(0)); else - { - std::string to = args(1).string_value (); + { + std::string to = args(1).string_value (); - if (error_state) - gripe_wrong_type_arg ("rename", args(1)); - else - { - std::string msg; + if (error_state) + gripe_wrong_type_arg ("rename", args(1)); + else + { + std::string msg; - int status = octave_rename (from, to, msg); + int status = octave_rename (from, to, msg); - retval(0) = status; + retval(0) = status; - if (status < 0) - retval(1) = msg; - } - } + if (status < 0) + retval(1) = msg; + } + } } else print_usage (); @@ -570,13 +570,13 @@ string_vector pat = args(0).all_strings (); if (error_state) - gripe_wrong_type_arg ("glob", args(0)); + gripe_wrong_type_arg ("glob", args(0)); else - { - glob_match pattern (file_ops::tilde_expand (pat)); + { + glob_match pattern (file_ops::tilde_expand (pat)); - retval = Cell (pattern.glob ()); - } + retval = Cell (pattern.glob ()); + } } else print_usage (); @@ -607,13 +607,13 @@ string_vector str = args(1).all_strings (); if (error_state) - gripe_wrong_type_arg ("fnmatch", args(0)); + gripe_wrong_type_arg ("fnmatch", args(0)); else - { - glob_match pattern (file_ops::tilde_expand (pat)); + { + glob_match pattern (file_ops::tilde_expand (pat)); - retval = pattern.match (str); - } + retval = pattern.match (str); + } } else print_usage (); @@ -643,14 +643,14 @@ std::string s = args(0).string_value (); if (! error_state) - { - if (s == "all") - retval = file_ops::dir_sep_chars (); - else - gripe_wrong_type_arg ("filesep", args(0)); - } + { + if (s == "all") + retval = file_ops::dir_sep_chars (); + else + gripe_wrong_type_arg ("filesep", args(0)); + } else - gripe_wrong_type_arg ("filesep", args(0)); + gripe_wrong_type_arg ("filesep", args(0)); } else print_usage (); @@ -679,24 +679,24 @@ std::string sval = args(0).string_value (); if (! error_state) - { - switch (sval.length ()) - { - case 1: - dir_path::path_sep_char (sval[0]); - break; + { + switch (sval.length ()) + { + case 1: + dir_path::path_sep_char (sval[0]); + break; - case 0: - dir_path::path_sep_char ('\0'); - break; + case 0: + dir_path::path_sep_char ('\0'); + break; - default: - error ("pathsep: argument must be a single character"); - break; - } - } + default: + error ("pathsep: argument must be a single character"); + break; + } + } else - error ("pathsep: argument must be a single character"); + error ("pathsep: argument must be a single character"); } else if (nargin > 1) print_usage (); diff --git a/src/display.cc b/src/display.cc --- a/src/display.cc +++ b/src/display.cc @@ -49,81 +49,81 @@ HDC hdc = GetDC (0); if (hdc) - { - dp = GetDeviceCaps (hdc, BITSPIXEL); + { + dp = GetDeviceCaps (hdc, BITSPIXEL); - ht = GetDeviceCaps (hdc, VERTRES); - wd = GetDeviceCaps (hdc, HORZRES); + ht = GetDeviceCaps (hdc, VERTRES); + wd = GetDeviceCaps (hdc, HORZRES); - double ht_mm = GetDeviceCaps (hdc, VERTSIZE); - double wd_mm = GetDeviceCaps (hdc, HORZSIZE); + double ht_mm = GetDeviceCaps (hdc, VERTSIZE); + double wd_mm = GetDeviceCaps (hdc, HORZSIZE); - rx = wd * 25.4 / wd_mm; - ry = ht * 25.4 / ht_mm; - } + rx = wd * 25.4 / wd_mm; + ry = ht * 25.4 / ht_mm; + } else - warning ("no graphical display found"); + warning ("no graphical display found"); #elif defined (HAVE_FRAMEWORK_CARBON) CGDirectDisplayID display = CGMainDisplayID (); if (display) - { - dp = CGDisplayBitsPerPixel (display); + { + dp = CGDisplayBitsPerPixel (display); - ht = CGDisplayPixelsHigh (display); - wd = CGDisplayPixelsWide (display); + ht = CGDisplayPixelsHigh (display); + wd = CGDisplayPixelsWide (display); - CGSize sz_mm = CGDisplayScreenSize (display); + CGSize sz_mm = CGDisplayScreenSize (display); - // On modern Mac systems (>= 10.5) CGSize is a struct keeping 2 - // CGFloat values, but the CGFloat typedef is not present on - // older systems, so use double instead. - double ht_mm = sz_mm.height; - double wd_mm = sz_mm.width; + // On modern Mac systems (>= 10.5) CGSize is a struct keeping 2 + // CGFloat values, but the CGFloat typedef is not present on + // older systems, so use double instead. + double ht_mm = sz_mm.height; + double wd_mm = sz_mm.width; - rx = wd * 25.4 / wd_mm; - ry = ht * 25.4 / ht_mm; - } + rx = wd * 25.4 / wd_mm; + ry = ht * 25.4 / ht_mm; + } else - warning ("no graphical display found"); + warning ("no graphical display found"); #elif defined (HAVE_X_WINDOWS) const char *display_name = getenv ("DISPLAY"); if (display_name && *display_name) - { - Display *display = XOpenDisplay (display_name); + { + Display *display = XOpenDisplay (display_name); - if (display) - { - Screen *screen = DefaultScreenOfDisplay (display); + if (display) + { + Screen *screen = DefaultScreenOfDisplay (display); - if (screen) - { - dp = DefaultDepthOfScreen (screen); + if (screen) + { + dp = DefaultDepthOfScreen (screen); - ht = HeightOfScreen (screen); - wd = WidthOfScreen (screen); + ht = HeightOfScreen (screen); + wd = WidthOfScreen (screen); - int screen_number = XScreenNumberOfScreen (screen); + int screen_number = XScreenNumberOfScreen (screen); - double ht_mm = DisplayHeightMM (display, screen_number); - double wd_mm = DisplayWidthMM (display, screen_number); + double ht_mm = DisplayHeightMM (display, screen_number); + double wd_mm = DisplayWidthMM (display, screen_number); - rx = wd * 25.4 / wd_mm; - ry = ht * 25.4 / ht_mm; - } - else - warning ("X11 display has no default screen"); - } - else - warning ("unable to open X11 DISPLAY"); - } + rx = wd * 25.4 / wd_mm; + ry = ht * 25.4 / ht_mm; + } + else + warning ("X11 display has no default screen"); + } + else + warning ("unable to open X11 DISPLAY"); + } else - warning ("X11 DISPLAY environment variable not set"); + warning ("X11 DISPLAY environment variable not set"); #else warning ("no graphical display found"); diff --git a/src/dynamic-ld.cc b/src/dynamic-ld.cc --- a/src/dynamic-ld.cc +++ b/src/dynamic-ld.cc @@ -101,20 +101,20 @@ void octave_shlib_list::do_remove (octave_shlib& shl, - octave_shlib::close_hook cl_hook) + octave_shlib::close_hook cl_hook) { for (iterator p = lib_list.begin (); p != lib_list.end (); p++) { if (*p == shl) - { + { // Erase first to avoid potentially invalidating the pointer by the // following hooks. - lib_list.erase (p); + lib_list.erase (p); - shl.close (cl_hook); + shl.close (cl_hook); - break; - } + break; + } } } @@ -126,10 +126,10 @@ for (const_iterator p = lib_list.begin (); p != lib_list.end (); p++) { if (p->file_name () == file_name) - { - retval = *p; - break; - } + { + retval = *p; + break; + } } return retval; @@ -170,7 +170,7 @@ void octave_shlib_list::remove (octave_shlib& shl, - octave_shlib::close_hook cl_hook) + octave_shlib::close_hook cl_hook) { if (instance_ok ()) instance->do_remove (shl, cl_hook); @@ -236,20 +236,20 @@ void octave_mex_file_list::do_remove (octave_shlib& shl, - octave_shlib::close_hook cl_hook) + octave_shlib::close_hook cl_hook) { for (iterator p = file_list.begin (); p != file_list.end (); p++) { if (*p == shl) - { + { // Erase first to avoid potentially invalidating the pointer by the // following hooks. - file_list.erase (p); + file_list.erase (p); - shl.close (cl_hook); + shl.close (cl_hook); - break; - } + break; + } } } @@ -280,7 +280,7 @@ void octave_mex_file_list::remove (octave_shlib& shl, - octave_shlib::close_hook cl_hook) + octave_shlib::close_hook cl_hook) { if (instance_ok ()) instance->do_remove (shl, cl_hook); @@ -333,8 +333,8 @@ octave_function * octave_dynamic_loader::do_load_oct (const std::string& fcn_name, - const std::string& file_name, - bool relative) + const std::string& file_name, + bool relative) { octave_function *retval = 0; @@ -360,32 +360,32 @@ if (! error_state) { if (oct_file) - { - void *function = oct_file.search (fcn_name, name_mangler); + { + void *function = oct_file.search (fcn_name, name_mangler); - if (! function) - { - // FIXME -- can we determine this C mangling scheme - // automatically at run time or configure time? + if (! function) + { + // FIXME -- can we determine this C mangling scheme + // automatically at run time or configure time? - function = oct_file.search (fcn_name, name_uscore_mangler); - } + function = oct_file.search (fcn_name, name_uscore_mangler); + } - if (function) - { - octave_dld_fcn_getter f - = FCN_PTR_CAST (octave_dld_fcn_getter, function); + if (function) + { + octave_dld_fcn_getter f + = FCN_PTR_CAST (octave_dld_fcn_getter, function); - retval = f (oct_file, relative); + retval = f (oct_file, relative); - if (! retval) - ::error ("failed to install .oct file function `%s'", - fcn_name.c_str ()); - } - } + if (! retval) + ::error ("failed to install .oct file function `%s'", + fcn_name.c_str ()); + } + } else - ::error ("%s is not a valid shared library", - file_name.c_str ()); + ::error ("%s is not a valid shared library", + file_name.c_str ()); } return retval; @@ -393,8 +393,8 @@ octave_function * octave_dynamic_loader::do_load_mex (const std::string& fcn_name, - const std::string& file_name, - bool /*relative*/) + const std::string& file_name, + bool /*relative*/) { octave_function *retval = 0; @@ -420,41 +420,41 @@ if (! error_state) { if (mex_file) - { - void *function = 0; + { + void *function = 0; - bool have_fmex = false; + bool have_fmex = false; - octave_mex_file_list::append (mex_file); + octave_mex_file_list::append (mex_file); - function = mex_file.search (fcn_name, mex_mangler); + function = mex_file.search (fcn_name, mex_mangler); - if (! function) - { - // FIXME -- can we determine this C mangling scheme - // automatically at run time or configure time? + if (! function) + { + // FIXME -- can we determine this C mangling scheme + // automatically at run time or configure time? - function = mex_file.search (fcn_name, mex_uscore_mangler); + function = mex_file.search (fcn_name, mex_uscore_mangler); - if (! function) - { - function = mex_file.search (fcn_name, mex_f77_mangler); + if (! function) + { + function = mex_file.search (fcn_name, mex_f77_mangler); - if (function) - have_fmex = true; - } - } + if (function) + have_fmex = true; + } + } - if (function) - retval = new octave_mex_function (function, have_fmex, - mex_file, fcn_name); - else - ::error ("failed to install .mex file function `%s'", - fcn_name.c_str ()); - } + if (function) + retval = new octave_mex_function (function, have_fmex, + mex_file, fcn_name); + else + ::error ("failed to install .mex file function `%s'", + fcn_name.c_str ()); + } else - ::error ("%s is not a valid shared library", - file_name.c_str ()); + ::error ("%s is not a valid shared library", + file_name.c_str ()); } return retval; @@ -462,7 +462,7 @@ bool octave_dynamic_loader::do_remove_oct (const std::string& fcn_name, - octave_shlib& shl) + octave_shlib& shl) { bool retval = false; @@ -474,7 +474,7 @@ retval = shl.remove (fcn_name); if (shl.number_of_functions_loaded () == 0) - octave_shlib_list::remove (shl); + octave_shlib_list::remove (shl); } return retval; @@ -482,7 +482,7 @@ bool octave_dynamic_loader::do_remove_mex (const std::string& fcn_name, - octave_shlib& shl) + octave_shlib& shl) { bool retval = false; @@ -494,7 +494,7 @@ retval = shl.remove (fcn_name); if (shl.number_of_functions_loaded () == 0) - octave_mex_file_list::remove (shl); + octave_mex_file_list::remove (shl); } return retval; @@ -502,8 +502,8 @@ octave_function * octave_dynamic_loader::load_oct (const std::string& fcn_name, - const std::string& file_name, - bool relative) + const std::string& file_name, + bool relative) { return (instance_ok ()) ? instance->do_load_oct (fcn_name, file_name, relative) : 0; @@ -511,8 +511,8 @@ octave_function * octave_dynamic_loader::load_mex (const std::string& fcn_name, - const std::string& file_name, - bool relative) + const std::string& file_name, + bool relative) { return (instance_ok ()) ? instance->do_load_mex (fcn_name, file_name, relative) : 0; @@ -520,14 +520,14 @@ bool octave_dynamic_loader::remove_oct (const std::string& fcn_name, - octave_shlib& shl) + octave_shlib& shl) { return (instance_ok ()) ? instance->do_remove_oct (fcn_name, shl) : false; } bool octave_dynamic_loader::remove_mex (const std::string& fcn_name, - octave_shlib& shl) + octave_shlib& shl) { return (instance_ok ()) ? instance->do_remove_mex (fcn_name, shl) : false; } diff --git a/src/error.cc b/src/error.cc --- a/src/error.cc +++ b/src/error.cc @@ -204,7 +204,7 @@ static void verror (bool save_last_error, std::ostream& os, - const char *name, const char *id, const char *fmt, va_list args, + const char *name, const char *id, const char *fmt, va_list args, bool with_cfn = false) { if (discard_error_messages) @@ -267,21 +267,21 @@ octave_user_code *fcn = octave_call_stack::caller_user_code (); if (fcn) - { - octave_idx_type curr_frame = -1; + { + octave_idx_type curr_frame = -1; - Vlast_error_stack = octave_call_stack::backtrace (0, curr_frame); - } + Vlast_error_stack = octave_call_stack::backtrace (0, curr_frame); + } else - Vlast_error_stack = initialize_last_error_stack (); + Vlast_error_stack = initialize_last_error_stack (); } if (buffer_error_messages) { if (error_message_buffer) - msg_string = "error: " + msg_string; + msg_string = "error: " + msg_string; else - error_message_buffer = new std::ostringstream (); + error_message_buffer = new std::ostringstream (); *error_message_buffer << msg_string; } @@ -298,42 +298,42 @@ static void error_1 (std::ostream& os, const char *name, const char *id, - const char *fmt, va_list args, bool with_cfn = false) + const char *fmt, va_list args, bool with_cfn = false) { if (error_state != -2) { if (fmt) - { - if (*fmt) - { - size_t len = strlen (fmt); + { + if (*fmt) + { + size_t len = strlen (fmt); - if (len > 0) - { - if (fmt[len - 1] == '\n') - { - if (len > 1) - { - char *tmp_fmt = strsave (fmt); - tmp_fmt[len - 1] = '\0'; - verror (true, os, name, id, tmp_fmt, args, with_cfn); - delete [] tmp_fmt; - } + if (len > 0) + { + if (fmt[len - 1] == '\n') + { + if (len > 1) + { + char *tmp_fmt = strsave (fmt); + tmp_fmt[len - 1] = '\0'; + verror (true, os, name, id, tmp_fmt, args, with_cfn); + delete [] tmp_fmt; + } - error_state = -2; - } - else - { - verror (true, os, name, id, fmt, args, with_cfn); + error_state = -2; + } + else + { + verror (true, os, name, id, fmt, args, with_cfn); - if (! error_state) - error_state = 1; - } - } - } - } + if (! error_state) + error_state = 1; + } + } + } + } else - panic ("error_1: invalid format"); + panic ("error_1: invalid format"); } } @@ -354,7 +354,7 @@ void vmessage_with_id (const char *name, const char *id, const char *fmt, - va_list args) + va_list args) { verror (false, std::cerr, name, id, fmt, args); } @@ -411,25 +411,25 @@ if (fmt) { if (*fmt) - { - size_t len = strlen (fmt); + { + size_t len = strlen (fmt); - if (len > 0) - { - if (fmt[len - 1] == '\n') - { - if (len > 1) - { - char *tmp_fmt = strsave (fmt); - tmp_fmt[len - 1] = '\0'; - verror (false, std::cerr, 0, "", tmp_fmt, args); - delete [] tmp_fmt; - } - } - else - verror (false, std::cerr, 0, "", fmt, args); - } - } + if (len > 0) + { + if (fmt[len - 1] == '\n') + { + if (len > 1) + { + char *tmp_fmt = strsave (fmt); + tmp_fmt[len - 1] = '\0'; + verror (false, std::cerr, 0, "", tmp_fmt, args); + delete [] tmp_fmt; + } + } + else + verror (false, std::cerr, 0, "", fmt, args); + } + } } else panic ("pr_where_2: invalid format"); @@ -462,16 +462,16 @@ Cell columns = stk.contents ("column"); for (octave_idx_type i = 0; i < nframes_to_display; i++) - { - octave_value name = names(i); - octave_value line = lines(i); - octave_value column = columns(i); + { + octave_value name = names(i); + octave_value line = lines(i); + octave_value column = columns(i); - std::string nm = name.string_value (); + std::string nm = name.string_value (); - pr_where_1 (" %s at line %d column %d\n", nm.c_str (), - line.int_value (), column.int_value ()); - } + pr_where_1 (" %s at line %d column %d\n", nm.c_str (), + line.int_value (), column.int_value ()); + } } } @@ -598,29 +598,29 @@ bool id_found = false; for (octave_idx_type i = 0; i < nel; i++) - { - octave_value ov = identifier(i); - std::string ovs = ov.string_value (); + { + octave_value ov = identifier(i); + std::string ovs = ov.string_value (); - if (! all_found && ovs == "all") - { - all_state = check_state (state(i).string_value ()); + if (! all_found && ovs == "all") + { + all_state = check_state (state(i).string_value ()); - if (all_state >= 0) - all_found = true; - } + if (all_state >= 0) + all_found = true; + } - if (! id_found && ovs == id) - { - id_state = check_state (state(i).string_value ()); + if (! id_found && ovs == id) + { + id_state = check_state (state(i).string_value ()); - if (id_state >= 0) - id_found = true; - } + if (id_state >= 0) + id_found = true; + } - if (all_found && id_found) - break; - } + if (all_found && id_found) + break; + } } if (all_state == -1) @@ -629,21 +629,21 @@ if (all_state == 0) { if (id_state >= 0) - retval = id_state; + retval = id_state; } else if (all_state == 1) { if (id_state == 0 || id_state == 2) - retval = id_state; + retval = id_state; else - retval = all_state; + retval = all_state; } else if (all_state == 2) { if (id_state == 0) - retval= id_state; + retval= id_state; else - retval = all_state; + retval = all_state; } return retval; @@ -665,23 +665,23 @@ vwarning ("warning", id, fmt, args); if (! symbol_table::at_top_level () - && Vbacktrace_on_warning - && ! warning_state - && ! discard_warning_messages) - pr_where ("warning"); + && Vbacktrace_on_warning + && ! warning_state + && ! discard_warning_messages) + pr_where ("warning"); warning_state = 1; if ((interactive || forced_interactive) - && Vdebug_on_warning - && octave_call_stack::caller_user_code ()) - { + && Vdebug_on_warning + && octave_call_stack::caller_user_code ()) + { unwind_protect frame; - frame.protect_var (Vdebug_on_warning); - Vdebug_on_warning = false; + frame.protect_var (Vdebug_on_warning); + Vdebug_on_warning = false; - do_keyboard (octave_value_list ()); - } + do_keyboard (octave_value_list ()); + } } } @@ -787,7 +787,7 @@ static std::string handle_message (error_fun f, const char *id, const char *msg, - const octave_value_list& args) + const octave_value_list& args) { std::string retval; @@ -800,26 +800,26 @@ octave_value arg; if (nargin > 1) - { - octave_value_list tmp = Fsprintf (args, 1); - arg = tmp(0); - } + { + octave_value_list tmp = Fsprintf (args, 1); + arg = tmp(0); + } else - arg = args(0); + arg = args(0); if (arg.is_defined ()) - { - if (arg.is_string ()) - { - tstr = arg.string_value (); - msg = tstr.c_str (); - - if (! msg) - return retval; - } - else if (arg.is_empty ()) - return retval; - } + { + if (arg.is_string ()) + { + tstr = arg.string_value (); + msg = tstr.c_str (); + + if (! msg) + return retval; + } + else if (arg.is_empty ()) + return retval; + } } // Ugh. @@ -829,21 +829,21 @@ if (len > 0) { if (msg[len - 1] == '\n') - { - if (len > 1) - { - char *tmp_msg = strsave (msg); - tmp_msg[len - 1] = '\0'; - f (id, "%s\n", tmp_msg); - retval = tmp_msg; - delete [] tmp_msg; - } - } + { + if (len > 1) + { + char *tmp_msg = strsave (msg); + tmp_msg[len - 1] = '\0'; + f (id, "%s\n", tmp_msg); + retval = tmp_msg; + delete [] tmp_msg; + } + } else - { - f (id, "%s", msg); - retval = msg; - } + { + f (id, "%s", msg); + retval = msg; + } } return retval; @@ -870,117 +870,117 @@ Octave_map err = args(0).map_value (); if (! error_state) - { - if (err.contains ("message") && err.contains ("identifier")) - { - std::string msg = err.contents("message")(0).string_value (); - std::string id = err.contents("identifier")(0).string_value (); - int len = msg.length(); + { + if (err.contains ("message") && err.contains ("identifier")) + { + std::string msg = err.contents("message")(0).string_value (); + std::string id = err.contents("identifier")(0).string_value (); + int len = msg.length(); - std::string file; - std::string nm; - int l = -1; - int c = -1; + std::string file; + std::string nm; + int l = -1; + int c = -1; - Octave_map err_stack = initialize_last_error_stack (); + Octave_map err_stack = initialize_last_error_stack (); - if (err.contains ("stack")) - { - err_stack = err.contents("stack")(0).map_value (); + if (err.contains ("stack")) + { + err_stack = err.contents("stack")(0).map_value (); - if (err_stack.numel () > 0) - { - if (err_stack.contains ("file")) - file = err_stack.contents("file")(0).string_value (); + if (err_stack.numel () > 0) + { + if (err_stack.contains ("file")) + file = err_stack.contents("file")(0).string_value (); - if (err_stack.contains ("name")) - nm = err_stack.contents("name")(0).string_value (); + if (err_stack.contains ("name")) + nm = err_stack.contents("name")(0).string_value (); - if (err_stack.contains ("line")) - l = err_stack.contents("line")(0).nint_value (); + if (err_stack.contains ("line")) + l = err_stack.contents("line")(0).nint_value (); - if (err_stack.contains ("column")) - c = err_stack.contents("column")(0).nint_value (); - } - } + if (err_stack.contains ("column")) + c = err_stack.contents("column")(0).nint_value (); + } + } - // Ugh. - char *tmp_msg = strsave (msg.c_str ()); - if (tmp_msg[len-1] == '\n') - { - if (len > 1) - { - tmp_msg[len - 1] = '\0'; - rethrow_error (id.c_str (), "%s\n", tmp_msg); - } - } - else - rethrow_error (id.c_str (), "%s", tmp_msg); - delete [] tmp_msg; + // Ugh. + char *tmp_msg = strsave (msg.c_str ()); + if (tmp_msg[len-1] == '\n') + { + if (len > 1) + { + tmp_msg[len - 1] = '\0'; + rethrow_error (id.c_str (), "%s\n", tmp_msg); + } + } + else + rethrow_error (id.c_str (), "%s", tmp_msg); + delete [] tmp_msg; - // FIXME -- is this the right thing to do for - // Vlast_error_stack? Should it be saved and restored - // with unwind_protect? + // FIXME -- is this the right thing to do for + // Vlast_error_stack? Should it be saved and restored + // with unwind_protect? - Vlast_error_stack = err_stack; + Vlast_error_stack = err_stack; - if (err.contains ("stack")) - { - if (file.empty ()) - { - if (nm.empty ()) - { - if (l > 0) - { - if (c > 0) - pr_where_1 ("error: near line %d, column %d", - l, c); - else - pr_where_1 ("error: near line %d", l); - } - } - else - { - if (l > 0) - { - if (c > 0) - pr_where_1 ("error: called from `%s' near line %d, column %d", - nm.c_str (), l, c); - else - pr_where_1 ("error: called from `%d' near line %d", nm.c_str (), l); - } - } - } - else - { - if (nm.empty ()) - { - if (l > 0) - { - if (c > 0) - pr_where_1 ("error: in file %s near line %d, column %d", - file.c_str (), l, c); - else - pr_where_1 ("error: in file %s near line %d", file.c_str (), l); - } - } - else - { - if (l > 0) - { - if (c > 0) - pr_where_1 ("error: called from `%s' in file %s near line %d, column %d", - nm.c_str (), file.c_str (), l, c); - else - pr_where_1 ("error: called from `%d' in file %s near line %d", nm.c_str (), file.c_str (), l); - } - } - } - } - } - else - error ("rethrow: structure must contain the fields 'message and 'identifier'"); - } + if (err.contains ("stack")) + { + if (file.empty ()) + { + if (nm.empty ()) + { + if (l > 0) + { + if (c > 0) + pr_where_1 ("error: near line %d, column %d", + l, c); + else + pr_where_1 ("error: near line %d", l); + } + } + else + { + if (l > 0) + { + if (c > 0) + pr_where_1 ("error: called from `%s' near line %d, column %d", + nm.c_str (), l, c); + else + pr_where_1 ("error: called from `%d' near line %d", nm.c_str (), l); + } + } + } + else + { + if (nm.empty ()) + { + if (l > 0) + { + if (c > 0) + pr_where_1 ("error: in file %s near line %d, column %d", + file.c_str (), l, c); + else + pr_where_1 ("error: in file %s near line %d", file.c_str (), l); + } + } + else + { + if (l > 0) + { + if (c > 0) + pr_where_1 ("error: called from `%s' in file %s near line %d, column %d", + nm.c_str (), file.c_str (), l, c); + else + pr_where_1 ("error: called from `%d' in file %s near line %d", nm.c_str (), file.c_str (), l); + } + } + } + } + } + else + error ("rethrow: structure must contain the fields 'message and 'identifier'"); + } } return retval; } @@ -1055,53 +1055,53 @@ else { if (nargin > 1) - { - std::string arg1 = args(0).string_value (); + { + std::string arg1 = args(0).string_value (); - if (! error_state) - { - if (arg1.find ('%') == std::string::npos) - { - id = arg1; + if (! error_state) + { + if (arg1.find ('%') == std::string::npos) + { + id = arg1; - nargs.resize (nargin-1); + nargs.resize (nargin-1); - for (int i = 1; i < nargin; i++) - nargs(i-1) = args(i); - } - } - else - return retval; - } + for (int i = 1; i < nargin; i++) + nargs(i-1) = args(i); + } + } + else + return retval; + } else if (nargin == 1 && args(0).is_map ()) - { - octave_value_list tmp; + { + octave_value_list tmp; - Octave_map m = args(0).map_value (); + Octave_map m = args(0).map_value (); - if (m.numel () == 1) - { - if (m.contains ("message")) - { - Cell c = m.contents ("message"); + if (m.numel () == 1) + { + if (m.contains ("message")) + { + Cell c = m.contents ("message"); - if (! c.is_empty () && c(0).is_string ()) - nargs(0) = c(0).string_value (); - } + if (! c.is_empty () && c(0).is_string ()) + nargs(0) = c(0).string_value (); + } - if (m.contains ("identifier")) - { - Cell c = m.contents ("identifier"); + if (m.contains ("identifier")) + { + Cell c = m.contents ("identifier"); - if (! c.is_empty () && c(0).is_string ()) - id = c(0).string_value (); - } + if (! c.is_empty () && c(0).is_string ()) + id = c(0).string_value (); + } - // FIXME -- also need to handle "stack" field in error - // structure, but that will require some more significant - // surgery on handle_message, error_with_id, etc. - } - } + // FIXME -- also need to handle "stack" field in error + // structure, but that will require some more significant + // surgery on handle_message, error_with_id, etc. + } + } handle_message (error_with_id, id.c_str (), "unspecified error", nargs); } @@ -1149,230 +1149,230 @@ string_vector argv = args.make_argv ("warning"); if (! error_state) - { - std::string arg1 = argv(1); - std::string arg2 = "all"; + { + std::string arg1 = argv(1); + std::string arg2 = "all"; - if (argc == 3) - arg2 = argv(2); + if (argc == 3) + arg2 = argv(2); - if (arg1 == "on" || arg1 == "off" || arg1 == "error") - { - Octave_map old_warning_options = warning_options; + if (arg1 == "on" || arg1 == "off" || arg1 == "error") + { + Octave_map old_warning_options = warning_options; - if (arg2 == "all") - { - Octave_map tmp; + if (arg2 == "all") + { + Octave_map tmp; - Cell id (1, 1); - Cell st (1, 1); + Cell id (1, 1); + Cell st (1, 1); - id(0) = arg2; - st(0) = arg1; + id(0) = arg2; + st(0) = arg1; - // Since internal Octave functions are not - // compatible, turning all warnings into errors - // should leave the state of - // Octave:matlab-incompatible alone. + // Since internal Octave functions are not + // compatible, turning all warnings into errors + // should leave the state of + // Octave:matlab-incompatible alone. - if (arg1 == "error" - && warning_options.contains ("identifier")) - { - octave_idx_type n = 1; + if (arg1 == "error" + && warning_options.contains ("identifier")) + { + octave_idx_type n = 1; - Cell tid = warning_options.contents ("identifier"); - Cell tst = warning_options.contents ("state"); + Cell tid = warning_options.contents ("identifier"); + Cell tst = warning_options.contents ("state"); - for (octave_idx_type i = 0; i < tid.numel (); i++) - { - octave_value vid = tid(i); + for (octave_idx_type i = 0; i < tid.numel (); i++) + { + octave_value vid = tid(i); - if (vid.is_string ()) - { - std::string key = vid.string_value (); + if (vid.is_string ()) + { + std::string key = vid.string_value (); - if (key == "Octave:matlab-incompatible" - || key == "Octave:single-quote-string") - { - id.resize (dim_vector (1, n+1)); - st.resize (dim_vector (1, n+1)); + if (key == "Octave:matlab-incompatible" + || key == "Octave:single-quote-string") + { + id.resize (dim_vector (1, n+1)); + st.resize (dim_vector (1, n+1)); - id(n) = tid(i); - st(n) = tst(i); + id(n) = tid(i); + st(n) = tst(i); - n++; - } - } - } - } + n++; + } + } + } + } - tmp.assign ("identifier", id); - tmp.assign ("state", st); + tmp.assign ("identifier", id); + tmp.assign ("state", st); - warning_options = tmp; + warning_options = tmp; - done = true; - } - else if (arg2 == "backtrace") - { - if (arg1 != "error") - { - Vbacktrace_on_warning = (arg1 == "on"); - done = true; - } - } - else if (arg2 == "debug") - { - if (arg1 != "error") - { - Vdebug_on_warning = (arg1 == "on"); - done = true; - } - } - else if (arg2 == "verbose") - { - if (arg1 != "error") - { - Vverbose_warning = (arg1 == "on"); - done = true; - } - } - else if (arg2 == "quiet") - { - if (arg1 != "error") - { - Vquiet_warning = (arg1 == "on"); - done = true; - } - } - else - { - if (arg2 == "last") - arg2 = Vlast_warning_id; + done = true; + } + else if (arg2 == "backtrace") + { + if (arg1 != "error") + { + Vbacktrace_on_warning = (arg1 == "on"); + done = true; + } + } + else if (arg2 == "debug") + { + if (arg1 != "error") + { + Vdebug_on_warning = (arg1 == "on"); + done = true; + } + } + else if (arg2 == "verbose") + { + if (arg1 != "error") + { + Vverbose_warning = (arg1 == "on"); + done = true; + } + } + else if (arg2 == "quiet") + { + if (arg1 != "error") + { + Vquiet_warning = (arg1 == "on"); + done = true; + } + } + else + { + if (arg2 == "last") + arg2 = Vlast_warning_id; - if (arg2 == "all") - initialize_warning_options (arg1); - else - { - Cell ident = warning_options.contents ("identifier"); - Cell state = warning_options.contents ("state"); + if (arg2 == "all") + initialize_warning_options (arg1); + else + { + Cell ident = warning_options.contents ("identifier"); + Cell state = warning_options.contents ("state"); - octave_idx_type nel = ident.numel (); + octave_idx_type nel = ident.numel (); - bool found = false; + bool found = false; - for (octave_idx_type i = 0; i < nel; i++) - { - if (ident(i).string_value () == arg2) - { - // FIXME -- if state for "all" is - // same as arg1, we can simply remove the - // item from the list. + for (octave_idx_type i = 0; i < nel; i++) + { + if (ident(i).string_value () == arg2) + { + // FIXME -- if state for "all" is + // same as arg1, we can simply remove the + // item from the list. - state(i) = arg1; - warning_options.assign ("state", state); - found = true; - break; - } - } + state(i) = arg1; + warning_options.assign ("state", state); + found = true; + break; + } + } - if (! found) - { - // FIXME -- if state for "all" is - // same as arg1, we don't need to do anything. + if (! found) + { + // FIXME -- if state for "all" is + // same as arg1, we don't need to do anything. - ident.resize (dim_vector (1, nel+1)); - state.resize (dim_vector (1, nel+1)); + ident.resize (dim_vector (1, nel+1)); + state.resize (dim_vector (1, nel+1)); - ident(nel) = arg2; - state(nel) = arg1; + ident(nel) = arg2; + state(nel) = arg1; - warning_options.clear (); + warning_options.clear (); - warning_options.assign ("identifier", ident); - warning_options.assign ("state", state); - } - } + warning_options.assign ("identifier", ident); + warning_options.assign ("state", state); + } + } - done = true; - } + done = true; + } - if (done && nargout > 0) - retval = old_warning_options; - } - else if (arg1 == "query") - { - if (arg2 == "all") - retval = warning_options; - else if (arg2 == "backtrace" || arg2 == "debug" - || arg2 == "verbose" || arg2 == "quiet") - { - Octave_map tmp; - tmp.assign ("identifier", arg2); - if (arg2 == "backtrace") - tmp.assign ("state", Vbacktrace_on_warning ? "on" : "off"); - else if (arg2 == "debug") - tmp.assign ("state", Vdebug_on_warning ? "on" : "off"); - else if (arg2 == "verbose") - tmp.assign ("state", Vverbose_warning ? "on" : "off"); - else - tmp.assign ("state", Vquiet_warning ? "on" : "off"); + if (done && nargout > 0) + retval = old_warning_options; + } + else if (arg1 == "query") + { + if (arg2 == "all") + retval = warning_options; + else if (arg2 == "backtrace" || arg2 == "debug" + || arg2 == "verbose" || arg2 == "quiet") + { + Octave_map tmp; + tmp.assign ("identifier", arg2); + if (arg2 == "backtrace") + tmp.assign ("state", Vbacktrace_on_warning ? "on" : "off"); + else if (arg2 == "debug") + tmp.assign ("state", Vdebug_on_warning ? "on" : "off"); + else if (arg2 == "verbose") + tmp.assign ("state", Vverbose_warning ? "on" : "off"); + else + tmp.assign ("state", Vquiet_warning ? "on" : "off"); - retval = tmp; - } - else - { - if (arg2 == "last") - arg2 = Vlast_warning_id; + retval = tmp; + } + else + { + if (arg2 == "last") + arg2 = Vlast_warning_id; - Cell ident = warning_options.contents ("identifier"); - Cell state = warning_options.contents ("state"); + Cell ident = warning_options.contents ("identifier"); + Cell state = warning_options.contents ("state"); - octave_idx_type nel = ident.numel (); + octave_idx_type nel = ident.numel (); - bool found = false; - - std::string val; + bool found = false; + + std::string val; - for (octave_idx_type i = 0; i < nel; i++) - { - if (ident(i).string_value () == arg2) - { - val = state(i).string_value (); - found = true; - break; - } - } + for (octave_idx_type i = 0; i < nel; i++) + { + if (ident(i).string_value () == arg2) + { + val = state(i).string_value (); + found = true; + break; + } + } - if (! found) - { - for (octave_idx_type i = 0; i < nel; i++) - { - if (ident(i).string_value () == "all") - { - val = state(i).string_value (); - found = true; - break; - } - } - } + if (! found) + { + for (octave_idx_type i = 0; i < nel; i++) + { + if (ident(i).string_value () == "all") + { + val = state(i).string_value (); + found = true; + break; + } + } + } - if (found) - { - Octave_map tmp; + if (found) + { + Octave_map tmp; - tmp.assign ("identifier", arg2); - tmp.assign ("state", val); + tmp.assign ("identifier", arg2); + tmp.assign ("state", val); - retval = tmp; - } - else - error ("warning: unable to find default warning state!"); - } + retval = tmp; + } + else + error ("warning: unable to find default warning state!"); + } - done = true; - } - } + done = true; + } + } } else if (argc == 1) { @@ -1387,19 +1387,19 @@ Octave_map old_warning_options = warning_options; if (arg.is_map ()) - { - Octave_map m = arg.map_value (); + { + Octave_map m = arg.map_value (); - if (m.contains ("identifier") && m.contains ("state")) - warning_options = m; - else - error ("warning: expecting structure with fields `identifier' and `state'"); + if (m.contains ("identifier") && m.contains ("state")) + warning_options = m; + else + error ("warning: expecting structure with fields `identifier' and `state'"); - done = true; + done = true; - if (nargout > 0) - retval = old_warning_options; - } + if (nargout > 0) + retval = old_warning_options; + } } if (! (error_state || done)) @@ -1409,32 +1409,32 @@ std::string id; if (nargin > 1) - { - std::string arg1 = args(0).string_value (); + { + std::string arg1 = args(0).string_value (); - if (! error_state) - { - if (arg1.find ('%') == std::string::npos) - { - id = arg1; + if (! error_state) + { + if (arg1.find ('%') == std::string::npos) + { + id = arg1; - nargs.resize (nargin-1); + nargs.resize (nargin-1); - for (int i = 1; i < nargin; i++) - nargs(i-1) = args(i); - } - } - else - return retval; - } + for (int i = 1; i < nargin; i++) + nargs(i-1) = args(i); + } + } + else + return retval; + } std::string prev_msg = Vlast_warning_message; std::string curr_msg = handle_message (warning_with_id, id.c_str (), - "unspecified warning", nargs); + "unspecified warning", nargs); if (nargout > 0) - retval = prev_msg; + retval = prev_msg; } return retval; @@ -1537,94 +1537,94 @@ err.assign ("stack", octave_value (Vlast_error_stack)); if (nargin == 1) - { - if (args(0).is_string()) - { - if (args(0).string_value () == "reset") - { - Vlast_error_message = std::string(); - Vlast_error_id = std::string(); + { + if (args(0).is_string()) + { + if (args(0).string_value () == "reset") + { + Vlast_error_message = std::string(); + Vlast_error_id = std::string(); - Vlast_error_stack = initialize_last_error_stack (); - } - else - error("lasterror: unrecognized string argument"); - } - else if (args(0).is_map ()) - { - Octave_map new_err = args(0).map_value (); - std::string new_error_message; - std::string new_error_id; - std::string new_error_file; - std::string new_error_name; - int new_error_line = -1; - int new_error_column = -1; + Vlast_error_stack = initialize_last_error_stack (); + } + else + error("lasterror: unrecognized string argument"); + } + else if (args(0).is_map ()) + { + Octave_map new_err = args(0).map_value (); + std::string new_error_message; + std::string new_error_id; + std::string new_error_file; + std::string new_error_name; + int new_error_line = -1; + int new_error_column = -1; - if (! error_state && new_err.contains ("message")) - { - const std::string tmp = - new_err.contents("message")(0).string_value (); - new_error_message = tmp; - } + if (! error_state && new_err.contains ("message")) + { + const std::string tmp = + new_err.contents("message")(0).string_value (); + new_error_message = tmp; + } - if (! error_state && new_err.contains ("identifier")) - { - const std::string tmp = - new_err.contents("identifier")(0).string_value (); - new_error_id = tmp; - } + if (! error_state && new_err.contains ("identifier")) + { + const std::string tmp = + new_err.contents("identifier")(0).string_value (); + new_error_id = tmp; + } - if (! error_state && new_err.contains ("stack")) - { - Octave_map new_err_stack = - new_err.contents("identifier")(0).map_value (); + if (! error_state && new_err.contains ("stack")) + { + Octave_map new_err_stack = + new_err.contents("identifier")(0).map_value (); - if (! error_state && new_err_stack.contains ("file")) - { - const std::string tmp = - new_err_stack.contents("file")(0).string_value (); - new_error_file = tmp; - } + if (! error_state && new_err_stack.contains ("file")) + { + const std::string tmp = + new_err_stack.contents("file")(0).string_value (); + new_error_file = tmp; + } - if (! error_state && new_err_stack.contains ("name")) - { - const std::string tmp = - new_err_stack.contents("name")(0).string_value (); - new_error_name = tmp; - } + if (! error_state && new_err_stack.contains ("name")) + { + const std::string tmp = + new_err_stack.contents("name")(0).string_value (); + new_error_name = tmp; + } - if (! error_state && new_err_stack.contains ("line")) - { - const int tmp = - new_err_stack.contents("line")(0).nint_value (); - new_error_line = tmp; - } - - if (! error_state && new_err_stack.contains ("column")) - { - const int tmp = - new_err_stack.contents("column")(0).nint_value (); - new_error_column = tmp; - } - } + if (! error_state && new_err_stack.contains ("line")) + { + const int tmp = + new_err_stack.contents("line")(0).nint_value (); + new_error_line = tmp; + } + + if (! error_state && new_err_stack.contains ("column")) + { + const int tmp = + new_err_stack.contents("column")(0).nint_value (); + new_error_column = tmp; + } + } - if (! error_state) - { - Vlast_error_message = new_error_message; - Vlast_error_id = new_error_id; + if (! error_state) + { + Vlast_error_message = new_error_message; + Vlast_error_id = new_error_id; - octave_idx_type curr_frame = -1; + octave_idx_type curr_frame = -1; - Vlast_error_stack - = octave_call_stack::backtrace (0, curr_frame); - } - } - else - error ("lasterror: argument must be a structure or a string"); - } + Vlast_error_stack + = octave_call_stack::backtrace (0, curr_frame); + } + } + else + error ("lasterror: argument must be a structure or a string"); + } if (! error_state) - retval = err; + retval = err; } else print_usage (); @@ -1654,24 +1654,24 @@ string_vector argv = args.make_argv ("lasterr"); if (! error_state) - { - std::string prev_error_id = Vlast_error_id; - std::string prev_error_message = Vlast_error_message; + { + std::string prev_error_id = Vlast_error_id; + std::string prev_error_message = Vlast_error_message; - if (argc > 2) - Vlast_error_id = argv(2); + if (argc > 2) + Vlast_error_id = argv(2); - if (argc > 1) - Vlast_error_message = argv(1); + if (argc > 1) + Vlast_error_message = argv(1); - if (argc == 1 || nargout > 0) - { - retval(1) = prev_error_id; - retval(0) = prev_error_message; - } - } + if (argc == 1 || nargout > 0) + { + retval(1) = prev_error_id; + retval(0) = prev_error_message; + } + } else - error ("lasterr: expecting arguments to be character strings"); + error ("lasterr: expecting arguments to be character strings"); } else print_usage (); @@ -1700,25 +1700,25 @@ string_vector argv = args.make_argv ("lastwarn"); if (! error_state) - { - std::string prev_warning_id = Vlast_warning_id; - std::string prev_warning_message = Vlast_warning_message; + { + std::string prev_warning_id = Vlast_warning_id; + std::string prev_warning_message = Vlast_warning_message; - if (argc > 2) - Vlast_warning_id = argv(2); + if (argc > 2) + Vlast_warning_id = argv(2); - if (argc > 1) - Vlast_warning_message = argv(1); + if (argc > 1) + Vlast_warning_message = argv(1); - if (argc == 1 || nargout > 0) - { - warning_state = 0; - retval(1) = prev_warning_id; - retval(0) = prev_warning_message; - } - } + if (argc == 1 || nargout > 0) + { + warning_state = 0; + retval(1) = prev_warning_id; + retval(0) = prev_warning_message; + } + } else - error ("lastwarn: expecting arguments to be character strings"); + error ("lastwarn: expecting arguments to be character strings"); } else print_usage (); diff --git a/src/file-io.cc b/src/file-io.cc --- a/src/file-io.cc +++ b/src/file-io.cc @@ -148,61 +148,61 @@ size_t pos = mode.find ('W'); if (pos != std::string::npos) - { - warning ("fopen: treating mode \"W\" as equivalent to \"w\""); - mode[pos] = 'w'; - } + { + warning ("fopen: treating mode \"W\" as equivalent to \"w\""); + mode[pos] = 'w'; + } pos = mode.find ('R'); if (pos != std::string::npos) - { - warning ("fopen: treating mode \"R\" as equivalent to \"r\""); - mode[pos] = 'r'; - } + { + warning ("fopen: treating mode \"R\" as equivalent to \"r\""); + mode[pos] = 'r'; + } pos = mode.find ('z'); if (pos != std::string::npos) - { + { #if defined (HAVE_ZLIB) - mode.erase (pos, 1); + mode.erase (pos, 1); #else - error ("this version of Octave does not support gzipped files"); + error ("this version of Octave does not support gzipped files"); #endif - } + } if (! error_state) - { - if (mode == "rt") - retval = std::ios::in; - else if (mode == "wt") - retval = std::ios::out | std::ios::trunc; - else if (mode == "at") - retval = std::ios::out | std::ios::app; - else if (mode == "r+t" || mode == "rt+") - retval = std::ios::in | std::ios::out; - else if (mode == "w+t" || mode == "wt+") - retval = std::ios::in | std::ios::out | std::ios::trunc; - else if (mode == "a+t" || mode == "at+") - retval = std::ios::in | std::ios::out | std::ios::app; - else if (mode == "rb" || mode == "r") - retval = std::ios::in | std::ios::binary; - else if (mode == "wb" || mode == "w") - retval = std::ios::out | std::ios::trunc | std::ios::binary; - else if (mode == "ab" || mode == "a") - retval = std::ios::out | std::ios::app | std::ios::binary; - else if (mode == "r+b" || mode == "rb+" || mode == "r+") - retval = std::ios::in | std::ios::out | std::ios::binary; - else if (mode == "w+b" || mode == "wb+" || mode == "w+") - retval = (std::ios::in | std::ios::out | std::ios::trunc - | std::ios::binary); - else if (mode == "a+b" || mode == "ab+" || mode == "a+") - retval = (std::ios::in | std::ios::out | std::ios::app - | std::ios::binary); - else - ::error ("invalid mode specified"); - } + { + if (mode == "rt") + retval = std::ios::in; + else if (mode == "wt") + retval = std::ios::out | std::ios::trunc; + else if (mode == "at") + retval = std::ios::out | std::ios::app; + else if (mode == "r+t" || mode == "rt+") + retval = std::ios::in | std::ios::out; + else if (mode == "w+t" || mode == "wt+") + retval = std::ios::in | std::ios::out | std::ios::trunc; + else if (mode == "a+t" || mode == "at+") + retval = std::ios::in | std::ios::out | std::ios::app; + else if (mode == "rb" || mode == "r") + retval = std::ios::in | std::ios::binary; + else if (mode == "wb" || mode == "w") + retval = std::ios::out | std::ios::trunc | std::ios::binary; + else if (mode == "ab" || mode == "a") + retval = std::ios::out | std::ios::app | std::ios::binary; + else if (mode == "r+b" || mode == "rb+" || mode == "r+") + retval = std::ios::in | std::ios::out | std::ios::binary; + else if (mode == "w+b" || mode == "wb+" || mode == "w+") + retval = (std::ios::in | std::ios::out | std::ios::trunc + | std::ios::binary); + else if (mode == "a+b" || mode == "ab+" || mode == "a+") + retval = (std::ios::in | std::ios::out | std::ios::app + | std::ios::binary); + else + ::error ("invalid mode specified"); + } } return retval; @@ -245,7 +245,7 @@ octave_stream os = octave_stream_list::lookup (fid, "fclear"); if (! error_state) - os.clearerr (); + os.clearerr (); } else print_usage (); @@ -277,18 +277,18 @@ int fid = octave_stream_list::get_file_number (args (0)); if (fid == 1) - { - flush_octave_stdout (); + { + flush_octave_stdout (); - retval = 0; - } + retval = 0; + } else - { - octave_stream os = octave_stream_list::lookup (fid, "fflush"); + { + octave_stream os = octave_stream_list::lookup (fid, "fflush"); - if (! error_state) - retval = os.flush (); - } + if (! error_state) + retval = os.flush (); + } } else print_usage (); @@ -324,19 +324,19 @@ octave_stream os = octave_stream_list::lookup (args(0), who); if (! error_state) - { - octave_value len_arg = (nargin == 2) ? args(1) : octave_value (); + { + octave_value len_arg = (nargin == 2) ? args(1) : octave_value (); - bool err = false; + bool err = false; - std::string tmp = os.getl (len_arg, err, who); + std::string tmp = os.getl (len_arg, err, who); - if (! (error_state || err)) - { - retval(1) = tmp.length (); - retval(0) = tmp; - } - } + if (! (error_state || err)) + { + retval(1) = tmp.length (); + retval(0) = tmp; + } + } } else print_usage (); @@ -372,19 +372,19 @@ octave_stream os = octave_stream_list::lookup (args(0), who); if (! error_state) - { - octave_value len_arg = (nargin == 2) ? args(1) : octave_value (); + { + octave_value len_arg = (nargin == 2) ? args(1) : octave_value (); - bool err = false; + bool err = false; - std::string tmp = os.gets (len_arg, err, who); + std::string tmp = os.gets (len_arg, err, who); - if (! (error_state || err)) - { - retval(1) = tmp.length (); - retval(0) = tmp; - } - } + if (! (error_state || err)) + { + retval(1) = tmp.length (); + retval(0) = tmp; + } + } } else print_usage (); @@ -415,16 +415,16 @@ octave_stream os = octave_stream_list::lookup (args(0), who); if (! error_state) - { - octave_value count_arg = (nargin == 2) ? args(1) : octave_value (); + { + octave_value count_arg = (nargin == 2) ? args(1) : octave_value (); - bool err = false; + bool err = false; - long tmp = os.skipl (count_arg, err, who); + long tmp = os.skipl (count_arg, err, who); - if (! (error_state || err)) + if (! (error_state || err)) retval = tmp; - } + } } else print_usage (); @@ -435,7 +435,7 @@ static octave_stream do_stream_open (const std::string& name, const std::string& mode, - const std::string& arch, int& fid) + const std::string& arch, int& fid) { octave_stream retval; @@ -446,78 +446,78 @@ if (! error_state) { oct_mach_info::float_format flt_fmt = - oct_mach_info::string_to_float_format (arch); + oct_mach_info::string_to_float_format (arch); if (! error_state) - { - std::string fname = file_ops::tilde_expand (name); + { + std::string fname = file_ops::tilde_expand (name); - file_stat fs (fname); + file_stat fs (fname); - if (! (md & std::ios::out - || octave_env::absolute_pathname (fname) - || octave_env::rooted_relative_pathname (fname))) - { - if (! fs.exists ()) - { - std::string tmp + if (! (md & std::ios::out + || octave_env::absolute_pathname (fname) + || octave_env::rooted_relative_pathname (fname))) + { + if (! fs.exists ()) + { + std::string tmp = octave_env::make_absolute (load_path::find_file (fname)); - if (! tmp.empty ()) - { - warning_with_id ("Octave:fopen-file-in-path", - "fopen: file found in load path"); - fname = tmp; - } - } - } - - if (! fs.is_dir ()) - { - std::string tmode = mode; + if (! tmp.empty ()) + { + warning_with_id ("Octave:fopen-file-in-path", + "fopen: file found in load path"); + fname = tmp; + } + } + } + + if (! fs.is_dir ()) + { + std::string tmode = mode; - // Use binary mode if 't' is not specified, but don't add - // 'b' if it is already present. + // Use binary mode if 't' is not specified, but don't add + // 'b' if it is already present. - size_t bpos = tmode.find ('b'); - size_t tpos = tmode.find ('t'); + size_t bpos = tmode.find ('b'); + size_t tpos = tmode.find ('t'); - if (bpos == std::string::npos && tpos == std::string::npos) - tmode += 'b'; + if (bpos == std::string::npos && tpos == std::string::npos) + tmode += 'b'; #if defined (HAVE_ZLIB) - size_t pos = tmode.find ('z'); + size_t pos = tmode.find ('z'); - if (pos != std::string::npos) - { - tmode.erase (pos, 1); + if (pos != std::string::npos) + { + tmode.erase (pos, 1); - gzFile fptr = ::gzopen (fname.c_str (), tmode.c_str ()); + gzFile fptr = ::gzopen (fname.c_str (), tmode.c_str ()); - if (fptr) - retval = octave_zstdiostream::create (fname, fptr, md, flt_fmt); - else - { - using namespace std; - retval.error (::strerror (errno)); - } - } - else + if (fptr) + retval = octave_zstdiostream::create (fname, fptr, md, flt_fmt); + else + { + using namespace std; + retval.error (::strerror (errno)); + } + } + else #endif - { - FILE *fptr = ::fopen (fname.c_str (), tmode.c_str ()); + { + FILE *fptr = ::fopen (fname.c_str (), tmode.c_str ()); - retval = octave_stdiostream::create (fname, fptr, md, flt_fmt); + retval = octave_stdiostream::create (fname, fptr, md, flt_fmt); - if (! fptr) - { - using namespace std; - retval.error (::strerror (errno)); - } - } + if (! fptr) + { + using namespace std; + retval.error (::strerror (errno)); + } + } - } - } + } + } } return retval; @@ -525,7 +525,7 @@ static octave_stream do_stream_open (const octave_value& tc_name, const octave_value& tc_mode, - const octave_value& tc_arch, const char *fcn, int& fid) + const octave_value& tc_arch, const char *fcn, int& fid) { octave_stream retval; @@ -538,16 +538,16 @@ std::string mode = tc_mode.string_value (); if (! error_state) - { - std::string arch = tc_arch.string_value (); + { + std::string arch = tc_arch.string_value (); - if (! error_state) - retval = do_stream_open (name, mode, arch, fid); - else - ::error ("%s: architecture type must be a string", fcn); - } + if (! error_state) + retval = do_stream_open (name, mode, arch, fid); + else + ::error ("%s: architecture type must be a string", fcn); + } else - ::error ("%s: file mode must be a string", fcn); + ::error ("%s: file mode must be a string", fcn); } else ::error ("%s: file name must be a string", fcn); @@ -666,54 +666,54 @@ if (nargin == 1) { if (args(0).is_string ()) - { - // If there is only one argument and it is a string but it - // is not the string "all", we assume it is a file to open - // with MODE = "r". To open a file called "all", you have - // to supply more than one argument. + { + // If there is only one argument and it is a string but it + // is not the string "all", we assume it is a file to open + // with MODE = "r". To open a file called "all", you have + // to supply more than one argument. - if (args(0).string_value () == "all") - return octave_stream_list::open_file_numbers (); - } + if (args(0).string_value () == "all") + return octave_stream_list::open_file_numbers (); + } else - { - string_vector tmp = octave_stream_list::get_info (args(0)); + { + string_vector tmp = octave_stream_list::get_info (args(0)); - if (! error_state) - { - retval(2) = tmp(2); - retval(1) = tmp(1); - retval(0) = tmp(0); - } + if (! error_state) + { + retval(2) = tmp(2); + retval(1) = tmp(1); + retval(0) = tmp(0); + } - return retval; - } + return retval; + } } if (nargin > 0 && nargin < 4) { octave_value mode = (nargin == 2 || nargin == 3) - ? args(1) : octave_value ("r"); + ? args(1) : octave_value ("r"); octave_value arch = (nargin == 3) - ? args(2) : octave_value ("native"); + ? args(2) : octave_value ("native"); int fid = -1; octave_stream os = do_stream_open (args(0), mode, arch, "fopen", fid); if (os && ! error_state) - { - retval(1) = ""; - retval(0) = octave_stream_list::insert (os); - } + { + retval(1) = ""; + retval(0) = octave_stream_list::insert (os); + } else - { - int error_number = 0; + { + int error_number = 0; - retval(1) = os.error (false, error_number); - retval(0) = -1.0; - } + retval(1) = os.error (false, error_number); + retval(0) = -1.0; + } } else print_usage (); @@ -772,7 +772,7 @@ octave_stream os = octave_stream_list::lookup (args(0), "frewind"); if (! error_state) - result = os.rewind (); + result = os.rewind (); } else print_usage (); @@ -808,12 +808,12 @@ octave_stream os = octave_stream_list::lookup (args(0), "fseek"); if (! error_state) - { - octave_value origin_arg = (nargin == 3) - ? args(2) : octave_value (-1.0); + { + octave_value origin_arg = (nargin == 3) + ? args(2) : octave_value (-1.0); - retval = os.seek (args(1), origin_arg); - } + retval = os.seek (args(1), origin_arg); + } } else print_usage (); @@ -838,7 +838,7 @@ octave_stream os = octave_stream_list::lookup (args(0), "ftell"); if (! error_state) - retval = os.tell (); + retval = os.tell (); } else print_usage (); @@ -869,34 +869,34 @@ int fmt_n = 0; if (args(0).is_string ()) - { - os = octave_stream_list::lookup (1, who); - } + { + os = octave_stream_list::lookup (1, who); + } else - { - fmt_n = 1; - os = octave_stream_list::lookup (args(0), who); - } + { + fmt_n = 1; + os = octave_stream_list::lookup (args(0), who); + } if (! error_state) - { - if (args(fmt_n).is_string ()) - { - octave_value_list tmp_args; + { + if (args(fmt_n).is_string ()) + { + octave_value_list tmp_args; - if (nargin > 1 + fmt_n) - { - tmp_args.resize (nargin-fmt_n-1, octave_value ()); + if (nargin > 1 + fmt_n) + { + tmp_args.resize (nargin-fmt_n-1, octave_value ()); - for (int i = fmt_n + 1; i < nargin; i++) - tmp_args(i-fmt_n-1) = args(i); - } + for (int i = fmt_n + 1; i < nargin; i++) + tmp_args(i-fmt_n-1) = args(i); + } - result = os.printf (args(fmt_n), tmp_args, who); - } - else - ::error ("%s: format must be a string", who.c_str ()); - } + result = os.printf (args(fmt_n), tmp_args, who); + } + else + ::error ("%s: format must be a string", who.c_str ()); + } } else print_usage (); @@ -932,21 +932,21 @@ if (nargin > 0) { if (args(0).is_string ()) - { - octave_value_list tmp_args; + { + octave_value_list tmp_args; - if (nargin > 1) - { - tmp_args.resize (nargin-1, octave_value ()); + if (nargin > 1) + { + tmp_args.resize (nargin-1, octave_value ()); - for (int i = 1; i < nargin; i++) - tmp_args(i-1) = args(i); - } + for (int i = 1; i < nargin; i++) + tmp_args(i-1) = args(i); + } - result = stdout_stream.printf (args(0), tmp_args, who); - } + result = stdout_stream.printf (args(0), tmp_args, who); + } else - ::error ("%s: format must be a string", who.c_str ()); + ::error ("%s: format must be a string", who.c_str ()); } else print_usage (); @@ -977,7 +977,7 @@ octave_stream os = octave_stream_list::lookup (args(0), who); if (! error_state) - retval = os.puts (args(1), who); + retval = os.puts (args(1), who); } else print_usage (); @@ -1033,31 +1033,31 @@ octave_stream os (ostr); if (os.is_valid ()) - { - octave_value fmt_arg = args(0); + { + octave_value fmt_arg = args(0); - if (fmt_arg.is_string ()) - { - octave_value_list tmp_args; + if (fmt_arg.is_string ()) + { + octave_value_list tmp_args; - if (nargin > 1) - { - tmp_args.resize (nargin-1, octave_value ()); + if (nargin > 1) + { + tmp_args.resize (nargin-1, octave_value ()); - for (int i = 1; i < nargin; i++) - tmp_args(i-1) = args(i); - } + for (int i = 1; i < nargin; i++) + tmp_args(i-1) = args(i); + } - retval(2) = os.printf (fmt_arg, tmp_args, who); - retval(1) = os.error (); - retval(0) = octave_value (ostr->str (), - fmt_arg.is_sq_string () ? '\'' : '"'); - } - else - ::error ("%s: format must be a string", who.c_str ()); - } + retval(2) = os.printf (fmt_arg, tmp_args, who); + retval(1) = os.error (); + retval(0) = octave_value (ostr->str (), + fmt_arg.is_sq_string () ? '\'' : '"'); + } + else + ::error ("%s: format must be a string", who.c_str ()); + } else - ::error ("%s: unable to create output buffer", who.c_str ()); + ::error ("%s: unable to create output buffer", who.c_str ()); } else print_usage (); @@ -1125,12 +1125,12 @@ octave_stream os = octave_stream_list::lookup (args(0), who); if (! error_state) - { - if (args(1).is_string ()) - retval = os.oscanf (args(1), who); - else - ::error ("%s: format must be a string", who.c_str ()); - } + { + if (args(1).is_string ()) + retval = os.oscanf (args(1), who); + else + ::error ("%s: format must be a string", who.c_str ()); + } } else { @@ -1138,36 +1138,36 @@ retval (0) = Matrix (); if (nargin == 2 || nargin == 3) - { - octave_stream os = octave_stream_list::lookup (args(0), who); + { + octave_stream os = octave_stream_list::lookup (args(0), who); - if (! error_state) - { - if (args(1).is_string ()) - { - octave_idx_type count = 0; + if (! error_state) + { + if (args(1).is_string ()) + { + octave_idx_type count = 0; - Array size = (nargin == 3) - ? args(2).vector_value () - : Array (1, lo_ieee_inf_value ()); + Array size = (nargin == 3) + ? args(2).vector_value () + : Array (1, lo_ieee_inf_value ()); - if (! error_state) - { - octave_value tmp = os.scanf (args(1), size, count, who); + if (! error_state) + { + octave_value tmp = os.scanf (args(1), size, count, who); - if (! error_state) - { - retval(1) = count; - retval(0) = tmp; - } - } - } - else - ::error ("%s: format must be a string", who.c_str ()); - } - } + if (! error_state) + { + retval(1) = count; + retval(0) = tmp; + } + } + } + else + ::error ("%s: format must be a string", who.c_str ()); + } + } else - print_usage (); + print_usage (); } return retval; @@ -1192,77 +1192,77 @@ if (nargin == 3 && args(2).is_string ()) { if (args(0).is_string ()) - { - std::string data = args(0).string_value (); + { + std::string data = args(0).string_value (); - octave_stream os = octave_istrstream::create (data); + octave_stream os = octave_istrstream::create (data); - if (os.is_valid ()) - { - if (args(1).is_string ()) - retval = os.oscanf (args(1), who); - else - ::error ("%s: format must be a string", who.c_str ()); - } - else - ::error ("%s: unable to create temporary input buffer", - who.c_str ()); - } + if (os.is_valid ()) + { + if (args(1).is_string ()) + retval = os.oscanf (args(1), who); + else + ::error ("%s: format must be a string", who.c_str ()); + } + else + ::error ("%s: unable to create temporary input buffer", + who.c_str ()); + } else - ::error ("%s: first argument must be a string", who.c_str ()); + ::error ("%s: first argument must be a string", who.c_str ()); } else { if (nargin == 2 || nargin == 3) - { - retval(3) = -1.0; - retval(2) = "unknown error"; - retval(1) = 0.0; - retval(0) = Matrix (); + { + retval(3) = -1.0; + retval(2) = "unknown error"; + retval(1) = 0.0; + retval(0) = Matrix (); - if (args(0).is_string ()) - { - std::string data = args(0).string_value (); + if (args(0).is_string ()) + { + std::string data = args(0).string_value (); - octave_stream os = octave_istrstream::create (data); + octave_stream os = octave_istrstream::create (data); - if (os.is_valid ()) - { - if (args(1).is_string ()) - { - octave_idx_type count = 0; + if (os.is_valid ()) + { + if (args(1).is_string ()) + { + octave_idx_type count = 0; - Array size = (nargin == 3) - ? args(2).vector_value () - : Array (1, lo_ieee_inf_value ()); + Array size = (nargin == 3) + ? args(2).vector_value () + : Array (1, lo_ieee_inf_value ()); - octave_value tmp = os.scanf (args(1), size, count, who); + octave_value tmp = os.scanf (args(1), size, count, who); - if (! error_state) - { - // FIXME -- is this the right thing to do? - // Extract error message first, because getting - // position will clear it. - std::string errmsg = os.error (); + if (! error_state) + { + // FIXME -- is this the right thing to do? + // Extract error message first, because getting + // position will clear it. + std::string errmsg = os.error (); - retval(3) = os.tell () + 1; - retval(2) = errmsg; - retval(1) = count; - retval(0) = tmp; - } - } - else - ::error ("%s: format must be a string", who.c_str ()); - } - else - ::error ("%s: unable to create temporary input buffer", - who.c_str ()); - } - else - ::error ("%s: first argument must be a string", who.c_str ()); - } + retval(3) = os.tell () + 1; + retval(2) = errmsg; + retval(1) = count; + retval(0) = tmp; + } + } + else + ::error ("%s: format must be a string", who.c_str ()); + } + else + ::error ("%s: unable to create temporary input buffer", + who.c_str ()); + } + else + ::error ("%s: first argument must be a string", who.c_str ()); + } else - print_usage (); + print_usage (); } return retval; @@ -1292,8 +1292,8 @@ static octave_value do_fread (octave_stream& os, const octave_value& size_arg, - const octave_value& prec_arg, const octave_value& skip_arg, - const octave_value& arch_arg, octave_idx_type& count) + const octave_value& prec_arg, const octave_value& skip_arg, + const octave_value& arch_arg, octave_idx_type& count) { octave_value retval; @@ -1306,42 +1306,42 @@ std::string prec = prec_arg.string_value (); if (! error_state) - { - int block_size = 1; - oct_data_conv::data_type input_type; - oct_data_conv::data_type output_type; + { + int block_size = 1; + oct_data_conv::data_type input_type; + oct_data_conv::data_type output_type; - oct_data_conv::string_to_data_type (prec, block_size, - input_type, output_type); + oct_data_conv::string_to_data_type (prec, block_size, + input_type, output_type); - if (! error_state) - { - int skip = skip_arg.int_value (true); + if (! error_state) + { + int skip = skip_arg.int_value (true); - if (! error_state) - { - std::string arch = arch_arg.string_value (); + if (! error_state) + { + std::string arch = arch_arg.string_value (); - if (! error_state) - { - oct_mach_info::float_format flt_fmt - = oct_mach_info::string_to_float_format (arch); + if (! error_state) + { + oct_mach_info::float_format flt_fmt + = oct_mach_info::string_to_float_format (arch); - if (! error_state) - retval = os.read (size, block_size, input_type, - output_type, skip, flt_fmt, count); - } - else - ::error ("fread: architecture type must be a string"); - } - else - ::error ("fread: skip must be an integer"); - } - else - ::error ("fread: invalid data type specified"); - } + if (! error_state) + retval = os.read (size, block_size, input_type, + output_type, skip, flt_fmt, count); + } + else + ::error ("fread: architecture type must be a string"); + } + else + ::error ("fread: skip must be an integer"); + } + else + ::error ("fread: invalid data type specified"); + } else - ::error ("fread: precision must be a string"); + ::error ("fread: precision must be a string"); } else ::error ("fread: invalid size specified"); @@ -1536,38 +1536,38 @@ octave_stream os = octave_stream_list::lookup (args(0), "fread"); if (! error_state) - { - octave_value size = lo_ieee_inf_value (); - octave_value prec = "uchar"; - octave_value skip = 0; - octave_value arch = "unknown"; + { + octave_value size = lo_ieee_inf_value (); + octave_value prec = "uchar"; + octave_value skip = 0; + octave_value arch = "unknown"; - int idx = 1; + int idx = 1; - if (nargin > idx && ! args(idx).is_string ()) - size = args(idx++); + if (nargin > idx && ! args(idx).is_string ()) + size = args(idx++); - if (nargin > idx) - prec = args(idx++); + if (nargin > idx) + prec = args(idx++); - if (nargin > idx) - skip = args(idx++); + if (nargin > idx) + skip = args(idx++); - if (nargin > idx) - arch = args(idx++); - else if (skip.is_string ()) - { - arch = skip; - skip = 0; - } + if (nargin > idx) + arch = args(idx++); + else if (skip.is_string ()) + { + arch = skip; + skip = 0; + } - octave_idx_type count = -1; + octave_idx_type count = -1; - octave_value tmp = do_fread (os, size, prec, skip, arch, count); + octave_value tmp = do_fread (os, size, prec, skip, arch, count); - retval(1) = count; - retval(0) = tmp; - } + retval(1) = count; + retval(0) = tmp; + } } else print_usage (); @@ -1577,8 +1577,8 @@ static int do_fwrite (octave_stream& os, const octave_value& data, - const octave_value& prec_arg, const octave_value& skip_arg, - const octave_value& arch_arg) + const octave_value& prec_arg, const octave_value& skip_arg, + const octave_value& arch_arg) { int retval = -1; @@ -1592,30 +1592,30 @@ oct_data_conv::string_to_data_type (prec, block_size, output_type); if (! error_state) - { - int skip = skip_arg.int_value (true); + { + int skip = skip_arg.int_value (true); - if (! error_state) - { - std::string arch = arch_arg.string_value (); + if (! error_state) + { + std::string arch = arch_arg.string_value (); - if (! error_state) - { - oct_mach_info::float_format flt_fmt - = oct_mach_info::string_to_float_format (arch); + if (! error_state) + { + oct_mach_info::float_format flt_fmt + = oct_mach_info::string_to_float_format (arch); - if (! error_state) - retval = os.write (data, block_size, output_type, - skip, flt_fmt); - } - else - ::error ("fwrite: architecture type must be a string"); - } - else - ::error ("fwrite: skip must be an integer"); - } + if (! error_state) + retval = os.write (data, block_size, output_type, + skip, flt_fmt); + } + else + ::error ("fwrite: architecture type must be a string"); + } + else + ::error ("fwrite: skip must be an integer"); + } else - ::error ("fwrite: invalid precision specified"); + ::error ("fwrite: invalid precision specified"); } else ::error ("fwrite: precision must be a string"); @@ -1650,33 +1650,33 @@ octave_stream os = octave_stream_list::lookup (args(0), "fwrite"); if (! error_state) - { - octave_value prec = "uchar"; - octave_value skip = 0; - octave_value arch = "unknown"; + { + octave_value prec = "uchar"; + octave_value skip = 0; + octave_value arch = "unknown"; - int idx = 1; + int idx = 1; - octave_value data = args(idx++); + octave_value data = args(idx++); - if (nargin > idx) - prec = args(idx++); + if (nargin > idx) + prec = args(idx++); - if (nargin > idx) - skip = args(idx++); + if (nargin > idx) + skip = args(idx++); - if (nargin > idx) - arch = args(idx++); - else if (skip.is_string ()) - { - arch = skip; - skip = 0; - } + if (nargin > idx) + arch = args(idx++); + else if (skip.is_string ()) + { + arch = skip; + skip = 0; + } - double status = do_fwrite (os, data, prec, skip, arch); + double status = do_fwrite (os, data, prec, skip, arch); - retval = status; - } + retval = status; + } } else print_usage (); @@ -1703,7 +1703,7 @@ octave_stream os = octave_stream_list::lookup (args(0), "feof"); if (! error_state) - retval = os.eof () ? 1.0 : 0.0; + retval = os.eof () ? 1.0 : 0.0; } else print_usage (); @@ -1732,26 +1732,26 @@ octave_stream os = octave_stream_list::lookup (args(0), "ferror"); if (! error_state) - { - bool clear = false; + { + bool clear = false; - if (nargin == 2) - { - std::string opt = args(1).string_value (); + if (nargin == 2) + { + std::string opt = args(1).string_value (); - if (! error_state) - clear = (opt == "clear"); - else - return retval; - } + if (! error_state) + clear = (opt == "clear"); + else + return retval; + } - int error_number = 0; + int error_number = 0; - std::string error_message = os.error (clear, error_number); + std::string error_message = os.error (clear, error_number); - retval(1) = error_number; - retval(0) = error_message; - } + retval(1) = error_number; + retval(0) = error_message; + } } else print_usage (); @@ -1801,31 +1801,31 @@ std::string name = args(0).string_value (); if (! error_state) - { - std::string mode = args(1).string_value (); + { + std::string mode = args(1).string_value (); - if (! error_state) - { - if (mode == "r") - { - octave_stream ips = octave_iprocstream::create (name); + if (! error_state) + { + if (mode == "r") + { + octave_stream ips = octave_iprocstream::create (name); - retval = octave_stream_list::insert (ips); - } - else if (mode == "w") - { - octave_stream ops = octave_oprocstream::create (name); + retval = octave_stream_list::insert (ips); + } + else if (mode == "w") + { + octave_stream ops = octave_oprocstream::create (name); - retval = octave_stream_list::insert (ops); - } - else - ::error ("popen: invalid mode specified"); - } - else - ::error ("popen: mode must be a string"); - } + retval = octave_stream_list::insert (ops); + } + else + ::error ("popen: invalid mode specified"); + } + else + ::error ("popen: mode must be a string"); + } else - ::error ("popen: name must be a string"); + ::error ("popen: name must be a string"); } else print_usage (); @@ -1875,17 +1875,17 @@ std::string dir = len > 0 ? args(0).string_value () : std::string (); if (! error_state) - { - std::string pfx - = len > 1 ? args(1).string_value () : std::string ("oct-"); + { + std::string pfx + = len > 1 ? args(1).string_value () : std::string ("oct-"); - if (! error_state) - retval = octave_tempnam (dir, pfx); - else - ::error ("expecting second argument to be a string"); - } + if (! error_state) + retval = octave_tempnam (dir, pfx); + else + ::error ("expecting second argument to be a string"); + } else - ::error ("expecting first argument to be a string"); + ::error ("expecting first argument to be a string"); } else print_usage (); @@ -1921,25 +1921,25 @@ FILE *fid = tmpfile (); if (fid) - { - std::string nm; + { + std::string nm; - std::ios::openmode md = fopen_mode_to_ios_mode ("w+b"); + std::ios::openmode md = fopen_mode_to_ios_mode ("w+b"); - octave_stream s = octave_stdiostream::create (nm, fid, md); + octave_stream s = octave_stdiostream::create (nm, fid, md); - if (s) - retval(0) = octave_stream_list::insert (s); - else - error ("tmpfile: failed to create octave_stdiostream object"); + if (s) + retval(0) = octave_stream_list::insert (s); + else + error ("tmpfile: failed to create octave_stdiostream object"); - } + } else - { - using namespace std; - retval(1) = ::strerror (errno); - retval(0) = -1; - } + { + using namespace std; + retval(1) = ::strerror (errno); + retval(0) = -1; + } } else print_usage (); @@ -1960,7 +1960,7 @@ int ret=-1; mktemp (tmpl); ret = open (tmpl, O_RDWR | O_BINARY | O_CREAT | O_EXCL | _O_SHORT_LIVED, - _S_IREAD | _S_IWRITE); + _S_IREAD | _S_IWRITE); return ret; } #define HAVE_MKSTEMP 1 @@ -2003,57 +2003,57 @@ std::string tmpl8 = args(0).string_value (); if (! error_state) - { - OCTAVE_LOCAL_BUFFER (char, tmp, tmpl8.size () + 1); - strcpy (tmp, tmpl8.c_str ()); + { + OCTAVE_LOCAL_BUFFER (char, tmp, tmpl8.size () + 1); + strcpy (tmp, tmpl8.c_str ()); #if defined (HAVE_MKSTEMP) - int fd = mkstemp (tmp); + int fd = mkstemp (tmp); #else - int fd = mkstemps (tmp, 0); + int fd = mkstemps (tmp, 0); #endif - if (fd < 0) - { - using namespace std; - retval(2) = ::strerror (errno); - retval(0) = fd; - } - else - { - const char *fopen_mode = "w+"; + if (fd < 0) + { + using namespace std; + retval(2) = ::strerror (errno); + retval(0) = fd; + } + else + { + const char *fopen_mode = "w+"; - FILE *fid = fdopen (fd, fopen_mode); + FILE *fid = fdopen (fd, fopen_mode); - if (fid) - { - std::string nm = tmp; + if (fid) + { + std::string nm = tmp; - std::ios::openmode md = fopen_mode_to_ios_mode (fopen_mode); + std::ios::openmode md = fopen_mode_to_ios_mode (fopen_mode); - octave_stream s = octave_stdiostream::create (nm, fid, md); + octave_stream s = octave_stdiostream::create (nm, fid, md); - if (s) - { - retval(1) = nm; - retval(0) = octave_stream_list::insert (s); + if (s) + { + retval(1) = nm; + retval(0) = octave_stream_list::insert (s); - if (nargin == 2 && args(1).is_true ()) - mark_for_deletion (nm); - } - else - error ("mkstemp: failed to create octave_stdiostream object"); - } - else - { - using namespace std; - retval(2) = ::strerror (errno); - retval(0) = -1; - } - } - } + if (nargin == 2 && args(1).is_true ()) + mark_for_deletion (nm); + } + else + error ("mkstemp: failed to create octave_stdiostream object"); + } + else + { + using namespace std; + retval(2) = ::strerror (errno); + retval(0) = -1; + } + } + } else - error ("mkstemp: expecting string as first argument"); + error ("mkstemp: expecting string as first argument"); } else print_usage (); @@ -2079,16 +2079,16 @@ retval = tmp; int mult = ibase; while ((x = (x - tmp) / obase)) - { - tmp = x % obase; - if (tmp > ibase - 1) - { - ::error ("umask: invalid digit"); - break; - } - retval += mult * tmp; - mult *= ibase; - } + { + tmp = x % obase; + if (tmp > ibase - 1) + { + ::error ("umask: invalid digit"); + break; + } + retval += mult * tmp; + mult *= ibase; + } } return retval; @@ -2112,25 +2112,25 @@ int mask = args(0).int_value (true); if (! error_state) - { - if (mask < 0) - { - status = -1; - ::error ("umask: MASK must be a positive integer value"); - } - else - { - int oct_mask = convert (mask, 8, 10); + { + if (mask < 0) + { + status = -1; + ::error ("umask: MASK must be a positive integer value"); + } + else + { + int oct_mask = convert (mask, 8, 10); - if (! error_state) - status = convert (octave_umask (oct_mask), 10, 8); - } - } + if (! error_state) + status = convert (octave_umask (oct_mask), 10, 8); + } + } else - { - status = -1; - ::error ("umask: expecting integer argument"); - } + { + status = -1; + ::error ("umask: expecting integer argument"); + } } else print_usage (); @@ -2224,7 +2224,7 @@ static octave_value const_value (const char *, const octave_value_list& args, - const octave_value& val) + const octave_value& val) { octave_value retval; diff --git a/src/gl-render.cc b/src/gl-render.cc --- a/src/gl-render.cc +++ b/src/gl-render.cc @@ -66,14 +66,14 @@ texture_rep (void) : valid (false), count (1) { } texture_rep (GLuint id_arg, int w_arg, int h_arg, int tw_arg, int th_arg) - : id (id_arg), w (w_arg), h (h_arg), tw (tw_arg), th (th_arg), - tx (double(w)/tw), ty (double(h)/th), valid (true), - count (1) { } + : id (id_arg), w (w_arg), h (h_arg), tw (tw_arg), th (th_arg), + tx (double(w)/tw), ty (double(h)/th), valid (true), + count (1) { } ~texture_rep (void) { - if (valid) - glDeleteTextures (1, &id); + if (valid) + glDeleteTextures (1, &id); } void bind (int mode) const @@ -107,13 +107,13 @@ ~opengl_texture (void) { if (--rep->count == 0) - delete rep; + delete rep; } opengl_texture& operator = (const opengl_texture& tx) { if (--rep->count == 0) - delete rep; + delete rep; rep = tx.rep; rep->count++; @@ -167,59 +167,59 @@ glBindTexture (GL_TEXTURE_2D, id); if (data.is_double_type ()) - { - const NDArray xdata = data.array_value (); - - OCTAVE_LOCAL_BUFFER (float, a, (3*tw*th)); - - for (int i = 0; i < h; i++) - { - for (int j = 0, idx = i*tw*3; j < w; j++, idx += 3) - { - a[idx] = xdata(i,j,0); - a[idx+1] = xdata(i,j,1); - a[idx+2] = xdata(i,j,2); - } - } - - glTexImage2D (GL_TEXTURE_2D, 0, 3, tw, th, 0, - GL_RGB, GL_FLOAT, a); - } + { + const NDArray xdata = data.array_value (); + + OCTAVE_LOCAL_BUFFER (float, a, (3*tw*th)); + + for (int i = 0; i < h; i++) + { + for (int j = 0, idx = i*tw*3; j < w; j++, idx += 3) + { + a[idx] = xdata(i,j,0); + a[idx+1] = xdata(i,j,1); + a[idx+2] = xdata(i,j,2); + } + } + + glTexImage2D (GL_TEXTURE_2D, 0, 3, tw, th, 0, + GL_RGB, GL_FLOAT, a); + } else if (data.is_uint8_type ()) - { - const uint8NDArray xdata = data.uint8_array_value (); - - OCTAVE_LOCAL_BUFFER (octave_uint8, a, (3*tw*th)); - - for (int i = 0; i < h; i++) - { - for (int j = 0, idx = i*tw*3; j < w; j++, idx += 3) - { - a[idx] = xdata(i,j,0); - a[idx+1] = xdata(i,j,1); - a[idx+2] = xdata(i,j,2); - } - } - - glTexImage2D (GL_TEXTURE_2D, 0, 3, tw, th, 0, - GL_RGB, GL_UNSIGNED_BYTE, a); - } + { + const uint8NDArray xdata = data.uint8_array_value (); + + OCTAVE_LOCAL_BUFFER (octave_uint8, a, (3*tw*th)); + + for (int i = 0; i < h; i++) + { + for (int j = 0, idx = i*tw*3; j < w; j++, idx += 3) + { + a[idx] = xdata(i,j,0); + a[idx+1] = xdata(i,j,1); + a[idx+2] = xdata(i,j,2); + } + } + + glTexImage2D (GL_TEXTURE_2D, 0, 3, tw, th, 0, + GL_RGB, GL_UNSIGNED_BYTE, a); + } else - { - ok = false; - warning ("opengl_texture::create: invalid texture data type (expected double or uint8)"); - } + { + ok = false; + warning ("opengl_texture::create: invalid texture data type (expected double or uint8)"); + } if (ok) - { - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - - if (glGetError () != GL_NO_ERROR) - warning ("opengl_texture::create: OpenGL error while generating texture data"); - else - retval = opengl_texture (new texture_rep (id, w, h, tw, th)); - } + { + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + if (glGetError () != GL_NO_ERROR) + warning ("opengl_texture::create: OpenGL error while generating texture data"); + else + retval = opengl_texture (new texture_rep (id, w, h, tw, th)); + } } else warning ("opengl_texture::create: invalid texture data size"); @@ -247,7 +247,7 @@ void begin_polygon (bool filled = true) { gluTessProperty (glu_tess, GLU_TESS_BOUNDARY_ONLY, - (filled ? GL_FALSE : GL_TRUE)); + (filled ? GL_FALSE : GL_TRUE)); fill = filled; gluTessBeginPolygon (glu_tess, this); } @@ -272,7 +272,7 @@ virtual void vertex (void */*data*/) { } virtual void combine (GLdouble /*c*/[3], void */*data*/[4], - GLfloat /*w*/[4], void **/*out_data*/) { } + GLfloat /*w*/[4], void **/*out_data*/) { } virtual void edge_flag (GLboolean /*flag*/) { } @@ -284,17 +284,17 @@ glu_tess = gluNewTess (); gluTessCallback (glu_tess, GLU_TESS_BEGIN_DATA, - reinterpret_cast (tess_begin)); + reinterpret_cast (tess_begin)); gluTessCallback (glu_tess, GLU_TESS_END_DATA, - reinterpret_cast (tess_end)); + reinterpret_cast (tess_end)); gluTessCallback (glu_tess, GLU_TESS_VERTEX_DATA, - reinterpret_cast (tess_vertex)); + reinterpret_cast (tess_vertex)); gluTessCallback (glu_tess, GLU_TESS_COMBINE_DATA, - reinterpret_cast (tess_combine)); + reinterpret_cast (tess_combine)); gluTessCallback (glu_tess, GLU_TESS_EDGE_FLAG_DATA, - reinterpret_cast (tess_edge_flag)); + reinterpret_cast (tess_edge_flag)); gluTessCallback (glu_tess, GLU_TESS_ERROR_DATA, - reinterpret_cast (tess_error)); + reinterpret_cast (tess_error)); } bool is_filled (void) const { return fill; } @@ -310,7 +310,7 @@ { reinterpret_cast (t)->vertex (v); } static void CALLBACK tess_combine (GLdouble c[3], void *v[4], GLfloat w[4], - void **out, void *t) + void **out, void *t) { reinterpret_cast (t)->combine (c, v, w, out); } static void CALLBACK tess_edge_flag (GLboolean flag, void *t) @@ -346,10 +346,10 @@ vertex_data_rep (void) : count (1) { } vertex_data_rep (const Matrix& c, const Matrix& col, const Matrix& n, - double a, float as, float ds, float ss, float se) - : coords (c), color (col), normal (n), alpha (a), - ambient (as), diffuse (ds), specular (ss), specular_exp (se), - count (1) { } + double a, float as, float ds, float ss, float se) + : coords (c), color (col), normal (n), alpha (a), + ambient (as), diffuse (ds), specular (ss), specular_exp (se), + count (1) { } }; private: @@ -370,7 +370,7 @@ { rep->count++; } vertex_data (const Matrix& c, const Matrix& col, const Matrix& n, - double a, float as, float ds, float ss, float se) + double a, float as, float ds, float ss, float se) : rep (new vertex_data_rep (c, col, n, a, as, ds, ss, se)) { } @@ -380,13 +380,13 @@ ~vertex_data (void) { if (--rep->count == 0) - delete rep; + delete rep; } vertex_data& operator = (const vertex_data& v) { if (--rep->count == 0) - delete rep; + delete rep; rep = v.rep; rep->count++; @@ -413,12 +413,12 @@ first = true; if (color_mode == 2 || light_mode == 2) - glShadeModel (GL_SMOOTH); + glShadeModel (GL_SMOOTH); else - glShadeModel (GL_FLAT); + glShadeModel (GL_FLAT); if (is_filled ()) - renderer->set_polygon_offset (true, 1+index); + renderer->set_polygon_offset (true, 1+index); glBegin (type); } @@ -433,7 +433,7 @@ void vertex (void *data) { vertex_data::vertex_data_rep *v - = reinterpret_cast (data); + = reinterpret_cast (data); //printf("patch_tesselator::vertex (%g, %g, %g)\n", v->coords(0), v->coords(1), v->coords(2)); // FIXME: why did I need to keep the first vertex of the face @@ -442,29 +442,29 @@ // the first one you get here might not be the first one of the face; // but I can't figure out the actual reason. if (color_mode > 0 && (first || color_mode == 2)) - { - Matrix col = v->color; - - if (col.numel () == 3) - { - glColor3dv (col.data ()); - if (light_mode > 0) - { - float buf[4] = { 0, 0, 0, 1 }; - - for (int k = 0; k < 3; k++) - buf[k] = (v->ambient * col(k)); - glMaterialfv (LIGHT_MODE, GL_AMBIENT, buf); - - for (int k = 0; k < 3; k++) - buf[k] = (v->diffuse * col(k)); - glMaterialfv (LIGHT_MODE, GL_AMBIENT, buf); - } - } - } + { + Matrix col = v->color; + + if (col.numel () == 3) + { + glColor3dv (col.data ()); + if (light_mode > 0) + { + float buf[4] = { 0, 0, 0, 1 }; + + for (int k = 0; k < 3; k++) + buf[k] = (v->ambient * col(k)); + glMaterialfv (LIGHT_MODE, GL_AMBIENT, buf); + + for (int k = 0; k < 3; k++) + buf[k] = (v->diffuse * col(k)); + glMaterialfv (LIGHT_MODE, GL_AMBIENT, buf); + } + } + } if (light_mode > 0 && (first || light_mode == 2)) - glNormal3dv (v->normal.data ()); + glNormal3dv (v->normal.data ()); glVertex3dv (v->coords.data ()); @@ -472,7 +472,7 @@ } void combine (GLdouble xyz[3], void *data[4], GLfloat w[4], - void **out_data) + void **out_data) { //printf("patch_tesselator::combine\n"); @@ -480,12 +480,12 @@ int vmax = 4; for (int i = 0; i < 4; i++) - { - v[i] = reinterpret_cast (data[i]); - - if (vmax == 4 && ! v[i]) - vmax = i; - } + { + v[i] = reinterpret_cast (data[i]); + + if (vmax == 4 && ! v[i]) + vmax = i; + } Matrix vv (1, 3, 0.0); Matrix cc; @@ -497,25 +497,25 @@ vv(2) = xyz[2]; if (v[0]->color.numel ()) - { - cc.resize (1, 3, 0.0); - for (int ic = 0; ic < 3; ic++) - for (int iv = 0; iv < vmax; iv++) - cc(ic) += (w[iv] * v[iv]->color(ic)); - } + { + cc.resize (1, 3, 0.0); + for (int ic = 0; ic < 3; ic++) + for (int iv = 0; iv < vmax; iv++) + cc(ic) += (w[iv] * v[iv]->color(ic)); + } if (v[0]->normal.numel () > 0) - { - for (int in = 0; in < 3; in++) - for (int iv = 0; iv < vmax; iv++) - nn(in) += (w[iv] * v[iv]->normal(in)); - } + { + for (int in = 0; in < 3; in++) + for (int iv = 0; iv < vmax; iv++) + nn(in) += (w[iv] * v[iv]->normal(in)); + } for (int iv = 0; iv < vmax; iv++) - aa += (w[iv] * v[iv]->alpha); + aa += (w[iv] * v[iv]->alpha); vertex_data new_v (vv, cc, nn, aa, v[0]->ambient, v[0]->diffuse, - v[0]->specular, v[0]->specular_exp); + v[0]->specular, v[0]->specular_exp); tmp_vdata.push_back (new_v); *out_data = new_v.get_rep (); @@ -523,8 +523,8 @@ private: opengl_renderer *renderer; - int color_mode; // 0: uni, 1: flat, 2: interp - int light_mode; // 0: none, 1: flat, 2: gouraud + int color_mode; // 0: uni, 1: flat, 2: interp + int light_mode; // 0: none, 1: flat, 2: gouraud int index; bool first; std::list tmp_vdata; @@ -556,7 +556,7 @@ draw_image (dynamic_cast (props)); else warning ("opengl_renderer: cannot render object of type `%s'", - props.graphics_object_name ().c_str ()); + props.graphics_object_name ().c_str ()); } void @@ -748,8 +748,8 @@ //double tickdir = (props.tickdir_is ("in") ? -1 : 1); double tickdir = (props.tickdirmode_is ("auto") ? - (mode2d ? -1 : 1) : - (props.tickdir_is ("in") ? -1 : 1)); + (mode2d ? -1 : 1) : + (props.tickdir_is ("in") ? -1 : 1)); double xtickoffset = (mode2d && tickdir < 0 ? 0 : xticklen) + 5; double ytickoffset = (mode2d && tickdir < 0 ? 0 : yticklen) + 5; double ztickoffset = (mode2d && tickdir < 0 ? 0 : zticklen) + 5; @@ -975,25 +975,25 @@ // tick texts if (xticklabels.numel () > 0) - { - int n = std::min (xticklabels.numel (), xticks.numel ()); - int halign = (xstate == AXE_HORZ_DIR ? 1 : (xySym ? 0 : 2)); - int valign = (xstate == AXE_VERT_DIR - ? 1 - : (zd*zv(2) <= 0 && !x2Dtop ? 2 : 0)); - - for (int i = 0; i < n; i++) - { - // FIXME: as tick text is transparent, shouldn't be - // drawn after axes object, for correct rendering? - Matrix b = render_text (xticklabels(i), - tickpos(i,0), tickpos(i,1), tickpos(i,2), - halign, valign); - - wmax = std::max (wmax, static_cast (b(2))); - hmax = std::max (hmax, static_cast (b(3))); - } - } + { + int n = std::min (xticklabels.numel (), xticks.numel ()); + int halign = (xstate == AXE_HORZ_DIR ? 1 : (xySym ? 0 : 2)); + int valign = (xstate == AXE_VERT_DIR + ? 1 + : (zd*zv(2) <= 0 && !x2Dtop ? 2 : 0)); + + for (int i = 0; i < n; i++) + { + // FIXME: as tick text is transparent, shouldn't be + // drawn after axes object, for correct rendering? + Matrix b = render_text (xticklabels(i), + tickpos(i,0), tickpos(i,1), tickpos(i,2), + halign, valign); + + wmax = std::max (wmax, static_cast (b(2))); + hmax = std::max (hmax, static_cast (b(3))); + } + } // minor grid lines if (do_xminorgrid) @@ -1015,7 +1015,7 @@ glEnd (); set_linestyle ("-", true); } - + // minor tick marks if (do_xminortick) { @@ -1069,7 +1069,7 @@ if (! xlabel_props.get_string ().empty ()) { xlabel_props.set_horizontalalignment (xstate > AXE_DEPTH_DIR ? "center" : (xySym ? "left" : "right")); - xlabel_props.set_verticalalignment (xstate == AXE_VERT_DIR ? "bottom" : (zd*zv(2) <= 0 ? "top" : "bottom")); + xlabel_props.set_verticalalignment (xstate == AXE_VERT_DIR ? "bottom" : (zd*zv(2) <= 0 ? "top" : "bottom")); double angle = 0; ColumnVector p = graphics_xform::xform_vector ((x_min+x_max)/2, yPlaneN, zPlane); @@ -1104,7 +1104,7 @@ } // Y grid - + if (ystate != AXE_DEPTH_DIR && visible) { bool do_ygrid = (props.is_ygrid () && (gridstyle != "none")); @@ -1187,23 +1187,23 @@ // tick texts if (yticklabels.numel () > 0) - { - int n = std::min (yticklabels.numel (), yticks.numel ()); - int halign = (ystate == AXE_HORZ_DIR ? 1 : (!xySym || y2Dright ? 0 : 2)); - int valign = (ystate == AXE_VERT_DIR ? 1 : (zd*zv(2) <= 0 ? 2 : 0)); - - for (int i = 0; i < n; i++) - { - // FIXME: as tick text is transparent, shouldn't be - // drawn after axes object, for correct rendering? - Matrix b = render_text (yticklabels(i), - tickpos(i,0), tickpos(i,1), tickpos(i,2), - halign, valign); - - wmax = std::max (wmax, static_cast (b(2))); - hmax = std::max (hmax, static_cast (b(3))); - } - } + { + int n = std::min (yticklabels.numel (), yticks.numel ()); + int halign = (ystate == AXE_HORZ_DIR ? 1 : (!xySym || y2Dright ? 0 : 2)); + int valign = (ystate == AXE_VERT_DIR ? 1 : (zd*zv(2) <= 0 ? 2 : 0)); + + for (int i = 0; i < n; i++) + { + // FIXME: as tick text is transparent, shouldn't be + // drawn after axes object, for correct rendering? + Matrix b = render_text (yticklabels(i), + tickpos(i,0), tickpos(i,1), tickpos(i,2), + halign, valign); + + wmax = std::max (wmax, static_cast (b(2))); + hmax = std::max (hmax, static_cast (b(3))); + } + } // minor grid lines if (do_yminorgrid) @@ -1279,7 +1279,7 @@ if (! ylabel_props.get_string ().empty ()) { ylabel_props.set_horizontalalignment (ystate > AXE_DEPTH_DIR ? "center" : (!xySym ? "left" : "right")); - ylabel_props.set_verticalalignment (ystate == AXE_VERT_DIR ? "bottom" : (zd*zv(2) <= 0 ? "top" : "bottom")); + ylabel_props.set_verticalalignment (ystate == AXE_VERT_DIR ? "bottom" : (zd*zv(2) <= 0 ? "top" : "bottom")); double angle = 0; ColumnVector p = graphics_xform::xform_vector (xPlaneN, (y_min+y_max)/2, zPlane); @@ -1312,7 +1312,7 @@ { gh_manager::get_object (props.get_ylabel ()).set ("visible", "off"); } - + // Z Grid if (zstate != AXE_DEPTH_DIR && visible) @@ -1429,23 +1429,23 @@ // FIXME: tick texts if (zticklabels.numel () > 0) - { - int n = std::min (zticklabels.numel (), zticks.numel ()); - int halign = 2; - int valign = (zstate == AXE_VERT_DIR ? 1 : (zd*zv(2) < 0 ? 3 : 2)); - - for (int i = 0; i < n; i++) - { - // FIXME: as tick text is transparent, shouldn't be - // drawn after axes object, for correct rendering? - Matrix b = render_text (zticklabels(i), - tickpos(i,0), tickpos(i,1), tickpos(i,2), - halign, valign); - - wmax = std::max (wmax, static_cast (b(2))); - hmax = std::max (hmax, static_cast (b(3))); - } - } + { + int n = std::min (zticklabels.numel (), zticks.numel ()); + int halign = 2; + int valign = (zstate == AXE_VERT_DIR ? 1 : (zd*zv(2) < 0 ? 3 : 2)); + + for (int i = 0; i < n; i++) + { + // FIXME: as tick text is transparent, shouldn't be + // drawn after axes object, for correct rendering? + Matrix b = render_text (zticklabels(i), + tickpos(i,0), tickpos(i,1), tickpos(i,2), + halign, valign); + + wmax = std::max (wmax, static_cast (b(2))); + hmax = std::max (hmax, static_cast (b(3))); + } + } // minor grid lines if (do_zminorgrid) @@ -1548,7 +1548,7 @@ bool camAuto = props.cameraupvectormode_is ("auto"); zlabel_props.set_horizontalalignment ((zstate > AXE_DEPTH_DIR || camAuto) ? "center" : "right"); - zlabel_props.set_verticalalignment(zstate == AXE_VERT_DIR ? "bottom" : ((zd*zv(2) < 0 || camAuto) ? "bottom" : "top")); + zlabel_props.set_verticalalignment(zstate == AXE_VERT_DIR ? "bottom" : ((zd*zv(2) < 0 || camAuto) ? "bottom" : "top")); double angle = 0; ColumnVector p; @@ -1638,7 +1638,7 @@ if (go.get_properties ().is_visible ()) { if (go.isa ("light")) - draw (go); + draw (go); else obj_list.push_back (go); } @@ -1658,9 +1658,9 @@ draw (go); it = obj_list.erase (it); - } + } else - it++; + it++; } // 3rd pass: draw remaining objects @@ -1699,7 +1699,7 @@ double z_mid = (zmin+zmax)/2; for (int i = 0; i < n; i++) - clip[i] = (clip_code (x(i), y(i), z_mid) & clip_mask); + clip[i] = (clip_code (x(i), y(i), z_mid) & clip_mask); } if (! props.linestyle_is ("none")) @@ -1709,58 +1709,58 @@ set_linewidth (props.get_linewidth ()); if (has_z) - { - bool flag = false; - - for (int i = 1; i < n; i++) - { - if ((clip[i-1] & clip[i]) == clip_ok) - { - if (! flag) - { - flag = true; - glBegin (GL_LINE_STRIP); - glVertex3d (x(i-1), y(i-1), z(i-1)); - } - glVertex3d (x(i), y(i), z(i)); - } - else if (flag) - { - flag = false; - glEnd (); - } - } - - if (flag) - glEnd (); - } + { + bool flag = false; + + for (int i = 1; i < n; i++) + { + if ((clip[i-1] & clip[i]) == clip_ok) + { + if (! flag) + { + flag = true; + glBegin (GL_LINE_STRIP); + glVertex3d (x(i-1), y(i-1), z(i-1)); + } + glVertex3d (x(i), y(i), z(i)); + } + else if (flag) + { + flag = false; + glEnd (); + } + } + + if (flag) + glEnd (); + } else - { - bool flag = false; - - for (int i = 1; i < n; i++) - { - if ((clip[i-1] & clip[i]) == clip_ok) - { - if (! flag) - { - flag = true; - glBegin (GL_LINE_STRIP); - glVertex2d (x(i-1), y(i-1)); - } - glVertex2d (x(i), y(i)); - } - else if (flag) - { - flag = false; - glEnd (); - } - } - - if (flag) - glEnd (); - } - + { + bool flag = false; + + for (int i = 1; i < n; i++) + { + if ((clip[i-1] & clip[i]) == clip_ok) + { + if (! flag) + { + flag = true; + glBegin (GL_LINE_STRIP); + glVertex2d (x(i-1), y(i-1)); + } + glVertex2d (x(i), y(i)); + } + else if (flag) + { + flag = false; + glEnd (); + } + } + + if (flag) + glEnd (); + } + set_linewidth (0.5); set_linestyle ("-"); } @@ -1769,22 +1769,22 @@ if (! props.marker_is ("none") && ! (props.markeredgecolor_is ("none") - && props.markerfacecolor_is ("none"))) + && props.markerfacecolor_is ("none"))) { Matrix lc, fc; if (props.markeredgecolor_is ("auto")) - lc = props.get_color_rgb (); + lc = props.get_color_rgb (); else if (! props.markeredgecolor_is ("none")) - lc = props.get_markeredgecolor_rgb (); + lc = props.get_markeredgecolor_rgb (); if (props.markerfacecolor_is ("auto")) - fc = props.get_color_rgb (); + fc = props.get_color_rgb (); else if (! props.markerfacecolor_is ("none")) - fc = props.get_markerfacecolor_rgb (); + fc = props.get_markerfacecolor_rgb (); init_marker (props.get_marker (), props.get_markersize (), - props.get_linewidth ()); + props.get_linewidth ()); for (int i = 0; i < n; i++) { @@ -1817,20 +1817,20 @@ warning ("opengl_renderer::draw: phong light model not supported"); int fc_mode = (props.facecolor_is_rgb () ? 0 : - (props.facecolor_is ("flat") ? 1 : - (props.facecolor_is ("interp") ? 2 : - (props.facecolor_is ("texturemap") ? 3 : -1)))); + (props.facecolor_is ("flat") ? 1 : + (props.facecolor_is ("interp") ? 2 : + (props.facecolor_is ("texturemap") ? 3 : -1)))); int fl_mode = (props.facelighting_is ("none") ? 0 : - (props.facelighting_is ("flat") ? 1 : 2)); + (props.facelighting_is ("flat") ? 1 : 2)); int fa_mode = (props.facealpha_is_double () ? 0 : - (props.facealpha_is ("flat") ? 1 : 2)); + (props.facealpha_is ("flat") ? 1 : 2)); int ec_mode = (props.edgecolor_is_rgb () ? 0 : - (props.edgecolor_is ("flat") ? 1 : - (props.edgecolor_is ("interp") ? 2 : -1))); + (props.edgecolor_is ("flat") ? 1 : + (props.edgecolor_is ("interp") ? 2 : -1))); int el_mode = (props.edgelighting_is ("none") ? 0 : - (props.edgelighting_is ("flat") ? 1 : 2)); + (props.edgelighting_is ("flat") ? 1 : 2)); int ea_mode = (props.edgealpha_is_double () ? 0 : - (props.edgealpha_is ("flat") ? 1 : 2)); + (props.edgealpha_is ("flat") ? 1 : 2)); Matrix fcolor = (fc_mode == 3 ? Matrix (1, 3, 1.0) : props.get_facecolor_rgb ()); Matrix ecolor = props.get_edgecolor_rgb (); @@ -1855,15 +1855,15 @@ for (int i = 0; i < zr; i++) { if (x_mat) - i1 = i; + i1 = i; for (int j = 0; j < zc; j++) - { - if (y_mat) - j1 = j; - - clip(i,j) = is_nan_or_inf (x(i1,j), y(i,j1), z(i,j)); - } + { + if (y_mat) + j1 = j; + + clip(i,j) = is_nan_or_inf (x(i1,j), y(i,j1), z(i,j)); + } } if ((fc_mode > 0 && fc_mode < 3) || ec_mode > 0) @@ -1891,396 +1891,396 @@ if (! props.facecolor_is ("none")) { if (props.get_facealpha_double () == 1) - { - if (fc_mode == 0 || fc_mode == 3) - { - glColor3dv (fcolor.data ()); - if (fl_mode > 0) - { - for (int i = 0; i < 3; i++) - cb[i] = as * fcolor(i); - glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); - - for (int i = 0; i < 3; i++) - cb[i] = ds * fcolor(i); - glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); - } - } - - if (fl_mode > 0) - glEnable (GL_LIGHTING); - glShadeModel ((fc_mode == 2 || fl_mode == 2) ? GL_SMOOTH : GL_FLAT); - set_polygon_offset (true, 1); - if (fc_mode == 3) - glEnable (GL_TEXTURE_2D); - - for (int i = 1; i < zc; i++) - { - if (y_mat) - { - i1 = i-1; - i2 = i; - } - - for (int j = 1; j < zr; j++) - { - if (clip(j-1, i-1) || clip (j, i-1) - || clip (j-1, i) || clip (j, i)) - continue; - - if (x_mat) - { - j1 = j-1; - j2 = j; - } - - glBegin (GL_QUADS); - - // Vertex 1 - if (fc_mode == 3) - tex.tex_coord (double (i-1) / (zc-1), double (j-1) / (zr-1)); - else if (fc_mode > 0) - { - // FIXME: is there a smarter way to do this? - for (int k = 0; k < 3; k++) - cb[k] = c(j-1, i-1, k); - glColor3fv (cb); - - if (fl_mode > 0) - { - for (int k = 0; k < 3; k++) - cb[k] *= as; - glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); - - for (int k = 0; k < 3; k++) - cb[k] = ds * c(j-1, i-1, k); - glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); - } - } + { + if (fc_mode == 0 || fc_mode == 3) + { + glColor3dv (fcolor.data ()); + if (fl_mode > 0) + { + for (int i = 0; i < 3; i++) + cb[i] = as * fcolor(i); + glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); + + for (int i = 0; i < 3; i++) + cb[i] = ds * fcolor(i); + glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); + } + } + + if (fl_mode > 0) + glEnable (GL_LIGHTING); + glShadeModel ((fc_mode == 2 || fl_mode == 2) ? GL_SMOOTH : GL_FLAT); + set_polygon_offset (true, 1); + if (fc_mode == 3) + glEnable (GL_TEXTURE_2D); + + for (int i = 1; i < zc; i++) + { + if (y_mat) + { + i1 = i-1; + i2 = i; + } + + for (int j = 1; j < zr; j++) + { + if (clip(j-1, i-1) || clip (j, i-1) + || clip (j-1, i) || clip (j, i)) + continue; + + if (x_mat) + { + j1 = j-1; + j2 = j; + } + + glBegin (GL_QUADS); + + // Vertex 1 + if (fc_mode == 3) + tex.tex_coord (double (i-1) / (zc-1), double (j-1) / (zr-1)); + else if (fc_mode > 0) + { + // FIXME: is there a smarter way to do this? + for (int k = 0; k < 3; k++) + cb[k] = c(j-1, i-1, k); + glColor3fv (cb); + + if (fl_mode > 0) + { + for (int k = 0; k < 3; k++) + cb[k] *= as; + glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); + + for (int k = 0; k < 3; k++) + cb[k] = ds * c(j-1, i-1, k); + glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); + } + } if (fl_mode > 0) - { - d = sqrt (n(j-1,i-1,0) * n(j-1,i-1,0) - + n(j-1,i-1,1) * n(j-1,i-1,1) - + n(j-1,i-1,2) * n(j-1,i-1,2)); - glNormal3d (n(j-1,i-1,0)/d, n(j-1,i-1,1)/d, n(j-1,i-1,2)/d); - } - glVertex3d (x(j1,i-1), y(j-1,i1), z(j-1,i-1)); - - // Vertex 2 - if (fc_mode == 3) - tex.tex_coord (double (i) / (zc-1), double (j-1) / (zr-1)); - else if (fc_mode == 2) - { - for (int k = 0; k < 3; k++) - cb[k] = c(j-1, i, k); - glColor3fv (cb); - - if (fl_mode > 0) - { - for (int k = 0; k < 3; k++) - cb[k] *= as; - glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); - - for (int k = 0; k < 3; k++) - cb[k] = ds * c(j-1, i, k); - glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); - } - } + { + d = sqrt (n(j-1,i-1,0) * n(j-1,i-1,0) + + n(j-1,i-1,1) * n(j-1,i-1,1) + + n(j-1,i-1,2) * n(j-1,i-1,2)); + glNormal3d (n(j-1,i-1,0)/d, n(j-1,i-1,1)/d, n(j-1,i-1,2)/d); + } + glVertex3d (x(j1,i-1), y(j-1,i1), z(j-1,i-1)); + + // Vertex 2 + if (fc_mode == 3) + tex.tex_coord (double (i) / (zc-1), double (j-1) / (zr-1)); + else if (fc_mode == 2) + { + for (int k = 0; k < 3; k++) + cb[k] = c(j-1, i, k); + glColor3fv (cb); + + if (fl_mode > 0) + { + for (int k = 0; k < 3; k++) + cb[k] *= as; + glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); + + for (int k = 0; k < 3; k++) + cb[k] = ds * c(j-1, i, k); + glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); + } + } if (fl_mode == 2) - { - d = sqrt (n(j-1,i,0) * n(j-1,i,0) - + n(j-1,i,1) * n(j-1,i,1) - + n(j-1,i,2) * n(j-1,i,2)); - glNormal3d (n(j-1,i,0)/d, n(j-1,i,1)/d, n(j-1,i,2)/d); - } - - glVertex3d (x(j1,i), y(j-1,i2), z(j-1,i)); - - // Vertex 3 - if (fc_mode == 3) - tex.tex_coord (double (i) / (zc-1), double (j) / (zr-1)); - else if (fc_mode == 2) - { - for (int k = 0; k < 3; k++) - cb[k] = c(j, i, k); - glColor3fv (cb); - - if (fl_mode > 0) - { - for (int k = 0; k < 3; k++) - cb[k] *= as; - glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); - - for (int k = 0; k < 3; k++) - cb[k] = ds * c(j, i, k); - glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); - } - } - if (fl_mode == 2) - { - d = sqrt (n(j,i,0) * n(j,i,0) - + n(j,i,1) * n(j,i,1) - + n(j,i,2) * n(j,i,2)); - glNormal3d (n(j,i,0)/d, n(j,i,1)/d, n(j,i,2)/d); - } - glVertex3d (x(j2,i), y(j,i2), z(j,i)); - - // Vertex 4 - if (fc_mode == 3) - tex.tex_coord (double (i-1) / (zc-1), double (j) / (zr-1)); - else if (fc_mode == 2) - { - for (int k = 0; k < 3; k++) - cb[k] = c(j, i-1, k); - glColor3fv (cb); - - if (fl_mode > 0) - { - for (int k = 0; k < 3; k++) - cb[k] *= as; - glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); - - for (int k = 0; k < 3; k++) - cb[k] = ds * c(j, i-1, k); - glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); - } - } + { + d = sqrt (n(j-1,i,0) * n(j-1,i,0) + + n(j-1,i,1) * n(j-1,i,1) + + n(j-1,i,2) * n(j-1,i,2)); + glNormal3d (n(j-1,i,0)/d, n(j-1,i,1)/d, n(j-1,i,2)/d); + } + + glVertex3d (x(j1,i), y(j-1,i2), z(j-1,i)); + + // Vertex 3 + if (fc_mode == 3) + tex.tex_coord (double (i) / (zc-1), double (j) / (zr-1)); + else if (fc_mode == 2) + { + for (int k = 0; k < 3; k++) + cb[k] = c(j, i, k); + glColor3fv (cb); + + if (fl_mode > 0) + { + for (int k = 0; k < 3; k++) + cb[k] *= as; + glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); + + for (int k = 0; k < 3; k++) + cb[k] = ds * c(j, i, k); + glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); + } + } if (fl_mode == 2) - { - d = sqrt (n(j,i-1,0) * n(j,i-1,0) - + n(j,i-1,1) * n(j,i-1,1) - + n(j,i-1,2) * n(j,i-1,2)); - glNormal3d (n(j,i-1,0)/d, n(j,i-1,1)/d, n(j,i-1,2)/d); - } - glVertex3d (x(j2,i-1), y(j,i1), z(j,i-1)); - - glEnd (); - } - } - - set_polygon_offset (false); - if (fc_mode == 3) - glDisable (GL_TEXTURE_2D); - - if (fl_mode > 0) - glDisable (GL_LIGHTING); - } + { + d = sqrt (n(j,i,0) * n(j,i,0) + + n(j,i,1) * n(j,i,1) + + n(j,i,2) * n(j,i,2)); + glNormal3d (n(j,i,0)/d, n(j,i,1)/d, n(j,i,2)/d); + } + glVertex3d (x(j2,i), y(j,i2), z(j,i)); + + // Vertex 4 + if (fc_mode == 3) + tex.tex_coord (double (i-1) / (zc-1), double (j) / (zr-1)); + else if (fc_mode == 2) + { + for (int k = 0; k < 3; k++) + cb[k] = c(j, i-1, k); + glColor3fv (cb); + + if (fl_mode > 0) + { + for (int k = 0; k < 3; k++) + cb[k] *= as; + glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); + + for (int k = 0; k < 3; k++) + cb[k] = ds * c(j, i-1, k); + glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); + } + } + if (fl_mode == 2) + { + d = sqrt (n(j,i-1,0) * n(j,i-1,0) + + n(j,i-1,1) * n(j,i-1,1) + + n(j,i-1,2) * n(j,i-1,2)); + glNormal3d (n(j,i-1,0)/d, n(j,i-1,1)/d, n(j,i-1,2)/d); + } + glVertex3d (x(j2,i-1), y(j,i1), z(j,i-1)); + + glEnd (); + } + } + + set_polygon_offset (false); + if (fc_mode == 3) + glDisable (GL_TEXTURE_2D); + + if (fl_mode > 0) + glDisable (GL_LIGHTING); + } else - { - // FIXME: implement transparency - } + { + // FIXME: implement transparency + } } if (! props.edgecolor_is ("none")) { if (props.get_edgealpha_double () == 1) - { - if (ec_mode == 0) - { - glColor3dv (ecolor.data ()); - if (fl_mode > 0) - { - for (int i = 0; i < 3; i++) - cb[i] = as * ecolor(i); - glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); - - for (int i = 0; i < 3; i++) - cb[i] = ds * ecolor(i); - glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); - } - } - - if (el_mode > 0) - glEnable (GL_LIGHTING); - glShadeModel ((ec_mode == 2 || el_mode == 2) ? GL_SMOOTH : GL_FLAT); - - set_linestyle (props.get_linestyle (), false); - set_linewidth (props.get_linewidth ()); - - // Mesh along Y-axis - - if (props.meshstyle_is ("both") || props.meshstyle_is ("column")) - { - for (int i = 0; i < zc; i++) - { - if (y_mat) - { - i1 = i-1; - i2 = i; - } - - for (int j = 1; j < zr; j++) - { - if (clip(j-1,i) || clip(j,i)) - continue; - - if (x_mat) - { - j1 = j-1; - j2 = j; - } - - glBegin (GL_LINES); - - // Vertex 1 - if (ec_mode > 0) - { - for (int k = 0; k < 3; k++) - cb[k] = c(j-1, i, k); - glColor3fv (cb); - - if (fl_mode > 0) - { - for (int k = 0; k < 3; k++) - cb[k] *= as; - glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); - - for (int k = 0; k < 3; k++) - cb[k] = ds * c(j-1, i, k); - glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); - } - } - if (el_mode > 0) - { - d = sqrt (n(j-1,i,0) * n(j-1,i,0) - + n(j-1,i,1) * n(j-1,i,1) - + n(j-1,i,2) * n(j-1,i,2)); - glNormal3d (n(j-1,i,0)/d, n(j-1,i,1)/d, n(j-1,i,2)/d); - } - glVertex3d (x(j1,i), y(j-1,i2), z(j-1,i)); - - // Vertex 2 - if (ec_mode == 2) - { - for (int k = 0; k < 3; k++) - cb[k] = c(j, i, k); - glColor3fv (cb); - - if (fl_mode > 0) - { - for (int k = 0; k < 3; k++) - cb[k] *= as; - glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); - - for (int k = 0; k < 3; k++) - cb[k] = ds * c(j, i, k); - glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); - } - } - if (el_mode == 2) - { - d = sqrt (n(j,i,0) * n(j,i,0) - + n(j,i,1) * n(j,i,1) - + n(j,i,2) * n(j,i,2)); - glNormal3d (n(j,i,0)/d, n(j,i,1)/d, n(j,i,2)/d); - } - glVertex3d (x(j2,i), y(j,i2), z(j,i)); - - glEnd (); - } - } - } - - // Mesh along X-axis - - if (props.meshstyle_is ("both") || props.meshstyle_is ("row")) - { - for (int j = 0; j < zr; j++) - { - if (x_mat) - { - j1 = j-1; - j2 = j; - } - - for (int i = 1; i < zc; i++) - { - if (clip(j,i-1) || clip(j,i)) - continue; - - if (y_mat) - { - i1 = i-1; - i2 = i; - } - - glBegin (GL_LINES); - - // Vertex 1 - if (ec_mode > 0) - { - for (int k = 0; k < 3; k++) - cb[k] = c(j, i-1, k); - glColor3fv (cb); - - if (fl_mode > 0) - { - for (int k = 0; k < 3; k++) - cb[k] *= as; - glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); - - for (int k = 0; k < 3; k++) - cb[k] = ds * c(j, i-1, k); - glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); - } - } - if (el_mode > 0) + { + if (ec_mode == 0) + { + glColor3dv (ecolor.data ()); + if (fl_mode > 0) + { + for (int i = 0; i < 3; i++) + cb[i] = as * ecolor(i); + glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); + + for (int i = 0; i < 3; i++) + cb[i] = ds * ecolor(i); + glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); + } + } + + if (el_mode > 0) + glEnable (GL_LIGHTING); + glShadeModel ((ec_mode == 2 || el_mode == 2) ? GL_SMOOTH : GL_FLAT); + + set_linestyle (props.get_linestyle (), false); + set_linewidth (props.get_linewidth ()); + + // Mesh along Y-axis + + if (props.meshstyle_is ("both") || props.meshstyle_is ("column")) + { + for (int i = 0; i < zc; i++) + { + if (y_mat) + { + i1 = i-1; + i2 = i; + } + + for (int j = 1; j < zr; j++) + { + if (clip(j-1,i) || clip(j,i)) + continue; + + if (x_mat) + { + j1 = j-1; + j2 = j; + } + + glBegin (GL_LINES); + + // Vertex 1 + if (ec_mode > 0) + { + for (int k = 0; k < 3; k++) + cb[k] = c(j-1, i, k); + glColor3fv (cb); + + if (fl_mode > 0) + { + for (int k = 0; k < 3; k++) + cb[k] *= as; + glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); + + for (int k = 0; k < 3; k++) + cb[k] = ds * c(j-1, i, k); + glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); + } + } + if (el_mode > 0) + { + d = sqrt (n(j-1,i,0) * n(j-1,i,0) + + n(j-1,i,1) * n(j-1,i,1) + + n(j-1,i,2) * n(j-1,i,2)); + glNormal3d (n(j-1,i,0)/d, n(j-1,i,1)/d, n(j-1,i,2)/d); + } + glVertex3d (x(j1,i), y(j-1,i2), z(j-1,i)); + + // Vertex 2 + if (ec_mode == 2) + { + for (int k = 0; k < 3; k++) + cb[k] = c(j, i, k); + glColor3fv (cb); + + if (fl_mode > 0) + { + for (int k = 0; k < 3; k++) + cb[k] *= as; + glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); + + for (int k = 0; k < 3; k++) + cb[k] = ds * c(j, i, k); + glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); + } + } + if (el_mode == 2) { - d = sqrt (n(j,i-1,0) * n(j,i-1,0) - + n(j,i-1,1) * n(j,i-1,1) - + n(j,i-1,2) * n(j,i-1,2)); - glNormal3d (n(j,i-1,0)/d, n(j,i-1,1)/d, n(j,i-1,2)/d); - } - glVertex3d (x(j2,i-1), y(j,i1), z(j,i-1)); - - // Vertex 2 - if (ec_mode == 2) - { - for (int k = 0; k < 3; k++) - cb[k] = c(j, i, k); - glColor3fv (cb); - - if (fl_mode > 0) - { - for (int k = 0; k < 3; k++) - cb[k] *= as; - glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); - - for (int k = 0; k < 3; k++) - cb[k] = ds * c(j, i, k); - glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); - } - } - if (el_mode == 2) - { - d = sqrt (n(j,i,0) * n(j,i,0) - + n(j,i,1) * n(j,i,1) - + n(j,i,2) * n(j,i,2)); - glNormal3d (n(j,i,0)/d, n(j,i,1)/d, n(j,i,2)/d); - } - glVertex3d (x(j2,i), y(j,i2), z(j,i)); - - glEnd (); - } - } - } - - set_linestyle ("-"); - set_linewidth (0.5); - - if (el_mode > 0) - glDisable (GL_LIGHTING); - } + d = sqrt (n(j,i,0) * n(j,i,0) + + n(j,i,1) * n(j,i,1) + + n(j,i,2) * n(j,i,2)); + glNormal3d (n(j,i,0)/d, n(j,i,1)/d, n(j,i,2)/d); + } + glVertex3d (x(j2,i), y(j,i2), z(j,i)); + + glEnd (); + } + } + } + + // Mesh along X-axis + + if (props.meshstyle_is ("both") || props.meshstyle_is ("row")) + { + for (int j = 0; j < zr; j++) + { + if (x_mat) + { + j1 = j-1; + j2 = j; + } + + for (int i = 1; i < zc; i++) + { + if (clip(j,i-1) || clip(j,i)) + continue; + + if (y_mat) + { + i1 = i-1; + i2 = i; + } + + glBegin (GL_LINES); + + // Vertex 1 + if (ec_mode > 0) + { + for (int k = 0; k < 3; k++) + cb[k] = c(j, i-1, k); + glColor3fv (cb); + + if (fl_mode > 0) + { + for (int k = 0; k < 3; k++) + cb[k] *= as; + glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); + + for (int k = 0; k < 3; k++) + cb[k] = ds * c(j, i-1, k); + glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); + } + } + if (el_mode > 0) + { + d = sqrt (n(j,i-1,0) * n(j,i-1,0) + + n(j,i-1,1) * n(j,i-1,1) + + n(j,i-1,2) * n(j,i-1,2)); + glNormal3d (n(j,i-1,0)/d, n(j,i-1,1)/d, n(j,i-1,2)/d); + } + glVertex3d (x(j2,i-1), y(j,i1), z(j,i-1)); + + // Vertex 2 + if (ec_mode == 2) + { + for (int k = 0; k < 3; k++) + cb[k] = c(j, i, k); + glColor3fv (cb); + + if (fl_mode > 0) + { + for (int k = 0; k < 3; k++) + cb[k] *= as; + glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); + + for (int k = 0; k < 3; k++) + cb[k] = ds * c(j, i, k); + glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); + } + } + if (el_mode == 2) + { + d = sqrt (n(j,i,0) * n(j,i,0) + + n(j,i,1) * n(j,i,1) + + n(j,i,2) * n(j,i,2)); + glNormal3d (n(j,i,0)/d, n(j,i,1)/d, n(j,i,2)/d); + } + glVertex3d (x(j2,i), y(j,i2), z(j,i)); + + glEnd (); + } + } + } + + set_linestyle ("-"); + set_linewidth (0.5); + + if (el_mode > 0) + glDisable (GL_LIGHTING); + } else - { - // FIXME: implement transparency - } + { + // FIXME: implement transparency + } } if (! props.marker_is ("none") && ! (props.markeredgecolor_is ("none") - && props.markerfacecolor_is ("none"))) + && props.markerfacecolor_is ("none"))) { // FIXME: check how transparency should be handled in markers // FIXME: check what to do with marker facecolor set to auto @@ -2294,50 +2294,50 @@ Matrix cc (1, 3, 0.0); if (mecolor.numel () == 0 && props.markeredgecolor_is ("auto")) - { - mecolor = props.get_edgecolor_rgb (); - do_edge = ! props.edgecolor_is ("none"); - } + { + mecolor = props.get_edgecolor_rgb (); + do_edge = ! props.edgecolor_is ("none"); + } if (mfcolor.numel () == 0 && props.markerfacecolor_is ("auto")) - { - mfcolor = props.get_facecolor_rgb (); - do_face = ! props.facecolor_is ("none"); - } + { + mfcolor = props.get_facecolor_rgb (); + do_face = ! props.facecolor_is ("none"); + } if ((mecolor.numel () == 0 || mfcolor.numel () == 0) - && c.numel () == 0) - c = props.get_color_data ().array_value (); + && c.numel () == 0) + c = props.get_color_data ().array_value (); init_marker (props.get_marker (), props.get_markersize (), - props.get_linewidth ()); + props.get_linewidth ()); for (int i = 0; i < zc; i++) - { - if (y_mat) - i1 = i; - - for (int j = 0; j < zr; j++) - { - if (clip(j,i)) - continue; - - if (x_mat) - j1 = j; - - if ((do_edge && mecolor.numel () == 0) - || (do_face && mfcolor.numel () == 0)) - { - for (int k = 0; k < 3; k++) - cc(k) = c(j,i,k); - } - - Matrix lc = (do_edge ? (mecolor.numel () == 0 ? cc : mecolor) : Matrix ()); - Matrix fc = (do_face ? (mfcolor.numel () == 0 ? cc : mfcolor) : Matrix ()); - - draw_marker (x(j1,i), y(j,i1), z(j,i), lc, fc); - } - } + { + if (y_mat) + i1 = i; + + for (int j = 0; j < zr; j++) + { + if (clip(j,i)) + continue; + + if (x_mat) + j1 = j; + + if ((do_edge && mecolor.numel () == 0) + || (do_face && mfcolor.numel () == 0)) + { + for (int k = 0; k < 3; k++) + cc(k) = c(j,i,k); + } + + Matrix lc = (do_edge ? (mecolor.numel () == 0 ? cc : mecolor) : Matrix ()); + Matrix fc = (do_face ? (mfcolor.numel () == 0 ? cc : mfcolor) : Matrix ()); + + draw_marker (x(j1,i), y(j,i1), z(j,i), lc, fc); + } + } end_marker (); } @@ -2364,17 +2364,17 @@ bool has_facealpha = false; int fc_mode = (props.facecolor_is_rgb () ? 0 : - (props.facecolor_is("flat") ? 1 : 2)); + (props.facecolor_is("flat") ? 1 : 2)); int fl_mode = (props.facelighting_is ("none") ? 0 : - (props.facelighting_is ("flat") ? 1 : 2)); + (props.facelighting_is ("flat") ? 1 : 2)); int fa_mode = (props.facealpha_is_double () ? 0 : - (props.facealpha_is ("flat") ? 1 : 2)); + (props.facealpha_is ("flat") ? 1 : 2)); int ec_mode = (props.edgecolor_is_rgb () ? 0 : - (props.edgecolor_is("flat") ? 1 : 2)); + (props.edgecolor_is("flat") ? 1 : 2)); int el_mode = (props.edgelighting_is ("none") ? 0 : - (props.edgelighting_is ("flat") ? 1 : 2)); + (props.edgelighting_is ("flat") ? 1 : 2)); int ea_mode = (props.edgealpha_is_double () ? 0 : - (props.edgealpha_is ("flat") ? 1 : 2)); + (props.edgealpha_is ("flat") ? 1 : 2)); Matrix fcolor = props.get_facecolor_rgb (); Matrix ecolor = props.get_edgecolor_rgb (); @@ -2402,7 +2402,7 @@ int count = 0; for (int j = 0; j < fcmax && ! xisnan (f(i,j)); j++, count++) - fclip = (fclip || clip(int (f(i,j) - 1))); + fclip = (fclip || clip(int (f(i,j) - 1))); clip_f(i) = fclip; count_f(i) = count; @@ -2413,25 +2413,25 @@ c = props.get_color_data ().matrix_value (); if (c.rows () == 1) - { - // Single color specifications, we can simplify a little bit - - if (fc_mode > 0) - { - fcolor = c; - fc_mode = 0; - } - - if (ec_mode > 0) - { - ecolor = c; - ec_mode = 0; - } - - c = Matrix (); - } + { + // Single color specifications, we can simplify a little bit + + if (fc_mode > 0) + { + fcolor = c; + fc_mode = 0; + } + + if (ec_mode > 0) + { + ecolor = c; + ec_mode = 0; + } + + c = Matrix (); + } else - has_facecolor = ((c.numel () > 0) && (c.rows () == f.rows ())); + has_facecolor = ((c.numel () > 0) && (c.rows () == f.rows ())); } if (fa_mode > 0 || ea_mode > 0) @@ -2447,36 +2447,36 @@ for (int i = 0; i < nf; i++) for (int j = 0; j < count_f(i); j++) { - int idx = int (f(i,j) - 1); - - Matrix vv (1, 3, 0.0); - Matrix cc; - Matrix nn(1, 3, 0.0); - double aa = 1.0; - - vv(0) = v(idx,0); vv(1) = v(idx,1); - if (has_z) - vv(2) = v(idx,2); - // FIXME: uncomment when patch object has normal computation - //nn(0) = n(idx,0); nn(1) = n(idx,1); nn(2) = n(idx,2); - if (c.numel () > 0) - { - cc.resize (1, 3); - if (has_facecolor) - cc(0) = c(i,0), cc(1) = c(i,1), cc(2) = c(i,2); - else - cc(0) = c(idx,0), cc(1) = c(idx,1), cc(2) = c(idx,2); - } - if (a.numel () > 0) - { - if (has_facealpha) - aa = a(i); - else - aa = a(idx); - } - - vdata[i+j*fr] = - vertex_data (vv, cc, nn, aa, as, ds, ss, se); + int idx = int (f(i,j) - 1); + + Matrix vv (1, 3, 0.0); + Matrix cc; + Matrix nn(1, 3, 0.0); + double aa = 1.0; + + vv(0) = v(idx,0); vv(1) = v(idx,1); + if (has_z) + vv(2) = v(idx,2); + // FIXME: uncomment when patch object has normal computation + //nn(0) = n(idx,0); nn(1) = n(idx,1); nn(2) = n(idx,2); + if (c.numel () > 0) + { + cc.resize (1, 3); + if (has_facecolor) + cc(0) = c(i,0), cc(1) = c(i,1), cc(2) = c(i,2); + else + cc(0) = c(idx,0), cc(1) = c(idx,1), cc(2) = c(idx,2); + } + if (a.numel () > 0) + { + if (has_facealpha) + aa = a(i); + else + aa = a(idx); + } + + vdata[i+j*fr] = + vertex_data (vv, cc, nn, aa, as, ds, ss, se); } if (fl_mode > 0 || el_mode > 0) @@ -2491,119 +2491,119 @@ { // FIXME: adapt to double-radio property if (props.get_facealpha_double () == 1) - { - if (fc_mode == 0) - { - glColor3dv (fcolor.data ()); - if (fl_mode > 0) - { - float cb[4] = { 0, 0, 0, 1 }; - - for (int i = 0; i < 3; i++) - cb[i] = (as * fcolor(i)); - glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); - - for (int i = 0; i < 3; i++) - cb[i] = ds * fcolor(i); - glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); - } - } - - if (fl_mode > 0) - glEnable (GL_LIGHTING); - - // FIXME: use __index__ property from patch object - patch_tesselator tess (this, fc_mode, fl_mode, 0); - - for (int i = 0; i < nf; i++) - { - if (clip_f(i)) - continue; - - tess.begin_polygon (true); - tess.begin_contour (); - - for (int j = 0; j < count_f(i); j++) - { - vertex_data::vertex_data_rep *vv = vdata[i+j*fr].get_rep (); - - tess.add_vertex (vv->coords.fortran_vec (), vv); - } - - tess.end_contour (); - tess.end_polygon (); - } - - if (fl_mode > 0) - glDisable (GL_LIGHTING); - } + { + if (fc_mode == 0) + { + glColor3dv (fcolor.data ()); + if (fl_mode > 0) + { + float cb[4] = { 0, 0, 0, 1 }; + + for (int i = 0; i < 3; i++) + cb[i] = (as * fcolor(i)); + glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); + + for (int i = 0; i < 3; i++) + cb[i] = ds * fcolor(i); + glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); + } + } + + if (fl_mode > 0) + glEnable (GL_LIGHTING); + + // FIXME: use __index__ property from patch object + patch_tesselator tess (this, fc_mode, fl_mode, 0); + + for (int i = 0; i < nf; i++) + { + if (clip_f(i)) + continue; + + tess.begin_polygon (true); + tess.begin_contour (); + + for (int j = 0; j < count_f(i); j++) + { + vertex_data::vertex_data_rep *vv = vdata[i+j*fr].get_rep (); + + tess.add_vertex (vv->coords.fortran_vec (), vv); + } + + tess.end_contour (); + tess.end_polygon (); + } + + if (fl_mode > 0) + glDisable (GL_LIGHTING); + } else - { - // FIXME: implement transparency - } + { + // FIXME: implement transparency + } } if (! props.edgecolor_is ("none")) { // FIXME: adapt to double-radio property if (props.get_edgealpha_double () == 1) - { - if (ec_mode == 0) - { - glColor3dv (ecolor.data ()); - if (el_mode > 0) - { - float cb[4] = { 0, 0, 0, 1 }; - - for (int i = 0; i < 3; i++) - cb[i] = (as * ecolor(i)); - glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); - - for (int i = 0; i < 3; i++) - cb[i] = ds * ecolor(i); - glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); - } - } - - if (el_mode > 0) - glEnable (GL_LIGHTING); - - set_linestyle (props.get_linestyle (), false); - set_linewidth (props.get_linewidth ()); - - // FIXME: use __index__ property from patch object; should we - // offset patch contour as well? - patch_tesselator tess (this, ec_mode, el_mode); - - for (int i = 0; i < nf; i++) - { - if (clip_f(i)) - continue; - - tess.begin_polygon (false); - tess.begin_contour (); - - for (int j = 0; j < count_f(i); j++) - { - vertex_data::vertex_data_rep *vv = vdata[i+j*fr].get_rep (); - - tess.add_vertex (vv->coords.fortran_vec (), vv); - } - - tess.end_contour (); - tess.end_polygon (); - } - - set_linestyle ("-"); - set_linewidth (0.5); - - if (el_mode > 0) - glDisable (GL_LIGHTING); - } + { + if (ec_mode == 0) + { + glColor3dv (ecolor.data ()); + if (el_mode > 0) + { + float cb[4] = { 0, 0, 0, 1 }; + + for (int i = 0; i < 3; i++) + cb[i] = (as * ecolor(i)); + glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb); + + for (int i = 0; i < 3; i++) + cb[i] = ds * ecolor(i); + glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb); + } + } + + if (el_mode > 0) + glEnable (GL_LIGHTING); + + set_linestyle (props.get_linestyle (), false); + set_linewidth (props.get_linewidth ()); + + // FIXME: use __index__ property from patch object; should we + // offset patch contour as well? + patch_tesselator tess (this, ec_mode, el_mode); + + for (int i = 0; i < nf; i++) + { + if (clip_f(i)) + continue; + + tess.begin_polygon (false); + tess.begin_contour (); + + for (int j = 0; j < count_f(i); j++) + { + vertex_data::vertex_data_rep *vv = vdata[i+j*fr].get_rep (); + + tess.add_vertex (vv->coords.fortran_vec (), vv); + } + + tess.end_contour (); + tess.end_polygon (); + } + + set_linestyle ("-"); + set_linewidth (0.5); + + if (el_mode > 0) + glDisable (GL_LIGHTING); + } else - { - // FIXME: implement transparency - } + { + // FIXME: implement transparency + } } if (! props.marker_is ("none") && @@ -2617,37 +2617,37 @@ Matrix cc (1, 3, 0.0); if (mecolor.numel () == 0 && props.markeredgecolor_is ("auto")) - { - mecolor = props.get_edgecolor_rgb (); - do_edge = ! props.edgecolor_is ("none"); - } + { + mecolor = props.get_edgecolor_rgb (); + do_edge = ! props.edgecolor_is ("none"); + } if (mfcolor.numel () == 0 && props.markerfacecolor_is ("auto")) - { - mfcolor = props.get_facecolor_rgb (); - do_face = ! props.facecolor_is ("none"); - } + { + mfcolor = props.get_facecolor_rgb (); + do_face = ! props.facecolor_is ("none"); + } init_marker (props.get_marker (), props.get_markersize (), - props.get_linewidth ()); + props.get_linewidth ()); for (int i = 0; i < nf; i++) - for (int j = 0; j < count_f(i); j++) - { - int idx = int (f(i,j) - 1); - - if (clip(idx)) - continue; - - Matrix lc = (do_edge ? (mecolor.numel () == 0 ? - vdata[i+j*fr].get_rep ()->color : mecolor) - : Matrix ()); - Matrix fc = (do_face ? (mfcolor.numel () == 0 ? - vdata[i+j*fr].get_rep ()->color : mfcolor) - : Matrix ()); - - draw_marker (v(idx,0), v(idx,1), (has_z ? v(idx,2) : 0), lc, fc); - } + for (int j = 0; j < count_f(i); j++) + { + int idx = int (f(i,j) - 1); + + if (clip(idx)) + continue; + + Matrix lc = (do_edge ? (mecolor.numel () == 0 ? + vdata[i+j*fr].get_rep ()->color : mecolor) + : Matrix ()); + Matrix fc = (do_face ? (mfcolor.numel () == 0 ? + vdata[i+j*fr].get_rep ()->color : mfcolor) + : Matrix ()); + + draw_marker (v(idx,0), v(idx,1), (has_z ? v(idx,2) : 0), lc, fc); + } end_marker (); } @@ -2687,8 +2687,8 @@ // FIXME: handle margin and surrounding box render_text (props.get_string (), - pos(0), pos(1), pos(2), - halign, valign, props.get_rotation ()); + pos(0), pos(1), pos(2), + halign, valign, props.get_rotation ()); } void @@ -2748,14 +2748,14 @@ if (props.is_clipping ()) // clip to axes { if (im_xmin < xmin) - j0 += (xmin - im_xmin)/nor_dx + 1; + j0 += (xmin - im_xmin)/nor_dx + 1; if (im_xmax > xmax) - j1 -= (im_xmax - xmax)/nor_dx ; + j1 -= (im_xmax - xmax)/nor_dx ; if (im_ymin < ymin) - i0 += (ymin - im_ymin)/nor_dy + 1; + i0 += (ymin - im_ymin)/nor_dy + 1; if (im_ymax > ymax) - i1 -= (im_ymax - ymax)/nor_dy; + i1 -= (im_ymax - ymax)/nor_dy; } else // clip to viewport { @@ -2778,66 +2778,66 @@ if (dv.length () == 3 && dv(2) == 3) { if (cdata.is_double_type ()) - { - const NDArray xcdata = cdata.array_value (); - - OCTAVE_LOCAL_BUFFER (GLfloat, a, 3*(j1-j0)*(i1-i0)); - - for (int i = i0; i < i1; i++) - { - for (int j = j0, idx = (i-i0)*(j1-j0)*3; j < j1; j++, idx += 3) - { - a[idx] = xcdata(i,j,0); - a[idx+1] = xcdata(i,j,1); - a[idx+2] = xcdata(i,j,2); - } - } - - draw_pixels (j1-j0, i1-i0, GL_RGB, GL_FLOAT, a); - - } + { + const NDArray xcdata = cdata.array_value (); + + OCTAVE_LOCAL_BUFFER (GLfloat, a, 3*(j1-j0)*(i1-i0)); + + for (int i = i0; i < i1; i++) + { + for (int j = j0, idx = (i-i0)*(j1-j0)*3; j < j1; j++, idx += 3) + { + a[idx] = xcdata(i,j,0); + a[idx+1] = xcdata(i,j,1); + a[idx+2] = xcdata(i,j,2); + } + } + + draw_pixels (j1-j0, i1-i0, GL_RGB, GL_FLOAT, a); + + } else if (cdata.is_uint16_type ()) - { - const uint16NDArray xcdata = cdata.uint16_array_value (); - - OCTAVE_LOCAL_BUFFER (GLushort, a, 3*(j1-j0)*(i1-i0)); - - for (int i = i0; i < i1; i++) - { - for (int j = j0, idx = (i-i0)*(j1-j0)*3; j < j1; j++, idx += 3) - { - a[idx] = xcdata(i,j,0); - a[idx+1] = xcdata(i,j,1); - a[idx+2] = xcdata(i,j,2); - } - } - - draw_pixels (j1-j0, i1-i0, GL_RGB, GL_UNSIGNED_SHORT, a); - - } + { + const uint16NDArray xcdata = cdata.uint16_array_value (); + + OCTAVE_LOCAL_BUFFER (GLushort, a, 3*(j1-j0)*(i1-i0)); + + for (int i = i0; i < i1; i++) + { + for (int j = j0, idx = (i-i0)*(j1-j0)*3; j < j1; j++, idx += 3) + { + a[idx] = xcdata(i,j,0); + a[idx+1] = xcdata(i,j,1); + a[idx+2] = xcdata(i,j,2); + } + } + + draw_pixels (j1-j0, i1-i0, GL_RGB, GL_UNSIGNED_SHORT, a); + + } else if (cdata.is_uint8_type ()) - { - const uint8NDArray xcdata = cdata.uint8_array_value (); - - OCTAVE_LOCAL_BUFFER (GLubyte, a, 3*(j1-j0)*(i1-i0)); - - for (int i = i0; i < i1; i++) - { - for (int j = j0, idx = (i-i0)*(j1-j0)*3; j < j1; j++, idx += 3) - { - a[idx] = xcdata(i,j,0); - a[idx+1] = xcdata(i,j,1); - a[idx+2] = xcdata(i,j,2); - } - } - - draw_pixels (j1-j0, i1-i0, GL_RGB, GL_UNSIGNED_BYTE, a); - } + { + const uint8NDArray xcdata = cdata.uint8_array_value (); + + OCTAVE_LOCAL_BUFFER (GLubyte, a, 3*(j1-j0)*(i1-i0)); + + for (int i = i0; i < i1; i++) + { + for (int j = j0, idx = (i-i0)*(j1-j0)*3; j < j1; j++, idx += 3) + { + a[idx] = xcdata(i,j,0); + a[idx+1] = xcdata(i,j,1); + a[idx+2] = xcdata(i,j,2); + } + } + + draw_pixels (j1-j0, i1-i0, GL_RGB, GL_UNSIGNED_BYTE, a); + } else - { - ok = false; - warning ("opengl_texture::draw: invalid image data type (expected double, uint16, or uint8)"); - } + { + ok = false; + warning ("opengl_texture::draw: invalid image data type (expected double, uint16, or uint8)"); + } } else { @@ -2926,7 +2926,7 @@ void opengl_renderer::set_clipbox (double x1, double x2, double y1, double y2, - double z1, double z2) + double z1, double z2) { double dx = (x2-x1); double dy = (y2-y1); @@ -3012,7 +3012,7 @@ void opengl_renderer::draw_marker (double x, double y, double z, - const Matrix& lc, const Matrix& fc) + const Matrix& lc, const Matrix& fc) { ColumnVector tmp = xform.transform (x, y, z, false); @@ -3025,14 +3025,14 @@ set_polygon_offset (true, -1.0); glCallList (filled_marker_id); if (lc.numel () > 0) - { - glColor3dv (lc.data ()); - glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); - glEdgeFlag (GL_TRUE); - set_polygon_offset (true, -2.0); - glCallList (filled_marker_id); - glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); - } + { + glColor3dv (lc.data ()); + glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); + glEdgeFlag (GL_TRUE); + set_polygon_offset (true, -2.0); + glCallList (filled_marker_id); + glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); + } set_polygon_offset (false); } else if (marker_id > 0 && lc.numel () > 0) @@ -3044,7 +3044,7 @@ unsigned int opengl_renderer::make_marker_list (const std::string& marker, double size, - bool filled) const + bool filled) const { char c = marker[0]; @@ -3108,12 +3108,12 @@ break; case 'o': { - double ang_step = M_PI / 5; - - glBegin ((filled ? GL_POLYGON : GL_LINE_LOOP)); - for (double ang = 0; ang < (2*M_PI); ang += ang_step) - glVertex2d (sz*cos(ang)/2, sz*sin(ang)/2); - glEnd (); + double ang_step = M_PI / 5; + + glBegin ((filled ? GL_POLYGON : GL_LINE_LOOP)); + for (double ang = 0; ang < (2*M_PI); ang += ang_step) + glVertex2d (sz*cos(ang)/2, sz*sin(ang)/2); + glEnd (); } break; case 'd': @@ -3154,7 +3154,7 @@ break; default: warning ("opengl_renderer: unsupported marker `%s'", - marker.c_str ()); + marker.c_str ()); break; } @@ -3165,10 +3165,10 @@ void opengl_renderer::text_to_pixels (const std::string& txt, - double rotation, - uint8NDArray& pixels, - Matrix& bbox, - int& rot_mode) + double rotation, + uint8NDArray& pixels, + Matrix& bbox, + int& rot_mode) { // FIXME: clip "rotation" between 0 and 360 @@ -3188,8 +3188,8 @@ Matrix opengl_renderer::render_text (const std::string& txt, - double x, double y, double z, - int halign, int valign, double rotation) + double x, double y, double z, + int halign, int valign, double rotation) { #if HAVE_FREETYPE if (txt.empty ()) @@ -3248,7 +3248,7 @@ glRasterPos3d (x, y, z); glBitmap(0, 0, 0, 0, x0, y0, 0); glDrawPixels (w, h, - GL_RGBA, GL_UNSIGNED_BYTE, pixels.data ()); + GL_RGBA, GL_UNSIGNED_BYTE, pixels.data ()); glDisable (GL_ALPHA_TEST); if (! blend) glDisable (GL_BLEND); diff --git a/src/gl2ps-renderer.cc b/src/gl2ps-renderer.cc --- a/src/gl2ps-renderer.cc +++ b/src/gl2ps-renderer.cc @@ -50,18 +50,18 @@ glGetIntegerv (GL_VIEWPORT, viewport); while (state == GL2PS_OVERFLOW) - { - buffsize += 1024*1024; - gl2psBeginPage ("glps_renderer figure", "Octave", viewport, - GL2PS_EPS, GL2PS_BSP_SORT, - (GL2PS_SILENT | GL2PS_SIMPLE_LINE_OFFSET - | GL2PS_NO_BLENDING | GL2PS_OCCLUSION_CULL - | GL2PS_BEST_ROOT), GL_RGBA, 0, NULL, 0, 0, 0, - buffsize, fp, filename.c_str () ); + { + buffsize += 1024*1024; + gl2psBeginPage ("glps_renderer figure", "Octave", viewport, + GL2PS_EPS, GL2PS_BSP_SORT, + (GL2PS_SILENT | GL2PS_SIMPLE_LINE_OFFSET + | GL2PS_NO_BLENDING | GL2PS_OCCLUSION_CULL + | GL2PS_BEST_ROOT), GL_RGBA, 0, NULL, 0, 0, 0, + buffsize, fp, filename.c_str () ); - opengl_renderer::draw (go); - state = gl2psEndPage (); - } + opengl_renderer::draw (go); + state = gl2psEndPage (); + } fclose (fp); @@ -73,8 +73,8 @@ Matrix glps_renderer::render_text (const std::string& txt, - double x, double y, double z, - int ha, int va, double rotation) + double x, double y, double z, + int ha, int va, double rotation) { if (txt.empty ()) return Matrix (1, 4, 0.0); @@ -83,29 +83,29 @@ if (ha == 0) { if (va == 0 || va == 3) - gl2psa=GL2PS_TEXT_BL; + gl2psa=GL2PS_TEXT_BL; else if (va == 2) - gl2psa=GL2PS_TEXT_TL; + gl2psa=GL2PS_TEXT_TL; else if (va == 1) - gl2psa=GL2PS_TEXT_CL; + gl2psa=GL2PS_TEXT_CL; } else if (ha == 2) { if (va == 0 || va == 3) - gl2psa=GL2PS_TEXT_BR; + gl2psa=GL2PS_TEXT_BR; else if (va == 2) - gl2psa=GL2PS_TEXT_TR; + gl2psa=GL2PS_TEXT_TR; else if (va == 1) - gl2psa=GL2PS_TEXT_CR; + gl2psa=GL2PS_TEXT_CR; } else if (ha == 1) { if (va == 0 || va == 3) - gl2psa=GL2PS_TEXT_B; + gl2psa=GL2PS_TEXT_B; else if (va == 2) - gl2psa=GL2PS_TEXT_T; + gl2psa=GL2PS_TEXT_T; else if (va == 1) - gl2psa=GL2PS_TEXT_C; + gl2psa=GL2PS_TEXT_C; } glRasterPos3d (x, y, z); diff --git a/src/graphics.cc b/src/graphics.cc --- a/src/graphics.cc +++ b/src/graphics.cc @@ -67,8 +67,8 @@ static caseless_str validate_property_name (const std::string& who, const std::string& what, - const std::set& pnames, - const caseless_str& pname) + const std::set& pnames, + const caseless_str& pname) { size_t len = pname.length (); std::set matches; @@ -77,15 +77,15 @@ p != pnames.end (); p++) { if (pname.compare (*p, len)) - { - if (len == p->length ()) - { - // Exact match. - return pname; - } - - matches.insert (*p); - } + { + if (len == p->length ()) + { + // Exact match. + return pname; + } + + matches.insert (*p); + } } size_t num_matches = matches.size (); @@ -93,7 +93,7 @@ if (num_matches == 0) { error ("%s: unknown %s property %s", - who.c_str (), what.c_str (), pname.c_str ()); + who.c_str (), what.c_str (), pname.c_str ()); } else if (num_matches > 1) { @@ -106,7 +106,7 @@ std::string match_list = os.str (); error ("%s: ambiguous %s property name %s; possible matches:\n\n%s", - who.c_str (), what.c_str (), pname.c_str (), match_list.c_str ()); + who.c_str (), what.c_str (), pname.c_str (), match_list.c_str ()); } else if (num_matches == 1) { @@ -115,9 +115,9 @@ std::string possible_match = *(matches.begin ()); warning_with_id ("Octave:abbreviated-property-match", - "%s: allowing %s to match %s property %s", - who.c_str (), pname.c_str (), what.c_str (), - possible_match.c_str ()); + "%s: allowing %s to match %s property %s", + who.c_str (), pname.c_str (), what.c_str (), + possible_match.c_str ()); return possible_match; } @@ -308,8 +308,8 @@ static Matrix convert_position (const Matrix& pos, const caseless_str& from_units, - const caseless_str& to_units, - const Matrix& parent_dim = Matrix (1, 2, 0.0)) + const caseless_str& to_units, + const Matrix& parent_dim = Matrix (1, 2, 0.0)) { Matrix retval (1, 4); double res = 0; @@ -326,7 +326,7 @@ else if (from_units.compare ("characters")) { if (res <= 0) - res = xget (0, "screenpixelsperinch").double_value (); + res = xget (0, "screenpixelsperinch").double_value (); double f = 0.0; @@ -335,84 +335,84 @@ f = 12.0 * res / 74.951; if (f > 0) - { - retval(0) = 0.5 * pos(0) * f; - retval(1) = pos(1) * f; - retval(2) = 0.5 * pos(2) * f; - retval(3) = pos(3) * f; - } + { + retval(0) = 0.5 * pos(0) * f; + retval(1) = pos(1) * f; + retval(2) = 0.5 * pos(2) * f; + retval(3) = pos(3) * f; + } } else { if (res <= 0) - res = xget (0, "screenpixelsperinch").double_value (); + res = xget (0, "screenpixelsperinch").double_value (); double f = 0.0; if (from_units.compare ("points")) - f = res / 72.0; + f = res / 72.0; else if (from_units.compare ("inches")) - f = res; + f = res; else if (from_units.compare ("centimeters")) - f = res / 2.54; + f = res / 2.54; if (f > 0) - { - retval(0) = pos(0) * f + 1; - retval(1) = pos(1) * f + 1; - retval(2) = pos(2) * f; - retval(3) = pos(3) * f; - } + { + retval(0) = pos(0) * f + 1; + retval(1) = pos(1) * f + 1; + retval(2) = pos(2) * f; + retval(3) = pos(3) * f; + } } if (! to_units.compare ("pixels")) { if (to_units.compare ("normalized")) - { - retval(0) = (retval(0) - 1) / parent_dim(0); - retval(1) = (retval(1) - 1) / parent_dim(1); - retval(2) /= parent_dim(0); - retval(3) /= parent_dim(1); - } + { + retval(0) = (retval(0) - 1) / parent_dim(0); + retval(1) = (retval(1) - 1) / parent_dim(1); + retval(2) /= parent_dim(0); + retval(3) /= parent_dim(1); + } else if (to_units.compare ("characters")) - { - if (res <= 0) - res = xget (0, "screenpixelsperinch").double_value (); - - double f = 0.0; - - f = 12.0 * res / 74.951; - - if (f > 0) - { - retval(0) = 2 * retval(0) / f; - retval(1) = retval(1) / f; - retval(2) = 2 * retval(2) / f; - retval(3) = retval(3) / f; - } - } + { + if (res <= 0) + res = xget (0, "screenpixelsperinch").double_value (); + + double f = 0.0; + + f = 12.0 * res / 74.951; + + if (f > 0) + { + retval(0) = 2 * retval(0) / f; + retval(1) = retval(1) / f; + retval(2) = 2 * retval(2) / f; + retval(3) = retval(3) / f; + } + } else - { - if (res <= 0) - res = xget (0, "screenpixelsperinch").double_value (); - - double f = 0.0; - - if (to_units.compare ("points")) - f = res / 72.0; - else if (to_units.compare ("inches")) - f = res; - else if (to_units.compare ("centimeters")) - f = res / 2.54; - - if (f > 0) - { - retval(0) = (retval(0) - 1) / f; - retval(1) = (retval(1) - 1) / f; - retval(2) /= f; - retval(3) /= f; - } - } + { + if (res <= 0) + res = xget (0, "screenpixelsperinch").double_value (); + + double f = 0.0; + + if (to_units.compare ("points")) + f = res / 72.0; + else if (to_units.compare ("inches")) + f = res; + else if (to_units.compare ("centimeters")) + f = res / 2.54; + + if (f > 0) + { + retval(0) = (retval(0) - 1) / f; + retval(1) = (retval(1) - 1) / f; + retval(2) /= f; + retval(3) /= f; + } + } } return retval; @@ -426,21 +426,21 @@ do { if (go.valid_object ()) - { - if (go.isa (type)) - return go; - else - go = gh_manager::get_object (go.get_parent ()); - } + { + if (go.isa (type)) + return go; + else + go = gh_manager::get_object (go.get_parent ()); + } else - return graphics_object (); + return graphics_object (); } while (true); } static octave_value convert_cdata (const base_properties& props, const octave_value& cdata, - bool is_scaled, int cdim) + bool is_scaled, int cdim) { dim_vector dv (cdata.dims ()); @@ -458,7 +458,7 @@ Matrix _cmap = fig.get (caseless_str ("colormap")).matrix_value (); if (! error_state) - cmap = _cmap; + cmap = _cmap; } if (is_scaled) @@ -466,12 +466,12 @@ graphics_object ax = xget_ancestor (go, "axes"); if (ax.valid_object ()) - { - Matrix _clim = ax.get (caseless_str ("clim")).matrix_value (); - - if (! error_state) - clim = _clim; - } + { + Matrix _clim = ax.get (caseless_str ("clim")).matrix_value (); + + if (! error_state) + clim = _clim; + } } dv.resize (cdim); @@ -497,29 +497,29 @@ double x = (cv ? cv[i] : double (icv[i])); if (is_scaled) - x = xround ((nc - 1) * (x - clim(0)) / (clim(1) - clim(0))); + x = xround ((nc - 1) * (x - clim(0)) / (clim(1) - clim(0))); else - x = xround (x - 1); + x = xround (x - 1); if (xisnan (x)) - { - av[i] = x; - av[i+lda] = x; - av[i+2*lda] = x; - } + { + av[i] = x; + av[i+lda] = x; + av[i+2*lda] = x; + } else - { - if (x < 0) - x = 0; - else if (x >= nc) - x = (nc - 1); - - octave_idx_type idx = static_cast (x); - - av[i] = cmapv[idx]; - av[i+lda] = cmapv[idx+nc]; - av[i+2*lda] = cmapv[idx+2*nc]; - } + { + if (x < 0) + x = 0; + else if (x >= nc) + x = (nc - 1); + + octave_idx_type idx = static_cast (x); + + av[i] = cmapv[idx]; + av[i+lda] = cmapv[idx+nc]; + av[i+2*lda] = cmapv[idx+2*nc]; + } } return octave_value (a); @@ -528,7 +528,7 @@ template static void get_array_limits (const Array& m, double& emin, double& emax, - double& eminp) + double& eminp) { const T *data = m.data (); octave_idx_type n = m.numel (); @@ -538,22 +538,22 @@ double e = double (data[i]); if (! (xisinf (e) || xisnan (e))) - { - if (e < emin) - emin = e; - - if (e > emax) - emax = e; - - if (e > 0 && e < eminp) - eminp = e; - } + { + if (e < emin) + emin = e; + + if (e > emax) + emax = e; + + if (e > 0 && e < eminp) + eminp = e; + } } } static bool lookup_object_name (const caseless_str& name, caseless_str& go_name, - caseless_str& rest) + caseless_str& rest) { int len = name.length (); int offset = 0; @@ -564,36 +564,36 @@ caseless_str pfx = name.substr (0, 4); if (pfx.compare ("axes") || pfx.compare ("line") - || pfx.compare ("text")) - offset = 4; + || pfx.compare ("text")) + offset = 4; else if (len >= 5) - { - pfx = name.substr (0, 5); - - if (pfx.compare ("image") || pfx.compare ("patch")) - offset = 5; - else if (len >= 6) - { - pfx = name.substr (0, 6); - - if (pfx.compare ("figure")) - offset = 6; - else if (len >= 7) - { - pfx = name.substr (0, 7); - - if (pfx.compare ("surface") || pfx.compare ("hggroup")) - offset = 7; - } - } - } + { + pfx = name.substr (0, 5); + + if (pfx.compare ("image") || pfx.compare ("patch")) + offset = 5; + else if (len >= 6) + { + pfx = name.substr (0, 6); + + if (pfx.compare ("figure")) + offset = 6; + else if (len >= 7) + { + pfx = name.substr (0, 7); + + if (pfx.compare ("surface") || pfx.compare ("hggroup")) + offset = 7; + } + } + } if (offset > 0) - { - go_name = pfx; - rest = name.substr (offset); - result = true; - } + { + go_name = pfx; + rest = name.substr (offset); + result = true; + } } return result; @@ -601,8 +601,8 @@ static base_graphics_object* make_graphics_object_from_type (const caseless_str& type, - const graphics_handle& h = graphics_handle (), - const graphics_handle& p = graphics_handle ()) + const graphics_handle& h = graphics_handle (), + const graphics_handle& p = graphics_handle ()) { base_graphics_object *go = 0; @@ -636,19 +636,19 @@ // notify backend if (id >= 0) - { - graphics_object go = gh_manager::get_object (parent); - if (go) - { - graphics_backend backend = go.get_backend(); - if (backend) - backend.property_changed (go, id); - } - } + { + graphics_object go = gh_manager::get_object (parent); + if (go) + { + graphics_backend backend = go.get_backend(); + if (backend) + backend.property_changed (go, id); + } + } // run listeners if (do_run && ! error_state) - run_listeners (POSTSET); + run_listeners (POSTSET); return true; } @@ -667,7 +667,7 @@ gh_manager::execute_callback (parent, l(i), octave_value ()); if (error_state) - break; + break; } } @@ -682,21 +682,21 @@ size_t end = opt_string.find ('|', beg); if (end == std::string::npos) - { - end = len; - done = true; - } + { + end = len; + done = true; + } std::string t = opt_string.substr (beg, end-beg); // Might want more error checking here... if (t[0] == '{') - { - t = t.substr (1, t.length () - 2); - default_val = t; - } + { + t = t.substr (1, t.length () - 2); + default_val = t; + } else if (beg == 0) // ensure default value - default_val = t; + default_val = t; possible_vals.insert (t); @@ -716,7 +716,7 @@ if (str.compare(0, len, "blue", 0, len) == 0) tmp_rgb[2] = 1; else if (str.compare(0, len, "black", 0, len) == 0 - || str.compare(0, len, "k", 0, len) == 0) + || str.compare(0, len, "k", 0, len) == 0) tmp_rgb[0] = tmp_rgb[1] = tmp_rgb[2] = 0; else if (str.compare(0, len, "red", 0, len) == 0) tmp_rgb[0] = 1; @@ -729,15 +729,15 @@ else if (str.compare(0, len, "cyan", 0, len) == 0) tmp_rgb[1] = tmp_rgb[2] = 1; else if (str.compare(0, len, "white", 0, len) == 0 - || str.compare(0, len, "w", 0, len) == 0) + || str.compare(0, len, "w", 0, len) == 0) tmp_rgb[0] = tmp_rgb[1] = tmp_rgb[2] = 1; - else + else retval = false; if (retval) { for (int i = 0; i < 3; i++) - xrgb(i) = tmp_rgb[i]; + xrgb(i) = tmp_rgb[i]; } return retval; @@ -751,35 +751,35 @@ std::string s = val.string_value (); if (! s.empty ()) - { - if (radio_val.contains (s)) - { - if (current_type != radio_t || current_val != s) - { - current_val = s; - current_type = radio_t; - return true; - } - } + { + if (radio_val.contains (s)) + { + if (current_type != radio_t || current_val != s) + { + current_val = s; + current_type = radio_t; + return true; + } + } else - { - color_values col (s); - if (! error_state) - { - if (current_type != color_t || col != color_val) - { - color_val = col; - current_type = color_t; - return true; - } - } - else - error ("invalid value for color property \"%s\" (value = %s)", - get_name ().c_str (), s.c_str ()); - } - } + { + color_values col (s); + if (! error_state) + { + if (current_type != color_t || col != color_val) + { + color_val = col; + current_type = color_t; + return true; + } + } + else + error ("invalid value for color property \"%s\" (value = %s)", + get_name ().c_str (), s.c_str ()); + } + } else - error ("invalid value for color property \"%s\"", + error ("invalid value for color property \"%s\"", get_name ().c_str ()); } else if (val.is_numeric_type ()) @@ -787,20 +787,20 @@ Matrix m = val.matrix_value (); if (m.numel () == 3) - { - color_values col (m (0), m (1), m(2)); - if (! error_state) - { - if (current_type != color_t || col != color_val) - { - color_val = col; - current_type = color_t; - return true; - } - } - } + { + color_values col (m (0), m (1), m(2)); + if (! error_state) + { + if (current_type != color_t || col != color_val) + { + color_val = col; + current_type = color_t; + return true; + } + } + } else - error ("invalid value for color property \"%s\"", + error ("invalid value for color property \"%s\"", get_name ().c_str ()); } else @@ -818,32 +818,32 @@ std::string s = val.string_value (); if (! s.empty () && radio_val.contains (s)) - { - if (current_type != radio_t || s != current_val) - { - current_val = s; - current_type = radio_t; - return true; - } - } + { + if (current_type != radio_t || s != current_val) + { + current_val = s; + current_type = radio_t; + return true; + } + } else - error ("invalid value for double_radio property \"%s\"", - get_name ().c_str ()); + error ("invalid value for double_radio property \"%s\"", + get_name ().c_str ()); } else if (val.is_scalar_type () && val.is_real_type ()) { double new_dval = val.double_value (); if (current_type != double_t || new_dval != dval) - { - dval = new_dval; - current_type = double_t; - return true; - } + { + dval = new_dval; + current_type = double_t; + return true; + } } else error ("invalid value for double_radio property \"%s\"", - get_name ().c_str ()); + get_name ().c_str ()); return false; } @@ -904,53 +904,53 @@ if (data.type_name () == v.type_name ()) { if (data.dims () == v.dims ()) - { + { #define CHECK_ARRAY_EQUAL(T,F,A) \ - { \ - if (data.numel () == 1) \ - return data.F ## scalar_value () == \ - v.F ## scalar_value (); \ - else \ - { \ + { \ + if (data.numel () == 1) \ + return data.F ## scalar_value () == \ + v.F ## scalar_value (); \ + else \ + { \ /* Keep copy of array_value to allow sparse/bool arrays */ \ - /* that are converted, to not be deallocated early */ \ - const A m1 = data.F ## array_value (); \ - const T* d1 = m1.data (); \ - const A m2 = v.F ## array_value (); \ - const T* d2 = m2.data ();\ - \ - bool flag = true; \ - \ - for (int i = 0; flag && i < data.numel (); i++) \ - if (d1[i] != d2[i]) \ - flag = false; \ - \ - return flag; \ - } \ - } - - if (data.is_double_type() || data.is_bool_type ()) - CHECK_ARRAY_EQUAL (double, , NDArray) - else if (data.is_single_type ()) - CHECK_ARRAY_EQUAL (float, float_, FloatNDArray) - else if (data.is_int8_type ()) - CHECK_ARRAY_EQUAL (octave_int8, int8_, int8NDArray) - else if (data.is_int16_type ()) - CHECK_ARRAY_EQUAL (octave_int16, int16_, int16NDArray) - else if (data.is_int32_type ()) - CHECK_ARRAY_EQUAL (octave_int32, int32_, int32NDArray) - else if (data.is_int64_type ()) - CHECK_ARRAY_EQUAL (octave_int64, int64_, int64NDArray) - else if (data.is_uint8_type ()) - CHECK_ARRAY_EQUAL (octave_uint8, uint8_, uint8NDArray) - else if (data.is_uint16_type ()) - CHECK_ARRAY_EQUAL (octave_uint16, uint16_, uint16NDArray) - else if (data.is_uint32_type ()) - CHECK_ARRAY_EQUAL (octave_uint32, uint32_, uint32NDArray) - else if (data.is_uint64_type ()) - CHECK_ARRAY_EQUAL (octave_uint64, uint64_, uint64NDArray) - } + /* that are converted, to not be deallocated early */ \ + const A m1 = data.F ## array_value (); \ + const T* d1 = m1.data (); \ + const A m2 = v.F ## array_value (); \ + const T* d2 = m2.data ();\ + \ + bool flag = true; \ + \ + for (int i = 0; flag && i < data.numel (); i++) \ + if (d1[i] != d2[i]) \ + flag = false; \ + \ + return flag; \ + } \ + } + + if (data.is_double_type() || data.is_bool_type ()) + CHECK_ARRAY_EQUAL (double, , NDArray) + else if (data.is_single_type ()) + CHECK_ARRAY_EQUAL (float, float_, FloatNDArray) + else if (data.is_int8_type ()) + CHECK_ARRAY_EQUAL (octave_int8, int8_, int8NDArray) + else if (data.is_int16_type ()) + CHECK_ARRAY_EQUAL (octave_int16, int16_, int16NDArray) + else if (data.is_int32_type ()) + CHECK_ARRAY_EQUAL (octave_int32, int32_, int32NDArray) + else if (data.is_int64_type ()) + CHECK_ARRAY_EQUAL (octave_int64, int64_, int64NDArray) + else if (data.is_uint8_type ()) + CHECK_ARRAY_EQUAL (octave_uint8, uint8_, uint8NDArray) + else if (data.is_uint16_type ()) + CHECK_ARRAY_EQUAL (octave_uint16, uint16_, uint16NDArray) + else if (data.is_uint32_type ()) + CHECK_ARRAY_EQUAL (octave_uint32, uint32_, uint32NDArray) + else if (data.is_uint64_type ()) + CHECK_ARRAY_EQUAL (octave_uint64, uint64_, uint64NDArray) + } } return false; @@ -965,26 +965,26 @@ if (! data.is_empty ()) { if (data.is_integer_type ()) - { - if (data.is_int8_type ()) - get_array_limits (data.int8_array_value (), xmin, xmax, xminp); - else if (data.is_uint8_type ()) - get_array_limits (data.uint8_array_value (), xmin, xmax, xminp); - else if (data.is_int16_type ()) - get_array_limits (data.int16_array_value (), xmin, xmax, xminp); - else if (data.is_uint16_type ()) - get_array_limits (data.uint16_array_value (), xmin, xmax, xminp); - else if (data.is_int32_type ()) - get_array_limits (data.int32_array_value (), xmin, xmax, xminp); - else if (data.is_uint32_type ()) - get_array_limits (data.uint32_array_value (), xmin, xmax, xminp); - else if (data.is_int64_type ()) - get_array_limits (data.int64_array_value (), xmin, xmax, xminp); - else if (data.is_uint64_type ()) - get_array_limits (data.uint64_array_value (), xmin, xmax, xminp); - } + { + if (data.is_int8_type ()) + get_array_limits (data.int8_array_value (), xmin, xmax, xminp); + else if (data.is_uint8_type ()) + get_array_limits (data.uint8_array_value (), xmin, xmax, xminp); + else if (data.is_int16_type ()) + get_array_limits (data.int16_array_value (), xmin, xmax, xminp); + else if (data.is_uint16_type ()) + get_array_limits (data.uint16_array_value (), xmin, xmax, xminp); + else if (data.is_int32_type ()) + get_array_limits (data.int32_array_value (), xmin, xmax, xminp); + else if (data.is_uint32_type ()) + get_array_limits (data.uint32_array_value (), xmin, xmax, xminp); + else if (data.is_int64_type ()) + get_array_limits (data.int64_array_value (), xmin, xmax, xminp); + else if (data.is_uint64_type ()) + get_array_limits (data.uint64_array_value (), xmin, xmax, xminp); + } else - get_array_limits (data.array_value (), xmin, xmax, xminp); + get_array_limits (data.array_value (), xmin, xmax, xminp); } } @@ -998,20 +998,20 @@ graphics_handle gh = gh_manager::lookup (dv); if (xisnan (gh.value ()) || gh.ok ()) - { - if (current_val != gh) - { - current_val = gh; - return true; - } - } + { + if (current_val != gh) + { + current_val = gh; + return true; + } + } else error ("set: invalid graphics handle (= %g) for property \"%s\"", - dv, get_name ().c_str ()); + dv, get_name ().c_str ()); } else error ("set: invalid graphics handle for property \"%s\"", - get_name ().c_str ()); + get_name ().c_str ()); return false; } @@ -1053,7 +1053,7 @@ property property::create (const std::string& name, const graphics_handle& h, - const caseless_str& type, const octave_value_list& args) + const caseless_str& type, const octave_value_list& args) { property retval; @@ -1062,70 +1062,70 @@ std::string val = (args.length () > 0 ? args(0).string_value () : ""); if (! error_state) - retval = property (new string_property (name, h, val)); + retval = property (new string_property (name, h, val)); } else if (type.compare ("any")) { octave_value val = - (args.length () > 0 ? args(0) : octave_value (Matrix ())); + (args.length () > 0 ? args(0) : octave_value (Matrix ())); retval = property (new any_property (name, h, val)); } else if (type.compare ("radio")) { if (args.length () > 0) - { - std::string vals = args(0).string_value (); - - if (! error_state) - { - retval = property (new radio_property (name, h, vals)); - - if (args.length () > 1) - retval.set (args(1)); - } - else - error ("addproperty: invalid argument for radio property, expected a string value"); - } + { + std::string vals = args(0).string_value (); + + if (! error_state) + { + retval = property (new radio_property (name, h, vals)); + + if (args.length () > 1) + retval.set (args(1)); + } + else + error ("addproperty: invalid argument for radio property, expected a string value"); + } else - error ("addproperty: missing possible values for radio property"); + error ("addproperty: missing possible values for radio property"); } else if (type.compare ("double")) { double d = (args.length () > 0 ? args(0).double_value () : 0); if (! error_state) - retval = property (new double_property (name, h, d)); + retval = property (new double_property (name, h, d)); } else if (type.compare ("handle")) { double hh = (args.length () > 0 ? args(0).double_value () : octave_NaN); if (! error_state) - { - graphics_handle gh (hh); - - retval = property (new handle_property (name, h, gh)); - } + { + graphics_handle gh (hh); + + retval = property (new handle_property (name, h, gh)); + } } else if (type.compare ("boolean")) { retval = property (new bool_property (name, h, false)); if (args.length () > 0) - retval.set (args(0)); + retval.set (args(0)); } else if (type.compare ("data")) { retval = property (new array_property (name, h, Matrix ())); if (args.length () > 0) - { - retval.set (args(0)); - - // FIXME -- additional argument could define constraints, - // but is this really useful? - } + { + retval.set (args(0)); + + // FIXME -- additional argument could define constraints, + // but is this really useful? + } } else if (type.compare ("color")) { @@ -1133,69 +1133,69 @@ radio_values rv; if (args.length () > 1) - rv = radio_values (args(1).string_value ()); + rv = radio_values (args(1).string_value ()); if (! error_state) - { - retval = property (new color_property (name, h, cv, rv)); - - if (! error_state) - { - if (args.length () > 0 && ! args(0).is_empty ()) - retval.set (args(0)); - else - retval.set (rv.default_value ()); - } - } + { + retval = property (new color_property (name, h, cv, rv)); + + if (! error_state) + { + if (args.length () > 0 && ! args(0).is_empty ()) + retval.set (args(0)); + else + retval.set (rv.default_value ()); + } + } } else { caseless_str go_name, go_rest; if (lookup_object_name (type, go_name, go_rest)) - { - graphics_object go; - - std::map::const_iterator it = - dprop_obj_map.find (go_name); - - if (it == dprop_obj_map.end ()) - { - base_graphics_object *bgo = - make_graphics_object_from_type (go_name); - - if (bgo) - { - go = graphics_object (bgo); - - dprop_obj_map[go_name] = go; - } - } - else - go = it->second; - - if (go.valid_object ()) - { - property prop = go.get_properties ().get_property (go_rest); - - if (! error_state) - { - retval = prop.clone (); - - retval.set_parent (h); - retval.set_name (name); - - if (args.length () > 0) - retval.set (args(0)); - } - } - else - error ("addproperty: invalid object type (= %s)", - go_name.c_str ()); - } + { + graphics_object go; + + std::map::const_iterator it = + dprop_obj_map.find (go_name); + + if (it == dprop_obj_map.end ()) + { + base_graphics_object *bgo = + make_graphics_object_from_type (go_name); + + if (bgo) + { + go = graphics_object (bgo); + + dprop_obj_map[go_name] = go; + } + } + else + go = it->second; + + if (go.valid_object ()) + { + property prop = go.get_properties ().get_property (go_rest); + + if (! error_state) + { + retval = prop.clone (); + + retval.set_parent (h); + retval.set_name (name); + + if (args.length () > 0) + retval.set (args(0)); + } + } + else + error ("addproperty: invalid object type (= %s)", + go_name.c_str ()); + } else - error ("addproperty: unsupported type for dynamic property (= %s)", - type.c_str ()); + error ("addproperty: unsupported type for dynamic property (= %s)", + type.c_str ()); } return retval; @@ -1215,82 +1215,82 @@ caseless_str pfx = name.substr (0, 4); if (pfx.compare ("axes") || pfx.compare ("line") - || pfx.compare ("text")) - offset = 4; + || pfx.compare ("text")) + offset = 4; else if (len > 5) - { - pfx = name.substr (0, 5); - - if (pfx.compare ("image") || pfx.compare ("patch")) - offset = 5; - else if (len > 6) - { - pfx = name.substr (0, 6); - - if (pfx.compare ("figure")) - offset = 6; - else if (len > 7) - { - pfx = name.substr (0, 7); - - if (pfx.compare ("surface") || pfx.compare ("hggroup")) - offset = 7; - } - } - } + { + pfx = name.substr (0, 5); + + if (pfx.compare ("image") || pfx.compare ("patch")) + offset = 5; + else if (len > 6) + { + pfx = name.substr (0, 6); + + if (pfx.compare ("figure")) + offset = 6; + else if (len > 7) + { + pfx = name.substr (0, 7); + + if (pfx.compare ("surface") || pfx.compare ("hggroup")) + offset = 7; + } + } + } if (offset > 0) - { - // FIXME -- should we validate property names and values here? - - std::string pname = name.substr (offset); - - std::transform (pfx.begin (), pfx.end (), pfx.begin (), tolower); - std::transform (pname.begin (), pname.end (), pname.begin (), tolower); - - bool has_property = false; - if (pfx == "axes") - has_property = axes::properties::has_core_property (pname); - else if (pfx == "line") - has_property = line::properties::has_core_property (pname); - else if (pfx == "text") - has_property = text::properties::has_core_property (pname); - else if (pfx == "image") - has_property = image::properties::has_core_property (pname); - else if (pfx == "patch") - has_property = patch::properties::has_core_property (pname); - else if (pfx == "figure") - has_property = figure::properties::has_core_property (pname); - else if (pfx == "surface") - has_property = surface::properties::has_core_property (pname); - else if (pfx == "hggroup") - has_property = hggroup::properties::has_core_property (pname); - - if (has_property) - { - bool remove = false; - if (val.is_string ()) - { - caseless_str tval = val.string_value (); - - remove = tval.compare ("remove"); - } - - pval_map_type& pval_map = plist_map[pfx]; - - if (remove) - { - pval_map_iterator p = pval_map.find (pname); - - if (p != pval_map.end ()) - pval_map.erase (p); - } - else - pval_map[pname] = val; - } - else - error ("invalid %s property `%s'", pfx.c_str (), pname.c_str ()); - } + { + // FIXME -- should we validate property names and values here? + + std::string pname = name.substr (offset); + + std::transform (pfx.begin (), pfx.end (), pfx.begin (), tolower); + std::transform (pname.begin (), pname.end (), pname.begin (), tolower); + + bool has_property = false; + if (pfx == "axes") + has_property = axes::properties::has_core_property (pname); + else if (pfx == "line") + has_property = line::properties::has_core_property (pname); + else if (pfx == "text") + has_property = text::properties::has_core_property (pname); + else if (pfx == "image") + has_property = image::properties::has_core_property (pname); + else if (pfx == "patch") + has_property = patch::properties::has_core_property (pname); + else if (pfx == "figure") + has_property = figure::properties::has_core_property (pname); + else if (pfx == "surface") + has_property = surface::properties::has_core_property (pname); + else if (pfx == "hggroup") + has_property = hggroup::properties::has_core_property (pname); + + if (has_property) + { + bool remove = false; + if (val.is_string ()) + { + caseless_str tval = val.string_value (); + + remove = tval.compare ("remove"); + } + + pval_map_type& pval_map = plist_map[pfx]; + + if (remove) + { + pval_map_iterator p = pval_map.find (pname); + + if (p != pval_map.end ()) + pval_map.erase (p); + } + else + pval_map[pname] = val; + } + else + error ("invalid %s property `%s'", pfx.c_str (), pname.c_str ()); + } } if (! error_state && offset == 0) @@ -1311,49 +1311,49 @@ caseless_str pfx = name.substr (0, 4); if (pfx.compare ("axes") || pfx.compare ("line") - || pfx.compare ("text")) - offset = 4; + || pfx.compare ("text")) + offset = 4; else if (len > 5) - { - pfx = name.substr (0, 5); - - if (pfx.compare ("image") || pfx.compare ("patch")) - offset = 5; - else if (len > 6) - { - pfx = name.substr (0, 6); - - if (pfx.compare ("figure")) - offset = 6; - else if (len > 7) - { - pfx = name.substr (0, 7); - - if (pfx.compare ("surface") || pfx.compare ("hggroup")) - offset = 7; - } - } - } + { + pfx = name.substr (0, 5); + + if (pfx.compare ("image") || pfx.compare ("patch")) + offset = 5; + else if (len > 6) + { + pfx = name.substr (0, 6); + + if (pfx.compare ("figure")) + offset = 6; + else if (len > 7) + { + pfx = name.substr (0, 7); + + if (pfx.compare ("surface") || pfx.compare ("hggroup")) + offset = 7; + } + } + } if (offset > 0) - { - std::string pname = name.substr (offset); - - std::transform (pfx.begin (), pfx.end (), pfx.begin (), tolower); - std::transform (pname.begin (), pname.end (), pname.begin (), tolower); - - plist_map_const_iterator p = find (pfx); - - if (p != end ()) - { - const pval_map_type& pval_map = p->second; - - pval_map_const_iterator q = pval_map.find (pname); - - if (q != pval_map.end ()) - retval = q->second; - } - } + { + std::string pname = name.substr (offset); + + std::transform (pfx.begin (), pfx.end (), pfx.begin (), tolower); + std::transform (pname.begin (), pname.end (), pname.begin (), tolower); + + plist_map_const_iterator p = find (pfx); + + if (p != end ()) + { + const pval_map_type& pval_map = p->second; + + pval_map_const_iterator q = pval_map.find (pname); + + if (q != pval_map.end ()) + retval = q->second; + } + } } return retval; @@ -1371,9 +1371,9 @@ const pval_map_type pval_map = p->second; for (pval_map_const_iterator q = pval_map.begin (); - q != pval_map.end (); - q++) - m.assign (prefix + q->first, q->second); + q != pval_map.end (); + q++) + m.assign (prefix + q->first, q->second); } return m; @@ -1389,9 +1389,9 @@ double tval = a.double_value (); if (! error_state) - val = tval; + val = tval; else - error ("invalid graphics handle"); + error ("invalid graphics handle"); } } @@ -1407,21 +1407,21 @@ else if (nargin % 2 == 0) { for (int i = 0; i < nargin; i += 2) - { - caseless_str name = args(i).string_value (); - - if (! error_state) - { - octave_value val = args(i+1); + { + caseless_str name = args(i).string_value (); + + if (! error_state) + { + octave_value val = args(i+1); set_value_or_default (name, val); - if (error_state) - break; - } - else - error ("set: expecting argument %d to be a property name", i); - } + if (error_state) + break; + } + else + error ("set: expecting argument %d to be a property name", i); + } } else error ("set: invalid number of arguments"); @@ -1596,7 +1596,7 @@ retval = 1; while (handle_map.find (retval) != handle_map.end ()) - retval++; + retval++; } else { @@ -1608,16 +1608,16 @@ free_list_iterator p = handle_free_list.begin (); if (p != handle_free_list.end ()) - { - retval = *p; - handle_free_list.erase (p); - } + { + retval = *p; + handle_free_list.erase (p); + } else - { - retval = graphics_handle (next_handle); - - next_handle = ceil (next_handle) - 1.0 - make_handle_fraction (); - } + { + retval = graphics_handle (next_handle); + + next_handle = ceil (next_handle) - 1.0 - make_handle_fraction (); + } } return retval; @@ -1629,45 +1629,45 @@ if (h.ok ()) { if (h.value () != 0) - { - iterator p = handle_map.find (h); - - if (p != handle_map.end ()) - { - base_properties& bp = p->second.get_properties (); - - bp.set_beingdeleted (true); - - bp.delete_children (); - - octave_value val = bp.get_deletefcn (); - - bp.execute_deletefcn (); - - // notify backend - graphics_backend backend = p->second.get_backend (); - if (backend) + { + iterator p = handle_map.find (h); + + if (p != handle_map.end ()) + { + base_properties& bp = p->second.get_properties (); + + bp.set_beingdeleted (true); + + bp.delete_children (); + + octave_value val = bp.get_deletefcn (); + + bp.execute_deletefcn (); + + // notify backend + graphics_backend backend = p->second.get_backend (); + if (backend) backend.object_destroyed (p->second); - // Note: this will be valid only for first explicitly - // deleted object. All its children will then have an - // unknown backend. - - // Graphics handles for non-figure objects are negative - // integers plus some random fractional part. To avoid - // running out of integers, we recycle the integer part - // but tack on a new random part each time. - - handle_map.erase (p); - - if (h.value () < 0) - handle_free_list.insert (ceil (h.value ()) - make_handle_fraction ()); - } - else - error ("graphics_handle::free: invalid object %g", h.value ()); - } + // Note: this will be valid only for first explicitly + // deleted object. All its children will then have an + // unknown backend. + + // Graphics handles for non-figure objects are negative + // integers plus some random fractional part. To avoid + // running out of integers, we recycle the integer part + // but tack on a new random part each time. + + handle_map.erase (p); + + if (h.value () < 0) + handle_free_list.insert (ceil (h.value ()) - make_handle_fraction ()); + } + else + error ("graphics_handle::free: invalid object %g", h.value ()); + } else - error ("graphics_handle::free: can't delete root figure"); + error ("graphics_handle::free: can't delete root figure"); } } @@ -1701,8 +1701,8 @@ static graphics_handle reparent (const octave_value& ov, const std::string& who, - const std::string& property, const graphics_handle& new_parent, - bool adopt = true) + const std::string& property, const graphics_handle& new_parent, + bool adopt = true) { graphics_handle h = octave_NaN; @@ -1713,27 +1713,27 @@ h = gh_manager::lookup (val); if (h.ok ()) - { - graphics_object obj = gh_manager::get_object (h); - - graphics_handle parent_h = obj.get_parent (); - - graphics_object parent_obj = gh_manager::get_object (parent_h); - - parent_obj.remove_child (h); - - if (adopt) - obj.set ("parent", new_parent.value ()); - else - obj.reparent (new_parent); - } + { + graphics_object obj = gh_manager::get_object (h); + + graphics_handle parent_h = obj.get_parent (); + + graphics_object parent_obj = gh_manager::get_object (parent_h); + + parent_obj.remove_child (h); + + if (adopt) + obj.set ("parent", new_parent.value ()); + else + obj.reparent (new_parent); + } else - error ("%s: invalid graphics handle (= %g) for %s", - who.c_str (), val, property.c_str ()); + error ("%s: invalid graphics handle (= %g) for %s", + who.c_str (), val, property.c_str ()); } else error ("%s: expecting %s to be a graphics handle", - who.c_str (), property.c_str ()); + who.c_str (), property.c_str ()); return h; } @@ -1788,21 +1788,21 @@ else if (val.is_real_matrix ()) { if (val.is_string ()) - retval = boolNDArray (val.dims (), false); + retval = boolNDArray (val.dims (), false); else - { - const NDArray handles = val.array_value (); - - if (! error_state) - { - boolNDArray result (handles.dims ()); - - for (octave_idx_type i = 0; i < handles.numel (); i++) - result.xelem (i) = is_handle (handles (i)); - - retval = result; - } - } + { + const NDArray handles = val.array_value (); + + if (! error_state) + { + boolNDArray result (handles.dims ()); + + for (octave_idx_type i = 0; i < handles.numel (); i++) + result.xelem (i) = is_handle (handles (i)); + + retval = result; + } + } } return retval; @@ -1852,7 +1852,7 @@ void base_properties::set_from_list (base_graphics_object& obj, - property_list& defaults) + property_list& defaults) { std::string go_name = graphics_object_name (); @@ -1863,19 +1863,19 @@ const property_list::pval_map_type pval_map = p->second; for (property_list::pval_map_const_iterator q = pval_map.begin (); - q != pval_map.end (); - q++) - { - std::string pname = q->first; - - obj.set (pname, q->second); - - if (error_state) - { - error ("error setting default property %s", pname.c_str ()); - break; - } - } + q != pval_map.end (); + q++) + { + std::string pname = q->first; + + obj.set (pname, q->second); + + if (error_state) + { + error ("error setting default property %s", pname.c_str ()); + break; + } + } } } @@ -1923,7 +1923,7 @@ void base_properties::set_dynamic (const caseless_str& pname, - const octave_value& val) + const octave_value& val) { std::map::iterator it = all_props.find (pname); @@ -1962,10 +1962,10 @@ for (octave_idx_type i = 0; i < n; i++) { if (h.value () == children(i)) - { - k = i; - break; - } + { + k = i; + break; + } } if (k >= 0) @@ -1973,10 +1973,10 @@ Matrix new_kids (n-1, 1); octave_idx_type j = 0; for (octave_idx_type i = 0; i < n; i++) - { - if (i != k) - new_kids(j++) = children(i); - } + { + if (i != k) + new_kids(j++) = children(i); + } children = new_kids; mark_modified (); } @@ -1994,17 +1994,17 @@ new_parent = gh_manager::lookup (tmp); if (new_parent.ok ()) - { - graphics_object parent_obj = gh_manager::get_object (get_parent ()); - - parent_obj.remove_child (__myhandle__); - - parent = new_parent.as_octave_value (); - - ::adopt (parent.handle_value (), __myhandle__); - } + { + graphics_object parent_obj = gh_manager::get_object (get_parent ()); + + parent_obj.remove_child (__myhandle__); + + parent = new_parent.as_octave_value (); + + ::adopt (parent.handle_value (), __myhandle__); + } else - error ("set: invalid graphics handle (= %g) for parent", tmp); + error ("set: invalid graphics handle (= %g) for parent", tmp); } else error ("set: expecting parent to be a graphics handle"); @@ -2026,18 +2026,18 @@ const Matrix visible_kids = get_children (); if (visible_kids.numel () == new_kids.numel ()) - { - Matrix t1 = visible_kids.sort (); - Matrix t2 = new_kids_column.sort (); - - if (t1 != t2) - ok = false; - } + { + Matrix t1 = visible_kids.sort (); + Matrix t2 = new_kids_column.sort (); + + if (t1 != t2) + ok = false; + } else - ok = false; + ok = false; if (! ok) - error ("set: new children must be a permutation of existing children"); + error ("set: new children must be a permutation of existing children"); } else { @@ -2088,7 +2088,7 @@ graphics_object go = gh_manager::get_object (children(i)); if (go.valid_object ()) - gh_manager::free (children(i)); + gh_manager::free (children(i)); } } @@ -2113,13 +2113,13 @@ graphics_object go = gh_manager::get_object (kids(i)); if (go.valid_object ()) - go.get_properties ().update_boundingbox (); + go.get_properties ().update_boundingbox (); } } void base_properties::add_listener (const caseless_str& nm, const octave_value& v, - listener_mode mode) + listener_mode mode) { property p = get_property (nm); @@ -2129,7 +2129,7 @@ void base_properties::delete_listener (const caseless_str& nm, - const octave_value& v, listener_mode mode) + const octave_value& v, listener_mode mode) { property p = get_property (nm); @@ -2152,35 +2152,35 @@ void object_destroyed (const graphics_object& go) { if (go.isa ("figure")) - { - const figure::properties& props = - dynamic_cast (go.get_properties ()); - - send_quit (props.get___plot_stream__ ()); - } + { + const figure::properties& props = + dynamic_cast (go.get_properties ()); + + send_quit (props.get___plot_stream__ ()); + } } void property_changed (const graphics_object& go, int id) { if (go.isa ("figure")) - { - graphics_object obj (go); - - figure::properties& props = - dynamic_cast (obj.get_properties ()); - - switch (id) - { - case base_properties::VISIBLE: - if (! props.is_visible ()) - { - send_quit (props.get___plot_stream__ ()); - props.set___plot_stream__ (Matrix ()); - props.set___enhanced__ (false); - } - break; - } - } + { + graphics_object obj (go); + + figure::properties& props = + dynamic_cast (obj.get_properties ()); + + switch (id) + { + case base_properties::VISIBLE: + if (! props.is_visible ()) + { + send_quit (props.get___plot_stream__ ()); + props.set___plot_stream__ (Matrix ()); + props.set___enhanced__ (false); + } + break; + } + } } void redraw_figure (const graphics_object& go) const @@ -2191,12 +2191,12 @@ } void print_figure (const graphics_object& go, const std::string& term, - const std::string& file, bool mono, - const std::string& debug_file) const + const std::string& file, bool mono, + const std::string& debug_file) const { octave_value_list args; if (! debug_file.empty ()) - args(4) = debug_file; + args(4) = debug_file; args(3) = mono; args(2) = file; args(1) = term; @@ -2220,33 +2220,33 @@ void send_quit (const octave_value& pstream) const { if (! pstream.is_empty ()) - { - octave_value_list args; - Matrix fids = pstream.matrix_value (); - - if (! error_state) - { - args(1) = "\nquit;\n"; - args(0) = fids(0); - feval ("fputs", args); - - args.resize (1); - feval ("fflush", args); - feval ("pclose", args); - - if (fids.numel () > 1) - { - args(0) = fids(1); - feval ("pclose", args); - - if (fids.numel () > 2) - { - args(0) = fids(2); - feval ("waitpid", args); - } - } - } - } + { + octave_value_list args; + Matrix fids = pstream.matrix_value (); + + if (! error_state) + { + args(1) = "\nquit;\n"; + args(0) = fids(0); + feval ("fputs", args); + + args.resize (1); + feval ("fflush", args); + feval ("pclose", args); + + if (fids.numel () > 1) + { + args(0) = fids(1); + feval ("pclose", args); + + if (fids.numel () > 2) + { + args(0) = fids(2); + feval ("waitpid", args); + } + } + } + } } }; @@ -2271,7 +2271,7 @@ graphics_object parent_obj = gh_manager::get_object (get_parent ()); if (parent_obj) - parent_obj.update_axis_limits (axis_type); + parent_obj.update_axis_limits (axis_type); } else error ("base_graphics_object::update_axis_limits: invalid graphics object"); @@ -2298,7 +2298,7 @@ property p = get_properties ().get_property (pa->first); if (! error_state && p.ok ()) - p.delete_listener (); + p.delete_listener (); } } @@ -2337,18 +2337,18 @@ if (xisnan (val.value ())) { if (! cbo_stack.empty ()) - { - val = cbo_stack.front (); - - cbo_stack.pop_front (); - } + { + val = cbo_stack.front (); + + cbo_stack.pop_front (); + } callbackobject = val; } else if (is_handle (val)) { if (get_callbackobject ().ok ()) - cbo_stack.push_front (get_callbackobject ()); + cbo_stack.push_front (get_callbackobject ()); callbackobject = val; } @@ -2435,17 +2435,17 @@ graphics_handle new_currentaxes; for (octave_idx_type i = 0; i < children.numel (); i++) - { - graphics_handle kid = children(i); - - graphics_object go = gh_manager::get_object (kid); - - if (go.isa ("axes")) - { - new_currentaxes = kid; - break; - } - } + { + graphics_handle kid = children(i); + + graphics_object go = gh_manager::get_object (kid); + + if (go.isa ("axes")) + { + new_currentaxes = kid; + break; + } + } currentaxes = new_currentaxes; } @@ -2459,7 +2459,7 @@ if (! error_state) { if (s == "on") - xset (0, "currentfigure", __myhandle__.value ()); + xset (0, "currentfigure", __myhandle__.value ()); visible = val; } @@ -2472,7 +2472,7 @@ Matrix pos; pos = convert_position (get_position ().matrix_value (), get_units (), - "pixels", screen_size); + "pixels", screen_size); pos(0)--; pos(1)--; @@ -2507,13 +2507,13 @@ new_bb = get_boundingbox (); if (old_bb != new_bb) - { - if (old_bb(2) != new_bb(2) || old_bb(3) != new_bb(3)) - { - execute_resizefcn (); - update_boundingbox (); - } - } + { + if (old_bb(2) != new_bb(2) || old_bb(3) != new_bb(3)) + { + execute_resizefcn (); + update_boundingbox (); + } + } mark_modified (); } @@ -2529,7 +2529,7 @@ os << "Figure " << __myhandle__.value (); if (! nm.empty ()) - os << ": " << get_name (); + os << ": " << get_name (); return os.str (); } @@ -2659,8 +2659,8 @@ void axes::properties::set_text_child (handle_property& hp, - const std::string& who, - const octave_value& v) + const std::string& who, + const octave_value& v) { graphics_handle val; @@ -2725,7 +2725,7 @@ void axes::properties::set_defaults (base_graphics_object& obj, - const std::string& mode) + const std::string& mode) { box = "on"; key = "off"; @@ -2882,7 +2882,7 @@ graphics_object go = gh_manager::get_object (h); if (go.valid_object ()) - gh_manager::free (h); + gh_manager::free (h); base_properties::remove_child (h); } @@ -2932,10 +2932,10 @@ octave_idx_type k = 0; for (octave_idx_type i = 0; i < children.numel (); i++) - { - graphics_handle kid = children (i); - - if (gh_manager::is_handle_visible (kid)) + { + graphics_handle kid = children (i); + + if (gh_manager::is_handle_visible (kid)) { if (! return_hidden) retval(k++) = children(i); @@ -2945,7 +2945,7 @@ if (return_hidden) retval(k++) = children(i); } - } + } retval.resize (k, 1); } @@ -3124,11 +3124,11 @@ Matrix pb = get_plotboxaspectratio ().matrix_value (); bool autocam = (camerapositionmode_is ("auto") - && cameratargetmode_is ("auto") - && cameraupvectormode_is ("auto") - && cameraviewanglemode_is ("auto")); + && cameratargetmode_is ("auto") + && cameraupvectormode_is ("auto") + && cameraviewanglemode_is ("auto")); bool dowarp = (autocam && dataaspectratiomode_is("auto") - && plotboxaspectratiomode_is ("auto")); + && plotboxaspectratiomode_is ("auto")); ColumnVector c_eye (xform_vector ()); ColumnVector c_center (xform_vector ()); @@ -3152,15 +3152,15 @@ double d = 5*sqrt(pb(0)*pb(0)+pb(1)*pb(1)+pb(2)*pb(2)); if (el == 90 || el == -90) - c_eye(2) = d*signum(el); + c_eye(2) = d*signum(el); else - { - az *= M_PI/180.0; - el *= M_PI/180.0; - c_eye(0) = d*cos(el)*sin(az); - c_eye(1) = -d*cos(el)*cos(az); - c_eye(2) = d*sin(el); - } + { + az *= M_PI/180.0; + el *= M_PI/180.0; + c_eye(0) = d*cos(el)*sin(az); + c_eye(1) = -d*cos(el)*cos(az); + c_eye(2) = d*sin(el); + } c_eye(0) = c_eye(0)*(xlimits(1)-xlimits(0))/(xd*pb(0))+c_center(0); c_eye(1) = c_eye(1)*(ylimits(1)-ylimits(0))/(yd*pb(1))+c_center(1); c_eye(2) = c_eye(2)*(zlimits(1)-zlimits(0))/(zd*pb(2))+c_center(2); @@ -3176,12 +3176,12 @@ double az = tview(0), el = tview(1); if (el == 90 || el == -90) - { - c_upv(0) = -sin(az*M_PI/180.0)*(xlimits(1)-xlimits(0))/pb(0); - c_upv(1) = cos(az*M_PI/180.0)*(ylimits(1)-ylimits(0))/pb(1); - } + { + c_upv(0) = -sin(az*M_PI/180.0)*(xlimits(1)-xlimits(0))/pb(0); + c_upv(1) = cos(az*M_PI/180.0)*(ylimits(1)-ylimits(0))/pb(1); + } else - c_upv(2) = 1; + c_upv(2) = 1; cameraupvector = xform2cam (c_upv); } @@ -3200,13 +3200,13 @@ scale (x_pre, pb(0), pb(1), pb(2)); translate (x_pre, -0.5, -0.5, -0.5); scale (x_pre, xd/(xlimits(1)-xlimits(0)), yd/(ylimits(1)-ylimits(0)), - zd/(zlimits(1)-zlimits(0))); + zd/(zlimits(1)-zlimits(0))); translate (x_pre, -xo, -yo, -zo); xform (c_eye, x_pre); xform (c_center, x_pre); scale (c_upv, pb(0)/(xlimits(1)-xlimits(0)), pb(1)/(ylimits(1)-ylimits(0)), - pb(2)/(zlimits(1)-zlimits(0))); + pb(2)/(zlimits(1)-zlimits(0))); translate (c_center, -c_eye(0), -c_eye(1), -c_eye(2)); ColumnVector F (c_center), f (F), UP (c_upv); @@ -3278,14 +3278,14 @@ { double pix = 1; if (autocam) - { - if ((bb(2)/bb(3)) > (xM/yM)) - pix = bb(3); - else - pix = bb(2); - } + { + if ((bb(2)/bb(3)) > (xM/yM)) + pix = bb(3); + else + pix = bb(2); + } else - pix = (bb(2) < bb(3) ? bb(2) : bb(3)); + pix = (bb(2) < bb(3) ? bb(2) : bb(3)); translate (x_viewport, bb(0)+bb(2)/2, bb(1)+bb(3)/2, 0); scale (x_viewport, pix, -pix, 1); } @@ -3301,7 +3301,7 @@ x_render = x_normrender; scale (x_render, xd/(xlimits(1)-xlimits(0)), yd/(ylimits(1)-ylimits(0)), - zd/(zlimits(1)-zlimits(0))); + zd/(zlimits(1)-zlimits(0))); translate (x_render, -xo, -yo, -zo); x_viewtransform = x_view; @@ -3317,7 +3317,7 @@ // => x_gl_mat2) x_gl_mat1 = x_view; scale (x_gl_mat1, xd/(xlimits(1)-xlimits(0)), yd/(ylimits(1)-ylimits(0)), - zd/(zlimits(1)-zlimits(0))); + zd/(zlimits(1)-zlimits(0))); translate (x_gl_mat1, -xo, -yo, -zo); x_gl_mat2 = x_viewport * x_projection; } @@ -3348,16 +3348,16 @@ if (plotboxaspectratiomode_is ("auto")) { if (dataaspectratiomode_is ("auto")) - plotboxaspectratio = Matrix (1, 3, 1.0); + plotboxaspectratio = Matrix (1, 3, 1.0); else - { - Matrix da = get_dataaspectratio ().matrix_value (); - Matrix pba (1, 3, 0.0); - - pba(0) = dx/da(0); - pba(1) = dy/da(1); - pba(2) = dz/da(2); - } + { + Matrix da = get_dataaspectratio ().matrix_value (); + Matrix pba (1, 3, 0.0); + + pba(0) = dx/da(0); + pba(1) = dy/da(1); + pba(2) = dz/da(2); + } } // FIXME -- if plotboxaspectratiomode is "manual", limits @@ -3372,12 +3372,12 @@ graphics_object obj = gh_manager::get_object (get_parent ()); Matrix parent_bb = obj.get_properties ().get_boundingbox (true); Matrix pos = (internal ? - get_position ().matrix_value () - : get_outerposition ().matrix_value ()); + get_position ().matrix_value () + : get_outerposition ().matrix_value ()); pos = convert_position (pos, get_units (), "pixels", - parent_bb.extract_n (0, 2, 1, 2)); + parent_bb.extract_n (0, 2, 1, 2)); pos(0)--; pos(1)--; pos(1) = parent_bb(3) - pos(1) - pos(3); @@ -3399,7 +3399,7 @@ ColumnVector graphics_xform::transform (double x, double y, double z, - bool use_scale) const + bool use_scale) const { if (use_scale) { @@ -3413,7 +3413,7 @@ ColumnVector graphics_xform::untransform (double x, double y, double z, - bool use_scale) const + bool use_scale) const { ColumnVector v = ::transform (xform_inv, x, y, z); @@ -3448,7 +3448,7 @@ /* static void check_limit_vals (double& min_val, double& max_val, double& min_pos, - const array_property& data) + const array_property& data) { double val = data.min_val (); if (! (xisinf (val) || xisnan (val)) && val < min_val) @@ -3464,28 +3464,28 @@ static void check_limit_vals (double& min_val, double& max_val, double& min_pos, - const octave_value& data) + const octave_value& data) { if (data.is_matrix_type ()) { Matrix m = data.matrix_value (); if (! error_state && m.numel () == 3) - { - double val; - - val = m(0); - if (! (xisinf (val) || xisnan (val)) && val < min_val) - min_val = val; - - val = m(1); - if (! (xisinf (val) || xisnan (val)) && val > max_val) - max_val = val; - - val = m(2); - if (! (xisinf (val) || xisnan (val)) && val > 0 && val < min_pos) - min_pos = val; - } + { + double val; + + val = m(0); + if (! (xisinf (val) || xisnan (val)) && val < min_val) + min_val = val; + + val = m(1); + if (! (xisinf (val) || xisnan (val)) && val > max_val) + max_val = val; + + val = m(2); + if (! (xisinf (val) || xisnan (val)) && val > 0 && val < min_pos) + min_pos = val; + } } } @@ -3507,13 +3507,13 @@ a = std::pow (10.0, r); b = static_cast (l-r); if (a < 1) - { - a *= 10; - b -= 1; - } + { + a *= 10; + b -= 1; + } if (x < 0) - a = -a; + a = -a; } } @@ -3559,7 +3559,7 @@ Matrix axes::properties::get_axis_limits (double xmin, double xmax, - double min_pos, bool logscale) + double min_pos, bool logscale) { Matrix retval; @@ -3569,45 +3569,45 @@ if (! (xisinf (min_val) || xisinf (max_val))) { if (logscale) - { - if (xisinf (min_pos)) - { - // warning ("axis: logscale with no positive values to plot"); - return retval; - } - - if (min_val <= 0) - { - warning ("axis: omitting nonpositive data in log plot"); - min_val = min_pos; - } - // FIXME -- maybe this test should also be relative? - if (std::abs (min_val - max_val) < sqrt (DBL_EPSILON)) - { - min_val *= 0.9; - max_val *= 1.1; - } - min_val = pow (10, floor (log10 (min_val))); - max_val = pow (10, ceil (log10 (max_val))); - } + { + if (xisinf (min_pos)) + { + // warning ("axis: logscale with no positive values to plot"); + return retval; + } + + if (min_val <= 0) + { + warning ("axis: omitting nonpositive data in log plot"); + min_val = min_pos; + } + // FIXME -- maybe this test should also be relative? + if (std::abs (min_val - max_val) < sqrt (DBL_EPSILON)) + { + min_val *= 0.9; + max_val *= 1.1; + } + min_val = pow (10, floor (log10 (min_val))); + max_val = pow (10, ceil (log10 (max_val))); + } else - { - if (min_val == 0 && max_val == 0) - { - min_val = -1; - max_val = 1; - } - // FIXME -- maybe this test should also be relative? - else if (std::abs (min_val - max_val) < sqrt (DBL_EPSILON)) - { - min_val -= 0.1 * std::abs (min_val); - max_val += 0.1 * std::abs (max_val); - } - - double tick_sep = calc_tick_sep (min_val , max_val); - min_val = tick_sep * std::floor (min_val / tick_sep); - max_val = tick_sep * ceil (max_val / tick_sep); - } + { + if (min_val == 0 && max_val == 0) + { + min_val = -1; + max_val = 1; + } + // FIXME -- maybe this test should also be relative? + else if (std::abs (min_val - max_val) < sqrt (DBL_EPSILON)) + { + min_val -= 0.1 * std::abs (min_val); + max_val += 0.1 * std::abs (max_val); + } + + double tick_sep = calc_tick_sep (min_val , max_val); + min_val = tick_sep * std::floor (min_val / tick_sep); + max_val = tick_sep * ceil (max_val / tick_sep); + } } retval.resize (1, 2); @@ -3620,8 +3620,8 @@ void axes::properties::calc_ticks_and_lims (array_property& lims, - array_property& ticks, - bool limmode_is_auto, bool is_logscale) + array_property& ticks, + bool limmode_is_auto, bool is_logscale) { // FIXME -- add log ticks and lims @@ -3658,10 +3658,10 @@ tmp_lims(1) = tick_sep * i2; if (is_logscale) - { - tmp_lims(0) = std::pow (10.,tmp_lims(0)); - tmp_lims(1) = std::pow (10.,tmp_lims(1)); - } + { + tmp_lims(0) = std::pow (10.,tmp_lims(0)); + tmp_lims(1) = std::pow (10.,tmp_lims(1)); + } lims = tmp_lims; } else @@ -3676,7 +3676,7 @@ { tmp_ticks (i) = tick_sep * (i+i1); if (is_logscale) - tmp_ticks (i) = std::pow (10., tmp_ticks (i)); + tmp_ticks (i) = std::pow (10., tmp_ticks (i)); } ticks = tmp_ticks; @@ -3684,7 +3684,7 @@ void axes::properties::calc_ticklabels (const array_property& ticks, - any_property& labels, bool /*logscale*/) + any_property& labels, bool /*logscale*/) { Matrix values = ticks.get ().matrix_value (); Cell c (values.dims ()); @@ -3702,7 +3702,7 @@ void get_children_limits (double& min_val, double& max_val, double& min_pos, - const Matrix& kids, char limit_type) + const Matrix& kids, char limit_type) { octave_idx_type n = kids.numel (); @@ -3710,72 +3710,72 @@ { case 'x': for (octave_idx_type i = 0; i < n; i++) - { - graphics_object obj = gh_manager::get_object (kids(i)); - - if (obj.is_xliminclude ()) - { - octave_value lim = obj.get_xlim (); - - check_limit_vals (min_val, max_val, min_pos, lim); - } - } + { + graphics_object obj = gh_manager::get_object (kids(i)); + + if (obj.is_xliminclude ()) + { + octave_value lim = obj.get_xlim (); + + check_limit_vals (min_val, max_val, min_pos, lim); + } + } break; case 'y': for (octave_idx_type i = 0; i < n; i++) - { - graphics_object obj = gh_manager::get_object (kids(i)); - - if (obj.is_yliminclude ()) - { - octave_value lim = obj.get_ylim (); - - check_limit_vals (min_val, max_val, min_pos, lim); - } - } + { + graphics_object obj = gh_manager::get_object (kids(i)); + + if (obj.is_yliminclude ()) + { + octave_value lim = obj.get_ylim (); + + check_limit_vals (min_val, max_val, min_pos, lim); + } + } break; case 'z': for (octave_idx_type i = 0; i < n; i++) - { - graphics_object obj = gh_manager::get_object (kids(i)); - - if (obj.is_zliminclude ()) - { - octave_value lim = obj.get_zlim (); - - check_limit_vals (min_val, max_val, min_pos, lim); - } - } + { + graphics_object obj = gh_manager::get_object (kids(i)); + + if (obj.is_zliminclude ()) + { + octave_value lim = obj.get_zlim (); + + check_limit_vals (min_val, max_val, min_pos, lim); + } + } break; case 'c': for (octave_idx_type i = 0; i < n; i++) - { - graphics_object obj = gh_manager::get_object (kids(i)); - - if (obj.is_climinclude ()) - { - octave_value lim = obj.get_clim (); - - check_limit_vals (min_val, max_val, min_pos, lim); - } - } + { + graphics_object obj = gh_manager::get_object (kids(i)); + + if (obj.is_climinclude ()) + { + octave_value lim = obj.get_clim (); + + check_limit_vals (min_val, max_val, min_pos, lim); + } + } break; case 'a': for (octave_idx_type i = 0; i < n; i++) - { - graphics_object obj = gh_manager::get_object (kids(i)); - - if (obj.is_aliminclude ()) - { - octave_value lim = obj.get_alim (); - - check_limit_vals (min_val, max_val, min_pos, lim); - } - } + { + graphics_object obj = gh_manager::get_object (kids(i)); + + if (obj.is_aliminclude ()) + { + octave_value lim = obj.get_alim (); + + check_limit_vals (min_val, max_val, min_pos, lim); + } + } break; default: @@ -3807,92 +3807,92 @@ || axis_type == "xlim") { if (xproperties.xlimmode_is ("auto")) - { - get_children_limits (min_val, max_val, min_pos, kids, 'x'); - - limits = xproperties.get_axis_limits (min_val, max_val, min_pos, - xproperties.xscale_is ("log")); - - update_type = 'x'; - } + { + get_children_limits (min_val, max_val, min_pos, kids, 'x'); + + limits = xproperties.get_axis_limits (min_val, max_val, min_pos, + xproperties.xscale_is ("log")); + + update_type = 'x'; + } } else if (axis_type == "ydata" || axis_type == "yscale" - || axis_type == "ldata" || axis_type == "udata" - || axis_type == "ylimmode" || axis_type == "yliminclude" - || axis_type == "ylim") + || axis_type == "ldata" || axis_type == "udata" + || axis_type == "ylimmode" || axis_type == "yliminclude" + || axis_type == "ylim") { if (xproperties.ylimmode_is ("auto")) - { - get_children_limits (min_val, max_val, min_pos, kids, 'y'); - - limits = xproperties.get_axis_limits (min_val, max_val, min_pos, - xproperties.yscale_is ("log")); - - update_type = 'y'; - } + { + get_children_limits (min_val, max_val, min_pos, kids, 'y'); + + limits = xproperties.get_axis_limits (min_val, max_val, min_pos, + xproperties.yscale_is ("log")); + + update_type = 'y'; + } } else if (axis_type == "zdata" || axis_type == "zscale" - || axis_type == "zlimmode" || axis_type == "zliminclude" - || axis_type == "zlim") + || axis_type == "zlimmode" || axis_type == "zliminclude" + || axis_type == "zlim") { if (xproperties.zlimmode_is ("auto")) - { - get_children_limits (min_val, max_val, min_pos, kids, 'z'); - - limits = xproperties.get_axis_limits (min_val, max_val, min_pos, - xproperties.zscale_is ("log")); - - update_type = 'z'; - } + { + get_children_limits (min_val, max_val, min_pos, kids, 'z'); + + limits = xproperties.get_axis_limits (min_val, max_val, min_pos, + xproperties.zscale_is ("log")); + + update_type = 'z'; + } } else if (axis_type == "cdata" || axis_type == "climmode" - || axis_type == "cdatamapping" || axis_type == "climinclude" - || axis_type == "clim") + || axis_type == "cdatamapping" || axis_type == "climinclude" + || axis_type == "clim") { if (xproperties.climmode_is ("auto")) - { - get_children_limits (min_val, max_val, min_pos, kids, 'c'); - - if (min_val > max_val) - { - min_val = min_pos = 0; - max_val = 1; - } - else if (min_val == max_val) - max_val = min_val + 1; - - limits.resize (1, 2); - - limits(0) = min_val; - limits(1) = max_val; - - update_type = 'c'; - } + { + get_children_limits (min_val, max_val, min_pos, kids, 'c'); + + if (min_val > max_val) + { + min_val = min_pos = 0; + max_val = 1; + } + else if (min_val == max_val) + max_val = min_val + 1; + + limits.resize (1, 2); + + limits(0) = min_val; + limits(1) = max_val; + + update_type = 'c'; + } } else if (axis_type == "alphadata" || axis_type == "alimmode" - || axis_type == "alphadatamapping" || axis_type == "aliminclude" - || axis_type == "alim") + || axis_type == "alphadatamapping" || axis_type == "aliminclude" + || axis_type == "alim") { if (xproperties.alimmode_is ("auto")) - { - get_children_limits (min_val, max_val, min_pos, kids, 'a'); - - if (min_val > max_val) - { - min_val = min_pos = 0; - max_val = 1; - } - else if (min_val == max_val) - max_val = min_val + 1; - - limits.resize (1, 2); - - limits(0) = min_val; - limits(1) = max_val; - - update_type = 'a'; - } + { + get_children_limits (min_val, max_val, min_pos, kids, 'a'); + + if (min_val > max_val) + { + min_val = min_pos = 0; + max_val = 1; + } + else if (min_val == max_val) + max_val = min_val + 1; + + limits.resize (1, 2); + + limits(0) = min_val; + limits(1) = max_val; + + update_type = 'a'; + } } @@ -4107,7 +4107,7 @@ image::properties::get_color_data (void) const { return convert_cdata (*this, get_cdata (), - cdatamapping_is ("scaled"), 3); + cdatamapping_is ("scaled"), 3); } // --------------------------------------------------------------------- @@ -4116,7 +4116,7 @@ patch::properties::get_color_data (void) const { return convert_cdata (*this, get_facevertexcdata (), - cdatamapping_is ("scaled"), 2); + cdatamapping_is ("scaled"), 2); } // --------------------------------------------------------------------- @@ -4129,8 +4129,8 @@ inline void cross_product (double x1, double y1, double z1, - double x2, double y2, double z2, - double& x, double& y, double& z) + double x2, double y2, double z2, + double& x, double& y, double& z) { x += (y1 * z2 - z1 * y2); y += (z1 * x2 - x1 * z2); @@ -4157,58 +4157,58 @@ NDArray n (dim_vector (q, p, 3), 0.0); for (int i = 0; i < p; i++) - { - if (y_mat) - { - i1 = i - 1; - i2 = i; - i3 = i + 1; - } - - for (int j = 0; j < q; j++) - { - if (x_mat) - { - j1 = j - 1; - j2 = j; - j3 = j + 1; - } - - double& nx = n(j, i, 0); - double& ny = n(j, i, 1); - double& nz = n(j, i, 2); + { + if (y_mat) + { + i1 = i - 1; + i2 = i; + i3 = i + 1; + } + + for (int j = 0; j < q; j++) + { + if (x_mat) + { + j1 = j - 1; + j2 = j; + j3 = j + 1; + } + + double& nx = n(j, i, 0); + double& ny = n(j, i, 1); + double& nz = n(j, i, 2); if ((j > 0) && (i > 0)) // upper left quadrangle - cross_product (x(j1,i-1)-x(j2,i), y(j-1,i1)-y(j,i2), z(j-1,i-1)-z(j,i), - x(j2,i-1)-x(j1,i), y(j,i1)-y(j-1,i2), z(j,i-1)-z(j-1,i), - nx, ny, nz); + cross_product (x(j1,i-1)-x(j2,i), y(j-1,i1)-y(j,i2), z(j-1,i-1)-z(j,i), + x(j2,i-1)-x(j1,i), y(j,i1)-y(j-1,i2), z(j,i-1)-z(j-1,i), + nx, ny, nz); if ((j > 0) && (i < (p -1))) // upper right quadrangle cross_product (x(j1,i+1)-x(j2,i), y(j-1,i3)-y(j,i2), z(j-1,i+1)-z(j,i), - x(j1,i)-x(j2,i+1), y(j-1,i2)-y(j,i3), z(j-1,i)-z(j,i+1), - nx, ny, nz); + x(j1,i)-x(j2,i+1), y(j-1,i2)-y(j,i3), z(j-1,i)-z(j,i+1), + nx, ny, nz); if ((j < (q - 1)) && (i > 0)) // lower left quadrangle cross_product (x(j2,i-1)-x(j3,i), y(j,i1)-y(j+1,i2), z(j,i-1)-z(j+1,i), - x(j3,i-1)-x(j2,i), y(j+1,i1)-y(j,i2), z(j+1,i-1)-z(j,i), - nx, ny, nz); + x(j3,i-1)-x(j2,i), y(j+1,i1)-y(j,i2), z(j+1,i-1)-z(j,i), + nx, ny, nz); if ((j < (q - 1)) && (i < (p -1))) // lower right quadrangle - cross_product (x(j3,i)-x(j2,i+1), y(j+1,i2)-y(j,i3), z(j+1,i)-z(j,i+1), + cross_product (x(j3,i)-x(j2,i+1), y(j+1,i2)-y(j,i3), z(j+1,i)-z(j,i+1), x(j3,i+1)-x(j2,i), y(j+1,i3)-y(j,i2), z(j+1,i+1)-z(j,i), - nx, ny, nz); + nx, ny, nz); double d = - std::max(std::max(fabs(nx), fabs(ny)), fabs(nz)); - nx /= d; - ny /= d; - nz /= d; - } - } + nx /= d; + ny /= d; + nz /= d; + } + } vertexnormals = n; } } @@ -4326,7 +4326,7 @@ graphics_handle gh_manager::do_make_graphics_handle (const std::string& go_name, - const graphics_handle& p, bool do_createfcn) + const graphics_handle& p, bool do_createfcn) { graphics_handle h = get_handle (go_name); @@ -4349,7 +4349,7 @@ } else error ("gh_manager::do_make_graphics_handle: invalid object type `%s'", - go_name.c_str ()); + go_name.c_str ()); return h; } @@ -4388,10 +4388,10 @@ p++) { if (*p == h) - { - figure_list.erase (p); - break; - } + { + figure_list.erase (p); + break; + } } } @@ -4400,7 +4400,7 @@ { public: callback_event (const graphics_handle& h, const std::string& name, - const octave_value& data = Matrix ()) + const octave_value& data = Matrix ()) : base_graphics_event (), handle (h), callback_name (name), callback_data (data) { } @@ -4446,7 +4446,7 @@ { public: set_event (const graphics_handle& h, const std::string& name, - const octave_value& value) + const octave_value& value) : base_graphics_event (), handle (h), property_name (name), property_value (value) { } @@ -4469,8 +4469,8 @@ graphics_event graphics_event::create_callback_event (const graphics_handle& h, - const std::string& name, - const octave_value& data) + const std::string& name, + const octave_value& data) { graphics_event e; @@ -4481,7 +4481,7 @@ graphics_event graphics_event::create_function_event (graphics_event::event_fcn fcn, - void *data) + void *data) { graphics_event e; @@ -4492,8 +4492,8 @@ graphics_event graphics_event::create_set_event (const graphics_handle& h, - const std::string& name, - const octave_value& data) + const std::string& name, + const octave_value& data) { graphics_event e; @@ -4520,14 +4520,14 @@ callback_objects.pop_front (); xset_gcbo (callback_objects.empty () - ? graphics_handle () - : callback_objects.front ().get_handle ()); + ? graphics_handle () + : callback_objects.front ().get_handle ()); } void gh_manager::do_execute_callback (const graphics_handle& h, - const octave_value& cb_arg, - const octave_value& data) + const octave_value& cb_arg, + const octave_value& data) { octave_value_list args; octave_function *fcn = 0; @@ -4581,7 +4581,7 @@ { std::string nm = cb.class_name (); error ("trying to execute non-executable object (class = %s)", - nm.c_str ()); + nm.c_str ()); } if (fcn && ! error_state) @@ -4600,7 +4600,7 @@ void gh_manager::do_post_callback (const graphics_handle& h, const std::string name, - const octave_value& data) + const octave_value& data) { gh_manager::autolock guard; @@ -4609,32 +4609,32 @@ if (go.valid_object ()) { if (callback_objects.empty ()) - do_post_event (graphics_event::create_callback_event (h, name, data)); + do_post_event (graphics_event::create_callback_event (h, name, data)); else - { - const graphics_object& current = callback_objects.front (); - - if (current.get_properties ().is_interruptible ()) - do_post_event (graphics_event::create_callback_event (h, name, data)); - else - { - caseless_str busy_action (go.get_properties ().get_busyaction ()); - - if (busy_action.compare ("queue")) - do_post_event (graphics_event::create_callback_event (h, name, data)); - else - { - caseless_str cname (name); - - if (cname.compare ("deletefcn") - || cname.compare ("createfcn") - || (go.isa ("figure") - && (cname.compare ("closerequestfcn") - || cname.compare ("resizefcn")))) - do_post_event (graphics_event::create_callback_event (h, name, data)); - } - } - } + { + const graphics_object& current = callback_objects.front (); + + if (current.get_properties ().is_interruptible ()) + do_post_event (graphics_event::create_callback_event (h, name, data)); + else + { + caseless_str busy_action (go.get_properties ().get_busyaction ()); + + if (busy_action.compare ("queue")) + do_post_event (graphics_event::create_callback_event (h, name, data)); + else + { + caseless_str cname (name); + + if (cname.compare ("deletefcn") + || cname.compare ("createfcn") + || (go.isa ("figure") + && (cname.compare ("closerequestfcn") + || cname.compare ("resizefcn")))) + do_post_event (graphics_event::create_callback_event (h, name, data)); + } + } + } } } @@ -4648,7 +4648,7 @@ void gh_manager::do_post_set (const graphics_handle& h, const std::string name, - const octave_value& value) + const octave_value& value) { gh_manager::autolock guard; @@ -4667,30 +4667,30 @@ gh_manager::lock (); if (! event_queue.empty ()) - { - if (callback_objects.empty () || force) - { - e = event_queue.front (); - - event_queue.pop_front (); - } - else - { - const graphics_object& go = callback_objects.front (); - - if (go.get_properties ().is_interruptible ()) - { - e = event_queue.front (); - - event_queue.pop_front (); - } - } - } + { + if (callback_objects.empty () || force) + { + e = event_queue.front (); + + event_queue.pop_front (); + } + else + { + const graphics_object& go = callback_objects.front (); + + if (go.get_properties ().is_interruptible ()) + { + e = event_queue.front (); + + event_queue.pop_front (); + } + } + } gh_manager::unlock (); if (e.ok ()) - e.execute (); + e.execute (); } while (e.ok ()); @@ -4787,7 +4787,7 @@ if (! error_state) { - bool request_drawnow = false; + bool request_drawnow = false; // loop over graphics objects for (octave_idx_type n = 0; n < hcv.length (); n++) @@ -4828,10 +4828,10 @@ } } else - { - error ("set: invalid handle (= %g)", hcv(n)); - break; - } + { + error ("set: invalid handle (= %g)", hcv(n)); + break; + } if (error_state) break; @@ -4839,8 +4839,8 @@ request_drawnow = true; } - if (! error_state && request_drawnow) - Vdrawnow_requested = true; + if (! error_state && request_drawnow) + Vdrawnow_requested = true; } else error ("set: expecting graphics handle as first argument"); @@ -4874,9 +4874,9 @@ if (! error_state) { - octave_idx_type len = hcv.length (); - - vals.resize (dim_vector (len, 1)); + octave_idx_type len = hcv.length (); + + vals.resize (dim_vector (len, 1)); for (octave_idx_type n = 0; n < len; n++) { @@ -4893,17 +4893,17 @@ if (! error_state) vals(n) = obj.get (property); else - { - error ("get: expecting property name as second argument"); - break; - } + { + error ("get: expecting property name as second argument"); + break; + } } } else - { - error ("get: invalid handle (= %g)", hcv(n)); - break; - } + { + error ("get: invalid handle (= %g)", hcv(n)); + break; + } } } else @@ -4917,9 +4917,9 @@ octave_idx_type len = vals.numel (); if (len > 1) - retval = vals; + retval = vals; else if (len == 1) - retval = vals(0); + retval = vals(0); } return retval; @@ -4987,7 +4987,7 @@ static octave_value make_graphics_object (const std::string& go_name, - const octave_value_list& args) + const octave_value_list& args) { octave_value retval; @@ -4999,21 +4999,21 @@ for (int i = 0; i < xargs.length (); i++) if (xargs(i).is_string () - && p.compare (xargs(i).string_value ())) + && p.compare (xargs(i).string_value ())) { - if (i < (xargs.length () - 1)) - { - val = xargs(i+1).double_value (); - - if (! error_state) - { - xargs = xargs.splice (i, 2); - break; - } - } - else - error ("__go_%s__: missing value for parent property", - go_name.c_str ()); + if (i < (xargs.length () - 1)) + { + val = xargs(i+1).double_value (); + + if (! error_state) + { + xargs = xargs.splice (i, 2); + break; + } + } + else + error ("__go_%s__: missing value for parent property", + go_name.c_str ()); } if (! error_state && xisnan (val)) @@ -5024,28 +5024,28 @@ graphics_handle parent = gh_manager::lookup (val); if (parent.ok ()) - { - graphics_handle h - = gh_manager::make_graphics_handle (go_name, parent, false); - - if (! error_state) - { - adopt (parent, h); - - xset (h, xargs); - xcreatefcn (h); - - retval = h.value (); - - if (! error_state) - Vdrawnow_requested = true; - } - else - error ("__go%s__: unable to create graphics handle", - go_name.c_str ()); - } + { + graphics_handle h + = gh_manager::make_graphics_handle (go_name, parent, false); + + if (! error_state) + { + adopt (parent, h); + + xset (h, xargs); + xcreatefcn (h); + + retval = h.value (); + + if (! error_state) + Vdrawnow_requested = true; + } + else + error ("__go%s__: unable to create graphics handle", + go_name.c_str ()); + } else - error ("__go_%s__: invalid parent", go_name.c_str ()); + error ("__go_%s__: invalid parent", go_name.c_str ()); } else error ("__go_%s__: invalid parent", go_name.c_str ()); @@ -5068,41 +5068,41 @@ double val = args(0).double_value (); if (! error_state) - { - if (is_figure (val)) - { - graphics_handle h = gh_manager::lookup (val); - - xset (h, args.splice (0, 1)); - - retval = h.value (); - } - else - { - graphics_handle h = octave_NaN; - - if (xisnan (val)) - h = gh_manager::make_graphics_handle ("figure", 0, false); - else if (val > 0 && D_NINT (val) == val) - h = gh_manager::make_figure_handle (val); - else - error ("__go_figure__: invalid figure number"); - - if (! error_state && h.ok ()) - { - adopt (0, h); - - xset (h, args.splice (0, 1)); - xcreatefcn (h); - - retval = h.value (); - } - else - error ("__go_figure__: failed to create figure handle"); - } - } + { + if (is_figure (val)) + { + graphics_handle h = gh_manager::lookup (val); + + xset (h, args.splice (0, 1)); + + retval = h.value (); + } + else + { + graphics_handle h = octave_NaN; + + if (xisnan (val)) + h = gh_manager::make_graphics_handle ("figure", 0, false); + else if (val > 0 && D_NINT (val) == val) + h = gh_manager::make_figure_handle (val); + else + error ("__go_figure__: invalid figure number"); + + if (! error_state && h.ok ()) + { + adopt (0, h); + + xset (h, args.splice (0, 1)); + xcreatefcn (h); + + retval = h.value (); + } + else + error ("__go_figure__: failed to create figure handle"); + } + } else - error ("__go_figure__: expecting figure number to be double value"); + error ("__go_figure__: expecting figure number to be double value"); } else print_usage (); @@ -5202,60 +5202,60 @@ const NDArray vals = args (0).array_value (); if (! error_state) - { - // Check is all the handles to delete are valid first - // as callbacks might delete one of the handles we - // later want to delete - for (octave_idx_type i = 0; i < vals.numel (); i++) - { - h = gh_manager::lookup (vals.elem (i)); - - if (! h.ok ()) - { - error ("delete: invalid graphics object (= %g)", - vals.elem (i)); - break; - } - } - - if (! error_state) - { - for (octave_idx_type i = 0; i < vals.numel (); i++) - { - h = gh_manager::lookup (vals.elem (i)); - - if (h.ok ()) - { - graphics_object obj = gh_manager::get_object (h); - - // Don't do recursive deleting, due to callbacks - if (! obj.get_properties ().is_beingdeleted ()) - { - graphics_handle parent_h = obj.get_parent (); - - graphics_object parent_obj = - gh_manager::get_object (parent_h); - - // NOTE: free the handle before removing it from its - // parent's children, such that the object's - // state is correct when the deletefcn callback - // is executed - - gh_manager::free (h); - - // A callback function might have already deleted - // the parent - if (parent_obj.valid_object ()) - parent_obj.remove_child (h); - - Vdrawnow_requested = true; - } - } - } - } - } + { + // Check is all the handles to delete are valid first + // as callbacks might delete one of the handles we + // later want to delete + for (octave_idx_type i = 0; i < vals.numel (); i++) + { + h = gh_manager::lookup (vals.elem (i)); + + if (! h.ok ()) + { + error ("delete: invalid graphics object (= %g)", + vals.elem (i)); + break; + } + } + + if (! error_state) + { + for (octave_idx_type i = 0; i < vals.numel (); i++) + { + h = gh_manager::lookup (vals.elem (i)); + + if (h.ok ()) + { + graphics_object obj = gh_manager::get_object (h); + + // Don't do recursive deleting, due to callbacks + if (! obj.get_properties ().is_beingdeleted ()) + { + graphics_handle parent_h = obj.get_parent (); + + graphics_object parent_obj = + gh_manager::get_object (parent_h); + + // NOTE: free the handle before removing it from its + // parent's children, such that the object's + // state is correct when the deletefcn callback + // is executed + + gh_manager::free (h); + + // A callback function might have already deleted + // the parent + if (parent_obj.valid_object ()) + parent_obj.remove_child (h); + + Vdrawnow_requested = true; + } + } + } + } + } else - error ("delete: invalid graphics object"); + error ("delete: invalid graphics object"); } else print_usage (); @@ -5282,7 +5282,7 @@ mode = args(1).string_value (); if (error_state) - return retval; + return retval; } if (nargin == 1 || nargin == 2) @@ -5292,24 +5292,24 @@ double val = args(0).double_value (); if (! error_state) - { - h = gh_manager::lookup (val); - - if (h.ok ()) - { - graphics_object obj = gh_manager::get_object (h); - - obj.set_defaults (mode); - - h = gh_manager::lookup (val); - if (! h.ok ()) - error ("__go_axes_init__: axis deleted during initialization (= %g)", val); - } - else - error ("__go_axes_init__: invalid graphics object (= %g)", val); - } + { + h = gh_manager::lookup (val); + + if (h.ok ()) + { + graphics_object obj = gh_manager::get_object (h); + + obj.set_defaults (mode); + + h = gh_manager::lookup (val); + if (! h.ok ()) + error ("__go_axes_init__: axis deleted during initialization (= %g)", val); + } + else + error ("__go_axes_init__: invalid graphics object (= %g)", val); + } else - error ("__go_axes_init__: invalid graphics object"); + error ("__go_axes_init__: invalid graphics object"); } else print_usage (); @@ -5355,29 +5355,29 @@ double val = args(0).double_value (); if (! error_state) - { - graphics_handle h = gh_manager::lookup (val); - - if (h.ok ()) - { - std::string name = args(1).string_value (); - - if (! error_state) - { - if (nargin == 2) - gh_manager::execute_callback (h, name); - else - gh_manager::execute_callback (h, name, args(2)); - } - else - error ("__go_execute_callback__: invalid callback name"); - } - else - error ("__go_execute_callback__: invalid graphics object (= %g)", - val); - } + { + graphics_handle h = gh_manager::lookup (val); + + if (h.ok ()) + { + std::string name = args(1).string_value (); + + if (! error_state) + { + if (nargin == 2) + gh_manager::execute_callback (h, name); + else + gh_manager::execute_callback (h, name, args(2)); + } + else + error ("__go_execute_callback__: invalid callback name"); + } + else + error ("__go_execute_callback__: invalid graphics object (= %g)", + val); + } else - error ("__go_execute_callback__: invalid graphics object"); + error ("__go_execute_callback__: invalid graphics object"); } else print_usage (); @@ -5424,134 +5424,134 @@ if (++drawnow_executing <= 1) { if (! __go_close_all_registered__) - { - octave_add_atexit_function ("__go_close_all__"); - - __go_close_all_registered__ = true; - } + { + octave_add_atexit_function ("__go_close_all__"); + + __go_close_all_registered__ = true; + } if (args.length () == 0 || args.length () == 1) - { - Matrix hlist = gh_manager::figure_handle_list (); - - for (int i = 0; ! error_state && i < hlist.length (); i++) - { - graphics_handle h = gh_manager::lookup (hlist(i)); - - if (h.ok () && h != 0) - { - graphics_object go = gh_manager::get_object (h); - figure::properties& fprops = dynamic_cast (go.get_properties ()); - - if (fprops.is_modified ()) - { - if (fprops.is_visible ()) - { - gh_manager::unlock (); - - fprops.get_backend ().redraw_figure (go); - - gh_manager::lock (); - } - - fprops.set_modified (false); - } - } - } - - bool do_events = true; - - if (args.length () == 1) - { - caseless_str val (args(0).string_value ()); - - if (! error_state && val.compare ("expose")) - do_events = false; - else - { - error ("drawnow: invalid argument, expected `expose' as argument"); - return retval; - } - } - - if (do_events) - { - gh_manager::unlock (); - - gh_manager::process_events (); - - gh_manager::lock (); - } - } + { + Matrix hlist = gh_manager::figure_handle_list (); + + for (int i = 0; ! error_state && i < hlist.length (); i++) + { + graphics_handle h = gh_manager::lookup (hlist(i)); + + if (h.ok () && h != 0) + { + graphics_object go = gh_manager::get_object (h); + figure::properties& fprops = dynamic_cast (go.get_properties ()); + + if (fprops.is_modified ()) + { + if (fprops.is_visible ()) + { + gh_manager::unlock (); + + fprops.get_backend ().redraw_figure (go); + + gh_manager::lock (); + } + + fprops.set_modified (false); + } + } + } + + bool do_events = true; + + if (args.length () == 1) + { + caseless_str val (args(0).string_value ()); + + if (! error_state && val.compare ("expose")) + do_events = false; + else + { + error ("drawnow: invalid argument, expected `expose' as argument"); + return retval; + } + } + + if (do_events) + { + gh_manager::unlock (); + + gh_manager::process_events (); + + gh_manager::lock (); + } + } else if (args.length () >= 2 && args.length () <= 4) - { - std::string term, file, debug_file; - bool mono; - - term = args(0).string_value (); - - if (! error_state) - { - file = args(1).string_value (); - - if (! error_state) - { - size_t pos = file.find_last_of (file_ops::dir_sep_chars ()); - - if (pos != std::string::npos) - { - std::string dirname = file.substr (0, pos+1); - - file_stat fs (dirname); - - if (! (fs && fs.is_dir ())) - { - error ("drawnow: nonexistent directory `%s'", - dirname.c_str ()); - - return retval; - } - } - - mono = (args.length () >= 3 ? args(2).bool_value () : false); - - if (! error_state) - { - debug_file = (args.length () > 3 ? args(3).string_value () - : ""); - - if (! error_state) - { - graphics_handle h = gcf (); - - if (h.ok ()) - { - graphics_object go = gh_manager::get_object (h); - - gh_manager::unlock (); - - go.get_backend () - .print_figure (go, term, file, mono, debug_file); - - gh_manager::lock (); - } - else - error ("drawnow: nothing to draw"); - } - else - error ("drawnow: invalid debug_file, expected a string value"); - } - else - error ("drawnow: invalid colormode, expected a boolean value"); - } - else - error ("drawnow: invalid file, expected a string value"); - } - else - error ("drawnow: invalid terminal, expected a string value"); - } + { + std::string term, file, debug_file; + bool mono; + + term = args(0).string_value (); + + if (! error_state) + { + file = args(1).string_value (); + + if (! error_state) + { + size_t pos = file.find_last_of (file_ops::dir_sep_chars ()); + + if (pos != std::string::npos) + { + std::string dirname = file.substr (0, pos+1); + + file_stat fs (dirname); + + if (! (fs && fs.is_dir ())) + { + error ("drawnow: nonexistent directory `%s'", + dirname.c_str ()); + + return retval; + } + } + + mono = (args.length () >= 3 ? args(2).bool_value () : false); + + if (! error_state) + { + debug_file = (args.length () > 3 ? args(3).string_value () + : ""); + + if (! error_state) + { + graphics_handle h = gcf (); + + if (h.ok ()) + { + graphics_object go = gh_manager::get_object (h); + + gh_manager::unlock (); + + go.get_backend () + .print_figure (go, term, file, mono, debug_file); + + gh_manager::lock (); + } + else + error ("drawnow: nothing to draw"); + } + else + error ("drawnow: invalid debug_file, expected a string value"); + } + else + error ("drawnow: invalid colormode, expected a boolean value"); + } + else + error ("drawnow: invalid file, expected a string value"); + } + else + error ("drawnow: invalid terminal, expected a string value"); + } else - print_usage (); + print_usage (); } gh_manager::unlock (); @@ -5601,28 +5601,28 @@ double h = args(0).double_value (); if (! error_state) - { - std::string pname = args(1).string_value (); - - if (! error_state) - { - graphics_handle gh = gh_manager::lookup (h); - - if (gh.ok ()) - { - graphics_object go = gh_manager::get_object (gh); - - go.add_property_listener (pname, args(2), POSTSET); - } - else - error ("addlistener: invalid graphics object (= %g)", - h); - } - else - error ("addlistener: invalid property name, expected a string value"); - } + { + std::string pname = args(1).string_value (); + + if (! error_state) + { + graphics_handle gh = gh_manager::lookup (h); + + if (gh.ok ()) + { + graphics_object go = gh_manager::get_object (gh); + + go.add_property_listener (pname, args(2), POSTSET); + } + else + error ("addlistener: invalid graphics object (= %g)", + h); + } + else + error ("addlistener: invalid property name, expected a string value"); + } else - error ("addlistener: invalid handle"); + error ("addlistener: invalid handle"); } else print_usage (); @@ -5666,31 +5666,31 @@ double h = args(0).double_value (); if (! error_state) - { - std::string pname = args(1).string_value (); - - if (! error_state) - { - graphics_handle gh = gh_manager::lookup (h); - - if (gh.ok ()) - { - graphics_object go = gh_manager::get_object (gh); - - if (args.length () == 2) - go.delete_property_listener (pname, octave_value (), POSTSET); - else - go.delete_property_listener (pname, args(2), POSTSET); - } - else - error ("dellistener: invalid graphics object (= %g)", - h); - } - else - error ("dellistener: invalid property name, expected a string value"); - } + { + std::string pname = args(1).string_value (); + + if (! error_state) + { + graphics_handle gh = gh_manager::lookup (h); + + if (gh.ok ()) + { + graphics_object go = gh_manager::get_object (gh); + + if (args.length () == 2) + go.delete_property_listener (pname, octave_value (), POSTSET); + else + go.delete_property_listener (pname, args(2), POSTSET); + } + else + error ("dellistener: invalid graphics object (= %g)", + h); + } + else + error ("dellistener: invalid property name, expected a string value"); + } else - error ("dellistener: invalid handle"); + error ("dellistener: invalid handle"); } else print_usage (); @@ -5769,44 +5769,44 @@ std::string name = args(0).string_value (); if (! error_state) - { - double h = args(1).double_value (); - - if (! error_state) - { - graphics_handle gh = gh_manager::lookup (h); - - if (gh.ok ()) - { - graphics_object go = gh_manager::get_object (gh); - - std::string type = args(2).string_value (); - - if (! error_state) - { - if (! go.get_properties ().has_property (name)) - { - property p = property::create (name, gh, type, - args.splice (0, 3)); - - if (! error_state) - go.get_properties ().insert_property (name, p); - } - else - error ("addproperty: a `%s' property already exists in the graphics object", - name.c_str ()); - } - else - error ("addproperty: invalid property type, expected a string value"); - } - else - error ("addproperty: invalid graphics object (= %g)", h); - } - else - error ("addproperty: invalid handle value"); - } + { + double h = args(1).double_value (); + + if (! error_state) + { + graphics_handle gh = gh_manager::lookup (h); + + if (gh.ok ()) + { + graphics_object go = gh_manager::get_object (gh); + + std::string type = args(2).string_value (); + + if (! error_state) + { + if (! go.get_properties ().has_property (name)) + { + property p = property::create (name, gh, type, + args.splice (0, 3)); + + if (! error_state) + go.get_properties ().insert_property (name, p); + } + else + error ("addproperty: a `%s' property already exists in the graphics object", + name.c_str ()); + } + else + error ("addproperty: invalid property type, expected a string value"); + } + else + error ("addproperty: invalid graphics object (= %g)", h); + } + else + error ("addproperty: invalid handle value"); + } else - error ("addproperty: invalid property name, expected a string value"); + error ("addproperty: invalid property name, expected a string value"); } else print_usage (); @@ -5816,7 +5816,7 @@ octave_value get_property_from_handle (double handle, const std::string& property, - const std::string& func) + const std::string& func) { gh_manager::autolock guard; @@ -5833,7 +5833,7 @@ bool set_property_in_handle (double handle, const std::string& property, - const octave_value& arg, const std::string& func) + const octave_value& arg, const std::string& func) { gh_manager::autolock guard; @@ -5845,7 +5845,7 @@ obj.set (caseless_str (property), arg); if (! error_state) - ret = true; + ret = true; } else error ("%s: invalid handle (= %g)", func.c_str(), handle); diff --git a/src/gripes.cc b/src/gripes.cc --- a/src/gripes.cc +++ b/src/gripes.cc @@ -65,7 +65,7 @@ gripe_nonconformant (octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) { error ("nonconformant matrices (op1 is %dx%d, op2 is %dx%d)", - r1, c1, r2, c2); + r1, c1, r2, c2); } void @@ -148,7 +148,7 @@ void gripe_wrong_type_arg (const char *name, const octave_value& tc, - bool is_error) + bool is_error) { std::string type = tc.type_name (); @@ -157,7 +157,7 @@ void gripe_wrong_type_arg (const std::string& name, const octave_value& tc, - bool is_error) + bool is_error) { gripe_wrong_type_arg (name.c_str (), tc, is_error); } @@ -184,11 +184,11 @@ void gripe_implicit_conversion (const std::string& id, - const std::string& from, const std::string& to) + const std::string& from, const std::string& to) { warning_with_id (id.c_str (), - "implicit conversion from %s to %s", - from.c_str (), to.c_str ()); + "implicit conversion from %s to %s", + from.c_str (), to.c_str ()); } void @@ -201,7 +201,7 @@ gripe_logical_conversion (void) { warning_with_id ("Octave:logical-conversion", - "value not equal to 1 or 0 converted to logical 1"); + "value not equal to 1 or 0 converted to logical 1"); } void diff --git a/src/help.cc b/src/help.cc --- a/src/help.cc +++ b/src/help.cc @@ -626,7 +626,7 @@ static bool raw_help_from_symbol_table (const std::string& nm, std::string& h, - std::string& w, bool& symbol_found) + std::string& w, bool& symbol_found) { bool retval = false; @@ -637,19 +637,19 @@ octave_function *fcn = val.function_value (); if (fcn) - { - symbol_found = true; + { + symbol_found = true; - h = fcn->doc_string (); + h = fcn->doc_string (); retval = true; - w = fcn->fcn_file_name (); + w = fcn->fcn_file_name (); - if (w.empty ()) + if (w.empty ()) w = fcn->is_user_function () ? "command-line function" : "built-in function"; - } + } } return retval; @@ -657,7 +657,7 @@ static bool raw_help_from_file (const std::string& nm, std::string& h, - std::string& file, bool& symbol_found) + std::string& file, bool& symbol_found) { bool retval = false; @@ -676,7 +676,7 @@ static bool raw_help_from_map (const std::string& nm, std::string& h, - const map_type& map, bool& symbol_found) + const map_type& map, bool& symbol_found) { map_iter idx = map.find (nm); symbol_found = (idx != map.end ()); @@ -701,7 +701,7 @@ static void do_get_help_text (const std::string& name, std::string& text, - std::string& format) + std::string& format) { bool symbol_found = false; text = raw_help (name, symbol_found); @@ -751,17 +751,17 @@ const std::string name = args (0).string_value (); if (! error_state) - { - std::string text; - std::string format; + { + std::string text; + std::string format; - do_get_help_text (name, text, format); + do_get_help_text (name, text, format); - retval(1) = format; - retval(0) = text; - } + retval(1) = format; + retval(0) = text; + } else - error ("get_help_text: invalid input"); + error ("get_help_text: invalid input"); } else print_usage (); @@ -771,7 +771,7 @@ static void do_get_help_text_from_file (const std::string& fname, std::string& text, - std::string& format) + std::string& format) { bool symbol_found = false; @@ -825,17 +825,17 @@ const std::string fname = args(0).string_value (); if (! error_state) - { - std::string text; - std::string format; + { + std::string text; + std::string format; - do_get_help_text_from_file (fname, text, format); + do_get_help_text_from_file (fname, text, format); - retval(1) = format; - retval(0) = text; - } + retval(1) = format; + retval(0) = text; + } else - error ("get_help_text_from_file: invalid input"); + error ("get_help_text_from_file: invalid input"); } else print_usage (); @@ -961,34 +961,34 @@ int argc = argv.length (); if (argc > 1) - { - Octave_map m (dim_vector (1, argc-1)); + { + Octave_map m (dim_vector (1, argc-1)); - Cell names (1, argc-1); - Cell files (1, argc-1); - Cell types (1, argc-1); + Cell names (1, argc-1); + Cell files (1, argc-1); + Cell types (1, argc-1); - for (int i = 1; i < argc; i++) - { - std::string name = argv[i]; + for (int i = 1; i < argc; i++) + { + std::string name = argv[i]; - std::string type; + std::string type; - std::string file = do_which (name, type); + std::string file = do_which (name, type); - names(i-1) = name; - files(i-1) = file; - types(i-1) = type; - } + names(i-1) = name; + files(i-1) = file; + types(i-1) = type; + } - m.assign ("name", names); - m.assign ("file", files); - m.assign ("type", types); + m.assign ("name", names); + m.assign ("file", files); + m.assign ("type", types); - retval = m; - } + retval = m; + } else - print_usage (); + print_usage (); } return retval; @@ -1039,19 +1039,19 @@ std::string dir = args (0).string_value (); if (! error_state) - { - string_vector fl = load_path::files (dir, true); + { + string_vector fl = load_path::files (dir, true); - if (! error_state) - { - // Return a sorted list with unique entries (in case of - // .m and .oct versions of the same function in a given - // directory, for example). - fl.sort (true); + if (! error_state) + { + // Return a sorted list with unique entries (in case of + // .m and .oct versions of the same function in a given + // directory, for example). + fl.sort (true); - retval = Cell (fl); - } - } + retval = Cell (fl); + } + } else error ("__list_functions__: input must be a string"); } diff --git a/src/input.cc b/src/input.cc --- a/src/input.cc +++ b/src/input.cc @@ -172,22 +172,22 @@ if (do_echo) { if (forced_interactive) - { - if (promptflag > 0) - octave_stdout << command_editor::decode_prompt_string (VPS1); - else - octave_stdout << command_editor::decode_prompt_string (VPS2); - } + { + if (promptflag > 0) + octave_stdout << command_editor::decode_prompt_string (VPS1); + else + octave_stdout << command_editor::decode_prompt_string (VPS2); + } else - octave_stdout << command_editor::decode_prompt_string (VPS4); + octave_stdout << command_editor::decode_prompt_string (VPS4); if (! input_string.empty ()) - { - octave_stdout << input_string; + { + octave_stdout << input_string; - if (input_string[input_string.length () - 1] != '\n') - octave_stdout << "\n"; - } + if (input_string[input_string.length () - 1] != '\n') + octave_stdout << "\n"; + } } } @@ -205,22 +205,22 @@ retval = command_editor::readline (s, eof); if (! eof && retval.empty ()) - retval = "\n"; + retval = "\n"; } else { if (! s.empty () && (interactive || forced_interactive)) - { - FILE *stream = command_editor::get_output_stream (); + { + FILE *stream = command_editor::get_output_stream (); - fputs (s.c_str (), stream); - fflush (stream); - } + fputs (s.c_str (), stream); + fflush (stream); + } FILE *curr_stream = command_editor::get_input_stream (); if (reading_fcn_file || reading_script_file || reading_classdef_file) - curr_stream = ff_instream; + curr_stream = ff_instream; retval = octave_fgets (curr_stream); } @@ -245,7 +245,7 @@ Vdrawnow_requested = false; if (error_state) - return "\n"; + return "\n"; } return gnu_readline (s, force_readline); @@ -262,11 +262,11 @@ if ((interactive || forced_interactive) && (! (reading_fcn_file - || reading_classdef_file - || reading_script_file - || get_input_from_eval_string - || input_from_startup_file - || input_from_command_line_file))) + || reading_classdef_file + || reading_script_file + || get_input_from_eval_string + || input_from_startup_file + || input_from_command_line_file))) { std::string ps = (promptflag > 0) ? VPS1 : VPS2; @@ -283,20 +283,20 @@ // There is no need to update the load_path cache if there is no // user input. if (! retval.empty () - && retval.find_first_not_of (" \t\n\r") != std::string::npos) - { - load_path::update (); + && retval.find_first_not_of (" \t\n\r") != std::string::npos) + { + load_path::update (); - if (Vdebugging) - last_debugging_command = retval; - else - last_debugging_command = std::string (); - } + if (Vdebugging) + last_debugging_command = retval; + else + last_debugging_command = std::string (); + } else if (Vdebugging) - { - retval = last_debugging_command; - history_skip_auto_repeated_debugging_command = true; - } + { + retval = last_debugging_command; + history_skip_auto_repeated_debugging_command = true; + } } else retval = gnu_readline (""); @@ -306,16 +306,16 @@ if (! current_input_line.empty ()) { if (! (input_from_startup_file || input_from_command_line_file - || history_skip_auto_repeated_debugging_command)) - command_history::add (current_input_line); + || history_skip_auto_repeated_debugging_command)) + command_history::add (current_input_line); if (! (reading_fcn_file || reading_script_file || reading_classdef_file)) - { - octave_diary << current_input_line; + { + octave_diary << current_input_line; - if (current_input_line[current_input_line.length () - 1] != '\n') - octave_diary << "\n"; - } + if (current_input_line[current_input_line.length () - 1] != '\n') + octave_diary << "\n"; + } do_input_echo (current_input_line); } @@ -337,16 +337,16 @@ if (get_input_from_eval_string) { if (input_from_eval_string_pending) - { - input_from_eval_string_pending = false; + { + input_from_eval_string_pending = false; - retval = current_eval_string; + retval = current_eval_string; - size_t len = retval.length (); + size_t len = retval.length (); - if (len > 0 && retval[len-1] != '\n') - retval.append ("\n"); - } + if (len > 0 && retval[len-1] != '\n') + retval.append ("\n"); + } } else retval = octave_gets (); @@ -390,22 +390,22 @@ // Make sure input ends with a new line character. if (chars_left == 0 && buf[len-1] != '\n') - { - if (len < max_size) - { - // There is enough room to plug the newline character in - // the buffer. - buf[len++] = '\n'; - } - else - { - // There isn't enough room to plug the newline character - // in the buffer so make sure it is returned on the next - // octave_read call. - pos = eol; - chars_left = 1; - } - } + { + if (len < max_size) + { + // There is enough room to plug the newline character in + // the buffer. + buf[len++] = '\n'; + } + else + { + // There isn't enough room to plug the newline character + // in the buffer so make sure it is returned on the next + // octave_read call. + pos = eol; + chars_left = 1; + } + } status = len; @@ -457,7 +457,7 @@ static string_vector generate_possible_completions (const std::string& text, std::string& prefix, - std::string& hint) + std::string& hint) { string_vector names; @@ -490,10 +490,10 @@ int index = line.find (dirfns_commands[i] + " "); if (index == 0) - { - retval = true; - break; - } + { + retval = true; + break; + } } return retval; @@ -529,7 +529,7 @@ // file/directory operation. if (is_completing_dirfns ()) - name_list = string_vector (); + name_list = string_vector (); else name_list = generate_possible_completions (text, prefix, hint); @@ -546,42 +546,42 @@ matches = 0; for (int i = 0; i < name_list_len; i++) - if (hint == name_list[i].substr (0, hint_len)) - matches++; + if (hint == name_list[i].substr (0, hint_len)) + matches++; } if (name_list_total_len > 0 && matches > 0) { while (list_index < name_list_total_len) - { - std::string name = name_list[list_index]; + { + std::string name = name_list[list_index]; - list_index++; + list_index++; - if (hint == name.substr (0, hint_len)) - { - if (list_index <= name_list_len && ! prefix.empty ()) - retval = prefix + "." + name; - else - retval = name; + if (hint == name.substr (0, hint_len)) + { + if (list_index <= name_list_len && ! prefix.empty ()) + retval = prefix + "." + name; + else + retval = name; - // FIXME -- looks_like_struct is broken for now, - // so it always returns false. + // FIXME -- looks_like_struct is broken for now, + // so it always returns false. - if (matches == 1 && looks_like_struct (retval)) - { - // Don't append anything, since we don't know - // whether it should be '(' or '.'. + if (matches == 1 && looks_like_struct (retval)) + { + // Don't append anything, since we don't know + // whether it should be '(' or '.'. - command_editor::set_completion_append_character ('\0'); - } - else - command_editor::set_completion_append_character - (Vcompletion_append_char); + command_editor::set_completion_append_character ('\0'); + } + else + command_editor::set_completion_append_character + (Vcompletion_append_char); - break; - } - } + break; + } + } } return retval; @@ -638,9 +638,9 @@ nm = caller->fcn_file_name (); if (nm.empty ()) - nm = caller->name (); + nm = caller->name (); else - have_file = true; + have_file = true; } else curr_debug_line = -1; @@ -650,31 +650,31 @@ if (! nm.empty ()) { if (Vgud_mode) - { - static char ctrl_z = 'Z' & 0x1f; + { + static char ctrl_z = 'Z' & 0x1f; - buf << ctrl_z << ctrl_z << nm << ":" << curr_debug_line; - } + buf << ctrl_z << ctrl_z << nm << ":" << curr_debug_line; + } else - { - // FIXME -- we should come up with a clean way to detect - // that we are stopped on the no-op command that marks the - // end of a function or script. + { + // FIXME -- we should come up with a clean way to detect + // that we are stopped on the no-op command that marks the + // end of a function or script. - buf << "stopped in " << nm; + buf << "stopped in " << nm; - if (curr_debug_line > 0) - buf << " at line " << curr_debug_line; + if (curr_debug_line > 0) + buf << " at line " << curr_debug_line; - if (have_file) - { - std::string line_buf - = get_file_line (nm, curr_debug_line); + if (have_file) + { + std::string line_buf + = get_file_line (nm, curr_debug_line); - if (! line_buf.empty ()) - buf << "\n" << curr_debug_line << ": " << line_buf; - } - } + if (! line_buf.empty ()) + buf << "\n" << curr_debug_line << ": " << line_buf; + } + } } std::string msg = buf.str (); @@ -805,35 +805,35 @@ if (! (error_state || input_buf.empty ())) { if (! input_from_startup_file) - command_history::add (input_buf); + command_history::add (input_buf); size_t len = input_buf.length (); octave_diary << input_buf; if (input_buf[len - 1] != '\n') - octave_diary << "\n"; + octave_diary << "\n"; if (len < 1) - return read_as_string ? octave_value ("") : octave_value (Matrix ()); + return read_as_string ? octave_value ("") : octave_value (Matrix ()); if (read_as_string) - { - // FIXME -- fix gnu_readline and octave_gets instead! - if (input_buf.length () == 1 && input_buf[0] == '\n') - retval(0) = ""; - else - retval(0) = input_buf; - } + { + // FIXME -- fix gnu_readline and octave_gets instead! + if (input_buf.length () == 1 && input_buf[0] == '\n') + retval(0) = ""; + else + retval(0) = input_buf; + } else - { - int parse_status = 0; + { + int parse_status = 0; - retval = eval_string (input_buf, true, parse_status, nargout); + retval = eval_string (input_buf, true, parse_status, nargout); - if (! Vdebugging && retval.length () == 0) - retval(0) = Matrix (); - } + if (! Vdebugging && retval.length () == 0) + retval(0) = Matrix (); + } } else error ("input: reading user-input failed!"); @@ -899,11 +899,11 @@ std::string input_buf = interactive_input (prompt_string, true); if (input_buf == "yes") - return true; + return true; else if (input_buf == "no") - return false; + return false; else - message (0, "Please answer yes or no."); + message (0, "Please answer yes or no."); } } @@ -926,15 +926,15 @@ std::string prompt; if (nargin == 1) - { - prompt = args(0).string_value (); + { + prompt = args(0).string_value (); - if (error_state) - { - error ("yes_or_no: expecting argument to be character string"); - return retval; - } - } + if (error_state) + { + error ("yes_or_no: expecting argument to be character string"); + return retval; + } + } retval = octave_yes_or_no (prompt); } @@ -1069,40 +1069,40 @@ { case 1: { - if ((Vecho_executing_commands & ECHO_SCRIPTS) - || (Vecho_executing_commands & ECHO_FUNCTIONS)) - Vecho_executing_commands = ECHO_OFF; - else - Vecho_executing_commands = ECHO_SCRIPTS; + if ((Vecho_executing_commands & ECHO_SCRIPTS) + || (Vecho_executing_commands & ECHO_FUNCTIONS)) + Vecho_executing_commands = ECHO_OFF; + else + Vecho_executing_commands = ECHO_SCRIPTS; } break; case 2: { - std::string arg = argv[1]; + std::string arg = argv[1]; - if (arg == "on") - Vecho_executing_commands = ECHO_SCRIPTS; - else if (arg == "off") - Vecho_executing_commands = ECHO_OFF; - else - print_usage (); + if (arg == "on") + Vecho_executing_commands = ECHO_SCRIPTS; + else if (arg == "off") + Vecho_executing_commands = ECHO_OFF; + else + print_usage (); } break; case 3: { - std::string arg = argv[1]; + std::string arg = argv[1]; - if (arg == "on" && argv[2] == "all") - { - int tmp = (ECHO_SCRIPTS | ECHO_FUNCTIONS); - Vecho_executing_commands = tmp; - } - else if (arg == "off" && argv[2] == "all") - Vecho_executing_commands = ECHO_OFF; - else - print_usage (); + if (arg == "on" && argv[2] == "all") + { + int tmp = (ECHO_SCRIPTS | ECHO_FUNCTIONS); + Vecho_executing_commands = tmp; + } + else if (arg == "off" && argv[2] == "all") + Vecho_executing_commands = ECHO_OFF; + else + print_usage (); } break; @@ -1134,55 +1134,55 @@ std::string hint = args(0).string_value (); if (! error_state) - { - int n = 32; + { + int n = 32; - string_vector list (n); + string_vector list (n); - int k = 0; + int k = 0; - for (;;) - { - std::string cmd = generate_completion (hint, k); + for (;;) + { + std::string cmd = generate_completion (hint, k); - if (! cmd.empty ()) - { - if (k == n) - { - n *= 2; - list.resize (n); - } + if (! cmd.empty ()) + { + if (k == n) + { + n *= 2; + list.resize (n); + } - list[k++] = cmd; - } - else - { - list.resize (k); - break; - } - } + list[k++] = cmd; + } + else + { + list.resize (k); + break; + } + } - if (nargout > 0) - { - if (! list.empty ()) - retval = list; - else - retval = ""; - } - else - { - // We don't use string_vector::list_in_columns here - // because it will be easier for Emacs if the names - // appear in a single column. + if (nargout > 0) + { + if (! list.empty ()) + retval = list; + else + retval = ""; + } + else + { + // We don't use string_vector::list_in_columns here + // because it will be easier for Emacs if the names + // appear in a single column. - int len = list.length (); + int len = list.length (); - for (int i = 0; i < len; i++) - octave_stdout << list[i] << "\n"; - } + for (int i = 0; i < len; i++) + octave_stdout << list[i] << "\n"; + } - octave_completion_matches_called = true; - } + octave_completion_matches_called = true; + } } else print_usage (); @@ -1212,7 +1212,7 @@ std::string file = args(0).string_value (); if (! error_state) - command_editor::read_init_file (file); + command_editor::read_init_file (file); } else print_usage (); @@ -1255,14 +1255,14 @@ p++; if (is_valid_function (hook_fcn)) - { - if (user_data.is_defined ()) - feval (hook_fcn, user_data, 0); - else - feval (hook_fcn, octave_value_list (), 0); - } + { + if (user_data.is_defined ()) + feval (hook_fcn, user_data, 0); + else + feval (hook_fcn, octave_value_list (), 0); + } else - hook_fcn_map.erase (p); + hook_fcn_map.erase (p); } if (hook_fcn_map.empty ()) @@ -1295,19 +1295,19 @@ octave_value user_data; if (nargin == 2) - user_data = args(1); + user_data = args(1); std::string hook_fcn = args(0).string_value (); if (! error_state) - { - if (hook_fcn_map.empty ()) - command_editor::add_event_hook (input_event_hook); + { + if (hook_fcn_map.empty ()) + command_editor::add_event_hook (input_event_hook); - hook_fcn_map[hook_fcn] = user_data; - } + hook_fcn_map[hook_fcn] = user_data; + } else - error ("add_input_event_hook: expecting string as first arg"); + error ("add_input_event_hook: expecting string as first arg"); } else print_usage (); @@ -1332,20 +1332,20 @@ std::string hook_fcn = args(0).string_value (); if (! error_state) - { - hook_fcn_map_type::iterator p = hook_fcn_map.find (hook_fcn); + { + hook_fcn_map_type::iterator p = hook_fcn_map.find (hook_fcn); - if (p != hook_fcn_map.end ()) - hook_fcn_map.erase (p); - else - error ("remove_input_event_hook: %s not found in list", - hook_fcn.c_str ()); + if (p != hook_fcn_map.end ()) + hook_fcn_map.erase (p); + else + error ("remove_input_event_hook: %s not found in list", + hook_fcn.c_str ()); - if (hook_fcn_map.empty ()) - command_editor::remove_event_hook (input_event_hook); - } + if (hook_fcn_map.empty ()) + command_editor::remove_event_hook (input_event_hook); + } else - error ("remove_input_event_hook: expecting string as first arg"); + error ("remove_input_event_hook: expecting string as first arg"); } else print_usage (); diff --git a/src/lex.ll b/src/lex.ll --- a/src/lex.ll +++ b/src/lex.ll @@ -119,10 +119,10 @@ display_token (tok_val); \ if (lexer_debug_flag) \ { \ - std::cerr << "R: "; \ + std::cerr << "R: "; \ display_token (tok_val); \ - std::cerr << std::endl; \ - } \ + std::cerr << std::endl; \ + } \ return tok_val; \ } \ while (0) @@ -149,7 +149,7 @@ do \ { \ yylval.tok_val = new token (name, input_line_number, \ - current_input_column); \ + current_input_column); \ token_stack.push (yylval.tok_val); \ TOK_RETURN (tok); \ } \ @@ -232,7 +232,7 @@ bool is_bracket_or_brace (void) { return (! context.empty () - && (context.top () == BRACKET || context.top () == BRACE)); } + && (context.top () == BRACKET || context.top () == BRACE)); } bool none (void) { return context.empty (); } @@ -307,23 +307,23 @@ %} -D [0-9] -S [ \t] -NL ((\n)|(\r)|(\r\n)) -SNL ({S}|{NL}) -EL (\.\.\.) -BS (\\) -CONT ({EL}|{BS}) -Im [iIjJ] -CCHAR [#%] -COMMENT ({CCHAR}.*{NL}) -SNLCMT ({SNL}|{COMMENT}) -NOT ((\~)|(\!)) +D [0-9] +S [ \t] +NL ((\n)|(\r)|(\r\n)) +SNL ({S}|{NL}) +EL (\.\.\.) +BS (\\) +CONT ({EL}|{BS}) +Im [iIjJ] +CCHAR [#%] +COMMENT ({CCHAR}.*{NL}) +SNLCMT ({SNL}|{COMMENT}) +NOT ((\~)|(\!)) POW ((\*\*)|(\^)) EPOW (\.{POW}) -IDENT ([_$a-zA-Z][_$a-zA-Z0-9]*) -EXPON ([DdEe][+-]?{D}+) -NUMBER (({D}+\.?{D}*{EXPON}?)|(\.{D}+{EXPON}?)|(0[xX][0-9a-fA-F]+)) +IDENT ([_$a-zA-Z][_$a-zA-Z0-9]*) +EXPON ([DdEe][+-]?{D}+) +NUMBER (({D}+\.?{D}*{EXPON}?)|(\.{D}+{EXPON}?)|(0[xX][0-9a-fA-F]+)) %% %{ @@ -484,12 +484,12 @@ if (! lexer_flags.looking_at_object_index.front ()) { - if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) - { - maybe_warn_separator_insert (';'); - - xunput (';', yytext); - } + if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) + { + maybe_warn_separator_insert (';'); + + xunput (';', yytext); + } } COUNT_TOK_AND_RETURN (','); @@ -513,28 +513,28 @@ if (! lexer_flags.looking_at_object_index.front ()) { - bool bin_op = next_token_is_bin_op (true); - bool postfix_un_op = next_token_is_postfix_unary_op (true); - bool sep_op = next_token_is_sep_op (); - - if (! (postfix_un_op || bin_op || sep_op) - && nesting_level.is_bracket_or_brace () - && lexer_flags.convert_spaces_to_comma) - { - if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) - { - maybe_warn_separator_insert (';'); - - xunput (';', yytext); - } - - lexer_flags.quote_is_transpose = false; - lexer_flags.convert_spaces_to_comma = true; - - maybe_warn_separator_insert (','); - - COUNT_TOK_AND_RETURN (','); - } + bool bin_op = next_token_is_bin_op (true); + bool postfix_un_op = next_token_is_postfix_unary_op (true); + bool sep_op = next_token_is_sep_op (); + + if (! (postfix_un_op || bin_op || sep_op) + && nesting_level.is_bracket_or_brace () + && lexer_flags.convert_spaces_to_comma) + { + if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) + { + maybe_warn_separator_insert (';'); + + xunput (';', yytext); + } + + lexer_flags.quote_is_transpose = false; + lexer_flags.convert_spaces_to_comma = true; + + maybe_warn_separator_insert (','); + + COUNT_TOK_AND_RETURN (','); + } } } @@ -585,11 +585,11 @@ return LEXICAL_ERROR; if (! lexer_flags.looking_at_object_index.front () - && nesting_level.is_bracket_or_brace ()) + && nesting_level.is_bracket_or_brace ()) { - maybe_warn_separator_insert (';'); - - COUNT_TOK_AND_RETURN (';'); + maybe_warn_separator_insert (';'); + + COUNT_TOK_AND_RETURN (';'); } } @@ -689,12 +689,12 @@ if (block_comment_nesting_level != 0) { - warning ("block comment open at end of input"); - - if ((reading_fcn_file || reading_script_file || reading_classdef_file) - && ! curr_fcn_file_name.empty ()) - warning ("near line %d of file `%s.m'", - input_line_number, curr_fcn_file_name.c_str ()); + warning ("block comment open at end of input"); + + if ((reading_fcn_file || reading_script_file || reading_classdef_file) + && ! curr_fcn_file_name.empty ()) + warning ("near line %d of file `%s.m'", + input_line_number, curr_fcn_file_name.c_str ()); } TOK_RETURN (END_OF_INPUT); @@ -786,13 +786,13 @@ if (nesting_level.none ()) { - lexer_flags.at_beginning_of_statement = true; - COUNT_TOK_AND_RETURN ('\n'); + lexer_flags.at_beginning_of_statement = true; + COUNT_TOK_AND_RETURN ('\n'); } else if (nesting_level.is_paren ()) { - lexer_flags.at_beginning_of_statement = false; - gripe_matlab_incompatible ("bare newline inside parentheses"); + lexer_flags.at_beginning_of_statement = false; + gripe_matlab_incompatible ("bare newline inside parentheses"); } else if (nesting_level.is_bracket_or_brace ()) return LEXICAL_ERROR; @@ -811,13 +811,13 @@ if (lexer_flags.quote_is_transpose) { - do_comma_insert_check (); - COUNT_TOK_AND_RETURN (QUOTE); + do_comma_insert_check (); + COUNT_TOK_AND_RETURN (QUOTE); } else { - int tok = handle_string ('\''); - COUNT_TOK_AND_RETURN (tok); + int tok = handle_string ('\''); + COUNT_TOK_AND_RETURN (tok); } } @@ -878,39 +878,39 @@ ":" { LEXER_DEBUG (":"); BIN_OP_RETURN (':', false, false); } -".+" { LEXER_DEBUG (".+"); XBIN_OP_RETURN (EPLUS, false, false); } -".-" { LEXER_DEBUG (".-"); XBIN_OP_RETURN (EMINUS, false, false); } -".*" { LEXER_DEBUG (".*"); BIN_OP_RETURN (EMUL, false, false); } -"./" { LEXER_DEBUG ("./"); BIN_OP_RETURN (EDIV, false, false); } -".\\" { LEXER_DEBUG (".\\"); BIN_OP_RETURN (ELEFTDIV, false, false); } -".^" { LEXER_DEBUG (".^"); BIN_OP_RETURN (EPOW, false, false); } -".**" { LEXER_DEBUG (".**"); XBIN_OP_RETURN (EPOW, false, false); } -".'" { LEXER_DEBUG (".'"); do_comma_insert_check (); BIN_OP_RETURN (TRANSPOSE, true, false); } -"++" { LEXER_DEBUG ("++"); do_comma_insert_check (); XBIN_OP_RETURN (PLUS_PLUS, true, false); } -"--" { LEXER_DEBUG ("--"); do_comma_insert_check (); XBIN_OP_RETURN (MINUS_MINUS, true, false); } -"<=" { LEXER_DEBUG ("<="); BIN_OP_RETURN (EXPR_LE, false, false); } -"==" { LEXER_DEBUG ("=="); BIN_OP_RETURN (EXPR_EQ, false, false); } -"~=" { LEXER_DEBUG ("~="); BIN_OP_RETURN (EXPR_NE, false, false); } -"!=" { LEXER_DEBUG ("!="); XBIN_OP_RETURN (EXPR_NE, false, false); } -">=" { LEXER_DEBUG (">="); BIN_OP_RETURN (EXPR_GE, false, false); } -"&" { LEXER_DEBUG ("&"); BIN_OP_RETURN (EXPR_AND, false, false); } -"|" { LEXER_DEBUG ("|"); BIN_OP_RETURN (EXPR_OR, false, false); } -"<" { LEXER_DEBUG ("<"); BIN_OP_RETURN (EXPR_LT, false, false); } -">" { LEXER_DEBUG (">"); BIN_OP_RETURN (EXPR_GT, false, false); } +".+" { LEXER_DEBUG (".+"); XBIN_OP_RETURN (EPLUS, false, false); } +".-" { LEXER_DEBUG (".-"); XBIN_OP_RETURN (EMINUS, false, false); } +".*" { LEXER_DEBUG (".*"); BIN_OP_RETURN (EMUL, false, false); } +"./" { LEXER_DEBUG ("./"); BIN_OP_RETURN (EDIV, false, false); } +".\\" { LEXER_DEBUG (".\\"); BIN_OP_RETURN (ELEFTDIV, false, false); } +".^" { LEXER_DEBUG (".^"); BIN_OP_RETURN (EPOW, false, false); } +".**" { LEXER_DEBUG (".**"); XBIN_OP_RETURN (EPOW, false, false); } +".'" { LEXER_DEBUG (".'"); do_comma_insert_check (); BIN_OP_RETURN (TRANSPOSE, true, false); } +"++" { LEXER_DEBUG ("++"); do_comma_insert_check (); XBIN_OP_RETURN (PLUS_PLUS, true, false); } +"--" { LEXER_DEBUG ("--"); do_comma_insert_check (); XBIN_OP_RETURN (MINUS_MINUS, true, false); } +"<=" { LEXER_DEBUG ("<="); BIN_OP_RETURN (EXPR_LE, false, false); } +"==" { LEXER_DEBUG ("=="); BIN_OP_RETURN (EXPR_EQ, false, false); } +"~=" { LEXER_DEBUG ("~="); BIN_OP_RETURN (EXPR_NE, false, false); } +"!=" { LEXER_DEBUG ("!="); XBIN_OP_RETURN (EXPR_NE, false, false); } +">=" { LEXER_DEBUG (">="); BIN_OP_RETURN (EXPR_GE, false, false); } +"&" { LEXER_DEBUG ("&"); BIN_OP_RETURN (EXPR_AND, false, false); } +"|" { LEXER_DEBUG ("|"); BIN_OP_RETURN (EXPR_OR, false, false); } +"<" { LEXER_DEBUG ("<"); BIN_OP_RETURN (EXPR_LT, false, false); } +">" { LEXER_DEBUG (">"); BIN_OP_RETURN (EXPR_GT, false, false); } "+" { LEXER_DEBUG ("+"); BIN_OP_RETURN ('+', false, false); } "-" { LEXER_DEBUG ("-"); BIN_OP_RETURN ('-', false, false); } -"*" { LEXER_DEBUG ("*"); BIN_OP_RETURN ('*', false, false); } -"/" { LEXER_DEBUG ("/"); BIN_OP_RETURN ('/', false, false); } -"\\" { LEXER_DEBUG ("\\"); BIN_OP_RETURN (LEFTDIV, false, false); } +"*" { LEXER_DEBUG ("*"); BIN_OP_RETURN ('*', false, false); } +"/" { LEXER_DEBUG ("/"); BIN_OP_RETURN ('/', false, false); } +"\\" { LEXER_DEBUG ("\\"); BIN_OP_RETURN (LEFTDIV, false, false); } ";" { LEXER_DEBUG (";"); BIN_OP_RETURN (';', true, true); } "," { LEXER_DEBUG (","); BIN_OP_RETURN (',', true, ! lexer_flags.looking_at_object_index.front ()); } -"^" { LEXER_DEBUG ("^"); BIN_OP_RETURN (POW, false, false); } -"**" { LEXER_DEBUG ("**"); XBIN_OP_RETURN (POW, false, false); } -"=" { LEXER_DEBUG ("="); BIN_OP_RETURN ('=', true, false); } -"&&" { LEXER_DEBUG ("&&"); BIN_OP_RETURN (EXPR_AND_AND, false, false); } -"||" { LEXER_DEBUG ("||"); BIN_OP_RETURN (EXPR_OR_OR, false, false); } -"<<" { LEXER_DEBUG ("<<"); XBIN_OP_RETURN (LSHIFT, false, false); } -">>" { LEXER_DEBUG (">>"); XBIN_OP_RETURN (RSHIFT, false, false); } +"^" { LEXER_DEBUG ("^"); BIN_OP_RETURN (POW, false, false); } +"**" { LEXER_DEBUG ("**"); XBIN_OP_RETURN (POW, false, false); } +"=" { LEXER_DEBUG ("="); BIN_OP_RETURN ('=', true, false); } +"&&" { LEXER_DEBUG ("&&"); BIN_OP_RETURN (EXPR_AND_AND, false, false); } +"||" { LEXER_DEBUG ("||"); BIN_OP_RETURN (EXPR_OR_OR, false, false); } +"<<" { LEXER_DEBUG ("<<"); XBIN_OP_RETURN (LSHIFT, false, false); } +">>" { LEXER_DEBUG (">>"); XBIN_OP_RETURN (RSHIFT, false, false); } {NOT} { LEXER_DEBUG ("{NOT}"); @@ -969,22 +969,22 @@ TOK_RETURN ('.'); } -"+=" { LEXER_DEBUG ("+="); XBIN_OP_RETURN (ADD_EQ, false, false); } -"-=" { LEXER_DEBUG ("-="); XBIN_OP_RETURN (SUB_EQ, false, false); } -"*=" { LEXER_DEBUG ("*="); XBIN_OP_RETURN (MUL_EQ, false, false); } -"/=" { LEXER_DEBUG ("/="); XBIN_OP_RETURN (DIV_EQ, false, false); } -"\\=" { LEXER_DEBUG ("\\="); XBIN_OP_RETURN (LEFTDIV_EQ, false, false); } -".+=" { LEXER_DEBUG (".+="); XBIN_OP_RETURN (ADD_EQ, false, false); } -".-=" { LEXER_DEBUG (".-="); XBIN_OP_RETURN (SUB_EQ, false, false); } -".*=" { LEXER_DEBUG (".*="); XBIN_OP_RETURN (EMUL_EQ, false, false); } -"./=" { LEXER_DEBUG ("./="); XBIN_OP_RETURN (EDIV_EQ, false, false); } -".\\=" { LEXER_DEBUG (".\\="); XBIN_OP_RETURN (ELEFTDIV_EQ, false, false); } +"+=" { LEXER_DEBUG ("+="); XBIN_OP_RETURN (ADD_EQ, false, false); } +"-=" { LEXER_DEBUG ("-="); XBIN_OP_RETURN (SUB_EQ, false, false); } +"*=" { LEXER_DEBUG ("*="); XBIN_OP_RETURN (MUL_EQ, false, false); } +"/=" { LEXER_DEBUG ("/="); XBIN_OP_RETURN (DIV_EQ, false, false); } +"\\=" { LEXER_DEBUG ("\\="); XBIN_OP_RETURN (LEFTDIV_EQ, false, false); } +".+=" { LEXER_DEBUG (".+="); XBIN_OP_RETURN (ADD_EQ, false, false); } +".-=" { LEXER_DEBUG (".-="); XBIN_OP_RETURN (SUB_EQ, false, false); } +".*=" { LEXER_DEBUG (".*="); XBIN_OP_RETURN (EMUL_EQ, false, false); } +"./=" { LEXER_DEBUG ("./="); XBIN_OP_RETURN (EDIV_EQ, false, false); } +".\\=" { LEXER_DEBUG (".\\="); XBIN_OP_RETURN (ELEFTDIV_EQ, false, false); } {POW}= { LEXER_DEBUG ("{POW}="); XBIN_OP_RETURN (POW_EQ, false, false); } {EPOW}= { LEXER_DEBUG ("{EPOW}="); XBIN_OP_RETURN (EPOW_EQ, false, false); } -"&=" { LEXER_DEBUG ("&="); XBIN_OP_RETURN (AND_EQ, false, false); } -"|=" { LEXER_DEBUG ("|="); XBIN_OP_RETURN (OR_EQ, false, false); } -"<<=" { LEXER_DEBUG ("<<="); XBIN_OP_RETURN (LSHIFT_EQ, false, false); } -">>=" { LEXER_DEBUG (">>="); XBIN_OP_RETURN (RSHIFT_EQ, false, false); } +"&=" { LEXER_DEBUG ("&="); XBIN_OP_RETURN (AND_EQ, false, false); } +"|=" { LEXER_DEBUG ("|="); XBIN_OP_RETURN (OR_EQ, false, false); } +"<<=" { LEXER_DEBUG ("<<="); XBIN_OP_RETURN (LSHIFT_EQ, false, false); } +">>=" { LEXER_DEBUG (">>="); XBIN_OP_RETURN (RSHIFT_EQ, false, false); } \{{S}* { LEXER_DEBUG ("\\{{S}*"); @@ -1034,13 +1034,13 @@ if (c != EOF) { - current_input_column++; - - error ("invalid character `%s' (ASCII %d) near line %d, column %d", - undo_string_escape (static_cast (c)), c, - input_line_number, current_input_column); - - return LEXICAL_ERROR; + current_input_column++; + + error ("invalid character `%s' (ASCII %d) near line %d, column %d", + undo_string_escape (static_cast (c)), c, + input_line_number, current_input_column); + + return LEXICAL_ERROR; } else TOK_RETURN (END_OF_INPUT); @@ -1066,7 +1066,7 @@ xunput (' ', yytext); lexer_flags.do_comma_insert = (! lexer_flags.looking_at_object_index.front () - && lexer_flags.bracketflag && c == '['); + && lexer_flags.bracketflag && c == '['); } // Fix things up for errors or interrupts. The parser is never called @@ -1113,9 +1113,9 @@ if ((interactive || forced_interactive) && ! (reading_fcn_file || reading_classdef_file - || reading_script_file - || get_input_from_eval_string - || input_from_startup_file)) + || reading_script_file + || get_input_from_eval_string + || input_from_startup_file)) yyrestart (stdin); // Clear the buffer for help text. @@ -1135,140 +1135,140 @@ switch (c) { case 0: - std::cerr << "NUL"; - break; + std::cerr << "NUL"; + break; case 1: - std::cerr << "SOH"; - break; + std::cerr << "SOH"; + break; case 2: - std::cerr << "STX"; - break; + std::cerr << "STX"; + break; case 3: - std::cerr << "ETX"; - break; + std::cerr << "ETX"; + break; case 4: - std::cerr << "EOT"; - break; + std::cerr << "EOT"; + break; case 5: - std::cerr << "ENQ"; - break; + std::cerr << "ENQ"; + break; case 6: - std::cerr << "ACK"; - break; + std::cerr << "ACK"; + break; case 7: - std::cerr << "\\a"; - break; + std::cerr << "\\a"; + break; case 8: - std::cerr << "\\b"; - break; + std::cerr << "\\b"; + break; case 9: - std::cerr << "\\t"; - break; + std::cerr << "\\t"; + break; case 10: - std::cerr << "\\n"; - break; + std::cerr << "\\n"; + break; case 11: - std::cerr << "\\v"; - break; + std::cerr << "\\v"; + break; case 12: - std::cerr << "\\f"; - break; + std::cerr << "\\f"; + break; case 13: - std::cerr << "\\r"; - break; + std::cerr << "\\r"; + break; case 14: - std::cerr << "SO"; - break; + std::cerr << "SO"; + break; case 15: - std::cerr << "SI"; - break; + std::cerr << "SI"; + break; case 16: - std::cerr << "DLE"; - break; + std::cerr << "DLE"; + break; case 17: - std::cerr << "DC1"; - break; + std::cerr << "DC1"; + break; case 18: - std::cerr << "DC2"; - break; + std::cerr << "DC2"; + break; case 19: - std::cerr << "DC3"; - break; + std::cerr << "DC3"; + break; case 20: - std::cerr << "DC4"; - break; + std::cerr << "DC4"; + break; case 21: - std::cerr << "NAK"; - break; + std::cerr << "NAK"; + break; case 22: - std::cerr << "SYN"; - break; + std::cerr << "SYN"; + break; case 23: - std::cerr << "ETB"; - break; + std::cerr << "ETB"; + break; case 24: - std::cerr << "CAN"; - break; + std::cerr << "CAN"; + break; case 25: - std::cerr << "EM"; - break; + std::cerr << "EM"; + break; case 26: - std::cerr << "SUB"; - break; + std::cerr << "SUB"; + break; case 27: - std::cerr << "ESC"; - break; + std::cerr << "ESC"; + break; case 28: - std::cerr << "FS"; - break; + std::cerr << "FS"; + break; case 29: - std::cerr << "GS"; - break; + std::cerr << "GS"; + break; case 30: - std::cerr << "RS"; - break; + std::cerr << "RS"; + break; case 31: - std::cerr << "US"; - break; + std::cerr << "US"; + break; case 32: - std::cerr << "SPACE"; - break; + std::cerr << "SPACE"; + break; case 127: - std::cerr << "DEL"; - break; + std::cerr << "DEL"; + break; } } @@ -1291,17 +1291,17 @@ c = yyinput (); if (lexer_debug_flag) - { - std::cerr << "I: "; - display_character (c); - std::cerr << std::endl; - } + { + std::cerr << "I: "; + display_character (c); + std::cerr << std::endl; + } if (c != '\n') - { - xunput (c, yytext); - c = '\n'; - } + { + xunput (c, yytext); + c = '\n'; + } } if (c == '\n') @@ -1341,7 +1341,7 @@ current_input_column = 1; } else - current_input_column++; + current_input_column++; } } @@ -1410,10 +1410,10 @@ i != lexer_flags.looking_at_object_index.end (); i++) { if (*i) - { - retval = true; - break; - } + { + retval = true; + break; + } } return retval; @@ -1436,168 +1436,168 @@ yylval.tok_val = 0; switch (kw->kw_id) - { - case break_kw: - case catch_kw: - case continue_kw: - case else_kw: - case otherwise_kw: - case return_kw: - case unwind_protect_cleanup_kw: - lexer_flags.at_beginning_of_statement = true; - break; - - case case_kw: - case elseif_kw: - case global_kw: - case static_kw: - case until_kw: - break; - - case end_kw: - if (! reading_classdef_file - && (inside_any_object_index () - || (lexer_flags.defining_func - && ! (lexer_flags.looking_at_return_list - || lexer_flags.parsed_function_name)))) - return 0; - - yylval.tok_val = new token (token::simple_end, l, c); - lexer_flags.at_beginning_of_statement = true; - break; - - case end_try_catch_kw: - yylval.tok_val = new token (token::try_catch_end, l, c); - lexer_flags.at_beginning_of_statement = true; - break; - - case end_unwind_protect_kw: - yylval.tok_val = new token (token::unwind_protect_end, l, c); - lexer_flags.at_beginning_of_statement = true; - break; - - case endfor_kw: - yylval.tok_val = new token (token::for_end, l, c); - lexer_flags.at_beginning_of_statement = true; - break; - - case endfunction_kw: - yylval.tok_val = new token (token::function_end, l, c); - lexer_flags.at_beginning_of_statement = true; - break; - - case endif_kw: - yylval.tok_val = new token (token::if_end, l, c); - lexer_flags.at_beginning_of_statement = true; - break; - - case endswitch_kw: - yylval.tok_val = new token (token::switch_end, l, c); - lexer_flags.at_beginning_of_statement = true; - break; - - case endwhile_kw: - yylval.tok_val = new token (token::while_end, l, c); - lexer_flags.at_beginning_of_statement = true; - break; - - case endclassdef_kw: - yylval.tok_val = new token (token::classdef_end, l, c); - lexer_flags.at_beginning_of_statement = true; - break; - - case endevents_kw: - yylval.tok_val = new token (token::events_end, l, c); - lexer_flags.at_beginning_of_statement = true; - break; - - case endmethods_kw: - yylval.tok_val = new token (token::methods_end, l, c); - lexer_flags.at_beginning_of_statement = true; - break; - - case endproperties_kw: - yylval.tok_val = new token (token::properties_end, l, c); - lexer_flags.at_beginning_of_statement = true; - break; - - case for_kw: - case while_kw: - promptflag--; - lexer_flags.looping++; - break; - - case do_kw: - lexer_flags.at_beginning_of_statement = true; - promptflag--; - lexer_flags.looping++; - break; - - case try_kw: - case unwind_protect_kw: - lexer_flags.at_beginning_of_statement = true; - promptflag--; - break; - - case if_kw: - case switch_kw: - promptflag--; - break; - - case get_kw: - case set_kw: - // 'get' and 'set' are keywords in classdef method - // declarations. - if (! lexer_flags.maybe_classdef_get_set_method) - return 0; - break; - - case properties_kw: - case methods_kw: - case events_kw: - // 'properties', 'methods' and 'events' are keywords for - // classdef blocks. - if (! lexer_flags.parsing_classdef) - return 0; - // fall through ... - - case classdef_kw: - // 'classdef' is always a keyword. - promptflag--; - break; - - case function_kw: - promptflag--; - - lexer_flags.defining_func = true; - lexer_flags.parsed_function_name = false; - - if (! (reading_fcn_file || reading_script_file - || reading_classdef_file)) - input_line_number = 1; - break; + { + case break_kw: + case catch_kw: + case continue_kw: + case else_kw: + case otherwise_kw: + case return_kw: + case unwind_protect_cleanup_kw: + lexer_flags.at_beginning_of_statement = true; + break; + + case case_kw: + case elseif_kw: + case global_kw: + case static_kw: + case until_kw: + break; + + case end_kw: + if (! reading_classdef_file + && (inside_any_object_index () + || (lexer_flags.defining_func + && ! (lexer_flags.looking_at_return_list + || lexer_flags.parsed_function_name)))) + return 0; + + yylval.tok_val = new token (token::simple_end, l, c); + lexer_flags.at_beginning_of_statement = true; + break; + + case end_try_catch_kw: + yylval.tok_val = new token (token::try_catch_end, l, c); + lexer_flags.at_beginning_of_statement = true; + break; + + case end_unwind_protect_kw: + yylval.tok_val = new token (token::unwind_protect_end, l, c); + lexer_flags.at_beginning_of_statement = true; + break; + + case endfor_kw: + yylval.tok_val = new token (token::for_end, l, c); + lexer_flags.at_beginning_of_statement = true; + break; + + case endfunction_kw: + yylval.tok_val = new token (token::function_end, l, c); + lexer_flags.at_beginning_of_statement = true; + break; + + case endif_kw: + yylval.tok_val = new token (token::if_end, l, c); + lexer_flags.at_beginning_of_statement = true; + break; + + case endswitch_kw: + yylval.tok_val = new token (token::switch_end, l, c); + lexer_flags.at_beginning_of_statement = true; + break; + + case endwhile_kw: + yylval.tok_val = new token (token::while_end, l, c); + lexer_flags.at_beginning_of_statement = true; + break; + + case endclassdef_kw: + yylval.tok_val = new token (token::classdef_end, l, c); + lexer_flags.at_beginning_of_statement = true; + break; + + case endevents_kw: + yylval.tok_val = new token (token::events_end, l, c); + lexer_flags.at_beginning_of_statement = true; + break; + + case endmethods_kw: + yylval.tok_val = new token (token::methods_end, l, c); + lexer_flags.at_beginning_of_statement = true; + break; + + case endproperties_kw: + yylval.tok_val = new token (token::properties_end, l, c); + lexer_flags.at_beginning_of_statement = true; + break; + + case for_kw: + case while_kw: + promptflag--; + lexer_flags.looping++; + break; + + case do_kw: + lexer_flags.at_beginning_of_statement = true; + promptflag--; + lexer_flags.looping++; + break; + + case try_kw: + case unwind_protect_kw: + lexer_flags.at_beginning_of_statement = true; + promptflag--; + break; + + case if_kw: + case switch_kw: + promptflag--; + break; + + case get_kw: + case set_kw: + // 'get' and 'set' are keywords in classdef method + // declarations. + if (! lexer_flags.maybe_classdef_get_set_method) + return 0; + break; + + case properties_kw: + case methods_kw: + case events_kw: + // 'properties', 'methods' and 'events' are keywords for + // classdef blocks. + if (! lexer_flags.parsing_classdef) + return 0; + // fall through ... + + case classdef_kw: + // 'classdef' is always a keyword. + promptflag--; + break; + + case function_kw: + promptflag--; + + lexer_flags.defining_func = true; + lexer_flags.parsed_function_name = false; + + if (! (reading_fcn_file || reading_script_file + || reading_classdef_file)) + input_line_number = 1; + break; case magic_file_kw: - { - if ((reading_fcn_file || reading_script_file - || reading_classdef_file) - && ! curr_fcn_file_full_name.empty ()) - yylval.tok_val = new token (curr_fcn_file_full_name, l, c); - else - yylval.tok_val = new token ("stdin", l, c); - } - break; + { + if ((reading_fcn_file || reading_script_file + || reading_classdef_file) + && ! curr_fcn_file_full_name.empty ()) + yylval.tok_val = new token (curr_fcn_file_full_name, l, c); + else + yylval.tok_val = new token ("stdin", l, c); + } + break; case magic_line_kw: - yylval.tok_val = new token (static_cast (l), "", l, c); - break; - - default: - panic_impossible (); - } + yylval.tok_val = new token (static_cast (l), "", l, c); + break; + + default: + panic_impossible (); + } if (! yylval.tok_val) - yylval.tok_val = new token (l, c); + yylval.tok_val = new token (l, c); token_stack.push (yylval.tok_val); @@ -1611,8 +1611,8 @@ is_variable (const std::string& name) { return (symbol_table::is_variable (name) - || (lexer_flags.pending_local_variables.find (name) - != lexer_flags.pending_local_variables.end ())); + || (lexer_flags.pending_local_variables.find (name) + != lexer_flags.pending_local_variables.end ())); } static std::string @@ -1632,87 +1632,87 @@ current_input_column++; if (look_for_marker) - { - at_bol = false; - look_for_marker = false; - - if (c == '{' || c == '}') - { - std::string tmp_buf (1, static_cast (c)); - - int type = c; - - bool done = false; - - while ((c = reader.getc ()) != EOF && ! done) - { - current_input_column++; - - switch (c) - { - case ' ': - case '\t': - tmp_buf += static_cast (c); - break; - - case '\n': - { - current_input_column = 0; - at_bol = true; - done = true; - - if (type == '{') - { - block_comment_nesting_level++; - promptflag--; - } - else - { - block_comment_nesting_level--; - promptflag++; - - if (block_comment_nesting_level == 0) - { - buf += grab_comment_block (reader, true, eof); - - return buf; - } - } - } - break; - - default: - at_bol = false; - tmp_buf += static_cast (c); - buf += tmp_buf; - done = true; - break; - } - } - } - } + { + at_bol = false; + look_for_marker = false; + + if (c == '{' || c == '}') + { + std::string tmp_buf (1, static_cast (c)); + + int type = c; + + bool done = false; + + while ((c = reader.getc ()) != EOF && ! done) + { + current_input_column++; + + switch (c) + { + case ' ': + case '\t': + tmp_buf += static_cast (c); + break; + + case '\n': + { + current_input_column = 0; + at_bol = true; + done = true; + + if (type == '{') + { + block_comment_nesting_level++; + promptflag--; + } + else + { + block_comment_nesting_level--; + promptflag++; + + if (block_comment_nesting_level == 0) + { + buf += grab_comment_block (reader, true, eof); + + return buf; + } + } + } + break; + + default: + at_bol = false; + tmp_buf += static_cast (c); + buf += tmp_buf; + done = true; + break; + } + } + } + } if (at_bol && (c == '%' || c == '#')) { if (c == '#' && ! warned_incompatible) - { - warned_incompatible = true; - maybe_gripe_matlab_incompatible_comment (c); - } - - at_bol = false; - look_for_marker = true; - } + { + warned_incompatible = true; + maybe_gripe_matlab_incompatible_comment (c); + } + + at_bol = false; + look_for_marker = true; + } else - { - buf += static_cast (c); - - if (c == '\n') - { - current_input_column = 0; - at_bol = true; - } - } + { + buf += static_cast (c); + + if (c == '\n') + { + current_input_column = 0; + at_bol = true; + } + } } if (c == EOF) @@ -1723,7 +1723,7 @@ std::string grab_comment_block (stream_reader& reader, bool at_bol, - bool& eof) + bool& eof) { std::string buf; @@ -1742,115 +1742,115 @@ current_input_column++; if (begin_comment) - { - if (c == '%' || c == '#') - { - at_bol = false; - continue; - } - else if (at_bol && c == '{') - { - std::string tmp_buf (1, static_cast (c)); - - bool done = false; - - while ((c = reader.getc ()) != EOF && ! done) - { - current_input_column++; - - switch (c) - { - case ' ': - case '\t': - tmp_buf += static_cast (c); - break; - - case '\n': - { - current_input_column = 0; - at_bol = true; - done = true; - - block_comment_nesting_level++; - promptflag--; - - buf += grab_block_comment (reader, eof); - - in_comment = false; - - if (eof) - goto done; - } - break; - - default: - at_bol = false; - tmp_buf += static_cast (c); - buf += tmp_buf; - done = true; - break; - } - } - } - else - { - at_bol = false; - begin_comment = false; - } - } + { + if (c == '%' || c == '#') + { + at_bol = false; + continue; + } + else if (at_bol && c == '{') + { + std::string tmp_buf (1, static_cast (c)); + + bool done = false; + + while ((c = reader.getc ()) != EOF && ! done) + { + current_input_column++; + + switch (c) + { + case ' ': + case '\t': + tmp_buf += static_cast (c); + break; + + case '\n': + { + current_input_column = 0; + at_bol = true; + done = true; + + block_comment_nesting_level++; + promptflag--; + + buf += grab_block_comment (reader, eof); + + in_comment = false; + + if (eof) + goto done; + } + break; + + default: + at_bol = false; + tmp_buf += static_cast (c); + buf += tmp_buf; + done = true; + break; + } + } + } + else + { + at_bol = false; + begin_comment = false; + } + } if (in_comment) - { - buf += static_cast (c); - - if (c == '\n') - { - at_bol = true; - current_input_column = 0; - in_comment = false; - - // FIXME -- bailing out here prevents things like - // - // octave> # comment - // octave> x = 1 - // - // from failing at the command line, while still - // allowing blocks of comments to be grabbed properly - // for function doc strings. But only the first line of - // a mult-line doc string will be picked up for - // functions defined on the command line. We need a - // better way of collecting these comments... - if (! (reading_fcn_file || reading_script_file)) - goto done; - } - } + { + buf += static_cast (c); + + if (c == '\n') + { + at_bol = true; + current_input_column = 0; + in_comment = false; + + // FIXME -- bailing out here prevents things like + // + // octave> # comment + // octave> x = 1 + // + // from failing at the command line, while still + // allowing blocks of comments to be grabbed properly + // for function doc strings. But only the first line of + // a mult-line doc string will be picked up for + // functions defined on the command line. We need a + // better way of collecting these comments... + if (! (reading_fcn_file || reading_script_file)) + goto done; + } + } else - { - switch (c) - { - case ' ': - case '\t': - break; - - case '#': - if (! warned_incompatible) - { - warned_incompatible = true; - maybe_gripe_matlab_incompatible_comment (c); - } - // fall through... - - case '%': - in_comment = true; - begin_comment = true; - break; - - default: - current_input_column--; - reader.ungetc (c); - goto done; - } - } + { + switch (c) + { + case ' ': + case '\t': + break; + + case '#': + if (! warned_incompatible) + { + warned_incompatible = true; + maybe_gripe_matlab_incompatible_comment (c); + } + // fall through... + + case '%': + in_comment = true; + begin_comment = true; + break; + + default: + current_input_column--; + reader.ungetc (c); + goto done; + } + } } done: @@ -1899,7 +1899,7 @@ if (help_txt.empty () && nesting_level.none ()) { if (! help_buf.empty ()) - help_buf.pop (); + help_buf.pop (); help_buf.push (txt); } @@ -1932,7 +1932,7 @@ while ((tmp = *s++) != '\0') { if (c == tmp) - return true; + return true; } return false; } @@ -2032,27 +2032,27 @@ case '+': case '-': { - int c1 = text_yyinput (); - - switch (c1) - { - case '+': - case '-': - // Unary ops, spacing doesn't matter. - break; - - case '=': - // Binary ops, spacing doesn't matter. - bin_op = true; - break; - - default: - // Could be either, spacing matters. - bin_op = looks_like_bin_op (spc_prev, c1); - break; - } - - xunput (c1, yytext); + int c1 = text_yyinput (); + + switch (c1) + { + case '+': + case '-': + // Unary ops, spacing doesn't matter. + break; + + case '=': + // Binary ops, spacing doesn't matter. + bin_op = true; + break; + + default: + // Could be either, spacing matters. + bin_op = looks_like_bin_op (spc_prev, c1); + break; + } + + xunput (c1, yytext); } break; @@ -2067,16 +2067,16 @@ // .+ .- ./ .\ .^ .* .** case '.': { - int c1 = text_yyinput (); - - if (match_any (c1, "+-/\\^*")) - // Always a binary op (may also include .+=, .-=, ./=, ...). - bin_op = true; - else if (! isdigit (c1) && c1 != ' ' && c1 != '\t' && c1 != '.') - // A structure element reference is a binary op. - bin_op = true; - - xunput (c1, yytext); + int c1 = text_yyinput (); + + if (match_any (c1, "+-/\\^*")) + // Always a binary op (may also include .+=, .-=, ./=, ...). + bin_op = true; + else if (! isdigit (c1) && c1 != ' ' && c1 != '\t' && c1 != '.') + // A structure element reference is a binary op. + bin_op = true; + + xunput (c1, yytext); } break; @@ -2100,13 +2100,13 @@ case '~': case '!': { - int c1 = text_yyinput (); - - // ~ and ! can be unary ops, so require following =. - if (c1 == '=') - bin_op = true; - - xunput (c1, yytext); + int c1 = text_yyinput (); + + // ~ and ! can be unary ops, so require following =. + if (c1 == '=') + bin_op = true; + + xunput (c1, yytext); } break; @@ -2152,41 +2152,41 @@ char c = text[i++]; switch (c) - { - case '%': - case '#': - if (in_comment) - { - if (! beginning_of_comment) - comment_buf += static_cast (c); - } - else - { - maybe_gripe_matlab_incompatible_comment (c); - in_comment = true; - beginning_of_comment = true; - } - break; - - case '\n': - if (in_comment) - { - comment_buf += static_cast (c); - octave_comment_buffer::append (comment_buf); - comment_buf.resize (0); - in_comment = false; - beginning_of_comment = false; - } - break; - - default: - if (in_comment) - { - comment_buf += static_cast (c); - beginning_of_comment = false; - } - break; - } + { + case '%': + case '#': + if (in_comment) + { + if (! beginning_of_comment) + comment_buf += static_cast (c); + } + else + { + maybe_gripe_matlab_incompatible_comment (c); + in_comment = true; + beginning_of_comment = true; + } + break; + + case '\n': + if (in_comment) + { + comment_buf += static_cast (c); + octave_comment_buffer::append (comment_buf); + comment_buf.resize (0); + in_comment = false; + beginning_of_comment = false; + } + break; + + default: + if (in_comment) + { + comment_buf += static_cast (c); + beginning_of_comment = false; + } + break; + } } if (! comment_buf.empty ()) @@ -2220,85 +2220,85 @@ current_input_column++; switch (c) - { - case ' ': - case '\t': - if (in_comment) - { - comment_buf += static_cast (c); - beginning_of_comment = false; - } - retval |= ATE_SPACE_OR_TAB; - break; - - case '\n': - retval |= ATE_NEWLINE; - if (in_comment) - { - comment_buf += static_cast (c); - octave_comment_buffer::append (comment_buf); - comment_buf.resize (0); - in_comment = false; - beginning_of_comment = false; - } - current_input_column = 0; - break; - - case '#': - case '%': - if (in_comment) - { - if (! beginning_of_comment) - comment_buf += static_cast (c); - } - else - { - maybe_gripe_matlab_incompatible_comment (c); - in_comment = true; - beginning_of_comment = true; - } - break; - - case '.': - if (in_comment) - { - comment_buf += static_cast (c); - beginning_of_comment = false; - break; - } - else - { - if (have_ellipsis_continuation ()) - break; - else - goto done; - } - - case '\\': - if (in_comment) - { - comment_buf += static_cast (c); - beginning_of_comment = false; - break; - } - else - { - if (have_continuation ()) - break; - else - goto done; - } - - default: - if (in_comment) - { - comment_buf += static_cast (c); - beginning_of_comment = false; - break; - } - else - goto done; - } + { + case ' ': + case '\t': + if (in_comment) + { + comment_buf += static_cast (c); + beginning_of_comment = false; + } + retval |= ATE_SPACE_OR_TAB; + break; + + case '\n': + retval |= ATE_NEWLINE; + if (in_comment) + { + comment_buf += static_cast (c); + octave_comment_buffer::append (comment_buf); + comment_buf.resize (0); + in_comment = false; + beginning_of_comment = false; + } + current_input_column = 0; + break; + + case '#': + case '%': + if (in_comment) + { + if (! beginning_of_comment) + comment_buf += static_cast (c); + } + else + { + maybe_gripe_matlab_incompatible_comment (c); + in_comment = true; + beginning_of_comment = true; + } + break; + + case '.': + if (in_comment) + { + comment_buf += static_cast (c); + beginning_of_comment = false; + break; + } + else + { + if (have_ellipsis_continuation ()) + break; + else + goto done; + } + + case '\\': + if (in_comment) + { + comment_buf += static_cast (c); + beginning_of_comment = false; + break; + } + else + { + if (have_continuation ()) + break; + else + goto done; + } + + default: + if (in_comment) + { + comment_buf += static_cast (c); + beginning_of_comment = false; + break; + } + else + goto done; + } } if (! comment_buf.empty ()) @@ -2337,7 +2337,7 @@ char *idx = strpbrk (tmp, "Dd"); if (idx) - *idx = 'e'; + *idx = 'e'; nread = sscanf (tmp, "%lf", &value); @@ -2354,7 +2354,7 @@ lexer_flags.at_beginning_of_statement = false; yylval.tok_val = new token (value, yytext, input_line_number, - current_input_column); + current_input_column); token_stack.push (yylval.tok_val); @@ -2391,57 +2391,57 @@ buf << static_cast (c); switch (c) - { - case ' ': - case '\t': - if (in_comment) - { - comment_buf += static_cast (c); - beginning_of_comment = false; - } - break; - - case '%': - case '#': - if (trailing_comments_ok) - { - if (in_comment) - { - if (! beginning_of_comment) - comment_buf += static_cast (c); - } - else - { - maybe_gripe_matlab_incompatible_comment (c); - in_comment = true; - beginning_of_comment = true; - } - } - else - goto cleanup; - break; - - case '\n': - if (in_comment) - { - comment_buf += static_cast (c); - octave_comment_buffer::append (comment_buf); - } - current_input_column = 0; - promptflag--; - gripe_matlab_incompatible_continuation (); - return true; - - default: - if (in_comment) - { - comment_buf += static_cast (c); - beginning_of_comment = false; - } - else - goto cleanup; - break; - } + { + case ' ': + case '\t': + if (in_comment) + { + comment_buf += static_cast (c); + beginning_of_comment = false; + } + break; + + case '%': + case '#': + if (trailing_comments_ok) + { + if (in_comment) + { + if (! beginning_of_comment) + comment_buf += static_cast (c); + } + else + { + maybe_gripe_matlab_incompatible_comment (c); + in_comment = true; + beginning_of_comment = true; + } + } + else + goto cleanup; + break; + + case '\n': + if (in_comment) + { + comment_buf += static_cast (c); + octave_comment_buffer::append (comment_buf); + } + current_input_column = 0; + promptflag--; + gripe_matlab_incompatible_continuation (); + return true; + + default: + if (in_comment) + { + comment_buf += static_cast (c); + beginning_of_comment = false; + } + else + goto cleanup; + break; + } } xunput (c, yytext); @@ -2470,12 +2470,12 @@ { char c2 = text_yyinput (); if (c2 == '.' && have_continuation (trailing_comments_ok)) - return true; + return true; else - { - xunput (c2, yytext); - xunput (c1, yytext); - } + { + xunput (c2, yytext); + xunput (c1, yytext); + } } else xunput (c1, yytext); @@ -2520,77 +2520,77 @@ current_input_column++; if (c == '\\') - { - if (delim == '\'' || escape_pending) - { - buf << static_cast (c); - escape_pending = 0; - } - else - { - if (have_continuation (false)) - escape_pending = 0; - else - { - buf << static_cast (c); - escape_pending = 1; - } - } - continue; - } + { + if (delim == '\'' || escape_pending) + { + buf << static_cast (c); + escape_pending = 0; + } + else + { + if (have_continuation (false)) + escape_pending = 0; + else + { + buf << static_cast (c); + escape_pending = 1; + } + } + continue; + } else if (c == '.') - { - if (delim == '\'' || ! have_ellipsis_continuation (false)) - buf << static_cast (c); - } + { + if (delim == '\'' || ! have_ellipsis_continuation (false)) + buf << static_cast (c); + } else if (c == '\n') - { - error ("unterminated string constant"); - break; - } + { + error ("unterminated string constant"); + break; + } else if (c == delim) - { - if (escape_pending) - buf << static_cast (c); - else - { - c = text_yyinput (); - if (c == delim) - { - buf << static_cast (c); - } - else - { - std::string s; - xunput (c, yytext); - - if (delim == '\'') - s = buf.str (); - else - s = do_string_escapes (buf.str ()); - - lexer_flags.quote_is_transpose = true; - lexer_flags.convert_spaces_to_comma = true; - - yylval.tok_val = new token (s, bos_line, bos_col); - token_stack.push (yylval.tok_val); - - if (delim == '"') - gripe_matlab_incompatible ("\" used as string delimiter"); - else if (delim == '\'') - gripe_single_quote_string (); + { + if (escape_pending) + buf << static_cast (c); + else + { + c = text_yyinput (); + if (c == delim) + { + buf << static_cast (c); + } + else + { + std::string s; + xunput (c, yytext); + + if (delim == '\'') + s = buf.str (); + else + s = do_string_escapes (buf.str ()); + + lexer_flags.quote_is_transpose = true; + lexer_flags.convert_spaces_to_comma = true; + + yylval.tok_val = new token (s, bos_line, bos_col); + token_stack.push (yylval.tok_val); + + if (delim == '"') + gripe_matlab_incompatible ("\" used as string delimiter"); + else if (delim == '\'') + gripe_single_quote_string (); lexer_flags.looking_for_object_index = true; - lexer_flags.at_beginning_of_statement = false; - - return delim == '"' ? DQ_STRING : SQ_STRING; - } - } - } + lexer_flags.at_beginning_of_statement = false; + + return delim == '"' ? DQ_STRING : SQ_STRING; + } + } + } else - { - buf << static_cast (c); - } + { + buf << static_cast (c); + } escape_pending = 0; } @@ -2609,10 +2609,10 @@ { case '=': { - int c1 = text_yyinput (); - xunput (c1, yytext); - if (c1 != '=') - retval = true; + int c1 = text_yyinput (); + xunput (c1, yytext); + if (c1 != '=') + retval = true; } break; @@ -2624,52 +2624,52 @@ case '&': case '|': { - int c1 = text_yyinput (); - xunput (c1, yytext); - if (c1 == '=') - retval = true; + int c1 = text_yyinput (); + xunput (c1, yytext); + if (c1 == '=') + retval = true; } break; case '.': { - int c1 = text_yyinput (); - if (match_any (c1, "+-*/\\")) - { - int c2 = text_yyinput (); - xunput (c2, yytext); - if (c2 == '=') - retval = true; - } - xunput (c1, yytext); + int c1 = text_yyinput (); + if (match_any (c1, "+-*/\\")) + { + int c2 = text_yyinput (); + xunput (c2, yytext); + if (c2 == '=') + retval = true; + } + xunput (c1, yytext); } break; case '>': { - int c1 = text_yyinput (); - if (c1 == '>') - { - int c2 = text_yyinput (); - xunput (c2, yytext); - if (c2 == '=') - retval = true; - } - xunput (c1, yytext); + int c1 = text_yyinput (); + if (c1 == '>') + { + int c2 = text_yyinput (); + xunput (c2, yytext); + if (c2 == '=') + retval = true; + } + xunput (c1, yytext); } break; case '<': { - int c1 = text_yyinput (); - if (c1 == '<') - { - int c2 = text_yyinput (); - xunput (c2, yytext); - if (c2 == '=') - retval = true; - } - xunput (c1, yytext); + int c1 = text_yyinput (); + if (c1 == '<') + { + int c2 = text_yyinput (); + xunput (c2, yytext); + if (c2 == '=') + retval = true; + } + xunput (c1, yytext); } break; @@ -2700,11 +2700,11 @@ nesting_level.remove (); if (bracket_type == ']') - lexer_flags.bracketflag--; + lexer_flags.bracketflag--; else if (bracket_type == '}') - lexer_flags.braceflag--; + lexer_flags.braceflag--; else - panic_impossible (); + panic_impossible (); } if (lexer_flags.bracketflag == 0 && lexer_flags.braceflag == 0) @@ -2717,10 +2717,10 @@ retval = CLOSE_BRACE; } else if ((lexer_flags.bracketflag || lexer_flags.braceflag) - && lexer_flags.convert_spaces_to_comma - && (nesting_level.is_bracket () - || (nesting_level.is_brace () - && ! lexer_flags.looking_at_object_index.front ()))) + && lexer_flags.convert_spaces_to_comma + && (nesting_level.is_bracket () + || (nesting_level.is_brace () + && ! lexer_flags.looking_at_object_index.front ()))) { bool index_op = next_token_is_index_op (); @@ -2733,21 +2733,21 @@ // [x{i} {j}] or [x{i} (j)] if (spc_gobbled || ! (bracket_type == '}' && index_op)) - { - bool bin_op = next_token_is_bin_op (spc_gobbled); - - bool postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); - - bool sep_op = next_token_is_sep_op (); - - if (! (postfix_un_op || bin_op || sep_op)) - { - maybe_warn_separator_insert (','); - - xunput (',', yytext); - return retval; - } - } + { + bool bin_op = next_token_is_bin_op (spc_gobbled); + + bool postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); + + bool sep_op = next_token_is_sep_op (); + + if (! (postfix_un_op || bin_op || sep_op)) + { + maybe_warn_separator_insert (','); + + xunput (',', yytext); + return retval; + } + } } lexer_flags.quote_is_transpose = true; @@ -2761,7 +2761,7 @@ { if (nesting_level.is_bracket () || (nesting_level.is_brace () - && ! lexer_flags.looking_at_object_index.front ())) + && ! lexer_flags.looking_at_object_index.front ())) { int bin_op = next_token_is_bin_op (spc_gobbled); @@ -2776,10 +2776,10 @@ int sep_op = next_token_is_sep_op (); int dot_op = (c1 == '.' - && (isalpha (c2) || isspace (c2) || c2 == '_')); + && (isalpha (c2) || isspace (c2) || c2 == '_')); if (postfix_un_op || bin_op || sep_op || dot_op) - return; + return; int index_op = (c1 == '(' || c1 == '{'); @@ -2787,7 +2787,7 @@ // a comma. if (index_op && ! spc_gobbled) - return; + return; maybe_warn_separator_insert (','); @@ -2810,7 +2810,7 @@ buf.push (c); if (match_any (c, ",;\n") || (c != ' ' && c != '\t')) - break; + break; } // Restore input. @@ -2849,22 +2849,22 @@ // = == case '=': { - int c1 = text_yyinput (); - - if (c1 == '=') - { - int c2 = text_yyinput (); - - if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') - && next_token_can_follow_bin_op ()) - retval = false; - - xunput (c2, yytext); - } - else - retval = false; - - xunput (c1, yytext); + int c1 = text_yyinput (); + + if (c1 == '=') + { + int c2 = text_yyinput (); + + if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') + && next_token_can_follow_bin_op ()) + retval = false; + + xunput (c2, yytext); + } + else + retval = false; + + xunput (c1, yytext); } break; @@ -2887,39 +2887,39 @@ case '+': case '-': { - int c1 = text_yyinput (); - - switch (c1) - { - case '\n': - // EOL. - case '+': - case '-': - // Unary ops, spacing doesn't matter. - break; - - case '\t': - case ' ': - { - if (next_token_can_follow_bin_op ()) - retval = false; - } - break; - - case '=': - { - int c2 = text_yyinput (); - - if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') - && next_token_can_follow_bin_op ()) - retval = false; - - xunput (c2, yytext); - } - break; - } - - xunput (c1, yytext); + int c1 = text_yyinput (); + + switch (c1) + { + case '\n': + // EOL. + case '+': + case '-': + // Unary ops, spacing doesn't matter. + break; + + case '\t': + case ' ': + { + if (next_token_can_follow_bin_op ()) + retval = false; + } + break; + + case '=': + { + int c2 = text_yyinput (); + + if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') + && next_token_can_follow_bin_op ()) + retval = false; + + xunput (c2, yytext); + } + break; + } + + xunput (c1, yytext); } break; @@ -2928,51 +2928,51 @@ case '\\': case '^': { - int c1 = text_yyinput (); - - if (! match_any (c1, ",;\n") && (c1 == ' ' || c1 == '\t') - && next_token_can_follow_bin_op ()) - retval = false; - - xunput (c1, yytext); + int c1 = text_yyinput (); + + if (! match_any (c1, ",;\n") && (c1 == ' ' || c1 == '\t') + && next_token_can_follow_bin_op ()) + retval = false; + + xunput (c1, yytext); } break; // .+ .- ./ .\ .^ .* .** case '.': { - int c1 = text_yyinput (); - - if (match_any (c1, "+-/\\^*")) - { - int c2 = text_yyinput (); - - if (c2 == '=') - { - int c3 = text_yyinput (); - - if (! match_any (c3, ",;\n") && (c3 == ' ' || c3 == '\t') - && next_token_can_follow_bin_op ()) - retval = false; - - xunput (c3, yytext); - } - else if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') - && next_token_can_follow_bin_op ()) - retval = false; - - xunput (c2, yytext); - } - else if (! match_any (c1, ",;\n") - && (! isdigit (c1) && c1 != ' ' && c1 != '\t' - && c1 != '.')) - { - // Structure reference. FIXME -- is this a complete check? - - retval = false; - } - - xunput (c1, yytext); + int c1 = text_yyinput (); + + if (match_any (c1, "+-/\\^*")) + { + int c2 = text_yyinput (); + + if (c2 == '=') + { + int c3 = text_yyinput (); + + if (! match_any (c3, ",;\n") && (c3 == ' ' || c3 == '\t') + && next_token_can_follow_bin_op ()) + retval = false; + + xunput (c3, yytext); + } + else if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') + && next_token_can_follow_bin_op ()) + retval = false; + + xunput (c2, yytext); + } + else if (! match_any (c1, ",;\n") + && (! isdigit (c1) && c1 != ' ' && c1 != '\t' + && c1 != '.')) + { + // Structure reference. FIXME -- is this a complete check? + + retval = false; + } + + xunput (c1, yytext); } break; @@ -2981,23 +2981,23 @@ case '|': case '*': { - int c1 = text_yyinput (); - - if (c1 == c0) - { - int c2 = text_yyinput (); - - if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') - && next_token_can_follow_bin_op ()) - retval = false; - - xunput (c2, yytext); - } - else if (! match_any (c1, ",;\n") && (c1 == ' ' || c1 == '\t') - && next_token_can_follow_bin_op ()) - retval = false; - - xunput (c1, yytext); + int c1 = text_yyinput (); + + if (c1 == c0) + { + int c2 = text_yyinput (); + + if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') + && next_token_can_follow_bin_op ()) + retval = false; + + xunput (c2, yytext); + } + else if (! match_any (c1, ",;\n") && (c1 == ' ' || c1 == '\t') + && next_token_can_follow_bin_op ()) + retval = false; + + xunput (c1, yytext); } break; @@ -3005,23 +3005,23 @@ case '<': case '>': { - int c1 = text_yyinput (); - - if (c1 == '=') - { - int c2 = text_yyinput (); - - if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') - && next_token_can_follow_bin_op ()) - retval = false; - - xunput (c2, yytext); - } - else if (! match_any (c1, ",;\n") && (c1 == ' ' || c1 == '\t') - && next_token_can_follow_bin_op ()) - retval = false; - - xunput (c1, yytext); + int c1 = text_yyinput (); + + if (c1 == '=') + { + int c2 = text_yyinput (); + + if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') + && next_token_can_follow_bin_op ()) + retval = false; + + xunput (c2, yytext); + } + else if (! match_any (c1, ",;\n") && (c1 == ' ' || c1 == '\t') + && next_token_can_follow_bin_op ()) + retval = false; + + xunput (c1, yytext); } break; @@ -3029,24 +3029,24 @@ case '~': case '!': { - int c1 = text_yyinput (); - - // ~ and ! can be unary ops, so require following =. - if (c1 == '=') - { - int c2 = text_yyinput (); - - if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') - && next_token_can_follow_bin_op ()) - retval = false; - - xunput (c2, yytext); - } - else if (! match_any (c1, ",;\n") && (c1 == ' ' || c1 == '\t') - && next_token_can_follow_bin_op ()) - retval = false; - - xunput (c1, yytext); + int c1 = text_yyinput (); + + // ~ and ! can be unary ops, so require following =. + if (c1 == '=') + { + int c2 = text_yyinput (); + + if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') + && next_token_can_follow_bin_op ()) + retval = false; + + xunput (c2, yytext); + } + else if (! match_any (c1, ",;\n") && (c1 == ' ' || c1 == '\t') + && next_token_can_follow_bin_op ()) + retval = false; + + xunput (c1, yytext); } break; @@ -3072,13 +3072,13 @@ pos = cls.find ("."); if (pos != std::string::npos) - { + { pkg = cls.substr (pos).substr (1); cls = cls.substr (0, pos - 1); } int kw_token = (is_keyword_token (meth) || is_keyword_token (cls) - || is_keyword_token (pkg)); + || is_keyword_token (pkg)); if (kw_token) { error ("method, class and package names may not be keywords"); @@ -3089,7 +3089,7 @@ = new token (meth.empty () ? 0 : &(symbol_table::insert (meth)), cls.empty () ? 0 : &(symbol_table::insert (cls)), pkg.empty () ? 0 : &(symbol_table::insert (pkg)), - input_line_number, current_input_column); + input_line_number, current_input_column); token_stack.push (yylval.tok_val); lexer_flags.convert_spaces_to_comma = true; @@ -3108,7 +3108,7 @@ size_t pos = cls.find ("."); if (pos != std::string::npos) - { + { pkg = cls.substr (pos).substr (1); cls = cls.substr (0, pos - 1); } @@ -3122,8 +3122,8 @@ yylval.tok_val = new token (cls.empty () ? 0 : &(symbol_table::insert (cls)), - pkg.empty () ? 0 : &(symbol_table::insert (pkg)), - input_line_number, current_input_column); + pkg.empty () ? 0 : &(symbol_table::insert (pkg)), + input_line_number, current_input_column); token_stack.push (yylval.tok_val); @@ -3162,7 +3162,7 @@ maybe_unput_comma (spc_gobbled); yylval.tok_val = new token (tok, input_line_number, - current_input_column); + current_input_column); token_stack.push (yylval.tok_val); @@ -3191,25 +3191,25 @@ if (lexer_flags.looking_at_function_handle) { if (kw_token) - { - error ("function handles may not refer to keywords"); - - return LEXICAL_ERROR; - } + { + error ("function handles may not refer to keywords"); + + return LEXICAL_ERROR; + } else - { - yylval.tok_val = new token (tok, input_line_number, - current_input_column); - - token_stack.push (yylval.tok_val); - - current_input_column += yyleng; - lexer_flags.quote_is_transpose = false; - lexer_flags.convert_spaces_to_comma = true; - lexer_flags.looking_for_object_index = true; - - return FCN_HANDLE; - } + { + yylval.tok_val = new token (tok, input_line_number, + current_input_column); + + token_stack.push (yylval.tok_val); + + current_input_column += yyleng; + lexer_flags.quote_is_transpose = false; + lexer_flags.convert_spaces_to_comma = true; + lexer_flags.looking_for_object_index = true; + + return FCN_HANDLE; + } } // If we have a regular keyword, return it. @@ -3218,12 +3218,12 @@ if (kw_token) { if (kw_token >= 0) - { - current_input_column += yyleng; - lexer_flags.quote_is_transpose = false; - lexer_flags.convert_spaces_to_comma = true; - lexer_flags.looking_for_object_index = false; - } + { + current_input_column += yyleng; + lexer_flags.quote_is_transpose = false; + lexer_flags.convert_spaces_to_comma = true; + lexer_flags.looking_for_object_index = false; + } return kw_token; } @@ -3239,7 +3239,7 @@ xunput (c2, yytext); if (c2 != '=') - next_tok_is_eq = true; + next_tok_is_eq = true; } xunput (c1, yytext); @@ -3258,21 +3258,21 @@ { if (at_bos && spc_gobbled && can_be_command (tok) && looks_like_command_arg ()) - { - BEGIN (COMMAND_START); - } + { + BEGIN (COMMAND_START); + } else if (next_tok_is_eq - || lexer_flags.looking_at_decl_list - || lexer_flags.looking_at_return_list - || (lexer_flags.looking_at_parameter_list - && ! lexer_flags.looking_at_initializer_expression)) - { - symbol_table::force_variable (tok); - } + || lexer_flags.looking_at_decl_list + || lexer_flags.looking_at_return_list + || (lexer_flags.looking_at_parameter_list + && ! lexer_flags.looking_at_initializer_expression)) + { + symbol_table::force_variable (tok); + } else if (lexer_flags.looking_at_matrix_or_assign_lhs) - { - lexer_flags.pending_local_variables.insert (tok); - } + { + lexer_flags.pending_local_variables.insert (tok); + } } // Find the token in the symbol table. Beware the magic @@ -3282,7 +3282,7 @@ tok = "__end__"; yylval.tok_val = new token (&(symbol_table::insert (tok)), - input_line_number, current_input_column); + input_line_number, current_input_column); token_stack.push (yylval.tok_val); @@ -3398,7 +3398,7 @@ string_vector lst (TOTAL_KEYWORDS); for (int i = 0; i < TOTAL_KEYWORDS; i++) - lst[i] = wordlist[i].name; + lst[i] = wordlist[i].name; retval = Cell (lst.sort ()); } @@ -3431,12 +3431,12 @@ if (nm.empty ()) warning_with_id ("Octave:separator-insert", - "potential auto-insertion of `%c' near line %d", - sep, input_line_number); + "potential auto-insertion of `%c' near line %d", + sep, input_line_number); else warning_with_id ("Octave:separator-insert", - "potential auto-insertion of `%c' near line %d of file %s", - sep, input_line_number, nm.c_str ()); + "potential auto-insertion of `%c' near line %d of file %s", + sep, input_line_number, nm.c_str ()); } static void @@ -3446,12 +3446,12 @@ if (nm.empty ()) warning_with_id ("Octave:single-quote-string", - "single quote delimited string near line %d", - input_line_number); + "single quote delimited string near line %d", + input_line_number); else warning_with_id ("Octave:single-quote-string", - "single quote delimited string near line %d of file %s", - input_line_number, nm.c_str ()); + "single quote delimited string near line %d of file %s", + input_line_number, nm.c_str ()); } static void @@ -3461,12 +3461,12 @@ if (nm.empty ()) warning_with_id ("Octave:matlab-incompatible", - "potential Matlab compatibility problem: %s", - msg.c_str ()); + "potential Matlab compatibility problem: %s", + msg.c_str ()); else warning_with_id ("Octave:matlab-incompatible", - "potential Matlab compatibility problem: %s near line %d offile %s", - msg.c_str (), input_line_number, nm.c_str ()); + "potential Matlab compatibility problem: %s near line %d offile %s", + msg.c_str (), input_line_number, nm.c_str ()); } static void @@ -3589,9 +3589,9 @@ default: { if (tok < 256) - std::cerr << static_cast (tok) << "\n"; - else - std::cerr << "UNKNOWN(" << tok << ")\n"; + std::cerr << static_cast (tok) << "\n"; + else + std::cerr << "UNKNOWN(" << tok << ")\n"; } break; } @@ -3669,7 +3669,7 @@ octave_value retval; retval = set_internal_variable (lexer_debug_flag, args, nargout, - "__lexer_debug_flag__"); + "__lexer_debug_flag__"); return retval; } diff --git a/src/load-path.cc b/src/load-path.cc --- a/src/load-path.cc +++ b/src/load-path.cc @@ -57,46 +57,46 @@ if (fs) { if (is_relative) - { - try - { - std::string abs_name = octave_env::make_absolute (dir_name); - - abs_dir_cache_iterator p = abs_dir_cache.find (abs_name); - - if (p != abs_dir_cache.end ()) - { - // The directory is in the cache of all directories - // we have visited (indexed by its absolute name). - // If it is out of date, initialize it. Otherwise, - // copy the info from the cache. By doing that, we - // avoid unnecessary calls to stat that can slow - // things down tremendously for large directories. - - const dir_info& di = p->second; - - if (fs.mtime () + fs.time_resolution () > di.dir_time_last_checked) - initialize (); - else - *this = di; - } - else - { - // We haven't seen this directory before. - - initialize (); - } - } - catch (octave_execution_exception) - { - // Skip updating if we don't know where we are, but - // don't treat it as an error. - - error_state = 0; - } - } + { + try + { + std::string abs_name = octave_env::make_absolute (dir_name); + + abs_dir_cache_iterator p = abs_dir_cache.find (abs_name); + + if (p != abs_dir_cache.end ()) + { + // The directory is in the cache of all directories + // we have visited (indexed by its absolute name). + // If it is out of date, initialize it. Otherwise, + // copy the info from the cache. By doing that, we + // avoid unnecessary calls to stat that can slow + // things down tremendously for large directories. + + const dir_info& di = p->second; + + if (fs.mtime () + fs.time_resolution () > di.dir_time_last_checked) + initialize (); + else + *this = di; + } + else + { + // We haven't seen this directory before. + + initialize (); + } + } + catch (octave_execution_exception) + { + // Skip updating if we don't know where we are, but + // don't treat it as an error. + + error_state = 0; + } + } else if (fs.mtime () + fs.time_resolution () > dir_time_last_checked) - initialize (); + initialize (); } else { @@ -122,19 +122,19 @@ get_file_list (dir_name); try - { - std::string abs_name = octave_env::make_absolute (dir_name); - - // FIXME -- nothing is ever removed from this cache of - // directory information, so there could be some resource - // problems. Perhaps it should be pruned from time to time. - - abs_dir_cache[abs_name] = *this; - } + { + std::string abs_name = octave_env::make_absolute (dir_name); + + // FIXME -- nothing is ever removed from this cache of + // directory information, so there could be some resource + // problems. Perhaps it should be pruned from time to time. + + abs_dir_cache[abs_name] = *this; + } catch (octave_execution_exception) - { - // Skip updating if we don't know where we are. - } + { + // Skip updating if we don't know where we are. + } } else { @@ -161,43 +161,43 @@ octave_idx_type fcn_files_count = 0; for (octave_idx_type i = 0; i < len; i++) - { - std::string fname = flist[i]; - - std::string full_name = file_ops::concat (d, fname); - - file_stat fs (full_name); - - if (fs) - { - if (fs.is_dir ()) - { - if (fname == "private") - get_private_file_map (full_name); - else if (fname[0] == '@') - get_method_file_map (full_name, fname.substr (1)); - } - else - { - all_files[all_files_count++] = fname; - - size_t pos = fname.rfind ('.'); - - if (pos != std::string::npos) - { - std::string ext = fname.substr (pos); - - if (ext == ".m" || ext == ".oct" || ext == ".mex") - { - std::string base = fname.substr (0, pos); - - if (valid_identifier (base)) - fcn_files[fcn_files_count++] = fname; - } - } - } - } - } + { + std::string fname = flist[i]; + + std::string full_name = file_ops::concat (d, fname); + + file_stat fs (full_name); + + if (fs) + { + if (fs.is_dir ()) + { + if (fname == "private") + get_private_file_map (full_name); + else if (fname[0] == '@') + get_method_file_map (full_name, fname.substr (1)); + } + else + { + all_files[all_files_count++] = fname; + + size_t pos = fname.rfind ('.'); + + if (pos != std::string::npos) + { + std::string ext = fname.substr (pos); + + if (ext == ".m" || ext == ".oct" || ext == ".mex") + { + std::string base = fname.substr (0, pos); + + if (valid_identifier (base)) + fcn_files[fcn_files_count++] = fname; + } + } + } + } + } all_files.resize (all_files_count); fcn_files.resize (fcn_files_count); @@ -223,34 +223,34 @@ octave_idx_type len = flist.length (); for (octave_idx_type i = 0; i < len; i++) - { - std::string fname = flist[i]; - - std::string ext; - std::string base = fname; - - size_t pos = fname.rfind ('.'); - - if (pos != std::string::npos) - { - base = fname.substr (0, pos); - ext = fname.substr (pos); - - if (valid_identifier (base)) - { - int t = 0; - - if (ext == ".m") - t = load_path::M_FILE; - else if (ext == ".oct") - t = load_path::OCT_FILE; - else if (ext == ".mex") - t = load_path::MEX_FILE; - - retval[base] |= t; - } - } - } + { + std::string fname = flist[i]; + + std::string ext; + std::string base = fname; + + size_t pos = fname.rfind ('.'); + + if (pos != std::string::npos) + { + base = fname.substr (0, pos); + ext = fname.substr (pos); + + if (valid_identifier (base)) + { + int t = 0; + + if (ext == ".m") + t = load_path::M_FILE; + else if (ext == ".oct") + t = load_path::OCT_FILE; + else if (ext == ".mex") + t = load_path::MEX_FILE; + + retval[base] |= t; + } + } + } } else { @@ -269,7 +269,7 @@ void load_path::dir_info::get_method_file_map (const std::string& d, - const std::string& class_name) + const std::string& class_name) { method_file_map[class_name].method_file_map = get_fcn_files (d); @@ -312,7 +312,7 @@ while (retval != dir_info_list.end ()) { if (retval->dir_name == dir) - break; + break; retval++; } @@ -330,7 +330,7 @@ while (retval != dir_info_list.end ()) { if (retval->dir_name == dir) - break; + break; retval++; } @@ -346,7 +346,7 @@ void load_path::move_fcn_map (const std::string& dir_name, - const string_vector& fcn_files, bool at_end) + const string_vector& fcn_files, bool at_end) { octave_idx_type len = fcn_files.length (); @@ -360,36 +360,36 @@ size_t pos = fname.rfind ('.'); if (pos != std::string::npos) - { - base = fname.substr (0, pos); - ext = fname.substr (pos); - } + { + base = fname.substr (0, pos); + ext = fname.substr (pos); + } file_info_list_type& file_info_list = fcn_map[base]; if (file_info_list.size () == 1) - continue; + continue; else - { - for (file_info_list_iterator p = file_info_list.begin (); - p != file_info_list.end (); - p++) - { - if (p->dir_name == dir_name) - { - file_info fi = *p; - - file_info_list.erase (p); - - if (at_end) - file_info_list.push_back (fi); - else - file_info_list.push_front (fi); - - break; - } - } - } + { + for (file_info_list_iterator p = file_info_list.begin (); + p != file_info_list.end (); + p++) + { + if (p->dir_name == dir_name) + { + file_info fi = *p; + + file_info_list.erase (p); + + if (at_end) + file_info_list.push_back (fi); + else + file_info_list.push_front (fi); + + break; + } + } + } } } @@ -405,36 +405,36 @@ fcn_map_type& fm = i->second; std::string full_dir_name - = file_ops::concat (dir_name, "@" + class_name); + = file_ops::concat (dir_name, "@" + class_name); for (fcn_map_iterator q = fm.begin (); q != fm.end (); q++) - { - file_info_list_type& file_info_list = q->second; - - if (file_info_list.size () == 1) - continue; - else - { - for (file_info_list_iterator p = file_info_list.begin (); - p != file_info_list.end (); - p++) - { - if (p->dir_name == full_dir_name) - { - file_info fi = *p; - - file_info_list.erase (p); - - if (at_end) - file_info_list.push_back (fi); - else - file_info_list.push_front (fi); - - break; - } - } - } - } + { + file_info_list_type& file_info_list = q->second; + + if (file_info_list.size () == 1) + continue; + else + { + for (file_info_list_iterator p = file_info_list.begin (); + p != file_info_list.end (); + p++) + { + if (p->dir_name == full_dir_name) + { + file_info fi = *p; + + file_info_list.erase (p); + + if (at_end) + file_info_list.push_back (fi); + else + file_info_list.push_front (fi); + + break; + } + } + } + } } } @@ -448,9 +448,9 @@ dir_info_list.erase (i); if (at_end) - dir_info_list.push_back (di); + dir_info_list.push_back (di); else - dir_info_list.push_front (di); + dir_info_list.push_front (di); std::string dir_name = di.dir_name; @@ -470,9 +470,9 @@ if (! tpath.empty ()) { if (path.empty ()) - path = tpath; + path = tpath; else - path += dir_path::path_sep_str () + tpath; + path += dir_path::path_sep_str () + tpath; } } @@ -537,12 +537,12 @@ std::string elt = p.substr (beg, end-beg); if (! elt.empty ()) - retval.push_back (elt); + retval.push_back (elt); beg = end + 1; if (beg == len) - break; + break; end = p.find (dir_path::path_sep_char (), beg); } @@ -582,7 +582,7 @@ i++) { if (add_hook) - add_hook (i->dir_name); + add_hook (i->dir_name); } // Always prepend current directory. @@ -610,7 +610,7 @@ if (len > 1 && dir_arg.substr (len-2) == "//") warning_with_id ("Octave:recursive-path-search", - "trailing `//' is no longer special in search path elements"); + "trailing `//' is no longer special in search path elements"); std::string dir = file_ops::tilde_expand (dir_arg); @@ -623,36 +623,36 @@ file_stat fs (dir); if (fs) - { - if (fs.is_dir ()) - { - dir_info di (dir); - - if (! error_state) - { - if (at_end) - dir_info_list.push_back (di); - else - dir_info_list.push_front (di); - - add_to_fcn_map (di, at_end); - - add_to_private_fcn_map (di); - - add_to_method_map (di, at_end); - - if (add_hook) - add_hook (dir); - } - } - else if (warn) - warning ("addpath: %s: not a directory", dir_arg.c_str ()); - } + { + if (fs.is_dir ()) + { + dir_info di (dir); + + if (! error_state) + { + if (at_end) + dir_info_list.push_back (di); + else + dir_info_list.push_front (di); + + add_to_fcn_map (di, at_end); + + add_to_private_fcn_map (di); + + add_to_method_map (di, at_end); + + if (add_hook) + add_hook (dir); + } + } + else if (warn) + warning ("addpath: %s: not a directory", dir_arg.c_str ()); + } else if (warn) - { - std::string msg = fs.error (); - warning ("addpath: %s: %s", dir_arg.c_str (), msg.c_str ()); - } + { + std::string msg = fs.error (); + warning ("addpath: %s: %s", dir_arg.c_str (), msg.c_str ()); + } } // FIXME -- is there a better way to do this? @@ -665,7 +665,7 @@ void load_path::remove_fcn_map (const std::string& dir, - const string_vector& fcn_files) + const string_vector& fcn_files) { octave_idx_type len = fcn_files.length (); @@ -679,27 +679,27 @@ size_t pos = fname.rfind ('.'); if (pos != std::string::npos) - { - base = fname.substr (0, pos); - ext = fname.substr (pos); - } + { + base = fname.substr (0, pos); + ext = fname.substr (pos); + } file_info_list_type& file_info_list = fcn_map[base]; for (file_info_list_iterator p = file_info_list.begin (); - p != file_info_list.end (); - p++) - { - if (p->dir_name == dir) - { - file_info_list.erase (p); - - if (file_info_list.empty ()) - fcn_map.erase (fname); - - break; - } - } + p != file_info_list.end (); + p++) + { + if (p->dir_name == dir) + { + file_info_list.erase (p); + + if (file_info_list.empty ()) + fcn_map.erase (fname); + + break; + } + } } } @@ -726,30 +726,30 @@ std::string full_dir_name = file_ops::concat (dir, "@" + class_name); for (fcn_map_iterator q = fm.begin (); q != fm.end (); q++) - { - file_info_list_type& file_info_list = q->second; - - if (file_info_list.size () == 1) - continue; - else - { - for (file_info_list_iterator p = file_info_list.begin (); - p != file_info_list.end (); - p++) - { - if (p->dir_name == full_dir_name) - { - file_info_list.erase (p); - - // FIXME -- if there are no other elements, we - // should remove this element of fm but calling - // erase here would invalidate the iterator q. - - break; - } - } - } - } + { + file_info_list_type& file_info_list = q->second; + + if (file_info_list.size () == 1) + continue; + else + { + for (file_info_list_iterator p = file_info_list.begin (); + p != file_info_list.end (); + p++) + { + if (p->dir_name == full_dir_name) + { + file_info_list.erase (p); + + // FIXME -- if there are no other elements, we + // should remove this element of fm but calling + // erase here would invalidate the iterator q. + + break; + } + } + } + } } } @@ -761,36 +761,36 @@ if (! dir_arg.empty ()) { if (dir_arg == ".") - { - warning ("rmpath: can't remove \".\" from path"); - - // Avoid additional warnings. - retval = true; - } + { + warning ("rmpath: can't remove \".\" from path"); + + // Avoid additional warnings. + retval = true; + } else - { - std::string dir = file_ops::tilde_expand (dir_arg); - - dir_info_list_iterator i = find_dir_info (dir); - - if (i != dir_info_list.end ()) - { - retval = true; - - if (remove_hook) - remove_hook (dir); - - string_vector fcn_files = i->fcn_files; - - dir_info_list.erase (i); - - remove_fcn_map (dir, fcn_files); - - remove_private_fcn_map (dir); - - remove_method_map (dir); - } - } + { + std::string dir = file_ops::tilde_expand (dir_arg); + + dir_info_list_iterator i = find_dir_info (dir); + + if (i != dir_info_list.end ()) + { + retval = true; + + if (remove_hook) + remove_hook (dir); + + string_vector fcn_files = i->fcn_files; + + dir_info_list.erase (i); + + remove_fcn_map (dir, fcn_files); + + remove_private_fcn_map (dir); + + remove_method_map (dir); + } + } } return retval; @@ -827,91 +827,91 @@ bool load_path::check_file_type (std::string& fname, int type, int possible_types, - const std::string& fcn, const char *who) + const std::string& fcn, const char *who) { bool retval = false; if (type == load_path::OCT_FILE) { if ((type & possible_types) == load_path::OCT_FILE) - { - fname += ".oct"; - retval = true; - } + { + fname += ".oct"; + retval = true; + } } else if (type == load_path::M_FILE) { if ((type & possible_types) == load_path::M_FILE) - { - fname += ".m"; - retval = true; - } + { + fname += ".m"; + retval = true; + } } else if (type == load_path::MEX_FILE) { if ((type & possible_types) == load_path::MEX_FILE) - { - fname += ".mex"; - retval = true; - } + { + fname += ".mex"; + retval = true; + } } else if (type == (load_path::M_FILE | load_path::OCT_FILE)) { if (possible_types & load_path::OCT_FILE) - { - fname += ".oct"; - retval = true; - } + { + fname += ".oct"; + retval = true; + } else if (possible_types & load_path::M_FILE) - { - fname += ".m"; - retval = true; - } + { + fname += ".m"; + retval = true; + } } else if (type == (load_path::M_FILE | load_path::MEX_FILE)) { if (possible_types & load_path::MEX_FILE) - { - fname += ".mex"; - retval = true; - } + { + fname += ".mex"; + retval = true; + } else if (possible_types & load_path::M_FILE) - { - fname += ".m"; - retval = true; - } + { + fname += ".m"; + retval = true; + } } else if (type == (load_path::OCT_FILE | load_path::MEX_FILE)) { if (possible_types & load_path::OCT_FILE) - { - fname += ".oct"; - retval = true; - } + { + fname += ".oct"; + retval = true; + } else if (possible_types & load_path::MEX_FILE) - { - fname += ".mex"; - retval = true; - } + { + fname += ".mex"; + retval = true; + } } else if (type == (load_path::M_FILE | load_path::OCT_FILE - | load_path::MEX_FILE)) + | load_path::MEX_FILE)) { if (possible_types & load_path::OCT_FILE) - { - fname += ".oct"; - retval = true; - } + { + fname += ".oct"; + retval = true; + } else if (possible_types & load_path::MEX_FILE) - { - fname += ".mex"; - retval = true; - } + { + fname += ".mex"; + retval = true; + } else if (possible_types & load_path::M_FILE) - { - fname += ".m"; - retval = true; - } + { + fname += ".m"; + retval = true; + } } else error ("%s: %s: invalid type code = %d", who, fcn.c_str (), type); @@ -921,7 +921,7 @@ std::string load_path::do_find_fcn (const std::string& fcn, std::string& dir_name, - int type) const + int type) const { std::string retval; @@ -932,14 +932,14 @@ size_t pos = fcn.find ('/'); if (pos != std::string::npos) - { - std::string class_name = fcn.substr (1, pos-1); - std::string meth = fcn.substr (pos+1); - - retval = do_find_method (class_name, meth, dir_name); - } + { + std::string class_name = fcn.substr (1, pos-1); + std::string meth = fcn.substr (pos+1); + + retval = do_find_method (class_name, meth, dir_name); + } else - retval = std::string (); + retval = std::string (); } else { @@ -948,27 +948,27 @@ const_fcn_map_iterator p = fcn_map.find (fcn); if (p != fcn_map.end ()) - { - const file_info_list_type& file_info_list = p->second; - - for (const_file_info_list_iterator i = file_info_list.begin (); - i != file_info_list.end (); - i++) - { - const file_info& fi = *i; - - retval = file_ops::concat (fi.dir_name, fcn); - - if (check_file_type (retval, type, fi.types, - fcn, "load_path::do_find_fcn")) - { - dir_name = fi.dir_name; - break; - } - else - retval = std::string (); - } - } + { + const file_info_list_type& file_info_list = p->second; + + for (const_file_info_list_iterator i = file_info_list.begin (); + i != file_info_list.end (); + i++) + { + const file_info& fi = *i; + + retval = file_ops::concat (fi.dir_name, fcn); + + if (check_file_type (retval, type, fi.types, + fcn, "load_path::do_find_fcn")) + { + dir_name = fi.dir_name; + break; + } + else + retval = std::string (); + } + } } return retval; @@ -976,7 +976,7 @@ std::string load_path::do_find_private_fcn (const std::string& dir, - const std::string& fcn, int type) const + const std::string& fcn, int type) const { std::string retval; @@ -991,14 +991,14 @@ dir_info::const_fcn_file_map_iterator p = m.find (fcn); if (p != m.end ()) - { - std::string fname - = file_ops::concat (file_ops::concat (dir, "private"), fcn); - - if (check_file_type (fname, type, p->second, fcn, - "load_path::find_private_fcn")) - retval = fname; - } + { + std::string fname + = file_ops::concat (file_ops::concat (dir, "private"), fcn); + + if (check_file_type (fname, type, p->second, fcn, + "load_path::find_private_fcn")) + retval = fname; + } } return retval; @@ -1006,8 +1006,8 @@ std::string load_path::do_find_method (const std::string& class_name, - const std::string& meth, - std::string& dir_name, int type) const + const std::string& meth, + std::string& dir_name, int type) const { std::string retval; @@ -1024,29 +1024,29 @@ const_fcn_map_iterator p = m.find (meth); if (p != m.end ()) - { - const file_info_list_type& file_info_list = p->second; - - for (const_file_info_list_iterator i = file_info_list.begin (); - i != file_info_list.end (); - i++) - { - const file_info& fi = *i; - - retval = file_ops::concat (fi.dir_name, meth); - - bool found = check_file_type (retval, type, fi.types, - meth, "load_path::do_find_method"); - - if (found) - { - dir_name = fi.dir_name; - break; - } - else - retval = std::string (); - } - } + { + const file_info_list_type& file_info_list = p->second; + + for (const_file_info_list_iterator i = file_info_list.begin (); + i != file_info_list.end (); + i++) + { + const file_info& fi = *i; + + retval = file_ops::concat (fi.dir_name, meth); + + bool found = check_file_type (retval, type, fi.types, + meth, "load_path::do_find_method"); + + if (found) + { + dir_name = fi.dir_name; + break; + } + else + retval = std::string (); + } + } } return retval; @@ -1066,7 +1066,7 @@ const fcn_map_type& m = q->second; for (const_fcn_map_iterator p = m.begin (); p != m.end (); p++) - retval.push_back (p->first); + retval.push_back (p->first); } if (! retval.empty ()) @@ -1105,44 +1105,44 @@ if (file.find_first_of (file_ops::dir_sep_chars ()) != std::string::npos) { if (octave_env::absolute_pathname (file) - || octave_env::rooted_relative_pathname (file)) - { - file_stat fs (file); - - if (fs.exists ()) - return file; - } + || octave_env::rooted_relative_pathname (file)) + { + file_stat fs (file); + + if (fs.exists ()) + return file; + } else - { - for (const_dir_info_list_iterator p = dir_info_list.begin (); - p != dir_info_list.end (); - p++) - { - std::string tfile = file_ops::concat (p->dir_name, file); - - file_stat fs (tfile); - - if (fs.exists ()) - return tfile; - } - } + { + for (const_dir_info_list_iterator p = dir_info_list.begin (); + p != dir_info_list.end (); + p++) + { + std::string tfile = file_ops::concat (p->dir_name, file); + + file_stat fs (tfile); + + if (fs.exists ()) + return tfile; + } + } } else { for (const_dir_info_list_iterator p = dir_info_list.begin (); - p != dir_info_list.end (); - p++) - { - string_vector all_files = p->all_files; - - octave_idx_type len = all_files.length (); - - for (octave_idx_type i = 0; i < len; i++) - { - if (all_files[i] == file) - return file_ops::concat (p->dir_name, file); - } - } + p != dir_info_list.end (); + p++) + { + string_vector all_files = p->all_files; + + octave_idx_type len = all_files.length (); + + for (octave_idx_type i = 0; i < len; i++) + { + if (all_files[i] == file) + return file_ops::concat (p->dir_name, file); + } + } } return retval; @@ -1155,41 +1155,41 @@ if (dir.find_first_of (file_ops::dir_sep_chars ()) != std::string::npos && (octave_env::absolute_pathname (dir) - || octave_env::rooted_relative_pathname (dir))) + || octave_env::rooted_relative_pathname (dir))) { file_stat fs (dir); if (fs.exists () && fs.is_dir ()) - return dir; + return dir; } else { for (const_dir_info_list_iterator p = dir_info_list.begin (); - p != dir_info_list.end (); - p++) - { - std::string dname = octave_env::make_absolute (p->dir_name); - - size_t dname_len = dname.length (); - - if (dname.substr (dname_len - 1) == file_ops::dir_sep_str ()) - { - dname = dname.substr (0, dname_len - 1); - dname_len--; - } - - size_t dir_len = dir.length (); - - if (dname_len >= dir_len - && file_ops::is_dir_sep (dname[dname_len - dir_len - 1]) - && dir.compare (dname.substr (dname_len - dir_len)) == 0) - { - file_stat fs (p->dir_name); - - if (fs.exists () && fs.is_dir ()) - return p->dir_name; - } - } + p != dir_info_list.end (); + p++) + { + std::string dname = octave_env::make_absolute (p->dir_name); + + size_t dname_len = dname.length (); + + if (dname.substr (dname_len - 1) == file_ops::dir_sep_str ()) + { + dname = dname.substr (0, dname_len - 1); + dname_len--; + } + + size_t dir_len = dir.length (); + + if (dname_len >= dir_len + && file_ops::is_dir_sep (dname[dname_len - dir_len - 1]) + && dir.compare (dname.substr (dname_len - dir_len)) == 0) + { + file_stat fs (p->dir_name); + + if (fs.exists () && fs.is_dir ()) + return p->dir_name; + } + } } return retval; @@ -1202,41 +1202,41 @@ if (dir.find_first_of (file_ops::dir_sep_chars ()) != std::string::npos && (octave_env::absolute_pathname (dir) - || octave_env::rooted_relative_pathname (dir))) + || octave_env::rooted_relative_pathname (dir))) { file_stat fs (dir); if (fs.exists () && fs.is_dir ()) - retlist.push_back (dir); + retlist.push_back (dir); } else { for (const_dir_info_list_iterator p = dir_info_list.begin (); - p != dir_info_list.end (); - p++) - { - std::string dname = octave_env::make_absolute (p->dir_name); - - size_t dname_len = dname.length (); - - if (dname.substr (dname_len - 1) == file_ops::dir_sep_str ()) - { - dname = dname.substr (0, dname_len - 1); - dname_len--; - } - - size_t dir_len = dir.length (); - - if (dname_len >= dir_len - && file_ops::is_dir_sep (dname[dname_len - dir_len - 1]) - && dir.compare (dname.substr (dname_len - dir_len)) == 0) - { - file_stat fs (p->dir_name); - - if (fs.exists () && fs.is_dir ()) - retlist.push_back (p->dir_name); - } - } + p != dir_info_list.end (); + p++) + { + std::string dname = octave_env::make_absolute (p->dir_name); + + size_t dname_len = dname.length (); + + if (dname.substr (dname_len - 1) == file_ops::dir_sep_str ()) + { + dname = dname.substr (0, dname_len - 1); + dname_len--; + } + + size_t dir_len = dir.length (); + + if (dname_len >= dir_len + && file_ops::is_dir_sep (dname[dname_len - dir_len - 1]) + && dir.compare (dname.substr (dname_len - dir_len)) == 0) + { + file_stat fs (p->dir_name); + + if (fs.exists () && fs.is_dir ()) + retlist.push_back (p->dir_name); + } + } } return retlist; @@ -1258,14 +1258,14 @@ for (octave_idx_type i = 0; i < flen; i++) { if (octave_env::absolute_pathname (flist[i])) - { - file_stat fs (flist[i]); - - if (fs.exists ()) - return flist[i]; - } + { + file_stat fs (flist[i]); + + if (fs.exists ()) + return flist[i]; + } else - rel_flist[rel_flen++] = flist[i]; + rel_flist[rel_flen++] = flist[i]; } rel_flist.resize (rel_flen); @@ -1279,18 +1279,18 @@ octave_idx_type len = all_files.length (); for (octave_idx_type i = 0; i < len; i++) - { - for (octave_idx_type j = 0; j < rel_flen; j++) - { - if (all_files[i] == rel_flist[j]) - { - dir_name = p->dir_name; - file_name = rel_flist[j]; - - goto done; - } - } - } + { + for (octave_idx_type j = 0; j < rel_flen; j++) + { + if (all_files[i] == rel_flist[j]) + { + dir_name = p->dir_name; + file_name = rel_flist[j]; + + goto done; + } + } + } } done: @@ -1317,14 +1317,14 @@ for (octave_idx_type i = 0; i < flen; i++) { if (octave_env::absolute_pathname (flist[i])) - { - file_stat fs (flist[i]); - - if (fs.exists ()) - retlist.push_back (flist[i]); - } + { + file_stat fs (flist[i]); + + if (fs.exists ()) + retlist.push_back (flist[i]); + } else - rel_flist[rel_flen++] = flist[i]; + rel_flist[rel_flen++] = flist[i]; } rel_flist.resize (rel_flen); @@ -1338,14 +1338,14 @@ octave_idx_type len = all_files.length (); for (octave_idx_type i = 0; i < len; i++) - { - for (octave_idx_type j = 0; j < rel_flen; j++) - { - if (all_files[i] == rel_flist[j]) - retlist.push_back - (file_ops::concat (p->dir_name, rel_flist[j])); - } - } + { + for (octave_idx_type j = 0; j < rel_flen; j++) + { + if (all_files[i] == rel_flist[j]) + retlist.push_back + (file_ops::concat (p->dir_name, rel_flist[j])); + } + } } return retlist; @@ -1396,14 +1396,14 @@ octave_idx_type len = retval.length (); for (octave_idx_type i = 0; i < len; i++) - { - std::string fname = retval[i]; - - size_t pos = fname.rfind ('.'); - - if (pos != std::string::npos) - retval[i] = fname.substr (0, pos); - } + { + std::string fname = retval[i]; + + size_t pos = fname.rfind ('.'); + + if (pos != std::string::npos) + retval[i] = fname.substr (0, pos); + } } return retval; @@ -1458,7 +1458,7 @@ if (types & load_path::MEX_FILE) { if (printed_type) - os << "|"; + os << "|"; os << "mex"; printed_type = true; } @@ -1466,7 +1466,7 @@ if (types & load_path::M_FILE) { if (printed_type) - os << "|"; + os << "|"; os << "m"; printed_type = true; } @@ -1474,7 +1474,7 @@ void print_fcn_list (std::ostream& os, - const load_path::dir_info::fcn_file_map_type& lst) + const load_path::dir_info::fcn_file_map_type& lst) { for (load_path::dir_info::const_fcn_file_map_iterator p = lst.begin (); p != lst.end (); @@ -1506,11 +1506,11 @@ int types = p->second; if (types & load_path::OCT_FILE) - nm += ".oct"; + nm += ".oct"; else if (types & load_path::MEX_FILE) - nm += ".mex"; + nm += ".mex"; else - nm += ".m"; + nm += ".m"; retval[count++] = nm; } @@ -1528,38 +1528,38 @@ string_vector fcn_files = i->fcn_files; if (! fcn_files.empty ()) - { - os << "\n*** function files in " << i->dir_name << ":\n\n"; - - fcn_files.list_in_columns (os); - } + { + os << "\n*** function files in " << i->dir_name << ":\n\n"; + + fcn_files.list_in_columns (os); + } const dir_info::method_file_map_type& method_file_map - = i->method_file_map; + = i->method_file_map; if (! method_file_map.empty ()) - { - for (dir_info::const_method_file_map_iterator p = method_file_map.begin (); - p != method_file_map.end (); - p++) - { - os << "\n*** methods in " << i->dir_name - << "/@" << p->first << ":\n\n"; - - const dir_info::class_info& ci = p->second; - - string_vector method_files = get_file_list (ci.method_file_map); - - method_files.list_in_columns (os); - } - } + { + for (dir_info::const_method_file_map_iterator p = method_file_map.begin (); + p != method_file_map.end (); + p++) + { + os << "\n*** methods in " << i->dir_name + << "/@" << p->first << ":\n\n"; + + const dir_info::class_info& ci = p->second; + + string_vector method_files = get_file_list (ci.method_file_map); + + method_files.list_in_columns (os); + } + } } for (const_private_fcn_map_iterator i = private_fcn_map.begin (); i != private_fcn_map.end (); i++) { os << "\n*** private functions in " - << file_ops::concat (i->first, "private") << ":\n\n"; + << file_ops::concat (i->first, "private") << ":\n\n"; print_fcn_list (os, i->second); } @@ -1575,15 +1575,15 @@ const file_info_list_type& file_info_list = i->second; for (const_file_info_list_iterator p = file_info_list.begin (); - p != file_info_list.end (); - p++) - { - os << " " << p->dir_name << " ("; - - print_types (os, p->types); - - os << ")\n"; - } + p != file_info_list.end (); + p++) + { + os << " " << p->dir_name << " ("; + + print_types (os, p->types); + + os << ")\n"; + } } for (const_method_map_iterator i = method_map.begin (); @@ -1595,24 +1595,24 @@ const fcn_map_type& fm = i->second; for (const_fcn_map_iterator q = fm.begin (); - q != fm.end (); - q++) - { - os << " " << q->first << ":\n"; - - const file_info_list_type& file_info_list = q->second; - - for (const_file_info_list_iterator p = file_info_list.begin (); - p != file_info_list.end (); - p++) - { - os << " " << p->dir_name << " ("; - - print_types (os, p->types); - - os << ")\n"; - } - } + q != fm.end (); + q++) + { + os << " " << q->first << ":\n"; + + const file_info_list_type& file_info_list = q->second; + + for (const_file_info_list_iterator p = file_info_list.begin (); + p != file_info_list.end (); + p++) + { + os << " " << p->dir_name << " ("; + + print_types (os, p->types); + + os << ")\n"; + } + } } os << "\n"; @@ -1639,38 +1639,38 @@ size_t pos = fname.rfind ('.'); if (pos != std::string::npos) - { - base = fname.substr (0, pos); - ext = fname.substr (pos); - } + { + base = fname.substr (0, pos); + ext = fname.substr (pos); + } file_info_list_type& file_info_list = fcn_map[base]; file_info_list_iterator p = file_info_list.begin (); while (p != file_info_list.end ()) - { - if (p->dir_name == dir_name) - break; - - p++; - } + { + if (p->dir_name == dir_name) + break; + + p++; + } int t = 0; if (ext == ".m") - t = load_path::M_FILE; + t = load_path::M_FILE; else if (ext == ".oct") - t = load_path::OCT_FILE; + t = load_path::OCT_FILE; else if (ext == ".mex") - t = load_path::MEX_FILE; + t = load_path::MEX_FILE; if (p == file_info_list.end ()) - { - file_info fi (dir_name, t); - - if (at_end) - file_info_list.push_back (fi); - else + { + file_info fi (dir_name, t); + + if (at_end) + file_info_list.push_back (fi); + else { // Warn if a built-in or library function is being shadowed. if (! file_info_list.empty ()) @@ -1694,13 +1694,13 @@ file_info_list.push_front (fi); } - } + } else - { - file_info& fi = *p; - - fi.types |= t; - } + { + file_info& fi = *p; + + fi.types |= t; + } } } @@ -1730,7 +1730,7 @@ fcn_map_type& fm = method_map[class_name]; std::string full_dir_name - = file_ops::concat (dir_name, "@" + class_name); + = file_ops::concat (dir_name, "@" + class_name); const dir_info::class_info& ci = q->second; @@ -1738,49 +1738,49 @@ const dir_info::fcn_file_map_type& m = ci.method_file_map; for (dir_info::const_fcn_file_map_iterator p = m.begin (); - p != m.end (); - p++) - { - std::string base = p->first; - - int types = p->second; - - file_info_list_type& file_info_list = fm[base]; - - file_info_list_iterator p2 = file_info_list.begin (); - - while (p2 != file_info_list.end ()) - { - if (p2->dir_name == full_dir_name) - break; - - p2++; - } - - if (p2 == file_info_list.end ()) - { - file_info fi (full_dir_name, types); - - if (at_end) - file_info_list.push_back (fi); - else - file_info_list.push_front (fi); - } - else - { - // FIXME -- is this possible? - - file_info& fi = *p2; - - fi.types = types; - } - } + p != m.end (); + p++) + { + std::string base = p->first; + + int types = p->second; + + file_info_list_type& file_info_list = fm[base]; + + file_info_list_iterator p2 = file_info_list.begin (); + + while (p2 != file_info_list.end ()) + { + if (p2->dir_name == full_dir_name) + break; + + p2++; + } + + if (p2 == file_info_list.end ()) + { + file_info fi (full_dir_name, types); + + if (at_end) + file_info_list.push_back (fi); + else + file_info_list.push_front (fi); + } + else + { + // FIXME -- is this possible? + + file_info& fi = *p2; + + fi.types = types; + } + } // dir_info::fcn_file_map_type private_file_map = ci.private_file_map; if (! private_file_map.empty ()) - private_fcn_map[full_dir_name] = private_file_map; + private_fcn_map[full_dir_name] = private_file_map; } } @@ -1800,35 +1800,35 @@ octave_idx_type len = dirlist.length (); for (octave_idx_type i = 0; i < len; i++) - { - std::string elt = dirlist[i]; - - // FIXME -- the caller should be able to specify the list of - // directories to skip in addition to ".", "..", and - // directories beginning with "@". - - bool skip_p = (elt == "." || elt == ".." || elt[0] == '@'); - - if (! skip_p) - { - for (octave_idx_type j = 0; j < skip.length (); j++) - { - skip_p = (elt == skip[j]); - if (skip_p) - break; - } - - if (! skip_p) - { - std::string nm = file_ops::concat (dirname, elt); - - file_stat fs (nm); - - if (fs && fs.is_dir ()) - retval += dir_path::path_sep_str () + genpath (nm); - } - } - } + { + std::string elt = dirlist[i]; + + // FIXME -- the caller should be able to specify the list of + // directories to skip in addition to ".", "..", and + // directories beginning with "@". + + bool skip_p = (elt == "." || elt == ".." || elt[0] == '@'); + + if (! skip_p) + { + for (octave_idx_type j = 0; j < skip.length (); j++) + { + skip_p = (elt == skip[j]); + if (skip_p) + break; + } + + if (! skip_p) + { + std::string nm = file_ops::concat (dirname, elt); + + file_stat fs (nm); + + if (fs && fs.is_dir ()) + retval += dir_path::path_sep_str () + genpath (nm); + } + } + } } return retval; @@ -1836,7 +1836,7 @@ static void execute_pkg_add_or_del (const std::string& dir, - const std::string& script_file) + const std::string& script_file) { if (! octave_interpreter_ready) return; @@ -1880,9 +1880,9 @@ std::string dirname = args(0).string_value (); if (! error_state) - retval = genpath (dirname); + retval = genpath (dirname); else - error ("genpath: expecting argument to be a character string"); + error ("genpath: expecting argument to be a character string"); } else print_usage (); @@ -1981,29 +1981,29 @@ if (! error_state) { if (argc > 1) - { - std::string path = argv[1]; - - for (int i = 2; i < argc; i++) - path += dir_path::path_sep_str () + argv[i]; - - load_path::set (path, true); - - rehash_internal (); - } + { + std::string path = argv[1]; + + for (int i = 2; i < argc; i++) + path += dir_path::path_sep_str () + argv[i]; + + load_path::set (path, true); + + rehash_internal (); + } if (nargout > 0) - retval = load_path::path (); + retval = load_path::path (); else if (argc == 1 && nargout == 0) - { - octave_stdout << "\nOctave's search path contains the following directories:\n\n"; - - string_vector dirs = load_path::dirs (); - - dirs.list_in_columns (octave_stdout); - - octave_stdout << "\n"; - } + { + octave_stdout << "\nOctave's search path contains the following directories:\n\n"; + + string_vector dirs = load_path::dirs (); + + dirs.list_in_columns (octave_stdout); + + octave_stdout << "\n"; + } } return retval; @@ -2038,76 +2038,76 @@ octave_value option_arg = args(nargin-1); if (option_arg.is_string ()) - { - std::string option = option_arg.string_value (); - - if (option == "-end") - { - append = true; - nargin--; - } - else if (option == "-begin") - nargin--; - } + { + std::string option = option_arg.string_value (); + + if (option == "-end") + { + append = true; + nargin--; + } + else if (option == "-begin") + nargin--; + } else if (option_arg.is_numeric_type ()) - { - int val = option_arg.int_value (); - - if (! error_state) - { - if (val == 0) - append = false; - else if (val == 1) - append = true; - else - { - error ("addpath: expecting final argument to be 1 or 0"); - return retval; - } - } - else - { - error ("addpath: expecting final argument to be 1 or 0"); - return retval; - } - } + { + int val = option_arg.int_value (); + + if (! error_state) + { + if (val == 0) + append = false; + else if (val == 1) + append = true; + else + { + error ("addpath: expecting final argument to be 1 or 0"); + return retval; + } + } + else + { + error ("addpath: expecting final argument to be 1 or 0"); + return retval; + } + } bool need_to_update = false; for (int i = 0; i < nargin; i++) - { - std::string arg = args(i).string_value (); - - if (! error_state) - { - std::list dir_elts = split_path (arg); - - if (! append) - std::reverse (dir_elts.begin (), dir_elts.end ()); - - for (std::list::const_iterator p = dir_elts.begin (); - p != dir_elts.end (); - p++) - { - std::string dir = *p; - - //dir = regexprep (dir_elts{j}, "//+", "/"); - //dir = regexprep (dir, "/$", ""); - - if (append) - load_path::append (dir, true); - else - load_path::prepend (dir, true); - - need_to_update = true; - } - } - else - error ("addpath: expecting all args to be character strings"); - } + { + std::string arg = args(i).string_value (); + + if (! error_state) + { + std::list dir_elts = split_path (arg); + + if (! append) + std::reverse (dir_elts.begin (), dir_elts.end ()); + + for (std::list::const_iterator p = dir_elts.begin (); + p != dir_elts.end (); + p++) + { + std::string dir = *p; + + //dir = regexprep (dir_elts{j}, "//+", "/"); + //dir = regexprep (dir, "/$", ""); + + if (append) + load_path::append (dir, true); + else + load_path::prepend (dir, true); + + need_to_update = true; + } + } + else + error ("addpath: expecting all args to be character strings"); + } if (need_to_update) - rehash_internal (); + rehash_internal (); } else print_usage (); @@ -2138,34 +2138,34 @@ bool need_to_update = false; for (int i = 0; i < nargin; i++) - { - std::string arg = args(i).string_value (); - - if (! error_state) - { - std::list dir_elts = split_path (arg); - - for (std::list::const_iterator p = dir_elts.begin (); - p != dir_elts.end (); - p++) - { - std::string dir = *p; - - //dir = regexprep (dir_elts{j}, "//+", "/"); - //dir = regexprep (dir, "/$", ""); - - if (! load_path::remove (dir)) - warning ("rmpath: %s: not found", dir.c_str ()); - else - need_to_update = true; - } - } - else - error ("addpath: expecting all args to be character strings"); - } + { + std::string arg = args(i).string_value (); + + if (! error_state) + { + std::list dir_elts = split_path (arg); + + for (std::list::const_iterator p = dir_elts.begin (); + p != dir_elts.end (); + p++) + { + std::string dir = *p; + + //dir = regexprep (dir_elts{j}, "//+", "/"); + //dir = regexprep (dir, "/$", ""); + + if (! load_path::remove (dir)) + warning ("rmpath: %s: not found", dir.c_str ()); + else + need_to_update = true; + } + } + else + error ("addpath: expecting all args to be character strings"); + } if (need_to_update) - rehash_internal (); + rehash_internal (); } else print_usage (); diff --git a/src/load-save.cc b/src/load-save.cc --- a/src/load-save.cc +++ b/src/load-save.cc @@ -114,7 +114,7 @@ { return std::string ("# Created by Octave " OCTAVE_VERSION - ", %a %b %d %H:%M:%S %Y %Z <") + ", %a %b %d %H:%M:%S %Y %Z <") + octave_env::get_user_name () + std::string ("@") + octave_env::get_host_name () @@ -142,8 +142,8 @@ static void install_loaded_variable (const std::string& name, - const octave_value& val, - bool global, const std::string& /*doc*/) + const octave_value& val, + bool global, const std::string& /*doc*/) { if (global) { @@ -159,14 +159,14 @@ static bool matches_patterns (const string_vector& patterns, int pat_idx, - int num_pat, const std::string& name) + int num_pat, const std::string& name) { for (int i = pat_idx; i < num_pat; i++) { glob_match pattern (patterns[i]); if (pattern.match (name)) - return true; + return true; } return false; @@ -174,7 +174,7 @@ int read_binary_file_header (std::istream& is, bool& swap, - oct_mach_info::float_format& flt_fmt, bool quiet) + oct_mach_info::float_format& flt_fmt, bool quiet) { const int magic_len = 10; char magic[magic_len+1]; @@ -188,10 +188,10 @@ else { if (! quiet) - error ("load: unable to read read binary file"); + error ("load: unable to read read binary file"); return -1; } - + char tmp = 0; is.read (&tmp, 1); @@ -246,31 +246,31 @@ int err = read_mat_file_header (file, swap, mopt, nr, nc, imag, len, 1); if (! err) - retval = LS_MAT_BINARY; + retval = LS_MAT_BINARY; else - { - file.clear (); - file.seekg (0, std::ios::beg); + { + file.clear (); + file.seekg (0, std::ios::beg); - err = read_mat5_binary_file_header (file, swap, true, filename); + err = read_mat5_binary_file_header (file, swap, true, filename); - if (! err) - { - file.clear (); - file.seekg (0, std::ios::beg); - retval = LS_MAT5_BINARY; - } - else - { - file.clear (); - file.seekg (0, std::ios::beg); + if (! err) + { + file.clear (); + file.seekg (0, std::ios::beg); + retval = LS_MAT5_BINARY; + } + else + { + file.clear (); + file.seekg (0, std::ios::beg); - std::string tmp = extract_keyword (file, "name"); + std::string tmp = extract_keyword (file, "name"); - if (! tmp.empty ()) - retval = LS_ASCII; - } - } + if (! tmp.empty ()) + retval = LS_ASCII; + } + } } return retval; @@ -278,7 +278,7 @@ static load_save_format get_file_format (const std::string& fname, const std::string& orig_fname, - bool &use_zlib) + bool &use_zlib) { load_save_format retval = LS_UNKNOWN; @@ -297,30 +297,30 @@ file.close (); #ifdef HAVE_ZLIB - if (retval == LS_UNKNOWN && check_gzip_magic (fname)) - { - gzifstream gzfile (fname.c_str ()); - use_zlib = true; + if (retval == LS_UNKNOWN && check_gzip_magic (fname)) + { + gzifstream gzfile (fname.c_str ()); + use_zlib = true; - if (gzfile) - { - retval = get_file_format (gzfile, orig_fname); - gzfile.close (); - } - } + if (gzfile) + { + retval = get_file_format (gzfile, orig_fname); + gzfile.close (); + } + } #endif if (retval == LS_UNKNOWN) - { - // Try reading the file as numbers only, determining the - // number of rows and columns from the data. We don't - // even bother to check to see if the first item in the - // file is a number, so that get_complete_line() can - // skip any comments that might appear at the top of the - // file. + { + // Try reading the file as numbers only, determining the + // number of rows and columns from the data. We don't + // even bother to check to see if the first item in the + // file is a number, so that get_complete_line() can + // skip any comments that might appear at the top of the + // file. - retval = LS_MAT_ASCII; - } + retval = LS_MAT_ASCII; + } } else gripe_file_open ("load", orig_fname); @@ -330,9 +330,9 @@ octave_value do_load (std::istream& stream, const std::string& orig_fname, - load_save_format format, oct_mach_info::float_format flt_fmt, - bool list_only, bool swap, bool verbose, - const string_vector& argv, int argv_idx, int argc, int nargout) + load_save_format format, oct_mach_info::float_format flt_fmt, + bool list_only, bool swap, bool verbose, + const string_vector& argv, int argv_idx, int argc, int nargout) { octave_value retval; @@ -352,132 +352,132 @@ std::string doc; switch (format.type) - { - case LS_ASCII: - name = read_ascii_data (stream, orig_fname, global, tc, count); - break; + { + case LS_ASCII: + name = read_ascii_data (stream, orig_fname, global, tc, count); + break; - case LS_BINARY: - name = read_binary_data (stream, swap, flt_fmt, orig_fname, - global, tc, doc); - break; + case LS_BINARY: + name = read_binary_data (stream, swap, flt_fmt, orig_fname, + global, tc, doc); + break; - case LS_MAT_ASCII: - name = read_mat_ascii_data (stream, orig_fname, tc); - break; + case LS_MAT_ASCII: + name = read_mat_ascii_data (stream, orig_fname, tc); + break; - case LS_MAT_BINARY: - name = read_mat_binary_data (stream, orig_fname, tc); - break; + case LS_MAT_BINARY: + name = read_mat_binary_data (stream, orig_fname, tc); + break; #ifdef HAVE_HDF5 - case LS_HDF5: - name = read_hdf5_data (stream, orig_fname, global, tc, doc); - break; + case LS_HDF5: + name = read_hdf5_data (stream, orig_fname, global, tc, doc); + break; #endif /* HAVE_HDF5 */ - case LS_MAT5_BINARY: - case LS_MAT7_BINARY: - name = read_mat5_binary_element (stream, orig_fname, swap, - global, tc); - break; + case LS_MAT5_BINARY: + case LS_MAT7_BINARY: + name = read_mat5_binary_element (stream, orig_fname, swap, + global, tc); + break; - default: - gripe_unrecognized_data_fmt ("load"); - break; - } + default: + gripe_unrecognized_data_fmt ("load"); + break; + } if (error_state || stream.eof () || name.empty ()) - break; + break; else if (! error_state && ! name.empty ()) - { - if (tc.is_defined ()) - { - if (format == LS_MAT_ASCII && argv_idx < argc) - warning ("load: loaded ASCII file `%s' -- ignoring extra args", - orig_fname.c_str ()); + { + if (tc.is_defined ()) + { + if (format == LS_MAT_ASCII && argv_idx < argc) + warning ("load: loaded ASCII file `%s' -- ignoring extra args", + orig_fname.c_str ()); - if (format == LS_MAT_ASCII - || argv_idx == argc - || matches_patterns (argv, argv_idx, argc, name)) - { - count++; - if (list_only) - { - if (verbose) - { - if (count == 1) - output_buf - << "type rows cols name\n" - << "==== ==== ==== ====\n"; + if (format == LS_MAT_ASCII + || argv_idx == argc + || matches_patterns (argv, argv_idx, argc, name)) + { + count++; + if (list_only) + { + if (verbose) + { + if (count == 1) + output_buf + << "type rows cols name\n" + << "==== ==== ==== ====\n"; - output_buf - << std::setiosflags (std::ios::left) - << std::setw (16) << tc.type_name () . c_str () - << std::setiosflags (std::ios::right) - << std::setw (7) << tc.rows () - << std::setw (7) << tc.columns () - << " " << name << "\n"; - } - else - symbol_names.push_back (name); - } - else - { - if (nargout == 1) - { - if (format == LS_MAT_ASCII) - retval = tc; - else - retstruct.assign (name, tc); - } - else - install_loaded_variable (name, tc, global, doc); - } - } + output_buf + << std::setiosflags (std::ios::left) + << std::setw (16) << tc.type_name () . c_str () + << std::setiosflags (std::ios::right) + << std::setw (7) << tc.rows () + << std::setw (7) << tc.columns () + << " " << name << "\n"; + } + else + symbol_names.push_back (name); + } + else + { + if (nargout == 1) + { + if (format == LS_MAT_ASCII) + retval = tc; + else + retstruct.assign (name, tc); + } + else + install_loaded_variable (name, tc, global, doc); + } + } - // Only attempt to read one item from a headless text file. + // Only attempt to read one item from a headless text file. - if (format == LS_MAT_ASCII) - break; - } - else - error ("load: unable to load variable `%s'", name.c_str ()); - } + if (format == LS_MAT_ASCII) + break; + } + else + error ("load: unable to load variable `%s'", name.c_str ()); + } else - { - if (count == 0) - error ("load: are you sure `%s' is an Octave data file?", - orig_fname.c_str ()); + { + if (count == 0) + error ("load: are you sure `%s' is an Octave data file?", + orig_fname.c_str ()); - break; - } + break; + } } if (list_only && count) { if (verbose) - { - std::string msg = output_buf.str (); + { + std::string msg = output_buf.str (); - if (nargout > 0) - retval = msg; - else - octave_stdout << msg; - } + if (nargout > 0) + retval = msg; + else + octave_stdout << msg; + } else - { - if (nargout > 0) - retval = Cell (string_vector (symbol_names)); - else - { - string_vector names (symbol_names); + { + if (nargout > 0) + retval = Cell (string_vector (symbol_names)); + else + { + string_vector names (symbol_names); - names.list_in_columns (octave_stdout); + names.list_in_columns (octave_stdout); - octave_stdout << "\n"; - } - } + octave_stdout << "\n"; + } + } } else if (retstruct.nfields () != 0) retval = retstruct; @@ -491,22 +491,22 @@ std::string fname = name; if (! (octave_env::absolute_pathname (fname) - || octave_env::rooted_relative_pathname (fname))) + || octave_env::rooted_relative_pathname (fname))) { file_stat fs (fname); if (! (fs.exists () && fs.is_reg ())) - { - std::string tmp + { + std::string tmp = octave_env::make_absolute (load_path::find_file (fname)); - if (! tmp.empty ()) - { - warning_with_id ("Octave:load-file-in-path", - "load: file found in load path"); - fname = tmp; - } - } + if (! tmp.empty ()) + { + warning_with_id ("Octave:load-file-in-path", + "load: file found in load path"); + fname = tmp; + } + } } size_t dot_pos = fname.rfind ("."); @@ -521,18 +521,18 @@ file_stat fs (fname); if (! (fs.exists () && fs.is_reg ())) - fname = find_file_to_load (fname + ".mat", orig_name); + fname = find_file_to_load (fname + ".mat", orig_name); } else { file_stat fs (fname); if (! (fs.exists () && fs.is_reg ())) - { - fname = ""; + { + fname = ""; - error ("load: unable to find file %s", orig_name.c_str ()); - } + error ("load: unable to find file %s", orig_name.c_str ()); + } } return fname; @@ -670,59 +670,59 @@ for (i = 1; i < argc; i++) { if (argv[i] == "-force" || argv[i] == "-f") - { - // Silently ignore this - // warning ("load: -force ignored"); - } + { + // Silently ignore this + // warning ("load: -force ignored"); + } else if (argv[i] == "-list" || argv[i] == "-l") - { - list_only = true; - } + { + list_only = true; + } else if (argv[i] == "-verbose" || argv[i] == "-v") - { - verbose = true; - } + { + verbose = true; + } else if (argv[i] == "-ascii" || argv[i] == "-a") - { - format = LS_MAT_ASCII; - } + { + format = LS_MAT_ASCII; + } else if (argv[i] == "-binary" || argv[i] == "-b") - { - format = LS_BINARY; - } + { + format = LS_BINARY; + } else if (argv[i] == "-mat-binary" || argv[i] == "-mat" || argv[i] == "-m" - || argv[i] == "-6" || argv[i] == "-v6") - { - format = LS_MAT5_BINARY; - } + || argv[i] == "-6" || argv[i] == "-v6") + { + format = LS_MAT5_BINARY; + } else if (argv[i] == "-7" || argv[i] == "-v7") - { - format = LS_MAT7_BINARY; - } + { + format = LS_MAT7_BINARY; + } else if (argv[i] == "-mat4-binary" || argv[i] == "-V4" - || argv[i] == "-v4" || argv[i] == "-4") - { - format = LS_MAT_BINARY; - } + || argv[i] == "-v4" || argv[i] == "-4") + { + format = LS_MAT_BINARY; + } else if (argv[i] == "-hdf5" || argv[i] == "-h") - { + { #ifdef HAVE_HDF5 - format = LS_HDF5; + format = LS_HDF5; #else /* ! HAVE_HDF5 */ - error ("load: octave executable was not linked with HDF5 library"); - return retval; + error ("load: octave executable was not linked with HDF5 library"); + return retval; #endif /* ! HAVE_HDF5 */ - } + } else if (argv[i] == "-import" || argv[i] == "-i") - { - warning ("load: -import ignored"); - } + { + warning ("load: -import ignored"); + } else if (argv[i] == "-text" || argv[i] == "-t") - { - format = LS_ASCII; - } + { + format = LS_ASCII; + } else - break; + break; } if (i == argc) @@ -743,22 +743,22 @@ #ifdef HAVE_HDF5 if (format == LS_HDF5) - error ("load: cannot read HDF5 format from stdin"); + error ("load: cannot read HDF5 format from stdin"); else #endif /* HAVE_HDF5 */ if (format != LS_UNKNOWN) - { - // FIXME -- if we have already seen EOF on a - // previous call, how do we fix up the state of std::cin so - // that we can get additional input? I'm afraid that we - // can't fix this using std::cin only. + { + // FIXME -- if we have already seen EOF on a + // previous call, how do we fix up the state of std::cin so + // that we can get additional input? I'm afraid that we + // can't fix this using std::cin only. - retval = do_load (std::cin, orig_fname, format, flt_fmt, - list_only, swap, verbose, argv, i, argc, - nargout); - } + retval = do_load (std::cin, orig_fname, format, flt_fmt, + list_only, swap, verbose, argv, i, argc, + nargout); + } else - error ("load: must specify file format if reading from stdin"); + error ("load: must specify file format if reading from stdin"); } else { @@ -767,113 +767,113 @@ fname = find_file_to_load (fname, orig_fname); if (error_state) - return retval; + return retval; bool use_zlib = false; if (format == LS_UNKNOWN) - format = get_file_format (fname, orig_fname, use_zlib); + format = get_file_format (fname, orig_fname, use_zlib); #ifdef HAVE_HDF5 if (format == LS_HDF5) - { - i++; + { + i++; - hdf5_ifstream hdf5_file (fname.c_str ()); + hdf5_ifstream hdf5_file (fname.c_str ()); - if (hdf5_file.file_id >= 0) - { - retval = do_load (hdf5_file, orig_fname, format, - flt_fmt, list_only, swap, verbose, - argv, i, argc, nargout); + if (hdf5_file.file_id >= 0) + { + retval = do_load (hdf5_file, orig_fname, format, + flt_fmt, list_only, swap, verbose, + argv, i, argc, nargout); - hdf5_file.close (); - } - else - gripe_file_open ("load", orig_fname); - } + hdf5_file.close (); + } + else + gripe_file_open ("load", orig_fname); + } else #endif /* HAVE_HDF5 */ - // don't insert any statements here; the "else" above has to - // go with the "if" below!!!!! + // don't insert any statements here; the "else" above has to + // go with the "if" below!!!!! if (format != LS_UNKNOWN) - { - i++; + { + i++; - // Always open in binary mode and handle various - // line-endings explicitly. - std::ios::openmode mode = std::ios::in | std::ios::binary; + // Always open in binary mode and handle various + // line-endings explicitly. + std::ios::openmode mode = std::ios::in | std::ios::binary; #ifdef HAVE_ZLIB - if (use_zlib) - { - gzifstream file (fname.c_str (), mode); + if (use_zlib) + { + gzifstream file (fname.c_str (), mode); - if (file) - { - if (format == LS_BINARY) - { - if (read_binary_file_header (file, swap, flt_fmt) < 0) - { - if (file) file.close (); - return retval; - } - } - else if (format == LS_MAT5_BINARY - || format == LS_MAT7_BINARY) - { - if (read_mat5_binary_file_header (file, swap, false, orig_fname) < 0) - { - if (file) file.close (); - return retval; - } - } + if (file) + { + if (format == LS_BINARY) + { + if (read_binary_file_header (file, swap, flt_fmt) < 0) + { + if (file) file.close (); + return retval; + } + } + else if (format == LS_MAT5_BINARY + || format == LS_MAT7_BINARY) + { + if (read_mat5_binary_file_header (file, swap, false, orig_fname) < 0) + { + if (file) file.close (); + return retval; + } + } - retval = do_load (file, orig_fname, format, - flt_fmt, list_only, swap, verbose, - argv, i, argc, nargout); + retval = do_load (file, orig_fname, format, + flt_fmt, list_only, swap, verbose, + argv, i, argc, nargout); - file.close (); - } - else - gripe_file_open ("load", orig_fname); - } - else + file.close (); + } + else + gripe_file_open ("load", orig_fname); + } + else #endif - { - std::ifstream file (fname.c_str (), mode); + { + std::ifstream file (fname.c_str (), mode); - if (file) - { - if (format == LS_BINARY) - { - if (read_binary_file_header (file, swap, flt_fmt) < 0) - { - if (file) file.close (); - return retval; - } - } - else if (format == LS_MAT5_BINARY - || format == LS_MAT7_BINARY) - { - if (read_mat5_binary_file_header (file, swap, false, orig_fname) < 0) - { - if (file) file.close (); - return retval; - } - } + if (file) + { + if (format == LS_BINARY) + { + if (read_binary_file_header (file, swap, flt_fmt) < 0) + { + if (file) file.close (); + return retval; + } + } + else if (format == LS_MAT5_BINARY + || format == LS_MAT7_BINARY) + { + if (read_mat5_binary_file_header (file, swap, false, orig_fname) < 0) + { + if (file) file.close (); + return retval; + } + } - retval = do_load (file, orig_fname, format, - flt_fmt, list_only, swap, verbose, - argv, i, argc, nargout); + retval = do_load (file, orig_fname, format, + flt_fmt, list_only, swap, verbose, + argv, i, argc, nargout); - file.close (); - } - else - error ("load: unable open input file `%s'", - orig_fname.c_str ()); - } - } + file.close (); + } + else + error ("load: unable open input file `%s'", + orig_fname.c_str ()); + } + } } return retval; @@ -893,27 +893,27 @@ char c = pattern[i]; switch (c) - { - case '?': - case '*': - return true; + { + case '?': + case '*': + return true; - case '[': // Only accept an open brace if there is a close - open++; // brace to match it. Bracket expressions must be - continue; // complete, according to Posix.2 + case '[': // Only accept an open brace if there is a close + open++; // brace to match it. Bracket expressions must be + continue; // complete, according to Posix.2 - case ']': - if (open) - return true; - continue; + case ']': + if (open) + return true; + continue; - case '\\': - if (i == len - 1) - return false; + case '\\': + if (i == len - 1) + return false; - default: - continue; - } + default: + continue; + } } return false; @@ -921,8 +921,8 @@ static void do_save (std::ostream& os, const octave_value& tc, - const std::string& name, const std::string& help, - bool global, load_save_format fmt, bool save_as_floats) + const std::string& name, const std::string& help, + bool global, load_save_format fmt, bool save_as_floats) { switch (fmt.type) { @@ -937,7 +937,7 @@ case LS_MAT_ASCII: if (! save_mat_ascii_data (os, tc, fmt.opts & LS_MAT_ASCII_LONG ? 16 : 8, fmt.opts & LS_MAT_ASCII_TABS)) - warning ("save: unable to save %s in ASCII format", name.c_str ()); + warning ("save: unable to save %s in ASCII format", name.c_str ()); break; case LS_MAT_BINARY: @@ -968,7 +968,7 @@ void do_save (std::ostream& os, const symbol_table::symbol_record& sr, - load_save_format fmt, bool save_as_floats) + load_save_format fmt, bool save_as_floats) { octave_value val = sr.varval (); @@ -987,8 +987,8 @@ static size_t save_fields (std::ostream& os, const Octave_map& m, - const std::string& pattern, - load_save_format fmt, bool save_as_floats) + const std::string& pattern, + load_save_format fmt, bool save_as_floats) { glob_match pat (pattern); @@ -1001,7 +1001,7 @@ if (pat.match(p->first)) { do_save (os, p->second(0), p->first, empty_str, - 0, fmt, save_as_floats); + 0, fmt, save_as_floats); saved++; } @@ -1015,7 +1015,7 @@ static size_t save_vars (std::ostream& os, const std::string& pattern, - load_save_format fmt, bool save_as_floats) + load_save_format fmt, bool save_as_floats) { std::list vars = symbol_table::glob (pattern); @@ -1028,7 +1028,7 @@ do_save (os, *p, fmt, save_as_floats); if (error_state) - break; + break; saved++; } @@ -1038,8 +1038,8 @@ static string_vector parse_save_options (const string_vector &argv, - load_save_format &format, bool &append, - bool &save_as_floats, bool &use_zlib) + load_save_format &format, bool &append, + bool &save_as_floats, bool &use_zlib) { string_vector retval; int argc = argv.length (); @@ -1049,74 +1049,74 @@ for (int i = 0; i < argc; i++) { if (argv[i] == "-append") - { - append = true; - } + { + append = true; + } else if (argv[i] == "-ascii" || argv[i] == "-a") - { - format = LS_MAT_ASCII; - } + { + format = LS_MAT_ASCII; + } else if (argv[i] == "-double") - { - do_double = true; - } + { + do_double = true; + } else if (argv[i] == "-tabs") - { - do_tabs = true; - } + { + do_tabs = true; + } else if (argv[i] == "-text" || argv[i] == "-t") - { - format = LS_ASCII; - } + { + format = LS_ASCII; + } else if (argv[i] == "-binary" || argv[i] == "-b") - { - format = LS_BINARY; - } + { + format = LS_BINARY; + } else if (argv[i] == "-hdf5" || argv[i] == "-h") - { + { #ifdef HAVE_HDF5 - format = LS_HDF5; + format = LS_HDF5; #else /* ! HAVE_HDF5 */ - error ("save: octave executable was not linked with HDF5 library"); + error ("save: octave executable was not linked with HDF5 library"); #endif /* ! HAVE_HDF5 */ - } + } else if (argv[i] == "-mat-binary" || argv[i] == "-mat" - || argv[i] == "-m" || argv[i] == "-6" || argv[i] == "-v6" - || argv[i] == "-V6") - { - format = LS_MAT5_BINARY; - } + || argv[i] == "-m" || argv[i] == "-6" || argv[i] == "-v6" + || argv[i] == "-V6") + { + format = LS_MAT5_BINARY; + } #ifdef HAVE_ZLIB else if (argv[i] == "-mat7-binary" || argv[i] == "-7" - || argv[i] == "-v7" || argv[i] == "-V7") - { - format = LS_MAT7_BINARY; - } + || argv[i] == "-v7" || argv[i] == "-V7") + { + format = LS_MAT7_BINARY; + } #endif else if (argv[i] == "-mat4-binary" || argv[i] == "-V4" - || argv[i] == "-v4" || argv[i] == "-4") - { - format = LS_MAT_BINARY; - } + || argv[i] == "-v4" || argv[i] == "-4") + { + format = LS_MAT_BINARY; + } else if (argv[i] == "-float-binary" || argv[i] == "-f") - { - format = LS_BINARY; - save_as_floats = true; - } + { + format = LS_BINARY; + save_as_floats = true; + } else if (argv[i] == "-float-hdf5") - { + { #ifdef HAVE_HDF5 - format = LS_HDF5; - save_as_floats = true; + format = LS_HDF5; + save_as_floats = true; #else /* ! HAVE_HDF5 */ - error ("save: octave executable was not linked with HDF5 library"); + error ("save: octave executable was not linked with HDF5 library"); #endif /* ! HAVE_HDF5 */ - } + } #ifdef HAVE_ZLIB else if (argv[i] == "-zip" || argv[i] == "-z") - { - use_zlib = true; - } + { + use_zlib = true; + } #endif else retval.append (argv[i]); @@ -1125,17 +1125,17 @@ if (do_double) { if (format == LS_MAT_ASCII) - format.opts |= LS_MAT_ASCII_LONG; + format.opts |= LS_MAT_ASCII_LONG; else - warning ("save: \"-double\" option only has an effect with \"-ascii\""); + warning ("save: \"-double\" option only has an effect with \"-ascii\""); } if (do_tabs) { if (format == LS_MAT_ASCII) - format.opts |= LS_MAT_ASCII_TABS; + format.opts |= LS_MAT_ASCII_TABS; else - warning ("save: \"-tabs\" option only has an effect with \"-ascii\""); + warning ("save: \"-tabs\" option only has an effect with \"-ascii\""); } return retval; @@ -1143,8 +1143,8 @@ static string_vector parse_save_options (const std::string &arg, load_save_format &format, - bool &append, bool &save_as_floats, - bool &use_zlib) + bool &append, bool &save_as_floats, + bool &use_zlib) { std::istringstream is (arg); std::string str; @@ -1157,7 +1157,7 @@ } return parse_save_options (argv, format, append, save_as_floats, - use_zlib); + use_zlib); } void @@ -1167,48 +1167,48 @@ { case LS_BINARY: { - os << (oct_mach_info::words_big_endian () - ? "Octave-1-B" : "Octave-1-L"); + os << (oct_mach_info::words_big_endian () + ? "Octave-1-B" : "Octave-1-L"); - oct_mach_info::float_format flt_fmt = - oct_mach_info::native_float_format (); + oct_mach_info::float_format flt_fmt = + oct_mach_info::native_float_format (); - char tmp = static_cast (float_format_to_mopt_digit (flt_fmt)); + char tmp = static_cast (float_format_to_mopt_digit (flt_fmt)); - os.write (&tmp, 1); + os.write (&tmp, 1); } break; case LS_MAT5_BINARY: case LS_MAT7_BINARY: { - char const * versionmagic; - int16_t number = *(reinterpret_cast("\x00\x01")); - struct tm bdt; - time_t now; - char headertext[128]; + char const * versionmagic; + int16_t number = *(reinterpret_cast("\x00\x01")); + struct tm bdt; + time_t now; + char headertext[128]; - time (&now); - bdt = *gmtime (&now); - memset (headertext, ' ', 124); - // ISO 8601 format date - nstrftime (headertext, 124, "MATLAB 5.0 MAT-file, written by Octave " + time (&now); + bdt = *gmtime (&now); + memset (headertext, ' ', 124); + // ISO 8601 format date + nstrftime (headertext, 124, "MATLAB 5.0 MAT-file, written by Octave " OCTAVE_VERSION ", %Y-%m-%d %T UTC", &bdt, 1, 0); - // The first pair of bytes give the version of the MAT file - // format. The second pair of bytes form a magic number which - // signals a MAT file. MAT file data are always written in - // native byte order. The order of the bytes in the second - // pair indicates whether the file was written by a big- or - // little-endian machine. However, the version number is - // written in the *opposite* byte order from everything else! - if (number == 1) - versionmagic = "\x01\x00\x4d\x49"; // this machine is big endian - else - versionmagic = "\x00\x01\x49\x4d"; // this machine is little endian + // The first pair of bytes give the version of the MAT file + // format. The second pair of bytes form a magic number which + // signals a MAT file. MAT file data are always written in + // native byte order. The order of the bytes in the second + // pair indicates whether the file was written by a big- or + // little-endian machine. However, the version number is + // written in the *opposite* byte order from everything else! + if (number == 1) + versionmagic = "\x01\x00\x4d\x49"; // this machine is big endian + else + versionmagic = "\x00\x01\x49\x4d"; // this machine is little endian - memcpy (headertext+124, versionmagic, 4); - os.write (headertext, 128); + memcpy (headertext+124, versionmagic, 4); + os.write (headertext, 128); } break; @@ -1218,22 +1218,22 @@ #endif /* HAVE_HDF5 */ case LS_ASCII: { - octave_localtime now; + octave_localtime now; - std::string comment_string = now.strftime (Vsave_header_format_string); + std::string comment_string = now.strftime (Vsave_header_format_string); - if (! comment_string.empty ()) - { + if (! comment_string.empty ()) + { #ifdef HAVE_HDF5 - if (format == LS_HDF5) - { - hdf5_ofstream& hs = dynamic_cast (os); - H5Gset_comment (hs.file_id, "/", comment_string.c_str ()); - } - else + if (format == LS_HDF5) + { + hdf5_ofstream& hs = dynamic_cast (os); + H5Gset_comment (hs.file_id, "/", comment_string.c_str ()); + } + else #endif /* HAVE_HDF5 */ - os << comment_string << "\n"; - } + os << comment_string << "\n"; + } } break; @@ -1244,8 +1244,8 @@ static void save_vars (const string_vector& argv, int argv_idx, int argc, - std::ostream& os, load_save_format fmt, - bool save_as_floats, bool write_header_info) + std::ostream& os, load_save_format fmt, + bool save_as_floats, bool write_header_info) { if (write_header_info) write_header (os, fmt); @@ -1275,7 +1275,7 @@ if (! struct_var.is_map () || struct_var.numel () != 1) { error ("save: `%s' is not a scalar structure", - struct_name.c_str ()); + struct_name.c_str ()); return; } Octave_map struct_var_map = struct_var.map_value (); @@ -1287,29 +1287,29 @@ for (int i = argv_idx; i < argc; i++) { if (! save_fields (os, struct_var_map, argv[i], fmt, - save_as_floats)) + save_as_floats)) { warning ("save: no such field `%s.%s'", - struct_name.c_str (), argv[i].c_str ()); + struct_name.c_str (), argv[i].c_str ()); } } } else - save_fields (os, struct_var_map, "*", fmt, save_as_floats); + save_fields (os, struct_var_map, "*", fmt, save_as_floats); } else { for (int i = argv_idx; i < argc; i++) - { - if (! save_vars (os, argv[i], fmt, save_as_floats)) - warning ("save: no such variable `%s'", argv[i].c_str ()); - } + { + if (! save_vars (os, argv[i], fmt, save_as_floats)) + warning ("save: no such variable `%s'", argv[i].c_str ()); + } } } static void dump_octave_core (std::ostream& os, const char *fname, load_save_format fmt, - bool save_as_floats) + bool save_as_floats) { write_header (os, fmt); @@ -1325,26 +1325,26 @@ octave_value val = p->varval (); if (val.is_defined ()) - { - std::string name = p->name (); - std::string help; - bool global = p->is_global (); + { + std::string name = p->name (); + std::string help; + bool global = p->is_global (); - double val_size = val.byte_size () / 1024; + double val_size = val.byte_size () / 1024; - // FIXME -- maybe we should try to throw out the largest first... + // FIXME -- maybe we should try to throw out the largest first... - if (Voctave_core_file_limit < 0 - || save_mem_size + val_size < Voctave_core_file_limit) - { - save_mem_size += val_size; + if (Voctave_core_file_limit < 0 + || save_mem_size + val_size < Voctave_core_file_limit) + { + save_mem_size += val_size; - do_save (os, val, name, help, global, fmt, save_as_floats); + do_save (os, val, name, help, global, fmt, save_as_floats); - if (error_state) - break; - } - } + if (error_state) + break; + } + } } message (0, "save to `%s' complete", fname); @@ -1370,73 +1370,73 @@ bool use_zlib = false; parse_save_options (Voctave_core_file_options, format, append, - save_as_floats, use_zlib); + save_as_floats, use_zlib); std::ios::openmode mode = std::ios::out; // Matlab v7 files are always compressed if (format == LS_MAT7_BINARY) - use_zlib = false; + use_zlib = false; if (format == LS_BINARY #ifdef HAVE_HDF5 - || format == LS_HDF5 + || format == LS_HDF5 #endif - || format == LS_MAT_BINARY - || format == LS_MAT5_BINARY - || format == LS_MAT7_BINARY) - mode |= std::ios::binary; + || format == LS_MAT_BINARY + || format == LS_MAT5_BINARY + || format == LS_MAT7_BINARY) + mode |= std::ios::binary; mode |= append ? std::ios::ate : std::ios::trunc; #ifdef HAVE_HDF5 if (format == LS_HDF5) - { - hdf5_ofstream file (fname, mode); + { + hdf5_ofstream file (fname, mode); - if (file.file_id >= 0) - { - dump_octave_core (file, fname, format, save_as_floats); + if (file.file_id >= 0) + { + dump_octave_core (file, fname, format, save_as_floats); - file.close (); - } - else - warning ("unable to open `%s' for writing...", fname); - } + file.close (); + } + else + warning ("unable to open `%s' for writing...", fname); + } else #endif /* HAVE_HDF5 */ - // don't insert any commands here! The open brace below must - // go with the else above! - { + // don't insert any commands here! The open brace below must + // go with the else above! + { #ifdef HAVE_ZLIB - if (use_zlib) - { - gzofstream file (fname, mode); + if (use_zlib) + { + gzofstream file (fname, mode); - if (file) - { - dump_octave_core (file, fname, format, save_as_floats); + if (file) + { + dump_octave_core (file, fname, format, save_as_floats); - file.close (); - } - else - warning ("unable to open `%s' for writing...", fname); - } - else + file.close (); + } + else + warning ("unable to open `%s' for writing...", fname); + } + else #endif - { - std::ofstream file (fname, mode); - - if (file) - { - dump_octave_core (file, fname, format, save_as_floats); + { + std::ofstream file (fname, mode); + + if (file) + { + dump_octave_core (file, fname, format, save_as_floats); - file.close (); - } - else - warning ("unable to open `%s' for writing...", fname); - } - } + file.close (); + } + else + warning ("unable to open `%s' for writing...", fname); + } + } } } @@ -1628,18 +1628,18 @@ error ("save: cannot write HDF5 format to stdout"); else #endif /* HAVE_HDF5 */ - // don't insert any commands here! the brace below must go - // with the "else" above! - { - if (append) - warning ("save: ignoring -append option for output to stdout"); + // don't insert any commands here! the brace below must go + // with the "else" above! + { + if (append) + warning ("save: ignoring -append option for output to stdout"); - // FIXME -- should things intended for the screen end up - // in a octave_value (string)? - - save_vars (argv, i, argc, octave_stdout, format, - save_as_floats, true); - } + // FIXME -- should things intended for the screen end up + // in a octave_value (string)? + + save_vars (argv, i, argc, octave_stdout, format, + save_as_floats, true); + } } // Guard against things like `save a*', which are probably mistakes... @@ -1657,94 +1657,94 @@ // Matlab v7 files are always compressed if (format == LS_MAT7_BINARY) - use_zlib = false; + use_zlib = false; std::ios::openmode mode - = append ? (std::ios::app | std::ios::ate) : std::ios::out; + = append ? (std::ios::app | std::ios::ate) : std::ios::out; if (format == LS_BINARY #ifdef HAVE_HDF5 - || format == LS_HDF5 + || format == LS_HDF5 #endif - || format == LS_MAT_BINARY - || format == LS_MAT5_BINARY - || format == LS_MAT7_BINARY) - mode |= std::ios::binary; + || format == LS_MAT_BINARY + || format == LS_MAT5_BINARY + || format == LS_MAT7_BINARY) + mode |= std::ios::binary; #ifdef HAVE_HDF5 if (format == LS_HDF5) - { - // FIXME. It should be possible to append to HDF5 files. - if (append) - { - error ("save: appending to HDF5 files is not implemented"); - return retval; - } + { + // FIXME. It should be possible to append to HDF5 files. + if (append) + { + error ("save: appending to HDF5 files is not implemented"); + return retval; + } - bool write_header_info = ! (append && - H5Fis_hdf5 (fname.c_str ()) > 0); + bool write_header_info = ! (append && + H5Fis_hdf5 (fname.c_str ()) > 0); - hdf5_ofstream hdf5_file (fname.c_str (), mode); + hdf5_ofstream hdf5_file (fname.c_str (), mode); - if (hdf5_file.file_id != -1) - { - save_vars (argv, i, argc, hdf5_file, format, - save_as_floats, write_header_info); + if (hdf5_file.file_id != -1) + { + save_vars (argv, i, argc, hdf5_file, format, + save_as_floats, write_header_info); - hdf5_file.close (); - } - else - { - gripe_file_open ("save", fname); - return retval; - } - } + hdf5_file.close (); + } + else + { + gripe_file_open ("save", fname); + return retval; + } + } else #endif /* HAVE_HDF5 */ - // don't insert any statements here! The brace below must go - // with the "else" above! - { + // don't insert any statements here! The brace below must go + // with the "else" above! + { #ifdef HAVE_ZLIB - if (use_zlib) - { - gzofstream file (fname.c_str (), mode); + if (use_zlib) + { + gzofstream file (fname.c_str (), mode); - if (file) - { - bool write_header_info = ! file.tellp (); + if (file) + { + bool write_header_info = ! file.tellp (); - save_vars (argv, i, argc, file, format, - save_as_floats, write_header_info); + save_vars (argv, i, argc, file, format, + save_as_floats, write_header_info); - file.close (); - } - else - { - gripe_file_open ("save", fname); - return retval; - } - } - else + file.close (); + } + else + { + gripe_file_open ("save", fname); + return retval; + } + } + else #endif - { - std::ofstream file (fname.c_str (), mode); - - if (file) - { - bool write_header_info = ! file.tellp (); + { + std::ofstream file (fname.c_str (), mode); + + if (file) + { + bool write_header_info = ! file.tellp (); - save_vars (argv, i, argc, file, format, - save_as_floats, write_header_info); + save_vars (argv, i, argc, file, format, + save_as_floats, write_header_info); - file.close (); - } - else - { - gripe_file_open ("save", fname); - return retval; - } - } - } + file.close (); + } + else + { + gripe_file_open ("save", fname); + return retval; + } + } + } } return retval; diff --git a/src/ls-ascii-helper.cc b/src/ls-ascii-helper.cc --- a/src/ls-ascii-helper.cc +++ b/src/ls-ascii-helper.cc @@ -49,34 +49,34 @@ char c = is.peek (); if (c == '\n' || c == '\r') - { - // Reached newline. - if (! keep_newline) - { - // Eat the CR or LF character. - char d; - is.get (d); - - // Make sure that for binary-mode opened ascii files - // containing CRLF line endings we skip the LF after CR. - if (c == '\r' && is.peek () == '\n') - { - // Yes, LF following CR, eat it. - is.get (d); - } - } - - // Newline was found, and read from stream if - // keep_newline == true, so exit loop. - break; - } + { + // Reached newline. + if (! keep_newline) + { + // Eat the CR or LF character. + char d; + is.get (d); + + // Make sure that for binary-mode opened ascii files + // containing CRLF line endings we skip the LF after CR. + if (c == '\r' && is.peek () == '\n') + { + // Yes, LF following CR, eat it. + is.get (d); + } + } + + // Newline was found, and read from stream if + // keep_newline == true, so exit loop. + break; + } else - { - // No newline charater peeked, so read it and proceed to next - // character. - char d; - is.get (d); - } + { + // No newline charater peeked, so read it and proceed to next + // character. + char d; + is.get (d); + } } } @@ -98,24 +98,24 @@ { // Yes, at newline. do - { - // Eat the CR or LF character. - char d; - is.get (d); - - // Make sure that for binary-mode opened ascii files - // containing CRLF line endings we skip the LF after CR. - if (c == '\r' && is.peek () == '\n') - { - // Yes, LF following CR, eat it. - is.get (d); - } - - // Peek into next character. - c = is.peek (); + { + // Eat the CR or LF character. + char d; + is.get (d); + + // Make sure that for binary-mode opened ascii files + // containing CRLF line endings we skip the LF after CR. + if (c == '\r' && is.peek () == '\n') + { + // Yes, LF following CR, eat it. + is.get (d); + } + + // Peek into next character. + c = is.peek (); - // Loop while still a newline ahead. - } + // Loop while still a newline ahead. + } while (c == '\n' || c == '\r'); } } @@ -138,37 +138,37 @@ char c = is.peek (); if (c == '\n' || c == '\r') - { - // Reached newline. - if (! keep_newline) - { - // Eat the CR or LF character. - char d; - is.get (d); - - // Make sure that for binary-mode opened ascii files - // containing CRLF line endings we skip the LF after - // CR. + { + // Reached newline. + if (! keep_newline) + { + // Eat the CR or LF character. + char d; + is.get (d); + + // Make sure that for binary-mode opened ascii files + // containing CRLF line endings we skip the LF after + // CR. - if (c == '\r' && is.peek () == '\n') - { - // Yes, LF following CR, eat it. - is.get (d); - } - } - - // Newline was found, and read from stream if - // keep_newline == true, so exit loop. - break; - } + if (c == '\r' && is.peek () == '\n') + { + // Yes, LF following CR, eat it. + is.get (d); + } + } + + // Newline was found, and read from stream if + // keep_newline == true, so exit loop. + break; + } else - { - // No newline charater peeked, so read it, store it, and - // proceed to next. - char d; - is.get (d); - buf << d; - } + { + // No newline charater peeked, so read it, store it, and + // proceed to next. + char d; + is.get (d); + buf << d; + } } return buf.str (); diff --git a/src/ls-hdf5.cc b/src/ls-hdf5.cc --- a/src/ls-hdf5.cc +++ b/src/ls-hdf5.cc @@ -81,13 +81,13 @@ if (nm_len > 0) { if (! isalpha (nm[0])) - retval += '_'; + retval += '_'; for (size_t i = 0; i < nm_len; i++) - { - char c = nm[i]; - retval += (isalnum (c) || c == '_') ? c : '_'; - } + { + char c = nm[i]; + retval += (isalnum (c) || c == '_') ? c : '_'; + } } return retval; @@ -115,7 +115,7 @@ hid_t mt2 = H5Tget_member_type (t2, i); if (H5Tget_class (mt1) != H5Tget_class (mt2)) - return false; + return false; H5Tclose (mt2); H5Tclose (mt1); @@ -231,82 +231,82 @@ #endif if (subgroup_id < 0) - { - retval = subgroup_id; - goto done; - } + { + retval = subgroup_id; + goto done; + } if (hdf5_check_attr (subgroup_id, "OCTAVE_NEW_FORMAT")) - { + { #if HAVE_HDF5_18 - data_id = H5Dopen (subgroup_id, "type", H5P_DEFAULT); + data_id = H5Dopen (subgroup_id, "type", H5P_DEFAULT); #else - data_id = H5Dopen (subgroup_id, "type"); + data_id = H5Dopen (subgroup_id, "type"); #endif - if (data_id < 0) - { - retval = data_id; - goto done; - } + if (data_id < 0) + { + retval = data_id; + goto done; + } - type_id = H5Dget_type (data_id); + type_id = H5Dget_type (data_id); - type_class_id = H5Tget_class (type_id); + type_class_id = H5Tget_class (type_id); - if (type_class_id != H5T_STRING) - goto done; - - space_id = H5Dget_space (data_id); - hsize_t rank = H5Sget_simple_extent_ndims (space_id); + if (type_class_id != H5T_STRING) + goto done; + + space_id = H5Dget_space (data_id); + hsize_t rank = H5Sget_simple_extent_ndims (space_id); - if (rank != 0) - goto done; + if (rank != 0) + goto done; - int slen = H5Tget_size (type_id); - if (slen < 0) - goto done; + int slen = H5Tget_size (type_id); + if (slen < 0) + goto done; - OCTAVE_LOCAL_BUFFER (char, typ, slen); + OCTAVE_LOCAL_BUFFER (char, typ, slen); - // create datatype for (null-terminated) string to read into: - hid_t st_id = H5Tcopy (H5T_C_S1); - H5Tset_size (st_id, slen); + // create datatype for (null-terminated) string to read into: + hid_t st_id = H5Tcopy (H5T_C_S1); + H5Tset_size (st_id, slen); - if (H5Dread (data_id, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, - typ) < 0) - goto done; + if (H5Dread (data_id, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, + typ) < 0) + goto done; - H5Tclose (st_id); - H5Dclose (data_id); + H5Tclose (st_id); + H5Dclose (data_id); - d->tc = octave_value_typeinfo::lookup_type (typ); + d->tc = octave_value_typeinfo::lookup_type (typ); - retval = (d->tc.load_hdf5 (subgroup_id, "value") ? 1 : -1); + retval = (d->tc.load_hdf5 (subgroup_id, "value") ? 1 : -1); - // check for OCTAVE_GLOBAL attribute: - d->global = hdf5_check_attr (subgroup_id, "OCTAVE_GLOBAL"); + // check for OCTAVE_GLOBAL attribute: + d->global = hdf5_check_attr (subgroup_id, "OCTAVE_GLOBAL"); - H5Gclose (subgroup_id); - } + H5Gclose (subgroup_id); + } else - { - // an HDF5 group is treated as an octave structure by - // default (since that preserves name information), and an - // octave list otherwise. + { + // an HDF5 group is treated as an octave structure by + // default (since that preserves name information), and an + // octave list otherwise. - if (hdf5_check_attr (subgroup_id, "OCTAVE_LIST")) - d->tc = octave_value_typeinfo::lookup_type ("list"); - else - d->tc = octave_value_typeinfo::lookup_type ("struct"); - - // check for OCTAVE_GLOBAL attribute: - d->global = hdf5_check_attr (subgroup_id, "OCTAVE_GLOBAL"); + if (hdf5_check_attr (subgroup_id, "OCTAVE_LIST")) + d->tc = octave_value_typeinfo::lookup_type ("list"); + else + d->tc = octave_value_typeinfo::lookup_type ("struct"); + + // check for OCTAVE_GLOBAL attribute: + d->global = hdf5_check_attr (subgroup_id, "OCTAVE_GLOBAL"); - H5Gclose (subgroup_id); + H5Gclose (subgroup_id); - retval = (d->tc.load_hdf5 (group_id, name) ? 1 : -1); - } + retval = (d->tc.load_hdf5 (group_id, name) ? 1 : -1); + } } else if (info.type == H5G_DATASET && ident_valid) @@ -319,164 +319,164 @@ #endif if (data_id < 0) - { - retval = data_id; - goto done; - } + { + retval = data_id; + goto done; + } type_id = H5Dget_type (data_id); type_class_id = H5Tget_class (type_id); if (type_class_id == H5T_FLOAT) - { - space_id = H5Dget_space (data_id); + { + space_id = H5Dget_space (data_id); - hsize_t rank = H5Sget_simple_extent_ndims (space_id); - - if (rank == 0) - d->tc = octave_value_typeinfo::lookup_type ("scalar"); - else - d->tc = octave_value_typeinfo::lookup_type ("matrix"); + hsize_t rank = H5Sget_simple_extent_ndims (space_id); + + if (rank == 0) + d->tc = octave_value_typeinfo::lookup_type ("scalar"); + else + d->tc = octave_value_typeinfo::lookup_type ("matrix"); - H5Sclose (space_id); - } + H5Sclose (space_id); + } else if (type_class_id == H5T_INTEGER) - { - // What integer type do we really have.. - std::string int_typ; + { + // What integer type do we really have.. + std::string int_typ; #ifdef HAVE_H5T_GET_NATIVE_TYPE - // FIXME test this code and activated with an autoconf - // test!! It is also incorrect for 64-bit indexing!! - - switch (H5Tget_native_type (type_id, H5T_DIR_ASCEND)) - { - case H5T_NATIVE_CHAR: - int_typ = "int8 "; - break; + // FIXME test this code and activated with an autoconf + // test!! It is also incorrect for 64-bit indexing!! + + switch (H5Tget_native_type (type_id, H5T_DIR_ASCEND)) + { + case H5T_NATIVE_CHAR: + int_typ = "int8 "; + break; - case H5T_NATIVE_SHORT: - int_typ = "int16 "; - break; + case H5T_NATIVE_SHORT: + int_typ = "int16 "; + break; - case H5T_NATIVE_INT: - case H5T_NATIVE_LONG: - int_typ = "int32 "; - break; + case H5T_NATIVE_INT: + case H5T_NATIVE_LONG: + int_typ = "int32 "; + break; - case H5T_NATIVE_LLONG: - int_typ = "int64 "; - break; + case H5T_NATIVE_LLONG: + int_typ = "int64 "; + break; - case H5T_NATIVE_UCHAR: - int_typ = "uint8 "; - break; + case H5T_NATIVE_UCHAR: + int_typ = "uint8 "; + break; - case H5T_NATIVE_USHORT: - int_typ = "uint16 "; - break; + case H5T_NATIVE_USHORT: + int_typ = "uint16 "; + break; - case H5T_NATIVE_UINT: - case H5T_NATIVE_ULONG: - int_typ = "uint32 "; - break; + case H5T_NATIVE_UINT: + case H5T_NATIVE_ULONG: + int_typ = "uint32 "; + break; - case H5T_NATIVE_ULLONG: - int_typ = "uint64 "; - break; - } + case H5T_NATIVE_ULLONG: + int_typ = "uint64 "; + break; + } #else - hid_t int_sign = H5Tget_sign (type_id); + hid_t int_sign = H5Tget_sign (type_id); - if (int_sign == H5T_SGN_ERROR) - warning ("load: can't read `%s' (unknown datatype)", name); - else - { - if (int_sign == H5T_SGN_NONE) - int_typ.append ("u"); - int_typ.append ("int"); + if (int_sign == H5T_SGN_ERROR) + warning ("load: can't read `%s' (unknown datatype)", name); + else + { + if (int_sign == H5T_SGN_NONE) + int_typ.append ("u"); + int_typ.append ("int"); - int slen = H5Tget_size (type_id); - if (slen < 0) - warning ("load: can't read `%s' (unknown datatype)", name); - else - { - switch (slen) - { - case 1: - int_typ.append ("8 "); - break; + int slen = H5Tget_size (type_id); + if (slen < 0) + warning ("load: can't read `%s' (unknown datatype)", name); + else + { + switch (slen) + { + case 1: + int_typ.append ("8 "); + break; - case 2: - int_typ.append ("16 "); - break; + case 2: + int_typ.append ("16 "); + break; - case 4: - int_typ.append ("32 "); - break; + case 4: + int_typ.append ("32 "); + break; - case 8: - int_typ.append ("64 "); - break; + case 8: + int_typ.append ("64 "); + break; - default: - warning ("load: can't read `%s' (unknown datatype)", - name); - int_typ = ""; - break; - } - } - } + default: + warning ("load: can't read `%s' (unknown datatype)", + name); + int_typ = ""; + break; + } + } + } #endif - if (int_typ == "") - warning ("load: can't read `%s' (unknown datatype)", name); - else - { - // Matrix or scalar? - space_id = H5Dget_space (data_id); + if (int_typ == "") + warning ("load: can't read `%s' (unknown datatype)", name); + else + { + // Matrix or scalar? + space_id = H5Dget_space (data_id); - hsize_t rank = H5Sget_simple_extent_ndims (space_id); - - if (rank == 0) - int_typ.append ("scalar"); - else - int_typ.append ("matrix"); + hsize_t rank = H5Sget_simple_extent_ndims (space_id); + + if (rank == 0) + int_typ.append ("scalar"); + else + int_typ.append ("matrix"); - d->tc = octave_value_typeinfo::lookup_type (int_typ); - H5Sclose (space_id); - } - } + d->tc = octave_value_typeinfo::lookup_type (int_typ); + H5Sclose (space_id); + } + } else if (type_class_id == H5T_STRING) - d->tc = octave_value_typeinfo::lookup_type ("string"); + d->tc = octave_value_typeinfo::lookup_type ("string"); else if (type_class_id == H5T_COMPOUND) - { - hid_t complex_type = hdf5_make_complex_type (H5T_NATIVE_DOUBLE); + { + hid_t complex_type = hdf5_make_complex_type (H5T_NATIVE_DOUBLE); - if (hdf5_types_compatible (type_id, complex_type)) - { - // read complex matrix or scalar variable - space_id = H5Dget_space (data_id); - hsize_t rank = H5Sget_simple_extent_ndims (space_id); - - if (rank == 0) - d->tc = octave_value_typeinfo::lookup_type ("complex scalar"); - else - d->tc = octave_value_typeinfo::lookup_type ("complex matrix"); + if (hdf5_types_compatible (type_id, complex_type)) + { + // read complex matrix or scalar variable + space_id = H5Dget_space (data_id); + hsize_t rank = H5Sget_simple_extent_ndims (space_id); + + if (rank == 0) + d->tc = octave_value_typeinfo::lookup_type ("complex scalar"); + else + d->tc = octave_value_typeinfo::lookup_type ("complex matrix"); - H5Sclose (space_id); - } - else - // Assume that if its not complex its a range. If its not - // it'll be rejected later in the range code - d->tc = octave_value_typeinfo::lookup_type ("range"); + H5Sclose (space_id); + } + else + // Assume that if its not complex its a range. If its not + // it'll be rejected later in the range code + d->tc = octave_value_typeinfo::lookup_type ("range"); - H5Tclose (complex_type); - } + H5Tclose (complex_type); + } else - { - warning ("load: can't read `%s' (unknown datatype)", name); - retval = 0; // unknown datatype; skip - } + { + warning ("load: can't read `%s' (unknown datatype)", name); + retval = 0; // unknown datatype; skip + } // check for OCTAVE_GLOBAL attribute: d->global = hdf5_check_attr (data_id, "OCTAVE_GLOBAL"); @@ -492,7 +492,7 @@ // should we attempt to handle invalid identifiers by converting // bad characters to '_', say? warning ("load: skipping invalid identifier `%s' in hdf5 file", - name); + name); } done: @@ -505,17 +505,17 @@ int comment_length = H5Gget_comment (group_id, name, 0, 0); if (comment_length > 1) - { - OCTAVE_LOCAL_BUFFER (char, tdoc, comment_length); - H5Gget_comment (group_id, name, comment_length, tdoc); - d->doc = tdoc; - } + { + OCTAVE_LOCAL_BUFFER (char, tdoc, comment_length); + H5Gget_comment (group_id, name, comment_length, tdoc); + d->doc = tdoc; + } else if (vname != name) - { - // the name was changed; store the original name - // as the documentation string: - d->doc = name; - } + { + // the name was changed; store the original name + // as the documentation string: + d->doc = name; + } // copy name (actually, vname): d->name = vname; @@ -531,7 +531,7 @@ // and error. std::string read_hdf5_data (std::istream& is, const std::string& /* filename */, - bool& global, octave_value& tc, std::string& doc) + bool& global, octave_value& tc, std::string& doc) { std::string retval; @@ -552,7 +552,7 @@ H5Gclose (group_id); if (hs.current_item < static_cast (num_obj)) H5Giterate_retval = H5Giterate (hs.file_id, "/", &hs.current_item, - hdf5_read_next_data, &d); + hdf5_read_next_data, &d); if (H5Giterate_retval > 0) { @@ -586,21 +586,21 @@ { #if HAVE_HDF5_18 hid_t a_id = H5Acreate (loc_id, attr_name, H5T_NATIVE_UCHAR, - as_id, H5P_DEFAULT, H5P_DEFAULT); + as_id, H5P_DEFAULT, H5P_DEFAULT); #else hid_t a_id = H5Acreate (loc_id, attr_name, - H5T_NATIVE_UCHAR, as_id, H5P_DEFAULT); + H5T_NATIVE_UCHAR, as_id, H5P_DEFAULT); #endif if (a_id >= 0) - { - unsigned char attr_val = 1; + { + unsigned char attr_val = 1; - retval = H5Awrite (a_id, H5T_NATIVE_UCHAR, &attr_val); + retval = H5Awrite (a_id, H5T_NATIVE_UCHAR, &attr_val); - H5Aclose (a_id); - } + H5Aclose (a_id); + } else - retval = a_id; + retval = a_id; H5Sclose (as_id); } @@ -626,7 +626,7 @@ { dims[i] = d(i); if (dims[i] < 1) - empty = true; + empty = true; } if (!empty) @@ -636,10 +636,10 @@ if (space_hid < 0) return space_hid; #if HAVE_HDF5_18 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -648,7 +648,7 @@ } retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, - H5P_DEFAULT, dims) >= 0; + H5P_DEFAULT, dims) >= 0; H5Dclose (data_hid); H5Sclose (space_hid); @@ -682,12 +682,12 @@ OCTAVE_LOCAL_BUFFER (octave_idx_type, dims, hdims); retval = H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, - H5P_DEFAULT, dims); + H5P_DEFAULT, dims); if (retval >= 0) { d.resize (hdims); for (hsize_t i = 0; i < hdims; i++) - d(i) = dims[i]; + d(i) = dims[i]; } H5Sclose (space_id); @@ -743,8 +743,8 @@ bool add_hdf5_data (hid_t loc_id, const octave_value& tc, - const std::string& name, const std::string& doc, - bool mark_as_global, bool save_as_floats) + const std::string& name, const std::string& doc, + bool mark_as_global, bool save_as_floats) { hsize_t dims[3]; hid_t type_id = -1, space_id = -1, data_id = -1, data_type_id = -1; @@ -776,12 +776,12 @@ goto error_cleanup; #if HAVE_HDF5_18 data_type_id = H5Dcreate (data_id, "type", type_id, space_id, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_type_id = H5Dcreate (data_id, "type", type_id, space_id, H5P_DEFAULT); #endif if (data_type_id < 0 || H5Dwrite (data_type_id, type_id, H5S_ALL, H5S_ALL, - H5P_DEFAULT, t.c_str ()) < 0) + H5P_DEFAULT, t.c_str ()) < 0) goto error_cleanup; // Now call the real function to save the variable @@ -825,13 +825,13 @@ bool save_hdf5_data (std::ostream& os, const octave_value& tc, - const std::string& name, const std::string& doc, - bool mark_as_global, bool save_as_floats) + const std::string& name, const std::string& doc, + bool mark_as_global, bool save_as_floats) { hdf5_ofstream& hs = dynamic_cast (os); return add_hdf5_data (hs.file_id, tc, name, doc, - mark_as_global, save_as_floats); + mark_as_global, save_as_floats); } #endif diff --git a/src/ls-mat-ascii.cc b/src/ls-mat-ascii.cc --- a/src/ls-mat-ascii.cc +++ b/src/ls-mat-ascii.cc @@ -78,28 +78,28 @@ char c; while (is.get (c)) - { - if (c == '\n' || c == '\r') - { - is.putback (c); - skip_preceeding_newline (is); - break; - } + { + if (c == '\n' || c == '\r') + { + is.putback (c); + skip_preceeding_newline (is); + break; + } - if (c == '%' || c == '#') - { - skip_until_newline (is, false); - break; - } + if (c == '%' || c == '#') + { + skip_until_newline (is, false); + break; + } - if (! is.eof ()) - { - if (! have_data && c != ' ' && c != '\t') - have_data = true; + if (! is.eof ()) + { + if (! have_data && c != ' ' && c != '\t') + have_data = true; - retval += c; - } - } + retval += c; + } + } } while (! (have_data || is.eof ())); @@ -131,50 +131,50 @@ // will not be considered as whitespace. if (beg != std::string::npos && buf[beg] == '\r' && beg == buf.length () - 1) - { - // We had a blank line ending with a CRLF. Handle it the - // same as an empty line. - beg = std::string::npos; - } + { + // We had a blank line ending with a CRLF. Handle it the + // same as an empty line. + beg = std::string::npos; + } octave_idx_type tmp_nc = 0; while (beg != std::string::npos) - { - tmp_nc++; + { + tmp_nc++; - size_t end = buf.find_first_of (", \t", beg); + size_t end = buf.find_first_of (", \t", beg); - if (end != std::string::npos) - { - beg = buf.find_first_not_of (", \t", end); + if (end != std::string::npos) + { + beg = buf.find_first_not_of (", \t", end); - if (beg == std::string::npos || (buf[beg] == '\r' && - beg == buf.length () - 1)) - { - // We had a line with trailing spaces and - // ending with a CRLF, so this should look like EOL, - // not a new colum. - break; - } - } - else - break; - } + if (beg == std::string::npos || (buf[beg] == '\r' && + beg == buf.length () - 1)) + { + // We had a line with trailing spaces and + // ending with a CRLF, so this should look like EOL, + // not a new colum. + break; + } + } + else + break; + } if (tmp_nc > 0) - { - if (nc == 0) - { - nc = tmp_nc; - nr++; - } - else if (nc == tmp_nc) - nr++; - else - error ("load: %s: inconsistent number of columns near line %d", - filename.c_str (), file_line_number); - } + { + if (nc == 0) + { + nc = tmp_nc; + nr++; + } + else if (nc == tmp_nc) + nr++; + else + error ("load: %s: inconsistent number of columns near line %d", + filename.c_str (), file_line_number); + } } if (nr == 0 || nc == 0) @@ -197,7 +197,7 @@ std::string read_mat_ascii_data (std::istream& is, const std::string& filename, - octave_value& tc) + octave_value& tc) { std::string retval; @@ -220,7 +220,7 @@ { char c = varname[i]; if (! (isalnum (c) || c == '_')) - varname[i] = '_'; + varname[i] = '_'; } if (is_keyword (varname) || ! isalpha (varname[0])) @@ -238,98 +238,98 @@ octave_quit (); if (! error_state && nr > 0 && nc > 0) - { - Matrix tmp (nr, nc); + { + Matrix tmp (nr, nc); - if (nr < 1 || nc < 1) - is.clear (std::ios::badbit); - else - { - double d; - for (octave_idx_type i = 0; i < nr; i++) - { - std::string buf = get_mat_data_input_line (is); + if (nr < 1 || nc < 1) + is.clear (std::ios::badbit); + else + { + double d; + for (octave_idx_type i = 0; i < nr; i++) + { + std::string buf = get_mat_data_input_line (is); - std::istringstream tmp_stream (buf); + std::istringstream tmp_stream (buf); - for (octave_idx_type j = 0; j < nc; j++) - { - octave_quit (); + for (octave_idx_type j = 0; j < nc; j++) + { + octave_quit (); - d = octave_read_value (tmp_stream); + d = octave_read_value (tmp_stream); - if (tmp_stream || tmp_stream.eof ()) - { - tmp.elem (i, j) = d; - total_count++; + if (tmp_stream || tmp_stream.eof ()) + { + tmp.elem (i, j) = d; + total_count++; - // Skip whitespace and commas. - char c; - while (1) - { - tmp_stream >> c; + // Skip whitespace and commas. + char c; + while (1) + { + tmp_stream >> c; - if (! tmp_stream) - break; + if (! tmp_stream) + break; - if (! (c == ' ' || c == '\t' || c == ',')) - { - tmp_stream.putback (c); - break; - } - } + if (! (c == ' ' || c == '\t' || c == ',')) + { + tmp_stream.putback (c); + break; + } + } - if (tmp_stream.eof ()) - break; - } - else - { - error ("load: failed to read matrix from file `%s'", - filename.c_str ()); + if (tmp_stream.eof ()) + break; + } + else + { + error ("load: failed to read matrix from file `%s'", + filename.c_str ()); - return retval; - } + return retval; + } - } - } - } + } + } + } - if (is || is.eof ()) - { - // FIXME -- not sure this is best, but it works. + if (is || is.eof ()) + { + // FIXME -- not sure this is best, but it works. - if (is.eof ()) - is.clear (); + if (is.eof ()) + is.clear (); - octave_idx_type expected = nr * nc; + octave_idx_type expected = nr * nc; - if (expected == total_count) - { - tc = tmp; - retval = varname; - } - else - error ("load: expected %d elements, found %d", - expected, total_count); - } - else - error ("load: failed to read matrix from file `%s'", - filename.c_str ()); - } + if (expected == total_count) + { + tc = tmp; + retval = varname; + } + else + error ("load: expected %d elements, found %d", + expected, total_count); + } + else + error ("load: failed to read matrix from file `%s'", + filename.c_str ()); + } else - error ("load: unable to extract matrix size from file `%s'", - filename.c_str ()); + error ("load: unable to extract matrix size from file `%s'", + filename.c_str ()); } else error ("load: unable to convert filename `%s' to valid identifier", - filename.c_str ()); + filename.c_str ()); return retval; } bool save_mat_ascii_data (std::ostream& os, const octave_value& val, - int precision, bool tabs) + int precision, bool tabs) { bool success = true; @@ -351,7 +351,7 @@ os.precision (precision); std::ios::fmtflags oflags - = os.flags (static_cast (std::ios::scientific)); + = os.flags (static_cast (std::ios::scientific)); if (tabs) { diff --git a/src/ls-mat4.cc b/src/ls-mat4.cc --- a/src/ls-mat4.cc +++ b/src/ls-mat4.cc @@ -74,8 +74,8 @@ static void read_mat_binary_data (std::istream& is, double *data, int precision, - int len, bool swap, - oct_mach_info::float_format flt_fmt) + int len, bool swap, + oct_mach_info::float_format flt_fmt) { switch (precision) { @@ -110,9 +110,9 @@ int read_mat_file_header (std::istream& is, bool& swap, int32_t& mopt, - int32_t& nr, int32_t& nc, - int32_t& imag, int32_t& len, - int quiet) + int32_t& nr, int32_t& nc, + int32_t& imag, int32_t& len, + int quiet) { swap = false; @@ -165,7 +165,7 @@ if (mopt > 9999 || mopt < 0 || imag > 1 || imag < 0) { if (! quiet) - error ("load: can't read binary file"); + error ("load: can't read binary file"); return -1; } @@ -259,7 +259,7 @@ std::string read_mat_binary_data (std::istream& is, const std::string& filename, - octave_value& tc) + octave_value& tc) { std::string retval; @@ -282,9 +282,9 @@ if (err) { if (err < 0) - goto data_read_error; + goto data_read_error; else - return retval; + return retval; } type = mopt % 10; // Full, sparse, etc. @@ -326,105 +326,105 @@ if (order) { - octave_idx_type tmp = nr; - nr = nc; - nc = tmp; + octave_idx_type tmp = nr; + nr = nc; + nc = tmp; } if (type == 2) { - if (nc == 4) - { - octave_idx_type nr_new, nc_new; - Array data (dim_vector (1, nr - 1)); - Array c (dim_vector (1, nr - 1)); - Array r (dim_vector (1, nr - 1)); - OCTAVE_LOCAL_BUFFER (double, dtmp, nr); - OCTAVE_LOCAL_BUFFER (double, ctmp, nr); + if (nc == 4) + { + octave_idx_type nr_new, nc_new; + Array data (dim_vector (1, nr - 1)); + Array c (dim_vector (1, nr - 1)); + Array r (dim_vector (1, nr - 1)); + OCTAVE_LOCAL_BUFFER (double, dtmp, nr); + OCTAVE_LOCAL_BUFFER (double, ctmp, nr); - read_mat_binary_data (is, dtmp, prec, nr, swap, flt_fmt); - for (octave_idx_type i = 0; i < nr - 1; i++) - r.xelem(i) = dtmp[i] - 1; - nr_new = dtmp[nr - 1]; - read_mat_binary_data (is, dtmp, prec, nr, swap, flt_fmt); - for (octave_idx_type i = 0; i < nr - 1; i++) - c.xelem(i) = dtmp[i] - 1; - nc_new = dtmp[nr - 1]; - read_mat_binary_data (is, dtmp, prec, nr - 1, swap, flt_fmt); - read_mat_binary_data (is, ctmp, prec, 1, swap, flt_fmt); - read_mat_binary_data (is, ctmp, prec, nr - 1, swap, flt_fmt); + read_mat_binary_data (is, dtmp, prec, nr, swap, flt_fmt); + for (octave_idx_type i = 0; i < nr - 1; i++) + r.xelem(i) = dtmp[i] - 1; + nr_new = dtmp[nr - 1]; + read_mat_binary_data (is, dtmp, prec, nr, swap, flt_fmt); + for (octave_idx_type i = 0; i < nr - 1; i++) + c.xelem(i) = dtmp[i] - 1; + nc_new = dtmp[nr - 1]; + read_mat_binary_data (is, dtmp, prec, nr - 1, swap, flt_fmt); + read_mat_binary_data (is, ctmp, prec, 1, swap, flt_fmt); + read_mat_binary_data (is, ctmp, prec, nr - 1, swap, flt_fmt); - for (octave_idx_type i = 0; i < nr - 1; i++) - data.xelem(i) = Complex (dtmp[i], ctmp[i]); - read_mat_binary_data (is, ctmp, prec, 1, swap, flt_fmt); + for (octave_idx_type i = 0; i < nr - 1; i++) + data.xelem(i) = Complex (dtmp[i], ctmp[i]); + read_mat_binary_data (is, ctmp, prec, 1, swap, flt_fmt); - SparseComplexMatrix smc = SparseComplexMatrix (data, r, c, - nr_new, nc_new); + SparseComplexMatrix smc = SparseComplexMatrix (data, r, c, + nr_new, nc_new); - tc = order ? smc.transpose () : smc; - } - else - { - octave_idx_type nr_new, nc_new; - Array data (dim_vector (1, nr - 1)); - Array c (dim_vector (1, nr - 1)); - Array r (dim_vector (1, nr - 1)); - OCTAVE_LOCAL_BUFFER (double, dtmp, nr); + tc = order ? smc.transpose () : smc; + } + else + { + octave_idx_type nr_new, nc_new; + Array data (dim_vector (1, nr - 1)); + Array c (dim_vector (1, nr - 1)); + Array r (dim_vector (1, nr - 1)); + OCTAVE_LOCAL_BUFFER (double, dtmp, nr); - read_mat_binary_data (is, dtmp, prec, nr, swap, flt_fmt); - for (octave_idx_type i = 0; i < nr - 1; i++) - r.xelem(i) = dtmp[i] - 1; - nr_new = dtmp[nr - 1]; - read_mat_binary_data (is, dtmp, prec, nr, swap, flt_fmt); - for (octave_idx_type i = 0; i < nr - 1; i++) - c.xelem(i) = dtmp[i] - 1; - nc_new = dtmp[nr - 1]; - read_mat_binary_data (is, data.fortran_vec (), prec, nr - 1, swap, flt_fmt); - read_mat_binary_data (is, dtmp, prec, 1, swap, flt_fmt); + read_mat_binary_data (is, dtmp, prec, nr, swap, flt_fmt); + for (octave_idx_type i = 0; i < nr - 1; i++) + r.xelem(i) = dtmp[i] - 1; + nr_new = dtmp[nr - 1]; + read_mat_binary_data (is, dtmp, prec, nr, swap, flt_fmt); + for (octave_idx_type i = 0; i < nr - 1; i++) + c.xelem(i) = dtmp[i] - 1; + nc_new = dtmp[nr - 1]; + read_mat_binary_data (is, data.fortran_vec (), prec, nr - 1, swap, flt_fmt); + read_mat_binary_data (is, dtmp, prec, 1, swap, flt_fmt); - SparseMatrix sm = SparseMatrix (data, r, c, nr_new, nc_new); + SparseMatrix sm = SparseMatrix (data, r, c, nr_new, nc_new); - tc = order ? sm.transpose () : sm; - } + tc = order ? sm.transpose () : sm; + } } else { - re.resize (nr, nc); + re.resize (nr, nc); - read_mat_binary_data (is, re.fortran_vec (), prec, dlen, swap, flt_fmt); + read_mat_binary_data (is, re.fortran_vec (), prec, dlen, swap, flt_fmt); - if (! is || error_state) - { - error ("load: reading matrix data for `%s'", name); - goto data_read_error; - } + if (! is || error_state) + { + error ("load: reading matrix data for `%s'", name); + goto data_read_error; + } - if (imag) - { - Matrix im (nr, nc); + if (imag) + { + Matrix im (nr, nc); - read_mat_binary_data (is, im.fortran_vec (), prec, dlen, swap, - flt_fmt); + read_mat_binary_data (is, im.fortran_vec (), prec, dlen, swap, + flt_fmt); - if (! is || error_state) - { - error ("load: reading imaginary matrix data for `%s'", name); - goto data_read_error; - } + if (! is || error_state) + { + error ("load: reading imaginary matrix data for `%s'", name); + goto data_read_error; + } - ComplexMatrix ctmp (nr, nc); + ComplexMatrix ctmp (nr, nc); - for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - ctmp (i, j) = Complex (re (i, j), im (i, j)); + for (octave_idx_type j = 0; j < nc; j++) + for (octave_idx_type i = 0; i < nr; i++) + ctmp (i, j) = Complex (re (i, j), im (i, j)); - tc = order ? ctmp.transpose () : ctmp; - } - else - tc = order ? re.transpose () : re; + tc = order ? ctmp.transpose () : ctmp; + } + else + tc = order ? re.transpose () : re; - if (type == 1) - tc = tc.convert_to_str (false, true, '\''); + if (type == 1) + tc = tc.convert_to_str (false, true, '\''); } return retval; @@ -440,7 +440,7 @@ bool save_mat_binary_data (std::ostream& os, const octave_value& tc, - const std::string& name) + const std::string& name) { int32_t mopt = 0; @@ -498,17 +498,17 @@ octave_idx_type nrow = chm.rows (); octave_idx_type ncol = chm.cols (); - + OCTAVE_LOCAL_BUFFER (double, buf, ncol*nrow); - + for (octave_idx_type i = 0; i < nrow; i++) - { - std::string tstr = chm.row_as_string (i); - const char *s = tstr.data (); - - for (octave_idx_type j = 0; j < ncol; j++) - buf[j*nrow+i] = static_cast (*s++ & 0x00FF); - } + { + std::string tstr = chm.row_as_string (i); + const char *s = tstr.data (); + + for (octave_idx_type j = 0; j < ncol; j++) + buf[j*nrow+i] = static_cast (*s++ & 0x00FF); + } os.write (reinterpret_cast (buf), nrow*ncol*sizeof(double)); } else if (tc.is_range ()) @@ -518,10 +518,10 @@ double inc = r.inc (); octave_idx_type nel = r.nelem (); for (octave_idx_type i = 0; i < nel; i++) - { - double x = base + i * inc; - os.write (reinterpret_cast (&x), 8); - } + { + double x = base + i * inc; + os.write (reinterpret_cast (&x), 8); + } } else if (tc.is_real_scalar ()) { @@ -533,56 +533,56 @@ double ds; OCTAVE_LOCAL_BUFFER (double, dtmp, len); if (tc.is_complex_matrix ()) - { - SparseComplexMatrix m = tc.sparse_complex_matrix_value (); + { + SparseComplexMatrix m = tc.sparse_complex_matrix_value (); - for (octave_idx_type i = 0; i < len; i++) - dtmp [i] = m.ridx(i) + 1; - os.write (reinterpret_cast (dtmp), 8 * len); - ds = nr; - os.write (reinterpret_cast (&ds), 8); + for (octave_idx_type i = 0; i < len; i++) + dtmp [i] = m.ridx(i) + 1; + os.write (reinterpret_cast (dtmp), 8 * len); + ds = nr; + os.write (reinterpret_cast (&ds), 8); - octave_idx_type ii = 0; - for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) - dtmp[ii++] = j + 1; - os.write (reinterpret_cast (dtmp), 8 * len); - ds = nc; - os.write (reinterpret_cast (&ds), 8); + octave_idx_type ii = 0; + for (octave_idx_type j = 0; j < nc; j++) + for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) + dtmp[ii++] = j + 1; + os.write (reinterpret_cast (dtmp), 8 * len); + ds = nc; + os.write (reinterpret_cast (&ds), 8); - for (octave_idx_type i = 0; i < len; i++) - dtmp [i] = std::real (m.data(i)); - os.write (reinterpret_cast (dtmp), 8 * len); - ds = 0.; - os.write (reinterpret_cast (&ds), 8); + for (octave_idx_type i = 0; i < len; i++) + dtmp [i] = std::real (m.data(i)); + os.write (reinterpret_cast (dtmp), 8 * len); + ds = 0.; + os.write (reinterpret_cast (&ds), 8); - for (octave_idx_type i = 0; i < len; i++) - dtmp [i] = std::imag (m.data(i)); - os.write (reinterpret_cast (dtmp), 8 * len); - os.write (reinterpret_cast (&ds), 8); - } + for (octave_idx_type i = 0; i < len; i++) + dtmp [i] = std::imag (m.data(i)); + os.write (reinterpret_cast (dtmp), 8 * len); + os.write (reinterpret_cast (&ds), 8); + } else - { - SparseMatrix m = tc.sparse_matrix_value (); + { + SparseMatrix m = tc.sparse_matrix_value (); - for (octave_idx_type i = 0; i < len; i++) - dtmp [i] = m.ridx(i) + 1; - os.write (reinterpret_cast (dtmp), 8 * len); - ds = nr; - os.write (reinterpret_cast (&ds), 8); + for (octave_idx_type i = 0; i < len; i++) + dtmp [i] = m.ridx(i) + 1; + os.write (reinterpret_cast (dtmp), 8 * len); + ds = nr; + os.write (reinterpret_cast (&ds), 8); - octave_idx_type ii = 0; - for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) - dtmp[ii++] = j + 1; - os.write (reinterpret_cast (dtmp), 8 * len); - ds = nc; - os.write (reinterpret_cast (&ds), 8); + octave_idx_type ii = 0; + for (octave_idx_type j = 0; j < nc; j++) + for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) + dtmp[ii++] = j + 1; + os.write (reinterpret_cast (dtmp), 8 * len); + ds = nc; + os.write (reinterpret_cast (&ds), 8); - os.write (reinterpret_cast (m.data ()), 8 * len); - ds = 0.; - os.write (reinterpret_cast (&ds), 8); - } + os.write (reinterpret_cast (m.data ()), 8 * len); + ds = 0.; + os.write (reinterpret_cast (&ds), 8); + } } else if (tc.is_real_matrix ()) { diff --git a/src/ls-mat5.cc b/src/ls-mat5.cc --- a/src/ls-mat5.cc +++ b/src/ls-mat5.cc @@ -97,23 +97,23 @@ enum arrayclasstype { - MAT_FILE_CELL_CLASS=1, // cell array - MAT_FILE_STRUCT_CLASS, // structure - MAT_FILE_OBJECT_CLASS, // object - MAT_FILE_CHAR_CLASS, // character array - MAT_FILE_SPARSE_CLASS, // sparse array - MAT_FILE_DOUBLE_CLASS, // double precision array - MAT_FILE_SINGLE_CLASS, // single precision floating point - MAT_FILE_INT8_CLASS, // 8 bit signed integer - MAT_FILE_UINT8_CLASS, // 8 bit unsigned integer - MAT_FILE_INT16_CLASS, // 16 bit signed integer - MAT_FILE_UINT16_CLASS, // 16 bit unsigned integer - MAT_FILE_INT32_CLASS, // 32 bit signed integer - MAT_FILE_UINT32_CLASS, // 32 bit unsigned integer - MAT_FILE_INT64_CLASS, // 64 bit signed integer - MAT_FILE_UINT64_CLASS, // 64 bit unsigned integer + MAT_FILE_CELL_CLASS=1, // cell array + MAT_FILE_STRUCT_CLASS, // structure + MAT_FILE_OBJECT_CLASS, // object + MAT_FILE_CHAR_CLASS, // character array + MAT_FILE_SPARSE_CLASS, // sparse array + MAT_FILE_DOUBLE_CLASS, // double precision array + MAT_FILE_SINGLE_CLASS, // single precision floating point + MAT_FILE_INT8_CLASS, // 8 bit signed integer + MAT_FILE_UINT8_CLASS, // 8 bit unsigned integer + MAT_FILE_INT16_CLASS, // 16 bit signed integer + MAT_FILE_UINT16_CLASS, // 16 bit unsigned integer + MAT_FILE_INT32_CLASS, // 32 bit signed integer + MAT_FILE_UINT32_CLASS, // 32 bit unsigned integer + MAT_FILE_INT64_CLASS, // 64 bit signed integer + MAT_FILE_UINT64_CLASS, // 64 bit unsigned integer MAT_FILE_FUNCTION_CLASS, // Function handle - MAT_FILE_WORKSPACE_CLASS // Workspace (undocumented) + MAT_FILE_WORKSPACE_CLASS // Workspace (undocumented) }; // Read COUNT elements of data from IS in the format specified by TYPE, @@ -123,8 +123,8 @@ static void read_mat5_binary_data (std::istream& is, double *data, - int count, bool swap, mat5_data_type type, - oct_mach_info::float_format flt_fmt) + int count, bool swap, mat5_data_type type, + oct_mach_info::float_format flt_fmt) { switch (type) @@ -189,21 +189,21 @@ template void read_mat5_integer_data (std::istream& is, T *m, int count, bool swap, - mat5_data_type type) + mat5_data_type type) { -#define READ_INTEGER_DATA(TYPE, swap, data, size, len, stream) \ +#define READ_INTEGER_DATA(TYPE, swap, data, size, len, stream) \ do \ { \ if (len > 0) \ - { \ - OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \ - stream.read (reinterpret_cast (ptr), size * len); \ - if (swap) \ - swap_bytes< size > (ptr, len); \ - for (int i = 0; i < len; i++) \ - data[i] = ptr[i]; \ - } \ + { \ + OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \ + stream.read (reinterpret_cast (ptr), size * len); \ + if (swap) \ + swap_bytes< size > (ptr, len); \ + for (int i = 0; i < len; i++) \ + data[i] = ptr[i]; \ + } \ } \ while (0) @@ -258,91 +258,91 @@ } template void read_mat5_integer_data (std::istream& is, octave_int8 *m, - int count, bool swap, - mat5_data_type type); + int count, bool swap, + mat5_data_type type); template void read_mat5_integer_data (std::istream& is, octave_int16 *m, - int count, bool swap, - mat5_data_type type); + int count, bool swap, + mat5_data_type type); template void read_mat5_integer_data (std::istream& is, octave_int32 *m, - int count, bool swap, - mat5_data_type type); + int count, bool swap, + mat5_data_type type); template void read_mat5_integer_data (std::istream& is, octave_int64 *m, - int count, bool swap, - mat5_data_type type); + int count, bool swap, + mat5_data_type type); template void read_mat5_integer_data (std::istream& is, octave_uint8 *m, - int count, bool swap, - mat5_data_type type); + int count, bool swap, + mat5_data_type type); template void read_mat5_integer_data (std::istream& is, octave_uint16 *m, - int count, bool swap, - mat5_data_type type); + int count, bool swap, + mat5_data_type type); template void read_mat5_integer_data (std::istream& is, octave_uint32 *m, - int count, bool swap, - mat5_data_type type); + int count, bool swap, + mat5_data_type type); template void read_mat5_integer_data (std::istream& is, octave_uint64 *m, - int count, bool swap, - mat5_data_type type); + int count, bool swap, + mat5_data_type type); template void read_mat5_integer_data (std::istream& is, int *m, - int count, bool swap, - mat5_data_type type); + int count, bool swap, + mat5_data_type type); #define OCTAVE_MAT5_INTEGER_READ(TYP) \ { \ - TYP re (dims); \ + TYP re (dims); \ \ - std::streampos tmp_pos; \ + std::streampos tmp_pos; \ \ - if (read_mat5_tag (is, swap, type, len)) \ - { \ - error ("load: reading matrix data for `%s'", retval.c_str ()); \ - goto data_read_error; \ - } \ + if (read_mat5_tag (is, swap, type, len)) \ + { \ + error ("load: reading matrix data for `%s'", retval.c_str ()); \ + goto data_read_error; \ + } \ \ - int n = re.length (); \ - tmp_pos = is.tellg (); \ - read_mat5_integer_data (is, re.fortran_vec (), n, swap, \ - static_cast (type)); \ + int n = re.length (); \ + tmp_pos = is.tellg (); \ + read_mat5_integer_data (is, re.fortran_vec (), n, swap, \ + static_cast (type)); \ \ - if (! is || error_state) \ - { \ - error ("load: reading matrix data for `%s'", retval.c_str ()); \ - goto data_read_error; \ - } \ + if (! is || error_state) \ + { \ + error ("load: reading matrix data for `%s'", retval.c_str ()); \ + goto data_read_error; \ + } \ \ - is.seekg (tmp_pos + static_cast (PAD (len))); \ + is.seekg (tmp_pos + static_cast (PAD (len))); \ \ - if (imag) \ - { \ - /* We don't handle imag integer types, convert to an array */ \ - NDArray im (dims); \ + if (imag) \ + { \ + /* We don't handle imag integer types, convert to an array */ \ + NDArray im (dims); \ \ - if (read_mat5_tag (is, swap, type, len)) \ - { \ - error ("load: reading matrix data for `%s'", \ - retval.c_str ()); \ - goto data_read_error; \ - } \ + if (read_mat5_tag (is, swap, type, len)) \ + { \ + error ("load: reading matrix data for `%s'", \ + retval.c_str ()); \ + goto data_read_error; \ + } \ \ - n = im.length (); \ - read_mat5_binary_data (is, im.fortran_vec (), n, swap, \ - static_cast (type), flt_fmt); \ + n = im.length (); \ + read_mat5_binary_data (is, im.fortran_vec (), n, swap, \ + static_cast (type), flt_fmt); \ \ - if (! is || error_state) \ - { \ - error ("load: reading imaginary matrix data for `%s'", \ - retval.c_str ()); \ - goto data_read_error; \ - } \ + if (! is || error_state) \ + { \ + error ("load: reading imaginary matrix data for `%s'", \ + retval.c_str ()); \ + goto data_read_error; \ + } \ \ - ComplexNDArray ctmp (dims); \ + ComplexNDArray ctmp (dims); \ \ - for (int i = 0; i < n; i++) \ - ctmp(i) = Complex (re(i).double_value (), im(i)); \ + for (int i = 0; i < n; i++) \ + ctmp(i) = Complex (re(i).double_value (), im(i)); \ \ tc = ctmp; \ - } \ - else \ - tc = re; \ + } \ + else \ + tc = re; \ } // Read one element tag from stream IS, @@ -371,9 +371,9 @@ else { if (! is.read (reinterpret_cast (&temp), 4 )) - goto data_read_error; + goto data_read_error; if (swap) - swap_bytes<4> (&temp); + swap_bytes<4> (&temp); bytes = temp; } @@ -402,7 +402,7 @@ std::string read_mat5_binary_element (std::istream& is, const std::string& filename, - bool swap, bool& global, octave_value& tc) + bool swap, bool& global, octave_value& tc) { std::string retval; @@ -436,7 +436,7 @@ // element type and length if (read_mat5_tag (is, swap, type, element_length)) - return retval; // EOF + return retval; // EOF #ifdef HAVE_ZLIB if (type == miCOMPRESSED) @@ -453,32 +453,32 @@ uLongf destLen = 8; OCTAVE_LOCAL_BUFFER (unsigned int, tmp, 2); if (uncompress (reinterpret_cast (tmp), &destLen, - reinterpret_cast (inbuf), element_length) - != Z_MEM_ERROR) - { - // Why should I have to initialize outbuf as I'll just overwrite!! - if (swap) - swap_bytes<4> (tmp, 2); + reinterpret_cast (inbuf), element_length) + != Z_MEM_ERROR) + { + // Why should I have to initialize outbuf as I'll just overwrite!! + if (swap) + swap_bytes<4> (tmp, 2); - destLen = tmp[1] + 8; - std::string outbuf (destLen, ' '); + destLen = tmp[1] + 8; + std::string outbuf (destLen, ' '); - // FIXME -- find a way to avoid casting away const here! + // FIXME -- find a way to avoid casting away const here! - int err = uncompress (reinterpret_cast (const_cast (outbuf.c_str ())), &destLen, - reinterpret_cast (inbuf), element_length); + int err = uncompress (reinterpret_cast (const_cast (outbuf.c_str ())), &destLen, + reinterpret_cast (inbuf), element_length); - if (err != Z_OK) - error ("load: error uncompressing data element"); - else - { - std::istringstream gz_is (outbuf); - retval = read_mat5_binary_element (gz_is, filename, - swap, global, tc); - } - } + if (err != Z_OK) + error ("load: error uncompressing data element"); + else + { + std::istringstream gz_is (outbuf); + retval = read_mat5_binary_element (gz_is, filename, + swap, global, tc); + } + } else - error ("load: error probing size of compressed data element"); + error ("load: error probing size of compressed data element"); return retval; } @@ -507,11 +507,11 @@ } read_int (is, swap, flags); - imag = (flags & 0x0800) != 0; // has an imaginary part? + imag = (flags & 0x0800) != 0; // has an imaginary part? global = (flags & 0x0400) != 0; // global variable? logicalvar = (flags & 0x0200) != 0; // boolean ? arrayclass = static_cast (flags & 0xff); - read_int (is, swap, nzmax); // max number of non-zero in sparse + read_int (is, swap, nzmax); // max number of non-zero in sparse // dimensions array subelement if (arrayclass != MAT_FILE_WORKSPACE_CLASS) @@ -519,19 +519,19 @@ int32_t dim_len; if (read_mat5_tag (is, swap, type, dim_len) || type != miINT32) - { - error ("load: invalid dimensions array subelement"); - goto early_read_error; - } + { + error ("load: invalid dimensions array subelement"); + goto early_read_error; + } int ndims = dim_len / 4; dims.resize (ndims); for (int i = 0; i < ndims; i++) - { - int32_t n; - read_int (is, swap, n); - dims(i) = n; - } + { + int32_t n; + read_int (is, swap, n); + dims(i) = n; + } std::streampos tmp_pos = is.tellg (); is.seekg (tmp_pos + static_cast (PAD (dim_len) - dim_len)); @@ -559,10 +559,10 @@ if (len) { - if (! is.read (name, len )) - goto data_read_error; - - is.seekg (tmp_pos + static_cast (PAD (len))); + if (! is.read (name, len )) + goto data_read_error; + + is.seekg (tmp_pos + static_cast (PAD (len))); } name[len] = '\0'; @@ -573,27 +573,27 @@ { case MAT_FILE_CELL_CLASS: { - Cell cell_array (dims); + Cell cell_array (dims); - int n = cell_array.length (); + int n = cell_array.length (); - for (int i = 0; i < n; i++) - { - octave_value tc2; + for (int i = 0; i < n; i++) + { + octave_value tc2; - std::string nm - = read_mat5_binary_element (is, filename, swap, global, tc2); + std::string nm + = read_mat5_binary_element (is, filename, swap, global, tc2); - if (! is || error_state) - { - error ("load: reading cell data for `%s'", nm.c_str ()); - goto data_read_error; - } + if (! is || error_state) + { + error ("load: reading cell data for `%s'", nm.c_str ()); + goto data_read_error; + } - cell_array(i) = tc2; - } + cell_array(i) = tc2; + } - tc = cell_array; + tc = cell_array; } break; @@ -603,529 +603,529 @@ goto skip_ahead; #else { - int nr = dims(0); - int nc = dims(1); - SparseMatrix sm; - SparseComplexMatrix scm; - int *ridx; - int *cidx; - double *data; + int nr = dims(0); + int nc = dims(1); + SparseMatrix sm; + SparseComplexMatrix scm; + int *ridx; + int *cidx; + double *data; - // Setup return value - if (imag) - { - scm = SparseComplexMatrix (static_cast (nr), - static_cast (nc), - static_cast (nzmax)); - ridx = scm.ridx (); - cidx = scm.cidx (); - data = 0; - } - else - { - sm = SparseMatrix (static_cast (nr), - static_cast (nc), - static_cast (nzmax)); - ridx = sm.ridx (); - cidx = sm.cidx (); - data = sm.data (); - } + // Setup return value + if (imag) + { + scm = SparseComplexMatrix (static_cast (nr), + static_cast (nc), + static_cast (nzmax)); + ridx = scm.ridx (); + cidx = scm.cidx (); + data = 0; + } + else + { + sm = SparseMatrix (static_cast (nr), + static_cast (nc), + static_cast (nzmax)); + ridx = sm.ridx (); + cidx = sm.cidx (); + data = sm.data (); + } - // row indices - std::streampos tmp_pos; - - if (read_mat5_tag (is, swap, type, len)) - { - error ("load: reading sparse row data for `%s'", retval.c_str ()); - goto data_read_error; - } + // row indices + std::streampos tmp_pos; + + if (read_mat5_tag (is, swap, type, len)) + { + error ("load: reading sparse row data for `%s'", retval.c_str ()); + goto data_read_error; + } - tmp_pos = is.tellg (); + tmp_pos = is.tellg (); - read_mat5_integer_data (is, ridx, nzmax, swap, - static_cast (type)); + read_mat5_integer_data (is, ridx, nzmax, swap, + static_cast (type)); - if (! is || error_state) - { - error ("load: reading sparse row data for `%s'", retval.c_str ()); - goto data_read_error; - } + if (! is || error_state) + { + error ("load: reading sparse row data for `%s'", retval.c_str ()); + goto data_read_error; + } - is.seekg (tmp_pos + static_cast (PAD (len))); + is.seekg (tmp_pos + static_cast (PAD (len))); - // col indices - if (read_mat5_tag (is, swap, type, len)) - { - error ("load: reading sparse column data for `%s'", retval.c_str ()); - goto data_read_error; - } + // col indices + if (read_mat5_tag (is, swap, type, len)) + { + error ("load: reading sparse column data for `%s'", retval.c_str ()); + goto data_read_error; + } - tmp_pos = is.tellg (); + tmp_pos = is.tellg (); - read_mat5_integer_data (is, cidx, nc + 1, swap, - static_cast (type)); + read_mat5_integer_data (is, cidx, nc + 1, swap, + static_cast (type)); - if (! is || error_state) - { - error ("load: reading sparse column data for `%s'", retval.c_str ()); - goto data_read_error; - } + if (! is || error_state) + { + error ("load: reading sparse column data for `%s'", retval.c_str ()); + goto data_read_error; + } - is.seekg (tmp_pos + static_cast (PAD (len))); + is.seekg (tmp_pos + static_cast (PAD (len))); - // real data subelement - if (read_mat5_tag (is, swap, type, len)) - { - error ("load: reading sparse matrix data for `%s'", retval.c_str ()); - goto data_read_error; - } + // real data subelement + if (read_mat5_tag (is, swap, type, len)) + { + error ("load: reading sparse matrix data for `%s'", retval.c_str ()); + goto data_read_error; + } - int32_t nnz = cidx[nc]; - NDArray re; - if (imag) - { - re = NDArray (dim_vector (static_cast (nnz))); - data = re.fortran_vec (); - } + int32_t nnz = cidx[nc]; + NDArray re; + if (imag) + { + re = NDArray (dim_vector (static_cast (nnz))); + data = re.fortran_vec (); + } - tmp_pos = is.tellg (); - read_mat5_binary_data (is, data, nnz, swap, - static_cast (type), flt_fmt); + tmp_pos = is.tellg (); + read_mat5_binary_data (is, data, nnz, swap, + static_cast (type), flt_fmt); - if (! is || error_state) - { - error ("load: reading sparse matrix data for `%s'", retval.c_str ()); - goto data_read_error; - } + if (! is || error_state) + { + error ("load: reading sparse matrix data for `%s'", retval.c_str ()); + goto data_read_error; + } - is.seekg (tmp_pos + static_cast (PAD (len))); + is.seekg (tmp_pos + static_cast (PAD (len))); - // imaginary data subelement - if (imag) - { - NDArray im (dim_vector (static_cast (nnz))); - - if (read_mat5_tag (is, swap, type, len)) - { - error ("load: reading sparse matrix data for `%s'", retval.c_str ()); - goto data_read_error; - } + // imaginary data subelement + if (imag) + { + NDArray im (dim_vector (static_cast (nnz))); + + if (read_mat5_tag (is, swap, type, len)) + { + error ("load: reading sparse matrix data for `%s'", retval.c_str ()); + goto data_read_error; + } - read_mat5_binary_data (is, im.fortran_vec (), nnz, swap, - static_cast (type), flt_fmt); + read_mat5_binary_data (is, im.fortran_vec (), nnz, swap, + static_cast (type), flt_fmt); - if (! is || error_state) - { - error ("load: reading imaginary sparse matrix data for `%s'", - retval.c_str ()); - goto data_read_error; - } + if (! is || error_state) + { + error ("load: reading imaginary sparse matrix data for `%s'", + retval.c_str ()); + goto data_read_error; + } - for (int i = 0; i < nnz; i++) - scm.xdata (i) = Complex (re (i), im (i)); + for (int i = 0; i < nnz; i++) + scm.xdata (i) = Complex (re (i), im (i)); - tc = scm; - } - else - tc = sm; + tc = scm; + } + else + tc = sm; } #endif break; case MAT_FILE_FUNCTION_CLASS: { - octave_value tc2; - std::string nm - = read_mat5_binary_element (is, filename, swap, global, tc2); + octave_value tc2; + std::string nm + = read_mat5_binary_element (is, filename, swap, global, tc2); - if (! is || error_state) - goto data_read_error; + if (! is || error_state) + goto data_read_error; - // Octave can handle both "/" and "\" as a directry seperator - // and so can ignore the seperator field of m0. I think the - // sentinel field is also save to ignore. - Octave_map m0 = tc2.map_value(); - Octave_map m1 = m0.contents("function_handle")(0).map_value(); - std::string ftype = m1.contents("type")(0).string_value(); - std::string fname = m1.contents("function")(0).string_value(); - std::string fpath = m1.contents("file")(0).string_value(); + // Octave can handle both "/" and "\" as a directry seperator + // and so can ignore the seperator field of m0. I think the + // sentinel field is also save to ignore. + Octave_map m0 = tc2.map_value(); + Octave_map m1 = m0.contents("function_handle")(0).map_value(); + std::string ftype = m1.contents("type")(0).string_value(); + std::string fname = m1.contents("function")(0).string_value(); + std::string fpath = m1.contents("file")(0).string_value(); - if (ftype == "simple" || ftype == "scopedfunction") - { - if (fpath.length() == 0) - // We have a builtin function - tc = make_fcn_handle (fname); - else - { - std::string mroot = - m0.contents("matlabroot")(0).string_value(); + if (ftype == "simple" || ftype == "scopedfunction") + { + if (fpath.length() == 0) + // We have a builtin function + tc = make_fcn_handle (fname); + else + { + std::string mroot = + m0.contents("matlabroot")(0).string_value(); - if ((fpath.length () >= mroot.length ()) && - fpath.substr(0, mroot.length()) == mroot && - OCTAVE_EXEC_PREFIX != mroot) - { - // If fpath starts with matlabroot, and matlabroot - // doesn't equal octave_config_info ("exec_prefix") - // then the function points to a version of Octave - // or Matlab other than the running version. In that - // case we replace with the same function in the - // running version of Octave? - - // First check if just replacing matlabroot is enough - std::string str = OCTAVE_EXEC_PREFIX + - fpath.substr (mroot.length ()); - file_stat fs (str); + if ((fpath.length () >= mroot.length ()) && + fpath.substr(0, mroot.length()) == mroot && + OCTAVE_EXEC_PREFIX != mroot) + { + // If fpath starts with matlabroot, and matlabroot + // doesn't equal octave_config_info ("exec_prefix") + // then the function points to a version of Octave + // or Matlab other than the running version. In that + // case we replace with the same function in the + // running version of Octave? + + // First check if just replacing matlabroot is enough + std::string str = OCTAVE_EXEC_PREFIX + + fpath.substr (mroot.length ()); + file_stat fs (str); - if (fs.exists ()) - { - size_t xpos - = str.find_last_of (file_ops::dir_sep_chars ()); + if (fs.exists ()) + { + size_t xpos + = str.find_last_of (file_ops::dir_sep_chars ()); - std::string dir_name = str.substr (0, xpos); + std::string dir_name = str.substr (0, xpos); - octave_function *fcn - = load_fcn_from_file (str, dir_name, "", fname); - - if (fcn) - { - octave_value tmp (fcn); + octave_function *fcn + = load_fcn_from_file (str, dir_name, "", fname); + + if (fcn) + { + octave_value tmp (fcn); - tc = octave_value (new octave_fcn_handle (tmp, fname)); - } - } - else - { - // Next just search for it anywhere in the - // system path - string_vector names(3); - names(0) = fname + ".oct"; - names(1) = fname + ".mex"; - names(2) = fname + ".m"; + tc = octave_value (new octave_fcn_handle (tmp, fname)); + } + } + else + { + // Next just search for it anywhere in the + // system path + string_vector names(3); + names(0) = fname + ".oct"; + names(1) = fname + ".mex"; + names(2) = fname + ".m"; - dir_path p (load_path::system_path ()); + dir_path p (load_path::system_path ()); - str = octave_env::make_absolute (p.find_first_of (names)); + str = octave_env::make_absolute (p.find_first_of (names)); - size_t xpos - = str.find_last_of (file_ops::dir_sep_chars ()); + size_t xpos + = str.find_last_of (file_ops::dir_sep_chars ()); - std::string dir_name = str.substr (0, xpos); + std::string dir_name = str.substr (0, xpos); - octave_function *fcn - = load_fcn_from_file (str, dir_name, "", fname); + octave_function *fcn + = load_fcn_from_file (str, dir_name, "", fname); - if (fcn) - { - octave_value tmp (fcn); + if (fcn) + { + octave_value tmp (fcn); - tc = octave_value (new octave_fcn_handle (tmp, fname)); - } - else - { - warning ("load: can't find the file %s", - fpath.c_str()); - goto skip_ahead; - } - } - } - else - { - size_t xpos - = fpath.find_last_of (file_ops::dir_sep_chars ()); + tc = octave_value (new octave_fcn_handle (tmp, fname)); + } + else + { + warning ("load: can't find the file %s", + fpath.c_str()); + goto skip_ahead; + } + } + } + else + { + size_t xpos + = fpath.find_last_of (file_ops::dir_sep_chars ()); - std::string dir_name = fpath.substr (0, xpos); + std::string dir_name = fpath.substr (0, xpos); - octave_function *fcn - = load_fcn_from_file (fpath, dir_name, "", fname); + octave_function *fcn + = load_fcn_from_file (fpath, dir_name, "", fname); - if (fcn) - { - octave_value tmp (fcn); + if (fcn) + { + octave_value tmp (fcn); - tc = octave_value (new octave_fcn_handle (tmp, fname)); - } - else - { - warning ("load: can't find the file %s", - fpath.c_str()); - goto skip_ahead; - } - } - } - } - else if (ftype == "nested") - { - warning ("load: can't load nested function"); - goto skip_ahead; - } - else if (ftype == "anonymous") - { - Octave_map m2 = m1.contents("workspace")(0).map_value(); - uint32NDArray MCOS = m2.contents("MCOS")(0).uint32_array_value(); - octave_idx_type off = static_cast(MCOS(4).double_value ()); - m2 = subsys_ov.map_value(); - m2 = m2.contents("MCOS")(0).map_value(); - tc2 = m2.contents("MCOS")(0).cell_value()(1 + off).cell_value()(1); - m2 = tc2.map_value(); + tc = octave_value (new octave_fcn_handle (tmp, fname)); + } + else + { + warning ("load: can't find the file %s", + fpath.c_str()); + goto skip_ahead; + } + } + } + } + else if (ftype == "nested") + { + warning ("load: can't load nested function"); + goto skip_ahead; + } + else if (ftype == "anonymous") + { + Octave_map m2 = m1.contents("workspace")(0).map_value(); + uint32NDArray MCOS = m2.contents("MCOS")(0).uint32_array_value(); + octave_idx_type off = static_cast(MCOS(4).double_value ()); + m2 = subsys_ov.map_value(); + m2 = m2.contents("MCOS")(0).map_value(); + tc2 = m2.contents("MCOS")(0).cell_value()(1 + off).cell_value()(1); + m2 = tc2.map_value(); - unwind_protect_safe frame; + unwind_protect_safe frame; - // Set up temporary scope to use for evaluating the text - // that defines the anonymous function. + // Set up temporary scope to use for evaluating the text + // that defines the anonymous function. - symbol_table::scope_id local_scope = symbol_table::alloc_scope (); - frame.add_fcn (symbol_table::erase_scope, local_scope); + symbol_table::scope_id local_scope = symbol_table::alloc_scope (); + frame.add_fcn (symbol_table::erase_scope, local_scope); - symbol_table::set_scope (local_scope); + symbol_table::set_scope (local_scope); - octave_call_stack::push (local_scope, 0); - frame.add_fcn (octave_call_stack::pop); + octave_call_stack::push (local_scope, 0); + frame.add_fcn (octave_call_stack::pop); - if (m2.nfields() > 0) - { - octave_value tmp; + if (m2.nfields() > 0) + { + octave_value tmp; - for (Octave_map::iterator p0 = m2.begin() ; - p0 != m2.end(); p0++) - { - std::string key = m2.key(p0); - octave_value val = m2.contents(p0)(0); + for (Octave_map::iterator p0 = m2.begin() ; + p0 != m2.end(); p0++) + { + std::string key = m2.key(p0); + octave_value val = m2.contents(p0)(0); - symbol_table::varref (key, local_scope, 0) = val; + symbol_table::varref (key, local_scope, 0) = val; } - } - - int parse_status; - octave_value anon_fcn_handle = - eval_string (fname.substr (4), true, parse_status); + } + + int parse_status; + octave_value anon_fcn_handle = + eval_string (fname.substr (4), true, parse_status); - if (parse_status == 0) - { - octave_fcn_handle *fh = - anon_fcn_handle.fcn_handle_value (); + if (parse_status == 0) + { + octave_fcn_handle *fh = + anon_fcn_handle.fcn_handle_value (); - if (fh) - tc = new octave_fcn_handle (fh->fcn_val (), "@"); - else - { - error ("load: failed to load anonymous function handle"); - goto skip_ahead; - } - } - else - { - error ("load: failed to load anonymous function handle"); - goto skip_ahead; - } + if (fh) + tc = new octave_fcn_handle (fh->fcn_val (), "@"); + else + { + error ("load: failed to load anonymous function handle"); + goto skip_ahead; + } + } + else + { + error ("load: failed to load anonymous function handle"); + goto skip_ahead; + } - frame.run (); - } - else - { - error ("load: invalid function handle type"); - goto skip_ahead; - } + frame.run (); + } + else + { + error ("load: invalid function handle type"); + goto skip_ahead; + } } break; case MAT_FILE_WORKSPACE_CLASS: { - Octave_map m (dim_vector (1, 1)); - int n_fields = 2; - string_vector field (n_fields); + Octave_map m (dim_vector (1, 1)); + int n_fields = 2; + string_vector field (n_fields); - for (int i = 0; i < n_fields; i++) - { - int32_t fn_type; - int32_t fn_len; - if (read_mat5_tag (is, swap, fn_type, fn_len) || fn_type != miINT8) - { - error ("load: invalid field name subelement"); - goto data_read_error; - } + for (int i = 0; i < n_fields; i++) + { + int32_t fn_type; + int32_t fn_len; + if (read_mat5_tag (is, swap, fn_type, fn_len) || fn_type != miINT8) + { + error ("load: invalid field name subelement"); + goto data_read_error; + } - OCTAVE_LOCAL_BUFFER (char, elname, fn_len + 1); + OCTAVE_LOCAL_BUFFER (char, elname, fn_len + 1); - std::streampos tmp_pos = is.tellg (); + std::streampos tmp_pos = is.tellg (); - if (fn_len) - { - if (! is.read (elname, fn_len)) - goto data_read_error; + if (fn_len) + { + if (! is.read (elname, fn_len)) + goto data_read_error; - is.seekg (tmp_pos + - static_cast (PAD (fn_len))); - } + is.seekg (tmp_pos + + static_cast (PAD (fn_len))); + } - elname[fn_len] = '\0'; + elname[fn_len] = '\0'; - field(i) = elname; - } + field(i) = elname; + } - std::vector elt (n_fields); + std::vector elt (n_fields); - for (octave_idx_type i = 0; i < n_fields; i++) - elt[i] = Cell (dims); + for (octave_idx_type i = 0; i < n_fields; i++) + elt[i] = Cell (dims); - octave_idx_type n = dims.numel (); + octave_idx_type n = dims.numel (); - // fields subelements - for (octave_idx_type j = 0; j < n; j++) - { - for (octave_idx_type i = 0; i < n_fields; i++) - { - if (field(i) == "MCOS") - { - octave_value fieldtc; - read_mat5_binary_element (is, filename, swap, global, - fieldtc); - if (! is || error_state) - goto data_read_error; + // fields subelements + for (octave_idx_type j = 0; j < n; j++) + { + for (octave_idx_type i = 0; i < n_fields; i++) + { + if (field(i) == "MCOS") + { + octave_value fieldtc; + read_mat5_binary_element (is, filename, swap, global, + fieldtc); + if (! is || error_state) + goto data_read_error; - elt[i](j) = fieldtc; - } - else - elt[i](j) = octave_value (); - } - } + elt[i](j) = fieldtc; + } + else + elt[i](j) = octave_value (); + } + } - for (octave_idx_type i = 0; i < n_fields; i++) - m.assign (field (i), elt[i]); - tc = m; + for (octave_idx_type i = 0; i < n_fields; i++) + m.assign (field (i), elt[i]); + tc = m; } break; case MAT_FILE_OBJECT_CLASS: { - isclass = true; + isclass = true; - if (read_mat5_tag (is, swap, type, len) || type != miINT8) - { - error ("load: invalid class name"); - goto skip_ahead; - } + if (read_mat5_tag (is, swap, type, len) || type != miINT8) + { + error ("load: invalid class name"); + goto skip_ahead; + } - { - OCTAVE_LOCAL_BUFFER (char, name, len+1); + { + OCTAVE_LOCAL_BUFFER (char, name, len+1); - std::streampos tmp_pos = is.tellg (); + std::streampos tmp_pos = is.tellg (); - if (len) - { - if (! is.read (name, len )) - goto data_read_error; - - is.seekg (tmp_pos + static_cast (PAD (len))); - } + if (len) + { + if (! is.read (name, len )) + goto data_read_error; + + is.seekg (tmp_pos + static_cast (PAD (len))); + } - name[len] = '\0'; - classname = name; - } + name[len] = '\0'; + classname = name; + } } // Fall-through case MAT_FILE_STRUCT_CLASS: { - Octave_map m (dim_vector (1, 1)); - int32_t fn_type; - int32_t fn_len; - int32_t field_name_length; + Octave_map m (dim_vector (1, 1)); + int32_t fn_type; + int32_t fn_len; + int32_t field_name_length; - // field name length subelement -- actually the maximum length - // of a field name. The Matlab docs promise this will always - // be 32. We read and use the actual value, on the theory - // that eventually someone will recognize that's a waste of - // space. - if (read_mat5_tag (is, swap, fn_type, fn_len) || fn_type != miINT32) - { - error ("load: invalid field name length subelement"); - goto data_read_error; - } + // field name length subelement -- actually the maximum length + // of a field name. The Matlab docs promise this will always + // be 32. We read and use the actual value, on the theory + // that eventually someone will recognize that's a waste of + // space. + if (read_mat5_tag (is, swap, fn_type, fn_len) || fn_type != miINT32) + { + error ("load: invalid field name length subelement"); + goto data_read_error; + } - if (! is.read (reinterpret_cast (&field_name_length), fn_len )) - goto data_read_error; + if (! is.read (reinterpret_cast (&field_name_length), fn_len )) + goto data_read_error; - if (swap) - swap_bytes<4> (&field_name_length); + if (swap) + swap_bytes<4> (&field_name_length); - // field name subelement. The length of this subelement tells - // us how many fields there are. - if (read_mat5_tag (is, swap, fn_type, fn_len) || fn_type != miINT8) - { - error ("load: invalid field name subelement"); - goto data_read_error; - } + // field name subelement. The length of this subelement tells + // us how many fields there are. + if (read_mat5_tag (is, swap, fn_type, fn_len) || fn_type != miINT8) + { + error ("load: invalid field name subelement"); + goto data_read_error; + } - octave_idx_type n_fields = fn_len/field_name_length; + octave_idx_type n_fields = fn_len/field_name_length; - if (n_fields > 0) - { - fn_len = PAD (fn_len); + if (n_fields > 0) + { + fn_len = PAD (fn_len); - OCTAVE_LOCAL_BUFFER (char, elname, fn_len); + OCTAVE_LOCAL_BUFFER (char, elname, fn_len); - if (! is.read (elname, fn_len)) - goto data_read_error; + if (! is.read (elname, fn_len)) + goto data_read_error; - std::vector elt (n_fields); + std::vector elt (n_fields); - for (octave_idx_type i = 0; i < n_fields; i++) - elt[i] = Cell (dims); + for (octave_idx_type i = 0; i < n_fields; i++) + elt[i] = Cell (dims); - octave_idx_type n = dims.numel (); + octave_idx_type n = dims.numel (); - // fields subelements - for (octave_idx_type j = 0; j < n; j++) - { - for (octave_idx_type i = 0; i < n_fields; i++) - { - octave_value fieldtc; - read_mat5_binary_element (is, filename, swap, global, - fieldtc); - elt[i](j) = fieldtc; - } - } + // fields subelements + for (octave_idx_type j = 0; j < n; j++) + { + for (octave_idx_type i = 0; i < n_fields; i++) + { + octave_value fieldtc; + read_mat5_binary_element (is, filename, swap, global, + fieldtc); + elt[i](j) = fieldtc; + } + } - for (octave_idx_type i = 0; i < n_fields; i++) - { - const char *key = elname + i*field_name_length; + for (octave_idx_type i = 0; i < n_fields; i++) + { + const char *key = elname + i*field_name_length; - m.assign (key, elt[i]); - } - } + m.assign (key, elt[i]); + } + } - if (isclass) - { - if (classname == "inline") - { - // inline is not an object in Octave but rather an - // overload of a function handle. Special case. - tc = - new octave_fcn_inline (m.contents("expr")(0).string_value(), - m.contents("args")(0).string_value()); - } - else - { - octave_class* cls = new octave_class (m, classname); - cls->reconstruct_exemplar (); + if (isclass) + { + if (classname == "inline") + { + // inline is not an object in Octave but rather an + // overload of a function handle. Special case. + tc = + new octave_fcn_inline (m.contents("expr")(0).string_value(), + m.contents("args")(0).string_value()); + } + else + { + octave_class* cls = new octave_class (m, classname); + cls->reconstruct_exemplar (); - if (! cls->reconstruct_parents ()) - warning ("load: unable to reconstruct object inheritance"); + if (! cls->reconstruct_parents ()) + warning ("load: unable to reconstruct object inheritance"); - tc = cls; - if (load_path::find_method (classname, "loadobj") != - std::string()) - { - octave_value_list tmp = feval ("loadobj", tc, 1); + tc = cls; + if (load_path::find_method (classname, "loadobj") != + std::string()) + { + octave_value_list tmp = feval ("loadobj", tc, 1); - if (! error_state) - tc = tmp(0); - else - goto data_read_error; - } - } - } - else - tc = m; + if (! error_state) + tc = tmp(0); + else + goto data_read_error; + } + } + } + else + tc = m; } break; @@ -1135,23 +1135,23 @@ case MAT_FILE_UINT8_CLASS: { - OCTAVE_MAT5_INTEGER_READ (uint8NDArray); + OCTAVE_MAT5_INTEGER_READ (uint8NDArray); - // Logical variables can either be MAT_FILE_UINT8_CLASS or - // MAT_FILE_DOUBLE_CLASS, so check if we have a logical - // variable and convert it. + // Logical variables can either be MAT_FILE_UINT8_CLASS or + // MAT_FILE_DOUBLE_CLASS, so check if we have a logical + // variable and convert it. - if (logicalvar) - { - uint8NDArray in = tc.uint8_array_value (); - int nel = in.nelem (); - boolNDArray out (dims); - - for (int i = 0; i < nel; i++) - out (i) = in(i).bool_value (); + if (logicalvar) + { + uint8NDArray in = tc.uint8_array_value (); + int nel = in.nelem (); + boolNDArray out (dims); + + for (int i = 0; i < nel; i++) + out (i) = in(i).bool_value (); - tc = out; - } + tc = out; + } } break; @@ -1186,126 +1186,126 @@ case MAT_FILE_SINGLE_CLASS: default: { - NDArray re (dims); + NDArray re (dims); - // real data subelement + // real data subelement - std::streampos tmp_pos; - - if (read_mat5_tag (is, swap, type, len)) - { - error ("load: reading matrix data for `%s'", retval.c_str ()); - goto data_read_error; - } + std::streampos tmp_pos; + + if (read_mat5_tag (is, swap, type, len)) + { + error ("load: reading matrix data for `%s'", retval.c_str ()); + goto data_read_error; + } - int n = re.length (); - tmp_pos = is.tellg (); - read_mat5_binary_data (is, re.fortran_vec (), n, swap, - static_cast (type), flt_fmt); + int n = re.length (); + tmp_pos = is.tellg (); + read_mat5_binary_data (is, re.fortran_vec (), n, swap, + static_cast (type), flt_fmt); - if (! is || error_state) - { - error ("load: reading matrix data for `%s'", retval.c_str ()); - goto data_read_error; - } + if (! is || error_state) + { + error ("load: reading matrix data for `%s'", retval.c_str ()); + goto data_read_error; + } - is.seekg (tmp_pos + static_cast (PAD (len))); + is.seekg (tmp_pos + static_cast (PAD (len))); - if (logicalvar) - { - // Logical variables can either be MAT_FILE_UINT8_CLASS or - // MAT_FILE_DOUBLE_CLASS, so check if we have a logical - // variable and convert it. + if (logicalvar) + { + // Logical variables can either be MAT_FILE_UINT8_CLASS or + // MAT_FILE_DOUBLE_CLASS, so check if we have a logical + // variable and convert it. - boolNDArray out (dims); - - for (int i = 0; i < n; i++) - out (i) = static_cast (re (i)); + boolNDArray out (dims); + + for (int i = 0; i < n; i++) + out (i) = static_cast (re (i)); - tc = out; - } - else if (imag) - { - // imaginary data subelement + tc = out; + } + else if (imag) + { + // imaginary data subelement - NDArray im (dims); - - if (read_mat5_tag (is, swap, type, len)) - { - error ("load: reading matrix data for `%s'", retval.c_str ()); - goto data_read_error; - } + NDArray im (dims); + + if (read_mat5_tag (is, swap, type, len)) + { + error ("load: reading matrix data for `%s'", retval.c_str ()); + goto data_read_error; + } - n = im.length (); - read_mat5_binary_data (is, im.fortran_vec (), n, swap, - static_cast (type), flt_fmt); + n = im.length (); + read_mat5_binary_data (is, im.fortran_vec (), n, swap, + static_cast (type), flt_fmt); - if (! is || error_state) - { - error ("load: reading imaginary matrix data for `%s'", - retval.c_str ()); - goto data_read_error; - } + if (! is || error_state) + { + error ("load: reading imaginary matrix data for `%s'", + retval.c_str ()); + goto data_read_error; + } - ComplexNDArray ctmp (dims); + ComplexNDArray ctmp (dims); - for (int i = 0; i < n; i++) - ctmp(i) = Complex (re(i), im(i)); + for (int i = 0; i < n; i++) + ctmp(i) = Complex (re(i), im(i)); - tc = ctmp; - } - else - { - if (arrayclass == MAT_FILE_CHAR_CLASS) - { - if (type == miUTF16 || type == miUTF32) - { - bool found_big_char = false; - for (int i = 0; i < n; i++) - { - if (re(i) > 127) { - re(i) = '?'; - found_big_char = true; - } - } + tc = ctmp; + } + else + { + if (arrayclass == MAT_FILE_CHAR_CLASS) + { + if (type == miUTF16 || type == miUTF32) + { + bool found_big_char = false; + for (int i = 0; i < n; i++) + { + if (re(i) > 127) { + re(i) = '?'; + found_big_char = true; + } + } - if (found_big_char) - { - warning ("load: can not read non-ASCII portions of UTF characters."); - warning (" Replacing unreadable characters with '?'."); - } - } - else if (type == miUTF8) - { - // Search for multi-byte encoded UTF8 characters and - // replace with 0x3F for '?'... Give the user a warning + if (found_big_char) + { + warning ("load: can not read non-ASCII portions of UTF characters."); + warning (" Replacing unreadable characters with '?'."); + } + } + else if (type == miUTF8) + { + // Search for multi-byte encoded UTF8 characters and + // replace with 0x3F for '?'... Give the user a warning - bool utf8_multi_byte = false; - for (int i = 0; i < n; i++) - { - unsigned char a = static_cast (re(i)); - if (a > 0x7f) - utf8_multi_byte = true; - } - - if (utf8_multi_byte) - { - warning ("load: can not read multi-byte encoded UTF8 characters."); - warning (" Replacing unreadable characters with '?'."); - for (int i = 0; i < n; i++) - { - unsigned char a = static_cast (re(i)); - if (a > 0x7f) - re(i) = '?'; - } - } - } - tc = re; - tc = tc.convert_to_str (false, true, '\''); - } - else - tc = re; - } + bool utf8_multi_byte = false; + for (int i = 0; i < n; i++) + { + unsigned char a = static_cast (re(i)); + if (a > 0x7f) + utf8_multi_byte = true; + } + + if (utf8_multi_byte) + { + warning ("load: can not read multi-byte encoded UTF8 characters."); + warning (" Replacing unreadable characters with '?'."); + for (int i = 0; i < n; i++) + { + unsigned char a = static_cast (re(i)); + if (a > 0x7f) + re(i) = '?'; + } + } + } + tc = re; + tc = tc.convert_to_str (false, true, '\''); + } + else + tc = re; + } } } @@ -1329,7 +1329,7 @@ int read_mat5_binary_file_header (std::istream& is, bool& swap, bool quiet, - const std::string& filename) + const std::string& filename) { int16_t version=0, magic=0; uint64_t subsys_offset; @@ -1348,16 +1348,16 @@ else { if (! quiet) - error ("load: can't read binary file"); + error ("load: can't read binary file"); return -1; } - if (! swap) // version number is inverse swapped! + if (! swap) // version number is inverse swapped! version = ((version >> 8) & 0xff) + ((version & 0xff) << 8); if (version != 1 && !quiet) warning ("load: found version %d binary MAT file, " - "but only prepared for version 1", version); + "but only prepared for version 1", version); if (swap) swap_bytes<8> (&subsys_offset, 1); @@ -1372,30 +1372,30 @@ read_mat5_binary_element (is, filename, swap, global, tc); if (!is || error_state) - return -1; + return -1; if (tc.is_uint8_type ()) - { - const uint8NDArray itmp = tc.uint8_array_value(); - octave_idx_type ilen = itmp.nelem (); + { + const uint8NDArray itmp = tc.uint8_array_value(); + octave_idx_type ilen = itmp.nelem (); - // Why should I have to initialize outbuf as just overwrite - std::string outbuf (ilen - 7, ' '); + // Why should I have to initialize outbuf as just overwrite + std::string outbuf (ilen - 7, ' '); - // FIXME -- find a way to avoid casting away const here - char *ctmp = const_cast (outbuf.c_str ()); - for (octave_idx_type j = 8; j < ilen; j++) - ctmp[j-8] = itmp(j).char_value (); + // FIXME -- find a way to avoid casting away const here + char *ctmp = const_cast (outbuf.c_str ()); + for (octave_idx_type j = 8; j < ilen; j++) + ctmp[j-8] = itmp(j).char_value (); - std::istringstream fh_ws (outbuf); + std::istringstream fh_ws (outbuf); - read_mat5_binary_element (fh_ws, filename, swap, global, subsys_ov); + read_mat5_binary_element (fh_ws, filename, swap, global, subsys_ov); - if (error_state) - return -1; - } + if (error_state) + return -1; + } else - return -1; + return -1; // Reposition to just after the header is.seekg (128, std::ios::beg); @@ -1415,7 +1415,7 @@ { temp = type; if (! is.write (reinterpret_cast (&temp), 4)) - goto data_write_error; + goto data_write_error; temp = bytes; } @@ -1457,12 +1457,12 @@ if (save_as_floats) { if (m.too_large_for_float ()) - { - warning ("save: some values too large to save as floats --"); - warning ("save: saving as doubles instead"); - } + { + warning ("save: some values too large to save as floats --"); + warning ("save: saving as doubles instead"); + } else - st = LS_FLOAT; + st = LS_FLOAT; } if (m.all_integers (max_val, min_val)) @@ -1488,49 +1488,49 @@ switch (st) { case LS_U_CHAR: - MAT5_DO_WRITE (uint8_t, data, nel, os); - break; - + MAT5_DO_WRITE (uint8_t, data, nel, os); + break; + case LS_U_SHORT: - MAT5_DO_WRITE (uint16_t, data, nel, os); - break; - + MAT5_DO_WRITE (uint16_t, data, nel, os); + break; + case LS_U_INT: - MAT5_DO_WRITE (uint32_t, data, nel, os); - break; - + MAT5_DO_WRITE (uint32_t, data, nel, os); + break; + case LS_U_LONG: - MAT5_DO_WRITE (uint64_t, data, nel, os); - break; + MAT5_DO_WRITE (uint64_t, data, nel, os); + break; case LS_CHAR: - MAT5_DO_WRITE (int8_t, data, nel, os); - break; - + MAT5_DO_WRITE (int8_t, data, nel, os); + break; + case LS_SHORT: - MAT5_DO_WRITE (int16_t, data, nel, os); - break; + MAT5_DO_WRITE (int16_t, data, nel, os); + break; case LS_INT: - MAT5_DO_WRITE (int32_t, data, nel, os); - break; + MAT5_DO_WRITE (int32_t, data, nel, os); + break; case LS_LONG: - MAT5_DO_WRITE (int64_t, data, nel, os); - break; + MAT5_DO_WRITE (int64_t, data, nel, os); + break; case LS_FLOAT: - MAT5_DO_WRITE (float, data, nel, os); - break; + MAT5_DO_WRITE (float, data, nel, os); + break; case LS_DOUBLE: // No conversion necessary. - os.write (reinterpret_cast (data), len); - break; + os.write (reinterpret_cast (data), len); + break; default: - (*current_liboctave_error_handler) - ("unrecognized data format requested"); - break; + (*current_liboctave_error_handler) + ("unrecognized data format requested"); + break; } } if (PAD (len) > len) @@ -1593,30 +1593,30 @@ } template void write_mat5_integer_data (std::ostream& os, const octave_int8 *m, - int size, int nel); + int size, int nel); template void write_mat5_integer_data (std::ostream& os, const octave_int16 *m, - int size, int nel); + int size, int nel); template void write_mat5_integer_data (std::ostream& os, const octave_int32 *m, - int size, int nel); + int size, int nel); template void write_mat5_integer_data (std::ostream& os, const octave_int64 *m, - int size, int nel); + int size, int nel); template void write_mat5_integer_data (std::ostream& os, const octave_uint8 *m, - int size, int nel); + int size, int nel); template void write_mat5_integer_data (std::ostream& os, const octave_uint16 *m, - int size, int nel); + int size, int nel); template void write_mat5_integer_data (std::ostream& os, const octave_uint32 *m, - int size, int nel); + int size, int nel); template void write_mat5_integer_data (std::ostream& os, const octave_uint64 *m, - int size, int nel); + int size, int nel); template void write_mat5_integer_data (std::ostream& os, const int *m, - int size, int nel); + int size, int nel); // Write out cell element values in the cell array to OS, preceded by // the appropriate tag. static bool write_mat5_cell_array (std::ostream& os, const Cell& cell, - bool mark_as_global, bool save_as_floats) + bool mark_as_global, bool save_as_floats) { int nel = cell.nelem (); @@ -1625,8 +1625,8 @@ octave_value ov = cell(i); if (! save_mat5_binary_element (os, ov, "", mark_as_global, - false, save_as_floats)) - return false; + false, save_as_floats)) + return false; } return true; @@ -1640,23 +1640,23 @@ int size = 8; if (save_as_floats) - { - bool too_large_for_float = false; - for (int i = 0; i < nel; i++) - { - double tmp = val [i]; + { + bool too_large_for_float = false; + for (int i = 0; i < nel; i++) + { + double tmp = val [i]; - if (! (xisnan (tmp) || xisinf (tmp)) - && fabs (tmp) > FLT_MAX) - { - too_large_for_float = true; - break; - } - } + if (! (xisnan (tmp) || xisinf (tmp)) + && fabs (tmp) > FLT_MAX) + { + too_large_for_float = true; + break; + } + } - if (!too_large_for_float) - size = 4; - } + if (!too_large_for_float) + size = 4; + } // The code below is disabled since get_save_type currently doesn't // deal with integer types. This will need to be activated if get_save_type @@ -1727,7 +1727,7 @@ int save_mat5_element_length (const octave_value& tc, const std::string& name, - bool save_as_floats, bool mat7_format) + bool save_as_floats, bool mat7_format) { int max_namelen = (mat7_format ? 63 : 31); int len = name.length (); @@ -1744,28 +1744,28 @@ charNDArray chm = tc.char_array_value (); ret += 8; if (chm.nelem () > 2) - ret += PAD (2 * chm.nelem ()); + ret += PAD (2 * chm.nelem ()); } else if (tc.is_sparse_type ()) { if (tc.is_complex_type ()) - { - SparseComplexMatrix m = tc.sparse_complex_matrix_value (); - int nc = m.cols (); - int nnz = m.nzmax (); + { + SparseComplexMatrix m = tc.sparse_complex_matrix_value (); + int nc = m.cols (); + int nnz = m.nzmax (); - ret += 16 + PAD (nnz * sizeof (int)) + PAD ((nc + 1) * sizeof (int)) + - save_mat5_array_length (m.data (), m.nelem (), save_as_floats); - } + ret += 16 + PAD (nnz * sizeof (int)) + PAD ((nc + 1) * sizeof (int)) + + save_mat5_array_length (m.data (), m.nelem (), save_as_floats); + } else - { - SparseMatrix m = tc.sparse_matrix_value (); - int nc = m.cols (); - int nnz = m.nzmax (); + { + SparseMatrix m = tc.sparse_matrix_value (); + int nc = m.cols (); + int nnz = m.nzmax (); - ret += 16 + PAD (nnz * sizeof (int)) + PAD ((nc + 1) * sizeof (int)) + - save_mat5_array_length (m.data (), m.nelem (), save_as_floats); - } + ret += 16 + PAD (nnz * sizeof (int)) + PAD ((nc + 1) * sizeof (int)) + + save_mat5_array_length (m.data (), m.nelem (), save_as_floats); + } } #define INT_LEN(nel, size) \ @@ -1773,7 +1773,7 @@ ret += 8; \ int sz = nel * size; \ if (sz > 4) \ - ret += PAD (sz); \ + ret += PAD (sz); \ } else if (cname == "int8") @@ -1798,7 +1798,7 @@ { NDArray m = tc.array_value (); ret += save_mat5_array_length (m.fortran_vec (), m.nelem (), - save_as_floats); + save_as_floats); } else if (tc.is_cell ()) { @@ -1806,14 +1806,14 @@ int nel = cell.nelem (); for (int i = 0; i < nel; i++) - ret += 8 + - save_mat5_element_length (cell (i), "", save_as_floats, mat7_format); + ret += 8 + + save_mat5_element_length (cell (i), "", save_as_floats, mat7_format); } else if (tc.is_complex_scalar () || tc.is_complex_matrix ()) { ComplexNDArray m = tc.complex_array_value (); ret += save_mat5_array_length (m.fortran_vec (), m.nelem (), - save_as_floats); + save_as_floats); } else if (tc.is_map () || tc.is_inline_function () || tc.is_object ()) { @@ -1822,32 +1822,32 @@ int nel = m.numel (); if (tc.is_inline_function ()) - // length of "inline" is 6 - ret += 8 + PAD (6 > max_namelen ? max_namelen : 6); + // length of "inline" is 6 + ret += 8 + PAD (6 > max_namelen ? max_namelen : 6); else if (tc.is_object ()) - { - int classlen = tc.class_name (). length (); + { + int classlen = tc.class_name (). length (); - ret += 8 + PAD (classlen > max_namelen ? max_namelen : classlen); - } + ret += 8 + PAD (classlen > max_namelen ? max_namelen : classlen); + } for (Octave_map::const_iterator i = m.begin (); i != m.end (); i++) - fieldcnt++; + fieldcnt++; ret += 16 + fieldcnt * (max_namelen + 1); for (int j = 0; j < nel; j++) - { + { - for (Octave_map::const_iterator i = m.begin (); i != m.end (); i++) - { - const Cell elts = m.contents (i); + for (Octave_map::const_iterator i = m.begin (); i != m.end (); i++) + { + const Cell elts = m.contents (i); - ret += 8 + save_mat5_element_length (elts(j), "", - save_as_floats, mat7_format); - } - } + ret += 8 + save_mat5_element_length (elts(j), "", + save_as_floats, mat7_format); + } + } } else ret = -1; @@ -1860,9 +1860,9 @@ bool save_mat5_binary_element (std::ostream& os, - const octave_value& tc, const std::string& name, - bool mark_as_global, bool mat7_format, - bool save_as_floats, bool compressing) + const octave_value& tc, const std::string& name, + bool mark_as_global, bool mat7_format, + bool save_as_floats, bool compressing) { int32_t flags=0; int32_t nnz=0; @@ -1880,29 +1880,29 @@ // The code seeks backwards in the stream to fix the header. Can't // do this with zlib, so use a stringstream. ret = save_mat5_binary_element (buf, tc, name, mark_as_global, true, - save_as_floats, true); + save_as_floats, true); if (ret) - { - // destLen must be at least 0.1% larger than source buffer - // + 12 bytes. Reality is it must be larger again than that. - std::string buf_str = buf.str (); - uLongf srcLen = buf_str.length (); - uLongf destLen = srcLen * 101 / 100 + 12; - OCTAVE_LOCAL_BUFFER (char, out_buf, destLen); + { + // destLen must be at least 0.1% larger than source buffer + // + 12 bytes. Reality is it must be larger again than that. + std::string buf_str = buf.str (); + uLongf srcLen = buf_str.length (); + uLongf destLen = srcLen * 101 / 100 + 12; + OCTAVE_LOCAL_BUFFER (char, out_buf, destLen); - if (compress (reinterpret_cast (out_buf), &destLen, - reinterpret_cast (buf_str.c_str ()), srcLen) == Z_OK) - { - write_mat5_tag (os, miCOMPRESSED, static_cast (destLen)); - os.write (out_buf, destLen); - } - else - { - error ("save: error compressing data element"); - ret = false; - } - } + if (compress (reinterpret_cast (out_buf), &destLen, + reinterpret_cast (buf_str.c_str ()), srcLen) == Z_OK) + { + write_mat5_tag (os, miCOMPRESSED, static_cast (destLen)); + os.write (out_buf, destLen); + } + else + { + error ("save: error compressing data element"); + ret = false; + } + } return ret; } @@ -1911,7 +1911,7 @@ // element type and length fixup = os.tellp (); write_mat5_tag (os, miMATRIX, save_mat5_element_length - (tc, name, save_as_floats, mat7_format)); + (tc, name, save_as_floats, mat7_format)); // array flags subelement write_mat5_tag (os, miUINT32, 8); @@ -1947,15 +1947,15 @@ { flags |= MAT_FILE_SPARSE_CLASS; if (tc.is_complex_type ()) - { - SparseComplexMatrix scm = tc.sparse_complex_matrix_value (); - nnz = scm.nzmax (); - } + { + SparseComplexMatrix scm = tc.sparse_complex_matrix_value (); + nnz = scm.nzmax (); + } else - { - SparseMatrix sm = tc.sparse_matrix_value (); - nnz = sm.nzmax (); - } + { + SparseMatrix sm = tc.sparse_matrix_value (); + nnz = sm.nzmax (); + } } else if (tc.is_real_scalar ()) flags |= MAT_FILE_DOUBLE_CLASS; @@ -1989,14 +1989,14 @@ for (int i = 0; i < nd; i++) { - int32_t n = dv(i); - os.write (reinterpret_cast (&n), 4); + int32_t n = dv(i); + os.write (reinterpret_cast (&n), 4); } if (PAD (dim_len) > dim_len) { - static char buf[9]="\x00\x00\x00\x00\x00\x00\x00\x00"; - os.write (buf, PAD (dim_len) - dim_len); + static char buf[9]="\x00\x00\x00\x00\x00\x00\x00\x00"; + os.write (buf, PAD (dim_len) - dim_len); } } @@ -2030,59 +2030,59 @@ const char *s = chm.data (); for (int i = 0; i < nel; i++) - buf[i] = *s++ & 0x00FF; + buf[i] = *s++ & 0x00FF; os.write (reinterpret_cast (buf), len); if (paddedlength > len) - { - static char padbuf[9]="\x00\x00\x00\x00\x00\x00\x00\x00"; - os.write (padbuf, paddedlength - len); - } + { + static char padbuf[9]="\x00\x00\x00\x00\x00\x00\x00\x00"; + os.write (padbuf, paddedlength - len); + } } else if (tc.is_sparse_type ()) { if (tc.is_complex_type ()) - { - SparseComplexMatrix m = tc.sparse_complex_matrix_value (); - int nc = m.cols (); + { + SparseComplexMatrix m = tc.sparse_complex_matrix_value (); + int nc = m.cols (); - int tmp = sizeof (int); + int tmp = sizeof (int); - write_mat5_integer_data (os, m.ridx (), -tmp, nnz); - write_mat5_integer_data (os, m.cidx (), -tmp, nc + 1); + write_mat5_integer_data (os, m.ridx (), -tmp, nnz); + write_mat5_integer_data (os, m.cidx (), -tmp, nc + 1); - NDArray buf (dim_vector (nnz, 1)); + NDArray buf (dim_vector (nnz, 1)); - for (int i = 0; i < nnz; i++) - buf (i) = std::real (m.data (i)); + for (int i = 0; i < nnz; i++) + buf (i) = std::real (m.data (i)); - write_mat5_array (os, buf, save_as_floats); + write_mat5_array (os, buf, save_as_floats); - for (int i = 0; i < nnz; i++) - buf (i) = std::imag (m.data (i)); + for (int i = 0; i < nnz; i++) + buf (i) = std::imag (m.data (i)); - write_mat5_array (os, buf, save_as_floats); - } + write_mat5_array (os, buf, save_as_floats); + } else - { - SparseMatrix m = tc.sparse_matrix_value (); - int nc = m.cols (); + { + SparseMatrix m = tc.sparse_matrix_value (); + int nc = m.cols (); - int tmp = sizeof (int); + int tmp = sizeof (int); - write_mat5_integer_data (os, m.ridx (), -tmp, nnz); - write_mat5_integer_data (os, m.cidx (), -tmp, nc + 1); + write_mat5_integer_data (os, m.ridx (), -tmp, nnz); + write_mat5_integer_data (os, m.cidx (), -tmp, nc + 1); - // FIXME - // Is there a way to easily do without this buffer - NDArray buf (dim_vector (nnz, 1)); + // FIXME + // Is there a way to easily do without this buffer + NDArray buf (dim_vector (nnz, 1)); - for (int i = 0; i < nnz; i++) - buf (i) = m.data (i); + for (int i = 0; i < nnz; i++) + buf (i) = m.data (i); - write_mat5_array (os, buf, save_as_floats); - } + write_mat5_array (os, buf, save_as_floats); + } } else if (cname == "int8") { @@ -2149,7 +2149,7 @@ Cell cell = tc.cell_value (); if (! write_mat5_cell_array (os, cell, mark_as_global, save_as_floats)) - goto error_cleanup; + goto error_cleanup; } else if (tc.is_complex_scalar () || tc.is_complex_matrix ()) { @@ -2161,89 +2161,89 @@ else if (tc.is_map () || tc.is_inline_function() || tc.is_object ()) { if (tc.is_inline_function () || tc.is_object ()) - { - std::string classname = tc.is_object() ? tc.class_name () : "inline"; - int namelen = classname.length (); + { + std::string classname = tc.is_object() ? tc.class_name () : "inline"; + int namelen = classname.length (); - if (namelen > max_namelen) - namelen = max_namelen; // only 31 or 63 char names permitted + if (namelen > max_namelen) + namelen = max_namelen; // only 31 or 63 char names permitted - int paddedlength = PAD (namelen); + int paddedlength = PAD (namelen); - write_mat5_tag (os, miINT8, namelen); - OCTAVE_LOCAL_BUFFER (char, paddedname, paddedlength); - memset (paddedname, 0, paddedlength); - strncpy (paddedname, classname.c_str (), namelen); - os.write (paddedname, paddedlength); - } + write_mat5_tag (os, miINT8, namelen); + OCTAVE_LOCAL_BUFFER (char, paddedname, paddedlength); + memset (paddedname, 0, paddedlength); + strncpy (paddedname, classname.c_str (), namelen); + os.write (paddedname, paddedlength); + } Octave_map m; if (tc.is_object () && - load_path::find_method (tc.class_name (), "saveobj") != std::string()) - { - octave_value_list tmp = feval ("saveobj", tc, 1); - if (! error_state) - m = tmp(0).map_value (); - else - goto error_cleanup; - } + load_path::find_method (tc.class_name (), "saveobj") != std::string()) + { + octave_value_list tmp = feval ("saveobj", tc, 1); + if (! error_state) + m = tmp(0).map_value (); + else + goto error_cleanup; + } else - m = tc.map_value (); + m = tc.map_value (); // an Octave structure */ // recursively write each element of the structure { - char buf[64]; - int32_t maxfieldnamelength = max_namelen + 1; + char buf[64]; + int32_t maxfieldnamelength = max_namelen + 1; - octave_idx_type nf = m.nfields (); + octave_idx_type nf = m.nfields (); - int fieldcnt = nf; + int fieldcnt = nf; - write_mat5_tag (os, miINT32, 4); - os.write (reinterpret_cast (&maxfieldnamelength), 4); - write_mat5_tag (os, miINT8, fieldcnt*maxfieldnamelength); + write_mat5_tag (os, miINT32, 4); + os.write (reinterpret_cast (&maxfieldnamelength), 4); + write_mat5_tag (os, miINT8, fieldcnt*maxfieldnamelength); - // Iterating over the list of keys will preserve the order of - // the fields. - string_vector keys = m.keys (); + // Iterating over the list of keys will preserve the order of + // the fields. + string_vector keys = m.keys (); - for (octave_idx_type i = 0; i < nf; i++) - { - std::string key = keys(i); + for (octave_idx_type i = 0; i < nf; i++) + { + std::string key = keys(i); - // write the name of each element - memset (buf, 0, max_namelen + 1); - // only 31 or 63 char names permitted - strncpy (buf, key.c_str (), max_namelen); - os.write (buf, max_namelen + 1); - } + // write the name of each element + memset (buf, 0, max_namelen + 1); + // only 31 or 63 char names permitted + strncpy (buf, key.c_str (), max_namelen); + os.write (buf, max_namelen + 1); + } - int len = m.numel (); + int len = m.numel (); - // Create temporary copy of structure contents to avoid - // multiple calls of the contents method. - std::vector elts (nf); - for (octave_idx_type i = 0; i < nf; i++) - elts[i] = m.contents (keys(i)).data (); + // Create temporary copy of structure contents to avoid + // multiple calls of the contents method. + std::vector elts (nf); + for (octave_idx_type i = 0; i < nf; i++) + elts[i] = m.contents (keys(i)).data (); - for (int j = 0; j < len; j++) - { - // write the data of each element + for (int j = 0; j < len; j++) + { + // write the data of each element - // Iterating over the list of keys will preserve the order - // of the fields. - for (octave_idx_type i = 0; i < nf; i++) - { - bool retval2 = save_mat5_binary_element (os, elts[i][j], "", - mark_as_global, - false, - save_as_floats); - if (! retval2) - goto error_cleanup; - } - } + // Iterating over the list of keys will preserve the order + // of the fields. + for (octave_idx_type i = 0; i < nf; i++) + { + bool retval2 = save_mat5_binary_element (os, elts[i][j], "", + mark_as_global, + false, + save_as_floats); + if (! retval2) + goto error_cleanup; + } + } } } else diff --git a/src/ls-oct-ascii.cc b/src/ls-oct-ascii.cc --- a/src/ls-oct-ascii.cc +++ b/src/ls-oct-ascii.cc @@ -89,36 +89,36 @@ while (is.get (c)) { if (c == '%' || c == '#') - { - std::ostringstream buf; - - while (is.get (c) && (c == ' ' || c == '\t' || c == '%' || c == '#')) - ; // Skip whitespace and comment characters. + { + std::ostringstream buf; + + while (is.get (c) && (c == ' ' || c == '\t' || c == '%' || c == '#')) + ; // Skip whitespace and comment characters. - if (isalpha (c)) - buf << c; + if (isalpha (c)) + buf << c; - while (is.get (c) && isalpha (c)) - buf << c; + while (is.get (c) && isalpha (c)) + buf << c; - std::string tmp = buf.str (); - bool match = (tmp.compare (0, strlen (keyword), keyword) == 0); + std::string tmp = buf.str (); + bool match = (tmp.compare (0, strlen (keyword), keyword) == 0); - if (match) - { - std::ostringstream value; - while (is.get (c) && (c == ' ' || c == '\t' || c == ':')) - ; // Skip whitespace and the colon. + if (match) + { + std::ostringstream value; + while (is.get (c) && (c == ' ' || c == '\t' || c == ':')) + ; // Skip whitespace and the colon. - is.putback(c); - retval = read_until_newline (is, false); - break; - } - else if (next_only) - break; - else - skip_until_newline (is, false); - } + is.putback(c); + retval = read_until_newline (is, false); + break; + } + else if (next_only) + break; + else + skip_until_newline (is, false); + } } int len = retval.length (); @@ -126,17 +126,17 @@ if (len > 0) { while (len) - { - c = retval[len-1]; + { + c = retval[len-1]; - if (c == ' ' || c == '\t') - len--; - else - { - retval.resize (len); - break; - } - } + if (c == ' ' || c == '\t') + len--; + else + { + retval.resize (len); + break; + } + } } return retval; @@ -235,7 +235,7 @@ std::string read_ascii_data (std::istream& is, const std::string& filename, bool& global, - octave_value& tc, octave_idx_type count) + octave_value& tc, octave_idx_type count) { // Read name for this entry or break on EOF. @@ -244,17 +244,17 @@ if (name.empty ()) { if (count == 0) - error ("load: empty name keyword or no data found in file `%s'", - filename.c_str ()); + error ("load: empty name keyword or no data found in file `%s'", + filename.c_str ()); return std::string (); } if (! (name == ".nargin." || name == ".nargout." - || name == CELL_ELT_TAG || valid_identifier (name))) + || name == CELL_ELT_TAG || valid_identifier (name))) { error ("load: bogus identifier `%s' found in file `%s'", - name.c_str (), filename.c_str ()); + name.c_str (), filename.c_str ()); return std::string (); } @@ -268,22 +268,22 @@ size_t pos = tag.rfind (' '); if (pos != std::string::npos) - { - global = SUBSTRING_COMPARE_EQ (tag, 0, 6, "global"); + { + global = SUBSTRING_COMPARE_EQ (tag, 0, 6, "global"); - typ = global ? tag.substr (7) : tag; - } + typ = global ? tag.substr (7) : tag; + } else - typ = tag; + typ = tag; // Special case for backward compatiablity. A small bit of cruft if (SUBSTRING_COMPARE_EQ (typ, 0, 12, "string array")) - tc = charMatrix (); + tc = charMatrix (); else - tc = octave_value_typeinfo::lookup_type (typ); + tc = octave_value_typeinfo::lookup_type (typ); if (! tc.load_ascii (is)) - error ("load: trouble reading ascii file `%s'", filename.c_str ()); + error ("load: trouble reading ascii file `%s'", filename.c_str ()); } else error ("load: failed to extract keyword specifying value type"); @@ -310,8 +310,8 @@ bool save_ascii_data (std::ostream& os, const octave_value& val_arg, - const std::string& name, bool mark_as_global, - int precision) + const std::string& name, bool mark_as_global, + int precision) { bool success = true; @@ -340,7 +340,7 @@ bool save_ascii_data_for_plotting (std::ostream& os, const octave_value& t, - const std::string& name) + const std::string& name) { return save_ascii_data (os, t, name, false, 6); } @@ -362,41 +362,41 @@ if (tc.is_real_matrix ()) { os << "# 3D data...\n" - << "# type: matrix\n" - << "# total rows: " << nr << "\n" - << "# total columns: " << nc << "\n"; + << "# type: matrix\n" + << "# total rows: " << nr << "\n" + << "# total columns: " << nc << "\n"; long old_precision = os.precision (); os.precision (6); if (parametric) - { - octave_idx_type extras = nc % 3; - if (extras) - warning ("ignoring last %d columns", extras); + { + octave_idx_type extras = nc % 3; + if (extras) + warning ("ignoring last %d columns", extras); - Matrix tmp = tc.matrix_value (); - nr = tmp.rows (); + Matrix tmp = tc.matrix_value (); + nr = tmp.rows (); - for (octave_idx_type i = 0; i < nc-extras; i += 3) - { - os << tmp.extract (0, i, nr-1, i+2); - if (i+3 < nc-extras) - os << "\n"; - } - } + for (octave_idx_type i = 0; i < nc-extras; i += 3) + { + os << tmp.extract (0, i, nr-1, i+2); + if (i+3 < nc-extras) + os << "\n"; + } + } else - { - Matrix tmp = tc.matrix_value (); - nr = tmp.rows (); + { + Matrix tmp = tc.matrix_value (); + nr = tmp.rows (); - for (octave_idx_type i = 0; i < nc; i++) - { - os << tmp.extract (0, i, nr-1, i); - if (i+1 < nc) - os << "\n"; - } - } + for (octave_idx_type i = 0; i < nc; i++) + { + os << tmp.extract (0, i, nr-1, i); + if (i+1 < nc) + os << "\n"; + } + } os.precision (old_precision); } diff --git a/src/ls-oct-binary.cc b/src/ls-oct-binary.cc --- a/src/ls-oct-binary.cc +++ b/src/ls-oct-binary.cc @@ -132,9 +132,9 @@ std::string read_binary_data (std::istream& is, bool swap, - oct_mach_info::float_format fmt, - const std::string& filename, bool& global, - octave_value& tc, std::string& doc) + oct_mach_info::float_format fmt, + const std::string& filename, bool& global, + octave_value& tc, std::string& doc) { std::string retval; @@ -205,22 +205,22 @@ case 5: { - // FIXMEX - // This is cruft, since its for a save type that is old. Maybe - // this is taking backward compatability too far!! - int32_t len; - if (! is.read (reinterpret_cast (&len), 4)) - goto data_read_error; - if (swap) - swap_bytes<4> (&len); - OCTAVE_LOCAL_BUFFER (char, s, len+1); - if (! is.read (reinterpret_cast (s), len)) - goto data_read_error; - s[len] = '\0'; - tc = s; + // FIXMEX + // This is cruft, since its for a save type that is old. Maybe + // this is taking backward compatability too far!! + int32_t len; + if (! is.read (reinterpret_cast (&len), 4)) + goto data_read_error; + if (swap) + swap_bytes<4> (&len); + OCTAVE_LOCAL_BUFFER (char, s, len+1); + if (! is.read (reinterpret_cast (s), len)) + goto data_read_error; + s[len] = '\0'; + tc = s; - // Early return, since don't want rest of this function - return retval; + // Early return, since don't want rest of this function + return retval; } break; @@ -234,18 +234,18 @@ case 255: { - // Read the saved variable type - int32_t len; - if (! is.read (reinterpret_cast (&len), 4)) - goto data_read_error; - if (swap) - swap_bytes<4> (&len); - OCTAVE_LOCAL_BUFFER (char, s, len+1); - if (! is.read (s, len)) - goto data_read_error; - s[len] = '\0'; - std::string typ = s; - tc = octave_value_typeinfo::lookup_type (typ); + // Read the saved variable type + int32_t len; + if (! is.read (reinterpret_cast (&len), 4)) + goto data_read_error; + if (swap) + swap_bytes<4> (&len); + OCTAVE_LOCAL_BUFFER (char, s, len+1); + if (! is.read (s, len)) + goto data_read_error; + s[len] = '\0'; + std::string typ = s; + tc = octave_value_typeinfo::lookup_type (typ); } break; default: @@ -268,8 +268,8 @@ bool save_binary_data (std::ostream& os, const octave_value& tc, - const std::string& name, const std::string& doc, - bool mark_as_global, bool save_as_floats) + const std::string& name, const std::string& doc, + bool mark_as_global, bool save_as_floats) { int32_t name_len = name.length (); diff --git a/src/mex.cc b/src/mex.cc --- a/src/mex.cc +++ b/src/mex.cc @@ -70,7 +70,7 @@ mwSize tmp = strlen (str[i]); if (tmp > max_len) - max_len = tmp; + max_len = tmp; } return max_len; @@ -86,15 +86,15 @@ if (nel > 0) { if (isalpha (key[0])) - { - for (int i = 1; i < nel; i++) - { - if (! (isalnum (key[i]) || key[i] == '_')) - goto done; - } - - retval = 1; - } + { + for (int i = 1; i < nel; i++) + { + if (! (isalnum (key[i]) || key[i] == '_')) + goto done; + } + + retval = 1; + } } done: @@ -274,7 +274,7 @@ static mwIndex calc_single_subscript_internal (mwSize ndims, const mwSize *dims, - mwSize nsubs, const mwIndex *subs) + mwSize nsubs, const mwIndex *subs) { mwIndex retval = 0; @@ -289,14 +289,14 @@ default: { - // Both nsubs and ndims should be at least 2 here. - - mwSize n = nsubs <= ndims ? nsubs : ndims; - - retval = subs[--n]; - - while (--n >= 0) - retval = dims[n] * retval + subs[n]; + // Both nsubs and ndims should be at least 2 here. + + mwSize n = nsubs <= ndims ? nsubs : ndims; + + retval = subs[--n]; + + while (--n >= 0) + retval = dims[n] * retval + subs[n]; } break; } @@ -397,14 +397,14 @@ { if (! dims) { - ndims = val.ndims (); - - dims = static_cast (malloc (ndims * sizeof (mwSize))); - - dim_vector dv = val.dims (); - - for (mwIndex i = 0; i < ndims; i++) - dims[i] = dv(i); + ndims = val.ndims (); + + dims = static_cast (malloc (ndims * sizeof (mwSize))); + + dim_vector dv = val.dims (); + + for (mwIndex i = 0; i < ndims; i++) + dims[i] = dv(i); } return dims; @@ -475,8 +475,8 @@ { if (! class_name) { - std::string s = val.class_name (); - class_name = strsave (s.c_str ()); + std::string s = val.class_name (); + class_name = strsave (s.c_str ()); } return class_name; @@ -591,16 +591,16 @@ if (val.is_string () && nel < buflen) { - charNDArray tmp = val.char_array_value (); - - const char *p = tmp.data (); - - for (mwIndex i = 0; i < nel; i++) - buf[i] = p[i]; - - buf[nel] = 0; - - retval = 0; + charNDArray tmp = val.char_array_value (); + + const char *p = tmp.data (); + + for (mwIndex i = 0; i < nel; i++) + buf[i] = p[i]; + + buf[nel] = 0; + + retval = 0; } return retval; @@ -615,21 +615,21 @@ if (val.is_string ()) { - mwSize nel = get_number_of_elements (); - - buf = static_cast (malloc (nel + 1)); - - if (buf) - { - charNDArray tmp = val.char_array_value (); - - const char *p = tmp.data (); - - for (mwIndex i = 0; i < nel; i++) - buf[i] = p[i]; - - buf[nel] = '\0'; - } + mwSize nel = get_number_of_elements (); + + buf = static_cast (malloc (nel + 1)); + + if (buf) + { + charNDArray tmp = val.char_array_value (); + + const char *p = tmp.data (); + + for (mwIndex i = 0; i < nel; i++) + buf[i] = p[i]; + + buf[nel] = '\0'; + } } return buf; @@ -692,8 +692,8 @@ { if (dims) { - for (mwIndex i = 0; i < ndims; i++) - dims[i] = arg.dims[i]; + for (mwIndex i = 0; i < ndims; i++) + dims[i] = arg.dims[i]; } } @@ -730,8 +730,8 @@ { if (ndims_arg < 2) { - dims[0] = 1; - dims[1] = 1; + dims[0] = 1; + dims[1] = 1; } for (mwIndex i = 0; i < ndims_arg; i++) @@ -739,10 +739,10 @@ for (mwIndex i = ndims - 1; i > 1; i--) { - if (dims[i] == 1) - ndims--; - else - break; + if (dims[i] == 1) + ndims--; + else + break; } } @@ -756,10 +756,10 @@ for (mwIndex i = ndims - 1; i > 1; i--) { - if (dims[i] == 1) - ndims--; - else - break; + if (dims[i] == 1) + ndims--; + else + break; } } @@ -800,10 +800,10 @@ int is_numeric (void) const { return (id == mxDOUBLE_CLASS || id == mxSINGLE_CLASS - || id == mxINT8_CLASS || id == mxUINT8_CLASS - || id == mxINT16_CLASS || id == mxUINT16_CLASS - || id == mxINT32_CLASS || id == mxUINT32_CLASS - || id == mxINT64_CLASS || id == mxUINT64_CLASS); + || id == mxINT8_CLASS || id == mxUINT8_CLASS + || id == mxINT16_CLASS || id == mxUINT16_CLASS + || id == mxINT32_CLASS || id == mxUINT32_CLASS + || id == mxINT64_CLASS || id == mxUINT64_CLASS); } int is_single (void) const { return id == mxSINGLE_CLASS; } @@ -823,7 +823,7 @@ int is_logical_scalar_true (void) const { return (is_logical_scalar () - && static_cast (get_data ())[0] != 0); + && static_cast (get_data ())[0] != 0); } mwSize get_m (void) const { return dims[0]; } @@ -1096,13 +1096,13 @@ public: mxArray_number (mxClassID id_arg, mwSize ndims_arg, const mwSize *dims_arg, - mxComplexity flag = mxREAL) + mxComplexity flag = mxREAL) : mxArray_matlab (id_arg, ndims_arg, dims_arg), pr (calloc (get_number_of_elements (), get_element_size ())), pi (flag == mxCOMPLEX ? calloc (get_number_of_elements (), get_element_size ()) : 0) { } mxArray_number (mxClassID id_arg, const dim_vector& dv, - mxComplexity flag = mxREAL) + mxComplexity flag = mxREAL) : mxArray_matlab (id_arg, dv), pr (calloc (get_number_of_elements (), get_element_size ())), pi (flag == mxCOMPLEX ? calloc (get_number_of_elements (), get_element_size ()) : 0) { } @@ -1155,16 +1155,16 @@ for (mwIndex j = 0; j < m; j++) { - const char *ptr = str[j]; - - size_t tmp_len = strlen (ptr); - - for (size_t i = 0; i < tmp_len; i++) - cpr[m*i+j] = static_cast (ptr[i]); - - for (size_t i = tmp_len; i < nc; i++) - cpr[m*i+j] = static_cast (' '); - } + const char *ptr = str[j]; + + size_t tmp_len = strlen (ptr); + + for (size_t i = 0; i < tmp_len; i++) + cpr[m*i+j] = static_cast (ptr[i]); + + for (size_t i = tmp_len; i < nc; i++) + cpr[m*i+j] = static_cast (' '); + } } mxArray_number *clone (void) const { return new mxArray_number (*this); } @@ -1184,55 +1184,55 @@ switch (get_class_id ()) { case mxLOGICAL_CLASS: - retval = *(static_cast (pr)); - break; + retval = *(static_cast (pr)); + break; case mxCHAR_CLASS: - retval = *(static_cast (pr)); - break; + retval = *(static_cast (pr)); + break; case mxSINGLE_CLASS: - retval = *(static_cast (pr)); - break; + retval = *(static_cast (pr)); + break; case mxDOUBLE_CLASS: - retval = *(static_cast (pr)); - break; + retval = *(static_cast (pr)); + break; case mxINT8_CLASS: - retval = *(static_cast (pr)); - break; + retval = *(static_cast (pr)); + break; case mxUINT8_CLASS: - retval = *(static_cast (pr)); - break; + retval = *(static_cast (pr)); + break; case mxINT16_CLASS: - retval = *(static_cast (pr)); - break; + retval = *(static_cast (pr)); + break; case mxUINT16_CLASS: - retval = *(static_cast (pr)); - break; + retval = *(static_cast (pr)); + break; case mxINT32_CLASS: - retval = *(static_cast (pr)); - break; + retval = *(static_cast (pr)); + break; case mxUINT32_CLASS: - retval = *(static_cast (pr)); - break; + retval = *(static_cast (pr)); + break; case mxINT64_CLASS: - retval = *(static_cast (pr)); - break; + retval = *(static_cast (pr)); + break; case mxUINT64_CLASS: - retval = *(static_cast (pr)); - break; + retval = *(static_cast (pr)); + break; default: - panic_impossible (); + panic_impossible (); } return retval; @@ -1254,12 +1254,12 @@ if (nel < buflen) { - mxChar *ptr = static_cast (pr); - - for (mwIndex i = 0; i < nel; i++) - buf[i] = static_cast (ptr[i]); - - buf[nel] = 0; + mxChar *ptr = static_cast (pr); + + for (mwIndex i = 0; i < nel; i++) + buf[i] = static_cast (ptr[i]); + + buf[nel] = 0; } return retval; @@ -1276,12 +1276,12 @@ if (buf) { - mxChar *ptr = static_cast (pr); - - for (mwIndex i = 0; i < nel; i++) - buf[i] = static_cast (ptr[i]); - - buf[nel] = '\0'; + mxChar *ptr = static_cast (pr); + + for (mwIndex i = 0; i < nel; i++) + buf[i] = static_cast (ptr[i]); + + buf[nel] = '\0'; } return buf; @@ -1303,14 +1303,14 @@ error ("complex integer types are not supported"); else { - ARRAY_T val (dv); - - ARRAY_ELT_T *ptr = val.fortran_vec (); - - for (mwIndex i = 0; i < nel; i++) - ptr[i] = ppr[i]; - - retval = val; + ARRAY_T val (dv); + + ARRAY_ELT_T *ptr = val.fortran_vec (); + + for (mwIndex i = 0; i < nel; i++) + ptr[i] = ppr[i]; + + retval = val; } return retval; @@ -1325,126 +1325,126 @@ switch (get_class_id ()) { case mxLOGICAL_CLASS: - retval = int_to_ov (dv); - break; + retval = int_to_ov (dv); + break; case mxCHAR_CLASS: - { - mwSize nel = get_number_of_elements (); - - mxChar *ppr = static_cast (pr); - - charNDArray val (dv); - - char *ptr = val.fortran_vec (); - - for (mwIndex i = 0; i < nel; i++) - ptr[i] = static_cast (ppr[i]); - - retval = val; - } - break; + { + mwSize nel = get_number_of_elements (); + + mxChar *ppr = static_cast (pr); + + charNDArray val (dv); + + char *ptr = val.fortran_vec (); + + for (mwIndex i = 0; i < nel; i++) + ptr[i] = static_cast (ppr[i]); + + retval = val; + } + break; case mxSINGLE_CLASS: - { - mwSize nel = get_number_of_elements (); - - float *ppr = static_cast (pr); - - if (pi) - { - ComplexNDArray val (dv); - - Complex *ptr = val.fortran_vec (); - - float *ppi = static_cast (pi); - - for (mwIndex i = 0; i < nel; i++) - ptr[i] = Complex (ppr[i], ppi[i]); - - retval = val; - } - else - { - NDArray val (dv); - - double *ptr = val.fortran_vec (); - - for (mwIndex i = 0; i < nel; i++) - ptr[i] = ppr[i]; - - retval = val; - } - } - break; + { + mwSize nel = get_number_of_elements (); + + float *ppr = static_cast (pr); + + if (pi) + { + ComplexNDArray val (dv); + + Complex *ptr = val.fortran_vec (); + + float *ppi = static_cast (pi); + + for (mwIndex i = 0; i < nel; i++) + ptr[i] = Complex (ppr[i], ppi[i]); + + retval = val; + } + else + { + NDArray val (dv); + + double *ptr = val.fortran_vec (); + + for (mwIndex i = 0; i < nel; i++) + ptr[i] = ppr[i]; + + retval = val; + } + } + break; case mxDOUBLE_CLASS: - { - mwSize nel = get_number_of_elements (); - - double *ppr = static_cast (pr); - - if (pi) - { - ComplexNDArray val (dv); - - Complex *ptr = val.fortran_vec (); - - double *ppi = static_cast (pi); - - for (mwIndex i = 0; i < nel; i++) - ptr[i] = Complex (ppr[i], ppi[i]); - - retval = val; - } - else - { - NDArray val (dv); - - double *ptr = val.fortran_vec (); - - for (mwIndex i = 0; i < nel; i++) - ptr[i] = ppr[i]; - - retval = val; - } - } - break; + { + mwSize nel = get_number_of_elements (); + + double *ppr = static_cast (pr); + + if (pi) + { + ComplexNDArray val (dv); + + Complex *ptr = val.fortran_vec (); + + double *ppi = static_cast (pi); + + for (mwIndex i = 0; i < nel; i++) + ptr[i] = Complex (ppr[i], ppi[i]); + + retval = val; + } + else + { + NDArray val (dv); + + double *ptr = val.fortran_vec (); + + for (mwIndex i = 0; i < nel; i++) + ptr[i] = ppr[i]; + + retval = val; + } + } + break; case mxINT8_CLASS: - retval = int_to_ov (dv); - break; + retval = int_to_ov (dv); + break; case mxUINT8_CLASS: - retval = int_to_ov (dv); - break; + retval = int_to_ov (dv); + break; case mxINT16_CLASS: - retval = int_to_ov (dv); - break; + retval = int_to_ov (dv); + break; case mxUINT16_CLASS: - retval = int_to_ov (dv); - break; + retval = int_to_ov (dv); + break; case mxINT32_CLASS: - retval = int_to_ov (dv); - break; + retval = int_to_ov (dv); + break; case mxUINT32_CLASS: - retval = int_to_ov (dv); - break; + retval = int_to_ov (dv); + break; case mxINT64_CLASS: - retval = int_to_ov (dv); - break; + retval = int_to_ov (dv); + break; case mxUINT64_CLASS: - retval = int_to_ov (dv); - break; + retval = int_to_ov (dv); + break; default: - panic_impossible (); + panic_impossible (); } return retval; @@ -1477,7 +1477,7 @@ public: mxArray_sparse (mxClassID id_arg, int m, int n, int nzmax_arg, - mxComplexity flag = mxREAL) + mxComplexity flag = mxREAL) : mxArray_matlab (id_arg, m, n), nzmax (nzmax_arg) { pr = (calloc (nzmax, get_element_size ())); @@ -1531,73 +1531,73 @@ switch (get_class_id ()) { case mxLOGICAL_CLASS: - { - bool *ppr = static_cast (pr); - - SparseBoolMatrix val (get_m (), get_n (), - static_cast (nzmax)); - - for (mwIndex i = 0; i < nzmax; i++) - { - val.xdata(i) = ppr[i]; - val.xridx(i) = ir[i]; - } - - for (mwIndex i = 0; i < get_n () + 1; i++) - val.xcidx(i) = jc[i]; - - retval = val; - } - break; + { + bool *ppr = static_cast (pr); + + SparseBoolMatrix val (get_m (), get_n (), + static_cast (nzmax)); + + for (mwIndex i = 0; i < nzmax; i++) + { + val.xdata(i) = ppr[i]; + val.xridx(i) = ir[i]; + } + + for (mwIndex i = 0; i < get_n () + 1; i++) + val.xcidx(i) = jc[i]; + + retval = val; + } + break; case mxSINGLE_CLASS: - error ("single precision sparse data type not supported"); - break; + error ("single precision sparse data type not supported"); + break; case mxDOUBLE_CLASS: - { - if (pi) - { - double *ppr = static_cast (pr); - double *ppi = static_cast (pi); - - SparseComplexMatrix val (get_m (), get_n (), - static_cast (nzmax)); - - for (mwIndex i = 0; i < nzmax; i++) - { - val.xdata(i) = Complex (ppr[i], ppi[i]); - val.xridx(i) = ir[i]; - } - - for (mwIndex i = 0; i < get_n () + 1; i++) - val.xcidx(i) = jc[i]; - - retval = val; - } - else - { - double *ppr = static_cast (pr); - - SparseMatrix val (get_m (), get_n (), - static_cast (nzmax)); - - for (mwIndex i = 0; i < nzmax; i++) - { - val.xdata(i) = ppr[i]; - val.xridx(i) = ir[i]; - } - - for (mwIndex i = 0; i < get_n () + 1; i++) - val.xcidx(i) = jc[i]; - - retval = val; - } - } - break; + { + if (pi) + { + double *ppr = static_cast (pr); + double *ppi = static_cast (pi); + + SparseComplexMatrix val (get_m (), get_n (), + static_cast (nzmax)); + + for (mwIndex i = 0; i < nzmax; i++) + { + val.xdata(i) = Complex (ppr[i], ppi[i]); + val.xridx(i) = ir[i]; + } + + for (mwIndex i = 0; i < get_n () + 1; i++) + val.xcidx(i) = jc[i]; + + retval = val; + } + else + { + double *ppr = static_cast (pr); + + SparseMatrix val (get_m (), get_n (), + static_cast (nzmax)); + + for (mwIndex i = 0; i < nzmax; i++) + { + val.xdata(i) = ppr[i]; + val.xridx(i) = ir[i]; + } + + for (mwIndex i = 0; i < get_n () + 1; i++) + val.xcidx(i) = jc[i]; + + retval = val; + } + } + break; default: - panic_impossible (); + panic_impossible (); } return retval; @@ -1642,7 +1642,7 @@ public: mxArray_struct (mwSize ndims_arg, const mwSize *dims_arg, int num_keys_arg, - const char **keys) + const char **keys) : mxArray_matlab (mxSTRUCT_CLASS, ndims_arg, dims_arg), nfields (num_keys_arg), fields (static_cast (calloc (nfields, sizeof (char *)))), data (static_cast (calloc (nfields * get_number_of_elements (), sizeof (mxArray *)))) @@ -1695,44 +1695,44 @@ if (valid_key (key)) { - nfields++; - - fields = static_cast (mxRealloc (fields, nfields * sizeof (char *))); - - if (fields) - { - fields[nfields-1] = strsave (key); - - mwSize nel = get_number_of_elements (); - - mwSize ntot = nfields * nel; - - mxArray **new_data = static_cast (malloc (ntot * sizeof (mxArray *))); - - if (new_data) - { - mwIndex j = 0; - mwIndex k = 0; - mwIndex n = 0; - - for (mwIndex i = 0; i < ntot; i++) - { - if (++n == nfields) - { - new_data[j++] = 0; - n = 0; - } - else - new_data[j++] = data[k++]; - } - - mxFree (data); - - data = new_data; - - retval = nfields - 1; - } - } + nfields++; + + fields = static_cast (mxRealloc (fields, nfields * sizeof (char *))); + + if (fields) + { + fields[nfields-1] = strsave (key); + + mwSize nel = get_number_of_elements (); + + mwSize ntot = nfields * nel; + + mxArray **new_data = static_cast (malloc (ntot * sizeof (mxArray *))); + + if (new_data) + { + mwIndex j = 0; + mwIndex k = 0; + mwIndex n = 0; + + for (mwIndex i = 0; i < ntot; i++) + { + if (++n == nfields) + { + new_data[j++] = 0; + n = 0; + } + else + new_data[j++] = data[k++]; + } + + mxFree (data); + + data = new_data; + + retval = nfields - 1; + } + } } return retval; @@ -1742,47 +1742,47 @@ { if (key_num >= 0 && key_num < nfields) { - mwSize nel = get_number_of_elements (); - - mwSize ntot = nfields * nel; - - int new_nfields = nfields - 1; - - char **new_fields = static_cast (malloc (new_nfields * sizeof (char *))); - - mxArray **new_data = static_cast (malloc (new_nfields * nel * sizeof (mxArray *))); - - for (int i = 0; i < key_num; i++) - new_fields[i] = fields[i]; - - for (int i = key_num + 1; i < nfields; i++) - new_fields[i-1] = fields[i]; - - if (new_nfields > 0) - { - mwIndex j = 0; - mwIndex k = 0; - mwIndex n = 0; - - for (mwIndex i = 0; i < ntot; i++) - { - if (n == key_num) - k++; - else - new_data[j++] = data[k++]; - - if (++n == nfields) - n = 0; - } - } - - nfields = new_nfields; - - mxFree (fields); - mxFree (data); - - fields = new_fields; - data = new_data; + mwSize nel = get_number_of_elements (); + + mwSize ntot = nfields * nel; + + int new_nfields = nfields - 1; + + char **new_fields = static_cast (malloc (new_nfields * sizeof (char *))); + + mxArray **new_data = static_cast (malloc (new_nfields * nel * sizeof (mxArray *))); + + for (int i = 0; i < key_num; i++) + new_fields[i] = fields[i]; + + for (int i = key_num + 1; i < nfields; i++) + new_fields[i-1] = fields[i]; + + if (new_nfields > 0) + { + mwIndex j = 0; + mwIndex k = 0; + mwIndex n = 0; + + for (mwIndex i = 0; i < ntot; i++) + { + if (n == key_num) + k++; + else + new_data[j++] = data[k++]; + + if (++n == nfields) + n = 0; + } + } + + nfields = new_nfields; + + mxFree (fields); + mxFree (data); + + fields = new_fields; + data = new_data; } } @@ -1807,11 +1807,11 @@ for (int i = 0; i < nfields; i++) { - if (! strcmp (key, fields[i])) - { - retval = i; - break; - } + if (! strcmp (key, fields[i])) + { + retval = i; + break; + } } return retval; @@ -1835,15 +1835,15 @@ for (int i = 0; i < nfields; i++) { - Cell c (dv); - - octave_value *p = c.fortran_vec (); - - mwIndex k = 0; - for (mwIndex j = i; j < ntot; j += nfields) - p[k++] = mxArray::as_octave_value (data[j]); - - m.assign (keys[i], c); + Cell c (dv); + + octave_value *p = c.fortran_vec (); + + mwIndex k = 0; + for (mwIndex j = i; j < ntot; j += nfields) + p[k++] = mxArray::as_octave_value (data[j]); + + m.assign (keys[i], c); } return m; @@ -1869,8 +1869,8 @@ for (mwIndex i = 0; i < nel * nfields; i++) { - mxArray *ptr = val.data[i]; - data[i] = ptr ? ptr->clone () : 0; + mxArray *ptr = val.data[i]; + data[i] = ptr ? ptr->clone () : 0; } } }; @@ -1946,8 +1946,8 @@ for (mwIndex i = 0; i < nel; i++) { - mxArray *ptr = val.data[i]; - data[i] = ptr ? ptr->clone () : 0; + mxArray *ptr = val.data[i]; + data[i] = ptr ? ptr->clone () : 0; } } }; @@ -2037,12 +2037,12 @@ mxArray *new_val = rep->mutate (); if (new_val) - { - delete rep; - rep = new_val->rep; - new_val->rep = 0; - delete new_val; - } + { + delete rep; + rep = new_val->rep; + new_val->rep = 0; + delete new_val; + } } } @@ -2070,15 +2070,15 @@ { if (! fname) { - octave_function *fcn = octave_call_stack::current (); - - if (fcn) - { - std::string nm = fcn->name (); - fname = mxArray::strsave (nm.c_str ()); - } - else - fname = mxArray::strsave ("unknown"); + octave_function *fcn = octave_call_stack::current (); + + if (fcn) + { + std::string nm = fcn->name (); + fname = mxArray::strsave (nm.c_str ()); + } + else + fname = mxArray::strsave ("unknown"); } return fname; @@ -2091,14 +2091,14 @@ // We can't use mex::free here because it modifies memlist. for (std::set::iterator p = context->memlist.begin (); - p != context->memlist.end (); p++) + p != context->memlist.end (); p++) xfree (*p); context->memlist.clear (); // We can't use mex::free_value here because it modifies arraylist. for (std::set::iterator p = context->arraylist.begin (); - p != context->arraylist.end (); p++) + p != context->arraylist.end (); p++) delete *p; context->arraylist.clear (); @@ -2111,12 +2111,12 @@ if (! ptr) { - // FIXME -- could use "octave_new_handler();" instead - - error ("%s: failed to allocate %d bytes of memory", - function_name (), n); - - abort (); + // FIXME -- could use "octave_new_handler();" instead + + error ("%s: failed to allocate %d bytes of memory", + function_name (), n); + + abort (); } global_mark (ptr); @@ -2163,23 +2163,23 @@ if (ptr) { - v = ::realloc (ptr, n); - - std::set::iterator p = memlist.find (ptr); - - if (v && p != memlist.end ()) - { - memlist.erase (p); - memlist.insert (v); - } - - p = global_memlist.find (ptr); - - if (v && p != global_memlist.end ()) - { - global_memlist.erase (p); - global_memlist.insert (v); - } + v = ::realloc (ptr, n); + + std::set::iterator p = memlist.find (ptr); + + if (v && p != memlist.end ()) + { + memlist.erase (p); + memlist.insert (v); + } + + p = global_memlist.find (ptr); + + if (v && p != global_memlist.end ()) + { + global_memlist.erase (p); + global_memlist.insert (v); + } } else v = malloc (n); @@ -2192,25 +2192,25 @@ { if (ptr) { - unmark (ptr); - - std::set::iterator p = global_memlist.find (ptr); - - if (p != global_memlist.end ()) - { - global_memlist.erase (p); - - xfree (ptr); - } - else - { - p = foreign_memlist.find (ptr); - - if (p != foreign_memlist.end ()) - foreign_memlist.erase (p); - else - warning ("mxFree: skipping memory not allocated by mxMalloc, mxCalloc, or mxRealloc"); - } + unmark (ptr); + + std::set::iterator p = global_memlist.find (ptr); + + if (p != global_memlist.end ()) + { + global_memlist.erase (p); + + xfree (ptr); + } + else + { + p = foreign_memlist.find (ptr); + + if (p != foreign_memlist.end ()) + foreign_memlist.erase (p); + else + warning ("mxFree: skipping memory not allocated by mxMalloc, mxCalloc, or mxRealloc"); + } } } @@ -2294,9 +2294,9 @@ if (p != arraylist.end ()) { - inlist = true; - arraylist.erase (p); - delete ptr; + inlist = true; + arraylist.erase (p); + delete ptr; } #ifdef DEBUG else @@ -2559,7 +2559,7 @@ mxArray * mxCreateNumericArray (mwSize ndims, const mwSize *dims, mxClassID class_id, - mxComplexity flag) + mxComplexity flag) { return maybe_mark_array (new mxArray (class_id, ndims, dims, flag)); } @@ -2802,8 +2802,8 @@ mxSetDimensions (mxArray *ptr, const mwSize *dims, mwSize ndims) { ptr->set_dimensions (static_cast ( - maybe_unmark (const_cast (dims))), - ndims); + maybe_unmark (const_cast (dims))), + ndims); } // Data extractors. @@ -3031,7 +3031,7 @@ octave_value_list call_mex (bool have_fmex, void *f, const octave_value_list& args, - int nargout_arg, octave_mex_function *curr_mex_fcn) + int nargout_arg, octave_mex_function *curr_mex_fcn) { // Use at least 1 for nargout since even for zero specified args, // still want to be able to return an ans. @@ -3065,20 +3065,20 @@ mex_context = &context; if (have_fmex) - { - fmex_fptr fcn = FCN_PTR_CAST (fmex_fptr, f); - - int tmp_nargout = nargout; - int tmp_nargin = nargin; - - fcn (tmp_nargout, argout, tmp_nargin, argin); - } + { + fmex_fptr fcn = FCN_PTR_CAST (fmex_fptr, f); + + int tmp_nargout = nargout; + int tmp_nargin = nargin; + + fcn (tmp_nargout, argout, tmp_nargin, argin); + } else - { - cmex_fptr fcn = FCN_PTR_CAST (cmex_fptr, f); - - fcn (nargout, argout, nargin, argin); - } + { + cmex_fptr fcn = FCN_PTR_CAST (cmex_fptr, f); + + fcn (nargout, argout, nargin, argin); + } } // Convert returned array entries back into octave values. @@ -3088,15 +3088,15 @@ if (! error_state) { if (nargout == 0 && argout[0]) - { - // We have something for ans. - nargout = 1; - } + { + // We have something for ans. + nargout = 1; + } retval.resize (nargout); for (int i = 0; i < nargout; i++) - retval(i) = mxArray::as_octave_value (argout[i]); + retval(i) = mxArray::as_octave_value (argout[i]); } // Clean up mex resources. @@ -3115,7 +3115,7 @@ int mexCallMATLAB (int nargout, mxArray *argout[], int nargin, mxArray *argin[], - const char *fname) + const char *fname) { octave_value_list args; @@ -3288,19 +3288,19 @@ bool base = ! strcmp (space, "base"); if (caller || base) - { - if (caller) - octave_call_stack::goto_caller_frame (); - else - octave_call_stack::goto_base_frame (); - - if (! error_state) - frame.add_fcn (octave_call_stack::pop); - - val = symbol_table::varval (name); - } + { + if (caller) + octave_call_stack::goto_caller_frame (); + else + octave_call_stack::goto_base_frame (); + + if (! error_state) + frame.add_fcn (octave_call_stack::pop); + + val = symbol_table::varval (name); + } else - mexErrMsgTxt ("mexGetVariable: symbol table does not exist"); + mexErrMsgTxt ("mexGetVariable: symbol table does not exist"); } if (val.is_defined ()) @@ -3346,19 +3346,19 @@ bool base = ! strcmp (space, "base"); if (caller || base) - { - if (caller) - octave_call_stack::goto_caller_frame (); - else - octave_call_stack::goto_base_frame (); - - if (! error_state) - frame.add_fcn (octave_call_stack::pop); - - symbol_table::varref (name) = mxArray::as_octave_value (ptr); - } + { + if (caller) + octave_call_stack::goto_caller_frame (); + else + octave_call_stack::goto_base_frame (); + + if (! error_state) + frame.add_fcn (octave_call_stack::pop); + + symbol_table::varref (name) = mxArray::as_octave_value (ptr); + } else - mexErrMsgTxt ("mexPutVariable: symbol table does not exist"); + mexErrMsgTxt ("mexPutVariable: symbol table does not exist"); } return 0; @@ -3433,9 +3433,9 @@ const char *fname = mexFunctionName (); if (mex_lock_count.find (fname) == mex_lock_count.end ()) - mex_lock_count[fname] = 1; + mex_lock_count[fname] = 1; else - mex_lock_count[fname]++; + mex_lock_count[fname]++; mlock (); } @@ -3446,7 +3446,7 @@ { bool ret = set_property_in_handle (handle, property, mxArray::as_octave_value (val), - "mexSet"); + "mexSet"); return (ret ? 0 : 1); } @@ -3460,15 +3460,15 @@ std::map::iterator p = mex_lock_count.find (fname); if (p != mex_lock_count.end ()) - { - int count = --mex_lock_count[fname]; - - if (count == 0) - { - munlock (fname); - - mex_lock_count.erase (p); - } - } + { + int count = --mex_lock_count[fname]; + + if (count == 0) + { + munlock (fname); + + mex_lock_count.erase (p); + } + } } } diff --git a/src/oct-fstrm.cc b/src/oct-fstrm.cc --- a/src/oct-fstrm.cc +++ b/src/oct-fstrm.cc @@ -33,14 +33,14 @@ octave_stream octave_fstream::create (const std::string& nm_arg, std::ios::openmode arg_md, - oct_mach_info::float_format ff) + oct_mach_info::float_format ff) { return octave_stream (new octave_fstream (nm_arg, arg_md, ff)); } octave_fstream::octave_fstream (const std::string& nm_arg, - std::ios::openmode arg_md, - oct_mach_info::float_format ff) + std::ios::openmode arg_md, + oct_mach_info::float_format ff) : octave_base_stream (arg_md, ff), nm (nm_arg) { diff --git a/src/oct-hist.cc b/src/oct-hist.cc --- a/src/oct-hist.cc +++ b/src/oct-hist.cc @@ -84,7 +84,7 @@ if (file.empty ()) file = file_ops::concat (octave_env::get_home_directory (), - ".octave_hist"); + ".octave_hist"); return file; } @@ -104,7 +104,7 @@ int val; if (sscanf (env_size.c_str (), "%d", &val) == 1) - size = val > 0 ? val : 0; + size = val > 0 ? val : 0; } return size; @@ -149,41 +149,41 @@ std::string option = argv[i]; if (option == "-r" || option == "-w" || option == "-a" - || option == "-n") - { - if (i < argc - 1) - command_history::set_file (argv[i+1]); + || option == "-n") + { + if (i < argc - 1) + command_history::set_file (argv[i+1]); - if (option == "-a") - // Append `new' lines to file. - command_history::append (); + if (option == "-a") + // Append `new' lines to file. + command_history::append (); - else if (option == "-w") - // Write entire history. - command_history::write (); + else if (option == "-w") + // Write entire history. + command_history::write (); - else if (option == "-r") - // Read entire file. - command_history::read (); + else if (option == "-r") + // Read entire file. + command_history::read (); - else if (option == "-n") - // Read `new' history from file. - command_history::read_range (); + else if (option == "-n") + // Read `new' history from file. + command_history::read_range (); - else - panic_impossible (); + else + panic_impossible (); - return; - } + return; + } else if (argv[i] == "-q") - numbered_output = 0; + numbered_output = 0; else if (argv[i] == "--") - { - i++; - break; - } + { + i++; + break; + } else - break; + break; } int limit = -1; @@ -192,16 +192,16 @@ { if (sscanf (argv[i].c_str (), "%d", &limit) != 1) { - if (argv[i][0] == '-') - error ("history: unrecognized option `%s'", argv[i].c_str ()); - else - error ("history: bad non-numeric arg `%s'", argv[i].c_str ()); + if (argv[i][0] == '-') + error ("history: unrecognized option `%s'", argv[i].c_str ()); + else + error ("history: bad non-numeric arg `%s'", argv[i].c_str ()); - return; + return; } if (limit < 0) - limit = -limit; + limit = -limit; } string_vector hlist = command_history::list (limit, numbered_output); @@ -228,21 +228,21 @@ while (stream.get (c)) { if (lindex + 2 >= line_len) - { - char *tmp_line = new char [line_len += 128]; - strcpy (tmp_line, line); - delete [] line; - line = tmp_line; - } + { + char *tmp_line = new char [line_len += 128]; + strcpy (tmp_line, line); + delete [] line; + line = tmp_line; + } if (c == '\n') - { - line[lindex++] = '\n'; - line[lindex++] = '\0'; - return line; - } + { + line[lindex++] = '\n'; + line[lindex++] = '\0'; + return line; + } else - line[lindex++] = c; + line[lindex++] = c; } if (! lindex) @@ -282,24 +282,24 @@ int len = hlist.length (); if (len > 0) - { - int i = len - 1; + { + int i = len - 1; - std::string histent = command_history::get_entry (i); + std::string histent = command_history::get_entry (i); - if (! histent.empty ()) - { - std::string cmd = command; + if (! histent.empty ()) + { + std::string cmd = command; - int cmd_len = cmd.length (); + int cmd_len = cmd.length (); - if (cmd[cmd_len - 1] == '\n') - cmd.resize (cmd_len - 1); + if (cmd[cmd_len - 1] == '\n') + cmd.resize (cmd_len - 1); - if (! cmd.empty ()) - command_history::replace_entry (i, cmd); - } - } + if (! cmd.empty ()) + command_history::replace_entry (i, cmd); + } + } } } @@ -311,18 +311,18 @@ std::string tmp = line; int len = tmp.length (); - + if (len > 0 && tmp[len-1] == '\n') - tmp.resize (len - 1); + tmp.resize (len - 1); if (! tmp.empty ()) - command_history::add (tmp); + command_history::add (tmp); } } static std::string mk_tmp_hist_file (int argc, const string_vector& argv, - int insert_curr, const char *warn_for) + int insert_curr, const char *warn_for) { std::string retval; @@ -353,23 +353,23 @@ if (argc == 3) { if (sscanf (argv[1].c_str (), "%d", &hist_beg) != 1 - || sscanf (argv[2].c_str (), "%d", &hist_end) != 1) - usage_error = 1; + || sscanf (argv[2].c_str (), "%d", &hist_end) != 1) + usage_error = 1; else - { - hist_beg--; - hist_end--; - } + { + hist_beg--; + hist_end--; + } } else if (argc == 2) { if (sscanf (argv[1].c_str (), "%d", &hist_beg) != 1) - usage_error = 1; + usage_error = 1; else - { - hist_beg--; - hist_end = hist_beg; - } + { + hist_beg--; + hist_end = hist_beg; + } } if (hist_beg < 0 || hist_end < 0 || hist_beg > hist_count @@ -400,19 +400,19 @@ if (! file) { error ("%s: couldn't open temporary file `%s'", warn_for, - name.c_str ()); + name.c_str ()); return retval; } if (reverse) { for (int i = hist_end; i >= hist_beg; i--) - file << hlist[i] << "\n"; + file << hlist[i] << "\n"; } else { for (int i = hist_beg; i <= hist_end; i++) - file << hlist[i] << "\n"; + file << hlist[i] << "\n"; } file.close (); @@ -462,18 +462,18 @@ // Skip blank lines. if (line[0] == '\n') - { - delete [] line; - continue; - } + { + delete [] line; + continue; + } if (first) - { - first = 0; - edit_history_repl_hist (line); - } + { + first = 0; + edit_history_repl_hist (line); + } else - edit_history_add_hist (line); + edit_history_add_hist (line); } file.close (); diff --git a/src/oct-lvalue.cc b/src/oct-lvalue.cc --- a/src/oct-lvalue.cc +++ b/src/oct-lvalue.cc @@ -46,7 +46,7 @@ void octave_lvalue::set_index (const std::string& t, - const std::list& i) + const std::list& i) { if (idx.empty ()) { @@ -90,7 +90,7 @@ { octave_value_list t = val->subsref (type, idx, 1); if (t.length () > 0) - retval = t(0); + retval = t(0); } } } diff --git a/src/oct-map.cc b/src/oct-map.cc --- a/src/oct-map.cc +++ b/src/oct-map.cc @@ -39,11 +39,11 @@ if (key_vals.is_cellstr ()) { for (octave_idx_type i = 0; i < key_vals.numel (); i++) - { - std::string k = key_vals(i).string_value (); - map[k] = c; - key_list.push_back (k); - } + { + std::string k = key_vals(i).string_value (); + map[k] = c; + key_list.push_back (k); + } } else error ("Octave_map: expecting keys to be cellstr"); @@ -59,7 +59,7 @@ Cell tmp = contents (pa).squeeze (); if (error_state) - break; + break; retval.assign (key (pa), tmp); } @@ -87,7 +87,7 @@ Cell tmp = contents (pa).permute (vec, inv); if (error_state) - break; + break; retval.assign (key (pa), tmp); } @@ -136,7 +136,7 @@ std::string Octave_map::stringfield (const std::string& k, - const std::string& def_val) const + const std::string& def_val) const { std::string retval = def_val; @@ -196,7 +196,7 @@ if (new_dims != dims ()) { for (const_iterator p = begin (); p != end (); p++) - retval.assign (key(p), contents(p).reshape (new_dims)); + retval.assign (key(p), contents(p).reshape (new_dims)); retval.dimensions = new_dims; @@ -222,23 +222,23 @@ if (dv != dims ()) { if (nfields () == 0) - dimensions = dv; + dimensions = dv; else - { - for (const_iterator p = begin (); p != end (); p++) - { - Cell tmp = contents(p); + { + for (const_iterator p = begin (); p != end (); p++) + { + Cell tmp = contents(p); - if (fill) - tmp.resize (dv, Cell::resize_fill_value ()); - else - tmp.resize (dv); + if (fill) + tmp.resize (dv, Cell::resize_fill_value ()); + else + tmp.resize (dv); - dimensions = dv; + dimensions = dv; - assign (key(p), tmp); - } - } + assign (key(p), tmp); + } + } } } @@ -250,18 +250,18 @@ if (nfields () == rb.nfields ()) { for (const_iterator pa = begin (); pa != end (); pa++) - { - const_iterator pb = rb.seek (key(pa)); + { + const_iterator pb = rb.seek (key(pa)); - if (pb == rb.end ()) - { - error ("field name mismatch in structure concatenation"); - break; - } - - retval.assign (key(pa), - contents(pa).insert (rb.contents(pb), ra_idx)); - } + if (pb == rb.end ()) + { + error ("field name mismatch in structure concatenation"); + break; + } + + retval.assign (key(pa), + contents(pa).insert (rb.contents(pb), ra_idx)); + } // Preserve order of keys. retval.key_list = key_list; @@ -271,16 +271,16 @@ dim_vector dv = dims (); if (dv.all_zero ()) - retval = rb; + retval = rb; else - { - dv = rb.dims (); + { + dv = rb.dims (); - if (dv.all_zero ()) - retval = *this; - else - error ("invalid structure concatenation"); - } + if (dv.all_zero ()) + retval = *this; + else + error ("invalid structure concatenation"); + } } return retval; @@ -315,16 +315,16 @@ octave_idx_type b_len = b_keys.length (); if (a_len == b_len) - { - for (octave_idx_type i = 0; i < a_len; i++) - { - if (a_keys[i] != b_keys[i]) - goto done; - } + { + for (octave_idx_type i = 0; i < a_len; i++) + { + if (a_keys[i] != b_keys[i]) + goto done; + } - keys = a_keys; - retval = true; - } + keys = a_keys; + retval = true; + } } done: @@ -340,17 +340,17 @@ if (len > 0) { for (octave_idx_type i = 0; i < len; i++) - { - std::string k = t_keys[i]; + { + std::string k = t_keys[i]; - map[k] = contents(k).delete_elements (idx); + map[k] = contents(k).delete_elements (idx); - if (error_state) - break; - } + if (error_state) + break; + } if (!error_state) - dimensions = contents(t_keys[0]).dims(); + dimensions = contents(t_keys[0]).dims(); } return *this; @@ -366,31 +366,31 @@ octave_idx_type len = t_keys.length (); if (len == 0) - { - Cell tmp_lhs (dims ()); - Cell tmp_rhs (rhs.dims ()); + { + Cell tmp_lhs (dims ()); + Cell tmp_rhs (rhs.dims ()); - tmp_lhs.assign (idx, tmp_rhs, Matrix ()); + tmp_lhs.assign (idx, tmp_rhs, Matrix ()); - if (! error_state) - resize (tmp_lhs.dims ()); - else - error ("size mismatch in structure assignment"); - } + if (! error_state) + resize (tmp_lhs.dims ()); + else + error ("size mismatch in structure assignment"); + } else - { - for (octave_idx_type i = 0; i < len; i++) - { - std::string k = t_keys[i]; + { + for (octave_idx_type i = 0; i < len; i++) + { + std::string k = t_keys[i]; - Cell t_rhs = rhs.contents (k); + Cell t_rhs = rhs.contents (k); - assign (idx, k, t_rhs); + assign (idx, k, t_rhs); - if (error_state) - break; - } - } + if (error_state) + break; + } + } } else error ("field name mismatch in structure assignment"); @@ -400,7 +400,7 @@ Octave_map& Octave_map::assign (const octave_value_list& idx, const std::string& k, - const Cell& rhs) + const Cell& rhs) { Cell tmp; @@ -416,12 +416,12 @@ dim_vector tmp_dims = tmp.dims (); if (tmp_dims != dimensions) - { - for (iterator p = begin (); p != end (); p++) - contents(p).resize (tmp_dims, Cell::resize_fill_value ()); + { + for (iterator p = begin (); p != end (); p++) + contents(p).resize (tmp_dims, Cell::resize_fill_value ()); dimensions = tmp_dims; - } + } maybe_add_to_key_list (k); @@ -447,13 +447,13 @@ dim_vector dv = dims (); if (dv.all_ones ()) - { - maybe_add_to_key_list (k); + { + maybe_add_to_key_list (k); - map[k] = Cell (rhs); - } + map[k] = Cell (rhs); + } else - error ("invalid structure assignment"); + error ("invalid structure assignment"); } return *this; @@ -473,13 +473,13 @@ else { if (dims () == rhs.dims ()) - { - maybe_add_to_key_list (k); + { + maybe_add_to_key_list (k); - map[k] = rhs; - } + map[k] = rhs; + } else - error ("invalid structure assignment"); + error ("invalid structure assignment"); } return *this; diff --git a/src/oct-obj.cc b/src/oct-obj.cc --- a/src/oct-obj.cc +++ b/src/oct-obj.cc @@ -124,7 +124,7 @@ octave_value_list octave_value_list::splice (octave_idx_type offset, octave_idx_type rep_length, - const octave_value_list& lst) const + const octave_value_list& lst) const { octave_value_list retval; @@ -133,10 +133,10 @@ if (offset < 0 || offset >= len) { if (! (rep_length == 0 && offset == len)) - { - error ("octave_value_list::splice: invalid OFFSET"); - return retval; - } + { + error ("octave_value_list::splice: invalid OFFSET"); + return retval; + } } if (rep_length < 0 || rep_length + offset > len) @@ -223,14 +223,14 @@ octave_idx_type total_nr = 0; for (octave_idx_type i = 0; i < len; i++) - { - // An empty std::string ("") has zero columns and zero rows (a - // change that was made for Matlab contemptibility. + { + // An empty std::string ("") has zero columns and zero rows (a + // change that was made for Matlab contemptibility. - octave_idx_type n = elem(i).rows (); + octave_idx_type n = elem(i).rows (); - total_nr += n ? n : 1; - } + total_nr += n ? n : 1; + } octave_idx_type k = 0; if (! fcn_name.empty ()) @@ -243,19 +243,19 @@ argv.resize (total_nr); for (octave_idx_type i = 0; i < len; i++) - { - octave_idx_type nr = elem(i).rows (); + { + octave_idx_type nr = elem(i).rows (); - if (nr < 2) - argv[k++] = elem(i).string_value (); - else - { - string_vector tmp = elem(i).all_strings (); + if (nr < 2) + argv[k++] = elem(i).string_value (); + else + { + string_vector tmp = elem(i).all_strings (); - for (octave_idx_type j = 0; j < nr; j++) - argv[k++] = tmp[j]; - } - } + for (octave_idx_type j = 0; j < nr; j++) + argv[k++] = tmp[j]; + } + } } else error ("%s: expecting all arguments to be strings", fcn_name.c_str ()); diff --git a/src/oct-parse.yy b/src/oct-parse.yy --- a/src/oct-parse.yy +++ b/src/oct-parse.yy @@ -186,12 +186,12 @@ // Build a binary expression. static tree_expression * make_binary_op (int op, tree_expression *op1, token *tok_val, - tree_expression *op2); + tree_expression *op2); // Build a boolean expression. static tree_expression * make_boolean_op (int op, tree_expression *op1, token *tok_val, - tree_expression *op2); + tree_expression *op2); // Build a prefix expression. static tree_expression * @@ -204,31 +204,31 @@ // Build an unwind-protect command. static tree_command * make_unwind_command (token *unwind_tok, tree_statement_list *body, - tree_statement_list *cleanup, token *end_tok, - octave_comment_list *lc, octave_comment_list *mc); + tree_statement_list *cleanup, token *end_tok, + octave_comment_list *lc, octave_comment_list *mc); // Build a try-catch command. static tree_command * make_try_command (token *try_tok, tree_statement_list *body, - tree_statement_list *cleanup, token *end_tok, - octave_comment_list *lc, octave_comment_list *mc); + tree_statement_list *cleanup, token *end_tok, + octave_comment_list *lc, octave_comment_list *mc); // Build a while command. static tree_command * make_while_command (token *while_tok, tree_expression *expr, - tree_statement_list *body, token *end_tok, - octave_comment_list *lc); + tree_statement_list *body, token *end_tok, + octave_comment_list *lc); // Build a do-until command. static tree_command * make_do_until_command (token *until_tok, tree_statement_list *body, - tree_expression *expr, octave_comment_list *lc); + tree_expression *expr, octave_comment_list *lc); // Build a for command. static tree_command * make_for_command (token *for_tok, tree_argument_list *lhs, - tree_expression *expr, tree_statement_list *body, - token *end_tok, octave_comment_list *lc); + tree_expression *expr, tree_statement_list *body, + token *end_tok, octave_comment_list *lc); // Build a break command. static tree_command * @@ -249,28 +249,28 @@ // Finish an if command. static tree_if_command * finish_if_command (token *if_tok, tree_if_command_list *list, - token *end_tok, octave_comment_list *lc); + token *end_tok, octave_comment_list *lc); // Build an elseif clause. static tree_if_clause * make_elseif_clause (token *elseif_tok, tree_expression *expr, - tree_statement_list *list, octave_comment_list *lc); + tree_statement_list *list, octave_comment_list *lc); // Finish a switch command. static tree_switch_command * finish_switch_command (token *switch_tok, tree_expression *expr, - tree_switch_case_list *list, token *end_tok, - octave_comment_list *lc); + tree_switch_case_list *list, token *end_tok, + octave_comment_list *lc); // Build a switch case. static tree_switch_case * make_switch_case (token *case_tok, tree_expression *expr, - tree_statement_list *list, octave_comment_list *lc); + tree_statement_list *list, octave_comment_list *lc); // Build an assignment to a variable. static tree_expression * make_assign_op (int op, tree_argument_list *lhs, token *eq_tok, - tree_expression *rhs); + tree_expression *rhs); // Define a script. static void @@ -279,7 +279,7 @@ // Begin defining a function. static octave_user_function * start_function (tree_parameter_list *param_list, tree_statement_list *body, - tree_statement *end_function); + tree_statement *end_function); // Create a no-op statement for end_function. static tree_statement * @@ -292,7 +292,7 @@ // Finish defining a function. static tree_function_def * finish_function (tree_parameter_list *ret_list, - octave_user_function *fcn, octave_comment_list *lc); + octave_user_function *fcn, octave_comment_list *lc); // Reset state after parsing function. static void @@ -301,7 +301,7 @@ // Make an index expression. static tree_index_expression * make_index_expression (tree_expression *expr, - tree_argument_list *args, char type); + tree_argument_list *args, char type); // Make an indirect reference expression. static tree_index_expression * @@ -341,7 +341,7 @@ // Append a statement to an existing statement list. static tree_statement_list * append_statement_list (tree_statement_list *list, char sep, - tree_statement *stmt, bool warn_missing_semi); + tree_statement *stmt, bool warn_missing_semi); // Finish building a statement. template @@ -360,13 +360,13 @@ yyerrok; \ if (! symtab_context.empty ()) \ { \ - symbol_table::set_scope (symtab_context.top ()); \ - symtab_context.pop (); \ + symbol_table::set_scope (symtab_context.top ()); \ + symtab_context.pop (); \ } \ if (interactive || forced_interactive) \ - YYACCEPT; \ + YYACCEPT; \ else \ - YYABORT; \ + YYABORT; \ } \ while (0) @@ -532,70 +532,70 @@ // Statements and statement lists // ============================== -input : input1 - { - global_command = $1; - promptflag = 1; - YYACCEPT; - } - | function_file - { - YYACCEPT; - } - | simple_list parse_error - { ABORT_PARSE; } - | parse_error - { ABORT_PARSE; } - ; - -input1 : '\n' - { $$ = 0; } - | END_OF_INPUT - { - parser_end_of_input = 1; - $$ = 0; - } - | simple_list - { $$ = $1; } - | simple_list '\n' - { $$ = $1; } - | simple_list END_OF_INPUT - { $$ = $1; } - ; - -simple_list : simple_list1 opt_sep_no_nl - { $$ = set_stmt_print_flag ($1, $2, false); } - ; - -simple_list1 : statement - { $$ = make_statement_list ($1); } - | simple_list1 sep_no_nl statement - { $$ = append_statement_list ($1, $2, $3, false); } - ; - -opt_list : // empty - { $$ = new tree_statement_list (); } - | list - { $$ = $1; } - ; - -list : list1 opt_sep - { $$ = set_stmt_print_flag ($1, $2, true); } - ; - -list1 : statement - { $$ = make_statement_list ($1); } - | list1 sep statement - { $$ = append_statement_list ($1, $2, $3, true); } - ; - -statement : expression - { $$ = make_statement ($1); } - | command - { $$ = make_statement ($1); } - | word_list_cmd - { $$ = make_statement ($1); } - ; +input : input1 + { + global_command = $1; + promptflag = 1; + YYACCEPT; + } + | function_file + { + YYACCEPT; + } + | simple_list parse_error + { ABORT_PARSE; } + | parse_error + { ABORT_PARSE; } + ; + +input1 : '\n' + { $$ = 0; } + | END_OF_INPUT + { + parser_end_of_input = 1; + $$ = 0; + } + | simple_list + { $$ = $1; } + | simple_list '\n' + { $$ = $1; } + | simple_list END_OF_INPUT + { $$ = $1; } + ; + +simple_list : simple_list1 opt_sep_no_nl + { $$ = set_stmt_print_flag ($1, $2, false); } + ; + +simple_list1 : statement + { $$ = make_statement_list ($1); } + | simple_list1 sep_no_nl statement + { $$ = append_statement_list ($1, $2, $3, false); } + ; + +opt_list : // empty + { $$ = new tree_statement_list (); } + | list + { $$ = $1; } + ; + +list : list1 opt_sep + { $$ = set_stmt_print_flag ($1, $2, true); } + ; + +list1 : statement + { $$ = make_statement_list ($1); } + | list1 sep statement + { $$ = append_statement_list ($1, $2, $3, true); } + ; + +statement : expression + { $$ = make_statement ($1); } + | command + { $$ = make_statement ($1); } + | word_list_cmd + { $$ = make_statement ($1); } + ; // ================= // Word-list command @@ -605,1022 +605,1022 @@ // the RHS of an assignment. But they are also not like commands (IF, // WHILE, etc. -word_list_cmd : identifier word_list - { $$ = make_index_expression ($1, $2, '('); } - ; - -word_list : string - { $$ = new tree_argument_list ($1); } - | word_list string - { - $1->append ($2); - $$ = $1; - } - ; +word_list_cmd : identifier word_list + { $$ = make_index_expression ($1, $2, '('); } + ; + +word_list : string + { $$ = new tree_argument_list ($1); } + | word_list string + { + $1->append ($2); + $$ = $1; + } + ; // =========== // Expressions // =========== -identifier : NAME - { - symbol_table::symbol_record *sr = $1->sym_rec (); - $$ = new tree_identifier (*sr, $1->line (), $1->column ()); - } - ; +identifier : NAME + { + symbol_table::symbol_record *sr = $1->sym_rec (); + $$ = new tree_identifier (*sr, $1->line (), $1->column ()); + } + ; superclass_identifier - : SUPERCLASSREF - { $$ = new tree_identifier ($1->line (), $1->column ()); } - ; - -meta_identifier : METAQUERY - { $$ = new tree_identifier ($1->line (), $1->column ()); } - ; - -string : DQ_STRING - { $$ = make_constant (DQ_STRING, $1); } - | SQ_STRING - { $$ = make_constant (SQ_STRING, $1); } - ; - -constant : NUM - { $$ = make_constant (NUM, $1); } - | IMAG_NUM - { $$ = make_constant (IMAG_NUM, $1); } - | string - { $$ = $1; } - ; - -matrix : '[' ']' - { - $$ = new tree_constant (octave_null_matrix::instance); - lexer_flags.looking_at_matrix_or_assign_lhs = false; - lexer_flags.pending_local_variables.clear (); - } - | '[' ';' ']' - { - $$ = new tree_constant (octave_null_matrix::instance); - lexer_flags.looking_at_matrix_or_assign_lhs = false; - lexer_flags.pending_local_variables.clear (); - } - | '[' ',' ']' - { - $$ = new tree_constant (octave_null_matrix::instance); - lexer_flags.looking_at_matrix_or_assign_lhs = false; - lexer_flags.pending_local_variables.clear (); - } - | '[' matrix_rows ']' - { - $$ = finish_matrix ($2); - lexer_flags.looking_at_matrix_or_assign_lhs = false; - lexer_flags.pending_local_variables.clear (); - } - ; - -matrix_rows : matrix_rows1 - { $$ = $1; } - | matrix_rows1 ';' // Ignore trailing semicolon. - { $$ = $1; } - ; - -matrix_rows1 : cell_or_matrix_row - { $$ = new tree_matrix ($1); } - | matrix_rows1 ';' cell_or_matrix_row - { - $1->append ($3); - $$ = $1; - } - ; - -cell : '{' '}' - { $$ = new tree_constant (octave_value (Cell ())); } - | '{' ';' '}' - { $$ = new tree_constant (octave_value (Cell ())); } - | '{' cell_rows '}' - { $$ = finish_cell ($2); } - ; - -cell_rows : cell_rows1 - { $$ = $1; } - | cell_rows1 ';' // Ignore trailing semicolon. - { $$ = $1; } - ; - -cell_rows1 : cell_or_matrix_row - { $$ = new tree_cell ($1); } - | cell_rows1 ';' cell_or_matrix_row - { - $1->append ($3); - $$ = $1; - } - ; + : SUPERCLASSREF + { $$ = new tree_identifier ($1->line (), $1->column ()); } + ; + +meta_identifier : METAQUERY + { $$ = new tree_identifier ($1->line (), $1->column ()); } + ; + +string : DQ_STRING + { $$ = make_constant (DQ_STRING, $1); } + | SQ_STRING + { $$ = make_constant (SQ_STRING, $1); } + ; + +constant : NUM + { $$ = make_constant (NUM, $1); } + | IMAG_NUM + { $$ = make_constant (IMAG_NUM, $1); } + | string + { $$ = $1; } + ; + +matrix : '[' ']' + { + $$ = new tree_constant (octave_null_matrix::instance); + lexer_flags.looking_at_matrix_or_assign_lhs = false; + lexer_flags.pending_local_variables.clear (); + } + | '[' ';' ']' + { + $$ = new tree_constant (octave_null_matrix::instance); + lexer_flags.looking_at_matrix_or_assign_lhs = false; + lexer_flags.pending_local_variables.clear (); + } + | '[' ',' ']' + { + $$ = new tree_constant (octave_null_matrix::instance); + lexer_flags.looking_at_matrix_or_assign_lhs = false; + lexer_flags.pending_local_variables.clear (); + } + | '[' matrix_rows ']' + { + $$ = finish_matrix ($2); + lexer_flags.looking_at_matrix_or_assign_lhs = false; + lexer_flags.pending_local_variables.clear (); + } + ; + +matrix_rows : matrix_rows1 + { $$ = $1; } + | matrix_rows1 ';' // Ignore trailing semicolon. + { $$ = $1; } + ; + +matrix_rows1 : cell_or_matrix_row + { $$ = new tree_matrix ($1); } + | matrix_rows1 ';' cell_or_matrix_row + { + $1->append ($3); + $$ = $1; + } + ; + +cell : '{' '}' + { $$ = new tree_constant (octave_value (Cell ())); } + | '{' ';' '}' + { $$ = new tree_constant (octave_value (Cell ())); } + | '{' cell_rows '}' + { $$ = finish_cell ($2); } + ; + +cell_rows : cell_rows1 + { $$ = $1; } + | cell_rows1 ';' // Ignore trailing semicolon. + { $$ = $1; } + ; + +cell_rows1 : cell_or_matrix_row + { $$ = new tree_cell ($1); } + | cell_rows1 ';' cell_or_matrix_row + { + $1->append ($3); + $$ = $1; + } + ; cell_or_matrix_row - : arg_list - { $$ = validate_matrix_row ($1); } - | arg_list ',' // Ignore trailing comma. - { $$ = validate_matrix_row ($1); } - ; - -fcn_handle : '@' FCN_HANDLE - { - $$ = make_fcn_handle ($2); - lexer_flags.looking_at_function_handle--; - } - ; - -anon_fcn_handle : '@' param_list statement - { $$ = make_anon_fcn_handle ($2, $3); } - ; - -primary_expr : identifier - { $$ = $1; } - | constant - { $$ = $1; } - | fcn_handle - { $$ = $1; } - | matrix - { $$ = $1; } - | cell - { $$ = $1; } - | meta_identifier - { $$ = $1; } - | superclass_identifier - { $$ = $1; } - | '(' expression ')' - { $$ = $2->mark_in_parens (); } - ; - -magic_colon : ':' - { - octave_value tmp (octave_value::magic_colon_t); - $$ = new tree_constant (tmp); - } - ; - -magic_tilde : EXPR_NOT - { - $$ = new tree_black_hole (); - } - ; - -arg_list : expression - { $$ = new tree_argument_list ($1); } - | magic_colon - { $$ = new tree_argument_list ($1); } - | magic_tilde - { $$ = new tree_argument_list ($1); } - | arg_list ',' magic_colon - { - $1->append ($3); - $$ = $1; - } - | arg_list ',' magic_tilde - { - $1->append ($3); - $$ = $1; - } - | arg_list ',' expression - { - $1->append ($3); - $$ = $1; - } - ; - -indirect_ref_op : '.' - { lexer_flags.looking_at_indirect_ref = true; } - ; - -postfix_expr : primary_expr - { $$ = $1; } - | postfix_expr '(' ')' - { $$ = make_index_expression ($1, 0, '('); } - | postfix_expr '(' arg_list ')' - { $$ = make_index_expression ($1, $3, '('); } - | postfix_expr '{' '}' - { $$ = make_index_expression ($1, 0, '{'); } - | postfix_expr '{' arg_list '}' - { $$ = make_index_expression ($1, $3, '{'); } - | postfix_expr PLUS_PLUS - { $$ = make_postfix_op (PLUS_PLUS, $1, $2); } - | postfix_expr MINUS_MINUS - { $$ = make_postfix_op (MINUS_MINUS, $1, $2); } - | postfix_expr QUOTE - { $$ = make_postfix_op (QUOTE, $1, $2); } - | postfix_expr TRANSPOSE - { $$ = make_postfix_op (TRANSPOSE, $1, $2); } - | postfix_expr indirect_ref_op STRUCT_ELT - { $$ = make_indirect_ref ($1, $3->text ()); } - | postfix_expr indirect_ref_op '(' expression ')' - { $$ = make_indirect_ref ($1, $4); } - ; - -prefix_expr : postfix_expr - { $$ = $1; } - | binary_expr - { $$ = $1; } - | PLUS_PLUS prefix_expr %prec UNARY - { $$ = make_prefix_op (PLUS_PLUS, $2, $1); } - | MINUS_MINUS prefix_expr %prec UNARY - { $$ = make_prefix_op (MINUS_MINUS, $2, $1); } - | EXPR_NOT prefix_expr %prec UNARY - { $$ = make_prefix_op (EXPR_NOT, $2, $1); } - | '+' prefix_expr %prec UNARY - { $$ = make_prefix_op ('+', $2, $1); } - | '-' prefix_expr %prec UNARY - { $$ = make_prefix_op ('-', $2, $1); } - ; - -binary_expr : prefix_expr POW prefix_expr - { $$ = make_binary_op (POW, $1, $2, $3); } - | prefix_expr EPOW prefix_expr - { $$ = make_binary_op (EPOW, $1, $2, $3); } - | prefix_expr '+' prefix_expr - { $$ = make_binary_op ('+', $1, $2, $3); } - | prefix_expr '-' prefix_expr - { $$ = make_binary_op ('-', $1, $2, $3); } - | prefix_expr '*' prefix_expr - { $$ = make_binary_op ('*', $1, $2, $3); } - | prefix_expr '/' prefix_expr - { $$ = make_binary_op ('/', $1, $2, $3); } - | prefix_expr EPLUS prefix_expr - { $$ = make_binary_op ('+', $1, $2, $3); } - | prefix_expr EMINUS prefix_expr - { $$ = make_binary_op ('-', $1, $2, $3); } - | prefix_expr EMUL prefix_expr - { $$ = make_binary_op (EMUL, $1, $2, $3); } - | prefix_expr EDIV prefix_expr - { $$ = make_binary_op (EDIV, $1, $2, $3); } - | prefix_expr LEFTDIV prefix_expr - { $$ = make_binary_op (LEFTDIV, $1, $2, $3); } - | prefix_expr ELEFTDIV prefix_expr - { $$ = make_binary_op (ELEFTDIV, $1, $2, $3); } - ; - -colon_expr : colon_expr1 - { $$ = finish_colon_expression ($1); } - ; - -colon_expr1 : prefix_expr - { $$ = new tree_colon_expression ($1); } - | colon_expr1 ':' prefix_expr - { - if (! ($$ = $1->append ($3))) - ABORT_PARSE; - } - ; - -simple_expr : colon_expr - { $$ = $1; } - | simple_expr LSHIFT simple_expr - { $$ = make_binary_op (LSHIFT, $1, $2, $3); } - | simple_expr RSHIFT simple_expr - { $$ = make_binary_op (RSHIFT, $1, $2, $3); } - | simple_expr EXPR_LT simple_expr - { $$ = make_binary_op (EXPR_LT, $1, $2, $3); } - | simple_expr EXPR_LE simple_expr - { $$ = make_binary_op (EXPR_LE, $1, $2, $3); } - | simple_expr EXPR_EQ simple_expr - { $$ = make_binary_op (EXPR_EQ, $1, $2, $3); } - | simple_expr EXPR_GE simple_expr - { $$ = make_binary_op (EXPR_GE, $1, $2, $3); } - | simple_expr EXPR_GT simple_expr - { $$ = make_binary_op (EXPR_GT, $1, $2, $3); } - | simple_expr EXPR_NE simple_expr - { $$ = make_binary_op (EXPR_NE, $1, $2, $3); } - | simple_expr EXPR_AND simple_expr - { $$ = make_binary_op (EXPR_AND, $1, $2, $3); } - | simple_expr EXPR_OR simple_expr - { $$ = make_binary_op (EXPR_OR, $1, $2, $3); } - | simple_expr EXPR_AND_AND simple_expr - { $$ = make_boolean_op (EXPR_AND_AND, $1, $2, $3); } - | simple_expr EXPR_OR_OR simple_expr - { $$ = make_boolean_op (EXPR_OR_OR, $1, $2, $3); } - ; + : arg_list + { $$ = validate_matrix_row ($1); } + | arg_list ',' // Ignore trailing comma. + { $$ = validate_matrix_row ($1); } + ; + +fcn_handle : '@' FCN_HANDLE + { + $$ = make_fcn_handle ($2); + lexer_flags.looking_at_function_handle--; + } + ; + +anon_fcn_handle : '@' param_list statement + { $$ = make_anon_fcn_handle ($2, $3); } + ; + +primary_expr : identifier + { $$ = $1; } + | constant + { $$ = $1; } + | fcn_handle + { $$ = $1; } + | matrix + { $$ = $1; } + | cell + { $$ = $1; } + | meta_identifier + { $$ = $1; } + | superclass_identifier + { $$ = $1; } + | '(' expression ')' + { $$ = $2->mark_in_parens (); } + ; + +magic_colon : ':' + { + octave_value tmp (octave_value::magic_colon_t); + $$ = new tree_constant (tmp); + } + ; + +magic_tilde : EXPR_NOT + { + $$ = new tree_black_hole (); + } + ; + +arg_list : expression + { $$ = new tree_argument_list ($1); } + | magic_colon + { $$ = new tree_argument_list ($1); } + | magic_tilde + { $$ = new tree_argument_list ($1); } + | arg_list ',' magic_colon + { + $1->append ($3); + $$ = $1; + } + | arg_list ',' magic_tilde + { + $1->append ($3); + $$ = $1; + } + | arg_list ',' expression + { + $1->append ($3); + $$ = $1; + } + ; + +indirect_ref_op : '.' + { lexer_flags.looking_at_indirect_ref = true; } + ; + +postfix_expr : primary_expr + { $$ = $1; } + | postfix_expr '(' ')' + { $$ = make_index_expression ($1, 0, '('); } + | postfix_expr '(' arg_list ')' + { $$ = make_index_expression ($1, $3, '('); } + | postfix_expr '{' '}' + { $$ = make_index_expression ($1, 0, '{'); } + | postfix_expr '{' arg_list '}' + { $$ = make_index_expression ($1, $3, '{'); } + | postfix_expr PLUS_PLUS + { $$ = make_postfix_op (PLUS_PLUS, $1, $2); } + | postfix_expr MINUS_MINUS + { $$ = make_postfix_op (MINUS_MINUS, $1, $2); } + | postfix_expr QUOTE + { $$ = make_postfix_op (QUOTE, $1, $2); } + | postfix_expr TRANSPOSE + { $$ = make_postfix_op (TRANSPOSE, $1, $2); } + | postfix_expr indirect_ref_op STRUCT_ELT + { $$ = make_indirect_ref ($1, $3->text ()); } + | postfix_expr indirect_ref_op '(' expression ')' + { $$ = make_indirect_ref ($1, $4); } + ; + +prefix_expr : postfix_expr + { $$ = $1; } + | binary_expr + { $$ = $1; } + | PLUS_PLUS prefix_expr %prec UNARY + { $$ = make_prefix_op (PLUS_PLUS, $2, $1); } + | MINUS_MINUS prefix_expr %prec UNARY + { $$ = make_prefix_op (MINUS_MINUS, $2, $1); } + | EXPR_NOT prefix_expr %prec UNARY + { $$ = make_prefix_op (EXPR_NOT, $2, $1); } + | '+' prefix_expr %prec UNARY + { $$ = make_prefix_op ('+', $2, $1); } + | '-' prefix_expr %prec UNARY + { $$ = make_prefix_op ('-', $2, $1); } + ; + +binary_expr : prefix_expr POW prefix_expr + { $$ = make_binary_op (POW, $1, $2, $3); } + | prefix_expr EPOW prefix_expr + { $$ = make_binary_op (EPOW, $1, $2, $3); } + | prefix_expr '+' prefix_expr + { $$ = make_binary_op ('+', $1, $2, $3); } + | prefix_expr '-' prefix_expr + { $$ = make_binary_op ('-', $1, $2, $3); } + | prefix_expr '*' prefix_expr + { $$ = make_binary_op ('*', $1, $2, $3); } + | prefix_expr '/' prefix_expr + { $$ = make_binary_op ('/', $1, $2, $3); } + | prefix_expr EPLUS prefix_expr + { $$ = make_binary_op ('+', $1, $2, $3); } + | prefix_expr EMINUS prefix_expr + { $$ = make_binary_op ('-', $1, $2, $3); } + | prefix_expr EMUL prefix_expr + { $$ = make_binary_op (EMUL, $1, $2, $3); } + | prefix_expr EDIV prefix_expr + { $$ = make_binary_op (EDIV, $1, $2, $3); } + | prefix_expr LEFTDIV prefix_expr + { $$ = make_binary_op (LEFTDIV, $1, $2, $3); } + | prefix_expr ELEFTDIV prefix_expr + { $$ = make_binary_op (ELEFTDIV, $1, $2, $3); } + ; + +colon_expr : colon_expr1 + { $$ = finish_colon_expression ($1); } + ; + +colon_expr1 : prefix_expr + { $$ = new tree_colon_expression ($1); } + | colon_expr1 ':' prefix_expr + { + if (! ($$ = $1->append ($3))) + ABORT_PARSE; + } + ; + +simple_expr : colon_expr + { $$ = $1; } + | simple_expr LSHIFT simple_expr + { $$ = make_binary_op (LSHIFT, $1, $2, $3); } + | simple_expr RSHIFT simple_expr + { $$ = make_binary_op (RSHIFT, $1, $2, $3); } + | simple_expr EXPR_LT simple_expr + { $$ = make_binary_op (EXPR_LT, $1, $2, $3); } + | simple_expr EXPR_LE simple_expr + { $$ = make_binary_op (EXPR_LE, $1, $2, $3); } + | simple_expr EXPR_EQ simple_expr + { $$ = make_binary_op (EXPR_EQ, $1, $2, $3); } + | simple_expr EXPR_GE simple_expr + { $$ = make_binary_op (EXPR_GE, $1, $2, $3); } + | simple_expr EXPR_GT simple_expr + { $$ = make_binary_op (EXPR_GT, $1, $2, $3); } + | simple_expr EXPR_NE simple_expr + { $$ = make_binary_op (EXPR_NE, $1, $2, $3); } + | simple_expr EXPR_AND simple_expr + { $$ = make_binary_op (EXPR_AND, $1, $2, $3); } + | simple_expr EXPR_OR simple_expr + { $$ = make_binary_op (EXPR_OR, $1, $2, $3); } + | simple_expr EXPR_AND_AND simple_expr + { $$ = make_boolean_op (EXPR_AND_AND, $1, $2, $3); } + | simple_expr EXPR_OR_OR simple_expr + { $$ = make_boolean_op (EXPR_OR_OR, $1, $2, $3); } + ; // Arrange for the lexer to return CLOSE_BRACE for `]' by looking ahead // one token for an assignment op. -assign_lhs : simple_expr - { - $$ = new tree_argument_list ($1); - $$->mark_as_simple_assign_lhs (); - } - | '[' arg_list CLOSE_BRACE - { - $$ = $2; - lexer_flags.looking_at_matrix_or_assign_lhs = false; - for (std::set::const_iterator p = lexer_flags.pending_local_variables.begin (); - p != lexer_flags.pending_local_variables.end (); - p++) - { - symbol_table::force_variable (*p); - } - lexer_flags.pending_local_variables.clear (); - } - ; - -assign_expr : assign_lhs '=' expression - { $$ = make_assign_op ('=', $1, $2, $3); } - | assign_lhs ADD_EQ expression - { $$ = make_assign_op (ADD_EQ, $1, $2, $3); } - | assign_lhs SUB_EQ expression - { $$ = make_assign_op (SUB_EQ, $1, $2, $3); } - | assign_lhs MUL_EQ expression - { $$ = make_assign_op (MUL_EQ, $1, $2, $3); } - | assign_lhs DIV_EQ expression - { $$ = make_assign_op (DIV_EQ, $1, $2, $3); } - | assign_lhs LEFTDIV_EQ expression - { $$ = make_assign_op (LEFTDIV_EQ, $1, $2, $3); } - | assign_lhs POW_EQ expression - { $$ = make_assign_op (POW_EQ, $1, $2, $3); } - | assign_lhs LSHIFT_EQ expression - { $$ = make_assign_op (LSHIFT_EQ, $1, $2, $3); } - | assign_lhs RSHIFT_EQ expression - { $$ = make_assign_op (RSHIFT_EQ, $1, $2, $3); } - | assign_lhs EMUL_EQ expression - { $$ = make_assign_op (EMUL_EQ, $1, $2, $3); } - | assign_lhs EDIV_EQ expression - { $$ = make_assign_op (EDIV_EQ, $1, $2, $3); } - | assign_lhs ELEFTDIV_EQ expression - { $$ = make_assign_op (ELEFTDIV_EQ, $1, $2, $3); } - | assign_lhs EPOW_EQ expression - { $$ = make_assign_op (EPOW_EQ, $1, $2, $3); } - | assign_lhs AND_EQ expression - { $$ = make_assign_op (AND_EQ, $1, $2, $3); } - | assign_lhs OR_EQ expression - { $$ = make_assign_op (OR_EQ, $1, $2, $3); } - ; - -expression : simple_expr - { $$ = $1; } - | assign_expr - { $$ = $1; } - | anon_fcn_handle - { $$ = $1; } - ; +assign_lhs : simple_expr + { + $$ = new tree_argument_list ($1); + $$->mark_as_simple_assign_lhs (); + } + | '[' arg_list CLOSE_BRACE + { + $$ = $2; + lexer_flags.looking_at_matrix_or_assign_lhs = false; + for (std::set::const_iterator p = lexer_flags.pending_local_variables.begin (); + p != lexer_flags.pending_local_variables.end (); + p++) + { + symbol_table::force_variable (*p); + } + lexer_flags.pending_local_variables.clear (); + } + ; + +assign_expr : assign_lhs '=' expression + { $$ = make_assign_op ('=', $1, $2, $3); } + | assign_lhs ADD_EQ expression + { $$ = make_assign_op (ADD_EQ, $1, $2, $3); } + | assign_lhs SUB_EQ expression + { $$ = make_assign_op (SUB_EQ, $1, $2, $3); } + | assign_lhs MUL_EQ expression + { $$ = make_assign_op (MUL_EQ, $1, $2, $3); } + | assign_lhs DIV_EQ expression + { $$ = make_assign_op (DIV_EQ, $1, $2, $3); } + | assign_lhs LEFTDIV_EQ expression + { $$ = make_assign_op (LEFTDIV_EQ, $1, $2, $3); } + | assign_lhs POW_EQ expression + { $$ = make_assign_op (POW_EQ, $1, $2, $3); } + | assign_lhs LSHIFT_EQ expression + { $$ = make_assign_op (LSHIFT_EQ, $1, $2, $3); } + | assign_lhs RSHIFT_EQ expression + { $$ = make_assign_op (RSHIFT_EQ, $1, $2, $3); } + | assign_lhs EMUL_EQ expression + { $$ = make_assign_op (EMUL_EQ, $1, $2, $3); } + | assign_lhs EDIV_EQ expression + { $$ = make_assign_op (EDIV_EQ, $1, $2, $3); } + | assign_lhs ELEFTDIV_EQ expression + { $$ = make_assign_op (ELEFTDIV_EQ, $1, $2, $3); } + | assign_lhs EPOW_EQ expression + { $$ = make_assign_op (EPOW_EQ, $1, $2, $3); } + | assign_lhs AND_EQ expression + { $$ = make_assign_op (AND_EQ, $1, $2, $3); } + | assign_lhs OR_EQ expression + { $$ = make_assign_op (OR_EQ, $1, $2, $3); } + ; + +expression : simple_expr + { $$ = $1; } + | assign_expr + { $$ = $1; } + | anon_fcn_handle + { $$ = $1; } + ; // ================================================ // Commands, declarations, and function definitions // ================================================ -command : declaration - { $$ = $1; } - | select_command - { $$ = $1; } - | loop_command - { $$ = $1; } - | jump_command - { $$ = $1; } - | except_command - { $$ = $1; } - | function - { $$ = $1; } - | script_file - { $$ = $1; } - | classdef - { $$ = $1; } - ; +command : declaration + { $$ = $1; } + | select_command + { $$ = $1; } + | loop_command + { $$ = $1; } + | jump_command + { $$ = $1; } + | except_command + { $$ = $1; } + | function + { $$ = $1; } + | script_file + { $$ = $1; } + | classdef + { $$ = $1; } + ; // ===================== // Declaration statemnts // ===================== parsing_decl_list - : // empty - { lexer_flags.looking_at_decl_list = true; } - -declaration : GLOBAL parsing_decl_list decl1 - { - $$ = make_decl_command (GLOBAL, $1, $3); - lexer_flags.looking_at_decl_list = false; - } - | STATIC parsing_decl_list decl1 - { - $$ = make_decl_command (STATIC, $1, $3); - lexer_flags.looking_at_decl_list = false; - } - ; - -decl1 : decl2 - { $$ = new tree_decl_init_list ($1); } - | decl1 decl2 - { - $1->append ($2); - $$ = $1; - } - ; + : // empty + { lexer_flags.looking_at_decl_list = true; } + +declaration : GLOBAL parsing_decl_list decl1 + { + $$ = make_decl_command (GLOBAL, $1, $3); + lexer_flags.looking_at_decl_list = false; + } + | STATIC parsing_decl_list decl1 + { + $$ = make_decl_command (STATIC, $1, $3); + lexer_flags.looking_at_decl_list = false; + } + ; + +decl1 : decl2 + { $$ = new tree_decl_init_list ($1); } + | decl1 decl2 + { + $1->append ($2); + $$ = $1; + } + ; decl_param_init : // empty - { lexer_flags.looking_at_initializer_expression = true; } - -decl2 : identifier - { $$ = new tree_decl_elt ($1); } - | identifier '=' decl_param_init expression - { - lexer_flags.looking_at_initializer_expression = false; - $$ = new tree_decl_elt ($1, $4); - } + { lexer_flags.looking_at_initializer_expression = true; } + +decl2 : identifier + { $$ = new tree_decl_elt ($1); } + | identifier '=' decl_param_init expression + { + lexer_flags.looking_at_initializer_expression = false; + $$ = new tree_decl_elt ($1, $4); + } | magic_tilde { $$ = new tree_decl_elt ($1); } - ; + ; // ==================== // Selection statements // ==================== -select_command : if_command - { $$ = $1; } - | switch_command - { $$ = $1; } - ; +select_command : if_command + { $$ = $1; } + | switch_command + { $$ = $1; } + ; // ============ // If statement // ============ -if_command : IF stash_comment if_cmd_list END - { - if (! ($$ = finish_if_command ($1, $3, $4, $2))) - ABORT_PARSE; - } - ; - -if_cmd_list : if_cmd_list1 - { $$ = $1; } - | if_cmd_list1 else_clause - { - $1->append ($2); - $$ = $1; - } - ; - -if_cmd_list1 : expression opt_sep opt_list - { $$ = start_if_command ($1, $3); } - | if_cmd_list1 elseif_clause - { - $1->append ($2); - $$ = $1; - } - ; - -elseif_clause : ELSEIF stash_comment opt_sep expression opt_sep opt_list - { $$ = make_elseif_clause ($1, $4, $6, $2); } - ; - -else_clause : ELSE stash_comment opt_sep opt_list - { $$ = new tree_if_clause ($4, $2); } - ; +if_command : IF stash_comment if_cmd_list END + { + if (! ($$ = finish_if_command ($1, $3, $4, $2))) + ABORT_PARSE; + } + ; + +if_cmd_list : if_cmd_list1 + { $$ = $1; } + | if_cmd_list1 else_clause + { + $1->append ($2); + $$ = $1; + } + ; + +if_cmd_list1 : expression opt_sep opt_list + { $$ = start_if_command ($1, $3); } + | if_cmd_list1 elseif_clause + { + $1->append ($2); + $$ = $1; + } + ; + +elseif_clause : ELSEIF stash_comment opt_sep expression opt_sep opt_list + { $$ = make_elseif_clause ($1, $4, $6, $2); } + ; + +else_clause : ELSE stash_comment opt_sep opt_list + { $$ = new tree_if_clause ($4, $2); } + ; // ================ // Switch statement // ================ -switch_command : SWITCH stash_comment expression opt_sep case_list END - { - if (! ($$ = finish_switch_command ($1, $3, $5, $6, $2))) - ABORT_PARSE; - } - ; - -case_list : // empty - { $$ = new tree_switch_case_list (); } - | case_list1 - { $$ = $1; } - | case_list1 default_case - { - $1->append ($2); - $$ = $1; - } - ; - -case_list1 : switch_case - { $$ = new tree_switch_case_list ($1); } - | case_list1 switch_case - { - $1->append ($2); - $$ = $1; - } - ; - -switch_case : CASE stash_comment opt_sep expression opt_sep opt_list - { $$ = make_switch_case ($1, $4, $6, $2); } - ; - -default_case : OTHERWISE stash_comment opt_sep opt_list - { - $$ = new tree_switch_case ($4, $2); - } - ; +switch_command : SWITCH stash_comment expression opt_sep case_list END + { + if (! ($$ = finish_switch_command ($1, $3, $5, $6, $2))) + ABORT_PARSE; + } + ; + +case_list : // empty + { $$ = new tree_switch_case_list (); } + | case_list1 + { $$ = $1; } + | case_list1 default_case + { + $1->append ($2); + $$ = $1; + } + ; + +case_list1 : switch_case + { $$ = new tree_switch_case_list ($1); } + | case_list1 switch_case + { + $1->append ($2); + $$ = $1; + } + ; + +switch_case : CASE stash_comment opt_sep expression opt_sep opt_list + { $$ = make_switch_case ($1, $4, $6, $2); } + ; + +default_case : OTHERWISE stash_comment opt_sep opt_list + { + $$ = new tree_switch_case ($4, $2); + } + ; // ======= // Looping // ======= -loop_command : WHILE stash_comment expression opt_sep opt_list END - { - if (! ($$ = make_while_command ($1, $3, $5, $6, $2))) - ABORT_PARSE; - } - | DO stash_comment opt_sep opt_list UNTIL expression - { - if (! ($$ = make_do_until_command ($5, $4, $6, $2))) - ABORT_PARSE; - } - | FOR stash_comment assign_lhs '=' expression opt_sep opt_list END - { - if (! ($$ = make_for_command ($1, $3, $5, $7, $8, $2))) - ABORT_PARSE; - } - | FOR stash_comment '(' assign_lhs '=' expression ')' opt_sep opt_list END - { - if (! ($$ = make_for_command ($1, $4, $6, $9, $10, $2))) - ABORT_PARSE; - } - ; +loop_command : WHILE stash_comment expression opt_sep opt_list END + { + if (! ($$ = make_while_command ($1, $3, $5, $6, $2))) + ABORT_PARSE; + } + | DO stash_comment opt_sep opt_list UNTIL expression + { + if (! ($$ = make_do_until_command ($5, $4, $6, $2))) + ABORT_PARSE; + } + | FOR stash_comment assign_lhs '=' expression opt_sep opt_list END + { + if (! ($$ = make_for_command ($1, $3, $5, $7, $8, $2))) + ABORT_PARSE; + } + | FOR stash_comment '(' assign_lhs '=' expression ')' opt_sep opt_list END + { + if (! ($$ = make_for_command ($1, $4, $6, $9, $10, $2))) + ABORT_PARSE; + } + ; // ======= // Jumping // ======= -jump_command : BREAK - { - if (! ($$ = make_break_command ($1))) - ABORT_PARSE; - } - | CONTINUE - { - if (! ($$ = make_continue_command ($1))) - ABORT_PARSE; - } - | FUNC_RET - { - if (! ($$ = make_return_command ($1))) - ABORT_PARSE; - } - ; +jump_command : BREAK + { + if (! ($$ = make_break_command ($1))) + ABORT_PARSE; + } + | CONTINUE + { + if (! ($$ = make_continue_command ($1))) + ABORT_PARSE; + } + | FUNC_RET + { + if (! ($$ = make_return_command ($1))) + ABORT_PARSE; + } + ; // ========== // Exceptions // ========== -except_command : UNWIND stash_comment opt_sep opt_list CLEANUP - stash_comment opt_sep opt_list END - { - if (! ($$ = make_unwind_command ($1, $4, $8, $9, $2, $6))) - ABORT_PARSE; - } - | TRY stash_comment opt_sep opt_list CATCH - stash_comment opt_sep opt_list END - { - if (! ($$ = make_try_command ($1, $4, $8, $9, $2, $6))) - ABORT_PARSE; - } - | TRY stash_comment opt_sep opt_list END - { - if (! ($$ = make_try_command ($1, $4, 0, $5, $2, 0))) - ABORT_PARSE; - } - ; +except_command : UNWIND stash_comment opt_sep opt_list CLEANUP + stash_comment opt_sep opt_list END + { + if (! ($$ = make_unwind_command ($1, $4, $8, $9, $2, $6))) + ABORT_PARSE; + } + | TRY stash_comment opt_sep opt_list CATCH + stash_comment opt_sep opt_list END + { + if (! ($$ = make_try_command ($1, $4, $8, $9, $2, $6))) + ABORT_PARSE; + } + | TRY stash_comment opt_sep opt_list END + { + if (! ($$ = make_try_command ($1, $4, 0, $5, $2, 0))) + ABORT_PARSE; + } + ; // =========================================== // Some `subroutines' for function definitions // =========================================== -push_fcn_symtab : // empty - { - current_function_depth++; - - if (max_function_depth < current_function_depth) - max_function_depth = current_function_depth; - - symtab_context.push (symbol_table::current_scope ()); - symbol_table::set_scope (symbol_table::alloc_scope ()); - - if (! reading_script_file && current_function_depth == 1 - && ! parsing_subfunctions) - primary_fcn_scope = symbol_table::current_scope (); - - if (reading_script_file && current_function_depth > 1) - yyerror ("nested functions not implemented in this context"); - } - ; +push_fcn_symtab : // empty + { + current_function_depth++; + + if (max_function_depth < current_function_depth) + max_function_depth = current_function_depth; + + symtab_context.push (symbol_table::current_scope ()); + symbol_table::set_scope (symbol_table::alloc_scope ()); + + if (! reading_script_file && current_function_depth == 1 + && ! parsing_subfunctions) + primary_fcn_scope = symbol_table::current_scope (); + + if (reading_script_file && current_function_depth > 1) + yyerror ("nested functions not implemented in this context"); + } + ; // =========================== // List of function parameters // =========================== -param_list_beg : '(' - { - lexer_flags.looking_at_parameter_list = true; - - if (lexer_flags.looking_at_function_handle) - { - symtab_context.push (symbol_table::current_scope ()); - symbol_table::set_scope (symbol_table::alloc_scope ()); - lexer_flags.looking_at_function_handle--; - } - } - ; - -param_list_end : ')' - { - lexer_flags.looking_at_parameter_list = false; - lexer_flags.looking_for_object_index = false; - } - ; - -param_list : param_list_beg param_list1 param_list_end - { - lexer_flags.quote_is_transpose = false; - $$ = $2; - } - | param_list_beg error - { - yyerror ("invalid parameter list"); - $$ = 0; - ABORT_PARSE; - } - ; - -param_list1 : // empty - { $$ = 0; } - | param_list2 - { - $1->mark_as_formal_parameters (); - if ($1->validate (tree_parameter_list::in)) - $$ = $1; - else - ABORT_PARSE; - } - ; - -param_list2 : decl2 - { $$ = new tree_parameter_list ($1); } - | param_list2 ',' decl2 - { - $1->append ($3); - $$ = $1; - } - ; +param_list_beg : '(' + { + lexer_flags.looking_at_parameter_list = true; + + if (lexer_flags.looking_at_function_handle) + { + symtab_context.push (symbol_table::current_scope ()); + symbol_table::set_scope (symbol_table::alloc_scope ()); + lexer_flags.looking_at_function_handle--; + } + } + ; + +param_list_end : ')' + { + lexer_flags.looking_at_parameter_list = false; + lexer_flags.looking_for_object_index = false; + } + ; + +param_list : param_list_beg param_list1 param_list_end + { + lexer_flags.quote_is_transpose = false; + $$ = $2; + } + | param_list_beg error + { + yyerror ("invalid parameter list"); + $$ = 0; + ABORT_PARSE; + } + ; + +param_list1 : // empty + { $$ = 0; } + | param_list2 + { + $1->mark_as_formal_parameters (); + if ($1->validate (tree_parameter_list::in)) + $$ = $1; + else + ABORT_PARSE; + } + ; + +param_list2 : decl2 + { $$ = new tree_parameter_list ($1); } + | param_list2 ',' decl2 + { + $1->append ($3); + $$ = $1; + } + ; // =================================== // List of function return value names // =================================== -return_list : '[' ']' - { - lexer_flags.looking_at_return_list = false; - $$ = new tree_parameter_list (); - } - | return_list1 - { - lexer_flags.looking_at_return_list = false; - if ($1->validate (tree_parameter_list::out)) - $$ = $1; - else - ABORT_PARSE; - } - | '[' return_list1 ']' - { - lexer_flags.looking_at_return_list = false; - if ($2->validate (tree_parameter_list::out)) - $$ = $2; - else - ABORT_PARSE; - } - ; - -return_list1 : identifier - { $$ = new tree_parameter_list (new tree_decl_elt ($1)); } - | return_list1 ',' identifier - { - $1->append (new tree_decl_elt ($3)); - $$ = $1; - } - ; +return_list : '[' ']' + { + lexer_flags.looking_at_return_list = false; + $$ = new tree_parameter_list (); + } + | return_list1 + { + lexer_flags.looking_at_return_list = false; + if ($1->validate (tree_parameter_list::out)) + $$ = $1; + else + ABORT_PARSE; + } + | '[' return_list1 ']' + { + lexer_flags.looking_at_return_list = false; + if ($2->validate (tree_parameter_list::out)) + $$ = $2; + else + ABORT_PARSE; + } + ; + +return_list1 : identifier + { $$ = new tree_parameter_list (new tree_decl_elt ($1)); } + | return_list1 ',' identifier + { + $1->append (new tree_decl_elt ($3)); + $$ = $1; + } + ; // =========== // Script file // =========== -script_file : SCRIPT_FILE opt_list END_OF_INPUT - { - tree_statement *end_of_script - = make_end ("endscript", input_line_number, - current_input_column); - - make_script ($2, end_of_script); - - $$ = 0; - } - ; +script_file : SCRIPT_FILE opt_list END_OF_INPUT + { + tree_statement *end_of_script + = make_end ("endscript", input_line_number, + current_input_column); + + make_script ($2, end_of_script); + + $$ = 0; + } + ; // ============= // Function file // ============= function_file : FUNCTION_FILE function_list opt_sep END_OF_INPUT - { $$ = 0; } - ; + { $$ = 0; } + ; function_list : function - | function_list sep function - ; + | function_list sep function + ; // =================== // Function definition // =================== -function_beg : push_fcn_symtab FCN stash_comment - { - $$ = $3; - - if (reading_classdef_file || lexer_flags.parsing_classdef) - lexer_flags.maybe_classdef_get_set_method = true; - } - ; - -function : function_beg function1 - { - $$ = finish_function (0, $2, $1); - recover_from_parsing_function (); - } - | function_beg return_list '=' function1 - { - $$ = finish_function ($2, $4, $1); - recover_from_parsing_function (); - } - ; - -fcn_name : identifier - { - std::string id_name = $1->name (); - - lexer_flags.parsed_function_name = true; - lexer_flags.defining_func = false; - lexer_flags.maybe_classdef_get_set_method = false; +function_beg : push_fcn_symtab FCN stash_comment + { + $$ = $3; + + if (reading_classdef_file || lexer_flags.parsing_classdef) + lexer_flags.maybe_classdef_get_set_method = true; + } + ; + +function : function_beg function1 + { + $$ = finish_function (0, $2, $1); + recover_from_parsing_function (); + } + | function_beg return_list '=' function1 + { + $$ = finish_function ($2, $4, $1); + recover_from_parsing_function (); + } + ; + +fcn_name : identifier + { + std::string id_name = $1->name (); + + lexer_flags.parsed_function_name = true; + lexer_flags.defining_func = false; + lexer_flags.maybe_classdef_get_set_method = false; - $$ = $1; - } - | GET '.' identifier - { - lexer_flags.maybe_classdef_get_set_method = false; - $$ = $3; - } - | SET '.' identifier - { - lexer_flags.maybe_classdef_get_set_method = false; - $$ = $3; - } - ; - -function1 : fcn_name function2 - { - std::string fname = $1->name (); - - delete $1; - - if (! ($$ = frob_function (fname, $2))) - ABORT_PARSE; - } - ; - -function2 : param_list opt_sep opt_list function_end - { $$ = start_function ($1, $3, $4); } - | opt_sep opt_list function_end - { $$ = start_function (0, $2, $3); } - ; - -function_end : END - { - endfunction_found = true; - if (end_token_ok ($1, token::function_end)) - $$ = make_end ("endfunction", $1->line (), $1->column ()); - else - ABORT_PARSE; - } - | END_OF_INPUT - { + $$ = $1; + } + | GET '.' identifier + { + lexer_flags.maybe_classdef_get_set_method = false; + $$ = $3; + } + | SET '.' identifier + { + lexer_flags.maybe_classdef_get_set_method = false; + $$ = $3; + } + ; + +function1 : fcn_name function2 + { + std::string fname = $1->name (); + + delete $1; + + if (! ($$ = frob_function (fname, $2))) + ABORT_PARSE; + } + ; + +function2 : param_list opt_sep opt_list function_end + { $$ = start_function ($1, $3, $4); } + | opt_sep opt_list function_end + { $$ = start_function (0, $2, $3); } + ; + +function_end : END + { + endfunction_found = true; + if (end_token_ok ($1, token::function_end)) + $$ = make_end ("endfunction", $1->line (), $1->column ()); + else + ABORT_PARSE; + } + | END_OF_INPUT + { // A lot of tests are based on the assumption that this is OK -// if (reading_script_file) -// { -// yyerror ("function body open at end of script"); -// YYABORT; -// } - - if (endfunction_found) - { - yyerror ("inconsistent function endings -- " - "if one function is explicitly ended, " - "so must all the others"); - YYABORT; - } - - if (! (reading_fcn_file || reading_script_file +// if (reading_script_file) +// { +// yyerror ("function body open at end of script"); +// YYABORT; +// } + + if (endfunction_found) + { + yyerror ("inconsistent function endings -- " + "if one function is explicitly ended, " + "so must all the others"); + YYABORT; + } + + if (! (reading_fcn_file || reading_script_file || get_input_from_eval_string)) - { - yyerror ("function body open at end of input"); - YYABORT; - } - - if (reading_classdef_file) - { - yyerror ("classdef body open at end of input"); - YYABORT; - } - - $$ = make_end ("endfunction", input_line_number, - current_input_column); - } - ; + { + yyerror ("function body open at end of input"); + YYABORT; + } + + if (reading_classdef_file) + { + yyerror ("classdef body open at end of input"); + YYABORT; + } + + $$ = make_end ("endfunction", input_line_number, + current_input_column); + } + ; // ======== // Classdef // ======== -classdef_beg : CLASSDEF stash_comment - { - $$ = 0; - lexer_flags.parsing_classdef = true; - } - ; - -classdef_end : END - { - lexer_flags.parsing_classdef = false; - - if (end_token_ok ($1, token::classdef_end)) - $$ = make_end ("endclassdef", $1->line (), $1->column ()); - else - ABORT_PARSE; - } - ; - -classdef1 : classdef_beg opt_attr_list identifier opt_superclasses - { $$ = 0; } - ; - -classdef : classdef1 '\n' class_body '\n' stash_comment classdef_end - { $$ = 0; } - ; - -opt_attr_list : // empty - { $$ = 0; } - | '(' attr_list ')' - { $$ = 0; } - ; - -attr_list : attr - { $$ = 0; } - | attr_list ',' attr - { $$ = 0; } - ; - -attr : identifier - { $$ = 0; } - | identifier '=' decl_param_init expression - { $$ = 0; } - | EXPR_NOT identifier - { $$ = 0; } - ; +classdef_beg : CLASSDEF stash_comment + { + $$ = 0; + lexer_flags.parsing_classdef = true; + } + ; + +classdef_end : END + { + lexer_flags.parsing_classdef = false; + + if (end_token_ok ($1, token::classdef_end)) + $$ = make_end ("endclassdef", $1->line (), $1->column ()); + else + ABORT_PARSE; + } + ; + +classdef1 : classdef_beg opt_attr_list identifier opt_superclasses + { $$ = 0; } + ; + +classdef : classdef1 '\n' class_body '\n' stash_comment classdef_end + { $$ = 0; } + ; + +opt_attr_list : // empty + { $$ = 0; } + | '(' attr_list ')' + { $$ = 0; } + ; + +attr_list : attr + { $$ = 0; } + | attr_list ',' attr + { $$ = 0; } + ; + +attr : identifier + { $$ = 0; } + | identifier '=' decl_param_init expression + { $$ = 0; } + | EXPR_NOT identifier + { $$ = 0; } + ; opt_superclasses - : // empty - { $$ = 0; } - | superclasses - { $$ = 0; } - ; - -superclasses : EXPR_LT identifier '.' identifier - { $$ = 0; } - | EXPR_LT identifier - { $$ = 0; } - | superclasses EXPR_AND identifier '.' identifier - { $$ = 0; } - | superclasses EXPR_AND identifier - { $$ = 0; } - ; - -class_body : properties_block - { $$ = 0; } - | methods_block - { $$ = 0; } - | events_block - { $$ = 0; } - | class_body '\n' properties_block - { $$ = 0; } - | class_body '\n' methods_block - { $$ = 0; } - | class_body '\n' events_block - { $$ = 0; } - ; - -properties_beg : PROPERTIES stash_comment - { $$ = 0; } - ; + : // empty + { $$ = 0; } + | superclasses + { $$ = 0; } + ; + +superclasses : EXPR_LT identifier '.' identifier + { $$ = 0; } + | EXPR_LT identifier + { $$ = 0; } + | superclasses EXPR_AND identifier '.' identifier + { $$ = 0; } + | superclasses EXPR_AND identifier + { $$ = 0; } + ; + +class_body : properties_block + { $$ = 0; } + | methods_block + { $$ = 0; } + | events_block + { $$ = 0; } + | class_body '\n' properties_block + { $$ = 0; } + | class_body '\n' methods_block + { $$ = 0; } + | class_body '\n' events_block + { $$ = 0; } + ; + +properties_beg : PROPERTIES stash_comment + { $$ = 0; } + ; properties_block - : properties_beg opt_attr_list '\n' properties_list '\n' END - { $$ = 0; } - ; + : properties_beg opt_attr_list '\n' properties_list '\n' END + { $$ = 0; } + ; properties_list - : class_property - { $$ = 0; } - | properties_list '\n' class_property - { $$ = 0; } - ; - -class_property : identifier - { $$ = 0; } - | identifier '=' decl_param_init expression ';' - { $$ = 0; } - ; - -methods_beg : METHODS stash_comment - { $$ = 0; } - ; - -methods_block : methods_beg opt_attr_list '\n' methods_list '\n' END - { $$ = 0; } - ; - -methods_list : function - { $$ = 0; } - | methods_list '\n' function - { $$ = 0; } - ; - -events_beg : EVENTS stash_comment - { $$ = 0; } - ; - -events_block : events_beg opt_attr_list '\n' events_list '\n' END - { $$ = 0; } - ; - -events_list : class_event - { $$ = 0; } - | events_list '\n' class_event - { $$ = 0; } - ; - -class_event : identifier - { $$ = 0; } - ; + : class_property + { $$ = 0; } + | properties_list '\n' class_property + { $$ = 0; } + ; + +class_property : identifier + { $$ = 0; } + | identifier '=' decl_param_init expression ';' + { $$ = 0; } + ; + +methods_beg : METHODS stash_comment + { $$ = 0; } + ; + +methods_block : methods_beg opt_attr_list '\n' methods_list '\n' END + { $$ = 0; } + ; + +methods_list : function + { $$ = 0; } + | methods_list '\n' function + { $$ = 0; } + ; + +events_beg : EVENTS stash_comment + { $$ = 0; } + ; + +events_block : events_beg opt_attr_list '\n' events_list '\n' END + { $$ = 0; } + ; + +events_list : class_event + { $$ = 0; } + | events_list '\n' class_event + { $$ = 0; } + ; + +class_event : identifier + { $$ = 0; } + ; // ============= // Miscellaneous // ============= -stash_comment : // empty - { $$ = octave_comment_buffer::get_comment (); } - ; - -parse_error : LEXICAL_ERROR - { yyerror ("parse error"); } - | error - ; - -sep_no_nl : ',' - { $$ = ','; } - | ';' - { $$ = ';'; } - | sep_no_nl ',' - { $$ = $1; } - | sep_no_nl ';' - { $$ = $1; } - ; - -opt_sep_no_nl : // empty - { $$ = 0; } - | sep_no_nl - { $$ = $1; } - ; - -sep : ',' - { $$ = ','; } - | ';' - { $$ = ';'; } - | '\n' - { $$ = '\n'; } - | sep ',' - { $$ = $1; } - | sep ';' - { $$ = $1; } - | sep '\n' - { $$ = $1; } - ; - -opt_sep : // empty - { $$ = 0; } - | sep - { $$ = $1; } - ; +stash_comment : // empty + { $$ = octave_comment_buffer::get_comment (); } + ; + +parse_error : LEXICAL_ERROR + { yyerror ("parse error"); } + | error + ; + +sep_no_nl : ',' + { $$ = ','; } + | ';' + { $$ = ';'; } + | sep_no_nl ',' + { $$ = $1; } + | sep_no_nl ';' + { $$ = $1; } + ; + +opt_sep_no_nl : // empty + { $$ = 0; } + | sep_no_nl + { $$ = $1; } + ; + +sep : ',' + { $$ = ','; } + | ';' + { $$ = ';'; } + | '\n' + { $$ = '\n'; } + | sep ',' + { $$ = $1; } + | sep ';' + { $$ = $1; } + | sep '\n' + { $$ = $1; } + ; + +opt_sep : // empty + { $$ = 0; } + | sep + { $$ = $1; } + ; %% @@ -1635,7 +1635,7 @@ if (reading_fcn_file || reading_script_file || reading_classdef_file) output_buf << "parse error near line " << input_line_number - << " of file " << curr_fcn_file_full_name; + << " of file " << curr_fcn_file_full_name; else output_buf << "parse error:"; @@ -1656,10 +1656,10 @@ output_buf << ">>> " << current_input_line << "\n"; if (err_col == 0) - err_col = len; + err_col = len; for (int i = 0; i < err_col + 3; i++) - output_buf << " "; + output_buf << " "; output_buf << "^"; } @@ -1742,43 +1742,43 @@ int c = tok->column (); switch (expected) - { - case token::classdef_end: - end_error ("classdef", ettype, l, c); - break; - - case token::for_end: - end_error ("for", ettype, l, c); - break; - - case token::function_end: - end_error ("function", ettype, l, c); - break; - - case token::if_end: - end_error ("if", ettype, l, c); - break; - - case token::try_catch_end: - end_error ("try", ettype, l, c); - break; - - case token::switch_end: - end_error ("switch", ettype, l, c); - break; - - case token::unwind_protect_end: - end_error ("unwind_protect", ettype, l, c); - break; - - case token::while_end: - end_error ("while", ettype, l, c); - break; - - default: - panic_impossible (); - break; - } + { + case token::classdef_end: + end_error ("classdef", ettype, l, c); + break; + + case token::for_end: + end_error ("for", ettype, l, c); + break; + + case token::function_end: + end_error ("function", ettype, l, c); + break; + + case token::if_end: + end_error ("if", ettype, l, c); + break; + + case token::try_catch_end: + end_error ("try", ettype, l, c); + break; + + case token::switch_end: + end_error ("switch", ettype, l, c); + break; + + case token::unwind_protect_end: + end_error ("unwind_protect", ettype, l, c); + break; + + case token::while_end: + end_error ("while", ettype, l, c); + break; + + default: + panic_impossible (); + break; + } } return retval; @@ -1794,14 +1794,14 @@ && expr->paren_count () < 2) { if (curr_fcn_file_full_name.empty ()) - warning_with_id - ("Octave:assign-as-truth-value", - "suggest parenthesis around assignment used as truth value"); + warning_with_id + ("Octave:assign-as-truth-value", + "suggest parenthesis around assignment used as truth value"); else - warning_with_id - ("Octave:assign-as-truth-value", - "suggest parenthesis around assignment used as truth value near line %d, column %d in file `%s'", - expr->line (), expr->column (), curr_fcn_file_full_name.c_str ()); + warning_with_id + ("Octave:assign-as-truth-value", + "suggest parenthesis around assignment used as truth value near line %d, column %d in file `%s'", + expr->line (), expr->column (), curr_fcn_file_full_name.c_str ()); } } @@ -1813,13 +1813,13 @@ if (! expr->is_constant ()) { if (curr_fcn_file_full_name.empty ()) - warning_with_id ("Octave:variable-switch-label", - "variable switch label"); + warning_with_id ("Octave:variable-switch-label", + "variable switch label"); else - warning_with_id - ("Octave:variable-switch-label", - "variable switch label near line %d, column %d in file `%s'", - expr->line (), expr->column (), curr_fcn_file_full_name.c_str ()); + warning_with_id + ("Octave:variable-switch-label", + "variable switch label near line %d, column %d in file `%s'", + expr->line (), expr->column (), curr_fcn_file_full_name.c_str ()); } } @@ -1846,29 +1846,29 @@ if (op1->is_constant () && op2->is_constant () && (! ((warning_enabled ("Octave:associativity-change") - && (op_type == POW || op_type == EPOW)) - || (warning_enabled ("Octave:precedence-change") - && (op_type == EXPR_OR || op_type == EXPR_OR_OR))))) + && (op_type == POW || op_type == EPOW)) + || (warning_enabled ("Octave:precedence-change") + && (op_type == EXPR_OR || op_type == EXPR_OR_OR))))) { octave_value tmp = e->rvalue1 (); if (! (error_state || warning_state)) - { - tree_constant *tc_retval - = new tree_constant (tmp, op1->line (), op1->column ()); - - std::ostringstream buf; - - tree_print_code tpc (buf); - - e->accept (tpc); - - tc_retval->stash_original_text (buf.str ()); - - delete e; - - retval = tc_retval; - } + { + tree_constant *tc_retval + = new tree_constant (tmp, op1->line (), op1->column ()); + + std::ostringstream buf; + + tree_print_code tpc (buf); + + e->accept (tpc); + + tc_retval->stash_original_text (buf.str ()); + + delete e; + + retval = tc_retval; + } } return retval; @@ -1897,22 +1897,22 @@ octave_value tmp = e->rvalue1 (); if (! (error_state || warning_state)) - { - tree_constant *tc_retval - = new tree_constant (tmp, op->line (), op->column ()); - - std::ostringstream buf; - - tree_print_code tpc (buf); - - e->accept (tpc); - - tc_retval->stash_original_text (buf.str ()); - - delete e; - - retval = tc_retval; - } + { + tree_constant *tc_retval + = new tree_constant (tmp, op->line (), op->column ()); + + std::ostringstream buf; + + tree_print_code tpc (buf); + + e->accept (tpc); + + tc_retval->stash_original_text (buf.str ()); + + delete e; + + retval = tc_retval; + } } return retval; @@ -1943,40 +1943,40 @@ if (base) { if (limit) - { - if (base->is_constant () && limit->is_constant () - && (! incr || (incr && incr->is_constant ()))) - { - octave_value tmp = e->rvalue1 (); - - if (! (error_state || warning_state)) - { - tree_constant *tc_retval - = new tree_constant (tmp, base->line (), base->column ()); - - std::ostringstream buf; - - tree_print_code tpc (buf); - - e->accept (tpc); - - tc_retval->stash_original_text (buf.str ()); - - delete e; - - retval = tc_retval; - } - } - } + { + if (base->is_constant () && limit->is_constant () + && (! incr || (incr && incr->is_constant ()))) + { + octave_value tmp = e->rvalue1 (); + + if (! (error_state || warning_state)) + { + tree_constant *tc_retval + = new tree_constant (tmp, base->line (), base->column ()); + + std::ostringstream buf; + + tree_print_code tpc (buf); + + e->accept (tpc); + + tc_retval->stash_original_text (buf.str ()); + + delete e; + + retval = tc_retval; + } + } + } else - { - e->preserve_base (); - delete e; - - // FIXME -- need to attempt constant folding here - // too (we need a generic way to do that). - retval = base; - } + { + e->preserve_base (); + delete e; + + // FIXME -- need to attempt constant folding here + // too (we need a generic way to do that). + retval = base; + } } return retval; @@ -1996,24 +1996,24 @@ { case NUM: { - octave_value tmp (tok_val->number ()); - retval = new tree_constant (tmp, l, c); - retval->stash_original_text (tok_val->text_rep ()); + octave_value tmp (tok_val->number ()); + retval = new tree_constant (tmp, l, c); + retval->stash_original_text (tok_val->text_rep ()); } break; case IMAG_NUM: { - octave_value tmp (Complex (0.0, tok_val->number ())); - retval = new tree_constant (tmp, l, c); - retval->stash_original_text (tok_val->text_rep ()); + octave_value tmp (Complex (0.0, tok_val->number ())); + retval = new tree_constant (tmp, l, c); + retval->stash_original_text (tok_val->text_rep ()); } break; case DQ_STRING: case SQ_STRING: { - std::string txt = tok_val->text (); + std::string txt = tok_val->text (); char delim = op == DQ_STRING ? '"' : '\''; octave_value tmp (txt, delim); @@ -2026,14 +2026,14 @@ tmp = octave_null_sq_str::instance; } - retval = new tree_constant (tmp, l, c); - - if (op == DQ_STRING) - txt = undo_string_escapes (txt); - - // FIXME -- maybe this should also be handled by - // tok_val->text_rep () for character strings? - retval->stash_original_text (delim + txt + delim); + retval = new tree_constant (tmp, l, c); + + if (op == DQ_STRING) + txt = undo_string_escapes (txt); + + // FIXME -- maybe this should also be handled by + // tok_val->text_rep () for character strings? + retval->stash_original_text (delim + txt + delim); } break; @@ -2097,27 +2097,27 @@ if (op->paren_count () == 0 && op->is_binary_expression ()) { tree_binary_expression *e - = dynamic_cast (op); + = dynamic_cast (op); octave_value::binary_op op_type = e->op_type (); if (op_type == octave_value::op_pow - || op_type == octave_value::op_el_pow) - { - std::string op_str = octave_value::binary_op_as_string (op_type); - - if (curr_fcn_file_full_name.empty ()) - warning_with_id - ("Octave:associativity-change", - "meaning may have changed due to change in associativity for %s operator", - op_str.c_str ()); - else - warning_with_id - ("Octave:associativity-change", - "meaning may have changed due to change in associativity for %s operator near line %d, column %d in file `%s'", - op_str.c_str (), op->line (), op->column (), - curr_fcn_file_full_name.c_str ()); - } + || op_type == octave_value::op_el_pow) + { + std::string op_str = octave_value::binary_op_as_string (op_type); + + if (curr_fcn_file_full_name.empty ()) + warning_with_id + ("Octave:associativity-change", + "meaning may have changed due to change in associativity for %s operator", + op_str.c_str ()); + else + warning_with_id + ("Octave:associativity-change", + "meaning may have changed due to change in associativity for %s operator near line %d, column %d in file `%s'", + op_str.c_str (), op->line (), op->column (), + curr_fcn_file_full_name.c_str ()); + } } } @@ -2125,7 +2125,7 @@ static tree_expression * make_binary_op (int op, tree_expression *op1, token *tok_val, - tree_expression *op2) + tree_expression *op2) { octave_value::binary_op t = octave_value::unknown_binary_op; @@ -2213,22 +2213,22 @@ t = octave_value::op_el_or; if (op2->paren_count () == 0 && op2->is_binary_expression ()) { - tree_binary_expression *e - = dynamic_cast (op2); - - if (e->op_type () == octave_value::op_el_and) - { - if (curr_fcn_file_full_name.empty ()) - warning_with_id - ("Octave:precedence-change", - "meaning may have changed due to change in precedence for & and | operators"); - else - warning_with_id - ("Octave:precedence-change", - "meaning may have changed due to change in precedence for & and | operators near line %d, column %d in file `%s'", - op2->line (), op2->column (), - curr_fcn_file_full_name.c_str ()); - } + tree_binary_expression *e + = dynamic_cast (op2); + + if (e->op_type () == octave_value::op_el_and) + { + if (curr_fcn_file_full_name.empty ()) + warning_with_id + ("Octave:precedence-change", + "meaning may have changed due to change in precedence for & and | operators"); + else + warning_with_id + ("Octave:precedence-change", + "meaning may have changed due to change in precedence for & and | operators near line %d, column %d in file `%s'", + op2->line (), op2->column (), + curr_fcn_file_full_name.c_str ()); + } } break; @@ -2250,7 +2250,7 @@ static tree_expression * make_boolean_op (int op, tree_expression *op1, token *tok_val, - tree_expression *op2) + tree_expression *op2) { tree_boolean_expression::type t; @@ -2264,13 +2264,13 @@ t = tree_boolean_expression::bool_or; if (op2->paren_count () == 0 && op2->is_boolean_expression ()) { - tree_boolean_expression *e - = dynamic_cast (op2); - - if (e->op_type () == tree_boolean_expression::bool_and) - warning_with_id - ("Octave:precedence-change", - "meaning may have changed due to change in precedence for && and || operators"); + tree_boolean_expression *e + = dynamic_cast (op2); + + if (e->op_type () == tree_boolean_expression::bool_and) + warning_with_id + ("Octave:precedence-change", + "meaning may have changed due to change in precedence for && and || operators"); } break; @@ -2374,8 +2374,8 @@ static tree_command * make_unwind_command (token *unwind_tok, tree_statement_list *body, - tree_statement_list *cleanup, token *end_tok, - octave_comment_list *lc, octave_comment_list *mc) + tree_statement_list *cleanup, token *end_tok, + octave_comment_list *lc, octave_comment_list *mc) { tree_command *retval = 0; @@ -2387,7 +2387,7 @@ int c = unwind_tok->column (); retval = new tree_unwind_protect_command (body, cleanup, - lc, mc, tc, l, c); + lc, mc, tc, l, c); } return retval; @@ -2397,8 +2397,8 @@ static tree_command * make_try_command (token *try_tok, tree_statement_list *body, - tree_statement_list *cleanup, token *end_tok, - octave_comment_list *lc, octave_comment_list *mc) + tree_statement_list *cleanup, token *end_tok, + octave_comment_list *lc, octave_comment_list *mc) { tree_command *retval = 0; @@ -2410,7 +2410,7 @@ int c = try_tok->column (); retval = new tree_try_catch_command (body, cleanup, - lc, mc, tc, l, c); + lc, mc, tc, l, c); } return retval; @@ -2420,8 +2420,8 @@ static tree_command * make_while_command (token *while_tok, tree_expression *expr, - tree_statement_list *body, token *end_tok, - octave_comment_list *lc) + tree_statement_list *body, token *end_tok, + octave_comment_list *lc) { tree_command *retval = 0; @@ -2446,7 +2446,7 @@ static tree_command * make_do_until_command (token *until_tok, tree_statement_list *body, - tree_expression *expr, octave_comment_list *lc) + tree_expression *expr, octave_comment_list *lc) { tree_command *retval = 0; @@ -2468,8 +2468,8 @@ static tree_command * make_for_command (token *for_tok, tree_argument_list *lhs, - tree_expression *expr, tree_statement_list *body, - token *end_tok, octave_comment_list *lc) + tree_expression *expr, tree_statement_list *body, + token *end_tok, octave_comment_list *lc) { tree_command *retval = 0; @@ -2483,17 +2483,17 @@ int c = for_tok->column (); if (lhs->length () == 1) - { - tree_expression *tmp = lhs->remove_front (); - - retval = new tree_simple_for_command (tmp, expr, body, - lc, tc, l, c); - - delete lhs; - } + { + tree_expression *tmp = lhs->remove_front (); + + retval = new tree_simple_for_command (tmp, expr, body, + lc, tc, l, c); + + delete lhs; + } else - retval = new tree_complex_for_command (lhs, expr, body, - lc, tc, l, c); + retval = new tree_complex_for_command (lhs, expr, body, + lc, tc, l, c); } return retval; @@ -2560,7 +2560,7 @@ static tree_if_command * finish_if_command (token *if_tok, tree_if_command_list *list, - token *end_tok, octave_comment_list *lc) + token *end_tok, octave_comment_list *lc) { tree_if_command *retval = 0; @@ -2572,15 +2572,15 @@ int c = if_tok->column (); if (list && ! list->empty ()) - { - tree_if_clause *elt = list->front (); - - if (elt) - { - elt->line (l); - elt->column (c); - } - } + { + tree_if_clause *elt = list->front (); + + if (elt) + { + elt->line (l); + elt->column (c); + } + } retval = new tree_if_command (list, lc, tc, l, c); } @@ -2592,7 +2592,7 @@ static tree_if_clause * make_elseif_clause (token *elseif_tok, tree_expression *expr, - tree_statement_list *list, octave_comment_list *lc) + tree_statement_list *list, octave_comment_list *lc) { maybe_warn_assign_as_truth_value (expr); @@ -2606,8 +2606,8 @@ static tree_switch_command * finish_switch_command (token *switch_tok, tree_expression *expr, - tree_switch_case_list *list, token *end_tok, - octave_comment_list *lc) + tree_switch_case_list *list, token *end_tok, + octave_comment_list *lc) { tree_switch_command *retval = 0; @@ -2619,15 +2619,15 @@ int c = switch_tok->column (); if (list && ! list->empty ()) - { - tree_switch_case *elt = list->front (); - - if (elt) - { - elt->line (l); - elt->column (c); - } - } + { + tree_switch_case *elt = list->front (); + + if (elt) + { + elt->line (l); + elt->column (c); + } + } retval = new tree_switch_command (expr, list, lc, tc, l, c); } @@ -2639,7 +2639,7 @@ static tree_switch_case * make_switch_case (token *case_tok, tree_expression *expr, - tree_statement_list *list, octave_comment_list *lc) + tree_statement_list *list, octave_comment_list *lc) { maybe_warn_variable_switch_label (expr); @@ -2653,7 +2653,7 @@ static tree_expression * make_assign_op (int op, tree_argument_list *lhs, token *eq_tok, - tree_expression *rhs) + tree_expression *rhs) { tree_expression *retval = 0; @@ -2765,7 +2765,7 @@ octave_user_script *script = new octave_user_script (curr_fcn_file_full_name, curr_fcn_file_name, - cmds, doc_string); + cmds, doc_string); octave_time now; @@ -2783,7 +2783,7 @@ static octave_user_function * start_function (tree_parameter_list *param_list, tree_statement_list *body, - tree_statement *end_fcn_stmt) + tree_statement *end_fcn_stmt) { // We'll fill in the return list later. @@ -2794,7 +2794,7 @@ octave_user_function *fcn = new octave_user_function (symbol_table::current_scope (), - param_list, 0, body); + param_list, 0, body); if (fcn) { @@ -2825,7 +2825,7 @@ // name). if (! autoloading && reading_fcn_file && (current_function_depth == 1 - && ! (parsing_subfunctions || lexer_flags.parsing_class_method))) + && ! (parsing_subfunctions || lexer_flags.parsing_class_method))) { // FIXME -- should curr_fcn_file_name already be // preprocessed when we get here? It seems to only be a @@ -2840,12 +2840,12 @@ if (nm != id_name) { - warning_with_id - ("Octave:function-name-clash", - "function name `%s' does not agree with function file name `%s'", - id_name.c_str (), curr_fcn_file_full_name.c_str ()); - - id_name = nm; + warning_with_id + ("Octave:function-name-clash", + "function name `%s' does not agree with function file name `%s'", + id_name.c_str (), curr_fcn_file_full_name.c_str ()); + + id_name = nm; } } @@ -2858,23 +2858,23 @@ fcn->mark_as_system_fcn_file (); if (fcn_file_from_relative_lookup) - fcn->mark_relative (); + fcn->mark_relative (); if (current_function_depth > 1 || parsing_subfunctions) { - fcn->stash_parent_fcn_name (curr_fcn_file_name); - fcn->stash_parent_fcn_scope (primary_fcn_scope); + fcn->stash_parent_fcn_name (curr_fcn_file_name); + fcn->stash_parent_fcn_scope (primary_fcn_scope); } if (lexer_flags.parsing_class_method) - { - if (current_class_name == id_name) - fcn->mark_as_class_constructor (); - else - fcn->mark_as_class_method (); - - fcn->stash_dispatch_class (current_class_name); - } + { + if (current_class_name == id_name) + fcn->mark_as_class_constructor (); + else + fcn->mark_as_class_method (); + + fcn->stash_dispatch_class (current_class_name); + } std::string nm = fcn->fcn_file_name (); @@ -2882,14 +2882,14 @@ if (fs && fs.is_newer (now)) warning_with_id ("Octave:future-time-stamp", - "time stamp for `%s' is in the future", nm.c_str ()); + "time stamp for `%s' is in the future", nm.c_str ()); } else if (! (input_from_tmp_history_file || input_from_startup_file) - && reading_script_file - && curr_fcn_file_name == id_name) + && reading_script_file + && curr_fcn_file_name == id_name) { warning ("function `%s' defined within script file `%s'", - id_name.c_str (), curr_fcn_file_full_name.c_str ()); + id_name.c_str (), curr_fcn_file_full_name.c_str ()); } fcn->stash_function_name (id_name); @@ -2911,7 +2911,7 @@ static tree_function_def * finish_function (tree_parameter_list *ret_list, - octave_user_function *fcn, octave_comment_list *lc) + octave_user_function *fcn, octave_comment_list *lc) { tree_function_def *retval = 0; @@ -2925,12 +2925,12 @@ std::string tmp = nm; if (! file.empty ()) - tmp += ": " + file; + tmp += ": " + file; symbol_table::cache_name (fcn->scope (), tmp); if (lc) - fcn->stash_leading_comment (lc); + fcn->stash_leading_comment (lc); fcn->define_ret_list (ret_list); @@ -2938,25 +2938,25 @@ { // FIXME -- is this flag used to determine if the function is a // _subfunction_ somewhere? - fcn->mark_as_nested_function (); - - symbol_table::install_subfunction (nm, octave_value (fcn), - primary_fcn_scope); - } + fcn->mark_as_nested_function (); + + symbol_table::install_subfunction (nm, octave_value (fcn), + primary_fcn_scope); + } if (! reading_fcn_file) - { - // We are either reading a script file or defining a function - // at the command line, so this definition creates a - // tree_function object that is placed in the parse tree. - // Otherwise, it is just inserted in the symbol table, - // either as a subfunction (see above), or as the primary - // function for the file, via primary_fcn_ptr (see also - // load_fcn_from_file,, parse_fcn_file, and - // symbol_table::fcn_info::fcn_info_rep::find_user_function). + { + // We are either reading a script file or defining a function + // at the command line, so this definition creates a + // tree_function object that is placed in the parse tree. + // Otherwise, it is just inserted in the symbol table, + // either as a subfunction (see above), or as the primary + // function for the file, via primary_fcn_ptr (see also + // load_fcn_from_file,, parse_fcn_file, and + // symbol_table::fcn_info::fcn_info_rep::find_user_function). retval = new tree_function_def (fcn); - } + } // Unmark any symbols that may have been tagged as local // variables while parsing (for example, by force_local_variable @@ -2992,7 +2992,7 @@ static tree_index_expression * make_index_expression (tree_expression *expr, tree_argument_list *args, - char type) + char type) { tree_index_expression *retval = 0; @@ -3091,15 +3091,15 @@ case STATIC: if (current_function_depth > 0) - retval = new tree_static_command (lst, l, c); + retval = new tree_static_command (lst, l, c); else - { - if (reading_script_file) - warning ("ignoring persistent declaration near line %d of file `%s'", - l, curr_fcn_file_full_name.c_str ()); - else - warning ("ignoring persistent declaration near line %d", l); - } + { + if (reading_script_file) + warning ("ignoring persistent declaration near line %d of file `%s'", + l, curr_fcn_file_full_name.c_str ()); + else + warning ("ignoring persistent declaration near line %d", l); + } break; default: @@ -3141,22 +3141,22 @@ octave_value tmp = m->rvalue1 (); if (! (error_state || warning_state)) - { - tree_constant *tc_retval - = new tree_constant (tmp, m->line (), m->column ()); - - std::ostringstream buf; - - tree_print_code tpc (buf); - - m->accept (tpc); - - tc_retval->stash_original_text (buf.str ()); - - delete m; - - retval = tc_retval; - } + { + tree_constant *tc_retval + = new tree_constant (tmp, m->line (), m->column ()); + + std::ostringstream buf; + + tree_print_code tpc (buf); + + m->accept (tpc); + + tc_retval->stash_original_text (buf.str ()); + + delete m; + + retval = tc_retval; + } } return retval; @@ -3178,16 +3178,16 @@ tree_statement *tmp = t->back(); if (tmp->is_expression ()) - warning_with_id - ("Octave:missing-semicolon", - "missing semicolon near line %d, column %d in file `%s'", - tmp->line (), tmp->column (), curr_fcn_file_full_name.c_str ()); + warning_with_id + ("Octave:missing-semicolon", + "missing semicolon near line %d, column %d in file `%s'", + tmp->line (), tmp->column (), curr_fcn_file_full_name.c_str ()); } } static tree_statement_list * set_stmt_print_flag (tree_statement_list *list, char sep, - bool warn_missing_semi) + bool warn_missing_semi) { tree_statement *tmp = list->back (); @@ -3202,7 +3202,7 @@ case '\n': tmp->set_print_flag (true); if (warn_missing_semi) - maybe_warn_missing_semi (list); + maybe_warn_missing_semi (list); break; default: @@ -3230,7 +3230,7 @@ static tree_statement_list * append_statement_list (tree_statement_list *list, char sep, - tree_statement *stmt, bool warn_missing_semi) + tree_statement *stmt, bool warn_missing_semi) { set_stmt_print_flag (list, sep, warn_missing_semi); @@ -3282,10 +3282,10 @@ c = getc (f); if (c != '\n') - { - ungetc (c, f); - c = '\n'; - } + { + ungetc (c, f); + c = '\n'; + } } if (c == '\n') @@ -3321,21 +3321,21 @@ while ((c = reader.getc ()) != EOF) { switch (c) - { - case ' ': - case '\t': - current_input_column++; - break; - - case '\n': - current_input_column = 0; - break; - - default: - current_input_column--; - reader.ungetc (c); - goto done; - } + { + case ' ': + case '\t': + current_input_column++; + break; + + case '\n': + current_input_column = 0; + break; + + default: + current_input_column--; + reader.ungetc (c); + goto done; + } } done: @@ -3381,23 +3381,23 @@ eof = skip_white_space (stdio_reader); if (eof) - break; + break; txt = grab_comment_block (stdio_reader, true, eof); if (txt.empty ()) - break; + break; if (! (have_help_text || looks_like_copyright (txt))) - { - help_txt = txt; - have_help_text = true; - } + { + help_txt = txt; + have_help_text = true; + } octave_comment_buffer::append (txt); if (eof) - break; + break; } return help_txt; @@ -3424,8 +3424,8 @@ static octave_function * parse_fcn_file (const std::string& ff, const std::string& dispatch_type, - bool force_script = false, bool require_file = true, - const std::string& warn_for = std::string ()) + bool force_script = false, bool require_file = true, + const std::string& warn_for = std::string ()) { unwind_protect frame; @@ -3482,93 +3482,93 @@ std::string help_txt = gobble_leading_white_space (ffile, eof); if (! eof) - { - std::string file_type; - - frame.protect_var (get_input_from_eval_string); - frame.protect_var (parser_end_of_input); - frame.protect_var (reading_fcn_file); - frame.protect_var (reading_script_file); - frame.protect_var (reading_classdef_file); - frame.protect_var (Vecho_executing_commands); - - - get_input_from_eval_string = false; - parser_end_of_input = false; - - if (! force_script && looking_at_function_keyword (ffile)) - { - file_type = "function"; - - Vecho_executing_commands = ECHO_OFF; - - reading_classdef_file = false; - reading_fcn_file = true; - reading_script_file = false; - } - else if (! force_script && looking_at_classdef_keyword (ffile)) - { - file_type = "classdef"; - - Vecho_executing_commands = ECHO_OFF; - - reading_classdef_file = true; - reading_fcn_file = false; - reading_script_file = false; - } - else - { - file_type = "script"; - - Vecho_executing_commands = ECHO_OFF; - - reading_classdef_file = false; - reading_fcn_file = false; - reading_script_file = true; - } - - YY_BUFFER_STATE old_buf = current_buffer (); - YY_BUFFER_STATE new_buf = create_buffer (ffile); - - frame.add_fcn (switch_to_buffer, old_buf); - frame.add_fcn (delete_buffer, new_buf); - - switch_to_buffer (new_buf); - - frame.protect_var (primary_fcn_ptr); - primary_fcn_ptr = 0; - - reset_parser (); - - // Do this with an unwind-protect cleanup function so that - // the forced variables will be unmarked in the event of an - // interrupt. - symbol_table::scope_id scope = symbol_table::top_scope (); - frame.add_fcn (symbol_table::unmark_forced_variables, scope); - - if (! help_txt.empty ()) - help_buf.push (help_txt); - - if (reading_script_file) - prep_lexer_for_script_file (); - else - prep_lexer_for_function_file (); - - lexer_flags.parsing_class_method = ! dispatch_type.empty (); - - int status = yyparse (); - - fcn_ptr = primary_fcn_ptr; - - if (reading_fcn_file && endfunction_found && max_function_depth > 1) - warning_with_id ("Octave:nested-functions-coerced", - "nested functions are coerced into subfunctions " - "in file %s", ff.c_str ()); - - if (status != 0) - error ("parse error while reading %s file %s", - file_type.c_str(), ff.c_str ()); - } + { + std::string file_type; + + frame.protect_var (get_input_from_eval_string); + frame.protect_var (parser_end_of_input); + frame.protect_var (reading_fcn_file); + frame.protect_var (reading_script_file); + frame.protect_var (reading_classdef_file); + frame.protect_var (Vecho_executing_commands); + + + get_input_from_eval_string = false; + parser_end_of_input = false; + + if (! force_script && looking_at_function_keyword (ffile)) + { + file_type = "function"; + + Vecho_executing_commands = ECHO_OFF; + + reading_classdef_file = false; + reading_fcn_file = true; + reading_script_file = false; + } + else if (! force_script && looking_at_classdef_keyword (ffile)) + { + file_type = "classdef"; + + Vecho_executing_commands = ECHO_OFF; + + reading_classdef_file = true; + reading_fcn_file = false; + reading_script_file = false; + } + else + { + file_type = "script"; + + Vecho_executing_commands = ECHO_OFF; + + reading_classdef_file = false; + reading_fcn_file = false; + reading_script_file = true; + } + + YY_BUFFER_STATE old_buf = current_buffer (); + YY_BUFFER_STATE new_buf = create_buffer (ffile); + + frame.add_fcn (switch_to_buffer, old_buf); + frame.add_fcn (delete_buffer, new_buf); + + switch_to_buffer (new_buf); + + frame.protect_var (primary_fcn_ptr); + primary_fcn_ptr = 0; + + reset_parser (); + + // Do this with an unwind-protect cleanup function so that + // the forced variables will be unmarked in the event of an + // interrupt. + symbol_table::scope_id scope = symbol_table::top_scope (); + frame.add_fcn (symbol_table::unmark_forced_variables, scope); + + if (! help_txt.empty ()) + help_buf.push (help_txt); + + if (reading_script_file) + prep_lexer_for_script_file (); + else + prep_lexer_for_function_file (); + + lexer_flags.parsing_class_method = ! dispatch_type.empty (); + + int status = yyparse (); + + fcn_ptr = primary_fcn_ptr; + + if (reading_fcn_file && endfunction_found && max_function_depth > 1) + warning_with_id ("Octave:nested-functions-coerced", + "nested functions are coerced into subfunctions " + "in file %s", ff.c_str ()); + + if (status != 0) + error ("parse error while reading %s file %s", + file_type.c_str(), ff.c_str ()); + } } else if (require_file) error ("no such file, `%s'", ff.c_str ()); @@ -3580,7 +3580,7 @@ std::string get_help_from_file (const std::string& nm, bool& symbol_found, - std::string& file) + std::string& file) { std::string retval; @@ -3593,25 +3593,25 @@ FILE *fptr = fopen (file.c_str (), "r"); if (fptr) - { - unwind_protect frame; - frame.add_fcn (safe_fclose, fptr); - - bool eof; - retval = gobble_leading_white_space (fptr, eof); - - if (retval.empty ()) - { - octave_function *fcn = parse_fcn_file (file, ""); - - if (fcn) - { - retval = fcn->doc_string (); - - delete fcn; - } - } - } + { + unwind_protect frame; + frame.add_fcn (safe_fclose, fptr); + + bool eof; + retval = gobble_leading_white_space (fptr, eof); + + if (retval.empty ()) + { + octave_function *fcn = parse_fcn_file (file, ""); + + if (fcn) + { + retval = fcn->doc_string (); + + delete fcn; + } + } + } } return retval; @@ -3667,8 +3667,8 @@ octave_function * load_fcn_from_file (const std::string& file_name, const std::string& dir_name, - const std::string& dispatch_type, - const std::string& fcn_name, bool autoload) + const std::string& dispatch_type, + const std::string& fcn_name, bool autoload) { octave_function *retval = 0; @@ -3709,7 +3709,7 @@ if (len > 4 && file.substr (len-4, len-1) == ".oct") { if (autoload && ! fcn_name.empty ()) - nm = fcn_name; + nm = fcn_name; retval = octave_dynamic_loader::load_oct (nm, file, fcn_file_from_relative_lookup); } @@ -3733,11 +3733,11 @@ retval->stash_dir_name (dir_name); if (retval->is_user_function ()) - { - symbol_table::scope_id id = retval->scope (); - - symbol_table::stash_dir_name_for_subfunctions (id, dir_name); - } + { + symbol_table::scope_id id = retval->scope (); + + symbol_table::stash_dir_name_for_subfunctions (id, dir_name); + } } return retval; @@ -3788,12 +3788,12 @@ octave_idx_type i = 0; typedef std::map::const_iterator am_iter; for (am_iter p = autoload_map.begin (); p != autoload_map.end (); p++) - { - func_names(i) = p->first; - file_names(i) = p->second; - - i++; - } + { + func_names(i) = p->first; + file_names(i) = p->second; + + i++; + } Octave_map m; @@ -3808,39 +3808,39 @@ if (! error_state) { - std::string nm = argv[2]; - - if (! octave_env::absolute_pathname (nm)) - { - octave_user_code *fcn = octave_call_stack::caller_user_code (); - - bool found = false; - - if (fcn) - { - std::string fname = fcn->fcn_file_name (); - - if (! fname.empty ()) - { - fname = octave_env::make_absolute (fname); - fname = fname.substr (0, fname.find_last_of (file_ops::dir_sep_str ()) + 1); - - file_stat fs (fname + nm); - - if (fs.exists ()) - { - nm = fname + nm; - found = true; - } - } - } - if (! found) - warning_with_id ("Octave:autoload-relative-file-name", - "autoload: `%s' is not an absolute file name", - nm.c_str ()); - } - autoload_map[argv[1]] = nm; - } + std::string nm = argv[2]; + + if (! octave_env::absolute_pathname (nm)) + { + octave_user_code *fcn = octave_call_stack::caller_user_code (); + + bool found = false; + + if (fcn) + { + std::string fname = fcn->fcn_file_name (); + + if (! fname.empty ()) + { + fname = octave_env::make_absolute (fname); + fname = fname.substr (0, fname.find_last_of (file_ops::dir_sep_str ()) + 1); + + file_stat fs (fname + nm); + + if (fs.exists ()) + { + nm = fname + nm; + found = true; + } + } + } + if (! found) + warning_with_id ("Octave:autoload-relative-file-name", + "autoload: `%s' is not an absolute file name", + nm.c_str ()); + } + autoload_map[argv[1]] = nm; + } } else print_usage (); @@ -3850,7 +3850,7 @@ void source_file (const std::string& file_name, const std::string& context, - bool verbose, bool require_file, const std::string& warn_for) + bool verbose, bool require_file, const std::string& warn_for) { std::string file_full_name = file_ops::tilde_expand (file_name); @@ -3865,45 +3865,45 @@ if (! context.empty ()) { if (context == "caller") - octave_call_stack::goto_caller_frame (); + octave_call_stack::goto_caller_frame (); else if (context == "base") - octave_call_stack::goto_base_frame (); + octave_call_stack::goto_base_frame (); else - error ("source: context must be \"caller\" or \"base\""); + error ("source: context must be \"caller\" or \"base\""); if (! error_state) - frame.add_fcn (octave_call_stack::pop); + frame.add_fcn (octave_call_stack::pop); } if (! error_state) { octave_function *fcn = parse_fcn_file (file_full_name, "", true, - require_file, warn_for); + require_file, warn_for); if (! error_state) - { - if (fcn && fcn->is_user_script ()) - { - octave_value_list args; - - if (verbose) - { - std::cout << "executing commands from " << file_full_name << " ... "; - reading_startup_message_printed = true; - std::cout.flush (); - } - - fcn->do_multi_index_op (0, args); - - if (verbose) - std::cout << "done." << std::endl; - - delete fcn; - } - } + { + if (fcn && fcn->is_user_script ()) + { + octave_value_list args; + + if (verbose) + { + std::cout << "executing commands from " << file_full_name << " ... "; + reading_startup_message_printed = true; + std::cout.flush (); + } + + fcn->do_multi_index_op (0, args); + + if (verbose) + std::cout << "done." << std::endl; + + delete fcn; + } + } else - error ("source: error sourcing file `%s'", - file_full_name.c_str ()); + error ("source: error sourcing file `%s'", + file_full_name.c_str ()); } } @@ -3936,10 +3936,10 @@ arg = args(0).string_value (); if (error_state) - { - error ("mfilename: expecting argument to be a character string"); - return retval; - } + { + error ("mfilename: expecting argument to be a character string"); + return retval; + } } std::string fname; @@ -3967,7 +3967,7 @@ fname = (epos != std::string::npos) ? fname.substr (0, epos) : fname; if (arg == "fullpath") - retval = fname; + retval = fname; else retval = (dpos != std::string::npos) ? fname.substr (dpos+1) : fname; } @@ -3993,19 +3993,19 @@ std::string file_name = args(0).string_value (); if (! error_state) - { - std::string context; - - if (nargin == 2) - context = args(1).string_value (); - - if (! error_state) - source_file (file_name, context); - else - error ("source: expecting context to be character string"); - } + { + std::string context; + + if (nargin == 2) + context = args(1).string_value (); + + if (! error_state) + source_file (file_name, context); + else + error ("source: expecting context to be character string"); + } else - error ("source: expecting file name as argument"); + error ("source: expecting file name as argument"); } else print_usage (); @@ -4068,7 +4068,7 @@ string_vector tmp_arg_names (len); for (int i = 0; i < len; i++) - tmp_arg_names(i) = arg_names(i+1); + tmp_arg_names(i) = arg_names(i+1); retval.stash_name_tags (tmp_arg_names); } @@ -4096,26 +4096,26 @@ if (f_arg.is_string ()) { - std::string name = f_arg.string_value (); - - if (! error_state) - { - octave_value_list tmp_args = get_feval_args (args); - - retval = feval (name, tmp_args, nargout); - } - } + std::string name = f_arg.string_value (); + + if (! error_state) + { + octave_value_list tmp_args = get_feval_args (args); + + retval = feval (name, tmp_args, nargout); + } + } else - { - octave_function *fcn = f_arg.function_value (); - - if (fcn) - { - octave_value_list tmp_args = get_feval_args (args); - - retval = feval (fcn, tmp_args, nargout); - } - } + { + octave_function *fcn = f_arg.function_value (); + + if (fcn) + { + octave_value_list tmp_args = get_feval_args (args); + + retval = feval (fcn, tmp_args, nargout); + } + } } return retval; @@ -4223,56 +4223,56 @@ if (parse_status == 0) { - if (command_list) - { - tree_statement *stmt = 0; - - if (command_list->length () == 1 - && (stmt = command_list->front ()) - && stmt->is_expression ()) - { - tree_expression *expr = stmt->expression (); - - if (silent) - expr->set_print_flag (false); - - bool do_bind_ans = false; - - if (expr->is_identifier ()) - { - tree_identifier *id - = dynamic_cast (expr); - - do_bind_ans = (! id->is_variable ()); - } - else - do_bind_ans = (! expr->is_assignment_expression ()); - - retval = expr->rvalue (nargout); - - if (do_bind_ans && ! (error_state || retval.empty ())) - bind_ans (retval(0), expr->print_result ()); - - if (nargout == 0) - retval = octave_value_list (); - } - else if (nargout == 0) - command_list->accept (*current_evaluator); - else - error ("eval: invalid use of statement list"); - - delete command_list; - - command_list = 0; - - if (error_state - || tree_return_command::returning - || tree_break_command::breaking - || tree_continue_command::continuing) - break; - } - else if (parser_end_of_input) - break; + if (command_list) + { + tree_statement *stmt = 0; + + if (command_list->length () == 1 + && (stmt = command_list->front ()) + && stmt->is_expression ()) + { + tree_expression *expr = stmt->expression (); + + if (silent) + expr->set_print_flag (false); + + bool do_bind_ans = false; + + if (expr->is_identifier ()) + { + tree_identifier *id + = dynamic_cast (expr); + + do_bind_ans = (! id->is_variable ()); + } + else + do_bind_ans = (! expr->is_assignment_expression ()); + + retval = expr->rvalue (nargout); + + if (do_bind_ans && ! (error_state || retval.empty ())) + bind_ans (retval(0), expr->print_result ()); + + if (nargout == 0) + retval = octave_value_list (); + } + else if (nargout == 0) + command_list->accept (*current_evaluator); + else + error ("eval: invalid use of statement list"); + + delete command_list; + + command_list = 0; + + if (error_state + || tree_return_command::returning + || tree_break_command::breaking + || tree_continue_command::continuing) + break; + } + else if (parser_end_of_input) + break; } } while (parse_status == 0); @@ -4295,7 +4295,7 @@ static octave_value_list eval_string (const octave_value& arg, bool silent, int& parse_status, - int nargout) + int nargout) { std::string s = arg.string_value (); @@ -4343,32 +4343,32 @@ unwind_protect frame; if (nargin > 1) - { - frame.protect_var (buffer_error_messages); - buffer_error_messages++; - } + { + frame.protect_var (buffer_error_messages); + buffer_error_messages++; + } int parse_status = 0; octave_value_list tmp = eval_string (args(0), nargout > 0, - parse_status, nargout); + parse_status, nargout); if (nargin > 1 && (parse_status != 0 || error_state)) - { - error_state = 0; - - // Set up for letting the user print any messages from - // errors that occurred in the first part of this eval(). - - buffer_error_messages--; - - tmp = eval_string (args(1), nargout > 0, parse_status, nargout); - - if (nargout > 0) - retval = tmp; - } + { + error_state = 0; + + // Set up for letting the user print any messages from + // errors that occurred in the first part of this eval(). + + buffer_error_messages--; + + tmp = eval_string (args(1), nargout > 0, parse_status, nargout); + + if (nargout > 0) + retval = tmp; + } else if (nargout > 0) - retval = tmp; + retval = tmp; } else print_usage (); @@ -4476,32 +4476,32 @@ if (! error_state) { - unwind_protect frame; - - if (context == "caller") - octave_call_stack::goto_caller_frame (); - else if (context == "base") - octave_call_stack::goto_base_frame (); - else - error ("assignin: context must be \"caller\" or \"base\""); - - if (! error_state) - { - frame.add_fcn (octave_call_stack::pop); - - std::string nm = args(1).string_value (); - - if (! error_state) - { - if (valid_identifier (nm)) - symbol_table::varref (nm) = args(2); - else - error ("assignin: invalid variable name"); - } - else - error ("assignin: expecting variable name as second argument"); - } - } + unwind_protect frame; + + if (context == "caller") + octave_call_stack::goto_caller_frame (); + else if (context == "base") + octave_call_stack::goto_base_frame (); + else + error ("assignin: context must be \"caller\" or \"base\""); + + if (! error_state) + { + frame.add_fcn (octave_call_stack::pop); + + std::string nm = args(1).string_value (); + + if (! error_state) + { + if (valid_identifier (nm)) + symbol_table::varref (nm) = args(2); + else + error ("assignin: invalid variable name"); + } + else + error ("assignin: expecting variable name as second argument"); + } + } else error ("assignin: expecting string as first argument"); } @@ -4529,49 +4529,49 @@ if (! error_state) { - unwind_protect frame; - - if (context == "caller") - octave_call_stack::goto_caller_frame (); - else if (context == "base") - octave_call_stack::goto_base_frame (); - else - error ("evalin: context must be \"caller\" or \"base\""); - - if (! error_state) - { - frame.add_fcn (octave_call_stack::pop); - - if (nargin > 2) - { - frame.protect_var (buffer_error_messages); - buffer_error_messages++; - } - - int parse_status = 0; - - octave_value_list tmp = eval_string (args(1), nargout > 0, - parse_status, nargout); - - if (nargout > 0) - retval = tmp; - - if (nargin > 2 && (parse_status != 0 || error_state)) - { - error_state = 0; - - // Set up for letting the user print any messages from - // errors that occurred in the first part of this eval(). - - buffer_error_messages--; - - tmp = eval_string (args(2), nargout > 0, - parse_status, nargout); - - retval = (nargout > 0) ? tmp : octave_value_list (); - } - } - } + unwind_protect frame; + + if (context == "caller") + octave_call_stack::goto_caller_frame (); + else if (context == "base") + octave_call_stack::goto_base_frame (); + else + error ("evalin: context must be \"caller\" or \"base\""); + + if (! error_state) + { + frame.add_fcn (octave_call_stack::pop); + + if (nargin > 2) + { + frame.protect_var (buffer_error_messages); + buffer_error_messages++; + } + + int parse_status = 0; + + octave_value_list tmp = eval_string (args(1), nargout > 0, + parse_status, nargout); + + if (nargout > 0) + retval = tmp; + + if (nargin > 2 && (parse_status != 0 || error_state)) + { + error_state = 0; + + // Set up for letting the user print any messages from + // errors that occurred in the first part of this eval(). + + buffer_error_messages--; + + tmp = eval_string (args(2), nargout > 0, + parse_status, nargout); + + retval = (nargout > 0) ? tmp : octave_value_list (); + } + } + } else error ("evalin: expecting string as first argument"); } @@ -4592,7 +4592,7 @@ bool debug_flag = octave_debug; retval = set_internal_variable (debug_flag, args, nargout, - "__parser_debug_flag__"); + "__parser_debug_flag__"); octave_debug = debug_flag; diff --git a/src/oct-prcstrm.cc b/src/oct-prcstrm.cc --- a/src/oct-prcstrm.cc +++ b/src/oct-prcstrm.cc @@ -32,16 +32,16 @@ octave_stream octave_iprocstream::create (const std::string& n, std::ios::openmode arg_md, - oct_mach_info::float_format ff) + oct_mach_info::float_format ff) { return octave_stream (new octave_iprocstream (n, arg_md, ff)); } octave_iprocstream::octave_iprocstream (const std::string& n, - std::ios::openmode arg_md, - oct_mach_info::float_format ff) + std::ios::openmode arg_md, + oct_mach_info::float_format ff) : octave_stdiostream (n, octave_popen (n.c_str (), "r"), - arg_md, ff, octave_pclose) + arg_md, ff, octave_pclose) { } @@ -52,16 +52,16 @@ octave_stream octave_oprocstream::create (const std::string& n, std::ios::openmode arg_md, - oct_mach_info::float_format ff) + oct_mach_info::float_format ff) { return octave_stream (new octave_oprocstream (n, arg_md, ff)); } octave_oprocstream::octave_oprocstream (const std::string& n, - std::ios::openmode arg_md, - oct_mach_info::float_format ff) + std::ios::openmode arg_md, + oct_mach_info::float_format ff) : octave_stdiostream (n, octave_popen (n.c_str (), "w"), - arg_md, ff, octave_pclose) + arg_md, ff, octave_pclose) { } diff --git a/src/oct-procbuf.cc b/src/oct-procbuf.cc --- a/src/oct-procbuf.cc +++ b/src/oct-procbuf.cc @@ -108,23 +108,23 @@ ::close (parent_end); if (child_end != child_std_end) - { - ::dup2 (child_end, child_std_end); - ::close (child_end); - } + { + ::dup2 (child_end, child_std_end); + ::close (child_end); + } while (octave_procbuf_list) - { - FILE *fp = octave_procbuf_list->f; + { + FILE *fp = octave_procbuf_list->f; - if (fp) - { - ::fclose (fp); - fp = 0; - } + if (fp) + { + ::fclose (fp); + fp = 0; + } - octave_procbuf_list = octave_procbuf_list->next; - } + octave_procbuf_list = octave_procbuf_list->next; + } execl ("/bin/sh", "sh", "-c", command, static_cast (0)); @@ -182,27 +182,27 @@ int status = -1; for (octave_procbuf **ptr = &octave_procbuf_list; - *ptr != 0; - ptr = &(*ptr)->next) - { - if (*ptr == this) - { - *ptr = (*ptr)->next; - status = 0; - break; - } - } + *ptr != 0; + ptr = &(*ptr)->next) + { + if (*ptr == this) + { + *ptr = (*ptr)->next; + status = 0; + break; + } + } if (status == 0 && ::fclose (f) == 0) - { - using namespace std; + { + using namespace std; - do - { - wait_pid = octave_syscalls::waitpid (proc_pid, &wstatus, 0); - } - while (wait_pid == -1 && errno == EINTR); - } + do + { + wait_pid = octave_syscalls::waitpid (proc_pid, &wstatus, 0); + } + while (wait_pid == -1 && errno == EINTR); + } f = 0; } diff --git a/src/oct-stream.cc b/src/oct-stream.cc --- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -70,16 +70,16 @@ if (! error_state) { if (! lo_ieee_isnan (dval)) - { - int ival = NINT (dval); - - if (ival == dval) - retval = ival; - else - conv_err = 3; - } + { + int ival = NINT (dval); + + if (ival == dval) + retval = ival; + else + conv_err = 3; + } else - conv_err = 2; + conv_err = 2; } else conv_err = 1; @@ -95,15 +95,15 @@ if (! lo_ieee_isnan (d)) { if (! xisinf (d)) - { - if (d >= 0.0) - retval = NINT (d); - else - ::error ("%s: negative value invalid as size specification", - who.c_str ()); - } + { + if (d >= 0.0) + retval = NINT (d); + else + ::error ("%s: negative value invalid as size specification", + who.c_str ()); + } else - retval = -1; + retval = -1; } else ::error ("%s: NaN is invalid as size specification", who.c_str ()); @@ -113,7 +113,7 @@ static void get_size (const Array& size, octave_idx_type& nr, octave_idx_type& nc, bool& one_elt_size_spec, - const std::string& who) + const std::string& who) { nr = -1; nc = -1; @@ -138,9 +138,9 @@ dnr = size (0); if (! xisinf (dnr)) - dnc = size (1); + dnc = size (1); else - ::error ("%s: invalid size specification", who.c_str ()); + ::error ("%s: invalid size specification", who.c_str ()); } else ::error ("%s: invalid size specification", who.c_str ()); @@ -150,7 +150,7 @@ nr = get_size (dnr, who); if (! error_state && dnc >= 0.0) - nc = get_size (dnc, who); + nc = get_size (dnc, who); } } @@ -175,54 +175,54 @@ have_more = true; if (! buf) - buf = new std::ostringstream (); + buf = new std::ostringstream (); if (s[i] == '%') - { - // Process percent-escape conversion type. - - process_conversion (s, i, n, width, discard, type, modifier, - num_elts); - - have_more = (buf != 0); - } + { + // Process percent-escape conversion type. + + process_conversion (s, i, n, width, discard, type, modifier, + num_elts); + + have_more = (buf != 0); + } else if (isspace (s[i])) - { - type = scanf_format_elt::whitespace_conversion; - - width = 0; - discard = false; - modifier = '\0'; - *buf << " "; - - while (++i < n && isspace (s[i])) - /* skip whitespace */; - - add_elt_to_list (width, discard, type, modifier, num_elts); - - have_more = false; - } + { + type = scanf_format_elt::whitespace_conversion; + + width = 0; + discard = false; + modifier = '\0'; + *buf << " "; + + while (++i < n && isspace (s[i])) + /* skip whitespace */; + + add_elt_to_list (width, discard, type, modifier, num_elts); + + have_more = false; + } else - { - type = scanf_format_elt::literal_conversion; - - width = 0; - discard = false; - modifier = '\0'; - - while (i < n && ! isspace (s[i]) && s[i] != '%') - *buf << s[i++]; - - add_elt_to_list (width, discard, type, modifier, num_elts); - - have_more = false; - } + { + type = scanf_format_elt::literal_conversion; + + width = 0; + discard = false; + modifier = '\0'; + + while (i < n && ! isspace (s[i]) && s[i] != '%') + *buf << s[i++]; + + add_elt_to_list (width, discard, type, modifier, num_elts); + + have_more = false; + } if (nconv < 0) - { - have_more = false; - break; - } + { + have_more = false; + break; + } } if (have_more) @@ -241,29 +241,29 @@ { scanf_format_elt *elt = list(i); delete elt; - } + } } void scanf_format_list::add_elt_to_list (int width, bool discard, char type, - char modifier, octave_idx_type& num_elts, - const std::string& char_class) + char modifier, octave_idx_type& num_elts, + const std::string& char_class) { if (buf) { std::string text = buf->str (); if (! text.empty ()) - { - scanf_format_elt *elt - = new scanf_format_elt (text.c_str (), width, discard, type, - modifier, char_class); - - if (num_elts == list.length ()) - list.resize (2 * num_elts); - - list(num_elts++) = elt; - } + { + scanf_format_elt *elt + = new scanf_format_elt (text.c_str (), width, discard, type, + modifier, char_class); + + if (num_elts == list.length ()) + list.resize (2 * num_elts); + + list(num_elts++) = elt; + } delete buf; buf = 0; @@ -284,22 +284,22 @@ unsigned char c = s[i++]; if (c == '-' && i > 1 && i < len - && static_cast (s[i-2]) <= static_cast (s[i])) - { - // Add all characters from the range except the first (we - // already added it below). - - for (c = s[i-2]+1; c < s[i]; c++) - retval += c; - } + && static_cast (s[i-2]) <= static_cast (s[i])) + { + // Add all characters from the range except the first (we + // already added it below). + + for (c = s[i-2]+1; c < s[i]; c++) + retval += c; + } else - { - // Add the character to the class. Only add '-' if it is - // the last character in the class. - - if (c != '-' || i == len) - retval += c; - } + { + // Add the character to the class. Only add '-' if it is + // the last character in the class. + + if (c != '-' || i == len) + retval += c; + } } return retval; @@ -323,86 +323,86 @@ while (i < n) { switch (s[i]) - { - case '*': - if (discard) - nconv = -1; - else - { - discard = true; - *buf << s[i++]; - } - break; - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - if (have_width) - nconv = -1; - else - { - char c = s[i++]; - width = width * 10 + c - '0'; - have_width = true; - *buf << c; - while (i < n && isdigit (s[i])) - { - c = s[i++]; - width = width * 10 + c - '0'; - *buf << c; - } - } - break; - - case 'h': case 'l': case 'L': - if (modifier != '\0') - nconv = -1; - else - modifier = s[i++]; - break; - - case 'd': case 'i': case 'o': case 'u': case 'x': - if (modifier == 'L') - { - nconv = -1; - break; - } - goto fini; - - case 'e': case 'f': case 'g': - if (modifier == 'h') - { - nconv = -1; - break; - } - - // No float or long double conversions, thanks. - *buf << 'l'; - - goto fini; - - case 'c': case 's': case 'p': case '%': case '[': - if (modifier != '\0') - { - nconv = -1; - break; - } - goto fini; - - fini: - { - if (finish_conversion (s, i, n, width, discard, type, - modifier, num_elts) == 0) - return; - } - break; - - default: - nconv = -1; - break; - } + { + case '*': + if (discard) + nconv = -1; + else + { + discard = true; + *buf << s[i++]; + } + break; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + if (have_width) + nconv = -1; + else + { + char c = s[i++]; + width = width * 10 + c - '0'; + have_width = true; + *buf << c; + while (i < n && isdigit (s[i])) + { + c = s[i++]; + width = width * 10 + c - '0'; + *buf << c; + } + } + break; + + case 'h': case 'l': case 'L': + if (modifier != '\0') + nconv = -1; + else + modifier = s[i++]; + break; + + case 'd': case 'i': case 'o': case 'u': case 'x': + if (modifier == 'L') + { + nconv = -1; + break; + } + goto fini; + + case 'e': case 'f': case 'g': + if (modifier == 'h') + { + nconv = -1; + break; + } + + // No float or long double conversions, thanks. + *buf << 'l'; + + goto fini; + + case 'c': case 's': case 'p': case '%': case '[': + if (modifier != '\0') + { + nconv = -1; + break; + } + goto fini; + + fini: + { + if (finish_conversion (s, i, n, width, discard, type, + modifier, num_elts) == 0) + return; + } + break; + + default: + nconv = -1; + break; + } if (nconv < 0) - break; + break; } nconv = -1; @@ -431,44 +431,44 @@ type = s[i]; if (s[i] == '[') - { - *buf << s[i++]; - - if (i < n) - { - beg_idx = i; - - if (s[i] == '^') - { - type = '^'; - *buf << s[i++]; - - if (i < n) - { - beg_idx = i; - - if (s[i] == ']') - *buf << s[i++]; - } - } - else if (s[i] == ']') - *buf << s[i++]; - } - - while (i < n && s[i] != ']') - *buf << s[i++]; - - if (i < n && s[i] == ']') - { - end_idx = i-1; - *buf << s[i++]; - } - - if (s[i-1] != ']') - retval = nconv = -1; - } + { + *buf << s[i++]; + + if (i < n) + { + beg_idx = i; + + if (s[i] == '^') + { + type = '^'; + *buf << s[i++]; + + if (i < n) + { + beg_idx = i; + + if (s[i] == ']') + *buf << s[i++]; + } + } + else if (s[i] == ']') + *buf << s[i++]; + } + + while (i < n && s[i] != ']') + *buf << s[i++]; + + if (i < n && s[i] == ']') + { + end_idx = i-1; + *buf << s[i++]; + } + + if (s[i-1] != ']') + retval = nconv = -1; + } else - *buf << s[i++]; + *buf << s[i++]; nconv++; } @@ -476,8 +476,8 @@ if (nconv >= 0) { if (beg_idx != std::string::npos && end_idx != std::string::npos) - char_class = expand_char_class (s.substr (beg_idx, - end_idx - beg_idx + 1)); + char_class = expand_char_class (s.substr (beg_idx, + end_idx - beg_idx + 1)); add_elt_to_list (width, discard, type, modifier, num_elts, char_class); } @@ -495,21 +495,21 @@ scanf_format_elt *elt = list(i); std::cerr - << "width: " << elt->width << "\n" - << "discard: " << elt->discard << "\n" - << "type: "; + << "width: " << elt->width << "\n" + << "discard: " << elt->discard << "\n" + << "type: "; if (elt->type == scanf_format_elt::literal_conversion) - std::cerr << "literal text\n"; + std::cerr << "literal text\n"; else if (elt->type == scanf_format_elt::whitespace_conversion) - std::cerr << "whitespace\n"; + std::cerr << "whitespace\n"; else - std::cerr << elt->type << "\n"; + std::cerr << elt->type << "\n"; std::cerr - << "modifier: " << elt->modifier << "\n" - << "char_class: `" << undo_string_escapes (elt->char_class) << "'\n" - << "text: `" << undo_string_escapes (elt->text) << "'\n\n"; + << "modifier: " << elt->modifier << "\n" + << "char_class: `" << undo_string_escapes (elt->char_class) << "'\n" + << "text: `" << undo_string_escapes (elt->text) << "'\n\n"; } } @@ -521,21 +521,21 @@ if (n > 0) { for (octave_idx_type i = 0; i < n; i++) - { - scanf_format_elt *elt = list(i); - - switch (elt->type) - { - case 'c': case 's': case '%': case '[': case '^': - case scanf_format_elt::literal_conversion: - case scanf_format_elt::whitespace_conversion: - break; - - default: - return false; - break; - } - } + { + scanf_format_elt *elt = list(i); + + switch (elt->type) + { + case 'c': case 's': case '%': case '[': case '^': + case scanf_format_elt::literal_conversion: + case scanf_format_elt::whitespace_conversion: + break; + + default: + return false; + break; + } + } return true; } @@ -551,20 +551,20 @@ if (n > 0) { for (octave_idx_type i = 0; i < n; i++) - { - scanf_format_elt *elt = list(i); - - switch (elt->type) - { - case 'd': case 'i': case 'o': case 'u': case 'x': - case 'e': case 'f': case 'g': - break; - - default: - return false; - break; - } - } + { + scanf_format_elt *elt = list(i); + + switch (elt->type) + { + case 'd': case 'i': case 'o': case 'u': case 'x': + case 'e': case 'f': case 'g': + break; + + default: + return false; + break; + } + } return true; } @@ -596,7 +596,7 @@ if (n == 0) { printf_format_elt *elt - = new printf_format_elt ("", args, fw, prec, flags, type, modifier); + = new printf_format_elt ("", args, fw, prec, flags, type, modifier); list(num_elts++) = elt; @@ -605,55 +605,55 @@ else { while (i < n) - { - have_more = true; - - if (! buf) - { - buf = new std::ostringstream (); - empty_buf = true; - } - - switch (s[i]) - { - case '%': - { - if (empty_buf) - { - process_conversion (s, i, n, args, flags, fw, prec, - type, modifier, num_elts); - - have_more = (buf != 0); - } - else - add_elt_to_list (args, flags, fw, prec, type, modifier, - num_elts); - } - break; - - default: - { - args = 0; - flags = ""; - fw = 0; - prec = 0; - modifier = '\0'; - type = '\0'; - *buf << s[i++]; - empty_buf = false; - } - break; - } - - if (nconv < 0) - { - have_more = false; - break; - } - } + { + have_more = true; + + if (! buf) + { + buf = new std::ostringstream (); + empty_buf = true; + } + + switch (s[i]) + { + case '%': + { + if (empty_buf) + { + process_conversion (s, i, n, args, flags, fw, prec, + type, modifier, num_elts); + + have_more = (buf != 0); + } + else + add_elt_to_list (args, flags, fw, prec, type, modifier, + num_elts); + } + break; + + default: + { + args = 0; + flags = ""; + fw = 0; + prec = 0; + modifier = '\0'; + type = '\0'; + *buf << s[i++]; + empty_buf = false; + } + break; + } + + if (nconv < 0) + { + have_more = false; + break; + } + } if (have_more) - add_elt_to_list (args, flags, fw, prec, type, modifier, num_elts); + add_elt_to_list (args, flags, fw, prec, type, modifier, num_elts); list.resize (num_elts); @@ -669,29 +669,29 @@ { printf_format_elt *elt = list(i); delete elt; - } + } } void printf_format_list::add_elt_to_list (int args, const std::string& flags, - int fw, int prec, char type, - char modifier, octave_idx_type& num_elts) + int fw, int prec, char type, + char modifier, octave_idx_type& num_elts) { if (buf) { std::string text = buf->str (); if (! text.empty ()) - { - printf_format_elt *elt - = new printf_format_elt (text.c_str (), args, fw, prec, flags, - type, modifier); - - if (num_elts == list.length ()) - list.resize (2 * num_elts); - - list(num_elts++) = elt; - } + { + printf_format_elt *elt + = new printf_format_elt (text.c_str (), args, fw, prec, flags, + type, modifier); + + if (num_elts == list.length ()) + list.resize (2 * num_elts); + + list(num_elts++) = elt; + } delete buf; buf = 0; @@ -717,41 +717,41 @@ while (i < n) { switch (s[i]) - { - case '-': case '+': case ' ': case '0': case '#': - flags += s[i]; - *buf << s[i++]; - break; - - default: - nxt = true; - break; - } + { + case '-': case '+': case ' ': case '0': case '#': + flags += s[i]; + *buf << s[i++]; + break; + + default: + nxt = true; + break; + } if (nxt) - break; + break; } if (i < n) { if (s[i] == '*') - { - fw = -1; - args++; - *buf << s[i++]; - } + { + fw = -1; + args++; + *buf << s[i++]; + } else - { - if (isdigit (s[i])) - { - int nn = 0; - std::string tmp = s.substr (i); - sscanf (tmp.c_str (), "%d%n", &fw, &nn); - } - - while (i < n && isdigit (s[i])) - *buf << s[i++]; - } + { + if (isdigit (s[i])) + { + int nn = 0; + std::string tmp = s.substr (i); + sscanf (tmp.c_str (), "%d%n", &fw, &nn); + } + + while (i < n && isdigit (s[i])) + *buf << s[i++]; + } } if (i < n && s[i] == '.') @@ -759,40 +759,40 @@ *buf << s[i++]; if (i < n) - { - if (s[i] == '*') - { - prec = -1; - args++; - *buf << s[i++]; - } - else - { - if (isdigit (s[i])) - { - int nn = 0; - std::string tmp = s.substr (i); - sscanf (tmp.c_str (), "%d%n", &prec, &nn); - } - - while (i < n && isdigit (s[i])) - *buf << s[i++]; - } - } + { + if (s[i] == '*') + { + prec = -1; + args++; + *buf << s[i++]; + } + else + { + if (isdigit (s[i])) + { + int nn = 0; + std::string tmp = s.substr (i); + sscanf (tmp.c_str (), "%d%n", &prec, &nn); + } + + while (i < n && isdigit (s[i])) + *buf << s[i++]; + } + } } if (i < n) { switch (s[i]) - { - case 'h': case 'l': case 'L': - modifier = s[i]; - *buf << s[i++]; - break; - - default: - break; - } + { + case 'h': case 'l': case 'L': + modifier = s[i]; + *buf << s[i++]; + break; + + default: + break; + } } if (i < n) @@ -812,26 +812,26 @@ case 'd': case 'i': case 'o': case 'x': case 'X': case 'u': case 'c': if (modifier == 'L') - { - nconv = -1; - break; - } + { + nconv = -1; + break; + } goto fini; case 'f': case 'e': case 'E': case 'g': case 'G': if (modifier == 'h' || modifier == 'l') - { - nconv = -1; - break; - } + { + nconv = -1; + break; + } goto fini; case 's': case 'p': case '%': if (modifier != '\0') - { - nconv = -1; - break; - } + { + nconv = -1; + break; + } goto fini; fini: @@ -841,10 +841,10 @@ *buf << s[i++]; if (type != '%' || args != 0) - nconv++; + nconv++; if (type != '%') - args++; + args++; add_elt_to_list (args, flags, fw, prec, type, modifier, num_elts); @@ -866,13 +866,13 @@ printf_format_elt *elt = list(i); std::cerr - << "args: " << elt->args << "\n" - << "flags: `" << elt->flags << "'\n" - << "width: " << elt->fw << "\n" - << "prec: " << elt->prec << "\n" - << "type: `" << elt->type << "'\n" - << "modifier: `" << elt->modifier << "'\n" - << "text: `" << undo_string_escapes (elt->text) << "'\n\n"; + << "args: " << elt->args << "\n" + << "flags: `" << elt->flags << "'\n" + << "width: " << elt->fw << "\n" + << "prec: " << elt->prec << "\n" + << "type: `" << elt->type << "'\n" + << "modifier: `" << elt->modifier << "'\n" + << "text: `" << undo_string_escapes (elt->text) << "'\n\n"; } } @@ -911,9 +911,9 @@ if (i_fid >= 0) { if (o_fid >= 0) - retval = (i_fid == o_fid) ? i_fid : -1; + retval = (i_fid == o_fid) ? i_fid : -1; else - retval = i_fid; + retval = i_fid; } else if (o_fid >= 0) retval = o_fid; @@ -960,15 +960,15 @@ std::string octave_base_stream::do_gets (octave_idx_type max_len, bool& err, - bool strip_newline, const std::string& who) + bool strip_newline, const std::string& who) { std::string retval; if ((interactive || forced_interactive) && file_number () == 0) { ::error ("%s: unable to read from stdin while running interactively", - who.c_str ()); - + who.c_str ()); + return retval; } @@ -986,71 +986,71 @@ int char_count = 0; if (max_len != 0) - { - while (is && (c = is.get ()) != EOF) - { - char_count++; - - // Handle CRLF, CR, or LF as line ending. - - if (c == '\r') - { - if (! strip_newline) - buf << static_cast (c); - - c = is.get (); - - if (c != EOF) - { - if (c == '\n') - { - char_count++; - - if (! strip_newline) - buf << static_cast (c); - } - else - is.putback (c); - } - - break; - } - else if (c == '\n') - { - if (! strip_newline) - buf << static_cast (c); - - break; - } - else - buf << static_cast (c); - - if (max_len > 0 && char_count == max_len) - break; - } - } + { + while (is && (c = is.get ()) != EOF) + { + char_count++; + + // Handle CRLF, CR, or LF as line ending. + + if (c == '\r') + { + if (! strip_newline) + buf << static_cast (c); + + c = is.get (); + + if (c != EOF) + { + if (c == '\n') + { + char_count++; + + if (! strip_newline) + buf << static_cast (c); + } + else + is.putback (c); + } + + break; + } + else if (c == '\n') + { + if (! strip_newline) + buf << static_cast (c); + + break; + } + else + buf << static_cast (c); + + if (max_len > 0 && char_count == max_len) + break; + } + } if (! is.eof () && char_count > 0) - { - // GAGME. Matlab seems to check for EOF even if the last - // character in a file is a newline character. This is NOT - // what the corresponding C-library functions do. - int disgusting_compatibility_hack = is.get (); - if (! is.eof ()) - is.putback (disgusting_compatibility_hack); - } + { + // GAGME. Matlab seems to check for EOF even if the last + // character in a file is a newline character. This is NOT + // what the corresponding C-library functions do. + int disgusting_compatibility_hack = is.get (); + if (! is.eof ()) + is.putback (disgusting_compatibility_hack); + } if (is.good () || (is.eof () && char_count > 0)) - retval = buf.str (); + retval = buf.str (); else - { - err = true; - - if (is.eof () && char_count == 0) - error (who, "at end of file"); - else - error (who, "read error"); - } + { + err = true; + + if (is.eof () && char_count == 0) + error (who, "at end of file"); + else + error (who, "read error"); + } } else { @@ -1081,8 +1081,8 @@ if ((interactive || forced_interactive) && file_number () == 0) { ::error ("%s: unable to read from stdin while running interactively", - who.c_str ()); - + who.c_str ()); + return count; } @@ -1152,15 +1152,15 @@ case 'i': { - int c1 = is.get (); - - if (! is.eof ()) - { - if (c1 == '0') - { - int c2 = is.peek (); - - if (c2 == 'x' || c2 == 'X') + int c1 = is.get (); + + if (! is.eof ()) + { + if (c1 == '0') + { + int c2 = is.peek (); + + if (c2 == 'x' || c2 == 'X') { is.ignore (); if (std::isxdigit (is.peek ())) @@ -1168,23 +1168,23 @@ else ref = 0; } - else - { - if (c2 == '0' || c2 == '1' || c2 == '2' - || c2 == '3' || c2 == '4' || c2 == '5' - || c2 == '6' || c2 == '7') - is >> std::oct >> ref >> std::dec; - else - ref = 0; - } - } - else - { - is.putback (c1); - - is >> ref; - } - } + else + { + if (c2 == '0' || c2 == '1' || c2 == '2' + || c2 == '3' || c2 == '4' || c2 == '5' + || c2 == '6' || c2 == '7') + is >> std::oct >> ref >> std::dec; + else + ref = 0; + } + } + else + { + is.putback (c1); + + is >> ref; + } + } } break; @@ -1226,7 +1226,7 @@ template<> std::istream& octave_scan<> (std::istream& is, const scanf_format_elt& /* fmt */, - char* valptr) + char* valptr) { return is >> valptr; } @@ -1266,159 +1266,159 @@ case 'f': case 'g': { - int c1 = EOF; - - while (is && (c1 = is.get ()) != EOF && isspace (c1)) - /* skip whitespace */; - - if (c1 != EOF) - { - if (c1 == 'N') - { - int c2 = is.get (); - - if (c2 != EOF) - { - if (c2 == 'A') - { - int c3 = is.get (); - - if (c3 != EOF) - { - is.putback (c3); - - if (isspace (c3) || ispunct (c3)) - ref = octave_NA; - else - { - is.putback (c2); - is.putback (c1); - - is >> ref; - } - } - else - { - is.clear (); - - ref = octave_NA; - } - } - else if (c2 == 'a') - { - int c3 = is.get (); - - if (c3 != EOF) - { - if (c3 == 'N') - { - int c4 = is.get (); - - if (c4 != EOF) - { - is.putback (c4); - - if (isspace (c4) || ispunct (c4)) - ref = octave_NaN; - else - { - is.putback (c3); - is.putback (c2); - is.putback (c1); - - is >> ref; - } - } - else - { - is.clear (); - - ref = octave_NaN; - } - } - else - { - is.putback (c3); - is.putback (c2); - is.putback (c1); - - is >> ref; - } - } - } - else - { - is.putback (c2); - is.putback (c1); - - is >> ref; - } - } - } - else if (c1 == 'I') - { - int c2 = is.get (); - - if (c2 != EOF) - { - if (c2 == 'n') - { - int c3 = is.get (); - - if (c3 != EOF) - { - if (c3 == 'f') - { - int c4 = is.get (); - - if (c4 != EOF) - { - is.putback (c4); - - if (isspace (c4) || ispunct (c4)) - ref = octave_Inf; - else - { - is.putback (c3); - is.putback (c2); - is.putback (c1); - - is >> ref; - } - } - else - { - is.clear (); - - ref = octave_Inf; - } - } - else - { - is.putback (c3); - is.putback (c2); - is.putback (c1); - - is >> ref; - } - } - else - { - is.putback (c2); - is.putback (c1); - - is >> ref; - } - } - } - } - else - { - is.putback (c1); - - is >> ref; - } - } + int c1 = EOF; + + while (is && (c1 = is.get ()) != EOF && isspace (c1)) + /* skip whitespace */; + + if (c1 != EOF) + { + if (c1 == 'N') + { + int c2 = is.get (); + + if (c2 != EOF) + { + if (c2 == 'A') + { + int c3 = is.get (); + + if (c3 != EOF) + { + is.putback (c3); + + if (isspace (c3) || ispunct (c3)) + ref = octave_NA; + else + { + is.putback (c2); + is.putback (c1); + + is >> ref; + } + } + else + { + is.clear (); + + ref = octave_NA; + } + } + else if (c2 == 'a') + { + int c3 = is.get (); + + if (c3 != EOF) + { + if (c3 == 'N') + { + int c4 = is.get (); + + if (c4 != EOF) + { + is.putback (c4); + + if (isspace (c4) || ispunct (c4)) + ref = octave_NaN; + else + { + is.putback (c3); + is.putback (c2); + is.putback (c1); + + is >> ref; + } + } + else + { + is.clear (); + + ref = octave_NaN; + } + } + else + { + is.putback (c3); + is.putback (c2); + is.putback (c1); + + is >> ref; + } + } + } + else + { + is.putback (c2); + is.putback (c1); + + is >> ref; + } + } + } + else if (c1 == 'I') + { + int c2 = is.get (); + + if (c2 != EOF) + { + if (c2 == 'n') + { + int c3 = is.get (); + + if (c3 != EOF) + { + if (c3 == 'f') + { + int c4 = is.get (); + + if (c4 != EOF) + { + is.putback (c4); + + if (isspace (c4) || ispunct (c4)) + ref = octave_Inf; + else + { + is.putback (c3); + is.putback (c2); + is.putback (c1); + + is >> ref; + } + } + else + { + is.clear (); + + ref = octave_Inf; + } + } + else + { + is.putback (c3); + is.putback (c2); + is.putback (c1); + + is >> ref; + } + } + else + { + is.putback (c2); + is.putback (c1); + + is >> ref; + } + } + } + } + else + { + is.putback (c1); + + is >> ref; + } + } } break; @@ -1433,67 +1433,67 @@ template void do_scanf_conv (std::istream& is, const scanf_format_elt& fmt, - T valptr, Matrix& mval, double *data, octave_idx_type& idx, - octave_idx_type& conversion_count, octave_idx_type nr, octave_idx_type max_size, - bool discard) + T valptr, Matrix& mval, double *data, octave_idx_type& idx, + octave_idx_type& conversion_count, octave_idx_type nr, octave_idx_type max_size, + bool discard) { OCTAVE_SCAN (is, fmt, valptr); if (is) { if (idx == max_size && ! discard) - { - max_size *= 2; - - if (nr > 0) - mval.resize (nr, max_size / nr, 0.0); - else - mval.resize (max_size, 1, 0.0); - - data = mval.fortran_vec (); - } + { + max_size *= 2; + + if (nr > 0) + mval.resize (nr, max_size / nr, 0.0); + else + mval.resize (max_size, 1, 0.0); + + data = mval.fortran_vec (); + } if (! discard) - { - conversion_count++; - data[idx++] = *(valptr); - } + { + conversion_count++; + data[idx++] = *(valptr); + } } } template void do_scanf_conv (std::istream&, const scanf_format_elt&, int*, - Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); + Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); template void do_scanf_conv (std::istream&, const scanf_format_elt&, long int*, - Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); + Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); template void do_scanf_conv (std::istream&, const scanf_format_elt&, short int*, - Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); + Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); template void do_scanf_conv (std::istream&, const scanf_format_elt&, unsigned int*, - Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); + Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); template void do_scanf_conv (std::istream&, const scanf_format_elt&, unsigned long int*, - Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); + Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); template void do_scanf_conv (std::istream&, const scanf_format_elt&, unsigned short int*, - Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); + Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); #if 0 template void do_scanf_conv (std::istream&, const scanf_format_elt&, float*, - Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); + Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); #endif template void do_scanf_conv (std::istream&, const scanf_format_elt&, double*, - Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); + Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); #define DO_WHITESPACE_CONVERSION() \ do \ @@ -1501,10 +1501,10 @@ int c = EOF; \ \ while (is && (c = is.get ()) != EOF && isspace (c)) \ - /* skip whitespace */; \ + /* skip whitespace */; \ \ if (c != EOF) \ - is.putback (c); \ + is.putback (c); \ } \ while (0) @@ -1517,21 +1517,21 @@ int i = 0; \ \ while (i < n && is && (c = is.get ()) != EOF) \ - { \ - if (c == static_cast (fmt[i])) \ - { \ - i++; \ - continue; \ - } \ - else \ - { \ - is.putback (c); \ - break; \ - } \ - } \ + { \ + if (c == static_cast (fmt[i])) \ + { \ + i++; \ + continue; \ + } \ + else \ + { \ + is.putback (c); \ + break; \ + } \ + } \ \ if (i != n) \ - is.setstate (std::ios::failbit); \ + is.setstate (std::ios::failbit); \ } \ while (0) @@ -1541,15 +1541,15 @@ int c = is.get (); \ \ if (c != EOF) \ - { \ - if (c != '%') \ - { \ - is.putback (c); \ - is.setstate (std::ios::failbit); \ - } \ - } \ + { \ + if (c != '%') \ + { \ + is.putback (c); \ + is.setstate (std::ios::failbit); \ + } \ + } \ else \ - is.setstate (std::ios::failbit); \ + is.setstate (std::ios::failbit); \ } \ while (0) @@ -1627,7 +1627,7 @@ do \ { \ if (! width) \ - width = INT_MAX; \ + width = INT_MAX; \ \ std::ostringstream buf; \ \ @@ -1637,21 +1637,21 @@ \ if (elt->type == '[') \ { \ - int chars_read = 0; \ - while (is && chars_read++ < width && (c = is.get ()) != EOF \ - && char_class.find (c) != std::string::npos) \ - buf << static_cast (c); \ - } \ + int chars_read = 0; \ + while (is && chars_read++ < width && (c = is.get ()) != EOF \ + && char_class.find (c) != std::string::npos) \ + buf << static_cast (c); \ + } \ else \ - { \ - int chars_read = 0; \ - while (is && chars_read++ < width && (c = is.get ()) != EOF \ - && char_class.find (c) == std::string::npos) \ - buf << static_cast (c); \ - } \ + { \ + int chars_read = 0; \ + while (is && chars_read++ < width && (c = is.get ()) != EOF \ + && char_class.find (c) == std::string::npos) \ + buf << static_cast (c); \ + } \ \ if (width == INT_MAX && c != EOF) \ - is.putback (c); \ + is.putback (c); \ \ tmp = buf.str (); \ \ @@ -1666,55 +1666,55 @@ width = tmp.length (); \ \ if (is) \ - { \ - int i = 0; \ + { \ + int i = 0; \ \ - if (! discard) \ - { \ - conversion_count++; \ + if (! discard) \ + { \ + conversion_count++; \ \ - while (i < width) \ - { \ - if (data_index == max_size) \ - { \ - max_size *= 2; \ + while (i < width) \ + { \ + if (data_index == max_size) \ + { \ + max_size *= 2; \ \ - if (all_char_conv) \ - { \ - 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 \ - panic_impossible (); \ - } \ - else if (nr > 0) \ - mval.resize (nr, max_size / nr, 0.0); \ - else \ - mval.resize (max_size, 1, 0.0); \ + if (all_char_conv) \ + { \ + 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 \ + panic_impossible (); \ + } \ + else if (nr > 0) \ + mval.resize (nr, max_size / nr, 0.0); \ + else \ + mval.resize (max_size, 1, 0.0); \ \ - data = mval.fortran_vec (); \ - } \ + data = mval.fortran_vec (); \ + } \ \ - data[data_index++] = tmp[i++]; \ - } \ - } \ - } \ + data[data_index++] = tmp[i++]; \ + } \ + } \ + } \ } \ while (0) octave_value octave_base_stream::do_scanf (scanf_format_list& fmt_list, - octave_idx_type nr, octave_idx_type nc, bool one_elt_size_spec, - octave_idx_type& conversion_count, const std::string& who) + octave_idx_type nr, octave_idx_type nc, bool one_elt_size_spec, + octave_idx_type& conversion_count, const std::string& who) { octave_value retval = Matrix (); if ((interactive || forced_interactive) && file_number () == 0) { ::error ("%s: unable to read from stdin while running interactively", - who.c_str ()); - + who.c_str ()); + return retval; } @@ -1727,7 +1727,7 @@ if (nr == 0 || nc == 0) { if (one_elt_size_spec) - nc = 0; + nc = 0; return Matrix (nr, nc, 0.0); } @@ -1751,44 +1751,44 @@ // conversion). if (one_elt_size_spec) - { - max_size = 512; - mval.resize (1, max_size, 0.0); - - if (nr > 0) - max_conv = nr; - } + { + max_size = 512; + mval.resize (1, max_size, 0.0); + + if (nr > 0) + max_conv = nr; + } else if (nr > 0) - { - 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; - } - } + { + 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 (); + panic_impossible (); } else if (nr > 0) { if (nc > 0) - { - // Will not resize later. - mval.resize (nr, nc, 0.0); - max_size = nr * nc; - max_conv = max_size; - } + { + // Will not resize later. + mval.resize (nr, nc, 0.0); + max_size = nr * nc; + max_conv = max_size; + } else - { - // Maybe resize later. - mval.resize (nr, 32, 0.0); - max_size = nr * 32; - } + { + // Maybe resize later. + mval.resize (nr, 32, 0.0); + max_size = nr * 32; + } } else { @@ -1812,250 +1812,250 @@ octave_idx_type num_fmt_elts = fmt_list.length (); for (;;) - { - octave_quit (); - - if (elt) - { - if (! (elt->type == scanf_format_elt::whitespace_conversion + { + octave_quit (); + + if (elt) + { + if (! (elt->type == scanf_format_elt::whitespace_conversion || elt->type == scanf_format_elt::literal_conversion || elt->type == '%') && max_conv > 0 && conversion_count == max_conv) - { - if (all_char_conv && one_elt_size_spec) - { - final_nr = 1; - final_nc = data_index; - } - else - { - final_nr = nr; - final_nc = (data_index - 1) / nr + 1; - } - - break; - } - else if (data_index == max_size) - { - max_size *= 2; - - if (all_char_conv) - { - 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 - panic_impossible (); - } - else if (nr > 0) - mval.resize (nr, max_size / nr, 0.0); - else - mval.resize (max_size, 1, 0.0); - - data = mval.fortran_vec (); - } - - const char *fmt = elt->text; - - bool discard = elt->discard; - - switch (elt->type) - { - case scanf_format_elt::whitespace_conversion: - DO_WHITESPACE_CONVERSION (); - break; - - case scanf_format_elt::literal_conversion: - DO_LITERAL_CONVERSION (); - break; - - case '%': - DO_PCT_CONVERSION (); - break; - - case 'd': case 'i': - { - switch (elt->modifier) - { - case 'h': - { - short int tmp; - do_scanf_conv (is, *elt, &tmp, mval, data, - data_index, conversion_count, - nr, max_size, discard); - } - break; - - case 'l': - { - long int tmp; - do_scanf_conv (is, *elt, &tmp, mval, data, - data_index, conversion_count, - nr, max_size, discard); - } - break; - - default: - { - int tmp; - do_scanf_conv (is, *elt, &tmp, mval, data, - data_index, conversion_count, - nr, max_size, discard); - } - break; - } - } - break; - - case 'o': case 'u': case 'x': - { - switch (elt->modifier) - { - case 'h': - { - unsigned short int tmp; - do_scanf_conv (is, *elt, &tmp, mval, data, - data_index, conversion_count, - nr, max_size, discard); - } - break; - - case 'l': - { - unsigned long int tmp; - do_scanf_conv (is, *elt, &tmp, mval, data, - data_index, conversion_count, - nr, max_size, discard); - } - break; - - default: - { - unsigned int tmp; - do_scanf_conv (is, *elt, &tmp, mval, data, - data_index, conversion_count, - nr, max_size, discard); - } - break; - } - } - break; - - case 'e': case 'f': case 'g': - { - double tmp; - - do_scanf_conv (is, *elt, &tmp, mval, data, - data_index, conversion_count, - nr, max_size, discard); - } - break; - - case 'c': - { - BEGIN_C_CONVERSION (); - - FINISH_CHARACTER_CONVERSION (); - - is.setf (flags); - } - break; - - case 's': - { - BEGIN_S_CONVERSION (); - - FINISH_CHARACTER_CONVERSION (); - } - break; - - case '[': case '^': - { - BEGIN_CHAR_CLASS_CONVERSION (); - - FINISH_CHARACTER_CONVERSION (); - } - break; - - case 'p': - error ("%s: unsupported format specifier", who.c_str ()); - break; - - default: - error ("%s: internal format error", who.c_str ()); - break; - } - - if (! ok ()) - { - break; - } - else if (! is) - { - if (all_char_conv) - { - if (one_elt_size_spec) - { - final_nr = 1; - final_nc = data_index; - } - else if (data_index > nr) - { - final_nr = nr; - final_nc = (data_index - 1) / nr + 1; - } - else - { - final_nr = data_index; - final_nc = 1; - } - } - else if (nr > 0) - { - if (data_index > nr) - { - final_nr = nr; - final_nc = (data_index - 1) / nr + 1; - } - else - { - final_nr = data_index; - final_nc = 1; - } - } - else - { - final_nr = data_index; - final_nc = 1; - } - - // If it looks like we have a matching failure, then - // reset the failbit in the stream state. - - if (is.rdstate () & std::ios::failbit) - is.clear (is.rdstate () & (~std::ios::failbit)); - - // FIXME -- is this the right thing to do? - - if (interactive && name () == "stdin") - { - is.clear (); - - // Skip to end of line. - - bool err; - do_gets (-1, err, false, who); - } - - break; - } - } - else - { - error ("%s: internal format error", who.c_str ()); - break; - } + { + if (all_char_conv && one_elt_size_spec) + { + final_nr = 1; + final_nc = data_index; + } + else + { + final_nr = nr; + final_nc = (data_index - 1) / nr + 1; + } + + break; + } + else if (data_index == max_size) + { + max_size *= 2; + + if (all_char_conv) + { + 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 + panic_impossible (); + } + else if (nr > 0) + mval.resize (nr, max_size / nr, 0.0); + else + mval.resize (max_size, 1, 0.0); + + data = mval.fortran_vec (); + } + + const char *fmt = elt->text; + + bool discard = elt->discard; + + switch (elt->type) + { + case scanf_format_elt::whitespace_conversion: + DO_WHITESPACE_CONVERSION (); + break; + + case scanf_format_elt::literal_conversion: + DO_LITERAL_CONVERSION (); + break; + + case '%': + DO_PCT_CONVERSION (); + break; + + case 'd': case 'i': + { + switch (elt->modifier) + { + case 'h': + { + short int tmp; + do_scanf_conv (is, *elt, &tmp, mval, data, + data_index, conversion_count, + nr, max_size, discard); + } + break; + + case 'l': + { + long int tmp; + do_scanf_conv (is, *elt, &tmp, mval, data, + data_index, conversion_count, + nr, max_size, discard); + } + break; + + default: + { + int tmp; + do_scanf_conv (is, *elt, &tmp, mval, data, + data_index, conversion_count, + nr, max_size, discard); + } + break; + } + } + break; + + case 'o': case 'u': case 'x': + { + switch (elt->modifier) + { + case 'h': + { + unsigned short int tmp; + do_scanf_conv (is, *elt, &tmp, mval, data, + data_index, conversion_count, + nr, max_size, discard); + } + break; + + case 'l': + { + unsigned long int tmp; + do_scanf_conv (is, *elt, &tmp, mval, data, + data_index, conversion_count, + nr, max_size, discard); + } + break; + + default: + { + unsigned int tmp; + do_scanf_conv (is, *elt, &tmp, mval, data, + data_index, conversion_count, + nr, max_size, discard); + } + break; + } + } + break; + + case 'e': case 'f': case 'g': + { + double tmp; + + do_scanf_conv (is, *elt, &tmp, mval, data, + data_index, conversion_count, + nr, max_size, discard); + } + break; + + case 'c': + { + BEGIN_C_CONVERSION (); + + FINISH_CHARACTER_CONVERSION (); + + is.setf (flags); + } + break; + + case 's': + { + BEGIN_S_CONVERSION (); + + FINISH_CHARACTER_CONVERSION (); + } + break; + + case '[': case '^': + { + BEGIN_CHAR_CLASS_CONVERSION (); + + FINISH_CHARACTER_CONVERSION (); + } + break; + + case 'p': + error ("%s: unsupported format specifier", who.c_str ()); + break; + + default: + error ("%s: internal format error", who.c_str ()); + break; + } + + if (! ok ()) + { + break; + } + else if (! is) + { + if (all_char_conv) + { + if (one_elt_size_spec) + { + final_nr = 1; + final_nc = data_index; + } + else if (data_index > nr) + { + final_nr = nr; + final_nc = (data_index - 1) / nr + 1; + } + else + { + final_nr = data_index; + final_nc = 1; + } + } + else if (nr > 0) + { + if (data_index > nr) + { + final_nr = nr; + final_nc = (data_index - 1) / nr + 1; + } + else + { + final_nr = data_index; + final_nc = 1; + } + } + else + { + final_nr = data_index; + final_nc = 1; + } + + // If it looks like we have a matching failure, then + // reset the failbit in the stream state. + + if (is.rdstate () & std::ios::failbit) + is.clear (is.rdstate () & (~std::ios::failbit)); + + // FIXME -- is this the right thing to do? + + if (interactive && name () == "stdin") + { + is.clear (); + + // Skip to end of line. + + bool err; + do_gets (-1, err, false, who); + } + + break; + } + } + else + { + error ("%s: internal format error", who.c_str ()); + break; + } if (nconv == 0 && ++trips == num_fmt_elts) { @@ -2074,7 +2074,7 @@ } else elt = fmt_list.next (nconv > 0); - } + } } if (ok ()) @@ -2084,7 +2084,7 @@ retval = mval; if (all_char_conv) - retval = retval.convert_to_str (false, true); + retval = retval.convert_to_str (false, true); } return retval; @@ -2092,7 +2092,7 @@ octave_value octave_base_stream::scanf (const std::string& fmt, const Array& size, - octave_idx_type& conversion_count, const std::string& who) + octave_idx_type& conversion_count, const std::string& who) { octave_value retval = Matrix (); @@ -2105,20 +2105,20 @@ scanf_format_list fmt_list (fmt); if (fmt_list.num_conversions () == -1) - ::error ("%s: invalid format specified", who.c_str ()); + ::error ("%s: invalid format specified", who.c_str ()); else - { - octave_idx_type nr = -1; - octave_idx_type nc = -1; - - bool one_elt_size_spec; - - get_size (size, nr, nc, one_elt_size_spec, who); - - if (! error_state) - retval = do_scanf (fmt_list, nr, nc, one_elt_size_spec, - conversion_count, who); - } + { + octave_idx_type nr = -1; + octave_idx_type nc = -1; + + bool one_elt_size_spec; + + get_size (size, nr, nc, one_elt_size_spec, who); + + if (! error_state) + retval = do_scanf (fmt_list, nr, nc, one_elt_size_spec, + conversion_count, who); + } } else invalid_operation (who, "reading"); @@ -2128,7 +2128,7 @@ bool octave_base_stream::do_oscanf (const scanf_format_elt *elt, - octave_value& retval, const std::string& who) + octave_value& retval, const std::string& who) { bool quit = false; @@ -2141,135 +2141,135 @@ std::ios::fmtflags flags = is.flags (); if (elt) - { - const char *fmt = elt->text; - - bool discard = elt->discard; - - switch (elt->type) - { - case scanf_format_elt::whitespace_conversion: - DO_WHITESPACE_CONVERSION (); - break; - - case scanf_format_elt::literal_conversion: - DO_LITERAL_CONVERSION (); - break; - - case '%': - { - DO_PCT_CONVERSION (); - - if (! is) - quit = true; - - } - break; - - case 'd': case 'i': - { - int tmp; - - if (OCTAVE_SCAN (is, *elt, &tmp)) - { - if (! discard) - retval = tmp; - } - else - quit = true; - } - break; - - case 'o': case 'u': case 'x': - { - long int tmp; - - if (OCTAVE_SCAN (is, *elt, &tmp)) - { - if (! discard) - retval = tmp; - } - else - quit = true; - } - break; - - case 'e': case 'f': case 'g': - { - double tmp; - - if (OCTAVE_SCAN (is, *elt, &tmp)) - { - if (! discard) - retval = tmp; - } - else - quit = true; - } - break; - - case 'c': - { - BEGIN_C_CONVERSION (); - - if (! discard) - retval = tmp; - - if (! is) - quit = true; - - is.setf (flags); - } - break; - - case 's': - { - BEGIN_S_CONVERSION (); - - if (! discard) - retval = tmp; - - if (! is) - quit = true; - } - break; - - case '[': case '^': - { - BEGIN_CHAR_CLASS_CONVERSION (); - - if (! discard) - retval = tmp; - - if (! is) - quit = true; - } - break; - - case 'p': - error ("%s: unsupported format specifier", who.c_str ()); - break; - - default: - error ("%s: internal format error", who.c_str ()); - break; - } - } + { + const char *fmt = elt->text; + + bool discard = elt->discard; + + switch (elt->type) + { + case scanf_format_elt::whitespace_conversion: + DO_WHITESPACE_CONVERSION (); + break; + + case scanf_format_elt::literal_conversion: + DO_LITERAL_CONVERSION (); + break; + + case '%': + { + DO_PCT_CONVERSION (); + + if (! is) + quit = true; + + } + break; + + case 'd': case 'i': + { + int tmp; + + if (OCTAVE_SCAN (is, *elt, &tmp)) + { + if (! discard) + retval = tmp; + } + else + quit = true; + } + break; + + case 'o': case 'u': case 'x': + { + long int tmp; + + if (OCTAVE_SCAN (is, *elt, &tmp)) + { + if (! discard) + retval = tmp; + } + else + quit = true; + } + break; + + case 'e': case 'f': case 'g': + { + double tmp; + + if (OCTAVE_SCAN (is, *elt, &tmp)) + { + if (! discard) + retval = tmp; + } + else + quit = true; + } + break; + + case 'c': + { + BEGIN_C_CONVERSION (); + + if (! discard) + retval = tmp; + + if (! is) + quit = true; + + is.setf (flags); + } + break; + + case 's': + { + BEGIN_S_CONVERSION (); + + if (! discard) + retval = tmp; + + if (! is) + quit = true; + } + break; + + case '[': case '^': + { + BEGIN_CHAR_CLASS_CONVERSION (); + + if (! discard) + retval = tmp; + + if (! is) + quit = true; + } + break; + + case 'p': + error ("%s: unsupported format specifier", who.c_str ()); + break; + + default: + error ("%s: internal format error", who.c_str ()); + break; + } + } if (ok () && is.fail ()) - { - error ("%s: read error", who.c_str ()); - - // FIXME -- is this the right thing to do? - - if (interactive && name () == "stdin") - { - // Skip to end of line. - - bool err; - do_gets (-1, err, false, who); - } - } + { + error ("%s: read error", who.c_str ()); + + // FIXME -- is this the right thing to do? + + if (interactive && name () == "stdin") + { + // Skip to end of line. + + bool err; + do_gets (-1, err, false, who); + } + } } return quit; @@ -2291,56 +2291,56 @@ octave_idx_type nconv = fmt_list.num_conversions (); if (nconv == -1) - ::error ("%s: invalid format specified", who.c_str ()); + ::error ("%s: invalid format specified", who.c_str ()); else - { - is.clear (); - - octave_idx_type len = fmt_list.length (); - - retval.resize (nconv+1, Matrix ()); - - const scanf_format_elt *elt = fmt_list.first (); - - int num_values = 0; - - bool quit = false; - - for (octave_idx_type i = 0; i < len; i++) - { - octave_value tmp; - - quit = do_oscanf (elt, tmp, who); - - if (quit) - break; - else - { - if (tmp.is_defined ()) - retval (num_values++) = tmp; - - if (! ok ()) - break; - - elt = fmt_list.next (nconv > 0); - } - } - - retval(nconv) = num_values; - - if (! quit) - { - // Pick up any trailing stuff. - if (ok () && len > nconv) - { - octave_value tmp; - - elt = fmt_list.next (); - - do_oscanf (elt, tmp, who); - } - } - } + { + is.clear (); + + octave_idx_type len = fmt_list.length (); + + retval.resize (nconv+1, Matrix ()); + + const scanf_format_elt *elt = fmt_list.first (); + + int num_values = 0; + + bool quit = false; + + for (octave_idx_type i = 0; i < len; i++) + { + octave_value tmp; + + quit = do_oscanf (elt, tmp, who); + + if (quit) + break; + else + { + if (tmp.is_defined ()) + retval (num_values++) = tmp; + + if (! ok ()) + break; + + elt = fmt_list.next (nconv > 0); + } + } + + retval(nconv) = num_values; + + if (! quit) + { + // Pick up any trailing stuff. + if (ok () && len > nconv) + { + octave_value tmp; + + elt = fmt_list.next (); + + do_oscanf (elt, tmp, who); + } + } + } } else invalid_operation (who, "reading"); @@ -2363,7 +2363,7 @@ os->flush (); if (os->good ()) - retval = 0; + retval = 0; } else invalid_operation ("fflush", "writing"); @@ -2385,13 +2385,13 @@ { for (octave_idx_type i = 0; i < values.length (); i++) { - octave_value val = values(i); - - if (val.is_map () || val.is_cell () || val.is_object ()) - { - gripe_wrong_type_arg (who, val); - break; - } + octave_value val = values(i); + + if (val.is_map () || val.is_cell () || val.is_object ()) + { + gripe_wrong_type_arg (who, val); + break; + } } } @@ -2443,49 +2443,49 @@ while (! exhausted ()) { if (! data) - { - octave_value tmp_val = values (val_idx); - - // Force string conversion here for compatibility. - - curr_val = tmp_val.array_value (true); - - if (! error_state) - { - elt_idx = 0; - n_elts = curr_val.length (); - data = curr_val.data (); - } - else - { - curr_state = conversion_error; - break; - } - } + { + octave_value tmp_val = values (val_idx); + + // Force string conversion here for compatibility. + + curr_val = tmp_val.array_value (true); + + if (! error_state) + { + elt_idx = 0; + n_elts = curr_val.length (); + data = curr_val.data (); + } + else + { + curr_state = conversion_error; + break; + } + } if (elt_idx < n_elts) - { - retval = data[elt_idx++]; - - if (elt_idx >= n_elts) - { - elt_idx = 0; - val_idx++; - data = 0; - } - - break; - } + { + retval = data[elt_idx++]; + + if (elt_idx >= n_elts) + { + elt_idx = 0; + val_idx++; + data = 0; + } + + break; + } else - { - val_idx++; - data = 0; - - if (n_elts == 0 && exhausted ()) - curr_state = conversion_error; - - continue; - } + { + val_idx++; + data = 0; + + if (n_elts == 0 && exhausted ()) + curr_state = conversion_error; + + continue; + } } return retval; @@ -2501,9 +2501,9 @@ if (! error_state) { if (D_NINT (dval) == dval) - retval = NINT (dval); + retval = NINT (dval); else - curr_state = conversion_error; + curr_state = conversion_error; } return retval; @@ -2521,27 +2521,27 @@ octave_value tval = values (val_idx++); if (tval.rows () == 1) - retval = tval.string_value (); + retval = tval.string_value (); else - { - // In the name of Matlab compatibility. - - charMatrix chm = tval.char_matrix_value (); - - octave_idx_type nr = chm.rows (); - octave_idx_type nc = chm.columns (); - - int k = 0; - - retval.resize (nr * nc, '\0'); - - for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - retval[k++] = chm(i,j); - } + { + // In the name of Matlab compatibility. + + charMatrix chm = tval.char_matrix_value (); + + octave_idx_type nr = chm.rows (); + octave_idx_type nc = chm.columns (); + + int k = 0; + + retval.resize (nr * nc, '\0'); + + for (octave_idx_type j = 0; j < nc; j++) + for (octave_idx_type i = 0; i < nr; i++) + retval[k++] = chm(i,j); + } if (error_state) - curr_state = conversion_error; + curr_state = conversion_error; } return retval; @@ -2552,7 +2552,7 @@ template int do_printf_conv (std::ostream& os, const char *fmt, int nsa, int sa_1, - int sa_2, T arg, const std::string& who) + int sa_2, T arg, const std::string& who) { int retval = 0; @@ -2580,54 +2580,54 @@ template int do_printf_conv (std::ostream&, const char*, int, int, int, int, - const std::string&); + const std::string&); template int do_printf_conv (std::ostream&, const char*, int, int, int, long, - const std::string&); + const std::string&); template int do_printf_conv (std::ostream&, const char*, int, int, int, unsigned int, - const std::string&); + const std::string&); template int do_printf_conv (std::ostream&, const char*, int, int, int, unsigned long, - const std::string&); + const std::string&); template int do_printf_conv (std::ostream&, const char*, int, int, int, double, - const std::string&); + const std::string&); template int do_printf_conv (std::ostream&, const char*, int, int, int, const char*, - const std::string&); + const std::string&); #define DO_DOUBLE_CONV(TQUAL) \ do \ { \ if (val > std::numeric_limits::max () \ - || val < std::numeric_limits::min ()) \ - { \ - std::string tfmt = fmt; \ + || val < std::numeric_limits::min ()) \ + { \ + std::string tfmt = fmt; \ \ - tfmt.replace (tfmt.rfind (elt->type), 1, ".f"); \ + tfmt.replace (tfmt.rfind (elt->type), 1, ".f"); \ \ - if (elt->modifier == 'l') \ - tfmt.replace (tfmt.rfind (elt->modifier), 1, ""); \ + if (elt->modifier == 'l') \ + tfmt.replace (tfmt.rfind (elt->modifier), 1, ""); \ \ - retval += do_printf_conv (os, tfmt.c_str (), nsa, sa_1, sa_2, \ - val, who); \ - } \ + retval += do_printf_conv (os, tfmt.c_str (), nsa, sa_1, sa_2, \ + val, who); \ + } \ else \ - retval += do_printf_conv (os, fmt, nsa, sa_1, sa_2, \ - static_cast (val), who); \ + retval += do_printf_conv (os, fmt, nsa, sa_1, sa_2, \ + static_cast (val), who); \ } \ while (0) int octave_base_stream::do_printf (printf_format_list& fmt_list, - const octave_value_list& args, - const std::string& who) + const octave_value_list& args, + const std::string& who) { int retval = 0; @@ -2644,141 +2644,141 @@ printf_value_cache val_cache (args, who); if (error_state) - return retval; + return retval; for (;;) - { - octave_quit (); - - if (elt) - { - // NSA is the number of `star' args to convert. - - int nsa = (elt->fw < 0) + (elt->prec < 0); - - int sa_1 = 0; - int sa_2 = 0; - - if (nsa > 0) - { - sa_1 = val_cache.int_value (); - - if (! val_cache) - break; - else - { - if (nsa > 1) - { - sa_2 = val_cache.int_value (); - - if (! val_cache) - break; - } - } - } - - const char *fmt = elt->text; - - if (elt->type == '%') - { - os << "%"; - retval++; - } - else if (elt->args == 0 && elt->text) - { - os << elt->text; - retval += strlen (elt->text); - } - else if (elt->type == 's') - { - std::string val = val_cache.string_value (); - - if (val_cache) - retval += do_printf_conv (os, fmt, nsa, sa_1, - sa_2, val.c_str (), who); - else - break; - } - else - { - double val = val_cache.double_value (); - - if (val_cache) - { - if (lo_ieee_isnan (val) || xisinf (val)) - { - std::string tfmt = fmt; - std::string::size_type i1, i2; - - tfmt.replace ((i1 = tfmt.rfind (elt->type)), - 1, 1, 's'); - - if ((i2 = tfmt.rfind ('.')) != std::string::npos && i2 < i1) - { - tfmt.erase (i2, i1-i2); - if (elt->prec < 0) - nsa--; - } - - const char *tval = xisinf (val) - ? (val < 0 ? "-Inf" : "Inf") - : (lo_ieee_is_NA (val) ? "NA" : "NaN"); - - retval += do_printf_conv (os, tfmt.c_str (), - nsa, sa_1, sa_2, - tval, who); - } - else - { - char type = elt->type; - - switch (type) - { - case 'd': case 'i': case 'c': - DO_DOUBLE_CONV (OCTAVE_EMPTY_CPP_ARG); - break; - - case 'o': case 'x': case 'X': case 'u': - DO_DOUBLE_CONV (unsigned); - break; - - case 'f': case 'e': case 'E': - case 'g': case 'G': - retval - += do_printf_conv (os, fmt, nsa, sa_1, sa_2, - val, who); - break; - - default: - error ("%s: invalid format specifier", - who.c_str ()); - return -1; - break; - } - } - } - else - break; - } - - if (! os) - { - error ("%s: write error", who.c_str ()); - break; - } - } - else - { - ::error ("%s: internal error handling format", who.c_str ()); - retval = -1; - break; - } - - elt = fmt_list.next (nconv > 0 && ! val_cache.exhausted ()); - - if (! elt || (val_cache.exhausted () && elt->args > 0)) - break; - } + { + octave_quit (); + + if (elt) + { + // NSA is the number of `star' args to convert. + + int nsa = (elt->fw < 0) + (elt->prec < 0); + + int sa_1 = 0; + int sa_2 = 0; + + if (nsa > 0) + { + sa_1 = val_cache.int_value (); + + if (! val_cache) + break; + else + { + if (nsa > 1) + { + sa_2 = val_cache.int_value (); + + if (! val_cache) + break; + } + } + } + + const char *fmt = elt->text; + + if (elt->type == '%') + { + os << "%"; + retval++; + } + else if (elt->args == 0 && elt->text) + { + os << elt->text; + retval += strlen (elt->text); + } + else if (elt->type == 's') + { + std::string val = val_cache.string_value (); + + if (val_cache) + retval += do_printf_conv (os, fmt, nsa, sa_1, + sa_2, val.c_str (), who); + else + break; + } + else + { + double val = val_cache.double_value (); + + if (val_cache) + { + if (lo_ieee_isnan (val) || xisinf (val)) + { + std::string tfmt = fmt; + std::string::size_type i1, i2; + + tfmt.replace ((i1 = tfmt.rfind (elt->type)), + 1, 1, 's'); + + if ((i2 = tfmt.rfind ('.')) != std::string::npos && i2 < i1) + { + tfmt.erase (i2, i1-i2); + if (elt->prec < 0) + nsa--; + } + + const char *tval = xisinf (val) + ? (val < 0 ? "-Inf" : "Inf") + : (lo_ieee_is_NA (val) ? "NA" : "NaN"); + + retval += do_printf_conv (os, tfmt.c_str (), + nsa, sa_1, sa_2, + tval, who); + } + else + { + char type = elt->type; + + switch (type) + { + case 'd': case 'i': case 'c': + DO_DOUBLE_CONV (OCTAVE_EMPTY_CPP_ARG); + break; + + case 'o': case 'x': case 'X': case 'u': + DO_DOUBLE_CONV (unsigned); + break; + + case 'f': case 'e': case 'E': + case 'g': case 'G': + retval + += do_printf_conv (os, fmt, nsa, sa_1, sa_2, + val, who); + break; + + default: + error ("%s: invalid format specifier", + who.c_str ()); + return -1; + break; + } + } + } + else + break; + } + + if (! os) + { + error ("%s: write error", who.c_str ()); + break; + } + } + else + { + ::error ("%s: internal error handling format", who.c_str ()); + retval = -1; + break; + } + + elt = fmt_list.next (nconv > 0 && ! val_cache.exhausted ()); + + if (! elt || (val_cache.exhausted () && elt->args > 0)) + break; + } } else invalid_operation (who, "writing"); @@ -2788,8 +2788,8 @@ int octave_base_stream::printf (const std::string& fmt, - const octave_value_list& args, - const std::string& who) + const octave_value_list& args, + const std::string& who) { int retval = 0; @@ -2817,23 +2817,23 @@ os << s; if (os) - { - // FIXME -- why does this seem to be necessary? - // Without it, output from a loop like - // - // for i = 1:100, fputs (stdout, "foo\n"); endfor - // - // doesn't seem to go to the pager immediately. - - os.flush (); - - if (os) - retval = 0; - else - error ("%s: write error", who.c_str ()); - } + { + // FIXME -- why does this seem to be necessary? + // Without it, output from a loop like + // + // for i = 1:100, fputs (stdout, "foo\n"); endfor + // + // doesn't seem to go to the pager immediately. + + os.flush (); + + if (os) + retval = 0; + else + error ("%s: write error", who.c_str ()); + } else - error ("%s: write error", who.c_str ()); + error ("%s: write error", who.c_str ()); } else invalid_operation (who, "writing"); @@ -2890,12 +2890,12 @@ if (rep != s.rep) { if (rep && --rep->count == 0) - delete rep; + delete rep; rep = s.rep; if (rep) - rep->count++; + rep->count++; } return *this; @@ -2925,7 +2925,7 @@ std::string octave_stream::getl (const octave_value& tc_max_len, bool& err, - const std::string& who) + const std::string& who) { std::string retval; @@ -2940,10 +2940,10 @@ max_len = convert_to_valid_int (tc_max_len, conv_err); if (conv_err || max_len < 0) - { - err = true; - ::error ("%s: invalid maximum length specified", who.c_str ()); - } + { + err = true; + ::error ("%s: invalid maximum length specified", who.c_str ()); + } } if (! error_state) @@ -2965,7 +2965,7 @@ std::string octave_stream::gets (const octave_value& tc_max_len, bool& err, - const std::string& who) + const std::string& who) { std::string retval; @@ -2980,10 +2980,10 @@ max_len = convert_to_valid_int (tc_max_len, conv_err); if (conv_err || max_len < 0) - { - err = true; - ::error ("%s: invalid maximum length specified", who.c_str ()); - } + { + err = true; + ::error ("%s: invalid maximum length specified", who.c_str ()); + } } if (! error_state) @@ -3050,34 +3050,34 @@ status = rep->seek (offset, origin); if (status == 0) - { - long save_pos = rep->tell (); - - rep->seek (0, SEEK_END); - - long pos_eof = rep->tell (); - - // I don't think save_pos can be less than zero, but we'll - // check anyway... - - if (save_pos > pos_eof || save_pos < 0) - { - // Seek outside bounds of file. Failure should leave - // position unchanged. - - rep->seek (orig_pos, SEEK_SET); - - status = -1; - } - else - { - // Is it possible for this to fail? We are just - // returning to a position after the first successful - // seek. - - rep->seek (save_pos, SEEK_SET); - } - } + { + long save_pos = rep->tell (); + + rep->seek (0, SEEK_END); + + long pos_eof = rep->tell (); + + // I don't think save_pos can be less than zero, but we'll + // check anyway... + + if (save_pos > pos_eof || save_pos < 0) + { + // Seek outside bounds of file. Failure should leave + // position unchanged. + + rep->seek (orig_pos, SEEK_SET); + + status = -1; + } + else + { + // Is it possible for this to fail? We are just + // returning to a position after the first successful + // seek. + + rep->seek (save_pos, SEEK_SET); + } + } } return status; @@ -3085,7 +3085,7 @@ int octave_stream::seek (const octave_value& tc_offset, - const octave_value& tc_origin) + const octave_value& tc_origin) { int retval = -1; @@ -3098,44 +3098,44 @@ int origin = SEEK_SET; if (tc_origin.is_string ()) - { - std::string xorigin = tc_origin.string_value (); - - if (xorigin == "bof") - origin = SEEK_SET; - else if (xorigin == "cof") - origin = SEEK_CUR; - else if (xorigin == "eof") - origin = SEEK_END; - else - conv_err = -1; - } + { + std::string xorigin = tc_origin.string_value (); + + if (xorigin == "bof") + origin = SEEK_SET; + else if (xorigin == "cof") + origin = SEEK_CUR; + else if (xorigin == "eof") + origin = SEEK_END; + else + conv_err = -1; + } else - { - int xorigin = convert_to_valid_int (tc_origin, conv_err); - - if (! conv_err) - { - if (xorigin == -1) - origin = SEEK_SET; - else if (xorigin == 0) - origin = SEEK_CUR; - else if (xorigin == 1) - origin = SEEK_END; - else - conv_err = -1; - } - } + { + int xorigin = convert_to_valid_int (tc_origin, conv_err); + + if (! conv_err) + { + if (xorigin == -1) + origin = SEEK_SET; + else if (xorigin == 0) + origin = SEEK_CUR; + else if (xorigin == 1) + origin = SEEK_END; + else + conv_err = -1; + } + } if (! conv_err) - { - retval = seek (xoffset, origin); - - if (retval != 0) - error ("fseek: failed to seek to requested position"); - } + { + retval = seek (xoffset, origin); + + if (retval != 0) + error ("fseek: failed to seek to requested position"); + } else - error ("fseek: invalid value for origin"); + error ("fseek: invalid value for origin"); } else error ("fseek: invalid value for offset"); @@ -3181,8 +3181,8 @@ template octave_value do_read (octave_stream& strm, octave_idx_type nr, octave_idx_type nc, octave_idx_type block_size, - octave_idx_type skip, bool do_float_fmt_conv, bool do_NA_conv, - oct_mach_info::float_format from_flt_fmt, octave_idx_type& count) + octave_idx_type skip, bool do_float_fmt_conv, bool do_NA_conv, + oct_mach_info::float_format from_flt_fmt, octave_idx_type& count) { octave_value retval; @@ -3203,17 +3203,17 @@ if (nr > 0) { if (nc > 0) - { - nda.resize (dim_vector (nr, nc), elt_zero); - dat = nda.fortran_vec (); - max_size = nr * nc; - } + { + nda.resize (dim_vector (nr, nc), elt_zero); + dat = nda.fortran_vec (); + max_size = nr * nc; + } else - { - nda.resize (dim_vector (nr, 32), elt_zero); - dat = nda.fortran_vec (); - max_size = nr * 32; - } + { + nda.resize (dim_vector (nr, 32), elt_zero); + dat = nda.fortran_vec (); + max_size = nr * 32; + } } else { @@ -3228,8 +3228,8 @@ if (oct_mach_info::words_big_endian ()) swap = (from_flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian - || from_flt_fmt == oct_mach_info::flt_fmt_vax_g - || from_flt_fmt == oct_mach_info::flt_fmt_vax_g); + || from_flt_fmt == oct_mach_info::flt_fmt_vax_g + || from_flt_fmt == oct_mach_info::flt_fmt_vax_g); else swap = (from_flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian); @@ -3248,95 +3248,95 @@ octave_idx_type elts_read = 0; for (;;) - { - // FIXME -- maybe there should be a special case for - // skip == 0. - - if (is) - { - if (nr > 0 && nc > 0 && count == max_size) - { - final_nr = nr; - final_nc = nc; - - break; - } - - is.read (u.buf, sizeof (typename strip_template_param::type)); - - // We only swap bytes for integer types. For float - // types, the format conversion will also handle byte - // swapping. - - if (swap) - swap_bytes::type)> (u.buf); - else if (do_float_fmt_conv) - do_float_format_conversion - (u.buf, - sizeof (typename strip_template_param::type), - 1, from_flt_fmt, oct_mach_info::float_format ()); - - typename RET_T::element_type tmp - = static_cast (u.val); - - if (is) - { - if (count == max_size) - { - max_size *= 2; - - if (nr > 0) - nda.resize (dim_vector (nr, max_size / nr), - elt_zero); - else - nda.resize (dim_vector (max_size, 1), elt_zero); - - dat = nda.fortran_vec (); - } - - if (do_NA_conv && __lo_ieee_is_old_NA (tmp)) - tmp = __lo_ieee_replace_old_NA (tmp); - - dat[count++] = tmp; - - elts_read++; - } - - int seek_status = 0; - - if (skip != 0 && elts_read == block_size) - { - seek_status = strm.seek (skip, SEEK_CUR); - elts_read = 0; - } - - if (is.eof () || seek_status < 0) - { - if (nr > 0) - { - if (count > nr) - { - final_nr = nr; - final_nc = (count - 1) / nr + 1; - } - else - { - final_nr = count; - final_nc = 1; - } - } - else - { - final_nr = count; - final_nc = 1; - } - - break; - } - } - else if (is.eof ()) - break; - } + { + // FIXME -- maybe there should be a special case for + // skip == 0. + + if (is) + { + if (nr > 0 && nc > 0 && count == max_size) + { + final_nr = nr; + final_nc = nc; + + break; + } + + is.read (u.buf, sizeof (typename strip_template_param::type)); + + // We only swap bytes for integer types. For float + // types, the format conversion will also handle byte + // swapping. + + if (swap) + swap_bytes::type)> (u.buf); + else if (do_float_fmt_conv) + do_float_format_conversion + (u.buf, + sizeof (typename strip_template_param::type), + 1, from_flt_fmt, oct_mach_info::float_format ()); + + typename RET_T::element_type tmp + = static_cast (u.val); + + if (is) + { + if (count == max_size) + { + max_size *= 2; + + if (nr > 0) + nda.resize (dim_vector (nr, max_size / nr), + elt_zero); + else + nda.resize (dim_vector (max_size, 1), elt_zero); + + dat = nda.fortran_vec (); + } + + if (do_NA_conv && __lo_ieee_is_old_NA (tmp)) + tmp = __lo_ieee_replace_old_NA (tmp); + + dat[count++] = tmp; + + elts_read++; + } + + int seek_status = 0; + + if (skip != 0 && elts_read == block_size) + { + seek_status = strm.seek (skip, SEEK_CUR); + elts_read = 0; + } + + if (is.eof () || seek_status < 0) + { + if (nr > 0) + { + if (count > nr) + { + final_nr = nr; + final_nc = (count - 1) / nr + 1; + } + else + { + final_nr = count; + final_nc = 1; + } + } + else + { + final_nr = count; + final_nc = 1; + } + + break; + } + } + else if (is.eof ()) + break; + } } nda.resize (dim_vector (final_nr, final_nc), elt_zero); @@ -3349,7 +3349,7 @@ #define DO_READ_VAL_TEMPLATE(RET_T, READ_T) \ template octave_value \ do_read (octave_stream&, octave_idx_type, octave_idx_type, octave_idx_type, octave_idx_type, bool, bool, \ - oct_mach_info::float_format, octave_idx_type&) + oct_mach_info::float_format, octave_idx_type&) // FIXME -- should we only have float if it is a different // size from double? @@ -3383,7 +3383,7 @@ INSTANTIATE_DO_READ (boolNDArray); typedef octave_value (*read_fptr) (octave_stream&, octave_idx_type, octave_idx_type, octave_idx_type, octave_idx_type, bool, bool, - oct_mach_info::float_format ffmt, octave_idx_type&); + oct_mach_info::float_format ffmt, octave_idx_type&); #define FILL_TABLE_ROW(R, VAL_T) \ read_fptr_table[R][oct_data_conv::dt_int8] = do_read; \ @@ -3403,10 +3403,10 @@ octave_value octave_stream::read (const Array& size, octave_idx_type block_size, - oct_data_conv::data_type input_type, - oct_data_conv::data_type output_type, - octave_idx_type skip, oct_mach_info::float_format ffmt, - octave_idx_type& char_count) + oct_data_conv::data_type input_type, + oct_data_conv::data_type output_type, + octave_idx_type skip, oct_mach_info::float_format ffmt, + octave_idx_type& char_count) { static bool initialized = false; @@ -3458,42 +3458,42 @@ get_size (size, nr, nc, ignore, "fread"); if (! error_state) - { - if (nr == 0 || nc == 0) - retval = Matrix (nr, nc); - else - { - if (ffmt == oct_mach_info::flt_fmt_unknown) - ffmt = float_format (); - - read_fptr fcn = read_fptr_table[output_type][input_type]; - - bool do_float_fmt_conv = ((input_type == oct_data_conv::dt_double - || input_type == oct_data_conv::dt_single) - && ffmt != float_format ()); - - bool do_NA_conv = (output_type == oct_data_conv::dt_double); - - if (fcn) - { - retval = (*fcn) (*this, nr, nc, block_size, skip, - do_float_fmt_conv, do_NA_conv, - ffmt, char_count); - - // FIXME -- kluge! - - if (! error_state - && (output_type == oct_data_conv::dt_char - || output_type == oct_data_conv::dt_schar - || output_type == oct_data_conv::dt_uchar)) - retval = retval.char_matrix_value (); - } - else - error ("fread: unable to read and convert requested types"); - } - } + { + if (nr == 0 || nc == 0) + retval = Matrix (nr, nc); + else + { + if (ffmt == oct_mach_info::flt_fmt_unknown) + ffmt = float_format (); + + read_fptr fcn = read_fptr_table[output_type][input_type]; + + bool do_float_fmt_conv = ((input_type == oct_data_conv::dt_double + || input_type == oct_data_conv::dt_single) + && ffmt != float_format ()); + + bool do_NA_conv = (output_type == oct_data_conv::dt_double); + + if (fcn) + { + retval = (*fcn) (*this, nr, nc, block_size, skip, + do_float_fmt_conv, do_NA_conv, + ffmt, char_count); + + // FIXME -- kluge! + + if (! error_state + && (output_type == oct_data_conv::dt_char + || output_type == oct_data_conv::dt_schar + || output_type == oct_data_conv::dt_uchar)) + retval = retval.char_matrix_value (); + } + else + error ("fread: unable to read and convert requested types"); + } + } else - invalid_operation ("fread", "reading"); + invalid_operation ("fread", "reading"); } return retval; @@ -3501,28 +3501,28 @@ octave_idx_type octave_stream::write (const octave_value& data, octave_idx_type block_size, - oct_data_conv::data_type output_type, octave_idx_type skip, - oct_mach_info::float_format flt_fmt) + oct_data_conv::data_type output_type, octave_idx_type skip, + oct_mach_info::float_format flt_fmt) { octave_idx_type retval = -1; if (stream_ok ()) { if (! error_state) - { - if (flt_fmt == oct_mach_info::flt_fmt_unknown) - flt_fmt = float_format (); - - octave_idx_type status = data.write (*this, block_size, output_type, - skip, flt_fmt); - - if (status < 0) - error ("fwrite: write error"); - else - retval = status; - } + { + if (flt_fmt == oct_mach_info::flt_fmt_unknown) + flt_fmt = float_format (); + + octave_idx_type status = data.write (*this, block_size, output_type, + skip, flt_fmt); + + if (status < 0) + error ("fwrite: write error"); + else + retval = status; + } else - invalid_operation ("fwrite", "writing"); + invalid_operation ("fwrite", "writing"); } return retval; @@ -3538,7 +3538,7 @@ swap_bytes (&tmp); os.write (reinterpret_cast (&tmp), - sizeof (typename T::val_type)); + sizeof (typename T::val_type)); } template void write_int (std::ostream&, bool, const octave_int8&); @@ -3553,8 +3553,8 @@ template static inline bool do_write (std::ostream& os, const T& val, oct_data_conv::data_type output_type, - oct_mach_info::float_format flt_fmt, bool swap, - bool do_float_conversion) + oct_mach_info::float_format flt_fmt, bool swap, + bool do_float_conversion) { bool retval = true; @@ -3609,29 +3609,29 @@ case oct_data_conv::dt_single: { - float f = static_cast (val); - - if (do_float_conversion) - do_float_format_conversion (&f, 1, flt_fmt); - - os.write (reinterpret_cast (&f), sizeof (float)); + float f = static_cast (val); + + if (do_float_conversion) + do_float_format_conversion (&f, 1, flt_fmt); + + os.write (reinterpret_cast (&f), sizeof (float)); } break; case oct_data_conv::dt_double: { - double d = static_cast (val); - if (do_float_conversion) - do_double_format_conversion (&d, 1, flt_fmt); - - os.write (reinterpret_cast (&d), sizeof (double)); + double d = static_cast (val); + if (do_float_conversion) + do_double_format_conversion (&d, 1, flt_fmt); + + os.write (reinterpret_cast (&d), sizeof (double)); } break; default: retval = false; (*current_liboctave_error_handler) - ("write: invalid type specification"); + ("write: invalid type specification"); break; } @@ -3640,41 +3640,41 @@ template bool do_write (std::ostream&, const octave_int8&, oct_data_conv::data_type, - oct_mach_info::float_format, bool, bool); + oct_mach_info::float_format, bool, bool); template bool do_write (std::ostream&, const octave_uint8&, oct_data_conv::data_type, - oct_mach_info::float_format, bool, bool); + oct_mach_info::float_format, bool, bool); template bool do_write (std::ostream&, const octave_int16&, oct_data_conv::data_type, - oct_mach_info::float_format, bool, bool); + oct_mach_info::float_format, bool, bool); template bool do_write (std::ostream&, const octave_uint16&, oct_data_conv::data_type, - oct_mach_info::float_format, bool, bool); + oct_mach_info::float_format, bool, bool); template bool do_write (std::ostream&, const octave_int32&, oct_data_conv::data_type, - oct_mach_info::float_format, bool, bool); + oct_mach_info::float_format, bool, bool); template bool do_write (std::ostream&, const octave_uint32&, oct_data_conv::data_type, - oct_mach_info::float_format, bool, bool); + oct_mach_info::float_format, bool, bool); template bool do_write (std::ostream&, const octave_int64&, oct_data_conv::data_type, - oct_mach_info::float_format, bool, bool); + oct_mach_info::float_format, bool, bool); template bool do_write (std::ostream&, const octave_uint64&, oct_data_conv::data_type, - oct_mach_info::float_format, bool, bool); + oct_mach_info::float_format, bool, bool); template octave_idx_type octave_stream::write (const Array& data, octave_idx_type block_size, - oct_data_conv::data_type output_type, - octave_idx_type skip, oct_mach_info::float_format flt_fmt) + oct_data_conv::data_type output_type, + octave_idx_type skip, oct_mach_info::float_format flt_fmt) { octave_idx_type retval = -1; @@ -3697,8 +3697,8 @@ if (oct_mach_info::words_big_endian ()) swap = (flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian - || flt_fmt == oct_mach_info::flt_fmt_vax_g - || flt_fmt == oct_mach_info::flt_fmt_vax_g); + || flt_fmt == oct_mach_info::flt_fmt_vax_g + || flt_fmt == oct_mach_info::flt_fmt_vax_g); else swap = (flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian); @@ -3707,62 +3707,62 @@ std::ostream *osp = output_stream (); if (osp) - { - std::ostream& os = *osp; - - if (skip != 0 && (i % block_size) == 0) - { - // Seek to skip when inside bounds of existing file. - // Otherwise, write NUL to skip. - - long orig_pos = tell (); - - seek (0, SEEK_END); - - long eof_pos = tell (); - - // Is it possible for this to fail to return us to the - // original position? - seek (orig_pos, SEEK_SET); - - long remaining = eof_pos - orig_pos; - - if (remaining < skip) - { - seek (0, SEEK_END); - - // FIXME -- probably should try to write larger - // blocks... - - unsigned char zero = 0; - for (octave_idx_type j = 0; j < skip - remaining; j++) - os.write (reinterpret_cast (&zero), 1); - } - else - seek (skip, SEEK_CUR); - } - - if (os) - { - status = do_write (os, d[i], output_type, flt_fmt, swap, - do_float_conversion); - - if (os && status) - count++; - else - break; - } - else - { - status = false; - break; - } - } + { + std::ostream& os = *osp; + + if (skip != 0 && (i % block_size) == 0) + { + // Seek to skip when inside bounds of existing file. + // Otherwise, write NUL to skip. + + long orig_pos = tell (); + + seek (0, SEEK_END); + + long eof_pos = tell (); + + // Is it possible for this to fail to return us to the + // original position? + seek (orig_pos, SEEK_SET); + + long remaining = eof_pos - orig_pos; + + if (remaining < skip) + { + seek (0, SEEK_END); + + // FIXME -- probably should try to write larger + // blocks... + + unsigned char zero = 0; + for (octave_idx_type j = 0; j < skip - remaining; j++) + os.write (reinterpret_cast (&zero), 1); + } + else + seek (skip, SEEK_CUR); + } + + if (os) + { + status = do_write (os, d[i], output_type, flt_fmt, swap, + do_float_conversion); + + if (os && status) + count++; + else + break; + } + else + { + status = false; + break; + } + } else - { - status = false; - break; - } + { + status = false; + break; + } } if (status) @@ -3773,67 +3773,67 @@ template octave_idx_type octave_stream::write (const Array&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); octave_value octave_stream::scanf (const std::string& fmt, const Array& size, - octave_idx_type& count, const std::string& who) + octave_idx_type& count, const std::string& who) { octave_value retval; @@ -3845,7 +3845,7 @@ octave_value octave_stream::scanf (const octave_value& fmt, const Array& size, - octave_idx_type& count, const std::string& who) + octave_idx_type& count, const std::string& who) { octave_value retval = Matrix (); @@ -3854,7 +3854,7 @@ std::string sfmt = fmt.string_value (); if (fmt.is_sq_string ()) - sfmt = do_string_escapes (sfmt); + sfmt = do_string_escapes (sfmt); retval = scanf (sfmt, size, count, who); } @@ -3889,7 +3889,7 @@ std::string sfmt = fmt.string_value (); if (fmt.is_sq_string ()) - sfmt = do_string_escapes (sfmt); + sfmt = do_string_escapes (sfmt); retval = oscanf (sfmt, who); } @@ -3905,7 +3905,7 @@ int octave_stream::printf (const std::string& fmt, const octave_value_list& args, - const std::string& who) + const std::string& who) { int retval = -1; @@ -3917,7 +3917,7 @@ int octave_stream::printf (const octave_value& fmt, const octave_value_list& args, - const std::string& who) + const std::string& who) { int retval = 0; @@ -3926,7 +3926,7 @@ std::string sfmt = fmt.string_value (); if (fmt.is_sq_string ()) - sfmt = do_string_escapes (sfmt); + sfmt = do_string_escapes (sfmt); retval = printf (sfmt, args, who); } @@ -4050,17 +4050,17 @@ else if (in_mode == (std::ios::in | std::ios::binary)) retval = "rb"; else if (in_mode == (std::ios::out | std::ios::binary) - || in_mode == (std::ios::out | std::ios::trunc | std::ios::binary)) + || in_mode == (std::ios::out | std::ios::trunc | std::ios::binary)) retval = "wb"; else if (in_mode == (std::ios::out | std::ios::app | std::ios::binary)) retval = "ab"; else if (in_mode == (std::ios::in | std::ios::out | std::ios::binary)) retval = "r+b"; else if (in_mode == (std::ios::in | std::ios::out | std::ios::trunc - | std::ios::binary)) + | std::ios::binary)) retval = "w+b"; else if (in_mode == (std::ios::in | std::ios::out | std::ios::ate - | std::ios::binary)) + | std::ios::binary)) retval = "a+b"; return retval; @@ -4225,7 +4225,7 @@ octave_stream octave_stream_list::do_lookup (const octave_value& fid, - const std::string& who) const + const std::string& who) const { octave_stream retval; @@ -4250,22 +4250,22 @@ ostrl_map::iterator iter = list.find (fid); if (iter != list.end ()) - { - octave_stream os = iter->second; + { + octave_stream os = iter->second; list.erase (iter); lookup_cache = list.end (); // FIXME: is this check redundant? - if (os.is_valid ()) - { - os.close (); - retval = 0; - } - else - gripe_invalid_file_id (fid, who); - } + if (os.is_valid ()) + { + os.close (); + retval = 0; + } + else + gripe_invalid_file_id (fid, who); + } else - gripe_invalid_file_id (fid, who); + gripe_invalid_file_id (fid, who); } else gripe_invalid_file_id (fid, who); @@ -4289,7 +4289,7 @@ int i = get_file_number (fid); if (! error_state) - retval = do_remove (i, who); + retval = do_remove (i, who); } return retval; @@ -4376,16 +4376,16 @@ octave_stream os = p->second; buf << " " - << std::setiosflags (std::ios::right) - << std::setw (4) << p->first << " " - << std::setiosflags (std::ios::left) - << std::setw (3) - << octave_stream::mode_as_string (os.mode ()) - << " " - << std::setw (9) - << oct_mach_info::float_format_as_string (os.float_format ()) - << " " - << os.name () << "\n"; + << std::setiosflags (std::ios::right) + << std::setw (4) << p->first << " " + << std::setiosflags (std::ios::left) + << std::setw (3) + << octave_stream::mode_as_string (os.mode ()) + << " " + << std::setw (9) + << oct_mach_info::float_format_as_string (os.float_format ()) + << " " + << os.name () << "\n"; } buf << "\n"; @@ -4407,7 +4407,7 @@ // Skip stdin, stdout, and stderr. if (p->first > 2 && p->second) - retval(0,num_open++) = p->first; + retval(0,num_open++) = p->first; } retval.resize ((num_open > 0), num_open); @@ -4425,21 +4425,21 @@ std::string nm = fid.string_value (); for (ostrl_map::const_iterator p = list.begin (); p != list.end (); p++) - { - // stdin (std::cin), stdout (std::cout), and stderr (std::cerr) - // are unnamed. - - if (p->first > 2) - { - octave_stream os = p->second; - - if (os && os.name () == nm) - { - retval = p->first; - break; - } - } - } + { + // stdin (std::cin), stdout (std::cout), and stderr (std::cerr) + // are unnamed. + + if (p->first > 2) + { + octave_stream os = p->second; + + if (os && os.name () == nm) + { + retval = p->first; + break; + } + } + } } else { @@ -4448,9 +4448,9 @@ int int_fid = convert_to_valid_int (fid, conv_err); if (conv_err) - ::error ("file id must be a file object, std::string, or integer value"); + ::error ("file id must be a file object, std::string, or integer value"); else - retval = int_fid; + retval = int_fid; } return retval; diff --git a/src/oct-strstrm.cc b/src/oct-strstrm.cc --- a/src/oct-strstrm.cc +++ b/src/oct-strstrm.cc @@ -47,21 +47,21 @@ octave_stream octave_istrstream::create (const char *data, std::ios::openmode arg_md, - oct_mach_info::float_format flt_fmt) + oct_mach_info::float_format flt_fmt) { return octave_stream (new octave_istrstream (data, arg_md, flt_fmt)); } octave_stream octave_istrstream::create (const std::string& data, std::ios::openmode arg_md, - oct_mach_info::float_format flt_fmt) + oct_mach_info::float_format flt_fmt) { return octave_stream (new octave_istrstream (data, arg_md, flt_fmt)); } octave_stream octave_ostrstream::create (std::ios::openmode arg_md, - oct_mach_info::float_format flt_fmt) + oct_mach_info::float_format flt_fmt) { return octave_stream (new octave_ostrstream (arg_md, flt_fmt)); } diff --git a/src/octave.cc b/src/octave.cc --- a/src/octave.cc +++ b/src/octave.cc @@ -73,7 +73,7 @@ // Kluge. extern "C" F77_RET_T F77_FUNC (xerbla, XERBLA) (F77_CONST_CHAR_ARG_DECL, const octave_idx_type& - F77_CHAR_ARG_LEN_DECL); + F77_CHAR_ARG_LEN_DECL); extern void install_builtins (void); @@ -196,7 +196,7 @@ // Skip program name in argv. int i = argc; while (--i > 0) - octave_argv[i-1] = *(argv+i); + octave_argv[i-1] = *(argv+i); } } @@ -233,25 +233,25 @@ if (nargin == 4) { if (vinfo.nfields () == 0) - { - vinfo.assign ("Name", args (0)); - vinfo.assign ("Version", args (1)); - vinfo.assign ("Release", args (2)); - vinfo.assign ("Date", args (3)); - } + { + vinfo.assign ("Name", args (0)); + vinfo.assign ("Version", args (1)); + vinfo.assign ("Release", args (2)); + vinfo.assign ("Date", args (3)); + } else - { - octave_idx_type n = vinfo.numel () + 1; + { + octave_idx_type n = vinfo.numel () + 1; - vinfo.resize (dim_vector (n, 1)); + vinfo.resize (dim_vector (n, 1)); - octave_value idx (n); + octave_value idx (n); - vinfo.assign (idx, "Name", Cell (octave_value (args (0)))); - vinfo.assign (idx, "Version", Cell (octave_value (args (1)))); - vinfo.assign (idx, "Release", Cell (octave_value (args (2)))); - vinfo.assign (idx, "Date", Cell (octave_value (args (3)))); - } + vinfo.assign (idx, "Name", Cell (octave_value (args (0)))); + vinfo.assign (idx, "Version", Cell (octave_value (args (1)))); + vinfo.assign (idx, "Release", Cell (octave_value (args (2)))); + vinfo.assign (idx, "Date", Cell (octave_value (args (3)))); + } } else if (nargin == 0) retval = vinfo; @@ -314,7 +314,7 @@ std::string initfile = octave_env::getenv ("OCTAVE_INITFILE"); if (initfile.empty ()) - initfile = ".octaverc"; + initfile = ".octaverc"; std::string home_dir = octave_env::get_home_directory (); @@ -323,31 +323,31 @@ std::string local_rc; if (! home_rc.empty ()) - { - source_file (home_rc, context, verbose, require_file); + { + source_file (home_rc, context, verbose, require_file); - // Names alone are not enough. + // Names alone are not enough. - file_stat fs_home_rc (home_rc); + file_stat fs_home_rc (home_rc); - if (fs_home_rc) - { - // We want to check for curr_dir after executing home_rc - // because doing that may change the working directory. + if (fs_home_rc) + { + // We want to check for curr_dir after executing home_rc + // because doing that may change the working directory. - local_rc = octave_env::make_absolute (initfile); + local_rc = octave_env::make_absolute (initfile); - home_rc_already_executed = same_file (home_rc, local_rc); - } - } + home_rc_already_executed = same_file (home_rc, local_rc); + } + } if (! home_rc_already_executed) - { - if (local_rc.empty ()) + { + if (local_rc.empty ()) local_rc = octave_env::make_absolute (initfile); - source_file (local_rc, context, verbose, require_file); - } + source_file (local_rc, context, verbose, require_file); + } } } @@ -388,7 +388,7 @@ catch (std::bad_alloc) { std::cerr << "error: memory exhausted or requested size too large for range of Octave's index type -- eval failed" - << std::endl; + << std::endl; } return parse_status; @@ -455,7 +455,7 @@ catch (std::bad_alloc) { std::cerr << "error: memory exhausted or requested size too large for range of Octave's index type -- execution of " - << fname << " failed" << std::endl; + << fname << " failed" << std::endl; } } @@ -557,7 +557,7 @@ bind_internal_variable ("default_save_options", "-mat-binary"); bind_internal_variable ("fixed_point_format", true); bind_internal_variable ("history_timestamp_format_string", - "%%-- %D %I:%M %p --%%"); + "%%-- %D %I:%M %p --%%"); bind_internal_variable ("page_screen_output", false); bind_internal_variable ("print_empty_dimensions", false); @@ -631,126 +631,126 @@ break; switch (optc) - { - case 'H': - read_history_file = false; - bind_internal_variable ("saving_history", false); - break; + { + case 'H': + read_history_file = false; + bind_internal_variable ("saving_history", false); + break; - case 'V': - verbose_flag = true; - break; + case 'V': + verbose_flag = true; + break; - case 'd': - // This is the same as yydebug in parse.y. - octave_debug++; - break; + case 'd': + // This is the same as yydebug in parse.y. + octave_debug++; + break; - case 'f': - read_init_files = false; - read_site_files = false; - break; + case 'f': + read_init_files = false; + read_site_files = false; + break; - case 'h': - case '?': - verbose_usage (); - break; + case 'h': + case '?': + verbose_usage (); + break; - case 'i': - forced_interactive = true; - break; + case 'i': + forced_interactive = true; + break; - case 'p': - if (optarg) - load_path::set_command_line_path (optarg); - break; + case 'p': + if (optarg) + load_path::set_command_line_path (optarg); + break; - case 'q': - inhibit_startup_message = true; - break; + case 'q': + inhibit_startup_message = true; + break; - case 'x': - { - double tmp = (ECHO_SCRIPTS | ECHO_FUNCTIONS | ECHO_CMD_LINE); - bind_internal_variable ("echo_executing_commands", tmp); - } - break; + case 'x': + { + double tmp = (ECHO_SCRIPTS | ECHO_FUNCTIONS | ECHO_CMD_LINE); + bind_internal_variable ("echo_executing_commands", tmp); + } + break; - case 'v': - print_version_and_exit (); - break; + case 'v': + print_version_and_exit (); + break; - case DOC_CACHE_FILE_OPTION: - if (optarg) - bind_internal_variable ("doc_cache_file", optarg); - break; + case DOC_CACHE_FILE_OPTION: + if (optarg) + bind_internal_variable ("doc_cache_file", optarg); + break; - case EVAL_OPTION: - if (optarg) - { - if (code_to_eval.empty ()) - code_to_eval = optarg; - else - code_to_eval += std::string (" ") + optarg; - } - break; + case EVAL_OPTION: + if (optarg) + { + if (code_to_eval.empty ()) + code_to_eval = optarg; + else + code_to_eval += std::string (" ") + optarg; + } + break; - case EXEC_PATH_OPTION: - if (optarg) - set_exec_path (optarg); - break; + case EXEC_PATH_OPTION: + if (optarg) + set_exec_path (optarg); + break; - case IMAGE_PATH_OPTION: - if (optarg) - set_image_path (optarg); - break; + case IMAGE_PATH_OPTION: + if (optarg) + set_image_path (optarg); + break; - case INFO_FILE_OPTION: - if (optarg) - bind_internal_variable ("info_file", optarg); - break; + case INFO_FILE_OPTION: + if (optarg) + bind_internal_variable ("info_file", optarg); + break; - case INFO_PROG_OPTION: - if (optarg) - bind_internal_variable ("info_program", optarg); - break; + case INFO_PROG_OPTION: + if (optarg) + bind_internal_variable ("info_program", optarg); + break; - case LINE_EDITING_OPTION: - forced_line_editing = true; - break; + case LINE_EDITING_OPTION: + forced_line_editing = true; + break; - case NO_INIT_FILE_OPTION: - read_init_files = false; - break; + case NO_INIT_FILE_OPTION: + read_init_files = false; + break; - case NO_INIT_PATH_OPTION: - set_initial_path = false; - break; + case NO_INIT_PATH_OPTION: + set_initial_path = false; + break; - case NO_LINE_EDITING_OPTION: - line_editing = false; - break; + case NO_LINE_EDITING_OPTION: + line_editing = false; + break; - case NO_SITE_FILE_OPTION: - read_site_files = 0; - break; + case NO_SITE_FILE_OPTION: + read_site_files = 0; + break; - case NO_WINDOW_SYSTEM_OPTION: - display_info::no_window_system (); - break; + case NO_WINDOW_SYSTEM_OPTION: + display_info::no_window_system (); + break; - case PERSIST_OPTION: - persist = true; - break; + case PERSIST_OPTION: + persist = true; + break; - case TRADITIONAL_OPTION: - traditional = true; - break; + case TRADITIONAL_OPTION: + traditional = true; + break; - default: - usage (); - break; - } + default: + usage (); + break; + } } // Make sure we clean up when we exit. Also allow users to register @@ -818,7 +818,7 @@ int parse_status = execute_eval_option_code (code_to_eval); if (! (persist || remaining_args > 0)) - clean_up_and_exit (parse_status || error_state ? 1 : 0); + clean_up_and_exit (parse_status || error_state ? 1 : 0); } if (remaining_args > 0) @@ -831,7 +831,7 @@ execute_command_line_file (argv[last_arg_idx]); if (! persist) - clean_up_and_exit (error_state ? 1 : 0); + clean_up_and_exit (error_state ? 1 : 0); } // Avoid counting commands executed from startup files. diff --git a/src/ov-base-diag.cc b/src/ov-base-diag.cc --- a/src/ov-base-diag.cc +++ b/src/ov-base-diag.cc @@ -55,8 +55,8 @@ case '{': case '.': { - std::string nm = type_name (); - error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + std::string nm = type_name (); + error ("%s cannot be indexed with %c", nm.c_str (), type[0]); } break; @@ -118,7 +118,7 @@ { case '(': { - if (type.length () == 1) + if (type.length () == 1) { octave_value_list jdx = idx.front (); // Check for a simple element assignment. That means, if D is a diagonal matrix, @@ -142,29 +142,29 @@ if (! error_state && ! retval.is_defined ()) retval = numeric_assign (type, idx, rhs); } - else - { - std::string nm = type_name (); - error ("in indexed assignment of %s, last lhs index must be ()", - nm.c_str ()); - } + else + { + std::string nm = type_name (); + error ("in indexed assignment of %s, last lhs index must be ()", + nm.c_str ()); + } } break; case '{': case '.': { - if (is_empty ()) - { - octave_value tmp = octave_value::empty_conv (type, rhs); + if (is_empty ()) + { + octave_value tmp = octave_value::empty_conv (type, rhs); - retval = tmp.subsasgn (type, idx, rhs); - } - else - { - std::string nm = type_name (); - error ("%s cannot be indexed with %c", nm.c_str (), type[0]); - } + retval = tmp.subsasgn (type, idx, rhs); + } + else + { + std::string nm = type_name (); + error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + } } break; @@ -214,12 +214,12 @@ if (helper_iscomplex (el_type ()) && ! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex matrix", "real scalar"); + "complex matrix", "real scalar"); if (numel () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - type_name (), "real scalar"); + type_name (), "real scalar"); retval = helper_getreal (el_type (matrix (0, 0))); } @@ -238,12 +238,12 @@ if (helper_iscomplex (el_type ()) && ! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex matrix", "real scalar"); + "complex matrix", "real scalar"); if (numel () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - type_name (), "real scalar"); + type_name (), "real scalar"); retval = helper_getreal (el_type (matrix (0, 0))); } @@ -264,7 +264,7 @@ if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - type_name (), "complex scalar"); + type_name (), "complex scalar"); retval = matrix (0, 0); } @@ -285,7 +285,7 @@ if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - type_name (), "complex scalar"); + type_name (), "complex scalar"); retval = matrix (0, 0); } @@ -420,10 +420,10 @@ is >> tmp; if (!is) - { - error ("load: failed to load diagonal matrix constant"); - success = false; - } + { + error ("load: failed to load diagonal matrix constant"); + success = false; + } else { // This is a little tricky, as we have the Matrix type, but diff --git a/src/ov-base-int.cc b/src/ov-base-int.cc --- a/src/ov-base-int.cc +++ b/src/ov-base-int.cc @@ -153,23 +153,23 @@ static const bool is_signed = std::numeric_limits::is_signed; static const bool can_be_larger_than_uchar_max - = octave_base_int_helper_traits::can_be_larger_than_uchar_max; + = octave_base_int_helper_traits::can_be_larger_than_uchar_max; if (octave_base_int_helper::char_value_out_of_range (ival)) - { - // FIXME -- is there something better we could do? + can_be_larger_than_uchar_max>::char_value_out_of_range (ival)) + { + // FIXME -- is there something better we could do? - ival = 0; + ival = 0; - if (! warned) - { - ::warning ("range error for conversion to character value"); - warned = true; - } - } + if (! warned) + { + ::warning ("range error for conversion to character value"); + warned = true; + } + } else - chm (i) = static_cast (ival); + chm (i) = static_cast (ival); } retval = octave_value (chm, type); @@ -203,30 +203,30 @@ if (extract_keyword (is, "ndims", mdims, true)) { if (mdims >= 0) - { - dim_vector dv; - dv.resize (mdims); + { + dim_vector dv; + dv.resize (mdims); - for (int i = 0; i < mdims; i++) - is >> dv(i); + for (int i = 0; i < mdims; i++) + is >> dv(i); - T tmp(dv); + T tmp(dv); - is >> tmp; + is >> tmp; - if (!is) - { - error ("load: failed to load matrix constant"); - success = false; - } + if (!is) + { + error ("load: failed to load matrix constant"); + success = false; + } - this->matrix = tmp; - } + this->matrix = tmp; + } else - { - error ("load: failed to extract number of rows and columns"); - success = false; - } + { + error ("load: failed to extract number of rows and columns"); + success = false; + } } else error ("load: failed to extract number of dimensions"); @@ -259,7 +259,7 @@ template bool octave_base_int_matrix::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format ) + oct_mach_info::float_format ) { int32_t mdims; if (! is.read (reinterpret_cast (&mdims), 4)) @@ -277,9 +277,9 @@ for (int i = 0; i < mdims; i++) { if (! is.read (reinterpret_cast (&di), 4)) - return false; + return false; if (swap) - swap_bytes<4> (&di); + swap_bytes<4> (&di); dv(i) = di; } @@ -305,21 +305,21 @@ int nel = dv.numel (); int bytes = nel / m.byte_size(); for (int i = 0; i < nel; i++) - switch (bytes) - { - case 8: - swap_bytes<8> (&m(i)); - break; - case 4: - swap_bytes<4> (&m(i)); - break; - case 2: - swap_bytes<2> (&m(i)); - break; - case 1: - default: - break; - } + switch (bytes) + { + case 8: + swap_bytes<8> (&m(i)); + break; + case 4: + swap_bytes<4> (&m(i)); + break; + case 2: + swap_bytes<2> (&m(i)); + break; + case 1: + default: + break; + } } this->matrix = m; @@ -352,10 +352,10 @@ if (space_hid < 0) return false; #if HAVE_HDF5_18 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -364,7 +364,7 @@ } retval = H5Dwrite (data_hid, save_type_hid, H5S_ALL, H5S_ALL, - H5P_DEFAULT, this->matrix.data()) >= 0; + H5P_DEFAULT, this->matrix.data()) >= 0; H5Dclose (data_hid); H5Sclose (space_hid); @@ -417,12 +417,12 @@ { dv.resize (rank); for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--) - dv(j) = hdims[i]; + dv(j) = hdims[i]; } T m (dv); if (H5Dread (data_hid, save_type_hid, H5S_ALL, H5S_ALL, - H5P_DEFAULT, m.fortran_vec()) >= 0) + H5P_DEFAULT, m.fortran_vec()) >= 0) { retval = true; this->matrix = m; @@ -439,10 +439,10 @@ template void octave_base_int_matrix::print_raw (std::ostream& os, - bool pr_as_read_syntax) const + bool pr_as_read_syntax) const { octave_print_internal (os, this->matrix, pr_as_read_syntax, - this->current_print_indent_level ()); + this->current_print_indent_level ()); } template @@ -508,7 +508,7 @@ template bool octave_base_int_scalar::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format) + oct_mach_info::float_format) { T tmp; if (! is.read (reinterpret_cast (&tmp), this->byte_size())) @@ -518,17 +518,17 @@ switch (this->byte_size()) { case 8: - swap_bytes<8> (&tmp); - break; + swap_bytes<8> (&tmp); + break; case 4: - swap_bytes<4> (&tmp); - break; + swap_bytes<4> (&tmp); + break; case 2: - swap_bytes<2> (&tmp); - break; + swap_bytes<2> (&tmp); + break; case 1: default: - break; + break; } this->scalar = tmp; return true; @@ -550,10 +550,10 @@ #if HAVE_HDF5_18 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -562,7 +562,7 @@ } retval = H5Dwrite (data_hid, save_type_hid, H5S_ALL, H5S_ALL, - H5P_DEFAULT, &(this->scalar)) >= 0; + H5P_DEFAULT, &(this->scalar)) >= 0; H5Dclose (data_hid); H5Sclose (space_hid); @@ -592,7 +592,7 @@ T tmp; if (H5Dread (data_hid, save_type_hid, H5S_ALL, H5S_ALL, - H5P_DEFAULT, &tmp) < 0) + H5P_DEFAULT, &tmp) < 0) { H5Dclose (data_hid); return false; diff --git a/src/ov-base-mat.cc b/src/ov-base-mat.cc --- a/src/ov-base-mat.cc +++ b/src/ov-base-mat.cc @@ -38,7 +38,7 @@ template octave_value octave_base_matrix::subsref (const std::string& type, - const std::list& idx) + const std::list& idx) { octave_value retval; @@ -51,8 +51,8 @@ case '{': case '.': { - std::string nm = type_name (); - error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + std::string nm = type_name (); + error ("%s cannot be indexed with %c", nm.c_str (), type[0]); } break; @@ -66,8 +66,8 @@ template octave_value octave_base_matrix::subsasgn (const std::string& type, - const std::list& idx, - const octave_value& rhs) + const std::list& idx, + const octave_value& rhs) { octave_value retval; @@ -75,47 +75,47 @@ { case '(': { - if (type.length () == 1) - retval = numeric_assign (type, idx, rhs); - else if (is_empty ()) - { - // Allow conversion of empty matrix to some other type in - // cases like - // - // x = []; x(i).f = rhs + if (type.length () == 1) + retval = numeric_assign (type, idx, rhs); + else if (is_empty ()) + { + // Allow conversion of empty matrix to some other type in + // cases like + // + // x = []; x(i).f = rhs - if (type[1] == '.') - { - octave_value tmp = octave_value::empty_conv (type, rhs); + if (type[1] == '.') + { + octave_value tmp = octave_value::empty_conv (type, rhs); - retval = tmp.subsasgn (type, idx, rhs); - } - else - error ("invalid assignment expression"); - } - else - { - std::string nm = type_name (); - error ("in indexed assignment of %s, last lhs index must be ()", - nm.c_str ()); - } + retval = tmp.subsasgn (type, idx, rhs); + } + else + error ("invalid assignment expression"); + } + else + { + std::string nm = type_name (); + error ("in indexed assignment of %s, last lhs index must be ()", + nm.c_str ()); + } } break; case '{': case '.': { - if (is_empty ()) - { - octave_value tmp = octave_value::empty_conv (type, rhs); + if (is_empty ()) + { + octave_value tmp = octave_value::empty_conv (type, rhs); - retval = tmp.subsasgn (type, idx, rhs); - } - else - { - std::string nm = type_name (); - error ("%s cannot be indexed with %c", nm.c_str (), type[0]); - } + retval = tmp.subsasgn (type, idx, rhs); + } + else + { + std::string nm = type_name (); + error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + } } break; @@ -129,7 +129,7 @@ template octave_value octave_base_matrix::do_index_op (const octave_value_list& idx, - bool resize_ok) + bool resize_ok) { octave_value retval; @@ -145,9 +145,9 @@ case 1: { - idx_vector i = idx (0).index_vector (); + idx_vector i = idx (0).index_vector (); - if (! error_state) + if (! error_state) { // optimize single scalar index. if (i.is_scalar () && i(0) < matrix.numel ()) @@ -234,9 +234,9 @@ case 1: { - idx_vector i = idx (0).index_vector (); + idx_vector i = idx (0).index_vector (); - if (! error_state) + if (! error_state) matrix.assign (i, rhs); } break; @@ -305,9 +305,9 @@ case 1: { - idx_vector i = idx (0).index_vector (); + idx_vector i = idx (0).index_vector (); - if (! error_state) + if (! error_state) { // optimize single scalar index. if (i.is_scalar () && i(0) < matrix.numel ()) @@ -423,13 +423,13 @@ MT t1 (matrix.reshape (dim_vector (nel, 1))); if (t1.any_element_is_nan ()) - error ("invalid conversion from NaN to logical"); + error ("invalid conversion from NaN to logical"); else - { - boolNDArray t2 = t1.all (); + { + boolNDArray t2 = t1.all (); - retval = t2(0); - } + retval = t2(0); + } } return retval; @@ -455,7 +455,7 @@ template void octave_base_matrix::print_info (std::ostream& os, - const std::string& prefix) const + const std::string& prefix) const { matrix.print_info (os, prefix); } diff --git a/src/ov-base-scalar.cc b/src/ov-base-scalar.cc --- a/src/ov-base-scalar.cc +++ b/src/ov-base-scalar.cc @@ -37,7 +37,7 @@ template octave_value octave_base_scalar::subsref (const std::string& type, - const std::list& idx) + const std::list& idx) { octave_value retval; @@ -50,8 +50,8 @@ case '{': case '.': { - std::string nm = type_name (); - error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + std::string nm = type_name (); + error ("%s cannot be indexed with %c", nm.c_str (), type[0]); } break; @@ -65,8 +65,8 @@ template octave_value octave_base_scalar::subsasgn (const std::string& type, - const std::list& idx, - const octave_value& rhs) + const std::list& idx, + const octave_value& rhs) { octave_value retval; @@ -74,22 +74,22 @@ { case '(': { - if (type.length () == 1) + if (type.length () == 1) retval = numeric_assign (type, idx, rhs); - else - { - std::string nm = type_name (); - error ("in indexed assignment of %s, last rhs index must be ()", - nm.c_str ()); - } + else + { + std::string nm = type_name (); + error ("in indexed assignment of %s, last rhs index must be ()", + nm.c_str ()); + } } break; case '{': case '.': { - std::string nm = type_name (); - error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + std::string nm = type_name (); + error ("%s cannot be indexed with %c", nm.c_str (), type[0]); } break; @@ -125,7 +125,7 @@ template void octave_base_scalar::print_raw (std::ostream& os, - bool pr_as_read_syntax) const + bool pr_as_read_syntax) const { indent (os); octave_print_internal (os, scalar, pr_as_read_syntax); @@ -134,7 +134,7 @@ template bool octave_base_scalar::print_name_tag (std::ostream& os, - const std::string& name) const + const std::string& name) const { indent (os); os << name << " = "; diff --git a/src/ov-base-sparse.cc b/src/ov-base-sparse.cc --- a/src/ov-base-sparse.cc +++ b/src/ov-base-sparse.cc @@ -45,7 +45,7 @@ template octave_value octave_base_sparse::do_index_op (const octave_value_list& idx, - bool resize_ok) + bool resize_ok) { octave_value retval; @@ -61,42 +61,42 @@ case 1: { - idx_vector i = idx (0).index_vector (); + idx_vector i = idx (0).index_vector (); - if (! error_state) - retval = octave_value (matrix.index (i, resize_ok)); + if (! error_state) + retval = octave_value (matrix.index (i, resize_ok)); } break; default: { - if (n_idx == 2 && nd == 2) - { - idx_vector i = idx (0).index_vector (); + if (n_idx == 2 && nd == 2) + { + idx_vector i = idx (0).index_vector (); - if (! error_state) - { - idx_vector j = idx (1).index_vector (); + if (! error_state) + { + idx_vector j = idx (1).index_vector (); - if (! error_state) - retval = octave_value (matrix.index (i, j, resize_ok)); - } - } - else - { - Array idx_vec (n_idx); + if (! error_state) + retval = octave_value (matrix.index (i, j, resize_ok)); + } + } + else + { + Array idx_vec (n_idx); - for (octave_idx_type i = 0; i < n_idx; i++) - { - idx_vec(i) = idx(i).index_vector (); + for (octave_idx_type i = 0; i < n_idx; i++) + { + idx_vec(i) = idx(i).index_vector (); - if (error_state) - break; - } + if (error_state) + break; + } - if (! error_state) - retval = octave_value (matrix.index (idx_vec, resize_ok)); - } + if (! error_state) + retval = octave_value (matrix.index (idx_vec, resize_ok)); + } } break; } @@ -107,7 +107,7 @@ template octave_value octave_base_sparse::subsref (const std::string& type, - const std::list& idx) + const std::list& idx) { octave_value retval; @@ -120,8 +120,8 @@ case '{': case '.': { - std::string nm = type_name (); - error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + std::string nm = type_name (); + error ("%s cannot be indexed with %c", nm.c_str (), type[0]); } break; @@ -135,8 +135,8 @@ template octave_value octave_base_sparse::subsasgn (const std::string& type, - const std::list& idx, - const octave_value& rhs) + const std::list& idx, + const octave_value& rhs) { octave_value retval; @@ -144,31 +144,31 @@ { case '(': { - if (type.length () == 1) - retval = numeric_assign (type, idx, rhs); - else - { - std::string nm = type_name (); - error ("in indexed assignment of %s, last lhs index must be ()", - nm.c_str ()); - } + if (type.length () == 1) + retval = numeric_assign (type, idx, rhs); + else + { + std::string nm = type_name (); + error ("in indexed assignment of %s, last lhs index must be ()", + nm.c_str ()); + } } break; case '{': case '.': { - if (is_empty ()) - { - octave_value tmp = octave_value::empty_conv (type, rhs); + if (is_empty ()) + { + octave_value tmp = octave_value::empty_conv (type, rhs); - retval = tmp.subsasgn (type, idx, rhs); - } - else - { - std::string nm = type_name (); - error ("%s cannot be indexed with %c", nm.c_str (), type[0]); - } + retval = tmp.subsasgn (type, idx, rhs); + } + else + { + std::string nm = type_name (); + error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + } } break; @@ -261,7 +261,7 @@ template void octave_base_sparse::print_info (std::ostream& os, - const std::string& prefix) const + const std::string& prefix) const { matrix.print_info (os, prefix); } @@ -269,7 +269,7 @@ template void octave_base_sparse::print_raw (std::ostream& os, - bool pr_as_read_syntax) const + bool pr_as_read_syntax) const { octave_idx_type nr = matrix.rows (); octave_idx_type nc = matrix.cols (); @@ -296,24 +296,24 @@ if (nz != 0) { for (octave_idx_type j = 0; j < nc; j++) - { - octave_quit (); + { + octave_quit (); - // FIXME -- is there an easy way to get the max row - // and column indices so we can set the width appropriately - // and line up the columns here? Similarly, we should look - // at all the nonzero values and display them with the same - // formatting rules that apply to columns of a matrix. + // FIXME -- is there an easy way to get the max row + // and column indices so we can set the width appropriately + // and line up the columns here? Similarly, we should look + // at all the nonzero values and display them with the same + // formatting rules that apply to columns of a matrix. - for (octave_idx_type i = matrix.cidx(j); i < matrix.cidx(j+1); i++) - { - os << "\n"; - os << " (" << matrix.ridx(i)+1 << - ", " << j+1 << ") -> "; + for (octave_idx_type i = matrix.cidx(j); i < matrix.cidx(j+1); i++) + { + os << "\n"; + os << " (" << matrix.ridx(i)+1 << + ", " << j+1 << ") -> "; - octave_print_internal (os, matrix.data(i), pr_as_read_syntax); - } - } + octave_print_internal (os, matrix.data(i), pr_as_read_syntax); + } + } } } @@ -353,10 +353,10 @@ is >> tmp; if (!is) - { - error ("load: failed to load matrix constant"); - success = false; - } + { + error ("load: failed to load matrix constant"); + success = false; + } matrix = tmp; } diff --git a/src/ov-base.cc b/src/ov-base.cc --- a/src/ov-base.cc +++ b/src/ov-base.cc @@ -108,7 +108,7 @@ } DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_base_value, - "", "unknown"); + "", "unknown"); // TRUE means to perform automatic sparse to real mutation if there // is memory to be saved @@ -147,7 +147,7 @@ octave_value octave_base_value::subsref (const std::string&, - const std::list&) + const std::list&) { std::string nm = type_name (); error ("can't perform indexing operations for %s type", nm.c_str ()); @@ -156,7 +156,7 @@ octave_value_list octave_base_value::subsref (const std::string&, - const std::list&, int) + const std::list&, int) { std::string nm = type_name (); error ("can't perform indexing operations for %s type", nm.c_str ()); @@ -165,7 +165,7 @@ octave_value octave_base_value::subsref (const std::string& type, - const std::list& idx, + const std::list& idx, bool /* auto_add */) { // This way we may get a more meaningful error message. @@ -208,9 +208,9 @@ for (int i = n_dims; i > 2; i--) { if (dv(i-1) == 1) - n_dims--; + n_dims--; else - break; + break; } // The result is always >= 2. @@ -223,58 +223,58 @@ octave_value octave_base_value::subsasgn (const std::string& type, - const std::list& idx, - const octave_value& rhs) + const std::list& idx, + const octave_value& rhs) { octave_value retval; if (is_defined ()) { if (is_numeric_type ()) - { - switch (type[0]) - { - case '(': - { - if (type.length () == 1) - retval = numeric_assign (type, idx, rhs); - else if (is_empty ()) - { - // Allow conversion of empty matrix to some other - // type in cases like - // - // x = []; x(i).f = rhs + { + switch (type[0]) + { + case '(': + { + if (type.length () == 1) + retval = numeric_assign (type, idx, rhs); + else if (is_empty ()) + { + // Allow conversion of empty matrix to some other + // type in cases like + // + // x = []; x(i).f = rhs - octave_value tmp = octave_value::empty_conv (type, rhs); + octave_value tmp = octave_value::empty_conv (type, rhs); - retval = tmp.subsasgn (type, idx, rhs); - } - else - { - std::string nm = type_name (); - error ("in indexed assignment of %s, last rhs index must be ()", - nm.c_str ()); - } - } - break; + retval = tmp.subsasgn (type, idx, rhs); + } + else + { + std::string nm = type_name (); + error ("in indexed assignment of %s, last rhs index must be ()", + nm.c_str ()); + } + } + break; - case '{': - case '.': - { - std::string nm = type_name (); - error ("%s cannot be indexed with %c", nm.c_str (), type[0]); - } - break; + case '{': + case '.': + { + std::string nm = type_name (); + error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + } + break; - default: - panic_impossible (); - } - } + default: + panic_impossible (); + } + } else - { - std::string nm = type_name (); - error ("can't perform indexed assignment for %s type", nm.c_str ()); - } + { + std::string nm = type_name (); + error ("can't perform indexed assignment for %s type", nm.c_str ()); + } } else { @@ -364,7 +364,7 @@ if (! force && is_numeric_type ()) gripe_implicit_conversion ("Octave:num-to-str", - type_name (), retval.type_name ()); + type_name (), retval.type_name ()); return retval; } @@ -373,7 +373,7 @@ octave_base_value::convert_to_str_internal (bool, bool, char) const { gripe_wrong_type_arg ("octave_base_value::convert_to_str_internal ()", - type_name ()); + type_name ()); return octave_value (); } @@ -419,8 +419,8 @@ void octave_base_value::print_with_name (std::ostream& output_buf, - const std::string& name, - bool print_padding) + const std::string& name, + bool print_padding) { bool pad_after = print_name_tag (output_buf, name); @@ -432,7 +432,7 @@ void octave_base_value::print_info (std::ostream& os, - const std::string& /* prefix */) const + const std::string& /* prefix */) const { os << "no info for type: " << type_name () << "\n"; } @@ -447,18 +447,18 @@ \ if (! error_state) \ { \ - if (require_int && D_NINT (d) != d) \ - error_with_cfn ("conversion of %g to " #T " value failed", d); \ - else if (d < MIN_LIMIT) \ - retval = MIN_LIMIT; \ - else if (d > MAX_LIMIT) \ - retval = MAX_LIMIT; \ - else \ - retval = static_cast (::fix (d)); \ + if (require_int && D_NINT (d) != d) \ + error_with_cfn ("conversion of %g to " #T " value failed", d); \ + else if (d < MIN_LIMIT) \ + retval = MIN_LIMIT; \ + else if (d > MAX_LIMIT) \ + retval = MAX_LIMIT; \ + else \ + retval = static_cast (::fix (d)); \ } \ else \ gripe_wrong_type_arg ("octave_base_value::" #F "_value ()", \ - type_name ()); \ + type_name ()); \ \ return retval; \ } @@ -482,10 +482,10 @@ if (! error_state) { if (xisnan (d)) - { - error ("conversion of NaN to integer value failed"); - return retval; - } + { + error ("conversion of NaN to integer value failed"); + return retval; + } retval = static_cast (::fix (d)); } @@ -574,7 +574,7 @@ { ComplexMatrix retval; gripe_wrong_type_arg ("octave_base_value::complex_matrix_value()", - type_name ()); + type_name ()); return retval; } @@ -583,7 +583,7 @@ { FloatComplexMatrix retval; gripe_wrong_type_arg ("octave_base_value::float_complex_matrix_value()", - type_name ()); + type_name ()); return retval; } @@ -592,7 +592,7 @@ { ComplexNDArray retval; gripe_wrong_type_arg ("octave_base_value::complex_array_value()", - type_name ()); + type_name ()); return retval; } @@ -601,7 +601,7 @@ { FloatComplexNDArray retval; gripe_wrong_type_arg ("octave_base_value::float_complex_array_value()", - type_name ()); + type_name ()); return retval; } @@ -618,7 +618,7 @@ { boolMatrix retval; gripe_wrong_type_arg ("octave_base_value::bool_matrix_value()", - type_name ()); + type_name ()); return retval; } @@ -627,7 +627,7 @@ { boolNDArray retval; gripe_wrong_type_arg ("octave_base_value::bool_array_value()", - type_name ()); + type_name ()); return retval; } @@ -649,7 +649,7 @@ { charNDArray retval; gripe_wrong_type_arg ("octave_base_value::char_array_value()", - type_name ()); + type_name ()); return retval; } @@ -722,7 +722,7 @@ { octave_int8 retval; gripe_wrong_type_arg ("octave_base_value::int8_scalar_value()", - type_name ()); + type_name ()); return retval; } @@ -731,7 +731,7 @@ { octave_int16 retval; gripe_wrong_type_arg ("octave_base_value::int16_scalar_value()", - type_name ()); + type_name ()); return retval; } @@ -740,7 +740,7 @@ { octave_int32 retval; gripe_wrong_type_arg ("octave_base_value::int32_scalar_value()", - type_name ()); + type_name ()); return retval; } @@ -749,7 +749,7 @@ { octave_int64 retval; gripe_wrong_type_arg ("octave_base_value::int64_scalar_value()", - type_name ()); + type_name ()); return retval; } @@ -758,7 +758,7 @@ { octave_uint8 retval; gripe_wrong_type_arg ("octave_base_value::uint8_scalar_value()", - type_name ()); + type_name ()); return retval; } @@ -767,7 +767,7 @@ { octave_uint16 retval; gripe_wrong_type_arg ("octave_base_value::uint16_scalar_value()", - type_name ()); + type_name ()); return retval; } @@ -776,7 +776,7 @@ { octave_uint32 retval; gripe_wrong_type_arg ("octave_base_value::uint32_scalar_value()", - type_name ()); + type_name ()); return retval; } @@ -785,7 +785,7 @@ { octave_uint64 retval; gripe_wrong_type_arg ("octave_base_value::uint64_scalar_value()", - type_name ()); + type_name ()); return retval; } @@ -794,7 +794,7 @@ { int8NDArray retval; gripe_wrong_type_arg ("octave_base_value::int8_array_value()", - type_name ()); + type_name ()); return retval; } @@ -803,7 +803,7 @@ { int16NDArray retval; gripe_wrong_type_arg ("octave_base_value::int16_array_value()", - type_name ()); + type_name ()); return retval; } @@ -812,7 +812,7 @@ { int32NDArray retval; gripe_wrong_type_arg ("octave_base_value::int32_array_value()", - type_name ()); + type_name ()); return retval; } @@ -821,7 +821,7 @@ { int64NDArray retval; gripe_wrong_type_arg ("octave_base_value::int64_array_value()", - type_name ()); + type_name ()); return retval; } @@ -830,7 +830,7 @@ { uint8NDArray retval; gripe_wrong_type_arg ("octave_base_value::uint8_array_value()", - type_name ()); + type_name ()); return retval; } @@ -839,7 +839,7 @@ { uint16NDArray retval; gripe_wrong_type_arg ("octave_base_value::uint16_array_value()", - type_name ()); + type_name ()); return retval; } @@ -848,7 +848,7 @@ { uint32NDArray retval; gripe_wrong_type_arg ("octave_base_value::uint32_array_value()", - type_name ()); + type_name ()); return retval; } @@ -857,7 +857,7 @@ { uint64NDArray retval; gripe_wrong_type_arg ("octave_base_value::uint64_array_value()", - type_name ()); + type_name ()); return retval; } @@ -892,7 +892,7 @@ { Array retval; gripe_wrong_type_arg ("octave_base_value::cellstry_value()", - type_name ()); + type_name ()); return retval; } @@ -933,7 +933,7 @@ { std::list retval; gripe_wrong_type_arg ("octave_base_value::parent_class_name_list()", - type_name ()); + type_name ()); return retval; } @@ -942,7 +942,7 @@ { string_vector retval; gripe_wrong_type_arg ("octave_base_value::parent_class_names()", - type_name ()); + type_name ()); return retval; } @@ -953,7 +953,7 @@ if (! silent) gripe_wrong_type_arg ("octave_base_value::function_value()", - type_name ()); + type_name ()); return retval; } @@ -964,7 +964,7 @@ if (! silent) gripe_wrong_type_arg ("octave_base_value::user_function_value()", - type_name ()); + type_name ()); return retval; } @@ -975,7 +975,7 @@ if (! silent) gripe_wrong_type_arg ("octave_base_value::user_script_value()", - type_name ()); + type_name ()); return retval; } @@ -986,7 +986,7 @@ if (! silent) gripe_wrong_type_arg ("octave_base_value::user_code_value()", - type_name ()); + type_name ()); return retval; } @@ -997,7 +997,7 @@ if (! silent) gripe_wrong_type_arg ("octave_base_value::fcn_handle_value()", - type_name ()); + type_name ()); return retval; } @@ -1008,7 +1008,7 @@ if (! silent) gripe_wrong_type_arg ("octave_base_value::fcn_inline_value()", - type_name ()); + type_name ()); return retval; } @@ -1043,7 +1043,7 @@ bool octave_base_value::load_binary (std::istream&, bool, - oct_mach_info::float_format) + oct_mach_info::float_format) { gripe_wrong_type_arg ("octave_base_value::load_binary()", type_name ()); return false; @@ -1071,7 +1071,7 @@ int octave_base_value::write (octave_stream&, int, oct_data_conv::data_type, - int, oct_mach_info::float_format) const + int, oct_mach_info::float_format) const { gripe_wrong_type_arg ("octave_base_value::write()", type_name ()); @@ -1104,7 +1104,7 @@ octave_value octave_base_value::sort (Array &, - octave_idx_type, sortmode) const + octave_idx_type, sortmode) const { gripe_wrong_type_arg ("octave_base_value::sort ()", type_name ()); @@ -1237,29 +1237,29 @@ gripe_indexed_assignment (const std::string& tn1, const std::string& tn2) { error ("assignment of `%s' to indexed `%s' not implemented", - tn2.c_str (), tn1.c_str ()); + tn2.c_str (), tn1.c_str ()); } static void gripe_assign_conversion_failed (const std::string& tn1, - const std::string& tn2) + const std::string& tn2) { error ("type conversion for assignment of `%s' to indexed `%s' failed", - tn2.c_str (), tn1.c_str ()); + tn2.c_str (), tn1.c_str ()); } static void gripe_no_conversion (const std::string& on, const std::string& tn1, - const std::string& tn2) + const std::string& tn2) { error ("operator %s: no conversion for assignment of `%s' to indexed `%s'", - on.c_str (), tn2.c_str (), tn1.c_str ()); + on.c_str (), tn2.c_str (), tn1.c_str ()); } octave_value octave_base_value::numeric_assign (const std::string& type, - const std::list& idx, - const octave_value& rhs) + const std::list& idx, + const octave_value& rhs) { octave_value retval; @@ -1274,7 +1274,7 @@ octave_value_typeinfo::assign_op_fcn f = octave_value_typeinfo::lookup_assign_op (octave_value::op_asn_eq, - t_lhs, t_rhs); + t_lhs, t_rhs); bool done = false; @@ -1293,42 +1293,42 @@ else { int t_result - = octave_value_typeinfo::lookup_pref_assign_conv (t_lhs, t_rhs); + = octave_value_typeinfo::lookup_pref_assign_conv (t_lhs, t_rhs); if (t_result >= 0) - { - octave_base_value::type_conv_fcn cf - = octave_value_typeinfo::lookup_widening_op (t_lhs, t_result); + { + octave_base_value::type_conv_fcn cf + = octave_value_typeinfo::lookup_widening_op (t_lhs, t_result); - if (cf) - { - octave_base_value *tmp = cf (*this); + if (cf) + { + octave_base_value *tmp = cf (*this); - if (tmp) - { - octave_value val (tmp); + if (tmp) + { + octave_value val (tmp); - retval = val.subsasgn (type, idx, rhs); + retval = val.subsasgn (type, idx, rhs); - done = (! error_state); - } - else - gripe_assign_conversion_failed (type_name (), - rhs.type_name ()); - } - else - gripe_indexed_assignment (type_name (), rhs.type_name ()); - } + done = (! error_state); + } + else + gripe_assign_conversion_failed (type_name (), + rhs.type_name ()); + } + else + gripe_indexed_assignment (type_name (), rhs.type_name ()); + } if (! (done || error_state)) - { - octave_value tmp_rhs; + { + octave_value tmp_rhs; - octave_base_value::type_conv_info cf_rhs - = rhs.numeric_conversion_function (); + octave_base_value::type_conv_info cf_rhs + = rhs.numeric_conversion_function (); - octave_base_value::type_conv_info cf_this - = numeric_conversion_function (); + octave_base_value::type_conv_info cf_this + = numeric_conversion_function (); // Try biased (one-sided) conversions first. if (cf_rhs.type_id () >= 0 @@ -1344,49 +1344,49 @@ t_rhs) >= 0)) cf_rhs = 0; - if (cf_rhs) - { - octave_base_value *tmp = cf_rhs (rhs.get_rep ()); + if (cf_rhs) + { + octave_base_value *tmp = cf_rhs (rhs.get_rep ()); - if (tmp) - tmp_rhs = octave_value (tmp); - else - { - gripe_assign_conversion_failed (type_name (), - rhs.type_name ()); - return octave_value (); - } - } - else - tmp_rhs = rhs; + if (tmp) + tmp_rhs = octave_value (tmp); + else + { + gripe_assign_conversion_failed (type_name (), + rhs.type_name ()); + return octave_value (); + } + } + else + tmp_rhs = rhs; - count++; - octave_value tmp_lhs = octave_value (this); + count++; + octave_value tmp_lhs = octave_value (this); - if (cf_this) - { - octave_base_value *tmp = cf_this (*this); + if (cf_this) + { + octave_base_value *tmp = cf_this (*this); - if (tmp) - tmp_lhs = octave_value (tmp); - else - { - gripe_assign_conversion_failed (type_name (), - rhs.type_name ()); - return octave_value (); - } - } + if (tmp) + tmp_lhs = octave_value (tmp); + else + { + gripe_assign_conversion_failed (type_name (), + rhs.type_name ()); + return octave_value (); + } + } - if (cf_this || cf_rhs) - { - retval = tmp_lhs.subsasgn (type, idx, tmp_rhs); + if (cf_this || cf_rhs) + { + retval = tmp_lhs.subsasgn (type, idx, tmp_rhs); - done = (! error_state); - } - else - gripe_no_conversion (octave_value::assign_op_as_string (octave_value::op_asn_eq), - type_name (), rhs.type_name ()); - } + done = (! error_state); + } + else + gripe_no_conversion (octave_value::assign_op_as_string (octave_value::op_asn_eq), + type_name (), rhs.type_name ()); + } } // The assignment may have converted to a type that is wider than @@ -1418,7 +1418,7 @@ // os << prefix; for (int i = 0; i < curr_print_indent_level; i++) - os << " "; + os << " "; beginning_of_line = false; } diff --git a/src/ov-bool-mat.cc b/src/ov-bool-mat.cc --- a/src/ov-bool-mat.cc +++ b/src/ov-bool-mat.cc @@ -54,7 +54,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_bool_matrix); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_bool_matrix, - "bool matrix", "logical"); + "bool matrix", "logical"); static octave_base_value * default_numeric_conversion_function (const octave_base_value& a) @@ -84,7 +84,7 @@ octave_idx_type nc = bm.cols (); if (nr == 1 && nc == 1) - retval = new octave_bool (bm (0, 0)); + retval = new octave_bool (bm (0, 0)); } return retval; @@ -98,7 +98,7 @@ if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "bool matrix", "real scalar"); + "bool matrix", "real scalar"); retval = matrix (0, 0); } @@ -116,7 +116,7 @@ if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "bool matrix", "real scalar"); + "bool matrix", "real scalar"); retval = matrix (0, 0); } @@ -136,7 +136,7 @@ if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "bool matrix", "complex scalar"); + "bool matrix", "complex scalar"); retval = matrix (0, 0); } @@ -156,7 +156,7 @@ if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "bool matrix", "complex scalar"); + "bool matrix", "complex scalar"); retval = matrix (0, 0); } @@ -168,7 +168,7 @@ octave_value octave_bool_matrix::convert_to_str_internal (bool pad, bool force, - char type) const + char type) const { octave_value tmp = octave_value (array_value ()); return tmp.convert_to_str (pad, force, type); @@ -176,10 +176,10 @@ void octave_bool_matrix::print_raw (std::ostream& os, - bool pr_as_read_syntax) const + bool pr_as_read_syntax) const { octave_print_internal (os, matrix, pr_as_read_syntax, - current_print_indent_level ()); + current_print_indent_level ()); } bool @@ -192,7 +192,7 @@ os << "# ndims: " << d.length () << "\n"; for (int i = 0; i < d.length (); i++) - os << " " << d (i); + os << " " << d (i); os << "\n" << tmp; } @@ -201,7 +201,7 @@ // Keep this case, rather than use generic code above for backward // compatiability. Makes load_ascii much more complex!! os << "# rows: " << rows () << "\n" - << "# columns: " << columns () << "\n"; + << "# columns: " << columns () << "\n"; Matrix tmp = matrix_value (); @@ -227,93 +227,93 @@ if (extract_keyword (is, keywords, kw, val, true)) { if (kw == "ndims") - { - int mdims = static_cast (val); + { + int mdims = static_cast (val); - if (mdims >= 0) - { - dim_vector dv; - dv.resize (mdims); + if (mdims >= 0) + { + dim_vector dv; + dv.resize (mdims); - for (int i = 0; i < mdims; i++) - is >> dv(i); + for (int i = 0; i < mdims; i++) + is >> dv(i); - if (is) - { - boolNDArray btmp (dv); + if (is) + { + boolNDArray btmp (dv); - if (btmp.is_empty ()) - matrix = btmp; - else - { - NDArray tmp(dv); - is >> tmp; + if (btmp.is_empty ()) + matrix = btmp; + else + { + NDArray tmp(dv); + is >> tmp; - if (is) - { - for (octave_idx_type i = 0; i < btmp.nelem (); i++) - btmp.elem (i) = (tmp.elem (i) != 0.); + if (is) + { + for (octave_idx_type i = 0; i < btmp.nelem (); i++) + btmp.elem (i) = (tmp.elem (i) != 0.); - matrix = btmp; - } - else - { - error ("load: failed to load matrix constant"); - success = false; - } - } - } - else - { - error ("load: failed to extract dimensions"); - success = false; - } - } - else - { - error ("load: failed to extract number of dimensions"); - success = false; - } - } + matrix = btmp; + } + else + { + error ("load: failed to load matrix constant"); + success = false; + } + } + } + else + { + error ("load: failed to extract dimensions"); + success = false; + } + } + else + { + error ("load: failed to extract number of dimensions"); + success = false; + } + } else if (kw == "rows") - { - octave_idx_type nr = val; - octave_idx_type nc = 0; + { + octave_idx_type nr = val; + octave_idx_type nc = 0; - if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0) - { - if (nr > 0 && nc > 0) - { - Matrix tmp (nr, nc); - is >> tmp; - if (is) - { - boolMatrix btmp (nr, nc); - for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - btmp.elem (i,j) = (tmp.elem (i, j) != 0.); + if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0) + { + if (nr > 0 && nc > 0) + { + Matrix tmp (nr, nc); + is >> tmp; + if (is) + { + boolMatrix btmp (nr, nc); + for (octave_idx_type j = 0; j < nc; j++) + for (octave_idx_type i = 0; i < nr; i++) + btmp.elem (i,j) = (tmp.elem (i, j) != 0.); - matrix = btmp; - } - else - { - error ("load: failed to load matrix constant"); - success = false; - } - } - else if (nr == 0 || nc == 0) - matrix = boolMatrix (nr, nc); - else - panic_impossible (); - } - else - { - error ("load: failed to extract number of rows and columns"); - success = false; - } - } + matrix = btmp; + } + else + { + error ("load: failed to load matrix constant"); + success = false; + } + } + else if (nr == 0 || nc == 0) + matrix = boolMatrix (nr, nc); + else + panic_impossible (); + } + else + { + error ("load: failed to extract number of rows and columns"); + success = false; + } + } else - panic_impossible (); + panic_impossible (); } else { @@ -356,7 +356,7 @@ bool octave_bool_matrix::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format /* fmt */) + oct_mach_info::float_format /* fmt */) { int32_t mdims; if (! is.read (reinterpret_cast (&mdims), 4)) @@ -377,9 +377,9 @@ for (int i = 0; i < mdims; i++) { if (! is.read (reinterpret_cast (&di), 4)) - return false; + return false; if (swap) - swap_bytes<4> (&di); + swap_bytes<4> (&di); dv(i) = di; } @@ -412,7 +412,7 @@ bool octave_bool_matrix::save_hdf5 (hid_t loc_id, const char *name, - bool /* save_as_floats */) + bool /* save_as_floats */) { dim_vector dv = dims (); int empty = save_hdf5_empty (loc_id, name, dv); @@ -434,10 +434,10 @@ if (space_hid < 0) return false; #if HAVE_HDF5_18 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_HBOOL, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_HBOOL, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -453,7 +453,7 @@ htmp[i] = mtmp[i]; retval = H5Dwrite (data_hid, H5T_NATIVE_HBOOL, H5S_ALL, H5S_ALL, - H5P_DEFAULT, htmp) >= 0; + H5P_DEFAULT, htmp) >= 0; H5Dclose (data_hid); H5Sclose (space_hid); @@ -504,7 +504,7 @@ { dv.resize (rank); for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--) - dv(j) = hdims[i]; + dv(j) = hdims[i]; } octave_idx_type nel = dv.numel (); @@ -515,7 +515,7 @@ boolNDArray btmp (dv); for (octave_idx_type i = 0; i < nel; i++) - btmp.elem (i) = htmp[i]; + btmp.elem (i) = htmp[i]; matrix = btmp; } diff --git a/src/ov-bool-sparse.cc b/src/ov-bool-sparse.cc --- a/src/ov-bool-sparse.cc +++ b/src/ov-bool-sparse.cc @@ -77,16 +77,16 @@ // Note that for the second test, this means it becomes approximative // since it involves a cast to double to avoid issues of overflow if (matrix.rows () == 1 && matrix.cols () == 1) - { - // Const copy of the matrix, so the right version of () operator used - const SparseBoolMatrix tmp (matrix); + { + // Const copy of the matrix, so the right version of () operator used + const SparseBoolMatrix tmp (matrix); - retval = new octave_bool (tmp (0)); - } + retval = new octave_bool (tmp (0)); + } else if (matrix.cols () > 0 && matrix.rows () > 0 - && (double (matrix.byte_size ()) > double (matrix.rows ()) - * double (matrix.cols ()) * sizeof (bool))) - retval = new octave_bool_matrix (matrix.matrix_value ()); + && (double (matrix.byte_size ()) > double (matrix.rows ()) + * double (matrix.cols ()) * sizeof (bool))) + retval = new octave_bool_matrix (matrix.matrix_value ()); } return retval; @@ -100,8 +100,8 @@ if (numel () > 0) { if (numel () > 1) - gripe_implicit_conversion ("Octave:array-as-scalar", - "bool sparse matrix", "real scalar"); + gripe_implicit_conversion ("Octave:array-as-scalar", + "bool sparse matrix", "real scalar"); retval = matrix (0, 0); } @@ -121,8 +121,8 @@ if (rows () > 0 && columns () > 0) { if (numel () > 1) - gripe_implicit_conversion ("Octave:array-as-scalar", - "bool sparse matrix", "complex scalar"); + gripe_implicit_conversion ("Octave:array-as-scalar", + "bool sparse matrix", "complex scalar"); retval = matrix (0, 0); } @@ -134,7 +134,7 @@ octave_value octave_sparse_bool_matrix::convert_to_str_internal (bool pad, bool force, - char type) const + char type) const { octave_value tmp = octave_value (array_value ()); return tmp.convert_to_str (pad, force, type); @@ -261,7 +261,7 @@ bool octave_sparse_bool_matrix::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format /* fmt */) + oct_mach_info::float_format /* fmt */) { int32_t nz, nc, nr, tmp; if (! is.read (reinterpret_cast (&tmp), 4)) @@ -290,16 +290,16 @@ } SparseBoolMatrix m (static_cast (nr), - static_cast (nc), - static_cast (nz)); + static_cast (nc), + static_cast (nz)); for (int i = 0; i < nc+1; i++) { octave_quit (); if (! is.read (reinterpret_cast (&tmp), 4)) - return false; + return false; if (swap) - swap_bytes<4> (&tmp); + swap_bytes<4> (&tmp); m.cidx(i) = tmp; } @@ -307,9 +307,9 @@ { octave_quit (); if (! is.read (reinterpret_cast (&tmp), 4)) - return false; + return false; if (swap) - swap_bytes<4> (&tmp); + swap_bytes<4> (&tmp); m.ridx(i) = tmp; } @@ -366,10 +366,10 @@ } #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "nr", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "nr", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -390,10 +390,10 @@ #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "nc", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "nc", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -404,7 +404,7 @@ tmp = m.cols (); retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, - H5P_DEFAULT, &tmp) >= 0; + H5P_DEFAULT, &tmp) >= 0; H5Dclose (data_hid); if (!retval) { @@ -415,10 +415,10 @@ #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "nz", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "nz", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -429,7 +429,7 @@ tmp = m.nzmax (); retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, - H5P_DEFAULT, &tmp) >= 0; + H5P_DEFAULT, &tmp) >= 0; H5Dclose (data_hid); if (!retval) { @@ -453,10 +453,10 @@ #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "cidx", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "cidx", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -467,7 +467,7 @@ octave_idx_type * itmp = m.xcidx (); retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, - H5P_DEFAULT, itmp) >= 0; + H5P_DEFAULT, itmp) >= 0; H5Dclose (data_hid); if (!retval) { @@ -491,10 +491,10 @@ #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "ridx", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "ridx", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -505,7 +505,7 @@ itmp = m.xridx (); retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, - H5P_DEFAULT, itmp) >= 0; + H5P_DEFAULT, itmp) >= 0; H5Dclose (data_hid); if (!retval) { @@ -516,10 +516,10 @@ #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "data", H5T_NATIVE_HBOOL, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "data", H5T_NATIVE_HBOOL, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -533,7 +533,7 @@ htmp[i] = m.xdata(i); retval = H5Dwrite (data_hid, H5T_NATIVE_HBOOL, H5S_ALL, H5S_ALL, - H5P_DEFAULT, htmp) >= 0; + H5P_DEFAULT, htmp) >= 0; H5Dclose (data_hid); H5Sclose (space_hid); H5Gclose (group_hid); @@ -635,8 +635,8 @@ H5Dclose (data_hid); SparseBoolMatrix m (static_cast (nr), - static_cast (nc), - static_cast (nz)); + static_cast (nc), + static_cast (nz)); #if HAVE_HDF5_18 data_hid = H5Dopen (group_hid, "cidx", H5P_DEFAULT); @@ -709,7 +709,7 @@ itmp = m.xridx (); if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, - H5P_DEFAULT, itmp) < 0) + H5P_DEFAULT, itmp) < 0) { H5Sclose (space_hid); H5Dclose (data_hid); @@ -750,13 +750,13 @@ OCTAVE_LOCAL_BUFFER (hbool_t, htmp, nz); bool retval = false; if (H5Dread (data_hid, H5T_NATIVE_HBOOL, H5S_ALL, H5S_ALL, - H5P_DEFAULT, htmp) >= 0 + H5P_DEFAULT, htmp) >= 0 && m.indices_ok ()) { retval = true; for (int i = 0; i < nz; i++) - m.xdata(i) = htmp[i]; + m.xdata(i) = htmp[i]; matrix = m; } @@ -775,7 +775,7 @@ { mwSize nz = nzmax (); mxArray *retval = new mxArray (mxLOGICAL_CLASS, rows (), columns (), - nz, mxREAL); + nz, mxREAL); bool *pr = static_cast (retval->get_data ()); mwIndex *ir = retval->get_ir (); mwIndex *jc = retval->get_jc (); diff --git a/src/ov-bool.cc b/src/ov-bool.cc --- a/src/ov-bool.cc +++ b/src/ov-bool.cc @@ -91,14 +91,14 @@ { boolNDArray retval (dv, false); if (dv.numel()) - retval(0) = scalar; + retval(0) = scalar; return retval; } else { boolNDArray retval (dv); if (dv.numel()) - retval(0) = scalar; + retval(0) = scalar; return retval; } } @@ -149,7 +149,7 @@ bool octave_bool::load_binary (std::istream& is, bool /* swap */, - oct_mach_info::float_format /* fmt */) + oct_mach_info::float_format /* fmt */) { char tmp; if (! is.read (reinterpret_cast (&tmp), 1)) @@ -162,7 +162,7 @@ bool octave_bool::save_hdf5 (hid_t loc_id, const char *name, - bool /* save_as_floats */) + bool /* save_as_floats */) { hsize_t dimens[3]; hid_t space_hid = -1, data_hid = -1; @@ -172,10 +172,10 @@ if (space_hid < 0) return false; #if HAVE_HDF5_18 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_DOUBLE, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_DOUBLE, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -185,7 +185,7 @@ double tmp = double_value (); retval = H5Dwrite (data_hid, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, &tmp) >= 0; + H5P_DEFAULT, &tmp) >= 0; H5Dclose (data_hid); H5Sclose (space_hid); @@ -213,7 +213,7 @@ double dtmp; if (H5Dread (data_hid, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, &dtmp) < 0) + H5P_DEFAULT, &dtmp) < 0) { H5Dclose (data_hid); return false; diff --git a/src/ov-builtin.cc b/src/ov-builtin.cc --- a/src/ov-builtin.cc +++ b/src/ov-builtin.cc @@ -36,13 +36,13 @@ DEFINE_OCTAVE_ALLOCATOR (octave_builtin); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_builtin, - "built-in function", - "built-in function"); + "built-in function", + "built-in function"); octave_value_list octave_builtin::subsref (const std::string& type, - const std::list& idx, - int nargout) + const std::list& idx, + int nargout) { octave_value_list retval; @@ -50,17 +50,17 @@ { case '(': { - int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; + int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; - retval = do_multi_index_op (tmp_nargout, idx.front ()); + retval = do_multi_index_op (tmp_nargout, idx.front ()); } break; case '{': case '.': { - std::string nm = type_name (); - error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + std::string nm = type_name (); + error ("%s cannot be indexed with %c", nm.c_str (), type[0]); } break; @@ -103,8 +103,8 @@ frame.add_fcn (octave_call_stack::pop); try - { - retval = (*f) (args, nargout); + { + retval = (*f) (args, nargout); // Do not allow null values to be returned from functions. // FIXME -- perhaps true builtins should be allowed? retval.make_storable_values (); @@ -116,11 +116,11 @@ // the idiom is very common, so we solve that here. if (retval.length () == 1 && retval.xelem (0).is_undefined ()) retval.clear (); - } + } catch (octave_execution_exception) - { - gripe_library_execution_error (); - } + { + gripe_library_execution_error (); + } } return retval; diff --git a/src/ov-cell.cc b/src/ov-cell.cc --- a/src/ov-cell.cc +++ b/src/ov-cell.cc @@ -106,8 +106,8 @@ octave_value_list octave_cell::subsref (const std::string& type, - const std::list& idx, - int nargout) + const std::list& idx, + int nargout) { octave_value_list retval; @@ -119,24 +119,24 @@ case '{': { - octave_value tmp = do_index_op (idx.front ()); + octave_value tmp = do_index_op (idx.front ()); - if (! error_state) - { - Cell tcell = tmp.cell_value (); + if (! error_state) + { + Cell tcell = tmp.cell_value (); - if (tcell.length () == 1) - retval(0) = tcell(0,0); - else + if (tcell.length () == 1) + retval(0) = tcell(0,0); + else retval = octave_value (octave_value_list (tcell), true); - } + } } break; case '.': { - std::string nm = type_name (); - error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + std::string nm = type_name (); + error ("%s cannot be indexed with %c", nm.c_str (), type[0]); } break; @@ -156,8 +156,8 @@ octave_value octave_cell::subsref (const std::string& type, - const std::list& idx, - bool auto_add) + const std::list& idx, + bool auto_add) { octave_value retval; @@ -169,24 +169,24 @@ case '{': { - octave_value tmp = do_index_op (idx.front (), auto_add); + octave_value tmp = do_index_op (idx.front (), auto_add); - if (! error_state) - { - const Cell tcell = tmp.cell_value (); + if (! error_state) + { + const Cell tcell = tmp.cell_value (); - if (tcell.length () == 1) - retval = tcell(0,0); - else + if (tcell.length () == 1) + retval = tcell(0,0); + else retval = octave_value (octave_value_list (tcell), true); - } + } } break; case '.': { - std::string nm = type_name (); - error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + std::string nm = type_name (); + error ("%s cannot be indexed with %c", nm.c_str (), type[0]); } break; @@ -206,8 +206,8 @@ octave_value octave_cell::subsasgn (const std::string& type, - const std::list& idx, - const octave_value& rhs) + const std::list& idx, + const octave_value& rhs) { octave_value retval; @@ -226,48 +226,48 @@ if (n > 1) { switch (type[0]) - { - case '(': - { - if (is_empty () && type[1] == '.') - { - // Allow conversion of empty cell array to some other - // type in cases like - // - // x = []; x(i).f = rhs + { + case '(': + { + if (is_empty () && type[1] == '.') + { + // Allow conversion of empty cell array to some other + // type in cases like + // + // x = []; x(i).f = rhs - octave_value tmp = octave_value::empty_conv (type, rhs); + octave_value tmp = octave_value::empty_conv (type, rhs); - return tmp.subsasgn (type, idx, rhs); - } - else - { - octave_value tmp = do_index_op (idx.front (), true); + return tmp.subsasgn (type, idx, rhs); + } + else + { + octave_value tmp = do_index_op (idx.front (), true); - if (! tmp.is_defined ()) - tmp = octave_value::empty_conv (type.substr (1), rhs); + if (! tmp.is_defined ()) + tmp = octave_value::empty_conv (type.substr (1), rhs); - if (! error_state) - { - std::list next_idx (idx); + if (! error_state) + { + std::list next_idx (idx); - next_idx.erase (next_idx.begin ()); + next_idx.erase (next_idx.begin ()); - tmp.make_unique (); + tmp.make_unique (); - t_rhs = tmp.subsasgn (type.substr (1), next_idx, rhs); - } - } - } - break; + t_rhs = tmp.subsasgn (type.substr (1), next_idx, rhs); + } + } + } + break; - case '{': - { + case '{': + { matrix.make_unique (); - Cell tmpc = matrix.index (idx.front (), true); + Cell tmpc = matrix.index (idx.front (), true); - if (! error_state) - { + if (! error_state) + { std::list next_idx (idx); next_idx.erase (next_idx.begin ()); @@ -275,11 +275,11 @@ std::string next_type = type.substr (1); if (tmpc.numel () == 1) - { - octave_value tmp = tmpc(0); + { + octave_value tmp = tmpc(0); tmpc = Cell (); - if (! tmp.is_defined () || tmp.is_zero_by_zero ()) + if (! tmp.is_defined () || tmp.is_zero_by_zero ()) { tmp = octave_value::empty_conv (type.substr (1), rhs); tmp.make_unique (); // probably a no-op. @@ -288,60 +288,60 @@ // optimization: ignore the copy still stored inside our array. tmp.make_unique (1); - if (! error_state) - t_rhs = tmp.subsasgn (next_type, next_idx, rhs); - } + if (! error_state) + t_rhs = tmp.subsasgn (next_type, next_idx, rhs); + } else gripe_indexed_cs_list (); - } - } - break; + } + } + break; - case '.': - { - std::string nm = type_name (); - error ("%s cannot be indexed with %c", nm.c_str (), type[0]); - } - break; + case '.': + { + std::string nm = type_name (); + error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + } + break; - default: - panic_impossible (); - } + default: + panic_impossible (); + } } if (! error_state) { switch (type[0]) - { - case '(': - { - octave_value_list i = idx.front (); + { + case '(': + { + octave_value_list i = idx.front (); - if (t_rhs.is_cell ()) - octave_base_matrix::assign (i, t_rhs.cell_value ()); - else - if (t_rhs.is_null_value ()) - octave_base_matrix::delete_elements (i); - else - octave_base_matrix::assign (i, Cell (t_rhs)); + if (t_rhs.is_cell ()) + octave_base_matrix::assign (i, t_rhs.cell_value ()); + else + if (t_rhs.is_null_value ()) + octave_base_matrix::delete_elements (i); + else + octave_base_matrix::assign (i, Cell (t_rhs)); - if (! error_state) - { - count++; - retval = octave_value (this); - } - else - gripe_failed_assignment (); - } - break; + if (! error_state) + { + count++; + retval = octave_value (this); + } + else + gripe_failed_assignment (); + } + break; - case '{': - { - octave_value_list idxf = idx.front (); + case '{': + { + octave_value_list idxf = idx.front (); - if (t_rhs.is_cs_list ()) - { - Cell tmp_cell = Cell (t_rhs.list_value ()); + if (t_rhs.is_cs_list ()) + { + Cell tmp_cell = Cell (t_rhs.list_value ()); // Inquire the proper shape of the RHS. @@ -353,34 +353,34 @@ tmp_cell = tmp_cell.reshape (didx); - octave_base_matrix::assign (idxf, tmp_cell); - } - else if (idxf.all_scalars () || do_index_op (idxf, true).numel () == 1) + octave_base_matrix::assign (idxf, tmp_cell); + } + else if (idxf.all_scalars () || do_index_op (idxf, true).numel () == 1) // Regularize a null matrix if stored into a cell. octave_base_matrix::assign (idxf, Cell (t_rhs.storable_value ())); else if (! error_state) gripe_nonbraced_cs_list_assignment (); - if (! error_state) - { - count++; - retval = octave_value (this); - } - else - gripe_failed_assignment (); - } - break; + if (! error_state) + { + count++; + retval = octave_value (this); + } + else + gripe_failed_assignment (); + } + break; - case '.': - { - std::string nm = type_name (); - error ("%s cannot be indexed with %c", nm.c_str (), type[0]); - } - break; + case '.': + { + std::string nm = type_name (); + error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + } + break; - default: - panic_impossible (); - } + default: + panic_impossible (); + } } return retval; @@ -458,7 +458,7 @@ octave_value octave_cell::sort (Array &sidx, octave_idx_type dim, - sortmode mode) const + sortmode mode) const { octave_value retval; @@ -560,7 +560,7 @@ string_vector s = matrix(i).all_strings (); if (error_state) - return retval; + return retval; octave_idx_type s_len = s.length (); @@ -569,7 +569,7 @@ octave_idx_type s_max_len = s.max_length (); if (s_max_len > max_len) - max_len = s_max_len; + max_len = s_max_len; strvec_queue.push (s); } @@ -586,22 +586,22 @@ octave_idx_type s_len = s.length (); if (s_len) - { - for (octave_idx_type j = 0; j < s_len; j++) - { - std::string t = s[j]; - int t_len = t.length (); + { + for (octave_idx_type j = 0; j < s_len; j++) + { + std::string t = s[j]; + int t_len = t.length (); - if (pad && max_len > t_len) - t += std::string (max_len - t_len, ' '); + if (pad && max_len > t_len) + t += std::string (max_len - t_len, ' '); - retval[k++] = t; - } - } + retval[k++] = t; + } + } else if (pad) - retval[k++] = std::string (max_len, ' '); + retval[k++] = std::string (max_len, ' '); else - retval[k++] = std::string (); + retval[k++] = std::string (); } return retval; @@ -648,42 +648,42 @@ octave_idx_type nc = columns (); if (nr > 0 && nc > 0) - { - indent (os); - os << "{"; - newline (os); + { + indent (os); + os << "{"; + newline (os); - increment_indent_level (); + increment_indent_level (); - for (octave_idx_type j = 0; j < nc; j++) - { - for (octave_idx_type i = 0; i < nr; i++) - { - octave_quit (); + for (octave_idx_type j = 0; j < nc; j++) + { + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); - std::ostringstream buf; - buf << "[" << i+1 << "," << j+1 << "]"; + std::ostringstream buf; + buf << "[" << i+1 << "," << j+1 << "]"; - octave_value val = matrix(i,j); + octave_value val = matrix(i,j); - val.print_with_name (os, buf.str ()); - } - } + val.print_with_name (os, buf.str ()); + } + } - decrement_indent_level (); + decrement_indent_level (); - indent (os); - os << "}"; - newline (os); - } + indent (os); + os << "}"; + newline (os); + } else - { + { indent (os); - os << "{}"; - if (Vprint_empty_dimensions) - os << "(" << nr << "x" << nc << ")"; + os << "{}"; + if (Vprint_empty_dimensions) + os << "(" << nr << "x" << nc << ")"; newline (os); - } + } } else { @@ -705,46 +705,46 @@ os << "# ndims: " << d.length () << "\n"; for (int i = 0; i < d.length (); i++) - os << " " << d (i); + os << " " << d (i); os << "\n"; Cell tmp = cell_value (); for (octave_idx_type i = 0; i < d.numel (); i++) - { - octave_value o_val = tmp.elem (i); + { + octave_value o_val = tmp.elem (i); - // Recurse to print sub-value. - bool b = save_ascii_data (os, o_val, CELL_ELT_TAG, false, 0); - - if (! b) - return os; - } + // Recurse to print sub-value. + bool b = save_ascii_data (os, o_val, CELL_ELT_TAG, false, 0); + + if (! b) + return os; + } } else { // Keep this case, rather than use generic code above for backward // compatiability. Makes load_ascii much more complex!! os << "# rows: " << rows () << "\n" - << "# columns: " << columns () << "\n"; + << "# columns: " << columns () << "\n"; Cell tmp = cell_value (); for (octave_idx_type j = 0; j < tmp.cols (); j++) - { - for (octave_idx_type i = 0; i < tmp.rows (); i++) - { - octave_value o_val = tmp.elem (i, j); + { + for (octave_idx_type i = 0; i < tmp.rows (); i++) + { + octave_value o_val = tmp.elem (i, j); - // Recurse to print sub-value. - bool b = save_ascii_data (os, o_val, CELL_ELT_TAG, false, 0); - - if (! b) - return os; - } - - os << "\n"; - } + // Recurse to print sub-value. + bool b = save_ascii_data (os, o_val, CELL_ELT_TAG, false, 0); + + if (! b) + return os; + } + + os << "\n"; + } } return true; @@ -768,114 +768,114 @@ if (extract_keyword (is, keywords, kw, val, true)) { if (kw == "ndims") - { - int mdims = static_cast (val); + { + int mdims = static_cast (val); - if (mdims >= 0) - { - dim_vector dv; - dv.resize (mdims); + if (mdims >= 0) + { + dim_vector dv; + dv.resize (mdims); - for (int i = 0; i < mdims; i++) - is >> dv(i); + for (int i = 0; i < mdims; i++) + is >> dv(i); - Cell tmp(dv); + Cell tmp(dv); - for (octave_idx_type i = 0; i < dv.numel (); i++) - { - octave_value t2; - bool dummy; + for (octave_idx_type i = 0; i < dv.numel (); i++) + { + octave_value t2; + bool dummy; - // recurse to read cell elements - std::string nm = read_ascii_data (is, std::string (), - dummy, t2, i); + // recurse to read cell elements + std::string nm = read_ascii_data (is, std::string (), + dummy, t2, i); - if (nm == CELL_ELT_TAG) - { - if (is) - tmp.elem (i) = t2; - } - else - { - error ("load: cell array element had unexpected name"); - success = false; - break; - } - } + if (nm == CELL_ELT_TAG) + { + if (is) + tmp.elem (i) = t2; + } + else + { + error ("load: cell array element had unexpected name"); + success = false; + break; + } + } - if (is) - matrix = tmp; - else - { - error ("load: failed to load matrix constant"); - success = false; - } - } - else - { - error ("load: failed to extract number of rows and columns"); - success = false; - } - } + if (is) + matrix = tmp; + else + { + error ("load: failed to load matrix constant"); + success = false; + } + } + else + { + error ("load: failed to extract number of rows and columns"); + success = false; + } + } else if (kw == "rows") - { - octave_idx_type nr = val; - octave_idx_type nc = 0; + { + octave_idx_type nr = val; + octave_idx_type nc = 0; - if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0) - { - if (nr > 0 && nc > 0) - { - Cell tmp (nr, nc); + if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0) + { + if (nr > 0 && nc > 0) + { + Cell tmp (nr, nc); - for (octave_idx_type j = 0; j < nc; j++) - { - for (octave_idx_type i = 0; i < nr; i++) - { - octave_value t2; - bool dummy; + for (octave_idx_type j = 0; j < nc; j++) + { + for (octave_idx_type i = 0; i < nr; i++) + { + octave_value t2; + bool dummy; - // recurse to read cell elements - std::string nm = read_ascii_data (is, std::string (), - dummy, t2, i); + // recurse to read cell elements + std::string nm = read_ascii_data (is, std::string (), + dummy, t2, i); - if (nm == CELL_ELT_TAG) - { - if (is) - tmp.elem (i, j) = t2; - } - else - { - error ("load: cell array element had unexpected name"); - success = false; - goto cell_read_error; - } - } - } - - cell_read_error: + if (nm == CELL_ELT_TAG) + { + if (is) + tmp.elem (i, j) = t2; + } + else + { + error ("load: cell array element had unexpected name"); + success = false; + goto cell_read_error; + } + } + } + + cell_read_error: - if (is) - matrix = tmp; - else - { - error ("load: failed to load cell element"); - success = false; - } - } - else if (nr == 0 || nc == 0) - matrix = Cell (nr, nc); - else - panic_impossible (); - } - else - { - error ("load: failed to extract number of rows and columns for cell array"); - success = false; - } - } + if (is) + matrix = tmp; + else + { + error ("load: failed to load cell element"); + success = false; + } + } + else if (nr == 0 || nc == 0) + matrix = Cell (nr, nc); + else + panic_impossible (); + } + else + { + error ("load: failed to extract number of rows and columns for cell array"); + success = false; + } + } else - panic_impossible (); + panic_impossible (); } else { @@ -910,10 +910,10 @@ // Recurse to print sub-value. bool b = save_binary_data (os, o_val, CELL_ELT_TAG, "", 0, - save_as_floats); - + save_as_floats); + if (! b) - return false; + return false; } return true; @@ -942,9 +942,9 @@ for (int i = 0; i < mdims; i++) { if (! is.read (reinterpret_cast (&di), 4)) - return false; + return false; if (swap) - swap_bytes<4> (&di); + swap_bytes<4> (&di); dv(i) = di; } @@ -971,19 +971,19 @@ // recurse to read cell elements std::string nm = read_binary_data (is, swap, fmt, std::string (), - dummy, t2, doc); + dummy, t2, doc); if (nm == CELL_ELT_TAG) - { - if (is) - tmp.elem (i) = t2; - } + { + if (is) + tmp.elem (i) = t2; + } else - { - error ("load: cell array element had unexpected name"); - success = false; - break; - } + { + error ("load: cell array element had unexpected name"); + success = false; + break; + } } if (is) @@ -1045,10 +1045,10 @@ #if HAVE_HDF5_18 size_hid = H5Dcreate (data_hid, "dims", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else size_hid = H5Dcreate (data_hid, "dims", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (size_hid < 0) { @@ -1058,7 +1058,7 @@ } if (H5Dwrite (size_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, - H5P_DEFAULT, hdims) < 0) + H5P_DEFAULT, hdims) < 0) { H5Dclose (size_hid); H5Sclose (space_hid); @@ -1083,11 +1083,11 @@ std::string s = buf.str (); if (! add_hdf5_data (data_hid, tmp.elem (i), s.c_str (), "", false, - save_as_floats)) - { - H5Gclose (data_hid); - return false; - } + save_as_floats)) + { + H5Gclose (data_hid); + return false; + } } H5Gclose (data_hid); @@ -1144,7 +1144,7 @@ OCTAVE_LOCAL_BUFFER (octave_idx_type, tmp, hdims[0]); if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, - H5P_DEFAULT, tmp) < 0) + H5P_DEFAULT, tmp) < 0) { H5Dclose (data_hid); H5Gclose (group_id); @@ -1178,13 +1178,13 @@ { if (current_item >= static_cast (num_obj)) - retval2 = -1; + retval2 = -1; else - retval2 = H5Giterate (loc_id, name, ¤t_item, - hdf5_read_next_data, &dsub); + retval2 = H5Giterate (loc_id, name, ¤t_item, + hdf5_read_next_data, &dsub); if (retval2 <= 0) - break; + break; octave_value ov = dsub.tc; m.elem (i) = ov; @@ -1249,18 +1249,18 @@ default: { - dims.resize (nargin); + dims.resize (nargin); - for (int i = 0; i < nargin; i++) - { - dims(i) = args(i).is_empty () ? 0 : args(i).nint_value (); + for (int i = 0; i < nargin; i++) + { + dims(i) = args(i).is_empty () ? 0 : args(i).nint_value (); - if (error_state) - { - error ("cell: expecting scalar arguments"); - break; - } - } + if (error_state) + { + error ("cell: expecting scalar arguments"); + break; + } + } } break; } @@ -1314,18 +1314,18 @@ octave_value_list tmp = Fiscellstr (args, 1); if (tmp(0).is_true ()) - retval = args(0); + retval = args(0); else - { - string_vector s = args(0).all_strings (); + { + string_vector s = args(0).all_strings (); - if (! error_state) - retval = (s.is_empty () + if (! error_state) + retval = (s.is_empty () ? Cell (octave_value (std::string ())) : Cell (s, true)); - else - error ("cellstr: expecting argument to be a 2-d character array"); - } + else + error ("cellstr: expecting argument to be a 2-d character array"); + } } else print_usage (); @@ -1375,49 +1375,49 @@ Octave_map m = args(0).map_value (); if (! error_state) - { - dim_vector m_dv = m.dims (); + { + dim_vector m_dv = m.dims (); - string_vector keys = m.keys (); + string_vector keys = m.keys (); - octave_idx_type num_fields = keys.length (); + octave_idx_type num_fields = keys.length (); - // The resulting dim_vector should have dimensions: - // [numel(fields) size(struct)] - // except if the struct is a column vector. + // The resulting dim_vector should have dimensions: + // [numel(fields) size(struct)] + // except if the struct is a column vector. - dim_vector result_dv; - if (m_dv (m_dv.length () - 1) == 1) - result_dv.resize (m_dv.length ()); - else - result_dv.resize (m_dv.length () + 1); // Add 1 for the fields. + dim_vector result_dv; + if (m_dv (m_dv.length () - 1) == 1) + result_dv.resize (m_dv.length ()); + else + result_dv.resize (m_dv.length () + 1); // Add 1 for the fields. - result_dv(0) = num_fields; + result_dv(0) = num_fields; - for (int i = 1; i < result_dv.length (); i++) - result_dv(i) = m_dv(i-1); + for (int i = 1; i < result_dv.length (); i++) + result_dv(i) = m_dv(i-1); - Cell c (result_dv); + Cell c (result_dv); - octave_idx_type n_elts = m.numel (); + octave_idx_type n_elts = m.numel (); - for (octave_idx_type j = 0; j < num_fields; j++) - { - octave_idx_type k = j; + for (octave_idx_type j = 0; j < num_fields; j++) + { + octave_idx_type k = j; - const Cell vals = m.contents (keys(j)); + const Cell vals = m.contents (keys(j)); - for (octave_idx_type i = 0; i < n_elts; i++) - { - c(k) = vals(i); - k += num_fields; - } - } + for (octave_idx_type i = 0; i < n_elts; i++) + { + c(k) = vals(i); + k += num_fields; + } + } - retval = c; - } + retval = c; + } else - error ("struct2cell: expecting argument to be a cell array"); + error ("struct2cell: expecting argument to be a cell array"); } else print_usage (); diff --git a/src/ov-ch-mat.cc b/src/ov-ch-mat.cc --- a/src/ov-ch-mat.cc +++ b/src/ov-ch-mat.cc @@ -58,7 +58,7 @@ if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "character matrix", "real scalar"); + "character matrix", "real scalar"); retval = static_cast (matrix (0, 0)); } @@ -76,7 +76,7 @@ if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "character matrix", "real scalar"); + "character matrix", "real scalar"); retval = static_cast (matrix (0, 0)); } @@ -96,7 +96,7 @@ if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "character matrix", "complex scalar"); + "character matrix", "complex scalar"); retval = static_cast (matrix (0, 0)); } @@ -116,7 +116,7 @@ if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "character matrix", "complex scalar"); + "character matrix", "complex scalar"); retval = static_cast (matrix (0, 0)); } @@ -128,10 +128,10 @@ void octave_char_matrix::print_raw (std::ostream& os, - bool pr_as_read_syntax) const + bool pr_as_read_syntax) const { octave_print_internal (os, matrix, pr_as_read_syntax, - current_print_indent_level ()); + current_print_indent_level ()); } mxArray * diff --git a/src/ov-class.cc b/src/ov-class.cc --- a/src/ov-class.cc +++ b/src/ov-class.cc @@ -67,7 +67,7 @@ } octave_class::octave_class (const Octave_map& m, const std::string& id, - const octave_value_list& parents) + const octave_value_list& parents) : octave_base_value (), map (m), c_name (id), obsolete_copies (0) { octave_idx_type n = parents.length (); @@ -77,20 +77,20 @@ octave_value parent = parents(idx); if (! parent.is_object ()) - error ("parents must be objects"); + error ("parents must be objects"); else - { - std::string cnm = parent.class_name (); + { + std::string cnm = parent.class_name (); - if (find_parent_class (cnm)) - error ("duplicate class in parent tree"); - else - { - parent_list.push_back (cnm); + if (find_parent_class (cnm)) + error ("duplicate class in parent tree"); + else + { + parent_list.push_back (cnm); - map.assign (cnm, parent); - } - } + map.assign (cnm, parent); + } + } } if (! error_state) @@ -161,7 +161,7 @@ for (octave_idx_type i = 0; i < ovl.length (); i++) { if (retval(i).is_magic_colon ()) - retval(i) = ":"; + retval(i) = ":"; } return retval; @@ -169,8 +169,8 @@ static inline octave_value make_idx_args (const std::string& type, - const std::list& idx, - const std::string& who) + const std::list& idx, + const std::string& who) { octave_value retval; @@ -184,52 +184,52 @@ std::list::const_iterator p = idx.begin (); for (size_t i = 0; i < len; i++) - { - char t = type[i]; + { + char t = type[i]; - switch (t) - { - case '(': - type_field(i) = "()"; - subs_field(i) = Cell (sanitize (*p++)); - break; + switch (t) + { + case '(': + type_field(i) = "()"; + subs_field(i) = Cell (sanitize (*p++)); + break; - case '{': - type_field(i) = "{}"; - subs_field(i) = Cell (sanitize (*p++)); - break; + case '{': + type_field(i) = "{}"; + subs_field(i) = Cell (sanitize (*p++)); + break; - case '.': - { - type_field(i) = "."; + case '.': + { + type_field(i) = "."; - octave_value_list vlist = *p++; + octave_value_list vlist = *p++; - if (vlist.length () == 1) - { - octave_value val = vlist(0); + if (vlist.length () == 1) + { + octave_value val = vlist(0); - if (val.is_string ()) - subs_field(i) = val; - else - { - error ("expecting character string argument for `.' index"); - return retval; - } - } - else - { - error ("expecting single argument for `.' index"); - return retval; - } - } - break; + if (val.is_string ()) + subs_field(i) = val; + else + { + error ("expecting character string argument for `.' index"); + return retval; + } + } + else + { + error ("expecting single argument for `.' index"); + return retval; + } + } + break; - default: - panic_impossible (); - break; - } - } + default: + panic_impossible (); + break; + } + } Octave_map m; @@ -270,9 +270,9 @@ Octave_map::const_iterator p = my_map.seek (nm); if (p != my_map.end ()) - retval = my_map.contents (p); + retval = my_map.contents (p); else - error ("class has no member `%s'", nm.c_str ()); + error ("class has no member `%s'", nm.c_str ()); } else gripe_invalid_index (); @@ -353,8 +353,8 @@ octave_value_list octave_class::subsref (const std::string& type, - const std::list& idx, - int nargout) + const std::list& idx, + int nargout) { octave_value_list retval; @@ -367,75 +367,75 @@ int skip = 1; switch (type[0]) - { - case '(': - { - if (type.length () > 1 && type[1] == '.') - { - std::list::const_iterator p = idx.begin (); - octave_value_list key_idx = *++p; + { + case '(': + { + if (type.length () > 1 && type[1] == '.') + { + std::list::const_iterator p = idx.begin (); + octave_value_list key_idx = *++p; - Cell tmp = dotref (key_idx); + Cell tmp = dotref (key_idx); - if (! error_state) - { - Cell t = tmp.index (idx.front ()); + if (! error_state) + { + Cell t = tmp.index (idx.front ()); - retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); + retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); - // We handled two index elements, so tell - // next_subsref to skip both of them. + // We handled two index elements, so tell + // next_subsref to skip both of them. - skip++; - } - } - else - retval(0) = octave_value (map.index (idx.front ()), - class_name ()); - } - break; + skip++; + } + } + else + retval(0) = octave_value (map.index (idx.front ()), + class_name ()); + } + break; - case '.': - { - if (map.numel() > 0) - { - Cell t = dotref (idx.front ()); + case '.': + { + if (map.numel() > 0) + { + Cell t = dotref (idx.front ()); - retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); - } - } - break; + retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); + } + } + break; - case '{': - gripe_invalid_index_type (type_name (), type[0]); - break; + case '{': + gripe_invalid_index_type (type_name (), type[0]); + break; - default: - panic_impossible (); - } + default: + panic_impossible (); + } // FIXME -- perhaps there should be an // octave_value_list::next_subsref member function? See also // octave_user_function::subsref. if (idx.size () > 1) - retval = retval(0).next_subsref (nargout, type, idx, skip); + retval = retval(0).next_subsref (nargout, type, idx, skip); } else { octave_value meth = symbol_table::find_method ("subsref", class_name ()); if (meth.is_defined ()) - { - octave_value_list args; + { + octave_value_list args; - args(1) = make_idx_args (type, idx, "subsref"); + args(1) = make_idx_args (type, idx, "subsref"); - if (error_state) - return octave_value_list (); + if (error_state) + return octave_value_list (); - count++; - args(0) = octave_value (this); + count++; + args(0) = octave_value (this); // FIXME: for Matlab compatibility, let us attempt to set up a proper // value for nargout at least in the simple case where the @@ -463,14 +463,14 @@ // rvalue1 calls. if (retval.length () > 1) retval = octave_value (retval, true); - } + } else - { - if (type.length () == 1 && type[0] == '(') - retval(0) = octave_value (map.index (idx.front ()), class_name ()); - else - gripe_invalid_index (); - } + { + if (type.length () == 1 && type[0] == '(') + retval(0) = octave_value (map.index (idx.front ()), class_name ()); + else + gripe_invalid_index (); + } } return retval; @@ -486,7 +486,7 @@ retval = val(0); if (type.length () > 0 && type[0] == '.' && ! retval.is_map ()) - retval = Octave_map (); + retval = Octave_map (); } else gripe_invalid_index_for_assignment (); @@ -496,8 +496,8 @@ octave_value octave_class::subsasgn (const std::string& type, - const std::list& idx, - const octave_value& rhs) + const std::list& idx, + const octave_value& rhs) { octave_value retval; @@ -506,8 +506,8 @@ octave_value meth = symbol_table::find_method ("subsasgn", class_name ()); if (meth.is_defined ()) - { - octave_value_list args; + { + octave_value_list args; if (rhs.is_cs_list ()) { @@ -519,13 +519,13 @@ else args(2) = rhs; - args(1) = make_idx_args (type, idx, "subsasgn"); + args(1) = make_idx_args (type, idx, "subsasgn"); - if (error_state) - return octave_value_list (); + if (error_state) + return octave_value_list (); - count++; - args(0) = octave_value (this); + count++; + args(0) = octave_value (this); // Now comes the magic. Count copies with me: // 1. myself (obsolete) @@ -554,18 +554,18 @@ else tmp = feval (meth.function_value (), args); - // FIXME -- should the subsasgn method be able to return - // more than one value? + // FIXME -- should the subsasgn method be able to return + // more than one value? - if (tmp.length () > 1) - error ("expecting single return value from @%s/subsasgn", - class_name().c_str ()); + if (tmp.length () > 1) + error ("expecting single return value from @%s/subsasgn", + class_name().c_str ()); - else - retval = tmp(0); + else + retval = tmp(0); - return retval; - } + return retval; + } } // FIXME -- this block of code is the same as the body of @@ -579,65 +579,65 @@ if (n > 1 && ! (type.length () == 2 && type[0] == '(' && type[1] == '.')) { switch (type[0]) - { - case '(': - { - if (type.length () > 1 && type[1] == '.') - { - std::list::const_iterator p = idx.begin (); - octave_value_list t_idx = *p; + { + case '(': + { + if (type.length () > 1 && type[1] == '.') + { + std::list::const_iterator p = idx.begin (); + octave_value_list t_idx = *p; - octave_value_list key_idx = *++p; + octave_value_list key_idx = *++p; - assert (key_idx.length () == 1); + assert (key_idx.length () == 1); - std::string key = key_idx(0).string_value (); + std::string key = key_idx(0).string_value (); - if (! error_state) - { - octave_value u; + if (! error_state) + { + octave_value u; - if (! map.contains (key)) - u = octave_value::empty_conv (type.substr (2), rhs); - else - { - Cell map_val = map.contents (key); + if (! map.contains (key)) + u = octave_value::empty_conv (type.substr (2), rhs); + else + { + Cell map_val = map.contents (key); - Cell map_elt = map_val.index (idx.front (), true); + Cell map_elt = map_val.index (idx.front (), true); - u = numeric_conv (map_elt, type.substr (2)); - } + u = numeric_conv (map_elt, type.substr (2)); + } - if (! error_state) - { - std::list next_idx (idx); + if (! error_state) + { + std::list next_idx (idx); - // We handled two index elements, so subsasgn to - // needs to skip both of them. + // We handled two index elements, so subsasgn to + // needs to skip both of them. - next_idx.erase (next_idx.begin ()); - next_idx.erase (next_idx.begin ()); + next_idx.erase (next_idx.begin ()); + next_idx.erase (next_idx.begin ()); - u.make_unique (); + u.make_unique (); - t_rhs = u.subsasgn (type.substr (2), next_idx, rhs); - } - } - else - gripe_invalid_index_for_assignment (); - } - else - gripe_invalid_index_for_assignment (); - } - break; + t_rhs = u.subsasgn (type.substr (2), next_idx, rhs); + } + } + else + gripe_invalid_index_for_assignment (); + } + else + gripe_invalid_index_for_assignment (); + } + break; - case '.': - { - octave_value_list key_idx = idx.front (); + case '.': + { + octave_value_list key_idx = idx.front (); - assert (key_idx.length () == 1); + assert (key_idx.length () == 1); - std::string key = key_idx(0).string_value (); + std::string key = key_idx(0).string_value (); std::list next_idx (idx); @@ -675,134 +675,134 @@ else gripe_indexed_cs_list (); } - } - break; + } + break; - case '{': - gripe_invalid_index_type (type_name (), type[0]); - break; + case '{': + gripe_invalid_index_type (type_name (), type[0]); + break; - default: - panic_impossible (); - } + default: + panic_impossible (); + } } if (! error_state) { switch (type[0]) - { - case '(': - { - if (n > 1 && type[1] == '.') - { - std::list::const_iterator p = idx.begin (); - octave_value_list key_idx = *++p; + { + case '(': + { + if (n > 1 && type[1] == '.') + { + std::list::const_iterator p = idx.begin (); + octave_value_list key_idx = *++p; - assert (key_idx.length () == 1); + assert (key_idx.length () == 1); - std::string key = key_idx(0).string_value (); + std::string key = key_idx(0).string_value (); - if (! error_state) - { - map.assign (idx.front (), key, t_rhs); + if (! error_state) + { + map.assign (idx.front (), key, t_rhs); - if (! error_state) - { - count++; - retval = octave_value (this); - } - else - gripe_failed_assignment (); - } - else - gripe_failed_assignment (); - } - else - { - if (t_rhs.is_object () || t_rhs.is_map ()) - { - Octave_map rhs_map = t_rhs.map_value (); + if (! error_state) + { + count++; + retval = octave_value (this); + } + else + gripe_failed_assignment (); + } + else + gripe_failed_assignment (); + } + else + { + if (t_rhs.is_object () || t_rhs.is_map ()) + { + Octave_map rhs_map = t_rhs.map_value (); - if (! error_state) - { - map.assign (idx.front (), rhs_map); + if (! error_state) + { + map.assign (idx.front (), rhs_map); - if (! error_state) - { - count++; - retval = octave_value (this); - } - else - gripe_failed_assignment (); - } - else - error ("invalid class assignment"); - } - else - { - if (t_rhs.is_empty ()) - { - map.maybe_delete_elements (idx.front()); + if (! error_state) + { + count++; + retval = octave_value (this); + } + else + gripe_failed_assignment (); + } + else + error ("invalid class assignment"); + } + else + { + if (t_rhs.is_empty ()) + { + map.maybe_delete_elements (idx.front()); - if (! error_state) - { - count++; - retval = octave_value (this); - } - else - gripe_failed_assignment (); - } - else - error ("invalid class assignment"); - } - } - } - break; + if (! error_state) + { + count++; + retval = octave_value (this); + } + else + gripe_failed_assignment (); + } + else + error ("invalid class assignment"); + } + } + } + break; - case '.': - { - // Find the class in which this method resides before - // attempting to access the requested field. + case '.': + { + // Find the class in which this method resides before + // attempting to access the requested field. - std::string method_class = get_current_method_class (); + std::string method_class = get_current_method_class (); - octave_base_value *obvp = unique_parent_class (method_class); + octave_base_value *obvp = unique_parent_class (method_class); - if (obvp) - { - octave_value_list key_idx = idx.front (); + if (obvp) + { + octave_value_list key_idx = idx.front (); - assert (key_idx.length () == 1); + assert (key_idx.length () == 1); - std::string key = key_idx(0).string_value (); + std::string key = key_idx(0).string_value (); - if (! error_state) - { - obvp->assign (key, t_rhs); + if (! error_state) + { + obvp->assign (key, t_rhs); - if (! error_state) - { - count++; - retval = octave_value (this); - } - else - gripe_failed_assignment (); - } - else - gripe_failed_assignment (); - } - else - error ("malformed class"); - } - break; + if (! error_state) + { + count++; + retval = octave_value (this); + } + else + gripe_failed_assignment (); + } + else + gripe_failed_assignment (); + } + else + error ("malformed class"); + } + break; - case '{': - gripe_invalid_index_type (type_name (), type[0]); - break; + case '{': + gripe_invalid_index_type (type_name (), type[0]); + break; - default: - panic_impossible (); - } + default: + panic_impossible (); + } } else gripe_failed_assignment (); @@ -825,21 +825,21 @@ octave_value_list tmp = feval (meth.function_value (), args, 1); if (!error_state && tmp.length () >= 1) - { - if (tmp(0).is_object()) - error ("subsindex function must return a valid index vector"); - else - // Index vector returned by subsindex is zero based - // (why this inconsistency Mathworks?), and so we must - // add one to the value returned as the index_vector method - // expects it to be one based. - retval = do_binary_op (octave_value::op_add, tmp (0), - octave_value (1.0)).index_vector (); - } + { + if (tmp(0).is_object()) + error ("subsindex function must return a valid index vector"); + else + // Index vector returned by subsindex is zero based + // (why this inconsistency Mathworks?), and so we must + // add one to the value returned as the index_vector method + // expects it to be one based. + retval = do_binary_op (octave_value::op_add, tmp (0), + octave_value (1.0)).index_vector (); + } } else error ("no subsindex method defined for class %s", - class_name().c_str ()); + class_name().c_str ()); return retval; } @@ -881,22 +881,22 @@ else { for (std::list::iterator pit = parent_list.begin (); - pit != parent_list.end (); - pit++) - { - Octave_map::const_iterator smap = map.seek (*pit); + pit != parent_list.end (); + pit++) + { + Octave_map::const_iterator smap = map.seek (*pit); - const Cell& tmp = smap->second; + const Cell& tmp = smap->second; - octave_value vtmp = tmp(0); + octave_value vtmp = tmp(0); - octave_base_value *obvp = vtmp.internal_rep (); + octave_base_value *obvp = vtmp.internal_rep (); - retval = obvp->find_parent_class (parent_class_name); + retval = obvp->find_parent_class (parent_class_name); - if (retval) - break; - } + if (retval) + break; + } } return retval; @@ -912,21 +912,21 @@ else { for (std::list::iterator pit = parent_list.begin (); - pit != parent_list.end (); - pit++) - { - Octave_map::iterator smap = map.seek (*pit); + pit != parent_list.end (); + pit++) + { + Octave_map::iterator smap = map.seek (*pit); - Cell& tmp = smap->second; + Cell& tmp = smap->second; - octave_value& vtmp = tmp(0); + octave_value& vtmp = tmp(0); - octave_base_value *obvp = vtmp.internal_rep (); + octave_base_value *obvp = vtmp.internal_rep (); // Use find_parent_class first to avoid uniquifying if not necessary. - retval = obvp->find_parent_class (parent_class_name); + retval = obvp->find_parent_class (parent_class_name); - if (retval) + if (retval) { vtmp.make_unique (); obvp = vtmp.internal_rep (); @@ -934,7 +934,7 @@ break; } - } + } } return retval; @@ -973,7 +973,7 @@ void octave_class::print_with_name (std::ostream& os, const std::string& name, - bool) + bool) { octave_value fcn = symbol_table::find_method ("display", class_name ()); @@ -1018,16 +1018,16 @@ octave_value ctor = symbol_table::find_method (c_name, c_name); if (ctor.is_defined ()) - { - octave_value_list result = feval (ctor, 1); + { + octave_value_list result = feval (ctor, 1); - if (result.length () == 1) - retval = true; - else - warning ("call to constructor for class %s failed", c_name.c_str ()); - } + if (result.length () == 1) + retval = true; + else + warning ("call to constructor for class %s failed", c_name.c_str ()); + } else - warning ("no constructor for class %s", c_name.c_str ()); + warning ("no constructor for class %s", c_name.c_str ()); } return retval; @@ -1058,41 +1058,41 @@ std::string key = map.key (p); Cell val = map.contents (p); if ( val(0).is_object() ) - { - dbgstr = "blork"; - if( key == val(0).class_name() ) - { - might_have_inheritance = true; - dbgstr = "cork"; - break; - } - } + { + dbgstr = "blork"; + if( key == val(0).class_name() ) + { + might_have_inheritance = true; + dbgstr = "cork"; + break; + } + } } if (might_have_inheritance) { octave_class::exemplar_const_iterator it - = octave_class::exemplar_map.find (c_name); + = octave_class::exemplar_map.find (c_name); if (it == octave_class::exemplar_map.end ()) - retval = false; + retval = false; else - { - octave_class::exemplar_info exmplr = it->second; - parent_list = exmplr.parents (); - for (std::list::iterator pit = parent_list.begin (); - pit != parent_list.end (); - pit++) - { - dbgstr = *pit; - bool dbgbool = map.contains (*pit); - if (!dbgbool) - { - retval = false; - break; - } - } - } + { + octave_class::exemplar_info exmplr = it->second; + parent_list = exmplr.parents (); + for (std::list::iterator pit = parent_list.begin (); + pit != parent_list.end (); + pit++) + { + dbgstr = *pit; + bool dbgbool = map.contains (*pit); + if (!dbgbool) + { + retval = false; + break; + } + } + } } return retval; @@ -1108,9 +1108,9 @@ octave_value in = new octave_class (*this); octave_value_list tmp = feval ("saveobj", in, 1); if (! error_state) - m = tmp(0).map_value (); + m = tmp(0).map_value (); else - return false; + return false; } else m = map_value (); @@ -1125,7 +1125,7 @@ bool b = save_ascii_data (os, val, m.key (i), false, 0); if (! b) - return os; + return os; i++; } @@ -1143,77 +1143,77 @@ if (extract_keyword (is, "classname", classname) && classname != "") { if (extract_keyword (is, "length", len) && len >= 0) - { - if (len > 0) - { - Octave_map m (map); + { + if (len > 0) + { + Octave_map m (map); - for (octave_idx_type j = 0; j < len; j++) - { - octave_value t2; - bool dummy; + for (octave_idx_type j = 0; j < len; j++) + { + octave_value t2; + bool dummy; - // recurse to read cell elements - std::string nm - = read_ascii_data (is, std::string (), dummy, t2, j); + // recurse to read cell elements + std::string nm + = read_ascii_data (is, std::string (), dummy, t2, j); - if (! is) - break; + if (! is) + break; - Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); + Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); - if (error_state) - { - error ("load: internal error loading class elements"); - return false; - } + if (error_state) + { + error ("load: internal error loading class elements"); + return false; + } - m.assign (nm, tcell); - } + m.assign (nm, tcell); + } - if (is) - { - c_name = classname; - reconstruct_exemplar (); + if (is) + { + c_name = classname; + reconstruct_exemplar (); - map = m; - - if (! reconstruct_parents ()) - warning ("load: unable to reconstruct object inheritance"); - else - { - if (load_path::find_method (classname, "loadobj") - != std::string ()) - { - octave_value in = new octave_class (*this); - octave_value_list tmp = feval ("loadobj", in, 1); + map = m; + + if (! reconstruct_parents ()) + warning ("load: unable to reconstruct object inheritance"); + else + { + if (load_path::find_method (classname, "loadobj") + != std::string ()) + { + octave_value in = new octave_class (*this); + octave_value_list tmp = feval ("loadobj", in, 1); - if (! error_state) - map = tmp(0).map_value (); - else - success = false; - } - } - } - else - { - error ("load: failed to load class"); - success = false; - } - } - else if (len == 0 ) - { - map = Octave_map (dim_vector (1, 1)); - c_name = classname; - } - else - panic_impossible (); - } + if (! error_state) + map = tmp(0).map_value (); + else + success = false; + } + } + } + else + { + error ("load: failed to load class"); + success = false; + } + } + else if (len == 0 ) + { + map = Octave_map (dim_vector (1, 1)); + c_name = classname; + } + else + panic_impossible (); + } else - { - error ("load: failed to extract number of elements in class"); - success = false; - } + { + error ("load: failed to extract number of elements in class"); + success = false; + } } else { @@ -1238,9 +1238,9 @@ octave_value in = new octave_class (*this); octave_value_list tmp = feval ("saveobj", in, 1); if (! error_state) - m = tmp(0).map_value (); + m = tmp(0).map_value (); else - return false; + return false; } else m = map_value (); @@ -1256,7 +1256,7 @@ bool b = save_binary_data (os, val, m.key (i), "", 0, save_as_floats); if (! b) - return os; + return os; i++; } @@ -1266,7 +1266,7 @@ bool octave_class::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) + oct_mach_info::float_format fmt) { bool success = true; @@ -1298,54 +1298,54 @@ Octave_map m (map); for (octave_idx_type j = 0; j < len; j++) - { - octave_value t2; - bool dummy; - std::string doc; + { + octave_value t2; + bool dummy; + std::string doc; - // recurse to read cell elements - std::string nm = read_binary_data (is, swap, fmt, std::string (), - dummy, t2, doc); + // recurse to read cell elements + std::string nm = read_binary_data (is, swap, fmt, std::string (), + dummy, t2, doc); - if (! is) - break; + if (! is) + break; - Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); + Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); - if (error_state) - { - error ("load: internal error loading class elements"); - return false; - } + if (error_state) + { + error ("load: internal error loading class elements"); + return false; + } - m.assign (nm, tcell); - } + m.assign (nm, tcell); + } if (is) - { - map = m; + { + map = m; - if (! reconstruct_parents ()) - warning ("load: unable to reconstruct object inheritance"); - else - { - if (load_path::find_method (c_name, "loadobj") != std::string ()) - { - octave_value in = new octave_class (*this); - octave_value_list tmp = feval ("loadobj", in, 1); + if (! reconstruct_parents ()) + warning ("load: unable to reconstruct object inheritance"); + else + { + if (load_path::find_method (c_name, "loadobj") != std::string ()) + { + octave_value in = new octave_class (*this); + octave_value_list tmp = feval ("loadobj", in, 1); - if (! error_state) - map = tmp(0).map_value (); - else - success = false; - } - } - } + if (! error_state) + map = tmp(0).map_value (); + else + success = false; + } + } + } else - { - warning ("load: failed to load class"); - success = false; - } + { + warning ("load: failed to load class"); + success = false; + } } else if (len == 0 ) map = Octave_map (dim_vector (1, 1)); @@ -1388,13 +1388,13 @@ goto error_cleanup; #if HAVE_HDF5_18 class_hid = H5Dcreate (group_hid, "classname", type_hid, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else class_hid = H5Dcreate (group_hid, "classname", type_hid, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (class_hid < 0 || H5Dwrite (class_hid, type_hid, H5S_ALL, H5S_ALL, - H5P_DEFAULT, c_name.c_str ()) < 0) + H5P_DEFAULT, c_name.c_str ()) < 0) goto error_cleanup; #if HAVE_HDF5_18 @@ -1410,9 +1410,9 @@ octave_value in = new octave_class (*this); octave_value_list tmp = feval ("saveobj", in, 1); if (! error_state) - m = tmp(0).map_value (); + m = tmp(0).map_value (); else - goto error_cleanup; + goto error_cleanup; } else m = map_value (); @@ -1424,10 +1424,10 @@ octave_value val = map.contents (i); bool retval2 = add_hdf5_data (data_hid, val, m.key (i), "", false, - save_as_floats); + save_as_floats); if (! retval2) - break; + break; i++; } @@ -1497,7 +1497,7 @@ if (type_class_hid != H5T_STRING) goto error_cleanup; - + space_hid = H5Dget_space (data_hid); rank = H5Sget_simple_extent_ndims (space_hid); @@ -1518,13 +1518,13 @@ H5Tset_size (st_id, slen); if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, - classname) < 0) - { - H5Tclose (st_id); - H5Dclose (data_hid); - H5Gclose (group_hid); - return false; - } + classname) < 0) + { + H5Tclose (st_id); + H5Dclose (data_hid); + H5Gclose (group_hid); + return false; + } H5Tclose (st_id); H5Dclose (data_hid); @@ -1544,18 +1544,18 @@ H5Gclose (subgroup_hid); while (current_item < static_cast (num_obj) - && (retval2 = H5Giterate (group_hid, name, ¤t_item, - hdf5_read_next_data, &dsub)) > 0) + && (retval2 = H5Giterate (group_hid, name, ¤t_item, + hdf5_read_next_data, &dsub)) > 0) { octave_value t2 = dsub.tc; Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); if (error_state) - { - error ("load: internal error loading class elements"); - return false; - } + { + error ("load: internal error loading class elements"); + return false; + } m.assign (dsub.name, tcell); @@ -1566,25 +1566,25 @@ map = m; if (!reconstruct_parents ()) - warning ("load: unable to reconstruct object inheritance"); + warning ("load: unable to reconstruct object inheritance"); else - { - if (load_path::find_method (c_name, "loadobj") != std::string ()) - { - octave_value in = new octave_class (*this); - octave_value_list tmp = feval ("loadobj", in, 1); + { + if (load_path::find_method (c_name, "loadobj") != std::string ()) + { + octave_value in = new octave_class (*this); + octave_value_list tmp = feval ("loadobj", in, 1); - if (! error_state) - { - map = tmp(0).map_value (); - retval = true; - } - else - retval = false; - } - else - retval = true; - } + if (! error_state) + { + map = tmp(0).map_value (); + retval = true; + } + else + retval = false; + } + else + retval = true; + } } error_cleanup: @@ -1613,10 +1613,10 @@ octave_function *fcn = octave_call_stack::current (); return (fcn - && (fcn->is_class_method () - || fcn->is_class_constructor () - || fcn->is_private_function_of_class (class_name ())) - && find_parent_class (fcn->dispatch_class ())); + && (fcn->is_class_method () + || fcn->is_class_constructor () + || fcn->is_private_function_of_class (class_name ())) + && find_parent_class (fcn->dispatch_class ())); } octave_class::exemplar_info::exemplar_info (const octave_value& obj) @@ -1645,51 +1645,51 @@ if (obj.is_object ()) { if (nfields () == obj.nfields ()) - { - Octave_map obj_map = obj.map_value (); - string_vector obj_fnames = obj_map.keys (); - string_vector fnames = fields (); + { + Octave_map obj_map = obj.map_value (); + string_vector obj_fnames = obj_map.keys (); + string_vector fnames = fields (); - for (octave_idx_type i = 0; i < nfields (); i++) - { - if (obj_fnames[i] != fnames[i]) - { - retval = false; - error ("mismatch in field names"); - break; - } - } + for (octave_idx_type i = 0; i < nfields (); i++) + { + if (obj_fnames[i] != fnames[i]) + { + retval = false; + error ("mismatch in field names"); + break; + } + } - if (nparents () == obj.nparents ()) - { - std::list obj_parents - = obj.parent_class_name_list (); - std::list pnames = parents (); + if (nparents () == obj.nparents ()) + { + std::list obj_parents + = obj.parent_class_name_list (); + std::list pnames = parents (); - std::list::const_iterator p = obj_parents.begin (); - std::list::const_iterator q = pnames.begin (); + std::list::const_iterator p = obj_parents.begin (); + std::list::const_iterator q = pnames.begin (); - while (p != obj_parents.end ()) - { - if (*p++ != *q++) - { - retval = false; - error ("mismatch in parent classes"); - break; - } - } - } - else - { - retval = false; - error ("mismatch in number of parent classes"); - } - } + while (p != obj_parents.end ()) + { + if (*p++ != *q++) + { + retval = false; + error ("mismatch in parent classes"); + break; + } + } + } + else + { + retval = false; + error ("mismatch in number of parent classes"); + } + } else - { - retval = false; - error ("mismatch in number of fields"); - } + { + retval = false; + error ("mismatch in number of fields"); + } } else { @@ -1733,33 +1733,33 @@ if (! error_state) { - if (nargin == 2) - retval = octave_value (new octave_class (m, id)); - else - { - octave_value_list parents = args.slice (2, nargin-2); + if (nargin == 2) + retval = octave_value (new octave_class (m, id)); + else + { + octave_value_list parents = args.slice (2, nargin-2); - retval = octave_value (new octave_class (m, id, parents)); - } + retval = octave_value (new octave_class (m, id, parents)); + } - if (! error_state) - { - octave_class::exemplar_const_iterator it - = octave_class::exemplar_map.find (id); + if (! error_state) + { + octave_class::exemplar_const_iterator it + = octave_class::exemplar_map.find (id); - if (it == octave_class::exemplar_map.end ()) - octave_class::exemplar_map[id] - = octave_class::exemplar_info (retval); - else if (! it->second.compare (retval)) - error ("class: object of class `%s' does not match previously constructed objects", id.c_str ()); - } + if (it == octave_class::exemplar_map.end ()) + octave_class::exemplar_map[id] + = octave_class::exemplar_info (retval); + else if (! it->second.compare (retval)) + error ("class: object of class `%s' does not match previously constructed objects", id.c_str ()); + } } - else + else error ("class: expecting character string as second argument"); - } - else + } + else error ("class: expecting structure as first argument"); - } + } else error ("class: invalid call from outside class constructor"); } @@ -1781,12 +1781,12 @@ octave_value nm = args(1); if (! error_state) - { - if (cls.find_parent_class (nm.string_value ())) - retval = true; - } + { + if (cls.find_parent_class (nm.string_value ())) + retval = true; + } else - error ("__isa_parent__: expecting arguments to be character strings"); + error ("__isa_parent__: expecting arguments to be character strings"); } else print_usage (); @@ -1807,7 +1807,7 @@ octave_value arg = args(0); if (arg.is_object ()) - retval = Cell (arg.parent_class_names ()); + retval = Cell (arg.parent_class_names ()); } else print_usage (); @@ -1847,24 +1847,24 @@ std::string class_name; if (arg.is_object ()) - class_name = arg.class_name (); + class_name = arg.class_name (); else if (arg.is_string ()) - class_name = arg.string_value (); + class_name = arg.string_value (); else - error ("ismethod: expecting object or class name as first argument"); + error ("ismethod: expecting object or class name as first argument"); if (! error_state) - { - std::string method = args(1).string_value (); + { + std::string method = args(1).string_value (); - if (! error_state) - { - if (load_path::find_method (class_name, method) != std::string ()) - retval = true; - else - retval = false; - } - } + if (! error_state) + { + if (load_path::find_method (class_name, method) != std::string ()) + retval = true; + else + retval = false; + } + } } else print_usage (); @@ -1889,27 +1889,27 @@ std::string class_name; if (arg.is_object ()) - class_name = arg.class_name (); + class_name = arg.class_name (); else if (arg.is_string ()) - class_name = arg.string_value (); + class_name = arg.string_value (); else - error ("methods: expecting object or class name as argument"); + error ("methods: expecting object or class name as argument"); if (! error_state) - { - string_vector sv = load_path::methods (class_name); + { + string_vector sv = load_path::methods (class_name); - if (nargout == 0) - { - octave_stdout << "Methods for class " << class_name << ":\n\n"; + if (nargout == 0) + { + octave_stdout << "Methods for class " << class_name << ":\n\n"; - sv.list_in_columns (octave_stdout); + sv.list_in_columns (octave_stdout); - octave_stdout << std::endl; - } - else - retval = Cell (sv); - } + octave_stdout << std::endl; + } + else + retval = Cell (sv); + } } else print_usage (); @@ -1960,35 +1960,35 @@ if (fcn && fcn->is_class_constructor ()) { for (int i = 0; i < args.length(); i++) - { - std::string class_name = args(i).string_value (); + { + std::string class_name = args(i).string_value (); - if (! error_state) - { - if (! is_built_in_class (class_name)) - { - std::string this_class_name = fcn->name (); + if (! error_state) + { + if (! is_built_in_class (class_name)) + { + std::string this_class_name = fcn->name (); - if (! symbol_table::set_class_relationship (this_class_name, - class_name)) - { - error ("superiorto: precedence already set for %s and %s", - this_class_name.c_str (), class_name.c_str ()); - break; - } - } - else - { - // User defined classes always have higher precedence - // than built-in classes. - } - } - else - { - error ("superiorto: expecting argument to be class name"); - break; - } - } + if (! symbol_table::set_class_relationship (this_class_name, + class_name)) + { + error ("superiorto: precedence already set for %s and %s", + this_class_name.c_str (), class_name.c_str ()); + break; + } + } + else + { + // User defined classes always have higher precedence + // than built-in classes. + } + } + else + { + error ("superiorto: expecting argument to be class name"); + break; + } + } } else error ("superiorto: invalid call from outside class constructor"); @@ -2012,38 +2012,38 @@ if (fcn && fcn->is_class_constructor ()) { for (int i = 0; i < args.length(); i++) - { - std::string class_name = args(i).string_value (); + { + std::string class_name = args(i).string_value (); - if (! error_state) - { - if (! is_built_in_class (class_name)) - { - std::string this_class_name = fcn->name (); + if (! error_state) + { + if (! is_built_in_class (class_name)) + { + std::string this_class_name = fcn->name (); - symbol_table::set_class_relationship (class_name, - this_class_name); + symbol_table::set_class_relationship (class_name, + this_class_name); - if (! symbol_table::set_class_relationship (this_class_name, - class_name)) - { - error ("inferiorto: precedence already set for %s and %s", - this_class_name.c_str (), class_name.c_str ()); - break; - } - } - else - { - error ("inferiorto: cannot give user-defined class lower precedence than built-in class"); - break; - } - } - else - { - error ("inferiorto: expecting argument to be class name"); - break; - } - } + if (! symbol_table::set_class_relationship (this_class_name, + class_name)) + { + error ("inferiorto: precedence already set for %s and %s", + this_class_name.c_str (), class_name.c_str ()); + break; + } + } + else + { + error ("inferiorto: cannot give user-defined class lower precedence than built-in class"); + break; + } + } + else + { + error ("inferiorto: expecting argument to be class name"); + break; + } + } } else error ("inferiorto: invalid call from outside class constructor"); diff --git a/src/ov-colon.cc b/src/ov-colon.cc --- a/src/ov-colon.cc +++ b/src/ov-colon.cc @@ -33,7 +33,7 @@ #include "ov-colon.h" DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_magic_colon, - "magic-colon", "magic-colon"); + "magic-colon", "magic-colon"); void octave_magic_colon::print (std::ostream& os, bool) const diff --git a/src/ov-complex.cc b/src/ov-complex.cc --- a/src/ov-complex.cc +++ b/src/ov-complex.cc @@ -53,7 +53,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_complex); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_complex, - "complex scalar", "double"); + "complex scalar", "double"); static octave_base_value * default_numeric_demotion_function (const octave_base_value& a) @@ -108,7 +108,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex scalar", "real scalar"); + "complex scalar", "real scalar"); retval = std::real (scalar); @@ -122,7 +122,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex scalar", "real scalar"); + "complex scalar", "real scalar"); retval = std::real (scalar); @@ -136,7 +136,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex scalar", "real matrix"); + "complex scalar", "real matrix"); retval = Matrix (1, 1, std::real (scalar)); @@ -150,7 +150,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex scalar", "real matrix"); + "complex scalar", "real matrix"); retval = FloatMatrix (1, 1, std::real (scalar)); @@ -164,7 +164,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex scalar", "real matrix"); + "complex scalar", "real matrix"); retval = NDArray (dim_vector (1, 1), std::real (scalar)); @@ -178,7 +178,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex scalar", "real matrix"); + "complex scalar", "real matrix"); retval = FloatNDArray (dim_vector (1, 1), std::real (scalar)); @@ -229,7 +229,7 @@ ComplexNDArray retval (dv, ComplexNDArray::resize_fill_value ()); if (dv.numel ()) - retval(0) = scalar; + retval(0) = scalar; return retval; } @@ -238,7 +238,7 @@ ComplexNDArray retval (dv); if (dv.numel ()) - retval(0) = scalar; + retval(0) = scalar; return retval; } @@ -284,7 +284,7 @@ bool octave_complex::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) + oct_mach_info::float_format fmt) { char tmp; if (! is.read (reinterpret_cast (&tmp), 1)) @@ -292,7 +292,7 @@ Complex ctmp; read_doubles (is, reinterpret_cast (&ctmp), - static_cast (tmp), 2, swap, fmt); + static_cast (tmp), 2, swap, fmt); if (error_state || ! is) return false; @@ -304,7 +304,7 @@ bool octave_complex::save_hdf5 (hid_t loc_id, const char *name, - bool /* save_as_floats */) + bool /* save_as_floats */) { hsize_t dimens[3]; hid_t space_hid = -1, type_hid = -1, data_hid = -1; @@ -322,7 +322,7 @@ } #if HAVE_HDF5_18 data_hid = H5Dcreate (loc_id, name, type_hid, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (loc_id, name, type_hid, space_hid, H5P_DEFAULT); #endif @@ -335,7 +335,7 @@ Complex tmp = complex_value (); retval = H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, H5P_DEFAULT, - &tmp) >= 0; + &tmp) >= 0; H5Dclose (data_hid); H5Tclose (type_hid); @@ -378,7 +378,7 @@ // complex scalar: Complex ctmp; if (H5Dread (data_hid, complex_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, - &ctmp) >= 0) + &ctmp) >= 0) { retval = true; scalar = ctmp; diff --git a/src/ov-cx-diag.cc b/src/ov-cx-diag.cc --- a/src/ov-cx-diag.cc +++ b/src/ov-cx-diag.cc @@ -102,7 +102,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - type_name (), "real matrix"); + type_name (), "real matrix"); retval = ::real (matrix); @@ -116,7 +116,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - type_name (), "real matrix"); + type_name (), "real matrix"); retval = ::real (matrix); @@ -173,18 +173,18 @@ if (save_as_floats) { if (m.too_large_for_float ()) - { - warning ("save: some values too large to save as floats --"); - warning ("save: saving as doubles instead"); - } + { + warning ("save: some values too large to save as floats --"); + warning ("save: saving as doubles instead"); + } else - st = LS_FLOAT; + st = LS_FLOAT; } else if (matrix.length () > 4096) // FIXME -- make this configurable. { double max_val, min_val; if (m.all_integers (max_val, min_val)) - st = get_save_type (max_val, min_val); + st = get_save_type (max_val, min_val); } const Complex *mtmp = m.data (); @@ -195,7 +195,7 @@ bool octave_complex_diag_matrix::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) + oct_mach_info::float_format fmt) { int32_t r, c; char tmp; diff --git a/src/ov-cx-mat.cc b/src/ov-cx-mat.cc --- a/src/ov-cx-mat.cc +++ b/src/ov-cx-mat.cc @@ -60,7 +60,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_complex_matrix); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_complex_matrix, - "complex matrix", "double"); + "complex matrix", "double"); static octave_base_value * default_numeric_demotion_function (const octave_base_value& a) @@ -104,12 +104,12 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex matrix", "real scalar"); + "complex matrix", "real scalar"); if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "complex matrix", "real scalar"); + "complex matrix", "real scalar"); retval = std::real (matrix (0, 0)); } @@ -126,12 +126,12 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex matrix", "real scalar"); + "complex matrix", "real scalar"); if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "complex matrix", "real scalar"); + "complex matrix", "real scalar"); retval = std::real (matrix (0, 0)); } @@ -148,7 +148,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex matrix", "real matrix"); + "complex matrix", "real matrix"); retval = ::real (matrix.matrix_value ()); @@ -162,7 +162,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex matrix", "real matrix"); + "complex matrix", "real matrix"); retval = ::real (matrix.matrix_value ()); @@ -179,7 +179,7 @@ if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "complex matrix", "complex scalar"); + "complex matrix", "complex scalar"); retval = matrix (0, 0); } @@ -199,7 +199,7 @@ if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "complex matrix", "complex scalar"); + "complex matrix", "complex scalar"); retval = matrix (0, 0); } @@ -240,14 +240,14 @@ if (! frc_str_conv) gripe_implicit_conversion ("Octave:num-to-str", - "complex matrix", "string"); + "complex matrix", "string"); else { retval = charNDArray (dims ()); octave_idx_type nel = numel (); for (octave_idx_type i = 0; i < nel; i++) - retval.elem (i) = static_cast(std::real (matrix.elem (i))); + retval.elem (i) = static_cast(std::real (matrix.elem (i))); } return retval; @@ -266,7 +266,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex matrix", "real matrix"); + "complex matrix", "real matrix"); retval = SparseMatrix (::real (matrix.matrix_value ())); @@ -303,7 +303,7 @@ os << "# ndims: " << d.length () << "\n"; for (int i = 0; i < d.length (); i++) - os << " " << d (i); + os << " " << d (i); os << "\n" << tmp; } @@ -312,7 +312,7 @@ // Keep this case, rather than use generic code above for backward // compatiability. Makes load_ascii much more complex!! os << "# rows: " << rows () << "\n" - << "# columns: " << columns () << "\n"; + << "# columns: " << columns () << "\n"; os << complex_matrix_value (); } @@ -336,20 +336,20 @@ if (extract_keyword (is, keywords, kw, val, true)) { if (kw == "ndims") - { - int mdims = static_cast (val); + { + int mdims = static_cast (val); - if (mdims >= 0) - { - dim_vector dv; - dv.resize (mdims); + if (mdims >= 0) + { + dim_vector dv; + dv.resize (mdims); - for (int i = 0; i < mdims; i++) - is >> dv(i); + for (int i = 0; i < mdims; i++) + is >> dv(i); - if (is) - { - ComplexNDArray tmp(dv); + if (is) + { + ComplexNDArray tmp(dv); is >> tmp; @@ -360,51 +360,51 @@ error ("load: failed to load matrix constant"); success = false; } - } - else - { - error ("load: failed to read dimensions"); - success = false; - } - } - else - { - error ("load: failed to extract number of dimensions"); - success = false; - } - } + } + else + { + error ("load: failed to read dimensions"); + success = false; + } + } + else + { + error ("load: failed to extract number of dimensions"); + success = false; + } + } else if (kw == "rows") - { - octave_idx_type nr = val; - octave_idx_type nc = 0; + { + octave_idx_type nr = val; + octave_idx_type nc = 0; - if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0) - { - if (nr > 0 && nc > 0) - { - ComplexMatrix tmp (nr, nc); - is >> tmp; - if (is) - matrix = tmp; - else - { - error ("load: failed to load matrix constant"); - success = false; - } - } - else if (nr == 0 || nc == 0) - matrix = ComplexMatrix (nr, nc); - else - panic_impossible (); - } - else - { - error ("load: failed to extract number of rows and columns"); - success = false; - } - } + if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0) + { + if (nr > 0 && nc > 0) + { + ComplexMatrix tmp (nr, nc); + is >> tmp; + if (is) + matrix = tmp; + else + { + error ("load: failed to load matrix constant"); + success = false; + } + } + else if (nr == 0 || nc == 0) + matrix = ComplexMatrix (nr, nc); + else + panic_impossible (); + } + else + { + error ("load: failed to extract number of rows and columns"); + success = false; + } + } else - panic_impossible (); + panic_impossible (); } else { @@ -436,18 +436,18 @@ if (save_as_floats) { if (m.too_large_for_float ()) - { - warning ("save: some values too large to save as floats --"); - warning ("save: saving as doubles instead"); - } + { + warning ("save: some values too large to save as floats --"); + warning ("save: saving as doubles instead"); + } else - st = LS_FLOAT; + st = LS_FLOAT; } else if (d.numel () > 4096) // FIXME -- make this configurable. { double max_val, min_val; if (m.all_integers (max_val, min_val)) - st = get_save_type (max_val, min_val); + st = get_save_type (max_val, min_val); } @@ -459,7 +459,7 @@ bool octave_complex_matrix::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) + oct_mach_info::float_format fmt) { char tmp; int32_t mdims; @@ -475,35 +475,35 @@ dv.resize (mdims); for (int i = 0; i < mdims; i++) - { - if (! is.read (reinterpret_cast (&di), 4)) - return false; - if (swap) - swap_bytes<4> (&di); - dv(i) = di; - } + { + if (! is.read (reinterpret_cast (&di), 4)) + return false; + if (swap) + swap_bytes<4> (&di); + dv(i) = di; + } // Convert an array with a single dimension to be a row vector. // Octave should never write files like this, other software // might. if (mdims == 1) - { - mdims = 2; - dv.resize (mdims); - dv(1) = dv(0); - dv(0) = 1; - } + { + mdims = 2; + dv.resize (mdims); + dv(1) = dv(0); + dv(0) = 1; + } if (! is.read (reinterpret_cast (&tmp), 1)) - return false; + return false; ComplexNDArray m(dv); Complex *im = m.fortran_vec (); read_doubles (is, reinterpret_cast (im), - static_cast (tmp), 2 * dv.numel (), swap, fmt); + static_cast (tmp), 2 * dv.numel (), swap, fmt); if (error_state || ! is) - return false; + return false; matrix = m; } else @@ -511,18 +511,18 @@ int32_t nr, nc; nr = mdims; if (! is.read (reinterpret_cast (&nc), 4)) - return false; + return false; if (swap) - swap_bytes<4> (&nc); + swap_bytes<4> (&nc); if (! is.read (reinterpret_cast (&tmp), 1)) - return false; + return false; ComplexMatrix m (nr, nc); Complex *im = m.fortran_vec (); octave_idx_type len = nr * nc; read_doubles (is, reinterpret_cast (im), - static_cast (tmp), 2*len, swap, fmt); + static_cast (tmp), 2*len, swap, fmt); if (error_state || ! is) - return false; + return false; matrix = m; } return true; @@ -532,7 +532,7 @@ bool octave_complex_matrix::save_hdf5 (hid_t loc_id, const char *name, - bool save_as_floats) + bool save_as_floats) { dim_vector dv = dims (); int empty = save_hdf5_empty (loc_id, name, dv); @@ -558,12 +558,12 @@ if (save_as_floats) { if (m.too_large_for_float ()) - { - warning ("save: some values too large to save as floats --"); - warning ("save: saving as doubles instead"); - } + { + warning ("save: some values too large to save as floats --"); + warning ("save: saving as doubles instead"); + } else - save_type_hid = H5T_NATIVE_FLOAT; + save_type_hid = H5T_NATIVE_FLOAT; } #if HAVE_HDF5_INT2FLOAT_CONVERSIONS // hdf5 currently doesn't support float/integer conversions @@ -572,8 +572,8 @@ double max_val, min_val; if (m.all_integers (max_val, min_val)) - save_type_hid - = save_type_to_hdf5 (get_save_type (max_val, min_val)); + save_type_hid + = save_type_to_hdf5 (get_save_type (max_val, min_val)); } #endif /* HAVE_HDF5_INT2FLOAT_CONVERSIONS */ @@ -585,7 +585,7 @@ } #if HAVE_HDF5_18 data_hid = H5Dcreate (loc_id, name, type_hid, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (loc_id, name, type_hid, space_hid, H5P_DEFAULT); #endif @@ -603,11 +603,11 @@ { Complex *mtmp = m.fortran_vec (); if (H5Dwrite (data_hid, complex_type_hid, H5S_ALL, H5S_ALL, H5P_DEFAULT, - mtmp) < 0) - { - H5Tclose (complex_type_hid); - retval = false; - } + mtmp) < 0) + { + H5Tclose (complex_type_hid); + retval = false; + } } H5Tclose (complex_type_hid); @@ -674,13 +674,13 @@ { dv.resize (rank); for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--) - dv(j) = hdims[i]; + dv(j) = hdims[i]; } ComplexNDArray m (dv); Complex *reim = m.fortran_vec (); if (H5Dread (data_hid, complex_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, - reim) >= 0) + reim) >= 0) { retval = true; matrix = m; @@ -697,10 +697,10 @@ void octave_complex_matrix::print_raw (std::ostream& os, - bool pr_as_read_syntax) const + bool pr_as_read_syntax) const { octave_print_internal (os, matrix, pr_as_read_syntax, - current_print_indent_level ()); + current_print_indent_level ()); } mxArray * diff --git a/src/ov-cx-sparse.cc b/src/ov-cx-sparse.cc --- a/src/ov-cx-sparse.cc +++ b/src/ov-cx-sparse.cc @@ -67,35 +67,35 @@ // Note that for the tests on matrix size, they become approximative // since they involves a cast to double to avoid issues of overflow if (matrix.rows () == 1 && matrix.cols () == 1) - { - // Const copy of the matrix, so the right version of () operator used - const SparseComplexMatrix tmp (matrix); + { + // Const copy of the matrix, so the right version of () operator used + const SparseComplexMatrix tmp (matrix); - Complex c = tmp (0, 0); + Complex c = tmp (0, 0); - if (std::imag (c) == 0.0) - retval = new octave_scalar (std::real (c)); - else - retval = new octave_complex (c); - } + if (std::imag (c) == 0.0) + retval = new octave_scalar (std::real (c)); + else + retval = new octave_complex (c); + } else if (nr == 0 || nc == 0) - retval = new octave_matrix (Matrix (nr, nc)); + retval = new octave_matrix (Matrix (nr, nc)); else if (matrix.all_elements_are_real ()) - if (matrix.cols () > 0 && matrix.rows () > 0 - && (double (matrix.byte_size ()) > double (matrix.rows ()) - * double (matrix.cols ()) * sizeof (double))) - retval = new octave_matrix (::real (matrix.matrix_value ())); - else - retval = new octave_sparse_matrix (::real (matrix)); + if (matrix.cols () > 0 && matrix.rows () > 0 + && (double (matrix.byte_size ()) > double (matrix.rows ()) + * double (matrix.cols ()) * sizeof (double))) + retval = new octave_matrix (::real (matrix.matrix_value ())); + else + retval = new octave_sparse_matrix (::real (matrix)); else if (matrix.cols () > 0 && matrix.rows () > 0 - && (double (matrix.byte_size ()) > double (matrix.rows ()) - * double (matrix.cols ()) * sizeof (Complex))) - retval = new octave_complex_matrix (matrix.matrix_value ()); + && (double (matrix.byte_size ()) > double (matrix.rows ()) + * double (matrix.cols ()) * sizeof (Complex))) + retval = new octave_complex_matrix (matrix.matrix_value ()); } else { if (matrix.all_elements_are_real ()) - retval = new octave_sparse_matrix (::real (matrix)); + retval = new octave_sparse_matrix (::real (matrix)); } return retval; @@ -103,14 +103,14 @@ void octave_sparse_complex_matrix::assign (const octave_value_list& idx, - const SparseComplexMatrix& rhs) + const SparseComplexMatrix& rhs) { octave_base_sparse::assign (idx, rhs); } void octave_sparse_complex_matrix::assign (const octave_value_list& idx, - const SparseMatrix& rhs) + const SparseMatrix& rhs) { int len = idx.length (); @@ -127,14 +127,14 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex sparse matrix", "real scalar"); + "complex sparse matrix", "real scalar"); // FIXME -- maybe this should be a function, valid_as_scalar() if (numel () > 0) { if (numel () > 1) - gripe_implicit_conversion ("Octave:array-as-scalar", - "complex sparse matrix", "real scalar"); + gripe_implicit_conversion ("Octave:array-as-scalar", + "complex sparse matrix", "real scalar"); retval = std::real (matrix (0, 0)); } @@ -151,7 +151,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex sparse matrix", "real matrix"); + "complex sparse matrix", "real matrix"); retval = ::real (matrix.matrix_value ()); @@ -169,8 +169,8 @@ if (numel () > 0) { if (numel () > 1) - gripe_implicit_conversion ("Octave:array-as-scalar", - "complex sparse matrix", "real scalar"); + gripe_implicit_conversion ("Octave:array-as-scalar", + "complex sparse matrix", "real scalar"); retval = matrix (0, 0); } @@ -199,7 +199,7 @@ if (! frc_str_conv) gripe_implicit_conversion ("Octave:num-to-str", - "sparse complex matrix", "string"); + "sparse complex matrix", "string"); else { retval = charNDArray (dims (), 0); @@ -207,9 +207,9 @@ octave_idx_type nr = matrix.rows (); for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = matrix.cidx(j); i < matrix.cidx(j+1); i++) - retval(matrix.ridx(i) + nr * j) = - static_cast(std::real (matrix.data (i))); + for (octave_idx_type i = matrix.cidx(j); i < matrix.cidx(j+1); i++) + retval(matrix.ridx(i) + nr * j) = + static_cast(std::real (matrix.data (i))); } return retval; @@ -222,8 +222,8 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex sparse matrix", - "real sparse matrix"); + "complex sparse matrix", + "real sparse matrix"); retval = ::real (matrix); @@ -244,7 +244,7 @@ bool octave_sparse_complex_matrix::save_binary (std::ostream& os, - bool&save_as_floats) + bool&save_as_floats) { dim_vector d = this->dims (); if (d.length() < 1) @@ -275,18 +275,18 @@ if (save_as_floats) { if (matrix.too_large_for_float ()) - { - warning ("save: some values too large to save as floats --"); - warning ("save: saving as doubles instead"); - } + { + warning ("save: some values too large to save as floats --"); + warning ("save: saving as doubles instead"); + } else - st = LS_FLOAT; + st = LS_FLOAT; } else if (matrix.nzmax () > 8192) // FIXME -- make this configurable. { double max_val, min_val; if (matrix.all_integers (max_val, min_val)) - st = get_save_type (max_val, min_val); + st = get_save_type (max_val, min_val); } // add one to the printed indices to go from @@ -312,7 +312,7 @@ bool octave_sparse_complex_matrix::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) + oct_mach_info::float_format fmt) { int32_t nz, nc, nr, tmp; char ctmp; @@ -343,16 +343,16 @@ } SparseComplexMatrix m (static_cast (nr), - static_cast (nc), - static_cast (nz)); + static_cast (nc), + static_cast (nz)); for (int i = 0; i < nc+1; i++) { octave_quit (); if (! is.read (reinterpret_cast (&tmp), 4)) - return false; + return false; if (swap) - swap_bytes<4> (&tmp); + swap_bytes<4> (&tmp); m.cidx(i) = tmp; } @@ -360,9 +360,9 @@ { octave_quit (); if (! is.read (reinterpret_cast (&tmp), 4)) - return false; + return false; if (swap) - swap_bytes<4> (&tmp); + swap_bytes<4> (&tmp); m.ridx(i) = tmp; } @@ -370,7 +370,7 @@ return false; read_doubles (is, reinterpret_cast (m.data ()), - static_cast (ctmp), 2 * nz, swap, fmt); + static_cast (ctmp), 2 * nz, swap, fmt); if (error_state || ! is) return false; @@ -387,7 +387,7 @@ bool octave_sparse_complex_matrix::save_hdf5 (hid_t loc_id, const char *name, - bool save_as_floats) + bool save_as_floats) { dim_vector dv = dims (); int empty = save_hdf5_empty (loc_id, name, dv); @@ -420,10 +420,10 @@ #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "nr", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "nr", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -434,7 +434,7 @@ tmp = m.rows (); retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, - H5P_DEFAULT, &tmp) >= 0; + H5P_DEFAULT, &tmp) >= 0; H5Dclose (data_hid); if (!retval) { @@ -445,10 +445,10 @@ #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "nc", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "nc", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -459,7 +459,7 @@ tmp = m.cols (); retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, - H5P_DEFAULT, &tmp) >= 0; + H5P_DEFAULT, &tmp) >= 0; H5Dclose (data_hid); if (!retval) { @@ -470,10 +470,10 @@ #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "nz", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "nz", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -484,7 +484,7 @@ tmp = m.nzmax (); retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, - H5P_DEFAULT, &tmp) >= 0; + H5P_DEFAULT, &tmp) >= 0; H5Dclose (data_hid); if (!retval) { @@ -508,10 +508,10 @@ #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "cidx", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "cidx", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -522,7 +522,7 @@ octave_idx_type * itmp = m.xcidx (); retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, - H5P_DEFAULT, itmp) >= 0; + H5P_DEFAULT, itmp) >= 0; H5Dclose (data_hid); if (!retval) { @@ -546,10 +546,10 @@ #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "ridx", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "ridx", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -573,12 +573,12 @@ if (save_as_floats) { if (m.too_large_for_float ()) - { - warning ("save: some values too large to save as floats --"); - warning ("save: saving as doubles instead"); - } + { + warning ("save: some values too large to save as floats --"); + warning ("save: saving as doubles instead"); + } else - save_type_hid = H5T_NATIVE_FLOAT; + save_type_hid = H5T_NATIVE_FLOAT; } #if HAVE_HDF5_INT2FLOAT_CONVERSIONS // hdf5 currently doesn't support float/integer conversions @@ -587,8 +587,8 @@ double max_val, min_val; if (m.all_integers (max_val, min_val)) - save_type_hid - = save_type_to_hdf5 (get_save_type (max_val, min_val)); + save_type_hid + = save_type_to_hdf5 (get_save_type (max_val, min_val)); } #endif /* HAVE_HDF5_INT2FLOAT_CONVERSIONS */ @@ -601,7 +601,7 @@ } #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "data", type_hid, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "data", type_hid, space_hid, H5P_DEFAULT); #endif @@ -620,7 +620,7 @@ Complex * ctmp = m.xdata (); retval = H5Dwrite (data_hid, complex_type_hid, H5S_ALL, H5S_ALL, - H5P_DEFAULT, ctmp) >= 0; + H5P_DEFAULT, ctmp) >= 0; } H5Dclose (data_hid); @@ -725,8 +725,8 @@ H5Dclose (data_hid); SparseComplexMatrix m (static_cast (nr), - static_cast (nc), - static_cast (nz)); + static_cast (nc), + static_cast (nz)); #if HAVE_HDF5_18 data_hid = H5Dopen (group_hid, "cidx", H5P_DEFAULT); @@ -851,7 +851,7 @@ Complex *ctmp = m.xdata (); bool retval = false; if (H5Dread (data_hid, complex_type, H5S_ALL, H5S_ALL, - H5P_DEFAULT, ctmp) >= 0 + H5P_DEFAULT, ctmp) >= 0 && m.indices_ok ()) { retval = true; @@ -873,7 +873,7 @@ { mwSize nz = nzmax (); mxArray *retval = new mxArray (mxDOUBLE_CLASS, rows (), columns (), - nz, mxCOMPLEX); + nz, mxCOMPLEX); double *pr = static_cast (retval->get_data ()); double *pi = static_cast (retval->get_imag_data ()); mwIndex *ir = retval->get_ir (); diff --git a/src/ov-dld-fcn.cc b/src/ov-dld-fcn.cc --- a/src/ov-dld-fcn.cc +++ b/src/ov-dld-fcn.cc @@ -37,8 +37,8 @@ DEFINE_OCTAVE_ALLOCATOR (octave_dld_function); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_dld_function, - "dynamically-linked function", - "dynamically-linked function"); + "dynamically-linked function", + "dynamically-linked function"); octave_dld_function::octave_dld_function @@ -85,7 +85,7 @@ octave_dld_function* octave_dld_function::create (octave_builtin::fcn ff, const octave_shlib& shl, - const std::string& nm, const std::string& ds) + const std::string& nm, const std::string& ds) { return new octave_dld_function (ff, shl, nm, ds); } diff --git a/src/ov-fcn-handle.cc b/src/ov-fcn-handle.cc --- a/src/ov-fcn-handle.cc +++ b/src/ov-fcn-handle.cc @@ -65,13 +65,13 @@ DEFINE_OCTAVE_ALLOCATOR (octave_fcn_handle); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_fcn_handle, - "function handle", - "function_handle"); + "function handle", + "function_handle"); const std::string octave_fcn_handle::anonymous ("@"); octave_fcn_handle::octave_fcn_handle (const octave_value& f, - const std::string& n) + const std::string& n) : fcn (f), nm (n) { octave_user_function *uf = fcn.user_function_value (true); @@ -82,8 +82,8 @@ octave_value_list octave_fcn_handle::subsref (const std::string& type, - const std::list& idx, - int nargout) + const std::list& idx, + int nargout) { octave_value_list retval; @@ -91,17 +91,17 @@ { case '(': { - int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; + int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; - retval = do_multi_index_op (tmp_nargout, idx.front ()); + retval = do_multi_index_op (tmp_nargout, idx.front ()); } break; case '{': case '.': { - std::string tnm = type_name (); - error ("%s cannot be indexed with %c", tnm.c_str (), type[0]); + std::string tnm = type_name (); + error ("%s cannot be indexed with %c", tnm.c_str (), type[0]); } break; @@ -180,7 +180,7 @@ bool octave_fcn_handle::set_fcn (const std::string &octaveroot, - const std::string& fpath) + const std::string& fpath) { bool success = true; @@ -191,93 +191,93 @@ { // First check if just replacing matlabroot is enough std::string str = OCTAVE_EXEC_PREFIX + - fpath.substr (octaveroot.length ()); + fpath.substr (octaveroot.length ()); file_stat fs (str); if (fs.exists ()) - { - size_t xpos = str.find_last_of (file_ops::dir_sep_chars ()); + { + size_t xpos = str.find_last_of (file_ops::dir_sep_chars ()); - std::string dir_name = str.substr (0, xpos); + std::string dir_name = str.substr (0, xpos); - octave_function *xfcn - = load_fcn_from_file (str, dir_name, "", nm); + octave_function *xfcn + = load_fcn_from_file (str, dir_name, "", nm); - if (xfcn) - { - octave_value tmp (xfcn); + if (xfcn) + { + octave_value tmp (xfcn); - fcn = octave_value (new octave_fcn_handle (tmp, nm)); - } - else - { - error ("function handle points to non-existent function"); - success = false; - } - } + fcn = octave_value (new octave_fcn_handle (tmp, nm)); + } + else + { + error ("function handle points to non-existent function"); + success = false; + } + } else - { - // Next just search for it anywhere in the system path - string_vector names(3); - names(0) = nm + ".oct"; - names(1) = nm + ".mex"; - names(2) = nm + ".m"; + { + // Next just search for it anywhere in the system path + string_vector names(3); + names(0) = nm + ".oct"; + names(1) = nm + ".mex"; + names(2) = nm + ".m"; - dir_path p (load_path::system_path ()); + dir_path p (load_path::system_path ()); - str = octave_env::make_absolute (p.find_first_of (names)); + str = octave_env::make_absolute (p.find_first_of (names)); - size_t xpos = str.find_last_of (file_ops::dir_sep_chars ()); + size_t xpos = str.find_last_of (file_ops::dir_sep_chars ()); - std::string dir_name = str.substr (0, xpos); + std::string dir_name = str.substr (0, xpos); - octave_function *xfcn = load_fcn_from_file (str, dir_name, "", nm); + octave_function *xfcn = load_fcn_from_file (str, dir_name, "", nm); - if (xfcn) - { - octave_value tmp (xfcn); + if (xfcn) + { + octave_value tmp (xfcn); - fcn = octave_value (new octave_fcn_handle (tmp, nm)); - } - else - { - error ("function handle points to non-existent function"); - success = false; - } - } + fcn = octave_value (new octave_fcn_handle (tmp, nm)); + } + else + { + error ("function handle points to non-existent function"); + success = false; + } + } } else { if (fpath.length () > 0) - { - size_t xpos = fpath.find_last_of (file_ops::dir_sep_chars ()); + { + size_t xpos = fpath.find_last_of (file_ops::dir_sep_chars ()); - std::string dir_name = fpath.substr (0, xpos); + std::string dir_name = fpath.substr (0, xpos); - octave_function *xfcn = load_fcn_from_file (fpath, dir_name, "", nm); + octave_function *xfcn = load_fcn_from_file (fpath, dir_name, "", nm); - if (xfcn) - { - octave_value tmp (xfcn); + if (xfcn) + { + octave_value tmp (xfcn); - fcn = octave_value (new octave_fcn_handle (tmp, nm)); - } - else - { - error ("function handle points to non-existent function"); - success = false; - } - } + fcn = octave_value (new octave_fcn_handle (tmp, nm)); + } + else + { + error ("function handle points to non-existent function"); + success = false; + } + } else - { - fcn = symbol_table::find_function (nm); + { + fcn = symbol_table::find_function (nm); - if (! fcn.is_function ()) - { - error ("function handle points to non-existent function"); - success = false; - } - } + if (! fcn.is_function ()) + { + error ("function handle points to non-existent function"); + success = false; + } + } } return success; @@ -294,26 +294,26 @@ os << "\n"; if (fcn.is_undefined ()) - return false; + return false; octave_user_function *f = fcn.user_function_value (); std::list vars - = symbol_table::all_variables (f->scope (), 0); + = symbol_table::all_variables (f->scope (), 0); size_t varlen = vars.size (); if (varlen > 0) - { - os << "# length: " << varlen << "\n"; + { + os << "# length: " << varlen << "\n"; - for (std::list::const_iterator p = vars.begin (); - p != vars.end (); p++) - { - if (! save_ascii_data (os, p->varval (), p->name (), false, 0)) - return os; - } - } + for (std::list::const_iterator p = vars.begin (); + p != vars.end (); p++) + { + if (! save_ascii_data (os, p->varval (), p->name (), false, 0)) + return os; + } + } } else { @@ -322,7 +322,7 @@ os << "# octaveroot: " << OCTAVE_EXEC_PREFIX << "\n"; if (! fnm.empty ()) - os << "# path: " << fnm << "\n"; + os << "# path: " << fnm << "\n"; os << nm << "\n"; } @@ -358,13 +358,13 @@ std::string buf; if (is) - { + { - // Get a line of text whitespace characters included, leaving - // newline in the stream. - buf = read_until_newline (is, true); + // Get a line of text whitespace characters included, leaving + // newline in the stream. + buf = read_until_newline (is, true); - } + } pos = is.tellg (); @@ -384,61 +384,61 @@ octave_idx_type len = 0; if (extract_keyword (is, "length", len, true) && len >= 0) - { - if (len > 0) - { - for (octave_idx_type i = 0; i < len; i++) - { - octave_value t2; - bool dummy; + { + if (len > 0) + { + for (octave_idx_type i = 0; i < len; i++) + { + octave_value t2; + bool dummy; - std::string name - = read_ascii_data (is, std::string (), dummy, t2, i); + std::string name + = read_ascii_data (is, std::string (), dummy, t2, i); - if (!is) - { - error ("load: failed to load anonymous function handle"); - break; - } + if (!is) + { + error ("load: failed to load anonymous function handle"); + break; + } - symbol_table::varref (name, local_scope, 0) = t2; - } - } - } + symbol_table::varref (name, local_scope, 0) = t2; + } + } + } else - { - is.seekg (pos); - is.clear (); - } + { + is.seekg (pos); + is.clear (); + } if (is && success) - { - int parse_status; - octave_value anon_fcn_handle = - eval_string (buf, true, parse_status); + { + int parse_status; + octave_value anon_fcn_handle = + eval_string (buf, true, parse_status); - if (parse_status == 0) - { - octave_fcn_handle *fh = - anon_fcn_handle.fcn_handle_value (); + if (parse_status == 0) + { + octave_fcn_handle *fh = + anon_fcn_handle.fcn_handle_value (); - if (fh) - { - fcn = fh->fcn; + if (fh) + { + fcn = fh->fcn; - octave_user_function *uf = fcn.user_function_value (true); + octave_user_function *uf = fcn.user_function_value (true); - if (uf) - symbol_table::cache_name (uf->scope (), nm); - } - else - success = false; - } - else - success = false; - } + if (uf) + symbol_table::cache_name (uf->scope (), nm); + } + else + success = false; + } + else + success = false; + } else - success = false; + success = false; } else success = set_fcn (octaveroot, fpath); @@ -454,19 +454,19 @@ std::ostringstream nmbuf; if (fcn.is_undefined ()) - return false; + return false; octave_user_function *f = fcn.user_function_value (); std::list vars - = symbol_table::all_variables (f->scope (), 0); + = symbol_table::all_variables (f->scope (), 0); size_t varlen = vars.size (); if (varlen > 0) - nmbuf << nm << " " << varlen; + nmbuf << nm << " " << varlen; else - nmbuf << nm; + nmbuf << nm; std::string buf_str = nmbuf.str(); int32_t tmp = buf_str.length (); @@ -481,15 +481,15 @@ os.write (stmp.c_str (), stmp.length ()); if (varlen > 0) - { - for (std::list::const_iterator p = vars.begin (); - p != vars.end (); p++) - { - if (! save_binary_data (os, p->varval (), p->name (), - "", 0, save_as_floats)) - return os; - } - } + { + for (std::list::const_iterator p = vars.begin (); + p != vars.end (); p++) + { + if (! save_binary_data (os, p->varval (), p->name (), + "", 0, save_as_floats)) + return os; + } + } } else { @@ -511,7 +511,7 @@ bool octave_fcn_handle::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) + oct_mach_info::float_format fmt) { bool success = true; @@ -535,16 +535,16 @@ octave_idx_type len = 0; if (nm.length() > anl) - { - std::istringstream nm_is (nm.substr (anl)); - nm_is >> len; - nm = nm.substr (0, anl); - } + { + std::istringstream nm_is (nm.substr (anl)); + nm_is >> len; + nm = nm.substr (0, anl); + } if (! is.read (reinterpret_cast (&tmp), 4)) - return false; + return false; if (swap) - swap_bytes<4> (&tmp); + swap_bytes<4> (&tmp); OCTAVE_LOCAL_BUFFER (char, ctmp2, tmp+1); is.get (ctmp2, tmp+1, 0); @@ -555,7 +555,7 @@ // defines the anonymous function. symbol_table::scope_id local_scope = symbol_table::alloc_scope (); - frame.add_fcn (symbol_table::erase_scope, local_scope); + frame.add_fcn (symbol_table::erase_scope, local_scope); symbol_table::set_scope (local_scope); @@ -563,52 +563,52 @@ frame.add_fcn (octave_call_stack::pop); if (len > 0) - { - for (octave_idx_type i = 0; i < len; i++) - { - octave_value t2; - bool dummy; - std::string doc; + { + for (octave_idx_type i = 0; i < len; i++) + { + octave_value t2; + bool dummy; + std::string doc; - std::string name = - read_binary_data (is, swap, fmt, std::string (), - dummy, t2, doc); + std::string name = + read_binary_data (is, swap, fmt, std::string (), + dummy, t2, doc); - if (!is) - { - error ("load: failed to load anonymous function handle"); - break; - } + if (!is) + { + error ("load: failed to load anonymous function handle"); + break; + } - symbol_table::varref (name, local_scope) = t2; - } - } + symbol_table::varref (name, local_scope) = t2; + } + } if (is && success) - { - int parse_status; - octave_value anon_fcn_handle = - eval_string (ctmp2, true, parse_status); + { + int parse_status; + octave_value anon_fcn_handle = + eval_string (ctmp2, true, parse_status); - if (parse_status == 0) - { - octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); + if (parse_status == 0) + { + octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); - if (fh) - { - fcn = fh->fcn; + if (fh) + { + fcn = fh->fcn; - octave_user_function *uf = fcn.user_function_value (true); + octave_user_function *uf = fcn.user_function_value (true); - if (uf) - symbol_table::cache_name (uf->scope (), nm); - } - else - success = false; - } - else - success = false; - } + if (uf) + symbol_table::cache_name (uf->scope (), nm); + } + else + success = false; + } + else + success = false; + } } else { @@ -616,13 +616,13 @@ std::string fpath; if (nm.find_first_of ("\n") != std::string::npos) - { - size_t pos1 = nm.find_first_of ("\n"); - size_t pos2 = nm.find_first_of ("\n", pos1 + 1); - octaveroot = nm.substr (pos1 + 1, pos2 - pos1 - 1); - fpath = nm.substr (pos2 + 1); - nm = nm.substr (0, pos1); - } + { + size_t pos1 = nm.find_first_of ("\n"); + size_t pos2 = nm.find_first_of ("\n", pos1 + 1); + octaveroot = nm.substr (pos1 + 1, pos2 - pos1 - 1); + fpath = nm.substr (pos2 + 1); + nm = nm.substr (0, pos1); + } success = set_fcn (octaveroot, fpath); } @@ -633,7 +633,7 @@ #if defined (HAVE_HDF5) bool octave_fcn_handle::save_hdf5 (hid_t loc_id, const char *name, - bool save_as_floats) + bool save_as_floats) { bool retval = true; @@ -669,12 +669,12 @@ } #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, H5P_DEFAULT); #endif if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, - H5P_DEFAULT, nm.c_str ()) < 0) + H5P_DEFAULT, nm.c_str ()) < 0) { H5Sclose (space_hid); H5Tclose (type_hid); @@ -692,88 +692,88 @@ // attach the type of the variable H5Tset_size (type_hid, stmp.length () + 1); if (type_hid < 0) - { - H5Sclose (space_hid); - H5Gclose (group_hid); - return false; - } + { + H5Sclose (space_hid); + H5Gclose (group_hid); + return false; + } #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, - H5P_DEFAULT, stmp.c_str ()) < 0) - { - H5Sclose (space_hid); - H5Tclose (type_hid); - H5Gclose (group_hid); - return false; - } + H5P_DEFAULT, stmp.c_str ()) < 0) + { + H5Sclose (space_hid); + H5Tclose (type_hid); + H5Gclose (group_hid); + return false; + } H5Dclose (data_hid); octave_user_function *f = fcn.user_function_value (); std::list vars - = symbol_table::all_variables (f->scope (), 0); + = symbol_table::all_variables (f->scope (), 0); size_t varlen = vars.size (); if (varlen > 0) - { - hid_t as_id = H5Screate (H5S_SCALAR); + { + hid_t as_id = H5Screate (H5S_SCALAR); - if (as_id >= 0) - { + if (as_id >= 0) + { #if HAVE_HDF5_18 - hid_t a_id = H5Acreate (group_hid, "SYMBOL_TABLE", - H5T_NATIVE_IDX, as_id, - H5P_DEFAULT, H5P_DEFAULT); + hid_t a_id = H5Acreate (group_hid, "SYMBOL_TABLE", + H5T_NATIVE_IDX, as_id, + H5P_DEFAULT, H5P_DEFAULT); #else - hid_t a_id = H5Acreate (group_hid, "SYMBOL_TABLE", - H5T_NATIVE_IDX, as_id, H5P_DEFAULT); + hid_t a_id = H5Acreate (group_hid, "SYMBOL_TABLE", + H5T_NATIVE_IDX, as_id, H5P_DEFAULT); #endif - if (a_id >= 0) - { - retval = (H5Awrite (a_id, H5T_NATIVE_IDX, &varlen) >= 0); + if (a_id >= 0) + { + retval = (H5Awrite (a_id, H5T_NATIVE_IDX, &varlen) >= 0); - H5Aclose (a_id); - } - else - retval = false; + H5Aclose (a_id); + } + else + retval = false; - H5Sclose (as_id); - } - else - retval = false; + H5Sclose (as_id); + } + else + retval = false; #if HAVE_HDF5_18 - data_hid = H5Gcreate (group_hid, "symbol table", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + data_hid = H5Gcreate (group_hid, "symbol table", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else - data_hid = H5Gcreate (group_hid, "symbol table", 0); + data_hid = H5Gcreate (group_hid, "symbol table", 0); #endif - if (data_hid < 0) - { - H5Sclose (space_hid); - H5Tclose (type_hid); - H5Gclose (group_hid); - return false; - } + if (data_hid < 0) + { + H5Sclose (space_hid); + H5Tclose (type_hid); + H5Gclose (group_hid); + return false; + } - for (std::list::const_iterator p = vars.begin (); - p != vars.end (); p++) - { - if (! add_hdf5_data (data_hid, p->varval (), p->name (), - "", false, save_as_floats)) - break; - } - H5Gclose (data_hid); - } + for (std::list::const_iterator p = vars.begin (); + p != vars.end (); p++) + { + if (! add_hdf5_data (data_hid, p->varval (), p->name (), + "", false, save_as_floats)) + break; + } + H5Gclose (data_hid); + } } else { @@ -787,47 +787,47 @@ hdims[1] = octaveroot.length (); space_hid = H5Screate_simple (0 , hdims, 0); if (space_hid < 0) - { - H5Tclose (type_hid); - H5Gclose (group_hid); - return false; - } + { + H5Tclose (type_hid); + H5Gclose (group_hid); + return false; + } H5Tclose (type_hid); type_hid = H5Tcopy (H5T_C_S1); H5Tset_size (type_hid, octaveroot.length () + 1); #if HAVE_HDF5_18 hid_t a_id = H5Acreate (group_hid, "OCTAVEROOT", - type_hid, space_hid, H5P_DEFAULT, H5P_DEFAULT); + type_hid, space_hid, H5P_DEFAULT, H5P_DEFAULT); #else hid_t a_id = H5Acreate (group_hid, "OCTAVEROOT", - type_hid, space_hid, H5P_DEFAULT); + type_hid, space_hid, H5P_DEFAULT); #endif if (a_id >= 0) - { - retval = (H5Awrite (a_id, type_hid, octaveroot.c_str ()) >= 0); + { + retval = (H5Awrite (a_id, type_hid, octaveroot.c_str ()) >= 0); - H5Aclose (a_id); - } + H5Aclose (a_id); + } else - { - H5Sclose (space_hid); - H5Tclose (type_hid); - H5Gclose (group_hid); - return false; - } + { + H5Sclose (space_hid); + H5Tclose (type_hid); + H5Gclose (group_hid); + return false; + } H5Sclose (space_hid); hdims[0] = 1; hdims[1] = fpath.length (); space_hid = H5Screate_simple (0 , hdims, 0); if (space_hid < 0) - { - H5Tclose (type_hid); - H5Gclose (group_hid); - return false; - } + { + H5Tclose (type_hid); + H5Gclose (group_hid); + return false; + } H5Tclose (type_hid); type_hid = H5Tcopy (H5T_C_S1); @@ -835,19 +835,19 @@ #if HAVE_HDF5_18 a_id = H5Acreate (group_hid, "FILE", type_hid, space_hid, - H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT); #else a_id = H5Acreate (group_hid, "FILE", type_hid, space_hid, H5P_DEFAULT); #endif if (a_id >= 0) - { - retval = (H5Awrite (a_id, type_hid, fpath.c_str ()) >= 0); + { + retval = (H5Awrite (a_id, type_hid, fpath.c_str ()) >= 0); - H5Aclose (a_id); - } + H5Aclose (a_id); + } else - retval = false; + retval = false; } H5Sclose (space_hid); @@ -947,48 +947,48 @@ #endif if (data_hid < 0) - { - H5Sclose (space_hid); - H5Tclose (type_hid); - H5Gclose (group_hid); - return false; - } + { + H5Sclose (space_hid); + H5Tclose (type_hid); + H5Gclose (group_hid); + return false; + } H5Tclose (type_hid); type_hid = H5Dget_type (data_hid); type_class_hid = H5Tget_class (type_hid); if (type_class_hid != H5T_STRING) - { - H5Sclose (space_hid); - H5Tclose (type_hid); - H5Dclose (data_hid); - H5Gclose (group_hid); - return false; - } + { + H5Sclose (space_hid); + H5Tclose (type_hid); + H5Dclose (data_hid); + H5Gclose (group_hid); + return false; + } H5Sclose (space_hid); space_hid = H5Dget_space (data_hid); rank = H5Sget_simple_extent_ndims (space_hid); if (rank != 0) - { - H5Sclose (space_hid); - H5Tclose (type_hid); - H5Dclose (data_hid); - H5Gclose (group_hid); - return false; - } + { + H5Sclose (space_hid); + H5Tclose (type_hid); + H5Dclose (data_hid); + H5Gclose (group_hid); + return false; + } slen = H5Tget_size (type_hid); if (slen < 0) - { - H5Sclose (space_hid); - H5Tclose (type_hid); - H5Dclose (data_hid); - H5Gclose (group_hid); - return false; - } + { + H5Sclose (space_hid); + H5Tclose (type_hid); + H5Dclose (data_hid); + H5Gclose (group_hid); + return false; + } OCTAVE_LOCAL_BUFFER (char, fcn_tmp, slen); @@ -997,14 +997,14 @@ H5Tset_size (st_id, slen); if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, fcn_tmp) < 0) - { - H5Tclose (st_id); - H5Sclose (space_hid); - H5Tclose (type_hid); - H5Dclose (data_hid); - H5Gclose (group_hid); - return false; - } + { + H5Tclose (st_id); + H5Sclose (space_hid); + H5Tclose (type_hid); + H5Dclose (data_hid); + H5Gclose (group_hid); + return false; + } H5Tclose (st_id); H5Dclose (data_hid); @@ -1030,12 +1030,12 @@ hid_t attr_id = H5Aopen_name (group_hid, "SYMBOL_TABLE"); if (attr_id >= 0) - { - if (H5Aread (attr_id, H5T_NATIVE_IDX, &len) < 0) - success = false; + { + if (H5Aread (attr_id, H5T_NATIVE_IDX, &len) < 0) + success = false; - H5Aclose (attr_id); - } + H5Aclose (attr_id); + } // restore error reporting: #if HAVE_HDF5_18 @@ -1058,66 +1058,66 @@ frame.add_fcn (octave_call_stack::pop); if (len > 0 && success) - { - hsize_t num_obj = 0; + { + hsize_t num_obj = 0; #if HAVE_HDF5_18 - data_hid = H5Gopen (group_hid, "symbol table", H5P_DEFAULT); + data_hid = H5Gopen (group_hid, "symbol table", H5P_DEFAULT); #else - data_hid = H5Gopen (group_hid, "symbol table"); + data_hid = H5Gopen (group_hid, "symbol table"); #endif - H5Gget_num_objs (data_hid, &num_obj); - H5Gclose (data_hid); + H5Gget_num_objs (data_hid, &num_obj); + H5Gclose (data_hid); - if (num_obj != static_cast(len)) - { - error ("load: failed to load anonymous function handle"); - success = false; - } + if (num_obj != static_cast(len)) + { + error ("load: failed to load anonymous function handle"); + success = false; + } - if (! error_state) - { - hdf5_callback_data dsub; - int current_item = 0; - for (octave_idx_type i = 0; i < len; i++) - { - if (H5Giterate (group_hid, "symbol table", ¤t_item, - hdf5_read_next_data, &dsub) <= 0) - { - error ("load: failed to load anonymous function handle"); - success = false; - break; - } + if (! error_state) + { + hdf5_callback_data dsub; + int current_item = 0; + for (octave_idx_type i = 0; i < len; i++) + { + if (H5Giterate (group_hid, "symbol table", ¤t_item, + hdf5_read_next_data, &dsub) <= 0) + { + error ("load: failed to load anonymous function handle"); + success = false; + break; + } - symbol_table::varref (dsub.name, local_scope) = dsub.tc; - } - } - } + symbol_table::varref (dsub.name, local_scope) = dsub.tc; + } + } + } if (success) - { - int parse_status; - octave_value anon_fcn_handle = - eval_string (fcn_tmp, true, parse_status); + { + int parse_status; + octave_value anon_fcn_handle = + eval_string (fcn_tmp, true, parse_status); - if (parse_status == 0) - { - octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); + if (parse_status == 0) + { + octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); - if (fh) - { - fcn = fh->fcn; + if (fh) + { + fcn = fh->fcn; - octave_user_function *uf = fcn.user_function_value (true); + octave_user_function *uf = fcn.user_function_value (true); - if (uf) - symbol_table::cache_name (uf->scope (), nm); - } - else - success = false; - } - else - success = false; - } + if (uf) + symbol_table::cache_name (uf->scope (), nm); + } + else + success = false; + } + else + success = false; + } frame.run (); } @@ -1145,60 +1145,60 @@ hid_t attr_id = H5Aopen_name (group_hid, "OCTAVEROOT"); if (attr_id >= 0) - { - H5Tclose (type_hid); - type_hid = H5Aget_type (attr_id); - type_class_hid = H5Tget_class (type_hid); + { + H5Tclose (type_hid); + type_hid = H5Aget_type (attr_id); + type_class_hid = H5Tget_class (type_hid); - if (type_class_hid != H5T_STRING) - success = false; - else - { - slen = H5Tget_size (type_hid); - st_id = H5Tcopy (H5T_C_S1); - H5Tset_size (st_id, slen); - OCTAVE_LOCAL_BUFFER (char, root_tmp, slen); + if (type_class_hid != H5T_STRING) + success = false; + else + { + slen = H5Tget_size (type_hid); + st_id = H5Tcopy (H5T_C_S1); + H5Tset_size (st_id, slen); + OCTAVE_LOCAL_BUFFER (char, root_tmp, slen); - if (H5Aread (attr_id, st_id, root_tmp) < 0) - success = false; - else - octaveroot = root_tmp; + if (H5Aread (attr_id, st_id, root_tmp) < 0) + success = false; + else + octaveroot = root_tmp; - H5Tclose (st_id); - } + H5Tclose (st_id); + } - H5Aclose (attr_id); - } + H5Aclose (attr_id); + } if (success) - { - attr_id = H5Aopen_name (group_hid, "FILE"); - if (attr_id >= 0) - { - H5Tclose (type_hid); - type_hid = H5Aget_type (attr_id); - type_class_hid = H5Tget_class (type_hid); + { + attr_id = H5Aopen_name (group_hid, "FILE"); + if (attr_id >= 0) + { + H5Tclose (type_hid); + type_hid = H5Aget_type (attr_id); + type_class_hid = H5Tget_class (type_hid); - if (type_class_hid != H5T_STRING) - success = false; - else - { - slen = H5Tget_size (type_hid); - st_id = H5Tcopy (H5T_C_S1); - H5Tset_size (st_id, slen); - OCTAVE_LOCAL_BUFFER (char, path_tmp, slen); + if (type_class_hid != H5T_STRING) + success = false; + else + { + slen = H5Tget_size (type_hid); + st_id = H5Tcopy (H5T_C_S1); + H5Tset_size (st_id, slen); + OCTAVE_LOCAL_BUFFER (char, path_tmp, slen); - if (H5Aread (attr_id, st_id, path_tmp) < 0) - success = false; - else - fpath = path_tmp; + if (H5Aread (attr_id, st_id, path_tmp) < 0) + success = false; + else + fpath = path_tmp; - H5Tclose (st_id); - } + H5Tclose (st_id); + } - H5Aclose (attr_id); - } - } + H5Aclose (attr_id); + } + } // restore error reporting: #if HAVE_HDF5_18 @@ -1280,51 +1280,51 @@ octave_user_function *f = ftmp.user_function_value (); if (f) - { - tree_parameter_list *p = f->parameter_list (); + { + tree_parameter_list *p = f->parameter_list (); - os << "@("; + os << "@("; - if (p) - p->accept (tpc); + if (p) + p->accept (tpc); - os << ") "; + os << ") "; - tree_statement_list *b = f->body (); + tree_statement_list *b = f->body (); - if (b) - { - assert (b->length () == 1); + if (b) + { + assert (b->length () == 1); - tree_statement *s = b->front (); + tree_statement *s = b->front (); - if (s) - { - if (s->is_expression ()) - { - tree_expression *e = s->expression (); + if (s) + { + if (s->is_expression ()) + { + tree_expression *e = s->expression (); - if (e) - e->accept (tpc); - } - else - { - tree_command *c = s->command (); + if (e) + e->accept (tpc); + } + else + { + tree_command *c = s->command (); - tpc.suspend_newline (); - c->accept (tpc); - tpc.resume_newline (); - } - } - } + tpc.suspend_newline (); + c->accept (tpc); + tpc.resume_newline (); + } + } + } - printed = true; - } + printed = true; + } } if (! printed) octave_print_internal (os, "@" + nm, pr_as_read_syntax, - current_print_indent_level ()); + current_print_indent_level ()); } octave_value @@ -1348,116 +1348,116 @@ else if (len == 2) { if (nm[0] == '.') - { - switch (nm[1]) - { - case '\'': - tnm = "transpose"; - break; + { + switch (nm[1]) + { + case '\'': + tnm = "transpose"; + break; - case '+': - tnm = "plus"; - break; + case '+': + tnm = "plus"; + break; - case '-': - tnm = "minus"; - break; + case '-': + tnm = "minus"; + break; - case '*': - tnm = "times"; - break; + case '*': + tnm = "times"; + break; - case '/': - tnm = "rdivide"; - break; + case '/': + tnm = "rdivide"; + break; - case '^': - tnm = "power"; - break; + case '^': + tnm = "power"; + break; - case '\\': - tnm = "ldivide"; - break; - } - } + case '\\': + tnm = "ldivide"; + break; + } + } else if (nm[1] == '=') - { - switch (nm[0]) - { - case '<': - tnm = "le"; - break; + { + switch (nm[0]) + { + case '<': + tnm = "le"; + break; - case '=': - tnm = "eq"; - break; + case '=': + tnm = "eq"; + break; - case '>': - tnm = "ge"; - break; + case '>': + tnm = "ge"; + break; - case '~': - case '!': - tnm = "ne"; - break; - } - } + case '~': + case '!': + tnm = "ne"; + break; + } + } else if (nm == "**") - tnm = "mpower"; + tnm = "mpower"; } else if (len == 1) { switch (nm[0]) - { - case '~': - case '!': - tnm = "not"; - break; + { + case '~': + case '!': + tnm = "not"; + break; - case '\'': - tnm = "ctranspose"; - break; + case '\'': + tnm = "ctranspose"; + break; - case '+': - tnm = "plus"; - break; + case '+': + tnm = "plus"; + break; - case '-': - tnm = "minus"; - break; + case '-': + tnm = "minus"; + break; - case '*': - tnm = "mtimes"; - break; + case '*': + tnm = "mtimes"; + break; - case '/': - tnm = "mrdivide"; - break; + case '/': + tnm = "mrdivide"; + break; - case '^': - tnm = "mpower"; - break; + case '^': + tnm = "mpower"; + break; - case '\\': - tnm = "mldivide"; - break; + case '\\': + tnm = "mldivide"; + break; - case '<': - tnm = "lt"; - break; + case '<': + tnm = "lt"; + break; - case '>': - tnm = "gt"; - break; + case '>': + tnm = "gt"; + break; - case '&': - tnm = "and"; - break; + case '&': + tnm = "and"; + break; - case '|': - tnm = "or"; - break; - } + case '|': + tnm = "or"; + break; + } } bool handle_ok = false; @@ -1558,83 +1558,83 @@ octave_fcn_handle *fh = args(0).fcn_handle_value (); if (! error_state) - { - octave_function *fcn = fh ? fh->function_value () : 0; + { + octave_function *fcn = fh ? fh->function_value () : 0; - if (fcn) - { - Octave_map m; + if (fcn) + { + Octave_map m; - std::string fh_nm = fh->fcn_name (); + std::string fh_nm = fh->fcn_name (); - if (fh_nm == octave_fcn_handle::anonymous) - { - std::ostringstream buf; - fh->print_raw (buf); - m.assign ("function", buf.str ()); + if (fh_nm == octave_fcn_handle::anonymous) + { + std::ostringstream buf; + fh->print_raw (buf); + m.assign ("function", buf.str ()); - m.assign ("type", "anonymous"); - } - else - { - m.assign ("function", fh_nm); + m.assign ("type", "anonymous"); + } + else + { + m.assign ("function", fh_nm); - if (fcn->is_nested_function ()) - { - m.assign ("type", "subfunction"); - Cell parentage (dim_vector (1, 2)); - parentage.elem(0) = fh_nm; - parentage.elem(1) = fcn->parent_fcn_name (); - m.assign ("parentage", octave_value (parentage)); - } + if (fcn->is_nested_function ()) + { + m.assign ("type", "subfunction"); + Cell parentage (dim_vector (1, 2)); + parentage.elem(0) = fh_nm; + parentage.elem(1) = fcn->parent_fcn_name (); + m.assign ("parentage", octave_value (parentage)); + } else if (fcn->is_private_function ()) - m.assign ("type", "private"); + m.assign ("type", "private"); else if (fh->is_overloaded ()) - m.assign ("type", "overloaded"); - else - m.assign ("type", "simple"); - } + m.assign ("type", "overloaded"); + else + m.assign ("type", "simple"); + } - std::string nm = fcn->fcn_file_name (); + std::string nm = fcn->fcn_file_name (); - if (fh_nm == octave_fcn_handle::anonymous) - { - m.assign ("file", nm); + if (fh_nm == octave_fcn_handle::anonymous) + { + m.assign ("file", nm); - octave_user_function *fu = fh->user_function_value (); + octave_user_function *fu = fh->user_function_value (); - std::list vars - = symbol_table::all_variables (fu->scope (), 0); + std::list vars + = symbol_table::all_variables (fu->scope (), 0); - size_t varlen = vars.size (); + size_t varlen = vars.size (); - if (varlen > 0) - { - Octave_map ws; - for (std::list::const_iterator p = vars.begin (); - p != vars.end (); p++) - { - ws.assign (p->name (), p->varval (0)); - } + if (varlen > 0) + { + Octave_map ws; + for (std::list::const_iterator p = vars.begin (); + p != vars.end (); p++) + { + ws.assign (p->name (), p->varval (0)); + } - m.assign ("workspace", ws); - } - } - else if (fcn->is_user_function () || fcn->is_user_script ()) - { - octave_function *fu = fh->function_value (); - m.assign ("file", fu->fcn_file_name ()); - } - else - m.assign ("file", ""); + m.assign ("workspace", ws); + } + } + else if (fcn->is_user_function () || fcn->is_user_script ()) + { + octave_function *fu = fh->function_value (); + m.assign ("file", fu->fcn_file_name ()); + } + else + m.assign ("file", ""); - retval = m; - } - else - error ("functions: invalid function handle object"); - } + retval = m; + } + else + error ("functions: invalid function handle object"); + } else - error ("functions: argument must be a function handle object"); + error ("functions: argument must be a function handle object"); } else print_usage (); @@ -1656,22 +1656,22 @@ octave_fcn_handle *fh = args(0).fcn_handle_value (); if (! error_state && fh) - { - std::string fh_nm = fh->fcn_name (); + { + std::string fh_nm = fh->fcn_name (); - if (fh_nm == octave_fcn_handle::anonymous) - { - std::ostringstream buf; + if (fh_nm == octave_fcn_handle::anonymous) + { + std::ostringstream buf; - fh->print_raw (buf); + fh->print_raw (buf); - retval = buf.str (); - } - else - retval = fh_nm; - } + retval = buf.str (); + } + else + retval = fh_nm; + } else - error ("func2str: expecting valid function handle as first argument"); + error ("func2str: expecting valid function handle as first argument"); } else print_usage (); @@ -1696,9 +1696,9 @@ std::string nm = args(0).string_value (); if (! error_state) - retval = make_fcn_handle (nm, nargin != 2); + retval = make_fcn_handle (nm, nargin != 2); else - error ("str2func: expecting string as first argument"); + error ("str2func: expecting string as first argument"); } else print_usage (); diff --git a/src/ov-fcn-inline.cc b/src/ov-fcn-inline.cc --- a/src/ov-fcn-inline.cc +++ b/src/ov-fcn-inline.cc @@ -56,12 +56,12 @@ DEFINE_OCTAVE_ALLOCATOR (octave_fcn_inline); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_fcn_inline, - "inline function", - "function_handle"); + "inline function", + "function_handle"); octave_fcn_inline::octave_fcn_inline (const std::string& f, - const string_vector& a, - const std::string& n) + const string_vector& a, + const std::string& n) : octave_fcn_handle (n), iftext (f), ifargs (a) { // Form a string representing the function. @@ -73,7 +73,7 @@ for (int i = 0; i < ifargs.length (); i++) { if (i > 0) - buf << ", "; + buf << ", "; buf << ifargs(i); } @@ -88,27 +88,27 @@ octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); if (fh) - { - fcn = fh->fcn_val (); + { + fcn = fh->fcn_val (); - octave_user_function *uf = fcn.user_function_value (); + octave_user_function *uf = fcn.user_function_value (); - if (uf) - { - octave_function *curr_fcn = octave_call_stack::current (); + if (uf) + { + octave_function *curr_fcn = octave_call_stack::current (); - if (curr_fcn) - { - symbol_table::scope_id parent_scope - = curr_fcn->parent_fcn_scope (); + if (curr_fcn) + { + symbol_table::scope_id parent_scope + = curr_fcn->parent_fcn_scope (); - if (parent_scope < 0) - parent_scope = curr_fcn->scope (); - - uf->stash_parent_fcn_scope (parent_scope); - } - } - } + if (parent_scope < 0) + parent_scope = curr_fcn->scope (); + + uf->stash_parent_fcn_scope (parent_scope); + } + } + } } if (fcn.is_undefined ()) @@ -158,22 +158,22 @@ { ifargs.resize (nargs); for (int i = 0; i < nargs; i++) - is >> ifargs(i); + is >> ifargs(i); is >> nm; if (nm == "0") - nm = ""; + nm = ""; skip_preceeding_newline (is); std::string buf; if (is) - { + { - // Get a line of text whitespace characters included, - // leaving newline in the stream. - buf = read_until_newline (is, true); - } + // Get a line of text whitespace characters included, + // leaving newline in the stream. + buf = read_until_newline (is, true); + } iftext = buf; @@ -208,7 +208,7 @@ bool octave_fcn_inline::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format) + oct_mach_info::float_format) { int32_t nargs; if (! is.read (reinterpret_cast (&nargs), 4)) @@ -223,43 +223,43 @@ int32_t tmp; ifargs.resize (nargs); for (int i = 0; i < nargs; i++) - { - if (! is.read (reinterpret_cast (&tmp), 4)) - return false; - if (swap) - swap_bytes<4> (&tmp); + { + if (! is.read (reinterpret_cast (&tmp), 4)) + return false; + if (swap) + swap_bytes<4> (&tmp); - OCTAVE_LOCAL_BUFFER (char, ctmp, tmp+1); - is.read (ctmp, tmp); - ifargs(i) = std::string (ctmp); + OCTAVE_LOCAL_BUFFER (char, ctmp, tmp+1); + is.read (ctmp, tmp); + ifargs(i) = std::string (ctmp); - if (! is) - return false; - } + if (! is) + return false; + } if (! is.read (reinterpret_cast (&tmp), 4)) - return false; + return false; if (swap) - swap_bytes<4> (&tmp); + swap_bytes<4> (&tmp); OCTAVE_LOCAL_BUFFER (char, ctmp1, tmp+1); is.read (ctmp1, tmp); nm = std::string (ctmp1); if (! is) - return false; + return false; if (! is.read (reinterpret_cast (&tmp), 4)) - return false; + return false; if (swap) - swap_bytes<4> (&tmp); + swap_bytes<4> (&tmp); OCTAVE_LOCAL_BUFFER (char, ctmp2, tmp+1); is.read (ctmp2, tmp); iftext = std::string (ctmp2); if (! is) - return false; + return false; octave_fcn_inline ftmp (iftext, ifargs, nm); fcn = ftmp.fcn; @@ -270,7 +270,7 @@ #if defined (HAVE_HDF5) bool octave_fcn_inline::save_hdf5 (hid_t loc_id, const char *name, - bool /* save_as_floats */) + bool /* save_as_floats */) { hid_t group_hid = -1; #if HAVE_HDF5_18 @@ -305,10 +305,10 @@ } #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "args", H5T_NATIVE_CHAR, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "args", H5T_NATIVE_CHAR, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -324,12 +324,12 @@ { const char * cptr = ifargs(i).c_str (); for (size_t j = 0; j < ifargs(i).length (); j++) - s[i*(len+1)+j] = *cptr++; + s[i*(len+1)+j] = *cptr++; s[ifargs(i).length ()] = '\0'; } retval = H5Dwrite (data_hid, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL, - H5P_DEFAULT, s) >= 0; + H5P_DEFAULT, s) >= 0; H5Dclose (data_hid); H5Sclose (space_hid); @@ -359,12 +359,12 @@ } #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, H5P_DEFAULT); #endif if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, - H5P_DEFAULT, nm.c_str ()) < 0) + H5P_DEFAULT, nm.c_str ()) < 0) { H5Sclose (space_hid); H5Tclose (type_hid); @@ -383,13 +383,13 @@ #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "iftext", type_hid, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "iftext", type_hid, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, - H5P_DEFAULT, iftext.c_str ()) < 0) + H5P_DEFAULT, iftext.c_str ()) < 0) { H5Sclose (space_hid); H5Tclose (type_hid); @@ -445,7 +445,7 @@ OCTAVE_LOCAL_BUFFER (char, s1, hdims[0] * hdims[1]); if (H5Dread (data_hid, H5T_NATIVE_UCHAR, H5S_ALL, H5S_ALL, - H5P_DEFAULT, s1) < 0) + H5P_DEFAULT, s1) < 0) { H5Dclose (data_hid); H5Sclose (space_hid); @@ -610,7 +610,7 @@ for (int i = 0; i < ifargs.length (); i++) { if (i) - buf << ", "; + buf << ", "; buf << ifargs(i); } @@ -618,7 +618,7 @@ buf << ") = " << iftext; octave_print_internal (os, buf.str (), pr_as_read_syntax, - current_print_indent_level ()); + current_print_indent_level ()); } octave_value @@ -658,137 +658,137 @@ std::string fun = args(0).string_value (); if (! error_state) - { - string_vector fargs; + { + string_vector fargs; - if (nargin == 1) - { - bool is_arg = false; - bool in_string = false; - std::string tmp_arg; - size_t i = 0; - - while (i < fun.length ()) - { - bool terminate_arg = false; - char c = fun[i++]; + if (nargin == 1) + { + bool is_arg = false; + bool in_string = false; + std::string tmp_arg; + size_t i = 0; + + while (i < fun.length ()) + { + bool terminate_arg = false; + char c = fun[i++]; - if (in_string) - { - if (c == '\'' || c == '\"') - in_string = false; - } - else if (c == '\'' || c == '\"') - { - in_string = true; - if (is_arg) - terminate_arg = true; - } - else if (! isalpha (c) && c != '_') - if (! is_arg) - continue; - else if (isdigit (c)) - tmp_arg.append (1, c); - else - { - // Before we do anything remove trailing whitespaces. - while (i < fun.length () && isspace (c)) - c = fun[i++]; - - // Do we have a variable or a function? - if (c != '(') - terminate_arg = true; - else - { - tmp_arg = std::string (); - is_arg = false; - } - } - else - { - tmp_arg.append (1, c); - is_arg = true; - } + if (in_string) + { + if (c == '\'' || c == '\"') + in_string = false; + } + else if (c == '\'' || c == '\"') + { + in_string = true; + if (is_arg) + terminate_arg = true; + } + else if (! isalpha (c) && c != '_') + if (! is_arg) + continue; + else if (isdigit (c)) + tmp_arg.append (1, c); + else + { + // Before we do anything remove trailing whitespaces. + while (i < fun.length () && isspace (c)) + c = fun[i++]; + + // Do we have a variable or a function? + if (c != '(') + terminate_arg = true; + else + { + tmp_arg = std::string (); + is_arg = false; + } + } + else + { + tmp_arg.append (1, c); + is_arg = true; + } - if (terminate_arg || (i == fun.length () && is_arg)) - { - bool have_arg = false; - - for (int j = 0; j < fargs.length (); j++) - if (tmp_arg == fargs (j)) - { - have_arg = true; - break; - } - - if (! have_arg && tmp_arg != "i" && tmp_arg != "j" && - tmp_arg != "NaN" && tmp_arg != "nan" && - tmp_arg != "Inf" && tmp_arg != "inf" && - tmp_arg != "NA" && tmp_arg != "pi" && - tmp_arg != "eps") - fargs.append (tmp_arg); + if (terminate_arg || (i == fun.length () && is_arg)) + { + bool have_arg = false; + + for (int j = 0; j < fargs.length (); j++) + if (tmp_arg == fargs (j)) + { + have_arg = true; + break; + } + + if (! have_arg && tmp_arg != "i" && tmp_arg != "j" && + tmp_arg != "NaN" && tmp_arg != "nan" && + tmp_arg != "Inf" && tmp_arg != "inf" && + tmp_arg != "NA" && tmp_arg != "pi" && + tmp_arg != "eps") + fargs.append (tmp_arg); - tmp_arg = std::string (); - is_arg = false; - } - } + tmp_arg = std::string (); + is_arg = false; + } + } - // Sort the arguments into ascii order. - fargs.sort (); - } - else if (nargin == 2 && args(1).is_numeric_type ()) - { - int n = args(1).int_value (); + // Sort the arguments into ascii order. + fargs.sort (); + } + else if (nargin == 2 && args(1).is_numeric_type ()) + { + int n = args(1).int_value (); - if (! error_state) - { - if (n >= 0) - { - fargs.resize (n+1); + if (! error_state) + { + if (n >= 0) + { + fargs.resize (n+1); - fargs(0) = "x"; + fargs(0) = "x"; - for (int i = 1; i < n+1; i++) - { - std::ostringstream buf; - buf << "P" << i; - fargs(i) = buf.str (); - } - } - else - { - error ("inline: numeric argument must be nonnegative"); - return retval; - } - } - else - { - error ("inline: expecting second argument to be an integer"); - return retval; - } - } - else - { - fargs.resize (nargin - 1); + for (int i = 1; i < n+1; i++) + { + std::ostringstream buf; + buf << "P" << i; + fargs(i) = buf.str (); + } + } + else + { + error ("inline: numeric argument must be nonnegative"); + return retval; + } + } + else + { + error ("inline: expecting second argument to be an integer"); + return retval; + } + } + else + { + fargs.resize (nargin - 1); - for (int i = 1; i < nargin; i++) - { - std::string s = args(i).string_value (); + for (int i = 1; i < nargin; i++) + { + std::string s = args(i).string_value (); - if (! error_state) - fargs(i-1) = s; - else - { - error ("inline: expecting string arguments"); - return retval; - } - } - } + if (! error_state) + fargs(i-1) = s; + else + { + error ("inline: expecting string arguments"); + return retval; + } + } + } - retval = octave_value (new octave_fcn_inline (fun, fargs)); - } + retval = octave_value (new octave_fcn_inline (fun, fargs)); + } else - error ("inline: first argument must be a string"); + error ("inline: first argument must be a string"); } else print_usage (); @@ -821,9 +821,9 @@ octave_fcn_inline* fn = args(0).fcn_inline_value (true); if (fn) - retval = octave_value (fn->fcn_text ()); + retval = octave_value (fn->fcn_text ()); else - error ("formula: must be an inline function"); + error ("formula: must be an inline function"); } else print_usage (); @@ -848,18 +848,18 @@ octave_fcn_inline *fn = args(0).fcn_inline_value (true); if (fn) - { - string_vector t1 = fn->fcn_arg_names (); + { + string_vector t1 = fn->fcn_arg_names (); - Cell t2 (dim_vector (t1.length (), 1)); + Cell t2 (dim_vector (t1.length (), 1)); - for (int i = 0; i < t1.length (); i++) - t2(i) = t1(i); + for (int i = 0; i < t1.length (); i++) + t2(i) = t1(i); - retval = t2; - } + retval = t2; + } else - error ("argnames: argument must be an inline function"); + error ("argnames: argument must be an inline function"); } else print_usage (); @@ -886,50 +886,50 @@ bool func_is_string = true; if (args(0).is_string ()) - old_func = args(0).string_value (); + old_func = args(0).string_value (); else - { - old = args(0).fcn_inline_value (true); - func_is_string = false; + { + old = args(0).fcn_inline_value (true); + func_is_string = false; - if (old) - old_func = old->fcn_text (); - else - error ("vectorize: must be a string or inline function"); - } + if (old) + old_func = old->fcn_text (); + else + error ("vectorize: must be a string or inline function"); + } if (! error_state) - { - std::string new_func; - size_t i = 0; + { + std::string new_func; + size_t i = 0; - while (i < old_func.length ()) - { - std::string t1 = old_func.substr (i, 1); + while (i < old_func.length ()) + { + std::string t1 = old_func.substr (i, 1); - if (t1 == "*" || t1 == "/" || t1 == "\\" || t1 == "^") - { - if (i && old_func.substr (i-1, 1) != ".") - new_func.append ("."); + if (t1 == "*" || t1 == "/" || t1 == "\\" || t1 == "^") + { + if (i && old_func.substr (i-1, 1) != ".") + new_func.append ("."); - // Special case for ** operator. - if (t1 == "*" && i < (old_func.length () - 1) - && old_func.substr (i+1, 1) == "*") - { - new_func.append ("*"); - i++; - } - } - new_func.append (t1); - i++; - } + // Special case for ** operator. + if (t1 == "*" && i < (old_func.length () - 1) + && old_func.substr (i+1, 1) == "*") + { + new_func.append ("*"); + i++; + } + } + new_func.append (t1); + i++; + } - if (func_is_string) - retval = octave_value (new_func); - else - retval = octave_value (new octave_fcn_inline - (new_func, old->fcn_arg_names ())); - } + if (func_is_string) + retval = octave_value (new_func); + else + retval = octave_value (new octave_fcn_inline + (new_func, old->fcn_arg_names ())); + } } else print_usage (); diff --git a/src/ov-float.cc b/src/ov-float.cc --- a/src/ov-float.cc +++ b/src/ov-float.cc @@ -83,7 +83,7 @@ FloatNDArray retval (dv, NDArray::resize_fill_value()); if (dv.numel ()) - retval(0) = scalar; + retval(0) = scalar; return retval; } @@ -92,7 +92,7 @@ FloatNDArray retval (dv); if (dv.numel ()) - retval(0) = scalar; + retval(0) = scalar; return retval; } @@ -110,13 +110,13 @@ int ival = NINT (scalar); if (ival < 0 || ival > UCHAR_MAX) - { - // FIXME -- is there something better we could do? + { + // FIXME -- is there something better we could do? - ival = 0; + ival = 0; - ::warning ("range error for conversion to character value"); - } + ::warning ("range error for conversion to character value"); + } retval = octave_value (std::string (1, static_cast (ival)), type); } @@ -162,7 +162,7 @@ bool octave_float_scalar::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) + oct_mach_info::float_format fmt) { char tmp; if (! is.read (reinterpret_cast (&tmp), 1)) @@ -181,7 +181,7 @@ bool octave_float_scalar::save_hdf5 (hid_t loc_id, const char *name, - bool /* save_as_floats */) + bool /* save_as_floats */) { hsize_t dimens[3]; hid_t space_hid = -1, data_hid = -1; @@ -191,10 +191,10 @@ if (space_hid < 0) return false; #if HAVE_HDF5_18 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_FLOAT, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_FLOAT, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -204,7 +204,7 @@ float tmp = float_value (); retval = H5Dwrite (data_hid, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, - H5P_DEFAULT, &tmp) >= 0; + H5P_DEFAULT, &tmp) >= 0; H5Dclose (data_hid); H5Sclose (space_hid); @@ -232,7 +232,7 @@ float dtmp; if (H5Dread (data_hid, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, - H5P_DEFAULT, &dtmp) < 0) + H5P_DEFAULT, &dtmp) < 0) { H5Dclose (data_hid); return false; diff --git a/src/ov-flt-complex.cc b/src/ov-flt-complex.cc --- a/src/ov-flt-complex.cc +++ b/src/ov-flt-complex.cc @@ -53,7 +53,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_float_complex); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_float_complex, - "float complex scalar", "single"); + "float complex scalar", "single"); octave_base_value * octave_float_complex::try_narrowing_conversion (void) @@ -93,7 +93,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex scalar", "real scalar"); + "complex scalar", "real scalar"); retval = std::real (scalar); @@ -107,7 +107,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex scalar", "real scalar"); + "complex scalar", "real scalar"); retval = std::real (scalar); @@ -121,7 +121,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex scalar", "real matrix"); + "complex scalar", "real matrix"); retval = Matrix (1, 1, std::real (scalar)); @@ -135,7 +135,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex scalar", "real matrix"); + "complex scalar", "real matrix"); retval = FloatMatrix (1, 1, std::real (scalar)); @@ -149,7 +149,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex scalar", "real matrix"); + "complex scalar", "real matrix"); retval = NDArray (dim_vector (1, 1), std::real (scalar)); @@ -163,7 +163,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex scalar", "real matrix"); + "complex scalar", "real matrix"); retval = FloatNDArray (dim_vector (1, 1), std::real (scalar)); @@ -214,7 +214,7 @@ FloatComplexNDArray retval (dv, FloatComplexNDArray::resize_fill_value ()); if (dv.numel ()) - retval(0) = scalar; + retval(0) = scalar; return retval; } @@ -223,7 +223,7 @@ FloatComplexNDArray retval (dv); if (dv.numel ()) - retval(0) = scalar; + retval(0) = scalar; return retval; } @@ -269,7 +269,7 @@ bool octave_float_complex::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) + oct_mach_info::float_format fmt) { char tmp; if (! is.read (reinterpret_cast (&tmp), 1)) @@ -277,7 +277,7 @@ FloatComplex ctmp; read_floats (is, reinterpret_cast (&ctmp), - static_cast (tmp), 2, swap, fmt); + static_cast (tmp), 2, swap, fmt); if (error_state || ! is) return false; @@ -289,7 +289,7 @@ bool octave_float_complex::save_hdf5 (hid_t loc_id, const char *name, - bool /* save_as_floats */) + bool /* save_as_floats */) { hsize_t dimens[3]; hid_t space_hid = -1, type_hid = -1, data_hid = -1; @@ -307,8 +307,8 @@ } #if HAVE_HDF5_18 data_hid = H5Dcreate (loc_id, name, type_hid, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); -#else + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); +#else data_hid = H5Dcreate (loc_id, name, type_hid, space_hid, H5P_DEFAULT); #endif if (data_hid < 0) @@ -320,7 +320,7 @@ FloatComplex tmp = float_complex_value (); retval = H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, H5P_DEFAULT, - &tmp) >= 0; + &tmp) >= 0; H5Dclose (data_hid); H5Tclose (type_hid); @@ -363,7 +363,7 @@ // complex scalar: FloatComplex ctmp; if (H5Dread (data_hid, complex_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, - &ctmp) >= 0) + &ctmp) >= 0) { retval = true; scalar = ctmp; diff --git a/src/ov-flt-cx-diag.cc b/src/ov-flt-cx-diag.cc --- a/src/ov-flt-cx-diag.cc +++ b/src/ov-flt-cx-diag.cc @@ -86,7 +86,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - type_name (), "real matrix"); + type_name (), "real matrix"); retval = ::real (matrix); @@ -100,7 +100,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - type_name (), "real matrix"); + type_name (), "real matrix"); retval = ::real (matrix); @@ -160,7 +160,7 @@ { float max_val, min_val; if (m.all_integers (max_val, min_val)) - st = get_save_type (max_val, min_val); + st = get_save_type (max_val, min_val); } const FloatComplex *mtmp = m.data (); @@ -171,7 +171,7 @@ bool octave_float_complex_diag_matrix::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) + oct_mach_info::float_format fmt) { int32_t r, c; char tmp; diff --git a/src/ov-flt-cx-mat.cc b/src/ov-flt-cx-mat.cc --- a/src/ov-flt-cx-mat.cc +++ b/src/ov-flt-cx-mat.cc @@ -64,7 +64,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_float_complex_matrix); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_float_complex_matrix, - "float complex matrix", "single"); + "float complex matrix", "single"); octave_base_value * octave_float_complex_matrix::try_narrowing_conversion (void) @@ -93,12 +93,12 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex matrix", "real scalar"); + "complex matrix", "real scalar"); if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "complex matrix", "real scalar"); + "complex matrix", "real scalar"); retval = std::real (matrix (0, 0)); } @@ -115,12 +115,12 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex matrix", "real scalar"); + "complex matrix", "real scalar"); if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "complex matrix", "real scalar"); + "complex matrix", "real scalar"); retval = std::real (matrix (0, 0)); } @@ -137,7 +137,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex matrix", "real matrix"); + "complex matrix", "real matrix"); retval = ::real (matrix.matrix_value ()); @@ -151,7 +151,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex matrix", "real matrix"); + "complex matrix", "real matrix"); retval = ::real (matrix.matrix_value ()); @@ -168,7 +168,7 @@ if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "complex matrix", "complex scalar"); + "complex matrix", "complex scalar"); retval = matrix (0, 0); } @@ -188,7 +188,7 @@ if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "complex matrix", "complex scalar"); + "complex matrix", "complex scalar"); retval = matrix (0, 0); } @@ -229,14 +229,14 @@ if (! frc_str_conv) gripe_implicit_conversion ("Octave:num-to-str", - "complex matrix", "string"); + "complex matrix", "string"); else { retval = charNDArray (dims ()); octave_idx_type nel = numel (); for (octave_idx_type i = 0; i < nel; i++) - retval.elem (i) = static_cast(std::real (matrix.elem (i))); + retval.elem (i) = static_cast(std::real (matrix.elem (i))); } return retval; @@ -255,7 +255,7 @@ if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", - "complex matrix", "real matrix"); + "complex matrix", "real matrix"); retval = SparseMatrix (::real (complex_matrix_value ())); @@ -292,7 +292,7 @@ os << "# ndims: " << d.length () << "\n"; for (int i = 0; i < d.length (); i++) - os << " " << d (i); + os << " " << d (i); os << "\n" << tmp; } @@ -301,7 +301,7 @@ // Keep this case, rather than use generic code above for backward // compatiability. Makes load_ascii much more complex!! os << "# rows: " << rows () << "\n" - << "# columns: " << columns () << "\n"; + << "# columns: " << columns () << "\n"; os << complex_matrix_value (); } @@ -325,20 +325,20 @@ if (extract_keyword (is, keywords, kw, val, true)) { if (kw == "ndims") - { - int mdims = static_cast (val); + { + int mdims = static_cast (val); - if (mdims >= 0) - { - dim_vector dv; - dv.resize (mdims); + if (mdims >= 0) + { + dim_vector dv; + dv.resize (mdims); - for (int i = 0; i < mdims; i++) - is >> dv(i); + for (int i = 0; i < mdims; i++) + is >> dv(i); - if (is) - { - FloatComplexNDArray tmp(dv); + if (is) + { + FloatComplexNDArray tmp(dv); is >> tmp; @@ -349,51 +349,51 @@ error ("load: failed to load matrix constant"); success = false; } - } - else - { - error ("load: failed to read dimensions"); - success = false; - } - } - else - { - error ("load: failed to extract number of dimensions"); - success = false; - } - } + } + else + { + error ("load: failed to read dimensions"); + success = false; + } + } + else + { + error ("load: failed to extract number of dimensions"); + success = false; + } + } else if (kw == "rows") - { - octave_idx_type nr = val; - octave_idx_type nc = 0; + { + octave_idx_type nr = val; + octave_idx_type nc = 0; - if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0) - { - if (nr > 0 && nc > 0) - { - FloatComplexMatrix tmp (nr, nc); - is >> tmp; - if (is) - matrix = tmp; - else - { - error ("load: failed to load matrix constant"); - success = false; - } - } - else if (nr == 0 || nc == 0) - matrix = FloatComplexMatrix (nr, nc); - else - panic_impossible (); - } - else - { - error ("load: failed to extract number of rows and columns"); - success = false; - } - } + if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0) + { + if (nr > 0 && nc > 0) + { + FloatComplexMatrix tmp (nr, nc); + is >> tmp; + if (is) + matrix = tmp; + else + { + error ("load: failed to load matrix constant"); + success = false; + } + } + else if (nr == 0 || nc == 0) + matrix = FloatComplexMatrix (nr, nc); + else + panic_impossible (); + } + else + { + error ("load: failed to extract number of rows and columns"); + success = false; + } + } else - panic_impossible (); + panic_impossible (); } else { @@ -426,7 +426,7 @@ { float max_val, min_val; if (m.all_integers (max_val, min_val)) - st = get_save_type (max_val, min_val); + st = get_save_type (max_val, min_val); } const FloatComplex *mtmp = m.data (); @@ -437,7 +437,7 @@ bool octave_float_complex_matrix::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) + oct_mach_info::float_format fmt) { char tmp; int32_t mdims; @@ -453,35 +453,35 @@ dv.resize (mdims); for (int i = 0; i < mdims; i++) - { - if (! is.read (reinterpret_cast (&di), 4)) - return false; - if (swap) - swap_bytes<4> (&di); - dv(i) = di; - } + { + if (! is.read (reinterpret_cast (&di), 4)) + return false; + if (swap) + swap_bytes<4> (&di); + dv(i) = di; + } // Convert an array with a single dimension to be a row vector. // Octave should never write files like this, other software // might. if (mdims == 1) - { - mdims = 2; - dv.resize (mdims); - dv(1) = dv(0); - dv(0) = 1; - } + { + mdims = 2; + dv.resize (mdims); + dv(1) = dv(0); + dv(0) = 1; + } if (! is.read (reinterpret_cast (&tmp), 1)) - return false; + return false; FloatComplexNDArray m(dv); FloatComplex *im = m.fortran_vec (); read_floats (is, reinterpret_cast (im), - static_cast (tmp), 2 * dv.numel (), swap, fmt); + static_cast (tmp), 2 * dv.numel (), swap, fmt); if (error_state || ! is) - return false; + return false; matrix = m; } else @@ -489,18 +489,18 @@ int32_t nr, nc; nr = mdims; if (! is.read (reinterpret_cast (&nc), 4)) - return false; + return false; if (swap) - swap_bytes<4> (&nc); + swap_bytes<4> (&nc); if (! is.read (reinterpret_cast (&tmp), 1)) - return false; + return false; FloatComplexMatrix m (nr, nc); FloatComplex *im = m.fortran_vec (); octave_idx_type len = nr * nc; read_floats (is, reinterpret_cast (im), - static_cast (tmp), 2*len, swap, fmt); + static_cast (tmp), 2*len, swap, fmt); if (error_state || ! is) - return false; + return false; matrix = m; } return true; @@ -539,8 +539,8 @@ float max_val, min_val; if (m.all_integers (max_val, min_val)) - save_type_hid - = save_type_to_hdf5 (get_save_type (max_val, min_val)); + save_type_hid + = save_type_to_hdf5 (get_save_type (max_val, min_val)); } #endif /* HAVE_HDF5_INT2FLOAT_CONVERSIONS */ @@ -552,7 +552,7 @@ } #if HAVE_HDF5_18 data_hid = H5Dcreate (loc_id, name, type_hid, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (loc_id, name, type_hid, space_hid, H5P_DEFAULT); #endif @@ -570,11 +570,11 @@ { FloatComplex *mtmp = m.fortran_vec (); if (H5Dwrite (data_hid, complex_type_hid, H5S_ALL, H5S_ALL, H5P_DEFAULT, - mtmp) < 0) - { - H5Tclose (complex_type_hid); - retval = false; - } + mtmp) < 0) + { + H5Tclose (complex_type_hid); + retval = false; + } } H5Tclose (complex_type_hid); @@ -641,13 +641,13 @@ { dv.resize (rank); for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--) - dv(j) = hdims[i]; + dv(j) = hdims[i]; } FloatComplexNDArray m (dv); FloatComplex *reim = m.fortran_vec (); if (H5Dread (data_hid, complex_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, - reim) >= 0) + reim) >= 0) { retval = true; matrix = m; @@ -664,10 +664,10 @@ void octave_float_complex_matrix::print_raw (std::ostream& os, - bool pr_as_read_syntax) const + bool pr_as_read_syntax) const { octave_print_internal (os, matrix, pr_as_read_syntax, - current_print_indent_level ()); + current_print_indent_level ()); } mxArray * diff --git a/src/ov-flt-re-diag.cc b/src/ov-flt-re-diag.cc --- a/src/ov-flt-re-diag.cc +++ b/src/ov-flt-re-diag.cc @@ -116,7 +116,7 @@ bool octave_float_diag_matrix::save_binary (std::ostream& os, - bool& /* save_as_floats*/) + bool& /* save_as_floats*/) { int32_t r = matrix.rows (), c = matrix.cols (); @@ -129,7 +129,7 @@ { float max_val, min_val; if (m.all_integers (max_val, min_val)) - st = get_save_type (max_val, min_val); + st = get_save_type (max_val, min_val); } const float *mtmp = m.data (); @@ -140,7 +140,7 @@ bool octave_float_diag_matrix::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) + oct_mach_info::float_format fmt) { int32_t r, c; char tmp; diff --git a/src/ov-flt-re-mat.cc b/src/ov-flt-re-mat.cc --- a/src/ov-flt-re-mat.cc +++ b/src/ov-flt-re-mat.cc @@ -97,7 +97,7 @@ if (numel () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "real matrix", "real scalar"); + "real matrix", "real scalar"); retval = matrix (0, 0); } @@ -115,7 +115,7 @@ if (numel () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "real matrix", "real scalar"); + "real matrix", "real scalar"); retval = matrix (0, 0); } @@ -149,7 +149,7 @@ if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "real matrix", "complex scalar"); + "real matrix", "complex scalar"); retval = matrix (0, 0); } @@ -169,7 +169,7 @@ if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "real matrix", "complex scalar"); + "real matrix", "complex scalar"); retval = matrix (0, 0); } @@ -281,30 +281,30 @@ float d = matrix (i); if (xisnan (d)) - { - ::error ("invalid conversion from NaN to character"); - return retval; - } + { + ::error ("invalid conversion from NaN to character"); + return retval; + } else - { - int ival = NINT (d); + { + int ival = NINT (d); - if (ival < 0 || ival > UCHAR_MAX) - { - // FIXME -- is there something - // better we could do? + if (ival < 0 || ival > UCHAR_MAX) + { + // FIXME -- is there something + // better we could do? - ival = 0; + ival = 0; - if (! warned) - { - ::warning ("range error for conversion to character value"); - warned = true; - } - } + if (! warned) + { + ::warning ("range error for conversion to character value"); + warned = true; + } + } - chm (i) = static_cast (ival); - } + chm (i) = static_cast (ival); + } } retval = octave_value (chm, type); @@ -324,7 +324,7 @@ os << "# ndims: " << d.length () << "\n"; for (int i=0; i < d.length (); i++) - os << " " << d (i); + os << " " << d (i); os << "\n" << tmp; } @@ -333,7 +333,7 @@ // Keep this case, rather than use generic code above for backward // compatiability. Makes load_ascii much more complex!! os << "# rows: " << rows () << "\n" - << "# columns: " << columns () << "\n"; + << "# columns: " << columns () << "\n"; os << float_matrix_value (); } @@ -357,20 +357,20 @@ if (extract_keyword (is, keywords, kw, val, true)) { if (kw == "ndims") - { - int mdims = static_cast (val); + { + int mdims = static_cast (val); - if (mdims >= 0) - { - dim_vector dv; - dv.resize (mdims); + if (mdims >= 0) + { + dim_vector dv; + dv.resize (mdims); - for (int i = 0; i < mdims; i++) - is >> dv(i); + for (int i = 0; i < mdims; i++) + is >> dv(i); - if (is) - { - FloatNDArray tmp(dv); + if (is) + { + FloatNDArray tmp(dv); is >> tmp; @@ -381,51 +381,51 @@ error ("load: failed to load matrix constant"); success = false; } - } - else - { - error ("load: failed to read dimensions"); - success = false; - } - } - else - { - error ("load: failed to extract number of dimensions"); - success = false; - } - } + } + else + { + error ("load: failed to read dimensions"); + success = false; + } + } + else + { + error ("load: failed to extract number of dimensions"); + success = false; + } + } else if (kw == "rows") - { - octave_idx_type nr = val; - octave_idx_type nc = 0; + { + octave_idx_type nr = val; + octave_idx_type nc = 0; - if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0) - { - if (nr > 0 && nc > 0) - { - FloatMatrix tmp (nr, nc); - is >> tmp; - if (is) - matrix = tmp; - else - { - error ("load: failed to load matrix constant"); - success = false; - } - } - else if (nr == 0 || nc == 0) - matrix = FloatMatrix (nr, nc); - else - panic_impossible (); - } - else - { - error ("load: failed to extract number of rows and columns"); - success = false; - } - } + if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0) + { + if (nr > 0 && nc > 0) + { + FloatMatrix tmp (nr, nc); + is >> tmp; + if (is) + matrix = tmp; + else + { + error ("load: failed to load matrix constant"); + success = false; + } + } + else if (nr == 0 || nc == 0) + matrix = FloatMatrix (nr, nc); + else + panic_impossible (); + } + else + { + error ("load: failed to extract number of rows and columns"); + success = false; + } + } else - panic_impossible (); + panic_impossible (); } else { @@ -459,7 +459,7 @@ { float max_val, min_val; if (m.all_integers (max_val, min_val)) - st = get_save_type (max_val, min_val); + st = get_save_type (max_val, min_val); } const float *mtmp = m.data (); @@ -470,7 +470,7 @@ bool octave_float_matrix::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) + oct_mach_info::float_format fmt) { char tmp; int32_t mdims; @@ -486,34 +486,34 @@ dv.resize (mdims); for (int i = 0; i < mdims; i++) - { - if (! is.read (reinterpret_cast (&di), 4)) - return false; - if (swap) - swap_bytes<4> (&di); - dv(i) = di; - } + { + if (! is.read (reinterpret_cast (&di), 4)) + return false; + if (swap) + swap_bytes<4> (&di); + dv(i) = di; + } // Convert an array with a single dimension to be a row vector. // Octave should never write files like this, other software // might. if (mdims == 1) - { - mdims = 2; - dv.resize (mdims); - dv(1) = dv(0); - dv(0) = 1; - } + { + mdims = 2; + dv.resize (mdims); + dv(1) = dv(0); + dv(0) = 1; + } if (! is.read (reinterpret_cast (&tmp), 1)) - return false; + return false; FloatNDArray m(dv); float *re = m.fortran_vec (); read_floats (is, re, static_cast (tmp), dv.numel (), swap, fmt); if (error_state || ! is) - return false; + return false; matrix = m; } else @@ -521,17 +521,17 @@ int32_t nr, nc; nr = mdims; if (! is.read (reinterpret_cast (&nc), 4)) - return false; + return false; if (swap) - swap_bytes<4> (&nc); + swap_bytes<4> (&nc); if (! is.read (reinterpret_cast (&tmp), 1)) - return false; + return false; FloatMatrix m (nr, nc); float *re = m.fortran_vec (); octave_idx_type len = nr * nc; read_floats (is, re, static_cast (tmp), len, swap, fmt); if (error_state || ! is) - return false; + return false; matrix = m; } return true; @@ -571,16 +571,16 @@ float max_val, min_val; if (m.all_integers (max_val, min_val)) - save_type_hid - = save_type_to_hdf5 (get_save_type (max_val, min_val)); + save_type_hid + = save_type_to_hdf5 (get_save_type (max_val, min_val)); } #endif /* HAVE_HDF5_INT2FLOAT_CONVERSIONS */ #if HAVE_HDF5_18 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -590,7 +590,7 @@ float *mtmp = m.fortran_vec (); retval = H5Dwrite (data_hid, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, - H5P_DEFAULT, mtmp) >= 0; + H5P_DEFAULT, mtmp) >= 0; H5Dclose (data_hid); H5Sclose (space_hid); @@ -642,13 +642,13 @@ { dv.resize (rank); for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--) - dv(j) = hdims[i]; + dv(j) = hdims[i]; } FloatNDArray m (dv); float *re = m.fortran_vec (); if (H5Dread (data_hid, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, - H5P_DEFAULT, re) >= 0) + H5P_DEFAULT, re) >= 0) { retval = true; matrix = m; @@ -664,10 +664,10 @@ void octave_float_matrix::print_raw (std::ostream& os, - bool pr_as_read_syntax) const + bool pr_as_read_syntax) const { octave_print_internal (os, matrix, pr_as_read_syntax, - current_print_indent_level ()); + current_print_indent_level ()); } mxArray * @@ -810,27 +810,27 @@ { if (args(0).is_diag_matrix ()) { - if (args(0).is_complex_type ()) - { - OCTAVE_TYPE_CONV_BODY3 (single, octave_float_complex_diag_matrix, octave_float_complex); - } - else - { - OCTAVE_TYPE_CONV_BODY3 (single, octave_float_diag_matrix, octave_float_scalar); - } + if (args(0).is_complex_type ()) + { + OCTAVE_TYPE_CONV_BODY3 (single, octave_float_complex_diag_matrix, octave_float_complex); + } + else + { + OCTAVE_TYPE_CONV_BODY3 (single, octave_float_diag_matrix, octave_float_scalar); + } } else if (args(0).is_sparse_type ()) - { - error ("single: sparse type do not support single precision"); - } + { + error ("single: sparse type do not support single precision"); + } else if (args(0).is_complex_type ()) - { - OCTAVE_TYPE_CONV_BODY3 (single, octave_float_complex_matrix, octave_float_complex); - } + { + OCTAVE_TYPE_CONV_BODY3 (single, octave_float_complex_matrix, octave_float_complex); + } else - { - OCTAVE_TYPE_CONV_BODY3 (single, octave_float_matrix, octave_float_scalar); - } + { + OCTAVE_TYPE_CONV_BODY3 (single, octave_float_matrix, octave_float_scalar); + } } else print_usage (); diff --git a/src/ov-int16.cc b/src/ov-int16.cc --- a/src/ov-int16.cc +++ b/src/ov-int16.cc @@ -63,7 +63,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_int16_matrix); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_int16_matrix, - "int16 matrix", "int16"); + "int16 matrix", "int16"); template class octave_base_scalar; @@ -72,7 +72,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_int16_scalar); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_int16_scalar, - "int16 scalar", "int16"); + "int16 scalar", "int16"); DEFUN (int16, args, , "-*- texinfo -*-\n\ diff --git a/src/ov-int32.cc b/src/ov-int32.cc --- a/src/ov-int32.cc +++ b/src/ov-int32.cc @@ -63,7 +63,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_int32_matrix); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_int32_matrix, - "int32 matrix", "int32"); + "int32 matrix", "int32"); template class octave_base_scalar; @@ -72,7 +72,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_int32_scalar); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_int32_scalar, - "int32 scalar", "int32"); + "int32 scalar", "int32"); DEFUN (int32, args, , "-*- texinfo -*-\n\ diff --git a/src/ov-int64.cc b/src/ov-int64.cc --- a/src/ov-int64.cc +++ b/src/ov-int64.cc @@ -63,7 +63,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_int64_matrix); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_int64_matrix, - "int64 matrix", "int64"); + "int64 matrix", "int64"); template class octave_base_scalar; @@ -72,7 +72,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_int64_scalar); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_int64_scalar, - "int64 scalar", "int64"); + "int64 scalar", "int64"); DEFUN (int64, args, , "-*- texinfo -*-\n\ diff --git a/src/ov-int8.cc b/src/ov-int8.cc --- a/src/ov-int8.cc +++ b/src/ov-int8.cc @@ -63,7 +63,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_int8_matrix); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_int8_matrix, - "int8 matrix", "int8"); + "int8 matrix", "int8"); template class octave_base_scalar; @@ -72,7 +72,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_int8_scalar); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_int8_scalar, - "int8 scalar", "int8"); + "int8 scalar", "int8"); DEFUN (int8, args, , "-*- texinfo -*-\n\ diff --git a/src/ov-mex-fcn.cc b/src/ov-mex-fcn.cc --- a/src/ov-mex-fcn.cc +++ b/src/ov-mex-fcn.cc @@ -39,7 +39,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_mex_function); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_mex_function, - "mex function", "mex function"); + "mex function", "mex function"); octave_mex_function::octave_mex_function (void *fptr, bool fmex, const octave_shlib& shl, @@ -78,8 +78,8 @@ octave_value_list octave_mex_function::subsref (const std::string& type, - const std::list& idx, - int nargout) + const std::list& idx, + int nargout) { octave_value_list retval; @@ -87,17 +87,17 @@ { case '(': { - int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; + int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; - retval = do_multi_index_op (tmp_nargout, idx.front ()); + retval = do_multi_index_op (tmp_nargout, idx.front ()); } break; case '{': case '.': { - std::string nm = type_name (); - error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + std::string nm = type_name (); + error ("%s cannot be indexed with %c", nm.c_str (), type[0]); } break; @@ -124,11 +124,11 @@ // FIXME -- shouldn't this declaration be a header file somewhere? extern octave_value_list call_mex (bool have_fmex, void *f, const octave_value_list& args, - int nargout, octave_mex_function *curr_mex_fcn); + int nargout, octave_mex_function *curr_mex_fcn); octave_value_list octave_mex_function::do_multi_index_op (int nargout, - const octave_value_list& args) + const octave_value_list& args) { octave_value_list retval; @@ -146,13 +146,13 @@ frame.add_fcn (octave_call_stack::pop); try - { - retval = call_mex (have_fmex, mex_fcn_ptr, args, nargout, this); - } + { + retval = call_mex (have_fmex, mex_fcn_ptr, args, nargout, this); + } catch (octave_execution_exception) - { - gripe_library_execution_error (); - } + { + gripe_library_execution_error (); + } } return retval; diff --git a/src/ov-perm.cc b/src/ov-perm.cc --- a/src/ov-perm.cc +++ b/src/ov-perm.cc @@ -51,8 +51,8 @@ case '{': case '.': { - std::string nm = type_name (); - error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + std::string nm = type_name (); + error ("%s cannot be indexed with %c", nm.c_str (), type[0]); } break; @@ -136,7 +136,7 @@ if (numel () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - type_name (), "real scalar"); + type_name (), "real scalar"); retval = matrix (0, 0); } @@ -154,7 +154,7 @@ if (numel () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - type_name (), "real scalar"); + type_name (), "real scalar"); retval = matrix (0, 0); } @@ -174,7 +174,7 @@ if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - type_name (), "complex scalar"); + type_name (), "complex scalar"); retval = matrix (0, 0); } @@ -194,7 +194,7 @@ if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - type_name (), "complex scalar"); + type_name (), "complex scalar"); retval = matrix (0, 0); } @@ -281,10 +281,10 @@ ColumnVector tmp (n); is >> tmp; if (!is) - { - error ("load: failed to load permutation matrix constant"); - success = false; - } + { + error ("load: failed to load permutation matrix constant"); + success = false; + } else { Array pvec (n); @@ -336,21 +336,21 @@ { int nel = m.numel (); for (int i = 0; i < nel; i++) - switch (sizeof (octave_idx_type)) - { - case 8: - swap_bytes<8> (&m(i)); - break; - case 4: - swap_bytes<4> (&m(i)); - break; - case 2: - swap_bytes<2> (&m(i)); - break; - case 1: - default: - break; - } + switch (sizeof (octave_idx_type)) + { + case 8: + swap_bytes<8> (&m(i)); + break; + case 4: + swap_bytes<4> (&m(i)); + break; + case 2: + swap_bytes<2> (&m(i)); + break; + case 1: + default: + break; + } } matrix = PermMatrix (m, colp); @@ -396,7 +396,7 @@ void octave_perm_matrix::print_info (std::ostream& os, - const std::string& prefix) const + const std::string& prefix) const { matrix.print_info (os, prefix); } diff --git a/src/ov-range.cc b/src/ov-range.cc --- a/src/ov-range.cc +++ b/src/ov-range.cc @@ -90,7 +90,7 @@ octave_value octave_range::subsref (const std::string& type, - const std::list& idx) + const std::list& idx) { octave_value retval; @@ -103,8 +103,8 @@ case '{': case '.': { - std::string nm = type_name (); - error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + std::string nm = type_name (); + error ("%s cannot be indexed with %c", nm.c_str (), type[0]); } break; @@ -152,7 +152,7 @@ if (nel > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "range", "real scalar"); + "range", "real scalar"); retval = range.base (); } @@ -172,7 +172,7 @@ if (nel > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "range", "real scalar"); + "range", "real scalar"); retval = range.base (); } @@ -254,7 +254,7 @@ if (nel > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "range", "complex scalar"); + "range", "complex scalar"); retval = range.base (); } @@ -276,7 +276,7 @@ if (nel > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "range", "complex scalar"); + "range", "complex scalar"); retval = range.base (); } @@ -315,7 +315,7 @@ octave_range::print_raw (std::ostream& os, bool pr_as_read_syntax) const { octave_print_internal (os, range, pr_as_read_syntax, - current_print_indent_level ()); + current_print_indent_level ()); } bool @@ -349,9 +349,9 @@ while (is.get (c)) { if (c == ' ' || c == '\t' || c == '\n') - ; // Skip whitespace on way to beginning of next line. + ; // Skip whitespace on way to beginning of next line. else - break; + break; } skip_until_newline (is, false); @@ -411,7 +411,7 @@ bool octave_range::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format /* fmt */) + oct_mach_info::float_format /* fmt */) { char tmp; if (! is.read (reinterpret_cast (&tmp), 1)) @@ -456,7 +456,7 @@ bool octave_range::save_hdf5 (hid_t loc_id, const char *name, - bool /* save_as_floats */) + bool /* save_as_floats */) { hsize_t dimens[3]; hid_t space_hid = -1, type_hid = -1, data_hid = -1; @@ -473,7 +473,7 @@ } #if HAVE_HDF5_18 data_hid = H5Dcreate (loc_id, name, type_hid, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (loc_id, name, type_hid, space_hid, H5P_DEFAULT); #endif @@ -491,7 +491,7 @@ range_vals[2] = r.inc (); retval = H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, H5P_DEFAULT, - range_vals) >= 0; + range_vals) >= 0; H5Dclose (data_hid); H5Tclose (type_hid); @@ -534,7 +534,7 @@ double rangevals[3]; if (H5Dread (data_hid, range_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, - rangevals) >= 0) + rangevals) >= 0) { retval = true; Range r (rangevals[0], rangevals[1], rangevals[2]); diff --git a/src/ov-re-diag.cc b/src/ov-re-diag.cc --- a/src/ov-re-diag.cc +++ b/src/ov-re-diag.cc @@ -187,18 +187,18 @@ if (save_as_floats) { if (m.too_large_for_float ()) - { - warning ("save: some values too large to save as floats --"); - warning ("save: saving as doubles instead"); - } + { + warning ("save: some values too large to save as floats --"); + warning ("save: saving as doubles instead"); + } else - st = LS_FLOAT; + st = LS_FLOAT; } else if (matrix.length () > 8192) // FIXME -- make this configurable. { double max_val, min_val; if (m.all_integers (max_val, min_val)) - st = get_save_type (max_val, min_val); + st = get_save_type (max_val, min_val); } const double *mtmp = m.data (); @@ -209,7 +209,7 @@ bool octave_diag_matrix::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) + oct_mach_info::float_format fmt) { int32_t r, c; char tmp; diff --git a/src/ov-re-mat.cc b/src/ov-re-mat.cc --- a/src/ov-re-mat.cc +++ b/src/ov-re-mat.cc @@ -111,7 +111,7 @@ if (numel () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "real matrix", "real scalar"); + "real matrix", "real scalar"); retval = matrix (0, 0); } @@ -129,7 +129,7 @@ if (numel () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "real matrix", "real scalar"); + "real matrix", "real scalar"); retval = matrix (0, 0); } @@ -163,7 +163,7 @@ if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "real matrix", "complex scalar"); + "real matrix", "complex scalar"); retval = matrix (0, 0); } @@ -183,7 +183,7 @@ if (rows () > 0 && columns () > 0) { gripe_implicit_conversion ("Octave:array-as-scalar", - "real matrix", "complex scalar"); + "real matrix", "complex scalar"); retval = matrix (0, 0); } @@ -317,30 +317,30 @@ double d = matrix (i); if (xisnan (d)) - { - ::error ("invalid conversion from NaN to character"); - return retval; - } + { + ::error ("invalid conversion from NaN to character"); + return retval; + } else - { - int ival = NINT (d); + { + int ival = NINT (d); - if (ival < 0 || ival > UCHAR_MAX) - { - // FIXME -- is there something - // better we could do? + if (ival < 0 || ival > UCHAR_MAX) + { + // FIXME -- is there something + // better we could do? - ival = 0; + ival = 0; - if (! warned) - { - ::warning ("range error for conversion to character value"); - warned = true; - } - } + if (! warned) + { + ::warning ("range error for conversion to character value"); + warned = true; + } + } - chm (i) = static_cast (ival); - } + chm (i) = static_cast (ival); + } } retval = octave_value (chm, type); @@ -360,7 +360,7 @@ os << "# ndims: " << d.length () << "\n"; for (int i=0; i < d.length (); i++) - os << " " << d (i); + os << " " << d (i); os << "\n" << tmp; } @@ -369,7 +369,7 @@ // Keep this case, rather than use generic code above for backward // compatiability. Makes load_ascii much more complex!! os << "# rows: " << rows () << "\n" - << "# columns: " << columns () << "\n"; + << "# columns: " << columns () << "\n"; os << matrix_value (); } @@ -393,20 +393,20 @@ if (extract_keyword (is, keywords, kw, val, true)) { if (kw == "ndims") - { - int mdims = static_cast (val); + { + int mdims = static_cast (val); - if (mdims >= 0) - { - dim_vector dv; - dv.resize (mdims); + if (mdims >= 0) + { + dim_vector dv; + dv.resize (mdims); - for (int i = 0; i < mdims; i++) - is >> dv(i); + for (int i = 0; i < mdims; i++) + is >> dv(i); - if (is) - { - NDArray tmp(dv); + if (is) + { + NDArray tmp(dv); is >> tmp; @@ -417,51 +417,51 @@ error ("load: failed to load matrix constant"); success = false; } - } - else - { - error ("load: failed to read dimensions"); - success = false; - } - } - else - { - error ("load: failed to extract number of dimensions"); - success = false; - } - } + } + else + { + error ("load: failed to read dimensions"); + success = false; + } + } + else + { + error ("load: failed to extract number of dimensions"); + success = false; + } + } else if (kw == "rows") - { - octave_idx_type nr = val; - octave_idx_type nc = 0; + { + octave_idx_type nr = val; + octave_idx_type nc = 0; - if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0) - { - if (nr > 0 && nc > 0) - { - Matrix tmp (nr, nc); - is >> tmp; - if (is) - matrix = tmp; - else - { - error ("load: failed to load matrix constant"); - success = false; - } - } - else if (nr == 0 || nc == 0) - matrix = Matrix (nr, nc); - else - panic_impossible (); - } - else - { - error ("load: failed to extract number of rows and columns"); - success = false; - } - } + if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0) + { + if (nr > 0 && nc > 0) + { + Matrix tmp (nr, nc); + is >> tmp; + if (is) + matrix = tmp; + else + { + error ("load: failed to load matrix constant"); + success = false; + } + } + else if (nr == 0 || nc == 0) + matrix = Matrix (nr, nc); + else + panic_impossible (); + } + else + { + error ("load: failed to extract number of rows and columns"); + success = false; + } + } else - panic_impossible (); + panic_impossible (); } else { @@ -494,18 +494,18 @@ if (save_as_floats) { if (m.too_large_for_float ()) - { - warning ("save: some values too large to save as floats --"); - warning ("save: saving as doubles instead"); - } + { + warning ("save: some values too large to save as floats --"); + warning ("save: saving as doubles instead"); + } else - st = LS_FLOAT; + st = LS_FLOAT; } else if (d.numel () > 8192) // FIXME -- make this configurable. { double max_val, min_val; if (m.all_integers (max_val, min_val)) - st = get_save_type (max_val, min_val); + st = get_save_type (max_val, min_val); } const double *mtmp = m.data (); @@ -516,7 +516,7 @@ bool octave_matrix::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) + oct_mach_info::float_format fmt) { char tmp; int32_t mdims; @@ -532,34 +532,34 @@ dv.resize (mdims); for (int i = 0; i < mdims; i++) - { - if (! is.read (reinterpret_cast (&di), 4)) - return false; - if (swap) - swap_bytes<4> (&di); - dv(i) = di; - } + { + if (! is.read (reinterpret_cast (&di), 4)) + return false; + if (swap) + swap_bytes<4> (&di); + dv(i) = di; + } // Convert an array with a single dimension to be a row vector. // Octave should never write files like this, other software // might. if (mdims == 1) - { - mdims = 2; - dv.resize (mdims); - dv(1) = dv(0); - dv(0) = 1; - } + { + mdims = 2; + dv.resize (mdims); + dv(1) = dv(0); + dv(0) = 1; + } if (! is.read (reinterpret_cast (&tmp), 1)) - return false; + return false; NDArray m(dv); double *re = m.fortran_vec (); read_doubles (is, re, static_cast (tmp), dv.numel (), swap, fmt); if (error_state || ! is) - return false; + return false; matrix = m; } else @@ -567,17 +567,17 @@ int32_t nr, nc; nr = mdims; if (! is.read (reinterpret_cast (&nc), 4)) - return false; + return false; if (swap) - swap_bytes<4> (&nc); + swap_bytes<4> (&nc); if (! is.read (reinterpret_cast (&tmp), 1)) - return false; + return false; Matrix m (nr, nc); double *re = m.fortran_vec (); octave_idx_type len = nr * nc; read_doubles (is, re, static_cast (tmp), len, swap, fmt); if (error_state || ! is) - return false; + return false; matrix = m; } return true; @@ -613,12 +613,12 @@ if (save_as_floats) { if (m.too_large_for_float ()) - { - warning ("save: some values too large to save as floats --"); - warning ("save: saving as doubles instead"); - } + { + warning ("save: some values too large to save as floats --"); + warning ("save: saving as doubles instead"); + } else - save_type_hid = H5T_NATIVE_FLOAT; + save_type_hid = H5T_NATIVE_FLOAT; } #if HAVE_HDF5_INT2FLOAT_CONVERSIONS // hdf5 currently doesn't support float/integer conversions @@ -627,17 +627,17 @@ double max_val, min_val; if (m.all_integers (max_val, min_val)) - save_type_hid - = save_type_to_hdf5 (get_save_type (max_val, min_val)); + save_type_hid + = save_type_to_hdf5 (get_save_type (max_val, min_val)); } #endif /* HAVE_HDF5_INT2FLOAT_CONVERSIONS */ #if HAVE_HDF5_18 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -647,7 +647,7 @@ double *mtmp = m.fortran_vec (); retval = H5Dwrite (data_hid, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, mtmp) >= 0; + H5P_DEFAULT, mtmp) >= 0; H5Dclose (data_hid); H5Sclose (space_hid); @@ -699,13 +699,13 @@ { dv.resize (rank); for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--) - dv(j) = hdims[i]; + dv(j) = hdims[i]; } NDArray m (dv); double *re = m.fortran_vec (); if (H5Dread (data_hid, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, re) >= 0) + H5P_DEFAULT, re) >= 0) { retval = true; matrix = m; @@ -721,10 +721,10 @@ void octave_matrix::print_raw (std::ostream& os, - bool pr_as_read_syntax) const + bool pr_as_read_syntax) const { octave_print_internal (os, matrix, pr_as_read_syntax, - current_print_indent_level ()); + current_print_indent_level ()); } mxArray * @@ -877,34 +877,34 @@ } else if (args(0).is_diag_matrix ()) { - if (args(0).is_complex_type ()) - { - OCTAVE_TYPE_CONV_BODY3 (double, octave_complex_diag_matrix, octave_complex); - } - else - { - OCTAVE_TYPE_CONV_BODY3 (double, octave_diag_matrix, octave_scalar); - } + if (args(0).is_complex_type ()) + { + OCTAVE_TYPE_CONV_BODY3 (double, octave_complex_diag_matrix, octave_complex); + } + else + { + OCTAVE_TYPE_CONV_BODY3 (double, octave_diag_matrix, octave_scalar); + } } else if (args(0).is_sparse_type ()) - { - if (args(0).is_complex_type ()) - { - OCTAVE_TYPE_CONV_BODY3 (double, octave_sparse_complex_matrix, octave_complex); - } - else - { - OCTAVE_TYPE_CONV_BODY3 (double, octave_sparse_matrix, octave_scalar); - } - } + { + if (args(0).is_complex_type ()) + { + OCTAVE_TYPE_CONV_BODY3 (double, octave_sparse_complex_matrix, octave_complex); + } + else + { + OCTAVE_TYPE_CONV_BODY3 (double, octave_sparse_matrix, octave_scalar); + } + } else if (args(0).is_complex_type ()) - { - OCTAVE_TYPE_CONV_BODY3 (double, octave_complex_matrix, octave_complex); - } + { + OCTAVE_TYPE_CONV_BODY3 (double, octave_complex_matrix, octave_complex); + } else - { - OCTAVE_TYPE_CONV_BODY3 (double, octave_matrix, octave_scalar); - } + { + OCTAVE_TYPE_CONV_BODY3 (double, octave_matrix, octave_scalar); + } } else print_usage (); diff --git a/src/ov-re-sparse.cc b/src/ov-re-sparse.cc --- a/src/ov-re-sparse.cc +++ b/src/ov-re-sparse.cc @@ -77,16 +77,16 @@ // Note that for the second test, this means it becomes approximative // since it involves a cast to double to avoid issues of overflow if (matrix.rows () == 1 && matrix.cols () == 1) - { - // Const copy of the matrix, so the right version of () operator used - const SparseMatrix tmp (matrix); + { + // Const copy of the matrix, so the right version of () operator used + const SparseMatrix tmp (matrix); - retval = new octave_scalar (tmp (0)); - } + retval = new octave_scalar (tmp (0)); + } else if (matrix.cols () > 0 && matrix.rows () > 0 - && (double (matrix.byte_size ()) > double (matrix.rows ()) - * double (matrix.cols ()) * sizeof (double))) - retval = new octave_matrix (matrix.matrix_value ()); + && (double (matrix.byte_size ()) > double (matrix.rows ()) + * double (matrix.cols ()) * sizeof (double))) + retval = new octave_matrix (matrix.matrix_value ()); } return retval; @@ -100,8 +100,8 @@ if (numel () > 0) { if (numel () > 1) - gripe_implicit_conversion ("Octave:array-as-scalar", - "real sparse matrix", "real scalar"); + gripe_implicit_conversion ("Octave:array-as-scalar", + "real sparse matrix", "real scalar"); retval = matrix (0, 0); } @@ -122,8 +122,8 @@ if (rows () > 0 && columns () > 0) { if (numel () > 1) - gripe_implicit_conversion ("Octave:array-as-scalar", - "real sparse matrix", "complex scalar"); + gripe_implicit_conversion ("Octave:array-as-scalar", + "real sparse matrix", "complex scalar"); retval = matrix (0, 0); } @@ -212,44 +212,44 @@ octave_idx_type nr = matrix.rows (); octave_idx_type nc = matrix.cols (); charNDArray chm (dv, static_cast (0)); - + bool warned = false; for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = matrix.cidx(j); - i < matrix.cidx(j+1); i++) - { - octave_quit (); + for (octave_idx_type i = matrix.cidx(j); + i < matrix.cidx(j+1); i++) + { + octave_quit (); - double d = matrix.data (i); + double d = matrix.data (i); - if (xisnan (d)) - { - ::error ("invalid conversion from NaN to character"); - return retval; - } - else - { - int ival = NINT (d); + if (xisnan (d)) + { + ::error ("invalid conversion from NaN to character"); + return retval; + } + else + { + int ival = NINT (d); - if (ival < 0 || ival > UCHAR_MAX) - { - // FIXME -- is there something - // better we could do? + if (ival < 0 || ival > UCHAR_MAX) + { + // FIXME -- is there something + // better we could do? - ival = 0; + ival = 0; - if (! warned) - { - ::warning ("range error for conversion to character value"); - warned = true; - } - } + if (! warned) + { + ::warning ("range error for conversion to character value"); + warned = true; + } + } - chm (matrix.ridx(i) + j * nr) = - static_cast (ival); - } - } + chm (matrix.ridx(i) + j * nr) = + static_cast (ival); + } + } retval = octave_value (chm, type); } @@ -289,18 +289,18 @@ if (save_as_floats) { if (matrix.too_large_for_float ()) - { - warning ("save: some values too large to save as floats --"); - warning ("save: saving as doubles instead"); - } + { + warning ("save: some values too large to save as floats --"); + warning ("save: saving as doubles instead"); + } else - st = LS_FLOAT; + st = LS_FLOAT; } else if (matrix.nzmax () > 8192) // FIXME -- make this configurable. { double max_val, min_val; if (matrix.all_integers (max_val, min_val)) - st = get_save_type (max_val, min_val); + st = get_save_type (max_val, min_val); } // add one to the printed indices to go from @@ -326,7 +326,7 @@ bool octave_sparse_matrix::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) + oct_mach_info::float_format fmt) { int32_t nz, nc, nr, tmp; char ctmp; @@ -357,16 +357,16 @@ } SparseMatrix m (static_cast (nr), - static_cast (nc), - static_cast (nz)); + static_cast (nc), + static_cast (nz)); for (int i = 0; i < nc+1; i++) { octave_quit (); if (! is.read (reinterpret_cast (&tmp), 4)) - return false; + return false; if (swap) - swap_bytes<4> (&tmp); + swap_bytes<4> (&tmp); m.xcidx(i) = tmp; } @@ -374,9 +374,9 @@ { octave_quit (); if (! is.read (reinterpret_cast (&tmp), 4)) - return false; + return false; if (swap) - swap_bytes<4> (&tmp); + swap_bytes<4> (&tmp); m.xridx(i) = tmp; } @@ -400,7 +400,7 @@ bool octave_sparse_matrix::save_hdf5 (hid_t loc_id, const char *name, - bool save_as_floats) + bool save_as_floats) { dim_vector dv = dims (); int empty = save_hdf5_empty (loc_id, name, dv); @@ -432,10 +432,10 @@ } #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "nr", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "nr", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -446,7 +446,7 @@ tmp = m.rows (); retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, - &tmp) >= 0; + &tmp) >= 0; H5Dclose (data_hid); if (!retval) { @@ -456,10 +456,10 @@ } #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "nc", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "nc", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -470,7 +470,7 @@ tmp = m.cols (); retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, - &tmp) >= 0; + &tmp) >= 0; H5Dclose (data_hid); if (!retval) { @@ -481,10 +481,10 @@ #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "nz", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "nz", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -495,7 +495,7 @@ tmp = m.nzmax (); retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, - &tmp) >= 0; + &tmp) >= 0; H5Dclose (data_hid); if (!retval) { @@ -519,10 +519,10 @@ #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "cidx", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "cidx", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -533,7 +533,7 @@ octave_idx_type * itmp = m.xcidx (); retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, - itmp) >= 0; + itmp) >= 0; H5Dclose (data_hid); if (!retval) { @@ -556,10 +556,10 @@ } #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "ridx", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "ridx", H5T_NATIVE_IDX, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -570,7 +570,7 @@ itmp = m.xridx (); retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, - itmp) >= 0; + itmp) >= 0; H5Dclose (data_hid); if (!retval) { @@ -584,12 +584,12 @@ if (save_as_floats) { if (m.too_large_for_float ()) - { - warning ("save: some values too large to save as floats --"); - warning ("save: saving as doubles instead"); - } + { + warning ("save: some values too large to save as floats --"); + warning ("save: saving as doubles instead"); + } else - save_type_hid = H5T_NATIVE_FLOAT; + save_type_hid = H5T_NATIVE_FLOAT; } #if HAVE_HDF5_INT2FLOAT_CONVERSIONS // hdf5 currently doesn't support float/integer conversions @@ -598,17 +598,17 @@ double max_val, min_val; if (m.all_integers (max_val, min_val)) - save_type_hid - = save_type_to_hdf5 (get_save_type (max_val, min_val)); + save_type_hid + = save_type_to_hdf5 (get_save_type (max_val, min_val)); } #endif /* HAVE_HDF5_INT2FLOAT_CONVERSIONS */ #if HAVE_HDF5_18 data_hid = H5Dcreate (group_hid, "data", save_type_hid, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (group_hid, "data", save_type_hid, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -619,7 +619,7 @@ double * dtmp = m.xdata (); retval = H5Dwrite (data_hid, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, dtmp) >= 0; + H5P_DEFAULT, dtmp) >= 0; H5Dclose (data_hid); H5Sclose (space_hid); H5Gclose (group_hid); @@ -664,7 +664,7 @@ } if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, - H5P_DEFAULT, &nr) < 0) + H5P_DEFAULT, &nr) < 0) { H5Dclose (data_hid); H5Gclose (group_hid); @@ -689,7 +689,7 @@ } if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, - H5P_DEFAULT, &nc) < 0) + H5P_DEFAULT, &nc) < 0) { H5Dclose (data_hid); H5Gclose (group_hid); @@ -714,7 +714,7 @@ } if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, - H5P_DEFAULT, &nz) < 0) + H5P_DEFAULT, &nz) < 0) { H5Dclose (data_hid); H5Gclose (group_hid); @@ -724,8 +724,8 @@ H5Dclose (data_hid); SparseMatrix m (static_cast (nr), - static_cast (nc), - static_cast (nz)); + static_cast (nc), + static_cast (nz)); #if HAVE_HDF5_18 data_hid = H5Dopen (group_hid, "cidx", H5P_DEFAULT); @@ -759,7 +759,7 @@ octave_idx_type *itmp = m.xcidx (); if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, - H5P_DEFAULT, itmp) < 0) + H5P_DEFAULT, itmp) < 0) { H5Sclose (space_hid); H5Dclose (data_hid); @@ -798,7 +798,7 @@ itmp = m.xridx (); if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, - H5P_DEFAULT, itmp) < 0) + H5P_DEFAULT, itmp) < 0) { H5Sclose (space_hid); H5Dclose (data_hid); @@ -838,7 +838,7 @@ double *dtmp = m.xdata (); bool retval = false; if (H5Dread (data_hid, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, dtmp) >= 0 + H5P_DEFAULT, dtmp) >= 0 && m.indices_ok ()) { retval = true; diff --git a/src/ov-scalar.cc b/src/ov-scalar.cc --- a/src/ov-scalar.cc +++ b/src/ov-scalar.cc @@ -98,7 +98,7 @@ NDArray retval (dv, NDArray::resize_fill_value()); if (dv.numel ()) - retval(0) = scalar; + retval(0) = scalar; return retval; } @@ -107,7 +107,7 @@ NDArray retval (dv); if (dv.numel ()) - retval(0) = scalar; + retval(0) = scalar; return retval; } @@ -125,13 +125,13 @@ int ival = NINT (scalar); if (ival < 0 || ival > UCHAR_MAX) - { - // FIXME -- is there something better we could do? + { + // FIXME -- is there something better we could do? - ival = 0; + ival = 0; - ::warning ("range error for conversion to character value"); - } + ::warning ("range error for conversion to character value"); + } retval = octave_value (std::string (1, static_cast (ival)), type); } @@ -177,7 +177,7 @@ bool octave_scalar::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) + oct_mach_info::float_format fmt) { char tmp; if (! is.read (reinterpret_cast (&tmp), 1)) @@ -196,7 +196,7 @@ bool octave_scalar::save_hdf5 (hid_t loc_id, const char *name, - bool /* save_as_floats */) + bool /* save_as_floats */) { hsize_t dimens[3]; hid_t space_hid = -1, data_hid = -1; @@ -207,10 +207,10 @@ #if HAVE_HDF5_18 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_DOUBLE, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_DOUBLE, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -220,7 +220,7 @@ double tmp = double_value (); retval = H5Dwrite (data_hid, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, &tmp) >= 0; + H5P_DEFAULT, &tmp) >= 0; H5Dclose (data_hid); H5Sclose (space_hid); @@ -248,7 +248,7 @@ double dtmp; if (H5Dread (data_hid, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, &dtmp) < 0) + H5P_DEFAULT, &dtmp) < 0) { H5Dclose (data_hid); return false; diff --git a/src/ov-str-mat.cc b/src/ov-str-mat.cc --- a/src/ov-str-mat.cc +++ b/src/ov-str-mat.cc @@ -88,7 +88,7 @@ octave_value octave_char_matrix_str::do_index_op_internal (const octave_value_list& idx, - bool resize_ok, char type) + bool resize_ok, char type) { octave_value retval; @@ -102,35 +102,35 @@ case 1: { - idx_vector i = idx (0).index_vector (); + idx_vector i = idx (0).index_vector (); - if (! error_state) - retval = octave_value (charNDArray (matrix.index (i, resize_ok)), - type); + if (! error_state) + retval = octave_value (charNDArray (matrix.index (i, resize_ok)), + type); } break; case 2: { - idx_vector i = idx (0).index_vector (); - idx_vector j = idx (1).index_vector (); + idx_vector i = idx (0).index_vector (); + idx_vector j = idx (1).index_vector (); - if (! error_state) - retval = octave_value (charNDArray (matrix.index (i, j, resize_ok)), - type); + if (! error_state) + retval = octave_value (charNDArray (matrix.index (i, j, resize_ok)), + type); } break; default: { - Array idx_vec (len); + Array idx_vec (len); - for (octave_idx_type i = 0; i < len; i++) - idx_vec(i) = idx(i).index_vector (); + for (octave_idx_type i = 0; i < len; i++) + idx_vec(i) = idx(i).index_vector (); - if (! error_state) - retval = octave_value (charNDArray (matrix.index (idx_vec, resize_ok)), - type); + if (! error_state) + retval = octave_value (charNDArray (matrix.index (idx_vec, resize_ok)), + type); } break; } @@ -157,8 +157,8 @@ else \ { \ warning_with_id ("Octave:str-to-num", \ - "implicit conversion from %s to %s", \ - "string", TNAME); \ + "implicit conversion from %s to %s", \ + "string", TNAME); \ \ retval = octave_char_matrix::FCN (); \ } \ @@ -199,7 +199,7 @@ octave_char_matrix_str::complex_array_value (bool force_string_conv) const { CHAR_MATRIX_CONV (ComplexNDArray, , "complex N-d array", - complex_array_value); + complex_array_value); } string_vector @@ -216,7 +216,7 @@ retval.resize (n); for (octave_idx_type i = 0; i < n; i++) - retval[i] = chm.row_as_string (i); + retval[i] = chm.row_as_string (i); } else error ("invalid conversion of charNDArray to string_vector"); @@ -245,7 +245,7 @@ octave_char_matrix_str::print_raw (std::ostream& os, bool pr_as_read_syntax) const { octave_print_internal (os, matrix, pr_as_read_syntax, - current_print_indent_level (), true); + current_print_indent_level (), true); } bool @@ -257,7 +257,7 @@ charNDArray tmp = char_array_value (); os << "# ndims: " << d.length () << "\n"; for (int i=0; i < d.length (); i++) - os << " " << d (i); + os << " " << d (i); os << "\n"; os.write (tmp.fortran_vec (), d.numel ()); os << "\n"; @@ -270,16 +270,16 @@ octave_idx_type elements = chm.rows (); os << "# elements: " << elements << "\n"; for (octave_idx_type i = 0; i < elements; i++) - { - unsigned len = chm.cols (); - os << "# length: " << len << "\n"; - std::string tstr = chm.row_as_string (i, false, true); - const char *tmp = tstr.data (); - if (tstr.length () > len) - panic_impossible (); - os.write (tmp, len); - os << "\n"; - } + { + unsigned len = chm.cols (); + os << "# length: " << len << "\n"; + std::string tstr = chm.row_as_string (i, false, true); + const char *tmp = tstr.data (); + if (tstr.length () > len) + panic_impossible (); + os.write (tmp, len); + os << "\n"; + } } return true; @@ -302,135 +302,135 @@ if (extract_keyword (is, keywords, kw, val, true)) { if (kw == "ndims") - { - int mdims = val; + { + int mdims = val; - if (mdims >= 0) - { - dim_vector dv; - dv.resize (mdims); + if (mdims >= 0) + { + dim_vector dv; + dv.resize (mdims); - for (int i = 0; i < mdims; i++) - is >> dv(i); + for (int i = 0; i < mdims; i++) + is >> dv(i); - if (is) - { - charNDArray tmp(dv); + if (is) + { + charNDArray tmp(dv); - if (tmp.is_empty ()) - matrix = tmp; - else - { - char *ftmp = tmp.fortran_vec (); + if (tmp.is_empty ()) + matrix = tmp; + else + { + char *ftmp = tmp.fortran_vec (); - skip_preceeding_newline (is); + skip_preceeding_newline (is); - if (! is.read (ftmp, dv.numel ()) || !is) - { - error ("load: failed to load string constant"); - success = false; - } - else - matrix = tmp; - } - } - else - { - error ("load: failed to read dimensions"); - success = false; - } - } - else - { - error ("load: failed to extract matrix size"); - success = false; - } - } + if (! is.read (ftmp, dv.numel ()) || !is) + { + error ("load: failed to load string constant"); + success = false; + } + else + matrix = tmp; + } + } + else + { + error ("load: failed to read dimensions"); + success = false; + } + } + else + { + error ("load: failed to extract matrix size"); + success = false; + } + } else if (kw == "elements") - { - int elements = val; + { + int elements = val; - if (elements >= 0) - { - // FIXME -- need to be able to get max length - // before doing anything. + if (elements >= 0) + { + // FIXME -- need to be able to get max length + // before doing anything. - charMatrix chm (elements, 0); - int max_len = 0; - for (int i = 0; i < elements; i++) - { - int len; - if (extract_keyword (is, "length", len) && len >= 0) - { - // Use this instead of a C-style character - // buffer so that we can properly handle - // embedded NUL characters. - charMatrix tmp (1, len); - char *ptmp = tmp.fortran_vec (); + charMatrix chm (elements, 0); + int max_len = 0; + for (int i = 0; i < elements; i++) + { + int len; + if (extract_keyword (is, "length", len) && len >= 0) + { + // Use this instead of a C-style character + // buffer so that we can properly handle + // embedded NUL characters. + charMatrix tmp (1, len); + char *ptmp = tmp.fortran_vec (); - if (len > 0 && ! is.read (ptmp, len)) - { - error ("load: failed to load string constant"); - success = false; - break; - } - else - { - if (len > max_len) - { - max_len = len; - chm.resize (elements, max_len, 0); - } + if (len > 0 && ! is.read (ptmp, len)) + { + error ("load: failed to load string constant"); + success = false; + break; + } + else + { + if (len > max_len) + { + max_len = len; + chm.resize (elements, max_len, 0); + } - chm.insert (tmp, i, 0); - } - } - else - { - error ("load: failed to extract string length for element %d", - i+1); - success = false; - } - } - - if (! error_state) - matrix = chm; - } - else - { - error ("load: failed to extract number of string elements"); - success = false; - } - } + chm.insert (tmp, i, 0); + } + } + else + { + error ("load: failed to extract string length for element %d", + i+1); + success = false; + } + } + + if (! error_state) + matrix = chm; + } + else + { + error ("load: failed to extract number of string elements"); + success = false; + } + } else if (kw == "length") - { - int len = val; + { + int len = val; - if (len >= 0) - { - // This is cruft for backward compatiability, - // but relatively harmless. + if (len >= 0) + { + // This is cruft for backward compatiability, + // but relatively harmless. - // Use this instead of a C-style character buffer so - // that we can properly handle embedded NUL characters. - charMatrix tmp (1, len); - char *ptmp = tmp.fortran_vec (); + // Use this instead of a C-style character buffer so + // that we can properly handle embedded NUL characters. + charMatrix tmp (1, len); + char *ptmp = tmp.fortran_vec (); - if (len > 0 && ! is.read (ptmp, len)) - { - error ("load: failed to load string constant"); - } - else - { - if (is) - matrix = tmp; - else - error ("load: failed to load string constant"); - } - } - } + if (len > 0 && ! is.read (ptmp, len)) + { + error ("load: failed to load string constant"); + } + else + { + if (is) + matrix = tmp; + else + error ("load: failed to load string constant"); + } + } + } else - panic_impossible (); + panic_impossible (); } else { @@ -443,7 +443,7 @@ bool octave_char_matrix_str::save_binary (std::ostream& os, - bool& /* save_as_floats */) + bool& /* save_as_floats */) { dim_vector d = dims (); if (d.length() < 1) @@ -465,7 +465,7 @@ bool octave_char_matrix_str::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format /* fmt */) + oct_mach_info::float_format /* fmt */) { int32_t elements; if (! is.read (reinterpret_cast (&elements), 4)) @@ -481,32 +481,32 @@ dv.resize (mdims); for (int i = 0; i < mdims; i++) - { - if (! is.read (reinterpret_cast (&di), 4)) - return false; - if (swap) - swap_bytes<4> (&di); - dv(i) = di; - } + { + if (! is.read (reinterpret_cast (&di), 4)) + return false; + if (swap) + swap_bytes<4> (&di); + dv(i) = di; + } // Convert an array with a single dimension to be a row vector. // Octave should never write files like this, other software // might. if (mdims == 1) - { - mdims = 2; - dv.resize (mdims); - dv(1) = dv(0); - dv(0) = 1; - } + { + mdims = 2; + dv.resize (mdims); + dv(1) = dv(0); + dv(0) = 1; + } charNDArray m(dv); char *tmp = m.fortran_vec (); is.read (tmp, dv.numel ()); if (error_state || ! is) - return false; + return false; matrix = m; } else @@ -514,23 +514,23 @@ charMatrix chm (elements, 0); int max_len = 0; for (int i = 0; i < elements; i++) - { - int32_t len; - if (! is.read (reinterpret_cast (&len), 4)) - return false; - if (swap) - swap_bytes<4> (&len); - charMatrix btmp (1, len); - char *pbtmp = btmp.fortran_vec (); - if (! is.read (pbtmp, len)) - return false; - if (len > max_len) - { - max_len = len; - chm.resize (elements, max_len, 0); - } - chm.insert (btmp, i, 0); - } + { + int32_t len; + if (! is.read (reinterpret_cast (&len), 4)) + return false; + if (swap) + swap_bytes<4> (&len); + charMatrix btmp (1, len); + char *pbtmp = btmp.fortran_vec (); + if (! is.read (pbtmp, len)) + return false; + if (len > max_len) + { + max_len = len; + chm.resize (elements, max_len, 0); + } + chm.insert (btmp, i, 0); + } matrix = chm; } return true; @@ -540,7 +540,7 @@ bool octave_char_matrix_str::save_hdf5 (hid_t loc_id, const char *name, - bool /* save_as_floats */) + bool /* save_as_floats */) { dim_vector dv = dims (); int empty = save_hdf5_empty (loc_id, name, dv); @@ -563,10 +563,10 @@ return false; #if HAVE_HDF5_18 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_CHAR, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_CHAR, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (data_hid < 0) { @@ -580,7 +580,7 @@ s[i] = m(i); retval = H5Dwrite (data_hid, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL, - H5P_DEFAULT, s) >= 0; + H5P_DEFAULT, s) >= 0; H5Dclose (data_hid); H5Sclose (space_hid); @@ -613,12 +613,12 @@ if (type_class_hid == H5T_INTEGER) { if (rank < 1) - { - H5Tclose (type_hid); - H5Sclose (space_hid); - H5Dclose (data_hid); - return false; - } + { + H5Tclose (type_hid); + H5Sclose (space_hid); + H5Dclose (data_hid); + return false; + } OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); @@ -627,26 +627,26 @@ // Octave uses column-major, while HDF5 uses row-major ordering if (rank == 1) - { - dv.resize (2); - dv(0) = 1; - dv(1) = hdims[0]; - } + { + dv.resize (2); + dv(0) = 1; + dv(1) = hdims[0]; + } else - { - dv.resize (rank); - for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--) - dv(j) = hdims[i]; - } + { + dv.resize (rank); + for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--) + dv(j) = hdims[i]; + } charNDArray m (dv); char *str = m.fortran_vec (); if (H5Dread (data_hid, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL, - H5P_DEFAULT, str) >= 0) - { - retval = true; - matrix = m; - } + H5P_DEFAULT, str) >= 0) + { + retval = true; + matrix = m; + } H5Tclose (type_hid); H5Sclose (space_hid); @@ -658,98 +658,98 @@ // This is cruft for backward compatiability and easy data // importation if (rank == 0) - { - // a single string: - int slen = H5Tget_size (type_hid); - if (slen < 0) - { - H5Tclose (type_hid); - H5Sclose (space_hid); - H5Dclose (data_hid); - return false; - } - else - { - OCTAVE_LOCAL_BUFFER (char, s, slen); - // create datatype for (null-terminated) string - // to read into: - hid_t st_id = H5Tcopy (H5T_C_S1); - H5Tset_size (st_id, slen); - if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, s) < 0) - { - H5Tclose (st_id); - H5Tclose (type_hid); - H5Sclose (space_hid); - H5Dclose (data_hid); - return false; - } + { + // a single string: + int slen = H5Tget_size (type_hid); + if (slen < 0) + { + H5Tclose (type_hid); + H5Sclose (space_hid); + H5Dclose (data_hid); + return false; + } + else + { + OCTAVE_LOCAL_BUFFER (char, s, slen); + // create datatype for (null-terminated) string + // to read into: + hid_t st_id = H5Tcopy (H5T_C_S1); + H5Tset_size (st_id, slen); + if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, s) < 0) + { + H5Tclose (st_id); + H5Tclose (type_hid); + H5Sclose (space_hid); + H5Dclose (data_hid); + return false; + } - matrix = charMatrix (s); - - H5Tclose (st_id); - H5Tclose (type_hid); - H5Sclose (space_hid); - H5Dclose (data_hid); - return true; - } - } + matrix = charMatrix (s); + + H5Tclose (st_id); + H5Tclose (type_hid); + H5Sclose (space_hid); + H5Dclose (data_hid); + return true; + } + } else if (rank == 1) - { - // string vector - hsize_t elements, maxdim; - H5Sget_simple_extent_dims (space_hid, &elements, &maxdim); - int slen = H5Tget_size (type_hid); - if (slen < 0) - { - H5Tclose (type_hid); - H5Sclose (space_hid); - H5Dclose (data_hid); - return false; - } - else - { - // hdf5 string arrays store strings of all the - // same physical length (I think), which is - // slightly wasteful, but oh well. - - OCTAVE_LOCAL_BUFFER (char, s, elements * slen); + { + // string vector + hsize_t elements, maxdim; + H5Sget_simple_extent_dims (space_hid, &elements, &maxdim); + int slen = H5Tget_size (type_hid); + if (slen < 0) + { + H5Tclose (type_hid); + H5Sclose (space_hid); + H5Dclose (data_hid); + return false; + } + else + { + // hdf5 string arrays store strings of all the + // same physical length (I think), which is + // slightly wasteful, but oh well. + + OCTAVE_LOCAL_BUFFER (char, s, elements * slen); - // create datatype for (null-terminated) string - // to read into: - hid_t st_id = H5Tcopy (H5T_C_S1); - H5Tset_size (st_id, slen); + // create datatype for (null-terminated) string + // to read into: + hid_t st_id = H5Tcopy (H5T_C_S1); + H5Tset_size (st_id, slen); - if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, s) < 0) - { - H5Tclose (st_id); - H5Tclose (type_hid); - H5Sclose (space_hid); - H5Dclose (data_hid); - return false; - } + if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, s) < 0) + { + H5Tclose (st_id); + H5Tclose (type_hid); + H5Sclose (space_hid); + H5Dclose (data_hid); + return false; + } - charMatrix chm (elements, slen - 1); - for (hsize_t i = 0; i < elements; ++i) - { - chm.insert (s + i*slen, i, 0); - } + charMatrix chm (elements, slen - 1); + for (hsize_t i = 0; i < elements; ++i) + { + chm.insert (s + i*slen, i, 0); + } - matrix = chm; + matrix = chm; - H5Tclose (st_id); - H5Tclose (type_hid); - H5Sclose (space_hid); - H5Dclose (data_hid); - return true; - } - } + H5Tclose (st_id); + H5Tclose (type_hid); + H5Sclose (space_hid); + H5Dclose (data_hid); + return true; + } + } else - { - H5Tclose (type_hid); - H5Sclose (space_hid); - H5Dclose (data_hid); - return false; - } + { + H5Tclose (type_hid); + H5Sclose (space_hid); + H5Dclose (data_hid); + return false; + } } return retval; diff --git a/src/ov-struct.cc b/src/ov-struct.cc --- a/src/ov-struct.cc +++ b/src/ov-struct.cc @@ -100,8 +100,8 @@ octave_value_list octave_struct::subsref (const std::string& type, - const std::list& idx, - int nargout) + const std::list& idx, + int nargout) { octave_value_list retval; @@ -111,38 +111,38 @@ { case '(': { - if (type.length () > 1 && type[1] == '.') - { - std::list::const_iterator p = idx.begin (); - octave_value_list key_idx = *++p; + if (type.length () > 1 && type[1] == '.') + { + std::list::const_iterator p = idx.begin (); + octave_value_list key_idx = *++p; - const Cell tmp = dotref (key_idx); + const Cell tmp = dotref (key_idx); - if (! error_state) - { - const Cell t = tmp.index (idx.front ()); + if (! error_state) + { + const Cell t = tmp.index (idx.front ()); - retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); + retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); - // We handled two index elements, so tell - // next_subsref to skip both of them. + // We handled two index elements, so tell + // next_subsref to skip both of them. - skip++; - } - } - else - retval(0) = map.index (idx.front ()); + skip++; + } + } + else + retval(0) = map.index (idx.front ()); } break; case '.': { - if (map.numel() > 0) - { - const Cell t = dotref (idx.front ()); + if (map.numel() > 0) + { + const Cell t = dotref (idx.front ()); - retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); - } + retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); + } } break; @@ -166,8 +166,8 @@ octave_value octave_struct::subsref (const std::string& type, - const std::list& idx, - bool auto_add) + const std::list& idx, + bool auto_add) { octave_value retval; @@ -177,38 +177,38 @@ { case '(': { - if (type.length () > 1 && type[1] == '.') - { - std::list::const_iterator p = idx.begin (); - octave_value_list key_idx = *++p; + if (type.length () > 1 && type[1] == '.') + { + std::list::const_iterator p = idx.begin (); + octave_value_list key_idx = *++p; - const Cell tmp = dotref (key_idx, auto_add); + const Cell tmp = dotref (key_idx, auto_add); - if (! error_state) - { - const Cell t = tmp.index (idx.front (), auto_add); + if (! error_state) + { + const Cell t = tmp.index (idx.front (), auto_add); - retval = (t.length () == 1) ? t(0) : octave_value (t, true); + retval = (t.length () == 1) ? t(0) : octave_value (t, true); - // We handled two index elements, so tell - // next_subsref to skip both of them. + // We handled two index elements, so tell + // next_subsref to skip both of them. - skip++; - } - } - else - retval = map.index (idx.front (), auto_add); + skip++; + } + } + else + retval = map.index (idx.front (), auto_add); } break; case '.': { - if (map.numel() > 0) - { - const Cell t = dotref (idx.front (), auto_add); + if (map.numel() > 0) + { + const Cell t = dotref (idx.front (), auto_add); - retval = (t.length () == 1) ? t(0) : octave_value (t, true); - } + retval = (t.length () == 1) ? t(0) : octave_value (t, true); + } } break; @@ -240,7 +240,7 @@ octave_value octave_struct::numeric_conv (const octave_value& val, - const std::string& type) + const std::string& type) { octave_value retval; @@ -254,8 +254,8 @@ octave_value octave_struct::subsasgn (const std::string& type, - const std::list& idx, - const octave_value& rhs) + const std::list& idx, + const octave_value& rhs) { octave_value retval; @@ -272,19 +272,19 @@ if (n > 1 && ! (type.length () == 2 && type[0] == '(' && type[1] == '.')) { switch (type[0]) - { - case '(': - { - if (type.length () > 1 && type[1] == '.') - { - std::list::const_iterator p = idx.begin (); - octave_value_list t_idx = *p; + { + case '(': + { + if (type.length () > 1 && type[1] == '.') + { + std::list::const_iterator p = idx.begin (); + octave_value_list t_idx = *p; - octave_value_list key_idx = *++p; + octave_value_list key_idx = *++p; - assert (key_idx.length () == 1); + assert (key_idx.length () == 1); - std::string key = key_idx(0).string_value (); + std::string key = key_idx(0).string_value (); std::list next_idx (idx); @@ -305,8 +305,8 @@ } // FIXME: better code reuse? cf. octave_cell::subsasgn and the case below. - if (! error_state) - { + if (! error_state) + { if (tmpc.numel () == 1) { octave_value& tmp = tmpc(0); @@ -325,20 +325,20 @@ } else gripe_indexed_cs_list (); - } - } - else - gripe_invalid_index_for_assignment (); - } - break; + } + } + else + gripe_invalid_index_for_assignment (); + } + break; - case '.': - { - octave_value_list key_idx = idx.front (); + case '.': + { + octave_value_list key_idx = idx.front (); - assert (key_idx.length () == 1); + assert (key_idx.length () == 1); - std::string key = key_idx(0).string_value (); + std::string key = key_idx(0).string_value (); std::list next_idx (idx); @@ -376,36 +376,36 @@ else gripe_indexed_cs_list (); } - } - break; + } + break; - case '{': - gripe_invalid_index_type (type_name (), type[0]); - break; + case '{': + gripe_invalid_index_type (type_name (), type[0]); + break; - default: - panic_impossible (); - } + default: + panic_impossible (); + } } if (! error_state) { switch (type[0]) - { - case '(': - { - if (n > 1 && type[1] == '.') - { - std::list::const_iterator p = idx.begin (); - octave_value_list key_idx = *++p; + { + case '(': + { + if (n > 1 && type[1] == '.') + { + std::list::const_iterator p = idx.begin (); + octave_value_list key_idx = *++p; octave_value_list idxf = idx.front (); - assert (key_idx.length () == 1); + assert (key_idx.length () == 1); - std::string key = key_idx(0).string_value (); + std::string key = key_idx(0).string_value (); - if (! error_state) - { + if (! error_state) + { if (t_rhs.is_cs_list ()) { Cell tmp_cell = Cell (t_rhs.list_value ()); @@ -449,94 +449,94 @@ else if (! error_state) gripe_nonbraced_cs_list_assignment (); } - } - else - gripe_failed_assignment (); - } - else - { - if (t_rhs.is_map()) - { - Octave_map rhs_map = t_rhs.map_value (); + } + else + gripe_failed_assignment (); + } + else + { + if (t_rhs.is_map()) + { + Octave_map rhs_map = t_rhs.map_value (); - if (! error_state) - { - map.assign (idx.front (), rhs_map); + if (! error_state) + { + map.assign (idx.front (), rhs_map); - if (! error_state) - { - count++; - retval = octave_value (this); - } - else - gripe_failed_assignment (); - } - else - error ("invalid structure assignment"); - } - else - { - if (t_rhs.is_null_value()) - { - map.maybe_delete_elements (idx.front()); + if (! error_state) + { + count++; + retval = octave_value (this); + } + else + gripe_failed_assignment (); + } + else + error ("invalid structure assignment"); + } + else + { + if (t_rhs.is_null_value()) + { + map.maybe_delete_elements (idx.front()); - if (! error_state) - { - count++; - retval = octave_value (this); - } - else - gripe_failed_assignment (); - } - else - error ("invalid structure assignment"); - } - } - } - break; + if (! error_state) + { + count++; + retval = octave_value (this); + } + else + gripe_failed_assignment (); + } + else + error ("invalid structure assignment"); + } + } + } + break; - case '.': - { - octave_value_list key_idx = idx.front (); + case '.': + { + octave_value_list key_idx = idx.front (); - assert (key_idx.length () == 1); + assert (key_idx.length () == 1); - std::string key = key_idx(0).string_value (); + std::string key = key_idx(0).string_value (); - if (t_rhs.is_cs_list ()) - { - Cell tmp_cell = Cell (t_rhs.list_value ()); + if (t_rhs.is_cs_list ()) + { + Cell tmp_cell = Cell (t_rhs.list_value ()); - // The shape of the RHS is irrelevant, we just want - // the number of elements to agree and to preserve the - // shape of the left hand side of the assignment. + // The shape of the RHS is irrelevant, we just want + // the number of elements to agree and to preserve the + // shape of the left hand side of the assignment. - if (numel () == tmp_cell.numel ()) - tmp_cell = tmp_cell.reshape (dims ()); + if (numel () == tmp_cell.numel ()) + tmp_cell = tmp_cell.reshape (dims ()); - map.assign (key, tmp_cell); - } - else + map.assign (key, tmp_cell); + } + else // Regularize a null matrix if stored into a struct component. - map.assign (key, t_rhs.storable_value ()); + map.assign (key, t_rhs.storable_value ()); - if (! error_state) - { - count++; - retval = octave_value (this); - } - else - gripe_failed_assignment (); - } - break; + if (! error_state) + { + count++; + retval = octave_value (this); + } + else + gripe_failed_assignment (); + } + break; - case '{': - gripe_invalid_index_type (type_name (), type[0]); - break; + case '{': + gripe_invalid_index_type (type_name (), type[0]); + break; - default: - panic_impossible (); - } + default: + panic_impossible (); + } } else gripe_failed_assignment (); @@ -596,43 +596,43 @@ octave_idx_type n = map.numel (); if (n != 1 || print_keys_only) - { - indent (os); - dim_vector dv = dims (); - os << dv.str () << " struct array containing the fields:"; - newline (os); - newline (os); + { + indent (os); + dim_vector dv = dims (); + os << dv.str () << " struct array containing the fields:"; + newline (os); + newline (os); - increment_indent_level (); - } + increment_indent_level (); + } string_vector key_list = map.keys (); for (octave_idx_type i = 0; i < key_list.length (); i++) - { - std::string key = key_list[i]; + { + std::string key = key_list[i]; - Cell val = map.contents (key); + Cell val = map.contents (key); - octave_value tmp = (n == 1) ? val(0) : octave_value (val, true); + octave_value tmp = (n == 1) ? val(0) : octave_value (val, true); - if (n != 1 || print_keys_only) - { - indent (os); - os << key; - if (n == 1) - { - dim_vector dv = tmp.dims (); - os << ": " << dv.str () << " " << tmp.type_name (); - } - newline (os); - } - else - tmp.print_with_name (os, key); - } + if (n != 1 || print_keys_only) + { + indent (os); + os << key; + if (n == 1) + { + dim_vector dv = tmp.dims (); + os << ": " << dv.str () << " " << tmp.type_name (); + } + newline (os); + } + else + tmp.print_with_name (os, key); + } if (n != 1 || print_keys_only) - decrement_indent_level (); + decrement_indent_level (); decrement_indent_level (); @@ -734,14 +734,14 @@ Cell fields; if (nargin == 2) - { - if (args(1).is_cellstr ()) - retval = Octave_map (args(0).dims (), args(1).cell_value ()); - else - error ("struct: expecting cell array of field names as second argument"); - } + { + if (args(1).is_cellstr ()) + retval = Octave_map (args(0).dims (), args(1).cell_value ()); + else + error ("struct: expecting cell array of field names as second argument"); + } else - retval = Octave_map (args(0).dims ()); + retval = Octave_map (args(0).dims ()); return retval; } @@ -751,10 +751,10 @@ for (int i = 0; i < nargin; i += 2) { if (! args(i).is_string () || i + 1 >= nargin) - { - error ("struct expects alternating \"field\", VALUE pairs"); - return retval; - } + { + error ("struct expects alternating \"field\", VALUE pairs"); + return retval; + } } // Check that the dimensions of the values correspond. @@ -766,24 +766,24 @@ for (int i = 1; i < nargin; i += 2) { if (args(i).is_cell ()) - { - dim_vector argdims (args(i).dims ()); + { + dim_vector argdims (args(i).dims ()); - if (! scalar (argdims)) - { - if (! first_dimensioned_value) - { - dims = argdims; - first_dimensioned_value = i + 1; - } - else if (dims != argdims) - { - error ("struct: dimensions of parameter %d do not match those of parameter %d", - first_dimensioned_value, i+1); - return retval; - } - } - } + if (! scalar (argdims)) + { + if (! first_dimensioned_value) + { + dims = argdims; + first_dimensioned_value = i + 1; + } + else if (dims != argdims) + { + error ("struct: dimensions of parameter %d do not match those of parameter %d", + first_dimensioned_value, i+1); + return retval; + } + } + } } // Create the return value. @@ -797,13 +797,13 @@ std::string key (args(i).string_value ()); if (error_state) - return retval; + return retval; if (! valid_identifier (key)) - { - error ("struct: invalid structure field name `%s'", key.c_str ()); - return retval; - } + { + error ("struct: invalid structure field name `%s'", key.c_str ()); + return retval; + } // Value may be v, { v }, or { v1, v2, ... } // In the first two cases, we need to create a cell array of @@ -812,22 +812,22 @@ // correct dimensions. if (args(i+1).is_cell ()) - { - const Cell c (args(i+1).cell_value ()); + { + const Cell c (args(i+1).cell_value ()); - if (error_state) - return retval; + if (error_state) + return retval; - if (scalar (c.dims ())) - map.assign (key, Cell (dims, c(0))); - else - map.assign (key, c); - } + if (scalar (c.dims ())) + map.assign (key, Cell (dims, c(0))); + else + map.assign (key, c); + } else - map.assign (key, Cell (dims, args(i+1))); + map.assign (key, Cell (dims, args(i+1))); if (error_state) - return retval; + return retval; } return octave_value (map); @@ -867,18 +867,18 @@ octave_value arg = args(0); if (arg.is_map () || arg.is_object ()) - { - Octave_map m = arg.map_value (); + { + Octave_map m = arg.map_value (); - string_vector keys = m.keys (); + string_vector keys = m.keys (); - if (keys.length () == 0) - retval = Cell (0, 1); - else - retval = Cell (m.keys ()); - } + if (keys.length () == 0) + retval = Cell (0, 1); + else + retval = Cell (m.keys ()); + } else - gripe_wrong_type_arg ("fieldnames", args(0)); + gripe_wrong_type_arg ("fieldnames", args(0)); } else print_usage (); @@ -913,13 +913,13 @@ // structure reference operations? if (args(0).is_map () && args(1).is_string ()) - { - std::string key = args(1).string_value (); + { + std::string key = args(1).string_value (); - Octave_map m = args(0).map_value (); + Octave_map m = args(0).map_value (); - retval = m.contains (key) != 0; - } + retval = m.contains (key) != 0; + } } else print_usage (); @@ -963,36 +963,36 @@ static bool cell2struct_check_args (const dim_vector& c_dv, const dim_vector& f_dv, - bool is_cell, int dim) + bool is_cell, int dim) { bool retval = true; if (dim >= 0 && dim < c_dv.length ()) { if (is_cell) - { - if (f_dv.numel () != c_dv(dim)) - { - error ("cell2struct: numel (FIELD) != size (CELL, DIM)"); + { + if (f_dv.numel () != c_dv(dim)) + { + error ("cell2struct: numel (FIELD) != size (CELL, DIM)"); - retval = false; - } - } + retval = false; + } + } else - { - if (f_dv.length () > 2) - { - error ("cell2struct: field array must be a 2-d matrix"); + { + if (f_dv.length () > 2) + { + error ("cell2struct: field array must be a 2-d matrix"); - retval = false; - } - else if (f_dv(0) != c_dv(dim)) - { - error ("cell2struct: size (FIELD, 1) != length (C, DIM)"); + retval = false; + } + else if (f_dv(0) != c_dv(dim)) + { + error ("cell2struct: size (FIELD, 1) != length (C, DIM)"); - retval = false; - } - } + retval = false; + } + } } else { @@ -1006,17 +1006,17 @@ static void cell2struct_construct_idx (Array& ra_idx1, - const Array& ra_idx2, - octave_idx_type dim, octave_idx_type fill_value) + const Array& ra_idx2, + octave_idx_type dim, octave_idx_type fill_value) { octave_idx_type iidx = 0; for (octave_idx_type idx = 0; idx < ra_idx1.length (); idx++) { if (idx == dim) - ra_idx1.elem (idx) = fill_value; + ra_idx1.elem (idx) = fill_value; else - ra_idx1.elem (idx) = ra_idx2(iidx++); + ra_idx1.elem (idx) = ra_idx2(iidx++); } } @@ -1050,155 +1050,155 @@ Cell c = args(0).cell_value (); if (! error_state) - { - octave_value field = args(1); + { + octave_value field = args(1); - // Field is either cell or character matrix. + // Field is either cell or character matrix. - // FIXME -- this could be simplified if we had - // cellstr and iscellstr functions available. + // FIXME -- this could be simplified if we had + // cellstr and iscellstr functions available. - bool field_is_cell = field.is_cell (); + bool field_is_cell = field.is_cell (); - Cell field_cell; - charMatrix field_char; + Cell field_cell; + charMatrix field_char; - if (field_is_cell) - field_cell = field.cell_value (); - else - field_char = field.char_matrix_value (); + if (field_is_cell) + field_cell = field.cell_value (); + else + field_char = field.char_matrix_value (); - if (! error_state) - { - // Retrieve the dimension value. + if (! error_state) + { + // Retrieve the dimension value. - // FIXME -- int_value () should print out the - // conversions it does to be Matlab compatible. + // FIXME -- int_value () should print out the + // conversions it does to be Matlab compatible. - octave_idx_type dim = args(2).int_value () - 1; + octave_idx_type dim = args(2).int_value () - 1; - if (! error_state) - { - dim_vector c_dv = c.dims (); - dim_vector field_dv = field.dims (); + if (! error_state) + { + dim_vector c_dv = c.dims (); + dim_vector field_dv = field.dims (); - if (cell2struct_check_args (c_dv, field_dv, field_is_cell, - dim)) - { - octave_idx_type c_dv_length = c_dv.length (); + if (cell2struct_check_args (c_dv, field_dv, field_is_cell, + dim)) + { + octave_idx_type c_dv_length = c_dv.length (); - // Dimension vector for the Cell arrays to be - // put into the structure. + // Dimension vector for the Cell arrays to be + // put into the structure. - dim_vector value_dv; + dim_vector value_dv; - // Initialize c_value_dv. + // Initialize c_value_dv. - if (c_dv_length == 2) - value_dv = dim_vector (1, 1); - else - value_dv.resize (c_dv_length - 1); + if (c_dv_length == 2) + value_dv = dim_vector (1, 1); + else + value_dv.resize (c_dv_length - 1); - octave_idx_type idx_tmp = 0; + octave_idx_type idx_tmp = 0; - for (octave_idx_type i = 0; i < c_dv_length; i++) - { - if (i != dim) - value_dv.elem (idx_tmp++) = c_dv.elem (i); - } + for (octave_idx_type i = 0; i < c_dv_length; i++) + { + if (i != dim) + value_dv.elem (idx_tmp++) = c_dv.elem (i); + } - // All initializing is done, we can start moving - // values. + // All initializing is done, we can start moving + // values. - Octave_map map; + Octave_map map; - // If field is a cell array then we use all - // elements in array, on the other hand when - // field is a character array the number of - // elements is equals the number of rows. + // If field is a cell array then we use all + // elements in array, on the other hand when + // field is a character array the number of + // elements is equals the number of rows. - octave_idx_type field_numel - = field_is_cell ? field_dv.numel (): field_dv(0); + octave_idx_type field_numel + = field_is_cell ? field_dv.numel (): field_dv(0); - // For matlab compatibility. + // For matlab compatibility. - if (field_numel == 0) - map.reshape (dim_vector (0, 1)); + if (field_numel == 0) + map.reshape (dim_vector (0, 1)); - for (octave_idx_type i = 0; i < field_numel; i++) - { - // Construct cell array which goes into the - // structure together with the appropriate - // field name. + for (octave_idx_type i = 0; i < field_numel; i++) + { + // Construct cell array which goes into the + // structure together with the appropriate + // field name. - Cell c_value (value_dv); + Cell c_value (value_dv); - Array value_idx (value_dv.length (), 0); - Array c_idx (c_dv_length, 0); + Array value_idx (value_dv.length (), 0); + Array c_idx (c_dv_length, 0); - for (octave_idx_type j = 0; j < value_dv.numel (); j++) - { - // Need to do this to construct the - // appropriate idx for getting elements - // from the original cell array. + for (octave_idx_type j = 0; j < value_dv.numel (); j++) + { + // Need to do this to construct the + // appropriate idx for getting elements + // from the original cell array. - cell2struct_construct_idx (c_idx, value_idx, - dim, i); + cell2struct_construct_idx (c_idx, value_idx, + dim, i); - c_value.elem (value_idx) = c.elem (c_idx); + c_value.elem (value_idx) = c.elem (c_idx); - increment_index (value_idx, value_dv); - } + increment_index (value_idx, value_dv); + } - std::string field_str; + std::string field_str; - if (field_is_cell) - { - // Matlab retrieves the field values - // column by column. + if (field_is_cell) + { + // Matlab retrieves the field values + // column by column. - octave_value field_tmp = field_cell.elem (i); + octave_value field_tmp = field_cell.elem (i); - field_str = field_tmp.string_value (); + field_str = field_tmp.string_value (); - if (error_state) - { - error ("cell2struct: fields have to be of type string"); - break; - } - } - else - { - field_str = field_char.row_as_string (i); + if (error_state) + { + error ("cell2struct: fields have to be of type string"); + break; + } + } + else + { + field_str = field_char.row_as_string (i); - if (error_state) - return retval; - } + if (error_state) + return retval; + } - if (! valid_identifier (field_str)) - { - error ("cell2struct: invalid field name `%s'", - field_str.c_str ()); - break; - } + if (! valid_identifier (field_str)) + { + error ("cell2struct: invalid field name `%s'", + field_str.c_str ()); + break; + } - map.reshape (value_dv); + map.reshape (value_dv); - map.assign (field_str, c_value); - } + map.assign (field_str, c_value); + } - if (! error_state) - retval = map; - } - } - else - error ("cell2struct: expecting third argument to be an integer"); - } - else - error ("cell2struct: expecting second argument to be a cell or character array"); - } + if (! error_state) + retval = map; + } + } + else + error ("cell2struct: expecting third argument to be an integer"); + } + else + error ("cell2struct: expecting second argument to be a cell or character array"); + } else - error ("cell2struct: expecting first argument to be a cell array"); + error ("cell2struct: expecting first argument to be a cell array"); } else print_usage (); @@ -1242,27 +1242,27 @@ octave_value_list fval = Fcellstr (args(1), 1); if (! error_state) - { - Cell fcell = fval(0).cell_value (); + { + Cell fcell = fval(0).cell_value (); - for (int i = 0; i < fcell.numel (); i++) - { - std::string key = fcell(i).string_value (); + for (int i = 0; i < fcell.numel (); i++) + { + std::string key = fcell(i).string_value (); - if (m.contains (key)) - m.del (key); - else - { - error ("rmfield: structure does not contain field %s", - key.c_str ()); + if (m.contains (key)) + m.del (key); + else + { + error ("rmfield: structure does not contain field %s", + key.c_str ()); - break; - } - } + break; + } + } - if (! error_state) - retval = m; - } + if (! error_state) + retval = m; + } } else print_usage (); @@ -1309,7 +1309,7 @@ bool b = save_ascii_data (os, val, key, false, 0); if (! b) - return os; + return os; } return true; @@ -1350,44 +1350,44 @@ if (success && len >= 0) { if (len > 0) - { - Octave_map m (dv); + { + Octave_map m (dv); - for (octave_idx_type j = 0; j < len; j++) - { - octave_value t2; - bool dummy; + for (octave_idx_type j = 0; j < len; j++) + { + octave_value t2; + bool dummy; - // recurse to read cell elements - std::string nm - = read_ascii_data (is, std::string (), dummy, t2, j); + // recurse to read cell elements + std::string nm + = read_ascii_data (is, std::string (), dummy, t2, j); - if (!is) - break; + if (!is) + break; - Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); + Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); - if (error_state) - { - error ("load: internal error loading struct elements"); - return false; - } + if (error_state) + { + error ("load: internal error loading struct elements"); + return false; + } - m.assign (nm, tcell); - } + m.assign (nm, tcell); + } - if (is) - map = m; - else - { - error ("load: failed to load structure"); - success = false; - } - } + if (is) + map = m; + else + { + error ("load: failed to load structure"); + success = false; + } + } else if (len == 0 ) - map = Octave_map (dv); + map = Octave_map (dv); else - panic_impossible (); + panic_impossible (); } else { error ("load: failed to extract number of elements in structure"); @@ -1433,7 +1433,7 @@ bool b = save_binary_data (os, val, key, "", 0, save_as_floats); if (! b) - return os; + return os; } return true; @@ -1441,7 +1441,7 @@ bool octave_struct::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) + oct_mach_info::float_format fmt) { bool success = true; int32_t len; @@ -1480,36 +1480,36 @@ Octave_map m (dv); for (octave_idx_type j = 0; j < len; j++) - { - octave_value t2; - bool dummy; - std::string doc; + { + octave_value t2; + bool dummy; + std::string doc; - // recurse to read cell elements - std::string nm = read_binary_data (is, swap, fmt, std::string (), - dummy, t2, doc); + // recurse to read cell elements + std::string nm = read_binary_data (is, swap, fmt, std::string (), + dummy, t2, doc); - if (!is) - break; + if (!is) + break; - Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); + Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); - if (error_state) - { - error ("load: internal error loading struct elements"); - return false; - } + if (error_state) + { + error ("load: internal error loading struct elements"); + return false; + } - m.assign (nm, tcell); - } + m.assign (nm, tcell); + } if (is) - map = m; + map = m; else - { - error ("load: failed to load structure"); - success = false; - } + { + error ("load: failed to load structure"); + success = false; + } } else if (len == 0) map = Octave_map (dv); @@ -1549,10 +1549,10 @@ octave_value val = map.contents (key); bool retval2 = add_hdf5_data (data_hid, val, key, "", false, - save_as_floats); + save_as_floats); if (! retval2) - break; + break; } H5Gclose (data_hid); @@ -1583,18 +1583,18 @@ // Why is that happening? while (current_item < static_cast (num_obj) - && (retval2 = H5Giterate (loc_id, name, ¤t_item, - hdf5_read_next_data, &dsub)) > 0) + && (retval2 = H5Giterate (loc_id, name, ¤t_item, + hdf5_read_next_data, &dsub)) > 0) { octave_value t2 = dsub.tc; Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); if (error_state) - { - error ("load: internal error loading struct elements"); - return false; - } + { + error ("load: internal error loading struct elements"); + return false; + } m.assign (dsub.name, tcell); @@ -1638,7 +1638,7 @@ mwIndex k = 0; for (mwIndex j = i; j < ntot; j += nf) - elts[j] = new mxArray (p[k++]); + elts[j] = new mxArray (p[k++]); } return retval; diff --git a/src/ov-typeinfo.cc b/src/ov-typeinfo.cc --- a/src/ov-typeinfo.cc +++ b/src/ov-typeinfo.cc @@ -59,8 +59,8 @@ int octave_value_typeinfo::register_type (const std::string& t_name, - const std::string& c_name, - const octave_value& val) + const std::string& c_name, + const octave_value& val) { return (instance_ok ()) ? instance->do_register_type (t_name, c_name, val) : -1; @@ -68,7 +68,7 @@ bool octave_value_typeinfo::register_unary_class_op (octave_value::unary_op op, - octave_value_typeinfo::unary_class_op_fcn f) + octave_value_typeinfo::unary_class_op_fcn f) { return (instance_ok ()) ? instance->do_register_unary_class_op (op, f) : false; @@ -76,7 +76,7 @@ bool octave_value_typeinfo::register_unary_op (octave_value::unary_op op, - int t, octave_value_typeinfo::unary_op_fcn f) + int t, octave_value_typeinfo::unary_op_fcn f) { return (instance_ok ()) ? instance->do_register_unary_op (op, t, f) : false; @@ -84,8 +84,8 @@ bool octave_value_typeinfo::register_non_const_unary_op (octave_value::unary_op op, - int t, - octave_value_typeinfo::non_const_unary_op_fcn f) + int t, + octave_value_typeinfo::non_const_unary_op_fcn f) { return (instance_ok ()) ? instance->do_register_non_const_unary_op (op, t, f) : false; @@ -93,7 +93,7 @@ bool octave_value_typeinfo::register_binary_class_op (octave_value::binary_op op, - octave_value_typeinfo::binary_class_op_fcn f) + octave_value_typeinfo::binary_class_op_fcn f) { return (instance_ok ()) ? instance->do_register_binary_class_op (op, f) : false; @@ -101,8 +101,8 @@ bool octave_value_typeinfo::register_binary_op (octave_value::binary_op op, - int t1, int t2, - octave_value_typeinfo::binary_op_fcn f) + int t1, int t2, + octave_value_typeinfo::binary_op_fcn f) { return (instance_ok ()) ? instance->do_register_binary_op (op, t1, t2, f) : false; @@ -110,7 +110,7 @@ bool octave_value_typeinfo::register_binary_class_op (octave_value::compound_binary_op op, - octave_value_typeinfo::binary_class_op_fcn f) + octave_value_typeinfo::binary_class_op_fcn f) { return (instance_ok ()) ? instance->do_register_binary_class_op (op, f) : false; @@ -118,8 +118,8 @@ bool octave_value_typeinfo::register_binary_op (octave_value::compound_binary_op op, - int t1, int t2, - octave_value_typeinfo::binary_op_fcn f) + int t1, int t2, + octave_value_typeinfo::binary_op_fcn f) { return (instance_ok ()) ? instance->do_register_binary_op (op, t1, t2, f) : false; @@ -134,8 +134,8 @@ bool octave_value_typeinfo::register_assign_op (octave_value::assign_op op, - int t_lhs, int t_rhs, - octave_value_typeinfo::assign_op_fcn f) + int t_lhs, int t_rhs, + octave_value_typeinfo::assign_op_fcn f) { return (instance_ok ()) ? instance->do_register_assign_op (op, t_lhs, t_rhs, f) : -1; @@ -143,7 +143,7 @@ bool octave_value_typeinfo::register_assignany_op (octave_value::assign_op op, - int t_lhs, octave_value_typeinfo::assignany_op_fcn f) + int t_lhs, octave_value_typeinfo::assignany_op_fcn f) { return (instance_ok ()) ? instance->do_register_assignany_op (op, t_lhs, f) : -1; @@ -151,7 +151,7 @@ bool octave_value_typeinfo::register_pref_assign_conv (int t_lhs, int t_rhs, - int t_result) + int t_result) { return (instance_ok ()) ? instance->do_register_pref_assign_conv (t_lhs, t_rhs, t_result) : false; @@ -159,7 +159,7 @@ bool octave_value_typeinfo::register_type_conv_op (int t, int t_result, - octave_base_value::type_conv_fcn f) + octave_base_value::type_conv_fcn f) { return (instance_ok ()) ? instance->do_register_type_conv_op (t, t_result, f) : false; @@ -167,7 +167,7 @@ bool octave_value_typeinfo::register_widening_op (int t, int t_result, - octave_base_value::type_conv_fcn f) + octave_base_value::type_conv_fcn f) { return (instance_ok ()) ? instance->do_register_widening_op (t, t_result, f) : false; @@ -178,8 +178,8 @@ int octave_value_typeinfo::do_register_type (const std::string& t_name, - const std::string& /* c_name */, - const octave_value& val) + const std::string& /* c_name */, + const octave_value& val) { int i = 0; @@ -200,10 +200,10 @@ unary_ops.resize (static_cast (octave_value::num_unary_ops), len, 0); non_const_unary_ops.resize - (static_cast (octave_value::num_unary_ops), len, 0); + (static_cast (octave_value::num_unary_ops), len, 0); binary_ops.resize (static_cast (octave_value::num_binary_ops), - len, len, 0); + len, len, 0); compound_binary_ops.resize (static_cast (octave_value::num_compound_binary_ops), len, len, 0); @@ -232,14 +232,14 @@ bool octave_value_typeinfo::do_register_unary_class_op (octave_value::unary_op op, - octave_value_typeinfo::unary_class_op_fcn f) + octave_value_typeinfo::unary_class_op_fcn f) { if (lookup_unary_class_op (op)) { std::string op_name = octave_value::unary_op_as_string (op); warning ("duplicate unary operator `%s' for class dispatch", - op_name.c_str ()); + op_name.c_str ()); } unary_class_ops.checkelem (static_cast (op)) = reinterpret_cast (f); @@ -249,7 +249,7 @@ bool octave_value_typeinfo::do_register_unary_op (octave_value::unary_op op, - int t, octave_value_typeinfo::unary_op_fcn f) + int t, octave_value_typeinfo::unary_op_fcn f) { if (lookup_unary_op (op, t)) { @@ -257,7 +257,7 @@ std::string type_name = types(t); warning ("duplicate unary operator `%s' for type `%s'", - op_name.c_str (), type_name.c_str ()); + op_name.c_str (), type_name.c_str ()); } unary_ops.checkelem (static_cast (op), t) = reinterpret_cast (f); @@ -275,7 +275,7 @@ std::string type_name = types(t); warning ("duplicate unary operator `%s' for type `%s'", - op_name.c_str (), type_name.c_str ()); + op_name.c_str (), type_name.c_str ()); } non_const_unary_ops.checkelem (static_cast (op), t) = reinterpret_cast (f); @@ -285,14 +285,14 @@ bool octave_value_typeinfo::do_register_binary_class_op (octave_value::binary_op op, - octave_value_typeinfo::binary_class_op_fcn f) + octave_value_typeinfo::binary_class_op_fcn f) { if (lookup_binary_class_op (op)) { std::string op_name = octave_value::binary_op_as_string (op); warning ("duplicate binary operator `%s' for class dispatch", - op_name.c_str ()); + op_name.c_str ()); } binary_class_ops.checkelem (static_cast (op)) = reinterpret_cast (f); @@ -302,8 +302,8 @@ bool octave_value_typeinfo::do_register_binary_op (octave_value::binary_op op, - int t1, int t2, - octave_value_typeinfo::binary_op_fcn f) + int t1, int t2, + octave_value_typeinfo::binary_op_fcn f) { if (lookup_binary_op (op, t1, t2)) { @@ -312,7 +312,7 @@ std::string t2_name = types(t2); warning ("duplicate binary operator `%s' for types `%s' and `%s'", - op_name.c_str (), t1_name.c_str (), t1_name.c_str ()); + op_name.c_str (), t1_name.c_str (), t1_name.c_str ()); } binary_ops.checkelem (static_cast (op), t1, t2) = reinterpret_cast (f); @@ -322,14 +322,14 @@ bool octave_value_typeinfo::do_register_binary_class_op (octave_value::compound_binary_op op, - octave_value_typeinfo::binary_class_op_fcn f) + octave_value_typeinfo::binary_class_op_fcn f) { if (lookup_binary_class_op (op)) { std::string op_name = octave_value::binary_op_fcn_name (op); warning ("duplicate compound binary operator `%s' for class dispatch", - op_name.c_str ()); + op_name.c_str ()); } compound_binary_class_ops.checkelem (static_cast (op)) = reinterpret_cast (f); @@ -339,8 +339,8 @@ bool octave_value_typeinfo::do_register_binary_op (octave_value::compound_binary_op op, - int t1, int t2, - octave_value_typeinfo::binary_op_fcn f) + int t1, int t2, + octave_value_typeinfo::binary_op_fcn f) { if (lookup_binary_op (op, t1, t2)) { @@ -349,7 +349,7 @@ std::string t2_name = types(t2); warning ("duplicate compound binary operator `%s' for types `%s' and `%s'", - op_name.c_str (), t1_name.c_str (), t1_name.c_str ()); + op_name.c_str (), t1_name.c_str (), t1_name.c_str ()); } compound_binary_ops.checkelem (static_cast (op), t1, t2) = reinterpret_cast (f); @@ -366,7 +366,7 @@ std::string t2_name = types(t2); warning ("duplicate concatenation operator for types `%s' and `%s'", - t1_name.c_str (), t1_name.c_str ()); + t1_name.c_str (), t1_name.c_str ()); } cat_ops.checkelem (t1, t2) = reinterpret_cast (f); @@ -376,8 +376,8 @@ bool octave_value_typeinfo::do_register_assign_op (octave_value::assign_op op, - int t_lhs, int t_rhs, - octave_value_typeinfo::assign_op_fcn f) + int t_lhs, int t_rhs, + octave_value_typeinfo::assign_op_fcn f) { if (lookup_assign_op (op, t_lhs, t_rhs)) { @@ -386,7 +386,7 @@ std::string t_rhs_name = types(t_rhs); warning ("duplicate assignment operator `%s' for types `%s' and `%s'", - op_name.c_str (), t_lhs_name.c_str (), t_rhs_name.c_str ()); + op_name.c_str (), t_lhs_name.c_str (), t_rhs_name.c_str ()); } assign_ops.checkelem (static_cast (op), t_lhs, t_rhs) = reinterpret_cast (f); @@ -396,7 +396,7 @@ bool octave_value_typeinfo::do_register_assignany_op (octave_value::assign_op op, - int t_lhs, octave_value_typeinfo::assignany_op_fcn f) + int t_lhs, octave_value_typeinfo::assignany_op_fcn f) { if (lookup_assignany_op (op, t_lhs)) { @@ -404,7 +404,7 @@ std::string t_lhs_name = types(t_lhs); warning ("duplicate assignment operator `%s' for types `%s'", - op_name.c_str (), t_lhs_name.c_str ()); + op_name.c_str (), t_lhs_name.c_str ()); } assignany_ops.checkelem (static_cast (op), t_lhs) = reinterpret_cast (f); @@ -414,7 +414,7 @@ bool octave_value_typeinfo::do_register_pref_assign_conv (int t_lhs, int t_rhs, - int t_result) + int t_result) { if (lookup_pref_assign_conv (t_lhs, t_rhs) >= 0) { @@ -422,7 +422,7 @@ std::string t_rhs_name = types(t_rhs); warning ("overriding assignment conversion for types `%s' and `%s'", - t_lhs_name.c_str (), t_rhs_name.c_str ()); + t_lhs_name.c_str (), t_rhs_name.c_str ()); } pref_assign_conv.checkelem (t_lhs, t_rhs) = t_result; @@ -440,7 +440,7 @@ std::string t_result_name = types(t_result); warning ("overriding type conversion op for `%s' to `%s'", - t_name.c_str (), t_result_name.c_str ()); + t_name.c_str (), t_result_name.c_str ()); } type_conv_ops.checkelem (t, t_result) = reinterpret_cast (f); @@ -458,7 +458,7 @@ std::string t_result_name = types(t_result); warning ("overriding widening op for `%s' to `%s'", - t_name.c_str (), t_result_name.c_str ()); + t_name.c_str (), t_result_name.c_str ()); } widening_ops.checkelem (t, t_result) = reinterpret_cast (f); @@ -474,11 +474,11 @@ for (int i = 0; i < num_types; i++) { if (nm == types(i)) - { - retval = vals(i); - retval.make_unique (); - break; - } + { + retval = vals(i); + retval.make_unique (); + break; + } } return retval; @@ -515,7 +515,7 @@ octave_value_typeinfo::binary_op_fcn octave_value_typeinfo::do_lookup_binary_op (octave_value::binary_op op, - int t1, int t2) + int t1, int t2) { void *f = binary_ops.checkelem (static_cast (op), t1, t2); return reinterpret_cast (f); @@ -530,7 +530,7 @@ octave_value_typeinfo::binary_op_fcn octave_value_typeinfo::do_lookup_binary_op (octave_value::compound_binary_op op, - int t1, int t2) + int t1, int t2) { void *f = compound_binary_ops.checkelem (static_cast (op), t1, t2); return reinterpret_cast (f); @@ -545,7 +545,7 @@ octave_value_typeinfo::assign_op_fcn octave_value_typeinfo::do_lookup_assign_op (octave_value::assign_op op, - int t_lhs, int t_rhs) + int t_lhs, int t_rhs) { void *f = assign_ops.checkelem (static_cast (op), t_lhs, t_rhs); return reinterpret_cast (f); @@ -553,7 +553,7 @@ octave_value_typeinfo::assignany_op_fcn octave_value_typeinfo::do_lookup_assignany_op (octave_value::assign_op op, - int t_lhs) + int t_lhs) { void *f = assignany_ops.checkelem (static_cast (op), t_lhs); return reinterpret_cast (f); diff --git a/src/ov-uint16.cc b/src/ov-uint16.cc --- a/src/ov-uint16.cc +++ b/src/ov-uint16.cc @@ -63,7 +63,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_uint16_matrix); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_uint16_matrix, - "uint16 matrix", "uint16"); + "uint16 matrix", "uint16"); template class octave_base_scalar; @@ -72,7 +72,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_uint16_scalar); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_uint16_scalar, - "uint16 scalar", "uint16"); + "uint16 scalar", "uint16"); DEFUN (uint16, args, , "-*- texinfo -*-\n\ diff --git a/src/ov-uint32.cc b/src/ov-uint32.cc --- a/src/ov-uint32.cc +++ b/src/ov-uint32.cc @@ -63,7 +63,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_uint32_matrix); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_uint32_matrix, - "uint32 matrix", "uint32"); + "uint32 matrix", "uint32"); template class octave_base_scalar; @@ -72,7 +72,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_uint32_scalar); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_uint32_scalar, - "uint32 scalar", "uint32"); + "uint32 scalar", "uint32"); DEFUN (uint32, args, , "-*- texinfo -*-\n\ diff --git a/src/ov-uint64.cc b/src/ov-uint64.cc --- a/src/ov-uint64.cc +++ b/src/ov-uint64.cc @@ -63,7 +63,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_uint64_matrix); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_uint64_matrix, - "uint64 matrix", "uint64"); + "uint64 matrix", "uint64"); template class octave_base_scalar; @@ -72,7 +72,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_uint64_scalar); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_uint64_scalar, - "uint64 scalar", "uint64"); + "uint64 scalar", "uint64"); DEFUN (uint64, args, , "-*- texinfo -*-\n\ diff --git a/src/ov-uint8.cc b/src/ov-uint8.cc --- a/src/ov-uint8.cc +++ b/src/ov-uint8.cc @@ -63,7 +63,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_uint8_matrix); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_uint8_matrix, - "uint8 matrix", "uint8"); + "uint8 matrix", "uint8"); template class octave_base_scalar; @@ -72,7 +72,7 @@ DEFINE_OCTAVE_ALLOCATOR (octave_uint8_scalar); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_uint8_scalar, - "uint8 scalar", "uint8"); + "uint8 scalar", "uint8"); DEFUN (uint8, args, , "-*- texinfo -*-\n\ diff --git a/src/ov-usr-fcn.cc b/src/ov-usr-fcn.cc --- a/src/ov-usr-fcn.cc +++ b/src/ov-usr-fcn.cc @@ -60,8 +60,8 @@ DEFINE_OCTAVE_ALLOCATOR (octave_user_script); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_user_script, - "user-defined script", - "user-defined script"); + "user-defined script", + "user-defined script"); octave_user_script::octave_user_script (void) : octave_user_code (), cmd_list (0), file_name (), @@ -71,9 +71,9 @@ { } octave_user_script::octave_user_script (const std::string& fnm, - const std::string& nm, - tree_statement_list *cmds, - const std::string& ds) + const std::string& nm, + tree_statement_list *cmds, + const std::string& ds) : octave_user_code (nm, ds), cmd_list (cmds), file_name (fnm), t_parsed (static_cast (0)), t_checked (static_cast (0)), @@ -84,8 +84,8 @@ } octave_user_script::octave_user_script (const std::string& fnm, - const std::string& nm, - const std::string& ds) + const std::string& nm, + const std::string& ds) : octave_user_code (nm, ds), cmd_list (0), file_name (fnm), t_parsed (static_cast (0)), t_checked (static_cast (0)), @@ -99,7 +99,7 @@ octave_value_list octave_user_script::subsref (const std::string&, - const std::list&, int) + const std::list&, int) { octave_value_list retval; @@ -110,7 +110,7 @@ octave_value_list octave_user_script::do_multi_index_op (int nargout, - const octave_value_list& args) + const octave_value_list& args) { octave_value_list retval; @@ -119,38 +119,38 @@ if (! error_state) { if (args.length () == 0 && nargout == 0) - { - if (cmd_list) - { - frame.protect_var (call_depth); - call_depth++; + { + if (cmd_list) + { + frame.protect_var (call_depth); + call_depth++; - if (call_depth < Vmax_recursion_depth) - { - octave_call_stack::push (this); + if (call_depth < Vmax_recursion_depth) + { + octave_call_stack::push (this); frame.add_fcn (octave_call_stack::pop); - frame.protect_var (tree_evaluator::in_fcn_or_script_body); - tree_evaluator::in_fcn_or_script_body = true; + frame.protect_var (tree_evaluator::in_fcn_or_script_body); + tree_evaluator::in_fcn_or_script_body = true; - cmd_list->accept (*current_evaluator); + cmd_list->accept (*current_evaluator); - if (tree_return_command::returning) - tree_return_command::returning = 0; + if (tree_return_command::returning) + tree_return_command::returning = 0; - if (tree_break_command::breaking) - tree_break_command::breaking--; + if (tree_break_command::breaking) + tree_break_command::breaking--; - if (error_state) - octave_call_stack::backtrace_error_message (); - } - else - ::error ("max_recursion_limit exceeded"); - } - } + if (error_state) + octave_call_stack::backtrace_error_message (); + } + else + ::error ("max_recursion_limit exceeded"); + } + } else - error ("invalid call to script %s", file_name.c_str ()); + error ("invalid call to script %s", file_name.c_str ()); } return retval; @@ -167,8 +167,8 @@ DEFINE_OCTAVE_ALLOCATOR (octave_user_function); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_user_function, - "user-defined function", - "user-defined function"); + "user-defined function", + "user-defined function"); // Ugh. This really needs to be simplified (code/data? // extrinsic/intrinsic state?). @@ -236,7 +236,7 @@ std::string ff_name = fcn_file_in_path (file_name); if (Vfcn_file_dir == ff_name.substr (0, Vfcn_file_dir.length ())) - system_fcn_file = 1; + system_fcn_file = 1; } else system_fcn_file = 0; @@ -281,8 +281,8 @@ octave_value_list octave_user_function::subsref (const std::string& type, - const std::list& idx, - int nargout) + const std::list& idx, + int nargout) { octave_value_list retval; @@ -290,17 +290,17 @@ { case '(': { - int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; + int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; - retval = do_multi_index_op (tmp_nargout, idx.front ()); + retval = do_multi_index_op (tmp_nargout, idx.front ()); } break; case '{': case '.': { - std::string nm = type_name (); - error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + std::string nm = type_name (); + error ("%s cannot be indexed with %c", nm.c_str (), type[0]); } break; @@ -320,7 +320,7 @@ octave_value_list octave_user_function::do_multi_index_op (int nargout, - const octave_value_list& args) + const octave_value_list& args) { octave_value_list retval; @@ -554,34 +554,34 @@ std::string fname = args(0).string_value (); if (! error_state) - { - octave_value fcn_val = symbol_table::find_user_function (fname); + { + octave_value fcn_val = symbol_table::find_user_function (fname); - octave_user_function *fcn = fcn_val.user_function_value (true); + octave_user_function *fcn = fcn_val.user_function_value (true); - if (fcn) - { - if (fcn->takes_varargs ()) - retval = -1; - else - { - tree_parameter_list *param_list = fcn->parameter_list (); + if (fcn) + { + if (fcn->takes_varargs ()) + retval = -1; + else + { + tree_parameter_list *param_list = fcn->parameter_list (); - retval = param_list ? param_list->length () : 0; - } - } - else - error ("nargin: invalid function"); - } + retval = param_list ? param_list->length () : 0; + } + } + else + error ("nargin: invalid function"); + } else - error ("nargin: expecting string as first argument"); + error ("nargin: expecting string as first argument"); } else if (nargin == 0) { retval = symbol_table::varval (".nargin."); if (retval.is_undefined ()) - retval = 0; + retval = 0; } else print_usage (); @@ -628,39 +628,39 @@ std::string fname = args(0).string_value (); if (! error_state) - { - octave_value fcn_val = symbol_table::find_user_function (fname); + { + octave_value fcn_val = symbol_table::find_user_function (fname); - octave_user_function *fcn = fcn_val.user_function_value (true); + octave_user_function *fcn = fcn_val.user_function_value (true); - if (fcn) - { - if (fcn->takes_var_return ()) - retval = -1; - else - { - tree_parameter_list *ret_list = fcn->return_list (); + if (fcn) + { + if (fcn->takes_var_return ()) + retval = -1; + else + { + tree_parameter_list *ret_list = fcn->return_list (); - retval = ret_list ? ret_list->length () : 0; - } - } - else - error ("nargout: invalid function"); - } + retval = ret_list ? ret_list->length () : 0; + } + } + else + error ("nargout: invalid function"); + } else - error ("nargout: expecting string as first argument"); + error ("nargout: expecting string as first argument"); } else if (nargin == 0) { if (! symbol_table::at_top_level ()) - { - retval = symbol_table::varval (".nargout."); + { + retval = symbol_table::varval (".nargout."); - if (retval.is_undefined ()) - retval = 0; - } + if (retval.is_undefined ()) + retval = 0; + } else - error ("nargout: invalid call at top level"); + error ("nargout: invalid call at top level"); } else print_usage (); diff --git a/src/ov.cc b/src/ov.cc --- a/src/ov.cc +++ b/src/ov.cc @@ -580,15 +580,15 @@ octave_value::octave_value (const Cell& c, bool is_csl) : rep (is_csl - ? dynamic_cast (new octave_cs_list (c)) - : dynamic_cast (new octave_cell (c))) + ? dynamic_cast (new octave_cs_list (c)) + : dynamic_cast (new octave_cell (c))) { } octave_value::octave_value (const Array& a, bool is_csl) : rep (is_csl - ? dynamic_cast (new octave_cs_list (Cell (a))) - : dynamic_cast (new octave_cell (Cell (a)))) + ? dynamic_cast (new octave_cs_list (Cell (a))) + : dynamic_cast (new octave_cell (Cell (a)))) { } @@ -779,80 +779,80 @@ octave_value::octave_value (char c, char type) : rep (type == '"' - ? new octave_char_matrix_dq_str (c) - : new octave_char_matrix_sq_str (c)) + ? new octave_char_matrix_dq_str (c) + : new octave_char_matrix_sq_str (c)) { maybe_mutate (); } octave_value::octave_value (const char *s, char type) : rep (type == '"' - ? new octave_char_matrix_dq_str (s) - : new octave_char_matrix_sq_str (s)) + ? new octave_char_matrix_dq_str (s) + : new octave_char_matrix_sq_str (s)) { maybe_mutate (); } octave_value::octave_value (const std::string& s, char type) : rep (type == '"' - ? new octave_char_matrix_dq_str (s) - : new octave_char_matrix_sq_str (s)) + ? new octave_char_matrix_dq_str (s) + : new octave_char_matrix_sq_str (s)) { maybe_mutate (); } octave_value::octave_value (const string_vector& s, char type) : rep (type == '"' - ? new octave_char_matrix_dq_str (s) - : new octave_char_matrix_sq_str (s)) + ? new octave_char_matrix_dq_str (s) + : new octave_char_matrix_sq_str (s)) { maybe_mutate (); } octave_value::octave_value (const charMatrix& chm, char type) : rep (type == '"' - ? new octave_char_matrix_dq_str (chm) - : new octave_char_matrix_sq_str (chm)) + ? new octave_char_matrix_dq_str (chm) + : new octave_char_matrix_sq_str (chm)) { maybe_mutate (); } octave_value::octave_value (const charNDArray& chm, char type) : rep (type == '"' - ? new octave_char_matrix_dq_str (chm) - : new octave_char_matrix_sq_str (chm)) + ? new octave_char_matrix_dq_str (chm) + : new octave_char_matrix_sq_str (chm)) { maybe_mutate (); } octave_value::octave_value (const Array& chm, char type) : rep (type == '"' - ? new octave_char_matrix_dq_str (chm) - : new octave_char_matrix_sq_str (chm)) + ? new octave_char_matrix_dq_str (chm) + : new octave_char_matrix_sq_str (chm)) { maybe_mutate (); } octave_value::octave_value (const charMatrix& chm, bool, char type) : rep (type == '"' - ? new octave_char_matrix_dq_str (chm) - : new octave_char_matrix_sq_str (chm)) + ? new octave_char_matrix_dq_str (chm) + : new octave_char_matrix_sq_str (chm)) { maybe_mutate (); } octave_value::octave_value (const charNDArray& chm, bool, char type) : rep (type == '"' - ? new octave_char_matrix_dq_str (chm) - : new octave_char_matrix_sq_str (chm)) + ? new octave_char_matrix_dq_str (chm) + : new octave_char_matrix_sq_str (chm)) { maybe_mutate (); } octave_value::octave_value (const Array& chm, bool, char type) : rep (type == '"' - ? new octave_char_matrix_dq_str (chm) - : new octave_char_matrix_sq_str (chm)) + ? new octave_char_matrix_dq_str (chm) + : new octave_char_matrix_sq_str (chm)) { maybe_mutate (); } @@ -1147,7 +1147,7 @@ if (tmp && tmp != rep) { if (--rep->count == 0) - delete rep; + delete rep; rep = tmp; } @@ -1155,7 +1155,7 @@ octave_value octave_value::single_subsref (const std::string& type, - const octave_value_list& idx) + const octave_value_list& idx) { std::list i; @@ -1166,7 +1166,7 @@ octave_value_list octave_value::subsref (const std::string& type, - const std::list& idx, int nargout) + const std::list& idx, int nargout) { if (nargout == 1) return rep->subsref (type, idx); @@ -1176,14 +1176,14 @@ octave_value octave_value::next_subsref (const std::string& type, - const std::list& idx, - size_t skip) + const std::list& idx, + size_t skip) { if (! error_state && idx.size () > skip) { std::list new_idx (idx); for (size_t i = 0; i < skip; i++) - new_idx.erase (new_idx.begin ()); + new_idx.erase (new_idx.begin ()); return subsref (type.substr (skip), new_idx); } else @@ -1192,14 +1192,14 @@ octave_value_list octave_value::next_subsref (int nargout, const std::string& type, - const std::list& idx, - size_t skip) + const std::list& idx, + size_t skip) { if (! error_state && idx.size () > skip) { std::list new_idx (idx); for (size_t i = 0; i < skip; i++) - new_idx.erase (new_idx.begin ()); + new_idx.erase (new_idx.begin ()); return subsref (type.substr (skip), new_idx, nargout); } else @@ -1208,14 +1208,14 @@ octave_value octave_value::next_subsref (bool auto_add, const std::string& type, - const std::list& idx, - size_t skip) + const std::list& idx, + size_t skip) { if (! error_state && idx.size () > skip) { std::list new_idx (idx); for (size_t i = 0; i < skip; i++) - new_idx.erase (new_idx.begin ()); + new_idx.erase (new_idx.begin ()); return subsref (type.substr (skip), new_idx, auto_add); } else @@ -1231,34 +1231,34 @@ #if 0 static void gripe_assign_failed (const std::string& on, const std::string& tn1, - const std::string& tn2) + const std::string& tn2) { error ("assignment failed for `%s %s %s'", - tn1.c_str (), on.c_str (), tn2.c_str ()); + tn1.c_str (), on.c_str (), tn2.c_str ()); } #endif static void gripe_assign_failed_or_no_method (const std::string& on, - const std::string& tn1, - const std::string& tn2) + const std::string& tn1, + const std::string& tn2) { error ("assignment failed, or no method for `%s %s %s'", - tn1.c_str (), on.c_str (), tn2.c_str ()); + tn1.c_str (), on.c_str (), tn2.c_str ()); } octave_value octave_value::subsasgn (const std::string& type, - const std::list& idx, - const octave_value& rhs) + const std::list& idx, + const octave_value& rhs) { return rep->subsasgn (type, idx, rhs); } octave_value octave_value::assign (assign_op op, const std::string& type, - const std::list& idx, - const octave_value& rhs) + const std::list& idx, + const octave_value& rhs) { octave_value retval; @@ -1271,23 +1271,23 @@ octave_value t = subsref (type, idx); if (! error_state) - { - binary_op binop = op_eq_to_binary_op (op); - - if (! error_state) - t_rhs = do_binary_op (binop, t, rhs); - } + { + binary_op binop = op_eq_to_binary_op (op); + + if (! error_state) + t_rhs = do_binary_op (binop, t, rhs); + } } if (! error_state) { if (type[0] == '.' && ! (is_map () || is_object ())) - { - octave_value tmp = Octave_map (); - retval = tmp.subsasgn (type, idx, t_rhs); - } + { + octave_value tmp = Octave_map (); + retval = tmp.subsasgn (type, idx, t_rhs); + } else - retval = subsasgn (type, idx, t_rhs); + retval = subsasgn (type, idx, t_rhs); if (error_state) gripe_assign_failed_or_no_method (assign_op_as_string (op_asn_eq), @@ -1313,21 +1313,21 @@ int tthis = this->type_id (); int trhs = rhs.type_id (); - f = octave_value_typeinfo::lookup_assign_op (op, tthis, trhs); + f = octave_value_typeinfo::lookup_assign_op (op, tthis, trhs); } if (f) - { - try - { - f (*rep, octave_value_list (), *rhs.rep); + { + try + { + f (*rep, octave_value_list (), *rhs.rep); maybe_mutate (); // Usually unnecessary, but may be needed (complex arrays). - } - catch (octave_execution_exception) - { - gripe_library_execution_error (); - } - } + } + catch (octave_execution_exception) + { + gripe_library_execution_error (); + } + } else { @@ -1356,19 +1356,19 @@ for (int i = 0; i < dv.length (); i++) { if (dv(i) < 0) - { - retval = -1; - break; - } + { + retval = -1; + break; + } if (dv(i) == 0) - { - retval = 0; - break; - } + { + retval = 0; + break; + } if (dv(i) > retval) - retval = dv(i); + retval = dv(i); } return retval; @@ -1387,7 +1387,7 @@ // Empty array also means a match. if (! error_state && tmp.is_defined ()) - retval = tmp.is_true () || tmp.is_empty (); + retval = tmp.is_true () || tmp.is_empty (); } return retval; @@ -1515,7 +1515,7 @@ Array octave_value::vector_value (bool force_string_conv, - bool force_vector_conversion) const + bool force_vector_conversion) const { Array retval = array_value (force_string_conv); @@ -1548,7 +1548,7 @@ Array octave_value::int_vector_value (bool force_string_conv, bool require_int, - bool force_vector_conversion) const + bool force_vector_conversion) const { Array retval; @@ -1630,7 +1630,7 @@ Array octave_value::octave_idx_type_vector_value (bool require_int, bool force_string_conv, - bool force_vector_conversion) const + bool force_vector_conversion) const { Array retval; @@ -1792,18 +1792,18 @@ int octave_value::write (octave_stream& os, int block_size, - oct_data_conv::data_type output_type, int skip, - oct_mach_info::float_format flt_fmt) const + oct_data_conv::data_type output_type, int skip, + oct_mach_info::float_format flt_fmt) const { return rep->write (os, block_size, output_type, skip, flt_fmt); } static void gripe_binary_op (const std::string& on, const std::string& tn1, - const std::string& tn2) + const std::string& tn2) { error ("binary operator `%s' not implemented for `%s' by `%s' operations", - on.c_str (), tn1.c_str (), tn2.c_str ()); + on.c_str (), tn1.c_str (), tn2.c_str ()); } static void @@ -1814,7 +1814,7 @@ octave_value do_binary_op (octave_value::binary_op op, - const octave_value& v1, const octave_value& v2) + const octave_value& v1, const octave_value& v2) { octave_value retval; @@ -1825,22 +1825,22 @@ || t2 == octave_class::static_type_id ()) { octave_value_typeinfo::binary_class_op_fcn f - = octave_value_typeinfo::lookup_binary_class_op (op); + = octave_value_typeinfo::lookup_binary_class_op (op); if (f) - { - try - { - retval = f (v1, v2); - } - catch (octave_execution_exception) - { - gripe_library_execution_error (); - } - } + { + try + { + retval = f (v1, v2); + } + catch (octave_execution_exception) + { + gripe_library_execution_error (); + } + } else - gripe_binary_op (octave_value::binary_op_as_string (op), - v1.class_name (), v2.class_name ()); + gripe_binary_op (octave_value::binary_op_as_string (op), + v1.class_name (), v2.class_name ()); } else { @@ -1848,26 +1848,26 @@ // classes (double, char, int8, etc.) octave_value_typeinfo::binary_op_fcn f - = octave_value_typeinfo::lookup_binary_op (op, t1, t2); + = octave_value_typeinfo::lookup_binary_op (op, t1, t2); if (f) - { - try - { - retval = f (*v1.rep, *v2.rep); - } - catch (octave_execution_exception) - { - gripe_library_execution_error (); - } - } + { + try + { + retval = f (*v1.rep, *v2.rep); + } + catch (octave_execution_exception) + { + gripe_library_execution_error (); + } + } else - { - octave_value tv1; - octave_base_value::type_conv_info cf1 = v1.numeric_conversion_function (); - - octave_value tv2; - octave_base_value::type_conv_info cf2 = v2.numeric_conversion_function (); + { + octave_value tv1; + octave_base_value::type_conv_info cf1 = v1.numeric_conversion_function (); + + octave_value tv2; + octave_base_value::type_conv_info cf2 = v2.numeric_conversion_function (); // Try biased (one-sided) conversions first. if (cf2.type_id () >= 0 && @@ -1877,52 +1877,52 @@ octave_value_typeinfo::lookup_binary_op (op, cf1.type_id (), t2)) cf2 = 0; - if (cf1) - { - octave_base_value *tmp = cf1 (*v1.rep); - - if (tmp) - { - tv1 = octave_value (tmp); - t1 = tv1.type_id (); - } - else - { - gripe_binary_op_conv (octave_value::binary_op_as_string (op)); - return retval; - } - } - else - tv1 = v1; - - if (cf2) - { - octave_base_value *tmp = cf2 (*v2.rep); - - if (tmp) - { - tv2 = octave_value (tmp); - t2 = tv2.type_id (); - } - else - { - gripe_binary_op_conv (octave_value::binary_op_as_string (op)); - return retval; - } - } - else - tv2 = v2; - - if (cf1 || cf2) - { + if (cf1) + { + octave_base_value *tmp = cf1 (*v1.rep); + + if (tmp) + { + tv1 = octave_value (tmp); + t1 = tv1.type_id (); + } + else + { + gripe_binary_op_conv (octave_value::binary_op_as_string (op)); + return retval; + } + } + else + tv1 = v1; + + if (cf2) + { + octave_base_value *tmp = cf2 (*v2.rep); + + if (tmp) + { + tv2 = octave_value (tmp); + t2 = tv2.type_id (); + } + else + { + gripe_binary_op_conv (octave_value::binary_op_as_string (op)); + return retval; + } + } + else + tv2 = v2; + + if (cf1 || cf2) + { retval = do_binary_op (op, tv1, tv2); - } - else - { - //demote double -> single and try again - cf1 = tv1.numeric_demotion_function (); - - cf2 = tv2.numeric_demotion_function (); + } + else + { + //demote double -> single and try again + cf1 = tv1.numeric_demotion_function (); + + cf2 = tv2.numeric_demotion_function (); // Try biased (one-sided) conversions first. if (cf2.type_id () >= 0 @@ -1932,62 +1932,62 @@ && octave_value_typeinfo::lookup_binary_op (op, cf1.type_id (), t2)) cf2 = 0; - if (cf1) - { - octave_base_value *tmp = cf1 (*tv1.rep); - - if (tmp) - { - tv1 = octave_value (tmp); - t1 = tv1.type_id (); - } - else - { - gripe_binary_op_conv (octave_value::binary_op_as_string (op)); - return retval; - } - } - - if (cf2) - { - octave_base_value *tmp = cf2 (*tv2.rep); - - if (tmp) - { - tv2 = octave_value (tmp); - t2 = tv2.type_id (); - } - else - { - gripe_binary_op_conv (octave_value::binary_op_as_string (op)); - return retval; - } - } - - if (cf1 || cf2) - { - f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); - - if (f) - { - try - { - retval = f (*tv1.rep, *tv2.rep); - } - catch (octave_execution_exception) - { - gripe_library_execution_error (); - } - } - else - gripe_binary_op (octave_value::binary_op_as_string (op), - v1.type_name (), v2.type_name ()); - } - else - gripe_binary_op (octave_value::binary_op_as_string (op), - v1.type_name (), v2.type_name ()); - } - } + if (cf1) + { + octave_base_value *tmp = cf1 (*tv1.rep); + + if (tmp) + { + tv1 = octave_value (tmp); + t1 = tv1.type_id (); + } + else + { + gripe_binary_op_conv (octave_value::binary_op_as_string (op)); + return retval; + } + } + + if (cf2) + { + octave_base_value *tmp = cf2 (*tv2.rep); + + if (tmp) + { + tv2 = octave_value (tmp); + t2 = tv2.type_id (); + } + else + { + gripe_binary_op_conv (octave_value::binary_op_as_string (op)); + return retval; + } + } + + if (cf1 || cf2) + { + f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); + + if (f) + { + try + { + retval = f (*tv1.rep, *tv2.rep); + } + catch (octave_execution_exception) + { + gripe_library_execution_error (); + } + } + else + gripe_binary_op (octave_value::binary_op_as_string (op), + v1.type_name (), v2.type_name ()); + } + else + gripe_binary_op (octave_value::binary_op_as_string (op), + v1.type_name (), v2.type_name ()); + } + } } return retval; @@ -2072,38 +2072,38 @@ || t2 == octave_class::static_type_id ()) { octave_value_typeinfo::binary_class_op_fcn f - = octave_value_typeinfo::lookup_binary_class_op (op); + = octave_value_typeinfo::lookup_binary_class_op (op); if (f) - { - try - { - retval = f (v1, v2); - } - catch (octave_execution_exception) - { - gripe_library_execution_error (); - } - } + { + try + { + retval = f (v1, v2); + } + catch (octave_execution_exception) + { + gripe_library_execution_error (); + } + } else retval = decompose_binary_op (op, v1, v2); } else { octave_value_typeinfo::binary_op_fcn f - = octave_value_typeinfo::lookup_binary_op (op, t1, t2); + = octave_value_typeinfo::lookup_binary_op (op, t1, t2); if (f) - { - try - { - retval = f (*v1.rep, *v2.rep); - } - catch (octave_execution_exception) - { - gripe_library_execution_error (); - } - } + { + try + { + retval = f (*v1.rep, *v2.rep); + } + catch (octave_execution_exception) + { + gripe_library_execution_error (); + } + } else retval = decompose_binary_op (op, v1, v2); } @@ -2115,7 +2115,7 @@ gripe_cat_op (const std::string& tn1, const std::string& tn2) { error ("concatenation operator not implemented for `%s' by `%s' operations", - tn1.c_str (), tn2.c_str ()); + tn1.c_str (), tn2.c_str ()); } static void @@ -2126,7 +2126,7 @@ octave_value do_cat_op (const octave_value& v1, const octave_value& v2, - const Array& ra_idx) + const Array& ra_idx) { octave_value retval; @@ -2142,13 +2142,13 @@ if (f) { try - { - retval = f (*v1.rep, *v2.rep, ra_idx); - } + { + retval = f (*v1.rep, *v2.rep, ra_idx); + } catch (octave_execution_exception) - { - gripe_library_execution_error (); - } + { + gripe_library_execution_error (); + } } else { @@ -2167,47 +2167,47 @@ cf2 = 0; if (cf1) - { - octave_base_value *tmp = cf1 (*v1.rep); - - if (tmp) - { - tv1 = octave_value (tmp); - t1 = tv1.type_id (); - } - else - { - gripe_cat_op_conv (); - return retval; - } - } + { + octave_base_value *tmp = cf1 (*v1.rep); + + if (tmp) + { + tv1 = octave_value (tmp); + t1 = tv1.type_id (); + } + else + { + gripe_cat_op_conv (); + return retval; + } + } else - tv1 = v1; + tv1 = v1; if (cf2) - { - octave_base_value *tmp = cf2 (*v2.rep); - - if (tmp) - { - tv2 = octave_value (tmp); - t2 = tv2.type_id (); - } - else - { - gripe_cat_op_conv (); - return retval; - } - } + { + octave_base_value *tmp = cf2 (*v2.rep); + + if (tmp) + { + tv2 = octave_value (tmp); + t2 = tv2.type_id (); + } + else + { + gripe_cat_op_conv (); + return retval; + } + } else - tv2 = v2; + tv2 = v2; if (cf1 || cf2) - { + { retval = do_cat_op (tv1, tv2, ra_idx); - } + } else - gripe_cat_op (v1.type_name (), v2.type_name ()); + gripe_cat_op (v1.type_name (), v2.type_name ()); } return retval; @@ -2227,7 +2227,7 @@ gripe_unary_op (const std::string& on, const std::string& tn) { error ("unary operator `%s' not implemented for `%s' operands", - on.c_str (), tn.c_str ()); + on.c_str (), tn.c_str ()); } static void @@ -2246,22 +2246,22 @@ if (t == octave_class::static_type_id ()) { octave_value_typeinfo::unary_class_op_fcn f - = octave_value_typeinfo::lookup_unary_class_op (op); + = octave_value_typeinfo::lookup_unary_class_op (op); if (f) - { - try - { - retval = f (v); - } - catch (octave_execution_exception) - { - gripe_library_execution_error (); - } - } + { + try + { + retval = f (v); + } + catch (octave_execution_exception) + { + gripe_library_execution_error (); + } + } else - gripe_unary_op (octave_value::unary_op_as_string (op), - v.class_name ()); + gripe_unary_op (octave_value::unary_op_as_string (op), + v.class_name ()); } else { @@ -2269,41 +2269,41 @@ // classes (double, char, int8, etc.) octave_value_typeinfo::unary_op_fcn f - = octave_value_typeinfo::lookup_unary_op (op, t); + = octave_value_typeinfo::lookup_unary_op (op, t); if (f) - { - try - { - retval = f (*v.rep); - } - catch (octave_execution_exception) - { - gripe_library_execution_error (); - } - } + { + try + { + retval = f (*v.rep); + } + catch (octave_execution_exception) + { + gripe_library_execution_error (); + } + } else - { - octave_value tv; - octave_base_value::type_conv_fcn cf - = v.numeric_conversion_function (); - - if (cf) - { - octave_base_value *tmp = cf (*v.rep); - - if (tmp) - { - tv = octave_value (tmp); + { + octave_value tv; + octave_base_value::type_conv_fcn cf + = v.numeric_conversion_function (); + + if (cf) + { + octave_base_value *tmp = cf (*v.rep); + + if (tmp) + { + tv = octave_value (tmp); retval = do_unary_op (op, tv); - } - else - gripe_unary_op_conv (octave_value::unary_op_as_string (op)); - } - else - gripe_unary_op (octave_value::unary_op_as_string (op), - v.type_name ()); - } + } + else + gripe_unary_op_conv (octave_value::unary_op_as_string (op)); + } + else + gripe_unary_op (octave_value::unary_op_as_string (op), + v.type_name ()); + } } return retval; @@ -2311,10 +2311,10 @@ static void gripe_unary_op_conversion_failed (const std::string& op, - const std::string& tn) + const std::string& tn) { error ("operator %s: type conversion for `%s' failed", - op.c_str (), tn.c_str ()); + op.c_str (), tn.c_str ()); } const octave_value& @@ -2426,10 +2426,10 @@ #if 0 static void gripe_unary_op_failed_or_no_method (const std::string& on, - const std::string& tn) + const std::string& tn) { error ("operator %s: no method, or unable to evaluate for %s operand", - on.c_str (), tn.c_str ()); + on.c_str (), tn.c_str ()); } #endif @@ -2441,7 +2441,7 @@ octave_value octave_value::do_non_const_unary_op (unary_op op, const std::string& type, - const std::list& idx) + const std::list& idx) { octave_value retval; @@ -2482,8 +2482,8 @@ default: { - std::string on = unary_op_as_string (op); - error ("operator %s: no assign operator found", on.c_str ()); + std::string on = unary_op_as_string (op); + error ("operator %s: no assign operator found", on.c_str ()); } } @@ -2555,8 +2555,8 @@ default: { - std::string on = assign_op_as_string (op); - error ("operator %s: no binary operator found", on.c_str ()); + std::string on = assign_op_as_string (op); + error ("operator %s: no binary operator found", on.c_str ()); } } @@ -2571,27 +2571,27 @@ if (type.length () > 0) { switch (type[0]) - { - case '(': - { - if (type.length () > 1 && type[1] == '.') - retval = Octave_map (); - else - retval = octave_value (rhs.empty_clone ()); - } - break; - - case '{': - retval = Cell (); - break; - - case '.': - retval = Octave_map (); - break; - - default: - panic_impossible (); - } + { + case '(': + { + if (type.length () > 1 && type[1] == '.') + retval = Octave_map (); + else + retval = octave_value (rhs.empty_clone ()); + } + break; + + case '{': + retval = Cell (); + break; + + case '.': + retval = Octave_map (); + break; + + default: + panic_impossible (); + } } else retval = octave_value (rhs.empty_clone ()); @@ -2791,7 +2791,7 @@ arg0.make_unique (); if (! error_state) - retval = arg0.subsasgn (type, idx, args(2)); + retval = arg0.subsasgn (type, idx, args(2)); } else print_usage (); diff --git a/src/pager.cc b/src/pager.cc --- a/src/pager.cc +++ b/src/pager.cc @@ -110,20 +110,20 @@ if (pid > 0) { if (WIFEXITED (status) || WIFSIGNALLED (status)) - { - // Avoid warning() since that will put us back in the pager, - // which would be bad news. + { + // Avoid warning() since that will put us back in the pager, + // which would be bad news. - std::cerr << "warning: connection to external pager lost (pid = " - << pid << ")" << std::endl; - std::cerr << "warning: flushing pending output (please wait)" - << std::endl; + std::cerr << "warning: connection to external pager lost (pid = " + << pid << ")" << std::endl; + std::cerr << "warning: flushing pending output (please wait)" + << std::endl; - // Request removal of this PID from the list of child - // processes. + // Request removal of this PID from the list of child + // processes. - retval = true; - } + retval = true; + } } return retval; @@ -146,53 +146,53 @@ if (msg && len > 0) { if (bypass_pager) - { - std::cout.write (msg, len); - std::cout.flush (); - } + { + std::cout.write (msg, len); + std::cout.flush (); + } else - { - if (! external_pager) - { - std::string pgr = pager_command (); + { + if (! external_pager) + { + std::string pgr = pager_command (); - if (! pgr.empty ()) - { - external_pager = new oprocstream (pgr.c_str ()); + if (! pgr.empty ()) + { + external_pager = new oprocstream (pgr.c_str ()); - if (external_pager) - octave_child_list::insert (external_pager->pid (), - pager_event_handler); - } - } + if (external_pager) + octave_child_list::insert (external_pager->pid (), + pager_event_handler); + } + } - if (external_pager) - { - if (external_pager->good ()) - { - external_pager->write (msg, len); + if (external_pager) + { + if (external_pager->good ()) + { + external_pager->write (msg, len); - external_pager->flush (); + external_pager->flush (); #if defined (EPIPE) - if (errno == EPIPE) - external_pager->setstate (std::ios::failbit); + if (errno == EPIPE) + external_pager->setstate (std::ios::failbit); #endif - } - else - { - // FIXME -- omething is not right with the - // pager. If it died then we should receive a - // signal for that. If there is some other problem, - // then what? - } - } - else - { - std::cout.write (msg, len); - std::cout.flush (); - } - } + } + else + { + // FIXME -- omething is not right with the + // pager. If it died then we should receive a + // signal for that. If there is some other problem, + // then what? + } + } + else + { + std::cout.write (msg, len); + std::cout.flush (); + } + } } } @@ -212,18 +212,18 @@ int chars_this_line = 0; for (int i = 0; i < len; i++) - { - if (*s++ == '\n') - { - count += chars_this_line / cols + 1; - chars_this_line = 0; - } - else - chars_this_line++; - } + { + if (*s++ == '\n') + { + count += chars_this_line / cols + 1; + chars_this_line = 0; + } + else + chars_this_line++; + } if (count > available_rows) - return true; + return true; } return false; @@ -242,20 +242,20 @@ int len = pptr () - buf; bool bypass_pager = (! interactive - || ! Vpage_screen_output - || (really_flush_to_pager - && Vpage_screen_output - && ! Vpage_output_immediately - && ! more_than_a_screenful (buf, len))); + || ! Vpage_screen_output + || (really_flush_to_pager + && Vpage_screen_output + && ! Vpage_output_immediately + && ! more_than_a_screenful (buf, len))); if (len > 0) - { - do_sync (buf, len, bypass_pager); + { + do_sync (buf, len, bypass_pager); - flush_current_contents_to_diary (); + flush_current_contents_to_diary (); - seekoff (0, std::ios::beg); - } + seekoff (0, std::ios::beg); + } } return 0; @@ -289,7 +289,7 @@ int len = pptr () - buf; if (len > 0) - external_diary_file.write (buf, len); + external_diary_file.write (buf, len); } seekoff (0, std::ios::beg); @@ -459,24 +459,24 @@ case 2: { - std::string arg = argv[1]; + std::string arg = argv[1]; - if (arg == "on") - { - write_to_diary_file = true; - open_diary_file (); - } - else if (arg == "off") - { - close_diary_file (); - write_to_diary_file = false; - } - else - { - diary_file = arg; - write_to_diary_file = true; - open_diary_file (); - } + if (arg == "on") + { + write_to_diary_file = true; + open_diary_file (); + } + else if (arg == "off") + { + close_diary_file (); + write_to_diary_file = false; + } + else + { + diary_file = arg; + write_to_diary_file = true; + open_diary_file (); + } } break; @@ -512,11 +512,11 @@ std::string arg = argv[1]; if (arg == "on") - Vpage_screen_output = true; + Vpage_screen_output = true; else if (arg == "off") - Vpage_screen_output = false; + Vpage_screen_output = false; else - error ("more: unrecognized argument `%s'", arg.c_str ()); + error ("more: unrecognized argument `%s'", arg.c_str ()); } else if (argc == 1) Vpage_screen_output = ! Vpage_screen_output; diff --git a/src/pr-output.cc b/src/pr-output.cc --- a/src/pr-output.cc +++ b/src/pr-output.cc @@ -139,7 +139,7 @@ public: float_format (int w = current_output_max_field_width (), - int p = current_output_precision (), int f = 0) + int p = current_output_precision (), int f = 0) : fw (w), prec (p), fmt (f), up (0), sp (0) { } float_format (const float_format& ff) @@ -148,13 +148,13 @@ float_format& operator = (const float_format& ff) { if (&ff != this) - { - fw = ff.fw; - prec = ff.prec; - fmt = ff.fmt; - up = ff.up; - sp = ff.sp; - } + { + fw = ff.fw; + prec = ff.prec; + fmt = ff.fmt; + up = ff.up; + sp = ff.sp; + } return *this; } @@ -176,10 +176,10 @@ { sp = tz ? std::ios::showpoint : 0; return *this; } friend std::ostream& operator << (std::ostream& os, - const pr_formatted_float& pff); + const pr_formatted_float& pff); friend std::ostream& operator << (std::ostream& os, - const pr_rational_float& pff); + const pr_rational_float& pff); private: @@ -266,57 +266,57 @@ s = buf2.str(); while (1) - { - double flip = 1. / frac; - double step = xround (flip); - double nextn = n; - double nextd = d; - - // Have we converged to 1/intmax ? - if (m > 100 || fabs (frac) < 1 / static_cast(INT_MAX)) - { - lastn = n; - lastd = d; - break; - } - - frac = flip - step; - n = n * step + lastn; - d = d * step + lastd; - lastn = nextn; - lastd = nextd; - - std::ostringstream buf; - buf.flags (std::ios::fixed); - buf << std::setprecision (0) << static_cast(n) - << "/" << static_cast(d); - m++; - - if (n < 0 && d < 0) - { - // Double negative, string can be two characters longer.. - if (buf.str().length() > static_cast(len + 2) && - m > 1) - break; - } - else if (buf.str().length() > static_cast(len) && - m > 1) - break; - - s = buf.str(); - } + { + double flip = 1. / frac; + double step = xround (flip); + double nextn = n; + double nextd = d; + + // Have we converged to 1/intmax ? + if (m > 100 || fabs (frac) < 1 / static_cast(INT_MAX)) + { + lastn = n; + lastd = d; + break; + } + + frac = flip - step; + n = n * step + lastn; + d = d * step + lastd; + lastn = nextn; + lastd = nextd; + + std::ostringstream buf; + buf.flags (std::ios::fixed); + buf << std::setprecision (0) << static_cast(n) + << "/" << static_cast(d); + m++; + + if (n < 0 && d < 0) + { + // Double negative, string can be two characters longer.. + if (buf.str().length() > static_cast(len + 2) && + m > 1) + break; + } + else if (buf.str().length() > static_cast(len) && + m > 1) + break; + + s = buf.str(); + } if (lastd < 0.) - { - // Move sign to the top - lastd = - lastd; - lastn = - lastn; - std::ostringstream buf; - buf.flags (std::ios::fixed); - buf << std::setprecision (0) << static_cast(lastn) - << "/" << static_cast(lastd); - s = buf.str(); - } + { + // Move sign to the top + lastd = - lastd; + lastn = - lastn; + std::ostringstream buf; + buf.flags (std::ios::fixed); + buf << std::setprecision (0) << static_cast(lastn) + << "/" << static_cast(lastd); + s = buf.str(); + } } return s; @@ -378,14 +378,14 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - double val = m(i,j); - if (xisinf (val) || xisnan (val)) - continue; - - all_inf_or_nan = false; - - if (val > result) - result = val; + double val = m(i,j); + if (xisinf (val) || xisnan (val)) + continue; + + all_inf_or_nan = false; + + if (val > result) + result = val; } if (all_inf_or_nan) @@ -407,14 +407,14 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - double val = m(i,j); - if (xisinf (val) || xisnan (val)) - continue; - - all_inf_or_nan = false; - - if (val < result) - result = val; + double val = m(i,j); + if (xisinf (val) || xisnan (val)) + continue; + + all_inf_or_nan = false; + + if (val < result) + result = val; } if (all_inf_or_nan) @@ -444,7 +444,7 @@ { fw = digits < 0 ? 4 : digits + 3; if (inf_or_nan && fw < 4) - fw = 4; + fw = 4; rd = 2; } else if (hex_format) @@ -461,49 +461,49 @@ { fw = 1 + digits; if (inf_or_nan && fw < 4) - fw = 4; + fw = 4; rd = fw; } else { if (digits > 0) - { - ld = digits; - rd = prec > digits ? prec - digits : prec; - digits++; - } + { + ld = digits; + rd = prec > digits ? prec - digits : prec; + digits++; + } else - { - ld = 1; - rd = prec > digits ? prec - digits : prec; - digits = -digits + 1; - } + { + ld = 1; + rd = prec > digits ? prec - digits : prec; + digits = -digits + 1; + } fw = 1 + ld + 1 + rd; if (inf_or_nan && fw < 4) - fw = 4; + fw = 4; } if (! (rat_format || bank_format || hex_format || bit_format) && (fw > Voutput_max_field_width || print_e || print_g)) { if (print_g) - fmt = float_format (); + fmt = float_format (); else - { - int exp_field = 4; - if (digits > 100) - exp_field++; - - fw = 2 + prec + exp_field; - if (inf_or_nan && fw < 4) - fw = 4; - - fmt = float_format (fw, prec - 1, std::ios::scientific); - } + { + int exp_field = 4; + if (digits > 100) + exp_field++; + + fw = 2 + prec + exp_field; + if (inf_or_nan && fw < 4) + fw = 4; + + fmt = float_format (fw, prec - 1, std::ios::scientific); + } if (print_big_e) - fmt.uppercase (); + fmt.uppercase (); } else if (! bank_format && (inf_or_nan || int_only)) fmt = float_format (fw, rd); @@ -543,7 +543,7 @@ static void set_real_matrix_format (int x_max, int x_min, bool inf_or_nan, - int int_or_inf_or_nan, int& fw) + int int_or_inf_or_nan, int& fw) { static float_format fmt; @@ -561,7 +561,7 @@ int digits = x_max > x_min ? x_max : x_min; fw = digits <= 0 ? 4 : digits + 3; if (inf_or_nan && fw < 4) - fw = 4; + fw = 4; rd = 2; } else if (hex_format) @@ -579,76 +579,76 @@ rd = prec; fw = rd + 2; if (inf_or_nan && fw < 4) - fw = 4; + fw = 4; } else if (int_or_inf_or_nan) { int digits = x_max > x_min ? x_max : x_min; fw = digits <= 0 ? 2 : digits + 1; if (inf_or_nan && fw < 4) - fw = 4; + fw = 4; rd = fw; } else { int ld_max, rd_max; if (x_max > 0) - { - ld_max = x_max; - rd_max = prec > x_max ? prec - x_max : prec; - x_max++; - } + { + ld_max = x_max; + rd_max = prec > x_max ? prec - x_max : prec; + x_max++; + } else - { - ld_max = 1; - rd_max = prec > x_max ? prec - x_max : prec; - x_max = -x_max + 1; - } + { + ld_max = 1; + rd_max = prec > x_max ? prec - x_max : prec; + x_max = -x_max + 1; + } int ld_min, rd_min; if (x_min > 0) - { - ld_min = x_min; - rd_min = prec > x_min ? prec - x_min : prec; - x_min++; - } + { + ld_min = x_min; + rd_min = prec > x_min ? prec - x_min : prec; + x_min++; + } else - { - ld_min = 1; - rd_min = prec > x_min ? prec - x_min : prec; - x_min = -x_min + 1; - } + { + ld_min = 1; + rd_min = prec > x_min ? prec - x_min : prec; + x_min = -x_min + 1; + } ld = ld_max > ld_min ? ld_max : ld_min; rd = rd_max > rd_min ? rd_max : rd_min; fw = 1 + ld + 1 + rd; if (inf_or_nan && fw < 4) - fw = 4; + fw = 4; } if (! (rat_format || bank_format || hex_format || bit_format) && (print_e - || print_g - || (! Vfixed_point_format && fw > Voutput_max_field_width))) + || print_g + || (! Vfixed_point_format && fw > Voutput_max_field_width))) { if (print_g) - fmt = float_format (); + fmt = float_format (); else - { - int exp_field = 4; - if (x_max > 100 || x_min > 100) - exp_field++; - - fw = 2 + prec + exp_field; - if (inf_or_nan && fw < 4) - fw = 4; - - fmt = float_format (fw, prec - 1, std::ios::scientific); - } + { + int exp_field = 4; + if (x_max > 100 || x_min > 100) + exp_field++; + + fw = 2 + prec + exp_field; + if (inf_or_nan && fw < 4) + fw = 4; + + fmt = float_format (fw, prec - 1, std::ios::scientific); + } if (print_big_e) - fmt.uppercase (); + fmt.uppercase (); } else if (! bank_format && int_or_inf_or_nan) fmt = float_format (fw, rd); @@ -696,7 +696,7 @@ static void set_complex_format (int x_max, int x_min, int r_x, bool inf_or_nan, - int int_only, int& r_fw, int& i_fw) + int int_only, int& r_fw, int& i_fw) { static float_format r_fmt; static float_format i_fmt; @@ -717,7 +717,7 @@ i_fw = 0; r_fw = digits <= 0 ? 4 : digits + 3; if (inf_or_nan && r_fw < 4) - r_fw = 4; + r_fw = 4; rd = 2; } else if (hex_format) @@ -738,41 +738,41 @@ i_fw = digits <= 0 ? 1 : digits; r_fw = i_fw + 1; if (inf_or_nan && i_fw < 3) - { - i_fw = 3; - r_fw = 4; - } + { + i_fw = 3; + r_fw = 4; + } rd = r_fw; } else { int ld_max, rd_max; if (x_max > 0) - { - ld_max = x_max; - rd_max = prec > x_max ? prec - x_max : prec; - x_max++; - } + { + ld_max = x_max; + rd_max = prec > x_max ? prec - x_max : prec; + x_max++; + } else - { - ld_max = 1; - rd_max = prec > x_max ? prec - x_max : prec; - x_max = -x_max + 1; - } + { + ld_max = 1; + rd_max = prec > x_max ? prec - x_max : prec; + x_max = -x_max + 1; + } int ld_min, rd_min; if (x_min > 0) - { - ld_min = x_min; - rd_min = prec > x_min ? prec - x_min : prec; - x_min++; - } + { + ld_min = x_min; + rd_min = prec > x_min ? prec - x_min : prec; + x_min++; + } else - { - ld_min = 1; - rd_min = prec > x_min ? prec - x_min : prec; - x_min = -x_min + 1; - } + { + ld_min = 1; + rd_min = prec > x_min ? prec - x_min : prec; + x_min = -x_min + 1; + } ld = ld_max > ld_min ? ld_max : ld_min; rd = rd_max > rd_min ? rd_max : rd_min; @@ -780,43 +780,43 @@ i_fw = ld + 1 + rd; r_fw = i_fw + 1; if (inf_or_nan && i_fw < 3) - { - i_fw = 3; - r_fw = 4; - } + { + i_fw = 3; + r_fw = 4; + } } if (! (rat_format || bank_format || hex_format || bit_format) && (r_fw > Voutput_max_field_width || print_e || print_g)) { if (print_g) - { - r_fmt = float_format (); - i_fmt = float_format (); - } + { + r_fmt = float_format (); + i_fmt = float_format (); + } else - { - int exp_field = 4; - if (x_max > 100 || x_min > 100) - exp_field++; - - i_fw = prec + exp_field; - r_fw = i_fw + 1; - if (inf_or_nan && i_fw < 3) - { - i_fw = 3; - r_fw = 4; - } - - r_fmt = float_format (r_fw, prec - 1, std::ios::scientific); - i_fmt = float_format (i_fw, prec - 1, std::ios::scientific); - } + { + int exp_field = 4; + if (x_max > 100 || x_min > 100) + exp_field++; + + i_fw = prec + exp_field; + r_fw = i_fw + 1; + if (inf_or_nan && i_fw < 3) + { + i_fw = 3; + r_fw = 4; + } + + r_fmt = float_format (r_fw, prec - 1, std::ios::scientific); + i_fmt = float_format (i_fw, prec - 1, std::ios::scientific); + } if (print_big_e) - { - r_fmt.uppercase (); - i_fmt.uppercase (); - } + { + r_fmt.uppercase (); + i_fmt.uppercase (); + } } else if (! bank_format && (inf_or_nan || int_only)) { @@ -883,8 +883,8 @@ static void set_complex_matrix_format (int x_max, int x_min, int r_x_max, - int r_x_min, bool inf_or_nan, - int int_or_inf_or_nan, int& r_fw, int& i_fw) + int r_x_min, bool inf_or_nan, + int int_or_inf_or_nan, int& r_fw, int& i_fw) { static float_format r_fmt; static float_format i_fmt; @@ -905,7 +905,7 @@ i_fw = 0; r_fw = digits <= 0 ? 4 : digits + 3; if (inf_or_nan && r_fw < 4) - r_fw = 4; + r_fw = 4; rd = 2; } else if (hex_format) @@ -926,10 +926,10 @@ i_fw = rd + 1; r_fw = i_fw + 1; if (inf_or_nan && i_fw < 3) - { - i_fw = 3; - r_fw = 4; - } + { + i_fw = 3; + r_fw = 4; + } } else if (int_or_inf_or_nan) { @@ -937,41 +937,41 @@ i_fw = digits <= 0 ? 1 : digits; r_fw = i_fw + 1; if (inf_or_nan && i_fw < 3) - { - i_fw = 3; - r_fw = 4; - } + { + i_fw = 3; + r_fw = 4; + } rd = r_fw; } else { int ld_max, rd_max; if (x_max > 0) - { - ld_max = x_max; - rd_max = prec > x_max ? prec - x_max : prec; - x_max++; - } + { + ld_max = x_max; + rd_max = prec > x_max ? prec - x_max : prec; + x_max++; + } else - { - ld_max = 1; - rd_max = prec > x_max ? prec - x_max : prec; - x_max = -x_max + 1; - } + { + ld_max = 1; + rd_max = prec > x_max ? prec - x_max : prec; + x_max = -x_max + 1; + } int ld_min, rd_min; if (x_min > 0) - { - ld_min = x_min; - rd_min = prec > x_min ? prec - x_min : prec; - x_min++; - } + { + ld_min = x_min; + rd_min = prec > x_min ? prec - x_min : prec; + x_min++; + } else - { - ld_min = 1; - rd_min = prec > x_min ? prec - x_min : prec; - x_min = -x_min + 1; - } + { + ld_min = 1; + rd_min = prec > x_min ? prec - x_min : prec; + x_min = -x_min + 1; + } ld = ld_max > ld_min ? ld_max : ld_min; rd = rd_max > rd_min ? rd_max : rd_min; @@ -979,45 +979,45 @@ i_fw = ld + 1 + rd; r_fw = i_fw + 1; if (inf_or_nan && i_fw < 3) - { - i_fw = 3; - r_fw = 4; - } + { + i_fw = 3; + r_fw = 4; + } } if (! (rat_format || bank_format || hex_format || bit_format) && (print_e - || print_g - || (! Vfixed_point_format && r_fw > Voutput_max_field_width))) + || print_g + || (! Vfixed_point_format && r_fw > Voutput_max_field_width))) { if (print_g) - { - r_fmt = float_format (); - i_fmt = float_format (); - } + { + r_fmt = float_format (); + i_fmt = float_format (); + } else - { - int exp_field = 4; - if (x_max > 100 || x_min > 100) - exp_field++; - - i_fw = prec + exp_field; - r_fw = i_fw + 1; - if (inf_or_nan && i_fw < 3) - { - i_fw = 3; - r_fw = 4; - } - - r_fmt = float_format (r_fw, prec - 1, std::ios::scientific); - i_fmt = float_format (i_fw, prec - 1, std::ios::scientific); - } + { + int exp_field = 4; + if (x_max > 100 || x_min > 100) + exp_field++; + + i_fw = prec + exp_field; + r_fw = i_fw + 1; + if (inf_or_nan && i_fw < 3) + { + i_fw = 3; + r_fw = 4; + } + + r_fmt = float_format (r_fw, prec - 1, std::ios::scientific); + i_fmt = float_format (i_fw, prec - 1, std::ios::scientific); + } if (print_big_e) - { - r_fmt.uppercase (); - i_fmt.uppercase (); - } + { + r_fmt.uppercase (); + i_fmt.uppercase (); + } } else if (! bank_format && int_or_inf_or_nan) { @@ -1049,7 +1049,7 @@ bool inf_or_nan = cm.any_element_is_inf_or_nan (); bool int_or_inf_or_nan = (rp.all_elements_are_int_or_inf_or_nan () - && ip.all_elements_are_int_or_inf_or_nan ()); + && ip.all_elements_are_int_or_inf_or_nan ()); Matrix r_m_abs = rp.abs (); double r_max_abs = pr_max_internal (r_m_abs); @@ -1077,7 +1077,7 @@ scale = (x_max == 0 || int_or_inf_or_nan) ? 1.0 : std::pow (10.0, x_max - 1); set_complex_matrix_format (x_max, x_min, r_x_max, r_x_min, inf_or_nan, - int_or_inf_or_nan, r_fw, i_fw); + int_or_inf_or_nan, r_fw, i_fw); } static inline void @@ -1133,31 +1133,31 @@ { int ld_max, rd_max; if (x_max > 0) - { - ld_max = x_max; - rd_max = prec > x_max ? prec - x_max : prec; - x_max++; - } + { + ld_max = x_max; + rd_max = prec > x_max ? prec - x_max : prec; + x_max++; + } else - { - ld_max = 1; - rd_max = prec > x_max ? prec - x_max : prec; - x_max = -x_max + 1; - } + { + ld_max = 1; + rd_max = prec > x_max ? prec - x_max : prec; + x_max = -x_max + 1; + } int ld_min, rd_min; if (x_min > 0) - { - ld_min = x_min; - rd_min = prec > x_min ? prec - x_min : prec; - x_min++; - } + { + ld_min = x_min; + rd_min = prec > x_min ? prec - x_min : prec; + x_min++; + } else - { - ld_min = 1; - rd_min = prec > x_min ? prec - x_min : prec; - x_min = -x_min + 1; - } + { + ld_min = 1; + rd_min = prec > x_min ? prec - x_min : prec; + x_min = -x_min + 1; + } ld = ld_max > ld_min ? ld_max : ld_min; rd = rd_max > rd_min ? rd_max : rd_min; @@ -1167,24 +1167,24 @@ if (! (rat_format || bank_format || hex_format || bit_format) && (print_e - || print_g - || (! Vfixed_point_format && fw > Voutput_max_field_width))) + || print_g + || (! Vfixed_point_format && fw > Voutput_max_field_width))) { if (print_g) - fmt = float_format (); + fmt = float_format (); else - { - int exp_field = 4; - if (x_max > 100 || x_min > 100) - exp_field++; - - fw = 3 + prec + exp_field; - - fmt = float_format (fw, prec - 1, std::ios::scientific); - } + { + int exp_field = 4; + if (x_max > 100 || x_min > 100) + exp_field++; + + fw = 3 + prec + exp_field; + + fmt = float_format (fw, prec - 1, std::ios::scientific); + } if (print_big_e) - fmt.uppercase (); + fmt.uppercase (); } else if (! bank_format && all_ints) fmt = float_format (fw, rd); @@ -1291,108 +1291,108 @@ // {bit,hex}_format == 2: print native if (hex_format) - { - equiv tmp; - tmp.d = d; - - // Unless explicitly asked for, always print in big-endian - // format. - - // FIXME -- is it correct to swap bytes for VAX - // formats and not for Cray? - - // FIXME -- will bad things happen if we are - // interrupted before resetting the format flags and fill - // character? - - oct_mach_info::float_format flt_fmt = - oct_mach_info::native_float_format (); - - char ofill = os.fill ('0'); - - std::ios::fmtflags oflags - = os.flags (std::ios::right | std::ios::hex); - - if (hex_format > 1 - || flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian - || flt_fmt == oct_mach_info::flt_fmt_cray - || flt_fmt == oct_mach_info::flt_fmt_unknown) - { - for (size_t i = 0; i < sizeof (double); i++) - os << std::setw (2) << static_cast (tmp.i[i]); - } - else - { - for (int i = sizeof (double) - 1; i >= 0; i--) - os << std::setw (2) << static_cast (tmp.i[i]); - } - - os.fill (ofill); - os.setf (oflags); - } + { + equiv tmp; + tmp.d = d; + + // Unless explicitly asked for, always print in big-endian + // format. + + // FIXME -- is it correct to swap bytes for VAX + // formats and not for Cray? + + // FIXME -- will bad things happen if we are + // interrupted before resetting the format flags and fill + // character? + + oct_mach_info::float_format flt_fmt = + oct_mach_info::native_float_format (); + + char ofill = os.fill ('0'); + + std::ios::fmtflags oflags + = os.flags (std::ios::right | std::ios::hex); + + if (hex_format > 1 + || flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian + || flt_fmt == oct_mach_info::flt_fmt_cray + || flt_fmt == oct_mach_info::flt_fmt_unknown) + { + for (size_t i = 0; i < sizeof (double); i++) + os << std::setw (2) << static_cast (tmp.i[i]); + } + else + { + for (int i = sizeof (double) - 1; i >= 0; i--) + os << std::setw (2) << static_cast (tmp.i[i]); + } + + os.fill (ofill); + os.setf (oflags); + } else if (bit_format) - { - equiv tmp; - tmp.d = d; - - // FIXME -- is it correct to swap bytes for VAX - // formats and not for Cray? - - oct_mach_info::float_format flt_fmt = - oct_mach_info::native_float_format (); - - if (flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian - || flt_fmt == oct_mach_info::flt_fmt_cray - || flt_fmt == oct_mach_info::flt_fmt_unknown) - { - for (size_t i = 0; i < sizeof (double); i++) - PRINT_CHAR_BITS (os, tmp.i[i]); - } - else - { - if (bit_format > 1) - { - for (size_t i = 0; i < sizeof (double); i++) - PRINT_CHAR_BITS_SWAPPED (os, tmp.i[i]); - } - else - { - for (int i = sizeof (double) - 1; i >= 0; i--) - PRINT_CHAR_BITS (os, tmp.i[i]); - } - } - } + { + equiv tmp; + tmp.d = d; + + // FIXME -- is it correct to swap bytes for VAX + // formats and not for Cray? + + oct_mach_info::float_format flt_fmt = + oct_mach_info::native_float_format (); + + if (flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian + || flt_fmt == oct_mach_info::flt_fmt_cray + || flt_fmt == oct_mach_info::flt_fmt_unknown) + { + for (size_t i = 0; i < sizeof (double); i++) + PRINT_CHAR_BITS (os, tmp.i[i]); + } + else + { + if (bit_format > 1) + { + for (size_t i = 0; i < sizeof (double); i++) + PRINT_CHAR_BITS_SWAPPED (os, tmp.i[i]); + } + else + { + for (int i = sizeof (double) - 1; i >= 0; i--) + PRINT_CHAR_BITS (os, tmp.i[i]); + } + } + } else if (octave_is_NA (d)) - { - if (fw > 0) - os << std::setw (fw) << "NA"; - else - os << "NA"; - } + { + if (fw > 0) + os << std::setw (fw) << "NA"; + else + os << "NA"; + } else if (rat_format) - os << pr_rational_float (*fmt, d); + os << pr_rational_float (*fmt, d); else if (xisinf (d)) - { - const char *s; - if (d < 0.0) - s = "-Inf"; - else - s = "Inf"; - - if (fw > 0) - os << std::setw (fw) << s; - else - os << s; - } + { + const char *s; + if (d < 0.0) + s = "-Inf"; + else + s = "Inf"; + + if (fw > 0) + os << std::setw (fw) << s; + else + os << s; + } else if (xisnan (d)) - { - if (fw > 0) - os << std::setw (fw) << "NaN"; - else - os << "NaN"; - } + { + if (fw > 0) + os << std::setw (fw) << "NaN"; + else + os << "NaN"; + } else - os << pr_formatted_float (*fmt, d); + os << pr_formatted_float (*fmt, d); } else os << d; @@ -1415,7 +1415,7 @@ static void pr_complex (std::ostream& os, const Complex& c, int r_fw = 0, - int i_fw = 0, double scale = 1.0) + int i_fw = 0, double scale = 1.0) { Complex tmp = (Vfixed_point_format && ! print_g && scale != 1.0) ? c / scale : c; @@ -1428,20 +1428,20 @@ { double i = tmp.imag (); if (! (hex_format || bit_format) && lo_ieee_signbit (i)) - { - os << " - "; - i = -i; - pr_imag_float (os, i, i_fw); - } + { + os << " - "; + i = -i; + pr_imag_float (os, i, i_fw); + } else - { - if (hex_format || bit_format) - os << " "; - else - os << " + "; - - pr_imag_float (os, i, i_fw); - } + { + if (hex_format || bit_format) + os << " "; + else + os << " + "; + + pr_imag_float (os, i, i_fw); + } os << "i"; } } @@ -1454,22 +1454,22 @@ if (pr_as_read_syntax) { if (nr == 0 && nc == 0) - os << "[]"; + os << "[]"; else - os << "zeros (" << nr << ", " << nc << ")"; + os << "zeros (" << nr << ", " << nc << ")"; } else { os << "[]"; if (Vprint_empty_dimensions) - os << "(" << nr << "x" << nc << ")"; + os << "(" << nr << "x" << nc << ")"; } } static void print_empty_nd_array (std::ostream& os, const dim_vector& dims, - bool pr_as_read_syntax) + bool pr_as_read_syntax) { assert (dims.any_zero ()); @@ -1480,7 +1480,7 @@ os << "[]"; if (Vprint_empty_dimensions) - os << "(" << dims.str () << ")"; + os << "(" << dims.str () << ")"; } } @@ -1490,44 +1490,44 @@ if (Vfixed_point_format && ! print_g && scale != 1.0) { os << " " - << std::setw (8) << std::setprecision (1) - << std::setiosflags (std::ios::scientific|std::ios::left) - << scale - << std::resetiosflags (std::ios::scientific|std::ios::left) - << " *\n"; + << std::setw (8) << std::setprecision (1) + << std::setiosflags (std::ios::scientific|std::ios::left) + << scale + << std::resetiosflags (std::ios::scientific|std::ios::left) + << " *\n"; if (! compact_format) - os << "\n"; + os << "\n"; } } static void pr_col_num_header (std::ostream& os, octave_idx_type total_width, int max_width, - octave_idx_type lim, octave_idx_type col, int extra_indent) + octave_idx_type lim, octave_idx_type col, int extra_indent) { if (total_width > max_width && Vsplit_long_rows) { if (col != 0) - { - if (compact_format) - os << "\n"; - else - os << "\n\n"; - } + { + if (compact_format) + os << "\n"; + else + os << "\n\n"; + } octave_idx_type num_cols = lim - col; os << std::setw (extra_indent) << ""; if (num_cols == 1) - os << " Column " << col + 1 << ":\n"; + os << " Column " << col + 1 << ":\n"; else if (num_cols == 2) - os << " Columns " << col + 1 << " and " << lim << ":\n"; + os << " Columns " << col + 1 << " and " << lim << ":\n"; else - os << " Columns " << col + 1 << " through " << lim << ":\n"; + os << " Columns " << col + 1 << " through " << lim << ":\n"; if (! compact_format) - os << "\n"; + os << "\n"; } } @@ -1545,7 +1545,7 @@ void octave_print_internal (std::ostream& os, double d, - bool /* pr_as_read_syntax */) + bool /* pr_as_read_syntax */) { if (plus_format) { @@ -1555,15 +1555,15 @@ { set_format (d); if (free_format) - os << d; + os << d; else - pr_float (os, d); + pr_float (os, d); } } void octave_print_internal (std::ostream& os, const Matrix& m, - bool pr_as_read_syntax, int extra_indent) + bool pr_as_read_syntax, int extra_indent) { octave_idx_type nr = m.rows (); octave_idx_type nc = m.columns (); @@ -1573,17 +1573,17 @@ else if (plus_format && ! pr_as_read_syntax) { for (octave_idx_type i = 0; i < nr; i++) - { - for (octave_idx_type j = 0; j < nc; j++) - { - octave_quit (); - - pr_plus_format (os, m(i,j)); - } - - if (i < nr - 1) - os << "\n"; - } + { + for (octave_idx_type j = 0; j < nc; j++) + { + octave_quit (); + + pr_plus_format (os, m(i,j)); + } + + if (i < nr - 1) + os << "\n"; + } } else { @@ -1595,109 +1595,109 @@ octave_idx_type max_width = command_editor::terminal_cols (); if (pr_as_read_syntax) - max_width -= 4; + max_width -= 4; else - max_width -= extra_indent; + max_width -= extra_indent; if (max_width < 0) - max_width = 0; + max_width = 0; if (free_format) - { - if (pr_as_read_syntax) - os << "[\n"; - - os << m; - - if (pr_as_read_syntax) - os << "]"; - - return; - } + { + if (pr_as_read_syntax) + os << "[\n"; + + os << m; + + if (pr_as_read_syntax) + os << "]"; + + return; + } octave_idx_type inc = nc; if (total_width > max_width && Vsplit_long_rows) - { - inc = max_width / column_width; - if (inc == 0) - inc++; - } + { + inc = max_width / column_width; + if (inc == 0) + inc++; + } if (pr_as_read_syntax) - { - for (octave_idx_type i = 0; i < nr; i++) - { - octave_idx_type col = 0; - while (col < nc) - { - octave_idx_type lim = col + inc < nc ? col + inc : nc; - - for (octave_idx_type j = col; j < lim; j++) - { - octave_quit (); - - if (i == 0 && j == 0) - os << "[ "; - else - { - if (j > col && j < lim) - os << ", "; - else - os << " "; - } - - pr_float (os, m(i,j)); - } - - col += inc; - - if (col >= nc) - { - if (i == nr - 1) - os << " ]"; - else - os << ";\n"; - } - else - os << " ...\n"; - } - } - } + { + for (octave_idx_type i = 0; i < nr; i++) + { + octave_idx_type col = 0; + while (col < nc) + { + octave_idx_type lim = col + inc < nc ? col + inc : nc; + + for (octave_idx_type j = col; j < lim; j++) + { + octave_quit (); + + if (i == 0 && j == 0) + os << "[ "; + else + { + if (j > col && j < lim) + os << ", "; + else + os << " "; + } + + pr_float (os, m(i,j)); + } + + col += inc; + + if (col >= nc) + { + if (i == nr - 1) + os << " ]"; + else + os << ";\n"; + } + else + os << " ...\n"; + } + } + } else - { - pr_scale_header (os, scale); - - for (octave_idx_type col = 0; col < nc; col += inc) - { - octave_idx_type lim = col + inc < nc ? col + inc : nc; - - pr_col_num_header (os, total_width, max_width, lim, col, - extra_indent); - - for (octave_idx_type i = 0; i < nr; i++) - { - os << std::setw (extra_indent) << ""; - - for (octave_idx_type j = col; j < lim; j++) - { - octave_quit (); - - os << " "; - - pr_float (os, m(i,j), fw, scale); - } - - if (i < nr - 1) - os << "\n"; - } - } - } + { + pr_scale_header (os, scale); + + for (octave_idx_type col = 0; col < nc; col += inc) + { + octave_idx_type lim = col + inc < nc ? col + inc : nc; + + pr_col_num_header (os, total_width, max_width, lim, col, + extra_indent); + + for (octave_idx_type i = 0; i < nr; i++) + { + os << std::setw (extra_indent) << ""; + + for (octave_idx_type j = col; j < lim; j++) + { + octave_quit (); + + os << " "; + + pr_float (os, m(i,j), fw, scale); + } + + if (i < nr - 1) + os << "\n"; + } + } + } } } void octave_print_internal (std::ostream& os, const DiagMatrix& m, - bool pr_as_read_syntax, int extra_indent) + bool pr_as_read_syntax, int extra_indent) { octave_idx_type nr = m.rows (); octave_idx_type nc = m.columns (); @@ -1707,17 +1707,17 @@ else if (plus_format && ! pr_as_read_syntax) { for (octave_idx_type i = 0; i < nr; i++) - { - for (octave_idx_type j = 0; j < nc; j++) - { - octave_quit (); - - pr_plus_format (os, m(i,j)); - } - - if (i < nr - 1) - os << "\n"; - } + { + for (octave_idx_type j = 0; j < nc; j++) + { + octave_quit (); + + pr_plus_format (os, m(i,j)); + } + + if (i < nr - 1) + os << "\n"; + } } else { @@ -1729,36 +1729,36 @@ octave_idx_type max_width = command_editor::terminal_cols (); if (pr_as_read_syntax) - max_width -= 4; + max_width -= 4; else - max_width -= extra_indent; + max_width -= extra_indent; if (max_width < 0) - max_width = 0; + max_width = 0; if (free_format) - { - if (pr_as_read_syntax) - os << "[\n"; - - os << Matrix (m); - - if (pr_as_read_syntax) - os << "]"; - - return; - } + { + if (pr_as_read_syntax) + os << "[\n"; + + os << Matrix (m); + + if (pr_as_read_syntax) + os << "]"; + + return; + } octave_idx_type inc = nc; if (total_width > max_width && Vsplit_long_rows) - { - inc = max_width / column_width; - if (inc == 0) - inc++; - } + { + inc = max_width / column_width; + if (inc == 0) + inc++; + } if (pr_as_read_syntax) - { + { os << "diag ("; octave_idx_type col = 0; @@ -1791,11 +1791,11 @@ os << " ...\n"; } os << ")"; - } + } else - { + { os << "Diagonal Matrix\n\n"; - pr_scale_header (os, scale); + pr_scale_header (os, scale); // kluge. Get the true width of a number. int zero_fw; @@ -1806,35 +1806,35 @@ zero_fw = tmp_oss.str ().length (); } - for (octave_idx_type col = 0; col < nc; col += inc) - { - octave_idx_type lim = col + inc < nc ? col + inc : nc; - - pr_col_num_header (os, total_width, max_width, lim, col, - extra_indent); - - for (octave_idx_type i = 0; i < nr; i++) - { - os << std::setw (extra_indent) << ""; - - for (octave_idx_type j = col; j < lim; j++) - { - octave_quit (); - - os << " "; + for (octave_idx_type col = 0; col < nc; col += inc) + { + octave_idx_type lim = col + inc < nc ? col + inc : nc; + + pr_col_num_header (os, total_width, max_width, lim, col, + extra_indent); + + for (octave_idx_type i = 0; i < nr; i++) + { + os << std::setw (extra_indent) << ""; + + for (octave_idx_type j = col; j < lim; j++) + { + octave_quit (); + + os << " "; if (i == j) pr_float (os, m(i,j), fw, scale); else os << std::setw (zero_fw) << '0'; - } - - if (i < nr - 1) - os << "\n"; - } - } - } + } + + if (i < nr - 1) + os << "\n"; + } + } + } } } #define PRINT_ND_ARRAY(os, nda, NDA_T, ELT_T, MAT_T) \ @@ -1861,7 +1861,7 @@ \ for (octave_idx_type i = 0; i < m; i++) \ { \ - octave_quit (); \ + octave_quit (); \ \ std::string nm = "ans"; \ \ @@ -1869,7 +1869,7 @@ { \ nm += "(:,:,"; \ \ - std::ostringstream buf; \ + std::ostringstream buf; \ \ for (int k = 2; k < ndims; k++) \ { \ @@ -1906,14 +1906,14 @@ void octave_print_internal (std::ostream& os, const NDArray& nda, - bool pr_as_read_syntax, int extra_indent) + bool pr_as_read_syntax, int extra_indent) { switch (nda.ndims ()) { case 1: case 2: octave_print_internal (os, nda.matrix_value (), - pr_as_read_syntax, extra_indent); + pr_as_read_syntax, extra_indent); break; default: @@ -1932,9 +1932,9 @@ if (rp == 0.0) { if (ip == 0.0) - os << " "; + os << " "; else - os << "i"; + os << "i"; } else if (ip == 0.0) pr_plus_format (os, rp); @@ -1944,7 +1944,7 @@ void octave_print_internal (std::ostream& os, const Complex& c, - bool /* pr_as_read_syntax */) + bool /* pr_as_read_syntax */) { if (plus_format) { @@ -1954,15 +1954,15 @@ { set_format (c); if (free_format) - os << c; + os << c; else - pr_complex (os, c); + pr_complex (os, c); } } void octave_print_internal (std::ostream& os, const ComplexMatrix& cm, - bool pr_as_read_syntax, int extra_indent) + bool pr_as_read_syntax, int extra_indent) { octave_idx_type nr = cm.rows (); octave_idx_type nc = cm.columns (); @@ -1972,17 +1972,17 @@ else if (plus_format && ! pr_as_read_syntax) { for (octave_idx_type i = 0; i < nr; i++) - { - for (octave_idx_type j = 0; j < nc; j++) - { - octave_quit (); - - pr_plus_format (os, cm(i,j)); - } - - if (i < nr - 1) - os << "\n"; - } + { + for (octave_idx_type j = 0; j < nc; j++) + { + octave_quit (); + + pr_plus_format (os, cm(i,j)); + } + + if (i < nr - 1) + os << "\n"; + } } else { @@ -1991,114 +1991,114 @@ set_format (cm, r_fw, i_fw, scale); int column_width = i_fw + r_fw; column_width += (rat_format || bank_format || hex_format - || bit_format) ? 2 : 7; + || bit_format) ? 2 : 7; octave_idx_type total_width = nc * column_width; octave_idx_type max_width = command_editor::terminal_cols (); if (pr_as_read_syntax) - max_width -= 4; + max_width -= 4; else - max_width -= extra_indent; + max_width -= extra_indent; if (max_width < 0) - max_width = 0; + max_width = 0; if (free_format) - { - if (pr_as_read_syntax) - os << "[\n"; - - os << cm; - - if (pr_as_read_syntax) - os << "]"; - - return; - } + { + if (pr_as_read_syntax) + os << "[\n"; + + os << cm; + + if (pr_as_read_syntax) + os << "]"; + + return; + } octave_idx_type inc = nc; if (total_width > max_width && Vsplit_long_rows) - { - inc = max_width / column_width; - if (inc == 0) - inc++; - } + { + inc = max_width / column_width; + if (inc == 0) + inc++; + } if (pr_as_read_syntax) - { - for (octave_idx_type i = 0; i < nr; i++) - { - octave_idx_type col = 0; - while (col < nc) - { - octave_idx_type lim = col + inc < nc ? col + inc : nc; - - for (octave_idx_type j = col; j < lim; j++) - { - octave_quit (); - - if (i == 0 && j == 0) - os << "[ "; - else - { - if (j > col && j < lim) - os << ", "; - else - os << " "; - } - - pr_complex (os, cm(i,j)); - } - - col += inc; - - if (col >= nc) - { - if (i == nr - 1) - os << " ]"; - else - os << ";\n"; - } - else - os << " ...\n"; - } - } - } + { + for (octave_idx_type i = 0; i < nr; i++) + { + octave_idx_type col = 0; + while (col < nc) + { + octave_idx_type lim = col + inc < nc ? col + inc : nc; + + for (octave_idx_type j = col; j < lim; j++) + { + octave_quit (); + + if (i == 0 && j == 0) + os << "[ "; + else + { + if (j > col && j < lim) + os << ", "; + else + os << " "; + } + + pr_complex (os, cm(i,j)); + } + + col += inc; + + if (col >= nc) + { + if (i == nr - 1) + os << " ]"; + else + os << ";\n"; + } + else + os << " ...\n"; + } + } + } else - { - pr_scale_header (os, scale); - - for (octave_idx_type col = 0; col < nc; col += inc) - { - octave_idx_type lim = col + inc < nc ? col + inc : nc; - - pr_col_num_header (os, total_width, max_width, lim, col, - extra_indent); - - for (octave_idx_type i = 0; i < nr; i++) - { - os << std::setw (extra_indent) << ""; - - for (octave_idx_type j = col; j < lim; j++) - { - octave_quit (); - - os << " "; - - pr_complex (os, cm(i,j), r_fw, i_fw, scale); - } - - if (i < nr - 1) - os << "\n"; - } - } - } + { + pr_scale_header (os, scale); + + for (octave_idx_type col = 0; col < nc; col += inc) + { + octave_idx_type lim = col + inc < nc ? col + inc : nc; + + pr_col_num_header (os, total_width, max_width, lim, col, + extra_indent); + + for (octave_idx_type i = 0; i < nr; i++) + { + os << std::setw (extra_indent) << ""; + + for (octave_idx_type j = col; j < lim; j++) + { + octave_quit (); + + os << " "; + + pr_complex (os, cm(i,j), r_fw, i_fw, scale); + } + + if (i < nr - 1) + os << "\n"; + } + } + } } } void octave_print_internal (std::ostream& os, const ComplexDiagMatrix& cm, - bool pr_as_read_syntax, int extra_indent) + bool pr_as_read_syntax, int extra_indent) { octave_idx_type nr = cm.rows (); octave_idx_type nc = cm.columns (); @@ -2108,17 +2108,17 @@ else if (plus_format && ! pr_as_read_syntax) { for (octave_idx_type i = 0; i < nr; i++) - { - for (octave_idx_type j = 0; j < nc; j++) - { - octave_quit (); - - pr_plus_format (os, cm(i,j)); - } - - if (i < nr - 1) - os << "\n"; - } + { + for (octave_idx_type j = 0; j < nc; j++) + { + octave_quit (); + + pr_plus_format (os, cm(i,j)); + } + + if (i < nr - 1) + os << "\n"; + } } else { @@ -2127,41 +2127,41 @@ set_format (ComplexMatrix (cm.diag ()), r_fw, i_fw, scale); int column_width = i_fw + r_fw; column_width += (rat_format || bank_format || hex_format - || bit_format) ? 2 : 7; + || bit_format) ? 2 : 7; octave_idx_type total_width = nc * column_width; octave_idx_type max_width = command_editor::terminal_cols (); if (pr_as_read_syntax) - max_width -= 4; + max_width -= 4; else - max_width -= extra_indent; + max_width -= extra_indent; if (max_width < 0) - max_width = 0; + max_width = 0; if (free_format) - { - if (pr_as_read_syntax) - os << "[\n"; - - os << ComplexMatrix (cm); - - if (pr_as_read_syntax) - os << "]"; - - return; - } + { + if (pr_as_read_syntax) + os << "[\n"; + + os << ComplexMatrix (cm); + + if (pr_as_read_syntax) + os << "]"; + + return; + } octave_idx_type inc = nc; if (total_width > max_width && Vsplit_long_rows) - { - inc = max_width / column_width; - if (inc == 0) - inc++; - } + { + inc = max_width / column_width; + if (inc == 0) + inc++; + } if (pr_as_read_syntax) - { + { os << "diag ("; octave_idx_type col = 0; @@ -2194,11 +2194,11 @@ os << " ...\n"; } os << ")"; - } + } else - { + { os << "Diagonal Matrix\n\n"; - pr_scale_header (os, scale); + pr_scale_header (os, scale); // kluge. Get the true width of a number. int zero_fw; @@ -2209,40 +2209,40 @@ zero_fw = tmp_oss.str ().length (); } - for (octave_idx_type col = 0; col < nc; col += inc) - { - octave_idx_type lim = col + inc < nc ? col + inc : nc; - - pr_col_num_header (os, total_width, max_width, lim, col, - extra_indent); - - for (octave_idx_type i = 0; i < nr; i++) - { - os << std::setw (extra_indent) << ""; - - for (octave_idx_type j = col; j < lim; j++) - { - octave_quit (); - - os << " "; + for (octave_idx_type col = 0; col < nc; col += inc) + { + octave_idx_type lim = col + inc < nc ? col + inc : nc; + + pr_col_num_header (os, total_width, max_width, lim, col, + extra_indent); + + for (octave_idx_type i = 0; i < nr; i++) + { + os << std::setw (extra_indent) << ""; + + for (octave_idx_type j = col; j < lim; j++) + { + octave_quit (); + + os << " "; if (i == j) pr_complex (os, cm(i,j), r_fw, i_fw, scale); else os << std::setw (zero_fw) << '0'; - } - - if (i < nr - 1) - os << "\n"; - } - } - } + } + + if (i < nr - 1) + os << "\n"; + } + } + } } } void octave_print_internal (std::ostream& os, const PermMatrix& m, - bool pr_as_read_syntax, int extra_indent) + bool pr_as_read_syntax, int extra_indent) { octave_idx_type nr = m.rows (); octave_idx_type nc = m.columns (); @@ -2252,17 +2252,17 @@ else if (plus_format && ! pr_as_read_syntax) { for (octave_idx_type i = 0; i < nr; i++) - { - for (octave_idx_type j = 0; j < nc; j++) - { - octave_quit (); - - pr_plus_format (os, m(i,j)); - } - - if (i < nr - 1) - os << "\n"; - } + { + for (octave_idx_type j = 0; j < nc; j++) + { + octave_quit (); + + pr_plus_format (os, m(i,j)); + } + + if (i < nr - 1) + os << "\n"; + } } else { @@ -2272,33 +2272,33 @@ octave_idx_type max_width = command_editor::terminal_cols (); if (pr_as_read_syntax) - max_width -= 4; + max_width -= 4; else - max_width -= extra_indent; + max_width -= extra_indent; if (max_width < 0) - max_width = 0; + max_width = 0; if (free_format) - { - if (pr_as_read_syntax) - os << "[\n"; - - os << Matrix (m); - - if (pr_as_read_syntax) - os << "]"; - - return; - } + { + if (pr_as_read_syntax) + os << "[\n"; + + os << Matrix (m); + + if (pr_as_read_syntax) + os << "]"; + + return; + } octave_idx_type inc = nc; if (total_width > max_width && Vsplit_long_rows) - { - inc = max_width / column_width; - if (inc == 0) - inc++; - } + { + inc = max_width / column_width; + if (inc == 0) + inc++; + } if (pr_as_read_syntax) { @@ -2339,49 +2339,49 @@ } if (! colp) os << ", :"; os << ")"; - } + } else - { + { os << "Permutation Matrix\n\n"; - for (octave_idx_type col = 0; col < nc; col += inc) - { - octave_idx_type lim = col + inc < nc ? col + inc : nc; - - pr_col_num_header (os, total_width, max_width, lim, col, - extra_indent); - - for (octave_idx_type i = 0; i < nr; i++) - { - os << std::setw (extra_indent) << ""; - - for (octave_idx_type j = col; j < lim; j++) - { - octave_quit (); - - os << " "; + for (octave_idx_type col = 0; col < nc; col += inc) + { + octave_idx_type lim = col + inc < nc ? col + inc : nc; + + pr_col_num_header (os, total_width, max_width, lim, col, + extra_indent); + + for (octave_idx_type i = 0; i < nr; i++) + { + os << std::setw (extra_indent) << ""; + + for (octave_idx_type j = col; j < lim; j++) + { + octave_quit (); + + os << " "; os << std::setw (fw) << m(i,j); - } - - if (i < nr - 1) - os << "\n"; - } - } - } + } + + if (i < nr - 1) + os << "\n"; + } + } + } } } void octave_print_internal (std::ostream& os, const ComplexNDArray& nda, - bool pr_as_read_syntax, int extra_indent) + bool pr_as_read_syntax, int extra_indent) { switch (nda.ndims ()) { case 1: case 2: octave_print_internal (os, nda.matrix_value (), - pr_as_read_syntax, extra_indent); + pr_as_read_syntax, extra_indent); break; default: @@ -2406,56 +2406,56 @@ void octave_print_internal (std::ostream& os, const FloatMatrix& m, - bool pr_as_read_syntax, int extra_indent) + bool pr_as_read_syntax, int extra_indent) { octave_print_internal (os, Matrix (m), pr_as_read_syntax, extra_indent); } void octave_print_internal (std::ostream& os, const FloatDiagMatrix& m, - bool pr_as_read_syntax, int extra_indent) + bool pr_as_read_syntax, int extra_indent) { octave_print_internal (os, DiagMatrix (m), pr_as_read_syntax, extra_indent); } void octave_print_internal (std::ostream& os, const FloatNDArray& nda, - bool pr_as_read_syntax, int extra_indent) + bool pr_as_read_syntax, int extra_indent) { octave_print_internal (os, NDArray (nda), pr_as_read_syntax, extra_indent); } void octave_print_internal (std::ostream& os, const FloatComplex& c, - bool pr_as_read_syntax) + bool pr_as_read_syntax) { octave_print_internal (os, Complex (c), pr_as_read_syntax); } void octave_print_internal (std::ostream& os, const FloatComplexMatrix& cm, - bool pr_as_read_syntax, int extra_indent) + bool pr_as_read_syntax, int extra_indent) { octave_print_internal (os, ComplexMatrix (cm), pr_as_read_syntax, extra_indent); } void octave_print_internal (std::ostream& os, const FloatComplexDiagMatrix& cm, - bool pr_as_read_syntax, int extra_indent) + bool pr_as_read_syntax, int extra_indent) { octave_print_internal (os, ComplexDiagMatrix (cm), pr_as_read_syntax, extra_indent); } void octave_print_internal (std::ostream& os, const FloatComplexNDArray& nda, - bool pr_as_read_syntax, int extra_indent) + bool pr_as_read_syntax, int extra_indent) { octave_print_internal (os, ComplexNDArray (nda), pr_as_read_syntax, extra_indent); } void octave_print_internal (std::ostream& os, const Range& r, - bool pr_as_read_syntax, int extra_indent) + bool pr_as_read_syntax, int extra_indent) { double base = r.base (); double increment = r.inc (); @@ -2465,13 +2465,13 @@ if (plus_format && ! pr_as_read_syntax) { for (octave_idx_type i = 0; i < num_elem; i++) - { - octave_quit (); - - double val = base + i * increment; - - pr_plus_format (os, val); - } + { + octave_quit (); + + double val = base + i * increment; + + pr_plus_format (os, val); + } } else { @@ -2480,93 +2480,93 @@ set_format (r, fw, scale); if (pr_as_read_syntax) - { - if (free_format) - { - os << base << " : "; - if (increment != 1.0) - os << increment << " : "; - os << limit; - } - else - { - pr_float (os, base, fw); - os << " : "; - if (increment != 1.0) - { - pr_float (os, increment, fw); - os << " : "; - } - pr_float (os, limit, fw); - } - } + { + if (free_format) + { + os << base << " : "; + if (increment != 1.0) + os << increment << " : "; + os << limit; + } + else + { + pr_float (os, base, fw); + os << " : "; + if (increment != 1.0) + { + pr_float (os, increment, fw); + os << " : "; + } + pr_float (os, limit, fw); + } + } else - { - int column_width = fw + 2; - octave_idx_type total_width = num_elem * column_width; - octave_idx_type max_width = command_editor::terminal_cols (); - - if (free_format) - { - os << r; - return; - } - - octave_idx_type inc = num_elem; - if (total_width > max_width && Vsplit_long_rows) - { - inc = max_width / column_width; - if (inc == 0) - inc++; - } - - max_width -= extra_indent; - - if (max_width < 0) - max_width = 0; - - pr_scale_header (os, scale); - - octave_idx_type col = 0; - while (col < num_elem) - { - octave_idx_type lim = col + inc < num_elem ? col + inc : num_elem; - - pr_col_num_header (os, total_width, max_width, lim, col, - extra_indent); - - os << std::setw (extra_indent) << ""; - - for (octave_idx_type i = col; i < lim; i++) - { - octave_quit (); - - double val = base + i * increment; - - if (i == num_elem - 1) - { - // See the comments in Range::matrix_value. - - if ((increment > 0 && val > limit) - || (increment < 0 && val < limit)) - val = limit; - } - - os << " "; - - pr_float (os, val, fw, scale); - } - - col += inc; - } - } + { + int column_width = fw + 2; + octave_idx_type total_width = num_elem * column_width; + octave_idx_type max_width = command_editor::terminal_cols (); + + if (free_format) + { + os << r; + return; + } + + octave_idx_type inc = num_elem; + if (total_width > max_width && Vsplit_long_rows) + { + inc = max_width / column_width; + if (inc == 0) + inc++; + } + + max_width -= extra_indent; + + if (max_width < 0) + max_width = 0; + + pr_scale_header (os, scale); + + octave_idx_type col = 0; + while (col < num_elem) + { + octave_idx_type lim = col + inc < num_elem ? col + inc : num_elem; + + pr_col_num_header (os, total_width, max_width, lim, col, + extra_indent); + + os << std::setw (extra_indent) << ""; + + for (octave_idx_type i = col; i < lim; i++) + { + octave_quit (); + + double val = base + i * increment; + + if (i == num_elem - 1) + { + // See the comments in Range::matrix_value. + + if ((increment > 0 && val > limit) + || (increment < 0 && val < limit)) + val = limit; + } + + os << " "; + + pr_float (os, val, fw, scale); + } + + col += inc; + } + } } } void octave_print_internal (std::ostream& os, const boolMatrix& bm, - bool pr_as_read_syntax, - int extra_indent) + bool pr_as_read_syntax, + int extra_indent) { Matrix tmp (bm); octave_print_internal (os, tmp, pr_as_read_syntax, extra_indent); @@ -2574,15 +2574,15 @@ void octave_print_internal (std::ostream& os, const boolNDArray& nda, - bool pr_as_read_syntax, - int extra_indent) + bool pr_as_read_syntax, + int extra_indent) { switch (nda.ndims ()) { case 1: case 2: octave_print_internal (os, nda.matrix_value (), - pr_as_read_syntax, extra_indent); + pr_as_read_syntax, extra_indent); break; default: @@ -2593,44 +2593,44 @@ void octave_print_internal (std::ostream& os, const charMatrix& chm, - bool pr_as_read_syntax, - int /* extra_indent FIXME */, - bool pr_as_string) + bool pr_as_read_syntax, + int /* extra_indent FIXME */, + bool pr_as_string) { if (pr_as_string) { octave_idx_type nstr = chm.rows (); if (pr_as_read_syntax && nstr > 1) - os << "[ "; + os << "[ "; if (nstr != 0) - { - for (octave_idx_type i = 0; i < nstr; i++) - { - octave_quit (); - - std::string row = chm.row_as_string (i); - - if (pr_as_read_syntax) - { - os << "\"" << undo_string_escapes (row) << "\""; - - if (i < nstr - 1) - os << "; "; - } - else - { - os << row; - - if (i < nstr - 1) - os << "\n"; - } - } - } + { + for (octave_idx_type i = 0; i < nstr; i++) + { + octave_quit (); + + std::string row = chm.row_as_string (i); + + if (pr_as_read_syntax) + { + os << "\"" << undo_string_escapes (row) << "\""; + + if (i < nstr - 1) + os << "; "; + } + else + { + os << row; + + if (i < nstr - 1) + os << "\n"; + } + } + } if (pr_as_read_syntax && nstr > 1) - os << " ]"; + os << " ]"; } else { @@ -2640,15 +2640,15 @@ void octave_print_internal (std::ostream& os, const charNDArray& nda, - bool pr_as_read_syntax, int extra_indent, - bool pr_as_string) + bool pr_as_read_syntax, int extra_indent, + bool pr_as_string) { switch (nda.ndims ()) { case 1: case 2: octave_print_internal (os, nda.matrix_value (), - pr_as_read_syntax, extra_indent, pr_as_string); + pr_as_read_syntax, extra_indent, pr_as_string); break; default: @@ -2659,7 +2659,7 @@ void octave_print_internal (std::ostream& os, const std::string& s, - bool pr_as_read_syntax, int extra_indent) + bool pr_as_read_syntax, int extra_indent) { Array nda (dim_vector (1, 1), s); @@ -2668,7 +2668,7 @@ void octave_print_internal (std::ostream& os, const Array& nda, - bool pr_as_read_syntax, int /* extra_indent */) + bool pr_as_read_syntax, int /* extra_indent */) { // FIXME -- this mostly duplicates the code in the // PRINT_ND_ARRAY macro. @@ -2690,66 +2690,66 @@ octave_idx_type m = 1; for (int i = 2; i < ndims; i++) - m *= dims(i); + m *= dims(i); octave_idx_type nr = dims(0); octave_idx_type nc = dims(1); for (octave_idx_type i = 0; i < m; i++) - { - std::string nm = "ans"; - - if (m > 1) - { - nm += "(:,:,"; - - std::ostringstream buf; - - for (int k = 2; k < ndims; k++) - { - buf << ra_idx(k) + 1; - - if (k < ndims - 1) - buf << ","; - else - buf << ")"; - } - - nm += buf.str (); - } - - Array idx (ndims); - - idx(0) = idx_vector (':'); - idx(1) = idx_vector (':'); - - for (int k = 2; k < ndims; k++) - idx(k) = idx_vector (ra_idx(k)); - - Array2 page (nda.index (idx), nr, nc); - - // FIXME -- need to do some more work to put these - // in neatly aligned columns... - - octave_idx_type n_rows = page.rows (); - octave_idx_type n_cols = page.cols (); - - os << nm << " =\n\n"; - - for (octave_idx_type ii = 0; ii < n_rows; ii++) - { - for (octave_idx_type jj = 0; jj < n_cols; jj++) - os << " " << page(ii,jj); - - os << "\n"; - } - - if (i < m - 1) - os << "\n"; - - if (i < m) - increment_index (ra_idx, dims, 2); - } + { + std::string nm = "ans"; + + if (m > 1) + { + nm += "(:,:,"; + + std::ostringstream buf; + + for (int k = 2; k < ndims; k++) + { + buf << ra_idx(k) + 1; + + if (k < ndims - 1) + buf << ","; + else + buf << ")"; + } + + nm += buf.str (); + } + + Array idx (ndims); + + idx(0) = idx_vector (':'); + idx(1) = idx_vector (':'); + + for (int k = 2; k < ndims; k++) + idx(k) = idx_vector (ra_idx(k)); + + Array2 page (nda.index (idx), nr, nc); + + // FIXME -- need to do some more work to put these + // in neatly aligned columns... + + octave_idx_type n_rows = page.rows (); + octave_idx_type n_cols = page.cols (); + + os << nm << " =\n\n"; + + for (octave_idx_type ii = 0; ii < n_rows; ii++) + { + for (octave_idx_type jj = 0; jj < n_cols; jj++) + os << " " << page(ii,jj); + + os << "\n"; + } + + if (i < m - 1) + os << "\n"; + + if (i < m) + increment_index (ra_idx, dims, 2); + } } } @@ -2793,50 +2793,50 @@ char ofill = os.fill ('0'); std::ios::fmtflags oflags - = os.flags (std::ios::right | std::ios::hex); + = os.flags (std::ios::right | std::ios::hex); if (hex_format > 1 || oct_mach_info::words_big_endian ()) - { - for (size_t i = 0; i < sz; i++) - os << std::setw (2) << static_cast (tmpi[i]); - } + { + for (size_t i = 0; i < sz; i++) + os << std::setw (2) << static_cast (tmpi[i]); + } else - { - for (int i = sz - 1; i >= 0; i--) - os << std::setw (2) << static_cast (tmpi[i]); - } + { + for (int i = sz - 1; i >= 0; i--) + os << std::setw (2) << static_cast (tmpi[i]); + } os.fill (ofill); - os.setf (oflags); + os.setf (oflags); } else if (bit_format) { if (oct_mach_info::words_big_endian ()) - { - for (size_t i = 0; i < sz; i++) - PRINT_CHAR_BITS (os, tmpi[i]); - } + { + for (size_t i = 0; i < sz; i++) + PRINT_CHAR_BITS (os, tmpi[i]); + } else - { - if (bit_format > 1) - { - for (size_t i = 0; i < sz; i++) - PRINT_CHAR_BITS_SWAPPED (os, tmpi[i]); - } - else - { - for (int i = sz - 1; i >= 0; i--) - PRINT_CHAR_BITS (os, tmpi[i]); - } - } + { + if (bit_format > 1) + { + for (size_t i = 0; i < sz; i++) + PRINT_CHAR_BITS_SWAPPED (os, tmpi[i]); + } + else + { + for (int i = sz - 1; i >= 0; i--) + PRINT_CHAR_BITS (os, tmpi[i]); + } + } } else { os << std::setw (fw) - << typename octave_print_conv::print_conv_type (d); + << typename octave_print_conv::print_conv_type (d); if (bank_format) - os << ".00"; + os << ".00"; } } @@ -2903,7 +2903,7 @@ template void octave_print_internal_template (std::ostream& os, const octave_int& val, - bool) + bool) { if (plus_format) { @@ -2912,9 +2912,9 @@ else { if (free_format) - os << typename octave_print_conv >::print_conv_type (val); + os << typename octave_print_conv >::print_conv_type (val); else - pr_int (os, val); + pr_int (os, val); } } @@ -2937,7 +2937,7 @@ template /* static */ inline void octave_print_internal_template (std::ostream& os, const intNDArray& nda, - bool pr_as_read_syntax, int extra_indent) + bool pr_as_read_syntax, int extra_indent) { // FIXME -- this mostly duplicates the code in the // PRINT_ND_ARRAY macro. @@ -2957,63 +2957,63 @@ octave_idx_type m = 1; for (int i = 2; i < ndims; i++) - m *= dims(i); + m *= dims(i); octave_idx_type nr = dims(0); octave_idx_type nc = dims(1); for (octave_idx_type i = 0; i < m; i++) - { - if (m > 1) - { - std::string nm = "ans(:,:,"; - - std::ostringstream buf; - - for (int k = 2; k < ndims; k++) - { - buf << ra_idx(k) + 1; - - if (k < ndims - 1) - buf << ","; - else - buf << ")"; - } - - nm += buf.str (); - - os << nm << " =\n\n"; - } - - Array idx (ndims); - - idx(0) = idx_vector (':'); - idx(1) = idx_vector (':'); - - for (int k = 2; k < ndims; k++) - idx(k) = idx_vector (ra_idx(k)); - - Array2 page (nda.index (idx), nr, nc); - - for (octave_idx_type ii = 0; ii < nr; ii++) - { - for (octave_idx_type jj = 0; jj < nc; jj++) - { - octave_quit (); - - pr_plus_format (os, page(ii,jj)); - } - - if ((ii < nr - 1) || (i < m -1)) - os << "\n"; - } - - if (i < m - 1) - { - os << "\n"; - increment_index (ra_idx, dims, 2); - } - } + { + if (m > 1) + { + std::string nm = "ans(:,:,"; + + std::ostringstream buf; + + for (int k = 2; k < ndims; k++) + { + buf << ra_idx(k) + 1; + + if (k < ndims - 1) + buf << ","; + else + buf << ")"; + } + + nm += buf.str (); + + os << nm << " =\n\n"; + } + + Array idx (ndims); + + idx(0) = idx_vector (':'); + idx(1) = idx_vector (':'); + + for (int k = 2; k < ndims; k++) + idx(k) = idx_vector (ra_idx(k)); + + Array2 page (nda.index (idx), nr, nc); + + for (octave_idx_type ii = 0; ii < nr; ii++) + { + for (octave_idx_type jj = 0; jj < nc; jj++) + { + octave_quit (); + + pr_plus_format (os, page(ii,jj)); + } + + if ((ii < nr - 1) || (i < m -1)) + os << "\n"; + } + + if (i < m - 1) + { + os << "\n"; + increment_index (ra_idx, dims, 2); + } + } } else { @@ -3026,140 +3026,140 @@ octave_idx_type m = 1; for (int i = 2; i < ndims; i++) - m *= dims(i); + m *= dims(i); octave_idx_type nr = dims(0); octave_idx_type nc = dims(1); int fw = 0; if (hex_format) - fw = 2 * nda(0).byte_size (); + fw = 2 * nda(0).byte_size (); else if (bit_format) - fw = nda(0).nbits (); + fw = nda(0).nbits (); else - { - bool isneg = false; - int digits = 0; - - for (octave_idx_type 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; - - if (! isneg) - isneg = (abs (nda(i).value ()) != nda(i).value ()); - } - - fw = digits + isneg; - } + { + bool isneg = false; + int digits = 0; + + for (octave_idx_type 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; + + if (! isneg) + isneg = (abs (nda(i).value ()) != nda(i).value ()); + } + + fw = digits + isneg; + } int column_width = fw + (rat_format ? 0 : (bank_format ? 5 : 2)); octave_idx_type total_width = nc * column_width; int max_width = command_editor::terminal_cols () - extra_indent; octave_idx_type inc = nc; if (total_width > max_width && Vsplit_long_rows) - { - inc = max_width / column_width; - if (inc == 0) - inc++; - } + { + inc = max_width / column_width; + if (inc == 0) + inc++; + } for (octave_idx_type i = 0; i < m; i++) - { - if (m > 1) - { - std::string nm = "ans(:,:,"; - - std::ostringstream buf; - - for (int k = 2; k < ndims; k++) - { - buf << ra_idx(k) + 1; - - if (k < ndims - 1) - buf << ","; - else - buf << ")"; - } - - nm += buf.str (); - - os << nm << " =\n\n"; - } - - Array idx (ndims); - - idx(0) = idx_vector (':'); - idx(1) = idx_vector (':'); - - for (int k = 2; k < ndims; k++) - idx(k) = idx_vector (ra_idx(k)); - - Array2 page (nda.index (idx), nr, nc); - - if (free_format) - { - if (pr_as_read_syntax) - os << "[\n"; - - for (octave_idx_type ii = 0; ii < nr; ii++) - { - for (octave_idx_type jj = 0; jj < nc; jj++) - { - octave_quit (); - os << " "; - os << typename octave_print_conv::print_conv_type (page(ii,jj)); - } - os << "\n"; - } - - if (pr_as_read_syntax) - os << "]"; - } - else - { - octave_idx_type n_rows = page.rows (); - octave_idx_type n_cols = page.cols (); - - for (octave_idx_type col = 0; col < n_cols; col += inc) - { - octave_idx_type lim = col + inc < n_cols ? col + inc : n_cols; - - pr_col_num_header (os, total_width, max_width, lim, col, - extra_indent); - - for (octave_idx_type ii = 0; ii < n_rows; ii++) - { - os << std::setw (extra_indent) << ""; - - for (octave_idx_type jj = col; jj < lim; jj++) - { - octave_quit (); - os << " "; - pr_int (os, page(ii,jj), fw); - } - if ((ii < n_rows - 1) || (i < m -1)) - os << "\n"; - } - } - } - - if (i < m - 1) - { - os << "\n"; - increment_index (ra_idx, dims, 2); - } - } + { + if (m > 1) + { + std::string nm = "ans(:,:,"; + + std::ostringstream buf; + + for (int k = 2; k < ndims; k++) + { + buf << ra_idx(k) + 1; + + if (k < ndims - 1) + buf << ","; + else + buf << ")"; + } + + nm += buf.str (); + + os << nm << " =\n\n"; + } + + Array idx (ndims); + + idx(0) = idx_vector (':'); + idx(1) = idx_vector (':'); + + for (int k = 2; k < ndims; k++) + idx(k) = idx_vector (ra_idx(k)); + + Array2 page (nda.index (idx), nr, nc); + + if (free_format) + { + if (pr_as_read_syntax) + os << "[\n"; + + for (octave_idx_type ii = 0; ii < nr; ii++) + { + for (octave_idx_type jj = 0; jj < nc; jj++) + { + octave_quit (); + os << " "; + os << typename octave_print_conv::print_conv_type (page(ii,jj)); + } + os << "\n"; + } + + if (pr_as_read_syntax) + os << "]"; + } + else + { + octave_idx_type n_rows = page.rows (); + octave_idx_type n_cols = page.cols (); + + for (octave_idx_type col = 0; col < n_cols; col += inc) + { + octave_idx_type lim = col + inc < n_cols ? col + inc : n_cols; + + pr_col_num_header (os, total_width, max_width, lim, col, + extra_indent); + + for (octave_idx_type ii = 0; ii < n_rows; ii++) + { + os << std::setw (extra_indent) << ""; + + for (octave_idx_type jj = col; jj < lim; jj++) + { + octave_quit (); + os << " "; + pr_int (os, page(ii,jj), fw); + } + if ((ii < n_rows - 1) || (i < m -1)) + os << "\n"; + } + } + } + + if (i < m - 1) + { + os << "\n"; + increment_index (ra_idx, dims, 2); + } + } } } #define PRINT_INT_ARRAY_INTERNAL(TYPE) \ OCTINTERP_API void \ octave_print_internal (std::ostream& os, const intNDArray& nda, \ - bool pr_as_read_syntax, int extra_indent) \ + bool pr_as_read_syntax, int extra_indent) \ { \ octave_print_internal_template (os, nda, pr_as_read_syntax, extra_indent); \ } @@ -3212,48 +3212,48 @@ rat_string_len = 9; if (nargin == 2) - rat_string_len = args(1).nint_value (); + rat_string_len = args(1).nint_value (); if (! error_state) - { - octave_value arg = args(0); - - if (arg.is_numeric_type ()) - { - frame.protect_var (rat_format); - - rat_format = true; - - std::ostringstream buf; - args(0).print (buf); - std::string s = buf.str (); - - std::list lst; - - size_t n = 0; - size_t s_len = s.length (); - - while (n < s_len) - { - size_t m = s.find ('\n', n); - - if (m == std::string::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"); - } + { + octave_value arg = args(0); + + if (arg.is_numeric_type ()) + { + frame.protect_var (rat_format); + + rat_format = true; + + std::ostringstream buf; + args(0).print (buf); + std::string s = buf.str (); + + std::list lst; + + size_t n = 0; + size_t s_len = s.length (); + + while (n < s_len) + { + size_t m = s.find ('\n', n); + + if (m == std::string::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"); + } } return retval; @@ -3288,14 +3288,14 @@ if (nargin == 1 && nargout < 2) { if (nargout == 0) - args(0).print (octave_stdout); + args(0).print (octave_stdout); else - { - octave_value arg = args(0); - std::ostringstream buf; - arg.print (buf); - retval = octave_value (buf.str (), arg.is_dq_string () ? '"' : '\''); - } + { + octave_value arg = args(0); + std::ostringstream buf; + arg.print (buf); + retval = octave_value (buf.str (), arg.is_dq_string () ? '"' : '\''); + } } else print_usage (); @@ -3333,14 +3333,14 @@ octave_stream os = octave_stream_list::lookup (fid, "fdisp"); if (! error_state) - { - std::ostream *osp = os.output_stream (); - - if (osp) - args(1).print (*osp); - else - error ("fdisp: stream not open for writing"); - } + { + std::ostream *osp = os.output_stream (); + + if (osp) + args(1).print (*osp); + else + error ("fdisp: stream not open for writing"); + } } else print_usage (); @@ -3392,155 +3392,155 @@ std::string arg = argv[idx++]; if (arg == "short") - { - if (--argc > 0) - { - arg = argv[idx++]; - - if (arg == "e") - { - init_format_state (); - print_e = true; - } - else if (arg == "E") - { - init_format_state (); - print_e = true; - print_big_e = true; - } - else if (arg == "g") - { - init_format_state (); - print_g = true; - } - else if (arg == "G") - { - init_format_state (); - print_g = true; - print_big_e = true; - } - else - { - error ("format: unrecognized option `short %s'", - arg.c_str ()); - return; - } - } - else - init_format_state (); - - set_output_prec_and_fw (5, 10); - } + { + if (--argc > 0) + { + arg = argv[idx++]; + + if (arg == "e") + { + init_format_state (); + print_e = true; + } + else if (arg == "E") + { + init_format_state (); + print_e = true; + print_big_e = true; + } + else if (arg == "g") + { + init_format_state (); + print_g = true; + } + else if (arg == "G") + { + init_format_state (); + print_g = true; + print_big_e = true; + } + else + { + error ("format: unrecognized option `short %s'", + arg.c_str ()); + return; + } + } + else + init_format_state (); + + set_output_prec_and_fw (5, 10); + } else if (arg == "long") - { - if (--argc > 0) - { - arg = argv[idx++]; - - if (arg == "e") - { - init_format_state (); - print_e = true; - } - else if (arg == "E") - { - init_format_state (); - print_e = true; - print_big_e = true; - } - else if (arg == "g") - { - init_format_state (); - print_g = true; - } - else if (arg == "G") - { - init_format_state (); - print_g = true; - print_big_e = true; - } - else - { - error ("format: unrecognized option `long %s'", - arg.c_str ()); - return; - } - } - else - init_format_state (); - - set_output_prec_and_fw (15, 20); - } + { + if (--argc > 0) + { + arg = argv[idx++]; + + if (arg == "e") + { + init_format_state (); + print_e = true; + } + else if (arg == "E") + { + init_format_state (); + print_e = true; + print_big_e = true; + } + else if (arg == "g") + { + init_format_state (); + print_g = true; + } + else if (arg == "G") + { + init_format_state (); + print_g = true; + print_big_e = true; + } + else + { + error ("format: unrecognized option `long %s'", + arg.c_str ()); + return; + } + } + else + init_format_state (); + + set_output_prec_and_fw (15, 20); + } else if (arg == "hex") - { - init_format_state (); - hex_format = 1; - } + { + init_format_state (); + hex_format = 1; + } else if (arg == "native-hex") - { - init_format_state (); - hex_format = 2; - } + { + init_format_state (); + hex_format = 2; + } else if (arg == "bit") - { - init_format_state (); - bit_format = 1; - } + { + init_format_state (); + bit_format = 1; + } else if (arg == "native-bit") - { - init_format_state (); - bit_format = 2; - } + { + init_format_state (); + bit_format = 2; + } 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; - } + { + 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; + } else if (arg == "rat") - { - init_format_state (); - rat_format = true; - } + { + init_format_state (); + rat_format = true; + } else if (arg == "bank") - { - init_format_state (); - bank_format = true; - } + { + init_format_state (); + bank_format = true; + } else if (arg == "free") - { - init_format_state (); - free_format = true; - } + { + init_format_state (); + free_format = true; + } else if (arg == "none") - { - init_format_state (); - free_format = true; - } + { + init_format_state (); + free_format = true; + } else if (arg == "compact") - { - compact_format = true; - } + { + compact_format = true; + } else if (arg == "loose") - { - compact_format = false; - } + { + compact_format = false; + } else - error ("format: unrecognized format state `%s'", arg.c_str ()); + error ("format: unrecognized format state `%s'", arg.c_str ()); } else { @@ -3842,5 +3842,5 @@ @end deftypefn") { return SET_INTERNAL_VARIABLE_WITH_LIMITS (struct_levels_to_print, - -1, INT_MAX); + -1, INT_MAX); } diff --git a/src/procstream.cc b/src/procstream.cc --- a/src/procstream.cc +++ b/src/procstream.cc @@ -62,7 +62,7 @@ if (is_open ()) { if (! pb.close ()) - std::ios::setstate (std::ios::failbit); + std::ios::setstate (std::ios::failbit); status = pb.wait_status (); } diff --git a/src/pt-arg-list.cc b/src/pt-arg-list.cc --- a/src/pt-arg-list.cc +++ b/src/pt-arg-list.cc @@ -65,7 +65,7 @@ tree_expression *elt = *p; if (elt && elt->has_magic_end ()) - return true; + return true; } return false; @@ -94,7 +94,7 @@ tree_expression *elt = *p; if (! elt->is_constant ()) - return false; + return false; } return true; @@ -112,46 +112,46 @@ if (indexed_object) { if (indexed_object->is_object ()) - { - octave_value_list args; + { + octave_value_list args; - args(2) = num_indices; - args(1) = index_position + 1; - args(0) = *indexed_object; + args(2) = num_indices; + args(1) = index_position + 1; + args(0) = *indexed_object; - std::string class_name = indexed_object->class_name (); + std::string class_name = indexed_object->class_name (); - octave_value meth = symbol_table::find_method ("end", class_name); + octave_value meth = symbol_table::find_method ("end", class_name); - if (meth.is_defined ()) - return feval (meth.function_value (), args, 1); - } + if (meth.is_defined ()) + return feval (meth.function_value (), args, 1); + } dim_vector dv = indexed_object->dims (); int ndims = dv.length (); if (num_indices < ndims) - { - for (int i = num_indices; i < ndims; i++) - dv(num_indices-1) *= dv(i); + { + for (int i = num_indices; i < ndims; i++) + dv(num_indices-1) *= dv(i); - if (num_indices == 1) - { - ndims = 2; - dv.resize (ndims); - dv(1) = 1; - } - else - { - ndims = num_indices; - dv.resize (ndims); - } - } + if (num_indices == 1) + { + ndims = 2; + dv.resize (ndims); + dv(1) = 1; + } + else + { + ndims = num_indices; + dv.resize (ndims); + } + } if (index_position < ndims) - retval = dv(index_position); + retval = dv(index_position); else - retval = 1; + retval = 1; } else ::error ("invalid use of end"); @@ -166,9 +166,9 @@ // way of asking an octave_value object this question? bool stash_object = (list_includes_magic_end - && object - && ! (object->is_function () - || object->is_function_handle ())); + && object + && ! (object->is_function () + || object->is_function_handle ())); unwind_protect frame; @@ -187,39 +187,39 @@ for (int k = 0; k < len; k++) { if (stash_object) - { - frame.protect_var (index_position); - frame.protect_var (num_indices); + { + frame.protect_var (index_position); + frame.protect_var (num_indices); - index_position = k; - num_indices = len; - } + index_position = k; + num_indices = len; + } tree_expression *elt = *p++; if (elt) - { - octave_value tmp = elt->rvalue1 (); + { + octave_value tmp = elt->rvalue1 (); - if (error_state) - { - ::error ("evaluating argument list element number %d", k+1); - args.clear (); - break; - } - else - { - if (tmp.is_cs_list ()) + if (error_state) + { + ::error ("evaluating argument list element number %d", k+1); + args.clear (); + break; + } + else + { + if (tmp.is_cs_list ()) args.push_back (tmp.list_value ()); - else if (tmp.is_defined ()) + else if (tmp.is_defined ()) args.push_back (tmp); - } - } + } + } else - { - args.push_back (octave_value ()); - break; - } + { + args.push_back (octave_value ()); + break; + } } return args; @@ -263,7 +263,7 @@ tree_argument_list * tree_argument_list::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { tree_argument_list *new_list = new tree_argument_list (); diff --git a/src/pt-assign.cc b/src/pt-assign.cc --- a/src/pt-assign.cc +++ b/src/pt-assign.cc @@ -148,7 +148,7 @@ const char **p = former_built_in_variables; while (*p) - vars.insert (*p++); + vars.insert (*p++); initialized = true; } @@ -158,8 +158,8 @@ const char *nm_c_str = nm.c_str (); warning_with_id ("Octave:built-in-variable-assignment", - "%s is now a function instead of a built-in variable. By assigning to %s, you have created a variable that hides the function %s. To remove the variable and restore the function, type \"clear %s\"", - nm_c_str, nm_c_str, nm_c_str, nm_c_str); + "%s is now a function instead of a built-in variable. By assigning to %s, you have created a variable that hides the function %s. To remove the variable and restore the function, type \"clear %s\"", + nm_c_str, nm_c_str, nm_c_str, nm_c_str); } } @@ -206,63 +206,63 @@ octave_value rhs_val = rhs->rvalue1 (); if (! error_state) - { - if (rhs_val.is_undefined ()) - { - error ("value on right hand side of assignment is undefined"); - return retval; - } - else - { - if (rhs_val.is_cs_list ()) - { - const octave_value_list lst = rhs_val.list_value (); + { + if (rhs_val.is_undefined ()) + { + error ("value on right hand side of assignment is undefined"); + return retval; + } + else + { + if (rhs_val.is_cs_list ()) + { + const octave_value_list lst = rhs_val.list_value (); - if (! lst.empty ()) - rhs_val = lst(0); - else - { - error ("invalid number of elements on RHS of assignment"); - return retval; - } - } + if (! lst.empty ()) + rhs_val = lst(0); + else + { + error ("invalid number of elements on RHS of assignment"); + return retval; + } + } - octave_lvalue ult = lhs->lvalue (); + octave_lvalue ult = lhs->lvalue (); if (ult.numel () != 1) gripe_nonbraced_cs_list_assignment (); - if (! error_state) - { - ult.assign (etype, rhs_val); + if (! error_state) + { + ult.assign (etype, rhs_val); - if (! error_state) - { - if (etype == octave_value::op_asn_eq) - retval = rhs_val; - else - retval = ult.value (); + if (! error_state) + { + if (etype == octave_value::op_asn_eq) + retval = rhs_val; + else + retval = ult.value (); - if (print_result ()) - { - // We clear any index here so that we can - // get the new value of the referenced - // object below, instead of the indexed - // value (which should be the same as the - // right hand side value). + if (print_result ()) + { + // We clear any index here so that we can + // get the new value of the referenced + // object below, instead of the indexed + // value (which should be the same as the + // right hand side value). - ult.clear_index (); + ult.clear_index (); - octave_value lhs_val = ult.value (); + octave_value lhs_val = ult.value (); - if (! error_state) - lhs_val.print_with_name (octave_stdout, - lhs->name ()); - } - } - } - } - } + if (! error_state) + lhs_val.print_with_name (octave_stdout, + lhs->name ()); + } + } + } + } + } } first_execution = false; @@ -278,12 +278,12 @@ tree_expression * tree_simple_assignment::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { tree_simple_assignment *new_sa = new tree_simple_assignment (lhs ? lhs->dup (scope, context) : 0, - rhs ? rhs->dup (scope, context) : 0, - preserve, etype); + rhs ? rhs->dup (scope, context) : 0, + preserve, etype); new_sa->copy_base (*this); @@ -352,14 +352,14 @@ std::list lvalue_list = lhs->lvalue_list (); if (error_state) - return retval; + return retval; int n_out = 0; for (std::list::const_iterator p = lvalue_list.begin (); - p != lvalue_list.end (); - p++) - n_out += p->numel (); + p != lvalue_list.end (); + p++) + n_out += p->numel (); // The following trick is used to keep rhs_val constant. const octave_value_list rhs_val1 = rhs->rvalue (n_out); @@ -367,7 +367,7 @@ ? rhs_val1(0).list_value () : rhs_val1); if (error_state) - return retval; + return retval; octave_idx_type k = 0; @@ -471,12 +471,12 @@ tree_expression * tree_multi_assignment::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { tree_multi_assignment *new_ma = new tree_multi_assignment (lhs ? lhs->dup (scope, context) : 0, - rhs ? rhs->dup (scope, context) : 0, - preserve); + rhs ? rhs->dup (scope, context) : 0, + preserve); new_ma->copy_base (*this); diff --git a/src/pt-binop.cc b/src/pt-binop.cc --- a/src/pt-binop.cc +++ b/src/pt-binop.cc @@ -41,7 +41,7 @@ if (nargout > 1) error ("binary operator `%s': invalid number of output arguments", - oper () . c_str ()); + oper () . c_str ()); else retval = rvalue1 (nargout); @@ -61,17 +61,17 @@ octave_value a = op_lhs->rvalue1 (); if (! error_state && a.is_defined () && op_rhs) - { - octave_value b = op_rhs->rvalue1 (); + { + octave_value b = op_rhs->rvalue1 (); - if (! error_state && b.is_defined ()) - { - retval = ::do_binary_op (etype, a, b); + if (! error_state && b.is_defined ()) + { + retval = ::do_binary_op (etype, a, b); - if (error_state) - retval = octave_value (); - } - } + if (error_state) + retval = octave_value (); + } + } } return retval; @@ -85,12 +85,12 @@ tree_expression * tree_binary_expression::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { tree_binary_expression *new_be = new tree_binary_expression (op_lhs ? op_lhs->dup (scope, context) : 0, - op_rhs ? op_rhs->dup (scope, context) : 0, - line (), column (), etype); + op_rhs ? op_rhs->dup (scope, context) : 0, + line (), column (), etype); new_be->copy_base (*this); @@ -112,7 +112,7 @@ if (nargout > 1) error ("binary operator `%s': invalid number of output arguments", - oper () . c_str ()); + oper () . c_str ()); else retval = rvalue1 (nargout); @@ -134,39 +134,39 @@ octave_value a = op_lhs->rvalue1 (); if (! error_state) - { - bool a_true = a.is_true (); + { + bool a_true = a.is_true (); - if (! error_state) - { - if (a_true) - { - if (etype == bool_or) - { - result = true; - goto done; - } - } - else - { - if (etype == bool_and) - goto done; - } + if (! error_state) + { + if (a_true) + { + if (etype == bool_or) + { + result = true; + goto done; + } + } + else + { + if (etype == bool_and) + goto done; + } - if (op_rhs) - { - octave_value b = op_rhs->rvalue1 (); + if (op_rhs) + { + octave_value b = op_rhs->rvalue1 (); - if (! error_state) - result = b.is_true (); - } + if (! error_state) + result = b.is_true (); + } - done: + done: - if (! error_state) - retval = octave_value (result); - } - } + if (! error_state) + retval = octave_value (result); + } + } } return retval; @@ -196,12 +196,12 @@ tree_expression * tree_boolean_expression::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { tree_boolean_expression *new_be = new tree_boolean_expression (op_lhs ? op_lhs->dup (scope, context) : 0, - op_rhs ? op_rhs->dup (scope, context) : 0, - line (), column (), etype); + op_rhs ? op_rhs->dup (scope, context) : 0, + line (), column (), etype); new_be->copy_base (*this); diff --git a/src/pt-bp.cc b/src/pt-bp.cc --- a/src/pt-bp.cc +++ b/src/pt-bp.cc @@ -43,7 +43,7 @@ tree_statement_list *lst = cmd.body (); if (lst) - lst->accept (*this); + lst->accept (*this); } } @@ -55,13 +55,13 @@ tree_statement_list *lst = cmd.body (); if (lst) - lst->accept (*this); + lst->accept (*this); if (! found) - { - if (cmd.line () >= line) - take_action (cmd); - } + { + if (cmd.line () >= line) + take_action (cmd); + } } } @@ -139,7 +139,7 @@ tree_statement_list *lst = cmd.body (); if (lst) - lst->accept (*this); + lst->accept (*this); } } @@ -154,7 +154,7 @@ tree_statement_list *lst = cmd.body (); if (lst) - lst->accept (*this); + lst->accept (*this); } } @@ -228,18 +228,18 @@ tree_if_clause *t = *p; if (t->line () >= line) - take_action (*t); + take_action (*t); if (! found) - { - tree_statement_list *stmt_lst = t->commands (); + { + tree_statement_list *stmt_lst = t->commands (); - if (stmt_lst) - stmt_lst->accept (*this); - } + if (stmt_lst) + stmt_lst->accept (*this); + } if (found) - break; + break; } } @@ -353,12 +353,12 @@ tree_statement *elt = *p; if (elt) - { - elt->accept (*this); + { + elt->accept (*this); - if (found) - break; - } + if (found) + break; + } } } @@ -376,18 +376,18 @@ tree_switch_case *t = *p; if (t->line () >= line) - take_action (*t); + take_action (*t); if (! found) - { - tree_statement_list *stmt_lst = t->commands (); + { + tree_statement_list *stmt_lst = t->commands (); - if (stmt_lst) - stmt_lst->accept (*this); - } + if (stmt_lst) + stmt_lst->accept (*this); + } if (found) - break; + break; } } @@ -402,7 +402,7 @@ tree_switch_case_list *lst = cmd.case_list (); if (lst) - lst->accept (*this); + lst->accept (*this); } } @@ -419,7 +419,7 @@ tree_statement_list *catch_code = cmd.cleanup (); if (catch_code) - catch_code->accept (*this); + catch_code->accept (*this); } } @@ -436,7 +436,7 @@ tree_statement_list *cleanup = cmd.cleanup (); if (cleanup) - cleanup->accept (*this); + cleanup->accept (*this); } } @@ -457,10 +457,10 @@ else if (act == list) { if (tr.is_breakpoint ()) - { - bp_list.append (octave_value (tr.line ())); - line = tr.line () + 1; - } + { + bp_list.append (octave_value (tr.line ())); + line = tr.line () + 1; + } } else panic_impossible (); @@ -485,10 +485,10 @@ else if (act == list) { if (stmt.is_breakpoint ()) - { - bp_list.append (octave_value (lineno)); - line = lineno + 1; - } + { + bp_list.append (octave_value (lineno)); + line = lineno + 1; + } } else panic_impossible (); diff --git a/src/pt-cbinop.cc b/src/pt-cbinop.cc --- a/src/pt-cbinop.cc +++ b/src/pt-cbinop.cc @@ -47,9 +47,9 @@ if (op == octave_value::op_transpose || op == octave_value::op_hermitian) - exp = uexp->operand (); + exp = uexp->operand (); else - op = octave_value::unknown_unary_op; + op = octave_value::unknown_unary_op; return op; } @@ -68,9 +68,9 @@ octave_value::unary_op op = uexp->op_type (); if (op == octave_value::op_not) - exp = uexp->operand (); + exp = uexp->operand (); else - op = octave_value::unknown_unary_op; + op = octave_value::unknown_unary_op; return op; } @@ -204,17 +204,17 @@ octave_value a = op_lhs->rvalue1 (); if (! error_state && a.is_defined () && op_rhs) - { - octave_value b = op_rhs->rvalue1 (); + { + octave_value b = op_rhs->rvalue1 (); - if (! error_state && b.is_defined ()) - { - retval = ::do_binary_op (etype, a, b); + if (! error_state && b.is_defined ()) + { + retval = ::do_binary_op (etype, a, b); - if (error_state) - retval = octave_value (); - } - } + if (error_state) + retval = octave_value (); + } + } } return retval; diff --git a/src/pt-cell.cc b/src/pt-cell.cc --- a/src/pt-cell.cc +++ b/src/pt-cell.cc @@ -62,24 +62,24 @@ // Optimize the single row case. val = row.cell_value (); else if (nc < 0) - { - nc = row.length (); + { + nc = row.length (); - val = Cell (nr, nc); - } + val = Cell (nr, nc); + } else - { - octave_idx_type this_nc = row.length (); + { + octave_idx_type this_nc = row.length (); - if (nc != this_nc) - { - ::error ("number of columns must match"); - return retval; - } - } + if (nc != this_nc) + { + ::error ("number of columns must match"); + return retval; + } + } for (octave_idx_type j = 0; j < nc; j++) - val(i,j) = row(j); + val(i,j) = row(j); i++; } @@ -104,7 +104,7 @@ tree_expression * tree_cell::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { tree_cell *new_cell = new tree_cell (0, line (), column ()); diff --git a/src/pt-check.cc b/src/pt-check.cc --- a/src/pt-check.cc +++ b/src/pt-check.cc @@ -40,10 +40,10 @@ tree_expression *elt = *p++; if (elt) - { - if (do_lvalue_check && ! elt->lvalue_ok ()) - gripe ("invalid lvalue in multiple assignment", elt->line ()); - } + { + if (do_lvalue_check && ! elt->lvalue_ok ()) + gripe ("invalid lvalue in multiple assignment", elt->line ()); + } } } @@ -135,7 +135,7 @@ tree_decl_elt *elt = *p++; if (elt) - elt->accept (*this); + elt->accept (*this); } } @@ -147,7 +147,7 @@ if (lhs) { if (! lhs->lvalue_ok ()) - gripe ("invalid lvalue in for command", cmd.line ()); + gripe ("invalid lvalue in for command", cmd.line ()); } tree_expression *expr = cmd.control_expr (); @@ -171,8 +171,8 @@ int len = lhs->length (); if (len == 0 || len > 2) - gripe ("invalid number of output arguments in for command", - cmd.line ()); + gripe ("invalid number of output arguments in for command", + cmd.line ()); do_lvalue_check = true; @@ -259,7 +259,7 @@ tree_if_clause *elt = *p++; if (elt) - elt->accept (*this); + elt->accept (*this); } } @@ -280,7 +280,7 @@ tree_argument_list *elt = *p++; if (elt) - elt->accept (*this); + elt->accept (*this); } } @@ -294,7 +294,7 @@ tree_argument_list *elt = *p++; if (elt) - elt->accept (*this); + elt->accept (*this); } } @@ -308,7 +308,7 @@ tree_argument_list *elt = *p++; if (elt) - elt->accept (*this); + elt->accept (*this); } } @@ -362,7 +362,7 @@ tree_decl_elt *elt = *p++; if (elt) - elt->accept (*this); + elt->accept (*this); } } @@ -399,7 +399,7 @@ tree_index_expression *elt = *p++; if (elt) - elt->accept (*this); + elt->accept (*this); } } @@ -411,7 +411,7 @@ if (lhs) { if (! lhs->lvalue_ok ()) - gripe ("invalid lvalue in assignment", expr.line ()); + gripe ("invalid lvalue in assignment", expr.line ()); } tree_expression *rhs = expr.right_hand_side (); @@ -432,7 +432,7 @@ tree_expression *expr = stmt.expression (); if (expr) - expr->accept (*this); + expr->accept (*this); } } @@ -444,7 +444,7 @@ tree_statement *elt = *p; if (elt) - elt->accept (*this); + elt->accept (*this); } } @@ -472,7 +472,7 @@ tree_switch_case *elt = *p++; if (elt) - elt->accept (*this); + elt->accept (*this); } } diff --git a/src/pt-cmd.cc b/src/pt-cmd.cc --- a/src/pt-cmd.cc +++ b/src/pt-cmd.cc @@ -32,7 +32,7 @@ tree_command * tree_no_op_command::dup (symbol_table::scope_id, - symbol_table::context_id) const + symbol_table::context_id) const { return new tree_no_op_command (orig_cmd, line (), column ()); } @@ -47,7 +47,7 @@ tree_command * tree_function_def::dup (symbol_table::scope_id, - symbol_table::context_id) const + symbol_table::context_id) const { return new tree_function_def (fcn, line (), column ()); } diff --git a/src/pt-colon.cc b/src/pt-colon.cc --- a/src/pt-colon.cc +++ b/src/pt-colon.cc @@ -43,22 +43,22 @@ if (op_base) { if (op_limit) - { - if (op_increment) - ::error ("invalid colon expression"); - else - { - // Stupid syntax: - // - // base : limit - // base : increment : limit + { + if (op_increment) + ::error ("invalid colon expression"); + else + { + // Stupid syntax: + // + // base : limit + // base : increment : limit - op_increment = op_limit; - op_limit = t; - } - } + op_increment = op_limit; + op_limit = t; + } + } else - op_limit = t; + op_limit = t; retval = this; } @@ -83,9 +83,9 @@ octave_value tree_colon_expression::make_range (const Matrix& m_base, - const Matrix& m_limit, - const Matrix& m_increment, - bool result_is_str, bool dq_str) const + const Matrix& m_limit, + const Matrix& m_increment, + bool result_is_str, bool dq_str) const { octave_value retval; @@ -100,7 +100,7 @@ retval = Range (m_base(0), m_limit(0), m_increment(0)); if (result_is_str) - retval = retval.convert_to_str (false, true, dq_str ? '"' : '\''); + retval = retval.convert_to_str (false, true, dq_str ? '"' : '\''); } return retval; @@ -108,8 +108,8 @@ octave_value tree_colon_expression::make_range (const octave_value& ov_base, - const octave_value& ov_limit, - const octave_value& ov_increment) const + const octave_value& ov_limit, + const octave_value& ov_increment) const { octave_value retval; @@ -124,14 +124,14 @@ octave_value fcn = symbol_table::find_function ("colon", tmp1); if (fcn.is_defined ()) - { - octave_value_list tmp2 = fcn.do_multi_index_op (1, tmp1); - - if (! error_state) - retval = tmp2 (0); - } + { + octave_value_list tmp2 = fcn.do_multi_index_op (1, tmp1); + + if (! error_state) + retval = tmp2 (0); + } else - ::error ("can not find overloaded colon function"); + ::error ("can not find overloaded colon function"); } else { @@ -141,24 +141,24 @@ Matrix m_base = ov_base.matrix_value (true); if (error_state) - eval_error ("invalid base value in colon expression"); + eval_error ("invalid base value in colon expression"); else - { - Matrix m_limit = ov_limit.matrix_value (true); + { + Matrix m_limit = ov_limit.matrix_value (true); - if (error_state) - eval_error ("invalid limit value in colon expression"); - else - { - Matrix m_increment = ov_increment.matrix_value (true); + if (error_state) + eval_error ("invalid limit value in colon expression"); + else + { + Matrix m_increment = ov_increment.matrix_value (true); - if (error_state) - eval_error ("invalid increment value in colon expression"); - else - retval = make_range (m_base, m_limit, m_increment, - result_is_str, dq_str); - } - } + if (error_state) + eval_error ("invalid increment value in colon expression"); + else + retval = make_range (m_base, m_limit, m_increment, + result_is_str, dq_str); + } + } } return retval; @@ -181,60 +181,60 @@ octave_value ov_limit = op_limit->rvalue1 (); if (error_state || ov_limit.is_undefined ()) - eval_error ("invalid limit value in colon expression"); + eval_error ("invalid limit value in colon expression"); else if (ov_base.is_object () || ov_limit.is_object ()) - { - octave_value_list tmp1; + { + octave_value_list tmp1; - if (op_increment) - { - octave_value ov_increment = op_increment->rvalue1 (); + if (op_increment) + { + octave_value ov_increment = op_increment->rvalue1 (); - if (error_state || ov_increment.is_undefined ()) - eval_error ("invalid increment value in colon expression"); - else - { - tmp1(2) = ov_limit; - tmp1(1) = ov_increment; - tmp1(0) = ov_base; - } - } - else - { - tmp1(1) = ov_limit; - tmp1(0) = ov_base; - } + if (error_state || ov_increment.is_undefined ()) + eval_error ("invalid increment value in colon expression"); + else + { + tmp1(2) = ov_limit; + tmp1(1) = ov_increment; + tmp1(0) = ov_base; + } + } + else + { + tmp1(1) = ov_limit; + tmp1(0) = ov_base; + } - if (!error_state) - { - octave_value fcn = symbol_table::find_function ("colon", tmp1); + if (!error_state) + { + octave_value fcn = symbol_table::find_function ("colon", tmp1); - if (fcn.is_defined ()) - { - octave_value_list tmp2 = fcn.do_multi_index_op (1, tmp1); - - if (! error_state) - retval = tmp2 (0); - } - else - ::error ("can not find overloaded colon function"); - } - } + if (fcn.is_defined ()) + { + octave_value_list tmp2 = fcn.do_multi_index_op (1, tmp1); + + if (! error_state) + retval = tmp2 (0); + } + else + ::error ("can not find overloaded colon function"); + } + } else - { - octave_value ov_increment = 1.0; + { + octave_value ov_increment = 1.0; - if (op_increment) - { - ov_increment = op_increment->rvalue1 (); + if (op_increment) + { + ov_increment = op_increment->rvalue1 (); - if (error_state || ov_increment.is_undefined ()) - eval_error ("invalid increment value in colon expression"); - } + if (error_state || ov_increment.is_undefined ()) + eval_error ("invalid increment value in colon expression"); + } - if (! error_state) - retval = make_range (ov_base, ov_limit, ov_increment); - } + if (! error_state) + retval = make_range (ov_base, ov_limit, ov_increment); + } } return retval; @@ -250,29 +250,29 @@ tree_colon_expression::line (void) const { return (op_base ? op_base->line () - : (op_increment ? op_increment->line () - : (op_limit ? op_limit->line () - : -1))); + : (op_increment ? op_increment->line () + : (op_limit ? op_limit->line () + : -1))); } int tree_colon_expression::column (void) const { return (op_base ? op_base->column () - : (op_increment ? op_increment->column () - : (op_limit ? op_limit->column () - : -1))); + : (op_increment ? op_increment->column () + : (op_limit ? op_limit->column () + : -1))); } tree_expression * tree_colon_expression::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { tree_colon_expression *new_ce = new tree_colon_expression (op_base ? op_base->dup (scope, context) : 0, - op_limit ? op_limit->dup (scope, context) : 0, - op_increment ? op_increment->dup (scope, context) : 0, - line (), column ()); + op_limit ? op_limit->dup (scope, context) : 0, + op_increment ? op_increment->dup (scope, context) : 0, + line (), column ()); new_ce->copy_base (*new_ce); diff --git a/src/pt-const.cc b/src/pt-const.cc --- a/src/pt-const.cc +++ b/src/pt-const.cc @@ -49,7 +49,7 @@ void tree_constant::print_raw (std::ostream& os, bool pr_as_read_syntax, - bool pr_orig_text) + bool pr_orig_text) { if (pr_orig_text && ! orig_text.empty ()) os << orig_text; @@ -72,7 +72,7 @@ tree_expression * tree_constant::dup (symbol_table::scope_id, - symbol_table::context_id) const + symbol_table::context_id) const { tree_constant *new_tc = new tree_constant (val, orig_text, line (), column ()); diff --git a/src/pt-decl.cc b/src/pt-decl.cc --- a/src/pt-decl.cc +++ b/src/pt-decl.cc @@ -58,11 +58,11 @@ octave_value init_val = expr->rvalue1 (); if (! error_state) - { - ult.assign (octave_value::op_asn_eq, init_val); + { + ult.assign (octave_value::op_asn_eq, init_val); - retval = true; - } + retval = true; + } } return retval; @@ -70,10 +70,10 @@ tree_decl_elt * tree_decl_elt::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { return new tree_decl_elt (id ? id->dup (scope, context) : 0, - expr ? expr->dup (scope, context) : 0); + expr ? expr->dup (scope, context) : 0); } void @@ -86,7 +86,7 @@ tree_decl_init_list * tree_decl_init_list::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { tree_decl_init_list *new_dil = new tree_decl_init_list (); @@ -117,11 +117,11 @@ tree_command * tree_global_command::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { return new tree_global_command (init_list ? init_list->dup (scope, context) : 0, - line (), column ()); + line (), column ()); } void @@ -134,11 +134,11 @@ tree_command * tree_static_command::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { return new tree_static_command (init_list ? init_list->dup (scope, context) : 0, - line (), column ()); + line (), column ()); } void diff --git a/src/pt-eval.cc b/src/pt-eval.cc --- a/src/pt-eval.cc +++ b/src/pt-eval.cc @@ -88,7 +88,7 @@ if (! error_state) { if (debug_mode) - do_breakpoint (cmd.is_breakpoint ()); + do_breakpoint (cmd.is_breakpoint ()); if (tree_evaluator::in_fcn_or_script_body || tree_evaluator::in_loop_command) @@ -108,7 +108,7 @@ if (! error_state) { if (debug_mode) - do_breakpoint (cmd.is_breakpoint ()); + do_breakpoint (cmd.is_breakpoint ()); if (tree_evaluator::in_fcn_or_script_body || tree_evaluator::in_loop_command) @@ -134,23 +134,23 @@ id->mark_global (); if (! error_state) - { - octave_lvalue ult = id->lvalue (); + { + octave_lvalue ult = id->lvalue (); - if (ult.is_undefined ()) - { - tree_expression *expr = elt.expression (); + if (ult.is_undefined ()) + { + tree_expression *expr = elt.expression (); - octave_value init_val; + octave_value init_val; - if (expr) - init_val = expr->rvalue1 (); - else - init_val = Matrix (); + if (expr) + init_val = expr->rvalue1 (); + else + init_val = Matrix (); - ult.assign (octave_value::op_asn_eq, init_val); - } - } + ult.assign (octave_value::op_asn_eq, init_val); + } + } } } @@ -166,37 +166,37 @@ octave_lvalue ult = id->lvalue (); if (ult.is_undefined ()) - { - tree_expression *expr = elt.expression (); + { + tree_expression *expr = elt.expression (); - octave_value init_val; + octave_value init_val; - if (expr) - init_val = expr->rvalue1 (); - else - init_val = Matrix (); + if (expr) + init_val = expr->rvalue1 (); + else + init_val = Matrix (); - ult.assign (octave_value::op_asn_eq, init_val); - } + ult.assign (octave_value::op_asn_eq, init_val); + } } } void tree_evaluator::do_decl_init_list (decl_elt_init_fcn fcn, - tree_decl_init_list *init_list) + tree_decl_init_list *init_list) { if (init_list) { for (tree_decl_init_list::iterator p = init_list->begin (); - p != init_list->end (); p++) - { - tree_decl_elt *elt = *p; + p != init_list->end (); p++) + { + tree_decl_elt *elt = *p; - fcn (*elt); + fcn (*elt); - if (error_state) - break; - } + if (error_state) + break; + } } } @@ -266,9 +266,9 @@ tree_continue_command::continuing--; bool quit = (error_state - || tree_return_command::returning - || tree_break_command::breaking - || tree_continue_command::continuing); + || tree_return_command::returning + || tree_break_command::breaking + || tree_continue_command::continuing); if (tree_break_command::breaking) tree_break_command::breaking--; @@ -282,7 +282,7 @@ ult.assign (octave_value::op_asn_eq, VAL); \ \ if (! error_state && loop_body) \ - loop_body->accept (*this); \ + loop_body->accept (*this); \ \ quit = quit_loop_now (); \ } \ @@ -322,37 +322,37 @@ if (rhs.is_range ()) { - Range rng = rhs.range_value (); + Range rng = rhs.range_value (); - octave_idx_type steps = rng.nelem (); - double b = rng.base (); - double increment = rng.inc (); - bool quit = false; + octave_idx_type steps = rng.nelem (); + double b = rng.base (); + double increment = rng.inc (); + bool quit = false; - for (octave_idx_type i = 0; i < steps; i++) - { - // Use multiplication here rather than declaring a - // temporary variable outside the loop and using - // - // tmp_val += increment - // - // to avoid problems with limited precision. Also, this - // is consistent with the way Range::matrix_value is - // implemented. + for (octave_idx_type i = 0; i < steps; i++) + { + // Use multiplication here rather than declaring a + // temporary variable outside the loop and using + // + // tmp_val += increment + // + // to avoid problems with limited precision. Also, this + // is consistent with the way Range::matrix_value is + // implemented. - octave_value val (b + i * increment); + octave_value val (b + i * increment); - DO_SIMPLE_FOR_LOOP_ONCE (val); + DO_SIMPLE_FOR_LOOP_ONCE (val); - if (quit) - break; - } + if (quit) + break; + } } else if (rhs.is_scalar_type ()) { - bool quit = false; + bool quit = false; - DO_SIMPLE_FOR_LOOP_ONCE (rhs); + DO_SIMPLE_FOR_LOOP_ONCE (rhs); } else if (rhs.is_matrix_type () || rhs.is_cell () || rhs.is_string () || rhs.is_map ()) @@ -401,8 +401,8 @@ } else { - ::error ("invalid type in for loop expression near line %d, column %d", - cmd.line (), cmd.column ()); + ::error ("invalid type in for loop expression near line %d, column %d", + cmd.line (), cmd.column ()); } } } @@ -456,24 +456,24 @@ octave_idx_type nel = keys.numel (); for (octave_idx_type i = 0; i < nel; i++) - { - std::string key = keys[i]; + { + std::string key = keys[i]; - const Cell val_lst = tmp_val.contents (key); + const Cell val_lst = tmp_val.contents (key); - octave_idx_type n = val_lst.numel (); + octave_idx_type n = val_lst.numel (); - octave_value val = (n == 1) ? val_lst(0) : octave_value (val_lst); + octave_value val = (n == 1) ? val_lst(0) : octave_value (val_lst); - val_ref.assign (octave_value::op_asn_eq, val); - key_ref.assign (octave_value::op_asn_eq, key); + val_ref.assign (octave_value::op_asn_eq, val); + key_ref.assign (octave_value::op_asn_eq, key); - if (! error_state && loop_body) - loop_body->accept (*this); + if (! error_state && loop_body) + loop_body->accept (*this); - if (quit_loop_now ()) - break; - } + if (quit_loop_now ()) + break; + } } else error ("in statement `for [X, Y] = VAL', VAL must be a structure"); @@ -554,20 +554,20 @@ tree_expression *expr = tic->condition (); if (debug_mode && ! tic->is_else_clause ()) - do_breakpoint (tic->is_breakpoint ()); + do_breakpoint (tic->is_breakpoint ()); if (tic->is_else_clause () || expr->is_logically_true ("if")) - { - if (! error_state) - { - tree_statement_list *stmt_lst = tic->commands (); + { + if (! error_state) + { + tree_statement_list *stmt_lst = tic->commands (); - if (stmt_lst) - stmt_lst->accept (*this); - } + if (stmt_lst) + stmt_lst->accept (*this); + } - break; - } + break; + } } } @@ -638,7 +638,7 @@ if (! error_state) { if (debug_mode) - do_breakpoint (cmd.is_breakpoint ()); + do_breakpoint (cmd.is_breakpoint ()); // Act like dbcont. @@ -676,58 +676,58 @@ if (cmd || expr) { if (in_fcn_or_script_body) - { - octave_call_stack::set_statement (&stmt); + { + octave_call_stack::set_statement (&stmt); - if (Vecho_executing_commands & ECHO_FUNCTIONS) - stmt.echo_code (); - } + if (Vecho_executing_commands & ECHO_FUNCTIONS) + stmt.echo_code (); + } try - { - if (cmd) - cmd->accept (*this); - else - { - if (debug_mode) - do_breakpoint (expr->is_breakpoint ()); + { + if (cmd) + cmd->accept (*this); + else + { + if (debug_mode) + do_breakpoint (expr->is_breakpoint ()); - if (in_fcn_or_script_body && Vsilent_functions) - expr->set_print_flag (false); + if (in_fcn_or_script_body && Vsilent_functions) + expr->set_print_flag (false); - // FIXME -- maybe all of this should be packaged in - // one virtual function that returns a flag saying whether - // or not the expression will take care of binding ans and - // printing the result. + // FIXME -- maybe all of this should be packaged in + // one virtual function that returns a flag saying whether + // or not the expression will take care of binding ans and + // printing the result. - // FIXME -- it seems that we should just have to - // call expr->rvalue1 () and that should take care of - // everything, binding ans as necessary? + // FIXME -- it seems that we should just have to + // call expr->rvalue1 () and that should take care of + // everything, binding ans as necessary? - bool do_bind_ans = false; + bool do_bind_ans = false; - if (expr->is_identifier ()) - { - tree_identifier *id = dynamic_cast (expr); + if (expr->is_identifier ()) + { + tree_identifier *id = dynamic_cast (expr); - do_bind_ans = (! id->is_variable ()); - } - else - do_bind_ans = (! expr->is_assignment_expression ()); + do_bind_ans = (! id->is_variable ()); + } + else + do_bind_ans = (! expr->is_assignment_expression ()); - octave_value tmp_result = expr->rvalue1 (0); + octave_value tmp_result = expr->rvalue1 (0); - if (do_bind_ans && ! (error_state || tmp_result.is_undefined ())) - bind_ans (tmp_result, expr->print_result ()); + if (do_bind_ans && ! (error_state || tmp_result.is_undefined ())) + bind_ans (tmp_result, expr->print_result ()); - // if (tmp_result.is_defined ()) - // result_values(0) = tmp_result; - } - } + // if (tmp_result.is_defined ()) + // result_values(0) = tmp_result; + } + } catch (octave_execution_exception) - { - gripe_library_execution_error (); - } + { + gripe_library_execution_error (); + } } } @@ -744,48 +744,48 @@ if (p != lst.end ()) { while (true) - { - tree_statement *elt = *p++; + { + tree_statement *elt = *p++; - if (elt) - { - octave_quit (); + if (elt) + { + octave_quit (); - elt->accept (*this); + elt->accept (*this); - if (error_state) - break; + if (error_state) + break; - if (tree_break_command::breaking - || tree_continue_command::continuing) - break; + if (tree_break_command::breaking + || tree_continue_command::continuing) + break; - if (tree_return_command::returning) - break; + if (tree_return_command::returning) + break; - if (p == lst.end ()) - break; - else - { - // Clear preivous values before next statement is - // evaluated so that we aren't holding an extra - // reference to a value that may be used next. For - // example, in code like this: - // - // X = rand (N); ## refcount for X should be 1 - // ## after this statement - // - // X(idx) = val; ## no extra copy of X should be - // ## needed, but we will be faked - // ## out if retval is not cleared - // ## between statements here + if (p == lst.end ()) + break; + else + { + // Clear preivous values before next statement is + // evaluated so that we aren't holding an extra + // reference to a value that may be used next. For + // example, in code like this: + // + // X = rand (N); ## refcount for X should be 1 + // ## after this statement + // + // X(idx) = val; ## no extra copy of X should be + // ## needed, but we will be faked + // ## out if retval is not cleared + // ## between statements here - // result_values = empty_list; - } - } - else - error ("invalid statement found in statement list!"); - } + // result_values = empty_list; + } + } + else + error ("invalid statement found in statement list!"); + } } } @@ -813,33 +813,33 @@ tree_switch_case_list *lst = cmd.case_list (); if (! error_state && lst) - { - for (tree_switch_case_list::iterator p = lst->begin (); - p != lst->end (); p++) - { - tree_switch_case *t = *p; + { + for (tree_switch_case_list::iterator p = lst->begin (); + p != lst->end (); p++) + { + tree_switch_case *t = *p; - if (debug_mode && ! t->is_default_case ()) - do_breakpoint (t->is_breakpoint ()); + if (debug_mode && ! t->is_default_case ()) + do_breakpoint (t->is_breakpoint ()); - if (t->is_default_case () || t->label_matches (val)) - { - if (error_state) - break; + if (t->is_default_case () || t->label_matches (val)) + { + if (error_state) + break; - tree_statement_list *stmt_lst = t->commands (); + tree_statement_list *stmt_lst = t->commands (); - if (stmt_lst) - stmt_lst->accept (*this); + if (stmt_lst) + stmt_lst->accept (*this); - break; - } - } - } + break; + } + } + } } else ::error ("missing value in switch command near line %d, column %d", - cmd.line (), cmd.column ()); + cmd.line (), cmd.column ()); } void @@ -1016,25 +1016,25 @@ for (;;) { if (debug_mode) - do_breakpoint (cmd.is_breakpoint ()); + do_breakpoint (cmd.is_breakpoint ()); if (expr->is_logically_true ("while")) - { - tree_statement_list *loop_body = cmd.body (); + { + tree_statement_list *loop_body = cmd.body (); - if (loop_body) - { - loop_body->accept (*this); + if (loop_body) + { + loop_body->accept (*this); - if (error_state) + if (error_state) return; - } + } - if (quit_loop_now ()) - break; - } + if (quit_loop_now ()) + break; + } else - break; + break; } } @@ -1060,21 +1060,21 @@ tree_statement_list *loop_body = cmd.body (); if (loop_body) - { - loop_body->accept (*this); + { + loop_body->accept (*this); - if (error_state) + if (error_state) return; - } + } if (quit_loop_now ()) - break; + break; if (debug_mode) - do_breakpoint (cmd.is_breakpoint ()); + do_breakpoint (cmd.is_breakpoint ()); if (expr->is_logically_true ("do-until")) - break; + break; } } @@ -1086,7 +1086,7 @@ void tree_evaluator::do_breakpoint (bool is_breakpoint, - bool is_end_of_fcn_or_script) const + bool is_end_of_fcn_or_script) const { bool break_on_this_statement = false; @@ -1096,14 +1096,14 @@ if (dbstep_flag > 1) { if (octave_call_stack::current_frame () == current_frame) - { - // Don't allow dbstep N to step past end of current frame. + { + // Don't allow dbstep N to step past end of current frame. - if (is_end_of_fcn_or_script) - dbstep_flag = 1; - else - dbstep_flag--; - } + if (is_end_of_fcn_or_script) + dbstep_flag = 1; + else + dbstep_flag--; + } } if (octave_debug_on_interrupt_state) @@ -1125,15 +1125,15 @@ else if (dbstep_flag == 1) { if (octave_call_stack::current_frame () == current_frame) - { - // We get here if we are doing a "dbstep" or a "dbstep N" - // and the count has reached 1 and we are in the current - // debugging frame. + { + // We get here if we are doing a "dbstep" or a "dbstep N" + // and the count has reached 1 and we are in the current + // debugging frame. - break_on_this_statement = true; + break_on_this_statement = true; - dbstep_flag = 0; - } + dbstep_flag = 0; + } } else if (dbstep_flag == -1) { @@ -1150,7 +1150,7 @@ // We get here if we are doing a "dbstep out". if (is_end_of_fcn_or_script) - dbstep_flag = -1; + dbstep_flag = -1; } if (break_on_this_statement) diff --git a/src/pt-except.cc b/src/pt-except.cc --- a/src/pt-except.cc +++ b/src/pt-except.cc @@ -53,15 +53,15 @@ tree_command * tree_try_catch_command::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { return new tree_try_catch_command (try_code ? try_code->dup (scope, context) : 0, - catch_code ? catch_code->dup (scope, context) : 0, - lead_comm ? lead_comm->dup () : 0, - mid_comm ? mid_comm->dup () : 0, - trail_comm ? trail_comm->dup () : 0, - line (), column ()); + catch_code ? catch_code->dup (scope, context) : 0, + lead_comm ? lead_comm->dup () : 0, + mid_comm ? mid_comm->dup () : 0, + trail_comm ? trail_comm->dup () : 0, + line (), column ()); } void @@ -83,7 +83,7 @@ tree_command * tree_unwind_protect_command::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { return new tree_unwind_protect_command (unwind_protect_code ? unwind_protect_code->dup (scope, context) : 0, diff --git a/src/pt-exp.cc b/src/pt-exp.cc --- a/src/pt-exp.cc +++ b/src/pt-exp.cc @@ -46,10 +46,10 @@ if (! error_state) { if (t1.is_defined ()) - return t1.is_true (); + return t1.is_true (); else - ::error ("%s: undefined value used in conditional expression", - warn_for); + ::error ("%s: undefined value used in conditional expression", + warn_for); } return expr_value; diff --git a/src/pt-fcn-handle.cc b/src/pt-fcn-handle.cc --- a/src/pt-fcn-handle.cc +++ b/src/pt-fcn-handle.cc @@ -37,14 +37,14 @@ void tree_fcn_handle::print (std::ostream& os, bool pr_as_read_syntax, - bool pr_orig_text) + bool pr_orig_text) { print_raw (os, pr_as_read_syntax, pr_orig_text); } void tree_fcn_handle::print_raw (std::ostream& os, bool pr_as_read_syntax, - bool pr_orig_text) + bool pr_orig_text) { os << ((pr_as_read_syntax || pr_orig_text) ? "@" : "") << nm; } @@ -70,7 +70,7 @@ tree_expression * tree_fcn_handle::dup (symbol_table::scope_id, - symbol_table::context_id) const + symbol_table::context_id) const { tree_fcn_handle *new_fh = new tree_fcn_handle (nm, line (), column ()); @@ -100,13 +100,13 @@ if (new_scope > 0) symbol_table::inherit (new_scope, symbol_table::current_scope (), - symbol_table::current_context ()); + symbol_table::current_context ()); octave_user_function *uf = new octave_user_function (new_scope, - param_list ? param_list->dup (new_scope, 0) : 0, - ret_list ? ret_list->dup (new_scope, 0) : 0, - cmd_list ? cmd_list->dup (new_scope, 0) : 0); + param_list ? param_list->dup (new_scope, 0) : 0, + ret_list ? ret_list->dup (new_scope, 0) : 0, + cmd_list ? cmd_list->dup (new_scope, 0) : 0); octave_function *curr_fcn = octave_call_stack::current (); @@ -117,8 +117,8 @@ symbol_table::scope_id parent_scope = curr_fcn->parent_fcn_scope (); if (parent_scope < 0) - parent_scope = curr_fcn->scope (); - + parent_scope = curr_fcn->scope (); + uf->stash_parent_fcn_scope (parent_scope); } @@ -165,7 +165,7 @@ tree_expression * tree_anon_fcn_handle::dup (symbol_table::scope_id, - symbol_table::context_id) const + symbol_table::context_id) const { tree_parameter_list *param_list = parameter_list (); tree_parameter_list *ret_list = return_list (); @@ -176,13 +176,13 @@ if (new_scope > 0) symbol_table::inherit (new_scope, symbol_table::current_scope (), - symbol_table::current_context ()); + symbol_table::current_context ()); tree_anon_fcn_handle *new_afh = new tree_anon_fcn_handle (param_list ? param_list->dup (new_scope, 0) : 0, - ret_list ? ret_list->dup (new_scope, 0) : 0, - cmd_list ? cmd_list->dup (new_scope, 0) : 0, - new_scope, line (), column ()); + ret_list ? ret_list->dup (new_scope, 0) : 0, + cmd_list ? cmd_list->dup (new_scope, 0) : 0, + new_scope, line (), column ()); new_afh->copy_base (*this); diff --git a/src/pt-id.cc b/src/pt-id.cc --- a/src/pt-id.cc +++ b/src/pt-id.cc @@ -49,7 +49,7 @@ ::error ("`%s' undefined", name ().c_str ()); else ::error ("`%s' undefined near line %d column %d", - name ().c_str (), l, c); + name ().c_str (), l, c); } octave_value_list @@ -76,18 +76,18 @@ // a value. if (val.is_function () && ! is_postfix_indexed ()) - { - octave_value_list tmp_args; + { + octave_value_list tmp_args; - retval = val.do_multi_index_op (nargout, tmp_args); - } + retval = val.do_multi_index_op (nargout, tmp_args); + } else - { - if (print_result () && nargout == 0) - val.print_with_name (octave_stdout, name ()); + { + if (print_result () && nargout == 0) + val.print_with_name (octave_stdout, name ()); - retval = val; - } + retval = val; + } } else eval_undefined_error (); @@ -116,7 +116,7 @@ tree_identifier * tree_identifier::dup (symbol_table::scope_id sc, - symbol_table::context_id) const + symbol_table::context_id) const { // The new tree_identifier object contains a symbol_record // entry from the duplicated scope. diff --git a/src/pt-idx.cc b/src/pt-idx.cc --- a/src/pt-idx.cc +++ b/src/pt-idx.cc @@ -48,8 +48,8 @@ arg_nm (), dyn_field () { } tree_index_expression::tree_index_expression (tree_expression *e, - tree_argument_list *lst, - int l, int c, char t) + tree_argument_list *lst, + int l, int c, char t) : tree_expression (l, c), expr (e), args (0), type (), arg_nm (), dyn_field () { @@ -57,8 +57,8 @@ } tree_index_expression::tree_index_expression (tree_expression *e, - const std::string& n, - int l, int c) + const std::string& n, + int l, int c) : tree_expression (l, c), expr (e), args (0), type (), arg_nm (), dyn_field () { @@ -66,8 +66,8 @@ } tree_index_expression::tree_index_expression (tree_expression *e, - tree_expression *df, - int l, int c) + tree_expression *df, + int l, int c) : tree_expression (l, c), expr (e), args (0), type (), arg_nm (), dyn_field () { @@ -126,7 +126,7 @@ tree_argument_list *elt = *p; if (elt && elt->has_magic_end ()) - return true; + return true; } return false; @@ -156,14 +156,14 @@ int n = arg_values.length (); if (n > 0) - { - arg_values.stash_name_tags (arg_nm); + { + arg_values.stash_name_tags (arg_nm); - retval.resize (dim_vector (1, n)); + retval.resize (dim_vector (1, n)); - for (int i = 0; i < n; i++) - retval(0,i) = arg_values(i); - } + for (int i = 0; i < n; i++) + retval(0,i) = arg_values(i); + } } return retval; @@ -171,7 +171,7 @@ static inline octave_value_list make_value_list (tree_argument_list *args, const string_vector& arg_nm, - const octave_value *object) + const octave_value *object) { octave_value_list retval; @@ -188,7 +188,7 @@ int n = retval.length (); if (n > 0) - retval.stash_name_tags (arg_nm); + retval.stash_name_tags (arg_nm); } return retval; @@ -206,19 +206,19 @@ tree_expression *df = *p_dyn_field; if (df) - { - octave_value t = df->rvalue1 (); + { + octave_value t = df->rvalue1 (); - if (! error_state) - { - fn = t.string_value (); + if (! error_state) + { + fn = t.string_value (); - if (! valid_identifier (fn)) - ::error ("invalid structure field name `%s'", fn.c_str ()); - } - } + if (! valid_identifier (fn)) + ::error ("invalid structure field name `%s'", fn.c_str ()); + } + } else - panic_impossible (); + panic_impossible (); } return fn; @@ -241,25 +241,25 @@ for (int i = 0; i < n; i++) { switch (type[i]) - { - case '(': - subs_field(i) = make_subs_cell (*p_args, *p_arg_nm); - break; + { + case '(': + subs_field(i) = make_subs_cell (*p_args, *p_arg_nm); + break; - case '{': - subs_field(i) = make_subs_cell (*p_args, *p_arg_nm); - break; + case '{': + subs_field(i) = make_subs_cell (*p_args, *p_arg_nm); + break; - case '.': - subs_field(i) = get_struct_index (p_arg_nm, p_dyn_field); - break; + case '.': + subs_field(i) = get_struct_index (p_arg_nm, p_dyn_field); + break; - default: - panic_impossible (); - } + default: + panic_impossible (); + } if (error_state) - return m; + return m; p_args++; p_arg_nm++; @@ -291,28 +291,28 @@ tree_identifier *id = dynamic_cast (expr); if (! (id->is_variable () || args.empty ())) - { - tree_argument_list *al = *(args.begin ()); + { + tree_argument_list *al = *(args.begin ()); - size_t n = al ? al->length () : 0; + size_t n = al ? al->length () : 0; - if (n > 0) - { - string_vector anm = *(arg_nm.begin ()); + if (n > 0) + { + string_vector anm = *(arg_nm.begin ()); have_args = true; first_args = al -> convert_to_const_vector (); first_args.stash_name_tags (anm); if (! error_state) first_expr_val = id->do_lookup (first_args); - } - } + } + } } if (! error_state) { if (first_expr_val.is_undefined ()) - first_expr_val = expr->rvalue1 (); + first_expr_val = expr->rvalue1 (); octave_value tmp = first_expr_val; octave_idx_type tmpi = 0; @@ -326,10 +326,10 @@ std::list::iterator p_dyn_field = dyn_field.begin (); for (int i = 0; i < n; i++) - { - if (i > 0) - { - tree_argument_list *al = *p_args; + { + if (i > 0) + { + tree_argument_list *al = *p_args; // In Matlab, () can only be followed by . In Octave, we do not // enforce this for rvalue expressions, but we'll split the @@ -338,67 +338,67 @@ // codes. bool force_split = type[i-1] == '(' && type[i] != '.'; - if (force_split || (al && al->has_magic_end ())) - { - // We have an expression like - // - // x{end}.a(end) - // - // and we are looking at the argument list that - // contains the second (or third, etc.) "end" token, - // so we must evaluate everything up to the point of - // that argument list so we can pass the appropriate - // value to the built-in __end__ function. + if (force_split || (al && al->has_magic_end ())) + { + // We have an expression like + // + // x{end}.a(end) + // + // and we are looking at the argument list that + // contains the second (or third, etc.) "end" token, + // so we must evaluate everything up to the point of + // that argument list so we can pass the appropriate + // value to the built-in __end__ function. - const octave_value_list tmp_list - = tmp.subsref (type.substr (tmpi, i - tmpi), idx, nargout); + const octave_value_list tmp_list + = tmp.subsref (type.substr (tmpi, i - tmpi), idx, nargout); - tmp = tmp_list.length () ? tmp_list(0) : octave_value (); + tmp = tmp_list.length () ? tmp_list(0) : octave_value (); tmpi = i; idx.clear (); if (tmp.is_cs_list ()) gripe_indexed_cs_list (); - if (error_state) - break; - } - } + if (error_state) + break; + } + } - switch (type[i]) - { - case '(': - if (have_args) - { - idx.push_back (first_args); - have_args = false; - } - else - idx.push_back (make_value_list (*p_args, *p_arg_nm, &tmp)); - break; + switch (type[i]) + { + case '(': + if (have_args) + { + idx.push_back (first_args); + have_args = false; + } + else + idx.push_back (make_value_list (*p_args, *p_arg_nm, &tmp)); + break; - case '{': - idx.push_back (make_value_list (*p_args, *p_arg_nm, &tmp)); - break; + case '{': + idx.push_back (make_value_list (*p_args, *p_arg_nm, &tmp)); + break; - case '.': - idx.push_back (octave_value (get_struct_index (p_arg_nm, p_dyn_field))); - break; + case '.': + idx.push_back (octave_value (get_struct_index (p_arg_nm, p_dyn_field))); + break; - default: - panic_impossible (); - } + default: + panic_impossible (); + } - if (error_state) - break; + if (error_state) + break; - p_args++; - p_arg_nm++; - p_dyn_field++; - } + p_args++; + p_arg_nm++; + p_dyn_field++; + } if (! error_state) - retval = tmp.subsref (type.substr (tmpi, n - tmpi), idx, nargout); + retval = tmp.subsref (type.substr (tmpi, n - tmpi), idx, nargout); } return retval; @@ -440,13 +440,13 @@ octave_value tmp; if (tro) - tmp = *tro; + tmp = *tro; octave_idx_type tmpi = 0; std::list tmpidx; for (int i = 0; i < n; i++) - { + { if (retval.numel () != 1) gripe_indexed_cs_list (); else if (tmpi < i) @@ -458,9 +458,9 @@ if (error_state) break; - switch (type[i]) - { - case '(': + switch (type[i]) + { + case '(': { octave_value_list tidx = make_value_list (*p_args, *p_arg_nm, &tmp); @@ -480,10 +480,10 @@ } break; - case '{': - { - octave_value_list tidx - = make_value_list (*p_args, *p_arg_nm, &tmp); + case '{': + { + octave_value_list tidx + = make_value_list (*p_args, *p_arg_nm, &tmp); if (tmp.is_undefined ()) { @@ -503,15 +503,15 @@ if (error_state) break; - idx.push_back (tidx); + idx.push_back (tidx); tmpidx.push_back (tidx); tmpi = i; - } - break; + } + break; - case '.': - { - octave_value tidx = get_struct_index (p_arg_nm, p_dyn_field); + case '.': + { + octave_value tidx = get_struct_index (p_arg_nm, p_dyn_field); if (error_state) break; @@ -558,26 +558,26 @@ break; idx.push_back (tidx); - } - break; + } + break; - default: - panic_impossible (); - } + default: + panic_impossible (); + } if (idx.back ().empty ()) error ("invalid empty index list"); - if (error_state) - break; + if (error_state) + break; - p_args++; - p_arg_nm++; - p_dyn_field++; - } + p_args++; + p_arg_nm++; + p_dyn_field++; + } if (! error_state) - retval.set_index (type, idx); + retval.set_index (type, idx); } @@ -611,7 +611,7 @@ tree_index_expression * tree_index_expression::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { tree_index_expression *new_idx_expr = new tree_index_expression (line (), column ()); diff --git a/src/pt-jump.cc b/src/pt-jump.cc --- a/src/pt-jump.cc +++ b/src/pt-jump.cc @@ -40,7 +40,7 @@ tree_command * tree_break_command::dup (symbol_table::scope_id, - symbol_table::context_id) const + symbol_table::context_id) const { return new tree_break_command (line (), column ()); } @@ -58,7 +58,7 @@ tree_command * tree_continue_command::dup (symbol_table::scope_id, - symbol_table::context_id) const + symbol_table::context_id) const { return new tree_continue_command (line (), column ()); } @@ -76,7 +76,7 @@ tree_command * tree_return_command::dup (symbol_table::scope_id, - symbol_table::context_id) const + symbol_table::context_id) const { return new tree_return_command (line (), column ()); } diff --git a/src/pt-loop.cc b/src/pt-loop.cc --- a/src/pt-loop.cc +++ b/src/pt-loop.cc @@ -54,13 +54,13 @@ tree_command * tree_while_command::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { return new tree_while_command (expr ? expr->dup (scope, context) : 0, - list ? list->dup (scope, context) : 0, - lead_comm ? lead_comm->dup () : 0, - trail_comm ? trail_comm->dup (): 0, - line (), column ()); + list ? list->dup (scope, context) : 0, + lead_comm ? lead_comm->dup () : 0, + trail_comm ? trail_comm->dup (): 0, + line (), column ()); } void @@ -73,13 +73,13 @@ tree_command * tree_do_until_command::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { return new tree_do_until_command (expr ? expr->dup (scope, context) : 0, - list ? list->dup (scope, context) : 0, - lead_comm ? lead_comm->dup () : 0, - trail_comm ? trail_comm->dup (): 0, - line (), column ()); + list ? list->dup (scope, context) : 0, + lead_comm ? lead_comm->dup () : 0, + trail_comm ? trail_comm->dup (): 0, + line (), column ()); } void @@ -100,14 +100,14 @@ tree_command * tree_simple_for_command::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { return new tree_simple_for_command (lhs ? lhs->dup (scope, context) : 0, - expr ? expr->dup (scope, context) : 0, - list ? list->dup (scope, context) : 0, - lead_comm ? lead_comm->dup () : 0, - trail_comm ? trail_comm->dup () : 0, - line (), column ()); + expr ? expr->dup (scope, context) : 0, + list ? list->dup (scope, context) : 0, + lead_comm ? lead_comm->dup () : 0, + trail_comm ? trail_comm->dup () : 0, + line (), column ()); } void @@ -126,14 +126,14 @@ tree_command * tree_complex_for_command::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { return new tree_complex_for_command (lhs ? lhs->dup (scope, context) : 0, - expr ? expr->dup (scope, context) : 0, - list ? list->dup (scope, context) : 0, - lead_comm ? lead_comm->dup () : 0, - trail_comm ? trail_comm->dup () : 0, - line (), column ()); + expr ? expr->dup (scope, context) : 0, + list ? list->dup (scope, context) : 0, + lead_comm ? lead_comm->dup () : 0, + trail_comm ? trail_comm->dup () : 0, + line (), column ()); } void diff --git a/src/pt-mat.cc b/src/pt-mat.cc --- a/src/pt-mat.cc +++ b/src/pt-mat.cc @@ -67,17 +67,17 @@ tm_row_const_rep (void) : count (1), dv (0, 0), all_str (false), - all_sq_str (false), all_dq_str (false), - some_str (false), all_real (false), all_cmplx (false), - all_mt (true), any_sparse (false), any_class (false), - class_nm (), ok (false) + all_sq_str (false), all_dq_str (false), + some_str (false), all_real (false), all_cmplx (false), + all_mt (true), any_sparse (false), any_class (false), + class_nm (), ok (false) { } tm_row_const_rep (const tree_argument_list& row) : count (1), dv (0, 0), all_str (false), all_sq_str (false), - some_str (false), all_real (false), all_cmplx (false), - all_mt (true), any_sparse (false), any_class (false), - class_nm (), ok (false) + some_str (false), all_real (false), all_cmplx (false), + all_mt (true), any_sparse (false), any_class (false), + class_nm (), ok (false) { init (row); } ~tm_row_const_rep (void) { } @@ -111,7 +111,7 @@ tm_row_const_rep& operator = (const tm_row_const_rep&); void eval_error (const char *msg, int l, int c, - int x = -1, int y = -1) const; + int x = -1, int y = -1) const; void eval_warning (const char *msg, int l, int c) const; }; @@ -138,13 +138,13 @@ { if (this != &x && rep != x.rep) { - if (rep && --rep->count == 0) - delete rep; + if (rep && --rep->count == 0) + delete rep; - rep = x.rep; + rep = x.rep; - if (rep) - rep->count++; + if (rep) + rep->count++; } return *this; @@ -204,13 +204,13 @@ else { bool c1_is_int = (c1 == "int8" || c1 == "uint8" - || c1 == "int16" || c1 == "uint16" - || c1 == "int32" || c1 == "uint32" - || c1 == "int64" || c1 == "uint64"); + || c1 == "int16" || c1 == "uint16" + || c1 == "int32" || c1 == "uint32" + || c1 == "int64" || c1 == "uint64"); bool c2_is_int = (c2 == "int8" || c2 == "uint8" - || c2 == "int16" || c2 == "uint16" - || c2 == "int32" || c2 == "uint32" - || c2 == "int64" || c2 == "uint64"); + || c2 == "int16" || c2 == "uint16" + || c2 == "int32" || c2 == "uint32" + || c2 == "int64" || c2 == "uint64"); bool c1_is_char = (c1 == "char"); bool c2_is_char = (c2 == "char"); @@ -225,33 +225,33 @@ bool c2_is_logical = (c2 == "logical"); bool c1_is_built_in_type - = (c1_is_int || c1_is_char || c1_is_double || c1_is_single - || c1_is_logical); + = (c1_is_int || c1_is_char || c1_is_double || c1_is_single + || c1_is_logical); bool c2_is_built_in_type - = (c2_is_int || c2_is_char || c2_is_double || c2_is_single - || c2_is_logical); + = (c2_is_int || c2_is_char || c2_is_double || c2_is_single + || c2_is_logical); // Order is important here... if (c1_is_char && c2_is_built_in_type) - retval = c1; + retval = c1; else if (c2_is_char && c1_is_built_in_type) - retval = c2; + retval = c2; else if (c1_is_int && c2_is_built_in_type) - retval = c1; + retval = c1; else if (c2_is_int && c1_is_built_in_type) - retval = c2; + retval = c2; else if (c1_is_single && c2_is_built_in_type) - retval = c1; + retval = c1; else if (c2_is_single && c1_is_built_in_type) - retval = c2; + retval = c2; else if (c1_is_double && c2_is_built_in_type) - retval = c1; + retval = c1; else if (c2_is_double && c1_is_built_in_type) - retval = c2; + retval = c2; else if (c1_is_logical && c2_is_logical) - retval = c1; + retval = c1; } return retval; @@ -259,8 +259,8 @@ bool tm_row_const::tm_row_const_rep::do_init_element (tree_expression *elt, - const octave_value& val, - bool& first_elem) + const octave_value& val, + bool& first_elem) { octave_idx_type this_elt_nr = val.rows (); octave_idx_type this_elt_nc = val.columns (); @@ -277,59 +277,59 @@ all_mt = false; if (first_elem) - { - first_elem = false; + { + first_elem = false; - dv.resize (this_elt_dv.length ()); - for (int i = 2; i < dv.length (); i++) - dv.elem (i) = this_elt_dv.elem (i); + dv.resize (this_elt_dv.length ()); + for (int i = 2; i < dv.length (); i++) + dv.elem (i) = this_elt_dv.elem (i); - dv.elem (0) = this_elt_nr; + dv.elem (0) = this_elt_nr; - dv.elem (1) = 0; - } + dv.elem (1) = 0; + } else - { - int len = (this_elt_dv.length () < dv.length () - ? this_elt_dv.length () : dv.length ()); + { + int len = (this_elt_dv.length () < dv.length () + ? this_elt_dv.length () : dv.length ()); - if (this_elt_nr != dv (0)) - { - eval_error ("number of rows must match", - elt->line (), elt->column (), this_elt_nr, dv (0)); - return false; - } - for (int i = 2; i < len; i++) - { - if (this_elt_dv (i) != dv (i)) - { - eval_error ("dimensions mismatch", elt->line (), elt->column (), this_elt_dv (i), dv (i)); - return false; - } - } + if (this_elt_nr != dv (0)) + { + eval_error ("number of rows must match", + elt->line (), elt->column (), this_elt_nr, dv (0)); + return false; + } + for (int i = 2; i < len; i++) + { + if (this_elt_dv (i) != dv (i)) + { + eval_error ("dimensions mismatch", elt->line (), elt->column (), this_elt_dv (i), dv (i)); + return false; + } + } - if (this_elt_dv.length () > len) - for (int i = len; i < this_elt_dv.length (); i++) - if (this_elt_dv (i) != 1) - { - eval_error ("dimensions mismatch", elt->line (), elt->column (), this_elt_dv (i), 1); - return false; - } + if (this_elt_dv.length () > len) + for (int i = len; i < this_elt_dv.length (); i++) + if (this_elt_dv (i) != 1) + { + eval_error ("dimensions mismatch", elt->line (), elt->column (), this_elt_dv (i), 1); + return false; + } - if (dv.length () > len) - for (int i = len; i < dv.length (); i++) - if (dv (i) != 1) - { - eval_error ("dimensions mismatch", elt->line (), elt->column (), 1, dv (i)); - return false; - } - } + if (dv.length () > len) + for (int i = len; i < dv.length (); i++) + if (dv (i) != 1) + { + eval_error ("dimensions mismatch", elt->line (), elt->column (), 1, dv (i)); + return false; + } + } dv.elem (1) = dv.elem (1) + this_elt_nc; } else eval_warning ("empty matrix found in matrix list", - elt->line (), elt->column ()); + elt->line (), elt->column ()); append (val); @@ -384,27 +384,27 @@ octave_value tmp = elt->rvalue1 (); if (error_state || tmp.is_undefined ()) - break; + break; else - { - if (tmp.is_cs_list ()) - { - octave_value_list tlst = tmp.list_value (); + { + if (tmp.is_cs_list ()) + { + octave_value_list tlst = tmp.list_value (); - for (octave_idx_type i = 0; i < tlst.length (); i++) - { - octave_quit (); + for (octave_idx_type i = 0; i < tlst.length (); i++) + { + octave_quit (); - if (! do_init_element (elt, tlst(i), first_elem)) - goto done; - } - } - else - { - if (! do_init_element (elt, tmp, first_elem)) - goto done; - } - } + if (! do_init_element (elt, tlst(i), first_elem)) + goto done; + } + } + else + { + if (! do_init_element (elt, tmp, first_elem)) + goto done; + } + } } done: @@ -414,33 +414,33 @@ void tm_row_const::tm_row_const_rep::eval_error (const char *msg, int l, - int c, int x, int y) const + int c, int x, int y) const { if (l == -1 && c == -1) { if (x == -1 || y == -1) - ::error ("%s", msg); + ::error ("%s", msg); else - ::error ("%s (%d != %d)", msg, x, y); + ::error ("%s (%d != %d)", msg, x, y); } else { if (x == -1 || y == -1) - ::error ("%s near line %d, column %d", msg, l, c); + ::error ("%s near line %d, column %d", msg, l, c); else - ::error ("%s (%d != %d) near line %d, column %d", msg, x, y, l, c); + ::error ("%s (%d != %d) near line %d, column %d", msg, x, y, l, c); } } void tm_row_const::tm_row_const_rep::eval_warning (const char *msg, int l, - int c) const + int c) const { if (l == -1 && c == -1) warning_with_id ("Octave:empty-list-elements", "%s", msg); else warning_with_id ("Octave:empty-list-elements", - "%s near line %d, column %d", msg, l, c); + "%s near line %d, column %d", msg, l, c); } class @@ -530,132 +530,132 @@ tm_row_const tmp (*elt); if (tmp && ! tmp.empty ()) - { - if (all_str && ! tmp.all_strings_p ()) - all_str = false; + { + if (all_str && ! tmp.all_strings_p ()) + all_str = false; - if (all_sq_str && ! tmp.all_sq_strings_p ()) - all_sq_str = false; + if (all_sq_str && ! tmp.all_sq_strings_p ()) + all_sq_str = false; - if (all_dq_str && ! tmp.all_dq_strings_p ()) - all_dq_str = false; + if (all_dq_str && ! tmp.all_dq_strings_p ()) + all_dq_str = false; - if (! some_str && tmp.some_strings_p ()) - some_str = true; + if (! some_str && tmp.some_strings_p ()) + some_str = true; - if (all_real && ! tmp.all_real_p ()) - all_real = false; + if (all_real && ! tmp.all_real_p ()) + all_real = false; - if (all_cmplx && ! tmp.all_complex_p ()) - all_cmplx = false; + if (all_cmplx && ! tmp.all_complex_p ()) + all_cmplx = false; - if (all_mt && ! tmp.all_empty_p ()) - all_mt = false; + if (all_mt && ! tmp.all_empty_p ()) + all_mt = false; - if (!any_sparse && tmp.any_sparse_p ()) - any_sparse = true; + if (!any_sparse && tmp.any_sparse_p ()) + any_sparse = true; - if (!any_class && tmp.any_class_p ()) - any_class = true; + if (!any_class && tmp.any_class_p ()) + any_class = true; - append (tmp); - } + append (tmp); + } else - break; + break; } if (! error_state) { for (iterator p = begin (); p != end (); p++) - { - octave_quit (); + { + octave_quit (); - tm_row_const elt = *p; + tm_row_const elt = *p; - octave_idx_type this_elt_nr = elt.rows (); - octave_idx_type this_elt_nc = elt.cols (); + octave_idx_type this_elt_nr = elt.rows (); + octave_idx_type this_elt_nc = elt.cols (); - std::string this_elt_class_nm = elt.class_name (); + std::string this_elt_class_nm = elt.class_name (); - dim_vector this_elt_dv = elt.dims (); + dim_vector this_elt_dv = elt.dims (); - if (!this_elt_dv.all_zero ()) - { - all_mt = false; + if (!this_elt_dv.all_zero ()) + { + all_mt = false; - if (first_elem) - { - first_elem = false; + if (first_elem) + { + first_elem = false; - class_nm = this_elt_class_nm; + class_nm = this_elt_class_nm; - dv.resize (this_elt_dv.length ()); - for (int i = 2; i < dv.length (); i++) - dv.elem (i) = this_elt_dv.elem (i); + dv.resize (this_elt_dv.length ()); + for (int i = 2; i < dv.length (); i++) + dv.elem (i) = this_elt_dv.elem (i); - dv.elem (0) = 0; + dv.elem (0) = 0; - dv.elem (1) = this_elt_nc; - } - else if (all_str) - { - class_nm = get_concat_class (class_nm, this_elt_class_nm); + dv.elem (1) = this_elt_nc; + } + else if (all_str) + { + class_nm = get_concat_class (class_nm, this_elt_class_nm); - if (this_elt_nc > cols ()) - dv.elem (1) = this_elt_nc; - } - else - { - class_nm = get_concat_class (class_nm, this_elt_class_nm); + if (this_elt_nc > cols ()) + dv.elem (1) = this_elt_nc; + } + else + { + class_nm = get_concat_class (class_nm, this_elt_class_nm); - bool get_out = false; - int len = (this_elt_dv.length () < dv.length () - ? this_elt_dv.length () : dv.length ()); + bool get_out = false; + int len = (this_elt_dv.length () < dv.length () + ? this_elt_dv.length () : dv.length ()); - for (int i = 1; i < len; i++) - { - if (i == 1 && this_elt_nc != dv (1)) - { - ::error ("number of columns must match (%d != %d)", - this_elt_nc, dv (1)); - get_out = true; - break; - } - else if (this_elt_dv (i) != dv (i)) - { - ::error ("dimensions mismatch (dim = %i, %d != %d)", i+1, this_elt_dv (i), dv (i)); - get_out = true; - break; - } - } + for (int i = 1; i < len; i++) + { + if (i == 1 && this_elt_nc != dv (1)) + { + ::error ("number of columns must match (%d != %d)", + this_elt_nc, dv (1)); + get_out = true; + break; + } + else if (this_elt_dv (i) != dv (i)) + { + ::error ("dimensions mismatch (dim = %i, %d != %d)", i+1, this_elt_dv (i), dv (i)); + get_out = true; + break; + } + } - if (this_elt_dv.length () > len) - for (int i = len; i < this_elt_dv.length (); i++) - if (this_elt_dv (i) != 1) - { - ::error ("dimensions mismatch (dim = %i, %d != %d)", i+1, this_elt_dv (i), 1); - get_out = true; - break; - } + if (this_elt_dv.length () > len) + for (int i = len; i < this_elt_dv.length (); i++) + if (this_elt_dv (i) != 1) + { + ::error ("dimensions mismatch (dim = %i, %d != %d)", i+1, this_elt_dv (i), 1); + get_out = true; + break; + } - if (dv.length () > len) - for (int i = len; i < dv.length (); i++) - if (dv (i) != 1) - { - ::error ("dimensions mismatch (dim = %i, %d != %d)", i+1, 1, dv(i)); - get_out = true; - break; - } + if (dv.length () > len) + for (int i = len; i < dv.length (); i++) + if (dv (i) != 1) + { + ::error ("dimensions mismatch (dim = %i, %d != %d)", i+1, 1, dv(i)); + get_out = true; + break; + } - if (get_out) - break; - } - dv.elem (0) = dv.elem (0) + this_elt_nr; - } - else - warning_with_id ("Octave:empty-list-elements", - "empty matrix found in matrix list"); - } + if (get_out) + break; + } + dv.elem (0) = dv.elem (0) + this_elt_nr; + } + else + warning_with_id ("Octave:empty-list-elements", + "empty matrix found in matrix list"); + } } ok = ! error_state; @@ -681,7 +681,7 @@ tree_argument_list *elt = *p; if (elt && elt->has_magic_end ()) - return true; + return true; } return false; @@ -697,7 +697,7 @@ tree_argument_list *elt = *p; if (! elt->all_elements_are_constant ()) - return false; + return false; } return true; @@ -721,7 +721,7 @@ { if (! (all_dq_strings_p || all_sq_strings_p)) warning_with_id ("Octave:string-concat", - "concatenation of different character string types may have unintended consequences"); + "concatenation of different character string types may have unintended consequences"); } template @@ -820,228 +820,228 @@ std::string result_type = tmp.class_name (); if (any_class_p) - { - octave_value_list tmp3 (tmp.length (), octave_value ()); + { + octave_value_list tmp3 (tmp.length (), octave_value ()); - int j = 0; - for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) - { - octave_quit (); + int j = 0; + for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) + { + octave_quit (); - tm_row_const row = *p; + tm_row_const row = *p; - if (row.length () == 1) - tmp3 (j++) = *(row.begin ()); - else - { - octave_value_list tmp1 (row.length (), octave_value ()); + if (row.length () == 1) + tmp3 (j++) = *(row.begin ()); + else + { + octave_value_list tmp1 (row.length (), octave_value ()); - int i = 0; - for (tm_row_const::iterator q = row.begin (); - q != row.end (); q++) - tmp1 (i++) = *q; + int i = 0; + for (tm_row_const::iterator q = row.begin (); + q != row.end (); q++) + tmp1 (i++) = *q; - octave_value_list tmp2; - octave_value fcn = - symbol_table::find_function ("horzcat", tmp1); + octave_value_list tmp2; + octave_value fcn = + symbol_table::find_function ("horzcat", tmp1); - if (fcn.is_defined ()) - { - tmp2 = fcn.do_multi_index_op (1, tmp1); - - if (error_state) - goto done; + if (fcn.is_defined ()) + { + tmp2 = fcn.do_multi_index_op (1, tmp1); + + if (error_state) + goto done; - tmp3 (j++) = tmp2 (0); - } - else - { - ::error ("cat not find overloaded horzcat function"); - goto done; - } - } - } + tmp3 (j++) = tmp2 (0); + } + else + { + ::error ("cat not find overloaded horzcat function"); + goto done; + } + } + } - if (tmp.length () == 1) - retval = tmp3 (0); - else - { - octave_value_list tmp2; - octave_value fcn = symbol_table::find_function ("vertcat", tmp3); + if (tmp.length () == 1) + retval = tmp3 (0); + else + { + octave_value_list tmp2; + octave_value fcn = symbol_table::find_function ("vertcat", tmp3); - if (fcn.is_defined ()) - { - tmp2 = fcn.do_multi_index_op (1, tmp3); - - if (! error_state) - retval = tmp2 (0); - } - else - ::error ("cat not find overloaded vertcat function"); - } - } + if (fcn.is_defined ()) + { + tmp2 = fcn.do_multi_index_op (1, tmp3); + + if (! error_state) + retval = tmp2 (0); + } + else + ::error ("cat not find overloaded vertcat function"); + } + } else if (result_type == "double") - { - if (any_sparse_p) - { - if (all_real_p) - retval = do_single_type_concat (dv, tmp); - else + { + if (any_sparse_p) + { + if (all_real_p) + retval = do_single_type_concat (dv, tmp); + else retval = do_single_type_concat_no_mutate (dv, tmp); - } - else - { - if (all_real_p) - retval = do_single_type_concat (dv, tmp); - else + } + else + { + if (all_real_p) + retval = do_single_type_concat (dv, tmp); + else retval = do_single_type_concat_no_mutate (dv, tmp); - } - } + } + } else if (result_type == "single") - { - if (all_real_p) - retval = do_single_type_concat (dv, tmp); - else + { + if (all_real_p) + retval = do_single_type_concat (dv, tmp); + else retval = do_single_type_concat_no_mutate (dv, tmp); - } + } else if (result_type == "char") - { - char type = all_dq_strings_p ? '"' : '\''; + { + char type = all_dq_strings_p ? '"' : '\''; - maybe_warn_string_concat (all_dq_strings_p, all_sq_strings_p); + maybe_warn_string_concat (all_dq_strings_p, all_sq_strings_p); - charNDArray result (dv, Vstring_fill_char); + charNDArray result (dv, Vstring_fill_char); single_type_concat (result, tmp); - retval = octave_value (result, type); - } + retval = octave_value (result, type); + } else if (result_type == "logical") - { - if (any_sparse_p) - retval = do_single_type_concat (dv, tmp); - else - retval = do_single_type_concat (dv, tmp); - } + { + if (any_sparse_p) + retval = do_single_type_concat (dv, tmp); + else + retval = do_single_type_concat (dv, tmp); + } else if (result_type == "int8") - retval = do_single_type_concat (dv, tmp); + retval = do_single_type_concat (dv, tmp); else if (result_type == "int16") - retval = do_single_type_concat (dv, tmp); + retval = do_single_type_concat (dv, tmp); else if (result_type == "int32") - retval = do_single_type_concat (dv, tmp); + retval = do_single_type_concat (dv, tmp); else if (result_type == "int64") - retval = do_single_type_concat (dv, tmp); + retval = do_single_type_concat (dv, tmp); else if (result_type == "uint8") - retval = do_single_type_concat (dv, tmp); + retval = do_single_type_concat (dv, tmp); else if (result_type == "uint16") - retval = do_single_type_concat (dv, tmp); + retval = do_single_type_concat (dv, tmp); else if (result_type == "uint32") - retval = do_single_type_concat (dv, tmp); + retval = do_single_type_concat (dv, tmp); else if (result_type == "uint64") - retval = do_single_type_concat (dv, tmp); + retval = do_single_type_concat (dv, tmp); else - { - // The line below might seem crazy, since we take a copy of - // the first argument, resize it to be empty and then resize - // it to be full. This is done since it means that there is - // no recopying of data, as would happen if we used a single - // resize. It should be noted that resize operation is also - // significantly slower than the do_cat_op function, so it - // makes sense to have an empty matrix and copy all data. - // - // We might also start with a empty octave_value using - // - // ctmp = octave_value_typeinfo::lookup_type - // (tmp.begin() -> begin() -> type_name()); - // - // and then directly resize. However, for some types there - // might be some additional setup needed, and so this should - // be avoided. + { + // The line below might seem crazy, since we take a copy of + // the first argument, resize it to be empty and then resize + // it to be full. This is done since it means that there is + // no recopying of data, as would happen if we used a single + // resize. It should be noted that resize operation is also + // significantly slower than the do_cat_op function, so it + // makes sense to have an empty matrix and copy all data. + // + // We might also start with a empty octave_value using + // + // ctmp = octave_value_typeinfo::lookup_type + // (tmp.begin() -> begin() -> type_name()); + // + // and then directly resize. However, for some types there + // might be some additional setup needed, and so this should + // be avoided. - octave_value ctmp; + octave_value ctmp; - // Find the first non-empty object + // Find the first non-empty object - if (any_sparse_p) - { - // Start with sparse matrix to avoid issues memory issues - // with things like [ones(1,4),sprandn(1e8,4,1e-4)] - if (all_real_p) - ctmp = octave_sparse_matrix ().resize (dv); - else - ctmp = octave_sparse_complex_matrix ().resize (dv); - } - else - { - for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) - { - octave_quit (); + if (any_sparse_p) + { + // Start with sparse matrix to avoid issues memory issues + // with things like [ones(1,4),sprandn(1e8,4,1e-4)] + if (all_real_p) + ctmp = octave_sparse_matrix ().resize (dv); + else + ctmp = octave_sparse_complex_matrix ().resize (dv); + } + else + { + for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) + { + octave_quit (); - tm_row_const row = *p; + tm_row_const row = *p; - for (tm_row_const::iterator q = row.begin (); - q != row.end (); q++) - { - octave_quit (); + for (tm_row_const::iterator q = row.begin (); + q != row.end (); q++) + { + octave_quit (); - ctmp = *q; + ctmp = *q; - if (! ctmp.all_zero_dims ()) - goto found_non_empty; - } - } + if (! ctmp.all_zero_dims ()) + goto found_non_empty; + } + } - ctmp = (*(tmp.begin() -> begin())); + ctmp = (*(tmp.begin() -> begin())); - found_non_empty: + found_non_empty: - if (! all_empty_p) - ctmp = ctmp.resize (dim_vector (0,0)).resize (dv); - } + if (! all_empty_p) + ctmp = ctmp.resize (dim_vector (0,0)).resize (dv); + } - if (! error_state) - { - // Now, extract the values from the individual elements and - // insert them in the result matrix. + if (! error_state) + { + // Now, extract the values from the individual elements and + // insert them in the result matrix. - int dv_len = dv.length (); - Array ra_idx (dv_len > 1 ? dv_len : 2, 0); + int dv_len = dv.length (); + Array ra_idx (dv_len > 1 ? dv_len : 2, 0); - for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) - { - octave_quit (); + for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) + { + octave_quit (); - tm_row_const row = *p; + tm_row_const row = *p; - for (tm_row_const::iterator q = row.begin (); - q != row.end (); - q++) - { - octave_quit (); + for (tm_row_const::iterator q = row.begin (); + q != row.end (); + q++) + { + octave_quit (); - octave_value elt = *q; + octave_value elt = *q; - ctmp = do_cat_op (ctmp, elt, ra_idx); + ctmp = do_cat_op (ctmp, elt, ra_idx); - if (error_state) - goto done; + if (error_state) + goto done; - ra_idx (1) += elt.columns (); - } + ra_idx (1) += elt.columns (); + } - ra_idx (0) += row.rows (); - ra_idx (1) = 0; - } + ra_idx (0) += row.rows (); + ra_idx (1) = 0; + } - retval = ctmp; + retval = ctmp; - if (frc_str_conv && ! retval.is_string ()) - retval = retval.convert_to_str (); - } - } + if (frc_str_conv && ! retval.is_string ()) + retval = retval.convert_to_str (); + } + } } done: @@ -1050,7 +1050,7 @@ tree_expression * tree_matrix::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { tree_matrix *new_matrix = new tree_matrix (0, line (), column ()); diff --git a/src/pt-misc.cc b/src/pt-misc.cc --- a/src/pt-misc.cc +++ b/src/pt-misc.cc @@ -73,8 +73,8 @@ tree_identifier *id = elt->ident (); if (id) - { - std::string name = id->name (); + { + std::string name = id->name (); if (id->is_black_hole ()) { @@ -82,15 +82,15 @@ error ("invalid use of ~ in output list"); } else if (dict.find (name) != dict.end ()) - { - retval = false; - error ("`%s' appears more than once in parameter list", - name.c_str ()); - break; - } - else - dict.insert (name); - } + { + retval = false; + error ("`%s' appears more than once in parameter list", + name.c_str ()); + break; + } + else + dict.insert (name); + } } if (! error_state) @@ -100,24 +100,24 @@ size_t len = length (); if (len > 0) - { - tree_decl_elt *elt = back (); + { + tree_decl_elt *elt = back (); - tree_identifier *id = elt->ident (); + tree_identifier *id = elt->ident (); - if (id && id->name () == va_type) - { - if (len == 1) - mark_varargs_only (); - else - mark_varargs (); + if (id && id->name () == va_type) + { + if (len == 1) + mark_varargs_only (); + else + mark_varargs (); - iterator p = end (); - --p; - delete *p; - erase (p); - } - } + iterator p = end (); + --p; + delete *p; + erase (p); + } + } } return retval; @@ -125,8 +125,8 @@ void tree_parameter_list::initialize_undefined_elements (const std::string& warnfor, - int nargout, - const octave_value& val) + int nargout, + const octave_value& val) { bool warned = false; @@ -135,26 +135,26 @@ for (iterator p = begin (); p != end (); p++) { if (++count > nargout) - break; + break; tree_decl_elt *elt = *p; if (! elt->is_variable ()) - { - if (! warned) - { - warned = true; + { + if (! warned) + { + warned = true; - warning_with_id - ("Octave:undefined-return-values", - "%s: some elements in list of return values are undefined", - warnfor.c_str ()); - } + warning_with_id + ("Octave:undefined-return-values", + "%s: some elements in list of return values are undefined", + warnfor.c_str ()); + } - octave_lvalue tmp = elt->lvalue (); + octave_lvalue tmp = elt->lvalue (); - tmp.assign (octave_value::op_asn_eq, val); - } + tmp.assign (octave_value::op_asn_eq, val); + } } } @@ -174,20 +174,20 @@ octave_lvalue ref = elt->lvalue (); if (i < nargin) - { - if (args(i).is_defined () && args(i).is_magic_colon ()) - { - if (! elt->eval ()) - { - ::error ("no default value for argument %d\n", i+1); - return; - } - } - else - ref.define (args(i)); - } + { + if (args(i).is_defined () && args(i).is_magic_colon ()) + { + if (! elt->eval ()) + { + ::error ("no default value for argument %d\n", i+1); + return; + } + } + else + ref.define (args(i)); + } else - elt->eval (); + elt->eval (); } } @@ -264,10 +264,10 @@ tree_decl_elt *elt = *p; if (! elt->is_variable ()) - { - status = false; - break; - } + { + status = false; + break; + } } return status; @@ -275,7 +275,7 @@ tree_parameter_list * tree_parameter_list::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { tree_parameter_list *new_list = new tree_parameter_list (); @@ -312,7 +312,7 @@ tree_return_list * tree_return_list::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { tree_return_list *new_list = new tree_return_list (); diff --git a/src/pt-pr-code.cc b/src/pt-pr-code.cc --- a/src/pt-pr-code.cc +++ b/src/pt-pr-code.cc @@ -69,12 +69,12 @@ tree_expression *elt = *p++; if (elt) - { - elt->accept (*this); + { + elt->accept (*this); - if (p != lst.end ()) - os << ", "; - } + if (p != lst.end ()) + os << ", "; + } } } @@ -202,12 +202,12 @@ tree_decl_elt *elt = *p++; if (elt) - { - elt->accept (*this); + { + elt->accept (*this); - if (p != lst.end ()) - os << ", "; - } + if (p != lst.end ()) + os << ", "; + } } } @@ -351,26 +351,26 @@ int len = ret_list->length (); if (len > 1 || takes_var_return) - { - os << "["; - nesting.push ('['); - } + { + os << "["; + nesting.push ('['); + } ret_list->accept (*this); if (takes_var_return) - { - if (len > 0) - os << ", "; + { + if (len > 0) + os << ", "; - os << "varargout"; - } + os << "varargout"; + } if (len > 1 || takes_var_return) - { - nesting.pop (); - os << "]"; - } + { + nesting.pop (); + os << "]"; + } os << " = "; } @@ -388,27 +388,27 @@ int len = param_list->length (); if (len > 0 || takes_varargs) - { - os << "("; - nesting.push ('('); - } + { + os << "("; + nesting.push ('('); + } param_list->accept (*this); if (takes_varargs) - { - if (len > 0) - os << ", "; + { + if (len > 0) + os << ", "; - os << "varargin"; - } + os << "varargin"; + } if (len > 0 || takes_varargs) - { - nesting.pop (); - os << ")"; - newline (); - } + { + nesting.pop (); + os << ")"; + newline (); + } } else { @@ -510,21 +510,21 @@ tree_if_clause *elt = *p++; if (elt) - { - if (! first_elt) - { - print_indented_comment (elt->leading_comment ()); + { + if (! first_elt) + { + print_indented_comment (elt->leading_comment ()); - indent (); + indent (); - if (elt->is_else_clause ()) - os << "else"; - else - os << "elseif "; - } + if (elt->is_else_clause ()) + os << "else"; + else + os << "elseif "; + } - elt->accept (*this); - } + elt->accept (*this); + } first_elt = false; } @@ -560,56 +560,56 @@ for (int i = 0; i < n; i++) { switch (type_tags[i]) - { - case '(': - { - char nc = nesting.top (); - if ((nc == '[' || nc == '{') && expr.paren_count () == 0) - os << "("; - else - os << " ("; - nesting.push ('('); + { + case '(': + { + char nc = nesting.top (); + if ((nc == '[' || nc == '{') && expr.paren_count () == 0) + os << "("; + else + os << " ("; + nesting.push ('('); - tree_argument_list *l = *p_arg_lists; - if (l) - l->accept (*this); + tree_argument_list *l = *p_arg_lists; + if (l) + l->accept (*this); - nesting.pop (); - os << ")"; - } - break; - - case '{': - { - char nc = nesting.top (); - if ((nc == '[' || nc == '{') && expr.paren_count () == 0) - os << "{"; - else - os << " {"; - // We only care about whitespace inside [] and {} when we - // are defining matrix and cell objects, not when indexing. - nesting.push ('('); + nesting.pop (); + os << ")"; + } + break; + + case '{': + { + char nc = nesting.top (); + if ((nc == '[' || nc == '{') && expr.paren_count () == 0) + os << "{"; + else + os << " {"; + // We only care about whitespace inside [] and {} when we + // are defining matrix and cell objects, not when indexing. + nesting.push ('('); - tree_argument_list *l = *p_arg_lists; - if (l) - l->accept (*this); + tree_argument_list *l = *p_arg_lists; + if (l) + l->accept (*this); - nesting.pop (); - os << "}"; - } - break; - - case '.': - { - string_vector nm = *p_arg_names; - assert (nm.length () == 1); - os << "." << nm(0); - } - break; + nesting.pop (); + os << "}"; + } + break; + + case '.': + { + string_vector nm = *p_arg_names; + assert (nm.length () == 1); + os << "." << nm(0); + } + break; - default: - panic_impossible (); - } + default: + panic_impossible (); + } p_arg_lists++; p_arg_names++; @@ -635,12 +635,12 @@ tree_argument_list *elt = *p++; if (elt) - { - elt->accept (*this); + { + elt->accept (*this); - if (p != lst.end ()) - os << "; "; - } + if (p != lst.end ()) + os << "; "; + } } nesting.pop (); @@ -666,12 +666,12 @@ tree_argument_list *elt = *p++; if (elt) - { - elt->accept (*this); + { + elt->accept (*this); - if (p != lst.end ()) - os << "; "; - } + if (p != lst.end ()) + os << "; "; + } } nesting.pop (); @@ -694,18 +694,18 @@ int len = lhs->length (); if (len > 1) - { - os << "["; - nesting.push ('['); - } + { + os << "["; + nesting.push ('['); + } lhs->accept (*this); if (len > 1) - { - nesting.pop (); - os << "]"; - } + { + nesting.pop (); + os << "]"; + } } os << " " << expr.oper () << " "; @@ -760,12 +760,12 @@ tree_decl_elt *elt = *p++; if (elt) - { - elt->accept (*this); + { + elt->accept (*this); - if (p != lst.end ()) - os << ", "; - } + if (p != lst.end ()) + os << ", "; + } } } @@ -821,12 +821,12 @@ tree_index_expression *elt = *p++; if (elt) - { - elt->accept (*this); + { + elt->accept (*this); - if (p != lst.end ()) - os << ", "; - } + if (p != lst.end ()) + os << ", "; + } } } @@ -864,29 +864,29 @@ cmd->accept (*this); if (! stmt.print_result ()) - { - os << ";"; - newline (" "); - } + { + os << ";"; + newline (" "); + } else - newline (); + newline (); } else { tree_expression *expr = stmt.expression (); if (expr) - { - expr->accept (*this); + { + expr->accept (*this); - if (! stmt.print_result ()) - { - os << ";"; - newline (" "); - } - else - newline (); - } + if (! stmt.print_result ()) + { + os << ";"; + newline (" "); + } + else + newline (); + } } } @@ -898,7 +898,7 @@ tree_statement *elt = *p; if (elt) - elt->accept (*this); + elt->accept (*this); } } @@ -945,7 +945,7 @@ tree_switch_case *elt = *p++; if (elt) - elt->accept (*this); + elt->accept (*this); } } @@ -1163,14 +1163,14 @@ if (printing_newlines) { if (beginning_of_line) - { - os << prefix; + { + os << prefix; - for (int i = 0; i < curr_print_indent_level; i++) - os << " "; + for (int i = 0; i < curr_print_indent_level; i++) + os << " "; - beginning_of_line = false; - } + beginning_of_line = false; + } } } @@ -1226,32 +1226,32 @@ char c = comment[i++]; if (c == '\n') - { - if (prev_char_was_newline) - os << "##"; + { + if (prev_char_was_newline) + os << "##"; - newline (); + newline (); - prev_char_was_newline = true; - } + prev_char_was_newline = true; + } else - { - if (beginning_of_line) - { - printed_something = true; + { + if (beginning_of_line) + { + printed_something = true; - indent (); + indent (); - os << "##"; + os << "##"; - if (! (isspace (c) || c == '!')) - os << " "; - } + if (! (isspace (c) || c == '!')) + os << " "; + } - os << static_cast (c); + os << static_cast (c); - prev_char_was_newline = false; - } + prev_char_was_newline = false; + } } if (printed_something && ! beginning_of_line) @@ -1266,14 +1266,14 @@ octave_comment_list::iterator p = comment_list->begin (); while (p != comment_list->end ()) - { - octave_comment_elt elt = *p++; + { + octave_comment_elt elt = *p++; - print_comment_elt (elt); + print_comment_elt (elt); - if (p != comment_list->end ()) - newline (); - } + if (p != comment_list->end ()) + newline (); + } } } diff --git a/src/pt-select.cc b/src/pt-select.cc --- a/src/pt-select.cc +++ b/src/pt-select.cc @@ -47,11 +47,11 @@ tree_if_clause * tree_if_clause::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { return new tree_if_clause (expr ? expr->dup (scope, context) : 0, - list ? list->dup (scope, context) : 0, - lead_comm ? lead_comm->dup () : 0); + list ? list->dup (scope, context) : 0, + lead_comm ? lead_comm->dup () : 0); } void @@ -64,7 +64,7 @@ tree_if_command_list * tree_if_command_list::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { tree_if_command_list *new_icl = new tree_if_command_list (); @@ -101,7 +101,7 @@ tree_if_clause *elt = list->front (); if (elt) - elt->set_breakpoint (); + elt->set_breakpoint (); } } @@ -113,18 +113,18 @@ tree_if_clause *elt = list->front (); if (elt) - elt->set_breakpoint (); + elt->set_breakpoint (); } } tree_command * tree_if_command::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { return new tree_if_command (list ? list->dup (scope, context) : 0, - lead_comm ? lead_comm->dup () : 0, - trail_comm ? trail_comm->dup () : 0, - line (), column ()); + lead_comm ? lead_comm->dup () : 0, + trail_comm ? trail_comm->dup () : 0, + line (), column ()); } void @@ -151,31 +151,31 @@ if (! error_state && label_value.is_defined() ) { if (label_value.is_cell ()) - { - Cell cell (label_value.cell_value ()); + { + Cell cell (label_value.cell_value ()); - for (octave_idx_type i = 0; i < cell.rows (); i++) - { - for (octave_idx_type j = 0; j < cell.columns (); j++) - { - bool match = val.is_equal (cell(i,j)); + for (octave_idx_type i = 0; i < cell.rows (); i++) + { + for (octave_idx_type j = 0; j < cell.columns (); j++) + { + bool match = val.is_equal (cell(i,j)); - if (error_state) - return false; - else if (match) - return true; - } - } - } + if (error_state) + return false; + else if (match) + return true; + } + } + } else - { - bool match = val.is_equal (label_value); + { + bool match = val.is_equal (label_value); - if (error_state) - return false; - else - return match; - } + if (error_state) + return false; + else + return match; + } } return false; @@ -183,11 +183,11 @@ tree_switch_case * tree_switch_case::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { return new tree_switch_case (label ? label->dup (scope, context) : 0, - list ? list->dup (scope, context) : 0, - lead_comm ? lead_comm->dup () : 0); + list ? list->dup (scope, context) : 0, + lead_comm ? lead_comm->dup () : 0); } void @@ -200,7 +200,7 @@ tree_switch_case_list * tree_switch_case_list::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { tree_switch_case_list *new_scl = new tree_switch_case_list (); @@ -238,7 +238,7 @@ tree_switch_case *elt = list->front (); if (elt) - elt->set_breakpoint (); + elt->set_breakpoint (); } } @@ -250,19 +250,19 @@ tree_switch_case *elt = list->front (); if (elt) - elt->set_breakpoint (); + elt->set_breakpoint (); } } tree_command * tree_switch_command::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { return new tree_switch_command (expr ? expr->dup (scope, context) : 0, - list ? list->dup (scope, context) : 0, - lead_comm ? lead_comm->dup () : 0, - trail_comm ? trail_comm->dup () : 0, - line (), column ()); + list ? list->dup (scope, context) : 0, + lead_comm ? lead_comm->dup () : 0, + trail_comm ? trail_comm->dup () : 0, + line (), column ()); } void diff --git a/src/pt-stmt.cc b/src/pt-stmt.cc --- a/src/pt-stmt.cc +++ b/src/pt-stmt.cc @@ -122,10 +122,10 @@ if (cmd) { tree_no_op_command *no_op_cmd - = dynamic_cast (cmd); + = dynamic_cast (cmd); if (no_op_cmd) - retval = no_op_cmd->is_end_of_fcn_or_script (); + retval = no_op_cmd->is_end_of_fcn_or_script (); } return retval; @@ -133,7 +133,7 @@ tree_statement * tree_statement::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { tree_statement *new_stmt = new tree_statement (); @@ -171,10 +171,10 @@ int len = bp_lst.length (); for (int i = 0; i < len; i++) - { - tree_breakpoint tbp (i, tree_breakpoint::clear); - accept (tbp); - } + { + tree_breakpoint tbp (i, tree_breakpoint::clear); + accept (tbp); + } } else { @@ -194,7 +194,7 @@ tree_statement_list * tree_statement_list::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { tree_statement_list *new_list = new tree_statement_list (); diff --git a/src/pt-unop.cc b/src/pt-unop.cc --- a/src/pt-unop.cc +++ b/src/pt-unop.cc @@ -50,7 +50,7 @@ if (nargout > 1) error ("prefix operator `%s': invalid number of output arguments", - oper () . c_str ()); + oper () . c_str ()); else retval = rvalue1 (nargout); @@ -68,27 +68,27 @@ if (op) { if (etype == octave_value::op_incr || etype == octave_value::op_decr) - { - op->rvalue1 (); + { + op->rvalue1 (); - if (! error_state) - { - octave_lvalue ref = op->lvalue (); + if (! error_state) + { + octave_lvalue ref = op->lvalue (); - if (! error_state && ref.is_defined ()) - { - ref.do_unary_op (etype); + if (! error_state && ref.is_defined ()) + { + ref.do_unary_op (etype); - retval = ref.value (); - } - } - } + retval = ref.value (); + } + } + } else - { - octave_value val = op->rvalue1 (); + { + octave_value val = op->rvalue1 (); - if (! error_state && val.is_defined ()) - { + if (! error_state && val.is_defined ()) + { // Attempt to do the operation in-place if it is unshared // (a temporary expression). if (val.get_count () == 1) @@ -96,10 +96,10 @@ else retval = ::do_unary_op (etype, val); - if (error_state) - retval = octave_value (); - } - } + if (error_state) + retval = octave_value (); + } + } } return retval; @@ -107,11 +107,11 @@ tree_expression * tree_prefix_expression::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { tree_prefix_expression *new_pe = new tree_prefix_expression (op ? op->dup (scope, context) : 0, - line (), column (), etype); + line (), column (), etype); new_pe->copy_base (*this); @@ -133,7 +133,7 @@ if (nargout > 1) error ("postfix operator `%s': invalid number of output arguments", - oper () . c_str ()); + oper () . c_str ()); else retval = rvalue1 (nargout); @@ -151,33 +151,33 @@ if (op) { if (etype == octave_value::op_incr || etype == octave_value::op_decr) - { - op->rvalue1 (); + { + op->rvalue1 (); - if (! error_state) - { - octave_lvalue ref = op->lvalue (); + if (! error_state) + { + octave_lvalue ref = op->lvalue (); - if (! error_state && ref.is_defined ()) - { - retval = ref.value (); + if (! error_state && ref.is_defined ()) + { + retval = ref.value (); - ref.do_unary_op (etype); - } - } - } + ref.do_unary_op (etype); + } + } + } else - { - octave_value val = op->rvalue1 (); + { + octave_value val = op->rvalue1 (); - if (! error_state && val.is_defined ()) - { - retval = ::do_unary_op (etype, val); + if (! error_state && val.is_defined ()) + { + retval = ::do_unary_op (etype, val); - if (error_state) - retval = octave_value (); - } - } + if (error_state) + retval = octave_value (); + } + } } return retval; @@ -185,11 +185,11 @@ tree_expression * tree_postfix_expression::dup (symbol_table::scope_id scope, - symbol_table::context_id context) const + symbol_table::context_id context) const { tree_postfix_expression *new_pe = new tree_postfix_expression (op ? op->dup (scope, context) : 0, - line (), column (), etype); + line (), column (), etype); new_pe->copy_base (*this); diff --git a/src/sighandlers.cc b/src/sighandlers.cc --- a/src/sighandlers.cc +++ b/src/sighandlers.cc @@ -95,34 +95,34 @@ for (int i = 0; i < NSIG; i++) { if (octave_signals_caught[i]) - { - octave_signals_caught[i] = false; + { + octave_signals_caught[i] = false; - switch (i) - { + switch (i) + { #ifdef SIGCHLD - case SIGCHLD: - octave_child_list::reap (); - break; + case SIGCHLD: + octave_child_list::reap (); + break; #endif - case SIGFPE: - std::cerr << "warning: floating point exception -- trying to return to prompt" << std::endl; - break; + case SIGFPE: + std::cerr << "warning: floating point exception -- trying to return to prompt" << std::endl; + break; #ifdef SIGPIPE - case SIGPIPE: - std::cerr << "warning: broken pipe -- some output may be lost" << std::endl; - break; + case SIGPIPE: + std::cerr << "warning: broken pipe -- some output may be lost" << std::endl; + break; #endif - } - } + } + } } } static void my_friendly_exit (const char *sig_name, int sig_number, - bool save_vars = true) + bool save_vars = true) { static bool been_there_done_that = false; @@ -145,33 +145,33 @@ std::cerr << "panic: " << sig_name << " -- stopping myself...\n"; if (save_vars) - dump_octave_core (); + dump_octave_core (); if (sig_number < 0) - { - MINGW_SIGNAL_CLEANUP (); + { + MINGW_SIGNAL_CLEANUP (); - exit (1); - } + exit (1); + } else - { - octave_set_signal_handler (sig_number, SIG_DFL); + { + octave_set_signal_handler (sig_number, SIG_DFL); #if defined (HAVE_RAISE) - raise (sig_number); + raise (sig_number); #elif defined (HAVE_KILL) - kill (getpid (), sig_number); + kill (getpid (), sig_number); #else - exit (1); + exit (1); #endif - } + } } } sig_handler * octave_set_signal_handler (int sig, sig_handler *handler, - bool restart_syscalls) + bool restart_syscalls) { struct sigaction act, oact; @@ -277,8 +277,8 @@ #if defined (SIGHUP) case SIGHUP: { - if (Vsighup_dumps_octave_core) - dump_octave_core (); + if (Vsighup_dumps_octave_core) + dump_octave_core (); } break; #endif @@ -286,8 +286,8 @@ #if defined (SIGTERM) case SIGTERM: { - if (Vsigterm_dumps_octave_core) - dump_octave_core (); + if (Vsigterm_dumps_octave_core) + dump_octave_core (); } break; #endif @@ -327,49 +327,49 @@ if (can_interrupt) { if (Vdebug_on_interrupt) - { - if (! octave_debug_on_interrupt_state) - { - tree_evaluator::debug_mode = true; - octave_debug_on_interrupt_state = true; + { + if (! octave_debug_on_interrupt_state) + { + tree_evaluator::debug_mode = true; + octave_debug_on_interrupt_state = true; - return; - } - else - { - // Clear the flag and do normal interrupt stuff. + return; + } + else + { + // Clear the flag and do normal interrupt stuff. - tree_evaluator::debug_mode + tree_evaluator::debug_mode = bp_table::have_breakpoints () || Vdebugging; - octave_debug_on_interrupt_state = false; - } - } + octave_debug_on_interrupt_state = false; + } + } if (octave_interrupt_immediately) - { - if (octave_interrupt_state == 0) - octave_interrupt_state = 1; + { + if (octave_interrupt_state == 0) + octave_interrupt_state = 1; - octave_jump_to_enclosing_context (); - } + octave_jump_to_enclosing_context (); + } else - { - // If we are already cleaning up from a previous interrupt, - // take note of the fact that another interrupt signal has - // arrived. + { + // If we are already cleaning up from a previous interrupt, + // take note of the fact that another interrupt signal has + // arrived. - if (octave_interrupt_state < 0) - octave_interrupt_state = 0; + if (octave_interrupt_state < 0) + octave_interrupt_state = 0; - octave_signal_caught = 1; - octave_interrupt_state++; + octave_signal_caught = 1; + octave_interrupt_state++; - if (interactive && octave_interrupt_state == 2) - std::cerr << "Press Control-C again to abort." << std::endl; + if (interactive && octave_interrupt_state == 2) + std::cerr << "Press Control-C again to abort." << std::endl; - if (octave_interrupt_state >= 3) - my_friendly_exit (sig_name, sig_number, true); - } + if (octave_interrupt_state >= 3) + my_friendly_exit (sig_name, sig_number, true); + } } } @@ -415,30 +415,30 @@ switch(sig) { case CTRL_BREAK_EVENT: - sig_name = "Ctrl-Break"; - break; + sig_name = "Ctrl-Break"; + break; case CTRL_C_EVENT: - sig_name = "Ctrl-C"; - break; + sig_name = "Ctrl-C"; + break; case CTRL_CLOSE_EVENT: - sig_name = "close console"; - break; + sig_name = "close console"; + break; case CTRL_LOGOFF_EVENT: - sig_name = "logoff"; - break; + sig_name = "logoff"; + break; case CTRL_SHUTDOWN_EVENT: - sig_name = "shutdown"; - break; + sig_name = "shutdown"; + break; default: - sig_name = "unknown console event"; - break; + sig_name = "unknown console event"; + break; } switch(sig) { case CTRL_BREAK_EVENT: case CTRL_C_EVENT: - w32_raise (SIGINT); + w32_raise (SIGINT); break; case CTRL_CLOSE_EVENT: @@ -448,7 +448,7 @@ // We should do the following: // clean_up_and_exit (0); // We can't because we aren't running in the normal Octave thread. - user_abort(sig_name, sig); + user_abort(sig_name, sig); break; } @@ -510,18 +510,18 @@ octave_interrupt_handler octave_set_interrupt_handler (const volatile octave_interrupt_handler& h, - bool restart_syscalls) + bool restart_syscalls) { octave_interrupt_handler retval; #ifdef SIGINT retval.int_handler = octave_set_signal_handler (SIGINT, h.int_handler, - restart_syscalls); + restart_syscalls); #endif #ifdef SIGBREAK retval.brk_handler = octave_set_signal_handler (SIGBREAK, h.brk_handler, - restart_syscalls); + restart_syscalls); #endif return retval; @@ -888,14 +888,14 @@ octave_child& oc = *p; if (oc.have_status) - { - oc.have_status = 0; + { + oc.have_status = 0; - octave_child::child_event_handler f = oc.handler; + octave_child::child_event_handler f = oc.handler; - if (f && f (oc.pid, oc.status)) - oc.pid = -1; - } + if (f && f (oc.pid, oc.status)) + oc.pid = -1; + } } remove_if (pid_equal (-1)); @@ -915,20 +915,20 @@ pid_t pid = oc.pid; if (pid > 0) - { - int status; + { + int status; - if (octave_syscalls::waitpid (pid, &status, WNOHANG) > 0) - { - oc.have_status = 1; + if (octave_syscalls::waitpid (pid, &status, WNOHANG) > 0) + { + oc.have_status = 1; - oc.status = status; + oc.status = status; - retval = true; + retval = true; - break; - } - } + break; + } + } } return retval; diff --git a/src/sparse-xdiv.cc b/src/sparse-xdiv.cc --- a/src/sparse-xdiv.cc +++ b/src/sparse-xdiv.cc @@ -144,7 +144,7 @@ octave_idx_type info; double rcond = 0.0; Matrix result = btmp.solve (btyp, atmp, info, rcond, - solve_singularity_warning); + solve_singularity_warning); typ = btyp.transpose (); return result.transpose (); @@ -224,7 +224,7 @@ octave_idx_type info; double rcond = 0.0; SparseMatrix result = btmp.solve (btyp, atmp, info, rcond, - solve_singularity_warning); + solve_singularity_warning); typ = btyp.transpose (); return result.transpose (); @@ -318,12 +318,12 @@ const octave_idx_type colend = a.cidx (j+1); r.xcidx (j) = k_result; if (s != zero) - for (octave_idx_type k = a.cidx (j); k < colend; ++k) - { - r.xdata (k_result) = a.data (k) / s; - r.xridx (k_result) = a.ridx (k); - ++k_result; - } + for (octave_idx_type k = a.cidx (j); k < colend; ++k) + { + r.xdata (k_result) = a.data (k) / s; + r.xridx (k_result) = a.ridx (k); + ++k_result; + } } r.xcidx (nc) = k_result; @@ -386,8 +386,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = b.cidx(j); i < b.cidx(j+1); i++) { - octave_quit (); - result.elem (b.ridx(i), j) = a / b.data (i); + octave_quit (); + result.elem (b.ridx(i), j) = a / b.data (i); } return result; @@ -404,8 +404,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = b.cidx(j); i < b.cidx(j+1); i++) { - octave_quit (); - result.elem (b.ridx(i), j) = a / b.data (i); + octave_quit (); + result.elem (b.ridx(i), j) = a / b.data (i); } return result; @@ -422,8 +422,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = b.cidx(j); i < b.cidx(j+1); i++) { - octave_quit (); - result.elem (b.ridx(i), j) = a / b.data (i); + octave_quit (); + result.elem (b.ridx(i), j) = a / b.data (i); } return result; @@ -440,8 +440,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = b.cidx(j); i < b.cidx(j+1); i++) { - octave_quit (); - result.elem (b.ridx(i), j) = a / b.data (i); + octave_quit (); + result.elem (b.ridx(i), j) = a / b.data (i); } return result; @@ -547,7 +547,7 @@ // -*- 8 -*- SparseComplexMatrix xleftdiv (const SparseComplexMatrix& a, const SparseComplexMatrix& b, - MatrixType &typ) + MatrixType &typ) { if (! mx_leftdiv_conform (a, b)) return SparseComplexMatrix (); @@ -584,19 +584,19 @@ const octave_idx_type colend = a.cidx (j+1); r.xcidx (j) = k_result; for (octave_idx_type k = a.cidx (j); k < colend; ++k) - { - const octave_idx_type i = a.ridx (k); - if (i < nr) - { - const DM_elt_type s = d.dgelem (i); - if (s != zero) - { - r.xdata (k_result) = a.data (k) / s; - r.xridx (k_result) = i; - ++k_result; - } - } - } + { + const octave_idx_type i = a.ridx (k); + if (i < nr) + { + const DM_elt_type s = d.dgelem (i); + if (s != zero) + { + r.xdata (k_result) = a.data (k) / s; + r.xridx (k_result) = i; + ++k_result; + } + } + } } r.xcidx (a_nc) = k_result; diff --git a/src/sparse-xpow.cc b/src/sparse-xpow.cc --- a/src/sparse-xpow.cc +++ b/src/sparse-xpow.cc @@ -46,8 +46,8 @@ xisint (double x) { return (D_NINT (x) == x - && ((x >= 0 && x < INT_MAX) - || (x <= 0 && x > INT_MIN))); + && ((x >= 0 && x < INT_MAX) + || (x <= 0 && x > INT_MIN))); } @@ -67,61 +67,61 @@ else { if (static_cast (b) == b) - { - int btmp = static_cast (b); - if (btmp == 0) - { - SparseMatrix tmp = SparseMatrix (nr, nr, nr); - for (octave_idx_type i = 0; i < nr; i++) - { - tmp.data (i) = 1.0; - tmp.ridx (i) = i; - } - for (octave_idx_type i = 0; i < nr + 1; i++) - tmp.cidx (i) = i; + { + int btmp = static_cast (b); + if (btmp == 0) + { + SparseMatrix tmp = SparseMatrix (nr, nr, nr); + for (octave_idx_type i = 0; i < nr; i++) + { + tmp.data (i) = 1.0; + tmp.ridx (i) = i; + } + for (octave_idx_type i = 0; i < nr + 1; i++) + tmp.cidx (i) = i; - retval = tmp; - } - else - { - SparseMatrix atmp; - if (btmp < 0) - { - btmp = -btmp; + retval = tmp; + } + else + { + SparseMatrix atmp; + if (btmp < 0) + { + btmp = -btmp; - octave_idx_type info; - double rcond = 0.0; - MatrixType mattyp (a); + octave_idx_type info; + double rcond = 0.0; + MatrixType mattyp (a); - atmp = a.inverse (mattyp, info, rcond, 1); + atmp = a.inverse (mattyp, info, rcond, 1); - if (info == -1) - warning ("inverse: matrix singular to machine\ + if (info == -1) + warning ("inverse: matrix singular to machine\ precision, rcond = %g", rcond); - } - else - atmp = a; + } + else + atmp = a; - SparseMatrix result (atmp); + SparseMatrix result (atmp); - btmp--; + btmp--; - while (btmp > 0) - { - if (btmp & 1) - result = result * atmp; + while (btmp > 0) + { + if (btmp & 1) + result = result * atmp; - btmp >>= 1; + btmp >>= 1; - if (btmp > 0) - atmp = atmp * atmp; - } + if (btmp > 0) + atmp = atmp * atmp; + } - retval = result; - } - } + retval = result; + } + } else - error ("use full(a) ^ full(b)"); + error ("use full(a) ^ full(b)"); } return retval; @@ -140,61 +140,61 @@ else { if (static_cast (b) == b) - { - int btmp = static_cast (b); - if (btmp == 0) - { - SparseMatrix tmp = SparseMatrix (nr, nr, nr); - for (octave_idx_type i = 0; i < nr; i++) - { - tmp.data (i) = 1.0; - tmp.ridx (i) = i; - } - for (octave_idx_type i = 0; i < nr + 1; i++) - tmp.cidx (i) = i; + { + int btmp = static_cast (b); + if (btmp == 0) + { + SparseMatrix tmp = SparseMatrix (nr, nr, nr); + for (octave_idx_type i = 0; i < nr; i++) + { + tmp.data (i) = 1.0; + tmp.ridx (i) = i; + } + for (octave_idx_type i = 0; i < nr + 1; i++) + tmp.cidx (i) = i; - retval = tmp; - } - else - { - SparseComplexMatrix atmp; - if (btmp < 0) - { - btmp = -btmp; + retval = tmp; + } + else + { + SparseComplexMatrix atmp; + if (btmp < 0) + { + btmp = -btmp; - octave_idx_type info; - double rcond = 0.0; - MatrixType mattyp (a); + octave_idx_type info; + double rcond = 0.0; + MatrixType mattyp (a); - atmp = a.inverse (mattyp, info, rcond, 1); + atmp = a.inverse (mattyp, info, rcond, 1); - if (info == -1) - warning ("inverse: matrix singular to machine\ + if (info == -1) + warning ("inverse: matrix singular to machine\ precision, rcond = %g", rcond); - } - else - atmp = a; + } + else + atmp = a; - SparseComplexMatrix result (atmp); + SparseComplexMatrix result (atmp); - btmp--; + btmp--; - while (btmp > 0) - { - if (btmp & 1) - result = result * atmp; + while (btmp > 0) + { + if (btmp & 1) + result = result * atmp; - btmp >>= 1; + btmp >>= 1; - if (btmp > 0) - atmp = atmp * atmp; - } + if (btmp > 0) + atmp = atmp * atmp; + } - retval = result; - } - } + retval = result; + } + } else - error ("use full(a) ^ full(b)"); + error ("use full(a) ^ full(b)"); } return retval; @@ -246,13 +246,13 @@ ComplexMatrix result (nr, nc); for (octave_idx_type j = 0; j < nc; j++) - { - for (octave_idx_type i = 0; i < nr; i++) - { - octave_quit (); - result (i, j) = std::pow (atmp, b(i,j)); - } - } + { + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); + result (i, j) = std::pow (atmp, b(i,j)); + } + } retval = result; } @@ -261,13 +261,13 @@ Matrix result (nr, nc); for (octave_idx_type j = 0; j < nc; j++) - { - for (octave_idx_type i = 0; i < nr; i++) - { - octave_quit (); - result (i, j) = std::pow (a, b(i,j)); - } - } + { + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); + result (i, j) = std::pow (a, b(i,j)); + } + } retval = result; } @@ -288,10 +288,10 @@ for (octave_idx_type j = 0; j < nc; j++) { for (octave_idx_type i = 0; i < nr; i++) - { - octave_quit (); - result (i, j) = std::pow (atmp, b(i,j)); - } + { + octave_quit (); + result (i, j) = std::pow (atmp, b(i,j)); + } } return result; @@ -315,55 +315,55 @@ octave_idx_type nc = a.cols (); if (static_cast (b) != b && a.any_element_is_negative ()) - { - ComplexMatrix result (nr, nc, Complex (std::pow (0.0, b))); + { + ComplexMatrix result (nr, nc, Complex (std::pow (0.0, b))); - // FIXME -- avoid apparent GNU libm bug by - // converting A and B to complex instead of just A. - Complex btmp (b); + // FIXME -- avoid apparent GNU libm bug by + // converting A and B to complex instead of just A. + Complex btmp (b); - for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++) - { - octave_quit (); - - Complex atmp (a.data (i)); - - result (a.ridx(i), j) = std::pow (atmp, btmp); - } + for (octave_idx_type j = 0; j < nc; j++) + for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++) + { + octave_quit (); + + Complex atmp (a.data (i)); + + result (a.ridx(i), j) = std::pow (atmp, btmp); + } - retval = octave_value (result); - } + retval = octave_value (result); + } else - { - Matrix result (nr, nc, (std::pow (0.0, b))); + { + Matrix result (nr, nc, (std::pow (0.0, b))); - for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++) - { - octave_quit (); - result (a.ridx(i), j) = std::pow (a.data (i), b); - } + for (octave_idx_type j = 0; j < nc; j++) + for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++) + { + octave_quit (); + result (a.ridx(i), j) = std::pow (a.data (i), b); + } - retval = octave_value (result); - } + retval = octave_value (result); + } } else if (static_cast (b) != b && a.any_element_is_negative ()) { SparseComplexMatrix result (a); for (octave_idx_type i = 0; i < nz; i++) - { - octave_quit (); + { + octave_quit (); - // FIXME -- avoid apparent GNU libm bug by - // converting A and B to complex instead of just A. + // FIXME -- avoid apparent GNU libm bug by + // converting A and B to complex instead of just A. - Complex atmp (a.data (i)); - Complex btmp (b); + Complex atmp (a.data (i)); + Complex btmp (b); - result.data (i) = std::pow (atmp, btmp); - } + result.data (i) = std::pow (atmp, btmp); + } result.maybe_compress (true); @@ -374,10 +374,10 @@ SparseMatrix result (a); for (octave_idx_type i = 0; i < nz; i++) - { - octave_quit (); - result.data (i) = std::pow (a.data (i), b); - } + { + octave_quit (); + result.data (i) = std::pow (a.data (i), b); + } result.maybe_compress (true); @@ -409,15 +409,15 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++) { - if (a.data(i) < 0.0) - { - double btmp = b (a.ridx(i), j); - if (static_cast (btmp) != btmp) - { - convert_to_complex = 1; - goto done; - } - } + if (a.data(i) < 0.0) + { + double btmp = b (a.ridx(i), j); + if (static_cast (btmp) != btmp) + { + convert_to_complex = 1; + goto done; + } + } } done: @@ -432,14 +432,14 @@ SparseComplexMatrix complex_result (nr, nc, Complex(1.0, 0.0)); for (octave_idx_type j = 0; j < nc; j++) - { - for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++) - { - octave_quit (); - complex_result.xelem(a.ridx(i), j) = - std::pow (Complex(a.data(i)), Complex(b(a.ridx(i), j))); - } - } + { + for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++) + { + octave_quit (); + complex_result.xelem(a.ridx(i), j) = + std::pow (Complex(a.data(i)), Complex(b(a.ridx(i), j))); + } + } complex_result.maybe_compress (true); retval = complex_result; } @@ -448,14 +448,14 @@ SparseMatrix result (nr, nc, 1.0); for (octave_idx_type j = 0; j < nc; j++) - { - for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++) - { - octave_quit (); - result.xelem(a.ridx(i), j) = std::pow (a.data(i), - b (a.ridx(i), j)); - } - } + { + for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++) + { + octave_quit (); + result.xelem(a.ridx(i), j) = std::pow (a.data(i), + b (a.ridx(i), j)); + } + } result.maybe_compress (true); retval = result; } @@ -478,10 +478,10 @@ SparseComplexMatrix result (a); for (octave_idx_type i = 0; i < nz; i++) - { - octave_quit (); - result.data (i) = std::pow (Complex (a.data (i)), b); - } + { + octave_quit (); + result.data (i) = std::pow (Complex (a.data (i)), b); + } result.maybe_compress (true); @@ -511,10 +511,10 @@ for (octave_idx_type j = 0; j < nc; j++) { for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++) - { - octave_quit (); - result.xelem(a.ridx(i), j) = std::pow (a.data(i), b (a.ridx(i), j)); - } + { + octave_quit (); + result.xelem(a.ridx(i), j) = std::pow (a.data(i), b (a.ridx(i), j)); + } } result.maybe_compress (true); @@ -534,14 +534,14 @@ for (octave_idx_type j = 0; j < nc; j++) { for (octave_idx_type i = 0; i < nr; i++) - { - octave_quit (); - double btmp = b (i, j); - if (xisint (btmp)) - result (i, j) = std::pow (a, static_cast (btmp)); - else - result (i, j) = std::pow (a, btmp); - } + { + octave_quit (); + double btmp = b (i, j); + if (xisint (btmp)) + result (i, j) = std::pow (a, static_cast (btmp)); + else + result (i, j) = std::pow (a, btmp); + } } return result; @@ -558,8 +558,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - result (i, j) = std::pow (a, b (i, j)); + octave_quit (); + result (i, j) = std::pow (a, b (i, j)); } return result; @@ -579,24 +579,24 @@ ComplexMatrix result (nr, nc, Complex (std::pow (0.0, b))); if (xisint (b)) - { - for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++) - { - octave_quit (); - result (a.ridx(i), j) = - std::pow (a.data (i), static_cast (b)); - } - } + { + for (octave_idx_type j = 0; j < nc; j++) + for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++) + { + octave_quit (); + result (a.ridx(i), j) = + std::pow (a.data (i), static_cast (b)); + } + } else - { - for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++) - { - octave_quit (); - result (a.ridx(i), j) = std::pow (a.data (i), b); - } - } + { + for (octave_idx_type j = 0; j < nc; j++) + for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++) + { + octave_quit (); + result (a.ridx(i), j) = std::pow (a.data (i), b); + } + } retval = result; } @@ -607,21 +607,21 @@ SparseComplexMatrix result (a); if (xisint (b)) - { - for (octave_idx_type i = 0; i < nz; i++) - { - octave_quit (); - result.data (i) = std::pow (a.data (i), static_cast (b)); - } - } + { + for (octave_idx_type i = 0; i < nz; i++) + { + octave_quit (); + result.data (i) = std::pow (a.data (i), static_cast (b)); + } + } else - { - for (octave_idx_type i = 0; i < nz; i++) - { - octave_quit (); - result.data (i) = std::pow (a.data (i), b); - } - } + { + for (octave_idx_type i = 0; i < nz; i++) + { + octave_quit (); + result.data (i) = std::pow (a.data (i), b); + } + } result.maybe_compress (true); @@ -651,17 +651,17 @@ for (octave_idx_type j = 0; j < nc; j++) { for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++) - { - octave_quit (); - double btmp = b (a.ridx(i), j); - Complex tmp; + { + octave_quit (); + double btmp = b (a.ridx(i), j); + Complex tmp; - if (xisint (btmp)) - result.xelem(a.ridx(i), j) = std::pow (a.data (i), - static_cast (btmp)); - else - result.xelem(a.ridx(i), j) = std::pow (a.data (i), btmp); - } + if (xisint (btmp)) + result.xelem(a.ridx(i), j) = std::pow (a.data (i), + static_cast (btmp)); + else + result.xelem(a.ridx(i), j) = std::pow (a.data (i), btmp); + } } result.maybe_compress (true); @@ -686,10 +686,10 @@ SparseComplexMatrix result (a); for (octave_idx_type i = 0; i < nz; i++) - { - octave_quit (); - result.data (i) = std::pow (a.data (i), b); - } + { + octave_quit (); + result.data (i) = std::pow (a.data (i), b); + } result.maybe_compress (true); @@ -719,10 +719,10 @@ for (octave_idx_type j = 0; j < nc; j++) { for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++) - { - octave_quit (); - result.xelem(a.ridx(i), j) = std::pow (a.data (i), b (a.ridx(i), j)); - } + { + octave_quit (); + result.xelem(a.ridx(i), j) = std::pow (a.data (i), b (a.ridx(i), j)); + } } result.maybe_compress (true); diff --git a/src/strfns.cc b/src/strfns.cc --- a/src/strfns.cc +++ b/src/strfns.cc @@ -82,7 +82,7 @@ if (nargin == 1) retval = args(0).convert_to_str (true, true, - args(0).is_dq_string () ? '"' : '\''); + args(0).is_dq_string () ? '"' : '\''); else if (nargin > 1) { int n_elts = 0; @@ -92,55 +92,55 @@ std::queue args_as_strings; for (int i = 0; i < nargin; i++) - { - string_vector s = args(i).all_strings (); + { + string_vector s = args(i).all_strings (); - if (error_state) - { - error ("char: unable to convert some args to strings"); - return retval; - } + if (error_state) + { + error ("char: unable to convert some args to strings"); + return retval; + } - if (s.length () > 0) + if (s.length () > 0) n_elts += s.length (); else n_elts += 1; - int s_max_len = s.max_length (); + int s_max_len = s.max_length (); - if (s_max_len > max_len) - max_len = s_max_len; + if (s_max_len > max_len) + max_len = s_max_len; - args_as_strings.push (s); - } + args_as_strings.push (s); + } string_vector result (n_elts); int k = 0; for (int i = 0; i < nargin; i++) - { - string_vector s = args_as_strings.front (); - args_as_strings.pop (); + { + string_vector s = args_as_strings.front (); + args_as_strings.pop (); - int n = s.length (); + int n = s.length (); if (n > 0) { - for (int j = 0; j < n; j++) - { - std::string t = s[j]; - int t_len = t.length (); + for (int j = 0; j < n; j++) + { + std::string t = s[j]; + int t_len = t.length (); - if (max_len > t_len) - t += std::string (max_len - t_len, ' '); + if (max_len > t_len) + t += std::string (max_len - t_len, ' '); - result[k++] = t; - } + result[k++] = t; + } } else - result[k++] = std::string (max_len, ' '); - } + result[k++] = std::string (max_len, ' '); + } retval = octave_value (result, '\''); } @@ -211,14 +211,14 @@ std::queue args_as_strings; for (int i = 0; i < nargin; i++) - { - string_vector s = args(i).all_strings (); + { + string_vector s = args(i).all_strings (); - if (error_state) - { - error ("strvcat: unable to convert some args to strings"); - return retval; - } + if (error_state) + { + error ("strvcat: unable to convert some args to strings"); + return retval; + } size_t n = s.length (); @@ -232,30 +232,30 @@ } } - size_t s_max_len = s.max_length (); + size_t s_max_len = s.max_length (); - if (s_max_len > max_len) - max_len = s_max_len; + if (s_max_len > max_len) + max_len = s_max_len; - args_as_strings.push (s); - } + args_as_strings.push (s); + } string_vector result (n_elts); octave_idx_type k = 0; for (int i = 0; i < nargin; i++) - { - string_vector s = args_as_strings.front (); - args_as_strings.pop (); + { + string_vector s = args_as_strings.front (); + args_as_strings.pop (); - size_t n = s.length (); + size_t n = s.length (); if (n > 0) { - for (size_t j = 0; j < n; j++) - { - std::string t = s[j]; + for (size_t j = 0; j < n; j++) + { + std::string t = s[j]; if (t.length () > 0) { size_t t_len = t.length (); @@ -265,9 +265,9 @@ result[k++] = t; } - } + } } - } + } retval = octave_value (result, '\''); } @@ -874,26 +874,26 @@ string_vector s = args(0).all_strings (); if (! error_state) - { - std::ostringstream buf; + { + std::ostringstream buf; - if (nargin == 1) - // Let list_in_columns query terminal width. - s.list_in_columns (buf); - else - { - int width = args(1).int_value (); + if (nargin == 1) + // Let list_in_columns query terminal width. + s.list_in_columns (buf); + else + { + int width = args(1).int_value (); - if (! error_state) - s.list_in_columns (buf, width); - else - error ("list_in_columns: expecting width to be an integer"); - } + if (! error_state) + s.list_in_columns (buf, width); + else + error ("list_in_columns: expecting width to be an integer"); + } - retval = buf.str (); - } + retval = buf.str (); + } else - error ("list_in_columns: expecting cellstr or char array"); + error ("list_in_columns: expecting cellstr or char array"); } else print_usage (); diff --git a/src/symtab.cc b/src/symtab.cc --- a/src/symtab.cc +++ b/src/symtab.cc @@ -81,14 +81,14 @@ if (val.is_defined ()) { os << " [" - << (is_local () ? "l" : "") - << (is_automatic () ? "a" : "") - << (is_formal () ? "f" : "") - << (is_hidden () ? "h" : "") - << (is_inherited () ? "i" : "") - << (is_global () ? "g" : "") - << (is_persistent () ? "p" : "") - << "] "; + << (is_local () ? "l" : "") + << (is_automatic () ? "a" : "") + << (is_formal () ? "f" : "") + << (is_hidden () ? "h" : "") + << (is_inherited () ? "i" : "") + << (is_global () ? "g" : "") + << (is_persistent () ? "p" : "") + << "] "; val.dump (os); } @@ -139,8 +139,8 @@ static inline bool load_out_of_date_fcn (const std::string& ff, const std::string& dir_name, - octave_value& function, - const std::string& dispatch_type = std::string ()) + octave_value& function, + const std::string& dispatch_type = std::string ()) { bool retval = false; @@ -172,19 +172,19 @@ // FIXME -- we need to handle nested functions properly here. if (! fcn->is_nested_function ()) - { - std::string ff = fcn->fcn_file_name (); + { + std::string ff = fcn->fcn_file_name (); - if (! ff.empty ()) - { - octave_time tc = fcn->time_checked (); + if (! ff.empty ()) + { + octave_time tc = fcn->time_checked (); - bool relative = check_relative && fcn->is_relative (); + bool relative = check_relative && fcn->is_relative (); - if (tc < Vlast_prompt_time - || (relative && tc < Vlast_chdir_time)) - { - bool clear_breakpoints = false; + if (tc < Vlast_prompt_time + || (relative && tc < Vlast_chdir_time)) + { + bool clear_breakpoints = false; std::string nm = fcn->name (); bool is_same_file = false; @@ -228,67 +228,67 @@ file = ff; } - if (file.empty ()) - { - // Can't see this function from current - // directory, so we should clear it. + if (file.empty ()) + { + // Can't see this function from current + // directory, so we should clear it. - function = octave_value (); + function = octave_value (); - clear_breakpoints = true; - } - else if (is_same_file) - { - // Same file. If it is out of date, then reload it. + clear_breakpoints = true; + } + else if (is_same_file) + { + // Same file. If it is out of date, then reload it. - octave_time ottp = fcn->time_parsed (); - time_t tp = ottp.unix_time (); + octave_time ottp = fcn->time_parsed (); + time_t tp = ottp.unix_time (); - fcn->mark_fcn_file_up_to_date (octave_time ()); + fcn->mark_fcn_file_up_to_date (octave_time ()); - if (! (Vignore_function_time_stamp == 2 - || (Vignore_function_time_stamp - && fcn->is_system_fcn_file ()))) - { - file_stat fs (ff); + if (! (Vignore_function_time_stamp == 2 + || (Vignore_function_time_stamp + && fcn->is_system_fcn_file ()))) + { + file_stat fs (ff); - if (fs) - { - if (fs.is_newer (tp)) - { - retval = load_out_of_date_fcn (ff, dir_name, - function, - dispatch_type); + if (fs) + { + if (fs.is_newer (tp)) + { + retval = load_out_of_date_fcn (ff, dir_name, + function, + dispatch_type); - clear_breakpoints = true; - } - } - else - { - function = octave_value (); + clear_breakpoints = true; + } + } + else + { + function = octave_value (); - clear_breakpoints = true; - } - } - } - else - { - // Not the same file, so load the new file in - // place of the old. + clear_breakpoints = true; + } + } + } + else + { + // Not the same file, so load the new file in + // place of the old. - retval = load_out_of_date_fcn (file, dir_name, function, - dispatch_type); + retval = load_out_of_date_fcn (file, dir_name, function, + dispatch_type); - clear_breakpoints = true; - } + clear_breakpoints = true; + } - // If the function has been replaced then clear any - // breakpoints associated with it - if (clear_breakpoints) - bp_table::remove_all_breakpoints_in_file (nm, true); - } - } - } + // If the function has been replaced then clear any + // breakpoints associated with it + if (clear_breakpoints) + bp_table::remove_all_breakpoints_in_file (nm, true); + } + } + } } return retval; @@ -307,25 +307,25 @@ octave_function *fcn = load_fcn_from_file (file_name, dir_name); if (fcn) - { - std::string class_name; + { + std::string class_name; - size_t pos = dir_name.find_last_of (file_ops::dir_sep_chars ()); + size_t pos = dir_name.find_last_of (file_ops::dir_sep_chars ()); - if (pos != std::string::npos) - { - std::string tmp = dir_name.substr (pos+1); + if (pos != std::string::npos) + { + std::string tmp = dir_name.substr (pos+1); - if (tmp[0] == '@') - class_name = tmp.substr (1); - } + if (tmp[0] == '@') + class_name = tmp.substr (1); + } - fcn->mark_as_private_function (class_name); + fcn->mark_as_private_function (class_name); - retval = octave_value (fcn); + retval = octave_value (fcn); - private_functions[dir_name] = retval; - } + private_functions[dir_name] = retval; + } } return retval; @@ -345,11 +345,11 @@ octave_function *fcn = load_fcn_from_file (file_name, dir_name, name); if (fcn) - { - retval = octave_value (fcn); + { + retval = octave_value (fcn); - class_constructors[name] = retval; - } + class_constructors[name] = retval; + } } return retval; @@ -368,20 +368,20 @@ std::string dir_name; std::string file_name = load_path::find_method (dispatch_type, name, - dir_name); + dir_name); if (! file_name.empty ()) - { - octave_function *fcn = load_fcn_from_file (file_name, dir_name, - dispatch_type); + { + octave_function *fcn = load_fcn_from_file (file_name, dir_name, + dispatch_type); - if (fcn) - { - retval = octave_value (fcn); + if (fcn) + { + retval = octave_value (fcn); - class_methods[dispatch_type] = retval; - } - } + class_methods[dispatch_type] = retval; + } + } if (retval.is_undefined ()) { @@ -423,9 +423,9 @@ os << "Overloaded function " << name << ":\n\n"; for (dispatch_map_const_iterator p = dispatch_map.begin (); - p != dispatch_map.end (); p++) - os << " " << name << " (" << p->first << ", ...) -> " - << p->second << " (" << p->first << ", ...)\n"; + p != dispatch_map.end (); p++) + os << " " << name << " (" << p->first << ", ...) -> " + << p->second << " (" << p->first << ", ...)\n"; os << std::endl; } @@ -441,8 +441,8 @@ retval = "Overloaded function:\n\n"; for (dispatch_map_const_iterator p = dispatch_map.begin (); - p != dispatch_map.end (); p++) - retval += " " + p->second + " (" + p->first + ", ...)\n\n"; + p != dispatch_map.end (); p++) + retval += " " + p->second + " (" + p->first + ", ...)\n\n"; } return retval; @@ -489,12 +489,12 @@ // Find first object, if any. for (int i = 0; i < n; i++) - { - octave_value arg = args(i); + { + octave_value arg = args(i); - if (arg.is_object ()) - { - dispatch_type = arg.class_name (); + if (arg.is_object ()) + { + dispatch_type = arg.class_name (); for (int j = i+1; j < n; j++) { octave_value arg1 = args(j); @@ -513,8 +513,8 @@ builtin_class = false; break; - } - } + } + } // No object. @@ -675,24 +675,24 @@ octave_value val = load_class_constructor (); if (val.is_defined ()) - return val; + return val; } else { octave_value& fval = q->second; if (fval.is_defined ()) - out_of_date_check (fval, name); + out_of_date_check (fval, name); if (fval.is_defined ()) - return fval; + return fval; else - { - octave_value val = load_class_constructor (); + { + octave_value val = load_class_constructor (); - if (val.is_defined ()) - return val; - } + if (val.is_defined ()) + return val; + } } // Class methods. @@ -718,18 +718,18 @@ dispatch_map_iterator p = dispatch_map.find (dispatch_type); if (p == dispatch_map.end ()) - p = dispatch_map.find ("any"); + p = dispatch_map.find ("any"); if (p != dispatch_map.end ()) - { - fname = p->second; + { + fname = p->second; - octave_value fcn - = symbol_table::find_function (fname, args); + octave_value fcn + = symbol_table::find_function (fname, args); - if (fcn.is_defined ()) - return fcn; - } + if (fcn.is_defined ()) + return fcn; + } } // Command-line function. @@ -829,34 +829,34 @@ std::string dir_name = curr_fcn->dir_name (); if (! dir_name.empty ()) - { - str_val_iterator q = private_functions.find (dir_name); + { + str_val_iterator q = private_functions.find (dir_name); - if (q == private_functions.end ()) - { - octave_value val = load_private_function (dir_name); + if (q == private_functions.end ()) + { + octave_value val = load_private_function (dir_name); - if (val.is_defined ()) - return val; - } - else - { - octave_value& fval = q->second; + if (val.is_defined ()) + return val; + } + else + { + octave_value& fval = q->second; - if (fval.is_defined ()) - out_of_date_check (fval); + if (fval.is_defined ()) + out_of_date_check (fval); - if (fval.is_defined ()) - return fval; - else - { - octave_value val = load_private_function (dir_name); + if (fval.is_defined ()) + return fval; + else + { + octave_value val = load_private_function (dir_name); - if (val.is_defined ()) - return val; - } - } - } + if (val.is_defined ()) + return val; + } + } + } } // Subfunction. I think it only makes sense to check for @@ -876,16 +876,16 @@ scope_id pscope = curr_fcn->parent_fcn_scope (); if (pscope > 0) - { - r = subfunctions.find (pscope); + { + r = subfunctions.find (pscope); - if (r != subfunctions.end ()) - { - // FIXME -- out-of-date check here. + if (r != subfunctions.end ()) + { + // FIXME -- out-of-date check here. - return r->second; - } - } + return r->second; + } + } } return octave_value (); @@ -903,24 +903,24 @@ octave_value val = load_class_method (dispatch_type); if (val.is_defined ()) - return val; + return val; } else { octave_value& fval = q->second; if (fval.is_defined ()) - out_of_date_check (fval, dispatch_type); + out_of_date_check (fval, dispatch_type); if (fval.is_defined ()) - return fval; + return fval; else - { - octave_value val = load_class_method (dispatch_type); + { + octave_value val = load_class_method (dispatch_type); - if (val.is_defined ()) - return val; - } + if (val.is_defined ()) + return val; + } } return retval; @@ -941,17 +941,17 @@ std::string file_name = lookup_autoload (name); if (! file_name.empty ()) - { - size_t pos = file_name.find_last_of (file_ops::dir_sep_chars ()); + { + size_t pos = file_name.find_last_of (file_ops::dir_sep_chars ()); - std::string dir_name = file_name.substr (0, pos); + std::string dir_name = file_name.substr (0, pos); - octave_function *fcn = load_fcn_from_file (file_name, dir_name, - "", name, true); + octave_function *fcn = load_fcn_from_file (file_name, dir_name, + "", name, true); - if (fcn) - autoload_function = octave_value (fcn); - } + if (fcn) + autoload_function = octave_value (fcn); + } } return autoload_function; @@ -972,12 +972,12 @@ std::string file_name = load_path::find_fcn (name, dir_name); if (! file_name.empty ()) - { - octave_function *fcn = load_fcn_from_file (file_name, dir_name); + { + octave_function *fcn = load_fcn_from_file (file_name, dir_name); - if (fcn) - function_on_path = octave_value (fcn); - } + if (fcn) + function_on_path = octave_value (fcn); + } } return function_on_path; @@ -989,7 +989,7 @@ bool symbol_table::set_class_relationship (const std::string& sup_class, - const std::string& inf_class) + const std::string& inf_class) { class_precedence_table_const_iterator p = class_precedence_table.find (inf_class); @@ -999,10 +999,10 @@ const std::set& inferior_classes = p->second; std::set::const_iterator q - = inferior_classes.find (sup_class); + = inferior_classes.find (sup_class); if (q != inferior_classes.end ()) - return false; + return false; } class_precedence_table[sup_class].insert (inf_class); @@ -1036,7 +1036,7 @@ std::set::const_iterator q = inferior_classes.find (b); if (q != inferior_classes.end ()) - retval = true; + retval = true; } return retval; @@ -1073,41 +1073,41 @@ if (! subfunctions.empty ()) { for (scope_val_const_iterator p = subfunctions.begin (); - p != subfunctions.end (); p++) - os << tprefix << "subfunction: " << fcn_file_name (p->second) - << " [" << p->first << "]\n"; + p != subfunctions.end (); p++) + os << tprefix << "subfunction: " << fcn_file_name (p->second) + << " [" << p->first << "]\n"; } if (! private_functions.empty ()) { for (str_val_const_iterator p = private_functions.begin (); - p != private_functions.end (); p++) - os << tprefix << "private: " << fcn_file_name (p->second) - << " [" << p->first << "]\n"; + p != private_functions.end (); p++) + os << tprefix << "private: " << fcn_file_name (p->second) + << " [" << p->first << "]\n"; } if (! class_constructors.empty ()) { for (str_val_const_iterator p = class_constructors.begin (); - p != class_constructors.end (); p++) - os << tprefix << "constructor: " << fcn_file_name (p->second) - << " [" << p->first << "]\n"; + p != class_constructors.end (); p++) + os << tprefix << "constructor: " << fcn_file_name (p->second) + << " [" << p->first << "]\n"; } if (! class_methods.empty ()) { for (str_val_const_iterator p = class_methods.begin (); - p != class_methods.end (); p++) - os << tprefix << "method: " << fcn_file_name (p->second) - << " [" << p->first << "]\n"; + p != class_methods.end (); p++) + os << tprefix << "method: " << fcn_file_name (p->second) + << " [" << p->first << "]\n"; } if (! dispatch_map.empty ()) { for (dispatch_map_const_iterator p = dispatch_map.begin (); - p != dispatch_map.end (); p++) - os << tprefix << "dispatch: " << fcn_file_name (p->second) - << " [" << p->first << "]\n"; + p != dispatch_map.end (); p++) + os << tprefix << "dispatch: " << fcn_file_name (p->second) + << " [" << p->first << "]\n"; } } @@ -1143,11 +1143,11 @@ { // Look for a class specific function. std::string dispatch_type = - name.substr (1, name.find_first_of (file_ops::dir_sep_str ()) - 1); + name.substr (1, name.find_first_of (file_ops::dir_sep_str ()) - 1); std::string method = - name.substr (name.find_last_of (file_ops::dir_sep_str ()) + 1, - std::string::npos); + name.substr (name.find_last_of (file_ops::dir_sep_str ()) + 1, + std::string::npos); retval = find_method (method, dispatch_type); } @@ -1156,30 +1156,30 @@ size_t pos = name.find_first_of (Vfilemarker); if (pos == std::string::npos) - retval = find (name, args, true, local_funcs); + retval = find (name, args, true, local_funcs); else - { - std::string fcn_scope = name.substr (0, pos); - scope_id stored_scope = xcurrent_scope; - xcurrent_scope = xtop_scope; - octave_value parent = find_function (name.substr(0, pos), + { + std::string fcn_scope = name.substr (0, pos); + scope_id stored_scope = xcurrent_scope; + xcurrent_scope = xtop_scope; + octave_value parent = find_function (name.substr(0, pos), octave_value_list (), false); - if (parent.is_defined ()) - { - octave_function *parent_fcn = parent.function_value (); + if (parent.is_defined ()) + { + octave_function *parent_fcn = parent.function_value (); - if (parent_fcn) - { - xcurrent_scope = parent_fcn->scope (); + if (parent_fcn) + { + xcurrent_scope = parent_fcn->scope (); - if (xcurrent_scope > 1) - retval = find_function (name.substr (pos + 1), args); - } - } + if (xcurrent_scope > 1) + retval = find_function (name.substr (pos + 1), args); + } + } - xcurrent_scope = stored_scope; - } + xcurrent_scope = stored_scope; + } } return retval; @@ -1195,26 +1195,26 @@ symbol_table *inst = get_instance (scope, false); if (inst) - { - os << "*** dumping symbol table scope " << scope - << " (" << inst->table_name << ")\n\n"; + { + os << "*** dumping symbol table scope " << scope + << " (" << inst->table_name << ")\n\n"; - std::map sfuns - = symbol_table::subfunctions_defined_in_scope (scope); + std::map sfuns + = symbol_table::subfunctions_defined_in_scope (scope); - if (! sfuns.empty ()) - { - os << " subfunctions defined in this scope:\n"; + if (! sfuns.empty ()) + { + os << " subfunctions defined in this scope:\n"; - for (std::map::const_iterator p = sfuns.begin (); - p != sfuns.end (); p++) - os << " " << p->first << "\n"; + for (std::map::const_iterator p = sfuns.begin (); + p != sfuns.end (); p++) + os << " " << p->first << "\n"; - os << "\n"; - } + os << "\n"; + } - inst->do_dump (os); - } + inst->do_dump (os); + } } } @@ -1226,15 +1226,15 @@ os << "*** dumping global symbol table\n\n"; for (global_table_const_iterator p = global_table.begin (); - p != global_table.end (); p++) - { - std::string nm = p->first; - octave_value val = p->second; + p != global_table.end (); p++) + { + std::string nm = p->first; + octave_value val = p->second; - os << " " << nm << " "; - val.dump (os); - os << "\n"; - } + os << " " << nm << " "; + val.dump (os); + os << "\n"; + } } } @@ -1244,11 +1244,11 @@ if (! fcn_table.empty ()) { os << "*** dumping globally visible functions from symbol table\n" - << " (c=commandline, b=built-in)\n\n"; + << " (c=commandline, b=built-in)\n\n"; for (fcn_table_const_iterator p = fcn_table.begin (); - p != fcn_table.end (); p++) - p->second.dump (os, " "); + p != fcn_table.end (); p++) + p->second.dump (os, " "); os << "\n"; } @@ -1256,7 +1256,7 @@ void symbol_table::stash_dir_name_for_subfunctions (scope_id scope, - const std::string& dir_name) + const std::string& dir_name) { // FIXME -- is this the best way to do this? Maybe it would be // better if we had a map from scope to list of subfunctions @@ -1266,26 +1266,26 @@ p != fcn_table.end (); p++) { std::pair tmp - = p->second.subfunction_defined_in_scope (scope); + = p->second.subfunction_defined_in_scope (scope); std::string nm = tmp.first; if (! nm.empty ()) - { - octave_value& fcn = tmp.second; + { + octave_value& fcn = tmp.second; - octave_user_function *f = fcn.user_function_value (); + octave_user_function *f = fcn.user_function_value (); - if (f) - f->stash_dir_name (dir_name); - } + if (f) + f->stash_dir_name (dir_name); + } } } octave_value symbol_table::do_find (const std::string& name, const octave_value_list& args, - bool skip_variables, + bool skip_variables, bool local_funcs) { octave_value retval; @@ -1297,21 +1297,21 @@ table_iterator p = table.find (name); if (p != table.end ()) - { - symbol_record sr = p->second; + { + symbol_record sr = p->second; - // FIXME -- should we be using something other than varref here? + // FIXME -- should we be using something other than varref here? - if (sr.is_global ()) - return symbol_table::global_varref (name); - else - { - octave_value& val = sr.varref (); + if (sr.is_global ()) + return symbol_table::global_varref (name); + else + { + octave_value& val = sr.varref (); - if (val.is_defined ()) - return val; - } - } + if (val.is_defined ()) + return val; + } + } } fcn_table_iterator p = fcn_table.find (name); @@ -1325,7 +1325,7 @@ octave_value fcn = finfo.find (args, local_funcs); if (fcn.is_defined ()) - fcn_table[name] = finfo; + fcn_table[name] = finfo; return fcn; } @@ -1349,7 +1349,7 @@ octave_value fcn = finfo.builtin_find (); if (fcn.is_defined ()) - fcn_table[name] = finfo; + fcn_table[name] = finfo; return fcn; } @@ -1365,15 +1365,15 @@ os << " persistent variables in this scope:\n\n"; for (persistent_table_const_iterator p = persistent_table.begin (); - p != persistent_table.end (); p++) - { - std::string nm = p->first; - octave_value val = p->second; + p != persistent_table.end (); p++) + { + std::string nm = p->first; + octave_value val = p->second; - os << " " << nm << " "; - val.dump (os); - os << "\n"; - } + os << " " << nm << " "; + val.dump (os); + os << "\n"; + } os << "\n"; } @@ -1381,10 +1381,10 @@ if (! table.empty ()) { os << " other symbols in this scope (l=local; a=auto; f=formal\n" - << " h=hidden; i=inherited; g=global; p=persistent)\n\n"; + << " h=hidden; i=inherited; g=global; p=persistent)\n\n"; for (table_const_iterator p = table.begin (); p != table.end (); p++) - p->second.dump (os, " "); + p->second.dump (os, " "); os << "\n"; } @@ -1445,19 +1445,19 @@ if (nargout > 0) { switch (Vignore_function_time_stamp) - { - case 1: - retval = "system"; - break; + { + case 1: + retval = "system"; + break; - case 2: - retval = "all"; - break; + case 2: + retval = "all"; + break; - default: - retval = "none"; - break; - } + default: + retval = "none"; + break; + } } int nargin = args.length (); @@ -1467,18 +1467,18 @@ std::string sval = args(0).string_value (); if (! error_state) - { - if (sval == "all") - Vignore_function_time_stamp = 2; - else if (sval == "system") - Vignore_function_time_stamp = 1; - else if (sval == "none") - Vignore_function_time_stamp = 0; - else - error ("ignore_function_time_stamp: expecting argument to be \"all\", \"system\", or \"none\""); - } + { + if (sval == "all") + Vignore_function_time_stamp = 2; + else if (sval == "system") + Vignore_function_time_stamp = 1; + else if (sval == "none") + Vignore_function_time_stamp = 0; + else + error ("ignore_function_time_stamp: expecting argument to be \"all\", \"system\", or \"none\""); + } else - error ("ignore_function_time_stamp: expecting argument to be character string"); + error ("ignore_function_time_stamp: expecting argument to be character string"); } else if (nargin > 1) print_usage (); @@ -1522,47 +1522,47 @@ std::list lst = symbol_table::scopes (); for (std::list::const_iterator p = lst.begin (); - p != lst.end (); p++) - symbol_table::dump (octave_stdout, *p); + p != lst.end (); p++) + symbol_table::dump (octave_stdout, *p); } else if (nargin == 1) { octave_value arg = args(0); if (arg.is_string ()) - { - std::string s_arg = arg.string_value (); + { + std::string s_arg = arg.string_value (); - if (s_arg == "scopes") - { - std::list lst = symbol_table::scopes (); + if (s_arg == "scopes") + { + std::list lst = symbol_table::scopes (); - RowVector v (lst.size ()); + RowVector v (lst.size ()); - octave_idx_type k = 0; + octave_idx_type k = 0; - for (std::list::const_iterator p = lst.begin (); - p != lst.end (); p++) - v.xelem (k++) = *p; + for (std::list::const_iterator p = lst.begin (); + p != lst.end (); p++) + v.xelem (k++) = *p; - retval = v; - } - else if (s_arg == "functions") - { - symbol_table::dump_functions (octave_stdout); - } - else - error ("__dump_symtab_info__: expecting \"functions\" or \"scopes\""); - } + retval = v; + } + else if (s_arg == "functions") + { + symbol_table::dump_functions (octave_stdout); + } + else + error ("__dump_symtab_info__: expecting \"functions\" or \"scopes\""); + } else - { - int s = arg.int_value (); + { + int s = arg.int_value (); - if (! error_state) - symbol_table::dump (octave_stdout, s); - else - error ("__dump_symtab_info__: expecting string or scope id"); - } + if (! error_state) + symbol_table::dump (octave_stdout, s); + else + error ("__dump_symtab_info__: expecting string or scope id"); + } } else print_usage (); @@ -1583,9 +1583,9 @@ std::string name = args(0).string_value (); if (! error_state) - symbol_table::varref (name) = args(1); + symbol_table::varref (name) = args(1); else - error ("set_variable: expecting variable name as first argument"); + error ("set_variable: expecting variable name as first argument"); } else print_usage (); @@ -1602,15 +1602,15 @@ std::string name = args(0).string_value (); if (! error_state) - { - retval = symbol_table::varval (name); + { + retval = symbol_table::varval (name); - if (retval.is_undefined ()) - error ("variable_value: `%s' is not a variable in the current scope", - name.c_str ()); - } + if (retval.is_undefined ()) + error ("variable_value: `%s' is not a variable in the current scope", + name.c_str ()); + } else - error ("variable_value: expecting variable name as first argument"); + error ("variable_value: expecting variable name as first argument"); } else print_usage (); diff --git a/src/syscalls.cc b/src/syscalls.cc --- a/src/syscalls.cc +++ b/src/syscalls.cc @@ -105,31 +105,31 @@ if (nargin == 2) { octave_stream old_stream - = octave_stream_list::lookup (args(0), "dup2"); + = octave_stream_list::lookup (args(0), "dup2"); if (! error_state) - { - octave_stream new_stream - = octave_stream_list::lookup (args(1), "dup2"); + { + octave_stream new_stream + = octave_stream_list::lookup (args(1), "dup2"); - if (! error_state) - { - int i_old = old_stream.file_number (); - int i_new = new_stream.file_number (); + if (! error_state) + { + int i_old = old_stream.file_number (); + int i_new = new_stream.file_number (); - if (i_old >= 0 && i_new >= 0) - { - std::string msg; + if (i_old >= 0 && i_new >= 0) + { + std::string msg; - int status = octave_syscalls::dup2 (i_old, i_new, msg); + int status = octave_syscalls::dup2 (i_old, i_new, msg); - retval(0) = status; - retval(1) = msg; - } - } - } + retval(0) = status; + retval(1) = msg; + } + } + } else - error ("dup2: invalid stream"); + error ("dup2: invalid stream"); } else print_usage (); @@ -168,46 +168,46 @@ std::string exec_file = args(0).string_value (); if (! error_state) - { - string_vector exec_args; + { + string_vector exec_args; - if (nargin == 2) - { - string_vector tmp = args(1).all_strings (); + if (nargin == 2) + { + string_vector tmp = args(1).all_strings (); - if (! error_state) - { - int len = tmp.length (); + if (! error_state) + { + int len = tmp.length (); - exec_args.resize (len + 1); + exec_args.resize (len + 1); - exec_args[0] = exec_file; + exec_args[0] = exec_file; - for (int i = 0; i < len; i++) - exec_args[i+1] = tmp[i]; - } - else - error ("exec: arguments must be character strings"); - } - else - { - exec_args.resize (1); + for (int i = 0; i < len; i++) + exec_args[i+1] = tmp[i]; + } + else + error ("exec: arguments must be character strings"); + } + else + { + exec_args.resize (1); - exec_args[0] = exec_file; - } + exec_args[0] = exec_file; + } - if (! error_state) - { - std::string msg; + if (! error_state) + { + std::string msg; - int status = octave_syscalls::execvp (exec_file, exec_args, msg); + int status = octave_syscalls::execvp (exec_file, exec_args, msg); - retval(0) = status; - retval(1) = msg; - } - } + retval(0) = status; + retval(1) = msg; + } + } else - error ("exec: first argument must be a string"); + error ("exec: first argument must be a string"); } else print_usage (); @@ -272,32 +272,32 @@ if (! error_state) { - string_vector arg_list; + string_vector arg_list; - if (nargin >= 2) - { - string_vector tmp = args(1).all_strings (); + if (nargin >= 2) + { + string_vector tmp = args(1).all_strings (); - if (! error_state) - { - int len = tmp.length (); + if (! error_state) + { + int len = tmp.length (); - arg_list.resize (len + 1); + arg_list.resize (len + 1); - arg_list[0] = exec_file; + arg_list[0] = exec_file; - for (int i = 0; i < len; i++) - arg_list[i+1] = tmp[i]; - } - else - error ("popen2: arguments must be character strings"); - } - else - { - arg_list.resize (1); + for (int i = 0; i < len; i++) + arg_list[i+1] = tmp[i]; + } + else + error ("popen2: arguments must be character strings"); + } + else + { + arg_list.resize (1); - arg_list[0] = exec_file; - } + arg_list[0] = exec_file; + } if (! error_state) { @@ -327,9 +327,9 @@ retval(0) = octave_stream_list::insert (os); retval(1) = octave_stream_list::insert (is); - retval(2) = pid; + retval(2) = pid; } - else + else error (msg.c_str ()); } } @@ -457,30 +457,30 @@ octave_stream strm = octave_stream_list::lookup (args (0), "fcntl"); if (! error_state) - { - int fid = strm.file_number (); + { + int fid = strm.file_number (); - int req = args(1).int_value (true); - int arg = args(2).int_value (true); + int req = args(1).int_value (true); + int arg = args(2).int_value (true); - if (! error_state) - { - // FIXME -- Need better checking here? - if (fid < 0) - error ("fcntl: invalid file id"); - else - { - std::string msg; + if (! error_state) + { + // FIXME -- Need better checking here? + if (fid < 0) + error ("fcntl: invalid file id"); + else + { + std::string msg; - int status = octave_fcntl (fid, req, arg, msg); + int status = octave_fcntl (fid, req, arg, msg); - retval(0) = status; - retval(1) = msg; - } - } - } + retval(0) = status; + retval(1) = msg; + } + } + } else - error ("fcntl: file id, request, and argument must be integers"); + error ("fcntl: file id, request, and argument must be integers"); } else print_usage (); @@ -699,19 +699,19 @@ pid_t pid = args(0).int_value (true); if (! error_state) - { - int sig = args(1).int_value (true); + { + int sig = args(1).int_value (true); - if (! error_state) - { - std::string msg; + if (! error_state) + { + std::string msg; - int status = octave_syscalls::kill (pid, sig, msg); + int status = octave_syscalls::kill (pid, sig, msg); - retval(1) = msg; - retval(0) = status; - } - } + retval(1) = msg; + retval(0) = status; + } + } } else print_usage (); @@ -733,22 +733,22 @@ int fid = octave_stream_list::get_file_number (args(0)); if (! error_state) - { - file_fstat fs (fid); + { + file_fstat fs (fid); - if (fs) - { - retval(2) = std::string (); - retval(1) = 0; - retval(0) = octave_value (mk_stat_map (fs)); - } - else - { - retval(2) = fs.error (); - retval(1) = -1; - retval(0) = Matrix (); - } - } + if (fs) + { + retval(2) = std::string (); + retval(1) = 0; + retval(0) = octave_value (mk_stat_map (fs)); + } + else + { + retval(2) = fs.error (); + retval(1) = -1; + retval(0) = Matrix (); + } + } } else print_usage (); @@ -769,22 +769,22 @@ std::string fname = args(0).string_value (); if (! error_state) - { - file_stat fs (fname, false); + { + file_stat fs (fname, false); - if (fs) - { - retval(2) = std::string (); - retval(1) = 0; - retval(0) = mk_stat_map (fs); - } - else - { - retval(2) = fs.error (); - retval(1) = -1; - retval(0) = Matrix (); - } - } + if (fs) + { + retval(2) = std::string (); + retval(1) = 0; + retval(0) = mk_stat_map (fs); + } + else + { + retval(2) = fs.error (); + retval(1) = -1; + retval(0) = Matrix (); + } + } } else print_usage (); @@ -814,32 +814,32 @@ if (nargin == 2) { if (args(0).is_string ()) - { - std::string name = args(0).string_value (); + { + std::string name = args(0).string_value (); - if (args(1).is_scalar_type ()) - { - long mode = args(1).long_value (); + if (args(1).is_scalar_type ()) + { + long mode = args(1).long_value (); - if (! error_state) - { - std::string msg; + if (! error_state) + { + std::string msg; - int status = octave_mkfifo (name, mode, msg); + int status = octave_mkfifo (name, mode, msg); - retval(0) = status; + retval(0) = status; - if (status < 0) - retval(1) = msg; - } - else - error ("mkfifo: invalid MODE"); - } - else - error ("mkfifo: MODE must be an integer"); - } + if (status < 0) + retval(1) = msg; + } + else + error ("mkfifo: invalid MODE"); + } + else + error ("mkfifo: MODE must be an integer"); + } else - error ("mkfifo: file name must be a string"); + error ("mkfifo: file name must be a string"); } else print_usage (); @@ -876,25 +876,25 @@ int status = octave_syscalls::pipe (fid, msg); if (status < 0) - retval(3) = msg; + retval(3) = msg; else - { - FILE *ifile = fdopen (fid[0], "r"); - FILE *ofile = fdopen (fid[1], "w"); + { + FILE *ifile = fdopen (fid[0], "r"); + FILE *ofile = fdopen (fid[1], "w"); - std::string nm; + std::string nm; - octave_stream is = octave_stdiostream::create (nm, ifile, - std::ios::in); + octave_stream is = octave_stdiostream::create (nm, ifile, + std::ios::in); - octave_stream os = octave_stdiostream::create (nm, ofile, - std::ios::out); + octave_stream os = octave_stdiostream::create (nm, ofile, + std::ios::out); - retval(1) = octave_stream_list::insert (os); - retval(0) = octave_stream_list::insert (is); + retval(1) = octave_stream_list::insert (os); + retval(0) = octave_stream_list::insert (is); - retval(2) = status; - } + retval(2) = status; + } } else print_usage (); @@ -1002,22 +1002,22 @@ std::string fname = args(0).string_value (); if (! error_state) - { - file_stat fs (fname); + { + file_stat fs (fname); - if (fs) - { - retval(2) = std::string (); - retval(1) = 0; - retval(0) = octave_value (mk_stat_map (fs)); - } - else - { - retval(2) = fs.error (); - retval(1) = -1; - retval(0) = Matrix (); - } - } + if (fs) + { + retval(2) = std::string (); + retval(1) = 0; + retval(0) = octave_value (mk_stat_map (fs)); + } + else + { + retval(2) = fs.error (); + retval(1) = -1; + retval(0) = Matrix (); + } + } } else print_usage (); @@ -1040,9 +1040,9 @@ double mode = args(0).double_value (); if (! error_state) - retval = file_stat::is_reg (static_cast (mode)); + retval = file_stat::is_reg (static_cast (mode)); else - error ("S_ISREG: invalid mode value"); + error ("S_ISREG: invalid mode value"); } else print_usage (); @@ -1065,9 +1065,9 @@ double mode = args(0).double_value (); if (! error_state) - retval = file_stat::is_dir (static_cast (mode)); + retval = file_stat::is_dir (static_cast (mode)); else - error ("S_ISDIR: invalid mode value"); + error ("S_ISDIR: invalid mode value"); } else print_usage (); @@ -1090,9 +1090,9 @@ double mode = args(0).double_value (); if (! error_state) - retval = file_stat::is_chr (static_cast (mode)); + retval = file_stat::is_chr (static_cast (mode)); else - error ("S_ISCHR: invalid mode value"); + error ("S_ISCHR: invalid mode value"); } else print_usage (); @@ -1115,9 +1115,9 @@ double mode = args(0).double_value (); if (! error_state) - retval = file_stat::is_blk (static_cast (mode)); + retval = file_stat::is_blk (static_cast (mode)); else - error ("S_ISBLK: invalid mode value"); + error ("S_ISBLK: invalid mode value"); } else print_usage (); @@ -1140,9 +1140,9 @@ double mode = args(0).double_value (); if (! error_state) - retval = file_stat::is_fifo (static_cast (mode)); + retval = file_stat::is_fifo (static_cast (mode)); else - error ("S_ISFIFO: invalid mode value"); + error ("S_ISFIFO: invalid mode value"); } else print_usage (); @@ -1165,9 +1165,9 @@ double mode = args(0).double_value (); if (! error_state) - retval = file_stat::is_lnk (static_cast (mode)); + retval = file_stat::is_lnk (static_cast (mode)); else - error ("S_ISLNK: invalid mode value"); + error ("S_ISLNK: invalid mode value"); } else print_usage (); @@ -1188,9 +1188,9 @@ double mode = args(0).double_value (); if (! error_state) - retval = file_stat::is_sock (static_cast (mode)); + retval = file_stat::is_sock (static_cast (mode)); else - error ("S_ISSOCK: invalid mode value"); + error ("S_ISSOCK: invalid mode value"); } else print_usage (); @@ -1265,18 +1265,18 @@ if (nargin == 1) { if (args(0).is_string ()) - { - std::string name = args(0).string_value (); + { + std::string name = args(0).string_value (); - std::string msg; + std::string msg; - int status = octave_unlink (name, msg); + int status = octave_unlink (name, msg); - retval(0) = status; - retval(1) = msg; - } + retval(0) = status; + retval(1) = msg; + } else - error ("unlink: file name must be a string"); + error ("unlink: file name must be a string"); } else print_usage (); @@ -1342,29 +1342,29 @@ pid_t pid = args(0).int_value (true); if (! error_state) - { - int options = 0; + { + int options = 0; - if (args.length () == 2) - options = args(1).int_value (true); + if (args.length () == 2) + options = args(1).int_value (true); - if (! error_state) - { - std::string msg; + if (! error_state) + { + std::string msg; - int status = 0; + int status = 0; - pid_t result = octave_syscalls::waitpid (pid, &status, options, msg); + pid_t result = octave_syscalls::waitpid (pid, &status, options, msg); - retval(0) = result; - retval(1) = status; - retval(2) = msg; - } - else - error ("waitpid: OPTIONS must be an integer"); - } + retval(0) = result; + retval(1) = status; + retval(2) = msg; + } + else + error ("waitpid: OPTIONS must be an integer"); + } else - error ("waitpid: PID must be an integer value"); + error ("waitpid: PID must be an integer value"); } else print_usage (); @@ -1388,9 +1388,9 @@ int status = args(0).int_value (); if (! error_state) - retval = WIFEXITED (status); + retval = WIFEXITED (status); else - error ("WIFEXITED: expecting integer argument"); + error ("WIFEXITED: expecting integer argument"); } #else warning ("WIFEXITED always returns false in this version of Octave") @@ -1416,9 +1416,9 @@ int status = args(0).int_value (); if (! error_state) - retval = WEXITSTATUS (status); + retval = WEXITSTATUS (status); else - error ("WEXITSTATUS: expecting integer argument"); + error ("WEXITSTATUS: expecting integer argument"); } #else warning ("WEXITSTATUS always returns false in this version of Octave") @@ -1443,9 +1443,9 @@ int status = args(0).int_value (); if (! error_state) - retval = WIFSIGNALED (status); + retval = WIFSIGNALED (status); else - error ("WIFSIGNALED: expecting integer argument"); + error ("WIFSIGNALED: expecting integer argument"); } #else warning ("WIFSIGNALED always returns false in this version of Octave"); @@ -1471,9 +1471,9 @@ int status = args(0).int_value (); if (! error_state) - retval = WTERMSIG (status); + retval = WTERMSIG (status); else - error ("WTERMSIG: expecting integer argument"); + error ("WTERMSIG: expecting integer argument"); } #else warning ("WTERMSIG always returns false in this version of Octave"); @@ -1501,9 +1501,9 @@ int status = args(0).int_value (); if (! error_state) - retval = WCOREDUMP (status); + retval = WCOREDUMP (status); else - error ("WCOREDUMP: expecting integer argument"); + error ("WCOREDUMP: expecting integer argument"); } #else warning ("WCOREDUMP always returns false in this version of Octave"); @@ -1530,9 +1530,9 @@ int status = args(0).int_value (); if (! error_state) - retval = WIFSTOPPED (status); + retval = WIFSTOPPED (status); else - error ("WIFSTOPPED: expecting integer argument"); + error ("WIFSTOPPED: expecting integer argument"); } #else warning ("WIFSTOPPED always returns false in this version of Octave"); @@ -1558,9 +1558,9 @@ int status = args(0).int_value (); if (! error_state) - retval = WSTOPSIG (status); + retval = WSTOPSIG (status); else - error ("WSTOPSIG: expecting integer argument"); + error ("WSTOPSIG: expecting integer argument"); } #else warning ("WSTOPSIG always returns false in this version of Octave"); @@ -1585,9 +1585,9 @@ int status = args(0).int_value (); if (! error_state) - retval = WIFCONTINUED (status); + retval = WIFCONTINUED (status); else - error ("WIFCONTINUED: expecting integer argument"); + error ("WIFCONTINUED: expecting integer argument"); } #else warning ("WIFCONTINUED always returns false in this version of Octave"); @@ -1609,17 +1609,17 @@ std::string name = args(0).string_value (); if (! error_state) - { - std::string msg; + { + std::string msg; - std::string result = octave_canonicalize_file_name (name, msg); + std::string result = octave_canonicalize_file_name (name, msg); - retval(2) = msg; - retval(1) = msg.empty () ? 0 : -1; - retval(0) = result; - } + retval(2) = msg; + retval(1) = msg.empty () ? 0 : -1; + retval(0) = result; + } else - error ("canonicalize_file_name: argument must be a character string"); + error ("canonicalize_file_name: argument must be a character string"); } else print_usage (); diff --git a/src/sysdep.cc b/src/sysdep.cc --- a/src/sysdep.cc +++ b/src/sysdep.cc @@ -115,15 +115,15 @@ int status = GetModuleFileName (hMod, &bin_dir[0], n); if (status < n) - { - bin_dir.resize (status); - break; - } + { + bin_dir.resize (status); + break; + } else - { - n *= 2; - bin_dir.resize (n); - } + { + n *= 2; + bin_dir.resize (n); + } } if (! bin_dir.empty ()) @@ -131,7 +131,7 @@ size_t pos = bin_dir.rfind ("\\bin\\"); if (pos != std::string::npos) - octave_env::putenv ("OCTAVE_HOME", bin_dir.substr (0, pos)); + octave_env::putenv ("OCTAVE_HOME", bin_dir.substr (0, pos)); } } @@ -194,27 +194,27 @@ // Reference: http://msdn2.microsoft.com/en-us/library/aa363788.aspx HANDLE hfile1 = CreateFile (file1.c_str (), 0, FILE_SHARE_READ, 0, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (hfile1 != INVALID_HANDLE_VALUE) { HANDLE hfile2 = CreateFile (file2.c_str (), 0, FILE_SHARE_READ, 0, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (hfile2 != INVALID_HANDLE_VALUE) - { - BY_HANDLE_FILE_INFORMATION hfi1; - BY_HANDLE_FILE_INFORMATION hfi2; + { + BY_HANDLE_FILE_INFORMATION hfi1; + BY_HANDLE_FILE_INFORMATION hfi2; - if (GetFileInformationByHandle (hfile1, &hfi1) - && GetFileInformationByHandle (hfile2, &hfi2)) + if (GetFileInformationByHandle (hfile1, &hfi1) + && GetFileInformationByHandle (hfile2, &hfi2)) - retval = (hfi1.dwVolumeSerialNumber == hfi2.dwVolumeSerialNumber - && hfi1.nFileIndexHigh == hfi2.nFileIndexHigh - && hfi1.nFileIndexLow == hfi2.nFileIndexLow); + retval = (hfi1.dwVolumeSerialNumber == hfi2.dwVolumeSerialNumber + && hfi1.nFileIndexHigh == hfi2.nFileIndexHigh + && hfi1.nFileIndexLow == hfi2.nFileIndexLow); - CloseHandle (hfile2); - } + CloseHandle (hfile2); + } CloseHandle (hfile1); } @@ -229,8 +229,8 @@ file_stat fs_file2 (file2); return (fs_file1 && fs_file2 - && fs_file1.ino () == fs_file2.ino () - && fs_file1.dev () == fs_file2.dev ()); + && fs_file1.ino () == fs_file2.ino () + && fs_file1.dev () == fs_file2.dev ()); #endif } @@ -274,7 +274,7 @@ OS2_init (void) { _control87 ((EM_INVALID | EM_DENORMAL | EM_ZERODIVIDE | EM_OVERFLOW - | EM_UNDERFLOW | EM_INEXACT), MCW_EM); + | EM_UNDERFLOW | EM_INEXACT), MCW_EM); } #endif @@ -319,12 +319,12 @@ // // Change terminal to "raw mode", or restore to "normal" mode. // "Raw mode" means -// 1. An outstanding read will complete on receipt of a single keystroke. -// 2. Input is not echoed. -// 3. On output, \n is mapped to \r\n. -// 4. \t is NOT expanded into spaces. -// 5. Signal-causing characters such as ctrl-C (interrupt), -// etc. are NOT disabled. +// 1. An outstanding read will complete on receipt of a single keystroke. +// 2. Input is not echoed. +// 3. On output, \n is mapped to \r\n. +// 4. \t is NOT expanded into spaces. +// 5. Signal-causing characters such as ctrl-C (interrupt), +// etc. are NOT disabled. // It doesn't matter whether an input \n is mapped to \r, or vice versa. void @@ -336,7 +336,7 @@ if (! isatty (tty_fd)) { if (interactive) - error ("stdin is not a tty!"); + error ("stdin is not a tty!"); return; } @@ -350,38 +350,38 @@ if (on) { - // Get terminal modes. + // Get terminal modes. - tcgetattr (tty_fd, &s); + tcgetattr (tty_fd, &s); - // Save modes and set certain variables dependent on modes. + // Save modes and set certain variables dependent on modes. - save_term = s; -// ospeed = s.c_cflag & CBAUD; -// erase_char = s.c_cc[VERASE]; -// kill_char = s.c_cc[VKILL]; + save_term = s; +// ospeed = s.c_cflag & CBAUD; +// erase_char = s.c_cc[VERASE]; +// kill_char = s.c_cc[VKILL]; - // Set the modes to the way we want them. + // Set the modes to the way we want them. - s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL); - s.c_oflag |= (OPOST|ONLCR); + s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL); + s.c_oflag |= (OPOST|ONLCR); #if defined (OCRNL) - s.c_oflag &= ~(OCRNL); + s.c_oflag &= ~(OCRNL); #endif #if defined (ONOCR) - s.c_oflag &= ~(ONOCR); + s.c_oflag &= ~(ONOCR); #endif #if defined (ONLRET) - s.c_oflag &= ~(ONLRET); + s.c_oflag &= ~(ONLRET); #endif - s.c_cc[VMIN] = wait ? 1 : 0; - s.c_cc[VTIME] = 0; + s.c_cc[VMIN] = wait ? 1 : 0; + s.c_cc[VTIME] = 0; } else { - // Restore saved modes. + // Restore saved modes. - s = save_term; + s = save_term; } tcsetattr (tty_fd, wait ? TCSAFLUSH : TCSADRAIN, &s); @@ -393,37 +393,37 @@ if (on) { - // Get terminal modes. + // Get terminal modes. - ioctl (tty_fd, TCGETA, &s); + ioctl (tty_fd, TCGETA, &s); - // Save modes and set certain variables dependent on modes. + // Save modes and set certain variables dependent on modes. - save_term = s; -// ospeed = s.c_cflag & CBAUD; -// erase_char = s.c_cc[VERASE]; -// kill_char = s.c_cc[VKILL]; + save_term = s; +// ospeed = s.c_cflag & CBAUD; +// erase_char = s.c_cc[VERASE]; +// kill_char = s.c_cc[VKILL]; - // Set the modes to the way we want them. + // Set the modes to the way we want them. - s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL); - s.c_oflag |= (OPOST|ONLCR); + s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL); + s.c_oflag |= (OPOST|ONLCR); #if defined (OCRNL) - s.c_oflag &= ~(OCRNL); + s.c_oflag &= ~(OCRNL); #endif #if defined (ONOCR) - s.c_oflag &= ~(ONOCR); + s.c_oflag &= ~(ONOCR); #endif #if defined (ONLRET) - s.c_oflag &= ~(ONLRET); + s.c_oflag &= ~(ONLRET); #endif - s.c_cc[VMIN] = wait ? 1 : 0; + s.c_cc[VMIN] = wait ? 1 : 0; } else { - // Restore saved modes. + // Restore saved modes. - s = save_term; + s = save_term; } ioctl (tty_fd, TCSETAW, &s); @@ -435,27 +435,27 @@ if (on) { - // Get terminal modes. + // Get terminal modes. - ioctl (tty_fd, TIOCGETP, &s); + ioctl (tty_fd, TIOCGETP, &s); - // Save modes and set certain variables dependent on modes. + // Save modes and set certain variables dependent on modes. - save_term = s; -// ospeed = s.sg_ospeed; -// erase_char = s.sg_erase; -// kill_char = s.sg_kill; + save_term = s; +// ospeed = s.sg_ospeed; +// erase_char = s.sg_erase; +// kill_char = s.sg_kill; - // Set the modes to the way we want them. + // Set the modes to the way we want them. - s.sg_flags |= CBREAK; - s.sg_flags &= ~(ECHO); + s.sg_flags |= CBREAK; + s.sg_flags &= ~(ECHO); } else { - // Restore saved modes. + // Restore saved modes. - s = save_term; + s = save_term; } ioctl (tty_fd, TIOCSETN, &s); @@ -569,7 +569,7 @@ std::string name = args(0).string_value (); if (! error_state) - retval = octave_env::getenv (name); + retval = octave_env::getenv (name); } else print_usage (); @@ -593,17 +593,17 @@ std::string var = args(0).string_value (); if (! error_state) - { - std::string val = (nargin == 2 - ? args(1).string_value () : std::string ()); + { + std::string val = (nargin == 2 + ? args(1).string_value () : std::string ()); - if (! error_state) - octave_env::putenv (var, val); - else - error ("putenv: second argument should be a string"); - } + if (! error_state) + octave_env::putenv (var, val); + else + error ("putenv: second argument should be a string"); + } else - error ("putenv: first argument should be a string"); + error ("putenv: first argument should be a string"); } else print_usage (); @@ -648,7 +648,7 @@ int c = octave_kbhit (args.length () == 0); if (c == -1) - c = 0; + c = 0; char *s = new char [2]; s[0] = c; @@ -692,22 +692,22 @@ double dval = args(0).double_value (); if (! error_state) - { - if (! xisnan (dval)) - { - feval ("drawnow"); + { + if (! xisnan (dval)) + { + feval ("drawnow"); - if (xisinf (dval)) - { - flush_octave_stdout (); - octave_kbhit (); - } - else - octave_sleep (dval); - } - else - warning ("pause: NaN is an invalid delay"); - } + if (xisinf (dval)) + { + flush_octave_stdout (); + octave_kbhit (); + } + else + octave_sleep (dval); + } + else + warning ("pause: NaN is an invalid delay"); + } } else { @@ -732,15 +732,15 @@ double dval = args(0).double_value (); if (! error_state) - { - if (xisnan (dval)) - warning ("sleep: NaN is an invalid delay"); - else - { - feval ("drawnow"); - octave_sleep (dval); - } - } + { + if (xisnan (dval)) + warning ("sleep: NaN is an invalid delay"); + else + { + feval ("drawnow"); + octave_sleep (dval); + } + } } else print_usage (); @@ -764,19 +764,19 @@ double dval = args(0).double_value (); if (! error_state) - { - if (xisnan (dval)) - warning ("usleep: NaN is an invalid delay"); - else - { - feval ("drawnow"); + { + if (xisnan (dval)) + warning ("usleep: NaN is an invalid delay"); + else + { + feval ("drawnow"); - int delay = NINT (dval); + int delay = NINT (dval); - if (delay > 0) - octave_usleep (delay); - } - } + if (delay > 0) + octave_usleep (delay); + } + } } else print_usage (); @@ -797,7 +797,7 @@ oct_mach_info::float_format flt_fmt = oct_mach_info::native_float_format (); return octave_value (flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian - || flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian); + || flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian); } DEFUN (native_float_format, , , @@ -843,16 +843,16 @@ string_vector sv = arg.all_strings (); if (! error_state) - { - sv = file_ops::tilde_expand (sv); + { + sv = file_ops::tilde_expand (sv); - if (arg.is_cellstr ()) - retval = Cell (arg.dims (), sv); - else - retval = sv; - } + if (arg.is_cellstr ()) + retval = Cell (arg.dims (), sv); + else + retval = sv; + } else - error ("tilde_expand: expecting argument to be char or cellstr object"); + error ("tilde_expand: expecting argument to be char or cellstr object"); } else print_usage (); diff --git a/src/toplev.cc b/src/toplev.cc --- a/src/toplev.cc +++ b/src/toplev.cc @@ -127,15 +127,15 @@ octave_function *f = elt.fcn; if (f && f->is_user_code ()) - { - tree_statement *stmt = elt.stmt; + { + tree_statement *stmt = elt.stmt; - if (stmt) - { - retval = stmt->line (); - break; - } - } + if (stmt) + { + retval = stmt->line (); + break; + } + } } return retval; @@ -155,15 +155,15 @@ octave_function *f = elt.fcn; if (f && f->is_user_code ()) - { - tree_statement *stmt = elt.stmt; + { + tree_statement *stmt = elt.stmt; - if (stmt) - { - retval = stmt->column (); - break; - } - } + if (stmt) + { + retval = stmt->column (); + break; + } + } } return retval; @@ -188,15 +188,15 @@ octave_function *f = (*p).fcn; if (--k == frame) - found = true; + found = true; if (f && f->is_user_code ()) - { - if (! found) - curr_user_frame++; + { + if (! found) + curr_user_frame++; - retval++; - } + retval++; + } } // We counted how many user frames were not the one, in reverse. @@ -220,15 +220,15 @@ octave_function *f = elt.fcn; if (f && f->is_user_code ()) - { - if (nskip > 0) - nskip--; - else - { - retval = dynamic_cast (f); - break; - } - } + { + if (nskip > 0) + nskip--; + else + { + retval = dynamic_cast (f); + break; + } + } } return retval; @@ -236,7 +236,7 @@ Octave_map octave_call_stack::do_backtrace (size_t nskip, - octave_idx_type& curr_user_frame) const + octave_idx_type& curr_user_frame) const { Octave_map retval; @@ -268,44 +268,44 @@ int k = 0; for (const_reverse_iterator p = cs.rbegin (); p != cs.rend (); p++) - { - const call_stack_elt& elt = *p; + { + const call_stack_elt& elt = *p; - octave_function *f = elt.fcn; + octave_function *f = elt.fcn; - if (f && f->is_user_code ()) - { - if (nskip > 0) - nskip--; - else - { - scope(k) = elt.scope; - context(k) = elt.context; + if (f && f->is_user_code ()) + { + if (nskip > 0) + nskip--; + else + { + scope(k) = elt.scope; + context(k) = elt.context; - file(k) = f->fcn_file_name (); - std::string parent_fcn_name = f->parent_fcn_name (); - if (parent_fcn_name == std::string ()) - name(k) = f->name (); - else - name(k) = f->parent_fcn_name () + Vfilemarker + f->name (); + file(k) = f->fcn_file_name (); + std::string parent_fcn_name = f->parent_fcn_name (); + if (parent_fcn_name == std::string ()) + name(k) = f->name (); + else + name(k) = f->parent_fcn_name () + Vfilemarker + f->name (); - tree_statement *stmt = elt.stmt; + tree_statement *stmt = elt.stmt; - if (stmt) - { - line(k) = stmt->line (); - column(k) = stmt->column (); - } - else - { - line(k) = -1; - column(k) = -1; - } + if (stmt) + { + line(k) = stmt->line (); + column(k) = stmt->column (); + } + else + { + line(k) = -1; + column(k) = -1; + } - k++; - } - } - } + k++; + } + } + } retval.assign ("file", file); retval.assign ("name", name); @@ -334,24 +334,24 @@ symbol_table::set_scope_and_context (elt.scope, elt.context); if (verbose) - { - octave_function *f = elt.fcn; - std::string nm = f ? f->name () : std::string (""); + { + octave_function *f = elt.fcn; + std::string nm = f ? f->name () : std::string (""); - tree_statement *s = elt.stmt; - int l = -1; - int c = -1; - if (s) - { - l = s->line (); - c = s->column (); - } + tree_statement *s = elt.stmt; + int l = -1; + int c = -1; + if (s) + { + l = s->line (); + c = s->column (); + } - octave_stdout << "stopped in " << nm - << " at line " << l << " column " << c - << " (" << elt.scope << "[" << elt.context << "])" - << std::endl; - } + octave_stdout << "stopped in " << nm + << " at line " << l << " column " << c + << " (" << elt.scope << "[" << elt.context << "])" + << std::endl; + } } return retval; @@ -375,7 +375,7 @@ while (true) { if ((incr < 0 && frame == 0) || (incr > 0 && frame == cs.size () - 1)) - break; + break; frame += incr; @@ -384,21 +384,21 @@ octave_function *f = elt.fcn; if (frame == 0 || (f && f->is_user_code ())) - { - if (nskip > 0) - nskip--; - else if (nskip < 0) - nskip++; + { + if (nskip > 0) + nskip--; + else if (nskip < 0) + nskip++; - if (nskip == 0) - { - curr_frame = frame; - cs[cs.size () - 1].prev = curr_frame; + if (nskip == 0) + { + curr_frame = frame; + cs[cs.size () - 1].prev = curr_frame; - symbol_table::set_scope_and_context (elt.scope, elt.context); + symbol_table::set_scope_and_context (elt.scope, elt.context); - if (verbose) - { + if (verbose) + { std::ostringstream buf; if (f) @@ -414,13 +414,13 @@ else buf << "at top level" << std::endl; - octave_stdout << buf.str (); - } + octave_stdout << buf.str (); + } - retval = true; - break; - } - } + retval = true; + break; + } + } // There is no need to set scope and context here. That will // happen when the dbup/dbdown/keyboard frame is popped and we @@ -446,25 +446,25 @@ octave_function *f = elt.fcn; if (frame == 0 || (f && f->is_user_code ())) - { - if (! skipped) - // We found the current user code frame, so skip it. - skipped = true; - else - { - // We found the caller user code frame. - call_stack_elt tmp (elt); - tmp.prev = curr_frame; + { + if (! skipped) + // We found the current user code frame, so skip it. + skipped = true; + else + { + // We found the caller user code frame. + call_stack_elt tmp (elt); + tmp.prev = curr_frame; - curr_frame = cs.size (); + curr_frame = cs.size (); - cs.push_back (tmp); + cs.push_back (tmp); - symbol_table::set_scope_and_context (tmp.scope, tmp.context); + symbol_table::set_scope_and_context (tmp.scope, tmp.context); - break; - } - } + break; + } + } } } @@ -501,18 +501,18 @@ std::string fcn_name = "?unknown?"; if (fcn) - { - fcn_name = fcn->fcn_file_name (); + { + fcn_name = fcn->fcn_file_name (); - if (fcn_name.empty ()) - fcn_name = fcn->name (); - } + if (fcn_name.empty ()) + fcn_name = fcn->name (); + } int line = stmt ? stmt->line () : -1; int column = stmt ? stmt->column () : -1; error (" %s at line %d, column %d", - fcn_name.c_str (), line, column); + fcn_name.c_str (), line, column); } } @@ -549,97 +549,97 @@ do { try - { - unwind_protect frame; + { + unwind_protect frame; - reset_error_handler (); + reset_error_handler (); - reset_parser (); + reset_parser (); if (symbol_table::at_top_level ()) tree_evaluator::reset_debug_state (); - // Do this with an unwind-protect cleanup function so that - // the forced variables will be unmarked in the event of an - // interrupt. - symbol_table::scope_id scope = symbol_table::top_scope (); - frame.add_fcn (symbol_table::unmark_forced_variables, scope); + // Do this with an unwind-protect cleanup function so that + // the forced variables will be unmarked in the event of an + // interrupt. + symbol_table::scope_id scope = symbol_table::top_scope (); + frame.add_fcn (symbol_table::unmark_forced_variables, scope); - // This is the same as yyparse in parse.y. - retval = octave_parse (); + // This is the same as yyparse in parse.y. + retval = octave_parse (); - if (retval == 0) - { - if (global_command) - { - global_command->accept (*current_evaluator); + if (retval == 0) + { + if (global_command) + { + global_command->accept (*current_evaluator); - delete global_command; + delete global_command; - global_command = 0; + global_command = 0; - octave_quit (); + octave_quit (); - if (! (interactive || forced_interactive)) - { - bool quit = (tree_return_command::returning - || tree_break_command::breaking); + if (! (interactive || forced_interactive)) + { + bool quit = (tree_return_command::returning + || tree_break_command::breaking); - if (tree_return_command::returning) - tree_return_command::returning = 0; + if (tree_return_command::returning) + tree_return_command::returning = 0; - if (tree_break_command::breaking) - tree_break_command::breaking--; + if (tree_break_command::breaking) + tree_break_command::breaking--; - if (quit) - break; - } + if (quit) + break; + } - if (error_state) - { - if (! (interactive || forced_interactive)) - { - // We should exit with a non-zero status. - retval = 1; - break; - } - } - else - { - if (octave_completion_matches_called) - octave_completion_matches_called = false; - else - command_editor::increment_current_command_number (); - } - } - else if (parser_end_of_input) - break; - } - } + if (error_state) + { + if (! (interactive || forced_interactive)) + { + // We should exit with a non-zero status. + retval = 1; + break; + } + } + else + { + if (octave_completion_matches_called) + octave_completion_matches_called = false; + else + command_editor::increment_current_command_number (); + } + } + else if (parser_end_of_input) + break; + } + } catch (octave_interrupt_exception) - { - recover_from_exception (); + { + recover_from_exception (); octave_stdout << "\n"; if (quitting_gracefully) { clean_up_and_exit (exit_status); break; // If user has overriden the exit func. } - } + } catch (octave_execution_exception) - { - recover_from_exception (); - std::cerr - << "error: unhandled execution exception -- trying to return to prompt" - << std::endl; - } + { + recover_from_exception (); + std::cerr + << "error: unhandled execution exception -- trying to return to prompt" + << std::endl; + } catch (std::bad_alloc) - { - recover_from_exception (); - std::cerr - << "error: memory exhausted or requested size too large for range of Octave's index type -- trying to return to prompt" - << std::endl; - } + { + recover_from_exception (); + std::cerr + << "error: memory exhausted or requested size too large for range of Octave's index type -- trying to return to prompt" + << std::endl; + } } while (retval == 0); @@ -697,12 +697,12 @@ else if (nargout == 0) { if (args.length () > 0) - { - int tmp = args(0).nint_value (); + { + int tmp = args(0).nint_value (); - if (! error_state) - exit_status = tmp; - } + if (! error_state) + exit_status = tmp; + } if (! error_state) { @@ -805,7 +805,7 @@ cmd->clear (); if (wait_for_input (fid) != 1) - break; + break; } else break; @@ -887,62 +887,62 @@ system_exec_type type = et_sync; if (! error_state) - { - if (nargin > 2) - { - std::string type_str = args(2).string_value (); + { + if (nargin > 2) + { + std::string type_str = args(2).string_value (); - if (! error_state) - { - if (type_str == "sync") - type = et_sync; - else if (type_str == "async") - type = et_async; - else - error ("system: third arg must be \"sync\" or \"async\""); - } - else - error ("system: third argument must be a string"); - } - } + if (! error_state) + { + if (type_str == "sync") + type = et_sync; + else if (type_str == "async") + type = et_async; + else + error ("system: third arg must be \"sync\" or \"async\""); + } + else + error ("system: third argument must be a string"); + } + } else - error ("system: expecting std::string as first argument"); + error ("system: expecting std::string as first argument"); if (! error_state) - { + { #if defined (__WIN32__) && ! defined (__CYGWIN__) - // Work around weird double-quote handling on Windows systems. + // Work around weird double-quote handling on Windows systems. if (type == et_sync) cmd_str = "\"" + cmd_str + "\""; #endif - if (type == et_async) - { - // FIXME -- maybe this should go in sysdep.cc? + if (type == et_async) + { + // FIXME -- maybe this should go in sysdep.cc? #ifdef HAVE_FORK - pid_t pid = fork (); + pid_t pid = fork (); - if (pid < 0) - error ("system: fork failed -- can't create child process"); - else if (pid == 0) - { - // FIXME -- should probably replace this - // call with something portable. + if (pid < 0) + error ("system: fork failed -- can't create child process"); + else if (pid == 0) + { + // FIXME -- should probably replace this + // call with something portable. - execl ("/bin/sh", "sh", "-c", cmd_str.c_str (), - static_cast (0)); + execl ("/bin/sh", "sh", "-c", cmd_str.c_str (), + static_cast (0)); - panic_impossible (); - } - else - retval(0) = pid; + panic_impossible (); + } + else + retval(0) = pid; #elif defined (__WIN32__) STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory (&si, sizeof (si)); ZeroMemory (&pi, sizeof (pi)); - OCTAVE_LOCAL_BUFFER (char, xcmd_str, cmd_str.length()+1); - strcpy (xcmd_str, cmd_str.c_str ()); + OCTAVE_LOCAL_BUFFER (char, xcmd_str, cmd_str.length()+1); + strcpy (xcmd_str, cmd_str.c_str ()); if (! CreateProcess (0, xcmd_str, 0, 0, FALSE, 0, 0, 0, &si, &pi)) error ("system: CreateProcess failed -- can't create child process"); @@ -953,26 +953,26 @@ CloseHandle (pi.hThread); } #else - error ("asynchronous system calls are not supported"); + error ("asynchronous system calls are not supported"); #endif - } - else if (return_output) - retval = run_command_and_return_output (cmd_str); - else - { - int status = system (cmd_str.c_str ()); + } + else if (return_output) + retval = run_command_and_return_output (cmd_str); + else + { + int status = system (cmd_str.c_str ()); - // The value in status is as returned by waitpid. If - // the process exited normally, extract the actual exit - // status of the command. Otherwise, return 127 as a - // failure code. + // The value in status is as returned by waitpid. If + // the process exited normally, extract the actual exit + // status of the command. Otherwise, return 127 as a + // failure code. - if (WIFEXITED (status)) - status = WEXITSTATUS (status); + if (WIFEXITED (status)) + status = WEXITSTATUS (status); - retval(0) = status; - } - } + retval(0) = status; + } + } } else print_usage (); @@ -1013,7 +1013,7 @@ // called. SAFE_CALL (clear_mex_functions, ()) - SAFE_CALL (command_editor::restore_terminal_state, ()) + SAFE_CALL (command_editor::restore_terminal_state, ()) // FIXME -- is this needed? Can it cause any trouble? SAFE_CALL (raw_mode, (0)) @@ -1021,7 +1021,7 @@ SAFE_CALL (octave_history_write_timestamp, ()) if (Vsaving_history) - SAFE_CALL (command_history::clean_up_and_save, ()) + SAFE_CALL (command_history::clean_up_and_save, ()) SAFE_CALL (close_files, ()) @@ -1030,14 +1030,14 @@ SAFE_CALL (flush_octave_stdout, ()) if (! quitting_gracefully && (interactive || forced_interactive)) - { - octave_stdout << "\n"; + { + octave_stdout << "\n"; - // Yes, we want this to be separate from the call to - // flush_octave_stdout above. + // Yes, we want this to be separate from the call to + // flush_octave_stdout above. - SAFE_CALL (flush_octave_stdout, ()) - } + SAFE_CALL (flush_octave_stdout, ()) + } } } @@ -1056,11 +1056,11 @@ p != octave_atexit_functions.end (); p++) { if (*p == fname) - { - octave_atexit_functions.erase (p); - found = true; - break; - } + { + octave_atexit_functions.erase (p); + found = true; + break; + } } return found; @@ -1126,18 +1126,18 @@ } if (! error_state) - { - if (add_mode) - octave_add_atexit_function (arg); - else - { - bool found = octave_remove_atexit_function (arg); + { + if (add_mode) + octave_add_atexit_function (arg); + else + { + bool found = octave_remove_atexit_function (arg); - if (nargout > 0) - retval(0) = found; - } - } - } + if (nargout > 0) + retval(0) = found; + } + } + } else error ("atexit: argument must be a string"); } @@ -1348,32 +1348,32 @@ oct_mach_info::float_format ff = oct_mach_info::native_float_format (); m.assign ("float_format", - octave_value (oct_mach_info::float_format_as_string (ff))); + octave_value (oct_mach_info::float_format_as_string (ff))); m.assign ("words_big_endian", - octave_value (oct_mach_info::words_big_endian ())); + octave_value (oct_mach_info::words_big_endian ())); m.assign ("words_little_endian", - octave_value (oct_mach_info::words_little_endian ())); + octave_value (oct_mach_info::words_little_endian ())); int i = 0; while (true) - { - const conf_info_struct& elt = conf_info[i++]; + { + const conf_info_struct& elt = conf_info[i++]; - const char *key = elt.key; + const char *key = elt.key; - if (key) - { - if (elt.subst_home) - m.assign (key, octave_value (subst_octave_home (elt.val))); - else - m.assign (key, octave_value (elt.val)); - } - else - break; - } + if (key) + { + if (elt.subst_home) + m.assign (key, octave_value (subst_octave_home (elt.val))); + else + m.assign (key, octave_value (elt.val)); + } + else + break; + } bool unix_system = true; bool mac_system = false; @@ -1404,14 +1404,14 @@ std::string arg = args(0).string_value (); if (! error_state) - { - Cell c = m.contents (arg.c_str ()); + { + Cell c = m.contents (arg.c_str ()); - if (c.is_empty ()) - error ("octave_config_info: no info for `%s'", arg.c_str ()); - else - retval = c(0); - } + if (c.is_empty ()) + error ("octave_config_info: no info for `%s'", arg.c_str ()); + else + retval = c(0); + } } else if (nargin == 0) retval = m; diff --git a/src/txt-eng-ft.cc b/src/txt-eng-ft.cc --- a/src/txt-eng-ft.cc +++ b/src/txt-eng-ft.cc @@ -45,23 +45,23 @@ bool retval = true; if (! instance) - instance = new ft_manager (); + instance = new ft_manager (); if (! instance) - { - ::error ("unable to create ft_manager!"); + { + ::error ("unable to create ft_manager!"); - retval = false; - } + retval = false; + } return retval; } static FT_Face get_font (const std::string& name, const std::string& weight, - const std::string& angle, double size) + const std::string& angle, double size) { return (instance_ok () - ? instance->do_get_font (name, weight, angle, size) - : 0); } + ? instance->do_get_font (name, weight, angle, size) + : 0); } private: static ft_manager *instance; @@ -70,20 +70,20 @@ ft_manager (void) { if (FT_Init_FreeType (&library)) - { - ::error ("unable to initialize freetype library"); - } + { + ::error ("unable to initialize freetype library"); + } #if HAVE_FONTCONFIG fc_init_done = false; if (! FcInit ()) - { - ::error ("unable to initialize fontconfig library"); - } + { + ::error ("unable to initialize fontconfig library"); + } else - { - fc_init_done = true; - } + { + fc_init_done = true; + } #endif } @@ -96,7 +96,7 @@ } FT_Face do_get_font (const std::string& name, const std::string& weight, - const std::string& angle, double size) + const std::string& angle, double size) { FT_Face retval = 0; @@ -104,76 +104,76 @@ #if HAVE_FONTCONFIG if (fc_init_done) - { - int fc_weight, fc_angle; + { + int fc_weight, fc_angle; - if (weight == "bold") - fc_weight = FC_WEIGHT_BOLD; - else if (weight == "light") - fc_weight = FC_WEIGHT_LIGHT; - else if (weight == "demi") - fc_weight = FC_WEIGHT_DEMIBOLD; - else - fc_weight = FC_WEIGHT_NORMAL; + if (weight == "bold") + fc_weight = FC_WEIGHT_BOLD; + else if (weight == "light") + fc_weight = FC_WEIGHT_LIGHT; + else if (weight == "demi") + fc_weight = FC_WEIGHT_DEMIBOLD; + else + fc_weight = FC_WEIGHT_NORMAL; - if (angle == "italic") - fc_angle = FC_SLANT_ITALIC; - else if (angle == "oblique") - fc_angle = FC_SLANT_OBLIQUE; - else - fc_angle = FC_SLANT_ROMAN; + if (angle == "italic") + fc_angle = FC_SLANT_ITALIC; + else if (angle == "oblique") + fc_angle = FC_SLANT_OBLIQUE; + else + fc_angle = FC_SLANT_ROMAN; - FcPattern *pat = FcPatternCreate (); + FcPattern *pat = FcPatternCreate (); - FcPatternAddString (pat, FC_FAMILY, - (reinterpret_cast - (name == "*" ? "sans" : name.c_str ()))); + FcPatternAddString (pat, FC_FAMILY, + (reinterpret_cast + (name == "*" ? "sans" : name.c_str ()))); - FcPatternAddInteger (pat, FC_WEIGHT, fc_weight); - FcPatternAddInteger (pat, FC_SLANT, fc_angle); - FcPatternAddDouble (pat, FC_PIXEL_SIZE, size); + FcPatternAddInteger (pat, FC_WEIGHT, fc_weight); + FcPatternAddInteger (pat, FC_SLANT, fc_angle); + FcPatternAddDouble (pat, FC_PIXEL_SIZE, size); - if (FcConfigSubstitute (0, pat, FcMatchPattern)) - { - FcResult res; - FcPattern *match; + if (FcConfigSubstitute (0, pat, FcMatchPattern)) + { + FcResult res; + FcPattern *match; - FcDefaultSubstitute (pat); - match = FcFontMatch (0, pat, &res); + FcDefaultSubstitute (pat); + match = FcFontMatch (0, pat, &res); - // FIXME -- originally, this test also required that - // res != FcResultNoMatch. Is that really needed? - if (match) - { - unsigned char *tmp; + // FIXME -- originally, this test also required that + // res != FcResultNoMatch. Is that really needed? + if (match) + { + unsigned char *tmp; - FcPatternGetString (match, FC_FILE, 0, &tmp); - file = reinterpret_cast (tmp); - } - else - ::warning ("could not match any font: %s-%s-%s-%g", - name.c_str (), weight.c_str (), angle.c_str (), - size); + FcPatternGetString (match, FC_FILE, 0, &tmp); + file = reinterpret_cast (tmp); + } + else + ::warning ("could not match any font: %s-%s-%s-%g", + name.c_str (), weight.c_str (), angle.c_str (), + size); - if (match) - FcPatternDestroy (match); - } + if (match) + FcPatternDestroy (match); + } - FcPatternDestroy (pat); - } + FcPatternDestroy (pat); + } #endif if (file.empty ()) - { + { #ifdef __WIN32__ - file = "C:/WINDOWS/Fonts/verdana.ttf"; + file = "C:/WINDOWS/Fonts/verdana.ttf"; #else - // FIXME: find a "standard" font for UNIX platforms + // FIXME: find a "standard" font for UNIX platforms #endif - } + } if (! file.empty () && FT_New_Face (library, file.c_str (), 0, &retval)) - ::warning ("ft_manager: unable to load font: %s", file.c_str ()); + ::warning ("ft_manager: unable to load font: %s", file.c_str ()); return retval; } @@ -212,14 +212,14 @@ double font_size = props.get ("fontsize").double_value (); face = ft_manager::get_font (props.get ("fontname").string_value (), - props.get ("fontweight").string_value (), - props.get ("fontangle").string_value (), - font_size); + props.get ("fontweight").string_value (), + props.get ("fontangle").string_value (), + font_size); if (face) { if (FT_Set_Char_Size (face, 0, font_size*64, 0, 0)) - ::warning ("ft_render: unable to set font size to %d", font_size); + ::warning ("ft_render: unable to set font size to %d", font_size); } else ::warning ("ft_render: unable to load appropriate font"); @@ -238,19 +238,19 @@ break; case MODE_RENDER: if (bbox.numel () != 4) - { - ::warning ("ft_render: invalid bounding box, cannot render"); + { + ::warning ("ft_render: invalid bounding box, cannot render"); - xoffset = yoffset = 0; - pixels = uint8NDArray (); - } + xoffset = yoffset = 0; + pixels = uint8NDArray (); + } else - { - pixels = uint8NDArray (dim_vector (4, bbox(2), bbox(3)), - static_cast (0)); - xoffset = 0; - yoffset = -bbox(1)-1; - } + { + pixels = uint8NDArray (dim_vector (4, bbox(2), bbox(3)), + static_cast (0)); + xoffset = 0; + yoffset = -bbox(1)-1; + } break; default: ::error ("ft_render: invalid mode `%d'", mode); @@ -267,98 +267,98 @@ FT_UInt glyph_index, previous = 0; for (int i = 0; i < str.length (); i++) - { - glyph_index = FT_Get_Char_Index (face, str[i]); + { + glyph_index = FT_Get_Char_Index (face, str[i]); - if (! glyph_index - || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT)) - ::warning ("ft_render: skipping missing glyph for character `%c'", - str[i]); - else - { - switch (mode) - { - case MODE_RENDER: - if (FT_Render_Glyph (face->glyph, FT_RENDER_MODE_NORMAL)) - ::warning ("ft_render: unable to render glyph for character `%c'", - str[i]); - else - { - FT_Bitmap& bitmap = face->glyph->bitmap; - int x0, y0; + if (! glyph_index + || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT)) + ::warning ("ft_render: skipping missing glyph for character `%c'", + str[i]); + else + { + switch (mode) + { + case MODE_RENDER: + if (FT_Render_Glyph (face->glyph, FT_RENDER_MODE_NORMAL)) + ::warning ("ft_render: unable to render glyph for character `%c'", + str[i]); + else + { + FT_Bitmap& bitmap = face->glyph->bitmap; + int x0, y0; - if (previous) - { - FT_Vector delta; + if (previous) + { + FT_Vector delta; - FT_Get_Kerning (face, previous, glyph_index, FT_KERNING_DEFAULT, &delta); - xoffset += (delta.x >> 6); - } + FT_Get_Kerning (face, previous, glyph_index, FT_KERNING_DEFAULT, &delta); + xoffset += (delta.x >> 6); + } - x0 = xoffset+face->glyph->bitmap_left; - y0 = yoffset+face->glyph->bitmap_top; - for (int r = 0; r < bitmap.rows; r++) - for (int c = 0; c < bitmap.width; c++) - { - unsigned char pix = bitmap.buffer[r*bitmap.width+c]; - if (x0+c < 0 || x0+c >= pixels.dim2() - || y0-r < 0 || y0-r >= pixels.dim3()) - { - //::error ("out-of-bound indexing!!"); - } - else if (pixels(3, x0+c, y0-r).value () == 0) - { - pixels(0, x0+c, y0-r) = red; - pixels(1, x0+c, y0-r) = green; - pixels(2, x0+c, y0-r) = blue; - pixels(3, x0+c, y0-r) = pix; - } - } + x0 = xoffset+face->glyph->bitmap_left; + y0 = yoffset+face->glyph->bitmap_top; + for (int r = 0; r < bitmap.rows; r++) + for (int c = 0; c < bitmap.width; c++) + { + unsigned char pix = bitmap.buffer[r*bitmap.width+c]; + if (x0+c < 0 || x0+c >= pixels.dim2() + || y0-r < 0 || y0-r >= pixels.dim3()) + { + //::error ("out-of-bound indexing!!"); + } + else if (pixels(3, x0+c, y0-r).value () == 0) + { + pixels(0, x0+c, y0-r) = red; + pixels(1, x0+c, y0-r) = green; + pixels(2, x0+c, y0-r) = blue; + pixels(3, x0+c, y0-r) = pix; + } + } - xoffset += (face->glyph->advance.x >> 6); - } - break; + xoffset += (face->glyph->advance.x >> 6); + } + break; - case MODE_BBOX: - // width - if (previous) - { - FT_Vector delta; + case MODE_BBOX: + // width + if (previous) + { + FT_Vector delta; - FT_Get_Kerning (face, previous, glyph_index, FT_KERNING_DEFAULT, &delta); - bbox(2) += (delta.x >> 6); - } - bbox(2) += (face->glyph->advance.x >> 6); + FT_Get_Kerning (face, previous, glyph_index, FT_KERNING_DEFAULT, &delta); + bbox(2) += (delta.x >> 6); + } + bbox(2) += (face->glyph->advance.x >> 6); - int asc, desc; + int asc, desc; - if (false /*tight*/) - { - desc = face->glyph->metrics.horiBearingY - face->glyph->metrics.height; - asc = face->glyph->metrics.horiBearingY; - } - else - { - asc = face->size->metrics.ascender; - desc = face->size->metrics.descender; - } + if (false /*tight*/) + { + desc = face->glyph->metrics.horiBearingY - face->glyph->metrics.height; + asc = face->glyph->metrics.horiBearingY; + } + else + { + asc = face->size->metrics.ascender; + desc = face->size->metrics.descender; + } - asc = yoffset + (asc >> 6); - desc = yoffset + (desc >> 6); + asc = yoffset + (asc >> 6); + desc = yoffset + (desc >> 6); - if (desc < bbox(1)) - { - bbox(3) += (bbox(1) - desc); - bbox(1) = desc; - } - if (asc > (bbox(3)+bbox(1))) - bbox(3) = asc-bbox(1); - break; - } + if (desc < bbox(1)) + { + bbox(3) += (bbox(1) - desc); + bbox(1) = desc; + } + if (asc > (bbox(3)+bbox(1))) + bbox(3) = asc-bbox(1); + break; + } - previous = glyph_index; - } - } + previous = glyph_index; + } + } } } @@ -395,49 +395,49 @@ elt->accept (*this); switch (rotation) - { - case ROTATION_0: - break; - case ROTATION_90: - { - Array perm (3); - perm(0) = 0; - perm(1) = 2; - perm(2) = 1; - pixels = pixels.permute (perm); + { + case ROTATION_0: + break; + case ROTATION_90: + { + Array perm (3); + perm(0) = 0; + perm(1) = 2; + perm(2) = 1; + pixels = pixels.permute (perm); - Array idx (3); - idx(0) = idx_vector (':'); - idx(1) = idx_vector (pixels.dim2()-1, -1, -1); - idx(2) = idx_vector (':'); - pixels = uint8NDArray (pixels.index (idx)); - } - break; - case ROTATION_180: - { - Array idx (3); - idx(0) = idx_vector (':'); - idx(1) = idx_vector (pixels.dim2()-1, -1, -1); - idx(2)= idx_vector (pixels.dim3()-1, -1, -1); - pixels = uint8NDArray (pixels.index (idx)); - } - break; - case ROTATION_270: - { - Array perm (3); - perm(0) = 0; - perm(1) = 2; - perm(2) = 1; - pixels = pixels.permute (perm); + Array idx (3); + idx(0) = idx_vector (':'); + idx(1) = idx_vector (pixels.dim2()-1, -1, -1); + idx(2) = idx_vector (':'); + pixels = uint8NDArray (pixels.index (idx)); + } + break; + case ROTATION_180: + { + Array idx (3); + idx(0) = idx_vector (':'); + idx(1) = idx_vector (pixels.dim2()-1, -1, -1); + idx(2)= idx_vector (pixels.dim3()-1, -1, -1); + pixels = uint8NDArray (pixels.index (idx)); + } + break; + case ROTATION_270: + { + Array perm (3); + perm(0) = 0; + perm(1) = 2; + perm(2) = 1; + pixels = pixels.permute (perm); - Array idx (3); - idx(0) = idx_vector (':'); - idx(1) = idx_vector (':'); - idx(2) = idx_vector (pixels.dim3()-1, -1, -1); - pixels = uint8NDArray (pixels.index (idx)); - } - break; - } + Array idx (3); + idx(0) = idx_vector (':'); + idx(1) = idx_vector (':'); + idx(2) = idx_vector (pixels.dim3()-1, -1, -1); + pixels = uint8NDArray (pixels.index (idx)); + } + break; + } } return pixels; diff --git a/src/utils.cc b/src/utils.cc --- a/src/utils.cc +++ b/src/utils.cc @@ -119,23 +119,23 @@ int almost_match (const std::string& std, const std::string& s, int min_match_len, - int case_sens) + int case_sens) { int stdlen = std.length (); int slen = s.length (); return (slen <= stdlen - && slen >= min_match_len - && (case_sens - ? (strncmp (std.c_str (), s.c_str (), slen) == 0) - : (octave_strncasecmp (std.c_str (), s.c_str (), slen) == 0))); + && slen >= min_match_len + && (case_sens + ? (strncmp (std.c_str (), s.c_str (), slen) == 0) + : (octave_strncasecmp (std.c_str (), s.c_str (), slen) == 0))); } // Ugh. int keyword_almost_match (const char * const *std, int *min_len, const std::string& s, - int min_toks_to_match, int max_toks) + int min_toks_to_match, int max_toks) { int status = 0; int tok_count = 0; @@ -150,7 +150,7 @@ while (*t != '\0') { if (*t == '\t') - *t = ' '; + *t = ' '; t++; } @@ -177,14 +177,14 @@ beg = end + 1; while (*beg == ' ') - beg++; + beg++; if (*beg == '\0') - break; + break; tok_count++; if (tok_count >= max_toks) - goto done; + goto done; s2[tok_count] = beg; } @@ -195,7 +195,7 @@ for (;;) { if (! almost_match (*s1, *s2, min_len[toks_matched], 0)) - goto done; + goto done; toks_matched++; @@ -203,13 +203,13 @@ s2++; if (! *s2) - { - status = (toks_matched >= min_toks_to_match); - goto done; - } + { + status = (toks_matched >= min_toks_to_match); + goto done; + } if (! *s1) - goto done; + goto done; } done: @@ -297,30 +297,30 @@ string_vector names = args(0).all_strings (); if (! error_state && names.length () > 0) - { - if (nargin == 1) - { - std::string fname + { + if (nargin == 1) + { + std::string fname = octave_env::make_absolute (load_path::find_first_of (names)); - if (fname.empty ()) - retval = Matrix (); - else - retval = fname; - } - else if (nargin == 2) - { - std::string opt = args(1).string_value (); + if (fname.empty ()) + retval = Matrix (); + else + retval = fname; + } + else if (nargin == 2) + { + std::string opt = args(1).string_value (); - if (! error_state && opt == "all") - retval = Cell (make_absolute + if (! error_state && opt == "all") + retval = Cell (make_absolute (load_path::find_all_first_of (names))); - else - error ("file_in_loadpath: invalid option"); - } - } + else + error ("file_in_loadpath: invalid option"); + } + } else - error ("file_in_loadpath: expecting string as first argument"); + error ("file_in_loadpath: expecting string as first argument"); } else print_usage (); @@ -363,36 +363,36 @@ std::string path = args(0).string_value (); if (! error_state) - { - string_vector names = args(1).all_strings (); + { + string_vector names = args(1).all_strings (); - if (! error_state && names.length () > 0) - { - if (nargin == 2) - { - std::string fname = search_path_for_file (path, names); + if (! error_state && names.length () > 0) + { + if (nargin == 2) + { + std::string fname = search_path_for_file (path, names); - if (fname.empty ()) - retval = Matrix (); - else - retval = fname; - } - else if (nargin == 3) - { - std::string opt = args(2).string_value (); + if (fname.empty ()) + retval = Matrix (); + else + retval = fname; + } + else if (nargin == 3) + { + std::string opt = args(2).string_value (); - if (! error_state && opt == "all") - retval = Cell (make_absolute + if (! error_state && opt == "all") + retval = Cell (make_absolute (search_path_for_all_files (path, names))); - else - error ("file_in_path: invalid option"); - } - } - else - error ("file_in_path: expecting string as second argument"); - } + else + error ("file_in_path: invalid option"); + } + } + else + error ("file_in_path: expecting string as second argument"); + } else - error ("file_in_path: expecting string as first argument"); + error ("file_in_path: expecting string as first argument"); } else print_usage (); @@ -424,23 +424,23 @@ if (len > 0) { if (octave_env::absolute_pathname (name)) - { - file_stat fs (name); + { + file_stat fs (name); - if (fs.exists ()) - retval = name; - } + if (fs.exists ()) + retval = name; + } else if (len > 2 && name [len - 2] == '.' && name [len - 1] == 'm') - retval = load_path::find_fcn_file (name.substr (0, len-2)); + retval = load_path::find_fcn_file (name.substr (0, len-2)); else - { - std::string fname = name; - size_t pos = name.find_first_of (Vfilemarker); - if (pos != std::string::npos) - fname = name.substr (0, pos); + { + std::string fname = name; + size_t pos = name.find_first_of (Vfilemarker); + if (pos != std::string::npos) + fname = name.substr (0, pos); - retval = load_path::find_fcn_file (fname); - } + retval = load_path::find_fcn_file (fname); + } } return retval; @@ -457,12 +457,12 @@ if (dir.length () > 0) { std::string tcontents = file_ops::concat (load_path::find_dir (dir), - std::string ("Contents.m")); + std::string ("Contents.m")); file_stat fs (tcontents); if (fs.exists ()) - retval = octave_env::make_absolute (tcontents); + retval = octave_env::make_absolute (tcontents); } return retval; @@ -481,17 +481,17 @@ if (len > 0) { if (octave_env::absolute_pathname (name)) - { - file_stat fs (name); + { + file_stat fs (name); - if (fs.exists ()) - retval = name; - } + if (fs.exists ()) + retval = name; + } else if (len > 4 && name [len - 4] == '.' && name [len - 3] == 'o' - && name [len - 2] == 'c' && name [len - 1] == 't') - retval = load_path::find_oct_file (name.substr (0, len-4)); + && name [len - 2] == 'c' && name [len - 1] == 't') + retval = load_path::find_oct_file (name.substr (0, len-4)); else - retval = load_path::find_oct_file (name); + retval = load_path::find_oct_file (name); } return retval; @@ -510,17 +510,17 @@ if (len > 0) { if (octave_env::absolute_pathname (name)) - { - file_stat fs (name); + { + file_stat fs (name); - if (fs.exists ()) - retval = name; - } + if (fs.exists ()) + retval = name; + } else if (len > 4 && name [len - 4] == '.' && name [len - 3] == 'm' - && name [len - 2] == 'e' && name [len - 1] == 'x') - retval = load_path::find_mex_file (name.substr (0, len-4)); + && name [len - 2] == 'e' && name [len - 1] == 'x') + retval = load_path::find_mex_file (name.substr (0, len-4)); else - retval = load_path::find_mex_file (name); + retval = load_path::find_mex_file (name); } return retval; @@ -542,64 +542,64 @@ while (j < len) { if (s[j] == '\\' && j+1 < len) - { - switch (s[++j]) - { - case '0': - retval[i] = '\0'; - break; + { + switch (s[++j]) + { + case '0': + retval[i] = '\0'; + break; - case 'a': - retval[i] = '\a'; - break; + case 'a': + retval[i] = '\a'; + break; - case 'b': // backspace - retval[i] = '\b'; - break; + case 'b': // backspace + retval[i] = '\b'; + break; - case 'f': // formfeed - retval[i] = '\f'; - break; + case 'f': // formfeed + retval[i] = '\f'; + break; - case 'n': // newline - retval[i] = '\n'; - break; + case 'n': // newline + retval[i] = '\n'; + break; - case 'r': // carriage return - retval[i] = '\r'; - break; + case 'r': // carriage return + retval[i] = '\r'; + break; - case 't': // horizontal tab - retval[i] = '\t'; - break; + case 't': // horizontal tab + retval[i] = '\t'; + break; - case 'v': // vertical tab - retval[i] = '\v'; - break; + case 'v': // vertical tab + retval[i] = '\v'; + break; - case '\\': // backslash - retval[i] = '\\'; - break; + case '\\': // backslash + retval[i] = '\\'; + break; - case '\'': // quote - retval[i] = '\''; - break; + case '\'': // quote + retval[i] = '\''; + break; - case '"': // double quote - retval[i] = '"'; - break; + case '"': // double quote + retval[i] = '"'; + break; - default: - warning ("unrecognized escape sequence `\\%c' --\ + default: + warning ("unrecognized escape sequence `\\%c' --\ converting to `%c'", s[j], s[j]); - retval[i] = s[j]; - break; - } - } + retval[i] = s[j]; + break; + } + } else - { - retval[i] = s[j]; - } + { + retval[i] = s[j]; + } i++; j++; @@ -623,9 +623,9 @@ if (nargin == 1) { if (args(0).is_string ()) - retval = do_string_escapes (args(0).string_value ()); + retval = do_string_escapes (args(0).string_value ()); else - error ("do_string_escapes: argument must be a string"); + error ("do_string_escapes: argument must be a string"); } else print_usage (); @@ -673,10 +673,10 @@ default: { - static char retval[2]; - retval[0] = c; - retval[1] = '\0'; - return retval; + static char retval[2]; + retval[0] = c; + retval[1] = '\0'; + return retval; } } } @@ -729,9 +729,9 @@ if (nargin == 1) { if (args(0).is_string ()) - retval = undo_string_escapes (args(0).string_value ()); + retval = undo_string_escapes (args(0).string_value ()); else - error ("undo_string_escapes: argument must be a string"); + error ("undo_string_escapes: argument must be a string"); } else print_usage (); @@ -749,7 +749,7 @@ if (args.length () == 1) retval = (args(0).is_string () - && octave_env::absolute_pathname (args(0).string_value ())); + && octave_env::absolute_pathname (args(0).string_value ())); else print_usage (); @@ -766,7 +766,7 @@ if (args.length () == 1) retval = (args(0).is_string () - && octave_env::rooted_relative_pathname (args(0).string_value ())); + && octave_env::rooted_relative_pathname (args(0).string_value ())); else print_usage (); @@ -786,9 +786,9 @@ std::string nm = args(0).string_value (); if (! error_state) - retval = octave_env::make_absolute (nm); + retval = octave_env::make_absolute (nm); else - error ("make_absolute_filename: expecting argument to be a file name"); + error ("make_absolute_filename: expecting argument to be a file name"); } else print_usage (); @@ -820,14 +820,14 @@ dir = args(0).string_value (); if (! error_state) - { - if (nargin == 1) - retval = load_path::find_dir (dir); - else if (nargin == 2) - retval = Cell (load_path::find_matching_dirs (dir)); - } + { + if (nargin == 1) + retval = load_path::find_dir (dir); + else if (nargin == 2) + retval = Cell (load_path::find_matching_dirs (dir)); + } else - error ("find_dir_in_path: expecting argument to be a directory name"); + error ("find_dir_in_path: expecting argument to be a directory name"); } else print_usage (); @@ -853,23 +853,23 @@ if (nargin == 1) { if (args(0).is_string ()) - { - std::string nm = args(0).string_value (); + { + std::string nm = args(0).string_value (); - if (! error_state) - retval = octave_errno::lookup (nm); - else - error ("errno: expecting character string argument"); - } + if (! error_state) + retval = octave_errno::lookup (nm); + else + error ("errno: expecting character string argument"); + } else - { - int val = args(0).int_value (); + { + int val = args(0).int_value (); - if (! error_state) - retval = octave_errno::set (val); - else - error ("errno: expecting integer argument"); - } + if (! error_state) + retval = octave_errno::set (val); + else + error ("errno: expecting integer argument"); + } } else if (nargin == 0) retval = octave_errno::get (); @@ -901,7 +901,7 @@ if (nr < 0 || nc < 0) { warning_with_id ("Octave:neg-dim-as-zero", - "%s: converting negative dimension to zero", warnfor); + "%s: converting negative dimension to zero", warnfor); nr = (nr < 0) ? 0 : nr; nc = (nc < 0) ? 0 : nc; @@ -924,7 +924,7 @@ if (neg) warning_with_id ("Octave:neg-dim-as-zero", - "%s: converting negative dimension to zero", warnfor); + "%s: converting negative dimension to zero", warnfor); } @@ -966,7 +966,7 @@ void get_dimensions (const octave_value& a, const char *warn_for, - octave_idx_type& nr, octave_idx_type& nc) + octave_idx_type& nr, octave_idx_type& nc) { if (a.is_scalar_type ()) { @@ -978,17 +978,17 @@ nc = a.columns (); if ((nr == 1 && nc == 2) || (nr == 2 && nc == 1)) - { - Array v = a.vector_value (); + { + Array v = a.vector_value (); - if (error_state) - return; + if (error_state) + return; - nr = static_cast (fix (v (0))); - nc = static_cast (fix (v (1))); - } + nr = static_cast (fix (v (0))); + nc = static_cast (fix (v (1))); + } else - error ("%s (A): use %s (size (A)) instead", warn_for, warn_for); + error ("%s (A): use %s (size (A)) instead", warn_for, warn_for); } if (! error_state) @@ -997,7 +997,7 @@ void get_dimensions (const octave_value& a, const octave_value& b, - const char *warn_for, octave_idx_type& nr, octave_idx_type& nc) + const char *warn_for, octave_idx_type& nr, octave_idx_type& nc) { nr = a.is_empty () ? 0 : a.int_value (); nc = b.is_empty () ? 0 : b.int_value (); @@ -1043,8 +1043,8 @@ void decode_subscripts (const char* name, const octave_value& arg, - std::string& type_string, - std::list& idx) + std::string& type_string, + std::list& idx) { Octave_map m = arg.map_value (); @@ -1057,56 +1057,56 @@ type_string = std::string (type.length(), '\0'); for (int k = 0; k < type.length (); k++) - { - std::string item = type(k).string_value (); + { + std::string item = type(k).string_value (); - if (! error_state) - { - if (item == "{}") - type_string[k] = '{'; - else if (item == "()") - type_string[k] = '('; - else if (item == ".") - type_string[k] = '.'; - else - { - error("%s: invalid indexing type `%s'", name, item.c_str ()); - return; - } - } - else - { - error ("%s: expecting type(%d) to be a character string", - name, k+1); - return; - } + if (! error_state) + { + if (item == "{}") + type_string[k] = '{'; + else if (item == "()") + type_string[k] = '('; + else if (item == ".") + type_string[k] = '.'; + else + { + error("%s: invalid indexing type `%s'", name, item.c_str ()); + return; + } + } + else + { + error ("%s: expecting type(%d) to be a character string", + name, k+1); + return; + } - octave_value_list idx_item; + octave_value_list idx_item; - if (subs(k).is_string ()) - idx_item(0) = subs(k); - else if (subs(k).is_cell ()) - { - Cell subs_cell = subs(k).cell_value (); + if (subs(k).is_string ()) + idx_item(0) = subs(k); + else if (subs(k).is_cell ()) + { + Cell subs_cell = subs(k).cell_value (); - for (int n = 0; n < subs_cell.length (); n++) - { - if (subs_cell(n).is_string () - && subs_cell(n).string_value () == ":") - idx_item(n) = octave_value(octave_value::magic_colon_t); - else - idx_item(n) = subs_cell(n); - } - } - else - { - error ("%s: expecting subs(%d) to be a character string or cell array", - name, k+1); - return; - } + for (int n = 0; n < subs_cell.length (); n++) + { + if (subs_cell(n).is_string () + && subs_cell(n).string_value () == ":") + idx_item(n) = octave_value(octave_value::magic_colon_t); + else + idx_item(n) = subs_cell(n); + } + } + else + { + error ("%s: expecting subs(%d) to be a character string or cell array", + name, k+1); + return; + } - idx.push_back (idx_item); - } + idx.push_back (idx_item); + } } else error ("%s: second argument must be a structure with fields `type' and `subs'", name); @@ -1122,7 +1122,7 @@ octave_idx_type n = std::min (nr, nc); for (octave_idx_type i = 0; i < n; i++) - m (i, i) = 1.0; + m (i, i) = 1.0; } return m; @@ -1138,7 +1138,7 @@ octave_idx_type n = std::min (nr, nc); for (octave_idx_type i = 0; i < n; i++) - m (i, i) = 1.0; + m (i, i) = 1.0; } return m; @@ -1288,10 +1288,10 @@ double t; unsigned int usec - = static_cast (modf (seconds, &t) * 1000000); + = static_cast (modf (seconds, &t) * 1000000); unsigned int sec - = (t > UINT_MAX) ? UINT_MAX : static_cast (t); + = (t > UINT_MAX) ? UINT_MAX : static_cast (t); // Versions of these functions that accept unsigned int args are // defined in cutils.c. diff --git a/src/variables.cc b/src/variables.cc --- a/src/variables.cc +++ b/src/variables.cc @@ -96,7 +96,7 @@ octave_function * is_valid_function (const std::string& fcn_name, - const std::string& warn_for, bool warn) + const std::string& warn_for, bool warn) { octave_function *ans = 0; @@ -105,19 +105,19 @@ octave_value val = symbol_table::find_function (fcn_name); if (val.is_defined ()) - ans = val.function_value (true); + ans = val.function_value (true); } if (! ans && warn) error ("%s: the symbol `%s' is not valid as a function", - warn_for.c_str (), fcn_name.c_str ()); + warn_for.c_str (), fcn_name.c_str ()); return ans; } octave_function * is_valid_function (const octave_value& arg, - const std::string& warn_for, bool warn) + const std::string& warn_for, bool warn) { octave_function *ans = 0; @@ -128,9 +128,9 @@ fcn_name = arg.string_value (); if (! error_state) - ans = is_valid_function (fcn_name, warn_for, warn); + ans = is_valid_function (fcn_name, warn_for, warn); else if (warn) - error ("%s: expecting function name as argument", warn_for.c_str ()); + error ("%s: expecting function name as argument", warn_for.c_str ()); } else if (warn) error ("%s: expecting function name as argument", warn_for.c_str ()); @@ -140,8 +140,8 @@ octave_function * extract_function (const octave_value& arg, const std::string& warn_for, - const std::string& fname, const std::string& header, - const std::string& trailer) + const std::string& fname, const std::string& header, + const std::string& trailer) { octave_function *retval = 0; @@ -156,32 +156,32 @@ cmd.append (trailer); if (! error_state) - { - int parse_status; + { + int parse_status; - eval_string (cmd, true, parse_status, 0); + eval_string (cmd, true, parse_status, 0); - if (parse_status == 0) - { - retval = is_valid_function (fname, warn_for, 0); + if (parse_status == 0) + { + retval = is_valid_function (fname, warn_for, 0); - if (! retval) - { - error ("%s: `%s' is not valid as a function", - warn_for.c_str (), fname.c_str ()); - return retval; - } + if (! retval) + { + error ("%s: `%s' is not valid as a function", + warn_for.c_str (), fname.c_str ()); + return retval; + } warning ("%s: passing function body as a string is obsolete." " Please use anonymous functions.", warn_for.c_str ()); - } - else - error ("%s: `%s' is not valid as a function", - warn_for.c_str (), fname.c_str ()); - } + } + else + error ("%s: `%s' is not valid as a function", + warn_for.c_str (), fname.c_str ()); + } else - error ("%s: expecting first argument to be a string", - warn_for.c_str ()); + error ("%s: expecting first argument to be a string", + warn_for.c_str ()); } return retval; @@ -199,7 +199,7 @@ while ((pos = text.find ('.', pos)) != std::string::npos) { if (++pos == len) - break; + break; n++; } @@ -213,12 +213,12 @@ len = text.find ('.', pos); if (len != std::string::npos) - len -= pos; + len -= pos; retval[i] = text.substr (pos, len); if (len != std::string::npos) - pos += len + 1; + pos += len + 1; } return retval; @@ -241,7 +241,7 @@ string_vector generate_struct_completions (const std::string& text, - std::string& prefix, std::string& hint) + std::string& prefix, std::string& hint) { string_vector names; @@ -250,9 +250,9 @@ if (pos != std::string::npos) { if (pos == text.length ()) - hint = ""; + hint = ""; else - hint = text.substr (pos+1); + hint = text.substr (pos+1); prefix = text.substr (0, pos); @@ -261,30 +261,30 @@ pos = base_name.find_first_of ("{(."); if (pos != std::string::npos) - base_name = base_name.substr (0, pos); + base_name = base_name.substr (0, pos); if (is_variable (base_name)) - { - int parse_status; + { + int parse_status; - unwind_protect frame; + unwind_protect frame; - frame.protect_var (error_state); - frame.protect_var (warning_state); + frame.protect_var (error_state); + frame.protect_var (warning_state); - frame.protect_var (discard_error_messages); - frame.protect_var (discard_warning_messages); + frame.protect_var (discard_error_messages); + frame.protect_var (discard_warning_messages); - discard_error_messages = true; - discard_warning_messages = true; + discard_error_messages = true; + discard_warning_messages = true; - octave_value tmp = eval_string (prefix, true, parse_status); + octave_value tmp = eval_string (prefix, true, parse_status); - frame.run (); + frame.run (); - if (tmp.is_defined () && tmp.is_map ()) - names = tmp.map_keys (); - } + if (tmp.is_defined () && tmp.is_map ()) + names = tmp.map_keys (); + } } return names; @@ -297,10 +297,10 @@ looks_like_struct (const std::string& text) { bool retval = (! text.empty () - && text != "." - && text.find_first_of (file_ops::dir_sep_chars ()) == std::string::npos - && text.find ("..") == std::string::npos - && text.rfind ('.') != std::string::npos); + && text != "." + && text.find_first_of (file_ops::dir_sep_chars ()) == std::string::npos + && text.find ("..") == std::string::npos + && text.rfind ('.') != std::string::npos); #if 0 symbol_record *sr = curr_sym_tab->lookup (text); @@ -428,82 +428,82 @@ bool var_ok = not_a_struct /* || val.is_map_element (struct_elts) */; if (! retval - && var_ok - && (type == "any" || type == "var") - && (val.is_constant () || val.is_object () - || val.is_inline_function () || val.is_function_handle ())) - { - retval = 1; - } + && var_ok + && (type == "any" || type == "var") + && (val.is_constant () || val.is_object () + || val.is_inline_function () || val.is_function_handle ())) + { + retval = 1; + } if (! retval - && (type == "any" || type == "builtin")) - { - if (not_a_struct && val.is_builtin_function ()) - { - retval = 5; - } - } + && (type == "any" || type == "builtin")) + { + if (not_a_struct && val.is_builtin_function ()) + { + retval = 5; + } + } if (! retval - && not_a_struct - && (type == "any" || type == "file") - && (val.is_user_function () || val.is_dld_function ())) - { - octave_function *f = val.function_value (true); - std::string s = f ? f->fcn_file_name () : std::string (); + && not_a_struct + && (type == "any" || type == "file") + && (val.is_user_function () || val.is_dld_function ())) + { + octave_function *f = val.function_value (true); + std::string s = f ? f->fcn_file_name () : std::string (); - retval = s.empty () ? 103 : (val.is_user_function () ? 2 : 3); - } + retval = s.empty () ? 103 : (val.is_user_function () ? 2 : 3); + } } if (! (type == "var" || type == "builtin")) { if (! retval) - { - std::string file_name = lookup_autoload (name); + { + std::string file_name = lookup_autoload (name); - if (file_name.empty ()) - file_name = load_path::find_fcn (name); + if (file_name.empty ()) + file_name = load_path::find_fcn (name); - size_t len = file_name.length (); + size_t len = file_name.length (); - if (len > 0) - { - if (type == "any" || type == "file") - { - if (len > 4 && (file_name.substr (len-4) == ".oct" - || file_name.substr (len-4) == ".mex")) - retval = 3; - else - retval = 2; - } - } - } + if (len > 0) + { + if (type == "any" || type == "file") + { + if (len > 4 && (file_name.substr (len-4) == ".oct" + || file_name.substr (len-4) == ".mex")) + retval = 3; + else + retval = 2; + } + } + } if (! retval) - { - std::string file_name = file_in_path (name, ""); + { + std::string file_name = file_in_path (name, ""); - if (file_name.empty ()) - file_name = name; + if (file_name.empty ()) + file_name = name; - file_stat fs (file_name); + file_stat fs (file_name); - if (fs) - { - if ((type == "any" || type == "file") - && fs.is_reg ()) - { - retval = 2; - } - else if ((type == "any" || type == "dir") - && fs.is_dir ()) - { - retval = 7; - } - } - } + if (fs) + { + if ((type == "any" || type == "file") + && fs.is_reg ()) + { + retval = 2; + } + else if ((type == "any" || type == "dir") + && fs.is_dir ()) + { + retval = 7; + } + } + } } return retval; @@ -575,17 +575,17 @@ std::string name = args(0).string_value (); if (! error_state) - { - std::string type - = (nargin == 2) ? args(1).string_value () : std::string ("any"); + { + std::string type + = (nargin == 2) ? args(1).string_value () : std::string ("any"); - if (! error_state) - retval = symbol_exist (name, type); - else - error ("exist: expecting second argument to be a string"); - } + if (! error_state) + retval = symbol_exist (name, type); + else + error ("exist: expecting second argument to be a string"); + } else - error ("exist: expecting first argument to be a string"); + error ("exist: expecting first argument to be a string"); } else print_usage (); @@ -639,7 +639,7 @@ octave_value set_internal_variable (bool& var, const octave_value_list& args, - int nargout, const char *nm) + int nargout, const char *nm) { octave_value retval; @@ -653,9 +653,9 @@ bool bval = args(0).bool_value (); if (! error_state) - var = bval; + var = bval; else - error ("%s: expecting arg to be a logical value", nm); + error ("%s: expecting arg to be a logical value", nm); } else if (nargin > 1) print_usage (); @@ -665,7 +665,7 @@ octave_value set_internal_variable (char& var, const octave_value_list& args, - int nargout, const char *nm) + int nargout, const char *nm) { octave_value retval; @@ -679,24 +679,24 @@ std::string sval = args(0).string_value (); if (! error_state) - { - switch (sval.length ()) - { - case 1: - var = sval[0]; - break; + { + switch (sval.length ()) + { + case 1: + var = sval[0]; + break; - case 0: - var = '\0'; - break; + case 0: + var = '\0'; + break; - default: - error ("%s: argument must be a single character", nm); - break; - } - } + default: + error ("%s: argument must be a single character", nm); + break; + } + } else - error ("%s: argument must be a single character", nm); + error ("%s: argument must be a single character", nm); } else if (nargin > 1) print_usage (); @@ -706,8 +706,8 @@ octave_value set_internal_variable (int& var, const octave_value_list& args, - int nargout, const char *nm, - int minval, int maxval) + int nargout, const char *nm, + int minval, int maxval) { octave_value retval; @@ -721,17 +721,17 @@ int ival = args(0).int_value (); if (! error_state) - { - if (ival < minval) - error ("%s: expecting arg to be greater than %d", nm, minval); - else if (ival > maxval) - error ("%s: expecting arg to be less than or equal to %d", - nm, maxval); - else - var = ival; - } + { + if (ival < minval) + error ("%s: expecting arg to be greater than %d", nm, minval); + else if (ival > maxval) + error ("%s: expecting arg to be less than or equal to %d", + nm, maxval); + else + var = ival; + } else - error ("%s: expecting arg to be an integer value", nm); + error ("%s: expecting arg to be an integer value", nm); } else if (nargin > 1) print_usage (); @@ -741,8 +741,8 @@ octave_value set_internal_variable (double& var, const octave_value_list& args, - int nargout, const char *nm, - double minval, double maxval) + int nargout, const char *nm, + double minval, double maxval) { octave_value retval; @@ -756,16 +756,16 @@ double dval = args(0).scalar_value (); if (! error_state) - { - if (dval < minval) - error ("%s: expecting arg to be greater than %g", minval); - else if (dval > maxval) - error ("%s: expecting arg to be less than or equal to %g", maxval); - else - var = dval; - } + { + if (dval < minval) + error ("%s: expecting arg to be greater than %g", minval); + else if (dval > maxval) + error ("%s: expecting arg to be less than or equal to %g", maxval); + else + var = dval; + } else - error ("%s: expecting arg to be a scalar value", nm); + error ("%s: expecting arg to be a scalar value", nm); } else if (nargin > 1) print_usage (); @@ -775,7 +775,7 @@ octave_value set_internal_variable (std::string& var, const octave_value_list& args, - int nargout, const char *nm, bool empty_ok) + int nargout, const char *nm, bool empty_ok) { octave_value retval; @@ -789,14 +789,14 @@ std::string sval = args(0).string_value (); if (! error_state) - { - if (empty_ok || ! sval.empty ()) - var = sval; - else - error ("%s: value must not be empty", nm); - } + { + if (empty_ok || ! sval.empty ()) + var = sval; + else + error ("%s: value must not be empty", nm); + } else - error ("%s: expecting arg to be a character string", nm); + error ("%s: expecting arg to be a character string", nm); } else if (nargin > 1) print_usage (); @@ -829,73 +829,73 @@ if (param.command != '\0') { - // Do the actual printing - switch (param.modifier) - { - case 'l': - os << std::setiosflags (std::ios::left) << std::setw (param.parameter_length); - param_buf << std::setiosflags (std::ios::left) << std::setw (param.parameter_length); - break; + // Do the actual printing + switch (param.modifier) + { + case 'l': + os << std::setiosflags (std::ios::left) << std::setw (param.parameter_length); + param_buf << std::setiosflags (std::ios::left) << std::setw (param.parameter_length); + break; - case 'r': - os << std::setiosflags (std::ios::right) << std::setw (param.parameter_length); - param_buf << std::setiosflags (std::ios::right) << std::setw (param.parameter_length); - break; + case 'r': + os << std::setiosflags (std::ios::right) << std::setw (param.parameter_length); + param_buf << std::setiosflags (std::ios::right) << std::setw (param.parameter_length); + break; - case 'c': - if (param.command != 's') - { - os << std::setiosflags (std::ios::left) - << std::setw (param.parameter_length); - param_buf << std::setiosflags (std::ios::left) - << std::setw (param.parameter_length); - } - break; + case 'c': + if (param.command != 's') + { + os << std::setiosflags (std::ios::left) + << std::setw (param.parameter_length); + param_buf << std::setiosflags (std::ios::left) + << std::setw (param.parameter_length); + } + break; - default: - os << std::setiosflags (std::ios::left) << std::setw (param.parameter_length); - param_buf << std::setiosflags (std::ios::left) << std::setw (param.parameter_length); - } + default: + os << std::setiosflags (std::ios::left) << std::setw (param.parameter_length); + param_buf << std::setiosflags (std::ios::left) << std::setw (param.parameter_length); + } - if (param.command == 's' && param.modifier == 'c') - { - int a, b; - - if (param.modifier == 'c') - { - a = param.first_parameter_length - param.balance; - a = (a < 0 ? 0 : a); - b = param.parameter_length - a - param.text . length (); - b = (b < 0 ? 0 : b); - os << std::setiosflags (std::ios::left) << std::setw (a) - << "" << std::resetiosflags (std::ios::left) << param.text - << std::setiosflags (std::ios::left) - << std::setw (b) << "" - << std::resetiosflags (std::ios::left); - param_buf << std::setiosflags (std::ios::left) << std::setw (a) - << "" << std::resetiosflags (std::ios::left) << param.line - << std::setiosflags (std::ios::left) - << std::setw (b) << "" - << std::resetiosflags (std::ios::left); - } - } - else - { - os << param.text; - param_buf << param.line; - } - os << std::resetiosflags (std::ios::left) - << std::resetiosflags (std::ios::right); - param_buf << std::resetiosflags (std::ios::left) - << std::resetiosflags (std::ios::right); - i++; - } + if (param.command == 's' && param.modifier == 'c') + { + int a, b; + + if (param.modifier == 'c') + { + a = param.first_parameter_length - param.balance; + a = (a < 0 ? 0 : a); + b = param.parameter_length - a - param.text . length (); + b = (b < 0 ? 0 : b); + os << std::setiosflags (std::ios::left) << std::setw (a) + << "" << std::resetiosflags (std::ios::left) << param.text + << std::setiosflags (std::ios::left) + << std::setw (b) << "" + << std::resetiosflags (std::ios::left); + param_buf << std::setiosflags (std::ios::left) << std::setw (a) + << "" << std::resetiosflags (std::ios::left) << param.line + << std::setiosflags (std::ios::left) + << std::setw (b) << "" + << std::resetiosflags (std::ios::left); + } + } + else + { + os << param.text; + param_buf << param.line; + } + os << std::resetiosflags (std::ios::left) + << std::resetiosflags (std::ios::right); + param_buf << std::resetiosflags (std::ios::left) + << std::resetiosflags (std::ios::right); + i++; + } else - { - os << param.text; - param_buf << param.line; - i++; - } + { + os << param.text; + param_buf << param.line; + i++; + } } os << param_buf.str (); @@ -928,135 +928,135 @@ struct symbol_info { symbol_info (const symbol_table::symbol_record& sr, - const std::string& expr_str = std::string (), - const octave_value& expr_val = octave_value ()) + const std::string& expr_str = std::string (), + const octave_value& expr_val = octave_value ()) : name (expr_str.empty () ? sr.name () : expr_str), - is_automatic (sr.is_automatic ()), - is_formal (sr.is_formal ()), - is_global (sr.is_global ()), - is_persistent (sr.is_persistent ()), - varval (expr_val.is_undefined () ? sr.varval () : expr_val) + is_automatic (sr.is_automatic ()), + is_formal (sr.is_formal ()), + is_global (sr.is_global ()), + is_persistent (sr.is_persistent ()), + varval (expr_val.is_undefined () ? sr.varval () : expr_val) { } void display_line (std::ostream& os, - const std::list& params) const + const std::list& params) const { std::string dims_str = get_dims_str (varval); std::list::const_iterator i = params.begin (); while (i != params.end ()) - { - whos_parameter param = *i; + { + whos_parameter param = *i; - if (param.command != '\0') - { - // Do the actual printing. + if (param.command != '\0') + { + // Do the actual printing. - switch (param.modifier) - { - case 'l': - os << std::setiosflags (std::ios::left) - << std::setw (param.parameter_length); - break; + switch (param.modifier) + { + case 'l': + os << std::setiosflags (std::ios::left) + << std::setw (param.parameter_length); + break; - case 'r': - os << std::setiosflags (std::ios::right) - << std::setw (param.parameter_length); - break; + case 'r': + os << std::setiosflags (std::ios::right) + << std::setw (param.parameter_length); + break; - case 'c': - if (param.command == 's') - { - int front = param.first_parameter_length - - dims_str.find ('x'); - int back = param.parameter_length - - dims_str.length () - - front; - front = (front > 0) ? front : 0; - back = (back > 0) ? back : 0; + case 'c': + if (param.command == 's') + { + int front = param.first_parameter_length + - dims_str.find ('x'); + int back = param.parameter_length + - dims_str.length () + - front; + front = (front > 0) ? front : 0; + back = (back > 0) ? back : 0; - os << std::setiosflags (std::ios::left) - << std::setw (front) - << "" - << std::resetiosflags (std::ios::left) - << dims_str - << std::setiosflags (std::ios::left) - << std::setw (back) - << "" - << std::resetiosflags (std::ios::left); - } - else - { - os << std::setiosflags (std::ios::left) - << std::setw (param.parameter_length); - } - break; + os << std::setiosflags (std::ios::left) + << std::setw (front) + << "" + << std::resetiosflags (std::ios::left) + << dims_str + << std::setiosflags (std::ios::left) + << std::setw (back) + << "" + << std::resetiosflags (std::ios::left); + } + else + { + os << std::setiosflags (std::ios::left) + << std::setw (param.parameter_length); + } + break; - default: - error ("whos_line_format: modifier `%c' unknown", - param.modifier); + default: + error ("whos_line_format: modifier `%c' unknown", + param.modifier); - os << std::setiosflags (std::ios::right) - << std::setw (param.parameter_length); - } + os << std::setiosflags (std::ios::right) + << std::setw (param.parameter_length); + } - switch (param.command) - { - case 'a': - { - char tmp[5]; + switch (param.command) + { + case 'a': + { + char tmp[5]; - tmp[0] = (is_automatic ? 'a' : ' '); - tmp[1] = (is_formal ? 'f' : ' '); - tmp[2] = (is_global ? 'g' : ' '); - tmp[3] = (is_persistent ? 'p' : ' '); - tmp[4] = 0; + tmp[0] = (is_automatic ? 'a' : ' '); + tmp[1] = (is_formal ? 'f' : ' '); + tmp[2] = (is_global ? 'g' : ' '); + tmp[3] = (is_persistent ? 'p' : ' '); + tmp[4] = 0; - os << tmp; - } - break; + os << tmp; + } + break; - case 'b': - os << varval.byte_size (); - break; + case 'b': + os << varval.byte_size (); + break; - case 'c': - os << varval.class_name (); - break; + case 'c': + os << varval.class_name (); + break; - case 'e': - os << varval.capacity (); - break; + case 'e': + os << varval.capacity (); + break; - case 'n': - os << name; - break; + case 'n': + os << name; + break; - case 's': - if (param.modifier != 'c') - os << dims_str; - break; + case 's': + if (param.modifier != 'c') + os << dims_str; + break; - case 't': - os << varval.type_name (); - break; - - default: - error ("whos_line_format: command `%c' unknown", - param.command); - } + case 't': + os << varval.type_name (); + break; + + default: + error ("whos_line_format: command `%c' unknown", + param.command); + } - os << std::resetiosflags (std::ios::left) - << std::resetiosflags (std::ios::right); - i++; - } - else - { - os << param.text; - i++; - } - } + os << std::resetiosflags (std::ios::left) + << std::resetiosflags (std::ios::right); + i++; + } + else + { + os << param.text; + i++; + } + } } std::string name; @@ -1088,8 +1088,8 @@ } void append (const symbol_table::symbol_record& sr, - const std::string& expr_str, - const octave_value& expr_val) + const std::string& expr_str, + const octave_value& expr_val) { lst.push_back (symbol_info (sr, expr_str, expr_val)); } @@ -1117,25 +1117,25 @@ for (size_t j = 0; j < len; j++) { - const symbol_info& si = *p++; + const symbol_info& si = *p++; - Octave_map ni; + Octave_map ni; - ni.assign ("function", caller_function_name); - ni.assign ("level", nesting_level); + ni.assign ("function", caller_function_name); + ni.assign ("level", nesting_level); - name_info(j) = si.name; - global_info(j) = si.is_global; - persistent_info(j) = si.is_persistent; + name_info(j) = si.name; + global_info(j) = si.is_global; + persistent_info(j) = si.is_persistent; - octave_value val = si.varval; + octave_value val = si.varval; - size_info(j) = val.size (); - bytes_info(j) = val.byte_size (); - class_info(j) = val.class_name (); - sparse_info(j) = val.is_sparse_type (); - complex_info(j) = val.is_complex_type (); - nesting_info(j) = ni; + size_info(j) = val.size (); + bytes_info(j) = val.byte_size (); + class_info(j) = val.class_name (); + sparse_info(j) = val.is_sparse_type (); + complex_info(j) = val.is_complex_type (); + nesting_info(j) = ni; } Octave_map info; @@ -1157,30 +1157,30 @@ { if (! lst.empty ()) { - size_t bytes = 0; - size_t elements = 0; + size_t bytes = 0; + size_t elements = 0; - std::list params = parse_whos_line_format (); + std::list params = parse_whos_line_format (); - print_descriptor (os, params); + print_descriptor (os, params); - octave_stdout << "\n"; + octave_stdout << "\n"; - for (std::list::const_iterator p = lst.begin (); - p != lst.end (); p++) - { - p->display_line (os, params); + for (std::list::const_iterator p = lst.begin (); + p != lst.end (); p++) + { + p->display_line (os, params); - octave_value val = p->varval; + octave_value val = p->varval; - elements += val.capacity (); - bytes += val.byte_size (); - } + elements += val.capacity (); + bytes += val.byte_size (); + } - os << "\nTotal is " << elements - << (elements == 1 ? " element" : " elements") - << " using " << bytes << (bytes == 1 ? " byte" : " bytes") - << "\n"; + os << "\nTotal is " << elements + << (elements == 1 ? " element" : " elements") + << " using " << bytes << (bytes == 1 ? " byte" : " bytes") + << "\n"; } } @@ -1225,183 +1225,183 @@ // bytes column, elements column and class column for (std::list::const_iterator p = lst.begin (); - p != lst.end (); p++) + p != lst.end (); p++) { - std::stringstream ss1, ss2; - std::string str; + std::stringstream ss1, ss2; + std::string str; - str = p->name; - param_length(pos_n) = ((str.length () - > static_cast (param_length(pos_n))) - ? str.length () : param_length(pos_n)); + str = p->name; + param_length(pos_n) = ((str.length () + > static_cast (param_length(pos_n))) + ? str.length () : param_length(pos_n)); - octave_value val = p->varval; + octave_value val = p->varval; - str = val.type_name (); - param_length(pos_t) = ((str.length () - > static_cast (param_length(pos_t))) - ? str.length () : param_length(pos_t)); + str = val.type_name (); + param_length(pos_t) = ((str.length () + > static_cast (param_length(pos_t))) + ? str.length () : param_length(pos_t)); - elements1 = val.capacity (); - ss1 << elements1; - str = ss1.str (); - param_length(pos_e) = ((str.length () - > static_cast (param_length(pos_e))) - ? str.length () : param_length(pos_e)); + elements1 = val.capacity (); + ss1 << elements1; + str = ss1.str (); + param_length(pos_e) = ((str.length () + > static_cast (param_length(pos_e))) + ? str.length () : param_length(pos_e)); - bytes1 = val.byte_size (); - ss2 << bytes1; - str = ss2.str (); - param_length(pos_b) = ((str.length () - > static_cast (param_length(pos_b))) - ? str.length () : param_length (pos_b)); + bytes1 = val.byte_size (); + ss2 << bytes1; + str = ss2.str (); + param_length(pos_b) = ((str.length () + > static_cast (param_length(pos_b))) + ? str.length () : param_length (pos_b)); } idx = 0; while (static_cast (idx) < format_len) { - whos_parameter param; - param.command = '\0'; + whos_parameter param; + param.command = '\0'; - if (Vwhos_line_format[idx] == '%') - { - bool error_encountered = false; - param.modifier = 'r'; - param.parameter_length = 0; + if (Vwhos_line_format[idx] == '%') + { + bool error_encountered = false; + param.modifier = 'r'; + param.parameter_length = 0; - int a = 0, b = -1, balance = 1; - unsigned int items; - size_t pos; - std::string cmd; + int a = 0, b = -1, balance = 1; + unsigned int items; + size_t pos; + std::string cmd; - // Parse one command from whos_line_format - cmd = Vwhos_line_format.substr (idx, Vwhos_line_format.length ()); - pos = cmd.find (';'); - if (pos != std::string::npos) - cmd = cmd.substr (0, pos+1); - else - error ("parameter without ; in whos_line_format"); + // Parse one command from whos_line_format + cmd = Vwhos_line_format.substr (idx, Vwhos_line_format.length ()); + pos = cmd.find (';'); + if (pos != std::string::npos) + cmd = cmd.substr (0, pos+1); + else + error ("parameter without ; in whos_line_format"); - idx += cmd.length (); + idx += cmd.length (); - // FIXME -- use iostream functions instead of sscanf! + // FIXME -- use iostream functions instead of sscanf! - if (cmd.find_first_of ("crl") != 1) - items = sscanf (cmd.c_str (), "%c%c:%d:%d:%d;", - &garbage, ¶m.command, &a, &b, &balance); - else - items = sscanf (cmd.c_str (), "%c%c%c:%d:%d:%d;", - &garbage, ¶m.modifier, ¶m.command, - &a, &b, &balance) - 1; + if (cmd.find_first_of ("crl") != 1) + items = sscanf (cmd.c_str (), "%c%c:%d:%d:%d;", + &garbage, ¶m.command, &a, &b, &balance); + else + items = sscanf (cmd.c_str (), "%c%c%c:%d:%d:%d;", + &garbage, ¶m.modifier, ¶m.command, + &a, &b, &balance) - 1; - if (items < 2) - { - error ("whos_line_format: parameter structure without command in whos_line_format"); - error_encountered = true; - } + if (items < 2) + { + error ("whos_line_format: parameter structure without command in whos_line_format"); + error_encountered = true; + } - // Insert data into parameter - param.first_parameter_length = 0; - pos = param_string.find (param.command); - if (pos != std::string::npos) - { - param.parameter_length = param_length(pos); - param.text = param_names(pos); - param.line.assign (param_names(pos).length (), '='); + // Insert data into parameter + param.first_parameter_length = 0; + pos = param_string.find (param.command); + if (pos != std::string::npos) + { + param.parameter_length = param_length(pos); + param.text = param_names(pos); + param.line.assign (param_names(pos).length (), '='); - param.parameter_length = (a > param.parameter_length - ? a : param.parameter_length); - if (param.command == 's' && param.modifier == 'c' && b > 0) - param.first_parameter_length = b; - } - else - { - error ("whos_line_format: '%c' is not a command", - param.command); - error_encountered = true; - } + param.parameter_length = (a > param.parameter_length + ? a : param.parameter_length); + if (param.command == 's' && param.modifier == 'c' && b > 0) + param.first_parameter_length = b; + } + else + { + error ("whos_line_format: '%c' is not a command", + param.command); + error_encountered = true; + } - if (param.command == 's') - { - // Have to calculate space needed for printing - // matrix dimensions Space needed for Size column is - // hard to determine in prior, because it depends on - // dimensions to be shown. That is why it is - // recalculated for each Size-command int first, - // rest = 0, total; - int rest = 0; - int first = param.first_parameter_length; - int total = param.parameter_length; + if (param.command == 's') + { + // Have to calculate space needed for printing + // matrix dimensions Space needed for Size column is + // hard to determine in prior, because it depends on + // dimensions to be shown. That is why it is + // recalculated for each Size-command int first, + // rest = 0, total; + int rest = 0; + int first = param.first_parameter_length; + int total = param.parameter_length; - for (std::list::const_iterator p = lst.begin (); - p != lst.end (); p++) - { - octave_value val = p->varval; - std::string dims_str = get_dims_str (val); - int first1 = dims_str.find ('x'); - int total1 = dims_str.length (); - int rest1 = total1 - first1; - rest = (rest1 > rest ? rest1 : rest); - first = (first1 > first ? first1 : first); - total = (total1 > total ? total1 : total); - } + for (std::list::const_iterator p = lst.begin (); + p != lst.end (); p++) + { + octave_value val = p->varval; + std::string dims_str = get_dims_str (val); + int first1 = dims_str.find ('x'); + int total1 = dims_str.length (); + int rest1 = total1 - first1; + rest = (rest1 > rest ? rest1 : rest); + first = (first1 > first ? first1 : first); + total = (total1 > total ? total1 : total); + } - if (param.modifier == 'c') - { - if (first < balance) - first += balance - first; - if (rest + balance < param.parameter_length) - rest += param.parameter_length - rest - balance; + if (param.modifier == 'c') + { + if (first < balance) + first += balance - first; + if (rest + balance < param.parameter_length) + rest += param.parameter_length - rest - balance; - param.parameter_length = first + rest; - param.first_parameter_length = first; - param.balance = balance; - } - else - { - param.parameter_length = total; - param.first_parameter_length = 0; - } - } - else if (param.modifier == 'c') - { - error ("whos_line_format: modifier 'c' not available for command '%c'", - param.command); - error_encountered = true; - } + param.parameter_length = first + rest; + param.first_parameter_length = first; + param.balance = balance; + } + else + { + param.parameter_length = total; + param.first_parameter_length = 0; + } + } + else if (param.modifier == 'c') + { + error ("whos_line_format: modifier 'c' not available for command '%c'", + param.command); + error_encountered = true; + } - // What happens if whos_line_format contains negative numbers - // at param_length positions? - param.balance = (b < 0 ? 0 : param.balance); - param.first_parameter_length = (b < 0 ? 0 : - param.first_parameter_length); - param.parameter_length = (a < 0 - ? 0 - : (param.parameter_length - < param_length(pos_s) - ? param_length(pos_s) - : param.parameter_length)); + // What happens if whos_line_format contains negative numbers + // at param_length positions? + param.balance = (b < 0 ? 0 : param.balance); + param.first_parameter_length = (b < 0 ? 0 : + param.first_parameter_length); + param.parameter_length = (a < 0 + ? 0 + : (param.parameter_length + < param_length(pos_s) + ? param_length(pos_s) + : param.parameter_length)); - // Parameter will not be pushed into parameter list if ... - if (! error_encountered) - params.push_back (param); - } - else - { - // Text string, to be printed as it is ... - std::string text; - size_t pos; - text = Vwhos_line_format.substr (idx, Vwhos_line_format.length ()); - pos = text.find ('%'); - if (pos != std::string::npos) - text = text.substr (0, pos); + // Parameter will not be pushed into parameter list if ... + if (! error_encountered) + params.push_back (param); + } + else + { + // Text string, to be printed as it is ... + std::string text; + size_t pos; + text = Vwhos_line_format.substr (idx, Vwhos_line_format.length ()); + pos = text.find ('%'); + if (pos != std::string::npos) + text = text.substr (0, pos); - // Push parameter into list ... - idx += text.length (); - param.text=text; - param.line.assign (text.length(), ' '); - params.push_back (param); - } + // Push parameter into list ... + idx += text.length (); + param.text=text; + param.line.assign (text.length(), ' '); + params.push_back (param); + } } return params; @@ -1414,7 +1414,7 @@ static octave_value do_who (int argc, const string_vector& argv, bool return_list, - bool verbose = false, std::string msg = std::string ()) + bool verbose = false, std::string msg = std::string ()) { octave_value retval; @@ -1427,55 +1427,55 @@ for (i = 1; i < argc; i++) { if (argv[i] == "-file") - { - // FIXME. This is an inefficient manner to implement this as the - // variables are loaded in to a temporary context and then treated. - // It would be better to refecat symbol_info_list to not store the - // symbol records and then use it in load-save.cc (do_load) to - // implement this option there so that the variables are never - // stored at all. - if (i == argc - 1) - error ("whos: -file argument must be followed by a file name"); - else - { - std::string nm = argv [i + 1]; + { + // FIXME. This is an inefficient manner to implement this as the + // variables are loaded in to a temporary context and then treated. + // It would be better to refecat symbol_info_list to not store the + // symbol records and then use it in load-save.cc (do_load) to + // implement this option there so that the variables are never + // stored at all. + if (i == argc - 1) + error ("whos: -file argument must be followed by a file name"); + else + { + std::string nm = argv [i + 1]; - unwind_protect frame; + unwind_protect frame; - // Set up temporary scope. + // Set up temporary scope. - symbol_table::scope_id tmp_scope = symbol_table::alloc_scope (); - frame.add_fcn (symbol_table::erase_scope, tmp_scope); + symbol_table::scope_id tmp_scope = symbol_table::alloc_scope (); + frame.add_fcn (symbol_table::erase_scope, tmp_scope); - symbol_table::set_scope (tmp_scope); + symbol_table::set_scope (tmp_scope); - octave_call_stack::push (tmp_scope, 0); - frame.add_fcn (octave_call_stack::pop); + octave_call_stack::push (tmp_scope, 0); + frame.add_fcn (octave_call_stack::pop); - frame.add_fcn (symbol_table::clear_variables); + frame.add_fcn (symbol_table::clear_variables); - feval ("load", octave_value (nm), 0); + feval ("load", octave_value (nm), 0); - if (! error_state) - { - std::string newmsg = std::string ("Variables in the file ") + - nm + ":\n\n"; + if (! error_state) + { + std::string newmsg = std::string ("Variables in the file ") + + nm + ":\n\n"; - retval = do_who (i, argv, return_list, verbose, newmsg); - } - } + retval = do_who (i, argv, return_list, verbose, newmsg); + } + } - return retval; - } + return retval; + } else if (argv[i] == "-regexp") - have_regexp = true; + have_regexp = true; else if (argv[i] == "global") - global_only = true; + global_only = true; else if (argv[i][0] == '-') - warning ("%s: unrecognized option `%s'", my_name.c_str (), - argv[i].c_str ()); + warning ("%s: unrecognized option `%s'", my_name.c_str (), + argv[i].c_str ()); else - break; + break; } int npats = argc - i; @@ -1484,7 +1484,7 @@ { pats.resize (npats); for (int j = 0; j < npats; j++) - pats[j] = argv[i+j]; + pats[j] = argv[i+j]; } else { @@ -1500,69 +1500,69 @@ std::string pat = pats[j]; if (have_regexp) - { - std::list tmp = global_only - ? symbol_table::regexp_global_variables (pat) - : symbol_table::regexp_variables (pat); + { + std::list tmp = global_only + ? symbol_table::regexp_global_variables (pat) + : symbol_table::regexp_variables (pat); - for (std::list::const_iterator p = tmp.begin (); - p != tmp.end (); p++) - { - if (p->is_variable ()) - { - if (verbose) - symbol_stats.append (*p); - else - symbol_names.push_back (p->name ()); - } - } - } + for (std::list::const_iterator p = tmp.begin (); + p != tmp.end (); p++) + { + if (p->is_variable ()) + { + if (verbose) + symbol_stats.append (*p); + else + symbol_names.push_back (p->name ()); + } + } + } else - { - size_t pos = pat.find_first_of (".({"); + { + size_t pos = pat.find_first_of (".({"); - if (pos != std::string::npos && pos > 0) - { - if (verbose) - { - // NOTE: we can only display information for - // expressions based on global values if the variable is - // global in the current scope because we currently have - // no way of looking up the base value in the global - // scope and then evaluating the arguments in the - // current scope. + if (pos != std::string::npos && pos > 0) + { + if (verbose) + { + // NOTE: we can only display information for + // expressions based on global values if the variable is + // global in the current scope because we currently have + // no way of looking up the base value in the global + // scope and then evaluating the arguments in the + // current scope. - std::string base_name = pat.substr (0, pos); + std::string base_name = pat.substr (0, pos); - if (symbol_table::is_variable (base_name)) - { - symbol_table::symbol_record sr - = symbol_table::find_symbol (base_name); + if (symbol_table::is_variable (base_name)) + { + symbol_table::symbol_record sr + = symbol_table::find_symbol (base_name); - if (! global_only || sr.is_global ()) - { - int parse_status; + if (! global_only || sr.is_global ()) + { + int parse_status; - octave_value expr_val - = eval_string (pat, true, parse_status); + octave_value expr_val + = eval_string (pat, true, parse_status); - if (! error_state) - symbol_stats.append (sr, pat, expr_val); - else - return retval; - } - } - } - } - else - { - std::list tmp = global_only - ? symbol_table::glob_global_variables (pat) - : symbol_table::glob_variables (pat); + if (! error_state) + symbol_stats.append (sr, pat, expr_val); + else + return retval; + } + } + } + } + else + { + std::list tmp = global_only + ? symbol_table::glob_global_variables (pat) + : symbol_table::glob_variables (pat); - for (std::list::const_iterator p = tmp.begin (); - p != tmp.end (); p++) - { + for (std::list::const_iterator p = tmp.begin (); + p != tmp.end (); p++) + { if (p->is_variable ()) { if (verbose) @@ -1570,43 +1570,43 @@ else symbol_names.push_back (p->name ()); } - } - } - } + } + } + } } if (return_list) { if (verbose) - { - std::string caller_function_name; - octave_function *caller = octave_call_stack::caller (); - if (caller) - caller_function_name = caller->name (); + { + std::string caller_function_name; + octave_function *caller = octave_call_stack::caller (); + if (caller) + caller_function_name = caller->name (); - retval = symbol_stats.map_value (caller_function_name, 1); - } + retval = symbol_stats.map_value (caller_function_name, 1); + } else - retval = Cell (string_vector (symbol_names)); + retval = Cell (string_vector (symbol_names)); } else if (! (symbol_stats.empty () && symbol_names.empty ())) { if (msg.length () == 0) - if (global_only) - octave_stdout << "Global variables:\n\n"; - else - octave_stdout << "Variables in the current scope:\n\n"; + if (global_only) + octave_stdout << "Global variables:\n\n"; + else + octave_stdout << "Variables in the current scope:\n\n"; else - octave_stdout << msg; + octave_stdout << msg; if (verbose) - symbol_stats.display (octave_stdout); + symbol_stats.display (octave_stdout); else - { - string_vector names (symbol_names); + { + string_vector names (symbol_names); - names.list_in_columns (octave_stdout); - } + names.list_in_columns (octave_stdout); + } octave_stdout << "\n"; } @@ -1654,7 +1654,7 @@ string_vector argv = args.make_argv ("who"); if (! error_state) - retval = do_who (argc, argv, nargout == 1); + retval = do_who (argc, argv, nargout == 1); } else print_usage (); @@ -1715,7 +1715,7 @@ string_vector argv = args.make_argv ("whos"); if (! error_state) - retval = do_who (argc, argv, nargout == 1, true); + retval = do_who (argc, argv, nargout == 1, true); } else print_usage (); @@ -1733,19 +1733,19 @@ if (val.is_defined ()) { if (val.is_cs_list ()) - { - octave_value_list lst = val.list_value (); + { + octave_value_list lst = val.list_value (); - for (octave_idx_type i = 0; i < lst.length (); i++) - bind_ans (lst(i), print); - } + for (octave_idx_type i = 0; i < lst.length (); i++) + bind_ans (lst(i), print); + } else - { - symbol_table::varref (ans) = val; + { + symbol_table::varref (ans) = val; - if (print) - val.print_with_name (octave_stdout, ans); - } + if (print) + val.print_with_name (octave_stdout, ans); + } } } @@ -1780,7 +1780,7 @@ octave_function *fcn = val.function_value (); if (fcn) - fcn->unlock (); + fcn->unlock (); } } @@ -1796,7 +1796,7 @@ octave_function *fcn = val.function_value (); if (fcn) - retval = fcn->islocked (); + retval = fcn->islocked (); } return retval; @@ -1816,9 +1816,9 @@ octave_function *fcn = octave_call_stack::caller (); if (fcn) - fcn->lock (); + fcn->lock (); else - error ("mlock: invalid use outside a function"); + error ("mlock: invalid use outside a function"); } else print_usage (); @@ -1843,7 +1843,7 @@ if (! error_state) munlock (name); else - error ("munlock: expecting argument to be a function name"); + error ("munlock: expecting argument to be a function name"); } else if (args.length () == 0) { @@ -1878,7 +1878,7 @@ if (! error_state) retval = mislocked (name); else - error ("mislocked: expecting argument to be a function name"); + error ("mislocked: expecting argument to be a function name"); } else if (args.length () == 0) { @@ -1899,7 +1899,7 @@ static inline bool name_matches_any_pattern (const std::string& nm, const string_vector& argv, - int argc, int idx, bool have_regexp = false) + int argc, int idx, bool have_regexp = false) { bool retval = false; @@ -1907,28 +1907,28 @@ { std::string patstr = argv[k]; if (! patstr.empty ()) - { - if (have_regexp) - { - regex_match pattern (patstr); + { + if (have_regexp) + { + regex_match pattern (patstr); - if (pattern.match (nm)) - { - retval = true; - break; - } - } - else - { - glob_match pattern (patstr); + if (pattern.match (nm)) + { + retval = true; + break; + } + } + else + { + glob_match pattern (patstr); - if (pattern.match (nm)) - { - retval = true; - break; - } - } - } + if (pattern.match (nm)) + { + retval = true; + break; + } + } + } } return retval; @@ -1943,37 +1943,37 @@ static void do_clear_functions (const string_vector& argv, int argc, int idx, - bool exclusive = false) + bool exclusive = false) { if (idx == argc) symbol_table::clear_functions (); else { if (exclusive) - { - string_vector fcns = symbol_table::user_function_names (); + { + string_vector fcns = symbol_table::user_function_names (); - int fcount = fcns.length (); + int fcount = fcns.length (); - for (int i = 0; i < fcount; i++) - { - std::string nm = fcns[i]; + for (int i = 0; i < fcount; i++) + { + std::string nm = fcns[i]; - if (! name_matches_any_pattern (nm, argv, argc, idx)) - symbol_table::clear_function (nm); - } - } + if (! name_matches_any_pattern (nm, argv, argc, idx)) + symbol_table::clear_function (nm); + } + } else - { - while (idx < argc) - symbol_table::clear_function_pattern (argv[idx++]); - } + { + while (idx < argc) + symbol_table::clear_function_pattern (argv[idx++]); + } } } static void do_clear_globals (const string_vector& argv, int argc, int idx, - bool exclusive = false) + bool exclusive = false) { if (idx == argc) { @@ -1982,89 +1982,89 @@ int gcount = gvars.length (); for (int i = 0; i < gcount; i++) - symbol_table::clear_global (gvars[i]); + symbol_table::clear_global (gvars[i]); } else { if (exclusive) - { - string_vector gvars = symbol_table::global_variable_names (); + { + string_vector gvars = symbol_table::global_variable_names (); - int gcount = gvars.length (); + int gcount = gvars.length (); - for (int i = 0; i < gcount; i++) - { - std::string nm = gvars[i]; + for (int i = 0; i < gcount; i++) + { + std::string nm = gvars[i]; - if (! name_matches_any_pattern (nm, argv, argc, idx)) - symbol_table::clear_global (nm); - } - } + if (! name_matches_any_pattern (nm, argv, argc, idx)) + symbol_table::clear_global (nm); + } + } else - { - while (idx < argc) - symbol_table::clear_global_pattern (argv[idx++]); - } + { + while (idx < argc) + symbol_table::clear_global_pattern (argv[idx++]); + } } } static void do_clear_variables (const string_vector& argv, int argc, int idx, - bool exclusive = false, bool have_regexp = false) + bool exclusive = false, bool have_regexp = false) { if (idx == argc) symbol_table::clear_variables (); else { if (exclusive) - { - string_vector lvars = symbol_table::variable_names (); + { + string_vector lvars = symbol_table::variable_names (); - int lcount = lvars.length (); + int lcount = lvars.length (); - for (int i = 0; i < lcount; i++) - { - std::string nm = lvars[i]; + for (int i = 0; i < lcount; i++) + { + std::string nm = lvars[i]; - if (! name_matches_any_pattern (nm, argv, argc, idx, have_regexp)) - symbol_table::clear_variable (nm); - } - } + if (! name_matches_any_pattern (nm, argv, argc, idx, have_regexp)) + symbol_table::clear_variable (nm); + } + } else - { - if (have_regexp) - while (idx < argc) - symbol_table::clear_variable_regexp (argv[idx++]); - else - while (idx < argc) - symbol_table::clear_variable_pattern (argv[idx++]); - } + { + if (have_regexp) + while (idx < argc) + symbol_table::clear_variable_regexp (argv[idx++]); + else + while (idx < argc) + symbol_table::clear_variable_pattern (argv[idx++]); + } } } static void do_clear_symbols (const string_vector& argv, int argc, int idx, - bool exclusive = false) + bool exclusive = false) { if (idx == argc) symbol_table::clear_variables (); else { if (exclusive) - { - // FIXME -- is this really what we want, or do we - // somehow want to only clear the functions that are not - // shadowed by local variables? It seems that would be a - // bit harder to do. + { + // FIXME -- is this really what we want, or do we + // somehow want to only clear the functions that are not + // shadowed by local variables? It seems that would be a + // bit harder to do. - do_clear_variables (argv, argc, idx, exclusive); - do_clear_functions (argv, argc, idx, exclusive); - } + do_clear_variables (argv, argc, idx, exclusive); + do_clear_functions (argv, argc, idx, exclusive); + } else - { - while (idx < argc) - symbol_table::clear_symbol_pattern (argv[idx++]); - } + { + while (idx < argc) + symbol_table::clear_symbol_pattern (argv[idx++]); + } } } @@ -2076,35 +2076,35 @@ for (; idx < argc; idx++) { if (argv[idx] == "all" - && ! symbol_table::is_local_variable ("all")) - { - symbol_table::clear_all (); - } + && ! symbol_table::is_local_variable ("all")) + { + symbol_table::clear_all (); + } else if (argv[idx] == "functions" - && ! symbol_table::is_local_variable ("functions")) - { - do_clear_functions (argv, argc, ++idx); - } + && ! symbol_table::is_local_variable ("functions")) + { + do_clear_functions (argv, argc, ++idx); + } else if (argv[idx] == "global" - && ! symbol_table::is_local_variable ("global")) - { - do_clear_globals (argv, argc, ++idx); - } + && ! symbol_table::is_local_variable ("global")) + { + do_clear_globals (argv, argc, ++idx); + } else if (argv[idx] == "variables" - && ! symbol_table::is_local_variable ("variables")) - { - symbol_table::clear_variables (); - } + && ! symbol_table::is_local_variable ("variables")) + { + symbol_table::clear_variables (); + } else if (argv[idx] == "classes" - && ! symbol_table::is_local_variable ("classes")) - { - symbol_table::clear_objects (); - octave_class::clear_exemplar_map (); - } + && ! symbol_table::is_local_variable ("classes")) + { + symbol_table::clear_objects (); + octave_class::clear_exemplar_map (); + } else - { - symbol_table::clear_symbol_pattern (argv[idx]); - } + { + symbol_table::clear_symbol_pattern (argv[idx]); + } } } @@ -2193,122 +2193,122 @@ if (! error_state) { if (argc == 1) - { + { do_clear_globals (argv, argc, 1); do_clear_variables (argv, argc, 1); - } + } else - { - int idx = 0; + { + int idx = 0; - bool clear_all = false; - bool clear_functions = false; - bool clear_globals = false; - bool clear_variables = false; + bool clear_all = false; + bool clear_functions = false; + bool clear_globals = false; + bool clear_variables = false; bool clear_objects = false; - bool exclusive = false; - bool have_regexp = false; - bool have_dash_option = false; + bool exclusive = false; + bool have_regexp = false; + bool have_dash_option = false; - while (++idx < argc) - { - if (argv[idx] == "-all" || argv[idx] == "-a") - { - CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); + while (++idx < argc) + { + if (argv[idx] == "-all" || argv[idx] == "-a") + { + CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); - have_dash_option = true; - clear_all = true; - } - else if (argv[idx] == "-exclusive" || argv[idx] == "-x") - { - have_dash_option = true; - exclusive = true; - } - else if (argv[idx] == "-functions" || argv[idx] == "-f") - { - CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); + have_dash_option = true; + clear_all = true; + } + else if (argv[idx] == "-exclusive" || argv[idx] == "-x") + { + have_dash_option = true; + exclusive = true; + } + else if (argv[idx] == "-functions" || argv[idx] == "-f") + { + CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); - have_dash_option = true; - clear_functions = true; - } - else if (argv[idx] == "-global" || argv[idx] == "-g") - { - CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); + have_dash_option = true; + clear_functions = true; + } + else if (argv[idx] == "-global" || argv[idx] == "-g") + { + CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); - have_dash_option = true; - clear_globals = true; - } - else if (argv[idx] == "-variables" || argv[idx] == "-v") - { - CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); + have_dash_option = true; + clear_globals = true; + } + else if (argv[idx] == "-variables" || argv[idx] == "-v") + { + CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); - have_dash_option = true; - clear_variables = true; - } - else if (argv[idx] == "-classes" || argv[idx] == "-c") - { - CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); + have_dash_option = true; + clear_variables = true; + } + else if (argv[idx] == "-classes" || argv[idx] == "-c") + { + CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); - have_dash_option = true; - clear_objects = true; - } - else if (argv[idx] == "-regexp" || argv[idx] == "-r") - { - CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); + have_dash_option = true; + clear_objects = true; + } + else if (argv[idx] == "-regexp" || argv[idx] == "-r") + { + CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); - have_dash_option = true; - have_regexp = true; - } - else - break; - } + have_dash_option = true; + have_regexp = true; + } + else + break; + } - if (idx <= argc) - { - if (! have_dash_option) - { - do_matlab_compatible_clear (argv, argc, idx); - } - else - { - if (clear_all) - { - maybe_warn_exclusive (exclusive); + if (idx <= argc) + { + if (! have_dash_option) + { + do_matlab_compatible_clear (argv, argc, idx); + } + else + { + if (clear_all) + { + maybe_warn_exclusive (exclusive); - if (++idx < argc) - warning - ("clear: ignoring extra arguments after -all"); + if (++idx < argc) + warning + ("clear: ignoring extra arguments after -all"); - symbol_table::clear_all (); - } - else if (have_regexp) - { - do_clear_variables (argv, argc, idx, exclusive, true); - } - else if (clear_functions) - { - do_clear_functions (argv, argc, idx, exclusive); - } - else if (clear_globals) - { - do_clear_globals (argv, argc, idx, exclusive); - } - else if (clear_variables) - { - do_clear_variables (argv, argc, idx, exclusive); - } - else if (clear_objects) - { - symbol_table::clear_objects (); - octave_class::clear_exemplar_map (); - } - else - { - do_clear_symbols (argv, argc, idx, exclusive); - } - } - } - } + symbol_table::clear_all (); + } + else if (have_regexp) + { + do_clear_variables (argv, argc, idx, exclusive, true); + } + else if (clear_functions) + { + do_clear_functions (argv, argc, idx, exclusive); + } + else if (clear_globals) + { + do_clear_globals (argv, argc, idx, exclusive); + } + else if (clear_variables) + { + do_clear_variables (argv, argc, idx, exclusive); + } + else if (clear_objects) + { + symbol_table::clear_objects (); + octave_class::clear_exemplar_map (); + } + else + { + do_clear_symbols (argv, argc, idx, exclusive); + } + } + } + } } return retval; diff --git a/src/xdiv.cc b/src/xdiv.cc --- a/src/xdiv.cc +++ b/src/xdiv.cc @@ -213,8 +213,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - result (i, j) = a / b (i, j); + octave_quit (); + result (i, j) = a / b (i, j); } return result; @@ -231,8 +231,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - result (i, j) = a / b (i, j); + octave_quit (); + result (i, j) = a / b (i, j); } return result; @@ -249,8 +249,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - result (i, j) = a / b (i, j); + octave_quit (); + result (i, j) = a / b (i, j); } return result; @@ -267,8 +267,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - result (i, j) = a / b (i, j); + octave_quit (); + result (i, j) = a / b (i, j); } return result; @@ -511,8 +511,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - result (i, j) = a / b (i, j); + octave_quit (); + result (i, j) = a / b (i, j); } return result; @@ -529,8 +529,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - result (i, j) = a / b (i, j); + octave_quit (); + result (i, j) = a / b (i, j); } return result; @@ -547,8 +547,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - result (i, j) = a / b (i, j); + octave_quit (); + result (i, j) = a / b (i, j); } return result; @@ -565,8 +565,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - result (i, j) = a / b (i, j); + octave_quit (); + result (i, j) = a / b (i, j); } return result; diff --git a/src/xpow.cc b/src/xpow.cc --- a/src/xpow.cc +++ b/src/xpow.cc @@ -57,8 +57,8 @@ xisint (double x) { return (D_NINT (x) == x - && ((x >= 0 && x < INT_MAX) - || (x <= 0 && x > INT_MIN))); + && ((x >= 0 && x < INT_MAX) + || (x <= 0 && x > INT_MIN))); } // Safer pow functions. @@ -108,24 +108,24 @@ EIG b_eig (b); if (! error_state) - { - ComplexColumnVector lambda (b_eig.eigenvalues ()); - ComplexMatrix Q (b_eig.eigenvectors ()); - - for (octave_idx_type i = 0; i < nr; i++) - { - Complex elt = lambda(i); - if (std::imag (elt) == 0.0) - lambda(i) = std::pow (a, std::real (elt)); - else - lambda(i) = std::pow (a, elt); - } - ComplexDiagMatrix D (lambda); - - retval = ComplexMatrix (Q * D * Q.inverse ()); - } + { + ComplexColumnVector lambda (b_eig.eigenvalues ()); + ComplexMatrix Q (b_eig.eigenvectors ()); + + for (octave_idx_type i = 0; i < nr; i++) + { + Complex elt = lambda(i); + if (std::imag (elt) == 0.0) + lambda(i) = std::pow (a, std::real (elt)); + else + lambda(i) = std::pow (a, elt); + } + ComplexDiagMatrix D (lambda); + + retval = ComplexMatrix (Q * D * Q.inverse ()); + } else - error ("xpow: matrix diagonalization failed"); + error ("xpow: matrix diagonalization failed"); } return retval; @@ -155,24 +155,24 @@ EIG b_eig (b); if (! error_state) - { - ComplexColumnVector lambda (b_eig.eigenvalues ()); - ComplexMatrix Q (b_eig.eigenvectors ()); - - for (octave_idx_type i = 0; i < nr; i++) - { - Complex elt = lambda(i); - if (std::imag (elt) == 0.0) - lambda(i) = std::pow (a, std::real (elt)); - else - lambda(i) = std::pow (a, elt); - } - ComplexDiagMatrix D (lambda); - - retval = ComplexMatrix (Q * D * Q.inverse ()); - } + { + ComplexColumnVector lambda (b_eig.eigenvalues ()); + ComplexMatrix Q (b_eig.eigenvectors ()); + + for (octave_idx_type i = 0; i < nr; i++) + { + Complex elt = lambda(i); + if (std::imag (elt) == 0.0) + lambda(i) = std::pow (a, std::real (elt)); + else + lambda(i) = std::pow (a, elt); + } + ComplexDiagMatrix D (lambda); + + retval = ComplexMatrix (Q * D * Q.inverse ()); + } else - error ("xpow: matrix diagonalization failed"); + error ("xpow: matrix diagonalization failed"); } return retval; @@ -192,73 +192,73 @@ else { if (static_cast (b) == b) - { - int btmp = static_cast (b); - if (btmp == 0) - { - retval = DiagMatrix (nr, nr, 1.0); - } - else - { - // Too much copying? - // FIXME -- we shouldn't do this if the exponent is - // large... - - Matrix atmp; - if (btmp < 0) - { - btmp = -btmp; - - octave_idx_type info; - double rcond = 0.0; - MatrixType mattype (a); - - atmp = a.inverse (mattype, info, rcond, 1); - - if (info == -1) - warning ("inverse: matrix singular to machine\ + { + int btmp = static_cast (b); + if (btmp == 0) + { + retval = DiagMatrix (nr, nr, 1.0); + } + else + { + // Too much copying? + // FIXME -- we shouldn't do this if the exponent is + // large... + + Matrix atmp; + if (btmp < 0) + { + btmp = -btmp; + + octave_idx_type info; + double rcond = 0.0; + MatrixType mattype (a); + + atmp = a.inverse (mattype, info, rcond, 1); + + if (info == -1) + warning ("inverse: matrix singular to machine\ precision, rcond = %g", rcond); - } - else - atmp = a; - - Matrix result (atmp); - - btmp--; - - while (btmp > 0) - { - if (btmp & 1) - result = result * atmp; - - btmp >>= 1; - - if (btmp > 0) - atmp = atmp * atmp; - } - - retval = result; - } - } + } + else + atmp = a; + + Matrix result (atmp); + + btmp--; + + while (btmp > 0) + { + if (btmp & 1) + result = result * atmp; + + btmp >>= 1; + + if (btmp > 0) + atmp = atmp * atmp; + } + + retval = result; + } + } else - { - EIG a_eig (a); - - if (! error_state) - { - ComplexColumnVector lambda (a_eig.eigenvalues ()); - ComplexMatrix Q (a_eig.eigenvectors ()); - - for (octave_idx_type i = 0; i < nr; i++) - lambda(i) = std::pow (lambda(i), b); - - ComplexDiagMatrix D (lambda); - - retval = ComplexMatrix (Q * D * Q.inverse ()); - } - else - error ("xpow: matrix diagonalization failed"); - } + { + EIG a_eig (a); + + if (! error_state) + { + ComplexColumnVector lambda (a_eig.eigenvalues ()); + ComplexMatrix Q (a_eig.eigenvectors ()); + + for (octave_idx_type i = 0; i < nr; i++) + lambda(i) = std::pow (lambda(i), b); + + ComplexDiagMatrix D (lambda); + + retval = ComplexMatrix (Q * D * Q.inverse ()); + } + else + error ("xpow: matrix diagonalization failed"); + } } return retval; @@ -278,19 +278,19 @@ else { if (static_cast (b) == b) - { + { DiagMatrix r (nr, nc); for (octave_idx_type i = 0; i < nc; i++) r(i, i) = std::pow (a(i, i), b); retval = r; } else - { + { ComplexDiagMatrix r (nr, nc); for (octave_idx_type i = 0; i < nc; i++) r(i, i) = std::pow (static_cast (a(i, i)), b); retval = r; - } + } } return retval; @@ -324,19 +324,19 @@ EIG a_eig (a); if (! error_state) - { - ComplexColumnVector lambda (a_eig.eigenvalues ()); - ComplexMatrix Q (a_eig.eigenvectors ()); - - for (octave_idx_type i = 0; i < nr; i++) - lambda(i) = std::pow (lambda(i), b); - - ComplexDiagMatrix D (lambda); - - retval = ComplexMatrix (Q * D * Q.inverse ()); - } + { + ComplexColumnVector lambda (a_eig.eigenvalues ()); + ComplexMatrix Q (a_eig.eigenvectors ()); + + for (octave_idx_type i = 0; i < nr; i++) + lambda(i) = std::pow (lambda(i), b); + + ComplexDiagMatrix D (lambda); + + retval = ComplexMatrix (Q * D * Q.inverse ()); + } else - error ("xpow: matrix diagonalization failed"); + error ("xpow: matrix diagonalization failed"); } return retval; @@ -372,24 +372,24 @@ EIG b_eig (b); if (! error_state) - { - ComplexColumnVector lambda (b_eig.eigenvalues ()); - ComplexMatrix Q (b_eig.eigenvectors ()); - - for (octave_idx_type i = 0; i < nr; i++) - { - Complex elt = lambda(i); - if (std::imag (elt) == 0.0) - lambda(i) = std::pow (a, std::real (elt)); - else - lambda(i) = std::pow (a, elt); - } - ComplexDiagMatrix D (lambda); - - retval = ComplexMatrix (Q * D * Q.inverse ()); - } + { + ComplexColumnVector lambda (b_eig.eigenvalues ()); + ComplexMatrix Q (b_eig.eigenvectors ()); + + for (octave_idx_type i = 0; i < nr; i++) + { + Complex elt = lambda(i); + if (std::imag (elt) == 0.0) + lambda(i) = std::pow (a, std::real (elt)); + else + lambda(i) = std::pow (a, elt); + } + ComplexDiagMatrix D (lambda); + + retval = ComplexMatrix (Q * D * Q.inverse ()); + } else - error ("xpow: matrix diagonalization failed"); + error ("xpow: matrix diagonalization failed"); } return retval; @@ -420,24 +420,24 @@ EIG b_eig (b); if (! error_state) - { - ComplexColumnVector lambda (b_eig.eigenvalues ()); - ComplexMatrix Q (b_eig.eigenvectors ()); - - for (octave_idx_type i = 0; i < nr; i++) - { - Complex elt = lambda(i); - if (std::imag (elt) == 0.0) - lambda(i) = std::pow (a, std::real (elt)); - else - lambda(i) = std::pow (a, elt); - } - ComplexDiagMatrix D (lambda); - - retval = ComplexMatrix (Q * D * Q.inverse ()); - } + { + ComplexColumnVector lambda (b_eig.eigenvalues ()); + ComplexMatrix Q (b_eig.eigenvectors ()); + + for (octave_idx_type i = 0; i < nr; i++) + { + Complex elt = lambda(i); + if (std::imag (elt) == 0.0) + lambda(i) = std::pow (a, std::real (elt)); + else + lambda(i) = std::pow (a, elt); + } + ComplexDiagMatrix D (lambda); + + retval = ComplexMatrix (Q * D * Q.inverse ()); + } else - error ("xpow: matrix diagonalization failed"); + error ("xpow: matrix diagonalization failed"); } return retval; @@ -457,73 +457,73 @@ else { if (static_cast (b) == b) - { - int btmp = static_cast (b); - if (btmp == 0) - { - retval = DiagMatrix (nr, nr, 1.0); - } - else - { - // Too much copying? - // FIXME -- we shouldn't do this if the exponent is - // large... - - ComplexMatrix atmp; - if (btmp < 0) - { - btmp = -btmp; - - octave_idx_type info; - double rcond = 0.0; - MatrixType mattype (a); - - atmp = a.inverse (mattype, info, rcond, 1); - - if (info == -1) - warning ("inverse: matrix singular to machine\ + { + int btmp = static_cast (b); + if (btmp == 0) + { + retval = DiagMatrix (nr, nr, 1.0); + } + else + { + // Too much copying? + // FIXME -- we shouldn't do this if the exponent is + // large... + + ComplexMatrix atmp; + if (btmp < 0) + { + btmp = -btmp; + + octave_idx_type info; + double rcond = 0.0; + MatrixType mattype (a); + + atmp = a.inverse (mattype, info, rcond, 1); + + if (info == -1) + warning ("inverse: matrix singular to machine\ precision, rcond = %g", rcond); - } - else - atmp = a; - - ComplexMatrix result (atmp); - - btmp--; - - while (btmp > 0) - { - if (btmp & 1) - result = result * atmp; - - btmp >>= 1; - - if (btmp > 0) - atmp = atmp * atmp; - } - - retval = result; - } - } + } + else + atmp = a; + + ComplexMatrix result (atmp); + + btmp--; + + while (btmp > 0) + { + if (btmp & 1) + result = result * atmp; + + btmp >>= 1; + + if (btmp > 0) + atmp = atmp * atmp; + } + + retval = result; + } + } else - { - EIG a_eig (a); - - if (! error_state) - { - ComplexColumnVector lambda (a_eig.eigenvalues ()); - ComplexMatrix Q (a_eig.eigenvectors ()); - - for (octave_idx_type i = 0; i < nr; i++) - lambda(i) = std::pow (lambda(i), b); - - ComplexDiagMatrix D (lambda); - - retval = ComplexMatrix (Q * D * Q.inverse ()); - } - else - error ("xpow: matrix diagonalization failed"); - } + { + EIG a_eig (a); + + if (! error_state) + { + ComplexColumnVector lambda (a_eig.eigenvalues ()); + ComplexMatrix Q (a_eig.eigenvectors ()); + + for (octave_idx_type i = 0; i < nr; i++) + lambda(i) = std::pow (lambda(i), b); + + ComplexDiagMatrix D (lambda); + + retval = ComplexMatrix (Q * D * Q.inverse ()); + } + else + error ("xpow: matrix diagonalization failed"); + } } return retval; @@ -545,19 +545,19 @@ EIG a_eig (a); if (! error_state) - { - ComplexColumnVector lambda (a_eig.eigenvalues ()); - ComplexMatrix Q (a_eig.eigenvectors ()); - - for (octave_idx_type i = 0; i < nr; i++) - lambda(i) = std::pow (lambda(i), b); - - ComplexDiagMatrix D (lambda); - - retval = ComplexMatrix (Q * D * Q.inverse ()); - } + { + ComplexColumnVector lambda (a_eig.eigenvalues ()); + ComplexMatrix Q (a_eig.eigenvectors ()); + + for (octave_idx_type i = 0; i < nr; i++) + lambda(i) = std::pow (lambda(i), b); + + ComplexDiagMatrix D (lambda); + + retval = ComplexMatrix (Q * D * Q.inverse ()); + } else - error ("xpow: matrix diagonalization failed"); + error ("xpow: matrix diagonalization failed"); } return retval; @@ -645,11 +645,11 @@ ComplexMatrix result (nr, nc); for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - { - octave_quit (); - result (i, j) = std::pow (atmp, b (i, j)); - } + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); + result (i, j) = std::pow (atmp, b (i, j)); + } retval = result; } @@ -658,11 +658,11 @@ Matrix result (nr, nc); for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - { - octave_quit (); - result (i, j) = std::pow (a, b (i, j)); - } + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); + result (i, j) = std::pow (a, b (i, j)); + } retval = result; } @@ -683,8 +683,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - result (i, j) = std::pow (atmp, b (i, j)); + octave_quit (); + result (i, j) = std::pow (atmp, b (i, j)); } return result; @@ -748,14 +748,14 @@ ComplexMatrix result (nr, nc); for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - { - octave_quit (); + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); - Complex atmp (a (i, j)); - - result (i, j) = std::pow (atmp, b); - } + Complex atmp (a (i, j)); + + result (i, j) = std::pow (atmp, b); + } retval = result; } @@ -764,11 +764,11 @@ Matrix result (nr, nc); for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - { - octave_quit (); - result (i, j) = std::pow (a (i, j), b); - } + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); + result (i, j) = std::pow (a (i, j), b); + } retval = result; } @@ -798,14 +798,14 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - double atmp = a (i, j); - double btmp = b (i, j); - if (atmp < 0.0 && static_cast (btmp) != btmp) - { - convert_to_complex = 1; - goto done; - } + octave_quit (); + double atmp = a (i, j); + double btmp = b (i, j); + if (atmp < 0.0 && static_cast (btmp) != btmp) + { + convert_to_complex = 1; + goto done; + } } done: @@ -815,13 +815,13 @@ ComplexMatrix complex_result (nr, nc); for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - { - octave_quit (); - Complex atmp (a (i, j)); - Complex btmp (b (i, j)); - complex_result (i, j) = std::pow (atmp, btmp); - } + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); + Complex atmp (a (i, j)); + Complex btmp (b (i, j)); + complex_result (i, j) = std::pow (atmp, btmp); + } retval = complex_result; } @@ -830,11 +830,11 @@ Matrix result (nr, nc); for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - { - octave_quit (); - result (i, j) = std::pow (a (i, j), b (i, j)); - } + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); + result (i, j) = std::pow (a (i, j), b (i, j)); + } retval = result; } @@ -854,8 +854,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - result (i, j) = std::pow (Complex (a (i, j)), b); + octave_quit (); + result (i, j) = std::pow (Complex (a (i, j)), b); } return result; @@ -882,8 +882,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - result (i, j) = std::pow (Complex (a (i, j)), b (i, j)); + octave_quit (); + result (i, j) = std::pow (Complex (a (i, j)), b (i, j)); } return result; @@ -901,12 +901,12 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - double btmp = b (i, j); - if (xisint (btmp)) - result (i, j) = std::pow (a, static_cast (btmp)); - else - result (i, j) = std::pow (a, btmp); + octave_quit (); + double btmp = b (i, j); + if (xisint (btmp)) + result (i, j) = std::pow (a, static_cast (btmp)); + else + result (i, j) = std::pow (a, btmp); } return result; @@ -924,8 +924,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - result (i, j) = std::pow (a, b (i, j)); + octave_quit (); + result (i, j) = std::pow (a, b (i, j)); } return result; @@ -983,20 +983,20 @@ if (xisint (b)) { for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - { - octave_quit (); - result (i, j) = std::pow (a (i, j), static_cast (b)); - } + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); + result (i, j) = std::pow (a (i, j), static_cast (b)); + } } else { for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - { - octave_quit (); - result (i, j) = std::pow (a (i, j), b); - } + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); + result (i, j) = std::pow (a (i, j), b); + } } return result; @@ -1023,12 +1023,12 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - double btmp = b (i, j); - if (xisint (btmp)) - result (i, j) = std::pow (a (i, j), static_cast (btmp)); - else - result (i, j) = std::pow (a (i, j), btmp); + octave_quit (); + double btmp = b (i, j); + if (xisint (btmp)) + result (i, j) = std::pow (a (i, j), static_cast (btmp)); + else + result (i, j) = std::pow (a (i, j), btmp); } return result; @@ -1046,8 +1046,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - result (i, j) = std::pow (a (i, j), b); + octave_quit (); + result (i, j) = std::pow (a (i, j), b); } return result; @@ -1074,8 +1074,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - result (i, j) = std::pow (a (i, j), b (i, j)); + octave_quit (); + result (i, j) = std::pow (a (i, j), b (i, j)); } return result; @@ -1123,10 +1123,10 @@ Complex atmp (a); ComplexNDArray result (b.dims ()); for (octave_idx_type i = 0; i < b.length (); i++) - { - octave_quit (); - result(i) = std::pow (atmp, b(i)); - } + { + octave_quit (); + result(i) = std::pow (atmp, b(i)); + } retval = result; } @@ -1134,10 +1134,10 @@ { NDArray result (b.dims ()); for (octave_idx_type i = 0; i < b.length (); i++) - { - octave_quit (); - result (i) = std::pow (a, b(i)); - } + { + octave_quit (); + result (i) = std::pow (a, b(i)); + } retval = result; } @@ -1255,10 +1255,10 @@ double atmp = a(i); double btmp = b(i); if (atmp < 0.0 && static_cast (btmp) != btmp) - { - convert_to_complex = true; - goto done; - } + { + convert_to_complex = true; + goto done; + } } done: @@ -1268,11 +1268,11 @@ ComplexNDArray complex_result (a_dims); for (octave_idx_type i = 0; i < len; i++) - { - octave_quit (); - Complex atmp (a(i)); - complex_result(i) = std::pow (atmp, b(i)); - } + { + octave_quit (); + Complex atmp (a(i)); + complex_result(i) = std::pow (atmp, b(i)); + } retval = complex_result; } @@ -1281,10 +1281,10 @@ NDArray result (a_dims); for (octave_idx_type i = 0; i < len; i++) - { - octave_quit (); - result(i) = std::pow (a(i), b(i)); - } + { + octave_quit (); + result(i) = std::pow (a(i), b(i)); + } retval = result; } @@ -1342,9 +1342,9 @@ octave_quit (); double btmp = b(i); if (xisint (btmp)) - result(i) = std::pow (a, static_cast (btmp)); + result(i) = std::pow (a, static_cast (btmp)); else - result(i) = std::pow (a, btmp); + result(i) = std::pow (a, btmp); } return result; @@ -1390,10 +1390,10 @@ else { for (octave_idx_type i = 0; i < a.length (); i++) - { - octave_quit (); - result(i) = std::pow (a(i), b); - } + { + octave_quit (); + result(i) = std::pow (a(i), b); + } } return result; @@ -1419,9 +1419,9 @@ octave_quit (); double btmp = b(i); if (xisint (btmp)) - result(i) = std::pow (a(i), static_cast (btmp)); + result(i) = std::pow (a(i), static_cast (btmp)); else - result(i) = std::pow (a(i), btmp); + result(i) = std::pow (a(i), btmp); } return result; @@ -1470,8 +1470,8 @@ xisint (float x) { return (D_NINT (x) == x - && ((x >= 0 && x < INT_MAX) - || (x <= 0 && x > INT_MIN))); + && ((x >= 0 && x < INT_MAX) + || (x <= 0 && x > INT_MIN))); } // Safer pow functions. @@ -1521,24 +1521,24 @@ FloatEIG b_eig (b); if (! error_state) - { - FloatComplexColumnVector lambda (b_eig.eigenvalues ()); - FloatComplexMatrix Q (b_eig.eigenvectors ()); - - for (octave_idx_type i = 0; i < nr; i++) - { - FloatComplex elt = lambda(i); - if (std::imag (elt) == 0.0) - lambda(i) = std::pow (a, std::real (elt)); - else - lambda(i) = std::pow (a, elt); - } - FloatComplexDiagMatrix D (lambda); - - retval = FloatComplexMatrix (Q * D * Q.inverse ()); - } + { + FloatComplexColumnVector lambda (b_eig.eigenvalues ()); + FloatComplexMatrix Q (b_eig.eigenvectors ()); + + for (octave_idx_type i = 0; i < nr; i++) + { + FloatComplex elt = lambda(i); + if (std::imag (elt) == 0.0) + lambda(i) = std::pow (a, std::real (elt)); + else + lambda(i) = std::pow (a, elt); + } + FloatComplexDiagMatrix D (lambda); + + retval = FloatComplexMatrix (Q * D * Q.inverse ()); + } else - error ("xpow: matrix diagonalization failed"); + error ("xpow: matrix diagonalization failed"); } return retval; @@ -1568,24 +1568,24 @@ FloatEIG b_eig (b); if (! error_state) - { - FloatComplexColumnVector lambda (b_eig.eigenvalues ()); - FloatComplexMatrix Q (b_eig.eigenvectors ()); - - for (octave_idx_type i = 0; i < nr; i++) - { - FloatComplex elt = lambda(i); - if (std::imag (elt) == 0.0) - lambda(i) = std::pow (a, std::real (elt)); - else - lambda(i) = std::pow (a, elt); - } - FloatComplexDiagMatrix D (lambda); - - retval = FloatComplexMatrix (Q * D * Q.inverse ()); - } + { + FloatComplexColumnVector lambda (b_eig.eigenvalues ()); + FloatComplexMatrix Q (b_eig.eigenvectors ()); + + for (octave_idx_type i = 0; i < nr; i++) + { + FloatComplex elt = lambda(i); + if (std::imag (elt) == 0.0) + lambda(i) = std::pow (a, std::real (elt)); + else + lambda(i) = std::pow (a, elt); + } + FloatComplexDiagMatrix D (lambda); + + retval = FloatComplexMatrix (Q * D * Q.inverse ()); + } else - error ("xpow: matrix diagonalization failed"); + error ("xpow: matrix diagonalization failed"); } return retval; @@ -1605,73 +1605,73 @@ else { if (static_cast (b) == b) - { - int btmp = static_cast (b); - if (btmp == 0) - { - retval = FloatDiagMatrix (nr, nr, 1.0); - } - else - { - // Too much copying? - // FIXME -- we shouldn't do this if the exponent is - // large... - - FloatMatrix atmp; - if (btmp < 0) - { - btmp = -btmp; - - octave_idx_type info; - float rcond = 0.0; - MatrixType mattype (a); - - atmp = a.inverse (mattype, info, rcond, 1); - - if (info == -1) - warning ("inverse: matrix singular to machine\ + { + int btmp = static_cast (b); + if (btmp == 0) + { + retval = FloatDiagMatrix (nr, nr, 1.0); + } + else + { + // Too much copying? + // FIXME -- we shouldn't do this if the exponent is + // large... + + FloatMatrix atmp; + if (btmp < 0) + { + btmp = -btmp; + + octave_idx_type info; + float rcond = 0.0; + MatrixType mattype (a); + + atmp = a.inverse (mattype, info, rcond, 1); + + if (info == -1) + warning ("inverse: matrix singular to machine\ precision, rcond = %g", rcond); - } - else - atmp = a; - - FloatMatrix result (atmp); - - btmp--; - - while (btmp > 0) - { - if (btmp & 1) - result = result * atmp; - - btmp >>= 1; - - if (btmp > 0) - atmp = atmp * atmp; - } - - retval = result; - } - } + } + else + atmp = a; + + FloatMatrix result (atmp); + + btmp--; + + while (btmp > 0) + { + if (btmp & 1) + result = result * atmp; + + btmp >>= 1; + + if (btmp > 0) + atmp = atmp * atmp; + } + + retval = result; + } + } else - { - FloatEIG a_eig (a); - - if (! error_state) - { - FloatComplexColumnVector lambda (a_eig.eigenvalues ()); - FloatComplexMatrix Q (a_eig.eigenvectors ()); - - for (octave_idx_type i = 0; i < nr; i++) - lambda(i) = std::pow (lambda(i), b); - - FloatComplexDiagMatrix D (lambda); - - retval = FloatComplexMatrix (Q * D * Q.inverse ()); - } - else - error ("xpow: matrix diagonalization failed"); - } + { + FloatEIG a_eig (a); + + if (! error_state) + { + FloatComplexColumnVector lambda (a_eig.eigenvalues ()); + FloatComplexMatrix Q (a_eig.eigenvectors ()); + + for (octave_idx_type i = 0; i < nr; i++) + lambda(i) = std::pow (lambda(i), b); + + FloatComplexDiagMatrix D (lambda); + + retval = FloatComplexMatrix (Q * D * Q.inverse ()); + } + else + error ("xpow: matrix diagonalization failed"); + } } return retval; @@ -1691,19 +1691,19 @@ else { if (static_cast (b) == b) - { + { FloatDiagMatrix r (nr, nc); for (octave_idx_type i = 0; i < nc; i++) r(i, i) = std::pow (a(i, i), b); retval = r; } else - { + { FloatComplexDiagMatrix r (nr, nc); for (octave_idx_type i = 0; i < nc; i++) r(i, i) = std::pow (static_cast (a(i, i)), b); retval = r; - } + } } return retval; @@ -1725,19 +1725,19 @@ FloatEIG a_eig (a); if (! error_state) - { - FloatComplexColumnVector lambda (a_eig.eigenvalues ()); - FloatComplexMatrix Q (a_eig.eigenvectors ()); - - for (octave_idx_type i = 0; i < nr; i++) - lambda(i) = std::pow (lambda(i), b); - - FloatComplexDiagMatrix D (lambda); - - retval = FloatComplexMatrix (Q * D * Q.inverse ()); - } + { + FloatComplexColumnVector lambda (a_eig.eigenvalues ()); + FloatComplexMatrix Q (a_eig.eigenvectors ()); + + for (octave_idx_type i = 0; i < nr; i++) + lambda(i) = std::pow (lambda(i), b); + + FloatComplexDiagMatrix D (lambda); + + retval = FloatComplexMatrix (Q * D * Q.inverse ()); + } else - error ("xpow: matrix diagonalization failed"); + error ("xpow: matrix diagonalization failed"); } return retval; @@ -1773,24 +1773,24 @@ FloatEIG b_eig (b); if (! error_state) - { - FloatComplexColumnVector lambda (b_eig.eigenvalues ()); - FloatComplexMatrix Q (b_eig.eigenvectors ()); - - for (octave_idx_type i = 0; i < nr; i++) - { - FloatComplex elt = lambda(i); - if (std::imag (elt) == 0.0) - lambda(i) = std::pow (a, std::real (elt)); - else - lambda(i) = std::pow (a, elt); - } - FloatComplexDiagMatrix D (lambda); - - retval = FloatComplexMatrix (Q * D * Q.inverse ()); - } + { + FloatComplexColumnVector lambda (b_eig.eigenvalues ()); + FloatComplexMatrix Q (b_eig.eigenvectors ()); + + for (octave_idx_type i = 0; i < nr; i++) + { + FloatComplex elt = lambda(i); + if (std::imag (elt) == 0.0) + lambda(i) = std::pow (a, std::real (elt)); + else + lambda(i) = std::pow (a, elt); + } + FloatComplexDiagMatrix D (lambda); + + retval = FloatComplexMatrix (Q * D * Q.inverse ()); + } else - error ("xpow: matrix diagonalization failed"); + error ("xpow: matrix diagonalization failed"); } return retval; @@ -1821,24 +1821,24 @@ FloatEIG b_eig (b); if (! error_state) - { - FloatComplexColumnVector lambda (b_eig.eigenvalues ()); - FloatComplexMatrix Q (b_eig.eigenvectors ()); - - for (octave_idx_type i = 0; i < nr; i++) - { - FloatComplex elt = lambda(i); - if (std::imag (elt) == 0.0) - lambda(i) = std::pow (a, std::real (elt)); - else - lambda(i) = std::pow (a, elt); - } - FloatComplexDiagMatrix D (lambda); - - retval = FloatComplexMatrix (Q * D * Q.inverse ()); - } + { + FloatComplexColumnVector lambda (b_eig.eigenvalues ()); + FloatComplexMatrix Q (b_eig.eigenvectors ()); + + for (octave_idx_type i = 0; i < nr; i++) + { + FloatComplex elt = lambda(i); + if (std::imag (elt) == 0.0) + lambda(i) = std::pow (a, std::real (elt)); + else + lambda(i) = std::pow (a, elt); + } + FloatComplexDiagMatrix D (lambda); + + retval = FloatComplexMatrix (Q * D * Q.inverse ()); + } else - error ("xpow: matrix diagonalization failed"); + error ("xpow: matrix diagonalization failed"); } return retval; @@ -1858,73 +1858,73 @@ else { if (static_cast (b) == b) - { - int btmp = static_cast (b); - if (btmp == 0) - { - retval = FloatDiagMatrix (nr, nr, 1.0); - } - else - { - // Too much copying? - // FIXME -- we shouldn't do this if the exponent is - // large... - - FloatComplexMatrix atmp; - if (btmp < 0) - { - btmp = -btmp; - - octave_idx_type info; - float rcond = 0.0; - MatrixType mattype (a); - - atmp = a.inverse (mattype, info, rcond, 1); - - if (info == -1) - warning ("inverse: matrix singular to machine\ + { + int btmp = static_cast (b); + if (btmp == 0) + { + retval = FloatDiagMatrix (nr, nr, 1.0); + } + else + { + // Too much copying? + // FIXME -- we shouldn't do this if the exponent is + // large... + + FloatComplexMatrix atmp; + if (btmp < 0) + { + btmp = -btmp; + + octave_idx_type info; + float rcond = 0.0; + MatrixType mattype (a); + + atmp = a.inverse (mattype, info, rcond, 1); + + if (info == -1) + warning ("inverse: matrix singular to machine\ precision, rcond = %g", rcond); - } - else - atmp = a; - - FloatComplexMatrix result (atmp); - - btmp--; - - while (btmp > 0) - { - if (btmp & 1) - result = result * atmp; - - btmp >>= 1; - - if (btmp > 0) - atmp = atmp * atmp; - } - - retval = result; - } - } + } + else + atmp = a; + + FloatComplexMatrix result (atmp); + + btmp--; + + while (btmp > 0) + { + if (btmp & 1) + result = result * atmp; + + btmp >>= 1; + + if (btmp > 0) + atmp = atmp * atmp; + } + + retval = result; + } + } else - { - FloatEIG a_eig (a); - - if (! error_state) - { - FloatComplexColumnVector lambda (a_eig.eigenvalues ()); - FloatComplexMatrix Q (a_eig.eigenvectors ()); - - for (octave_idx_type i = 0; i < nr; i++) - lambda(i) = std::pow (lambda(i), b); - - FloatComplexDiagMatrix D (lambda); - - retval = FloatComplexMatrix (Q * D * Q.inverse ()); - } - else - error ("xpow: matrix diagonalization failed"); - } + { + FloatEIG a_eig (a); + + if (! error_state) + { + FloatComplexColumnVector lambda (a_eig.eigenvalues ()); + FloatComplexMatrix Q (a_eig.eigenvectors ()); + + for (octave_idx_type i = 0; i < nr; i++) + lambda(i) = std::pow (lambda(i), b); + + FloatComplexDiagMatrix D (lambda); + + retval = FloatComplexMatrix (Q * D * Q.inverse ()); + } + else + error ("xpow: matrix diagonalization failed"); + } } return retval; @@ -1946,19 +1946,19 @@ FloatEIG a_eig (a); if (! error_state) - { - FloatComplexColumnVector lambda (a_eig.eigenvalues ()); - FloatComplexMatrix Q (a_eig.eigenvectors ()); - - for (octave_idx_type i = 0; i < nr; i++) - lambda(i) = std::pow (lambda(i), b); - - FloatComplexDiagMatrix D (lambda); - - retval = FloatComplexMatrix (Q * D * Q.inverse ()); - } + { + FloatComplexColumnVector lambda (a_eig.eigenvalues ()); + FloatComplexMatrix Q (a_eig.eigenvectors ()); + + for (octave_idx_type i = 0; i < nr; i++) + lambda(i) = std::pow (lambda(i), b); + + FloatComplexDiagMatrix D (lambda); + + retval = FloatComplexMatrix (Q * D * Q.inverse ()); + } else - error ("xpow: matrix diagonalization failed"); + error ("xpow: matrix diagonalization failed"); } return retval; @@ -2045,11 +2045,11 @@ FloatComplexMatrix result (nr, nc); for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - { - octave_quit (); - result (i, j) = std::pow (atmp, b (i, j)); - } + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); + result (i, j) = std::pow (atmp, b (i, j)); + } retval = result; } @@ -2058,11 +2058,11 @@ FloatMatrix result (nr, nc); for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - { - octave_quit (); - result (i, j) = std::pow (a, b (i, j)); - } + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); + result (i, j) = std::pow (a, b (i, j)); + } retval = result; } @@ -2083,8 +2083,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - result (i, j) = std::pow (atmp, b (i, j)); + octave_quit (); + result (i, j) = std::pow (atmp, b (i, j)); } return result; @@ -2104,14 +2104,14 @@ FloatComplexMatrix result (nr, nc); for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - { - octave_quit (); + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); - FloatComplex atmp (a (i, j)); - - result (i, j) = std::pow (atmp, b); - } + FloatComplex atmp (a (i, j)); + + result (i, j) = std::pow (atmp, b); + } retval = result; } @@ -2120,11 +2120,11 @@ FloatMatrix result (nr, nc); for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - { - octave_quit (); - result (i, j) = std::pow (a (i, j), b); - } + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); + result (i, j) = std::pow (a (i, j), b); + } retval = result; } @@ -2154,14 +2154,14 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - float atmp = a (i, j); - float btmp = b (i, j); - if (atmp < 0.0 && static_cast (btmp) != btmp) - { - convert_to_complex = 1; - goto done; - } + octave_quit (); + float atmp = a (i, j); + float btmp = b (i, j); + if (atmp < 0.0 && static_cast (btmp) != btmp) + { + convert_to_complex = 1; + goto done; + } } done: @@ -2171,13 +2171,13 @@ FloatComplexMatrix complex_result (nr, nc); for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - { - octave_quit (); - FloatComplex atmp (a (i, j)); - FloatComplex btmp (b (i, j)); - complex_result (i, j) = std::pow (atmp, btmp); - } + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); + FloatComplex atmp (a (i, j)); + FloatComplex btmp (b (i, j)); + complex_result (i, j) = std::pow (atmp, btmp); + } retval = complex_result; } @@ -2186,11 +2186,11 @@ FloatMatrix result (nr, nc); for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - { - octave_quit (); - result (i, j) = std::pow (a (i, j), b (i, j)); - } + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); + result (i, j) = std::pow (a (i, j), b (i, j)); + } retval = result; } @@ -2210,8 +2210,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - result (i, j) = std::pow (FloatComplex (a (i, j)), b); + octave_quit (); + result (i, j) = std::pow (FloatComplex (a (i, j)), b); } return result; @@ -2238,8 +2238,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - result (i, j) = std::pow (FloatComplex (a (i, j)), b (i, j)); + octave_quit (); + result (i, j) = std::pow (FloatComplex (a (i, j)), b (i, j)); } return result; @@ -2257,12 +2257,12 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - float btmp = b (i, j); - if (xisint (btmp)) - result (i, j) = std::pow (a, static_cast (btmp)); - else - result (i, j) = std::pow (a, btmp); + octave_quit (); + float btmp = b (i, j); + if (xisint (btmp)) + result (i, j) = std::pow (a, static_cast (btmp)); + else + result (i, j) = std::pow (a, btmp); } return result; @@ -2280,8 +2280,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - result (i, j) = std::pow (a, b (i, j)); + octave_quit (); + result (i, j) = std::pow (a, b (i, j)); } return result; @@ -2299,20 +2299,20 @@ if (xisint (b)) { for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - { - octave_quit (); - result (i, j) = std::pow (a (i, j), static_cast (b)); - } + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); + result (i, j) = std::pow (a (i, j), static_cast (b)); + } } else { for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - { - octave_quit (); - result (i, j) = std::pow (a (i, j), b); - } + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); + result (i, j) = std::pow (a (i, j), b); + } } return result; @@ -2339,12 +2339,12 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - float btmp = b (i, j); - if (xisint (btmp)) - result (i, j) = std::pow (a (i, j), static_cast (btmp)); - else - result (i, j) = std::pow (a (i, j), btmp); + octave_quit (); + float btmp = b (i, j); + if (xisint (btmp)) + result (i, j) = std::pow (a (i, j), static_cast (btmp)); + else + result (i, j) = std::pow (a (i, j), btmp); } return result; @@ -2362,8 +2362,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - result (i, j) = std::pow (a (i, j), b); + octave_quit (); + result (i, j) = std::pow (a (i, j), b); } return result; @@ -2390,8 +2390,8 @@ for (octave_idx_type j = 0; j < nc; j++) for (octave_idx_type i = 0; i < nr; i++) { - octave_quit (); - result (i, j) = std::pow (a (i, j), b (i, j)); + octave_quit (); + result (i, j) = std::pow (a (i, j), b (i, j)); } return result; @@ -2439,10 +2439,10 @@ FloatComplex atmp (a); FloatComplexNDArray result (b.dims ()); for (octave_idx_type i = 0; i < b.length (); i++) - { - octave_quit (); - result(i) = std::pow (atmp, b(i)); - } + { + octave_quit (); + result(i) = std::pow (atmp, b(i)); + } retval = result; } @@ -2450,10 +2450,10 @@ { FloatNDArray result (b.dims ()); for (octave_idx_type i = 0; i < b.length (); i++) - { - octave_quit (); - result (i) = std::pow (a, b(i)); - } + { + octave_quit (); + result (i) = std::pow (a, b(i)); + } retval = result; } @@ -2571,10 +2571,10 @@ float atmp = a(i); float btmp = b(i); if (atmp < 0.0 && static_cast (btmp) != btmp) - { - convert_to_complex = true; - goto done; - } + { + convert_to_complex = true; + goto done; + } } done: @@ -2584,11 +2584,11 @@ FloatComplexNDArray complex_result (a_dims); for (octave_idx_type i = 0; i < len; i++) - { - octave_quit (); - FloatComplex atmp (a(i)); - complex_result(i) = std::pow (atmp, b(i)); - } + { + octave_quit (); + FloatComplex atmp (a(i)); + complex_result(i) = std::pow (atmp, b(i)); + } retval = complex_result; } @@ -2597,10 +2597,10 @@ FloatNDArray result (a_dims); for (octave_idx_type i = 0; i < len; i++) - { - octave_quit (); - result(i) = std::pow (a(i), b(i)); - } + { + octave_quit (); + result(i) = std::pow (a(i), b(i)); + } retval = result; } @@ -2658,9 +2658,9 @@ octave_quit (); float btmp = b(i); if (xisint (btmp)) - result(i) = std::pow (a, static_cast (btmp)); + result(i) = std::pow (a, static_cast (btmp)); else - result(i) = std::pow (a, btmp); + result(i) = std::pow (a, btmp); } return result; @@ -2706,10 +2706,10 @@ else { for (octave_idx_type i = 0; i < a.length (); i++) - { - octave_quit (); - result(i) = std::pow (a(i), b); - } + { + octave_quit (); + result(i) = std::pow (a(i), b); + } } return result; @@ -2735,9 +2735,9 @@ octave_quit (); float btmp = b(i); if (xisint (btmp)) - result(i) = std::pow (a(i), static_cast (btmp)); + result(i) = std::pow (a(i), static_cast (btmp)); else - result(i) = std::pow (a(i), btmp); + result(i) = std::pow (a(i), btmp); } return result;