Mercurial > octave
annotate libinterp/corefcn/oct-stream.cc @ 22327:d0562b3159c7
move more classes inside octave namespace
* ov-complex.cc, quit.h, lo-array-errwarn.h, lo-array-errwarn.cc,
lo-array-gripes.cc: Move classes inside octave namespace.
* NEWS, file-editor-tab.cc, Cell.cc, __qp__.cc, cellfun.cc, daspk.cc,
dasrt.cc, dassl.cc, data.cc, error.cc, error.h, errwarn.cc, errwarn.h,
file-io.cc, gcd.cc, graphics.cc, graphics.in.h, gripes.cc, gripes.h,
input.cc, interpreter.cc, interpreter.h, inv.cc, jit-typeinfo.cc,
load-path.cc, ls-mat-ascii.cc, ls-mat5.cc, lsode.cc, mex.cc,
oct-handle.h, oct-map.cc, oct-stream.cc, quad.cc, rand.cc,
sparse-xdiv.cc, sparse-xpow.cc, sparse.cc, sub2ind.cc, toplev.cc,
utils.cc, variables.cc, xdiv.cc, xpow.cc, __eigs__.cc,
__init_gnuplot__.cc, ov-base-diag.cc, ov-base-mat.cc,
ov-base-scalar.cc, ov-base-sparse.cc, ov-base.cc, ov-class.cc,
ov-classdef.cc, ov-complex.h, ov-complex.cc, ov-cx-mat.cc,
ov-cx-sparse.cc, ov-fcn-handle.cc, ov-float.cc, ov-float.h,
ov-flt-complex.h, ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-java.cc,
ov-oncleanup.cc, ov-perm.cc, ov-range.cc, ov-re-diag.cc, ov-re-mat.cc,
ov-re-sparse.cc, ov-scalar.cc, ov-scalar.h, ov-str-mat.cc, ov.cc,
op-cs-cs.cc, op-fcs-fcs.cc, op-fs-fs.cc, op-int.h, op-s-s.cc, ops.h,
oct-parse.in.yy, pt-assign.cc, pt-eval.cc, pt-idx.cc, pt.cc,
Array-util.cc, Array.cc, CColVector.cc, CDiagMatrix.cc, CMatrix.cc,
CNDArray.cc, CRowVector.cc, CSparse.cc, DiagArray2.cc, MDiagArray2.cc,
MSparse.cc, PermMatrix.cc, Range.cc, Sparse.cc, dColVector.cc,
dDiagMatrix.cc, dMatrix.cc, dNDArray.cc, dRowVector.cc, dSparse.cc,
fCColVector.cc, fCDiagMatrix.cc, fCMatrix.cc, fCNDArray.cc,
fCRowVector.cc, fColVector.cc, fDiagMatrix.cc, fMatrix.cc,
fNDArray.cc, fRowVector.cc, idx-vector.cc, quit.cc, quit.h,
gepbalance.cc, Sparse-diag-op-defs.h, Sparse-op-defs.h,
Sparse-perm-op-defs.h, mx-inlines.cc, mx-op-defs.h, cmd-edit.cc,
lo-array-errwarn.cc, lo-array-errwarn.h, lo-array-gripes.cc,
lo-array-gripes.h, oct-binmap.h: Update to use namespace.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 17 Aug 2016 03:41:42 -0400 |
parents | 71dd9d5a5ecd |
children | 34ce5be04942 |
rev | line source |
---|---|
2117 | 1 /* |
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 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2117 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2117 | 21 |
22 */ | |
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 | 26 #endif |
27 | |
3268 | 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 | 30 #include <cstring> |
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 | 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 | 36 #include <sstream> |
3535 | 37 #include <string> |
2117 | 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 | 41 #include "byte-swap.h" |
2117 | 42 #include "lo-ieee.h" |
43 #include "lo-mappers.h" | |
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 | 48 #include "str-vec.h" |
49 | |
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 | 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 | 55 #include "oct-stdstrm.h" |
2117 | 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 | 59 #include "utils.h" |
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 | 71 // Possible values for conv_err: |
72 // | |
73 // 1 : not a real scalar | |
2902 | 74 // 2 : value is NaN |
75 // 3 : value is not an integer | |
2117 | 76 |
77 static int | |
78 convert_to_valid_int (const octave_value& tc, int& conv_err) | |
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 | 82 int retval = 0; |
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 | 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 | 98 { |
5389 | 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 | 108 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
109 conv_err = 2; |
2117 | 110 } |
111 | |
112 return retval; | |
113 } | |
114 | |
115 static int | |
4468 | 116 get_size (double d, const std::string& who) |
2117 | 117 { |
118 int retval = -1; | |
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 | 125 else |
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 | 132 } |
133 | |
134 return retval; | |
135 } | |
136 | |
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 | 140 { |
141 nr = -1; | |
142 nc = -1; | |
143 | |
3268 | 144 one_elt_size_spec = false; |
145 | |
2117 | 146 double dnr = -1.0; |
147 double dnc = -1.0; | |
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 | 150 |
151 if (sz_len == 1) | |
2601 | 152 { |
3268 | 153 one_elt_size_spec = true; |
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 | 156 |
157 dnc = (dnr == 0.0) ? 0.0 : 1.0; | |
2601 | 158 } |
3810 | 159 else if (sz_len == 2) |
2117 | 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 | 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 | 167 } |
168 else | |
4468 | 169 ::error ("%s: invalid size specification", who.c_str ()); |
2117 | 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 | 175 } |
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 | 326 |
3523 | 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 | 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 | 333 |
2215 | 334 int width = 0; |
2117 | 335 bool discard = false; |
336 char modifier = '\0'; | |
337 char type = '\0'; | |
338 | |
339 bool have_more = true; | |
340 | |
341 while (i < n) | |
342 { | |
343 have_more = true; | |
344 | |
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 | 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 | 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 | 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 | 384 |
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 | 390 } |
391 | |
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 | 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 | 397 } |
398 | |
399 scanf_format_list::~scanf_format_list (void) | |
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 | 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 | 406 delete elt; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
407 } |
2117 | 408 } |
409 | |
410 void | |
2215 | 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 | 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 | 428 } |
429 | |
3535 | 430 static std::string |
3523 | 431 expand_char_class (const std::string& s) |
3483 | 432 { |
3523 | 433 std::string retval; |
3483 | 434 |
435 size_t len = s.length (); | |
436 | |
437 size_t i = 0; | |
438 | |
439 while (i < len) | |
440 { | |
441 unsigned char c = s[i++]; | |
442 | |
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 | 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 | 461 } |
462 | |
463 return retval; | |
464 } | |
465 | |
2117 | 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 | 470 { |
2215 | 471 width = 0; |
2117 | 472 discard = false; |
473 modifier = '\0'; | |
474 type = '\0'; | |
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 | 477 |
478 bool have_width = false; | |
479 | |
480 while (i < n) | |
481 { | |
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 | 560 |
561 if (nconv < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
562 break; |
2117 | 563 } |
564 | |
565 nconv = -1; | |
566 } | |
567 | |
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 | 572 { |
573 int retval = 0; | |
574 | |
3523 | 575 std::string char_class; |
3483 | 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 | 579 |
2117 | 580 if (s[i] == '%') |
3640 | 581 { |
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 | 584 } |
2117 | 585 else |
586 { | |
587 type = s[i]; | |
588 | |
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 | 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 | 630 } |
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 | 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 | 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 | 639 } |
640 | |
641 return retval; | |
642 } | |
643 | |
644 void | |
645 scanf_format_list::printme (void) const | |
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 | 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 | 652 |
3531 | 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 | 657 |
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 | 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 | 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 | 664 |
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 | 669 } |
670 } | |
671 | |
672 bool | |
673 scanf_format_list::all_character_conversions (void) | |
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 | 676 |
677 if (n > 0) | |
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 | 695 |
696 return true; | |
697 } | |
698 else | |
699 return false; | |
700 } | |
701 | |
702 bool | |
703 scanf_format_list::all_numeric_conversions (void) | |
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 | 706 |
707 if (n > 0) | |
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 | 724 |
725 return true; | |
726 } | |
727 else | |
728 return false; | |
729 } | |
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 | 868 |
3523 | 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 | 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 | 875 |
876 int args = 0; | |
3643 | 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 | 880 char modifier = '\0'; |
881 char type = '\0'; | |
882 | |
883 bool have_more = true; | |
3640 | 884 bool empty_buf = true; |
2117 | 885 |
4223 | 886 if (n == 0) |
2117 | 887 { |
4223 | 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 | 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 | 892 } |
893 else | |
894 { | |
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 | 943 |
4223 | 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 | 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 | 949 } |
950 } | |
951 | |
952 printf_format_list::~printf_format_list (void) | |
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 | 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 | 959 delete elt; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
960 } |
2117 | 961 } |
962 | |
963 void | |
3640 | 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 | 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 | 981 } |
982 | |
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 | 989 { |
990 args = 0; | |
3640 | 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 | 994 modifier = '\0'; |
995 type = '\0'; | |
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 | 998 |
4587 | 999 bool nxt = false; |
2117 | 1000 |
1001 while (i < n) | |
1002 { | |
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 | 1014 |
4587 | 1015 if (nxt) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1016 break; |
2117 | 1017 } |
1018 | |
1019 if (i < n) | |
1020 { | |
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 | 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 | 1039 } |
1040 | |
1041 if (i < n && s[i] == '.') | |
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 | 1051 |
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 | 1073 } |
1074 | |
1075 if (i < n) | |
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 | 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 | 1090 } |
1091 | |
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 | 1094 else |
1095 nconv = -1; | |
1096 } | |
1097 | |
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 | 1103 { |
1104 switch (s[i]) | |
1105 { | |
1106 case 'd': case 'i': case 'o': case 'x': case 'X': | |
1107 case 'u': case 'c': | |
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 | 1113 goto fini; |
1114 | |
1115 case 'f': case 'e': case 'E': case 'g': case 'G': | |
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 | 1121 goto fini; |
1122 | |
1123 case 's': case 'p': case '%': | |
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 | 1129 goto fini; |
1130 | |
1131 fini: | |
1132 | |
3640 | 1133 type = s[i]; |
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 | 1136 |
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 | 1139 |
1140 if (type != '%') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1141 args++; |
3640 | 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 | 1144 |
2117 | 1145 break; |
1146 | |
1147 default: | |
1148 nconv = -1; | |
1149 break; | |
1150 } | |
1151 } | |
1152 | |
1153 void | |
1154 printf_format_list::printme (void) const | |
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 | 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 | 1161 |
3640 | 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 | 1170 } |
1171 } | |
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 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1618 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1619 whitespace_conversion = 1, |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1620 literal_conversion = 2 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1621 }; |
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 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2063 = new textscan_format_elt (text, width, prec, bitwidth, discard, type, char_class); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2064 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2065 if (! discard) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2066 output_container.push_back (val_type); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2067 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2068 fmt_elts.push_back (elt); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2069 } |
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 buf.clear (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2072 buf.str (""); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2073 } |
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 void |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2076 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
|
2077 size_t n) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2078 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2079 unsigned width = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2080 int prec = -1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2081 int bitwidth = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2082 bool discard = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2083 octave_value val_type; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2084 char type = '\0'; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2085 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2086 buf << s[i++]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2087 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2088 bool have_width = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2089 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2090 while (i < n) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2091 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2092 switch (s[i]) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2093 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2094 case '*': |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2095 if (discard) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2096 nconv = -1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2097 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2098 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2099 discard = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2100 buf << s[i++]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2101 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2102 break; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2103 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2104 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
|
2105 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
|
2106 if (have_width) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2107 nconv = -1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2108 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2109 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2110 char c = s[i++]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2111 width = width * 10 + c - '0'; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2112 have_width = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2113 buf << c; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2114 while (i < n && isdigit (s[i])) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2115 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2116 c = s[i++]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2117 width = width * 10 + c - '0'; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2118 buf << c; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2119 } |
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 if (i < n && s[i] == '.') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2122 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2123 buf << s[i++]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2124 prec = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2125 while (i < n && isdigit (s[i])) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2126 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2127 c = s[i++]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2128 prec = prec * 10 + c - '0'; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2129 buf << c; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2130 } |
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 break; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2134 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2135 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
|
2136 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2137 bool done = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2138 buf << (type = s[i++]); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2139 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
|
2140 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2141 if (s[i] == '8') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2142 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2143 bitwidth = 8; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2144 if (type == 'd') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2145 val_type = octave_value (int8NDArray ()); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2146 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2147 val_type = octave_value (uint8NDArray ()); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2148 buf << s[i++]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2149 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2150 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
|
2151 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2152 bitwidth = 16; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2153 if (type == 'd') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2154 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
|
2155 else |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2156 val_type = octave_value (uint16NDArray ()); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2157 buf << s[i++]; |
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 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2160 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
|
2161 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2162 done = false; // use default size below |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2163 buf << s[i++]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2164 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
|
2165 } |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2166 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
|
2167 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2168 bitwidth = 64; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2169 if (type == 'd') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2170 val_type = octave_value (int64NDArray ()); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2171 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2172 val_type = octave_value (uint64NDArray ()); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2173 buf << s[i++]; |
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 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2176 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2177 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
|
2178 } |
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 else |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2180 done = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2181 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2182 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
|
2183 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2184 bitwidth = 32; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2185 if (type == 'd') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2186 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
|
2187 else |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2188 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
|
2189 } |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2190 goto fini; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2191 } |
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 case 'f': |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2194 buf << (type = s[i++]); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2195 bitwidth = 64; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2196 if (i < n) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2197 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2198 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
|
2199 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2200 bitwidth = 32; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2201 val_type = octave_value (FloatNDArray ()); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2202 buf << s[i++]; |
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 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2205 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
|
2206 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2207 val_type = octave_value (NDArray ()); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2208 buf << s[i++]; |
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 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2211 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2212 val_type = octave_value (NDArray ()); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2213 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2214 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2215 val_type = octave_value (NDArray ()); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2216 goto fini; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2217 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2218 case 'n': |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2219 buf << (type = s[i++]); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2220 bitwidth = 64; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2221 val_type = octave_value (NDArray ()); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2222 goto fini; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2223 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2224 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
|
2225 if (! discard) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2226 val_type = octave_value (Cell ()); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2227 buf << (type = s[i++]); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2228 has_string = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2229 goto fini; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2230 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2231 fini: |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2232 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2233 if (! have_width) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2234 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2235 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
|
2236 width = 1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2237 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2238 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
|
2239 } |
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 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
|
2242 discard, type) == 0) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2243 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
|
2244 } |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2245 break; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2246 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2247 default: |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2248 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
|
2249 who.c_str (), s[i]); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2250 } |
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 if (nconv < 0) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2253 break; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2254 } |
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 nconv = -1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2257 } |
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 // Parse [...] and [^...] |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2260 // |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2261 // 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
|
2262 // 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
|
2263 // 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
|
2264 // 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
|
2265 // pattern. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2266 // |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2267 // 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
|
2268 // 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
|
2269 // The latter is efficient for [^...] patterns. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2270 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2271 std::string |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2272 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
|
2273 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2274 int len = pattern.length (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2275 if (len == 0) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2276 return ""; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2277 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2278 std::string retval (256, '\0'); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2279 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
|
2280 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2281 int in = 0, out = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2282 unsigned char ch, prev = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2283 bool flip = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2284 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2285 ch = pattern[in]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2286 if (ch == '^') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2287 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2288 in++; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2289 flip = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2290 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2291 mask[pattern[in]] = '\1'; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2292 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
|
2293 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2294 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
|
2295 bool prev_prev_was_range = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2296 for (; in < len; in++) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2297 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2298 bool was_range = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2299 ch = pattern[in]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2300 if (ch == ']') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2301 break; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2302 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2303 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
|
2304 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2305 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
|
2306 if (start_of_range < ch |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2307 && ((isupper (ch) && isupper (start_of_range)) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2308 || (islower (ch) && islower (start_of_range)) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2309 || (isdigit (ch) && isdigit (start_of_range)) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2310 || 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
|
2311 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2312 was_range = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2313 out--; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2314 mask['-']--; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2315 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
|
2316 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2317 if (mask[i] == '\0') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2318 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2319 mask[i] = '\1'; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2320 retval[out++] = i; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2321 } |
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 if (! was_range) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2326 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2327 if (mask[ch]++ == 0) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2328 retval[out++] = ch; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2329 else if (ch != '-') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2330 warning_with_id ("octave:textscan-pattern", |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2331 "%s: [...] contains two '%c's", |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2332 who.c_str (), ch); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2333 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2334 if (prev == '-' && mask['-'] >= 2) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2335 warning_with_id |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2336 ("octave:textscan-pattern", |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2337 "%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
|
2338 who.c_str ()); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2339 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2340 prev = ch; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2341 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
|
2342 prev_was_range = was_range; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2343 } |
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 if (flip) // [^...] |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2346 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2347 out = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2348 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
|
2349 if (! mask[i]) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2350 retval[out++] = i; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2351 } |
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 retval.resize (out); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2354 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2355 return retval; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2356 } |
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 int |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2359 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
|
2360 size_t n, unsigned int& width, |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2361 int& prec, int& bitwidth, |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2362 octave_value& val_type, bool discard, |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2363 char& type) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2364 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2365 int retval = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2366 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2367 std::string char_class; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2368 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2369 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
|
2370 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
|
2371 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2372 if (type != '%') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2373 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2374 nconv++; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2375 if (type == '[') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2376 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2377 if (i < n) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2378 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2379 beg_idx = i; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2380 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2381 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
|
2382 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2383 type = '^'; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2384 buf << s[i++]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2385 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2386 if (i < n) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2387 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2388 beg_idx = i; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2389 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2390 if (s[i] == ']') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2391 buf << s[i++]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2392 } |
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
|
2393 } |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2394 else if (s[i] == ']') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2395 buf << s[i++]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2396 } |
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 while (i < n && s[i] != ']') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2399 buf << s[i++]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2400 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2401 if (i < n && s[i] == ']') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2402 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2403 end_idx = i-1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2404 buf << s[i++]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2405 } |
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 if (s[i-1] != ']') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2408 retval = nconv = -1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2409 } |
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 if (nconv >= 0) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2413 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2414 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
|
2415 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
|
2416 end_idx - beg_idx + 1)); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2417 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2418 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
|
2419 char_class); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2420 } |
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 return retval; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2423 } |
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 void |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2426 textscan_format_list::printme (void) const |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2427 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2428 size_t n = numel (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2429 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2430 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
|
2431 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2432 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
|
2433 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2434 std::cerr |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2435 << "width: " << elt->width << "\n" |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2436 << "digits " << elt->prec << "\n" |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2437 << "bitwidth: " << elt->bitwidth << "\n" |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2438 << "discard: " << elt->discard << "\n" |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2439 << "type: "; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2440 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2441 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
|
2442 std::cerr << "literal text\n"; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2443 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
|
2444 std::cerr << "whitespace\n"; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2445 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2446 std::cerr << elt->type << "\n"; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2447 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2448 std::cerr |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2449 << "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
|
2450 << "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
|
2451 } |
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 // 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
|
2455 // 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
|
2456 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2457 int |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2458 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
|
2459 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2460 // 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
|
2461 std::string first_line (20, ' '); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2462 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2463 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
|
2464 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2465 if (! first_line.empty () |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2466 && 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
|
2467 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
|
2468 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2469 std::istringstream strstr (first_line); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2470 delimited_stream ds (strstr, is); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2471 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2472 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
|
2473 Complex val; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2474 octave_value val_type; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2475 nconv = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2476 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
|
2477 int retval = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2478 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2479 // 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
|
2480 while (! ds.eof ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2481 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2482 bool already_skipped_delim = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2483 ts.skip_whitespace (ds); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2484 ds.progress_benchmark (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2485 bool progress = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2486 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
|
2487 if (ds.fail ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2488 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2489 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
|
2490 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2491 if (ds.eof ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2492 break; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2493 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2494 // 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
|
2495 // return with an error status. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2496 ts.skip_delim (ds); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2497 if (ds.no_progress ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2498 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2499 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
|
2500 break; |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2501 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2502 already_skipped_delim = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2503 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2504 val = ts.empty_value.scalar_value (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2505 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2506 if (! --max_empty) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2507 break; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2508 } |
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 if (val.imag () == 0) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2511 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
|
2512 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2513 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
|
2514 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2515 output_container.push_back (val_type); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2516 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2517 if (! already_skipped_delim) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2518 ts.skip_delim (ds); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2519 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2520 if (! progress && ds.no_progress ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2521 break; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2522 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2523 nconv++; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2524 } |
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 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
|
2527 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2528 // 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
|
2529 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
|
2530 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
|
2531 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2532 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
|
2533 } |
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 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
|
2536 : 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
|
2537 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
|
2538 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
|
2539 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
|
2540 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
|
2541 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
|
2542 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
|
2543 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
|
2544 numeric_delim (false), lines (0) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2545 { } |
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 octave_value |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2548 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
|
2549 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
|
2550 octave_idx_type& count) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2551 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2552 textscan_format_list fmt_list (fmt); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2553 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2554 parse_options (options, fmt_list); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2555 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2556 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
|
2557 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2558 // 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
|
2559 // 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
|
2560 // 32-bit indexing. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2561 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2562 std::ios::iostate state = isp.rdstate (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2563 isp.clear (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2564 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
|
2565 isp.setstate (state); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2566 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2567 return result; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2568 } |
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 octave_value |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2571 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
|
2572 octave_idx_type ntimes) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2573 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2574 octave_value retval; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2575 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2576 if (fmt_list.num_conversions () == -1) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2577 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
|
2578 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2579 if (fmt_list.num_conversions () == 0) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2580 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
|
2581 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2582 // skip the first header_lines |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2583 std::string dummy; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2584 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
|
2585 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
|
2586 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2587 // 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
|
2588 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2589 // 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
|
2590 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
|
2591 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
|
2592 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2593 // 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
|
2594 octave_idx_type buf_size = 4096; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2595 if (buffer_size) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2596 buf_size = buffer_size; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2597 else if (ntimes > 0) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2598 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2599 // Avoid overflow of 80*ntimes... |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2600 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
|
2601 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
|
2602 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2603 // Finally, create the stream. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2604 delimited_stream is (isp, |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2605 (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
|
2606 max_lookahead, buf_size); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2607 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2608 // 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
|
2609 // (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
|
2610 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
|
2611 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
|
2612 row_idx(1) = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2613 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2614 int err = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2615 octave_idx_type row = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2616 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2617 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
|
2618 skip_delim (is); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2619 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2620 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
|
2621 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2622 // 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
|
2623 if (fmt_list.set_from_first) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2624 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2625 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
|
2626 lines = 1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2627 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2628 done_after = fmt_list.numel () + 1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2629 if (! err) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2630 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
|
2631 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2632 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2633 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
|
2634 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2635 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
|
2636 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2637 // 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
|
2638 // Check now which columns to merge. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2639 // 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
|
2640 // after reading in data. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2641 // 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
|
2642 // 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
|
2643 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
|
2644 int conv = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2645 if (collect_output) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2646 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2647 int prev_type = -1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2648 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
|
2649 col != out.end (); col++) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2650 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2651 if (col->type_id () == prev_type |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2652 || (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
|
2653 merge_with_prev [conv++] = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2654 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2655 merge_with_prev [conv++] = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2656 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2657 prev_type = col->type_id (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2658 } |
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 // 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
|
2662 // infinite loop below. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2663 if (fmt_list.num_conversions () == 0) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2664 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
|
2665 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2666 // 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
|
2667 if (! err) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2668 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2669 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
|
2670 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2671 if (row == 0 || row >= size) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2672 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2673 size += size+1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2674 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
|
2675 col != out.end (); col++) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2676 *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
|
2677 } |
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 row_idx(0) = row; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2680 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
|
2681 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2682 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
|
2683 break; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2684 } |
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 if ((err & 4) && ! return_on_error) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2688 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
|
2689 done_after + 1, row + 1); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2690 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2691 // 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
|
2692 bool uneven_columns = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2693 if (err & 4) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2694 uneven_columns = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2695 else if (isp.eof ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2696 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2697 isp.clear (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2698 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
|
2699 int last_char = isp.get (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2700 isp.setstate (isp.eofbit); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2701 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
|
2702 } |
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 // convert return value to Cell array |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2705 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
|
2706 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2707 // (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
|
2708 // 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
|
2709 if (err & 1) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2710 done_after = out.size () + 1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2711 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2712 int valid_rows = (row == ntimes) ? ntimes |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2713 : (((err & 1) && (err & 8)) ? row : row+1); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2714 dim_vector dv (valid_rows, 1); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2715 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2716 ra_idx(0) = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2717 int i = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2718 if (! collect_output) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2719 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2720 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
|
2721 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
|
2722 col != out.end (); col++, i++) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2723 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2724 // 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
|
2725 if (i == done_after && uneven_columns) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2726 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
|
2727 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2728 ra_idx(1) = i; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2729 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
|
2730 ra_idx); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2731 } |
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 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
|
2734 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2735 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
|
2736 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
|
2737 int prev_type = -1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2738 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2739 conv = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2740 retval = Cell (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2741 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
|
2742 col != out.end (); col++) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2743 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2744 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
|
2745 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2746 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
|
2747 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2748 ra_idx(1) = i++; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2749 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
|
2750 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
|
2751 } |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2752 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
|
2753 group_size = 1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2754 prev_type = col->type_id (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2755 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2756 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2757 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2758 ra_idx(1) = group_size++; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2759 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
|
2760 ra_idx); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2761 } |
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 ra_idx(1) = i; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2764 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
|
2765 } |
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 return retval; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2768 } |
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 // 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
|
2771 // EXP_CHARS option of OPTIONS. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2772 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2773 double |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2774 textscan::read_double (delimited_stream& is, |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2775 const textscan_format_elt& fmt) const |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2776 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2777 int sign = 1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2778 unsigned int width_left = fmt.width; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2779 double retval = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2780 bool valid = false; // syntactically correct double? |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2781 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2782 int ch = is.peek (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2783 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2784 if (ch == '+') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2785 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2786 is.get (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2787 ch = is.peek (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2788 if (width_left) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2789 width_left--; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2790 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2791 else if (ch == '-') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2792 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2793 sign = -1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2794 is.get (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2795 ch = is.peek (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2796 if (width_left) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2797 width_left--; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2798 } |
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 // Read integer part |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2801 if (ch != '.') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2802 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2803 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
|
2804 valid = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2805 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
|
2806 retval = retval * 10 + (ch - '0'); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2807 width_left++; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2808 } |
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 // 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
|
2811 if (ch == '.' && width_left) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2812 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2813 double multiplier = 1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2814 int precision = fmt.prec; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2815 int i; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2816 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2817 if (width_left) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2818 width_left--; // Consider width of '.' |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2819 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2820 if (precision == -1) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2821 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
|
2822 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2823 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
|
2824 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
|
2825 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2826 for (i = 0; i < precision; i++) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2827 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2828 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
|
2829 retval += (ch - '0') * (multiplier *= 0.1); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2830 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2831 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2832 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
|
2833 break; |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2834 } |
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 // 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
|
2838 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
|
2839 && ch <= '9') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2840 retval += multiplier; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2841 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2842 if (i > 0) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2843 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
|
2844 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2845 // 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
|
2846 if (i == precision) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2847 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
|
2848 ; // discard |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2849 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2850 width_left++; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2851 } |
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 // 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
|
2854 bool used_exp = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2855 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
|
2856 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2857 int ch1 = is.peek (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2858 if (ch1 == '-' || ch1 == '+' || (ch1 >= '0' && ch1 <= '9')) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2859 { // if 1.0e+$ or some such, this will set failbit, as we want |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2860 width_left--; // count "E" |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2861 int exp = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2862 int exp_sign = 1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2863 if (ch1 == '+') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2864 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2865 if (width_left) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2866 width_left--; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2867 is.get (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2868 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2869 else if (ch1 == '-') |
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 exp_sign = -1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2872 is.get (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2873 if (width_left) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2874 width_left--; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2875 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2876 valid = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2877 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
|
2878 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2879 exp = exp*10 + ch - '0'; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2880 valid = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2881 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2882 width_left++; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2883 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
|
2884 is.putback (ch); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2885 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2886 double multiplier = pown (10, exp); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2887 if (exp_sign > 0) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2888 retval *= multiplier; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2889 else |
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 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2892 used_exp = true; |
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 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2895 is.clear (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2896 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
|
2897 is.putback (ch); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2898 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2899 // Check for +/- inf and NaN |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2900 if (! valid && width_left >= 3) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2901 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2902 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
|
2903 if (i == 0) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2904 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2905 retval = octave::numeric_limits<double>::Inf (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2906 valid = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2907 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2908 else if (i == 1) |
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 retval = octave::numeric_limits<double>::NaN (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2911 valid = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2912 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2913 } |
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 // Check for +/- inf and NaN |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2916 if (! valid && width_left >= 3) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2917 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2918 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
|
2919 if (i == 0) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2920 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2921 retval = octave::numeric_limits<double>::Inf (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2922 valid = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2923 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2924 else if (i == 1) |
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 retval = octave::numeric_limits<double>::NaN (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2927 valid = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2928 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2929 } |
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 if (! valid) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2932 is.setstate (std::ios::failbit); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2933 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2934 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
|
2935 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2936 return retval * sign; |
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 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2939 // 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
|
2940 // 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
|
2941 // 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
|
2942 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2943 void |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2944 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
|
2945 Complex& val) const |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2946 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2947 double im = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2948 double re = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2949 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
|
2950 bool inf = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2951 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2952 int ch = is.peek (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2953 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
|
2954 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2955 ch = is.get (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2956 int ch2 = is.peek (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2957 if (ch2 == 'i' || ch2 == 'j') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2958 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2959 double value = 1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2960 is.get (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2961 // Check not -inf |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2962 if (is.peek () == 'n') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2963 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2964 char *pos = is.tellg (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2965 std::ios::iostate state = is.rdstate (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2966 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2967 is.get (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2968 ch2 = is.get (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2969 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
|
2970 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2971 inf = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2972 re = (ch == '+') ? octave::numeric_limits<double>::Inf () : -octave::numeric_limits<double>::Inf (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2973 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
|
2974 } |
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
|
2975 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
|
2976 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2977 is.clear (state); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2978 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
|
2979 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2980 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2981 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2982 im = (ch == '+') ? value : -value; |
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 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2985 is.putback (ch); |
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 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2988 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
|
2989 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2990 char *pos = is.tellg (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2991 std::ios::iostate state = is.rdstate (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2992 //re = octave_read_value<double> (is); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2993 re = read_double (is, fmt); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2994 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2995 // check for "treat as empty" string |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2996 if (treat_as_empty.numel () |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2997 && (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
|
2998 || re == octave::numeric_limits<double>::Inf ())) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2999 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3000 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3001 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
|
3002 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3003 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
|
3004 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3005 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
|
3006 break; |
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 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3009 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
|
3010 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3011 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
|
3012 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3013 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
|
3014 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
|
3015 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3016 // 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
|
3017 // 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
|
3018 // that matches. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3019 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
|
3020 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
|
3021 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3022 is.clear (state); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3023 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
|
3024 // FIXME: is.read could invalidate pos |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3025 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3026 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
|
3027 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3028 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
|
3029 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
|
3030 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3031 as_empty = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3032 // read just the right amount |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3033 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
|
3034 break; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3035 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3036 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3037 } |
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 if (! is.eof () && ! as_empty) |
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 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
|
3043 pos = is.tellg (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3044 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
|
3045 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
|
3046 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3047 is.get (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3048 im = re; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3049 re = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3050 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3051 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
|
3052 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3053 // 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
|
3054 pos = is.tellg (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3055 state = is.rdstate (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3056 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3057 //im = octave_read_value<double> (is); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3058 im = read_double (is, fmt); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3059 if (is.fail ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3060 im = 1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3061 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3062 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
|
3063 is.get (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3064 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3065 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3066 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
|
3067 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
|
3068 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
|
3069 } |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3070 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3071 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
|
3072 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
|
3073 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3074 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3075 if (as_empty) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3076 val = empty_value.scalar_value (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3077 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3078 val = Complex (re, im); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3079 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3080 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3081 // 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
|
3082 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3083 int |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3084 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
|
3085 std::string& val) const |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3086 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3087 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
|
3088 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
|
3089 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3090 while (is && ((c1 = (is && ! is.eof ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3091 ? is.get_undelim () |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3092 : std::istream::traits_type::eof ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3093 != std::istream::traits_type::eof ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3094 && pattern.find (c1) == std::string::npos) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3095 obuf << static_cast<char> (c1); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3096 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3097 val = obuf.str (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3098 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3099 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
|
3100 is.putback (c1); |
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 return c1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3103 } |
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 // 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
|
3106 // 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
|
3107 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3108 std::string |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3109 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
|
3110 const std::string& ends) const |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3111 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3112 std::string retval (""); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3113 bool done = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3114 do |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3115 { // find sequence ending with an ending char |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3116 std::string next; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3117 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
|
3118 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
|
3119 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3120 int last = (! is.eof () |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3121 ? 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
|
3122 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3123 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
|
3124 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3125 retval = retval + static_cast<char> (last); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3126 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
|
3127 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3128 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
|
3129 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
|
3130 ? retval.length () - delim.length () |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3131 : 0); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3132 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
|
3133 if (may_match == delim) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3134 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3135 done = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3136 retval = retval.substr (0, start); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3137 break; |
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 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3140 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3141 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3142 while (! done && is && ! is.eof ()); |
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 return retval; |
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 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3147 // 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
|
3148 // 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
|
3149 // 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
|
3150 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3151 void |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3152 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
|
3153 std::string& val) const |
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 if (delim_list.is_empty ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3156 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3157 unsigned int i = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3158 unsigned int width = fmt.width; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3159 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3160 for (i = 0; i < width; i++) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3161 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3162 if (i+1 > val.length ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3163 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
|
3164 int ch = is.get (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3165 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
|
3166 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3167 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
|
3168 break; |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3169 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3170 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3171 val[i] = ch; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3172 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3173 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
|
3174 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3175 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
|
3176 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3177 std::string ends (""); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3178 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
|
3179 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3180 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
|
3181 ends += tmp.substr (tmp.length () - 1); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3182 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3183 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
|
3184 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3185 } |
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 // 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
|
3188 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3189 int |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3190 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
|
3191 std::string& val) const |
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 c1 = std::istream::traits_type::eof (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3194 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
|
3195 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3196 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
|
3197 obuf << static_cast<char> (c1); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3198 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3199 val = obuf.str (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3200 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
|
3201 is.putback (c1); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3202 return c1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3203 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3204 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3205 // 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
|
3206 // 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
|
3207 // 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
|
3208 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3209 void |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3210 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
|
3211 std::string& val) |
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 skip_whitespace (is); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3214 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3215 if (is.peek () != '\"') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3216 scan_string (is, fmt, val); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3217 else |
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 is.get (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3220 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
|
3221 is.get (); // swallow " |
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 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
|
3224 { // and keep looking for single " |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3225 is.get (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3226 std::string val1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3227 scan_caret (is, "\"", val1); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3228 val = val + "\"" + val1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3229 is.get_undelim (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3230 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3231 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3232 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3233 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3234 // 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
|
3235 // including any whitespace or delimiters. |
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 void |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3238 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
|
3239 std::string& val) const |
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 val.resize (fmt.width); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3242 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3243 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
|
3244 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3245 int ch = is.get_undelim (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3246 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
|
3247 val[i] = ch; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3248 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3249 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3250 val.resize (i); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3251 break; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3252 } |
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 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3255 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3256 // 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
|
3257 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3258 void |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3259 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
|
3260 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
|
3261 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3262 skip_whitespace (is); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3263 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3264 is.clear (); |
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 octave_value val; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3267 if (fmt.numeric) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3268 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3269 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
|
3270 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3271 Complex v; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3272 skip_whitespace (is); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3273 scan_complex (is, fmt, v); |
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 if (! fmt.discard && ! is.fail ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3276 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3277 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
|
3278 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3279 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
|
3280 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
|
3281 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3282 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3283 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
|
3284 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
|
3285 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3286 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
|
3287 } |
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
|
3288 } |
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
|
3289 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
|
3290 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3291 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
|
3292 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
|
3293 float (v.real ())); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3294 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3295 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3296 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
|
3297 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
|
3298 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3299 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
|
3300 FloatComplex (v)); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3301 } |
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
|
3302 } |
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
|
3303 } |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3304 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3305 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3306 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3307 double v; // Matlab docs say 1e30 etc should be valid for %d and |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3308 // 1000 as a %d8 should be 127, so read as double. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3309 // Some loss of precision for d64 and u64. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3310 skip_whitespace (is); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3311 v = read_double (is, fmt); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3312 if (! fmt.discard && ! is.fail ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3313 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
|
3314 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3315 case 64: |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3316 switch (fmt.type) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3317 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3318 case 'd': |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3319 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3320 octave_int64 vv = v; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3321 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
|
3322 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3323 break; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3324 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3325 case 'u': |
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 octave_uint64 vv = v; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3328 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
|
3329 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3330 break; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3331 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3332 break; |
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 case 32: |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3335 switch (fmt.type) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3336 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3337 case 'd': |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3338 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3339 octave_int32 vv = v; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3340 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
|
3341 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3342 break; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3343 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3344 case 'u': |
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 octave_uint32 vv = v; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3347 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
|
3348 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3349 break; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3350 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3351 break; |
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 case 16: |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3354 if (fmt.type == 'd') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3355 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3356 octave_int16 vv = v; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3357 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
|
3358 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3359 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3360 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3361 octave_uint16 vv = v; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3362 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
|
3363 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3364 break; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3365 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3366 case 8: |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3367 if (fmt.type == 'd') |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3368 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3369 octave_int8 vv = v; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3370 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
|
3371 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3372 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3373 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3374 octave_uint8 vv = v; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3375 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
|
3376 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3377 break; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3378 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3379 } |
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 if (is.fail () & ! fmt.discard) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3382 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
|
3383 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3384 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3385 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3386 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
|
3387 switch (fmt.type) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3388 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3389 case 's': |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3390 scan_string (is, fmt, vv); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3391 break; |
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 'q': |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3394 scan_qstring (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 'c': |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3398 scan_cstring (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 '[': |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3402 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
|
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_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
|
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 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3410 if (! fmt.discard) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3411 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
|
3412 Cell (octave_value (vv))); |
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 // 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
|
3415 if (! vv.empty ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3416 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
|
3417 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3418 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3419 is.field_done (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3420 } |
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 // 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
|
3423 // values in row ROW of retval. |
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 int |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3426 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
|
3427 textscan_format_list& fmt_list, |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3428 std::list<octave_value>& retval, |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3429 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
|
3430 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3431 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
|
3432 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
|
3433 bool no_conversions = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3434 bool done = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3435 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
|
3436 bool nothing_worked = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3437 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3438 octave_quit (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3439 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3440 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
|
3441 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3442 bool this_conversion_failed = false; |
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 // Clear fail of previous numeric conversions. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3445 is.clear (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3446 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3447 switch (elem->type) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3448 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3449 case 'C': |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3450 case 'D': |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3451 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
|
3452 who.c_str (), elem->type); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3453 break; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3454 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3455 case 'u': |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3456 case 'd': |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3457 case 'f': |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3458 case 'n': |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3459 case 's': |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3460 case '[': |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3461 case '^': |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3462 case 'q': |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3463 case 'c': |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3464 scan_one (is, *elem, *out, row); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3465 break; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3466 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3467 case textscan_format_elt::literal_conversion : |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3468 match_literal (is, *elem); |
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 default: |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3472 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
|
3473 } |
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 if (! is.fail ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3476 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3477 if (! elem->discard) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3478 no_conversions = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3479 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3480 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3481 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3482 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
|
3483 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3484 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
|
3485 this_conversion_failed = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3486 } |
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 (! elem->discard) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3489 out++; |
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 elem = fmt_list.next (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3492 char *pos = is.tellg (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3493 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3494 // 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
|
3495 // 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
|
3496 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
|
3497 // && elem->type != '[' && elem->type != '^' && elem->type != 'c' |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3498 ) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3499 skip_delim (is); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3500 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3501 if (is.eof ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3502 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3503 if (! done) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3504 done_after = i+1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3505 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3506 // 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
|
3507 done = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3508 } |
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 if (this_conversion_failed) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3511 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3512 if (is.tellg () == pos && ! conversion_failed) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3513 { // done_after = first failure |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3514 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
|
3515 conversion_failed = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3516 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3517 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3518 this_conversion_failed = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3519 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3520 else if (! done && !conversion_failed) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3521 nothing_worked = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3522 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3523 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3524 if (done) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3525 is.setstate (std::ios::eofbit); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3526 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3527 return no_conversions + (is.eof () ? 2 : 0) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3528 + (conversion_failed ? 4 : 0) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3529 + (nothing_worked ? 8 : 0); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3530 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3531 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3532 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3533 void |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3534 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
|
3535 textscan_format_list& fmt_list) |
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 int last = args.length (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3538 int n = last; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3539 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3540 if (n & 1) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3541 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
|
3542 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
|
3543 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3544 delim_len = 1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3545 bool have_delims = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3546 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
|
3547 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3548 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
|
3549 who.c_str (), |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3550 args(i).type_name ().c_str (), |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3551 i/2 + 1); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3552 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
|
3553 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3554 if (param == "delimiter") |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3555 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3556 bool invalid = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3557 if (args(i+1).is_string ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3558 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3559 invalid = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3560 have_delims = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3561 delims = args(i+1).string_value (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3562 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
|
3563 delims = do_string_escapes (delims); |
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 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
|
3566 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3567 invalid = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3568 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
|
3569 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
|
3570 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3571 // 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
|
3572 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
|
3573 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3574 if (! delim_list(j).is_string ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3575 invalid = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3576 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3577 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3578 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
|
3579 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
|
3580 .string_value ()); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3581 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
|
3582 .length (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3583 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
|
3584 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3585 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3586 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3587 if (invalid) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3588 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
|
3589 who.c_str ()); |
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 else if (param == "commentstyle") |
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 (args(i+1).is_string ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3594 { // check here for names like "C++", "C", "shell", ...? |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3595 comment_style = Cell (args(i+1)); |
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 (args(i+1).is_cell ()) |
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 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
|
3600 int len = comment_style.numel (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3601 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
|
3602 || (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
|
3603 || (len >= 3)) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3604 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
|
3605 who.c_str ()); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3606 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3607 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3608 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
|
3609 who.c_str ()); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3610 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3611 // 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
|
3612 // 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
|
3613 if (comment_style.numel () >= 1) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3614 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3615 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
|
3616 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
|
3617 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3618 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3619 else if (param == "treatasempty") |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3620 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3621 bool invalid = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3622 if (args(i+1).is_string ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3623 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3624 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
|
3625 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
|
3626 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3627 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
|
3628 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3629 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
|
3630 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
|
3631 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
|
3632 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
|
3633 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
|
3634 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3635 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
|
3636 if (k > treat_as_empty_len) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3637 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
|
3638 } |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3639 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3640 if (invalid) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3641 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
|
3642 who.c_str ()); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3643 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3644 // 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
|
3645 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3646 else if (param == "collectoutput") |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3647 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3648 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
|
3649 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3650 else if (param == "emptyvalue") |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3651 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3652 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
|
3653 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3654 else if (param == "headerlines") |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3655 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3656 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
|
3657 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3658 else if (param == "bufsize") |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3659 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3660 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
|
3661 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3662 else if (param == "multipledelimsasone") |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3663 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3664 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
|
3665 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3666 else if (param == "returnonerror") |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3667 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3668 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
|
3669 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3670 else if (param == "whitespace") |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3671 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3672 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
|
3673 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3674 else if (param == "expchars") |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3675 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3676 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
|
3677 default_exp = false; |
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 else if (param == "endofline") |
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 bool valid = true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3682 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
|
3683 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
|
3684 s = do_string_escapes (s); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3685 int l = s.length (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3686 if (l == 0) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3687 eol1 = eol2 = -2; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3688 else if (l == 1) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3689 eol1 = eol2 = s.c_str ()[0]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3690 else if (l == 2) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3691 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3692 eol1 = s.c_str ()[0]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3693 eol2 = s.c_str ()[1]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3694 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
|
3695 valid = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3696 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3697 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3698 valid = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3699 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3700 if (! valid) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3701 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
|
3702 who.c_str ()); |
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 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
|
3706 } |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3707 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3708 whitespace_table = std::string (256, '\0'); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3709 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
|
3710 whitespace_table[whitespace[i]] = '1'; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3711 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3712 // 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
|
3713 // whitespace is explicitly ignored. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3714 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
|
3715 whitespace_table[' '] = '1'; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3716 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3717 // 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
|
3718 delim_table = std::string (256, '\0'); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3719 if (eol1 >= 0 && eol1 < 256) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3720 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
|
3721 if (eol2 >= 0 && eol2 < 256) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3722 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
|
3723 if (! have_delims) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3724 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
|
3725 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3726 if (isspace (i)) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3727 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
|
3728 } |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3729 else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3730 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
|
3731 delim_table[delims[i]] = '1'; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3732 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3733 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3734 // 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
|
3735 // 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
|
3736 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3737 int |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3738 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
|
3739 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3740 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
|
3741 bool found_comment = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3742 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3743 do |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3744 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3745 found_comment = false; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3746 int prev = -1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3747 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
|
3748 && ( ( (c1 == eol1 || c1 == eol2) && ++lines && ! EOLstop) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3749 || isspace (c1))) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3750 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3751 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
|
3752 lines--; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3753 prev = c1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3754 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3755 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3756 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
|
3757 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3758 // 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
|
3759 char *pos = is.tellg (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3760 std::ios::iostate state = is.rdstate (); |
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 std::string tmp (comment_len, '\0'); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3763 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
|
3764 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
|
3765 .c_str (), look, comment_len-1)) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3766 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3767 found_comment = true; |
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 dummy; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3770 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
|
3771 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3772 std::string eol (3, '\0'); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3773 eol[0] = eol1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3774 eol[1] = eol2; |
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 scan_caret (is, eol, dummy); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3777 c1 = is.get_undelim (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3778 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
|
3779 is.get_undelim (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3780 lines++; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3781 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3782 else // matching pair |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3783 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3784 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
|
3785 // last char of end-comment sequence |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3786 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
|
3787 std::string may_match (""); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3788 do |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3789 { // find sequence ending with last char |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3790 scan_caret (is, last, dummy); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3791 is.get_undelim (); // (read LAST itself) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3792 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3793 may_match = may_match + dummy + last; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3794 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
|
3795 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3796 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
|
3797 may_match = may_match.substr (start); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3798 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3799 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3800 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
|
3801 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3802 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3803 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
|
3804 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3805 is.clear (state); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3806 is.seekg (pos); |
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 } |
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 while (found_comment); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3811 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3812 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
|
3813 is.putback (c1); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3814 return c1; |
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 // 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
|
3818 // 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
|
3819 // 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
|
3820 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3821 int |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3822 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
|
3823 bool case_sensitive) const |
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 // target strings may be different sizes. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3826 // 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
|
3827 // that matches. |
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 char *pos = is.tellg (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3830 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3831 std::string tmp (max_len, '\0'); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3832 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
|
3833 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3834 is.clear (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3835 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
|
3836 // FIXME: pos may be corrupted by is.read |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3837 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3838 int i; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3839 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
|
3840 compare = case_sensitive ? strncmp : strncasecmp; |
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 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
|
3843 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3844 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
|
3845 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
|
3846 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3847 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
|
3848 break; |
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 } |
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 if (i == targets.numel ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3853 i = -1; |
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 return i; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3856 } |
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 // Skip delimiters -- multiple if MultipleDelimsAsOne specified. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3859 int |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3860 textscan::skip_delim (delimited_stream& is) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3861 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3862 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
|
3863 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
|
3864 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3865 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
|
3866 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3867 is.get (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3868 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
|
3869 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
|
3870 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3871 if (multiple_delims_as_one) |
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 int prev = -1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3874 // skip multiple delims. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3875 // 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
|
3876 while (is && ((c1 = is.get_undelim ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3877 != std::istream::traits_type::eof ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3878 && (((c1 == eol1 || c1 == eol2) && ++lines) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3879 || isspace (c1) || is_delim (c1))) |
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 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
|
3882 lines--; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3883 prev = c1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3884 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3885 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
|
3886 is.putback (c1); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3887 } |
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 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3890 else // multi-character delimiter |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3891 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3892 int first_match; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3893 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3894 if (c1 == eol1 || c1 == eol2 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3895 || (-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
|
3896 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3897 if (c1 == eol1) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3898 { |
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
|
3899 is.get_undelim (); |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3900 if (is.peek_undelim () == eol2) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3901 is.get_undelim (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3902 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3903 else if (c1 == eol2) |
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 is.get_undelim (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3906 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3907 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3908 if (multiple_delims_as_one) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3909 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3910 int prev = -1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3911 // skip multiple delims. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3912 // 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
|
3913 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
|
3914 != std::istream::traits_type::eof ()) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3915 && (((c1 == eol1 || c1 == eol2) && ++lines) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3916 || -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
|
3917 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3918 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
|
3919 lines--; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3920 prev = c1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3921 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3922 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3923 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3924 } |
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 return c1; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3927 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3928 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3929 // 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
|
3930 // 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
|
3931 // false (and set failbit). |
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 bool |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3934 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
|
3935 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3936 // "false" -> treat EOL as normal space |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3937 // 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
|
3938 skip_whitespace (is, false); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3939 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3940 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
|
3941 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3942 int ch = is.get_undelim (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3943 if (ch != fmt.text[i]) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3944 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3945 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
|
3946 is.putback (ch); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3947 is.setstate (std::ios::failbit); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3948 return false; |
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 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3951 return true; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3952 } |
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
|
3953 } |
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
|
3954 |
2117 | 3955 void |
3523 | 3956 octave_base_stream::error (const std::string& msg) |
2117 | 3957 { |
3958 fail = true; | |
3959 errmsg = msg; | |
3960 } | |
3961 | |
3962 void | |
4468 | 3963 octave_base_stream::error (const std::string& who, const std::string& msg) |
3964 { | |
3965 fail = true; | |
6296 | 3966 errmsg = who + ": " + msg; |
4468 | 3967 } |
3968 | |
3969 void | |
2117 | 3970 octave_base_stream::clear (void) |
3971 { | |
4889 | 3972 fail = false; |
3973 errmsg = ""; | |
3974 } | |
3975 | |
3976 void | |
3977 octave_base_stream::clearerr (void) | |
3978 { | |
4888 | 3979 std::istream *is = input_stream (); |
3980 std::ostream *os = output_stream (); | |
3981 | |
3982 if (is) | |
3983 is->clear (); | |
3984 | |
3985 if (os) | |
3986 os->clear (); | |
2117 | 3987 } |
3988 | |
3989 // Functions that are defined for all input streams (input streams | |
3990 // are those that define is). | |
3991 | |
3536 | 3992 std::string |
5275 | 3993 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
|
3994 bool strip_newline, const std::string& who) |
2117 | 3995 { |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3996 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
|
3997 ::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
|
3998 who.c_str ()); |
8773
9e3111d203c0
disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents:
8739
diff
changeset
|
3999 |
3523 | 4000 std::string retval; |
2117 | 4001 |
4002 err = false; | |
4003 | |
3523 | 4004 std::istream *isp = input_stream (); |
2117 | 4005 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4006 if (! isp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4007 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4008 err = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4009 invalid_operation (who, "reading"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4010 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4011 else |
2117 | 4012 { |
3523 | 4013 std::istream& is = *isp; |
2117 | 4014 |
5765 | 4015 std::ostringstream buf; |
2117 | 4016 |
4017 int c = 0; | |
3553 | 4018 int char_count = 0; |
6345 | 4019 |
4020 if (max_len != 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4021 { |
21184
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4022 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
|
4023 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4024 char_count++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4025 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4026 // Handle CRLF, CR, or LF as line ending. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4027 if (c == '\r') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4028 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4029 if (! strip_newline) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4030 buf << static_cast<char> (c); |
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 c = is.get (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4033 |
21184
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4034 if (c != std::istream::traits_type::eof ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4035 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4036 if (c == '\n') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4037 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4038 char_count++; |
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 if (! strip_newline) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4041 buf << static_cast<char> (c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4042 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4043 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4044 is.putback (c); |
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 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4047 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4048 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4049 else if (c == '\n') |
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 if (! strip_newline) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4052 buf << static_cast<char> (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 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4055 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4056 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4057 buf << static_cast<char> (c); |
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 (max_len > 0 && char_count == max_len) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4060 break; |
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 } |
6345 | 4063 |
4064 if (! is.eof () && char_count > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4065 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4066 // 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
|
4067 // 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
|
4068 // corresponding C-library functions do. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4069 int disgusting_compatibility_hack = is.get (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4070 if (! is.eof ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4071 is.putback (disgusting_compatibility_hack); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4072 } |
2117 | 4073 |
4224 | 4074 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
|
4075 retval = buf.str (); |
4224 | 4076 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4077 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4078 err = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4079 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4080 if (is.eof () && char_count == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4081 error (who, "at end of file"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4082 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4083 error (who, "read error"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4084 } |
2117 | 4085 } |
4086 | |
4087 return retval; | |
4088 } | |
4089 | |
3536 | 4090 std::string |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4091 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
|
4092 const std::string& who) |
2117 | 4093 { |
4468 | 4094 return do_gets (max_len, err, true, who); |
2117 | 4095 } |
4096 | |
3536 | 4097 std::string |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4098 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
|
4099 const std::string& who) |
2117 | 4100 { |
4468 | 4101 return do_gets (max_len, err, false, who); |
2117 | 4102 } |
4103 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
4104 off_t |
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
4105 octave_base_stream::skipl (off_t num, bool& err, const std::string& who) |
9701 | 4106 { |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
4107 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
|
4108 ::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
|
4109 who.c_str ()); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4110 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
4111 off_t cnt = -1; |
9701 | 4112 |
4113 err = false; | |
4114 | |
4115 std::istream *isp = input_stream (); | |
4116 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4117 if (! isp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4118 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4119 err = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4120 invalid_operation (who, "reading"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4121 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4122 else |
9701 | 4123 { |
4124 std::istream& is = *isp; | |
4125 | |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
4126 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
|
4127 int lastc = -1; |
9701 | 4128 cnt = 0; |
4129 | |
21184
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4130 while (is && (c = is.get ()) != std::istream::traits_type::eof ()) |
9701 | 4131 { |
4132 // Handle CRLF, CR, or LF as line ending. | |
4133 if (c == '\r' || (c == '\n' && lastc != '\r')) | |
4134 { | |
4135 if (++cnt == num) | |
4136 break; | |
4137 } | |
4138 | |
4139 lastc = c; | |
4140 } | |
4141 | |
4142 // Maybe eat the following \n if \r was just met. | |
4143 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
|
4144 is.get (); |
9701 | 4145 |
4146 if (is.bad ()) | |
4147 { | |
4148 err = true; | |
4149 error (who, "read error"); | |
4150 } | |
4151 | |
4152 if (err) | |
4153 cnt = -1; | |
4154 } | |
4155 | |
4156 return cnt; | |
4157 } | |
4158 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
4159 template <typename T> |
3636 | 4160 std::istream& |
6767 | 4161 octave_scan_1 (std::istream& is, const scanf_format_elt& fmt, T* valptr) |
3636 | 4162 { |
21687
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4163 T value = T (); |
3779 | 4164 |
4165 switch (fmt.type) | |
4166 { | |
4167 case 'o': | |
21687
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4168 is >> std::oct >> value >> std::dec; |
3779 | 4169 break; |
4170 | |
4171 case 'x': | |
21687
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4172 is >> std::hex >> value >> std::dec; |
4926 | 4173 break; |
4174 | |
4175 case 'i': | |
4176 { | |
21184
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4177 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
|
4178 |
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4179 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
|
4180 && isspace (c1)) |
20946 | 4181 ; // skip whitespace |
14675
757f729fd41d
skip leading whitespace for scanf %i format
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
4182 |
21184
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4183 if (c1 != std::istream::traits_type::eof ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4184 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4185 if (c1 == '0') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4186 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4187 int c2 = is.peek (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4188 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4189 if (c2 == 'x' || c2 == 'X') |
7709
fa41af732801
octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents:
7538
diff
changeset
|
4190 { |
fa41af732801
octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents:
7538
diff
changeset
|
4191 is.ignore (); |
fa41af732801
octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents:
7538
diff
changeset
|
4192 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
|
4193 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
|
4194 else |
21687
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4195 value = 0; |
7709
fa41af732801
octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents:
7538
diff
changeset
|
4196 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4197 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4198 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4199 if (c2 == '0' || c2 == '1' || c2 == '2' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4200 || c2 == '3' || c2 == '4' || c2 == '5' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4201 || 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
|
4202 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
|
4203 else if (c2 == '8' || c2 == '9') |
47908b818865
oct-stream.cc: Add FIXME note about bug #46493.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
4204 { |
47908b818865
oct-stream.cc: Add FIXME note about bug #46493.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
4205 // FIXME: Would like to set error state on octave stream. |
47908b818865
oct-stream.cc: Add FIXME note about bug #46493.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
4206 // See bug #46493. But only std::istream is input to fcn |
47908b818865
oct-stream.cc: Add FIXME note about bug #46493.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
4207 // error ("internal failure to match octal format"); |
21687
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4208 value = 0; |
21114
47908b818865
oct-stream.cc: Add FIXME note about bug #46493.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
4209 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4210 else |
21687
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4211 value = 0; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4212 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4213 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4214 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4215 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4216 is.putback (c1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4217 |
21687
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4218 is >> value; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4219 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4220 } |
4926 | 4221 } |
3779 | 4222 break; |
4223 | |
4224 default: | |
21687
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4225 is >> value; |
3779 | 4226 break; |
4227 } | |
3639 | 4228 |
21687
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4229 // 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
|
4230 // 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
|
4231 // 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
|
4232 // 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
|
4233 // *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
|
4234 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
|
4235 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
|
4236 |
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4237 // 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
|
4238 // want to continue reading. |
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4239 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
|
4240 *valptr = value; |
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4241 |
3638 | 4242 return is; |
3636 | 4243 } |
4244 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
4245 template <typename T> |
6767 | 4246 std::istream& |
4247 octave_scan (std::istream& is, const scanf_format_elt& fmt, T* valptr) | |
4248 { | |
4249 if (fmt.width) | |
4250 { | |
4251 // Limit input to fmt.width characters by reading into a | |
4252 // temporary stringstream buffer. | |
4253 std::string tmp; | |
4254 | |
4255 is.width (fmt.width); | |
4256 is >> tmp; | |
4257 | |
4258 std::istringstream ss (tmp); | |
4259 | |
4260 octave_scan_1 (ss, fmt, valptr); | |
4261 } | |
4262 else | |
4263 octave_scan_1 (is, fmt, valptr); | |
4264 | |
4265 return is; | |
4266 } | |
4267 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
4268 // 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
|
4269 // character strings. See BEGIN_S_CONVERSION for details. |
3779 | 4270 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
4271 template <> |
3779 | 4272 std::istream& |
4661 | 4273 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
|
4274 char* valptr) |
3779 | 4275 { |
4276 return is >> valptr; | |
4277 } | |
3636 | 4278 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
4279 template <> |
5176 | 4280 std::istream& |
5403 | 4281 octave_scan<> (std::istream& is, const scanf_format_elt& fmt, double* valptr) |
5176 | 4282 { |
4283 double& ref = *valptr; | |
4284 | |
4285 switch (fmt.type) | |
4286 { | |
4287 case 'e': | |
4288 case 'f': | |
4289 case 'g': | |
4290 { | |
21184
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4291 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
|
4292 |
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4293 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
|
4294 && isspace (c1)) |
20946 | 4295 ; // skip whitespace |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4296 |
21184
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4297 if (c1 != std::istream::traits_type::eof ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4298 { |
12936
b74cb659e757
accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
4299 is.putback (c1); |
b74cb659e757
accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
4300 |
b74cb659e757
accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
4301 ref = octave_read_value<double> (is); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4302 } |
5176 | 4303 } |
4304 break; | |
4305 | |
4306 default: | |
4307 panic_impossible (); | |
4308 break; | |
4309 } | |
4310 | |
4311 return is; | |
4312 } | |
4313 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
4314 template <typename T> |
2572 | 4315 void |
3636 | 4316 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
|
4317 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
|
4318 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
|
4319 octave_idx_type max_size, bool discard) |
2572 | 4320 { |
21147
95feb42d7a97
* oct-stream.cc (OCTAVE_SCAN): Eliminate trivial macro.
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
4321 octave_scan (is, fmt, valptr); |
2572 | 4322 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4323 if (! is) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4324 return; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4325 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4326 if (idx == max_size && ! discard) |
2572 | 4327 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4328 max_size *= 2; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4329 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4330 if (nr > 0) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4331 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
|
4332 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4333 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
|
4334 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4335 data = mval.fortran_vec (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4336 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4337 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4338 if (! discard) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4339 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4340 conversion_count++; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4341 data[idx++] = *(valptr); |
2572 | 4342 } |
4343 } | |
4344 | |
4345 template void | |
3636 | 4346 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
|
4347 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
|
4348 octave_idx_type, octave_idx_type, bool); |
2572 | 4349 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4350 #define DO_WHITESPACE_CONVERSION() \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4351 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4352 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4353 int c = std::istream::traits_type::eof (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4354 \ |
21184
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4355 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
|
4356 && isspace (c)) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4357 { /* skip whitespace */ } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4358 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4359 if (c != std::istream::traits_type::eof ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4360 is.putback (c); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4361 } \ |
3483 | 4362 while (0) |
4363 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4364 #define DO_LITERAL_CONVERSION() \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4365 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4366 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4367 int c = std::istream::traits_type::eof (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4368 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4369 int n = strlen (fmt); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4370 int i = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4371 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4372 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
|
4373 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4374 if (c == static_cast<unsigned char> (fmt[i])) \ |
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 i++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4377 continue; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4378 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4379 else \ |
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 is.putback (c); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4382 break; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4383 } \ |
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 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4386 if (i != n) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4387 is.setstate (std::ios::failbit); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4388 } \ |
3483 | 4389 while (0) |
4390 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4391 #define DO_PCT_CONVERSION() \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4392 do \ |
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 int c = is.get (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4395 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4396 if (c != std::istream::traits_type::eof ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4397 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4398 if (c != '%') \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4399 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4400 is.putback (c); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4401 is.setstate (std::ios::failbit); \ |
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 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4404 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4405 is.setstate (std::ios::failbit); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4406 } \ |
3640 | 4407 while (0) |
4408 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4409 #define BEGIN_C_CONVERSION() \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4410 is.unsetf (std::ios::skipws); \ |
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 int width = elt->width ? elt->width : 1; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4413 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4414 std::string tmp (width, '\0'); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4415 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4416 int c = std::istream::traits_type::eof (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4417 int n = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4418 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4419 while (is && n < width \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4420 && (c = is.get ()) != std::istream::traits_type::eof ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4421 tmp[n++] = static_cast<char> (c); \ |
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 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
|
4424 is.clear (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4425 \ |
12984
7626f8934466
correctly resize scanf output for %c formats (bug #34037)
John W. Eaton <jwe@octave.org>
parents:
12966
diff
changeset
|
4426 tmp.resize (n) |
3483 | 4427 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
4428 // For a '%s' format, skip initial whitespace and then read until the |
5338 | 4429 // 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
|
4430 #define BEGIN_S_CONVERSION() \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4431 int width = elt->width; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4432 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4433 std::string tmp; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4434 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4435 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4436 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4437 if (width) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4438 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4439 tmp = std::string (width, '\0'); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4440 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4441 int c = std::istream::traits_type::eof (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4442 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4443 int n = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4444 \ |
21184
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4445 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
|
4446 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4447 if (! isspace (c)) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4448 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4449 tmp[n++] = static_cast<char> (c); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4450 break; \ |
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 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4453 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4454 while (is && n < width \ |
21184
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4455 && (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
|
4456 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4457 if (isspace (c)) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4458 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4459 is.putback (c); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4460 break; \ |
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 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4463 tmp[n++] = static_cast<char> (c); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4464 } \ |
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 (n > 0 && c == std::istream::traits_type::eof ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4467 is.clear (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4468 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4469 tmp.resize (n); \ |
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 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4473 is >> std::ws >> tmp; \ |
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 } \ |
3483 | 4476 while (0) |
4477 | |
4478 // 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
|
4479 #define BEGIN_CHAR_CLASS_CONVERSION() \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4480 int width = elt->width; \ |
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 std::string 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 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4485 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4486 if (! width) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4487 width = std::numeric_limits<int>::max (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4488 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4489 std::ostringstream buf; \ |
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 char_class = elt->char_class; \ |
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 int c = std::istream::traits_type::eof (); \ |
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 (elt->type == '[') \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4496 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4497 int chars_read = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4498 while (is && chars_read++ < width \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4499 && (c = is.get ()) != std::istream::traits_type::eof () \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4500 && char_class.find (c) != std::string::npos) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4501 buf << static_cast<char> (c); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4502 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4503 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4504 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4505 int chars_read = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4506 while (is && chars_read++ < width \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4507 && (c = is.get ()) != std::istream::traits_type::eof () \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4508 && char_class.find (c) == std::string::npos) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4509 buf << static_cast<char> (c); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4510 } \ |
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 if (width == std::numeric_limits<int>::max () \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4513 && c != std::istream::traits_type::eof ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4514 is.putback (c); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4515 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4516 tmp = buf.str (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4517 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4518 if (tmp.empty ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4519 is.setstate (std::ios::failbit); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4520 else if (c == std::istream::traits_type::eof ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4521 is.clear (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4522 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4523 } \ |
3483 | 4524 while (0) |
4525 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4526 #define FINISH_CHARACTER_CONVERSION() \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4527 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4528 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4529 width = tmp.length (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4530 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4531 if (is) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4532 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4533 int i = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4534 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4535 if (! discard) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4536 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4537 conversion_count++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4538 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4539 while (i < width) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4540 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4541 if (data_index == max_size) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4542 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4543 max_size *= 2; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4544 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4545 if (all_char_conv) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4546 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4547 if (one_elt_size_spec) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4548 mval.resize (1, max_size, 0.0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4549 else if (nr > 0) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4550 mval.resize (nr, max_size / nr, 0.0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4551 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4552 panic_impossible (); \ |
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 else if (nr > 0) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4555 mval.resize (nr, max_size / nr, 0.0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4556 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4557 mval.resize (max_size, 1, 0.0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4558 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4559 data = mval.fortran_vec (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4560 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4561 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4562 data[data_index++] = tmp[i++]; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4563 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4564 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4565 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4566 } \ |
3410 | 4567 while (0) |
2117 | 4568 |
4569 octave_value | |
4570 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
|
4571 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
|
4572 bool one_elt_size_spec, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4573 octave_idx_type& conversion_count, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4574 const std::string& who) |
2117 | 4575 { |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
4576 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
|
4577 ::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
|
4578 who.c_str ()); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4579 |
8773
9e3111d203c0
disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents:
8739
diff
changeset
|
4580 octave_value retval = Matrix (); |
9e3111d203c0
disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents:
8739
diff
changeset
|
4581 |
3268 | 4582 conversion_count = 0; |
4583 | |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4584 octave_idx_type nconv = fmt_list.num_conversions (); |
3640 | 4585 |
5275 | 4586 octave_idx_type data_index = 0; |
2121 | 4587 |
3268 | 4588 if (nr == 0 || nc == 0) |
4589 { | |
4590 if (one_elt_size_spec) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4591 nc = 0; |
3268 | 4592 |
4593 return Matrix (nr, nc, 0.0); | |
4594 } | |
4595 | |
3523 | 4596 std::istream *isp = input_stream (); |
2117 | 4597 |
4598 bool all_char_conv = fmt_list.all_character_conversions (); | |
4599 | |
4600 Matrix mval; | |
4601 double *data = 0; | |
5275 | 4602 octave_idx_type max_size = 0; |
4603 octave_idx_type max_conv = 0; | |
4604 | |
4605 octave_idx_type final_nr = 0; | |
4606 octave_idx_type final_nc = 0; | |
2117 | 4607 |
3268 | 4608 if (all_char_conv) |
4609 { | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4610 // 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
|
4611 // we may read more than one element for each conversion). |
3268 | 4612 if (one_elt_size_spec) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4613 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4614 max_size = 512; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4615 mval.resize (1, max_size, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4616 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4617 if (nr > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4618 max_conv = nr; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4619 } |
4420 | 4620 else if (nr > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4621 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4622 if (nc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4623 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4624 mval.resize (nr, nc, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4625 max_size = max_conv = nr * nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4626 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4627 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4628 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4629 mval.resize (nr, 32, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4630 max_size = nr * 32; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4631 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4632 } |
4420 | 4633 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4634 panic_impossible (); |
3268 | 4635 } |
4636 else if (nr > 0) | |
2117 | 4637 { |
4638 if (nc > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4639 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4640 // Will not resize later. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4641 mval.resize (nr, nc, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4642 max_size = nr * nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4643 max_conv = max_size; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4644 } |
2117 | 4645 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4646 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4647 // Maybe resize later. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4648 mval.resize (nr, 32, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4649 max_size = nr * 32; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4650 } |
2117 | 4651 } |
4652 else | |
4653 { | |
4420 | 4654 // Maybe resize later. |
2117 | 4655 mval.resize (32, 1, 0.0); |
4656 max_size = 32; | |
4657 } | |
4658 | |
4420 | 4659 data = mval.fortran_vec (); |
4660 | |
2117 | 4661 if (isp) |
4662 { | |
3523 | 4663 std::istream& is = *isp; |
2117 | 4664 |
4665 const scanf_format_elt *elt = fmt_list.first (); | |
4666 | |
3538 | 4667 std::ios::fmtflags flags = is.flags (); |
2213 | 4668 |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4669 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
|
4670 |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4671 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
|
4672 |
2117 | 4673 for (;;) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4674 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4675 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4676 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4677 if (elt) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4678 { |
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
|
4679 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
|
4680 || (! (elt->type == scanf_format_elt::whitespace_conversion |
44eb1102f8a8
don't recycle scanf format string if all conversions are done (bug #45808)
John W. Eaton <jwe@octave.org>
parents:
20432
diff
changeset
|
4681 || elt->type == scanf_format_elt::literal_conversion |
44eb1102f8a8
don't recycle scanf format string if all conversions are done (bug #45808)
John W. Eaton <jwe@octave.org>
parents:
20432
diff
changeset
|
4682 || elt->type == '%') |
44eb1102f8a8
don't recycle scanf format string if all conversions are done (bug #45808)
John W. Eaton <jwe@octave.org>
parents:
20432
diff
changeset
|
4683 && max_conv > 0 && conversion_count == max_conv)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4684 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4685 // 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
|
4686 // 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
|
4687 // 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
|
4688 // 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
|
4689 // Determine final array size and exit. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4690 if (all_char_conv && one_elt_size_spec) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4691 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4692 final_nr = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4693 final_nc = data_index; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4694 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4695 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4696 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4697 final_nr = nr; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4698 final_nc = (data_index - 1) / nr + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4699 } |
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 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4702 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4703 else if (data_index == max_size) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4704 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4705 max_size *= 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4706 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4707 if (all_char_conv) |
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 if (one_elt_size_spec) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4710 mval.resize (1, max_size, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4711 else if (nr > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4712 mval.resize (nr, max_size / nr, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4713 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4714 panic_impossible (); |
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 else if (nr > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4717 mval.resize (nr, max_size / nr, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4718 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4719 mval.resize (max_size, 1, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4720 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4721 data = mval.fortran_vec (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4722 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4723 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4724 const char *fmt = elt->text; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4725 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4726 bool discard = elt->discard; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4727 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4728 switch (elt->type) |
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 case scanf_format_elt::whitespace_conversion: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4731 DO_WHITESPACE_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4732 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4733 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4734 case scanf_format_elt::literal_conversion: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4735 DO_LITERAL_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4736 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4737 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4738 case '%': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4739 DO_PCT_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4740 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4741 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4742 case 'd': case 'i': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4743 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4744 switch (elt->modifier) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4745 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4746 case 'h': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4747 { |
21686
f07d6f579214
scanf: use appropriate sized types for integer conversions (bug #47741)
Mike Miller <mtmiller@octave.org>
parents:
21622
diff
changeset
|
4748 int16_t tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4749 do_scanf_conv (is, *elt, &tmp, mval, data, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4750 data_index, conversion_count, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4751 nr, max_size, discard); |
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 break; |
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 'l': |
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 int64_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 default: |
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 int32_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 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4774 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4775 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4776 case 'o': case 'u': case 'x': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4777 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4778 switch (elt->modifier) |
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 case 'h': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4781 { |
21686
f07d6f579214
scanf: use appropriate sized types for integer conversions (bug #47741)
Mike Miller <mtmiller@octave.org>
parents:
21622
diff
changeset
|
4782 uint16_t tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4783 do_scanf_conv (is, *elt, &tmp, mval, data, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4784 data_index, conversion_count, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4785 nr, max_size, discard); |
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 break; |
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 'l': |
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 uint64_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 default: |
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 uint32_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 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4808 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4809 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4810 case 'e': case 'f': case 'g': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4811 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4812 double tmp; |
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 do_scanf_conv (is, *elt, &tmp, mval, data, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4815 data_index, conversion_count, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4816 nr, max_size, discard); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4817 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4818 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4819 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4820 case 'c': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4821 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4822 BEGIN_C_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4823 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4824 FINISH_CHARACTER_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4825 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4826 is.setf (flags); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4827 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4828 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4829 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4830 case 's': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4831 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4832 BEGIN_S_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4833 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4834 FINISH_CHARACTER_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4835 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4836 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4837 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4838 case '[': case '^': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4839 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4840 BEGIN_CHAR_CLASS_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4841 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4842 FINISH_CHARACTER_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4843 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4844 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4845 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4846 case 'p': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4847 error ("%s: unsupported format specifier", who.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4848 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4849 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4850 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4851 error ("%s: internal format error", who.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4852 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4853 } |
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 if (! ok ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4856 { |
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 else if (! is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4860 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4861 if (all_char_conv) |
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 if (one_elt_size_spec) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4864 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4865 final_nr = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4866 final_nc = data_index; |
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 (data_index > nr) |
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 final_nr = nr; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4871 final_nc = (data_index - 1) / nr + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4872 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4873 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4874 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4875 final_nr = data_index; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4876 final_nc = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4877 } |
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 else if (nr > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4880 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4881 if (data_index > nr) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4882 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4883 final_nr = nr; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4884 final_nc = (data_index - 1) / nr + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4885 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4886 else |
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 final_nr = data_index; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4889 final_nc = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4890 } |
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 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4893 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4894 final_nr = data_index; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4895 final_nc = 1; |
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 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4898 // 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
|
4899 // reset the failbit in the stream state. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4900 if (is.rdstate () & std::ios::failbit) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4901 is.clear (is.rdstate () & (~std::ios::failbit)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4902 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4903 // 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
|
4904 if (octave::application::interactive () |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
4905 && ! octave::application::forced_interactive () |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
4906 && name () == "stdin") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4907 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4908 is.clear (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4909 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4910 // Skip to end of line. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4911 bool err; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4912 do_gets (-1, err, false, who); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4913 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4914 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4915 break; |
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 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4918 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4919 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4920 error ("%s: internal format error", who.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4921 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4922 } |
2117 | 4923 |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4924 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
|
4925 { |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4926 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
|
4927 { |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4928 final_nr = 1; |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4929 final_nc = data_index; |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4930 } |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4931 else |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4932 { |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4933 final_nr = nr; |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4934 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
|
4935 } |
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 break; |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4938 } |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4939 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
|
4940 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4941 // 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
|
4942 // 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
|
4943 // 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
|
4944 // 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
|
4945 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
|
4946 && (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
|
4947 || 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
|
4948 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4949 } |
2117 | 4950 } |
4951 | |
4952 if (ok ()) | |
4953 { | |
2121 | 4954 mval.resize (final_nr, final_nc, 0.0); |
2117 | 4955 |
3268 | 4956 retval = mval; |
4957 | |
2117 | 4958 if (all_char_conv) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4959 retval = retval.convert_to_str (false, true); |
2117 | 4960 } |
4961 | |
4962 return retval; | |
4963 } | |
4964 | |
4965 octave_value | |
3810 | 4966 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
|
4967 octave_idx_type& conversion_count, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4968 const std::string& who) |
2117 | 4969 { |
4970 octave_value retval = Matrix (); | |
4971 | |
3559 | 4972 conversion_count = 0; |
2117 | 4973 |
3523 | 4974 std::istream *isp = input_stream (); |
2117 | 4975 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4976 if (! isp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4977 invalid_operation (who, "reading"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4978 else |
2117 | 4979 { |
4980 scanf_format_list fmt_list (fmt); | |
4981 | |
3640 | 4982 if (fmt_list.num_conversions () == -1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4983 ::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
|
4984 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4985 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
|
4986 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
|
4987 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4988 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
|
4989 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4990 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
|
4991 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4992 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
|
4993 conversion_count, who); |
2215 | 4994 } |
2572 | 4995 |
4996 return retval; | |
4997 } | |
4998 | |
2712 | 4999 bool |
5000 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
|
5001 octave_value& retval, const std::string& who) |
2572 | 5002 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5003 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
|
5004 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5005 if (! isp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5006 return false; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5007 |
2712 | 5008 bool quit = false; |
2215 | 5009 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5010 std::istream& is = *isp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5011 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5012 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
|
5013 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5014 if (elt) |
2215 | 5015 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5016 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
|
5017 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5018 bool discard = elt->discard; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5019 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5020 switch (elt->type) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5021 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5022 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
|
5023 DO_WHITESPACE_CONVERSION (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5024 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5025 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5026 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
|
5027 DO_LITERAL_CONVERSION (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5028 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5029 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5030 case '%': |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5031 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5032 DO_PCT_CONVERSION (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5033 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5034 if (! is) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5035 quit = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5036 } |
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 'd': case 'i': |
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 int tmp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5042 |
21147
95feb42d7a97
* oct-stream.cc (OCTAVE_SCAN): Eliminate trivial macro.
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
5043 if (octave_scan (is, *elt, &tmp)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5044 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5045 if (! discard) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5046 retval = tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5047 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5048 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5049 quit = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5050 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5051 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5052 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5053 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
|
5054 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5055 long int tmp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5056 |
21147
95feb42d7a97
* oct-stream.cc (OCTAVE_SCAN): Eliminate trivial macro.
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
5057 if (octave_scan (is, *elt, &tmp)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5058 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5059 if (! discard) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5060 retval = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5061 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5062 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5063 quit = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5064 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5065 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5066 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5067 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
|
5068 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5069 double tmp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5070 |
21147
95feb42d7a97
* oct-stream.cc (OCTAVE_SCAN): Eliminate trivial macro.
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
5071 if (octave_scan (is, *elt, &tmp)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5072 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5073 if (! discard) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5074 retval = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5075 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5076 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5077 quit = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5078 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5079 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5080 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5081 case 'c': |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5082 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5083 BEGIN_C_CONVERSION (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5084 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5085 if (! discard) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5086 retval = tmp; |
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 if (! is) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5089 quit = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5090 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5091 is.setf (flags); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5092 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5093 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5094 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5095 case 's': |
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 BEGIN_S_CONVERSION (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5098 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5099 if (! discard) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5100 retval = tmp; |
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 if (! is) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5103 quit = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5104 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5105 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5106 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5107 case '[': |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5108 case '^': |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5109 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5110 BEGIN_CHAR_CLASS_CONVERSION (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5111 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5112 if (! discard) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5113 retval = tmp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5114 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5115 if (! is) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5116 quit = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5117 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5118 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5119 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5120 case 'p': |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5121 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
|
5122 break; |
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 default: |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5125 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
|
5126 break; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5127 } |
20931
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 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5130 if (ok () && is.fail ()) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5131 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5132 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
|
5133 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5134 // 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
|
5135 |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
5136 if (octave::application::interactive () |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
5137 && ! octave::application::forced_interactive () |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
5138 && name () == "stdin") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5139 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5140 // 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
|
5141 bool err; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5142 do_gets (-1, err, false, who); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5143 } |
2215 | 5144 } |
5145 | |
2712 | 5146 return quit; |
2215 | 5147 } |
5148 | |
5149 octave_value_list | |
4468 | 5150 octave_base_stream::oscanf (const std::string& fmt, const std::string& who) |
2215 | 5151 { |
5152 octave_value_list retval; | |
5153 | |
3523 | 5154 std::istream *isp = input_stream (); |
2215 | 5155 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5156 if (! isp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5157 invalid_operation (who, "reading"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5158 else |
2215 | 5159 { |
3523 | 5160 std::istream& is = *isp; |
2215 | 5161 |
5162 scanf_format_list fmt_list (fmt); | |
5163 | |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
5164 octave_idx_type nconv = fmt_list.num_conversions (); |
2215 | 5165 |
3640 | 5166 if (nconv == -1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5167 ::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
|
5168 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5169 is.clear (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5170 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5171 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
|
5172 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5173 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
|
5174 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5175 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
|
5176 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5177 int num_values = 0; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5178 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5179 bool quit = false; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5180 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5181 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
|
5182 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5183 octave_value tmp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5184 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5185 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
|
5186 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5187 if (quit) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5188 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5189 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5190 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5191 if (tmp.is_defined ()) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5192 retval(num_values++) = 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 if (! ok ()) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5195 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5196 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5197 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
|
5198 } |
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 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5201 retval(nconv) = num_values; |
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 int err_num; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5204 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
|
5205 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5206 if (! quit) |
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 // 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
|
5209 if (ok () && len > nconv) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5210 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5211 octave_value tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5212 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5213 elt = fmt_list.next (); |
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 do_oscanf (elt, tmp, who); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5216 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5217 } |
2117 | 5218 } |
5219 | |
5220 return retval; | |
5221 } | |
5222 | |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5223 octave_value |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5224 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
|
5225 octave_idx_type ntimes, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5226 const octave_value_list& options, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5227 const std::string& who, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5228 octave_idx_type& read_count) |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5229 { |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
5230 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
|
5231 ::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
|
5232 who.c_str ()); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5233 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5234 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
|
5235 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5236 std::istream *isp = input_stream (); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5237 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5238 if (! isp) |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5239 invalid_operation (who, "reading"); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5240 else |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5241 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
5242 octave::textscan scanner (who); |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5243 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5244 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
|
5245 } |
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 return retval; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5248 } |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5249 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5250 // 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
|
5251 // (output streams are those that define os). |
2117 | 5252 |
5253 int | |
5254 octave_base_stream::flush (void) | |
5255 { | |
5256 int retval = -1; | |
5257 | |
3523 | 5258 std::ostream *os = output_stream (); |
2117 | 5259 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5260 if (! os) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5261 invalid_operation ("fflush", "writing"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5262 else |
2117 | 5263 { |
5264 os->flush (); | |
5265 | |
5266 if (os->good ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5267 retval = 0; |
2117 | 5268 } |
5269 | |
5270 return retval; | |
5271 } | |
5272 | |
5273 class | |
5274 printf_value_cache | |
5275 { | |
5276 public: | |
5277 | |
3653 | 5278 enum state { ok, conversion_error }; |
2117 | 5279 |
7352 | 5280 printf_value_cache (const octave_value_list& args, const std::string& who) |
2117 | 5281 : 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
|
5282 n_vals (values.length ()), n_elts (0), have_data (false), |
7352 | 5283 curr_state (ok) |
5284 { | |
5285 for (octave_idx_type i = 0; i < values.length (); i++) | |
5286 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5287 octave_value val = values(i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5288 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5289 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
|
5290 err_wrong_type_arg (who, val); |
7352 | 5291 } |
5292 } | |
2117 | 5293 |
5294 ~printf_value_cache (void) { } | |
5295 | |
5296 // 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
|
5297 octave_value get_next_value (char type = 0); |
2117 | 5298 |
5299 // Get the current value as an int and advance the internal pointer. | |
5300 int int_value (void); | |
5301 | |
3145 | 5302 operator bool () const { return (curr_state == ok); } |
2117 | 5303 |
3653 | 5304 bool exhausted (void) { return (val_idx >= n_vals); } |
2117 | 5305 |
5306 private: | |
5307 | |
5308 const octave_value_list values; | |
5309 int val_idx; | |
5310 int elt_idx; | |
5311 int n_vals; | |
5312 int n_elts; | |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5313 bool have_data; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5314 octave_value curr_val; |
2117 | 5315 state curr_state; |
5316 | |
5317 // Must create value cache with values! | |
5318 | |
5319 printf_value_cache (void); | |
5320 | |
5321 // No copying! | |
5322 | |
5323 printf_value_cache (const printf_value_cache&); | |
5324 | |
5325 printf_value_cache& operator = (const printf_value_cache&); | |
5326 }; | |
5327 | |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5328 octave_value |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5329 printf_value_cache::get_next_value (char type) |
2117 | 5330 { |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5331 octave_value retval; |
2117 | 5332 |
3711 | 5333 if (exhausted ()) |
5334 curr_state = conversion_error; | |
5335 | |
5336 while (! exhausted ()) | |
2117 | 5337 { |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5338 if (! have_data) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5339 { |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5340 curr_val = values (val_idx); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5341 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
5342 elt_idx = 0; |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
5343 n_elts = curr_val.numel (); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
5344 have_data = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5345 } |
2117 | 5346 |
5347 if (elt_idx < n_elts) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5348 { |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5349 if (type == 's') |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5350 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5351 if (curr_val.is_string ()) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5352 { |
21296
596e19e7e571
fix printf regression (bug #47192)
John W. Eaton <jwe@octave.org>
parents:
21235
diff
changeset
|
5353 dim_vector dv (1, curr_val.numel ()); |
596e19e7e571
fix printf regression (bug #47192)
John W. Eaton <jwe@octave.org>
parents:
21235
diff
changeset
|
5354 octave_value tmp = curr_val.reshape (dv); |
596e19e7e571
fix printf regression (bug #47192)
John W. Eaton <jwe@octave.org>
parents:
21235
diff
changeset
|
5355 |
596e19e7e571
fix printf regression (bug #47192)
John W. Eaton <jwe@octave.org>
parents:
21235
diff
changeset
|
5356 std::string sval = tmp.string_value (); |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5357 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5358 retval = sval.substr (elt_idx); |
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 // We've consumed the rest of the value. |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5361 elt_idx = n_elts; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5362 } |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5363 else |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5364 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5365 // Convert to character string while values are |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5366 // integers in the range [0 : char max] |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5367 const NDArray val = curr_val.array_value (); |
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 octave_idx_type idx = elt_idx; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5370 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5371 for (; idx < n_elts; idx++) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5372 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5373 double dval = val(idx); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5374 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21777
diff
changeset
|
5375 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
|
5376 break; |
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 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5379 octave_idx_type n = idx - elt_idx; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5380 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5381 if (n > 0) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5382 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5383 std::string sval (n, '\0'); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5384 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5385 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
|
5386 sval[i] = val(elt_idx++); |
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 retval = sval; |
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 else |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5391 retval = curr_val.fast_elem_extract (elt_idx++); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5392 } |
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 else |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5395 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5396 retval = curr_val.fast_elem_extract (elt_idx++); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5397 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5398 if (type == 'c' && ! retval.is_string ()) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5399 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5400 double dval = retval.double_value (); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5401 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21777
diff
changeset
|
5402 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
|
5403 retval = static_cast<char> (dval); |
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 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5406 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5407 if (elt_idx >= n_elts) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5408 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5409 elt_idx = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5410 val_idx++; |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5411 have_data = false; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5412 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5413 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5414 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5415 } |
2117 | 5416 else |
10315
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 val_idx++; |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5419 have_data = false; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5420 |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5421 if (n_elts == 0) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5422 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5423 if (elt_idx == 0 && (type == 's' || type == 'c')) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5424 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5425 retval = ""; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5426 break; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5427 } |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5428 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5429 if (exhausted ()) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5430 curr_state = conversion_error; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5431 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5432 } |
2117 | 5433 } |
5434 | |
5435 return retval; | |
5436 } | |
5437 | |
5438 int | |
5439 printf_value_cache::int_value (void) | |
5440 { | |
5441 int retval = 0; | |
5442 | |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5443 octave_value val = get_next_value (); |
2117 | 5444 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
5445 double dval = val.double_value (true); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
5446 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21777
diff
changeset
|
5447 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
|
5448 retval = octave::math::nint (dval); |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
5449 else |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
5450 curr_state = conversion_error; |
2117 | 5451 |
5452 return retval; | |
5453 } | |
5454 | |
5455 // Ugh again and again. | |
5456 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
5457 template <typename T> |
3620 | 5458 int |
3523 | 5459 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
|
5460 int sa_2, T arg, const std::string& who) |
2572 | 5461 { |
3620 | 5462 int retval = 0; |
5463 | |
2572 | 5464 switch (nsa) |
5465 { | |
5466 case 2: | |
3640 | 5467 retval = octave_format (os, fmt, sa_1, sa_2, arg); |
2572 | 5468 break; |
5469 | |
5470 case 1: | |
3640 | 5471 retval = octave_format (os, fmt, sa_1, arg); |
2572 | 5472 break; |
5473 | |
5474 case 0: | |
3640 | 5475 retval = octave_format (os, fmt, arg); |
2572 | 5476 break; |
5477 | |
5478 default: | |
4468 | 5479 ::error ("%s: internal error handling format", who.c_str ()); |
2572 | 5480 break; |
5481 } | |
3620 | 5482 |
5483 return retval; | |
2572 | 5484 } |
5485 | |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5486 static size_t |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5487 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
|
5488 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
|
5489 const std::string& who) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5490 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5491 if (nsa > 2) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20768
diff
changeset
|
5492 ::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
|
5493 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5494 std::string flags = elt->flags; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5495 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5496 bool left = flags.find ('-') != std::string::npos; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5497 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5498 size_t len = arg.length (); |
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 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
|
5501 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
|
5502 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5503 os << std::setw (fw) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5504 << (left ? std::left : std::right) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5505 << (prec < len ? arg.substr (0, prec) : arg); |
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 return len > fw ? len : fw; |
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 |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5510 static bool |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5511 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
|
5512 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5513 octave_value ov_isnan = val.isnan (); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5514 octave_value ov_isinf = val.isinf (); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5515 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5516 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
|
5517 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5518 |
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 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
|
5521 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5522 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
|
5523 |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5524 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
|
5525 return true; |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5526 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
|
5527 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5528 if (val.is_uint64_type ()) |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5529 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5530 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
|
5531 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5532 if (ival.value () <= limit) |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5533 return true; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5534 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5535 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5536 return true; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5537 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5538 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5539 { |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5540 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
|
5541 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21777
diff
changeset
|
5542 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
|
5543 return true; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5544 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5545 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5546 return false; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5547 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5548 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5549 static bool |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5550 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
|
5551 { |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5552 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
|
5553 return true; |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5554 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
|
5555 { |
7d0014bb9e4e
also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents:
18650
diff
changeset
|
5556 // 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
|
5557 |
7d0014bb9e4e
also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents:
18650
diff
changeset
|
5558 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
|
5559 = 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
|
5560 |
7d0014bb9e4e
also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents:
18650
diff
changeset
|
5561 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
|
5562 } |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5563 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5564 { |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5565 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
|
5566 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5567 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
|
5568 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21777
diff
changeset
|
5569 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
|
5570 return true; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5571 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5572 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5573 return false; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5574 } |
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 static std::string |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5577 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
|
5578 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5579 std::string tfmt = elt->text; |
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 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
|
5582 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5583 return tfmt; |
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 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5586 int |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5587 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
|
5588 const printf_format_elt *elt, |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5589 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
|
5590 const octave_value& val, |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5591 const std::string& who) |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5592 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5593 int retval = 0; |
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 const char *fmt = elt->text; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5596 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5597 if (is_nan_or_inf (val)) |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5598 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5599 double dval = val.double_value (); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5600 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5601 std::string tfmt = fmt; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5602 std::string::size_type i1, i2; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5603 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5604 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
|
5605 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5606 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
|
5607 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5608 tfmt.erase (i2, i1-i2); |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5609 if (elt->prec == -2) |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5610 nsa--; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5611 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5612 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5613 const char *tval; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5614 if (lo_ieee_isinf (dval)) |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5615 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5616 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
|
5617 tval = (dval < 0 ? "-Inf" : "+Inf"); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5618 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5619 tval = (dval < 0 ? "-Inf" : "Inf"); |
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 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5622 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5623 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
|
5624 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
|
5625 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5626 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
|
5627 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5628 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5629 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
|
5630 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5631 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5632 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5633 static std::string llmod |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5634 = 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
|
5635 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5636 char type = elt->type; |
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 switch (type) |
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 case 'd': case 'i': case 'c': |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5641 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
|
5642 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5643 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
|
5644 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5645 // Insert "long" modifier. |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5646 std::string tfmt = fmt; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5647 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
|
5648 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5649 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
|
5650 tval.value (), who); |
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 else |
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 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
|
5655 |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5656 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
|
5657 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
5658 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
|
5659 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
|
5660 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5661 break; |
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 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
|
5664 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
|
5665 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5666 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
|
5667 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5668 // Insert "long" modifier. |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5669 std::string tfmt = fmt; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5670 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
|
5671 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5672 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
|
5673 tval.value (), who); |
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 else |
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 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
|
5678 |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5679 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
|
5680 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
5681 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
|
5682 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
|
5683 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5684 break; |
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 case 'f': case 'e': case 'E': |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5687 case 'g': case 'G': |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5688 { |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5689 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
|
5690 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
5691 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
|
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 default: |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
5696 // 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
|
5697 // 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
|
5698 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
|
5699 return -1; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5700 break; |
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 } |
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 return retval; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5705 } |
6492 | 5706 |
2117 | 5707 int |
5708 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
|
5709 const octave_value_list& args, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5710 const std::string& who) |
2117 | 5711 { |
3620 | 5712 int retval = 0; |
2117 | 5713 |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
5714 octave_idx_type nconv = fmt_list.num_conversions (); |
3640 | 5715 |
3523 | 5716 std::ostream *osp = output_stream (); |
2117 | 5717 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5718 if (! osp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5719 invalid_operation (who, "writing"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5720 else |
2117 | 5721 { |
3523 | 5722 std::ostream& os = *osp; |
2117 | 5723 |
5724 const printf_format_elt *elt = fmt_list.first (); | |
5725 | |
7352 | 5726 printf_value_cache val_cache (args, who); |
5727 | |
2117 | 5728 for (;;) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5729 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5730 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5731 |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5732 if (! elt) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5733 ::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
|
5734 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5735 // 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
|
5736 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
|
5737 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5738 int sa_1 = 0; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5739 int sa_2 = 0; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5740 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5741 if (nsa > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5742 { |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5743 sa_1 = val_cache.int_value (); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5744 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5745 if (! val_cache) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5746 break; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5747 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5748 { |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5749 if (nsa > 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5750 { |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5751 sa_2 = val_cache.int_value (); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5752 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5753 if (! val_cache) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5754 break; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5755 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5756 } |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5757 } |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5758 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5759 if (elt->type == '%') |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5760 { |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5761 os << "%"; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5762 retval++; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5763 } |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5764 else if (elt->args == 0 && elt->text) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5765 { |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5766 os << elt->text; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5767 retval += strlen (elt->text); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5768 } |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5769 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
|
5770 { |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5771 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
|
5772 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5773 if (val_cache) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5774 { |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5775 if (val.is_string ()) |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5776 { |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5777 std::string sval = val.string_value (); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5778 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5779 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
|
5780 sa_2, sval, who); |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5781 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5782 else |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5783 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
|
5784 sa_2, val, who); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5785 } |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5786 else |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5787 break; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5788 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5789 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5790 { |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5791 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
|
5792 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5793 if (val_cache) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5794 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
|
5795 sa_2, val, who); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5796 else |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5797 break; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5798 } |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5799 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5800 if (! os) |
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 error ("%s: write error", who.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5803 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5804 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5805 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5806 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
|
5807 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5808 if (! elt || (val_cache.exhausted () && elt->args > 0)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5809 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
5810 } |
2117 | 5811 } |
5812 | |
5813 return retval; | |
5814 } | |
5815 | |
5816 int | |
3640 | 5817 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
|
5818 const octave_value_list& args, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5819 const std::string& who) |
2117 | 5820 { |
3640 | 5821 printf_format_list fmt_list (fmt); |
5822 | |
5823 if (fmt_list.num_conversions () == -1) | |
4468 | 5824 ::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
|
5825 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5826 return do_printf (fmt_list, args, who); |
2117 | 5827 } |
5828 | |
5829 int | |
4468 | 5830 octave_base_stream::puts (const std::string& s, const std::string& who) |
2117 | 5831 { |
5832 int retval = -1; | |
5833 | |
3523 | 5834 std::ostream *osp = output_stream (); |
2117 | 5835 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5836 if (! osp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5837 invalid_operation (who, "writing"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5838 else |
2117 | 5839 { |
3523 | 5840 std::ostream& os = *osp; |
2117 | 5841 |
5842 os << s; | |
5843 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5844 if (! os) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5845 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
|
5846 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5847 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5848 // 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
|
5849 // Without it, output from a loop like |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5850 // |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5851 // 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
|
5852 // |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5853 // 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
|
5854 os.flush (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5855 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5856 if (os) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5857 retval = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5858 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5859 error ("%s: write error", who.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5860 } |
2117 | 5861 } |
5862 | |
5863 return retval; | |
5864 } | |
5865 | |
5866 // Return current error message for this stream. | |
5867 | |
3536 | 5868 std::string |
2435 | 5869 octave_base_stream::error (bool clear_err, int& err_num) |
2117 | 5870 { |
2435 | 5871 err_num = fail ? -1 : 0; |
2117 | 5872 |
3523 | 5873 std::string tmp = errmsg; |
2117 | 5874 |
5875 if (clear_err) | |
5876 clear (); | |
5877 | |
5878 return tmp; | |
5879 } | |
5880 | |
5881 void | |
4468 | 5882 octave_base_stream::invalid_operation (const std::string& who, const char *rw) |
2117 | 5883 { |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
5884 // Note: This calls the member fcn error, not ::error from error.h. |
6297 | 5885 error (who, std::string ("stream not open for ") + rw); |
2117 | 5886 } |
5887 | |
3552 | 5888 octave_stream::octave_stream (octave_base_stream *bs) |
3340 | 5889 : rep (bs) |
5890 { | |
5891 if (rep) | |
5892 rep->count = 1; | |
5893 } | |
5894 | |
5895 octave_stream::~octave_stream (void) | |
5896 { | |
5897 if (rep && --rep->count == 0) | |
5898 delete rep; | |
5899 } | |
5900 | |
5901 octave_stream::octave_stream (const octave_stream& s) | |
5902 : rep (s.rep) | |
5903 { | |
5904 if (rep) | |
5905 rep->count++; | |
5906 } | |
5907 | |
5908 octave_stream& | |
5909 octave_stream::operator = (const octave_stream& s) | |
5910 { | |
5911 if (rep != s.rep) | |
5912 { | |
5913 if (rep && --rep->count == 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5914 delete rep; |
3340 | 5915 |
5916 rep = s.rep; | |
5917 | |
5918 if (rep) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5919 rep->count++; |
3340 | 5920 } |
5921 | |
5922 return *this; | |
5923 } | |
5924 | |
2117 | 5925 int |
5926 octave_stream::flush (void) | |
5927 { | |
5928 int retval = -1; | |
5929 | |
5659 | 5930 if (stream_ok ()) |
2117 | 5931 retval = rep->flush (); |
5932 | |
5933 return retval; | |
5934 } | |
5935 | |
3536 | 5936 std::string |
5275 | 5937 octave_stream::getl (octave_idx_type max_len, bool& err, const std::string& who) |
2117 | 5938 { |
3523 | 5939 std::string retval; |
2117 | 5940 |
5659 | 5941 if (stream_ok ()) |
4468 | 5942 retval = rep->getl (max_len, err, who); |
2117 | 5943 |
5944 return retval; | |
5945 } | |
5946 | |
3536 | 5947 std::string |
4468 | 5948 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
|
5949 const std::string& who) |
2117 | 5950 { |
5951 err = false; | |
5952 | |
5953 int conv_err = 0; | |
5954 | |
6345 | 5955 int max_len = -1; |
5956 | |
5957 if (tc_max_len.is_defined ()) | |
2117 | 5958 { |
6345 | 5959 max_len = convert_to_valid_int (tc_max_len, conv_err); |
5960 | |
5961 if (conv_err || max_len < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5962 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5963 err = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5964 ::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
|
5965 } |
2117 | 5966 } |
6345 | 5967 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5968 return getl (max_len, err, who); |
2117 | 5969 } |
5970 | |
3536 | 5971 std::string |
5275 | 5972 octave_stream::gets (octave_idx_type max_len, bool& err, const std::string& who) |
2117 | 5973 { |
3523 | 5974 std::string retval; |
2117 | 5975 |
5659 | 5976 if (stream_ok ()) |
4468 | 5977 retval = rep->gets (max_len, err, who); |
2117 | 5978 |
5979 return retval; | |
5980 } | |
5981 | |
3536 | 5982 std::string |
4468 | 5983 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
|
5984 const std::string& who) |
2117 | 5985 { |
5986 err = false; | |
5987 | |
5988 int conv_err = 0; | |
5989 | |
6345 | 5990 int max_len = -1; |
5991 | |
5992 if (tc_max_len.is_defined ()) | |
2117 | 5993 { |
6345 | 5994 max_len = convert_to_valid_int (tc_max_len, conv_err); |
5995 | |
5996 if (conv_err || max_len < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5997 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5998 err = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5999 ::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
|
6000 } |
2117 | 6001 } |
6345 | 6002 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6003 return gets (max_len, err, who); |
2117 | 6004 } |
6005 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
6006 off_t |
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
6007 octave_stream::skipl (off_t count, bool& err, const std::string& who) |
9701 | 6008 { |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
6009 off_t retval = -1; |
9701 | 6010 |
6011 if (stream_ok ()) | |
6012 retval = rep->skipl (count, err, who); | |
6013 | |
6014 return retval; | |
6015 } | |
6016 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
6017 off_t |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6018 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
|
6019 const std::string& who) |
9701 | 6020 { |
6021 err = false; | |
6022 | |
6023 int conv_err = 0; | |
6024 | |
6025 int count = 1; | |
6026 | |
6027 if (tc_count.is_defined ()) | |
6028 { | |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21777
diff
changeset
|
6029 if (tc_count.is_scalar_type () && octave::math::isinf (tc_count.scalar_value ())) |
9701 | 6030 count = -1; |
6031 else | |
6032 { | |
6033 count = convert_to_valid_int (tc_count, conv_err); | |
6034 | |
6035 if (conv_err || count < 0) | |
6036 { | |
6037 err = true; | |
6038 ::error ("%s: invalid number of lines specified", who.c_str ()); | |
6039 } | |
6040 } | |
6041 } | |
6042 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6043 return skipl (count, err, who); |
9701 | 6044 } |
6045 | |
2117 | 6046 int |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
6047 octave_stream::seek (off_t offset, int origin) |
2117 | 6048 { |
5065 | 6049 int status = -1; |
2117 | 6050 |
5659 | 6051 if (stream_ok ()) |
4889 | 6052 { |
6053 clearerr (); | |
6054 | |
12957
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
6055 // 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
|
6056 off_t orig_pos = rep->tell (); |
5065 | 6057 |
12957
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
6058 // 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
|
6059 status = rep->seek (0, SEEK_END); |
5065 | 6060 |
6061 if (status == 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6062 { |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
6063 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
|
6064 |
12943
8372d50de75a
improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
6065 if (origin == SEEK_CUR) |
8372d50de75a
improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
6066 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6067 // 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
|
6068 // 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
|
6069 // location. |
12943
8372d50de75a
improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
6070 rep->seek (orig_pos, SEEK_SET); |
8372d50de75a
improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
6071 } |
8372d50de75a
improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
6072 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6073 // 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
|
6074 // existing file. |
12957
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
6075 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
|
6076 |
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
6077 if (status == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6078 { |
12957
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
6079 // 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
|
6080 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
|
6081 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6082 // 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
|
6083 // 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
|
6084 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
|
6085 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6086 // 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
|
6087 // 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
|
6088 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
|
6089 |
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
6090 status = -1; |
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
6091 } |
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
6092 } |
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
6093 else |
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
6094 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6095 // 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
|
6096 // 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
|
6097 rep->seek (orig_pos, SEEK_SET); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6098 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6099 status = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6100 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6101 } |
4889 | 6102 } |
2117 | 6103 |
5065 | 6104 return status; |
2117 | 6105 } |
6106 | |
6107 int | |
6108 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
|
6109 const octave_value& tc_origin) |
2117 | 6110 { |
6111 int retval = -1; | |
6112 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6113 // 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
|
6114 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
|
6115 off_t xoffset = val.value (); |
4645 | 6116 |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6117 int conv_err = 0; |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6118 |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6119 int origin = SEEK_SET; |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6120 |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6121 if (tc_origin.is_string ()) |
2117 | 6122 { |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6123 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
|
6124 |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6125 if (xorigin == "bof") |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6126 origin = SEEK_SET; |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6127 else if (xorigin == "cof") |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6128 origin = SEEK_CUR; |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6129 else if (xorigin == "eof") |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6130 origin = SEEK_END; |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6131 else |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6132 conv_err = -1; |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6133 } |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6134 else |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6135 { |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6136 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
|
6137 |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6138 if (! conv_err) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6139 { |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6140 if (xorigin == -1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6141 origin = SEEK_SET; |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6142 else if (xorigin == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6143 origin = SEEK_CUR; |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6144 else if (xorigin == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6145 origin = SEEK_END; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6146 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6147 conv_err = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6148 } |
2117 | 6149 } |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6150 |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
6151 if (conv_err) |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
6152 ::error ("fseek: invalid value for origin"); |
2117 | 6153 |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
6154 retval = seek (xoffset, origin); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
6155 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
6156 if (retval != 0) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
6157 // 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
|
6158 error ("fseek: failed to seek to requested position"); |
2117 | 6159 |
6160 return retval; | |
6161 } | |
6162 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
6163 off_t |
4797 | 6164 octave_stream::tell (void) |
2117 | 6165 { |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
6166 off_t retval = -1; |
2117 | 6167 |
5659 | 6168 if (stream_ok ()) |
2117 | 6169 retval = rep->tell (); |
6170 | |
6171 return retval; | |
6172 } | |
6173 | |
6174 int | |
6175 octave_stream::rewind (void) | |
6176 { | |
6296 | 6177 return seek (0, SEEK_SET); |
2117 | 6178 } |
6179 | |
3340 | 6180 bool |
6181 octave_stream::is_open (void) const | |
6182 { | |
6183 bool retval = false; | |
6184 | |
5659 | 6185 if (stream_ok ()) |
3340 | 6186 retval = rep->is_open (); |
6187 | |
6188 return retval; | |
6189 } | |
6190 | |
6191 void | |
6192 octave_stream::close (void) | |
6193 { | |
5659 | 6194 if (stream_ok ()) |
3340 | 6195 rep->close (); |
6196 } | |
6197 | |
21335
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6198 // 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
|
6199 |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6200 template <typename T> |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6201 static inline bool |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6202 is_old_NA (T) |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6203 { |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6204 return false; |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6205 } |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6206 |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6207 template <> |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6208 inline bool |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6209 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
|
6210 { |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6211 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
|
6212 } |
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 template <typename T> |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6215 static inline T |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6216 replace_old_NA (T val) |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6217 { |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6218 return val; |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6219 } |
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 template <> |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6222 inline double |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6223 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
|
6224 { |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6225 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
|
6226 } |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6227 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
6228 template <typename SRC_T, typename DST_T> |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6229 static octave_value |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6230 convert_and_copy (std::list<void *>& input_buf_list, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6231 octave_idx_type input_buf_elts, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6232 octave_idx_type elts_read, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6233 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
|
6234 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
|
6235 octave::mach_info::float_format from_flt_fmt) |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6236 { |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6237 typedef typename DST_T::element_type dst_elt_type; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6238 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6239 DST_T conv (dim_vector (nr, nc)); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6240 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6241 dst_elt_type *conv_data = conv.fortran_vec (); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6242 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6243 octave_idx_type j = 0; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6244 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6245 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
|
6246 it != input_buf_list.end (); it++) |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6247 { |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6248 SRC_T *data = static_cast<SRC_T *> (*it); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6249 |
17463 | 6250 if (swap || do_float_fmt_conv) |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6251 { |
21335
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6252 if (do_NA_conv) |
17463 | 6253 { |
21335
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6254 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
|
6255 i++, j++) |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6256 { |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6257 if (swap) |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6258 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
|
6259 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
|
6260 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
|
6261 1, from_flt_fmt, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6262 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
|
6263 |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6264 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
|
6265 |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6266 if (is_old_NA (tmp)) |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6267 tmp = replace_old_NA (tmp); |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6268 |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6269 conv_data[j] = tmp; |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6270 } |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6271 } |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6272 else |
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 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
|
6275 i++, j++) |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6276 { |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6277 if (swap) |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6278 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
|
6279 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
|
6280 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
|
6281 1, from_flt_fmt, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6282 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
|
6283 |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6284 conv_data[j] = data[i]; |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6285 } |
17463 | 6286 } |
6287 } | |
6288 else | |
6289 { | |
6290 if (do_NA_conv) | |
6291 { | |
6292 for (octave_idx_type i = 0; i < input_buf_elts && j < elts_read; | |
6293 i++, j++) | |
6294 { | |
6295 dst_elt_type tmp (data[i]); | |
6296 | |
21335
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6297 if (is_old_NA (tmp)) |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6298 tmp = replace_old_NA (tmp); |
17463 | 6299 |
6300 conv_data[j] = tmp; | |
6301 } | |
6302 } | |
6303 else | |
6304 { | |
6305 for (octave_idx_type i = 0; i < input_buf_elts && j < elts_read; | |
6306 i++, j++) | |
6307 conv_data[j] = data[i]; | |
6308 } | |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6309 } |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6310 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6311 delete [] data; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6312 } |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6313 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6314 input_buf_list.clear (); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6315 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6316 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
|
6317 conv_data[i] = dst_elt_type (0); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6318 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6319 return conv; |
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 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6322 typedef octave_value (*conv_fptr) |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6323 (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
|
6324 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
|
6325 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
|
6326 octave::mach_info::float_format from_flt_fmt); |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6327 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6328 #define TABLE_ELT(T, U, V, W) \ |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6329 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
|
6330 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6331 #define FILL_TABLE_ROW(T, V) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6332 TABLE_ELT (T, dt_int8, V, int8NDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6333 TABLE_ELT (T, dt_uint8, V, uint8NDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6334 TABLE_ELT (T, dt_int16, V, int16NDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6335 TABLE_ELT (T, dt_uint16, V, uint16NDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6336 TABLE_ELT (T, dt_int32, V, int32NDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6337 TABLE_ELT (T, dt_uint32, V, uint32NDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6338 TABLE_ELT (T, dt_int64, V, int64NDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6339 TABLE_ELT (T, dt_uint64, V, uint64NDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6340 TABLE_ELT (T, dt_single, V, FloatNDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6341 TABLE_ELT (T, dt_double, V, NDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6342 TABLE_ELT (T, dt_char, V, charNDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6343 TABLE_ELT (T, dt_schar, V, charNDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6344 TABLE_ELT (T, dt_uchar, V, charNDArray); \ |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6345 TABLE_ELT (T, dt_logical, V, boolNDArray); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6346 |
2117 | 6347 octave_value |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6348 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
|
6349 octave_idx_type input_buf_elts, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6350 octave_idx_type elts_read, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6351 octave_idx_type nr, octave_idx_type nc, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6352 oct_data_conv::data_type input_type, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6353 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
|
6354 octave::mach_info::float_format ffmt) |
2117 | 6355 { |
6356 octave_value retval; | |
6357 | |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6358 static bool initialized = false; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6359 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6360 // Table function pointers for return types x read types. |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6361 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6362 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
|
6363 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6364 if (! initialized) |
4944 | 6365 { |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6366 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
|
6367 for (int j = 0; j < 14; j++) |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6368 conv_fptr_table[i][j] = 0; |
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 FILL_TABLE_ROW (dt_int8, int8_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6371 FILL_TABLE_ROW (dt_uint8, uint8_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6372 FILL_TABLE_ROW (dt_int16, int16_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6373 FILL_TABLE_ROW (dt_uint16, uint16_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6374 FILL_TABLE_ROW (dt_int32, int32_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6375 FILL_TABLE_ROW (dt_uint32, uint32_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6376 FILL_TABLE_ROW (dt_int64, int64_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6377 FILL_TABLE_ROW (dt_uint64, uint64_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6378 FILL_TABLE_ROW (dt_single, float); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6379 FILL_TABLE_ROW (dt_double, double); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6380 FILL_TABLE_ROW (dt_char, char); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6381 FILL_TABLE_ROW (dt_schar, signed char); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6382 FILL_TABLE_ROW (dt_uchar, unsigned char); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6383 FILL_TABLE_ROW (dt_logical, bool); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6384 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6385 initialized = true; |
4944 | 6386 } |
6387 | |
6388 bool swap = false; | |
6389 | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6390 if (ffmt == octave::mach_info::flt_fmt_unknown) |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6391 ffmt = float_format (); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6392 |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6393 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
|
6394 swap = (ffmt == octave::mach_info::flt_fmt_ieee_little_endian); |
4944 | 6395 else |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6396 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
|
6397 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6398 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
|
6399 || input_type == oct_data_conv::dt_single) |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6400 && ffmt != float_format ()); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6401 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6402 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
|
6403 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6404 switch (output_type) |
4944 | 6405 { |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6406 case oct_data_conv::dt_int8: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6407 case oct_data_conv::dt_uint8: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6408 case oct_data_conv::dt_int16: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6409 case oct_data_conv::dt_uint16: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6410 case oct_data_conv::dt_int32: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6411 case oct_data_conv::dt_uint32: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6412 case oct_data_conv::dt_int64: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6413 case oct_data_conv::dt_uint64: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6414 case oct_data_conv::dt_single: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6415 case oct_data_conv::dt_double: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6416 case oct_data_conv::dt_char: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6417 case oct_data_conv::dt_schar: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6418 case oct_data_conv::dt_uchar: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6419 case oct_data_conv::dt_logical: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6420 { |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6421 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
|
6422 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6423 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
|
6424 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
|
6425 } |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6426 break; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6427 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6428 default: |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
6429 ::error ("read: invalid type specification"); |
4944 | 6430 } |
6431 | |
6432 return retval; | |
6433 } | |
6434 | |
6435 octave_value | |
5275 | 6436 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
|
6437 oct_data_conv::data_type input_type, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6438 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
|
6439 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
|
6440 octave_idx_type& count) |
4944 | 6441 { |
6442 octave_value retval; | |
6443 | |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6444 octave_idx_type nr = -1; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6445 octave_idx_type nc = -1; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6446 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6447 bool one_elt_size_spec = false; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6448 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6449 if (! stream_ok ()) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6450 return retval; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6451 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6452 // 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
|
6453 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6454 // 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
|
6455 // 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
|
6456 // 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
|
6457 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6458 // 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
|
6459 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
|
6460 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6461 count = 0; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6462 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6463 try |
4944 | 6464 { |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6465 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
|
6466 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
6467 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
|
6468 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6469 invalid_operation ("fread", "reading"); |
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 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6472 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
|
6473 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6474 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
|
6475 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6476 // 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
|
6477 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6478 // 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
|
6479 // number of rows. |
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 // 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
|
6482 // 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
|
6483 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6484 if (nr == 0) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6485 nr = nc = 0; |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
6486 else |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6487 nc = 1; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6488 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6489 else |
4944 | 6490 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6491 // 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
|
6492 // 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
|
6493 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6494 // 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
|
6495 // should be. |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6496 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6497 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
|
6498 nr = nc = 0; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6499 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6500 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6501 // 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
|
6502 // 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
|
6503 // 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
|
6504 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
|
6505 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6506 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
|
6507 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6508 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
|
6509 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6510 if (skip == 0) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6511 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6512 if (read_to_eof) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6513 input_buf_elts = 1024 * 1024; |
4944 | 6514 else |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6515 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
|
6516 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6517 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6518 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
|
6519 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6520 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
|
6521 = 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
|
6522 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6523 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
|
6524 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6525 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
|
6526 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6527 // 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
|
6528 // 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
|
6529 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
|
6530 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6531 if (! isp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6532 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
|
6533 else |
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 std::istream& is = *isp; |
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 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
|
6538 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6539 while (is && ! is.eof () |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6540 && (read_to_eof || count < elts_to_read)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6541 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6542 if (! read_to_eof) |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6543 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6544 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
|
6545 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6546 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
|
6547 input_buf_size = remaining_elts * input_elt_size; |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6548 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6549 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6550 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
|
6551 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6552 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
|
6553 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6554 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
|
6555 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6556 char_count += gcount; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6557 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6558 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
|
6559 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6560 count += nel; |
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 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
|
6563 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6564 if (is && skip != 0 && nel == block_size) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6565 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6566 // Seek to skip. |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6567 // 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
|
6568 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6569 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
|
6570 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6571 seek (0, SEEK_END); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6572 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6573 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
|
6574 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6575 // 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
|
6576 // the original position? |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6577 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
|
6578 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6579 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
|
6580 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6581 if (remaining < skip) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6582 seek (0, SEEK_END); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6583 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6584 seek (skip, SEEK_CUR); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6585 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6586 if (! is) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6587 break; |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6588 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6589 } |
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 (read_to_eof) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6592 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6593 if (nc < 0) |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6594 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6595 nc = count / nr; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6596 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
6597 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
|
6598 nc++; |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6599 } |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6600 else |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6601 nr = count; |
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 else if (count == 0) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6604 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6605 nr = 0; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6606 nc = 0; |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
6607 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6608 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
|
6609 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6610 if (count % nr != 0) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6611 nc = count / nr + 1; |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6612 else |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6613 nc = count / nr; |
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 if (count < nr) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6616 nr = count; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
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 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6619 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
|
6620 nr, nc, input_type, output_type, ffmt); |
4944 | 6621 } |
2117 | 6622 |
6623 return retval; | |
6624 } | |
6625 | |
5275 | 6626 octave_idx_type |
6627 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
|
6628 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
|
6629 octave_idx_type skip, octave::mach_info::float_format flt_fmt) |
2117 | 6630 { |
5275 | 6631 octave_idx_type retval = -1; |
2117 | 6632 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6633 if (! stream_ok ()) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6634 invalid_operation ("fwrite", "writing"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6635 else |
4944 | 6636 { |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6637 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
|
6638 flt_fmt = float_format (); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
6639 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
6640 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
|
6641 skip, flt_fmt); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
6642 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
6643 if (status < 0) |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
6644 error ("fwrite: write error"); |
4944 | 6645 else |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
6646 retval = status; |
4944 | 6647 } |
2117 | 6648 |
6649 return retval; | |
6650 } | |
6651 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
6652 template <typename T, typename V> |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6653 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
|
6654 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
|
6655 { |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6656 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
|
6657 |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6658 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
|
6659 |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6660 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
|
6661 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
|
6662 } |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6663 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
6664 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
|
6665 static void |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6666 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
|
6667 bool swap) |
4944 | 6668 { |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6669 typedef typename V::val_type val_type; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6670 |
19739
3fa35defe495
Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19729
diff
changeset
|
6671 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
|
6672 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6673 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
|
6674 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6675 // 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
|
6676 V val (data[i]); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6677 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6678 vt_data[i] = val.value (); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6679 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6680 if (swap) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6681 swap_bytes<sizeof (val_type)> (&vt_data[i]); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6682 } |
4944 | 6683 } |
6684 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
6685 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
|
6686 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
|
6687 { |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6688 public: |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6689 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
|
6690 }; |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6691 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
6692 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
|
6693 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
|
6694 { |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6695 public: |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6696 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
|
6697 }; |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6698 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
6699 template <typename T> |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6700 static bool |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6701 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
|
6702 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
|
6703 octave::mach_info::float_format flt_fmt) |
4944 | 6704 { |
6705 bool retval = true; | |
6706 | |
21776
1e81dd035639
Write integers with correct byte order on big-endian systems (bug #47434)
Mike Miller <mtmiller@octave.org>
parents:
21296
diff
changeset
|
6707 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
|
6708 |
21777
d6826b38b29c
maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
diff
changeset
|
6709 if (octave::mach_info::words_big_endian ()) |
d6826b38b29c
maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
diff
changeset
|
6710 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
|
6711 else |
21777
d6826b38b29c
maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
diff
changeset
|
6712 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
|
6713 |
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6714 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
|
6715 |
18616
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6716 typedef typename ultimate_element_type<T>::type ult_elt_type; |
4944 | 6717 |
6718 switch (output_type) | |
6719 { | |
6720 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
|
6721 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
|
6722 break; |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6723 |
4944 | 6724 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
|
6725 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
|
6726 break; |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6727 |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6728 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
|
6729 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
|
6730 break; |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6731 |
4944 | 6732 case oct_data_conv::dt_int8: |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6733 convert_ints<T, octave_int8> (data, conv_data, n_elts, swap); |
4944 | 6734 break; |
6735 | |
6736 case oct_data_conv::dt_uint8: | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6737 convert_ints<T, octave_uint8> (data, conv_data, n_elts, swap); |
4944 | 6738 break; |
6739 | |
6740 case oct_data_conv::dt_int16: | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6741 convert_ints<T, octave_int16> (data, conv_data, n_elts, swap); |
4944 | 6742 break; |
6743 | |
6744 case oct_data_conv::dt_uint16: | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6745 convert_ints<T, octave_uint16> (data, conv_data, n_elts, swap); |
4944 | 6746 break; |
6747 | |
6748 case oct_data_conv::dt_int32: | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6749 convert_ints<T, octave_int32> (data, conv_data, n_elts, swap); |
4944 | 6750 break; |
6751 | |
6752 case oct_data_conv::dt_uint32: | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6753 convert_ints<T, octave_uint32> (data, conv_data, n_elts, swap); |
4944 | 6754 break; |
6755 | |
6756 case oct_data_conv::dt_int64: | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6757 convert_ints<T, octave_int64> (data, conv_data, n_elts, swap); |
4944 | 6758 break; |
6759 | |
6760 case oct_data_conv::dt_uint64: | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6761 convert_ints<T, octave_uint64> (data, conv_data, n_elts, swap); |
4944 | 6762 break; |
6763 | |
6764 case oct_data_conv::dt_single: | |
6765 { | |
19739
3fa35defe495
Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19729
diff
changeset
|
6766 float *vt_data = static_cast<float *> (conv_data); |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6767 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6768 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
|
6769 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6770 vt_data[i] = data[i]; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6771 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6772 if (do_float_conversion) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6773 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
|
6774 } |
4944 | 6775 } |
6776 break; | |
6777 | |
6778 case oct_data_conv::dt_double: | |
6779 { | |
19739
3fa35defe495
Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19729
diff
changeset
|
6780 double *vt_data = static_cast<double *> (conv_data); |
17416
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 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
|
6783 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6784 vt_data[i] = data[i]; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6785 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6786 if (do_float_conversion) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6787 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
|
6788 } |
4944 | 6789 } |
6790 break; | |
6791 | |
6792 default: | |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
6793 ::error ("write: invalid type specification"); |
4944 | 6794 } |
6795 | |
6796 return retval; | |
6797 } | |
6798 | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6799 bool |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6800 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
|
6801 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6802 bool status = false; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6803 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6804 std::ostream *osp = output_stream (); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6805 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6806 if (osp) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6807 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6808 std::ostream& os = *osp; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6809 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6810 if (os) |
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 os.write (static_cast<const char *> (data), nbytes); |
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 if (os) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6815 status = true; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6816 } |
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 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6819 return status; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6820 } |
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 bool |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6823 octave_stream::skip_bytes (size_t skip) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6824 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6825 bool status = false; |
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 std::ostream *osp = output_stream (); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6828 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6829 if (! osp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6830 return false; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6831 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6832 std::ostream& os = *osp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6833 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6834 // 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
|
6835 // 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
|
6836 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
|
6837 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6838 seek (0, SEEK_END); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6839 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6840 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
|
6841 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6842 // 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
|
6843 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
|
6844 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6845 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
|
6846 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6847 if (remaining < skip) |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6848 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6849 seek (0, SEEK_END); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6850 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6851 // 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
|
6852 unsigned char zero = 0; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6853 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
|
6854 os.write (reinterpret_cast<const char *> (&zero), 1); |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6855 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6856 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6857 seek (skip, SEEK_CUR); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6858 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6859 if (os) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6860 status = true; |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6861 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6862 return status; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6863 } |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6864 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
6865 template <typename T> |
5275 | 6866 octave_idx_type |
6867 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
|
6868 oct_data_conv::data_type output_type, |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6869 octave_idx_type skip, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6870 octave::mach_info::float_format flt_fmt) |
4944 | 6871 { |
21776
1e81dd035639
Write integers with correct byte order on big-endian systems (bug #47434)
Mike Miller <mtmiller@octave.org>
parents:
21296
diff
changeset
|
6872 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
|
6873 |
21777
d6826b38b29c
maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
diff
changeset
|
6874 if (octave::mach_info::words_big_endian ()) |
d6826b38b29c
maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
diff
changeset
|
6875 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
|
6876 else |
21777
d6826b38b29c
maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
diff
changeset
|
6877 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
|
6878 |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6879 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
|
6880 || flt_fmt != octave::mach_info::float_format ()); |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6881 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6882 octave_idx_type nel = data.numel (); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6883 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6884 octave_idx_type chunk_size; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6885 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6886 if (skip != 0) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6887 chunk_size = block_size; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6888 else if (do_data_conversion) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6889 chunk_size = 1024 * 1024; |
4944 | 6890 else |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6891 chunk_size = nel; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6892 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6893 octave_idx_type i = 0; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6894 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6895 const T *pdata = data.data (); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6896 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6897 while (i < nel) |
4944 | 6898 { |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6899 if (skip != 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6900 { |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6901 if (! skip_bytes (skip)) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6902 return -1; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6903 } |
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 octave_idx_type remaining_nel = nel - i; |
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 if (chunk_size > remaining_nel) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6908 chunk_size = remaining_nel; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6909 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6910 bool status = false; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6911 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6912 if (do_data_conversion) |
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 size_t output_size |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6915 = 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
|
6916 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6917 OCTAVE_LOCAL_BUFFER (unsigned char, conv_data, output_size); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6918 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6919 status = convert_data (&pdata[i], conv_data, chunk_size, |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6920 output_type, flt_fmt); |
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 (status) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6923 status = write_bytes (conv_data, output_size); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6924 } |
4944 | 6925 else |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6926 status = write_bytes (pdata, sizeof (T) * chunk_size); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6927 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6928 if (! status) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6929 return -1; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6930 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6931 i += chunk_size; |
4944 | 6932 } |
6933 | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6934 return nel; |
4944 | 6935 } |
6936 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6937 #define INSTANTIATE_WRITE(T) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6938 template \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6939 octave_idx_type \ |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6940 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
|
6941 oct_data_conv::data_type output_type, \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6942 octave_idx_type skip, \ |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6943 octave::mach_info::float_format flt_fmt) |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6944 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6945 INSTANTIATE_WRITE (octave_int8); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6946 INSTANTIATE_WRITE (octave_uint8); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6947 INSTANTIATE_WRITE (octave_int16); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6948 INSTANTIATE_WRITE (octave_uint16); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6949 INSTANTIATE_WRITE (octave_int32); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6950 INSTANTIATE_WRITE (octave_uint32); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6951 INSTANTIATE_WRITE (octave_int64); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6952 INSTANTIATE_WRITE (octave_uint64); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6953 INSTANTIATE_WRITE (int8_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6954 INSTANTIATE_WRITE (uint8_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6955 INSTANTIATE_WRITE (int16_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6956 INSTANTIATE_WRITE (uint16_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6957 INSTANTIATE_WRITE (int32_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6958 INSTANTIATE_WRITE (uint32_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6959 INSTANTIATE_WRITE (int64_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6960 INSTANTIATE_WRITE (uint64_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6961 INSTANTIATE_WRITE (bool); |
21354
06d15e4e611a
move public data type macros to octave-config.h
John W. Eaton <jwe@octave.org>
parents:
21335
diff
changeset
|
6962 #if defined (OCTAVE_HAVE_OVERLOAD_CHAR_INT8_TYPES) |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6963 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
|
6964 #endif |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6965 INSTANTIATE_WRITE (float); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6966 INSTANTIATE_WRITE (double); |
4944 | 6967 |
2117 | 6968 octave_value |
3810 | 6969 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
|
6970 octave_idx_type& count, const std::string& who) |
2117 | 6971 { |
6972 octave_value retval; | |
6973 | |
5659 | 6974 if (stream_ok ()) |
4468 | 6975 retval = rep->scanf (fmt, size, count, who); |
2117 | 6976 |
6977 return retval; | |
6978 } | |
6979 | |
5279 | 6980 octave_value |
6981 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
|
6982 octave_idx_type& count, const std::string& who) |
5279 | 6983 { |
6984 octave_value retval = Matrix (); | |
6985 | |
6986 if (fmt.is_string ()) | |
6987 { | |
6988 std::string sfmt = fmt.string_value (); | |
6989 | |
6990 if (fmt.is_sq_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6991 sfmt = do_string_escapes (sfmt); |
5279 | 6992 |
6993 retval = scanf (sfmt, size, count, who); | |
6994 } | |
6995 else | |
6996 { | |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
6997 // Note: error is member fcn from octave_stream, not ::error. |
5279 | 6998 error (who + ": format must be a string"); |
6999 } | |
7000 | |
7001 return retval; | |
7002 } | |
7003 | |
2215 | 7004 octave_value_list |
4468 | 7005 octave_stream::oscanf (const std::string& fmt, const std::string& who) |
2215 | 7006 { |
7007 octave_value_list retval; | |
7008 | |
5659 | 7009 if (stream_ok ()) |
4468 | 7010 retval = rep->oscanf (fmt, who); |
2215 | 7011 |
7012 return retval; | |
7013 } | |
7014 | |
5279 | 7015 octave_value_list |
7016 octave_stream::oscanf (const octave_value& fmt, const std::string& who) | |
7017 { | |
7018 octave_value_list retval; | |
7019 | |
7020 if (fmt.is_string ()) | |
7021 { | |
7022 std::string sfmt = fmt.string_value (); | |
7023 | |
7024 if (fmt.is_sq_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7025 sfmt = do_string_escapes (sfmt); |
5279 | 7026 |
7027 retval = oscanf (sfmt, who); | |
7028 } | |
7029 else | |
7030 { | |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
7031 // Note: error is member fcn from octave_stream, not ::error. |
5279 | 7032 error (who + ": format must be a string"); |
7033 } | |
7034 | |
7035 return retval; | |
7036 } | |
7037 | |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
7038 octave_value |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
7039 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
|
7040 const octave_value_list& options, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
7041 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
|
7042 { |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
7043 return (stream_ok () |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
7044 ? 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
|
7045 : octave_value ()); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
7046 } |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
7047 |
2117 | 7048 int |
4468 | 7049 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
|
7050 const std::string& who) |
2117 | 7051 { |
7052 int retval = -1; | |
7053 | |
5659 | 7054 if (stream_ok ()) |
4468 | 7055 retval = rep->printf (fmt, args, who); |
2117 | 7056 |
7057 return retval; | |
7058 } | |
7059 | |
7060 int | |
5279 | 7061 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
|
7062 const std::string& who) |
5279 | 7063 { |
7064 int retval = 0; | |
7065 | |
7066 if (fmt.is_string ()) | |
7067 { | |
7068 std::string sfmt = fmt.string_value (); | |
7069 | |
7070 if (fmt.is_sq_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7071 sfmt = do_string_escapes (sfmt); |
5279 | 7072 |
7073 retval = printf (sfmt, args, who); | |
7074 } | |
7075 else | |
7076 { | |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
7077 // Note: error is member fcn from octave_stream, not ::error. |
5279 | 7078 error (who + ": format must be a string"); |
7079 } | |
7080 | |
7081 return retval; | |
7082 } | |
7083 | |
7084 int | |
4468 | 7085 octave_stream::puts (const std::string& s, const std::string& who) |
2117 | 7086 { |
7087 int retval = -1; | |
7088 | |
5659 | 7089 if (stream_ok ()) |
4468 | 7090 retval = rep->puts (s, who); |
2117 | 7091 |
7092 return retval; | |
7093 } | |
7094 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7095 // FIXME: maybe this should work for string arrays too. |
2117 | 7096 |
7097 int | |
4468 | 7098 octave_stream::puts (const octave_value& tc_s, const std::string& who) |
2117 | 7099 { |
7100 int retval = -1; | |
7101 | |
7102 if (tc_s.is_string ()) | |
7103 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
7104 std::string s = tc_s.string_value (); |
5279 | 7105 retval = puts (s, who); |
2117 | 7106 } |
7107 else | |
4468 | 7108 { |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
7109 // Note: error is member fcn from octave_stream, not ::error. |
4468 | 7110 error (who + ": argument must be a string"); |
7111 } | |
2117 | 7112 |
7113 return retval; | |
7114 } | |
7115 | |
7116 bool | |
7117 octave_stream::eof (void) const | |
7118 { | |
7119 int retval = -1; | |
7120 | |
5659 | 7121 if (stream_ok ()) |
2117 | 7122 retval = rep->eof (); |
7123 | |
7124 return retval; | |
7125 } | |
7126 | |
3536 | 7127 std::string |
2435 | 7128 octave_stream::error (bool clear, int& err_num) |
2117 | 7129 { |
5649 | 7130 std::string retval = "invalid stream object"; |
7131 | |
5659 | 7132 if (stream_ok (false)) |
2435 | 7133 retval = rep->error (clear, err_num); |
2117 | 7134 |
7135 return retval; | |
7136 } | |
7137 | |
3536 | 7138 std::string |
3340 | 7139 octave_stream::name (void) const |
2117 | 7140 { |
3523 | 7141 std::string retval; |
2117 | 7142 |
5659 | 7143 if (stream_ok ()) |
2117 | 7144 retval = rep->name (); |
7145 | |
7146 return retval; | |
7147 } | |
7148 | |
7149 int | |
3340 | 7150 octave_stream::mode (void) const |
2117 | 7151 { |
7152 int retval = 0; | |
7153 | |
5659 | 7154 if (stream_ok ()) |
2117 | 7155 retval = rep->mode (); |
7156 | |
7157 return retval; | |
7158 } | |
7159 | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
7160 octave::mach_info::float_format |
3340 | 7161 octave_stream::float_format (void) const |
2117 | 7162 { |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
7163 octave::mach_info::float_format retval = octave::mach_info::flt_fmt_unknown; |
2317 | 7164 |
5659 | 7165 if (stream_ok ()) |
2317 | 7166 retval = rep->float_format (); |
2117 | 7167 |
7168 return retval; | |
7169 } | |
7170 | |
3536 | 7171 std::string |
2117 | 7172 octave_stream::mode_as_string (int mode) |
7173 { | |
3523 | 7174 std::string retval = "???"; |
3775 | 7175 std::ios::openmode in_mode = static_cast<std::ios::openmode> (mode); |
7176 | |
7177 if (in_mode == std::ios::in) | |
7178 retval = "r"; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
7179 else if (in_mode == std::ios::out |
4078 | 7180 || in_mode == (std::ios::out | std::ios::trunc)) |
3775 | 7181 retval = "w"; |
4078 | 7182 else if (in_mode == (std::ios::out | std::ios::app)) |
3775 | 7183 retval = "a"; |
4078 | 7184 else if (in_mode == (std::ios::in | std::ios::out)) |
3775 | 7185 retval = "r+"; |
4078 | 7186 else if (in_mode == (std::ios::in | std::ios::out | std::ios::trunc)) |
3775 | 7187 retval = "w+"; |
4078 | 7188 else if (in_mode == (std::ios::in | std::ios::out | std::ios::ate)) |
3775 | 7189 retval = "a+"; |
4078 | 7190 else if (in_mode == (std::ios::in | std::ios::binary)) |
3775 | 7191 retval = "rb"; |
4078 | 7192 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
|
7193 || in_mode == (std::ios::out | std::ios::trunc | std::ios::binary)) |
3775 | 7194 retval = "wb"; |
4078 | 7195 else if (in_mode == (std::ios::out | std::ios::app | std::ios::binary)) |
3775 | 7196 retval = "ab"; |
4078 | 7197 else if (in_mode == (std::ios::in | std::ios::out | std::ios::binary)) |
3775 | 7198 retval = "r+b"; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
7199 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
|
7200 | std::ios::binary)) |
3775 | 7201 retval = "w+b"; |
4078 | 7202 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
|
7203 | std::ios::binary)) |
3775 | 7204 retval = "a+b"; |
2117 | 7205 |
7206 return retval; | |
7207 } | |
7208 | |
7209 octave_stream_list *octave_stream_list::instance = 0; | |
7210 | |
2926 | 7211 bool |
7212 octave_stream_list::instance_ok (void) | |
7213 { | |
7214 bool retval = true; | |
7215 | |
7216 if (! instance) | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13271
diff
changeset
|
7217 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13271
diff
changeset
|
7218 instance = new octave_stream_list (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13271
diff
changeset
|
7219 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13271
diff
changeset
|
7220 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13271
diff
changeset
|
7221 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
|
7222 } |
2926 | 7223 |
7224 if (! instance) | |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20768
diff
changeset
|
7225 ::error ("unable to create stream list object!"); |
2926 | 7226 |
7227 return retval; | |
7228 } | |
7229 | |
5353 | 7230 int |
6757 | 7231 octave_stream_list::insert (octave_stream& os) |
2926 | 7232 { |
5353 | 7233 return (instance_ok ()) ? instance->do_insert (os) : -1; |
2926 | 7234 } |
7235 | |
3340 | 7236 octave_stream |
3523 | 7237 octave_stream_list::lookup (int fid, const std::string& who) |
2926 | 7238 { |
3341 | 7239 return (instance_ok ()) ? instance->do_lookup (fid, who) : octave_stream (); |
2926 | 7240 } |
7241 | |
3340 | 7242 octave_stream |
3523 | 7243 octave_stream_list::lookup (const octave_value& fid, const std::string& who) |
2926 | 7244 { |
3341 | 7245 return (instance_ok ()) ? instance->do_lookup (fid, who) : octave_stream (); |
2926 | 7246 } |
7247 | |
7248 int | |
3523 | 7249 octave_stream_list::remove (int fid, const std::string& who) |
2926 | 7250 { |
3341 | 7251 return (instance_ok ()) ? instance->do_remove (fid, who) : -1; |
2926 | 7252 } |
7253 | |
7254 int | |
3523 | 7255 octave_stream_list::remove (const octave_value& fid, const std::string& who) |
2926 | 7256 { |
3341 | 7257 return (instance_ok ()) ? instance->do_remove (fid, who) : -1; |
2926 | 7258 } |
7259 | |
7260 void | |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7261 octave_stream_list::clear (bool flush) |
2926 | 7262 { |
7263 if (instance) | |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7264 instance->do_clear (flush); |
2926 | 7265 } |
7266 | |
7267 string_vector | |
7268 octave_stream_list::get_info (int fid) | |
7269 { | |
7270 return (instance_ok ()) ? instance->do_get_info (fid) : string_vector (); | |
7271 } | |
7272 | |
7273 string_vector | |
7274 octave_stream_list::get_info (const octave_value& fid) | |
7275 { | |
7276 return (instance_ok ()) ? instance->do_get_info (fid) : string_vector (); | |
7277 } | |
7278 | |
3536 | 7279 std::string |
2926 | 7280 octave_stream_list::list_open_files (void) |
7281 { | |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20982
diff
changeset
|
7282 return (instance_ok ()) ? instance->do_list_open_files () : ""; |
2926 | 7283 } |
7284 | |
7285 octave_value | |
7286 octave_stream_list::open_file_numbers (void) | |
7287 { | |
7288 return (instance_ok ()) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7289 ? instance->do_open_file_numbers () : octave_value (); |
2926 | 7290 } |
7291 | |
7292 int | |
7293 octave_stream_list::get_file_number (const octave_value& fid) | |
7294 { | |
7295 return (instance_ok ()) ? instance->do_get_file_number (fid) : -1; | |
7296 } | |
7297 | |
5353 | 7298 int |
6757 | 7299 octave_stream_list::do_insert (octave_stream& os) |
2117 | 7300 { |
6757 | 7301 // Insert item with key corresponding to file-descriptor. |
7302 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
7303 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
|
7304 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
7305 if (stream_number == -1) |
6757 | 7306 return stream_number; |
7307 | |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
7308 // 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
|
7309 // |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
7310 // (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
|
7311 // && 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
|
7312 // |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
7313 // 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
|
7314 // 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
|
7315 // 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
|
7316 // 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
|
7317 // 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
|
7318 // 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
|
7319 // before. |
6757 | 7320 |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7321 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
|
7322 ::error ("could not create file id"); |
2117 | 7323 |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7324 list[stream_number] = os; |
2117 | 7325 |
5353 | 7326 return stream_number; |
2117 | 7327 } |
7328 | |
21040
3e7cfee5f786
maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents:
21029
diff
changeset
|
7329 OCTAVE_NORETURN static |
21029
e3b3bb522d62
maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
7330 void |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
7331 err_invalid_file_id (int fid, const std::string& who) |
3341 | 7332 { |
7333 if (who.empty ()) | |
7334 ::error ("invalid stream number = %d", fid); | |
7335 else | |
7336 ::error ("%s: invalid stream number = %d", who.c_str (), fid); | |
7337 } | |
7338 | |
3340 | 7339 octave_stream |
3523 | 7340 octave_stream_list::do_lookup (int fid, const std::string& who) const |
2117 | 7341 { |
3340 | 7342 octave_stream retval; |
2117 | 7343 |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7344 if (fid < 0) |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
7345 err_invalid_file_id (fid, who); |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7346 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7347 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
|
7348 retval = lookup_cache->second; |
3341 | 7349 else |
6757 | 7350 { |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7351 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
|
7352 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7353 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
|
7354 err_invalid_file_id (fid, who); |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7355 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7356 retval = iter->second; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7357 lookup_cache = iter; |
6757 | 7358 } |
2117 | 7359 |
7360 return retval; | |
7361 } | |
7362 | |
3340 | 7363 octave_stream |
3341 | 7364 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
|
7365 const std::string& who) const |
2117 | 7366 { |
7367 int i = get_file_number (fid); | |
7368 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
7369 return do_lookup (i, who); |
2117 | 7370 } |
7371 | |
7372 int | |
3523 | 7373 octave_stream_list::do_remove (int fid, const std::string& who) |
2117 | 7374 { |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7375 // 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
|
7376 if (fid < 3) |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
7377 err_invalid_file_id (fid, who); |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7378 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7379 ostrl_map::iterator iter = list.find (fid); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7380 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7381 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
|
7382 err_invalid_file_id (fid, who); |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7383 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7384 octave_stream os = iter->second; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7385 list.erase (iter); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7386 lookup_cache = list.end (); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7387 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7388 // FIXME: is this check redundant? |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7389 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
|
7390 err_invalid_file_id (fid, who); |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7391 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7392 os.close (); |
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 return 0; |
2117 | 7395 } |
7396 | |
7397 int | |
3523 | 7398 octave_stream_list::do_remove (const octave_value& fid, const std::string& who) |
2117 | 7399 { |
7400 int retval = -1; | |
7401 | |
6054 | 7402 if (fid.is_string () && fid.string_value () == "all") |
7403 { | |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7404 do_clear (false); |
6054 | 7405 |
7406 retval = 0; | |
7407 } | |
7408 else | |
7409 { | |
7410 int i = get_file_number (fid); | |
7411 | |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
7412 retval = do_remove (i, who); |
6054 | 7413 } |
2117 | 7414 |
7415 return retval; | |
7416 } | |
7417 | |
7418 void | |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7419 octave_stream_list::do_clear (bool flush) |
2117 | 7420 { |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7421 if (flush) |
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7422 { |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7423 // Flush stdout and stderr. |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7424 list[1].flush (); |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7425 list[2].flush (); |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7426 } |
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7427 |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7428 for (ostrl_map::iterator iter = list.begin (); iter != list.end (); ) |
6757 | 7429 { |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7430 int fid = iter->first; |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7431 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
|
7432 { |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7433 iter++; |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7434 continue; |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7435 } |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7436 |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7437 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
|
7438 |
7655b399abff
eliminate trailing whitespace in source files we maintain
John W. Eaton <jwe@octave.org>
parents:
20764
diff
changeset
|
7439 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
|
7440 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
|
7441 |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7442 // 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
|
7443 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
|
7444 { |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7445 // 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
|
7446 iter++; |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7447 continue; |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7448 } |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7449 |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7450 // 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
|
7451 if (os.is_valid ()) |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7452 os.close (); |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7453 |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7454 list.erase (iter++); |
6757 | 7455 } |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7456 |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7457 lookup_cache = list.end (); |
2117 | 7458 } |
7459 | |
7460 string_vector | |
7461 octave_stream_list::do_get_info (int fid) const | |
7462 { | |
3340 | 7463 octave_stream os = do_lookup (fid); |
2117 | 7464 |
20892 | 7465 if (! os.is_valid ()) |
3341 | 7466 ::error ("invalid file id = %d", fid); |
2117 | 7467 |
20892 | 7468 string_vector retval (3); |
7469 | |
7470 retval(0) = os.name (); | |
7471 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
|
7472 retval(2) = octave::mach_info::float_format_as_string (os.float_format ()); |
20892 | 7473 |
2117 | 7474 return retval; |
7475 } | |
7476 | |
7477 string_vector | |
7478 octave_stream_list::do_get_info (const octave_value& fid) const | |
7479 { | |
7480 int conv_err = 0; | |
7481 | |
7482 int int_fid = convert_to_valid_int (fid, conv_err); | |
7483 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
7484 if (conv_err) |
2915 | 7485 ::error ("file id must be a file object or integer value"); |
2117 | 7486 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
7487 return do_get_info (int_fid); |
2117 | 7488 } |
7489 | |
3536 | 7490 std::string |
2117 | 7491 octave_stream_list::do_list_open_files (void) const |
7492 { | |
5765 | 7493 std::ostringstream buf; |
2117 | 7494 |
7495 buf << "\n" | |
7496 << " number mode arch name\n" | |
7497 << " ------ ---- ---- ----\n"; | |
7498 | |
6757 | 7499 for (ostrl_map::const_iterator p = list.begin (); p != list.end (); p++) |
2117 | 7500 { |
6757 | 7501 octave_stream os = p->second; |
2117 | 7502 |
4326 | 7503 buf << " " |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7504 << std::setiosflags (std::ios::right) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7505 << std::setw (4) << p->first << " " |
19123 | 7506 // reset necessary in addition to setiosflags since this is one stmt. |
7507 << std::resetiosflags (std::ios::adjustfield) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7508 << std::setiosflags (std::ios::left) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7509 << std::setw (3) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7510 << octave_stream::mode_as_string (os.mode ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7511 << " " |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7512 << std::setw (9) |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
7513 << 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
|
7514 << " " |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7515 << os.name () << "\n"; |
2117 | 7516 } |
7517 | |
5765 | 7518 buf << "\n"; |
7519 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
7520 return buf.str (); |
2117 | 7521 } |
7522 | |
7523 octave_value | |
7524 octave_stream_list::do_open_file_numbers (void) const | |
7525 { | |
6757 | 7526 Matrix retval (1, list.size (), 0.0); |
2117 | 7527 |
7528 int num_open = 0; | |
7529 | |
6757 | 7530 for (ostrl_map::const_iterator p = list.begin (); p != list.end (); p++) |
2117 | 7531 { |
6757 | 7532 // Skip stdin, stdout, and stderr. |
7533 if (p->first > 2 && p->second) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7534 retval(0,num_open++) = p->first; |
2117 | 7535 } |
7536 | |
7537 retval.resize ((num_open > 0), num_open); | |
7538 | |
7539 return retval; | |
7540 } | |
7541 | |
7542 int | |
2609 | 7543 octave_stream_list::do_get_file_number (const octave_value& fid) const |
2117 | 7544 { |
7545 int retval = -1; | |
7546 | |
7547 if (fid.is_string ()) | |
7548 { | |
3523 | 7549 std::string nm = fid.string_value (); |
2117 | 7550 |
6757 | 7551 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
|
7552 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
7553 // stdin, stdout, and stderr are unnamed. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7554 if (p->first > 2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7555 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7556 octave_stream os = p->second; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7557 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7558 if (os && os.name () == nm) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7559 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7560 retval = p->first; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7561 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7562 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7563 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7564 } |
2117 | 7565 } |
7566 else | |
7567 { | |
7568 int conv_err = 0; | |
7569 | |
7570 int int_fid = convert_to_valid_int (fid, conv_err); | |
7571 | |
7572 if (conv_err) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7573 ::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
|
7574 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
7575 retval = int_fid; |
2117 | 7576 } |
7577 | |
7578 return retval; | |
7579 } |