annotate libinterp/corefcn/oct-stream.cc @ 22407:34ce5be04942

maint: Style check C++ code in libinterp/. * build-env.h, build-env.in.cc, builtins.h, Cell.cc, Cell.h, __contourc__.cc, __dispatch__.cc, __dsearchn__.cc, __ilu__.cc, __lin_interpn__.cc, __luinc__.cc, __magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, balance.cc, base-text-renderer.h, besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h, call-stack.cc, call-stack.h, cdisplay.c, cdisplay.h, cellfun.cc, coct-hdf5-types.c, comment-list.cc, comment-list.h, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, data.h, debug.cc, debug.h, defaults.cc, defaults.in.h, defun-dld.h, defun-int.h, defun.h, det.cc, dirfns.cc, dirfns.h, display.cc, display.h, dlmread.cc, dynamic-ld.cc, dynamic-ld.h, eig.cc, error.cc, error.h, errwarn.h, event-queue.cc, event-queue.h, fft.cc, fft2.cc, fftn.cc, file-io.cc, file-io.h, filter.cc, find.cc, ft-text-renderer.cc, ft-text-renderer.h, gammainc.cc, gcd.cc, getgrent.cc, getpwent.cc, givens.cc, gl-render.cc, gl-render.h, gl2ps-print.cc, gl2ps-print.h, graphics.cc, graphics.in.h, gripes.h, gsvd.cc, hash.cc, help.cc, help.h, hess.cc, hex2num.cc, hook-fcn.cc, hook-fcn.h, input.cc, input.h, interpreter.cc, interpreter.h, inv.cc, jit-ir.cc, jit-ir.h, jit-typeinfo.cc, jit-typeinfo.h, jit-util.cc, jit-util.h, kron.cc, load-path.cc, load-path.h, load-save.cc, load-save.h, lookup.cc, ls-ascii-helper.cc, ls-ascii-helper.h, ls-hdf5.cc, ls-hdf5.h, ls-mat-ascii.cc, ls-mat-ascii.h, ls-mat4.cc, ls-mat4.h, ls-mat5.h, ls-oct-binary.cc, ls-oct-binary.h, ls-oct-text.cc, ls-oct-text.h, ls-utils.cc, ls-utils.h, lsode.cc, lu.cc, matrix_type.cc, max.cc, mex.cc, mex.h, mexproto.h, mgorth.cc, mxarray.in.h, nproc.cc, oct-errno.h, oct-errno.in.cc, oct-fstrm.cc, oct-fstrm.h, oct-handle.h, oct-hdf5-types.cc, oct-hdf5-types.h, oct-hdf5.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h, oct-lvalue.cc, oct-lvalue.h, oct-map.h, oct-obj.h, oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.cc, oct-strstrm.h, oct.h, octave-default-image.h, octave-link.h, octave-preserve-stream-state.h, ordschur.cc, pager.cc, pager.h, pinv.cc, pr-output.cc, pr-output.h, procstream.cc, procstream.h, profiler.h, psi.cc, pt-jit.cc, pt-jit.h, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, sighandlers.cc, sighandlers.h, sparse-xdiv.cc, sparse-xdiv.h, sparse-xpow.cc, sparse-xpow.h, sparse.cc, spparms.cc, sqrtm.cc, str2double.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symtab.cc, symtab.h, syscalls.cc, sysdep.cc, sysdep.h, text-renderer.cc, text-renderer.h, time.cc, toplev.cc, toplev.h, tril.cc, tsearch.cc, txt-eng.cc, txt-eng.h, typecast.cc, urlwrite.cc, utils.cc, utils.h, variables.cc, variables.h, workspace-element.h, xdiv.cc, xdiv.h, xnorm.cc, xnorm.h, xpow.cc, xpow.h, zfstream.cc, zfstream.h, deprecated-config.h, __delaunayn__.cc, __eigs__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __osmesa_print__.cc, __voronoi__.cc, amd.cc, audiodevinfo.cc, audioread.cc, ccolamd.cc, chol.cc, colamd.cc, convhulln.cc, dmperm.cc, fftw.cc, gzip.cc, oct-qhull.h, qr.cc, symbfact.cc, symrcm.cc, liboctinterp-build-info.h, liboctinterp-build-info.in.cc, ov-base-diag.h, ov-base-int.cc, ov-base-int.h, ov-base-mat.cc, ov-base-mat.h, ov-base-scalar.h, ov-base-sparse.cc, ov-base-sparse.h, ov-base.cc, ov-base.h, ov-bool-mat.cc, ov-bool-mat.h, ov-bool-sparse.cc, ov-bool-sparse.h, ov-bool.cc, ov-bool.h, ov-builtin.cc, ov-builtin.h, ov-cell.cc, ov-cell.h, ov-ch-mat.cc, ov-ch-mat.h, ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h, ov-colon.cc, ov-colon.h, ov-complex.cc, ov-complex.h, ov-cs-list.h, ov-cx-diag.cc, ov-cx-diag.h, ov-cx-mat.cc, ov-cx-mat.h, ov-cx-sparse.cc, ov-cx-sparse.h, ov-dld-fcn.cc, ov-dld-fcn.h, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn-inline.cc, ov-fcn-inline.h, ov-fcn.cc, ov-fcn.h, ov-float.cc, ov-float.h, ov-flt-complex.cc, ov-flt-complex.h, ov-flt-cx-diag.cc, ov-flt-cx-diag.h, ov-flt-cx-mat.cc, ov-flt-cx-mat.h, ov-flt-re-diag.cc, ov-flt-re-diag.h, ov-flt-re-mat.cc, ov-flt-re-mat.h, ov-int-traits.h, ov-int16.cc, ov-int16.h, ov-int32.cc, ov-int32.h, ov-int64.cc, ov-int64.h, ov-int8.cc, ov-int8.h, ov-intx.h, ov-java.cc, ov-java.h, ov-lazy-idx.cc, ov-lazy-idx.h, ov-mex-fcn.cc, ov-mex-fcn.h, ov-null-mat.cc, ov-null-mat.h, ov-oncleanup.cc, ov-oncleanup.h, ov-perm.cc, ov-perm.h, ov-range.cc, ov-range.h, ov-re-diag.cc, ov-re-diag.h, ov-re-mat.cc, ov-re-mat.h, ov-re-sparse.cc, ov-re-sparse.h, ov-scalar.cc, ov-scalar.h, ov-str-mat.cc, ov-str-mat.h, ov-struct.cc, ov-struct.h, ov-typeinfo.cc, ov-typeinfo.h, ov-uint16.cc, ov-uint16.h, ov-uint32.cc, ov-uint32.h, ov-uint64.cc, ov-uint64.h, ov-uint8.cc, ov-uint8.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.h, ovl.cc, ovl.h, octave.cc, octave.h, op-b-b.cc, op-b-bm.cc, op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc, op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-pm.cc, op-cm-s.cc, op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc, op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc, op-dm-template.cc, op-dms-template.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcm-pm.cc, op-fcn.cc, op-fcs-fcm.cc, op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fm-pm.cc, op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc, op-int.h, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-pm.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-pm-cm.cc, op-pm-fcm.cc, op-pm-fm.cc, op-pm-m.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-pm-template.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc, op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc, op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc, ops.h, options-usage.h, lex.h, parse.h, pt-all.h, pt-arg-list.cc, pt-arg-list.h, pt-array-list.h, pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h, pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h, pt-classdef.cc, pt-classdef.h, pt-cmd.cc, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc, pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc, pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-funcall.cc, pt-funcall.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.cc, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc, pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc, pt-select.h, pt-stmt.cc, pt-stmt.h, pt-unop.cc, pt-unop.h, pt-walk.h, pt.cc, pt.h, token.cc, token.h, Array-jit.cc, Array-tc.cc, version.cc, version.in.h: Style check C++ code in libinterp/
author Rik <rik@octave.org>
date Tue, 30 Aug 2016 21:46:47 -0700
parents d0562b3159c7
children 7abc25e6206a 36df0e0072a5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1 /*
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2
22323
bac0d6f07a3e maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
3 Copyright (C) 1996-2016 John W. Eaton
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
4 Copyright (C) 2015-2016 Lachlan Andrew, Monash University
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6970
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6970
diff changeset
11 option) any later version.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
12
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
16 for more details.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
17
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6970
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6970
diff changeset
20 <http://www.gnu.org/licenses/>.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
21
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
22 */
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
23
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
24 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21297
diff changeset
25 # include "config.h"
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
26 #endif
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
27
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
28 #include <cassert>
7709
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
29 #include <cctype>
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
30 #include <cstring>
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
31
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
32 #include <deque>
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
33 #include <fstream>
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3491
diff changeset
34 #include <iomanip>
9202
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
35 #include <iostream>
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
36 #include <sstream>
3535
c5ebcd5d25a9 [project @ 2000-02-02 11:55:49 by jwe]
jwe
parents: 3534
diff changeset
37 #include <string>
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
38
19269
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 19123
diff changeset
39 #include "Array.h"
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
40 #include "Cell.h"
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
41 #include "byte-swap.h"
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
42 #include "lo-ieee.h"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
43 #include "lo-mappers.h"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
44 #include "lo-utils.h"
19269
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 19123
diff changeset
45 #include "oct-locbuf.h"
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
46 #include "quit.h"
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
47 #include "singleton-cleanup.h"
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
48 #include "str-vec.h"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
49
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
50 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21040
diff changeset
51 #include "errwarn.h"
3342
d8d3700fb4ab [project @ 1999-11-05 16:55:17 by jwe]
jwe
parents: 3341
diff changeset
52 #include "input.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 22089
diff changeset
53 #include "interpreter.h"
22089
c2c668b3051b use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
54 #include "octave.h"
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
55 #include "oct-stdstrm.h"
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
56 #include "oct-stream.h"
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
57 #include "ov.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20938
diff changeset
58 #include "ovl.h"
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
59 #include "utils.h"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
60
20938
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
61 // Programming Note: There are two very different error functions used
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
62 // in the stream code. When invoked with "error (...)" the member
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
63 // function from octave_stream or octave_base_stream is called. This
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
64 // function sets the error state on the stream AND returns control to
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
65 // the caller. The caller must then return a value at the end of the
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
66 // function. When invoked with "::error (...)" the exception-based
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
67 // error function from error.h is used. This function will throw an
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
68 // exception and not return control to the caller. BE CAREFUL and
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
69 // invoke the correct error function!
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
70
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
71 // Possible values for conv_err:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
72 //
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
73 // 1 : not a real scalar
2902
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2877
diff changeset
74 // 2 : value is NaN
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2877
diff changeset
75 // 3 : value is not an integer
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
76
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
77 static int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
78 convert_to_valid_int (const octave_value& tc, int& conv_err)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
79 {
20747
ee2743bd07a8 eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents: 20741
diff changeset
80 conv_err = 0;
ee2743bd07a8 eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents: 20741
diff changeset
81
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
82 int retval = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
83
20747
ee2743bd07a8 eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents: 20741
diff changeset
84 double dval = 0.0;
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
85
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
86 try
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
87 {
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
88 dval = tc.double_value ();
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
89 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
90 catch (const octave::execution_exception&)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
91 {
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20747
diff changeset
92 recover_from_exception ();
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20747
diff changeset
93
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
94 conv_err = 1;
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
95 }
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
96
20747
ee2743bd07a8 eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents: 20741
diff changeset
97 if (! conv_err)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
98 {
5389
25c8956d2204 [project @ 2005-06-15 03:45:46 by jwe]
jwe
parents: 5353
diff changeset
99 if (! lo_ieee_isnan (dval))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
100 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21777
diff changeset
101 int ival = octave::math::nint (dval);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
102
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
103 if (ival == dval)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
104 retval = ival;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
105 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
106 conv_err = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
107 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
108 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
109 conv_err = 2;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
110 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
111
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
112 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
113 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
114
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
115 static int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
116 get_size (double d, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
117 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
118 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
119
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
120 if (lo_ieee_isnan (d))
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
121 ::error ("%s: NaN is invalid as size specification", who.c_str ());
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
122
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21777
diff changeset
123 if (octave::math::isinf (d))
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
124 retval = -1;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
125 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
126 {
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
127 if (d < 0.0)
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
128 ::error ("%s: negative value invalid as size specification",
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
129 who.c_str ());
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
130
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21777
diff changeset
131 retval = octave::math::nint (d);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
132 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
133
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
134 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
135 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
136
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
137 static void
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
138 get_size (const Array<double>& size, octave_idx_type& nr, octave_idx_type& nc,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
139 bool& one_elt_size_spec, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
140 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
141 nr = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
142 nc = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
143
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
144 one_elt_size_spec = false;
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
145
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
146 double dnr = -1.0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
147 double dnc = -1.0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
148
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20230
diff changeset
149 octave_idx_type sz_len = size.numel ();
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
150
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
151 if (sz_len == 1)
2601
3723512a827a [project @ 1997-01-06 05:43:16 by jwe]
jwe
parents: 2600
diff changeset
152 {
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
153 one_elt_size_spec = true;
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
154
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
155 dnr = size(0);
4293
977f977fb2c3 [project @ 2003-01-06 18:18:14 by jwe]
jwe
parents: 4257
diff changeset
156
977f977fb2c3 [project @ 2003-01-06 18:18:14 by jwe]
jwe
parents: 4257
diff changeset
157 dnc = (dnr == 0.0) ? 0.0 : 1.0;
2601
3723512a827a [project @ 1997-01-06 05:43:16 by jwe]
jwe
parents: 2600
diff changeset
158 }
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
159 else if (sz_len == 2)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
160 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
161 dnr = size(0);
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
162
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21777
diff changeset
163 if (octave::math::isinf (dnr))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
164 ::error ("%s: invalid size specification", who.c_str ());
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
165
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
166 dnc = size(1);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
167 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
168 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
169 ::error ("%s: invalid size specification", who.c_str ());
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
170
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
171 nr = get_size (dnr, who);
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
172
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
173 if (dnc >= 0.0)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
174 nc = get_size (dnc, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
175 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
176
21477
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
177 class
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
178 scanf_format_elt
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
179 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
180 public:
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
181
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
182 enum special_conversion
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
183 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
184 whitespace_conversion = 1,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
185 literal_conversion = 2,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
186 null = 3
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
187 };
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
188
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
189 scanf_format_elt (const char *txt = 0, int w = 0, bool d = false,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
190 char typ = '\0', char mod = '\0',
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
191 const std::string& ch_class = "")
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
192 : text (strsave (txt)), width (w), discard (d), type (typ),
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
193 modifier (mod), char_class (ch_class)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
194 { }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
195
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
196 scanf_format_elt (const scanf_format_elt& e)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
197 : text (strsave (e.text)), width (e.width), discard (e.discard),
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
198 type (e.type), modifier (e.modifier), char_class (e.char_class)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
199 { }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
200
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
201 scanf_format_elt& operator = (const scanf_format_elt& e)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
202 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
203 if (this != &e)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
204 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
205 text = strsave (e.text);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
206 width = e.width;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
207 discard = e.discard;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
208 type = e.type;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
209 modifier = e.modifier;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
210 char_class = e.char_class;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
211 }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
212
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
213 return *this;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
214 }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
215
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
216 ~scanf_format_elt (void) { delete [] text; }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
217
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
218 // The C-style format string.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
219 const char *text;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
220
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
221 // The maximum field width.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
222 int width;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
223
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
224 // TRUE if we are not storing the result of this conversion.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
225 bool discard;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
226
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
227 // Type of conversion -- 'd', 'i', 'o', 'u', 'x', 'e', 'f', 'g',
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
228 // 'c', 's', 'p', '%', or '['.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
229 char type;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
230
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
231 // A length modifier -- 'h', 'l', or 'L'.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
232 char modifier;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
233
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
234 // The class of characters in a '[' format.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
235 std::string char_class;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
236 };
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
237
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
238 class
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
239 scanf_format_list
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
240 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
241 public:
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
242
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
243 scanf_format_list (const std::string& fmt = "");
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
244
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
245 ~scanf_format_list (void);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
246
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
247 octave_idx_type num_conversions (void) { return nconv; }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
248
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
249 // The length can be different than the number of conversions.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
250 // For example, "x %d y %d z" has 2 conversions but the length of
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
251 // the list is 3 because of the characters that appear after the
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
252 // last conversion.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
253
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
254 size_t length (void) const { return fmt_elts.size (); }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
255
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
256 const scanf_format_elt *first (void)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
257 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
258 curr_idx = 0;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
259 return current ();
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
260 }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
261
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
262 const scanf_format_elt *current (void) const
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
263 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
264 return length () > 0 ? fmt_elts[curr_idx] : 0;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
265 }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
266
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
267 const scanf_format_elt *next (bool cycle = true)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
268 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
269 static scanf_format_elt dummy
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
270 (0, 0, false, scanf_format_elt::null, '\0', "");
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
271
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
272 curr_idx++;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
273
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
274 if (curr_idx >= length ())
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
275 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
276 if (cycle)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
277 curr_idx = 0;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
278 else
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
279 return &dummy;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
280 }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
281
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
282 return current ();
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
283 }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
284
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
285 void printme (void) const;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
286
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
287 bool ok (void) const { return (nconv >= 0); }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
288
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
289 operator bool () const { return ok (); }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
290
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
291 bool all_character_conversions (void);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
292
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
293 bool all_numeric_conversions (void);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
294
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
295 private:
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
296
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
297 // Number of conversions specified by this format string, or -1 if
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
298 // invalid conversions have been found.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
299 octave_idx_type nconv;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
300
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
301 // Index to current element;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
302 size_t curr_idx;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
303
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
304 // List of format elements.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
305 std::deque<scanf_format_elt*> fmt_elts;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
306
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
307 // Temporary buffer.
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
308 std::ostringstream buf;
21477
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
309
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
310 void add_elt_to_list (int width, bool discard, char type, char modifier,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
311 const std::string& char_class = "");
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
312
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
313 void process_conversion (const std::string& s, size_t& i, size_t n,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
314 int& width, bool& discard, char& type,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
315 char& modifier);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
316
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
317 int finish_conversion (const std::string& s, size_t& i, size_t n,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
318 int& width, bool discard, char& type,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
319 char modifier);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
320 // No copying!
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
321
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
322 scanf_format_list (const scanf_format_list&);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
323
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
324 scanf_format_list& operator = (const scanf_format_list&);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
325 };
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
326
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
327 scanf_format_list::scanf_format_list (const std::string& s)
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
328 : nconv (0), curr_idx (0), fmt_elts (), buf ()
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
329 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
330 size_t n = s.length ();
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
331
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
332 size_t i = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
333
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
334 int width = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
335 bool discard = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
336 char modifier = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
337 char type = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
338
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
339 bool have_more = true;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
340
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
341 while (i < n)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
342 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
343 have_more = true;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
344
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
345 if (s[i] == '%')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
346 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
347 // Process percent-escape conversion type.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
348
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
349 process_conversion (s, i, n, width, discard, type, modifier);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
350
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
351 have_more = (buf.tellp () != 0);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
352 }
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
353 else if (isspace (s[i]))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
354 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
355 type = scanf_format_elt::whitespace_conversion;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
356
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
357 width = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
358 discard = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
359 modifier = '\0';
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
360 buf << " ";
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
361
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
362 while (++i < n && isspace (s[i]))
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
363 ; // skip whitespace
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
364
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
365 add_elt_to_list (width, discard, type, modifier);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
366
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
367 have_more = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
368 }
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
369 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
370 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
371 type = scanf_format_elt::literal_conversion;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
372
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
373 width = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
374 discard = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
375 modifier = '\0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
376
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
377 while (i < n && ! isspace (s[i]) && s[i] != '%')
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
378 buf << s[i++];
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
379
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
380 add_elt_to_list (width, discard, type, modifier);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
381
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
382 have_more = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
383 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
384
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
385 if (nconv < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
386 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
387 have_more = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
388 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
389 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
390 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
391
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
392 if (have_more)
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
393 add_elt_to_list (width, discard, type, modifier);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
394
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
395 buf.clear ();
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
396 buf.str ("");
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
397 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
398
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
399 scanf_format_list::~scanf_format_list (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
400 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
401 size_t n = fmt_elts.size ();
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
402
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
403 for (size_t i = 0; i < n; i++)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
404 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
405 scanf_format_elt *elt = fmt_elts[i];
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
406 delete elt;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
407 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
408 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
409
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
410 void
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
411 scanf_format_list::add_elt_to_list (int width, bool discard, char type,
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
412 char modifier,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
413 const std::string& char_class)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
414 {
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
415 std::string text = buf.str ();
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
416
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
417 if (! text.empty ())
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
418 {
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
419 scanf_format_elt *elt
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
420 = new scanf_format_elt (text.c_str (), width, discard, type,
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
421 modifier, char_class);
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
422
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
423 fmt_elts.push_back (elt);
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
424 }
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
425
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
426 buf.clear ();
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
427 buf.str ("");
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
428 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
429
3535
c5ebcd5d25a9 [project @ 2000-02-02 11:55:49 by jwe]
jwe
parents: 3534
diff changeset
430 static std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
431 expand_char_class (const std::string& s)
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
432 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
433 std::string retval;
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
434
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
435 size_t len = s.length ();
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
436
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
437 size_t i = 0;
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
438
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
439 while (i < len)
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
440 {
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
441 unsigned char c = s[i++];
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
442
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
443 if (c == '-' && i > 1 && i < len
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
444 && ( static_cast<unsigned char> (s[i-2])
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
445 <= static_cast<unsigned char> (s[i])))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
446 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
447 // Add all characters from the range except the first (we
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
448 // already added it below).
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
449
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
450 for (c = s[i-2]+1; c < s[i]; c++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
451 retval += c;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
452 }
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
453 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
454 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
455 // Add the character to the class. Only add '-' if it is
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
456 // the last character in the class.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
457
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
458 if (c != '-' || i == len)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
459 retval += c;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
460 }
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
461 }
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
462
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
463 return retval;
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
464 }
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
465
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
466 void
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
467 scanf_format_list::process_conversion (const std::string& s, size_t& i,
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
468 size_t n, int& width, bool& discard,
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
469 char& type, char& modifier)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
470 {
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
471 width = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
472 discard = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
473 modifier = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
474 type = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
475
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
476 buf << s[i++];
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
477
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
478 bool have_width = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
479
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
480 while (i < n)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
481 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
482 switch (s[i])
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
483 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
484 case '*':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
485 if (discard)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
486 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
487 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
488 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
489 discard = true;
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
490 buf << s[i++];
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
491 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
492 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
493
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
494 case '0': case '1': case '2': case '3': case '4':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
495 case '5': case '6': case '7': case '8': case '9':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
496 if (have_width)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
497 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
498 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
499 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
500 char c = s[i++];
20230
e914b5399c67 Use in-place operators in C++ code where possible.
Rik <rik@octave.org>
parents: 19864
diff changeset
501 width = 10 * width + c - '0';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
502 have_width = true;
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
503 buf << c;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
504 while (i < n && isdigit (s[i]))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
505 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
506 c = s[i++];
20230
e914b5399c67 Use in-place operators in C++ code where possible.
Rik <rik@octave.org>
parents: 19864
diff changeset
507 width = 10 * width + c - '0';
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
508 buf << c;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
509 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
510 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
511 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
512
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
513 case 'h': case 'l': case 'L':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
514 if (modifier != '\0')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
515 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
516 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
517 modifier = s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
518 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
519
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
520 case 'd': case 'i': case 'o': case 'u': case 'x':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
521 if (modifier == 'L')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
522 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
523 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
524 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
525 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
526 goto fini;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
527
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
528 case 'e': case 'f': case 'g':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
529 if (modifier == 'h')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
530 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
531 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
532 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
533 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
534
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
535 // No float or long double conversions, thanks.
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
536 buf << 'l';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
537
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
538 goto fini;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
539
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
540 case 'c': case 's': case 'p': case '%': case '[':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
541 if (modifier != '\0')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
542 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
543 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
544 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
545 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
546 goto fini;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
547
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
548 fini:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
549 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
550 if (finish_conversion (s, i, n, width, discard,
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
551 type, modifier) == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
552 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
553 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
554 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
555
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
556 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
557 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
558 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
559 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
560
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
561 if (nconv < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
562 break;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
563 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
564
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
565 nconv = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
566 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
567
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
568 int
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
569 scanf_format_list::finish_conversion (const std::string& s, size_t& i,
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
570 size_t n, int& width, bool discard,
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
571 char& type, char modifier)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
572 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
573 int retval = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
574
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
575 std::string char_class;
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
576
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
577 size_t beg_idx = std::string::npos;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
578 size_t end_idx = std::string::npos;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
579
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
580 if (s[i] == '%')
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
581 {
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
582 type = '%';
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
583 buf << s[i++];
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
584 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
585 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
586 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
587 type = s[i];
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
588
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
589 if (s[i] == '[')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
590 {
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
591 buf << s[i++];
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
592
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
593 if (i < n)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
594 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
595 beg_idx = i;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
596
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
597 if (s[i] == '^')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
598 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
599 type = '^';
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
600 buf << s[i++];
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
601
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
602 if (i < n)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
603 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
604 beg_idx = i;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
605
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
606 if (s[i] == ']')
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
607 buf << s[i++];
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
608 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
609 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
610 else if (s[i] == ']')
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
611 buf << s[i++];
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
612 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
613
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
614 while (i < n && s[i] != ']')
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
615 buf << s[i++];
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
616
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
617 if (i < n && s[i] == ']')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
618 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
619 end_idx = i-1;
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
620 buf << s[i++];
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
621 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
622
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
623 if (s[i-1] != ']')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
624 retval = nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
625 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
626 else
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
627 buf << s[i++];
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
628
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
629 nconv++;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
630 }
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
631
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
632 if (nconv >= 0)
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
633 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
634 if (beg_idx != std::string::npos && end_idx != std::string::npos)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
635 char_class = expand_char_class (s.substr (beg_idx,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
636 end_idx - beg_idx + 1));
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
637
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
638 add_elt_to_list (width, discard, type, modifier, char_class);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
639 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
640
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
641 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
642 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
643
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
644 void
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
645 scanf_format_list::printme (void) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
646 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
647 size_t n = fmt_elts.size ();
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
648
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
649 for (size_t i = 0; i < n; i++)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
650 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
651 scanf_format_elt *elt = fmt_elts[i];
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
652
3531
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
653 std::cerr
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
654 << "width: " << elt->width << "\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
655 << "discard: " << elt->discard << "\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
656 << "type: ";
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
657
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
658 if (elt->type == scanf_format_elt::literal_conversion)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
659 std::cerr << "literal text\n";
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
660 else if (elt->type == scanf_format_elt::whitespace_conversion)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
661 std::cerr << "whitespace\n";
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
662 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
663 std::cerr << elt->type << "\n";
3531
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
664
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
665 std::cerr
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
666 << "modifier: " << elt->modifier << "\n"
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
667 << "char_class: '" << undo_string_escapes (elt->char_class) << "'\n"
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
668 << "text: '" << undo_string_escapes (elt->text) << "'\n\n";
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
669 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
670 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
671
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
672 bool
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
673 scanf_format_list::all_character_conversions (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
674 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
675 size_t n = fmt_elts.size ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
676
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
677 if (n > 0)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
678 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
679 for (size_t i = 0; i < n; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
680 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
681 scanf_format_elt *elt = fmt_elts[i];
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
682
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
683 switch (elt->type)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
684 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
685 case 'c': case 's': case '%': case '[': case '^':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
686 case scanf_format_elt::literal_conversion:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
687 case scanf_format_elt::whitespace_conversion:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
688 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
689
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
690 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
691 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
692 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
693 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
694 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
695
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
696 return true;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
697 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
698 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
699 return false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
700 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
701
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
702 bool
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
703 scanf_format_list::all_numeric_conversions (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
704 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
705 size_t n = fmt_elts.size ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
706
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
707 if (n > 0)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
708 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
709 for (size_t i = 0; i < n; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
710 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
711 scanf_format_elt *elt = fmt_elts[i];
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
712
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
713 switch (elt->type)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
714 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
715 case 'd': case 'i': case 'o': case 'u': case 'x':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
716 case 'e': case 'f': case 'g':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
717 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
718
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
719 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
720 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
721 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
722 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
723 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
724
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
725 return true;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
726 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
727 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
728 return false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
729 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
730
21477
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
731 class
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
732 printf_format_elt
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
733 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
734 public:
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
735
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
736 printf_format_elt (const char *txt = 0, int n = 0, int w = -1,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
737 int p = -1, const std::string& f = "",
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
738 char typ = '\0', char mod = '\0')
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
739 : text (strsave (txt)), args (n), fw (w), prec (p), flags (f),
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
740 type (typ), modifier (mod)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
741 { }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
742
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
743 printf_format_elt (const printf_format_elt& e)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
744 : text (strsave (e.text)), args (e.args), fw (e.fw), prec (e.prec),
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
745 flags (e.flags), type (e.type), modifier (e.modifier)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
746 { }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
747
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
748 printf_format_elt& operator = (const printf_format_elt& e)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
749 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
750 if (this != &e)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
751 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
752 text = strsave (e.text);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
753 args = e.args;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
754 fw = e.fw;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
755 prec = e.prec;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
756 flags = e.flags;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
757 type = e.type;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
758 modifier = e.modifier;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
759 }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
760
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
761 return *this;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
762 }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
763
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
764 ~printf_format_elt (void) { delete [] text; }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
765
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
766 // The C-style format string.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
767 const char *text;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
768
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
769 // How many args do we expect to consume?
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
770 int args;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
771
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
772 // Field width.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
773 int fw;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
774
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
775 // Precision.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
776 int prec;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
777
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
778 // Flags -- '-', '+', ' ', '0', or '#'.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
779 std::string flags;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
780
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
781 // Type of conversion -- 'd', 'i', 'o', 'x', 'X', 'u', 'c', 's',
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
782 // 'f', 'e', 'E', 'g', 'G', 'p', or '%'
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
783 char type;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
784
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
785 // A length modifier -- 'h', 'l', or 'L'.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
786 char modifier;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
787 };
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
788
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
789 class
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
790 printf_format_list
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
791 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
792 public:
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
793
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
794 printf_format_list (const std::string& fmt = "");
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
795
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
796 ~printf_format_list (void);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
797
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
798 octave_idx_type num_conversions (void) { return nconv; }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
799
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
800 const printf_format_elt *first (void)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
801 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
802 curr_idx = 0;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
803 return current ();
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
804 }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
805
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
806 const printf_format_elt *current (void) const
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
807 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
808 return length () > 0 ? fmt_elts[curr_idx] : 0;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
809 }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
810
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
811 size_t length (void) const { return fmt_elts.size (); }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
812
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
813 const printf_format_elt *next (bool cycle = true)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
814 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
815 curr_idx++;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
816
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
817 if (curr_idx >= length ())
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
818 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
819 if (cycle)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
820 curr_idx = 0;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
821 else
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
822 return 0;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
823 }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
824
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
825 return current ();
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
826 }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
827
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
828 bool last_elt_p (void) { return (curr_idx + 1 == length ()); }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
829
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
830 void printme (void) const;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
831
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
832 bool ok (void) const { return (nconv >= 0); }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
833
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
834 operator bool () const { return ok (); }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
835
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
836 private:
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
837
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
838 // Number of conversions specified by this format string, or -1 if
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
839 // invalid conversions have been found.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
840 octave_idx_type nconv;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
841
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
842 // Index to current element;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
843 size_t curr_idx;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
844
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
845 // List of format elements.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
846 std::deque<printf_format_elt*> fmt_elts;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
847
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
848 // Temporary buffer.
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
849 std::ostringstream buf;
21477
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
850
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
851 void add_elt_to_list (int args, const std::string& flags, int fw,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
852 int prec, char type, char modifier);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
853
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
854 void process_conversion (const std::string& s, size_t& i, size_t n,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
855 int& args, std::string& flags, int& fw,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
856 int& prec, char& modifier, char& type);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
857
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
858 void finish_conversion (const std::string& s, size_t& i, int args,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
859 const std::string& flags, int fw, int prec,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
860 char modifier, char& type);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
861
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
862 // No copying!
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
863
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
864 printf_format_list (const printf_format_list&);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
865
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
866 printf_format_list& operator = (const printf_format_list&);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
867 };
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
868
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
869 printf_format_list::printf_format_list (const std::string& s)
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
870 : nconv (0), curr_idx (0), fmt_elts (), buf ()
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
871 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
872 size_t n = s.length ();
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
873
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
874 size_t i = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
875
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
876 int args = 0;
3643
3af6d00b82ed [project @ 2000-03-24 10:53:21 by jwe]
jwe
parents: 3640
diff changeset
877 std::string flags;
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
878 int fw = -1;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
879 int prec = -1;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
880 char modifier = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
881 char type = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
882
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
883 bool have_more = true;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
884 bool empty_buf = true;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
885
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
886 if (n == 0)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
887 {
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
888 printf_format_elt *elt
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
889 = new printf_format_elt ("", args, fw, prec, flags, type, modifier);
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
890
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
891 fmt_elts.push_back (elt);
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
892 }
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
893 else
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
894 {
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
895 while (i < n)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
896 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
897 have_more = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
898
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
899 empty_buf = (buf.tellp () == 0);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
900
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
901 switch (s[i])
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
902 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
903 case '%':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
904 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
905 if (empty_buf)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
906 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
907 process_conversion (s, i, n, args, flags, fw, prec,
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
908 type, modifier);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
909
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
910 // If there is nothing in the buffer, then
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
911 // add_elt_to_list must have just been called, so we
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
912 // are already done with the current element and we
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
913 // don't need to call add_elt_to_list if this is our
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
914 // last trip through the loop.
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
915
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
916 have_more = (buf.tellp () != 0);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
917 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
918 else
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
919 add_elt_to_list (args, flags, fw, prec, type, modifier);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
920 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
921 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
922
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
923 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
924 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
925 args = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
926 flags = "";
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
927 fw = -1;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
928 prec = -1;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
929 modifier = '\0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
930 type = '\0';
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
931 buf << s[i++];
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
932 empty_buf = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
933 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
934 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
935 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
936
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
937 if (nconv < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
938 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
939 have_more = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
940 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
941 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
942 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
943
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
944 if (have_more)
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
945 add_elt_to_list (args, flags, fw, prec, type, modifier);
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
946
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
947 buf.clear ();
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
948 buf.str ("");
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
949 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
950 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
951
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
952 printf_format_list::~printf_format_list (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
953 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
954 size_t n = fmt_elts.size ();
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
955
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
956 for (size_t i = 0; i < n; i++)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
957 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
958 printf_format_elt *elt = fmt_elts[i];
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
959 delete elt;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
960 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
961 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
962
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
963 void
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
964 printf_format_list::add_elt_to_list (int args, const std::string& flags,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
965 int fw, int prec, char type,
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
966 char modifier)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
967 {
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
968 std::string text = buf.str ();
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
969
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
970 if (! text.empty ())
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
971 {
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
972 printf_format_elt *elt
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
973 = new printf_format_elt (text.c_str (), args, fw, prec, flags,
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
974 type, modifier);
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
975
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
976 fmt_elts.push_back (elt);
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
977 }
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
978
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
979 buf.clear ();
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
980 buf.str ("");
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
981 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
982
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
983 void
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
984 printf_format_list::process_conversion (const std::string& s, size_t& i,
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
985 size_t n, int& args,
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
986 std::string& flags, int& fw,
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
987 int& prec, char& modifier,
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
988 char& type)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
989 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
990 args = 0;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
991 flags = "";
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
992 fw = -1;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
993 prec = -1;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
994 modifier = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
995 type = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
996
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
997 buf << s[i++];
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
998
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4574
diff changeset
999 bool nxt = false;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1000
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1001 while (i < n)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1002 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1003 switch (s[i])
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1004 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1005 case '-': case '+': case ' ': case '0': case '#':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1006 flags += s[i];
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
1007 buf << s[i++];
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1008 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1009
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1010 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1011 nxt = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1012 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1013 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1014
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4574
diff changeset
1015 if (nxt)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1016 break;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1017 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1018
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1019 if (i < n)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1020 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1021 if (s[i] == '*')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1022 {
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1023 fw = -2;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1024 args++;
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
1025 buf << s[i++];
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1026 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1027 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1028 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1029 if (isdigit (s[i]))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1030 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1031 int nn = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1032 std::string tmp = s.substr (i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1033 sscanf (tmp.c_str (), "%d%n", &fw, &nn);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1034 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1035
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1036 while (i < n && isdigit (s[i]))
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
1037 buf << s[i++];
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1038 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1039 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1040
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1041 if (i < n && s[i] == '.')
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1042 {
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1043 // nothing before the . means 0.
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1044 if (fw == -1)
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1045 fw = 0;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1046
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1047 // . followed by nothing is 0.
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1048 prec = 0;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1049
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
1050 buf << s[i++];
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1051
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1052 if (i < n)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1053 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1054 if (s[i] == '*')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1055 {
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1056 prec = -2;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1057 args++;
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
1058 buf << s[i++];
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1059 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1060 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1061 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1062 if (isdigit (s[i]))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1063 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1064 int nn = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1065 std::string tmp = s.substr (i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1066 sscanf (tmp.c_str (), "%d%n", &prec, &nn);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1067 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1068
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1069 while (i < n && isdigit (s[i]))
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
1070 buf << s[i++];
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1071 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1072 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1073 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1074
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1075 if (i < n)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1076 {
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
1077 // Accept and record modifier, but don't place it in the format
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
1078 // item text. All integer conversions are handled as 64-bit
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
1079 // integers.
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
1080
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1081 switch (s[i])
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1082 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1083 case 'h': case 'l': case 'L':
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
1084 modifier = s[i++];
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1085 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1086
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1087 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1088 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1089 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1090 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1091
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1092 if (i < n)
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
1093 finish_conversion (s, i, args, flags, fw, prec, modifier, type);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1094 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1095 nconv = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1096 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1097
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1098 void
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1099 printf_format_list::finish_conversion (const std::string& s, size_t& i,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1100 int args, const std::string& flags,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1101 int fw, int prec, char modifier,
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
1102 char& type)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1103 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1104 switch (s[i])
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1105 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1106 case 'd': case 'i': case 'o': case 'x': case 'X':
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1107 case 'u': case 'c':
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1108 if (modifier == 'L')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1109 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1110 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1111 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1112 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1113 goto fini;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1114
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1115 case 'f': case 'e': case 'E': case 'g': case 'G':
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1116 if (modifier == 'h' || modifier == 'l')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1117 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1118 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1119 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1120 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1121 goto fini;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1122
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1123 case 's': case 'p': case '%':
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1124 if (modifier != '\0')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1125 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1126 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1127 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1128 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1129 goto fini;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1130
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1131 fini:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1132
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1133 type = s[i];
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1134
21517
e626d8a3427e avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents: 21503
diff changeset
1135 buf << s[i++];
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1136
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1137 if (type != '%' || args != 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1138 nconv++;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1139
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1140 if (type != '%')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1141 args++;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1142
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
1143 add_elt_to_list (args, flags, fw, prec, type, modifier);
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1144
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1145 break;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1146
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1147 default:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1148 nconv = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1149 break;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1150 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1151 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1152
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1153 void
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1154 printf_format_list::printme (void) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1155 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
1156 size_t n = fmt_elts.size ();
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
1157
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
1158 for (size_t i = 0; i < n; i++)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1159 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
1160 printf_format_elt *elt = fmt_elts[i];
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1161
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1162 std::cerr
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1163 << "args: " << elt->args << "\n"
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1164 << "flags: '" << elt->flags << "'\n"
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1165 << "width: " << elt->fw << "\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1166 << "prec: " << elt->prec << "\n"
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1167 << "type: '" << elt->type << "'\n"
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1168 << "modifier: '" << elt->modifier << "'\n"
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1169 << "text: '" << undo_string_escapes (elt->text) << "'\n\n";
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1170 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1171 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1172
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1173 // Calculate x^n. Used for ...e+nn so that, for example, 1e2 is
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1174 // exactly 100 and 5e-1 is 1/2
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1175
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1176 static double
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1177 pown (double x, unsigned int n)
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1178 {
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1179 double retval = 1;
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1180
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1181 for (unsigned int d = n; d; d >>= 1)
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1182 {
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1183 if (d & 1)
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1184 retval *= x;
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1185 x *= x;
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1186 }
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1187
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1188 return retval;
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1189 }
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1190
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1191 static Cell
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1192 init_inf_nan (void)
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1193 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1194 Cell retval (dim_vector (1, 2));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1195
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1196 retval(0) = Cell (octave_value ("inf"));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1197 retval(1) = Cell (octave_value ("nan"));
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1198
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1199 return retval;
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1200 }
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1201
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1202 namespace octave
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1203 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1204 // Delimited stream, optimized to read strings of characters separated
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1205 // by single-character delimiters.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1206 //
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1207 // The reason behind this class is that octstream doesn't provide
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1208 // seek/tell, but the opportunity has been taken to optimise for the
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1209 // textscan workload.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1210 //
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1211 // The function reads chunks into a 4kiB buffer, and marks where the
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1212 // last delimiter occurs. Reads up to this delimiter can be fast.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1213 // After that last delimiter, the remaining text is moved to the front
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1214 // of the buffer and the buffer is refilled. This also allows cheap
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1215 // seek and tell operations within a "fast read" block.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1216
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1217 class
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1218 delimited_stream
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1219 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1220 public:
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1221
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1222 delimited_stream (std::istream& is, const std::string& delimiters,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1223 int longest_lookahead, octave_idx_type bsize = 4096);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1224
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1225 delimited_stream (std::istream& is, const delimited_stream& ds);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1226
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1227 ~delimited_stream (void);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1228
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1229 // Called when optimized sequence of get is finished. Ensures that
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1230 // there is a remaining delimiter in buf, or loads more data in.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1231 void field_done (void)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1232 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1233 if (idx >= last)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1234 refresh_buf ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1235 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1236
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1237 // Load new data into buffer, and set eob, last, idx.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1238 // Return EOF at end of file, 0 otherwise.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1239 int refresh_buf (void);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1240
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1241 // Get a character, relying on caller to call field_done if
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1242 // a delimiter has been reached.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1243 int get (void)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1244 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1245 if (delimited)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1246 return eof () ? std::istream::traits_type::eof () : *idx++;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1247 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1248 return get_undelim ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1249 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1250
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1251 // Get a character, checking for underrun of the buffer.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1252 int get_undelim (void);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1253
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1254 // Read character that will be got by the next get.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1255 int peek (void) { return eof () ? std::istream::traits_type::eof () : *idx; }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1256
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1257 // Read character that will be got by the next get.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1258 int peek_undelim (void);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1259
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1260 // Undo a 'get' or 'get_undelim'. It is the caller's responsibility
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1261 // to avoid overflow by calling putbacks only for a character got by
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1262 // get() or get_undelim(), with no intervening
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1263 // get, get_delim, field_done, refresh_buf, getline, read or seekg.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1264 void putback (char /*ch*/ = 0) { if (! eof ()) --idx; }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1265
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1266 int getline (std::string& dest, char delim);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1267
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1268 // int skipline (char delim);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1269
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1270 char *read (char *buffer, int size, char* &new_start);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1271
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1272 // Return a position suitable to "seekg", valid only within this
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1273 // block between calls to field_done.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1274 char *tellg (void) { return idx; }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1275
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1276 void seekg (char *old_idx) { idx = old_idx; }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1277
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1278 bool eof (void)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1279 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1280 return (eob == buf && i_stream.eof ()) || (flags & std::ios_base::eofbit);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1281 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1282
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1283 operator const void* (void) { return (! eof () && ! flags) ? this : 0; }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1284
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1285 bool fail (void) { return flags & std::ios_base::failbit; }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1286
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1287 std::ios_base::iostate rdstate (void) { return flags; }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1288
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1289 void setstate (std::ios_base::iostate m) { flags = flags | m; }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1290
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1291 void clear (std::ios_base::iostate m
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1292 = (std::ios_base::eofbit & ~std::ios_base::eofbit))
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1293 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1294 flags = flags & m;
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1295 }
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1296
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1297 // Report if any characters have been consumed.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1298 // (get, read, etc. not cancelled by putback or seekg)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1299
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1300 void progress_benchmark (void) { progress_marker = idx; }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1301
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1302 bool no_progress (void) { return progress_marker == idx; }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1303
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1304 private:
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1305
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1306 // Number of characters to read from the file at once.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1307 int bufsize;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1308
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1309 // Stream to read from.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1310 std::istream& i_stream;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1311
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1312 // Temporary storage for a "chunk" of data.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1313 char *buf;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1314
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1315 // Current read pointer.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1316 char *idx;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1317
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1318 // Location of last delimiter in the buffer at buf (undefined if
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1319 // delimited is false).
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1320 char *last;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1321
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1322 // Position after last character in buffer.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1323 char *eob;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1324
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1325 // True if there is delimiter in the bufer after idx.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1326 bool delimited;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1327
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1328 // Longest lookahead required.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1329 int longest;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1330
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1331 // Sequence of single-character delimiters.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1332 const std::string delims;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1333
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1334 // Position of start of buf in original stream.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1335 std::streampos buf_in_file;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1336
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1337 // Marker to see if a read consumes any characters.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1338 char *progress_marker;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1339
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1340 std::ios_base::iostate flags;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1341
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1342 // No copying!
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1343
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1344 delimited_stream (const delimited_stream&);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1345
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1346 delimited_stream& operator = (const delimited_stream&);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1347 };
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1348
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1349 // Create a delimited stream, reading from is, with delimiters delims,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1350 // and allowing reading of up to tellg + longest_lookeahead. When is
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1351 // is at EOF, lookahead may be padded by ASCII nuls.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1352
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1353 delimited_stream::delimited_stream (std::istream& is,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1354 const std::string& delimiters,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1355 int longest_lookahead,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1356 octave_idx_type bsize)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1357 : bufsize (bsize), i_stream (is), longest (longest_lookahead),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1358 delims (delimiters),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1359 flags (std::ios::failbit & ~std::ios::failbit) // can't cast 0
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1360 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1361 buf = new char[bufsize];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1362 eob = buf + bufsize;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1363 idx = eob; // refresh_buf shouldn't try to copy old data
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1364 progress_marker = idx;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1365 refresh_buf (); // load the first batch of data
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1366 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1367
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1368 // Used to create a stream from a strstream from data read from a dstr.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1369 // FIXME: Find a more efficient approach. Perhaps derived dstr
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1370 delimited_stream::delimited_stream (std::istream& is,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1371 const delimited_stream& ds)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1372 : bufsize (ds.bufsize), i_stream (is), longest (ds.longest),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1373 delims (ds.delims),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1374 flags (std::ios::failbit & ~std::ios::failbit) // can't cast 0
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1375 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1376 buf = new char[bufsize];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1377 eob = buf + bufsize;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1378 idx = eob; // refresh_buf shouldn't try to copy old data
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1379 progress_marker = idx;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1380 refresh_buf (); // load the first batch of data
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1381 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1382
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1383 delimited_stream::~delimited_stream (void)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1384 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1385 // Seek to the correct position in i_stream.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1386 if (! eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1387 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1388 i_stream.clear ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1389 i_stream.seekg (buf_in_file);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1390 i_stream.read (buf, idx - buf);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1391 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1392
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1393 delete [] buf;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1394 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1395
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1396 // Read a character from the buffer, refilling the buffer from the file
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1397 // if necessary.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1398
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1399 int
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1400 delimited_stream::get_undelim (void)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1401 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1402 int retval;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1403 if (eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1404 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1405 setstate (std::ios_base::failbit);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1406 return std::istream::traits_type::eof ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1407 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1408
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1409 if (idx < eob)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1410 retval = *idx++;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1411 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1412 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1413 refresh_buf ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1414
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1415 if (eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1416 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1417 setstate (std::ios_base::eofbit);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1418 retval = std::istream::traits_type::eof ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1419 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1420 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1421 retval = *idx++;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1422 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1423
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1424 if (idx >= last)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1425 delimited = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1426
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1427 return retval;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1428 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1429
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1430 // Return the next character to be read without incrementing the
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1431 // pointer, refilling the buffer from the file if necessary.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1432
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1433 int
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1434 delimited_stream::peek_undelim (void)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1435 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1436 int retval = get_undelim ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1437 putback ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1438
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1439 return retval;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1440 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1441
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1442 // Copy remaining unprocessed data to the start of the buffer and load
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1443 // new data to fill it. Return EOF if the file is at EOF before
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1444 // reading any data and all of the data that has been read has been
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1445 // processed.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1446
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1447 int
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1448 delimited_stream::refresh_buf (void)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1449 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1450 if (eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1451 return std::istream::traits_type::eof ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1452
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1453 int retval;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1454
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1455 if (eob < idx)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1456 idx = eob;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1457
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1458 size_t old_remaining = eob - idx;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1459
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1460 octave_quit (); // allow ctrl-C
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1461
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1462 if (old_remaining > 0)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1463 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1464 buf_in_file += (idx - buf);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1465 memmove (buf, idx, old_remaining);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1466 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1467
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1468 progress_marker -= idx - buf; // where original idx would have been
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1469 idx = buf;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1470
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1471 int gcount; // chars read
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1472 if (! i_stream.eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1473 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1474 buf_in_file = i_stream.tellg (); // record for destructor
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1475 i_stream.read (buf + old_remaining, bufsize - old_remaining);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1476 gcount = i_stream.gcount ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1477 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1478 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1479 gcount = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1480
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1481 eob = buf + old_remaining + gcount;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1482 last = eob;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1483 if (gcount == 0)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1484 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1485 delimited = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1486
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1487 if (eob != buf) // no more data in file, but still some to go
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1488 retval = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1489 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1490 // file and buffer are both done.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1491 retval = std::istream::traits_type::eof ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1492 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1493 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1494 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1495 delimited = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1496
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1497 for (last = eob - longest; last - buf >= 0; last--)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1498 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1499 if (delims.find (*last) != std::string::npos)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1500 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1501 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1502
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1503 if (last < buf)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1504 delimited = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1505
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1506 retval = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1507 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1508
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1509 // Ensure fast peek doesn't give valid char
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1510 if (retval == std::istream::traits_type::eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1511 *idx = '\0'; // FIXME: check that no TreatAsEmpty etc starts w. \0?
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1512
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1513 return retval;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1514 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1515
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1516 // Return a pointer to a block of data of size size, assuming that a
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1517 // sufficiently large buffer is available in buffer, if required.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1518 // If called when delimited == true, and size is no greater than
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1519 // longest_lookahead then this will not call refresh_buf, so seekg
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1520 // still works. Otherwise, seekg may be invalidated.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1521
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1522 char *
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1523 delimited_stream::read (char *buffer, int size, char* &prior_tell)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1524 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1525 char *retval;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1526
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1527 if (eob - idx > size)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1528 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1529 retval = idx;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1530 idx += size;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1531 if (idx > last)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1532 delimited = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1533 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1534 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1535 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1536 // If there was a tellg pointing to an earlier point than the current
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1537 // read position, try to keep it in the active buffer.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1538 // In the current code, prior_tell==idx for each call,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1539 // so this is not necessary, just a precaution.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1540
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1541 if (eob - prior_tell + size < bufsize)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1542 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1543 octave_idx_type gap = idx - prior_tell;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1544 idx = prior_tell;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1545 refresh_buf ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1546 idx += gap;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1547 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1548 else // can't keep the tellg in range. May skip some data.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1549 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1550 refresh_buf ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1551 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1552
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1553 prior_tell = buf;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1554
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1555 if (eob - idx > size)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1556 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1557 retval = idx;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1558 idx += size;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1559 if (idx > last)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1560 delimited = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1561 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1562 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1563 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1564 if (size <= bufsize) // small read, but reached EOF
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1565 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1566 retval = idx;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1567 memset (eob, 0, size + (idx - buf));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1568 idx += size;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1569 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1570 else // Reading more than the whole buf; return it in buffer
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1571 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1572 retval = buffer;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1573 // FIXME: read bufsize at a time
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1574 int i;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1575 for (i = 0; i < size && ! eof (); i++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1576 *buffer++ = get_undelim ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1577 if (eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1578 memset (buffer, 0, size - i);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1579 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1580 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1581 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1582
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1583 return retval;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1584 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1585
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1586 // Return in OUT an entire line, terminated by delim. On input, OUT
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1587 // must have length at least 1.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1588
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1589 int
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1590 delimited_stream::getline (std::string& out, char delim)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1591 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1592 int len = out.length (), used = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1593 int ch;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1594 while ((ch = get_undelim ()) != delim
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1595 && ch != std::istream::traits_type::eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1596 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1597 out[used++] = ch;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1598 if (used == len)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1599 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1600 len <<= 1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1601 out.resize (len);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1602 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1603 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1604 out.resize (used);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1605 field_done ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1606
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1607 return ch;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1608 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1609
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1610 // A single conversion specifier, such as %f or %c.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1611
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1612 class
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1613 textscan_format_elt
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1614 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1615 public:
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1616
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1617 enum special_conversion
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1618 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1619 whitespace_conversion = 1,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1620 literal_conversion = 2
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1621 };
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1622
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1623 textscan_format_elt (const std::string& txt, int w = 0, int p = -1,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1624 int bw = 0, bool dis = false, char typ = '\0',
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1625 const std::string& ch_class = std::string ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1626 : text (txt), width (w), prec (p), bitwidth (bw),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1627 char_class (ch_class), type (typ), discard (dis),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1628 numeric (typ == 'd' || typ == 'u' || type == 'f' || type == 'n')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1629 { }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1630
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1631 textscan_format_elt (const textscan_format_elt& e)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1632 : text (e.text), width (e.width), prec (e.prec),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1633 bitwidth (e.bitwidth), char_class (e.char_class), type (e.type),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1634 discard (e.discard), numeric (e.numeric)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1635 { }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1636
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1637 textscan_format_elt& operator = (const textscan_format_elt& e)
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1638 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1639 if (this != &e)
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1640 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1641 text = e.text;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1642 width = e.width;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1643 prec = e.prec;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1644 bitwidth = e.bitwidth;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1645 discard = e.discard;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1646 type = e.type;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1647 numeric = e.numeric;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1648 char_class = e.char_class;
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1649 }
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1650
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1651 return *this;
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1652 }
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1653
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1654 // The C-style format string.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1655 std::string text;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1656
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1657 // The maximum field width.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1658 unsigned int width;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1659
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1660 // The maximum number of digits to read after the decimal in a
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1661 // floating point conversion.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1662 int prec;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1663
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1664 // The size of the result. For integers, bitwidth may be 8, 16, 34,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1665 // or 64. For floating point values, bitwidth may be 32 or 64.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1666 int bitwidth;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1667
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1668 // The class of characters in a `[' or `^' format.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1669 std::string char_class;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1670
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1671 // Type of conversion
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1672 // -- `d', `u', `f', `n', `s', `q', `c', `%', `C', `D', `[' or `^'.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1673 char type;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1674
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1675 // TRUE if we are not storing the result of this conversion.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1676 bool discard;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1677
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1678 // TRUE if the type is 'd', 'u', 'f', 'n'
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1679 bool numeric;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1680 };
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1681
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1682 // The (parsed) sequence of format specifiers.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1683
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1684 class textscan;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1685
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1686 class
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1687 textscan_format_list
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1688 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1689 public:
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1690
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1691 textscan_format_list (const std::string& fmt = std::string (),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1692 const std::string& who = "textscan");
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1693
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1694 ~textscan_format_list (void);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1695
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1696 octave_idx_type num_conversions (void) const { return nconv; }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1697
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1698 // The length can be different than the number of conversions.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1699 // For example, "x %d y %d z" has 2 conversions but the length of
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1700 // the list is 3 because of the characters that appear after the
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1701 // last conversion.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1702
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1703 size_t numel (void) const { return fmt_elts.size (); }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1704
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1705 const textscan_format_elt *first (void)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1706 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1707 curr_idx = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1708 return current ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1709 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1710
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1711 const textscan_format_elt *current (void) const
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1712 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1713 return numel () > 0 ? fmt_elts[curr_idx] : 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1714 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1715
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1716 const textscan_format_elt *next (bool cycle = true)
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1717 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1718 curr_idx++;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1719
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1720 if (curr_idx >= numel ())
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
1721 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1722 if (cycle)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1723 curr_idx = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1724 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1725 return 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1726 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1727
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1728 return current ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1729 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1730
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1731 void printme (void) const;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1732
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1733 bool ok (void) const { return (nconv >= 0); }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1734
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1735 operator const void* (void) const { return ok () ? this : 0; }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1736
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1737 // What function name should be shown when reporting errors.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1738 std::string who;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1739
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1740 // True if number of %f to be set from data file.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1741 bool set_from_first;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1742
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1743 // At least one conversion specifier is s,q,c, or [...].
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1744 bool has_string;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1745
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1746 int read_first_row (delimited_stream& is, textscan& ts);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1747
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1748 std::list<octave_value> out_buf (void) const { return (output_container); }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1749
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1750 private:
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1751
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1752 // Number of conversions specified by this format string, or -1 if
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1753 // invalid conversions have been found.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1754 octave_idx_type nconv;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1755
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1756 // Index to current element;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1757 size_t curr_idx;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1758
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1759 // List of format elements.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1760 std::deque<textscan_format_elt*> fmt_elts;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1761
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1762 // list holding column arrays of types specified by conversions
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1763 std::list<octave_value> output_container;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1764
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1765 // Temporary buffer.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1766 std::ostringstream buf;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1767
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1768 void add_elt_to_list (unsigned int width, int prec, int bitwidth,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1769 octave_value val_type, bool discard,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1770 char type,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1771 const std::string& char_class = std::string ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1772
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1773 void process_conversion (const std::string& s, size_t& i, size_t n);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1774
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1775 std::string parse_char_class (const std::string& pattern) const;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1776
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1777 int finish_conversion (const std::string& s, size_t& i, size_t n,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1778 unsigned int& width, int& prec, int& bitwidth,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1779 octave_value& val_type,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1780 bool discard, char& type);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1781 // No copying!
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1782
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1783 textscan_format_list (const textscan_format_list&);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1784
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1785 textscan_format_list& operator = (const textscan_format_list&);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1786 };
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1787
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1788 // Main class to implement textscan. Read data and parse it
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1789 // according to a format.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1790 //
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1791 // The calling sequence is
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1792 //
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1793 // textscan scanner ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1794 // scanner.scan (...);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1795
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1796 class
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1797 OCTINTERP_API
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1798 textscan
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1799 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1800 public:
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1801
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1802 textscan (const std::string& who_arg = "textscan");
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1803
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1804 ~textscan (void) { }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1805
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1806 octave_value scan (std::istream& isp, const std::string& fmt,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1807 octave_idx_type ntimes,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1808 const octave_value_list& options,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1809 octave_idx_type& read_count);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1810
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1811 private:
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1812
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1813 friend class textscan_format_list;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1814
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1815 // What function name should be shown when reporting errors.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1816 std::string who;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1817
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1818 std::string buf;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1819
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1820 // Three cases for delim_table and delim_list
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1821 // 1. delim_table empty, delim_list empty: whitespace delimiters
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1822 // 2. delim_table = look-up table of delim chars, delim_list empty.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1823 // 3. delim_table non-empty, delim_list = Cell array of delim strings
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1824
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1825 std::string whitespace_table;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1826
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1827 // delim_table[i] == '\0' if i is not a delimiter.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1828 std::string delim_table;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1829
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1830 // String of delimiter characters.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1831 std::string delims;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1832
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1833 Cell comment_style;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1834
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1835 // How far ahead to look to detect an open comment.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1836 int comment_len;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1837
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1838 // First character of open comment.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1839 int comment_char;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1840
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1841 octave_idx_type buffer_size;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1842
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1843 std::string date_locale;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1844
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1845 // 'inf' and 'nan' for formatted_double.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1846 Cell inf_nan;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1847
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1848 // Array of strings of delimiters.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1849 Cell delim_list;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1850
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1851 // Longest delimiter.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1852 int delim_len;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1853
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1854 octave_value empty_value;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1855 std::string exp_chars;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1856 int header_lines;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1857 Cell treat_as_empty;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1858
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1859 // Longest string to treat as "N/A".
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1860 int treat_as_empty_len;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1861
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1862 std::string whitespace;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1863
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1864 short eol1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1865 short eol2;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1866 short return_on_error;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1867
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1868 bool collect_output;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1869 bool multiple_delims_as_one;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1870 bool default_exp;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1871 bool numeric_delim;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1872
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1873 octave_idx_type lines;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1874
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1875 octave_value do_scan (std::istream& isp, textscan_format_list& fmt_list,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1876 octave_idx_type ntimes);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1877
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1878 void parse_options (const octave_value_list& args,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1879 textscan_format_list& fmt_list);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1880
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1881 int read_format_once (delimited_stream& isp, textscan_format_list& fmt_list,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1882 std::list<octave_value>& retval,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1883 Array<octave_idx_type> row, int& done_after);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1884
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1885 void scan_one (delimited_stream& is, const textscan_format_elt& fmt,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1886 octave_value& ov, Array<octave_idx_type> row);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1887
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1888 // Methods to process a particular conversion specifier.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1889 double read_double (delimited_stream& is,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1890 const textscan_format_elt& fmt) const;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1891
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1892 void scan_complex (delimited_stream& is, const textscan_format_elt& fmt,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1893 Complex& val) const;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1894
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1895 int scan_bracket (delimited_stream& is, const std::string& pattern,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1896 std::string& val) const;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1897
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1898 int scan_caret (delimited_stream& is, const std::string& pattern,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1899 std::string& val) const;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1900
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1901 void scan_string (delimited_stream& is, const textscan_format_elt& fmt,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1902 std::string& val) const;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1903
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1904 void scan_cstring (delimited_stream& is, const textscan_format_elt& fmt,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1905 std::string& val) const;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1906
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1907 void scan_qstring (delimited_stream& is, const textscan_format_elt& fmt,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1908 std::string& val);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1909
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1910 // Helper methods.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1911 std::string read_until (delimited_stream& is, const Cell& delimiters,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1912 const std::string& ends) const;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1913
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1914 int lookahead (delimited_stream& is, const Cell& targets, int max_len,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1915 bool case_sensitive = true) const;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1916
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1917 bool match_literal (delimited_stream& isp, const textscan_format_elt& elem);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1918
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1919 int skip_whitespace (delimited_stream& is, bool EOLstop = false);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1920
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1921 int skip_delim (delimited_stream& is);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1922
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1923 bool is_delim (unsigned char ch) const
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1924 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1925 return ((delim_table.empty () && (isspace (ch) || ch == eol1 || ch == eol2))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1926 || delim_table[ch] != '\0');
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1927 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1928
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1929 bool isspace (unsigned int ch) const { return whitespace_table[ch & 0xff]; }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1930
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1931 // True if the only delimiter is whitespace.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1932 bool whitespace_delim (void) const { return delim_table.empty (); }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1933
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1934 // No copying!
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1935
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1936 textscan (const textscan&);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1937
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1938 textscan& operator = (const textscan&);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1939 };
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1940
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1941 textscan_format_list::textscan_format_list (const std::string& s,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1942 const std::string& who_arg)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1943 : who (who_arg), set_from_first (false), has_string (false),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1944 nconv (0), curr_idx (0), fmt_elts (), buf ()
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1945 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1946 size_t n = s.length ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1947
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1948 size_t i = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1949
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1950 unsigned int width = -1; // Unspecified width = max (except %c)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1951 int prec = -1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1952 int bitwidth = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1953 bool discard = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1954 char type = '\0';
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1955
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1956 bool have_more = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1957
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1958 if (s.empty ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1959 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1960 buf.clear ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1961 buf.str ("");
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1962
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1963 buf << "%f";
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1964
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1965 bitwidth = 64;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1966 type = 'f';
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1967 add_elt_to_list (width, prec, bitwidth, octave_value (NDArray ()),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1968 discard, type);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1969 have_more = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1970 set_from_first = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1971 nconv = 1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1972 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1973 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1974 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1975 set_from_first = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1976
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1977 while (i < n)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1978 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1979 have_more = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1980
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1981 if (s[i] == '%' && (i+1 == n || s[i+1] != '%'))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1982 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1983 // Process percent-escape conversion type.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1984
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1985 process_conversion (s, i, n);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1986
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1987 // If there is nothing in the buffer, then add_elt_to_list
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1988 // must have just been called, so we are already done with
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1989 // the current element and we don't need to call
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1990 // add_elt_to_list if this is our last trip through the
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1991 // loop.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1992
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1993 have_more = (buf.tellp () != 0);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1994 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1995 else if (isspace (s[i]))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1996 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1997 while (++i < n && isspace (s[i]))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1998 /* skip whitespace */;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1999
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2000 have_more = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2001 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2002 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2003 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2004 type = textscan_format_elt::literal_conversion;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2005
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2006 width = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2007 prec = -1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2008 bitwidth = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2009 discard = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2010
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2011 while (i < n && ! isspace (s[i])
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2012 && (s[i] != '%' || (i+1 < n && s[i+1] == '%')))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2013 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2014 if (s[i] == '%') // if double %, skip one
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2015 i++;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2016 buf << s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2017 width++;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2018 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2019
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2020 add_elt_to_list (width, prec, bitwidth, octave_value (),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2021 discard, type);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2022
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2023 have_more = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2024 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2025
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2026 if (nconv < 0)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2027 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2028 have_more = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2029 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2030 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2031 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2032 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2033
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2034 if (have_more)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2035 add_elt_to_list (width, prec, bitwidth, octave_value (), discard, type);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2036
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2037 buf.clear ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2038 buf.str ("");
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2039 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2040
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2041 textscan_format_list::~textscan_format_list (void)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2042 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2043 size_t n = numel ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2044
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2045 for (size_t i = 0; i < n; i++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2046 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2047 textscan_format_elt *elt = fmt_elts[i];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2048 delete elt;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2049 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2050 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2051
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2052 void
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2053 textscan_format_list::add_elt_to_list (unsigned int width, int prec,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2054 int bitwidth, octave_value val_type,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2055 bool discard, char type,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2056 const std::string& char_class)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2057 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2058 std::string text = buf.str ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2059
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2060 if (! text.empty ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2061 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2062 textscan_format_elt *elt
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
2063 = new textscan_format_elt (text, width, prec, bitwidth, discard, type,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
2064 char_class);
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2065
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2066 if (! discard)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2067 output_container.push_back (val_type);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2068
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2069 fmt_elts.push_back (elt);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2070 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2071
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2072 buf.clear ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2073 buf.str ("");
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2074 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2075
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2076 void
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2077 textscan_format_list::process_conversion (const std::string& s, size_t& i,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2078 size_t n)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2079 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2080 unsigned width = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2081 int prec = -1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2082 int bitwidth = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2083 bool discard = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2084 octave_value val_type;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2085 char type = '\0';
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2086
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2087 buf << s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2088
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2089 bool have_width = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2090
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2091 while (i < n)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2092 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2093 switch (s[i])
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2094 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2095 case '*':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2096 if (discard)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2097 nconv = -1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2098 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2099 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2100 discard = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2101 buf << s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2102 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2103 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2104
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2105 case '0': case '1': case '2': case '3': case '4':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2106 case '5': case '6': case '7': case '8': case '9':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2107 if (have_width)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2108 nconv = -1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2109 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2110 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2111 char c = s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2112 width = width * 10 + c - '0';
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2113 have_width = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2114 buf << c;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2115 while (i < n && isdigit (s[i]))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2116 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2117 c = s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2118 width = width * 10 + c - '0';
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2119 buf << c;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2120 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2121
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2122 if (i < n && s[i] == '.')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2123 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2124 buf << s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2125 prec = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2126 while (i < n && isdigit (s[i]))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2127 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2128 c = s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2129 prec = prec * 10 + c - '0';
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2130 buf << c;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2131 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2132 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2133 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2134 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2135
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2136 case 'd': case 'u':
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2137 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2138 bool done = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2139 buf << (type = s[i++]);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2140 if (i < n)
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2141 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2142 if (s[i] == '8')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2143 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2144 bitwidth = 8;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2145 if (type == 'd')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2146 val_type = octave_value (int8NDArray ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2147 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2148 val_type = octave_value (uint8NDArray ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2149 buf << s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2150 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2151 else if (s[i] == '1' && i+1 < n && s[i+1] == '6')
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2152 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2153 bitwidth = 16;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2154 if (type == 'd')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2155 val_type = octave_value (int16NDArray ());
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2156 else
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2157 val_type = octave_value (uint16NDArray ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2158 buf << s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2159 buf << s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2160 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2161 else if (s[i] == '3' && i+1 < n && s[i+1] == '2')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2162 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2163 done = false; // use default size below
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2164 buf << s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2165 buf << s[i++];
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2166 }
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2167 else if (s[i] == '6' && i+1 < n && s[i+1] == '4')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2168 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2169 bitwidth = 64;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2170 if (type == 'd')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2171 val_type = octave_value (int64NDArray ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2172 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2173 val_type = octave_value (uint64NDArray ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2174 buf << s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2175 buf << s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2176 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2177 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2178 done = false;
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2179 }
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2180 else
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2181 done = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2182
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2183 if (! done)
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2184 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2185 bitwidth = 32;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2186 if (type == 'd')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2187 val_type = octave_value (int32NDArray ());
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2188 else
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2189 val_type = octave_value (uint32NDArray ());
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2190 }
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2191 goto fini;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2192 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2193
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2194 case 'f':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2195 buf << (type = s[i++]);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2196 bitwidth = 64;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2197 if (i < n)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2198 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2199 if (s[i] == '3' && i+1 < n && s[i+1] == '2')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2200 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2201 bitwidth = 32;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2202 val_type = octave_value (FloatNDArray ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2203 buf << s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2204 buf << s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2205 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2206 else if (s[i] == '6' && i+1 < n && s[i+1] == '4')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2207 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2208 val_type = octave_value (NDArray ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2209 buf << s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2210 buf << s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2211 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2212 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2213 val_type = octave_value (NDArray ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2214 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2215 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2216 val_type = octave_value (NDArray ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2217 goto fini;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2218
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2219 case 'n':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2220 buf << (type = s[i++]);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2221 bitwidth = 64;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2222 val_type = octave_value (NDArray ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2223 goto fini;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2224
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2225 case 's': case 'q': case '[': case 'c':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2226 if (! discard)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2227 val_type = octave_value (Cell ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2228 buf << (type = s[i++]);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2229 has_string = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2230 goto fini;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2231
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2232 fini:
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2233 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2234 if (! have_width)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2235 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2236 if (type == 'c') // %c defaults to one character
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2237 width = 1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2238 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2239 width = static_cast<unsigned int> (-1); // others: unlimited
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2240 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2241
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2242 if (finish_conversion (s, i, n, width, prec, bitwidth, val_type,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2243 discard, type) == 0)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2244 return;
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2245 }
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2246 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2247
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2248 default:
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2249 error ("%s: '%%%c' is not a valid format specifier",
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2250 who.c_str (), s[i]);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2251 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2252
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2253 if (nconv < 0)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2254 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2255 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2256
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2257 nconv = -1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2258 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2259
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2260 // Parse [...] and [^...]
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2261 //
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2262 // Matlab does not expand expressions like A-Z, but they are useful, and
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2263 // so we parse them "carefully". We treat '-' as a usual character
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2264 // unless both start and end characters are from the same class (upper
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2265 // case, lower case, numeric), or this is not the first '-' in the
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2266 // pattern.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2267 //
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2268 // Keep both a running list of characters and a mask of which chars have
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2269 // occurred. The first is efficient for patterns with few characters.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2270 // The latter is efficient for [^...] patterns.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2271
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2272 std::string
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2273 textscan_format_list::parse_char_class (const std::string& pattern) const
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2274 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2275 int len = pattern.length ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2276 if (len == 0)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2277 return "";
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2278
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2279 std::string retval (256, '\0');
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2280 std::string mask (256, '\0'); // number of times chr has been seen
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2281
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2282 int in = 0, out = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2283 unsigned char ch, prev = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2284 bool flip = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2285
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2286 ch = pattern[in];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2287 if (ch == '^')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2288 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2289 in++;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2290 flip = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2291 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2292 mask[pattern[in]] = '\1';
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2293 retval[out++] = pattern[in++]; // even copy ']' if it is first
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2294
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2295 bool prev_was_range = false; // disallow "a-m-z" as a pattern
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2296 bool prev_prev_was_range = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2297 for (; in < len; in++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2298 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2299 bool was_range = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2300 ch = pattern[in];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2301 if (ch == ']')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2302 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2303
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2304 if (prev == '-' && in > 1 && isalnum (ch) && ! prev_prev_was_range)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2305 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2306 unsigned char start_of_range = pattern[in-2];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2307 if (start_of_range < ch
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2308 && ((isupper (ch) && isupper (start_of_range))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2309 || (islower (ch) && islower (start_of_range))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2310 || (isdigit (ch) && isdigit (start_of_range))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2311 || mask['-'] > 1)) // not the first '-'
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2312 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2313 was_range = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2314 out--;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2315 mask['-']--;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2316 for (int i = start_of_range; i <= ch; i++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2317 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2318 if (mask[i] == '\0')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2319 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2320 mask[i] = '\1';
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2321 retval[out++] = i;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2322 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2323 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2324 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2325 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2326 if (! was_range)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2327 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2328 if (mask[ch]++ == 0)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2329 retval[out++] = ch;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2330 else if (ch != '-')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2331 warning_with_id ("octave:textscan-pattern",
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2332 "%s: [...] contains two '%c's",
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2333 who.c_str (), ch);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2334
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2335 if (prev == '-' && mask['-'] >= 2)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2336 warning_with_id
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2337 ("octave:textscan-pattern",
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2338 "%s: [...] contains two '-'s outside range expressions",
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2339 who.c_str ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2340 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2341 prev = ch;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2342 prev_prev_was_range = prev_was_range;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2343 prev_was_range = was_range;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2344 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2345
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2346 if (flip) // [^...]
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2347 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2348 out = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2349 for (int i = 0; i < 256; i++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2350 if (! mask[i])
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2351 retval[out++] = i;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2352 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2353
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2354 retval.resize (out);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2355
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2356 return retval;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2357 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2358
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2359 int
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2360 textscan_format_list::finish_conversion (const std::string& s, size_t& i,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2361 size_t n, unsigned int& width,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2362 int& prec, int& bitwidth,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2363 octave_value& val_type, bool discard,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2364 char& type)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2365 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2366 int retval = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2367
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2368 std::string char_class;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2369
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2370 size_t beg_idx = std::string::npos;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2371 size_t end_idx = std::string::npos;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2372
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2373 if (type != '%')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2374 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2375 nconv++;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2376 if (type == '[')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2377 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2378 if (i < n)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2379 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2380 beg_idx = i;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2381
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2382 if (s[i] == '^')
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2383 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2384 type = '^';
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2385 buf << s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2386
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2387 if (i < n)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2388 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2389 beg_idx = i;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2390
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2391 if (s[i] == ']')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2392 buf << s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2393 }
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2394 }
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2395 else if (s[i] == ']')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2396 buf << s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2397 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2398
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2399 while (i < n && s[i] != ']')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2400 buf << s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2401
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2402 if (i < n && s[i] == ']')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2403 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2404 end_idx = i-1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2405 buf << s[i++];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2406 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2407
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2408 if (s[i-1] != ']')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2409 retval = nconv = -1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2410 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2411 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2412
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2413 if (nconv >= 0)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2414 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2415 if (beg_idx != std::string::npos && end_idx != std::string::npos)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2416 char_class = parse_char_class (s.substr (beg_idx,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2417 end_idx - beg_idx + 1));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2418
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2419 add_elt_to_list (width, prec, bitwidth, val_type, discard, type,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2420 char_class);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2421 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2422
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2423 return retval;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2424 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2425
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2426 void
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2427 textscan_format_list::printme (void) const
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2428 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2429 size_t n = numel ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2430
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2431 for (size_t i = 0; i < n; i++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2432 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2433 textscan_format_elt *elt = fmt_elts[i];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2434
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2435 std::cerr
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2436 << "width: " << elt->width << "\n"
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2437 << "digits " << elt->prec << "\n"
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2438 << "bitwidth: " << elt->bitwidth << "\n"
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2439 << "discard: " << elt->discard << "\n"
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2440 << "type: ";
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2441
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2442 if (elt->type == textscan_format_elt::literal_conversion)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2443 std::cerr << "literal text\n";
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2444 else if (elt->type == textscan_format_elt::whitespace_conversion)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2445 std::cerr << "whitespace\n";
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2446 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2447 std::cerr << elt->type << "\n";
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2448
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2449 std::cerr
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2450 << "char_class: `" << undo_string_escapes (elt->char_class) << "'\n"
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2451 << "text: `" << undo_string_escapes (elt->text) << "'\n\n";
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2452 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2453 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2454
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2455 // If FORMAT is explicitly "", it is assumed to be "%f" repeated enough
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2456 // times to read the first row of the file. Set it now.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2457
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2458 int
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2459 textscan_format_list::read_first_row (delimited_stream& is, textscan& ts)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2460 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2461 // Read first line and strip end-of-line, which may be two characters
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2462 std::string first_line (20, ' ');
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2463
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2464 is.getline (first_line, static_cast<char> (ts.eol2));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2465
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2466 if (! first_line.empty ()
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2467 && first_line[first_line.length () - 1] == ts.eol1)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2468 first_line.resize (first_line.length () - 1);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2469
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2470 std::istringstream strstr (first_line);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2471 delimited_stream ds (strstr, is);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2472
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2473 dim_vector dv (1,1); // initial size of each output_container
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2474 Complex val;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2475 octave_value val_type;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2476 nconv = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2477 int max_empty = 1000; // failsafe, if ds fails but not with eof
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2478 int retval = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2479
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2480 // read line, creating output_container as we go
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2481 while (! ds.eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2482 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2483 bool already_skipped_delim = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2484 ts.skip_whitespace (ds);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2485 ds.progress_benchmark ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2486 bool progress = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2487 ts.scan_complex (ds, *fmt_elts[0], val);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2488 if (ds.fail ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2489 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2490 ds.clear (ds.rdstate () & ~std::ios::failbit);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2491
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2492 if (ds.eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2493 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2494
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2495 // Unless this was a missing value (i.e., followed by a delimiter),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2496 // return with an error status.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2497 ts.skip_delim (ds);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2498 if (ds.no_progress ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2499 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2500 retval = 4;
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2501 break;
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2502 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2503 already_skipped_delim = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2504
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2505 val = ts.empty_value.scalar_value ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2506
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2507 if (! --max_empty)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2508 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2509 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2510
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2511 if (val.imag () == 0)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2512 val_type = octave_value (NDArray (dv, val.real ()));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2513 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2514 val_type = octave_value (ComplexNDArray (dv, val));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2515
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2516 output_container.push_back (val_type);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2517
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2518 if (! already_skipped_delim)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2519 ts.skip_delim (ds);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2520
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2521 if (! progress && ds.no_progress ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2522 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2523
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2524 nconv++;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2525 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2526
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2527 output_container.pop_front (); // discard empty element from constructor
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2528
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2529 // Create fmt_list now that the size is known
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2530 for (octave_idx_type i = 1; i < nconv; i++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2531 fmt_elts.push_back (new textscan_format_elt (*fmt_elts[0]));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2532
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2533 return retval; // May have returned 4 above.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2534 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2535
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2536 textscan::textscan (const std::string& who_arg)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2537 : who (who_arg), buf (), whitespace_table (), delim_table (),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2538 delims (), comment_style (), comment_len (0), comment_char (-2),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2539 buffer_size (0), date_locale (), inf_nan (init_inf_nan ()),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2540 empty_value (octave::numeric_limits<double>::NaN ()), exp_chars ("edED"),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2541 header_lines (0), treat_as_empty (), treat_as_empty_len (0),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2542 whitespace (" \b\t"), eol1 ('\r'), eol2 ('\n'),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2543 return_on_error (1), collect_output (false),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2544 multiple_delims_as_one (false), default_exp (true),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2545 numeric_delim (false), lines (0)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2546 { }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2547
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2548 octave_value
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2549 textscan::scan (std::istream& isp, const std::string& fmt,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2550 octave_idx_type ntimes, const octave_value_list& options,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2551 octave_idx_type& count)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2552 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2553 textscan_format_list fmt_list (fmt);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2554
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2555 parse_options (options, fmt_list);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2556
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2557 octave_value result = do_scan (isp, fmt_list, ntimes);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2558
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2559 // FIXME: this is probably not the best way to get count. The
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2560 // position could easily be larger than octave_idx_type when using
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2561 // 32-bit indexing.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2562
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2563 std::ios::iostate state = isp.rdstate ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2564 isp.clear ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2565 count = static_cast<octave_idx_type> (isp.tellg ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2566 isp.setstate (state);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2567
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2568 return result;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2569 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2570
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2571 octave_value
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2572 textscan::do_scan (std::istream& isp, textscan_format_list& fmt_list,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2573 octave_idx_type ntimes)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2574 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2575 octave_value retval;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2576
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2577 if (fmt_list.num_conversions () == -1)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2578 error ("%s: invalid format specified", who.c_str ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2579
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2580 if (fmt_list.num_conversions () == 0)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2581 error ("%s: no valid format conversion specifiers", who.c_str ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2582
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2583 // skip the first header_lines
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2584 std::string dummy;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2585 for (int i = 0; i < header_lines && isp; i++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2586 getline (isp, dummy, static_cast<char> (eol2));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2587
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2588 // Create our own buffered stream, for fast get/putback/tell/seek.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2589
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2590 // First, see how far ahead it should let us look.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2591 int max_lookahead = std::max (std::max (comment_len, treat_as_empty_len),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2592 std::max (delim_len, 3)); // 3 for NaN and Inf
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2593
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2594 // Next, choose a buffer size to avoid reading too much, or too often.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2595 octave_idx_type buf_size = 4096;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2596 if (buffer_size)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2597 buf_size = buffer_size;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2598 else if (ntimes > 0)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2599 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2600 // Avoid overflow of 80*ntimes...
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2601 buf_size = std::min (buf_size, std::max (ntimes, 80 * ntimes));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2602 buf_size = std::max (buf_size, ntimes);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2603 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2604 // Finally, create the stream.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2605 delimited_stream is (isp,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2606 (delim_table.empty () ? whitespace + "\r\n" : delims),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2607 max_lookahead, buf_size);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2608
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2609 // Grow retval dynamically. "size" is half the initial size
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2610 // (FIXME: Should we start smaller if ntimes is large?)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2611 octave_idx_type size = ((ntimes < 8 && ntimes >= 0) ? ntimes : 1);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2612 Array<octave_idx_type> row_idx (dim_vector (1,2));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2613 row_idx(1) = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2614
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2615 int err = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2616 octave_idx_type row = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2617
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2618 if (multiple_delims_as_one) // bug #44750?
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2619 skip_delim (is);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2620
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2621 int done_after; // Number of columns read when EOF seen.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2622
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2623 // If FORMAT explicitly "", read first line and see how many "%f" match
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2624 if (fmt_list.set_from_first)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2625 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2626 err = fmt_list.read_first_row (is, *this);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2627 lines = 1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2628
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2629 done_after = fmt_list.numel () + 1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2630 if (! err)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2631 row = 1; // the above puts the first line into fmt_list.out_buf ()
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2632 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2633 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2634 done_after = fmt_list.out_buf ().size () + 1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2635
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2636 std::list<octave_value> out = fmt_list.out_buf ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2637
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2638 // We will later merge adjacent columns of the same type.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2639 // Check now which columns to merge.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2640 // Reals may become complex, and so we can't trust types
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2641 // after reading in data.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2642 // If the format was "", that conversion may already have happened,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2643 // so force all to be merged (as all are %f).
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2644 bool merge_with_prev[fmt_list.numel ()];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2645 int conv = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2646 if (collect_output)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2647 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2648 int prev_type = -1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2649 for (std::list<octave_value>::iterator col = out.begin ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2650 col != out.end (); col++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2651 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2652 if (col->type_id () == prev_type
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2653 || (fmt_list.set_from_first && prev_type != -1))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2654 merge_with_prev [conv++] = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2655 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2656 merge_with_prev [conv++] = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2657
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2658 prev_type = col->type_id ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2659 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2660 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2661
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2662 // This should be caught by earlier code, but this avoids a possible
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2663 // infinite loop below.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2664 if (fmt_list.num_conversions () == 0)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2665 error ("%s: No conversions specified", who.c_str ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2666
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2667 // Read the data. This is the main loop.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2668 if (! err)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2669 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2670 for (/* row set ~30 lines above */; row < ntimes || ntimes == -1; row++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2671 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2672 if (row == 0 || row >= size)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2673 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2674 size += size+1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2675 for (std::list<octave_value>::iterator col = out.begin ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2676 col != out.end (); col++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2677 *col = (*col).resize (dim_vector (size, 1), 0);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2678 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2679
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2680 row_idx(0) = row;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2681 err = read_format_once (is, fmt_list, out, row_idx, done_after);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2682
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2683 if ((err & ~1) > 0 || ! is || (lines >= ntimes && ntimes > -1))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2684 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2685 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2686 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2687
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2688 if ((err & 4) && ! return_on_error)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2689 error ("%s: Read error in field %d of row %d", who.c_str (),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2690 done_after + 1, row + 1);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2691
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2692 // If file does not end in EOL, do not pad columns with NaN.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2693 bool uneven_columns = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2694 if (err & 4)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2695 uneven_columns = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2696 else if (isp.eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2697 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2698 isp.clear ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2699 isp.seekg (-1, std::ios_base::end);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2700 int last_char = isp.get ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2701 isp.setstate (isp.eofbit);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2702 uneven_columns = (last_char != eol1 && last_char != eol2);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2703 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2704
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2705 // convert return value to Cell array
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2706 Array<octave_idx_type> ra_idx (dim_vector (1,2));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2707
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2708 // (err & 1) means "error, and no columns read this row
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2709 // FIXME: This may redundant now that done_after=0 says the same
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2710 if (err & 1)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2711 done_after = out.size () + 1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2712
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2713 int valid_rows = (row == ntimes) ? ntimes
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
2714 : (((err & 1) && (err & 8)) ? row : row+1);
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2715 dim_vector dv (valid_rows, 1);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2716
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2717 ra_idx(0) = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2718 int i = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2719 if (! collect_output)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2720 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2721 retval = Cell (dim_vector (1, out.size ()));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2722 for (std::list<octave_value>::iterator col = out.begin ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2723 col != out.end (); col++, i++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2724 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2725 // trim last columns if that was requested
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2726 if (i == done_after && uneven_columns)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2727 dv = dim_vector (std::max (valid_rows - 1, 0), 1);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2728
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2729 ra_idx(1) = i;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2730 retval = do_cat_op (retval, octave_value (Cell (col->resize (dv,0))),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2731 ra_idx);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2732 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2733 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2734 else // group adjacent cells of the same type into a single cell
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2735 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2736 octave_value cur; // current cell, accumulating columns
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2737 octave_idx_type group_size = 0; // columns in this cell
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2738 int prev_type = -1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2739
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2740 conv = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2741 retval = Cell ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2742 for (std::list<octave_value>::iterator col = out.begin ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2743 col != out.end (); col++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2744 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2745 if (! merge_with_prev [conv++]) // including first time
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2746 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2747 if (prev_type != -1)
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2748 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2749 ra_idx(1) = i++;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2750 retval = do_cat_op (retval, octave_value (Cell (cur)),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2751 ra_idx);
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2752 }
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2753 cur = octave_value (col->resize (dv,0));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2754 group_size = 1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2755 prev_type = col->type_id ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2756 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2757 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2758 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2759 ra_idx(1) = group_size++;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2760 cur = do_cat_op (cur, octave_value (col->resize (dv,0)),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2761 ra_idx);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2762 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2763 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2764 ra_idx(1) = i;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2765 retval = do_cat_op (retval, octave_value (Cell (cur)), ra_idx);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2766 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2767
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2768 return retval;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2769 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2770
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2771 // Read a double considering the "precision" field of FMT and the
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2772 // EXP_CHARS option of OPTIONS.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2773
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2774 double
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2775 textscan::read_double (delimited_stream& is,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2776 const textscan_format_elt& fmt) const
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2777 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2778 int sign = 1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2779 unsigned int width_left = fmt.width;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2780 double retval = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2781 bool valid = false; // syntactically correct double?
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2782
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2783 int ch = is.peek ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2784
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2785 if (ch == '+')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2786 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2787 is.get ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2788 ch = is.peek ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2789 if (width_left)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2790 width_left--;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2791 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2792 else if (ch == '-')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2793 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2794 sign = -1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2795 is.get ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2796 ch = is.peek ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2797 if (width_left)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2798 width_left--;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2799 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2800
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2801 // Read integer part
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2802 if (ch != '.')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2803 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2804 if (ch >= '0' && ch <= '9') // valid if at least one digit
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2805 valid = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2806 while (width_left-- && is && (ch = is.get ()) >= '0' && ch <= '9')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2807 retval = retval * 10 + (ch - '0');
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2808 width_left++;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2809 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2810
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2811 // Read fractional part, up to specified precision
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2812 if (ch == '.' && width_left)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2813 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2814 double multiplier = 1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2815 int precision = fmt.prec;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2816 int i;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2817
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2818 if (width_left)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2819 width_left--; // Consider width of '.'
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2820
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2821 if (precision == -1)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2822 precision = 1<<30; // FIXME: Should be MAXINT
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2823
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2824 if (! valid) // if there was nothing before '.'...
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2825 is.get (); // ...ch was a "peek", not "get".
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2826
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2827 for (i = 0; i < precision; i++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2828 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2829 if (width_left-- && is && (ch = is.get ()) >= '0' && ch <= '9')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2830 retval += (ch - '0') * (multiplier *= 0.1);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2831 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2832 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2833 width_left++;
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2834 break;
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2835 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2836 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2837
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2838 // round up if we truncated and the next digit is >= 5
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2839 if ((i == precision || ! width_left) && (ch = is.get ()) >= '5'
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2840 && ch <= '9')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2841 retval += multiplier;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2842
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2843 if (i > 0)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2844 valid = true; // valid if at least one digit after '.'
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2845
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2846 // skip remainder after '.', to field width, to look for exponent
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2847 if (i == precision)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2848 while (width_left-- && is && (ch = is.get ()) >= '0' && ch <= '9')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2849 ; // discard
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2850
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2851 width_left++;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2852 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2853
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2854 // look for exponent part in, e.g., 6.023E+23
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2855 bool used_exp = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2856 if (valid && width_left > 1 && exp_chars.find (ch) != std::string::npos)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2857 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2858 int ch1 = is.peek ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2859 if (ch1 == '-' || ch1 == '+' || (ch1 >= '0' && ch1 <= '9'))
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
2860 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
2861 // if 1.0e+$ or some such, this will set failbit, as we want
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2862 width_left--; // count "E"
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2863 int exp = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2864 int exp_sign = 1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2865 if (ch1 == '+')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2866 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2867 if (width_left)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2868 width_left--;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2869 is.get ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2870 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2871 else if (ch1 == '-')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2872 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2873 exp_sign = -1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2874 is.get ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2875 if (width_left)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2876 width_left--;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2877 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2878 valid = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2879 while (width_left-- && is && (ch = is.get ()) >= '0' && ch <= '9')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2880 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2881 exp = exp*10 + ch - '0';
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2882 valid = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2883 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2884 width_left++;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2885 if (ch != std::istream::traits_type::eof () && width_left)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2886 is.putback (ch);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2887
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2888 double multiplier = pown (10, exp);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2889 if (exp_sign > 0)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2890 retval *= multiplier;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2891 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2892 retval /= multiplier;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2893
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2894 used_exp = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2895 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2896 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2897 is.clear ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2898 if (! used_exp && ch != std::istream::traits_type::eof () && width_left)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2899 is.putback (ch);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2900
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2901 // Check for +/- inf and NaN
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2902 if (! valid && width_left >= 3)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2903 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2904 int i = lookahead (is, inf_nan, 3, false); // false -> case insensitive
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2905 if (i == 0)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2906 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2907 retval = octave::numeric_limits<double>::Inf ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2908 valid = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2909 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2910 else if (i == 1)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2911 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2912 retval = octave::numeric_limits<double>::NaN ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2913 valid = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2914 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2915 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2916
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2917 // Check for +/- inf and NaN
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2918 if (! valid && width_left >= 3)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2919 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2920 int i = lookahead (is, inf_nan, 3, false); // false -> case insensitive
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2921 if (i == 0)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2922 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2923 retval = octave::numeric_limits<double>::Inf ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2924 valid = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2925 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2926 else if (i == 1)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2927 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2928 retval = octave::numeric_limits<double>::NaN ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2929 valid = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2930 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2931 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2932
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2933 if (! valid)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2934 is.setstate (std::ios::failbit);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2935 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2936 is.setstate (is.rdstate () & ~std::ios::failbit);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2937
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2938 return retval * sign;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2939 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2940
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2941 // Read a single number: real, complex, inf, NaN, possibly with limited
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2942 // precision. Calls to this should be preceded by skip_whitespace.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2943 // Calling that inside scan_complex would violate its const declaration.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2944
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2945 void
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2946 textscan::scan_complex (delimited_stream& is, const textscan_format_elt& fmt,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2947 Complex& val) const
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2948 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2949 double im = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2950 double re = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2951 bool as_empty = false; // did we fail but match a "treat_as_empty" string?
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2952 bool inf = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2953
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2954 int ch = is.peek ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2955 if (ch == '+' || ch == '-') // check for [+-][ij] with no coefficients
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2956 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2957 ch = is.get ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2958 int ch2 = is.peek ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2959 if (ch2 == 'i' || ch2 == 'j')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2960 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2961 double value = 1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2962 is.get ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2963 // Check not -inf
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2964 if (is.peek () == 'n')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2965 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2966 char *pos = is.tellg ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2967 std::ios::iostate state = is.rdstate ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2968
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2969 is.get ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2970 ch2 = is.get ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2971 if (ch2 == 'f')
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2972 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2973 inf = true;
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
2974 re = (ch == '+') ? octave::numeric_limits<double>::Inf ()
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
2975 : -octave::numeric_limits<double>::Inf ();
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2976 value = 0;
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2977 }
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2978 else
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
2979 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2980 is.clear (state);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2981 is.seekg (pos); // reset to position before look-ahead
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2982 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2983 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2984
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2985 im = (ch == '+') ? value : -value;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2986 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2987 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2988 is.putback (ch);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2989 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2990
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2991 if (! im && ! inf) // if not [+-][ij] or [+-]inf, read real normally
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2992 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2993 char *pos = is.tellg ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2994 std::ios::iostate state = is.rdstate ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2995 //re = octave_read_value<double> (is);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2996 re = read_double (is, fmt);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2997
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2998 // check for "treat as empty" string
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2999 if (treat_as_empty.numel ()
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3000 && (is.fail () || octave::math::is_NaN_or_NA (Complex (re))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3001 || re == octave::numeric_limits<double>::Inf ()))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3002 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3003
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3004 for (int i = 0; i < treat_as_empty.numel (); i++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3005 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3006 if (ch == treat_as_empty (i).string_value ()[0])
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3007 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3008 as_empty = true; // first char matches, so read the lot
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3009 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3010 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3011 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3012 if (as_empty) // if first char matched...
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3013 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3014 as_empty = false; // ...look for the whole string
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3015
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3016 is.clear (state); // treat_as_empty "-" causes partial read
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3017 is.seekg (pos); // reset to position before failed read
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3018
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3019 // treat_as_empty strings may be different sizes.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3020 // Read ahead longest, put it all back, then re-read the string
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3021 // that matches.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3022 std::string look_buf (treat_as_empty_len, '\0');
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3023 char *look = is.read (&look_buf[0], look_buf.size (), pos);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3024
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3025 is.clear (state);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3026 is.seekg (pos); // reset to position before look-ahead
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3027 // FIXME: is.read could invalidate pos
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3028
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3029 for (int i = 0; i < treat_as_empty.numel (); i++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3030 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3031 std::string s = treat_as_empty (i).string_value ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3032 if (! strncmp (s.c_str (), look, s.size ()))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3033 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3034 as_empty = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3035 // read just the right amount
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3036 is.read (&look_buf[0], s.size (), pos);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3037 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3038 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3039 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3040 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3041 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3042
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3043 if (! is.eof () && ! as_empty)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3044 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3045 state = is.rdstate (); // before tellg, since that fails at EOF
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3046 pos = is.tellg ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3047 ch = is.peek (); // ch == EOF if read failed; no need to chk fail
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3048 if (ch == 'i' || ch == 'j') // pure imaginary
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3049 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3050 is.get ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3051 im = re;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3052 re = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3053 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3054 else if (ch == '+' || ch == '-') // see if it is real+imag[ij]
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3055 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3056 // save stream state in case we have to restore it
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3057 pos = is.tellg ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3058 state = is.rdstate ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3059
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3060 //im = octave_read_value<double> (is);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3061 im = read_double (is, fmt);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3062 if (is.fail ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3063 im = 1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3064
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3065 if (is.peek () == 'i' || is.peek () == 'j')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3066 is.get ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3067 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3068 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3069 im = 0; // no valid imaginary part. Restore state
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3070 is.clear (state); // eof shouldn't cause fail.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3071 is.seekg (pos);
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
3072 }
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3073 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3074 else if (is.eof ()) // we've read enough to be a "valid" read
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3075 is.clear (state); // failed peek shouldn't cause fail
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3076 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3077 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3078 if (as_empty)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3079 val = empty_value.scalar_value ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3080 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3081 val = Complex (re, im);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3082 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3083
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3084 // Return in VAL the run of characters from IS NOT contained in PATTERN.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3085
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3086 int
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3087 textscan::scan_caret (delimited_stream& is, const std::string& pattern,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3088 std::string& val) const
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3089 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3090 int c1 = std::istream::traits_type::eof ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3091 std::ostringstream obuf; // Is this optimized for growing?
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3092
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3093 while (is && ((c1 = (is && ! is.eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3094 ? is.get_undelim ()
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3095 : std::istream::traits_type::eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3096 != std::istream::traits_type::eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3097 && pattern.find (c1) == std::string::npos)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3098 obuf << static_cast<char> (c1);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3099
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3100 val = obuf.str ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3101
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3102 if (c1 != std::istream::traits_type::eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3103 is.putback (c1);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3104
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3105 return c1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3106 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3107
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3108 // Read until one of the strings in DELIMITERS is found. For
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3109 // efficiency, ENDS is a list of the last character of each delimiter.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3110
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3111 std::string
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3112 textscan::read_until (delimited_stream& is, const Cell& delimiters,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3113 const std::string& ends) const
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3114 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3115 std::string retval ("");
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3116 bool done = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3117 do
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3118 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3119 // find sequence ending with an ending char
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3120 std::string next;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3121 scan_caret (is, ends.c_str (), next);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3122 retval = retval + next; // FIXME: could use repeated doubling of size
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3123
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3124 int last = (! is.eof ()
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3125 ? is.get_undelim () : std::istream::traits_type::eof ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3126
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3127 if (last != std::istream::traits_type::eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3128 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3129 retval = retval + static_cast<char> (last);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3130 for (int i = 0; i < delimiters.numel (); i++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3131 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3132 std::string delim = delimiters(i).string_value ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3133 size_t start = (retval.length () > delim.length ()
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3134 ? retval.length () - delim.length ()
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3135 : 0);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3136 std::string may_match = retval.substr (start);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3137 if (may_match == delim)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3138 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3139 done = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3140 retval = retval.substr (0, start);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3141 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3142 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3143 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3144 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3145 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3146 while (! done && is && ! is.eof ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3147
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3148 return retval;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3149 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3150
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3151 // Read stream until either fmt.width chars have been read, or
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3152 // options.delimiter has been found. Does *not* rely on fmt being 's'.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3153 // Used by formats like %6f to limit to 6.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3154
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3155 void
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3156 textscan::scan_string (delimited_stream& is, const textscan_format_elt& fmt,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3157 std::string& val) const
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3158 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3159 if (delim_list.is_empty ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3160 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3161 unsigned int i = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3162 unsigned int width = fmt.width;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3163
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3164 for (i = 0; i < width; i++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3165 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3166 if (i+1 > val.length ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3167 val = val + val + ' '; // grow even if empty
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3168 int ch = is.get ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3169 if (is_delim (ch) || ch == std::istream::traits_type::eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3170 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3171 is.putback (ch);
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
3172 break;
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3173 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3174 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3175 val[i] = ch;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3176 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3177 val = val.substr (0, i); // trim pre-allocation
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3178 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3179 else // Cell array of multi-character delimiters
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3180 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3181 std::string ends ("");
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3182 for (int i = 0; i < delim_list.numel (); i++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3183 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3184 std::string tmp = delim_list(i).string_value ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3185 ends += tmp.substr (tmp.length () - 1);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3186 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3187 val = textscan::read_until (is, delim_list, ends);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3188 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3189 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3190
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3191 // Return in VAL the run of characters from IS contained in PATTERN.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3192
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3193 int
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3194 textscan::scan_bracket (delimited_stream& is, const std::string& pattern,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3195 std::string& val) const
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3196 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3197 int c1 = std::istream::traits_type::eof ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3198 std::ostringstream obuf; // Is this optimized for growing?
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3199
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3200 while (is && pattern.find (c1 = is.get_undelim ()) != std::string::npos)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3201 obuf << static_cast<char> (c1);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3202
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3203 val = obuf.str ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3204 if (c1 != std::istream::traits_type::eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3205 is.putback (c1);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3206 return c1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3207 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3208
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3209 // Return in VAL a string, either delimited by whitespace/delimiters, or
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3210 // enclosed in a pair of double quotes ("..."). Enclosing quotes are
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3211 // removed. A consecutive pair "" is inserted into VAL as a single ".
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3212
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3213 void
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3214 textscan::scan_qstring (delimited_stream& is, const textscan_format_elt& fmt,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3215 std::string& val)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3216 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3217 skip_whitespace (is);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3218
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3219 if (is.peek () != '\"')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3220 scan_string (is, fmt, val);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3221 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3222 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3223 is.get ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3224 scan_caret (is, "\"", val); // read everything until "
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3225 is.get (); // swallow "
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3226
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3227 while (is && is.peek () == '\"') // if double ", insert one in stream,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3228 { // and keep looking for single "
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3229 is.get ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3230 std::string val1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3231 scan_caret (is, "\"", val1);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3232 val = val + "\"" + val1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3233 is.get_undelim ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3234 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3235 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3236 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3237
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3238 // Read from IS into VAL a string of the next fmt.width characters,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3239 // including any whitespace or delimiters.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3240
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3241 void
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3242 textscan::scan_cstring (delimited_stream& is, const textscan_format_elt& fmt,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3243 std::string& val) const
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3244 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3245 val.resize (fmt.width);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3246
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3247 for (unsigned int i = 0; is && i < fmt.width; i++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3248 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3249 int ch = is.get_undelim ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3250 if (ch != std::istream::traits_type::eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3251 val[i] = ch;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3252 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3253 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3254 val.resize (i);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3255 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3256 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3257 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3258 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3259
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3260 // Read a single '%...' conversion and place it in position ROW of OV.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3261
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3262 void
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3263 textscan::scan_one (delimited_stream& is, const textscan_format_elt& fmt,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3264 octave_value& ov, Array<octave_idx_type> row)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3265 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3266 skip_whitespace (is);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3267
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3268 is.clear ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3269
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3270 octave_value val;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3271 if (fmt.numeric)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3272 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3273 if (fmt.type == 'f' || fmt.type == 'n')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3274 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3275 Complex v;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3276 skip_whitespace (is);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3277 scan_complex (is, fmt, v);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3278
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3279 if (! fmt.discard && ! is.fail ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3280 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3281 if (fmt.bitwidth == 64)
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
3282 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3283 if (ov.is_real_type () && v.imag () == 0)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3284 ov.internal_rep ()->fast_elem_insert (row(0), v.real ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3285 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3286 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3287 if (ov.is_real_type ()) // cat does type conversion
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3288 ov = do_cat_op (ov, octave_value (v), row);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3289 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3290 ov.internal_rep ()->fast_elem_insert (row(0), v);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3291 }
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
3292 }
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
3293 else
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
3294 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3295 if (ov.is_real_type () && v.imag () == 0)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3296 ov.internal_rep ()->fast_elem_insert (row(0),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3297 float (v.real ()));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3298 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3299 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3300 if (ov.is_real_type ()) // cat does type conversion
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3301 ov = do_cat_op (ov, octave_value (v), row);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3302 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3303 ov.internal_rep ()->fast_elem_insert (row(0),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3304 FloatComplex (v));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3305 }
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
3306 }
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
3307 }
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3308 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3309 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3310 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3311 double v; // Matlab docs say 1e30 etc should be valid for %d and
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3312 // 1000 as a %d8 should be 127, so read as double.
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3313 // Some loss of precision for d64 and u64.
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3314 skip_whitespace (is);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3315 v = read_double (is, fmt);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3316 if (! fmt.discard && ! is.fail ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3317 switch (fmt.bitwidth)
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
3318 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3319 case 64:
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3320 switch (fmt.type)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3321 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3322 case 'd':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3323 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3324 octave_int64 vv = v;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3325 ov.internal_rep ()->fast_elem_insert (row(0), vv);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3326 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3327 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3328
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3329 case 'u':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3330 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3331 octave_uint64 vv = v;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3332 ov.internal_rep ()->fast_elem_insert (row(0), vv);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3333 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3334 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3335 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3336 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3337
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3338 case 32:
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3339 switch (fmt.type)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3340 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3341 case 'd':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3342 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3343 octave_int32 vv = v;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3344 ov.internal_rep ()->fast_elem_insert (row(0), vv);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3345 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3346 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3347
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3348 case 'u':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3349 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3350 octave_uint32 vv = v;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3351 ov.internal_rep ()->fast_elem_insert (row(0), vv);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3352 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3353 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3354 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3355 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3356
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3357 case 16:
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3358 if (fmt.type == 'd')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3359 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3360 octave_int16 vv = v;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3361 ov.internal_rep ()->fast_elem_insert (row(0), vv);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3362 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3363 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3364 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3365 octave_uint16 vv = v;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3366 ov.internal_rep ()->fast_elem_insert (row(0), vv);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3367 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3368 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3369
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3370 case 8:
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3371 if (fmt.type == 'd')
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3372 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3373 octave_int8 vv = v;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3374 ov.internal_rep ()->fast_elem_insert (row(0), vv);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3375 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3376 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3377 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3378 octave_uint8 vv = v;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3379 ov.internal_rep ()->fast_elem_insert (row(0), vv);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3380 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3381 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3382 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3383 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3384
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3385 if (is.fail () & ! fmt.discard)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3386 ov = do_cat_op (ov, empty_value, row);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3387 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3388 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3389 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3390 std::string vv (" "); // initial buffer. Grows as needed
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3391 switch (fmt.type)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3392 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3393 case 's':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3394 scan_string (is, fmt, vv);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3395 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3396
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3397 case 'q':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3398 scan_qstring (is, fmt, vv);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3399 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3400
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3401 case 'c':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3402 scan_cstring (is, fmt, vv);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3403 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3404
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3405 case '[':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3406 scan_bracket (is, fmt.char_class.c_str (), vv);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3407 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3408
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3409 case '^':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3410 scan_caret (is, fmt.char_class.c_str (), vv);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3411 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3412 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3413
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3414 if (! fmt.discard)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3415 ov.internal_rep ()->fast_elem_insert (row (0),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3416 Cell (octave_value (vv)));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3417
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3418 // FIXME: why does failbit get set at EOF, instead of eofbit?
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3419 if (! vv.empty ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3420 is.clear (is.rdstate () & ~std::ios_base::failbit);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3421 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3422
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3423 is.field_done ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3424 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3425
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3426 // Read data corresponding to the entire format string once, placing the
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3427 // values in row ROW of retval.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3428
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3429 int
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3430 textscan::read_format_once (delimited_stream& is,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3431 textscan_format_list& fmt_list,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3432 std::list<octave_value>& retval,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3433 Array<octave_idx_type> row, int& done_after)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3434 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3435 const textscan_format_elt *elem = fmt_list.first ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3436 std::list<octave_value>::iterator out = retval.begin ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3437 bool no_conversions = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3438 bool done = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3439 bool conversion_failed = false; // Record for ReturnOnError
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3440 bool nothing_worked = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3441
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3442 octave_quit ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3443
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3444 for (size_t i = 0; i < fmt_list.numel (); i++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3445 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3446 bool this_conversion_failed = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3447
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3448 // Clear fail of previous numeric conversions.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3449 is.clear ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3450
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3451 switch (elem->type)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3452 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3453 case 'C':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3454 case 'D':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3455 warning ("%s: conversion %c not yet implemented",
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3456 who.c_str (), elem->type);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3457 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3458
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3459 case 'u':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3460 case 'd':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3461 case 'f':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3462 case 'n':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3463 case 's':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3464 case '[':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3465 case '^':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3466 case 'q':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3467 case 'c':
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3468 scan_one (is, *elem, *out, row);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3469 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3470
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3471 case textscan_format_elt::literal_conversion :
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3472 match_literal (is, *elem);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3473 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3474
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3475 default:
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3476 error ("Unknown format element '%c'", elem->type);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3477 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3478
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3479 if (! is.fail ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3480 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3481 if (! elem->discard)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3482 no_conversions = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3483 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3484 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3485 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3486 is.clear (is.rdstate () & ~std::ios::failbit);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3487
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3488 if (!is.eof () && ~is_delim (is.peek ()))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3489 this_conversion_failed = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3490 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3491
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3492 if (! elem->discard)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3493 out++;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3494
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3495 elem = fmt_list.next ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3496 char *pos = is.tellg ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3497
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3498 // FIXME: these conversions "ignore delimiters". Should they include
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3499 // delimiters at the start of the conversion, or can those be skipped?
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3500 if (elem->type != textscan_format_elt::literal_conversion
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3501 // && elem->type != '[' && elem->type != '^' && elem->type != 'c'
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3502 )
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3503 skip_delim (is);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3504
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3505 if (is.eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3506 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3507 if (! done)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3508 done_after = i+1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3509
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3510 // note EOF, but process others to get empty_val.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3511 done = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3512 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3513
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3514 if (this_conversion_failed)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3515 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3516 if (is.tellg () == pos && ! conversion_failed)
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3517 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3518 // done_after = first failure
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3519 done_after = i; // note fail, but parse others to get empty_val
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3520 conversion_failed = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3521 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3522 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3523 this_conversion_failed = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3524 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3525 else if (! done && !conversion_failed)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3526 nothing_worked = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3527 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3528
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3529 if (done)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3530 is.setstate (std::ios::eofbit);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3531
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3532 return no_conversions
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3533 + (is.eof () ? 2 : 0)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3534 + (conversion_failed ? 4 : 0)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3535 + (nothing_worked ? 8 : 0);
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3536
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3537 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3538
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3539 void
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3540 textscan::parse_options (const octave_value_list& args,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3541 textscan_format_list& fmt_list)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3542 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3543 int last = args.length ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3544 int n = last;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3545
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3546 if (n & 1)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3547 error ("%s: %d parameters given, but only %d values",
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3548 who.c_str (), n-n/2, n/2);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3549
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3550 delim_len = 1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3551 bool have_delims = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3552 for (int i = 0; i < last; i += 2)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3553 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3554 std::string param = args(i).xstring_value ("%s: Invalid parameter type <%s> for parameter %d",
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3555 who.c_str (),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3556 args(i).type_name ().c_str (),
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3557 i/2 + 1);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3558 std::transform (param.begin (), param.end (), param.begin (), ::tolower);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3559
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3560 if (param == "delimiter")
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3561 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3562 bool invalid = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3563 if (args(i+1).is_string ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3564 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3565 invalid = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3566 have_delims = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3567 delims = args(i+1).string_value ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3568 if (args(i+1).is_sq_string ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3569 delims = do_string_escapes (delims);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3570 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3571 else if (args(i+1).is_cell ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3572 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3573 invalid = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3574 delim_list = args(i+1).cell_value ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3575 delim_table = " "; // non-empty, to flag non-default delim
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3576
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3577 // Check that all elements are strings, and find max length
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3578 for (int j = 0; j < delim_list.numel (); j++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3579 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3580 if (! delim_list(j).is_string ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3581 invalid = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3582 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3583 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3584 if (delim_list(j).is_sq_string ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3585 delim_list(j) = do_string_escapes (delim_list(j)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3586 .string_value ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3587 octave_idx_type len = delim_list(j).string_value ()
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3588 .length ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3589 delim_len = std::max (static_cast<int> (len), delim_len);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3590 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3591 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3592 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3593 if (invalid)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3594 error ("%s: Delimiters must be either a string or cell array of strings",
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3595 who.c_str ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3596 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3597 else if (param == "commentstyle")
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3598 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3599 if (args(i+1).is_string ())
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3600 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3601 // check here for names like "C++", "C", "shell", ...?
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3602 comment_style = Cell (args(i+1));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3603 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3604 else if (args(i+1).is_cell ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3605 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3606 comment_style = args(i+1).cell_value ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3607 int len = comment_style.numel ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3608 if ((len >= 1 && ! comment_style (0).is_string ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3609 || (len >= 2 && ! comment_style (1).is_string ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3610 || (len >= 3))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3611 error ("%s: CommentStyle must be either a string or cell array of one or two strings",
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3612 who.c_str ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3613 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3614 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3615 error ("%s: CommentStyle must be either a string or cell array of one or two strings",
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3616 who.c_str ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3617
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3618 // How far ahead do we need to look to detect an open comment
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3619 // and which character do we look for?
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3620 if (comment_style.numel () >= 1)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3621 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3622 comment_len = comment_style (0).string_value ().size ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3623 comment_char = comment_style (0).string_value ()[0];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3624 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3625 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3626 else if (param == "treatasempty")
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3627 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3628 bool invalid = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3629 if (args(i+1).is_string ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3630 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3631 treat_as_empty = Cell (args(i+1));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3632 treat_as_empty_len = args(i+1).string_value ().size ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3633 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3634 else if (args(i+1).is_cell ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3635 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3636 treat_as_empty = args(i+1).cell_value ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3637 for (int j = 0; j < treat_as_empty.numel (); j++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3638 if (! treat_as_empty (j).is_string ())
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
3639 invalid = true;
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
3640 else
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
3641 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3642 int k = treat_as_empty (j).string_value ().size ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3643 if (k > treat_as_empty_len)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3644 treat_as_empty_len = k;
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
3645 }
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3646 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3647 if (invalid)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3648 error ("%s: TreatAsEmpty must be either a string or cell array of one or two strings",
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3649 who.c_str ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3650
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3651 // FIXME: Ensure none is a prefix of a later one. Sort by length?
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3652 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3653 else if (param == "collectoutput")
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3654 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3655 collect_output = args(i+1).xbool_value ("%s: CollectOutput must be logical or numeric", who.c_str ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3656 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3657 else if (param == "emptyvalue")
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3658 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3659 empty_value = args(i+1).xscalar_value ("%s: EmptyValue must be numeric", who.c_str ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3660 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3661 else if (param == "headerlines")
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3662 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3663 header_lines = args(i+1).xscalar_value ("%s: HeaderLines must be numeric", who.c_str ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3664 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3665 else if (param == "bufsize")
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3666 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3667 buffer_size = args(i+1).xscalar_value ("%s: BufSize must be numeric", who.c_str ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3668 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3669 else if (param == "multipledelimsasone")
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3670 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3671 multiple_delims_as_one = args(i+1).xbool_value ("%s: MultipleDelimsAsOne must be logical or numeric", who.c_str ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3672 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3673 else if (param == "returnonerror")
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3674 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3675 return_on_error = args(i+1).xbool_value ("%s: ReturnOnError must be logical or numeric", who.c_str ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3676 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3677 else if (param == "whitespace")
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3678 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3679 whitespace = args(i+1).xstring_value ("%s: Whitespace must be a character string", who.c_str ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3680 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3681 else if (param == "expchars")
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3682 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3683 exp_chars = args(i+1).xstring_value ("%s: ExpChars must be a character string", who.c_str ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3684 default_exp = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3685 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3686 else if (param == "endofline")
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3687 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3688 bool valid = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3689 std::string s = args(i+1).xstring_value ("%s: EndOfLine must be at most one character or '\\r\\n'", who.c_str ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3690 if (args(i+1).is_sq_string ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3691 s = do_string_escapes (s);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3692 int l = s.length ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3693 if (l == 0)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3694 eol1 = eol2 = -2;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3695 else if (l == 1)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3696 eol1 = eol2 = s.c_str ()[0];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3697 else if (l == 2)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3698 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3699 eol1 = s.c_str ()[0];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3700 eol2 = s.c_str ()[1];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3701 if (eol1 != '\r' || eol2 != '\n') // Why limit it?
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3702 valid = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3703 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3704 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3705 valid = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3706
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3707 if (! valid)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3708 error ("%s: EndOfLine must be at most one character or '\\r\\n'",
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3709 who.c_str ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3710 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3711 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3712 error ("%s: unrecognized option '%s'", who.c_str (), param.c_str ());
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
3713 }
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3714
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3715 whitespace_table = std::string (256, '\0');
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3716 for (unsigned int i = 0; i < whitespace.length (); i++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3717 whitespace_table[whitespace[i]] = '1';
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3718
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3719 // For Matlab compatibility, add 0x20 to whitespace, unless
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3720 // whitespace is explicitly ignored.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3721 if (! (whitespace.empty () && fmt_list.has_string))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3722 whitespace_table[' '] = '1';
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3723
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3724 // Create look-up table of delimiters, based on 'delimiter'
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3725 delim_table = std::string (256, '\0');
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3726 if (eol1 >= 0 && eol1 < 256)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3727 delim_table[eol1] = '1'; // EOL is always a delimiter
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3728 if (eol2 >= 0 && eol2 < 256)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3729 delim_table[eol2] = '1'; // EOL is always a delimiter
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3730 if (! have_delims)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3731 for (unsigned int i = 0; i < 256; i++)
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
3732 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3733 if (isspace (i))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3734 delim_table[i] = '1';
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
3735 }
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3736 else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3737 for (unsigned int i = 0; i < delims.length (); i++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3738 delim_table[delims[i]] = '1';
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3739 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3740
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3741 // Skip comments, and characters specified by the "Whitespace" option.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3742 // If EOLstop == true, don't skip end of line.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3743
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3744 int
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3745 textscan::skip_whitespace (delimited_stream& is, bool EOLstop)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3746 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3747 int c1 = std::istream::traits_type::eof ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3748 bool found_comment = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3749
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3750 do
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3751 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3752 found_comment = false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3753 int prev = -1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3754 while (is && (c1 = is.get_undelim ()) != std::istream::traits_type::eof ()
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3755 && ( ( (c1 == eol1 || c1 == eol2) && ++lines && ! EOLstop)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3756 || isspace (c1)))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3757 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3758 if (prev == eol1 && eol1 != eol2 && c1 == eol2)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3759 lines--;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3760 prev = c1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3761 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3762
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3763 if (c1 == comment_char) // see if we match an open comment
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3764 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3765 // save stream state in case we have to restore it
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3766 char *pos = is.tellg ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3767 std::ios::iostate state = is.rdstate ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3768
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3769 std::string tmp (comment_len, '\0');
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3770 char *look = is.read (&tmp[0], comment_len-1, pos); // already read first char
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3771 if (is && ! strncmp (comment_style(0).string_value ().substr (1)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3772 .c_str (), look, comment_len-1))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3773 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3774 found_comment = true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3775
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3776 std::string dummy;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3777 if (comment_style.numel () == 1) // skip to end of line
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3778 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3779 std::string eol (3, '\0');
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3780 eol[0] = eol1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3781 eol[1] = eol2;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3782
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3783 scan_caret (is, eol, dummy);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3784 c1 = is.get_undelim ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3785 if (c1 == eol1 && eol1 != eol2 && is.peek_undelim () == eol2)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3786 is.get_undelim ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3787 lines++;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3788 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3789 else // matching pair
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3790 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3791 std::string end_c = comment_style(1).string_value ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3792 // last char of end-comment sequence
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3793 std::string last = end_c.substr (end_c.size () - 1);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3794 std::string may_match ("");
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3795 do
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3796 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3797 // find sequence ending with last char
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3798 scan_caret (is, last, dummy);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3799 is.get_undelim (); // (read LAST itself)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3800
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3801 may_match = may_match + dummy + last;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3802 if (may_match.length () > end_c.length ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3803 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3804 size_t start = may_match.length () - end_c.length ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3805 may_match = may_match.substr (start);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3806 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3807 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3808 while (may_match != end_c && is && ! is.eof ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3809 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3810 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3811 else // wasn't really a comment; restore state
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3812 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3813 is.clear (state);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3814 is.seekg (pos);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3815 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3816 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3817 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3818 while (found_comment);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3819
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3820 if (c1 != std::istream::traits_type::eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3821 is.putback (c1);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3822 return c1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3823 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3824
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3825 // See if the next few characters match one of the strings in target.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3826 // For efficiency, MAX_LEN is the cached longest length of any target.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3827 // Return -1 if none is found, or the index of the match.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3828
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3829 int
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3830 textscan::lookahead (delimited_stream& is, const Cell& targets, int max_len,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3831 bool case_sensitive) const
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3832 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3833 // target strings may be different sizes.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3834 // Read ahead longest, put it all back, then re-read the string
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3835 // that matches.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3836
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3837 char *pos = is.tellg ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3838
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3839 std::string tmp (max_len, '\0');
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3840 char *look = is.read (&tmp[0], tmp.size (), pos);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3841
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3842 is.clear ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3843 is.seekg (pos); // reset to position before look-ahead
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3844 // FIXME: pos may be corrupted by is.read
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3845
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3846 int i;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3847 int (*compare)(const char *, const char *, size_t);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3848 compare = case_sensitive ? strncmp : strncasecmp;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3849
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3850 for (i = 0; i < targets.numel (); i++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3851 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3852 std::string s = targets (i).string_value ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3853 if (! (*compare) (s.c_str (), look, s.size ()))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3854 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3855 is.read (&tmp[0], s.size (), pos); // read just the right amount
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3856 break;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3857 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3858 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3859
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3860 if (i == targets.numel ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3861 i = -1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3862
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3863 return i;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3864 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3865
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3866 // Skip delimiters -- multiple if MultipleDelimsAsOne specified.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3867 int
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3868 textscan::skip_delim (delimited_stream& is)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3869 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3870 int c1 = skip_whitespace (is, true); // 'true': stop once EOL is read
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3871 if (delim_list.numel () == 0) // single character delimiter
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3872 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3873 if (is_delim (c1) || c1 == eol1 || c1 == eol2)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3874 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3875 is.get ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3876 if (c1 == eol1 && is.peek_undelim () == eol2)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3877 is.get_undelim (); // if \r\n, skip the \n too.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3878
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3879 if (multiple_delims_as_one)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3880 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3881 int prev = -1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3882 // skip multiple delims.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3883 // Increment lines for each end-of-line seen; for \r\n, decrement
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3884 while (is && ((c1 = is.get_undelim ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3885 != std::istream::traits_type::eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3886 && (((c1 == eol1 || c1 == eol2) && ++lines)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3887 || isspace (c1) || is_delim (c1)))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3888 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3889 if (prev == eol1 && eol1 != eol2 && c1 == eol2)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3890 lines--;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3891 prev = c1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3892 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3893 if (c1 != std::istream::traits_type::eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3894 is.putback (c1);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3895 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3896 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3897 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3898 else // multi-character delimiter
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3899 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3900 int first_match;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3901
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3902 if (c1 == eol1 || c1 == eol2
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3903 || (-1 != (first_match = lookahead (is, delim_list, delim_len))))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3904 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3905 if (c1 == eol1)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3906 {
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
3907 is.get_undelim ();
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3908 if (is.peek_undelim () == eol2)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3909 is.get_undelim ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3910 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3911 else if (c1 == eol2)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3912 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3913 is.get_undelim ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3914 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3915
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3916 if (multiple_delims_as_one)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3917 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3918 int prev = -1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3919 // skip multiple delims.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3920 // Increment lines for each end-of-line seen; for \r\n, decrement
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3921 while (is && ((c1 = skip_whitespace (is, true))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3922 != std::istream::traits_type::eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3923 && (((c1 == eol1 || c1 == eol2) && ++lines)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3924 || -1 != lookahead (is, delim_list, delim_len)))
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3925 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3926 if (prev == eol1 && eol1 != eol2 && c1 == eol2)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3927 lines--;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3928 prev = c1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3929 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3930 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3931 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3932 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3933
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3934 return c1;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3935 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3936
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3937 // Read in as much of the input as coincides with the literal in the
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3938 // format string. Return "true" if the entire literal is matched, else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3939 // false (and set failbit).
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3940
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3941 bool
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3942 textscan::match_literal (delimited_stream& is, const textscan_format_elt& fmt)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3943 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3944 // "false" -> treat EOL as normal space
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3945 // since a delimiter at the start of a line is a mismatch, not empty field
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3946 skip_whitespace (is, false);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3947
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3948 for (unsigned int i = 0; i < fmt.width; i++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3949 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3950 int ch = is.get_undelim ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3951 if (ch != fmt.text[i])
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3952 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3953 if (ch != std::istream::traits_type::eof ())
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3954 is.putback (ch);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3955 is.setstate (std::ios::failbit);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3956 return false;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3957 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3958 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3959 return true;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3960 }
21502
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
3961 }
7a19c5678f91 move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents: 21477
diff changeset
3962
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3963 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
3964 octave_base_stream::error (const std::string& msg)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3965 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3966 fail = true;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3967 errmsg = msg;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3968 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3969
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3970 void
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3971 octave_base_stream::error (const std::string& who, const std::string& msg)
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3972 {
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3973 fail = true;
6296
85eb75190e01 [project @ 2007-02-10 07:10:42 by jwe]
jwe
parents: 6109
diff changeset
3974 errmsg = who + ": " + msg;
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3975 }
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3976
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3977 void
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3978 octave_base_stream::clear (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3979 {
4889
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
3980 fail = false;
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
3981 errmsg = "";
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
3982 }
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
3983
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
3984 void
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
3985 octave_base_stream::clearerr (void)
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
3986 {
4888
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
3987 std::istream *is = input_stream ();
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
3988 std::ostream *os = output_stream ();
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
3989
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
3990 if (is)
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
3991 is->clear ();
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
3992
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
3993 if (os)
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
3994 os->clear ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3995 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3996
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3997 // Functions that are defined for all input streams (input streams
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3998 // are those that define is).
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3999
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
4000 std::string
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
4001 octave_base_stream::do_gets (octave_idx_type max_len, bool& err,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4002 bool strip_newline, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4003 {
22089
c2c668b3051b use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
4004 if (octave::application::interactive () && file_number () == 0)
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20768
diff changeset
4005 ::error ("%s: unable to read from stdin while running interactively",
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20768
diff changeset
4006 who.c_str ());
8773
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
4007
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4008 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4009
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4010 err = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4011
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4012 std::istream *isp = input_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4013
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4014 if (! isp)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4015 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4016 err = true;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4017 invalid_operation (who, "reading");
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4018 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4019 else
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4020 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4021 std::istream& is = *isp;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4022
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
4023 std::ostringstream buf;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4024
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4025 int c = 0;
3553
c5600b44bef9 [project @ 2000-02-03 03:22:37 by jwe]
jwe
parents: 3552
diff changeset
4026 int char_count = 0;
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
4027
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
4028 if (max_len != 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4029 {
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
4030 while (is && (c = is.get ()) != std::istream::traits_type::eof ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4031 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4032 char_count++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4033
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4034 // Handle CRLF, CR, or LF as line ending.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4035 if (c == '\r')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4036 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4037 if (! strip_newline)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4038 buf << static_cast<char> (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4039
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4040 c = is.get ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4041
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
4042 if (c != std::istream::traits_type::eof ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4043 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4044 if (c == '\n')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4045 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4046 char_count++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4047
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4048 if (! strip_newline)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4049 buf << static_cast<char> (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4050 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4051 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4052 is.putback (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4053 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4054
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4055 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4056 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4057 else if (c == '\n')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4058 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4059 if (! strip_newline)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4060 buf << static_cast<char> (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4061
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4062 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4063 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4064 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4065 buf << static_cast<char> (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4066
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4067 if (max_len > 0 && char_count == max_len)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4068 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4069 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4070 }
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
4071
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
4072 if (! is.eof () && char_count > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4073 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4074 // GAGME. Matlab seems to check for EOF even if the last character
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4075 // in a file is a newline character. This is NOT what the
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4076 // corresponding C-library functions do.
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4077 int disgusting_compatibility_hack = is.get ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4078 if (! is.eof ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4079 is.putback (disgusting_compatibility_hack);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4080 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4081
4224
0179e6309248 [project @ 2002-12-18 00:34:29 by jwe]
jwe
parents: 4223
diff changeset
4082 if (is.good () || (is.eof () && char_count > 0))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4083 retval = buf.str ();
4224
0179e6309248 [project @ 2002-12-18 00:34:29 by jwe]
jwe
parents: 4223
diff changeset
4084 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4085 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4086 err = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4087
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4088 if (is.eof () && char_count == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4089 error (who, "at end of file");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4090 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4091 error (who, "read error");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4092 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4093 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4094
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4095 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4096 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4097
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
4098 std::string
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4099 octave_base_stream::getl (octave_idx_type max_len, bool& err,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4100 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4101 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
4102 return do_gets (max_len, err, true, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4103 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4104
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
4105 std::string
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4106 octave_base_stream::gets (octave_idx_type max_len, bool& err,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4107 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4108 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
4109 return do_gets (max_len, err, false, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4110 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4111
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
4112 off_t
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
4113 octave_base_stream::skipl (off_t num, bool& err, const std::string& who)
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4114 {
22089
c2c668b3051b use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
4115 if (octave::application::interactive () && file_number () == 0)
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4116 ::error ("%s: unable to read from stdin while running interactively",
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4117 who.c_str ());
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4118
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
4119 off_t cnt = -1;
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4120
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4121 err = false;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4122
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4123 std::istream *isp = input_stream ();
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4124
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4125 if (! isp)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4126 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4127 err = true;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4128 invalid_operation (who, "reading");
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4129 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4130 else
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4131 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4132 std::istream& is = *isp;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4133
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17787
diff changeset
4134 int c = 0;
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17787
diff changeset
4135 int lastc = -1;
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4136 cnt = 0;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4137
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
4138 while (is && (c = is.get ()) != std::istream::traits_type::eof ())
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4139 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4140 // Handle CRLF, CR, or LF as line ending.
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4141 if (c == '\r' || (c == '\n' && lastc != '\r'))
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4142 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4143 if (++cnt == num)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4144 break;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4145 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4146
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4147 lastc = c;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4148 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4149
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4150 // Maybe eat the following \n if \r was just met.
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4151 if (c == '\r' && is.peek () == '\n')
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4152 is.get ();
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4153
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4154 if (is.bad ())
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4155 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4156 err = true;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4157 error (who, "read error");
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4158 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4159
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4160 if (err)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4161 cnt = -1;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4162 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4163
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4164 return cnt;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4165 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
4166
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
4167 template <typename T>
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
4168 std::istream&
6767
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4169 octave_scan_1 (std::istream& is, const scanf_format_elt& fmt, T* valptr)
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
4170 {
21687
4418e579cca6 scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents: 21686
diff changeset
4171 T value = T ();
3779
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
4172
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
4173 switch (fmt.type)
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
4174 {
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
4175 case 'o':
21687
4418e579cca6 scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents: 21686
diff changeset
4176 is >> std::oct >> value >> std::dec;
3779
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
4177 break;
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
4178
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
4179 case 'x':
21687
4418e579cca6 scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents: 21686
diff changeset
4180 is >> std::hex >> value >> std::dec;
4926
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
4181 break;
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
4182
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
4183 case 'i':
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
4184 {
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
4185 int c1 = std::istream::traits_type::eof ();
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
4186
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
4187 while (is && (c1 = is.get ()) != std::istream::traits_type::eof ()
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
4188 && isspace (c1))
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
4189 ; // skip whitespace
14675
757f729fd41d skip leading whitespace for scanf %i format
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
4190
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
4191 if (c1 != std::istream::traits_type::eof ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4192 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4193 if (c1 == '0')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4194 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4195 int c2 = is.peek ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4196
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4197 if (c2 == 'x' || c2 == 'X')
7709
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
4198 {
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
4199 is.ignore ();
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
4200 if (std::isxdigit (is.peek ()))
21687
4418e579cca6 scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents: 21686
diff changeset
4201 is >> std::hex >> value >> std::dec;
7709
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
4202 else
21687
4418e579cca6 scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents: 21686
diff changeset
4203 value = 0;
7709
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
4204 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4205 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4206 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4207 if (c2 == '0' || c2 == '1' || c2 == '2'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4208 || c2 == '3' || c2 == '4' || c2 == '5'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4209 || c2 == '6' || c2 == '7')
21687
4418e579cca6 scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents: 21686
diff changeset
4210 is >> std::oct >> value >> std::dec;
21114
47908b818865 oct-stream.cc: Add FIXME note about bug #46493.
Rik <rik@octave.org>
parents: 21102
diff changeset
4211 else if (c2 == '8' || c2 == '9')
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
4212 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
4213 // FIXME: Would like to set error state on octave
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
4214 // stream. See bug #46493. But only std::istream is
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
4215 // input to fcn.
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
4216 // error ("internal failure to match octal format");
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
4217 value = 0;
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
4218 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4219 else
21687
4418e579cca6 scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents: 21686
diff changeset
4220 value = 0;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4221 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4222 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4223 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4224 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4225 is.putback (c1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4226
21687
4418e579cca6 scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents: 21686
diff changeset
4227 is >> value;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4228 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4229 }
4926
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
4230 }
3779
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
4231 break;
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
4232
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
4233 default:
21687
4418e579cca6 scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents: 21686
diff changeset
4234 is >> value;
3779
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
4235 break;
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
4236 }
3639
fed1847dfd6c [project @ 2000-03-24 05:12:46 by jwe]
jwe
parents: 3638
diff changeset
4237
21687
4418e579cca6 scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents: 21686
diff changeset
4238 // If conversion produces an integer that overflows, failbit is set but
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21739
diff changeset
4239 // value is non-zero. We want to treat this case as success, so clear
21687
4418e579cca6 scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents: 21686
diff changeset
4240 // failbit from the stream state to keep going.
4418e579cca6 scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents: 21686
diff changeset
4241 // FIXME: Maybe set error state on octave stream as above? Matlab does
4418e579cca6 scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents: 21686
diff changeset
4242 // *not* indicate an error message on overflow.
4418e579cca6 scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents: 21686
diff changeset
4243 if ((is.rdstate () & std::ios::failbit) && value != T ())
4418e579cca6 scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents: 21686
diff changeset
4244 is.clear (is.rdstate () & ~std::ios::failbit);
4418e579cca6 scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents: 21686
diff changeset
4245
4418e579cca6 scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents: 21686
diff changeset
4246 // Only copy the converted value if the stream is in a state where we
4418e579cca6 scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents: 21686
diff changeset
4247 // want to continue reading.
4418e579cca6 scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents: 21686
diff changeset
4248 if (! (is.rdstate () & std::ios::failbit))
4418e579cca6 scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents: 21686
diff changeset
4249 *valptr = value;
4418e579cca6 scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents: 21686
diff changeset
4250
3638
a76fa215a476 [project @ 2000-03-24 04:53:45 by jwe]
jwe
parents: 3637
diff changeset
4251 return is;
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
4252 }
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
4253
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
4254 template <typename T>
6767
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4255 std::istream&
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4256 octave_scan (std::istream& is, const scanf_format_elt& fmt, T* valptr)
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4257 {
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4258 if (fmt.width)
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4259 {
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4260 // Limit input to fmt.width characters by reading into a
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4261 // temporary stringstream buffer.
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4262 std::string tmp;
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4263
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4264 is.width (fmt.width);
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4265 is >> tmp;
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4266
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4267 std::istringstream ss (tmp);
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4268
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4269 octave_scan_1 (ss, fmt, valptr);
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4270 }
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4271 else
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4272 octave_scan_1 (is, fmt, valptr);
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4273
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4274 return is;
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4275 }
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
4276
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4277 // Note that this specialization is only used for reading characters, not
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21739
diff changeset
4278 // character strings. See BEGIN_S_CONVERSION for details.
3779
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
4279
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
4280 template <>
3779
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
4281 std::istream&
4661
12b6fbd57436 [project @ 2003-11-25 05:41:35 by jwe]
jwe
parents: 4649
diff changeset
4282 octave_scan<> (std::istream& is, const scanf_format_elt& /* fmt */,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4283 char* valptr)
3779
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
4284 {
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
4285 return is >> valptr;
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
4286 }
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
4287
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
4288 template <>
5176
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
4289 std::istream&
5403
7bdddf96f028 [project @ 2005-07-07 16:46:23 by jwe]
jwe
parents: 5389
diff changeset
4290 octave_scan<> (std::istream& is, const scanf_format_elt& fmt, double* valptr)
5176
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
4291 {
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
4292 double& ref = *valptr;
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
4293
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
4294 switch (fmt.type)
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
4295 {
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
4296 case 'e':
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
4297 case 'f':
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
4298 case 'g':
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
4299 {
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
4300 int c1 = std::istream::traits_type::eof ();
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
4301
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
4302 while (is && (c1 = is.get ()) != std::istream::traits_type::eof ()
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
4303 && isspace (c1))
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
4304 ; // skip whitespace
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4305
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
4306 if (c1 != std::istream::traits_type::eof ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4307 {
12936
b74cb659e757 accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
4308 is.putback (c1);
b74cb659e757 accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
4309
b74cb659e757 accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
4310 ref = octave_read_value<double> (is);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4311 }
5176
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
4312 }
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
4313 break;
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
4314
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
4315 default:
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
4316 panic_impossible ();
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
4317 break;
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
4318 }
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
4319
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
4320 return is;
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
4321 }
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
4322
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
4323 template <typename T>
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
4324 void
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
4325 do_scanf_conv (std::istream& is, const scanf_format_elt& fmt,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4326 T valptr, Matrix& mval, double *data, octave_idx_type& idx,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4327 octave_idx_type& conversion_count, octave_idx_type nr,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4328 octave_idx_type max_size, bool discard)
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
4329 {
21147
95feb42d7a97 * oct-stream.cc (OCTAVE_SCAN): Eliminate trivial macro.
John W. Eaton <jwe@octave.org>
parents: 21139
diff changeset
4330 octave_scan (is, fmt, valptr);
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
4331
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4332 if (! is)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4333 return;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4334
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4335 if (idx == max_size && ! discard)
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
4336 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4337 max_size *= 2;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4338
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4339 if (nr > 0)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4340 mval.resize (nr, max_size / nr, 0.0);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4341 else
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4342 mval.resize (max_size, 1, 0.0);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4343
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4344 data = mval.fortran_vec ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4345 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4346
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4347 if (! discard)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4348 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4349 conversion_count++;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4350 data[idx++] = *(valptr);
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
4351 }
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
4352 }
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
4353
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
4354 template void
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
4355 do_scanf_conv (std::istream&, const scanf_format_elt&, double*,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4356 Matrix&, double*, octave_idx_type&, octave_idx_type&,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4357 octave_idx_type, octave_idx_type, bool);
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
4358
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4359 #define DO_WHITESPACE_CONVERSION() \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4360 do \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4361 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4362 int c = std::istream::traits_type::eof (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4363 \
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
4364 while (is && (c = is.get ()) != std::istream::traits_type::eof () \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4365 && isspace (c)) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4366 { /* skip whitespace */ } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4367 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4368 if (c != std::istream::traits_type::eof ()) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4369 is.putback (c); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4370 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
4371 while (0)
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
4372
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4373 #define DO_LITERAL_CONVERSION() \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4374 do \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4375 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4376 int c = std::istream::traits_type::eof (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4377 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4378 int n = strlen (fmt); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4379 int i = 0; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4380 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4381 while (i < n && is && (c = is.get ()) != std::istream::traits_type::eof ()) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4382 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4383 if (c == static_cast<unsigned char> (fmt[i])) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4384 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4385 i++; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4386 continue; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4387 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4388 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4389 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4390 is.putback (c); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4391 break; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4392 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4393 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4394 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4395 if (i != n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4396 is.setstate (std::ios::failbit); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4397 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
4398 while (0)
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
4399
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4400 #define DO_PCT_CONVERSION() \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4401 do \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4402 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4403 int c = is.get (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4404 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4405 if (c != std::istream::traits_type::eof ()) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4406 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4407 if (c != '%') \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4408 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4409 is.putback (c); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4410 is.setstate (std::ios::failbit); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4411 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4412 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4413 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4414 is.setstate (std::ios::failbit); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4415 } \
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
4416 while (0)
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
4417
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4418 #define BEGIN_C_CONVERSION() \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4419 is.unsetf (std::ios::skipws); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4420 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4421 int width = elt->width ? elt->width : 1; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4422 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4423 std::string tmp (width, '\0'); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4424 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4425 int c = std::istream::traits_type::eof (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4426 int n = 0; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4427 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4428 while (is && n < width \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4429 && (c = is.get ()) != std::istream::traits_type::eof ()) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4430 tmp[n++] = static_cast<char> (c); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4431 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4432 if (n > 0 && c == std::istream::traits_type::eof ()) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4433 is.clear (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4434 \
12984
7626f8934466 correctly resize scanf output for %c formats (bug #34037)
John W. Eaton <jwe@octave.org>
parents: 12966
diff changeset
4435 tmp.resize (n)
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
4436
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
4437 // For a '%s' format, skip initial whitespace and then read until the
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
4438 // next whitespace character or until WIDTH characters have been read.
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4439 #define BEGIN_S_CONVERSION() \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4440 int width = elt->width; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4441 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4442 std::string tmp; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4443 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4444 do \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4445 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4446 if (width) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4447 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4448 tmp = std::string (width, '\0'); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4449 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4450 int c = std::istream::traits_type::eof (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4451 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4452 int n = 0; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4453 \
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
4454 while (is && (c = is.get ()) != std::istream::traits_type::eof ()) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4455 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4456 if (! isspace (c)) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4457 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4458 tmp[n++] = static_cast<char> (c); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4459 break; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4460 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4461 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4462 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4463 while (is && n < width \
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
4464 && (c = is.get ()) != std::istream::traits_type::eof ()) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4465 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4466 if (isspace (c)) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4467 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4468 is.putback (c); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4469 break; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4470 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4471 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4472 tmp[n++] = static_cast<char> (c); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4473 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4474 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4475 if (n > 0 && c == std::istream::traits_type::eof ()) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4476 is.clear (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4477 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4478 tmp.resize (n); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4479 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4480 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4481 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4482 is >> std::ws >> tmp; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4483 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4484 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
4485 while (0)
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
4486
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
4487 // This format must match a nonempty sequence of characters.
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4488 #define BEGIN_CHAR_CLASS_CONVERSION() \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4489 int width = elt->width; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4490 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4491 std::string tmp; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4492 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4493 do \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4494 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4495 if (! width) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4496 width = std::numeric_limits<int>::max (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4497 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4498 std::ostringstream buf; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4499 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4500 std::string char_class = elt->char_class; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4501 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4502 int c = std::istream::traits_type::eof (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4503 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4504 if (elt->type == '[') \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4505 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4506 int chars_read = 0; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4507 while (is && chars_read++ < width \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4508 && (c = is.get ()) != std::istream::traits_type::eof () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4509 && char_class.find (c) != std::string::npos) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4510 buf << static_cast<char> (c); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4511 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4512 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4513 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4514 int chars_read = 0; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4515 while (is && chars_read++ < width \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4516 && (c = is.get ()) != std::istream::traits_type::eof () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4517 && char_class.find (c) == std::string::npos) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4518 buf << static_cast<char> (c); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4519 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4520 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4521 if (width == std::numeric_limits<int>::max () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4522 && c != std::istream::traits_type::eof ()) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4523 is.putback (c); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4524 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4525 tmp = buf.str (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4526 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4527 if (tmp.empty ()) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4528 is.setstate (std::ios::failbit); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4529 else if (c == std::istream::traits_type::eof ()) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4530 is.clear (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4531 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4532 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
4533 while (0)
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
4534
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4535 #define FINISH_CHARACTER_CONVERSION() \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4536 do \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4537 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4538 width = tmp.length (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4539 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4540 if (is) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4541 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4542 int i = 0; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4543 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4544 if (! discard) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4545 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4546 conversion_count++; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4547 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4548 while (i < width) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4549 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4550 if (data_index == max_size) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4551 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4552 max_size *= 2; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4553 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4554 if (all_char_conv) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4555 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4556 if (one_elt_size_spec) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4557 mval.resize (1, max_size, 0.0); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4558 else if (nr > 0) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4559 mval.resize (nr, max_size / nr, 0.0); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4560 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4561 panic_impossible (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4562 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4563 else if (nr > 0) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4564 mval.resize (nr, max_size / nr, 0.0); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4565 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4566 mval.resize (max_size, 1, 0.0); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4567 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4568 data = mval.fortran_vec (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4569 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4570 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4571 data[data_index++] = tmp[i++]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4572 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4573 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4574 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
4575 } \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
4576 while (0)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4577
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4578 octave_value
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4579 octave_base_stream::do_scanf (scanf_format_list& fmt_list,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4580 octave_idx_type nr, octave_idx_type nc,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4581 bool one_elt_size_spec,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4582 octave_idx_type& conversion_count,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4583 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4584 {
22089
c2c668b3051b use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
4585 if (octave::application::interactive () && file_number () == 0)
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4586 ::error ("%s: unable to read from stdin while running interactively",
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4587 who.c_str ());
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4588
8773
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
4589 octave_value retval = Matrix ();
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
4590
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
4591 conversion_count = 0;
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
4592
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
4593 octave_idx_type nconv = fmt_list.num_conversions ();
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
4594
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
4595 octave_idx_type data_index = 0;
2121
bc6ecd8f1175 [project @ 1996-05-12 06:45:55 by jwe]
jwe
parents: 2117
diff changeset
4596
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
4597 if (nr == 0 || nc == 0)
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
4598 {
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
4599 if (one_elt_size_spec)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4600 nc = 0;
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
4601
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
4602 return Matrix (nr, nc, 0.0);
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
4603 }
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
4604
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4605 std::istream *isp = input_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4606
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4607 bool all_char_conv = fmt_list.all_character_conversions ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4608
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4609 Matrix mval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4610 double *data = 0;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
4611 octave_idx_type max_size = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
4612 octave_idx_type max_conv = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
4613
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
4614 octave_idx_type final_nr = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
4615 octave_idx_type final_nc = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4616
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
4617 if (all_char_conv)
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
4618 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4619 // Any of these could be resized later (if we have %s conversions,
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4620 // we may read more than one element for each conversion).
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
4621 if (one_elt_size_spec)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4622 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4623 max_size = 512;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4624 mval.resize (1, max_size, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4625
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4626 if (nr > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4627 max_conv = nr;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4628 }
4420
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
4629 else if (nr > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4630 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4631 if (nc > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4632 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4633 mval.resize (nr, nc, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4634 max_size = max_conv = nr * nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4635 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4636 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4637 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4638 mval.resize (nr, 32, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4639 max_size = nr * 32;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4640 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4641 }
4420
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
4642 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4643 panic_impossible ();
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
4644 }
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
4645 else if (nr > 0)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4646 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4647 if (nc > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4648 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4649 // Will not resize later.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4650 mval.resize (nr, nc, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4651 max_size = nr * nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4652 max_conv = max_size;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4653 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4654 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4655 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4656 // Maybe resize later.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4657 mval.resize (nr, 32, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4658 max_size = nr * 32;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4659 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4660 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4661 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4662 {
4420
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
4663 // Maybe resize later.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4664 mval.resize (32, 1, 0.0);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4665 max_size = 32;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4666 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4667
4420
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
4668 data = mval.fortran_vec ();
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
4669
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4670 if (isp)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4671 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4672 std::istream& is = *isp;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4673
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4674 const scanf_format_elt *elt = fmt_list.first ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4675
3538
0ff7323dab8b [project @ 2000-02-02 12:36:25 by jwe]
jwe
parents: 3536
diff changeset
4676 std::ios::fmtflags flags = is.flags ();
2213
c4a887694274 [project @ 1996-05-16 04:13:28 by jwe]
jwe
parents: 2127
diff changeset
4677
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
4678 octave_idx_type trips = 0;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
4679
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
4680 octave_idx_type num_fmt_elts = fmt_list.length ();
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
4681
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4682 for (;;)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4683 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4684 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4685
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4686 if (elt)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4687 {
20465
44eb1102f8a8 don't recycle scanf format string if all conversions are done (bug #45808)
John W. Eaton <jwe@octave.org>
parents: 20432
diff changeset
4688 if (elt->type == scanf_format_elt::null
44eb1102f8a8 don't recycle scanf format string if all conversions are done (bug #45808)
John W. Eaton <jwe@octave.org>
parents: 20432
diff changeset
4689 || (! (elt->type == scanf_format_elt::whitespace_conversion
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
4690 || elt->type == scanf_format_elt::literal_conversion
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
4691 || elt->type == '%')
20465
44eb1102f8a8 don't recycle scanf format string if all conversions are done (bug #45808)
John W. Eaton <jwe@octave.org>
parents: 20432
diff changeset
4692 && max_conv > 0 && conversion_count == max_conv))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4693 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4694 // We are done, either because we have reached the end of the
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4695 // format string and are not cycling through the format again
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4696 // or because we've converted all the values that have been
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4697 // requested and the next format element is a conversion.
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4698 // Determine final array size and exit.
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4699 if (all_char_conv && one_elt_size_spec)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4700 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4701 final_nr = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4702 final_nc = data_index;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4703 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4704 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4705 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4706 final_nr = nr;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4707 final_nc = (data_index - 1) / nr + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4708 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4709
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4710 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4711 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4712 else if (data_index == max_size)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4713 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4714 max_size *= 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4715
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4716 if (all_char_conv)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4717 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4718 if (one_elt_size_spec)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4719 mval.resize (1, max_size, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4720 else if (nr > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4721 mval.resize (nr, max_size / nr, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4722 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4723 panic_impossible ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4724 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4725 else if (nr > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4726 mval.resize (nr, max_size / nr, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4727 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4728 mval.resize (max_size, 1, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4729
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4730 data = mval.fortran_vec ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4731 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4732
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4733 const char *fmt = elt->text;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4734
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4735 bool discard = elt->discard;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4736
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4737 switch (elt->type)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4738 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4739 case scanf_format_elt::whitespace_conversion:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4740 DO_WHITESPACE_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4741 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4742
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4743 case scanf_format_elt::literal_conversion:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4744 DO_LITERAL_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4745 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4746
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4747 case '%':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4748 DO_PCT_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4749 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4750
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4751 case 'd': case 'i':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4752 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4753 switch (elt->modifier)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4754 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4755 case 'h':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4756 {
21686
f07d6f579214 scanf: use appropriate sized types for integer conversions (bug #47741)
Mike Miller <mtmiller@octave.org>
parents: 21622
diff changeset
4757 int16_t tmp;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4758 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4759 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4760 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4761 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4762 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4763
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4764 case 'l':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4765 {
21686
f07d6f579214 scanf: use appropriate sized types for integer conversions (bug #47741)
Mike Miller <mtmiller@octave.org>
parents: 21622
diff changeset
4766 int64_t tmp;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4767 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4768 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4769 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4770 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4771 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4772
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4773 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4774 {
21686
f07d6f579214 scanf: use appropriate sized types for integer conversions (bug #47741)
Mike Miller <mtmiller@octave.org>
parents: 21622
diff changeset
4775 int32_t tmp;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4776 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4777 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4778 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4779 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4780 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4781 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4782 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4783 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4784
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4785 case 'o': case 'u': case 'x':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4786 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4787 switch (elt->modifier)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4788 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4789 case 'h':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4790 {
21686
f07d6f579214 scanf: use appropriate sized types for integer conversions (bug #47741)
Mike Miller <mtmiller@octave.org>
parents: 21622
diff changeset
4791 uint16_t tmp;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4792 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4793 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4794 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4795 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4796 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4797
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4798 case 'l':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4799 {
21686
f07d6f579214 scanf: use appropriate sized types for integer conversions (bug #47741)
Mike Miller <mtmiller@octave.org>
parents: 21622
diff changeset
4800 uint64_t tmp;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4801 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4802 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4803 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4804 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4805 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4806
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4807 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4808 {
21686
f07d6f579214 scanf: use appropriate sized types for integer conversions (bug #47741)
Mike Miller <mtmiller@octave.org>
parents: 21622
diff changeset
4809 uint32_t tmp;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4810 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4811 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4812 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4813 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4814 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4815 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4816 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4817 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4818
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4819 case 'e': case 'f': case 'g':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4820 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4821 double tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4822
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4823 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4824 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4825 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4826 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4827 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4828
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4829 case 'c':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4830 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4831 BEGIN_C_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4832
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4833 FINISH_CHARACTER_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4834
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4835 is.setf (flags);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4836 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4837 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4838
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4839 case 's':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4840 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4841 BEGIN_S_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4842
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4843 FINISH_CHARACTER_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4844 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4845 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4846
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4847 case '[': case '^':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4848 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4849 BEGIN_CHAR_CLASS_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4850
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4851 FINISH_CHARACTER_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4852 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4853 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4854
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4855 case 'p':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4856 error ("%s: unsupported format specifier", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4857 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4858
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4859 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4860 error ("%s: internal format error", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4861 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4862 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4863
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4864 if (! ok ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4865 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4866 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4867 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4868 else if (! is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4869 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4870 if (all_char_conv)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4871 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4872 if (one_elt_size_spec)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4873 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4874 final_nr = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4875 final_nc = data_index;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4876 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4877 else if (data_index > nr)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4878 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4879 final_nr = nr;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4880 final_nc = (data_index - 1) / nr + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4881 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4882 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4883 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4884 final_nr = data_index;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4885 final_nc = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4886 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4887 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4888 else if (nr > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4889 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4890 if (data_index > nr)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4891 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4892 final_nr = nr;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4893 final_nc = (data_index - 1) / nr + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4894 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4895 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4896 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4897 final_nr = data_index;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4898 final_nc = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4899 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4900 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4901 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4902 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4903 final_nr = data_index;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4904 final_nc = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4905 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4906
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4907 // If it looks like we have a matching failure, then
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4908 // reset the failbit in the stream state.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4909 if (is.rdstate () & std::ios::failbit)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4910 is.clear (is.rdstate () & (~std::ios::failbit));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4911
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4912 // FIXME: is this the right thing to do?
22089
c2c668b3051b use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
4913 if (octave::application::interactive ()
c2c668b3051b use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
4914 && ! octave::application::forced_interactive ()
c2c668b3051b use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
4915 && name () == "stdin")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4916 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4917 is.clear ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4918
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4919 // Skip to end of line.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4920 bool err;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4921 do_gets (-1, err, false, who);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4922 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4923
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4924 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4925 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4926 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4927 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4928 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4929 error ("%s: internal format error", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4930 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4931 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4932
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
4933 if (nconv == 0 && ++trips == num_fmt_elts)
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
4934 {
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
4935 if (all_char_conv && one_elt_size_spec)
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
4936 {
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
4937 final_nr = 1;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
4938 final_nc = data_index;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
4939 }
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
4940 else
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
4941 {
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
4942 final_nr = nr;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
4943 final_nc = (data_index - 1) / nr + 1;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
4944 }
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
4945
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
4946 break;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
4947 }
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
4948 else
20465
44eb1102f8a8 don't recycle scanf format string if all conversions are done (bug #45808)
John W. Eaton <jwe@octave.org>
parents: 20432
diff changeset
4949 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4950 // Cycle through the format list more than once if we have some
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4951 // conversions to make and we haven't reached the limit on the
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4952 // number of values to convert (possibly because there is no
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4953 // specified limit).
20465
44eb1102f8a8 don't recycle scanf format string if all conversions are done (bug #45808)
John W. Eaton <jwe@octave.org>
parents: 20432
diff changeset
4954 elt = fmt_list.next (nconv > 0
44eb1102f8a8 don't recycle scanf format string if all conversions are done (bug #45808)
John W. Eaton <jwe@octave.org>
parents: 20432
diff changeset
4955 && (max_conv == 0
44eb1102f8a8 don't recycle scanf format string if all conversions are done (bug #45808)
John W. Eaton <jwe@octave.org>
parents: 20432
diff changeset
4956 || conversion_count < max_conv));
44eb1102f8a8 don't recycle scanf format string if all conversions are done (bug #45808)
John W. Eaton <jwe@octave.org>
parents: 20432
diff changeset
4957 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4958 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4959 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4960
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4961 if (ok ())
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4962 {
2121
bc6ecd8f1175 [project @ 1996-05-12 06:45:55 by jwe]
jwe
parents: 2117
diff changeset
4963 mval.resize (final_nr, final_nc, 0.0);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4964
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
4965 retval = mval;
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
4966
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4967 if (all_char_conv)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4968 retval = retval.convert_to_str (false, true);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4969 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4970
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4971 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4972 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4973
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4974 octave_value
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
4975 octave_base_stream::scanf (const std::string& fmt, const Array<double>& size,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4976 octave_idx_type& conversion_count,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4977 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4978 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4979 octave_value retval = Matrix ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4980
3559
12d7ec415f35 [project @ 2000-02-03 05:17:36 by jwe]
jwe
parents: 3553
diff changeset
4981 conversion_count = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4982
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4983 std::istream *isp = input_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4984
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4985 if (! isp)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4986 invalid_operation (who, "reading");
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4987 else
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4988 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4989 scanf_format_list fmt_list (fmt);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4990
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
4991 if (fmt_list.num_conversions () == -1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4992 ::error ("%s: invalid format specified", who.c_str ());
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4993
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4994 octave_idx_type nr = -1;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4995 octave_idx_type nc = -1;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4996
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4997 bool one_elt_size_spec;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4998
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4999 get_size (size, nr, nc, one_elt_size_spec, who);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5000
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5001 retval = do_scanf (fmt_list, nr, nc, one_elt_size_spec,
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5002 conversion_count, who);
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
5003 }
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5004
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5005 return retval;
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5006 }
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5007
2712
2ff2b536cc9d [project @ 1997-02-21 21:38:21 by jwe]
jwe
parents: 2687
diff changeset
5008 bool
2ff2b536cc9d [project @ 1997-02-21 21:38:21 by jwe]
jwe
parents: 2687
diff changeset
5009 octave_base_stream::do_oscanf (const scanf_format_elt *elt,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5010 octave_value& retval, const std::string& who)
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5011 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5012 std::istream *isp = input_stream ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5013
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5014 if (! isp)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5015 return false;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5016
2712
2ff2b536cc9d [project @ 1997-02-21 21:38:21 by jwe]
jwe
parents: 2687
diff changeset
5017 bool quit = false;
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
5018
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5019 std::istream& is = *isp;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5020
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5021 std::ios::fmtflags flags = is.flags ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5022
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5023 if (elt)
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
5024 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5025 const char *fmt = elt->text;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5026
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5027 bool discard = elt->discard;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5028
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5029 switch (elt->type)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5030 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5031 case scanf_format_elt::whitespace_conversion:
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5032 DO_WHITESPACE_CONVERSION ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5033 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5034
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5035 case scanf_format_elt::literal_conversion:
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5036 DO_LITERAL_CONVERSION ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5037 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5038
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5039 case '%':
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5040 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5041 DO_PCT_CONVERSION ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5042
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5043 if (! is)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5044 quit = true;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5045 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5046 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5047
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5048 case 'd': case 'i':
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5049 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5050 int tmp;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5051
21147
95feb42d7a97 * oct-stream.cc (OCTAVE_SCAN): Eliminate trivial macro.
John W. Eaton <jwe@octave.org>
parents: 21139
diff changeset
5052 if (octave_scan (is, *elt, &tmp))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5053 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5054 if (! discard)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5055 retval = tmp;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5056 }
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5057 else
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5058 quit = true;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5059 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5060 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5061
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5062 case 'o': case 'u': case 'x':
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5063 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5064 long int tmp;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5065
21147
95feb42d7a97 * oct-stream.cc (OCTAVE_SCAN): Eliminate trivial macro.
John W. Eaton <jwe@octave.org>
parents: 21139
diff changeset
5066 if (octave_scan (is, *elt, &tmp))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5067 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5068 if (! discard)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5069 retval = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5070 }
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5071 else
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5072 quit = true;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5073 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5074 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5075
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5076 case 'e': case 'f': case 'g':
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5077 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5078 double tmp;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5079
21147
95feb42d7a97 * oct-stream.cc (OCTAVE_SCAN): Eliminate trivial macro.
John W. Eaton <jwe@octave.org>
parents: 21139
diff changeset
5080 if (octave_scan (is, *elt, &tmp))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5081 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5082 if (! discard)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5083 retval = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5084 }
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5085 else
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5086 quit = true;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5087 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5088 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5089
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5090 case 'c':
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5091 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5092 BEGIN_C_CONVERSION ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5093
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5094 if (! discard)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5095 retval = tmp;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5096
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5097 if (! is)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5098 quit = true;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5099
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5100 is.setf (flags);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5101 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5102 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5103
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5104 case 's':
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5105 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5106 BEGIN_S_CONVERSION ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5107
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5108 if (! discard)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5109 retval = tmp;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5110
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5111 if (! is)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5112 quit = true;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5113 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5114 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5115
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5116 case '[':
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5117 case '^':
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5118 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5119 BEGIN_CHAR_CLASS_CONVERSION ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5120
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5121 if (! discard)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5122 retval = tmp;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5123
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5124 if (! is)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5125 quit = true;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5126 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5127 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5128
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5129 case 'p':
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5130 error ("%s: unsupported format specifier", who.c_str ());
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5131 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5132
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5133 default:
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5134 error ("%s: internal format error", who.c_str ());
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5135 break;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5136 }
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5137 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5138
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5139 if (ok () && is.fail ())
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5140 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5141 error ("%s: read error", who.c_str ());
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5142
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5143 // FIXME: is this the right thing to do?
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5144
22089
c2c668b3051b use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
5145 if (octave::application::interactive ()
c2c668b3051b use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
5146 && ! octave::application::forced_interactive ()
c2c668b3051b use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
5147 && name () == "stdin")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5148 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5149 // Skip to end of line.
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5150 bool err;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5151 do_gets (-1, err, false, who);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5152 }
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
5153 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
5154
2712
2ff2b536cc9d [project @ 1997-02-21 21:38:21 by jwe]
jwe
parents: 2687
diff changeset
5155 return quit;
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
5156 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
5157
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
5158 octave_value_list
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
5159 octave_base_stream::oscanf (const std::string& fmt, const std::string& who)
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
5160 {
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
5161 octave_value_list retval;
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
5162
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
5163 std::istream *isp = input_stream ();
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
5164
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5165 if (! isp)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5166 invalid_operation (who, "reading");
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5167 else
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
5168 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
5169 std::istream& is = *isp;
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
5170
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
5171 scanf_format_list fmt_list (fmt);
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
5172
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
5173 octave_idx_type nconv = fmt_list.num_conversions ();
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
5174
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
5175 if (nconv == -1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5176 ::error ("%s: invalid format specified", who.c_str ());
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5177
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5178 is.clear ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5179
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5180 octave_idx_type len = fmt_list.length ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5181
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5182 retval.resize (nconv+2, Matrix ());
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5183
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5184 const scanf_format_elt *elt = fmt_list.first ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5185
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5186 int num_values = 0;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5187
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5188 bool quit = false;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5189
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5190 for (octave_idx_type i = 0; i < len; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5191 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5192 octave_value tmp;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5193
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5194 quit = do_oscanf (elt, tmp, who);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5195
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5196 if (quit)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5197 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5198 else
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5199 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5200 if (tmp.is_defined ())
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5201 retval(num_values++) = tmp;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5202
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5203 if (! ok ())
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5204 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5205
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5206 elt = fmt_list.next (nconv > 0);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5207 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5208 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5209
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5210 retval(nconv) = num_values;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5211
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5212 int err_num;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5213 retval(nconv+1) = error (false, err_num);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5214
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5215 if (! quit)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5216 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5217 // Pick up any trailing stuff.
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5218 if (ok () && len > nconv)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5219 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5220 octave_value tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5221
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5222 elt = fmt_list.next ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5223
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5224 do_oscanf (elt, tmp, who);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5225 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5226 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5227 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5228
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5229 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5230 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5231
21503
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5232 octave_value
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5233 octave_base_stream::do_textscan (const std::string& fmt,
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5234 octave_idx_type ntimes,
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5235 const octave_value_list& options,
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5236 const std::string& who,
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5237 octave_idx_type& read_count)
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5238 {
22089
c2c668b3051b use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
5239 if (octave::application::interactive () && file_number () == 0)
21503
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5240 ::error ("%s: unable to read from stdin while running interactively",
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5241 who.c_str ());
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5242
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5243 octave_value retval = Cell (dim_vector (1, 1), Matrix (0, 1));
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5244
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5245 std::istream *isp = input_stream ();
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5246
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5247 if (! isp)
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5248 invalid_operation (who, "reading");
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5249 else
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5250 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
5251 octave::textscan scanner (who);
21503
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5252
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5253 retval = scanner.scan (*isp, fmt, ntimes, options, read_count);
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5254 }
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5255
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5256 return retval;
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5257 }
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
5258
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5259 // Functions that are defined for all output streams
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5260 // (output streams are those that define os).
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5261
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5262 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5263 octave_base_stream::flush (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5264 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5265 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5266
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
5267 std::ostream *os = output_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5268
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5269 if (! os)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5270 invalid_operation ("fflush", "writing");
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5271 else
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5272 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5273 os->flush ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5274
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5275 if (os->good ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5276 retval = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5277 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5278
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5279 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5280 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5281
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5282 class
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5283 printf_value_cache
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5284 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5285 public:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5286
3653
84b2f30007d5 [project @ 2000-03-31 23:33:25 by jwe]
jwe
parents: 3645
diff changeset
5287 enum state { ok, conversion_error };
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5288
7352
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
5289 printf_value_cache (const octave_value_list& args, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5290 : values (args), val_idx (0), elt_idx (0),
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5291 n_vals (values.length ()), n_elts (0), have_data (false),
7352
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
5292 curr_state (ok)
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
5293 {
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
5294 for (octave_idx_type i = 0; i < values.length (); i++)
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
5295 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5296 octave_value val = values(i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5297
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5298 if (val.is_map () || val.is_cell () || val.is_object ())
21129
228b65504557 maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents: 21114
diff changeset
5299 err_wrong_type_arg (who, val);
7352
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
5300 }
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
5301 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5302
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5303 ~printf_value_cache (void) { }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5304
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5305 // Get the current value as a double and advance the internal pointer.
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5306 octave_value get_next_value (char type = 0);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5307
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5308 // Get the current value as an int and advance the internal pointer.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5309 int int_value (void);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5310
3145
0d640dc625c7 [project @ 1998-02-05 08:44:59 by jwe]
jwe
parents: 3013
diff changeset
5311 operator bool () const { return (curr_state == ok); }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5312
3653
84b2f30007d5 [project @ 2000-03-31 23:33:25 by jwe]
jwe
parents: 3645
diff changeset
5313 bool exhausted (void) { return (val_idx >= n_vals); }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5314
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5315 private:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5316
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5317 const octave_value_list values;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5318 int val_idx;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5319 int elt_idx;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5320 int n_vals;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5321 int n_elts;
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5322 bool have_data;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5323 octave_value curr_val;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5324 state curr_state;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5325
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5326 // Must create value cache with values!
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5327
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5328 printf_value_cache (void);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5329
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5330 // No copying!
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5331
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5332 printf_value_cache (const printf_value_cache&);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5333
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5334 printf_value_cache& operator = (const printf_value_cache&);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5335 };
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5336
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5337 octave_value
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5338 printf_value_cache::get_next_value (char type)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5339 {
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5340 octave_value retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5341
3711
60db0e500f10 [project @ 2000-08-03 05:09:39 by jwe]
jwe
parents: 3704
diff changeset
5342 if (exhausted ())
60db0e500f10 [project @ 2000-08-03 05:09:39 by jwe]
jwe
parents: 3704
diff changeset
5343 curr_state = conversion_error;
60db0e500f10 [project @ 2000-08-03 05:09:39 by jwe]
jwe
parents: 3704
diff changeset
5344
60db0e500f10 [project @ 2000-08-03 05:09:39 by jwe]
jwe
parents: 3704
diff changeset
5345 while (! exhausted ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5346 {
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5347 if (! have_data)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5348 {
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5349 curr_val = values (val_idx);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5350
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
5351 elt_idx = 0;
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
5352 n_elts = curr_val.numel ();
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
5353 have_data = true;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5354 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5355
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5356 if (elt_idx < n_elts)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5357 {
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5358 if (type == 's')
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5359 {
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5360 if (curr_val.is_string ())
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5361 {
21296
596e19e7e571 fix printf regression (bug #47192)
John W. Eaton <jwe@octave.org>
parents: 21235
diff changeset
5362 dim_vector dv (1, curr_val.numel ());
596e19e7e571 fix printf regression (bug #47192)
John W. Eaton <jwe@octave.org>
parents: 21235
diff changeset
5363 octave_value tmp = curr_val.reshape (dv);
596e19e7e571 fix printf regression (bug #47192)
John W. Eaton <jwe@octave.org>
parents: 21235
diff changeset
5364
596e19e7e571 fix printf regression (bug #47192)
John W. Eaton <jwe@octave.org>
parents: 21235
diff changeset
5365 std::string sval = tmp.string_value ();
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5366
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5367 retval = sval.substr (elt_idx);
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5368
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5369 // We've consumed the rest of the value.
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5370 elt_idx = n_elts;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5371 }
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5372 else
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5373 {
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5374 // Convert to character string while values are
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5375 // integers in the range [0 : char max]
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5376 const NDArray val = curr_val.array_value ();
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5377
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5378 octave_idx_type idx = elt_idx;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5379
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5380 for (; idx < n_elts; idx++)
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5381 {
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5382 double dval = val(idx);
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5383
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21777
diff changeset
5384 if (octave::math::x_nint (dval) != dval || dval < 0 || dval > 255)
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5385 break;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5386 }
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5387
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5388 octave_idx_type n = idx - elt_idx;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5389
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5390 if (n > 0)
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5391 {
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5392 std::string sval (n, '\0');
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5393
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5394 for (octave_idx_type i = 0; i < n; i++)
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5395 sval[i] = val(elt_idx++);
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5396
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5397 retval = sval;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5398 }
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5399 else
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5400 retval = curr_val.fast_elem_extract (elt_idx++);
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5401 }
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5402 }
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5403 else
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5404 {
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5405 retval = curr_val.fast_elem_extract (elt_idx++);
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5406
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5407 if (type == 'c' && ! retval.is_string ())
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5408 {
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5409 double dval = retval.double_value ();
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5410
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21777
diff changeset
5411 if (octave::math::x_nint (dval) == dval && dval >= 0 && dval < 256)
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5412 retval = static_cast<char> (dval);
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5413 }
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5414 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5415
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5416 if (elt_idx >= n_elts)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5417 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5418 elt_idx = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5419 val_idx++;
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5420 have_data = false;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5421 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5422
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5423 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5424 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5425 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5426 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5427 val_idx++;
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5428 have_data = false;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5429
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5430 if (n_elts == 0)
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5431 {
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5432 if (elt_idx == 0 && (type == 's' || type == 'c'))
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5433 {
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5434 retval = "";
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5435 break;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5436 }
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5437
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5438 if (exhausted ())
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5439 curr_state = conversion_error;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5440 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5441 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5442 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5443
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5444 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5445 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5446
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5447 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5448 printf_value_cache::int_value (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5449 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5450 int retval = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5451
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5452 octave_value val = get_next_value ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5453
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
5454 double dval = val.double_value (true);
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
5455
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21777
diff changeset
5456 if (octave::math::x_nint (dval) == dval)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21777
diff changeset
5457 retval = octave::math::nint (dval);
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
5458 else
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
5459 curr_state = conversion_error;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5460
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5461 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5462 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5463
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5464 // Ugh again and again.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5465
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
5466 template <typename T>
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
5467 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
5468 do_printf_conv (std::ostream& os, const char *fmt, int nsa, int sa_1,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5469 int sa_2, T arg, const std::string& who)
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5470 {
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
5471 int retval = 0;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
5472
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5473 switch (nsa)
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5474 {
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5475 case 2:
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
5476 retval = octave_format (os, fmt, sa_1, sa_2, arg);
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5477 break;
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5478
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5479 case 1:
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
5480 retval = octave_format (os, fmt, sa_1, arg);
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5481 break;
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5482
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5483 case 0:
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
5484 retval = octave_format (os, fmt, arg);
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5485 break;
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5486
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5487 default:
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
5488 ::error ("%s: internal error handling format", who.c_str ());
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5489 break;
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5490 }
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
5491
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
5492 return retval;
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5493 }
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
5494
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5495 static size_t
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5496 do_printf_string (std::ostream& os, const printf_format_elt *elt,
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5497 int nsa, int sa_1, int sa_2, const std::string& arg,
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5498 const std::string& who)
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5499 {
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5500 if (nsa > 2)
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20768
diff changeset
5501 ::error ("%s: internal error handling format", who.c_str ());
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5502
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5503 std::string flags = elt->flags;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5504
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5505 bool left = flags.find ('-') != std::string::npos;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5506
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5507 size_t len = arg.length ();
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5508
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5509 size_t fw = nsa > 0 ? sa_1 : (elt->fw == -1 ? len : elt->fw);
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5510 size_t prec = nsa > 1 ? sa_2 : (elt->prec == -1 ? len : elt->prec);
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5511
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5512 os << std::setw (fw)
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5513 << (left ? std::left : std::right)
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5514 << (prec < len ? arg.substr (0, prec) : arg);
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5515
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5516 return len > fw ? len : fw;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5517 }
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5518
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5519 static bool
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5520 is_nan_or_inf (const octave_value& val)
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5521 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5522 octave_value ov_isnan = val.isnan ();
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5523 octave_value ov_isinf = val.isinf ();
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5524
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5525 return (ov_isnan.is_true () || ov_isinf.is_true ());
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5526 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5527
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5528 static bool
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5529 ok_for_signed_int_conv (const octave_value& val)
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5530 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5531 uint64_t limit = std::numeric_limits<int64_t>::max ();
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5532
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5533 if (val.is_string ())
20252
7fa170cc14fe Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents: 19864
diff changeset
5534 return true;
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5535 else if (val.is_integer_type ())
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5536 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5537 if (val.is_uint64_type ())
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5538 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5539 octave_uint64 ival = val.uint64_scalar_value ();
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5540
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5541 if (ival.value () <= limit)
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5542 return true;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5543 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5544 else
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5545 return true;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5546 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5547 else
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5548 {
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5549 double dval = val.double_value (true);
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5550
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21777
diff changeset
5551 if (dval == octave::math::round (dval) && dval <= limit)
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5552 return true;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5553 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5554
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5555 return false;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5556 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5557
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5558 static bool
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5559 ok_for_unsigned_int_conv (const octave_value& val)
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5560 {
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5561 if (val.is_string ())
20252
7fa170cc14fe Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents: 19864
diff changeset
5562 return true;
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5563 else if (val.is_integer_type ())
18653
7d0014bb9e4e also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents: 18650
diff changeset
5564 {
7d0014bb9e4e also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents: 18650
diff changeset
5565 // Easier than dispatching here...
7d0014bb9e4e also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents: 18650
diff changeset
5566
7d0014bb9e4e also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents: 18650
diff changeset
5567 octave_value ov_is_ge_zero
7d0014bb9e4e also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents: 18650
diff changeset
5568 = do_binary_op (octave_value::op_ge, val, octave_value (0.0));
7d0014bb9e4e also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents: 18650
diff changeset
5569
7d0014bb9e4e also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents: 18650
diff changeset
5570 return ov_is_ge_zero.is_true ();
7d0014bb9e4e also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents: 18650
diff changeset
5571 }
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5572 else
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5573 {
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5574 double dval = val.double_value (true);
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5575
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5576 uint64_t limit = std::numeric_limits<uint64_t>::max ();
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5577
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21777
diff changeset
5578 if (dval == octave::math::round (dval) && dval >= 0 && dval <= limit)
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5579 return true;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5580 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5581
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5582 return false;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5583 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5584
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5585 static std::string
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5586 switch_to_g_format (const printf_format_elt *elt)
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5587 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5588 std::string tfmt = elt->text;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5589
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5590 tfmt.replace (tfmt.rfind (elt->type), 1, "g");
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5591
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5592 return tfmt;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5593 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5594
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5595 int
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5596 octave_base_stream::do_numeric_printf_conv (std::ostream& os,
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5597 const printf_format_elt *elt,
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5598 int nsa, int sa_1, int sa_2,
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5599 const octave_value& val,
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5600 const std::string& who)
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5601 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5602 int retval = 0;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5603
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5604 const char *fmt = elt->text;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5605
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5606 if (is_nan_or_inf (val))
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5607 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5608 double dval = val.double_value ();
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5609
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5610 std::string tfmt = fmt;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5611 std::string::size_type i1, i2;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5612
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5613 tfmt.replace ((i1 = tfmt.rfind (elt->type)), 1, 1, 's');
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5614
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5615 if ((i2 = tfmt.rfind ('.')) != std::string::npos && i2 < i1)
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5616 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5617 tfmt.erase (i2, i1-i2);
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5618 if (elt->prec == -2)
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5619 nsa--;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5620 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5621
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5622 const char *tval;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5623 if (lo_ieee_isinf (dval))
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5624 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5625 if (elt->flags.find ('+') != std::string::npos)
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5626 tval = (dval < 0 ? "-Inf" : "+Inf");
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5627 else
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5628 tval = (dval < 0 ? "-Inf" : "Inf");
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5629 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5630 else
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5631 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5632 if (elt->flags.find ('+') != std::string::npos)
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5633 tval = (lo_ieee_is_NA (dval) ? "+NA" : "+NaN");
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5634 else
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5635 tval = (lo_ieee_is_NA (dval) ? "NA" : "NaN");
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5636 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5637
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5638 retval += do_printf_conv (os, tfmt.c_str (), nsa, sa_1, sa_2, tval, who);
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5639 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5640 else
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5641 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5642 static std::string llmod
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5643 = sizeof (long) == sizeof (int64_t) ? "l" : "ll";
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5644
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5645 char type = elt->type;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5646
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5647 switch (type)
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5648 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5649 case 'd': case 'i': case 'c':
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5650 if (ok_for_signed_int_conv (val))
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5651 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5652 octave_int64 tval = val.int64_scalar_value ();
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5653
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5654 // Insert "long" modifier.
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5655 std::string tfmt = fmt;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5656 tfmt.replace (tfmt.rfind (type), 1, llmod + type);
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5657
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5658 retval += do_printf_conv (os, tfmt.c_str (), nsa, sa_1, sa_2,
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5659 tval.value (), who);
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5660 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5661 else
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5662 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5663 std::string tfmt = switch_to_g_format (elt);
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5664
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5665 double dval = val.double_value (true);
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5666
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
5667 retval += do_printf_conv (os, tfmt.c_str (), nsa,
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
5668 sa_1, sa_2, dval, who);
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5669 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5670 break;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5671
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5672 case 'o': case 'x': case 'X': case 'u':
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5673 if (ok_for_unsigned_int_conv (val))
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5674 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5675 octave_uint64 tval = val.uint64_scalar_value ();
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5676
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5677 // Insert "long" modifier.
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5678 std::string tfmt = fmt;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5679 tfmt.replace (tfmt.rfind (type), 1, llmod + type);
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5680
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5681 retval += do_printf_conv (os, tfmt.c_str (), nsa, sa_1, sa_2,
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5682 tval.value (), who);
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5683 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5684 else
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5685 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5686 std::string tfmt = switch_to_g_format (elt);
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5687
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5688 double dval = val.double_value (true);
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5689
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
5690 retval += do_printf_conv (os, tfmt.c_str (), nsa,
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
5691 sa_1, sa_2, dval, who);
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5692 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5693 break;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5694
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5695 case 'f': case 'e': case 'E':
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5696 case 'g': case 'G':
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5697 {
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5698 double dval = val.double_value (true);
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5699
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
5700 retval += do_printf_conv (os, fmt, nsa, sa_1, sa_2, dval, who);
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5701 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5702 break;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5703
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5704 default:
20938
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
5705 // Note: error is member fcn from octave_base_stream, not ::error.
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
5706 // This error does not halt execution so "return ..." must exist.
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20768
diff changeset
5707 error ("%s: invalid format specifier", who.c_str ());
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5708 return -1;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5709 break;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5710 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5711 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5712
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5713 return retval;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5714 }
6492
bcfdc9f0d267 [project @ 2007-04-05 06:13:30 by jwe]
jwe
parents: 6483
diff changeset
5715
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5716 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5717 octave_base_stream::do_printf (printf_format_list& fmt_list,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5718 const octave_value_list& args,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5719 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5720 {
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
5721 int retval = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5722
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
5723 octave_idx_type nconv = fmt_list.num_conversions ();
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
5724
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
5725 std::ostream *osp = output_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5726
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5727 if (! osp)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5728 invalid_operation (who, "writing");
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5729 else
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5730 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
5731 std::ostream& os = *osp;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5732
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5733 const printf_format_elt *elt = fmt_list.first ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5734
7352
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
5735 printf_value_cache val_cache (args, who);
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
5736
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5737 for (;;)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5738 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5739 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5740
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5741 if (! elt)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5742 ::error ("%s: internal error handling format", who.c_str ());
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5743
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5744 // NSA is the number of 'star' args to convert.
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5745 int nsa = (elt->fw == -2) + (elt->prec == -2);
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5746
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5747 int sa_1 = 0;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5748 int sa_2 = 0;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5749
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5750 if (nsa > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5751 {
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5752 sa_1 = val_cache.int_value ();
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5753
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5754 if (! val_cache)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5755 break;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5756 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5757 {
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5758 if (nsa > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5759 {
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5760 sa_2 = val_cache.int_value ();
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5761
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5762 if (! val_cache)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5763 break;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5764 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5765 }
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5766 }
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5767
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5768 if (elt->type == '%')
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5769 {
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5770 os << "%";
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5771 retval++;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5772 }
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5773 else if (elt->args == 0 && elt->text)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5774 {
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5775 os << elt->text;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5776 retval += strlen (elt->text);
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5777 }
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5778 else if (elt->type == 's' || elt->type == 'c')
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5779 {
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5780 octave_value val = val_cache.get_next_value (elt->type);
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5781
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5782 if (val_cache)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5783 {
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5784 if (val.is_string ())
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5785 {
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5786 std::string sval = val.string_value ();
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5787
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5788 retval += do_printf_string (os, elt, nsa, sa_1,
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5789 sa_2, sval, who);
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5790 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5791 else
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5792 retval += do_numeric_printf_conv (os, elt, nsa, sa_1,
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
5793 sa_2, val, who);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5794 }
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5795 else
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5796 break;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5797 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5798 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5799 {
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5800 octave_value val = val_cache.get_next_value ();
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5801
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5802 if (val_cache)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5803 retval += do_numeric_printf_conv (os, elt, nsa, sa_1,
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5804 sa_2, val, who);
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5805 else
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5806 break;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5807 }
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5808
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5809 if (! os)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5810 {
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
5811 error ("%s: write error", who.c_str ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5812 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5813 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5814
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5815 elt = fmt_list.next (nconv > 0 && ! val_cache.exhausted ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5816
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5817 if (! elt || (val_cache.exhausted () && elt->args > 0))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5818 break;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5819 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5820 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5821
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5822 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5823 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5824
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5825 int
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
5826 octave_base_stream::printf (const std::string& fmt,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5827 const octave_value_list& args,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5828 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5829 {
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
5830 printf_format_list fmt_list (fmt);
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
5831
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
5832 if (fmt_list.num_conversions () == -1)
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
5833 ::error ("%s: invalid format specified", who.c_str ());
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5834
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5835 return do_printf (fmt_list, args, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5836 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5837
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5838 int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
5839 octave_base_stream::puts (const std::string& s, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5840 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5841 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5842
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
5843 std::ostream *osp = output_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5844
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5845 if (! osp)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5846 invalid_operation (who, "writing");
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5847 else
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5848 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
5849 std::ostream& os = *osp;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5850
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5851 os << s;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5852
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5853 if (! os)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5854 error ("%s: write error", who.c_str ());
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5855 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5856 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5857 // FIXME: why does this seem to be necessary?
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5858 // Without it, output from a loop like
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5859 //
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5860 // for i = 1:100, fputs (stdout, "foo\n"); endfor
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5861 //
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5862 // doesn't seem to go to the pager immediately.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5863 os.flush ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5864
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5865 if (os)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5866 retval = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5867 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5868 error ("%s: write error", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5869 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5870 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5871
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5872 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5873 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5874
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5875 // Return current error message for this stream.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5876
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
5877 std::string
2435
3be97fe02051 [project @ 1996-10-27 21:31:29 by jwe]
jwe
parents: 2341
diff changeset
5878 octave_base_stream::error (bool clear_err, int& err_num)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5879 {
2435
3be97fe02051 [project @ 1996-10-27 21:31:29 by jwe]
jwe
parents: 2341
diff changeset
5880 err_num = fail ? -1 : 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5881
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
5882 std::string tmp = errmsg;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5883
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5884 if (clear_err)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5885 clear ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5886
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5887 return tmp;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5888 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5889
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5890 void
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
5891 octave_base_stream::invalid_operation (const std::string& who, const char *rw)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5892 {
20938
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
5893 // Note: This calls the member fcn error, not ::error from error.h.
6297
a943cb9c8068 [project @ 2007-02-10 08:42:27 by jwe]
jwe
parents: 6296
diff changeset
5894 error (who, std::string ("stream not open for ") + rw);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5895 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5896
3552
41daa489833a [project @ 2000-02-03 03:05:28 by jwe]
jwe
parents: 3548
diff changeset
5897 octave_stream::octave_stream (octave_base_stream *bs)
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5898 : rep (bs)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5899 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5900 if (rep)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5901 rep->count = 1;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5902 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5903
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5904 octave_stream::~octave_stream (void)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5905 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5906 if (rep && --rep->count == 0)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5907 delete rep;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5908 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5909
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5910 octave_stream::octave_stream (const octave_stream& s)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5911 : rep (s.rep)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5912 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5913 if (rep)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5914 rep->count++;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5915 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5916
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5917 octave_stream&
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5918 octave_stream::operator = (const octave_stream& s)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5919 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5920 if (rep != s.rep)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5921 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5922 if (rep && --rep->count == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5923 delete rep;
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5924
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5925 rep = s.rep;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5926
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5927 if (rep)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5928 rep->count++;
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5929 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5930
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5931 return *this;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5932 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
5933
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5934 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5935 octave_stream::flush (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5936 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5937 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5938
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
5939 if (stream_ok ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5940 retval = rep->flush ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5941
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5942 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5943 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5944
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
5945 std::string
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
5946 octave_stream::getl (octave_idx_type max_len, bool& err, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5947 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
5948 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5949
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
5950 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
5951 retval = rep->getl (max_len, err, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5952
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5953 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5954 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5955
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
5956 std::string
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
5957 octave_stream::getl (const octave_value& tc_max_len, bool& err,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5958 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5959 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5960 err = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5961
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5962 int conv_err = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5963
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
5964 int max_len = -1;
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
5965
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
5966 if (tc_max_len.is_defined ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5967 {
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
5968 max_len = convert_to_valid_int (tc_max_len, conv_err);
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
5969
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
5970 if (conv_err || max_len < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5971 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5972 err = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5973 ::error ("%s: invalid maximum length specified", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5974 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5975 }
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
5976
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
5977 return getl (max_len, err, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5978 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5979
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
5980 std::string
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
5981 octave_stream::gets (octave_idx_type max_len, bool& err, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5982 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
5983 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5984
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
5985 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
5986 retval = rep->gets (max_len, err, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5987
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5988 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5989 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5990
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
5991 std::string
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
5992 octave_stream::gets (const octave_value& tc_max_len, bool& err,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
5993 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5994 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5995 err = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5996
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5997 int conv_err = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5998
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
5999 int max_len = -1;
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
6000
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
6001 if (tc_max_len.is_defined ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6002 {
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
6003 max_len = convert_to_valid_int (tc_max_len, conv_err);
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
6004
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
6005 if (conv_err || max_len < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6006 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6007 err = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6008 ::error ("%s: invalid maximum length specified", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6009 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6010 }
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
6011
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6012 return gets (max_len, err, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6013 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6014
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
6015 off_t
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
6016 octave_stream::skipl (off_t count, bool& err, const std::string& who)
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6017 {
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
6018 off_t retval = -1;
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6019
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6020 if (stream_ok ())
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6021 retval = rep->skipl (count, err, who);
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6022
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6023 return retval;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6024 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6025
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
6026 off_t
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6027 octave_stream::skipl (const octave_value& tc_count, bool& err,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6028 const std::string& who)
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6029 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6030 err = false;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6031
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6032 int conv_err = 0;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6033
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6034 int count = 1;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6035
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6036 if (tc_count.is_defined ())
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6037 {
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
6038 if (tc_count.is_scalar_type ()
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
6039 && octave::math::isinf (tc_count.scalar_value ()))
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6040 count = -1;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6041 else
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6042 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6043 count = convert_to_valid_int (tc_count, conv_err);
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6044
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6045 if (conv_err || count < 0)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6046 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6047 err = true;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6048 ::error ("%s: invalid number of lines specified", who.c_str ());
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6049 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6050 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6051 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6052
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6053 return skipl (count, err, who);
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6054 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
6055
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6056 int
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
6057 octave_stream::seek (off_t offset, int origin)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6058 {
5065
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
6059 int status = -1;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6060
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
6061 if (stream_ok ())
4889
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
6062 {
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
6063 clearerr ();
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
6064
12957
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
6065 // Find current position so we can return to it if needed.
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
6066 off_t orig_pos = rep->tell ();
5065
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
6067
12957
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
6068 // Move to end of file. If successful, find the offset of the end.
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
6069 status = rep->seek (0, SEEK_END);
5065
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
6070
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
6071 if (status == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6072 {
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
6073 off_t eof_pos = rep->tell ();
12957
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
6074
12943
8372d50de75a improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents: 12936
diff changeset
6075 if (origin == SEEK_CUR)
8372d50de75a improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents: 12936
diff changeset
6076 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6077 // Move back to original position, otherwise we will be seeking
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6078 // from the end of file which is probably not the original
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6079 // location.
12943
8372d50de75a improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents: 12936
diff changeset
6080 rep->seek (orig_pos, SEEK_SET);
8372d50de75a improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents: 12936
diff changeset
6081 }
8372d50de75a improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents: 12936
diff changeset
6082
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6083 // Attempt to move to desired position; may be outside bounds of
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6084 // existing file.
12957
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
6085 status = rep->seek (offset, origin);
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
6086
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
6087 if (status == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6088 {
12957
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
6089 // Where are we after moving to desired position?
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
6090 off_t desired_pos = rep->tell ();
12957
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
6091
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6092 // I don't think save_pos can be less than zero,
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6093 // but we'll check anyway...
12957
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
6094 if (desired_pos > eof_pos || desired_pos < 0)
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
6095 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6096 // Seek outside bounds of file.
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6097 // Failure should leave position unchanged.
12957
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
6098 rep->seek (orig_pos, SEEK_SET);
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
6099
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
6100 status = -1;
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
6101 }
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
6102 }
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
6103 else
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
6104 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6105 // Seeking to the desired position failed.
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6106 // Move back to original position and return failure status.
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6107 rep->seek (orig_pos, SEEK_SET);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6108
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6109 status = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6110 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6111 }
4889
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
6112 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6113
5065
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
6114 return status;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6115 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6116
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6117 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6118 octave_stream::seek (const octave_value& tc_offset,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6119 const octave_value& tc_origin)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6120 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6121 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6122
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6123 // FIXME: should we have octave_value methods that handle off_t explicitly?
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6124 octave_int64 val = tc_offset.xint64_scalar_value ("fseek: invalid value for offset");
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
6125 off_t xoffset = val.value ();
4645
bd2067547b40 [project @ 2003-11-23 08:07:52 by jwe]
jwe
parents: 4643
diff changeset
6126
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6127 int conv_err = 0;
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6128
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6129 int origin = SEEK_SET;
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6130
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6131 if (tc_origin.is_string ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6132 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6133 std::string xorigin = tc_origin.string_value ("fseek: invalid value for origin");
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6134
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6135 if (xorigin == "bof")
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6136 origin = SEEK_SET;
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6137 else if (xorigin == "cof")
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6138 origin = SEEK_CUR;
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6139 else if (xorigin == "eof")
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6140 origin = SEEK_END;
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6141 else
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6142 conv_err = -1;
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6143 }
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6144 else
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6145 {
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6146 int xorigin = convert_to_valid_int (tc_origin, conv_err);
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6147
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6148 if (! conv_err)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6149 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6150 if (xorigin == -1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6151 origin = SEEK_SET;
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6152 else if (xorigin == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6153 origin = SEEK_CUR;
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6154 else if (xorigin == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6155 origin = SEEK_END;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6156 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6157 conv_err = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6158 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6159 }
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
6160
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
6161 if (conv_err)
20938
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
6162 ::error ("fseek: invalid value for origin");
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6163
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
6164 retval = seek (xoffset, origin);
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
6165
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
6166 if (retval != 0)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
6167 // Note: error is member fcn from octave_stream, not ::error.
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
6168 error ("fseek: failed to seek to requested position");
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6169
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6170 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6171 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6172
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
6173 off_t
4797
19b8225bdaa2 [project @ 2004-02-23 22:10:31 by jwe]
jwe
parents: 4693
diff changeset
6174 octave_stream::tell (void)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6175 {
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
6176 off_t retval = -1;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6177
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
6178 if (stream_ok ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6179 retval = rep->tell ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6180
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6181 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6182 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6183
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6184 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6185 octave_stream::rewind (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6186 {
6296
85eb75190e01 [project @ 2007-02-10 07:10:42 by jwe]
jwe
parents: 6109
diff changeset
6187 return seek (0, SEEK_SET);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6188 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6189
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
6190 bool
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
6191 octave_stream::is_open (void) const
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
6192 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
6193 bool retval = false;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
6194
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
6195 if (stream_ok ())
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
6196 retval = rep->is_open ();
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
6197
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
6198 return retval;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
6199 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
6200
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
6201 void
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
6202 octave_stream::close (void)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
6203 {
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
6204 if (stream_ok ())
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
6205 rep->close ();
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
6206 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
6207
21335
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6208 // FIXME: maybe these should be defined in lo-ieee.h?
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6209
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6210 template <typename T>
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6211 static inline bool
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6212 is_old_NA (T)
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6213 {
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6214 return false;
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6215 }
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6216
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6217 template <>
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6218 inline bool
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6219 is_old_NA<double> (double val)
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6220 {
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6221 return __lo_ieee_is_old_NA (val);
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6222 }
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6223
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6224 template <typename T>
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6225 static inline T
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6226 replace_old_NA (T val)
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6227 {
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6228 return val;
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6229 }
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6230
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6231 template <>
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6232 inline double
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6233 replace_old_NA<double> (double val)
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6234 {
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6235 return __lo_ieee_replace_old_NA (val);
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6236 }
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6237
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
6238 template <typename SRC_T, typename DST_T>
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6239 static octave_value
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6240 convert_and_copy (std::list<void *>& input_buf_list,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6241 octave_idx_type input_buf_elts,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6242 octave_idx_type elts_read,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6243 octave_idx_type nr, octave_idx_type nc, bool swap,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6244 bool do_float_fmt_conv, bool do_NA_conv,
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
6245 octave::mach_info::float_format from_flt_fmt)
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6246 {
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6247 typedef typename DST_T::element_type dst_elt_type;
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6248
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6249 DST_T conv (dim_vector (nr, nc));
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6250
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6251 dst_elt_type *conv_data = conv.fortran_vec ();
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6252
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6253 octave_idx_type j = 0;
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6254
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6255 for (std::list<void *>::const_iterator it = input_buf_list.begin ();
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6256 it != input_buf_list.end (); it++)
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6257 {
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6258 SRC_T *data = static_cast<SRC_T *> (*it);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6259
17463
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6260 if (swap || do_float_fmt_conv)
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6261 {
21335
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6262 if (do_NA_conv)
17463
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6263 {
21335
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6264 for (octave_idx_type i = 0; i < input_buf_elts && j < elts_read;
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6265 i++, j++)
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6266 {
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6267 if (swap)
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6268 swap_bytes<sizeof (SRC_T)> (&data[i]);
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6269 else if (do_float_fmt_conv)
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6270 do_float_format_conversion (&data[i], sizeof (SRC_T),
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6271 1, from_flt_fmt,
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
6272 octave::mach_info::native_float_format ());
21335
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6273
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6274 dst_elt_type tmp (data[i]);
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6275
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6276 if (is_old_NA (tmp))
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6277 tmp = replace_old_NA (tmp);
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6278
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6279 conv_data[j] = tmp;
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6280 }
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6281 }
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6282 else
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6283 {
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6284 for (octave_idx_type i = 0; i < input_buf_elts && j < elts_read;
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6285 i++, j++)
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6286 {
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6287 if (swap)
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6288 swap_bytes<sizeof (SRC_T)> (&data[i]);
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6289 else if (do_float_fmt_conv)
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6290 do_float_format_conversion (&data[i], sizeof (SRC_T),
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6291 1, from_flt_fmt,
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
6292 octave::mach_info::native_float_format ());
21335
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6293
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6294 conv_data[j] = data[i];
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6295 }
17463
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6296 }
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6297 }
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6298 else
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6299 {
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6300 if (do_NA_conv)
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6301 {
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6302 for (octave_idx_type i = 0; i < input_buf_elts && j < elts_read;
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6303 i++, j++)
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6304 {
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6305 dst_elt_type tmp (data[i]);
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6306
21335
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6307 if (is_old_NA (tmp))
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
6308 tmp = replace_old_NA (tmp);
17463
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6309
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6310 conv_data[j] = tmp;
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6311 }
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6312 }
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6313 else
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6314 {
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6315 for (octave_idx_type i = 0; i < input_buf_elts && j < elts_read;
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6316 i++, j++)
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6317 conv_data[j] = data[i];
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
6318 }
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6319 }
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6320
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6321 delete [] data;
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6322 }
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6323
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6324 input_buf_list.clear ();
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6325
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6326 for (octave_idx_type i = elts_read; i < nr * nc; i++)
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6327 conv_data[i] = dst_elt_type (0);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6328
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6329 return conv;
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6330 }
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6331
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6332 typedef octave_value (*conv_fptr)
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6333 (std::list<void *>& input_buf_list, octave_idx_type input_buf_elts,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6334 octave_idx_type elts_read, octave_idx_type nr, octave_idx_type nc,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6335 bool swap, bool do_float_fmt_conv, bool do_NA_conv,
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
6336 octave::mach_info::float_format from_flt_fmt);
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6337
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
6338 #define TABLE_ELT(T, U, V, W) \
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6339 conv_fptr_table[oct_data_conv::T][oct_data_conv::U] = convert_and_copy<V, W>
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6340
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
6341 #define FILL_TABLE_ROW(T, V) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
6342 TABLE_ELT (T, dt_int8, V, int8NDArray); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
6343 TABLE_ELT (T, dt_uint8, V, uint8NDArray); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
6344 TABLE_ELT (T, dt_int16, V, int16NDArray); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
6345 TABLE_ELT (T, dt_uint16, V, uint16NDArray); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
6346 TABLE_ELT (T, dt_int32, V, int32NDArray); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
6347 TABLE_ELT (T, dt_uint32, V, uint32NDArray); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
6348 TABLE_ELT (T, dt_int64, V, int64NDArray); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
6349 TABLE_ELT (T, dt_uint64, V, uint64NDArray); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
6350 TABLE_ELT (T, dt_single, V, FloatNDArray); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
6351 TABLE_ELT (T, dt_double, V, NDArray); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
6352 TABLE_ELT (T, dt_char, V, charNDArray); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
6353 TABLE_ELT (T, dt_schar, V, charNDArray); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
6354 TABLE_ELT (T, dt_uchar, V, charNDArray); \
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6355 TABLE_ELT (T, dt_logical, V, boolNDArray);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6356
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6357 octave_value
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6358 octave_stream::finalize_read (std::list<void *>& input_buf_list,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6359 octave_idx_type input_buf_elts,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6360 octave_idx_type elts_read,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6361 octave_idx_type nr, octave_idx_type nc,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6362 oct_data_conv::data_type input_type,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6363 oct_data_conv::data_type output_type,
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
6364 octave::mach_info::float_format ffmt)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6365 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6366 octave_value retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6367
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6368 static bool initialized = false;
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6369
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6370 // Table function pointers for return types x read types.
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6371
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6372 static conv_fptr conv_fptr_table[oct_data_conv::dt_unknown][14];
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6373
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6374 if (! initialized)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6375 {
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6376 for (int i = 0; i < oct_data_conv::dt_unknown; i++)
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6377 for (int j = 0; j < 14; j++)
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6378 conv_fptr_table[i][j] = 0;
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6379
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6380 FILL_TABLE_ROW (dt_int8, int8_t);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6381 FILL_TABLE_ROW (dt_uint8, uint8_t);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6382 FILL_TABLE_ROW (dt_int16, int16_t);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6383 FILL_TABLE_ROW (dt_uint16, uint16_t);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6384 FILL_TABLE_ROW (dt_int32, int32_t);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6385 FILL_TABLE_ROW (dt_uint32, uint32_t);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6386 FILL_TABLE_ROW (dt_int64, int64_t);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6387 FILL_TABLE_ROW (dt_uint64, uint64_t);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6388 FILL_TABLE_ROW (dt_single, float);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6389 FILL_TABLE_ROW (dt_double, double);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6390 FILL_TABLE_ROW (dt_char, char);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6391 FILL_TABLE_ROW (dt_schar, signed char);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6392 FILL_TABLE_ROW (dt_uchar, unsigned char);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6393 FILL_TABLE_ROW (dt_logical, bool);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6394
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6395 initialized = true;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6396 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6397
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6398 bool swap = false;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6399
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
6400 if (ffmt == octave::mach_info::flt_fmt_unknown)
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6401 ffmt = float_format ();
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6402
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
6403 if (octave::mach_info::words_big_endian ())
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
6404 swap = (ffmt == octave::mach_info::flt_fmt_ieee_little_endian);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6405 else
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
6406 swap = (ffmt == octave::mach_info::flt_fmt_ieee_big_endian);
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6407
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6408 bool do_float_fmt_conv = ((input_type == oct_data_conv::dt_double
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6409 || input_type == oct_data_conv::dt_single)
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6410 && ffmt != float_format ());
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6411
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6412 bool do_NA_conv = (output_type == oct_data_conv::dt_double);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6413
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6414 switch (output_type)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6415 {
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6416 case oct_data_conv::dt_int8:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6417 case oct_data_conv::dt_uint8:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6418 case oct_data_conv::dt_int16:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6419 case oct_data_conv::dt_uint16:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6420 case oct_data_conv::dt_int32:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6421 case oct_data_conv::dt_uint32:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6422 case oct_data_conv::dt_int64:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6423 case oct_data_conv::dt_uint64:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6424 case oct_data_conv::dt_single:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6425 case oct_data_conv::dt_double:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6426 case oct_data_conv::dt_char:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6427 case oct_data_conv::dt_schar:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6428 case oct_data_conv::dt_uchar:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6429 case oct_data_conv::dt_logical:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6430 {
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6431 conv_fptr fptr = conv_fptr_table[input_type][output_type];
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6432
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6433 retval = fptr (input_buf_list, input_buf_elts, elts_read,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6434 nr, nc, swap, do_float_fmt_conv, do_NA_conv, ffmt);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6435 }
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6436 break;
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6437
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6438 default:
20938
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
6439 ::error ("read: invalid type specification");
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6440 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6441
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6442 return retval;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6443 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6444
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6445 octave_value
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
6446 octave_stream::read (const Array<double>& size, octave_idx_type block_size,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6447 oct_data_conv::data_type input_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6448 oct_data_conv::data_type output_type,
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
6449 octave_idx_type skip, octave::mach_info::float_format ffmt,
18210
a0abcf377ec5 return elements read, not bytes in fread second output (bug #41091)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
6450 octave_idx_type& count)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6451 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6452 octave_value retval;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6453
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6454 octave_idx_type nr = -1;
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6455 octave_idx_type nc = -1;
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6456
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6457 bool one_elt_size_spec = false;
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6458
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6459 if (! stream_ok ())
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6460 return retval;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6461
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6462 // FIXME: we may eventually want to make this extensible.
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6463
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6464 // FIXME: we need a better way to ensure that this
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6465 // numbering stays consistent with the order of the elements in the
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6466 // data_type enum in the oct_data_conv class.
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6467
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6468 // Expose this in a future version?
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6469 octave_idx_type char_count = 0;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6470
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6471 count = 0;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6472
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6473 try
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6474 {
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6475 get_size (size, nr, nc, one_elt_size_spec, "fread");
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6476 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
6477 catch (const octave::execution_exception&)
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6478 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6479 invalid_operation ("fread", "reading");
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6480 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6481
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6482 octave_idx_type elts_to_read;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6483
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6484 if (one_elt_size_spec)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6485 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6486 // If NR == 0, Matlab returns [](0x0).
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6487
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6488 // If NR > 0, the result will be a column vector with the given
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6489 // number of rows.
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6490
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6491 // If NR < 0, then we have Inf and the result will be a column
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6492 // vector but we have to wait to see how big NR will be.
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6493
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6494 if (nr == 0)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6495 nr = nc = 0;
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
6496 else
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6497 nc = 1;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6498 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6499 else
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6500 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6501 // Matlab returns [] even if there are two elements in the size
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6502 // specification and one is nonzero.
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6503
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6504 // If NC < 0 we have [NR, Inf] and we'll wait to decide how big NC
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6505 // should be.
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6506
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6507 if (nr == 0 || nc == 0)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6508 nr = nc = 0;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6509 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6510
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6511 // FIXME: Ensure that this does not overflow.
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6512 // Maybe try comparing nr * nc computed in double with
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6513 // std::numeric_limits<octave_idx_type>::max ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6514 elts_to_read = nr * nc;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6515
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6516 bool read_to_eof = elts_to_read < 0;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6517
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6518 octave_idx_type input_buf_elts = -1;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6519
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6520 if (skip == 0)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6521 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6522 if (read_to_eof)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6523 input_buf_elts = 1024 * 1024;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6524 else
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6525 input_buf_elts = elts_to_read;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6526 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6527 else
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6528 input_buf_elts = block_size;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6529
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6530 octave_idx_type input_elt_size
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6531 = oct_data_conv::data_type_size (input_type);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6532
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6533 octave_idx_type input_buf_size = input_buf_elts * input_elt_size;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6534
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6535 assert (input_buf_size >= 0);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6536
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6537 // Must also work and return correct type object
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6538 // for 0 elements to read.
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6539 std::istream *isp = input_stream ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6540
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6541 if (! isp)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6542 error ("fread: invalid input stream");
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6543 else
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6544 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6545 std::istream& is = *isp;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6546
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6547 std::list <void *> input_buf_list;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6548
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6549 while (is && ! is.eof ()
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6550 && (read_to_eof || count < elts_to_read))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6551 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6552 if (! read_to_eof)
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6553 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6554 octave_idx_type remaining_elts = elts_to_read - count;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6555
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6556 if (remaining_elts < input_buf_elts)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6557 input_buf_size = remaining_elts * input_elt_size;
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6558 }
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6559
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6560 char *input_buf = new char [input_buf_size];
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6561
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6562 is.read (input_buf, input_buf_size);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6563
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6564 size_t gcount = is.gcount ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6565
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6566 char_count += gcount;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6567
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6568 octave_idx_type nel = gcount / input_elt_size;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6569
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6570 count += nel;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6571
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6572 input_buf_list.push_back (input_buf);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6573
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6574 if (is && skip != 0 && nel == block_size)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6575 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6576 // Seek to skip.
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6577 // If skip would move past EOF, position at EOF.
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6578
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6579 off_t orig_pos = tell ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6580
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6581 seek (0, SEEK_END);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6582
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6583 off_t eof_pos = tell ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6584
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6585 // Is it possible for this to fail to return us to
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6586 // the original position?
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6587 seek (orig_pos, SEEK_SET);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6588
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6589 off_t remaining = eof_pos - orig_pos;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6590
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6591 if (remaining < skip)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6592 seek (0, SEEK_END);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6593 else
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6594 seek (skip, SEEK_CUR);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6595
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6596 if (! is)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6597 break;
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6598 }
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6599 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6600
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6601 if (read_to_eof)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6602 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6603 if (nc < 0)
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6604 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6605 nc = count / nr;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6606
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
6607 if (count % nr != 0)
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6608 nc++;
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6609 }
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6610 else
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6611 nr = count;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6612 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6613 else if (count == 0)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6614 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6615 nr = 0;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6616 nc = 0;
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
6617 }
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6618 else if (count != nr * nc)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6619 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6620 if (count % nr != 0)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6621 nc = count / nr + 1;
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
6622 else
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6623 nc = count / nr;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6624
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6625 if (count < nr)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6626 nr = count;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6627 }
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6628
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6629 retval = finalize_read (input_buf_list, input_buf_elts, count,
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6630 nr, nc, input_type, output_type, ffmt);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6631 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6632
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6633 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6634 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6635
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
6636 octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
6637 octave_stream::write (const octave_value& data, octave_idx_type block_size,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6638 oct_data_conv::data_type output_type,
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
6639 octave_idx_type skip, octave::mach_info::float_format flt_fmt)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6640 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
6641 octave_idx_type retval = -1;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6642
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6643 if (! stream_ok ())
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6644 invalid_operation ("fwrite", "writing");
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6645 else
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6646 {
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
6647 if (flt_fmt == octave::mach_info::flt_fmt_unknown)
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
6648 flt_fmt = float_format ();
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
6649
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
6650 octave_idx_type status = data.write (*this, block_size, output_type,
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
6651 skip, flt_fmt);
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
6652
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
6653 if (status < 0)
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
6654 error ("fwrite: write error");
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6655 else
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
6656 retval = status;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6657 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6658
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6659 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6660 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6661
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
6662 template <typename T, typename V>
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6663 static void
18616
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6664 convert_chars (const void *data, void *conv_data, octave_idx_type n_elts)
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6665 {
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6666 const T *tt_data = static_cast<const T *> (data);
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6667
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6668 V *vt_data = static_cast<V *> (conv_data);
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6669
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6670 for (octave_idx_type i = 0; i < n_elts; i++)
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6671 vt_data[i] = tt_data[i];
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6672 }
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6673
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
6674 template <typename T, typename V>
18616
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6675 static void
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6676 convert_ints (const T *data, void *conv_data, octave_idx_type n_elts,
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6677 bool swap)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6678 {
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6679 typedef typename V::val_type val_type;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6680
19739
3fa35defe495 Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19729
diff changeset
6681 val_type *vt_data = static_cast<val_type *> (conv_data);
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6682
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6683 for (octave_idx_type i = 0; i < n_elts; i++)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6684 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6685 // Yes, we want saturation semantics when converting to an integer type.
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6686 V val (data[i]);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6687
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6688 vt_data[i] = val.value ();
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6689
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6690 if (swap)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6691 swap_bytes<sizeof (val_type)> (&vt_data[i]);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6692 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6693 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6694
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
6695 template <typename T>
18616
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6696 class ultimate_element_type
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6697 {
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6698 public:
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6699 typedef T type;
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6700 };
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6701
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
6702 template <typename T>
18616
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6703 class ultimate_element_type<octave_int<T> >
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6704 {
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6705 public:
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6706 typedef T type;
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6707 };
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6708
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
6709 template <typename T>
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6710 static bool
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6711 convert_data (const T *data, void *conv_data, octave_idx_type n_elts,
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6712 oct_data_conv::data_type output_type,
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
6713 octave::mach_info::float_format flt_fmt)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6714 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6715 bool retval = true;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6716
21776
1e81dd035639 Write integers with correct byte order on big-endian systems (bug #47434)
Mike Miller <mtmiller@octave.org>
parents: 21296
diff changeset
6717 bool swap = false;
1e81dd035639 Write integers with correct byte order on big-endian systems (bug #47434)
Mike Miller <mtmiller@octave.org>
parents: 21296
diff changeset
6718
21777
d6826b38b29c maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
parents: 21751 21776
diff changeset
6719 if (octave::mach_info::words_big_endian ())
d6826b38b29c maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
parents: 21751 21776
diff changeset
6720 swap = (flt_fmt == octave::mach_info::flt_fmt_ieee_little_endian);
21776
1e81dd035639 Write integers with correct byte order on big-endian systems (bug #47434)
Mike Miller <mtmiller@octave.org>
parents: 21296
diff changeset
6721 else
21777
d6826b38b29c maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
parents: 21751 21776
diff changeset
6722 swap = (flt_fmt == octave::mach_info::flt_fmt_ieee_big_endian);
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
6723
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
6724 bool do_float_conversion = flt_fmt != octave::mach_info::float_format ();
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6725
18616
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6726 typedef typename ultimate_element_type<T>::type ult_elt_type;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6727
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6728 switch (output_type)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6729 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6730 case oct_data_conv::dt_char:
18616
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6731 convert_chars<ult_elt_type, char> (data, conv_data, n_elts);
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6732 break;
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6733
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6734 case oct_data_conv::dt_schar:
18616
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6735 convert_chars<ult_elt_type, signed char> (data, conv_data, n_elts);
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6736 break;
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6737
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6738 case oct_data_conv::dt_uchar:
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6739 convert_chars<ult_elt_type, unsigned char> (data, conv_data, n_elts);
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6740 break;
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
6741
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6742 case oct_data_conv::dt_int8:
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6743 convert_ints<T, octave_int8> (data, conv_data, n_elts, swap);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6744 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6745
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6746 case oct_data_conv::dt_uint8:
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6747 convert_ints<T, octave_uint8> (data, conv_data, n_elts, swap);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6748 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6749
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6750 case oct_data_conv::dt_int16:
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6751 convert_ints<T, octave_int16> (data, conv_data, n_elts, swap);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6752 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6753
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6754 case oct_data_conv::dt_uint16:
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6755 convert_ints<T, octave_uint16> (data, conv_data, n_elts, swap);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6756 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6757
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6758 case oct_data_conv::dt_int32:
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6759 convert_ints<T, octave_int32> (data, conv_data, n_elts, swap);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6760 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6761
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6762 case oct_data_conv::dt_uint32:
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6763 convert_ints<T, octave_uint32> (data, conv_data, n_elts, swap);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6764 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6765
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6766 case oct_data_conv::dt_int64:
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6767 convert_ints<T, octave_int64> (data, conv_data, n_elts, swap);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6768 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6769
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6770 case oct_data_conv::dt_uint64:
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6771 convert_ints<T, octave_uint64> (data, conv_data, n_elts, swap);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6772 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6773
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6774 case oct_data_conv::dt_single:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6775 {
19739
3fa35defe495 Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19729
diff changeset
6776 float *vt_data = static_cast<float *> (conv_data);
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6777
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6778 for (octave_idx_type i = 0; i < n_elts; i++)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6779 {
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6780 vt_data[i] = data[i];
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6781
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6782 if (do_float_conversion)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6783 do_float_format_conversion (&vt_data[i], 1, flt_fmt);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6784 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6785 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6786 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6787
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6788 case oct_data_conv::dt_double:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6789 {
19739
3fa35defe495 Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19729
diff changeset
6790 double *vt_data = static_cast<double *> (conv_data);
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6791
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6792 for (octave_idx_type i = 0; i < n_elts; i++)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6793 {
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6794 vt_data[i] = data[i];
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6795
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6796 if (do_float_conversion)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6797 do_double_format_conversion (&vt_data[i], 1, flt_fmt);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6798 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6799 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6800 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6801
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6802 default:
20938
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
6803 ::error ("write: invalid type specification");
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6804 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6805
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6806 return retval;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6807 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6808
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6809 bool
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6810 octave_stream::write_bytes (const void *data, size_t nbytes)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6811 {
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6812 bool status = false;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6813
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6814 std::ostream *osp = output_stream ();
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6815
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6816 if (osp)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6817 {
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6818 std::ostream& os = *osp;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6819
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6820 if (os)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6821 {
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6822 os.write (static_cast<const char *> (data), nbytes);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6823
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6824 if (os)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6825 status = true;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6826 }
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6827 }
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6828
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6829 return status;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6830 }
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6831
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6832 bool
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6833 octave_stream::skip_bytes (size_t skip)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6834 {
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6835 bool status = false;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6836
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6837 std::ostream *osp = output_stream ();
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6838
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6839 if (! osp)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6840 return false;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6841
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6842 std::ostream& os = *osp;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6843
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6844 // Seek to skip when inside bounds of existing file.
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6845 // Otherwise, write NUL to skip.
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6846 off_t orig_pos = tell ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6847
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6848 seek (0, SEEK_END);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6849
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6850 off_t eof_pos = tell ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6851
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6852 // Is it possible for this to fail to return us to the original position?
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6853 seek (orig_pos, SEEK_SET);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6854
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6855 size_t remaining = eof_pos - orig_pos;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6856
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6857 if (remaining < skip)
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6858 {
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6859 seek (0, SEEK_END);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6860
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6861 // FIXME: probably should try to write larger blocks...
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6862 unsigned char zero = 0;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6863 for (size_t j = 0; j < skip - remaining; j++)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6864 os.write (reinterpret_cast<const char *> (&zero), 1);
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6865 }
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6866 else
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6867 seek (skip, SEEK_CUR);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6868
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6869 if (os)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
6870 status = true;
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6871
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6872 return status;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6873 }
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6874
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
6875 template <typename T>
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
6876 octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
6877 octave_stream::write (const Array<T>& data, octave_idx_type block_size,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6878 oct_data_conv::data_type output_type,
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6879 octave_idx_type skip,
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
6880 octave::mach_info::float_format flt_fmt)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6881 {
21776
1e81dd035639 Write integers with correct byte order on big-endian systems (bug #47434)
Mike Miller <mtmiller@octave.org>
parents: 21296
diff changeset
6882 bool swap = false;
1e81dd035639 Write integers with correct byte order on big-endian systems (bug #47434)
Mike Miller <mtmiller@octave.org>
parents: 21296
diff changeset
6883
21777
d6826b38b29c maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
parents: 21751 21776
diff changeset
6884 if (octave::mach_info::words_big_endian ())
d6826b38b29c maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
parents: 21751 21776
diff changeset
6885 swap = (flt_fmt == octave::mach_info::flt_fmt_ieee_little_endian);
21776
1e81dd035639 Write integers with correct byte order on big-endian systems (bug #47434)
Mike Miller <mtmiller@octave.org>
parents: 21296
diff changeset
6886 else
21777
d6826b38b29c maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
parents: 21751 21776
diff changeset
6887 swap = (flt_fmt == octave::mach_info::flt_fmt_ieee_big_endian);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6888
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6889 bool do_data_conversion = (swap || ! is_equivalent_type<T> (output_type)
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
6890 || flt_fmt != octave::mach_info::float_format ());
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6891
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6892 octave_idx_type nel = data.numel ();
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6893
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6894 octave_idx_type chunk_size;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6895
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6896 if (skip != 0)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6897 chunk_size = block_size;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6898 else if (do_data_conversion)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6899 chunk_size = 1024 * 1024;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6900 else
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6901 chunk_size = nel;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6902
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6903 octave_idx_type i = 0;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6904
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6905 const T *pdata = data.data ();
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6906
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6907 while (i < nel)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6908 {
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6909 if (skip != 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6910 {
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6911 if (! skip_bytes (skip))
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6912 return -1;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6913 }
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6914
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6915 octave_idx_type remaining_nel = nel - i;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6916
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6917 if (chunk_size > remaining_nel)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6918 chunk_size = remaining_nel;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6919
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6920 bool status = false;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6921
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6922 if (do_data_conversion)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6923 {
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6924 size_t output_size
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6925 = chunk_size * oct_data_conv::data_type_size (output_type);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6926
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6927 OCTAVE_LOCAL_BUFFER (unsigned char, conv_data, output_size);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6928
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6929 status = convert_data (&pdata[i], conv_data, chunk_size,
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6930 output_type, flt_fmt);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6931
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6932 if (status)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6933 status = write_bytes (conv_data, output_size);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6934 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6935 else
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6936 status = write_bytes (pdata, sizeof (T) * chunk_size);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6937
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6938 if (! status)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6939 return -1;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6940
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6941 i += chunk_size;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6942 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6943
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6944 return nel;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6945 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6946
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
6947 #define INSTANTIATE_WRITE(T) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
6948 template \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
6949 octave_idx_type \
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6950 octave_stream::write (const Array<T>& data, octave_idx_type block_size, \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
6951 oct_data_conv::data_type output_type, \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
6952 octave_idx_type skip, \
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
6953 octave::mach_info::float_format flt_fmt)
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6954
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6955 INSTANTIATE_WRITE (octave_int8);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6956 INSTANTIATE_WRITE (octave_uint8);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6957 INSTANTIATE_WRITE (octave_int16);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6958 INSTANTIATE_WRITE (octave_uint16);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6959 INSTANTIATE_WRITE (octave_int32);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6960 INSTANTIATE_WRITE (octave_uint32);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6961 INSTANTIATE_WRITE (octave_int64);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6962 INSTANTIATE_WRITE (octave_uint64);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6963 INSTANTIATE_WRITE (int8_t);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6964 INSTANTIATE_WRITE (uint8_t);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6965 INSTANTIATE_WRITE (int16_t);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6966 INSTANTIATE_WRITE (uint16_t);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6967 INSTANTIATE_WRITE (int32_t);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6968 INSTANTIATE_WRITE (uint32_t);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6969 INSTANTIATE_WRITE (int64_t);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6970 INSTANTIATE_WRITE (uint64_t);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6971 INSTANTIATE_WRITE (bool);
21354
06d15e4e611a move public data type macros to octave-config.h
John W. Eaton <jwe@octave.org>
parents: 21335
diff changeset
6972 #if defined (OCTAVE_HAVE_OVERLOAD_CHAR_INT8_TYPES)
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6973 INSTANTIATE_WRITE (char);
21235
b48d65c5df5b Disable char/int8_t function overloads where not permitted (bug #45411)
Mike Miller <mtmiller@octave.org>
parents: 20252
diff changeset
6974 #endif
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6975 INSTANTIATE_WRITE (float);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
6976 INSTANTIATE_WRITE (double);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
6977
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6978 octave_value
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
6979 octave_stream::scanf (const std::string& fmt, const Array<double>& size,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6980 octave_idx_type& count, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6981 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6982 octave_value retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6983
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
6984 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
6985 retval = rep->scanf (fmt, size, count, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6986
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6987 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6988 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6989
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
6990 octave_value
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
6991 octave_stream::scanf (const octave_value& fmt, const Array<double>& size,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
6992 octave_idx_type& count, const std::string& who)
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
6993 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
6994 octave_value retval = Matrix ();
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
6995
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
6996 if (fmt.is_string ())
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
6997 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
6998 std::string sfmt = fmt.string_value ();
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
6999
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7000 if (fmt.is_sq_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7001 sfmt = do_string_escapes (sfmt);
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7002
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7003 retval = scanf (sfmt, size, count, who);
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7004 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7005 else
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7006 {
20938
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
7007 // Note: error is member fcn from octave_stream, not ::error.
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7008 error (who + ": format must be a string");
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7009 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7010
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7011 return retval;
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7012 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7013
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
7014 octave_value_list
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
7015 octave_stream::oscanf (const std::string& fmt, const std::string& who)
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
7016 {
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
7017 octave_value_list retval;
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
7018
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
7019 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
7020 retval = rep->oscanf (fmt, who);
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
7021
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
7022 return retval;
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
7023 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
7024
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7025 octave_value_list
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7026 octave_stream::oscanf (const octave_value& fmt, const std::string& who)
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7027 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7028 octave_value_list retval;
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7029
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7030 if (fmt.is_string ())
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7031 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7032 std::string sfmt = fmt.string_value ();
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7033
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7034 if (fmt.is_sq_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7035 sfmt = do_string_escapes (sfmt);
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7036
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7037 retval = oscanf (sfmt, who);
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7038 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7039 else
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7040 {
20938
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
7041 // Note: error is member fcn from octave_stream, not ::error.
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7042 error (who + ": format must be a string");
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7043 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7044
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7045 return retval;
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7046 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7047
21503
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
7048 octave_value
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
7049 octave_stream::textscan (const std::string& fmt, octave_idx_type ntimes,
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
7050 const octave_value_list& options,
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
7051 const std::string& who, octave_idx_type& count)
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
7052 {
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
7053 return (stream_ok ()
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
7054 ? rep->do_textscan (fmt, ntimes, options, who, count)
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
7055 : octave_value ());
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
7056 }
20bf0ec536e2 integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents: 21502
diff changeset
7057
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7058 int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
7059 octave_stream::printf (const std::string& fmt, const octave_value_list& args,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7060 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7061 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7062 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7063
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
7064 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
7065 retval = rep->printf (fmt, args, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7066
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7067 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7068 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7069
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7070 int
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7071 octave_stream::printf (const octave_value& fmt, const octave_value_list& args,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7072 const std::string& who)
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7073 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7074 int retval = 0;
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7075
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7076 if (fmt.is_string ())
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7077 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7078 std::string sfmt = fmt.string_value ();
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7079
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7080 if (fmt.is_sq_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7081 sfmt = do_string_escapes (sfmt);
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7082
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7083 retval = printf (sfmt, args, who);
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7084 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7085 else
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7086 {
20938
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
7087 // Note: error is member fcn from octave_stream, not ::error.
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7088 error (who + ": format must be a string");
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7089 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7090
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7091 return retval;
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7092 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7093
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7094 int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
7095 octave_stream::puts (const std::string& s, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7096 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7097 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7098
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
7099 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
7100 retval = rep->puts (s, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7101
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7102 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7103 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7104
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7105 // FIXME: maybe this should work for string arrays too.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7106
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7107 int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
7108 octave_stream::puts (const octave_value& tc_s, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7109 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7110 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7111
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7112 if (tc_s.is_string ())
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7113 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7114 std::string s = tc_s.string_value ();
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
7115 retval = puts (s, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7116 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7117 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
7118 {
20938
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
7119 // Note: error is member fcn from octave_stream, not ::error.
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
7120 error (who + ": argument must be a string");
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
7121 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7122
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7123 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7124 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7125
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7126 bool
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7127 octave_stream::eof (void) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7128 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7129 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7130
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
7131 if (stream_ok ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7132 retval = rep->eof ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7133
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7134 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7135 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7136
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
7137 std::string
2435
3be97fe02051 [project @ 1996-10-27 21:31:29 by jwe]
jwe
parents: 2341
diff changeset
7138 octave_stream::error (bool clear, int& err_num)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7139 {
5649
d24b97246b9b [project @ 2006-03-08 20:31:25 by jwe]
jwe
parents: 5581
diff changeset
7140 std::string retval = "invalid stream object";
d24b97246b9b [project @ 2006-03-08 20:31:25 by jwe]
jwe
parents: 5581
diff changeset
7141
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
7142 if (stream_ok (false))
2435
3be97fe02051 [project @ 1996-10-27 21:31:29 by jwe]
jwe
parents: 2341
diff changeset
7143 retval = rep->error (clear, err_num);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7144
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7145 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7146 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7147
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
7148 std::string
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
7149 octave_stream::name (void) const
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7150 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
7151 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7152
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
7153 if (stream_ok ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7154 retval = rep->name ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7155
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7156 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7157 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7158
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7159 int
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
7160 octave_stream::mode (void) const
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7161 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7162 int retval = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7163
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
7164 if (stream_ok ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7165 retval = rep->mode ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7166
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7167 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7168 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7169
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
7170 octave::mach_info::float_format
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
7171 octave_stream::float_format (void) const
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7172 {
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
7173 octave::mach_info::float_format retval = octave::mach_info::flt_fmt_unknown;
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 2305
diff changeset
7174
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
7175 if (stream_ok ())
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 2305
diff changeset
7176 retval = rep->float_format ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7177
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7178 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7179 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7180
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
7181 std::string
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7182 octave_stream::mode_as_string (int mode)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7183 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
7184 std::string retval = "???";
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
7185 std::ios::openmode in_mode = static_cast<std::ios::openmode> (mode);
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
7186
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
7187 if (in_mode == std::ios::in)
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
7188 retval = "r";
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7189 else if (in_mode == std::ios::out
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
7190 || in_mode == (std::ios::out | std::ios::trunc))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
7191 retval = "w";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
7192 else if (in_mode == (std::ios::out | std::ios::app))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
7193 retval = "a";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
7194 else if (in_mode == (std::ios::in | std::ios::out))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
7195 retval = "r+";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
7196 else if (in_mode == (std::ios::in | std::ios::out | std::ios::trunc))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
7197 retval = "w+";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
7198 else if (in_mode == (std::ios::in | std::ios::out | std::ios::ate))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
7199 retval = "a+";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
7200 else if (in_mode == (std::ios::in | std::ios::binary))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
7201 retval = "rb";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
7202 else if (in_mode == (std::ios::out | std::ios::binary)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7203 || in_mode == (std::ios::out | std::ios::trunc | std::ios::binary))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
7204 retval = "wb";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
7205 else if (in_mode == (std::ios::out | std::ios::app | std::ios::binary))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
7206 retval = "ab";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
7207 else if (in_mode == (std::ios::in | std::ios::out | std::ios::binary))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
7208 retval = "r+b";
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7209 else if (in_mode == (std::ios::in | std::ios::out | std::ios::trunc
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7210 | std::ios::binary))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
7211 retval = "w+b";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
7212 else if (in_mode == (std::ios::in | std::ios::out | std::ios::ate
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7213 | std::ios::binary))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
7214 retval = "a+b";
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7215
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7216 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7217 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7218
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7219 octave_stream_list *octave_stream_list::instance = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7220
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7221 bool
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7222 octave_stream_list::instance_ok (void)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7223 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7224 bool retval = true;
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7225
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7226 if (! instance)
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
7227 {
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
7228 instance = new octave_stream_list ();
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
7229
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
7230 if (instance)
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
7231 singleton_cleanup_list::add (cleanup_instance);
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
7232 }
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7233
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7234 if (! instance)
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20768
diff changeset
7235 ::error ("unable to create stream list object!");
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7236
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7237 return retval;
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7238 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7239
5353
df230b7df93c [project @ 2005-05-18 02:18:24 by jwe]
jwe
parents: 5338
diff changeset
7240 int
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
7241 octave_stream_list::insert (octave_stream& os)
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7242 {
5353
df230b7df93c [project @ 2005-05-18 02:18:24 by jwe]
jwe
parents: 5338
diff changeset
7243 return (instance_ok ()) ? instance->do_insert (os) : -1;
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7244 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7245
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
7246 octave_stream
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
7247 octave_stream_list::lookup (int fid, const std::string& who)
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7248 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
7249 return (instance_ok ()) ? instance->do_lookup (fid, who) : octave_stream ();
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7250 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7251
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
7252 octave_stream
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
7253 octave_stream_list::lookup (const octave_value& fid, const std::string& who)
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7254 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
7255 return (instance_ok ()) ? instance->do_lookup (fid, who) : octave_stream ();
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7256 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7257
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7258 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
7259 octave_stream_list::remove (int fid, const std::string& who)
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7260 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
7261 return (instance_ok ()) ? instance->do_remove (fid, who) : -1;
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7262 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7263
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7264 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
7265 octave_stream_list::remove (const octave_value& fid, const std::string& who)
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7266 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
7267 return (instance_ok ()) ? instance->do_remove (fid, who) : -1;
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7268 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7269
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7270 void
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
7271 octave_stream_list::clear (bool flush)
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7272 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7273 if (instance)
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
7274 instance->do_clear (flush);
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7275 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7276
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7277 string_vector
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7278 octave_stream_list::get_info (int fid)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7279 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7280 return (instance_ok ()) ? instance->do_get_info (fid) : string_vector ();
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7281 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7282
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7283 string_vector
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7284 octave_stream_list::get_info (const octave_value& fid)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7285 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7286 return (instance_ok ()) ? instance->do_get_info (fid) : string_vector ();
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7287 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7288
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
7289 std::string
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7290 octave_stream_list::list_open_files (void)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7291 {
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20982
diff changeset
7292 return (instance_ok ()) ? instance->do_list_open_files () : "";
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7293 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7294
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7295 octave_value
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7296 octave_stream_list::open_file_numbers (void)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7297 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7298 return (instance_ok ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7299 ? instance->do_open_file_numbers () : octave_value ();
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7300 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7301
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7302 int
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7303 octave_stream_list::get_file_number (const octave_value& fid)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7304 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7305 return (instance_ok ()) ? instance->do_get_file_number (fid) : -1;
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7306 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
7307
5353
df230b7df93c [project @ 2005-05-18 02:18:24 by jwe]
jwe
parents: 5338
diff changeset
7308 int
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
7309 octave_stream_list::do_insert (octave_stream& os)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7310 {
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
7311 // Insert item with key corresponding to file-descriptor.
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
7312
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
7313 int stream_number = os.file_number ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
7314
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
7315 if (stream_number == -1)
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
7316 return stream_number;
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
7317
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
7318 // Should we test for
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
7319 //
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
7320 // (list.find (stream_number) != list.end ()
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
7321 // && list[stream_number].is_open ())
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
7322 //
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
7323 // and respond with "error ("internal error: ...")"? It should not
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
7324 // happen except for some bug or if the user has opened a stream with
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
7325 // an interpreted command, but closed it directly with a system call
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
7326 // in an oct-file; then the kernel knows the fd is free, but Octave
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
7327 // does not know. If it happens, it should not do harm here to simply
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
7328 // overwrite this entry, although the wrong entry might have done harm
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
7329 // before.
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
7330
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7331 if (list.size () >= list.max_size ())
20938
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
7332 ::error ("could not create file id");
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7333
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7334 list[stream_number] = os;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7335
5353
df230b7df93c [project @ 2005-05-18 02:18:24 by jwe]
jwe
parents: 5338
diff changeset
7336 return stream_number;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7337 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7338
21040
3e7cfee5f786 maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents: 21029
diff changeset
7339 OCTAVE_NORETURN static
21029
e3b3bb522d62 maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents: 21017
diff changeset
7340 void
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
7341 err_invalid_file_id (int fid, const std::string& who)
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
7342 {
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
7343 if (who.empty ())
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
7344 ::error ("invalid stream number = %d", fid);
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
7345 else
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
7346 ::error ("%s: invalid stream number = %d", who.c_str (), fid);
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
7347 }
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
7348
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
7349 octave_stream
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
7350 octave_stream_list::do_lookup (int fid, const std::string& who) const
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7351 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
7352 octave_stream retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7353
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7354 if (fid < 0)
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
7355 err_invalid_file_id (fid, who);
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7356
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7357 if (lookup_cache != list.end () && lookup_cache->first == fid)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7358 retval = lookup_cache->second;
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
7359 else
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
7360 {
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7361 ostrl_map::const_iterator iter = list.find (fid);
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7362
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7363 if (iter == list.end ())
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
7364 err_invalid_file_id (fid, who);
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7365
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7366 retval = iter->second;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7367 lookup_cache = iter;
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
7368 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7369
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7370 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7371 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7372
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
7373 octave_stream
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
7374 octave_stream_list::do_lookup (const octave_value& fid,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7375 const std::string& who) const
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7376 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7377 int i = get_file_number (fid);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7378
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
7379 return do_lookup (i, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7380 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7381
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7382 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
7383 octave_stream_list::do_remove (int fid, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7384 {
20764
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7385 // Can't remove stdin (std::cin), stdout (std::cout), or stderr (std::cerr).
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
7386 if (fid < 3)
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
7387 err_invalid_file_id (fid, who);
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7388
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7389 ostrl_map::iterator iter = list.find (fid);
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7390
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7391 if (iter == list.end ())
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
7392 err_invalid_file_id (fid, who);
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7393
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7394 octave_stream os = iter->second;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7395 list.erase (iter);
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7396 lookup_cache = list.end ();
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7397
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7398 // FIXME: is this check redundant?
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7399 if (! os.is_valid ())
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
7400 err_invalid_file_id (fid, who);
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7401
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7402 os.close ();
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7403
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
7404 return 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7405 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7406
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7407 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
7408 octave_stream_list::do_remove (const octave_value& fid, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7409 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7410 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7411
6054
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
7412 if (fid.is_string () && fid.string_value () == "all")
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
7413 {
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
7414 do_clear (false);
6054
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
7415
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
7416 retval = 0;
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
7417 }
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
7418 else
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
7419 {
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
7420 int i = get_file_number (fid);
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
7421
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
7422 retval = do_remove (i, who);
6054
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
7423 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7424
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7425 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7426 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7427
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7428 void
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
7429 octave_stream_list::do_clear (bool flush)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7430 {
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
7431 if (flush)
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
7432 {
20764
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7433 // Flush stdout and stderr.
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
7434 list[1].flush ();
20764
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7435 list[2].flush ();
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
7436 }
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
7437
20764
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7438 for (ostrl_map::iterator iter = list.begin (); iter != list.end (); )
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
7439 {
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
7440 int fid = iter->first;
20764
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7441 if (fid < 3) // Don't delete stdin, stdout, stderr
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7442 {
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7443 iter++;
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7444 continue;
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7445 }
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7446
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
7447 octave_stream os = iter->second;
20768
7655b399abff eliminate trailing whitespace in source files we maintain
John W. Eaton <jwe@octave.org>
parents: 20764
diff changeset
7448
7655b399abff eliminate trailing whitespace in source files we maintain
John W. Eaton <jwe@octave.org>
parents: 20764
diff changeset
7449 std::string name = os.name ();
20764
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7450 std::transform (name.begin (), name.end (), name.begin (), tolower);
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7451
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7452 // FIXME: This test for gnuplot is hardly foolproof.
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7453 if (name.find ("gnuplot") != std::string::npos)
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7454 {
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7455 // Don't close down pipes to gnuplot
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7456 iter++;
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7457 continue;
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7458 }
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7459
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7460 // Normal file handle. Close and delete from list.
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7461 if (os.is_valid ())
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
7462 os.close ();
20764
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7463
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7464 list.erase (iter++);
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
7465 }
20764
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
7466
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
7467 lookup_cache = list.end ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7468 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7469
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7470 string_vector
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7471 octave_stream_list::do_get_info (int fid) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7472 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
7473 octave_stream os = do_lookup (fid);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7474
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20831
diff changeset
7475 if (! os.is_valid ())
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
7476 ::error ("invalid file id = %d", fid);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7477
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20831
diff changeset
7478 string_vector retval (3);
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20831
diff changeset
7479
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20831
diff changeset
7480 retval(0) = os.name ();
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20831
diff changeset
7481 retval(1) = octave_stream::mode_as_string (os.mode ());
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
7482 retval(2) = octave::mach_info::float_format_as_string (os.float_format ());
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20831
diff changeset
7483
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7484 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7485 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7486
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7487 string_vector
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7488 octave_stream_list::do_get_info (const octave_value& fid) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7489 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7490 int conv_err = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7491
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7492 int int_fid = convert_to_valid_int (fid, conv_err);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7493
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
7494 if (conv_err)
2915
649549662cf6 [project @ 1997-04-30 20:51:40 by jwe]
jwe
parents: 2902
diff changeset
7495 ::error ("file id must be a file object or integer value");
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7496
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
7497 return do_get_info (int_fid);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7498 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7499
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
7500 std::string
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7501 octave_stream_list::do_list_open_files (void) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7502 {
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
7503 std::ostringstream buf;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7504
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7505 buf << "\n"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7506 << " number mode arch name\n"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7507 << " ------ ---- ---- ----\n";
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7508
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
7509 for (ostrl_map::const_iterator p = list.begin (); p != list.end (); p++)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7510 {
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
7511 octave_stream os = p->second;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7512
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4312
diff changeset
7513 buf << " "
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7514 << std::setiosflags (std::ios::right)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7515 << std::setw (4) << p->first << " "
19123
c8f03ccdc9ee Align columns for freport() output.
Rik <rik@octave.org>
parents: 18676
diff changeset
7516 // reset necessary in addition to setiosflags since this is one stmt.
c8f03ccdc9ee Align columns for freport() output.
Rik <rik@octave.org>
parents: 18676
diff changeset
7517 << std::resetiosflags (std::ios::adjustfield)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7518 << std::setiosflags (std::ios::left)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7519 << std::setw (3)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7520 << octave_stream::mode_as_string (os.mode ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7521 << " "
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7522 << std::setw (9)
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
7523 << octave::mach_info::float_format_as_string (os.float_format ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7524 << " "
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7525 << os.name () << "\n";
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7526 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7527
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
7528 buf << "\n";
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
7529
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
7530 return buf.str ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7531 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7532
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7533 octave_value
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7534 octave_stream_list::do_open_file_numbers (void) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7535 {
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
7536 Matrix retval (1, list.size (), 0.0);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7537
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7538 int num_open = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7539
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
7540 for (ostrl_map::const_iterator p = list.begin (); p != list.end (); p++)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7541 {
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
7542 // Skip stdin, stdout, and stderr.
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
7543 if (p->first > 2 && p->second)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7544 retval(0,num_open++) = p->first;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7545 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7546
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7547 retval.resize ((num_open > 0), num_open);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7548
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7549 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7550 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7551
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7552 int
2609
12bc9d0a50b5 [project @ 1997-01-18 00:17:36 by jwe]
jwe
parents: 2601
diff changeset
7553 octave_stream_list::do_get_file_number (const octave_value& fid) const
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7554 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7555 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7556
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7557 if (fid.is_string ())
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7558 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
7559 std::string nm = fid.string_value ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7560
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
7561 for (ostrl_map::const_iterator p = list.begin (); p != list.end (); p++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7562 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
7563 // stdin, stdout, and stderr are unnamed.
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7564 if (p->first > 2)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7565 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7566 octave_stream os = p->second;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7567
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7568 if (os && os.name () == nm)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7569 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7570 retval = p->first;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7571 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7572 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7573 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7574 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7575 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7576 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7577 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7578 int conv_err = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7579
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7580 int int_fid = convert_to_valid_int (fid, conv_err);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7581
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7582 if (conv_err)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
7583 ::error ("file id must be a file object, std::string, or integer value");
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
7584
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
7585 retval = int_fid;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7586 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7587
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7588 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7589 }
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
7590