Mercurial > octave
annotate libinterp/corefcn/oct-stream.cc @ 21139:538b57866b90
consistently use "typename" intead of "class" in template declarations
* Object.h, QtHandlesUtils.cc, QtHandlesUtils.h, ToolBarButton.cc,
ToolBarButton.h, Cell.h, __lin_interpn__.cc, bitfcns.cc, bsxfun.cc,
cellfun.cc, data.cc, filter.cc, gcd.cc, graphics.cc, help.cc, kron.cc,
lookup.cc, ls-mat5.cc, ls-oct-text.h, lu.cc, max.cc, mgorth.cc,
oct-map.cc, oct-map.h, oct-stream.cc, oct-stream.h, octave-link.h,
pr-output.cc, profiler.h, schur.cc, sparse-xdiv.cc, sparse-xpow.cc,
sqrtm.cc, symtab.h, tril.cc, typecast.cc, variables.cc, xdiv.cc,
zfstream.h, __init_fltk__.cc, __magick_read__.cc, chol.cc, qr.cc,
ov-base-diag.cc, ov-base-diag.h, ov-base-int.cc, ov-base-int.h,
ov-base-mat.cc, ov-base-mat.h, ov-base-scalar.cc, ov-base-scalar.h,
ov-base-sparse.cc, ov-base-sparse.h, ov-base.h, ov-classdef.cc,
ov-int-traits.h, ov-java.h, ov-usr-fcn.h, ov.cc, ov.h,
op-dms-template.cc, oct-parse.in.yy, parse.h, pt-mat.cc, Array-b.cc,
Array.cc, Array.h, CDiagMatrix.h, CMatrix.h, CNDArray.h,
DiagArray2.cc, DiagArray2.h, MArray.cc, MArray.h, MDiagArray2.cc,
MDiagArray2.h, MSparse.cc, MSparse.h, MatrixType.cc, Sparse.cc,
Sparse.h, dDiagMatrix.h, dMatrix.h, dNDArray.h, fCDiagMatrix.h,
fCMatrix.h, fCNDArray.h, fDiagMatrix.h, fMatrix.h, fNDArray.h,
idx-vector.cc, idx-vector.h, intNDArray.cc, intNDArray.h, DET.h,
base-aepbal.h, base-lu.cc, base-lu.h, base-qr.cc, base-qr.h,
bsxfun-defs.cc, eigs-base.cc, lo-mappers.h, lo-specfun.cc,
lo-specfun.h, oct-convn.cc, oct-fftw.cc, oct-norm.cc,
sparse-base-chol.cc, sparse-base-chol.h, sparse-base-lu.cc,
sparse-base-lu.h, sparse-dmsolve.cc, mx-inlines.cc,
action-container.h, base-list.h, lo-traits.h, lo-utils.h,
oct-base64.h, oct-binmap.h, oct-cmplx.h, oct-inttypes.cc,
oct-inttypes.h, oct-locbuf.h, oct-refcount.h, oct-sort.cc, oct-sort.h:
Use "typename" instead of "class" in template declarations.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 24 Jan 2016 13:50:04 -0500 |
parents | 228b65504557 |
children | 95feb42d7a97 |
rev | line source |
---|---|
2117 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19346
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
2117 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2117 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2117 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
3268 | 27 #include <cassert> |
7709
fa41af732801
octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents:
7538
diff
changeset
|
28 #include <cctype> |
2215 | 29 #include <cstring> |
30 | |
3503 | 31 #include <iomanip> |
9202
4b2147b25e8d
clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9017
diff
changeset
|
32 #include <iostream> |
3559 | 33 #include <fstream> |
5765 | 34 #include <sstream> |
3535 | 35 #include <string> |
2117 | 36 |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
19123
diff
changeset
|
37 #include "Array.h" |
4944 | 38 #include "byte-swap.h" |
2117 | 39 #include "lo-ieee.h" |
40 #include "lo-mappers.h" | |
41 #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
|
42 #include "oct-locbuf.h" |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13271
diff
changeset
|
43 #include "quit.h" |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13271
diff
changeset
|
44 #include "singleton-cleanup.h" |
2117 | 45 #include "str-vec.h" |
46 | |
47 #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
|
48 #include "errwarn.h" |
3342 | 49 #include "input.h" |
3775 | 50 #include "oct-stdstrm.h" |
2117 | 51 #include "oct-stream.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20938
diff
changeset
|
52 #include "ovl.h" |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
53 #include "toplev.h" |
2117 | 54 #include "utils.h" |
55 | |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
56 // 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
|
57 // 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
|
58 // 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
|
59 // 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
|
60 // 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
|
61 // 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
|
62 // 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
|
63 // 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
|
64 // 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
|
65 |
2117 | 66 // Possible values for conv_err: |
67 // | |
68 // 1 : not a real scalar | |
2902 | 69 // 2 : value is NaN |
70 // 3 : value is not an integer | |
2117 | 71 |
72 static int | |
73 convert_to_valid_int (const octave_value& tc, int& conv_err) | |
74 { | |
20747
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
75 conv_err = 0; |
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
76 |
2117 | 77 int retval = 0; |
78 | |
20747
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
79 double dval = 0.0; |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
80 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
81 try |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
82 { |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
83 dval = tc.double_value (); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
84 } |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
85 catch (const octave_execution_exception&) |
2117 | 86 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
87 recover_from_exception (); |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
88 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
89 conv_err = 1; |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
90 } |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
91 |
20747
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
92 if (! conv_err) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
93 { |
20747
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
94 if (! lo_ieee_isnan (dval)) |
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
95 { |
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
96 int ival = NINT (dval); |
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
97 |
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
98 if (ival == dval) |
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
99 retval = ival; |
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
100 else |
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
101 conv_err = 3; |
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
102 } |
2117 | 103 else |
20747
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
104 conv_err = 2; |
2117 | 105 } |
106 | |
107 return retval; | |
108 } | |
109 | |
110 static int | |
4468 | 111 get_size (double d, const std::string& who) |
2117 | 112 { |
113 int retval = -1; | |
114 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
115 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
|
116 ::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
|
117 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
118 if (xisinf (d)) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
119 retval = -1; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
120 else |
2117 | 121 { |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
122 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
|
123 ::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
|
124 who.c_str ()); |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
125 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
126 retval = NINT (d); |
2117 | 127 } |
128 | |
129 return retval; | |
130 } | |
131 | |
132 static void | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
133 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
|
134 bool& one_elt_size_spec, const std::string& who) |
2117 | 135 { |
136 nr = -1; | |
137 nc = -1; | |
138 | |
3268 | 139 one_elt_size_spec = false; |
140 | |
2117 | 141 double dnr = -1.0; |
142 double dnc = -1.0; | |
143 | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20230
diff
changeset
|
144 octave_idx_type sz_len = size.numel (); |
3810 | 145 |
146 if (sz_len == 1) | |
2601 | 147 { |
3268 | 148 one_elt_size_spec = true; |
149 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
150 dnr = size(0); |
4293 | 151 |
152 dnc = (dnr == 0.0) ? 0.0 : 1.0; | |
2601 | 153 } |
3810 | 154 else if (sz_len == 2) |
2117 | 155 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
156 dnr = size(0); |
3810 | 157 |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
158 if (xisinf (dnr)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
159 ::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
|
160 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
161 dnc = size(1); |
2117 | 162 } |
163 else | |
4468 | 164 ::error ("%s: invalid size specification", who.c_str ()); |
2117 | 165 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
166 nr = get_size (dnr, who); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
167 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
168 if (dnc >= 0.0) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
169 nc = get_size (dnc, who); |
2117 | 170 } |
171 | |
3523 | 172 scanf_format_list::scanf_format_list (const std::string& s) |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
173 : nconv (0), curr_idx (0), list (dim_vector (16, 1)), buf (0) |
2117 | 174 { |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
175 octave_idx_type num_elts = 0; |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
176 |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
177 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
|
178 |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
179 size_t i = 0; |
2117 | 180 |
2215 | 181 int width = 0; |
2117 | 182 bool discard = false; |
183 char modifier = '\0'; | |
184 char type = '\0'; | |
185 | |
186 bool have_more = true; | |
187 | |
188 while (i < n) | |
189 { | |
190 have_more = true; | |
191 | |
192 if (! buf) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
193 buf = new std::ostringstream (); |
2117 | 194 |
195 if (s[i] == '%') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
196 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
197 // Process percent-escape conversion type. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
198 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
199 process_conversion (s, i, n, width, discard, type, modifier, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
200 num_elts); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
201 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
202 have_more = (buf != 0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
203 } |
3483 | 204 else if (isspace (s[i])) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
205 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
206 type = scanf_format_elt::whitespace_conversion; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
207 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
208 width = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
209 discard = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
210 modifier = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
211 *buf << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
212 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
213 while (++i < n && isspace (s[i])) |
20946 | 214 ; // skip whitespace |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
215 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
216 add_elt_to_list (width, discard, type, modifier, num_elts); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
217 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
218 have_more = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
219 } |
3483 | 220 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
221 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
222 type = scanf_format_elt::literal_conversion; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
223 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
224 width = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
225 discard = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
226 modifier = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
227 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
228 while (i < n && ! isspace (s[i]) && s[i] != '%') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
229 *buf << s[i++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
230 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
231 add_elt_to_list (width, discard, type, modifier, num_elts); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
232 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
233 have_more = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
234 } |
2117 | 235 |
236 if (nconv < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
237 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
238 have_more = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
239 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
240 } |
2117 | 241 } |
242 | |
243 if (have_more) | |
2215 | 244 add_elt_to_list (width, discard, type, modifier, num_elts); |
2117 | 245 |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
246 list.resize (dim_vector (num_elts, 1)); |
2117 | 247 |
248 delete buf; | |
249 } | |
250 | |
251 scanf_format_list::~scanf_format_list (void) | |
252 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20230
diff
changeset
|
253 octave_idx_type n = list.numel (); |
5275 | 254 |
255 for (octave_idx_type i = 0; i < n; i++) | |
2117 | 256 { |
3340 | 257 scanf_format_elt *elt = list(i); |
2117 | 258 delete elt; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
259 } |
2117 | 260 } |
261 | |
262 void | |
2215 | 263 scanf_format_list::add_elt_to_list (int width, bool discard, char type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
264 char modifier, octave_idx_type& num_elts, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
265 const std::string& char_class) |
2117 | 266 { |
267 if (buf) | |
268 { | |
5765 | 269 std::string text = buf->str (); |
4051 | 270 |
271 if (! text.empty ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
272 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
273 scanf_format_elt *elt |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
274 = new scanf_format_elt (text.c_str (), width, discard, type, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
275 modifier, char_class); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
276 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20230
diff
changeset
|
277 if (num_elts == list.numel ()) |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
278 list.resize (dim_vector (2 * num_elts, 1)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
279 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
280 list(num_elts++) = elt; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
281 } |
2117 | 282 |
283 delete buf; | |
284 buf = 0; | |
285 } | |
286 } | |
287 | |
3535 | 288 static std::string |
3523 | 289 expand_char_class (const std::string& s) |
3483 | 290 { |
3523 | 291 std::string retval; |
3483 | 292 |
293 size_t len = s.length (); | |
294 | |
295 size_t i = 0; | |
296 | |
297 while (i < len) | |
298 { | |
299 unsigned char c = s[i++]; | |
300 | |
301 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
|
302 && ( 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
|
303 <= static_cast<unsigned char> (s[i]))) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
304 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
305 // 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
|
306 // already added it below). |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
307 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
308 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
|
309 retval += c; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
310 } |
3483 | 311 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
312 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
313 // 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
|
314 // the last character in the class. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
315 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
316 if (c != '-' || i == len) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
317 retval += c; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
318 } |
3483 | 319 } |
320 | |
321 return retval; | |
322 } | |
323 | |
2117 | 324 void |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
325 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
|
326 size_t n, int& width, bool& discard, |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
327 char& type, char& modifier, |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
328 octave_idx_type& num_elts) |
2117 | 329 { |
2215 | 330 width = 0; |
2117 | 331 discard = false; |
332 modifier = '\0'; | |
333 type = '\0'; | |
334 | |
335 *buf << s[i++]; | |
336 | |
337 bool have_width = false; | |
338 | |
339 while (i < n) | |
340 { | |
341 switch (s[i]) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
342 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
343 case '*': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
344 if (discard) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
345 nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
346 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
347 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
348 discard = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
349 *buf << s[i++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
350 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
351 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
352 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
353 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
|
354 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
|
355 if (have_width) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
356 nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
357 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
358 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
359 char c = s[i++]; |
20230
e914b5399c67
Use in-place operators in C++ code where possible.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
360 width = 10 * width + c - '0'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
361 have_width = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
362 *buf << c; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
363 while (i < n && isdigit (s[i])) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
364 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
365 c = s[i++]; |
20230
e914b5399c67
Use in-place operators in C++ code where possible.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
366 width = 10 * width + c - '0'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
367 *buf << c; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
368 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
369 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
370 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
371 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
372 case 'h': case 'l': case 'L': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
373 if (modifier != '\0') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
374 nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
375 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
376 modifier = s[i++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
377 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
378 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
379 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
|
380 if (modifier == 'L') |
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 nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
383 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
384 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
385 goto fini; |
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 case 'e': case 'f': case 'g': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
388 if (modifier == 'h') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
389 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
390 nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
391 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
392 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
393 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
394 // No float or long double conversions, thanks. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
395 *buf << 'l'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
396 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
397 goto fini; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
398 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
399 case 'c': case 's': case 'p': case '%': case '[': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
400 if (modifier != '\0') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
401 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
402 nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
403 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
404 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
405 goto fini; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
406 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
407 fini: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
408 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
409 if (finish_conversion (s, i, n, width, discard, type, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
410 modifier, num_elts) == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
411 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
412 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
413 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
414 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
415 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
416 nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
417 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
418 } |
2117 | 419 |
420 if (nconv < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
421 break; |
2117 | 422 } |
423 | |
424 nconv = -1; | |
425 } | |
426 | |
427 int | |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
428 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
|
429 size_t n, int& width, bool discard, |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
430 char& type, char modifier, |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
431 octave_idx_type& num_elts) |
2117 | 432 { |
433 int retval = 0; | |
434 | |
3523 | 435 std::string char_class; |
3483 | 436 |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
437 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
|
438 size_t end_idx = std::string::npos; |
3640 | 439 |
2117 | 440 if (s[i] == '%') |
3640 | 441 { |
442 type = '%'; | |
443 *buf << s[i++]; | |
444 } | |
2117 | 445 else |
446 { | |
447 type = s[i]; | |
448 | |
449 if (s[i] == '[') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
450 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
451 *buf << s[i++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
452 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
453 if (i < n) |
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 beg_idx = i; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
456 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
457 if (s[i] == '^') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
458 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
459 type = '^'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
460 *buf << s[i++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
461 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
462 if (i < n) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
463 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
464 beg_idx = i; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
465 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
466 if (s[i] == ']') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
467 *buf << s[i++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
468 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
469 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
470 else if (s[i] == ']') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
471 *buf << s[i++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
472 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
473 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
474 while (i < n && s[i] != ']') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
475 *buf << s[i++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
476 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
477 if (i < n && s[i] == ']') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
478 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
479 end_idx = i-1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
480 *buf << s[i++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
481 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
482 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
483 if (s[i-1] != ']') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
484 retval = nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
485 } |
2117 | 486 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
487 *buf << s[i++]; |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
488 |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
489 nconv++; |
3640 | 490 } |
491 | |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
492 if (nconv >= 0) |
3640 | 493 { |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
494 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
|
495 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
|
496 end_idx - beg_idx + 1)); |
3640 | 497 |
498 add_elt_to_list (width, discard, type, modifier, num_elts, char_class); | |
2117 | 499 } |
500 | |
501 return retval; | |
502 } | |
503 | |
504 void | |
505 scanf_format_list::printme (void) const | |
506 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20230
diff
changeset
|
507 octave_idx_type n = list.numel (); |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
508 |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
509 for (octave_idx_type i = 0; i < n; i++) |
2117 | 510 { |
3340 | 511 scanf_format_elt *elt = list(i); |
2117 | 512 |
3531 | 513 std::cerr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
514 << "width: " << elt->width << "\n" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
515 << "discard: " << elt->discard << "\n" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
516 << "type: "; |
3483 | 517 |
518 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
|
519 std::cerr << "literal text\n"; |
3483 | 520 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
|
521 std::cerr << "whitespace\n"; |
3483 | 522 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
523 std::cerr << elt->type << "\n"; |
3531 | 524 |
525 std::cerr | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
526 << "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
|
527 << "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
|
528 << "text: '" << undo_string_escapes (elt->text) << "'\n\n"; |
2117 | 529 } |
530 } | |
531 | |
532 bool | |
533 scanf_format_list::all_character_conversions (void) | |
534 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20230
diff
changeset
|
535 octave_idx_type n = list.numel (); |
2117 | 536 |
537 if (n > 0) | |
538 { | |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
539 for (octave_idx_type i = 0; i < n; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
540 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
541 scanf_format_elt *elt = list(i); |
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 switch (elt->type) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
544 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
545 case 'c': case 's': case '%': case '[': case '^': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
546 case scanf_format_elt::literal_conversion: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
547 case scanf_format_elt::whitespace_conversion: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
548 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
549 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
550 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
551 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
552 break; |
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 } |
2117 | 555 |
556 return true; | |
557 } | |
558 else | |
559 return false; | |
560 } | |
561 | |
562 bool | |
563 scanf_format_list::all_numeric_conversions (void) | |
564 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20230
diff
changeset
|
565 octave_idx_type n = list.numel (); |
2117 | 566 |
567 if (n > 0) | |
568 { | |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
569 for (octave_idx_type i = 0; i < n; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
570 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
571 scanf_format_elt *elt = list(i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
572 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
573 switch (elt->type) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
574 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
575 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
|
576 case 'e': case 'f': case 'g': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
577 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
578 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
579 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
580 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
581 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
582 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
583 } |
2117 | 584 |
585 return true; | |
586 } | |
587 else | |
588 return false; | |
589 } | |
590 | |
591 // Ugh again. | |
592 | |
3523 | 593 printf_format_list::printf_format_list (const std::string& s) |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
594 : nconv (0), curr_idx (0), list (dim_vector (16, 1)), buf (0) |
2117 | 595 { |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
596 octave_idx_type num_elts = 0; |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
597 |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
598 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
|
599 |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
600 size_t i = 0; |
2117 | 601 |
602 int args = 0; | |
3643 | 603 std::string flags; |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
604 int fw = -1; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
605 int prec = -1; |
2117 | 606 char modifier = '\0'; |
607 char type = '\0'; | |
608 | |
609 bool have_more = true; | |
3640 | 610 bool empty_buf = true; |
2117 | 611 |
4223 | 612 if (n == 0) |
2117 | 613 { |
4223 | 614 printf_format_elt *elt |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
615 = new printf_format_elt ("", args, fw, prec, flags, type, modifier); |
4223 | 616 |
617 list(num_elts++) = elt; | |
618 | |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
619 list.resize (dim_vector (num_elts, 1)); |
4223 | 620 } |
621 else | |
622 { | |
623 while (i < n) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
624 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
625 have_more = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
626 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
627 if (! buf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
628 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
629 buf = new std::ostringstream (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
630 empty_buf = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
631 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
632 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
633 switch (s[i]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
634 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
635 case '%': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
636 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
637 if (empty_buf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
638 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
639 process_conversion (s, i, n, args, flags, fw, prec, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
640 type, modifier, num_elts); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
641 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
642 have_more = (buf != 0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
643 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
644 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
645 add_elt_to_list (args, flags, fw, prec, type, modifier, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
646 num_elts); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
647 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
648 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
649 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
650 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
651 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
652 args = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
653 flags = ""; |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
654 fw = -1; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
655 prec = -1; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
656 modifier = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
657 type = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
658 *buf << s[i++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
659 empty_buf = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
660 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
661 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
662 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
663 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
664 if (nconv < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
665 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
666 have_more = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
667 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
668 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
669 } |
2117 | 670 |
4223 | 671 if (have_more) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
672 add_elt_to_list (args, flags, fw, prec, type, modifier, num_elts); |
4223 | 673 |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
674 list.resize (dim_vector (num_elts, 1)); |
4223 | 675 |
676 delete buf; | |
2117 | 677 } |
678 } | |
679 | |
680 printf_format_list::~printf_format_list (void) | |
681 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20230
diff
changeset
|
682 octave_idx_type n = list.numel (); |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
683 |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
684 for (octave_idx_type i = 0; i < n; i++) |
2117 | 685 { |
3340 | 686 printf_format_elt *elt = list(i); |
2117 | 687 delete elt; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
688 } |
2117 | 689 } |
690 | |
691 void | |
3640 | 692 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
|
693 int fw, int prec, char type, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
694 char modifier, octave_idx_type& num_elts) |
2117 | 695 { |
696 if (buf) | |
697 { | |
5765 | 698 std::string text = buf->str (); |
4051 | 699 |
700 if (! text.empty ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
701 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
702 printf_format_elt *elt |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
703 = new printf_format_elt (text.c_str (), args, fw, prec, flags, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
704 type, modifier); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
705 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20230
diff
changeset
|
706 if (num_elts == list.numel ()) |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
707 list.resize (dim_vector (2 * num_elts, 1)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
708 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
709 list(num_elts++) = elt; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
710 } |
2117 | 711 |
712 delete buf; | |
713 buf = 0; | |
714 } | |
715 } | |
716 | |
717 void | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
718 printf_format_list::process_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
|
719 size_t n, int& args, std::string& flags, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
720 int& fw, int& prec, char& modifier, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
721 char& type, octave_idx_type& num_elts) |
2117 | 722 { |
723 args = 0; | |
3640 | 724 flags = ""; |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
725 fw = -1; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
726 prec = -1; |
2117 | 727 modifier = '\0'; |
728 type = '\0'; | |
729 | |
730 *buf << s[i++]; | |
731 | |
4587 | 732 bool nxt = false; |
2117 | 733 |
734 while (i < n) | |
735 { | |
736 switch (s[i]) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
737 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
738 case '-': case '+': case ' ': case '0': case '#': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
739 flags += s[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
740 *buf << s[i++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
741 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
742 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
743 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
744 nxt = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
745 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
746 } |
2117 | 747 |
4587 | 748 if (nxt) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
749 break; |
2117 | 750 } |
751 | |
752 if (i < n) | |
753 { | |
754 if (s[i] == '*') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
755 { |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
756 fw = -2; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
757 args++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
758 *buf << s[i++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
759 } |
2117 | 760 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
761 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
762 if (isdigit (s[i])) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
763 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
764 int nn = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
765 std::string tmp = s.substr (i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
766 sscanf (tmp.c_str (), "%d%n", &fw, &nn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
767 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
768 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
769 while (i < n && isdigit (s[i])) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
770 *buf << s[i++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
771 } |
2117 | 772 } |
773 | |
774 if (i < n && s[i] == '.') | |
775 { | |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
776 // nothing before the . means 0. |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
777 if (fw == -1) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
778 fw = 0; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
779 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
780 // . followed by nothing is 0. |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
781 prec = 0; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
782 |
2117 | 783 *buf << s[i++]; |
784 | |
785 if (i < n) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
786 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
787 if (s[i] == '*') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
788 { |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
789 prec = -2; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
790 args++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
791 *buf << s[i++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
792 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
793 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
794 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
795 if (isdigit (s[i])) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
796 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
797 int nn = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
798 std::string tmp = s.substr (i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
799 sscanf (tmp.c_str (), "%d%n", &prec, &nn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
800 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
801 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
802 while (i < n && isdigit (s[i])) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
803 *buf << s[i++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
804 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
805 } |
2117 | 806 } |
807 | |
808 if (i < n) | |
809 { | |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
810 // 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
|
811 // 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
|
812 // integers. |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
813 |
2117 | 814 switch (s[i]) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
815 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
816 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
|
817 modifier = s[i++]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
818 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
819 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
820 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
821 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
822 } |
2117 | 823 } |
824 | |
825 if (i < n) | |
3640 | 826 finish_conversion (s, i, args, flags, fw, prec, modifier, type, num_elts); |
2117 | 827 else |
828 nconv = -1; | |
829 } | |
830 | |
831 void | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
832 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
|
833 int args, const std::string& flags, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
834 int fw, int prec, char modifier, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
835 char& type, octave_idx_type& num_elts) |
2117 | 836 { |
837 switch (s[i]) | |
838 { | |
839 case 'd': case 'i': case 'o': case 'x': case 'X': | |
840 case 'u': case 'c': | |
841 if (modifier == 'L') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
842 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
843 nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
844 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
845 } |
2117 | 846 goto fini; |
847 | |
848 case 'f': case 'e': case 'E': case 'g': case 'G': | |
849 if (modifier == 'h' || modifier == 'l') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
850 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
851 nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
852 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
853 } |
2117 | 854 goto fini; |
855 | |
856 case 's': case 'p': case '%': | |
857 if (modifier != '\0') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
858 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
859 nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
860 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
861 } |
2117 | 862 goto fini; |
863 | |
864 fini: | |
865 | |
3640 | 866 type = s[i]; |
867 | |
868 *buf << s[i++]; | |
869 | |
870 if (type != '%' || args != 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
871 nconv++; |
3640 | 872 |
873 if (type != '%') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
874 args++; |
3640 | 875 |
876 add_elt_to_list (args, flags, fw, prec, type, modifier, num_elts); | |
877 | |
2117 | 878 break; |
879 | |
880 default: | |
881 nconv = -1; | |
882 break; | |
883 } | |
884 } | |
885 | |
886 void | |
887 printf_format_list::printme (void) const | |
888 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20230
diff
changeset
|
889 int n = list.numel (); |
2117 | 890 |
891 for (int i = 0; i < n; i++) | |
892 { | |
3340 | 893 printf_format_elt *elt = list(i); |
2117 | 894 |
3640 | 895 std::cerr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
896 << "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
|
897 << "flags: '" << elt->flags << "'\n" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
898 << "width: " << elt->fw << "\n" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
899 << "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
|
900 << "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
|
901 << "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
|
902 << "text: '" << undo_string_escapes (elt->text) << "'\n\n"; |
2117 | 903 } |
904 } | |
905 | |
906 void | |
3523 | 907 octave_base_stream::error (const std::string& msg) |
2117 | 908 { |
909 fail = true; | |
910 errmsg = msg; | |
911 } | |
912 | |
913 void | |
4468 | 914 octave_base_stream::error (const std::string& who, const std::string& msg) |
915 { | |
916 fail = true; | |
6296 | 917 errmsg = who + ": " + msg; |
4468 | 918 } |
919 | |
920 void | |
2117 | 921 octave_base_stream::clear (void) |
922 { | |
4889 | 923 fail = false; |
924 errmsg = ""; | |
925 } | |
926 | |
927 void | |
928 octave_base_stream::clearerr (void) | |
929 { | |
4888 | 930 std::istream *is = input_stream (); |
931 std::ostream *os = output_stream (); | |
932 | |
933 if (is) | |
934 is->clear (); | |
935 | |
936 if (os) | |
937 os->clear (); | |
2117 | 938 } |
939 | |
940 // Functions that are defined for all input streams (input streams | |
941 // are those that define is). | |
942 | |
3536 | 943 std::string |
5275 | 944 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
|
945 bool strip_newline, const std::string& who) |
2117 | 946 { |
19849
1c9ed5b4c73d
input.h: change meaning of interactive and forced_interactive global variables.
Carnë Draug <carandraug@octave.org>
parents:
19739
diff
changeset
|
947 if (interactive && file_number () == 0) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20768
diff
changeset
|
948 ::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
|
949 who.c_str ()); |
8773
9e3111d203c0
disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents:
8739
diff
changeset
|
950 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
951 std::string retval; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
952 |
2117 | 953 err = false; |
954 | |
3523 | 955 std::istream *isp = input_stream (); |
2117 | 956 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
957 if (! isp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
958 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
959 err = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
960 invalid_operation (who, "reading"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
961 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
962 else |
2117 | 963 { |
3523 | 964 std::istream& is = *isp; |
2117 | 965 |
5765 | 966 std::ostringstream buf; |
2117 | 967 |
968 int c = 0; | |
3553 | 969 int char_count = 0; |
6345 | 970 |
971 if (max_len != 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
972 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
973 while (is && (c = is.get ()) != EOF) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
974 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
975 char_count++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
976 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
977 // Handle CRLF, CR, or LF as line ending. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
978 if (c == '\r') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
979 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
980 if (! strip_newline) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
981 buf << static_cast<char> (c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
982 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
983 c = is.get (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
984 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
985 if (c != EOF) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
986 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
987 if (c == '\n') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
988 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
989 char_count++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
990 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
991 if (! strip_newline) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
992 buf << static_cast<char> (c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
993 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
994 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
995 is.putback (c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
996 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
997 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
998 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
999 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1000 else if (c == '\n') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1001 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1002 if (! strip_newline) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1003 buf << static_cast<char> (c); |
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 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1006 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1007 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1008 buf << static_cast<char> (c); |
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 if (max_len > 0 && char_count == max_len) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1011 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1012 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1013 } |
6345 | 1014 |
1015 if (! is.eof () && char_count > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1016 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1017 // 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
|
1018 // 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
|
1019 // corresponding C-library functions do. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1020 int disgusting_compatibility_hack = is.get (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1021 if (! is.eof ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1022 is.putback (disgusting_compatibility_hack); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1023 } |
2117 | 1024 |
4224 | 1025 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
|
1026 retval = buf.str (); |
4224 | 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 err = true; |
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 if (is.eof () && char_count == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1032 error (who, "at end of file"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1033 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1034 error (who, "read error"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1035 } |
2117 | 1036 } |
1037 | |
1038 return retval; | |
1039 } | |
1040 | |
3536 | 1041 std::string |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1042 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
|
1043 const std::string& who) |
2117 | 1044 { |
4468 | 1045 return do_gets (max_len, err, true, who); |
2117 | 1046 } |
1047 | |
3536 | 1048 std::string |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1049 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
|
1050 const std::string& who) |
2117 | 1051 { |
4468 | 1052 return do_gets (max_len, err, false, who); |
2117 | 1053 } |
1054 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1055 off_t |
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1056 octave_base_stream::skipl (off_t num, bool& err, const std::string& who) |
9701 | 1057 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1058 if (interactive && file_number () == 0) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1059 ::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
|
1060 who.c_str ()); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1061 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1062 off_t cnt = -1; |
9701 | 1063 |
1064 err = false; | |
1065 | |
1066 std::istream *isp = input_stream (); | |
1067 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1068 if (! isp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1069 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1070 err = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1071 invalid_operation (who, "reading"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1072 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1073 else |
9701 | 1074 { |
1075 std::istream& is = *isp; | |
1076 | |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
1077 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
|
1078 int lastc = -1; |
9701 | 1079 cnt = 0; |
1080 | |
1081 while (is && (c = is.get ()) != EOF) | |
1082 { | |
1083 // Handle CRLF, CR, or LF as line ending. | |
1084 if (c == '\r' || (c == '\n' && lastc != '\r')) | |
1085 { | |
1086 if (++cnt == num) | |
1087 break; | |
1088 } | |
1089 | |
1090 lastc = c; | |
1091 } | |
1092 | |
1093 // Maybe eat the following \n if \r was just met. | |
1094 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
|
1095 is.get (); |
9701 | 1096 |
1097 if (is.bad ()) | |
1098 { | |
1099 err = true; | |
1100 error (who, "read error"); | |
1101 } | |
1102 | |
1103 if (err) | |
1104 cnt = -1; | |
1105 } | |
1106 | |
1107 return cnt; | |
1108 } | |
1109 | |
3640 | 1110 #define OCTAVE_SCAN(is, fmt, arg) octave_scan (is, fmt, arg) |
3636 | 1111 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
1112 template <typename T> |
3636 | 1113 std::istream& |
6767 | 1114 octave_scan_1 (std::istream& is, const scanf_format_elt& fmt, T* valptr) |
3636 | 1115 { |
3779 | 1116 T& ref = *valptr; |
1117 | |
1118 switch (fmt.type) | |
1119 { | |
1120 case 'o': | |
4926 | 1121 is >> std::oct >> ref >> std::dec; |
3779 | 1122 break; |
1123 | |
1124 case 'x': | |
4926 | 1125 is >> std::hex >> ref >> std::dec; |
1126 break; | |
1127 | |
1128 case 'i': | |
1129 { | |
14675
757f729fd41d
skip leading whitespace for scanf %i format
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1130 int c1 = EOF; |
757f729fd41d
skip leading whitespace for scanf %i format
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1131 |
757f729fd41d
skip leading whitespace for scanf %i format
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1132 while (is && (c1 = is.get ()) != EOF && isspace (c1)) |
20946 | 1133 ; // skip whitespace |
14675
757f729fd41d
skip leading whitespace for scanf %i format
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1134 |
757f729fd41d
skip leading whitespace for scanf %i format
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1135 if (c1 != EOF) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1136 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1137 if (c1 == '0') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1138 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1139 int c2 = is.peek (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1140 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1141 if (c2 == 'x' || c2 == 'X') |
7709
fa41af732801
octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents:
7538
diff
changeset
|
1142 { |
fa41af732801
octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents:
7538
diff
changeset
|
1143 is.ignore (); |
fa41af732801
octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents:
7538
diff
changeset
|
1144 if (std::isxdigit (is.peek ())) |
fa41af732801
octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents:
7538
diff
changeset
|
1145 is >> std::hex >> ref >> std::dec; |
fa41af732801
octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents:
7538
diff
changeset
|
1146 else |
fa41af732801
octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents:
7538
diff
changeset
|
1147 ref = 0; |
fa41af732801
octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents:
7538
diff
changeset
|
1148 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1149 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1150 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1151 if (c2 == '0' || c2 == '1' || c2 == '2' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1152 || c2 == '3' || c2 == '4' || c2 == '5' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1153 || c2 == '6' || c2 == '7') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1154 is >> std::oct >> ref >> std::dec; |
21114
47908b818865
oct-stream.cc: Add FIXME note about bug #46493.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1155 else if (c2 == '8' || c2 == '9') |
47908b818865
oct-stream.cc: Add FIXME note about bug #46493.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1156 { |
47908b818865
oct-stream.cc: Add FIXME note about bug #46493.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1157 // 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
|
1158 // 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
|
1159 // error ("internal failure to match octal format"); |
47908b818865
oct-stream.cc: Add FIXME note about bug #46493.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1160 ref = 0; |
47908b818865
oct-stream.cc: Add FIXME note about bug #46493.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1161 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1162 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1163 ref = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1164 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1165 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1166 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1167 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1168 is.putback (c1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1169 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1170 is >> ref; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1171 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1172 } |
4926 | 1173 } |
3779 | 1174 break; |
1175 | |
1176 default: | |
1177 is >> ref; | |
1178 break; | |
1179 } | |
3639 | 1180 |
3638 | 1181 return is; |
3636 | 1182 } |
1183 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
1184 template <typename T> |
6767 | 1185 std::istream& |
1186 octave_scan (std::istream& is, const scanf_format_elt& fmt, T* valptr) | |
1187 { | |
1188 if (fmt.width) | |
1189 { | |
1190 // Limit input to fmt.width characters by reading into a | |
1191 // temporary stringstream buffer. | |
1192 std::string tmp; | |
1193 | |
1194 is.width (fmt.width); | |
1195 is >> tmp; | |
1196 | |
1197 std::istringstream ss (tmp); | |
1198 | |
1199 octave_scan_1 (ss, fmt, valptr); | |
1200 } | |
1201 else | |
1202 octave_scan_1 (is, fmt, valptr); | |
1203 | |
1204 return is; | |
1205 } | |
1206 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1207 // Note that this specialization is only used for reading characters, not |
3779 | 1208 // character strings. See BEGIN_S_CONVERSION for details. |
1209 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
1210 template <> |
3779 | 1211 std::istream& |
4661 | 1212 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
|
1213 char* valptr) |
3779 | 1214 { |
1215 return is >> valptr; | |
1216 } | |
3636 | 1217 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
1218 template <> |
5176 | 1219 std::istream& |
5403 | 1220 octave_scan<> (std::istream& is, const scanf_format_elt& fmt, double* valptr) |
5176 | 1221 { |
1222 double& ref = *valptr; | |
1223 | |
1224 switch (fmt.type) | |
1225 { | |
1226 case 'e': | |
1227 case 'f': | |
1228 case 'g': | |
1229 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1230 int c1 = EOF; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1231 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1232 while (is && (c1 = is.get ()) != EOF && isspace (c1)) |
20946 | 1233 ; // skip whitespace |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1234 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1235 if (c1 != EOF) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1236 { |
12936
b74cb659e757
accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1237 is.putback (c1); |
b74cb659e757
accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1238 |
b74cb659e757
accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1239 ref = octave_read_value<double> (is); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1240 } |
5176 | 1241 } |
1242 break; | |
1243 | |
1244 default: | |
1245 panic_impossible (); | |
1246 break; | |
1247 } | |
1248 | |
1249 return is; | |
1250 } | |
1251 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
1252 template <typename T> |
2572 | 1253 void |
3636 | 1254 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
|
1255 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
|
1256 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
|
1257 octave_idx_type max_size, bool discard) |
2572 | 1258 { |
3640 | 1259 OCTAVE_SCAN (is, fmt, valptr); |
2572 | 1260 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1261 if (! is) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1262 return; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1263 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1264 if (idx == max_size && ! discard) |
2572 | 1265 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1266 max_size *= 2; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1267 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1268 if (nr > 0) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1269 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
|
1270 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1271 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
|
1272 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1273 data = mval.fortran_vec (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1274 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1275 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1276 if (! discard) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1277 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1278 conversion_count++; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1279 data[idx++] = *(valptr); |
2572 | 1280 } |
1281 } | |
1282 | |
1283 template void | |
3636 | 1284 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
|
1285 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
|
1286 octave_idx_type, octave_idx_type, bool); |
2572 | 1287 |
3483 | 1288 #define DO_WHITESPACE_CONVERSION() \ |
1289 do \ | |
1290 { \ | |
1291 int c = EOF; \ | |
1292 \ | |
1293 while (is && (c = is.get ()) != EOF && isspace (c)) \ | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1294 { /* skip whitespace */ } \ |
3483 | 1295 \ |
1296 if (c != EOF) \ | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1297 is.putback (c); \ |
3483 | 1298 } \ |
1299 while (0) | |
1300 | |
1301 #define DO_LITERAL_CONVERSION() \ | |
1302 do \ | |
1303 { \ | |
1304 int c = EOF; \ | |
1305 \ | |
1306 int n = strlen (fmt); \ | |
1307 int i = 0; \ | |
1308 \ | |
1309 while (i < n && is && (c = is.get ()) != EOF) \ | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1310 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1311 if (c == static_cast<unsigned char> (fmt[i])) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1312 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1313 i++; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1314 continue; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1315 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1316 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1317 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1318 is.putback (c); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1319 break; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1320 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1321 } \ |
3483 | 1322 \ |
1323 if (i != n) \ | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1324 is.setstate (std::ios::failbit); \ |
3483 | 1325 } \ |
1326 while (0) | |
1327 | |
3640 | 1328 #define DO_PCT_CONVERSION() \ |
1329 do \ | |
1330 { \ | |
1331 int c = is.get (); \ | |
1332 \ | |
1333 if (c != EOF) \ | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1334 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1335 if (c != '%') \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1336 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1337 is.putback (c); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1338 is.setstate (std::ios::failbit); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1339 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1340 } \ |
3640 | 1341 else \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1342 is.setstate (std::ios::failbit); \ |
3640 | 1343 } \ |
1344 while (0) | |
1345 | |
3483 | 1346 #define BEGIN_C_CONVERSION() \ |
3538 | 1347 is.unsetf (std::ios::skipws); \ |
3483 | 1348 \ |
1349 int width = elt->width ? elt->width : 1; \ | |
1350 \ | |
9952
7cd2e1b372e5
allow scanf to store ASCII NUL values
John W. Eaton <jwe@octave.org>
parents:
9941
diff
changeset
|
1351 std::string tmp (width, '\0'); \ |
3483 | 1352 \ |
1353 int c = EOF; \ | |
1354 int n = 0; \ | |
1355 \ | |
1356 while (is && n < width && (c = is.get ()) != EOF) \ | |
9952
7cd2e1b372e5
allow scanf to store ASCII NUL values
John W. Eaton <jwe@octave.org>
parents:
9941
diff
changeset
|
1357 tmp[n++] = static_cast<char> (c); \ |
3483 | 1358 \ |
5266 | 1359 if (n > 0 && c == EOF) \ |
12984
7626f8934466
correctly resize scanf output for %c formats (bug #34037)
John W. Eaton <jwe@octave.org>
parents:
12966
diff
changeset
|
1360 is.clear (); \ |
7626f8934466
correctly resize scanf output for %c formats (bug #34037)
John W. Eaton <jwe@octave.org>
parents:
12966
diff
changeset
|
1361 \ |
7626f8934466
correctly resize scanf output for %c formats (bug #34037)
John W. Eaton <jwe@octave.org>
parents:
12966
diff
changeset
|
1362 tmp.resize (n) |
3483 | 1363 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1364 // For a '%s' format, skip initial whitespace and then read until the |
5338 | 1365 // next whitespace character or until WIDTH characters have been read. |
3483 | 1366 #define BEGIN_S_CONVERSION() \ |
1367 int width = elt->width; \ | |
1368 \ | |
4051 | 1369 std::string tmp; \ |
3483 | 1370 \ |
1371 do \ | |
1372 { \ | |
1373 if (width) \ | |
5338 | 1374 { \ |
10076 | 1375 tmp = std::string (width, '\0'); \ |
5338 | 1376 \ |
1377 int c = EOF; \ | |
1378 \ | |
1379 int n = 0; \ | |
1380 \ | |
1381 while (is && (c = is.get ()) != EOF) \ | |
1382 { \ | |
1383 if (! isspace (c)) \ | |
1384 { \ | |
9952
7cd2e1b372e5
allow scanf to store ASCII NUL values
John W. Eaton <jwe@octave.org>
parents:
9941
diff
changeset
|
1385 tmp[n++] = static_cast<char> (c); \ |
5338 | 1386 break; \ |
1387 } \ | |
1388 } \ | |
4051 | 1389 \ |
5338 | 1390 while (is && n < width && (c = is.get ()) != EOF) \ |
1391 { \ | |
1392 if (isspace (c)) \ | |
1393 { \ | |
1394 is.putback (c); \ | |
1395 break; \ | |
1396 } \ | |
1397 else \ | |
9952
7cd2e1b372e5
allow scanf to store ASCII NUL values
John W. Eaton <jwe@octave.org>
parents:
9941
diff
changeset
|
1398 tmp[n++] = static_cast<char> (c); \ |
5338 | 1399 } \ |
3483 | 1400 \ |
5338 | 1401 if (n > 0 && c == EOF) \ |
1402 is.clear (); \ | |
1403 \ | |
9952
7cd2e1b372e5
allow scanf to store ASCII NUL values
John W. Eaton <jwe@octave.org>
parents:
9941
diff
changeset
|
1404 tmp.resize (n); \ |
5338 | 1405 } \ |
3483 | 1406 else \ |
5338 | 1407 { \ |
1408 is >> std::ws >> tmp; \ | |
1409 } \ | |
3483 | 1410 } \ |
1411 while (0) | |
1412 | |
1413 // This format must match a nonempty sequence of characters. | |
1414 #define BEGIN_CHAR_CLASS_CONVERSION() \ | |
1415 int width = elt->width; \ | |
1416 \ | |
4051 | 1417 std::string tmp; \ |
3483 | 1418 \ |
1419 do \ | |
1420 { \ | |
7426 | 1421 if (! width) \ |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1422 width = std::numeric_limits<int>::max (); \ |
7427 | 1423 \ |
7426 | 1424 std::ostringstream buf; \ |
1425 \ | |
1426 std::string char_class = elt->char_class; \ | |
4051 | 1427 \ |
7426 | 1428 int c = EOF; \ |
3483 | 1429 \ |
7426 | 1430 if (elt->type == '[') \ |
1431 { \ | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1432 int chars_read = 0; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1433 while (is && chars_read++ < width && (c = is.get ()) != EOF \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1434 && char_class.find (c) != std::string::npos) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1435 buf << static_cast<char> (c); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1436 } \ |
3483 | 1437 else \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1438 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1439 int chars_read = 0; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1440 while (is && chars_read++ < width && (c = is.get ()) != EOF \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1441 && char_class.find (c) == std::string::npos) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1442 buf << static_cast<char> (c); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1443 } \ |
3483 | 1444 \ |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1445 if (width == std::numeric_limits<int>::max () && c != EOF) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1446 is.putback (c); \ |
3483 | 1447 \ |
7426 | 1448 tmp = buf.str (); \ |
3483 | 1449 \ |
7426 | 1450 if (tmp.empty ()) \ |
1451 is.setstate (std::ios::failbit); \ | |
10969
da355a1a6d44
fix scanf char class conversion bug
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
1452 else if (c == EOF) \ |
da355a1a6d44
fix scanf char class conversion bug
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
1453 is.clear (); \ |
da355a1a6d44
fix scanf char class conversion bug
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
1454 \ |
3483 | 1455 } \ |
1456 while (0) | |
1457 | |
3410 | 1458 #define FINISH_CHARACTER_CONVERSION() \ |
1459 do \ | |
1460 { \ | |
4051 | 1461 width = tmp.length (); \ |
3410 | 1462 \ |
1463 if (is) \ | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1464 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1465 int i = 0; \ |
3410 | 1466 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1467 if (! discard) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1468 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1469 conversion_count++; \ |
3410 | 1470 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1471 while (i < width) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1472 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1473 if (data_index == max_size) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1474 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1475 max_size *= 2; \ |
3410 | 1476 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1477 if (all_char_conv) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1478 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1479 if (one_elt_size_spec) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1480 mval.resize (1, max_size, 0.0); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1481 else if (nr > 0) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1482 mval.resize (nr, max_size / nr, 0.0); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1483 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1484 panic_impossible (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1485 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1486 else if (nr > 0) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1487 mval.resize (nr, max_size / nr, 0.0); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1488 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1489 mval.resize (max_size, 1, 0.0); \ |
3410 | 1490 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1491 data = mval.fortran_vec (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1492 } \ |
3410 | 1493 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1494 data[data_index++] = tmp[i++]; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1495 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1496 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1497 } \ |
3410 | 1498 } \ |
1499 while (0) | |
2117 | 1500 |
1501 octave_value | |
1502 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
|
1503 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
|
1504 bool one_elt_size_spec, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1505 octave_idx_type& conversion_count, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1506 const std::string& who) |
2117 | 1507 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1508 if (interactive && file_number () == 0) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1509 ::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
|
1510 who.c_str ()); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1511 |
8773
9e3111d203c0
disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents:
8739
diff
changeset
|
1512 octave_value retval = Matrix (); |
9e3111d203c0
disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents:
8739
diff
changeset
|
1513 |
3268 | 1514 conversion_count = 0; |
1515 | |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1516 octave_idx_type nconv = fmt_list.num_conversions (); |
3640 | 1517 |
5275 | 1518 octave_idx_type data_index = 0; |
2121 | 1519 |
3268 | 1520 if (nr == 0 || nc == 0) |
1521 { | |
1522 if (one_elt_size_spec) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1523 nc = 0; |
3268 | 1524 |
1525 return Matrix (nr, nc, 0.0); | |
1526 } | |
1527 | |
3523 | 1528 std::istream *isp = input_stream (); |
2117 | 1529 |
1530 bool all_char_conv = fmt_list.all_character_conversions (); | |
1531 | |
1532 Matrix mval; | |
1533 double *data = 0; | |
5275 | 1534 octave_idx_type max_size = 0; |
1535 octave_idx_type max_conv = 0; | |
1536 | |
1537 octave_idx_type final_nr = 0; | |
1538 octave_idx_type final_nc = 0; | |
2117 | 1539 |
3268 | 1540 if (all_char_conv) |
1541 { | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1542 // 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
|
1543 // we may read more than one element for each conversion). |
3268 | 1544 if (one_elt_size_spec) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1545 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1546 max_size = 512; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1547 mval.resize (1, max_size, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1548 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1549 if (nr > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1550 max_conv = nr; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1551 } |
4420 | 1552 else if (nr > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1553 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1554 if (nc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1555 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1556 mval.resize (nr, nc, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1557 max_size = max_conv = nr * nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1558 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1559 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1560 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1561 mval.resize (nr, 32, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1562 max_size = nr * 32; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1563 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1564 } |
4420 | 1565 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1566 panic_impossible (); |
3268 | 1567 } |
1568 else if (nr > 0) | |
2117 | 1569 { |
1570 if (nc > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1571 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1572 // Will not resize later. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1573 mval.resize (nr, nc, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1574 max_size = nr * nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1575 max_conv = max_size; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1576 } |
2117 | 1577 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1578 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1579 // Maybe resize later. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1580 mval.resize (nr, 32, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1581 max_size = nr * 32; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1582 } |
2117 | 1583 } |
1584 else | |
1585 { | |
4420 | 1586 // Maybe resize later. |
2117 | 1587 mval.resize (32, 1, 0.0); |
1588 max_size = 32; | |
1589 } | |
1590 | |
4420 | 1591 data = mval.fortran_vec (); |
1592 | |
2117 | 1593 if (isp) |
1594 { | |
3523 | 1595 std::istream& is = *isp; |
2117 | 1596 |
1597 const scanf_format_elt *elt = fmt_list.first (); | |
1598 | |
3538 | 1599 std::ios::fmtflags flags = is.flags (); |
2213 | 1600 |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1601 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
|
1602 |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1603 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
|
1604 |
2117 | 1605 for (;;) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1606 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1607 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1608 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1609 if (elt) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1610 { |
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
|
1611 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
|
1612 || (! (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
|
1613 || 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
|
1614 || 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
|
1615 && max_conv > 0 && conversion_count == max_conv)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1616 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1617 // 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
|
1618 // 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
|
1619 // 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
|
1620 // 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
|
1621 // Determine final array size and exit. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1622 if (all_char_conv && one_elt_size_spec) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1623 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1624 final_nr = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1625 final_nc = data_index; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1626 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1627 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1628 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1629 final_nr = nr; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1630 final_nc = (data_index - 1) / nr + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1631 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1632 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1633 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1634 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1635 else if (data_index == max_size) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1636 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1637 max_size *= 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1638 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1639 if (all_char_conv) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1640 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1641 if (one_elt_size_spec) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1642 mval.resize (1, max_size, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1643 else if (nr > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1644 mval.resize (nr, max_size / nr, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1645 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1646 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1647 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1648 else if (nr > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1649 mval.resize (nr, max_size / nr, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1650 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1651 mval.resize (max_size, 1, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1652 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1653 data = mval.fortran_vec (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1654 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1655 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1656 const char *fmt = elt->text; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1657 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1658 bool discard = elt->discard; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1659 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1660 switch (elt->type) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1661 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1662 case scanf_format_elt::whitespace_conversion: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1663 DO_WHITESPACE_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1664 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1665 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1666 case scanf_format_elt::literal_conversion: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1667 DO_LITERAL_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1668 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1669 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1670 case '%': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1671 DO_PCT_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1672 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1673 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1674 case 'd': case 'i': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1675 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1676 switch (elt->modifier) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1677 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1678 case 'h': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1679 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1680 short int tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1681 do_scanf_conv (is, *elt, &tmp, mval, data, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1682 data_index, conversion_count, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1683 nr, max_size, discard); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1684 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1685 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1686 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1687 case 'l': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1688 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1689 long int tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1690 do_scanf_conv (is, *elt, &tmp, mval, data, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1691 data_index, conversion_count, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1692 nr, max_size, discard); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1693 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1694 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1695 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1696 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1697 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1698 int tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1699 do_scanf_conv (is, *elt, &tmp, mval, data, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1700 data_index, conversion_count, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1701 nr, max_size, discard); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1702 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1703 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1704 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1705 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1706 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1707 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1708 case 'o': case 'u': case 'x': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1709 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1710 switch (elt->modifier) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1711 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1712 case 'h': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1713 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1714 unsigned short int tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1715 do_scanf_conv (is, *elt, &tmp, mval, data, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1716 data_index, conversion_count, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1717 nr, max_size, discard); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1718 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1719 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1720 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1721 case 'l': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1722 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1723 unsigned long int tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1724 do_scanf_conv (is, *elt, &tmp, mval, data, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1725 data_index, conversion_count, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1726 nr, max_size, discard); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1727 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1728 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1729 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1730 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1731 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1732 unsigned int tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1733 do_scanf_conv (is, *elt, &tmp, mval, data, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1734 data_index, conversion_count, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1735 nr, max_size, discard); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1736 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1737 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1738 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1739 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1740 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1741 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1742 case 'e': case 'f': case 'g': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1743 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1744 double tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1745 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1746 do_scanf_conv (is, *elt, &tmp, mval, data, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1747 data_index, conversion_count, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1748 nr, max_size, discard); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1749 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1750 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1751 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1752 case 'c': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1753 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1754 BEGIN_C_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1755 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1756 FINISH_CHARACTER_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1757 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1758 is.setf (flags); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1759 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1760 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1761 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1762 case 's': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1763 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1764 BEGIN_S_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1765 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1766 FINISH_CHARACTER_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1767 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1768 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1769 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1770 case '[': case '^': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1771 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1772 BEGIN_CHAR_CLASS_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1773 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1774 FINISH_CHARACTER_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1775 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1776 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1777 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1778 case 'p': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1779 error ("%s: unsupported format specifier", who.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1780 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1781 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1782 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1783 error ("%s: internal format error", who.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1784 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1785 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1786 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1787 if (! ok ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1788 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1789 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1790 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1791 else if (! is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1792 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1793 if (all_char_conv) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1794 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1795 if (one_elt_size_spec) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1796 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1797 final_nr = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1798 final_nc = data_index; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1799 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1800 else if (data_index > nr) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1801 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1802 final_nr = nr; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1803 final_nc = (data_index - 1) / nr + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1804 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1805 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1806 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1807 final_nr = data_index; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1808 final_nc = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1809 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1810 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1811 else if (nr > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1812 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1813 if (data_index > nr) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1814 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1815 final_nr = nr; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1816 final_nc = (data_index - 1) / nr + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1817 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1818 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1819 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1820 final_nr = data_index; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1821 final_nc = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1822 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1823 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1824 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1825 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1826 final_nr = data_index; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1827 final_nc = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1828 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1829 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1830 // 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
|
1831 // reset the failbit in the stream state. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1832 if (is.rdstate () & std::ios::failbit) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1833 is.clear (is.rdstate () & (~std::ios::failbit)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1834 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1835 // FIXME: is this the right thing to do? |
19849
1c9ed5b4c73d
input.h: change meaning of interactive and forced_interactive global variables.
Carnë Draug <carandraug@octave.org>
parents:
19739
diff
changeset
|
1836 if (interactive && ! forced_interactive && name () == "stdin") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1837 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1838 is.clear (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1839 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1840 // Skip to end of line. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1841 bool err; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1842 do_gets (-1, err, false, who); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1843 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1844 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1845 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1846 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1847 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1848 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1849 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1850 error ("%s: internal format error", who.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1851 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1852 } |
2117 | 1853 |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1854 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
|
1855 { |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1856 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
|
1857 { |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1858 final_nr = 1; |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1859 final_nc = data_index; |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1860 } |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1861 else |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1862 { |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1863 final_nr = nr; |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1864 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
|
1865 } |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1866 |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1867 break; |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1868 } |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1869 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
|
1870 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1871 // 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
|
1872 // 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
|
1873 // 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
|
1874 // 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
|
1875 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
|
1876 && (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
|
1877 || 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
|
1878 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1879 } |
2117 | 1880 } |
1881 | |
1882 if (ok ()) | |
1883 { | |
2121 | 1884 mval.resize (final_nr, final_nc, 0.0); |
2117 | 1885 |
3268 | 1886 retval = mval; |
1887 | |
2117 | 1888 if (all_char_conv) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1889 retval = retval.convert_to_str (false, true); |
2117 | 1890 } |
1891 | |
1892 return retval; | |
1893 } | |
1894 | |
1895 octave_value | |
3810 | 1896 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
|
1897 octave_idx_type& conversion_count, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1898 const std::string& who) |
2117 | 1899 { |
1900 octave_value retval = Matrix (); | |
1901 | |
3559 | 1902 conversion_count = 0; |
2117 | 1903 |
3523 | 1904 std::istream *isp = input_stream (); |
2117 | 1905 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1906 if (! isp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1907 invalid_operation (who, "reading"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1908 else |
2117 | 1909 { |
1910 scanf_format_list fmt_list (fmt); | |
1911 | |
3640 | 1912 if (fmt_list.num_conversions () == -1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1913 ::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
|
1914 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1915 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
|
1916 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
|
1917 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1918 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
|
1919 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1920 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
|
1921 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1922 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
|
1923 conversion_count, who); |
2215 | 1924 } |
2572 | 1925 |
1926 return retval; | |
1927 } | |
1928 | |
2712 | 1929 bool |
1930 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
|
1931 octave_value& retval, const std::string& who) |
2572 | 1932 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1933 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
|
1934 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1935 if (! isp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1936 return false; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1937 |
2712 | 1938 bool quit = false; |
2215 | 1939 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1940 std::istream& is = *isp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1941 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1942 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
|
1943 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1944 if (elt) |
2215 | 1945 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1946 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
|
1947 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1948 bool discard = elt->discard; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1949 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1950 switch (elt->type) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1951 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1952 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
|
1953 DO_WHITESPACE_CONVERSION (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1954 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1955 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1956 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
|
1957 DO_LITERAL_CONVERSION (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1958 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1959 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1960 case '%': |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1961 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1962 DO_PCT_CONVERSION (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1963 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1964 if (! is) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1965 quit = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1966 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1967 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1968 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1969 case 'd': case 'i': |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1970 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1971 int tmp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1972 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1973 if (OCTAVE_SCAN (is, *elt, &tmp)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1974 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1975 if (! discard) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1976 retval = tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1977 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1978 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1979 quit = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1980 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1981 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1982 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1983 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
|
1984 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1985 long int tmp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1986 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1987 if (OCTAVE_SCAN (is, *elt, &tmp)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1988 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1989 if (! discard) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1990 retval = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1991 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1992 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1993 quit = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1994 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1995 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1996 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1997 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
|
1998 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
1999 double tmp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2000 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2001 if (OCTAVE_SCAN (is, *elt, &tmp)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2002 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2003 if (! discard) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2004 retval = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2005 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2006 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2007 quit = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2008 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2009 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2010 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2011 case 'c': |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2012 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2013 BEGIN_C_CONVERSION (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2014 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2015 if (! discard) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2016 retval = tmp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2017 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2018 if (! is) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2019 quit = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2020 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2021 is.setf (flags); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2022 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2023 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2024 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2025 case 's': |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2026 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2027 BEGIN_S_CONVERSION (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2028 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2029 if (! discard) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2030 retval = tmp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2031 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2032 if (! is) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2033 quit = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2034 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2035 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2036 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2037 case '[': |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2038 case '^': |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2039 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2040 BEGIN_CHAR_CLASS_CONVERSION (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2041 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2042 if (! discard) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2043 retval = tmp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2044 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2045 if (! is) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2046 quit = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2047 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2048 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2049 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2050 case 'p': |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2051 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
|
2052 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2053 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2054 default: |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2055 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
|
2056 break; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2057 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2058 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2059 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2060 if (ok () && is.fail ()) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2061 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2062 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
|
2063 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2064 // 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
|
2065 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2066 if (interactive && ! forced_interactive && name () == "stdin") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2067 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2068 // 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
|
2069 bool err; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2070 do_gets (-1, err, false, who); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2071 } |
2215 | 2072 } |
2073 | |
2712 | 2074 return quit; |
2215 | 2075 } |
2076 | |
2077 octave_value_list | |
4468 | 2078 octave_base_stream::oscanf (const std::string& fmt, const std::string& who) |
2215 | 2079 { |
2080 octave_value_list retval; | |
2081 | |
3523 | 2082 std::istream *isp = input_stream (); |
2215 | 2083 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2084 if (! isp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2085 invalid_operation (who, "reading"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2086 else |
2215 | 2087 { |
3523 | 2088 std::istream& is = *isp; |
2215 | 2089 |
2090 scanf_format_list fmt_list (fmt); | |
2091 | |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2092 octave_idx_type nconv = fmt_list.num_conversions (); |
2215 | 2093 |
3640 | 2094 if (nconv == -1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2095 ::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
|
2096 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2097 is.clear (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2098 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2099 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
|
2100 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2101 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
|
2102 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2103 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
|
2104 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2105 int num_values = 0; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2106 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2107 bool quit = false; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2108 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2109 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
|
2110 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2111 octave_value tmp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2112 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2113 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
|
2114 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2115 if (quit) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2116 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2117 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2118 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2119 if (tmp.is_defined ()) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2120 retval(num_values++) = tmp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2121 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2122 if (! ok ()) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2123 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2124 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2125 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
|
2126 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2127 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2128 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2129 retval(nconv) = num_values; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2130 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2131 int err_num; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2132 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
|
2133 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2134 if (! quit) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2135 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2136 // 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
|
2137 if (ok () && len > nconv) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2138 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2139 octave_value tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2140 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2141 elt = fmt_list.next (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2142 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2143 do_oscanf (elt, tmp, who); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2144 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2145 } |
2117 | 2146 } |
2147 | |
2148 return retval; | |
2149 } | |
2150 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2151 // 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
|
2152 // (output streams are those that define os). |
2117 | 2153 |
2154 int | |
2155 octave_base_stream::flush (void) | |
2156 { | |
2157 int retval = -1; | |
2158 | |
3523 | 2159 std::ostream *os = output_stream (); |
2117 | 2160 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2161 if (! os) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2162 invalid_operation ("fflush", "writing"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2163 else |
2117 | 2164 { |
2165 os->flush (); | |
2166 | |
2167 if (os->good ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2168 retval = 0; |
2117 | 2169 } |
2170 | |
2171 return retval; | |
2172 } | |
2173 | |
2174 class | |
2175 printf_value_cache | |
2176 { | |
2177 public: | |
2178 | |
3653 | 2179 enum state { ok, conversion_error }; |
2117 | 2180 |
7352 | 2181 printf_value_cache (const octave_value_list& args, const std::string& who) |
2117 | 2182 : 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
|
2183 n_vals (values.length ()), n_elts (0), have_data (false), |
7352 | 2184 curr_state (ok) |
2185 { | |
2186 for (octave_idx_type i = 0; i < values.length (); i++) | |
2187 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2188 octave_value val = values(i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2189 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2190 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
|
2191 err_wrong_type_arg (who, val); |
7352 | 2192 } |
2193 } | |
2117 | 2194 |
2195 ~printf_value_cache (void) { } | |
2196 | |
2197 // 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
|
2198 octave_value get_next_value (char type = 0); |
2117 | 2199 |
2200 // Get the current value as an int and advance the internal pointer. | |
2201 int int_value (void); | |
2202 | |
3145 | 2203 operator bool () const { return (curr_state == ok); } |
2117 | 2204 |
3653 | 2205 bool exhausted (void) { return (val_idx >= n_vals); } |
2117 | 2206 |
2207 private: | |
2208 | |
2209 const octave_value_list values; | |
2210 int val_idx; | |
2211 int elt_idx; | |
2212 int n_vals; | |
2213 int n_elts; | |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2214 bool have_data; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2215 octave_value curr_val; |
2117 | 2216 state curr_state; |
2217 | |
2218 // Must create value cache with values! | |
2219 | |
2220 printf_value_cache (void); | |
2221 | |
2222 // No copying! | |
2223 | |
2224 printf_value_cache (const printf_value_cache&); | |
2225 | |
2226 printf_value_cache& operator = (const printf_value_cache&); | |
2227 }; | |
2228 | |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2229 octave_value |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2230 printf_value_cache::get_next_value (char type) |
2117 | 2231 { |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2232 octave_value retval; |
2117 | 2233 |
3711 | 2234 if (exhausted ()) |
2235 curr_state = conversion_error; | |
2236 | |
2237 while (! exhausted ()) | |
2117 | 2238 { |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2239 if (! have_data) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2240 { |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2241 curr_val = values (val_idx); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2242 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
2243 elt_idx = 0; |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
2244 n_elts = curr_val.numel (); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
2245 have_data = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2246 } |
2117 | 2247 |
2248 if (elt_idx < n_elts) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2249 { |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2250 if (type == 's') |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2251 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2252 if (curr_val.is_string ()) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2253 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2254 std::string sval = curr_val.string_value (); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2255 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2256 retval = sval.substr (elt_idx); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2257 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2258 // We've consumed the rest of the value. |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2259 elt_idx = n_elts; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2260 } |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2261 else |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2262 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2263 // Convert to character string while values are |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2264 // integers in the range [0 : char max] |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2265 const NDArray val = curr_val.array_value (); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2266 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2267 octave_idx_type idx = elt_idx; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2268 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2269 for (; idx < n_elts; idx++) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2270 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2271 double dval = val(idx); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2272 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2273 if (D_NINT (dval) != dval || dval < 0 || dval > 255) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2274 break; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2275 } |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2276 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2277 octave_idx_type n = idx - elt_idx; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2278 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2279 if (n > 0) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2280 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2281 std::string sval (n, '\0'); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2282 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2283 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
|
2284 sval[i] = val(elt_idx++); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2285 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2286 retval = sval; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2287 } |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2288 else |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2289 retval = curr_val.fast_elem_extract (elt_idx++); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2290 } |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2291 } |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2292 else |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2293 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2294 retval = curr_val.fast_elem_extract (elt_idx++); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2295 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2296 if (type == 'c' && ! retval.is_string ()) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2297 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2298 double dval = retval.double_value (); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2299 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2300 if (D_NINT (dval) == dval && dval >= 0 && dval < 256) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2301 retval = static_cast<char> (dval); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2302 } |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2303 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2304 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2305 if (elt_idx >= n_elts) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2306 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2307 elt_idx = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2308 val_idx++; |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2309 have_data = false; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2310 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2311 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2312 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2313 } |
2117 | 2314 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2315 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2316 val_idx++; |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2317 have_data = false; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2318 |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2319 if (n_elts == 0) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2320 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2321 if (elt_idx == 0 && (type == 's' || type == 'c')) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2322 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2323 retval = ""; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2324 break; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2325 } |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2326 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2327 if (exhausted ()) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2328 curr_state = conversion_error; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2329 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2330 } |
2117 | 2331 } |
2332 | |
2333 return retval; | |
2334 } | |
2335 | |
2336 int | |
2337 printf_value_cache::int_value (void) | |
2338 { | |
2339 int retval = 0; | |
2340 | |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2341 octave_value val = get_next_value (); |
2117 | 2342 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
2343 double dval = val.double_value (true); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
2344 |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
2345 if (D_NINT (dval) == dval) |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
2346 retval = NINT (dval); |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
2347 else |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
2348 curr_state = conversion_error; |
2117 | 2349 |
2350 return retval; | |
2351 } | |
2352 | |
2353 // Ugh again and again. | |
2354 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
2355 template <typename T> |
3620 | 2356 int |
3523 | 2357 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
|
2358 int sa_2, T arg, const std::string& who) |
2572 | 2359 { |
3620 | 2360 int retval = 0; |
2361 | |
2572 | 2362 switch (nsa) |
2363 { | |
2364 case 2: | |
3640 | 2365 retval = octave_format (os, fmt, sa_1, sa_2, arg); |
2572 | 2366 break; |
2367 | |
2368 case 1: | |
3640 | 2369 retval = octave_format (os, fmt, sa_1, arg); |
2572 | 2370 break; |
2371 | |
2372 case 0: | |
3640 | 2373 retval = octave_format (os, fmt, arg); |
2572 | 2374 break; |
2375 | |
2376 default: | |
4468 | 2377 ::error ("%s: internal error handling format", who.c_str ()); |
2572 | 2378 break; |
2379 } | |
3620 | 2380 |
2381 return retval; | |
2572 | 2382 } |
2383 | |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2384 static size_t |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2385 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
|
2386 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
|
2387 const std::string& who) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2388 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2389 if (nsa > 2) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20768
diff
changeset
|
2390 ::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
|
2391 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2392 std::string flags = elt->flags; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2393 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2394 bool left = flags.find ('-') != std::string::npos; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2395 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2396 size_t len = arg.length (); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2397 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2398 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
|
2399 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
|
2400 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2401 os << std::setw (fw) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2402 << (left ? std::left : std::right) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2403 << (prec < len ? arg.substr (0, prec) : arg); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2404 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2405 return len > fw ? len : fw; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2406 } |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2407 |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2408 static bool |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2409 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
|
2410 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2411 octave_value ov_isnan = val.isnan (); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2412 octave_value ov_isinf = val.isinf (); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2413 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2414 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
|
2415 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2416 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2417 static bool |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2418 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
|
2419 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2420 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
|
2421 |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2422 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
|
2423 return true; |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2424 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
|
2425 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2426 if (val.is_uint64_type ()) |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2427 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2428 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
|
2429 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2430 if (ival.value () <= limit) |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2431 return true; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2432 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2433 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2434 return true; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2435 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2436 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2437 { |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2438 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
|
2439 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2440 if (dval == xround (dval) && dval <= limit) |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2441 return true; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2442 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2443 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2444 return false; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2445 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2446 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2447 static bool |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2448 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
|
2449 { |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2450 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
|
2451 return true; |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2452 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
|
2453 { |
7d0014bb9e4e
also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents:
18650
diff
changeset
|
2454 // 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
|
2455 |
7d0014bb9e4e
also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents:
18650
diff
changeset
|
2456 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
|
2457 = 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
|
2458 |
7d0014bb9e4e
also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents:
18650
diff
changeset
|
2459 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
|
2460 } |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2461 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2462 { |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2463 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
|
2464 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2465 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
|
2466 |
18653
7d0014bb9e4e
also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents:
18650
diff
changeset
|
2467 if (dval == xround (dval) && dval >= 0 && dval <= limit) |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2468 return true; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2469 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2470 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2471 return false; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2472 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2473 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2474 static std::string |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2475 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
|
2476 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2477 std::string tfmt = elt->text; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2478 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2479 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
|
2480 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2481 return tfmt; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2482 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2483 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2484 int |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2485 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
|
2486 const printf_format_elt *elt, |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2487 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
|
2488 const octave_value& val, |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2489 const std::string& who) |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2490 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2491 int retval = 0; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2492 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2493 const char *fmt = elt->text; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2494 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2495 if (is_nan_or_inf (val)) |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2496 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2497 double dval = val.double_value (); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2498 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2499 std::string tfmt = fmt; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2500 std::string::size_type i1, i2; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2501 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2502 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
|
2503 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2504 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
|
2505 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2506 tfmt.erase (i2, i1-i2); |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2507 if (elt->prec == -2) |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2508 nsa--; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2509 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2510 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2511 const char *tval; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2512 if (lo_ieee_isinf (dval)) |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2513 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2514 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
|
2515 tval = (dval < 0 ? "-Inf" : "+Inf"); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2516 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2517 tval = (dval < 0 ? "-Inf" : "Inf"); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2518 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2519 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2520 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2521 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
|
2522 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
|
2523 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2524 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
|
2525 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2526 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2527 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
|
2528 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2529 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2530 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2531 static std::string llmod |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2532 = 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
|
2533 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2534 char type = elt->type; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2535 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2536 switch (type) |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2537 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2538 case 'd': case 'i': case 'c': |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2539 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
|
2540 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2541 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
|
2542 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2543 // Insert "long" modifier. |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2544 std::string tfmt = fmt; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2545 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
|
2546 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2547 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
|
2548 tval.value (), who); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2549 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2550 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2551 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2552 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
|
2553 |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2554 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
|
2555 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
2556 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
|
2557 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
|
2558 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2559 break; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2560 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2561 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
|
2562 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
|
2563 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2564 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
|
2565 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2566 // Insert "long" modifier. |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2567 std::string tfmt = fmt; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2568 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
|
2569 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2570 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
|
2571 tval.value (), who); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2572 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2573 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2574 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2575 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
|
2576 |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2577 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
|
2578 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
2579 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
|
2580 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
|
2581 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2582 break; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2583 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2584 case 'f': case 'e': case 'E': |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2585 case 'g': case 'G': |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2586 { |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2587 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
|
2588 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
2589 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
|
2590 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2591 break; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2592 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2593 default: |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
2594 // 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
|
2595 // 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
|
2596 error ("%s: invalid format specifier", who.c_str ()); |
20916
8ddb11c0b1f8
restore return statements after calls to octave_base_stream::error
John W. Eaton <jwe@octave.org>
parents:
20893
diff
changeset
|
2597 return -1; |
8ddb11c0b1f8
restore return statements after calls to octave_base_stream::error
John W. Eaton <jwe@octave.org>
parents:
20893
diff
changeset
|
2598 break; |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2599 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2600 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2601 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2602 return retval; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2603 } |
6492 | 2604 |
2117 | 2605 int |
2606 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
|
2607 const octave_value_list& args, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2608 const std::string& who) |
2117 | 2609 { |
3620 | 2610 int retval = 0; |
2117 | 2611 |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2612 octave_idx_type nconv = fmt_list.num_conversions (); |
3640 | 2613 |
3523 | 2614 std::ostream *osp = output_stream (); |
2117 | 2615 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2616 if (! osp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2617 invalid_operation (who, "writing"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2618 else |
2117 | 2619 { |
3523 | 2620 std::ostream& os = *osp; |
2117 | 2621 |
2622 const printf_format_elt *elt = fmt_list.first (); | |
2623 | |
7352 | 2624 printf_value_cache val_cache (args, who); |
2625 | |
2117 | 2626 for (;;) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2627 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2628 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2629 |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2630 if (! elt) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2631 ::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
|
2632 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2633 // 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
|
2634 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
|
2635 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2636 int sa_1 = 0; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2637 int sa_2 = 0; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2638 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2639 if (nsa > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2640 { |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2641 sa_1 = val_cache.int_value (); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2642 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2643 if (! val_cache) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2644 break; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2645 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2646 { |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2647 if (nsa > 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2648 { |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2649 sa_2 = val_cache.int_value (); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2650 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2651 if (! val_cache) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2652 break; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2653 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2654 } |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2655 } |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2656 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2657 if (elt->type == '%') |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2658 { |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2659 os << "%"; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2660 retval++; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2661 } |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2662 else if (elt->args == 0 && elt->text) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2663 { |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2664 os << elt->text; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2665 retval += strlen (elt->text); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2666 } |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2667 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
|
2668 { |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2669 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
|
2670 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2671 if (val_cache) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2672 { |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2673 if (val.is_string ()) |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2674 { |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2675 std::string sval = val.string_value (); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2676 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2677 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
|
2678 sa_2, sval, who); |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
2679 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2680 else |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
2681 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
|
2682 sa_2, val, who); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2683 } |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2684 else |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2685 break; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2686 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2687 else |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2688 { |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2689 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
|
2690 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2691 if (val_cache) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2692 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
|
2693 sa_2, val, who); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2694 else |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2695 break; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2696 } |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2697 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2698 if (! os) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2699 { |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2700 error ("%s: write error", who.c_str ()); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2701 break; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2702 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2703 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2704 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
|
2705 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2706 if (! elt || (val_cache.exhausted () && elt->args > 0)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2707 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2708 } |
2117 | 2709 } |
2710 | |
2711 return retval; | |
2712 } | |
2713 | |
2714 int | |
3640 | 2715 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
|
2716 const octave_value_list& args, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2717 const std::string& who) |
2117 | 2718 { |
3640 | 2719 printf_format_list fmt_list (fmt); |
2720 | |
2721 if (fmt_list.num_conversions () == -1) | |
4468 | 2722 ::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
|
2723 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2724 return do_printf (fmt_list, args, who); |
2117 | 2725 } |
2726 | |
2727 int | |
4468 | 2728 octave_base_stream::puts (const std::string& s, const std::string& who) |
2117 | 2729 { |
2730 int retval = -1; | |
2731 | |
3523 | 2732 std::ostream *osp = output_stream (); |
2117 | 2733 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2734 if (! osp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2735 invalid_operation (who, "writing"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2736 else |
2117 | 2737 { |
3523 | 2738 std::ostream& os = *osp; |
2117 | 2739 |
2740 os << s; | |
2741 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2742 if (! os) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2743 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
|
2744 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2745 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2746 // 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
|
2747 // Without it, output from a loop like |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2748 // |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2749 // 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
|
2750 // |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2751 // 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
|
2752 os.flush (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2753 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2754 if (os) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2755 retval = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2756 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2757 error ("%s: write error", who.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2758 } |
2117 | 2759 } |
2760 | |
2761 return retval; | |
2762 } | |
2763 | |
2764 // Return current error message for this stream. | |
2765 | |
3536 | 2766 std::string |
2435 | 2767 octave_base_stream::error (bool clear_err, int& err_num) |
2117 | 2768 { |
2435 | 2769 err_num = fail ? -1 : 0; |
2117 | 2770 |
3523 | 2771 std::string tmp = errmsg; |
2117 | 2772 |
2773 if (clear_err) | |
2774 clear (); | |
2775 | |
2776 return tmp; | |
2777 } | |
2778 | |
2779 void | |
4468 | 2780 octave_base_stream::invalid_operation (const std::string& who, const char *rw) |
2117 | 2781 { |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
2782 // Note: This calls the member fcn error, not ::error from error.h. |
6297 | 2783 error (who, std::string ("stream not open for ") + rw); |
2117 | 2784 } |
2785 | |
3552 | 2786 octave_stream::octave_stream (octave_base_stream *bs) |
3340 | 2787 : rep (bs) |
2788 { | |
2789 if (rep) | |
2790 rep->count = 1; | |
2791 } | |
2792 | |
2793 octave_stream::~octave_stream (void) | |
2794 { | |
2795 if (rep && --rep->count == 0) | |
2796 delete rep; | |
2797 } | |
2798 | |
2799 octave_stream::octave_stream (const octave_stream& s) | |
2800 : rep (s.rep) | |
2801 { | |
2802 if (rep) | |
2803 rep->count++; | |
2804 } | |
2805 | |
2806 octave_stream& | |
2807 octave_stream::operator = (const octave_stream& s) | |
2808 { | |
2809 if (rep != s.rep) | |
2810 { | |
2811 if (rep && --rep->count == 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2812 delete rep; |
3340 | 2813 |
2814 rep = s.rep; | |
2815 | |
2816 if (rep) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2817 rep->count++; |
3340 | 2818 } |
2819 | |
2820 return *this; | |
2821 } | |
2822 | |
2117 | 2823 int |
2824 octave_stream::flush (void) | |
2825 { | |
2826 int retval = -1; | |
2827 | |
5659 | 2828 if (stream_ok ()) |
2117 | 2829 retval = rep->flush (); |
2830 | |
2831 return retval; | |
2832 } | |
2833 | |
3536 | 2834 std::string |
5275 | 2835 octave_stream::getl (octave_idx_type max_len, bool& err, const std::string& who) |
2117 | 2836 { |
3523 | 2837 std::string retval; |
2117 | 2838 |
5659 | 2839 if (stream_ok ()) |
4468 | 2840 retval = rep->getl (max_len, err, who); |
2117 | 2841 |
2842 return retval; | |
2843 } | |
2844 | |
3536 | 2845 std::string |
4468 | 2846 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
|
2847 const std::string& who) |
2117 | 2848 { |
2849 err = false; | |
2850 | |
2851 int conv_err = 0; | |
2852 | |
6345 | 2853 int max_len = -1; |
2854 | |
2855 if (tc_max_len.is_defined ()) | |
2117 | 2856 { |
6345 | 2857 max_len = convert_to_valid_int (tc_max_len, conv_err); |
2858 | |
2859 if (conv_err || max_len < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2860 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2861 err = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2862 ::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
|
2863 } |
2117 | 2864 } |
6345 | 2865 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2866 return getl (max_len, err, who); |
2117 | 2867 } |
2868 | |
3536 | 2869 std::string |
5275 | 2870 octave_stream::gets (octave_idx_type max_len, bool& err, const std::string& who) |
2117 | 2871 { |
3523 | 2872 std::string retval; |
2117 | 2873 |
5659 | 2874 if (stream_ok ()) |
4468 | 2875 retval = rep->gets (max_len, err, who); |
2117 | 2876 |
2877 return retval; | |
2878 } | |
2879 | |
3536 | 2880 std::string |
4468 | 2881 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
|
2882 const std::string& who) |
2117 | 2883 { |
2884 err = false; | |
2885 | |
2886 int conv_err = 0; | |
2887 | |
6345 | 2888 int max_len = -1; |
2889 | |
2890 if (tc_max_len.is_defined ()) | |
2117 | 2891 { |
6345 | 2892 max_len = convert_to_valid_int (tc_max_len, conv_err); |
2893 | |
2894 if (conv_err || max_len < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2895 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2896 err = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2897 ::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
|
2898 } |
2117 | 2899 } |
6345 | 2900 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2901 return gets (max_len, err, who); |
2117 | 2902 } |
2903 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
2904 off_t |
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
2905 octave_stream::skipl (off_t count, bool& err, const std::string& who) |
9701 | 2906 { |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
2907 off_t retval = -1; |
9701 | 2908 |
2909 if (stream_ok ()) | |
2910 retval = rep->skipl (count, err, who); | |
2911 | |
2912 return retval; | |
2913 } | |
2914 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
2915 off_t |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2916 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
|
2917 const std::string& who) |
9701 | 2918 { |
2919 err = false; | |
2920 | |
2921 int conv_err = 0; | |
2922 | |
2923 int count = 1; | |
2924 | |
2925 if (tc_count.is_defined ()) | |
2926 { | |
2927 if (tc_count.is_scalar_type () && xisinf (tc_count.scalar_value ())) | |
2928 count = -1; | |
2929 else | |
2930 { | |
2931 count = convert_to_valid_int (tc_count, conv_err); | |
2932 | |
2933 if (conv_err || count < 0) | |
2934 { | |
2935 err = true; | |
2936 ::error ("%s: invalid number of lines specified", who.c_str ()); | |
2937 } | |
2938 } | |
2939 } | |
2940 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2941 return skipl (count, err, who); |
9701 | 2942 } |
2943 | |
2117 | 2944 int |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
2945 octave_stream::seek (off_t offset, int origin) |
2117 | 2946 { |
5065 | 2947 int status = -1; |
2117 | 2948 |
5659 | 2949 if (stream_ok ()) |
4889 | 2950 { |
2951 clearerr (); | |
2952 | |
12957
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
2953 // 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
|
2954 off_t orig_pos = rep->tell (); |
5065 | 2955 |
12957
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
2956 // 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
|
2957 status = rep->seek (0, SEEK_END); |
5065 | 2958 |
2959 if (status == 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2960 { |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
2961 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
|
2962 |
12943
8372d50de75a
improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
2963 if (origin == SEEK_CUR) |
8372d50de75a
improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
2964 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2965 // 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
|
2966 // 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
|
2967 // location. |
12943
8372d50de75a
improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
2968 rep->seek (orig_pos, SEEK_SET); |
8372d50de75a
improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
2969 } |
8372d50de75a
improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
2970 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2971 // 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
|
2972 // existing file. |
12957
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
2973 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
|
2974 |
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
2975 if (status == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2976 { |
12957
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
2977 // 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
|
2978 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
|
2979 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2980 // 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
|
2981 // 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
|
2982 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
|
2983 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2984 // 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
|
2985 // 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
|
2986 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
|
2987 |
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
2988 status = -1; |
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
2989 } |
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
2990 } |
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
2991 else |
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
2992 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
2993 // 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
|
2994 // 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
|
2995 rep->seek (orig_pos, SEEK_SET); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2996 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2997 status = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2998 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
2999 } |
4889 | 3000 } |
2117 | 3001 |
5065 | 3002 return status; |
2117 | 3003 } |
3004 | |
3005 int | |
3006 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
|
3007 const octave_value& tc_origin) |
2117 | 3008 { |
3009 int retval = -1; | |
3010 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3011 // 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
|
3012 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
|
3013 off_t xoffset = val.value (); |
4645 | 3014 |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3015 int conv_err = 0; |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3016 |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3017 int origin = SEEK_SET; |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3018 |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3019 if (tc_origin.is_string ()) |
2117 | 3020 { |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3021 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
|
3022 |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3023 if (xorigin == "bof") |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3024 origin = SEEK_SET; |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3025 else if (xorigin == "cof") |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3026 origin = SEEK_CUR; |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3027 else if (xorigin == "eof") |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3028 origin = SEEK_END; |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3029 else |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3030 conv_err = -1; |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3031 } |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3032 else |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3033 { |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3034 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
|
3035 |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3036 if (! conv_err) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
3037 { |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3038 if (xorigin == -1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
3039 origin = SEEK_SET; |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3040 else if (xorigin == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
3041 origin = SEEK_CUR; |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3042 else if (xorigin == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
3043 origin = SEEK_END; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
3044 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
3045 conv_err = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
3046 } |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3047 } |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
3048 |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
3049 if (conv_err) |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
3050 ::error ("fseek: invalid value for origin"); |
2117 | 3051 |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
3052 retval = seek (xoffset, origin); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
3053 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
3054 if (retval != 0) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
3055 // 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
|
3056 error ("fseek: failed to seek to requested position"); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
3057 |
2117 | 3058 return retval; |
3059 } | |
3060 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
3061 off_t |
4797 | 3062 octave_stream::tell (void) |
2117 | 3063 { |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
3064 off_t retval = -1; |
2117 | 3065 |
5659 | 3066 if (stream_ok ()) |
2117 | 3067 retval = rep->tell (); |
3068 | |
3069 return retval; | |
3070 } | |
3071 | |
3072 int | |
3073 octave_stream::rewind (void) | |
3074 { | |
6296 | 3075 return seek (0, SEEK_SET); |
2117 | 3076 } |
3077 | |
3340 | 3078 bool |
3079 octave_stream::is_open (void) const | |
3080 { | |
3081 bool retval = false; | |
3082 | |
5659 | 3083 if (stream_ok ()) |
3340 | 3084 retval = rep->is_open (); |
3085 | |
3086 return retval; | |
3087 } | |
3088 | |
3089 void | |
3090 octave_stream::close (void) | |
3091 { | |
5659 | 3092 if (stream_ok ()) |
3340 | 3093 rep->close (); |
3094 } | |
3095 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
3096 template <typename SRC_T, typename DST_T> |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3097 static octave_value |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3098 convert_and_copy (std::list<void *>& input_buf_list, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3099 octave_idx_type input_buf_elts, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3100 octave_idx_type elts_read, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3101 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
|
3102 bool do_float_fmt_conv, bool do_NA_conv, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3103 oct_mach_info::float_format from_flt_fmt) |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3104 { |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3105 typedef typename DST_T::element_type dst_elt_type; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3106 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3107 DST_T conv (dim_vector (nr, nc)); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3108 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3109 dst_elt_type *conv_data = conv.fortran_vec (); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3110 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3111 octave_idx_type j = 0; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3112 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3113 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
|
3114 it != input_buf_list.end (); it++) |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3115 { |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3116 SRC_T *data = static_cast<SRC_T *> (*it); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3117 |
17463 | 3118 if (swap || do_float_fmt_conv) |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3119 { |
17463 | 3120 for (octave_idx_type i = 0; i < input_buf_elts && j < elts_read; |
3121 i++, j++) | |
3122 { | |
3123 if (swap) | |
3124 swap_bytes<sizeof (SRC_T)> (&data[i]); | |
3125 else if (do_float_fmt_conv) | |
3126 do_float_format_conversion (&data[i], sizeof (SRC_T), | |
3127 1, from_flt_fmt, | |
20432
a76e20f2f156
Fix IEEE big-endian/little endian conversions in oct-stream (bug #45687).
Rik <rik@octave.org>
parents:
20253
diff
changeset
|
3128 oct_mach_info::native_float_format ()); |
17463 | 3129 |
3130 dst_elt_type tmp (data[i]); | |
3131 | |
3132 if (do_NA_conv && __lo_ieee_is_old_NA (tmp)) | |
3133 tmp = __lo_ieee_replace_old_NA (tmp); | |
3134 | |
3135 conv_data[j] = tmp; | |
3136 } | |
3137 } | |
3138 else | |
3139 { | |
3140 if (do_NA_conv) | |
3141 { | |
3142 for (octave_idx_type i = 0; i < input_buf_elts && j < elts_read; | |
3143 i++, j++) | |
3144 { | |
3145 dst_elt_type tmp (data[i]); | |
3146 | |
3147 if (__lo_ieee_is_old_NA (tmp)) | |
3148 tmp = __lo_ieee_replace_old_NA (tmp); | |
3149 | |
3150 conv_data[j] = tmp; | |
3151 } | |
3152 } | |
3153 else | |
3154 { | |
3155 for (octave_idx_type i = 0; i < input_buf_elts && j < elts_read; | |
3156 i++, j++) | |
3157 conv_data[j] = data[i]; | |
3158 } | |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3159 } |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3160 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3161 delete [] data; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3162 } |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3163 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3164 input_buf_list.clear (); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3165 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3166 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
|
3167 conv_data[i] = dst_elt_type (0); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3168 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3169 return conv; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3170 } |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3171 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3172 typedef octave_value (*conv_fptr) |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3173 (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
|
3174 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
|
3175 bool swap, bool do_float_fmt_conv, bool do_NA_conv, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3176 oct_mach_info::float_format from_flt_fmt); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3177 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3178 #define TABLE_ELT(T, U, V, W) \ |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3179 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
|
3180 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3181 #define FILL_TABLE_ROW(T, V) \ |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3182 TABLE_ELT (T, dt_int8, V, int8NDArray); \ |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3183 TABLE_ELT (T, dt_uint8, V, uint8NDArray); \ |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3184 TABLE_ELT (T, dt_int16, V, int16NDArray); \ |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3185 TABLE_ELT (T, dt_uint16, V, uint16NDArray); \ |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3186 TABLE_ELT (T, dt_int32, V, int32NDArray); \ |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3187 TABLE_ELT (T, dt_uint32, V, uint32NDArray); \ |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3188 TABLE_ELT (T, dt_int64, V, int64NDArray); \ |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3189 TABLE_ELT (T, dt_uint64, V, uint64NDArray); \ |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3190 TABLE_ELT (T, dt_single, V, FloatNDArray); \ |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3191 TABLE_ELT (T, dt_double, V, NDArray); \ |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3192 TABLE_ELT (T, dt_char, V, charNDArray); \ |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3193 TABLE_ELT (T, dt_schar, V, charNDArray); \ |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3194 TABLE_ELT (T, dt_uchar, V, charNDArray); \ |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3195 TABLE_ELT (T, dt_logical, V, boolNDArray); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3196 |
2117 | 3197 octave_value |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3198 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
|
3199 octave_idx_type input_buf_elts, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3200 octave_idx_type elts_read, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3201 octave_idx_type nr, octave_idx_type nc, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3202 oct_data_conv::data_type input_type, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3203 oct_data_conv::data_type output_type, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3204 oct_mach_info::float_format ffmt) |
2117 | 3205 { |
3206 octave_value retval; | |
3207 | |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3208 static bool initialized = false; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3209 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3210 // Table function pointers for return types x read types. |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3211 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3212 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
|
3213 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3214 if (! initialized) |
4944 | 3215 { |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3216 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
|
3217 for (int j = 0; j < 14; j++) |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3218 conv_fptr_table[i][j] = 0; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3219 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3220 FILL_TABLE_ROW (dt_int8, int8_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3221 FILL_TABLE_ROW (dt_uint8, uint8_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3222 FILL_TABLE_ROW (dt_int16, int16_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3223 FILL_TABLE_ROW (dt_uint16, uint16_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3224 FILL_TABLE_ROW (dt_int32, int32_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3225 FILL_TABLE_ROW (dt_uint32, uint32_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3226 FILL_TABLE_ROW (dt_int64, int64_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3227 FILL_TABLE_ROW (dt_uint64, uint64_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3228 FILL_TABLE_ROW (dt_single, float); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3229 FILL_TABLE_ROW (dt_double, double); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3230 FILL_TABLE_ROW (dt_char, char); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3231 FILL_TABLE_ROW (dt_schar, signed char); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3232 FILL_TABLE_ROW (dt_uchar, unsigned char); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3233 FILL_TABLE_ROW (dt_logical, bool); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3234 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3235 initialized = true; |
4944 | 3236 } |
3237 | |
3238 bool swap = false; | |
3239 | |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3240 if (ffmt == oct_mach_info::flt_fmt_unknown) |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3241 ffmt = float_format (); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3242 |
4944 | 3243 if (oct_mach_info::words_big_endian ()) |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3244 swap = (ffmt == oct_mach_info::flt_fmt_ieee_little_endian); |
4944 | 3245 else |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3246 swap = (ffmt == oct_mach_info::flt_fmt_ieee_big_endian); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3247 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3248 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
|
3249 || input_type == oct_data_conv::dt_single) |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3250 && ffmt != float_format ()); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3251 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3252 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
|
3253 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3254 switch (output_type) |
4944 | 3255 { |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3256 case oct_data_conv::dt_int8: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3257 case oct_data_conv::dt_uint8: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3258 case oct_data_conv::dt_int16: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3259 case oct_data_conv::dt_uint16: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3260 case oct_data_conv::dt_int32: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3261 case oct_data_conv::dt_uint32: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3262 case oct_data_conv::dt_int64: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3263 case oct_data_conv::dt_uint64: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3264 case oct_data_conv::dt_single: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3265 case oct_data_conv::dt_double: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3266 case oct_data_conv::dt_char: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3267 case oct_data_conv::dt_schar: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3268 case oct_data_conv::dt_uchar: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3269 case oct_data_conv::dt_logical: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3270 { |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3271 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
|
3272 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3273 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
|
3274 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
|
3275 } |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3276 break; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3277 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3278 default: |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
3279 ::error ("read: invalid type specification"); |
4944 | 3280 } |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3281 |
4944 | 3282 return retval; |
3283 } | |
3284 | |
3285 octave_value | |
5275 | 3286 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
|
3287 oct_data_conv::data_type input_type, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
3288 oct_data_conv::data_type output_type, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
3289 octave_idx_type skip, oct_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
|
3290 octave_idx_type& count) |
4944 | 3291 { |
3292 octave_value retval; | |
3293 | |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3294 octave_idx_type nr = -1; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3295 octave_idx_type nc = -1; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3296 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3297 bool one_elt_size_spec = false; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
3298 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3299 if (! stream_ok ()) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3300 return retval; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3301 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3302 // 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
|
3303 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3304 // 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
|
3305 // 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
|
3306 // 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
|
3307 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3308 // 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
|
3309 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
|
3310 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3311 count = 0; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3312 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3313 try |
4944 | 3314 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3315 get_size (size, nr, nc, one_elt_size_spec, "fread"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3316 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3317 catch (const octave_execution_exception&) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3318 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3319 invalid_operation ("fread", "reading"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3320 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3321 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3322 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
|
3323 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3324 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
|
3325 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3326 // 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
|
3327 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3328 // 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
|
3329 // number of rows. |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3330 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3331 // 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
|
3332 // 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
|
3333 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3334 if (nr == 0) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3335 nr = nc = 0; |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
3336 else |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3337 nc = 1; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3338 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3339 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3340 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3341 // 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
|
3342 // 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
|
3343 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3344 // 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
|
3345 // should be. |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3346 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3347 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
|
3348 nr = nc = 0; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3349 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3350 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3351 // 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
|
3352 // 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
|
3353 // 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
|
3354 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
|
3355 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3356 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
|
3357 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3358 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
|
3359 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3360 if (skip == 0) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3361 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3362 if (read_to_eof) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3363 input_buf_elts = 1024 * 1024; |
4944 | 3364 else |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3365 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
|
3366 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3367 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3368 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
|
3369 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3370 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
|
3371 = 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
|
3372 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3373 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
|
3374 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3375 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
|
3376 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3377 // 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
|
3378 // 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
|
3379 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
|
3380 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3381 if (! isp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3382 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
|
3383 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3384 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3385 std::istream& is = *isp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3386 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3387 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
|
3388 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3389 while (is && ! is.eof () |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3390 && (read_to_eof || count < elts_to_read)) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
3391 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3392 if (! read_to_eof) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3393 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3394 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
|
3395 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3396 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
|
3397 input_buf_size = remaining_elts * input_elt_size; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3398 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3399 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3400 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
|
3401 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3402 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
|
3403 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3404 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
|
3405 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3406 char_count += gcount; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3407 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3408 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
|
3409 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3410 count += nel; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3411 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3412 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
|
3413 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3414 if (is && skip != 0 && nel == block_size) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
3415 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3416 // Seek to skip. |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3417 // 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
|
3418 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3419 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
|
3420 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3421 seek (0, SEEK_END); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3422 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3423 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
|
3424 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3425 // 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
|
3426 // the original position? |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3427 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
|
3428 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3429 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
|
3430 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3431 if (remaining < skip) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3432 seek (0, SEEK_END); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3433 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3434 seek (skip, SEEK_CUR); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3435 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3436 if (! is) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3437 break; |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
3438 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3439 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3440 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3441 if (read_to_eof) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3442 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3443 if (nc < 0) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
3444 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3445 nc = count / nr; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3446 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
3447 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
|
3448 nc++; |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
3449 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3450 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3451 nr = count; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3452 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3453 else if (count == 0) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3454 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3455 nr = 0; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3456 nc = 0; |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
3457 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3458 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
|
3459 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3460 if (count % nr != 0) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3461 nc = count / nr + 1; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3462 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3463 nc = count / nr; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3464 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3465 if (count < nr) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3466 nr = count; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3467 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3468 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3469 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
|
3470 nr, nc, input_type, output_type, ffmt); |
4944 | 3471 } |
2117 | 3472 |
3473 return retval; | |
3474 } | |
3475 | |
5275 | 3476 octave_idx_type |
3477 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
|
3478 oct_data_conv::data_type output_type, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3479 octave_idx_type skip, oct_mach_info::float_format flt_fmt) |
2117 | 3480 { |
5275 | 3481 octave_idx_type retval = -1; |
2117 | 3482 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3483 if (! stream_ok ()) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3484 invalid_operation ("fwrite", "writing"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3485 else |
4944 | 3486 { |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
3487 if (flt_fmt == oct_mach_info::flt_fmt_unknown) |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
3488 flt_fmt = float_format (); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
3489 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
3490 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
|
3491 skip, flt_fmt); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
3492 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
3493 if (status < 0) |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
3494 error ("fwrite: write error"); |
4944 | 3495 else |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
3496 retval = status; |
4944 | 3497 } |
2117 | 3498 |
3499 return retval; | |
3500 } | |
3501 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
3502 template <typename T, typename V> |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3503 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
|
3504 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
|
3505 { |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
3506 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
|
3507 |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
3508 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
|
3509 |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
3510 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
|
3511 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
|
3512 } |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
3513 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
3514 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
|
3515 static void |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3516 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
|
3517 bool swap) |
4944 | 3518 { |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3519 typedef typename V::val_type val_type; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3520 |
19739
3fa35defe495
Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19729
diff
changeset
|
3521 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
|
3522 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3523 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
|
3524 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3525 // 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
|
3526 V val (data[i]); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3527 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3528 vt_data[i] = val.value (); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3529 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3530 if (swap) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3531 swap_bytes<sizeof (val_type)> (&vt_data[i]); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3532 } |
4944 | 3533 } |
3534 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
3535 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
|
3536 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
|
3537 { |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
3538 public: |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
3539 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
|
3540 }; |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
3541 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
3542 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
|
3543 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
|
3544 { |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
3545 public: |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
3546 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
|
3547 }; |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
3548 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
3549 template <typename T> |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3550 static bool |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3551 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
|
3552 oct_data_conv::data_type output_type, |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3553 oct_mach_info::float_format flt_fmt) |
4944 | 3554 { |
3555 bool retval = true; | |
3556 | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3557 bool swap |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3558 = ((oct_mach_info::words_big_endian () |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3559 && flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3560 || flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3561 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3562 bool do_float_conversion = flt_fmt != oct_mach_info::float_format (); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3563 |
18616
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
3564 typedef typename ultimate_element_type<T>::type ult_elt_type; |
4944 | 3565 |
3566 switch (output_type) | |
3567 { | |
3568 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
|
3569 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
|
3570 break; |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
3571 |
4944 | 3572 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
|
3573 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
|
3574 break; |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
3575 |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
3576 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
|
3577 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
|
3578 break; |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
3579 |
4944 | 3580 case oct_data_conv::dt_int8: |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3581 convert_ints<T, octave_int8> (data, conv_data, n_elts, swap); |
4944 | 3582 break; |
3583 | |
3584 case oct_data_conv::dt_uint8: | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3585 convert_ints<T, octave_uint8> (data, conv_data, n_elts, swap); |
4944 | 3586 break; |
3587 | |
3588 case oct_data_conv::dt_int16: | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3589 convert_ints<T, octave_int16> (data, conv_data, n_elts, swap); |
4944 | 3590 break; |
3591 | |
3592 case oct_data_conv::dt_uint16: | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3593 convert_ints<T, octave_uint16> (data, conv_data, n_elts, swap); |
4944 | 3594 break; |
3595 | |
3596 case oct_data_conv::dt_int32: | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3597 convert_ints<T, octave_int32> (data, conv_data, n_elts, swap); |
4944 | 3598 break; |
3599 | |
3600 case oct_data_conv::dt_uint32: | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3601 convert_ints<T, octave_uint32> (data, conv_data, n_elts, swap); |
4944 | 3602 break; |
3603 | |
3604 case oct_data_conv::dt_int64: | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3605 convert_ints<T, octave_int64> (data, conv_data, n_elts, swap); |
4944 | 3606 break; |
3607 | |
3608 case oct_data_conv::dt_uint64: | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3609 convert_ints<T, octave_uint64> (data, conv_data, n_elts, swap); |
4944 | 3610 break; |
3611 | |
3612 case oct_data_conv::dt_single: | |
3613 { | |
19739
3fa35defe495
Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19729
diff
changeset
|
3614 float *vt_data = static_cast<float *> (conv_data); |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3615 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3616 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
|
3617 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3618 vt_data[i] = data[i]; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3619 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3620 if (do_float_conversion) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3621 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
|
3622 } |
4944 | 3623 } |
3624 break; | |
3625 | |
3626 case oct_data_conv::dt_double: | |
3627 { | |
19739
3fa35defe495
Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19729
diff
changeset
|
3628 double *vt_data = static_cast<double *> (conv_data); |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3629 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3630 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
|
3631 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3632 vt_data[i] = data[i]; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3633 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3634 if (do_float_conversion) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3635 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
|
3636 } |
4944 | 3637 } |
3638 break; | |
3639 | |
3640 default: | |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
3641 ::error ("write: invalid type specification"); |
4944 | 3642 } |
3643 | |
3644 return retval; | |
3645 } | |
3646 | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3647 bool |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3648 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
|
3649 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3650 bool status = false; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3651 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3652 std::ostream *osp = output_stream (); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3653 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3654 if (osp) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3655 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3656 std::ostream& os = *osp; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3657 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3658 if (os) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3659 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3660 os.write (static_cast<const char *> (data), nbytes); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3661 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3662 if (os) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3663 status = true; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3664 } |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3665 } |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3666 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3667 return status; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3668 } |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3669 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3670 bool |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3671 octave_stream::skip_bytes (size_t skip) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3672 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3673 bool status = false; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3674 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3675 std::ostream *osp = output_stream (); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3676 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3677 if (! osp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3678 return false; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3679 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3680 std::ostream& os = *osp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3681 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3682 // 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
|
3683 // 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
|
3684 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
|
3685 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3686 seek (0, SEEK_END); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3687 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3688 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
|
3689 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3690 // 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
|
3691 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
|
3692 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3693 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
|
3694 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3695 if (remaining < skip) |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3696 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3697 seek (0, SEEK_END); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3698 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3699 // 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
|
3700 unsigned char zero = 0; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3701 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
|
3702 os.write (reinterpret_cast<const char *> (&zero), 1); |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3703 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3704 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3705 seek (skip, SEEK_CUR); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3706 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3707 if (os) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
3708 status = true; |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3709 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3710 return status; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3711 } |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3712 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
3713 template <typename T> |
5275 | 3714 octave_idx_type |
3715 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
|
3716 oct_data_conv::data_type output_type, |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3717 octave_idx_type skip, |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3718 oct_mach_info::float_format flt_fmt) |
4944 | 3719 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3720 bool swap = ((oct_mach_info::words_big_endian () |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3721 && flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3722 || flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3723 |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3724 bool do_data_conversion = (swap || ! is_equivalent_type<T> (output_type) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3725 || flt_fmt != oct_mach_info::float_format ()); |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3726 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3727 octave_idx_type nel = data.numel (); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3728 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3729 octave_idx_type chunk_size; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3730 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3731 if (skip != 0) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3732 chunk_size = block_size; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3733 else if (do_data_conversion) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3734 chunk_size = 1024 * 1024; |
4944 | 3735 else |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3736 chunk_size = nel; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3737 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3738 octave_idx_type i = 0; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3739 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3740 const T *pdata = data.data (); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3741 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3742 while (i < nel) |
4944 | 3743 { |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3744 if (skip != 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
3745 { |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3746 if (! skip_bytes (skip)) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3747 return -1; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3748 } |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3749 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3750 octave_idx_type remaining_nel = nel - i; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3751 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3752 if (chunk_size > remaining_nel) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3753 chunk_size = remaining_nel; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3754 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3755 bool status = false; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3756 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3757 if (do_data_conversion) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3758 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3759 size_t output_size |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3760 = 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
|
3761 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3762 OCTAVE_LOCAL_BUFFER (unsigned char, conv_data, output_size); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3763 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3764 status = convert_data (&pdata[i], conv_data, chunk_size, |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3765 output_type, flt_fmt); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3766 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3767 if (status) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3768 status = write_bytes (conv_data, output_size); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
3769 } |
4944 | 3770 else |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3771 status = write_bytes (pdata, sizeof (T) * chunk_size); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3772 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3773 if (! status) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3774 return -1; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3775 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3776 i += chunk_size; |
4944 | 3777 } |
3778 | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3779 return nel; |
4944 | 3780 } |
3781 | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3782 #define INSTANTIATE_WRITE(T) \ |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3783 template \ |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3784 octave_idx_type \ |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3785 octave_stream::write (const Array<T>& data, octave_idx_type block_size, \ |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3786 oct_data_conv::data_type output_type, \ |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3787 octave_idx_type skip, \ |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3788 oct_mach_info::float_format flt_fmt) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3789 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3790 INSTANTIATE_WRITE (octave_int8); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3791 INSTANTIATE_WRITE (octave_uint8); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3792 INSTANTIATE_WRITE (octave_int16); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3793 INSTANTIATE_WRITE (octave_uint16); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3794 INSTANTIATE_WRITE (octave_int32); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3795 INSTANTIATE_WRITE (octave_uint32); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3796 INSTANTIATE_WRITE (octave_int64); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3797 INSTANTIATE_WRITE (octave_uint64); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3798 INSTANTIATE_WRITE (int8_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3799 INSTANTIATE_WRITE (uint8_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3800 INSTANTIATE_WRITE (int16_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3801 INSTANTIATE_WRITE (uint16_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3802 INSTANTIATE_WRITE (int32_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3803 INSTANTIATE_WRITE (uint32_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3804 INSTANTIATE_WRITE (int64_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3805 INSTANTIATE_WRITE (uint64_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3806 INSTANTIATE_WRITE (bool); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3807 INSTANTIATE_WRITE (char); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3808 INSTANTIATE_WRITE (float); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3809 INSTANTIATE_WRITE (double); |
4944 | 3810 |
2117 | 3811 octave_value |
3810 | 3812 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
|
3813 octave_idx_type& count, const std::string& who) |
2117 | 3814 { |
3815 octave_value retval; | |
3816 | |
5659 | 3817 if (stream_ok ()) |
4468 | 3818 retval = rep->scanf (fmt, size, count, who); |
2117 | 3819 |
3820 return retval; | |
3821 } | |
3822 | |
5279 | 3823 octave_value |
3824 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
|
3825 octave_idx_type& count, const std::string& who) |
5279 | 3826 { |
3827 octave_value retval = Matrix (); | |
3828 | |
3829 if (fmt.is_string ()) | |
3830 { | |
3831 std::string sfmt = fmt.string_value (); | |
3832 | |
3833 if (fmt.is_sq_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
3834 sfmt = do_string_escapes (sfmt); |
5279 | 3835 |
3836 retval = scanf (sfmt, size, count, who); | |
3837 } | |
3838 else | |
3839 { | |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
3840 // Note: error is member fcn from octave_stream, not ::error. |
5279 | 3841 error (who + ": format must be a string"); |
3842 } | |
3843 | |
3844 return retval; | |
3845 } | |
3846 | |
2215 | 3847 octave_value_list |
4468 | 3848 octave_stream::oscanf (const std::string& fmt, const std::string& who) |
2215 | 3849 { |
3850 octave_value_list retval; | |
3851 | |
5659 | 3852 if (stream_ok ()) |
4468 | 3853 retval = rep->oscanf (fmt, who); |
2215 | 3854 |
3855 return retval; | |
3856 } | |
3857 | |
5279 | 3858 octave_value_list |
3859 octave_stream::oscanf (const octave_value& fmt, const std::string& who) | |
3860 { | |
3861 octave_value_list retval; | |
3862 | |
3863 if (fmt.is_string ()) | |
3864 { | |
3865 std::string sfmt = fmt.string_value (); | |
3866 | |
3867 if (fmt.is_sq_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
3868 sfmt = do_string_escapes (sfmt); |
5279 | 3869 |
3870 retval = oscanf (sfmt, who); | |
3871 } | |
3872 else | |
3873 { | |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
3874 // Note: error is member fcn from octave_stream, not ::error. |
5279 | 3875 error (who + ": format must be a string"); |
3876 } | |
3877 | |
3878 return retval; | |
3879 } | |
3880 | |
2117 | 3881 int |
4468 | 3882 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
|
3883 const std::string& who) |
2117 | 3884 { |
3885 int retval = -1; | |
3886 | |
5659 | 3887 if (stream_ok ()) |
4468 | 3888 retval = rep->printf (fmt, args, who); |
2117 | 3889 |
3890 return retval; | |
3891 } | |
3892 | |
3893 int | |
5279 | 3894 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
|
3895 const std::string& who) |
5279 | 3896 { |
3897 int retval = 0; | |
3898 | |
3899 if (fmt.is_string ()) | |
3900 { | |
3901 std::string sfmt = fmt.string_value (); | |
3902 | |
3903 if (fmt.is_sq_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
3904 sfmt = do_string_escapes (sfmt); |
5279 | 3905 |
3906 retval = printf (sfmt, args, who); | |
3907 } | |
3908 else | |
3909 { | |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
3910 // Note: error is member fcn from octave_stream, not ::error. |
5279 | 3911 error (who + ": format must be a string"); |
3912 } | |
3913 | |
3914 return retval; | |
3915 } | |
3916 | |
3917 int | |
4468 | 3918 octave_stream::puts (const std::string& s, const std::string& who) |
2117 | 3919 { |
3920 int retval = -1; | |
3921 | |
5659 | 3922 if (stream_ok ()) |
4468 | 3923 retval = rep->puts (s, who); |
2117 | 3924 |
3925 return retval; | |
3926 } | |
3927 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3928 // FIXME: maybe this should work for string arrays too. |
2117 | 3929 |
3930 int | |
4468 | 3931 octave_stream::puts (const octave_value& tc_s, const std::string& who) |
2117 | 3932 { |
3933 int retval = -1; | |
3934 | |
3935 if (tc_s.is_string ()) | |
3936 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3937 std::string s = tc_s.string_value (); |
5279 | 3938 retval = puts (s, who); |
2117 | 3939 } |
3940 else | |
4468 | 3941 { |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
3942 // Note: error is member fcn from octave_stream, not ::error. |
4468 | 3943 error (who + ": argument must be a string"); |
3944 } | |
2117 | 3945 |
3946 return retval; | |
3947 } | |
3948 | |
3949 bool | |
3950 octave_stream::eof (void) const | |
3951 { | |
3952 int retval = -1; | |
3953 | |
5659 | 3954 if (stream_ok ()) |
2117 | 3955 retval = rep->eof (); |
3956 | |
3957 return retval; | |
3958 } | |
3959 | |
3536 | 3960 std::string |
2435 | 3961 octave_stream::error (bool clear, int& err_num) |
2117 | 3962 { |
5649 | 3963 std::string retval = "invalid stream object"; |
3964 | |
5659 | 3965 if (stream_ok (false)) |
2435 | 3966 retval = rep->error (clear, err_num); |
2117 | 3967 |
3968 return retval; | |
3969 } | |
3970 | |
3536 | 3971 std::string |
3340 | 3972 octave_stream::name (void) const |
2117 | 3973 { |
3523 | 3974 std::string retval; |
2117 | 3975 |
5659 | 3976 if (stream_ok ()) |
2117 | 3977 retval = rep->name (); |
3978 | |
3979 return retval; | |
3980 } | |
3981 | |
3982 int | |
3340 | 3983 octave_stream::mode (void) const |
2117 | 3984 { |
3985 int retval = 0; | |
3986 | |
5659 | 3987 if (stream_ok ()) |
2117 | 3988 retval = rep->mode (); |
3989 | |
3990 return retval; | |
3991 } | |
3992 | |
2317 | 3993 oct_mach_info::float_format |
3340 | 3994 octave_stream::float_format (void) const |
2117 | 3995 { |
4574 | 3996 oct_mach_info::float_format retval = oct_mach_info::flt_fmt_unknown; |
2317 | 3997 |
5659 | 3998 if (stream_ok ()) |
2317 | 3999 retval = rep->float_format (); |
2117 | 4000 |
4001 return retval; | |
4002 } | |
4003 | |
3536 | 4004 std::string |
2117 | 4005 octave_stream::mode_as_string (int mode) |
4006 { | |
3523 | 4007 std::string retval = "???"; |
3775 | 4008 std::ios::openmode in_mode = static_cast<std::ios::openmode> (mode); |
4009 | |
4010 if (in_mode == std::ios::in) | |
4011 retval = "r"; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
4012 else if (in_mode == std::ios::out |
4078 | 4013 || in_mode == (std::ios::out | std::ios::trunc)) |
3775 | 4014 retval = "w"; |
4078 | 4015 else if (in_mode == (std::ios::out | std::ios::app)) |
3775 | 4016 retval = "a"; |
4078 | 4017 else if (in_mode == (std::ios::in | std::ios::out)) |
3775 | 4018 retval = "r+"; |
4078 | 4019 else if (in_mode == (std::ios::in | std::ios::out | std::ios::trunc)) |
3775 | 4020 retval = "w+"; |
4078 | 4021 else if (in_mode == (std::ios::in | std::ios::out | std::ios::ate)) |
3775 | 4022 retval = "a+"; |
4078 | 4023 else if (in_mode == (std::ios::in | std::ios::binary)) |
3775 | 4024 retval = "rb"; |
4078 | 4025 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
|
4026 || in_mode == (std::ios::out | std::ios::trunc | std::ios::binary)) |
3775 | 4027 retval = "wb"; |
4078 | 4028 else if (in_mode == (std::ios::out | std::ios::app | std::ios::binary)) |
3775 | 4029 retval = "ab"; |
4078 | 4030 else if (in_mode == (std::ios::in | std::ios::out | std::ios::binary)) |
3775 | 4031 retval = "r+b"; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
4032 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
|
4033 | std::ios::binary)) |
3775 | 4034 retval = "w+b"; |
4078 | 4035 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
|
4036 | std::ios::binary)) |
3775 | 4037 retval = "a+b"; |
2117 | 4038 |
4039 return retval; | |
4040 } | |
4041 | |
4042 octave_stream_list *octave_stream_list::instance = 0; | |
4043 | |
2926 | 4044 bool |
4045 octave_stream_list::instance_ok (void) | |
4046 { | |
4047 bool retval = true; | |
4048 | |
4049 if (! instance) | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13271
diff
changeset
|
4050 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13271
diff
changeset
|
4051 instance = new octave_stream_list (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13271
diff
changeset
|
4052 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13271
diff
changeset
|
4053 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13271
diff
changeset
|
4054 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
|
4055 } |
2926 | 4056 |
4057 if (! instance) | |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20768
diff
changeset
|
4058 ::error ("unable to create stream list object!"); |
2926 | 4059 |
4060 return retval; | |
4061 } | |
4062 | |
5353 | 4063 int |
6757 | 4064 octave_stream_list::insert (octave_stream& os) |
2926 | 4065 { |
5353 | 4066 return (instance_ok ()) ? instance->do_insert (os) : -1; |
2926 | 4067 } |
4068 | |
3340 | 4069 octave_stream |
3523 | 4070 octave_stream_list::lookup (int fid, const std::string& who) |
2926 | 4071 { |
3341 | 4072 return (instance_ok ()) ? instance->do_lookup (fid, who) : octave_stream (); |
2926 | 4073 } |
4074 | |
3340 | 4075 octave_stream |
3523 | 4076 octave_stream_list::lookup (const octave_value& fid, const std::string& who) |
2926 | 4077 { |
3341 | 4078 return (instance_ok ()) ? instance->do_lookup (fid, who) : octave_stream (); |
2926 | 4079 } |
4080 | |
4081 int | |
3523 | 4082 octave_stream_list::remove (int fid, const std::string& who) |
2926 | 4083 { |
3341 | 4084 return (instance_ok ()) ? instance->do_remove (fid, who) : -1; |
2926 | 4085 } |
4086 | |
4087 int | |
3523 | 4088 octave_stream_list::remove (const octave_value& fid, const std::string& who) |
2926 | 4089 { |
3341 | 4090 return (instance_ok ()) ? instance->do_remove (fid, who) : -1; |
2926 | 4091 } |
4092 | |
4093 void | |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
4094 octave_stream_list::clear (bool flush) |
2926 | 4095 { |
4096 if (instance) | |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
4097 instance->do_clear (flush); |
2926 | 4098 } |
4099 | |
4100 string_vector | |
4101 octave_stream_list::get_info (int fid) | |
4102 { | |
4103 return (instance_ok ()) ? instance->do_get_info (fid) : string_vector (); | |
4104 } | |
4105 | |
4106 string_vector | |
4107 octave_stream_list::get_info (const octave_value& fid) | |
4108 { | |
4109 return (instance_ok ()) ? instance->do_get_info (fid) : string_vector (); | |
4110 } | |
4111 | |
3536 | 4112 std::string |
2926 | 4113 octave_stream_list::list_open_files (void) |
4114 { | |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20982
diff
changeset
|
4115 return (instance_ok ()) ? instance->do_list_open_files () : ""; |
2926 | 4116 } |
4117 | |
4118 octave_value | |
4119 octave_stream_list::open_file_numbers (void) | |
4120 { | |
4121 return (instance_ok ()) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4122 ? instance->do_open_file_numbers () : octave_value (); |
2926 | 4123 } |
4124 | |
4125 int | |
4126 octave_stream_list::get_file_number (const octave_value& fid) | |
4127 { | |
4128 return (instance_ok ()) ? instance->do_get_file_number (fid) : -1; | |
4129 } | |
4130 | |
5353 | 4131 int |
6757 | 4132 octave_stream_list::do_insert (octave_stream& os) |
2117 | 4133 { |
6757 | 4134 // Insert item with key corresponding to file-descriptor. |
4135 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4136 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
|
4137 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4138 if (stream_number == -1) |
6757 | 4139 return stream_number; |
4140 | |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
4141 // 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
|
4142 // |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
4143 // (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
|
4144 // && 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
|
4145 // |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
4146 // 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
|
4147 // 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
|
4148 // 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
|
4149 // 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
|
4150 // 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
|
4151 // 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
|
4152 // before. |
6757 | 4153 |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4154 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
|
4155 ::error ("could not create file id"); |
2117 | 4156 |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4157 list[stream_number] = os; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4158 |
5353 | 4159 return stream_number; |
2117 | 4160 } |
4161 | |
21040
3e7cfee5f786
maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents:
21029
diff
changeset
|
4162 OCTAVE_NORETURN static |
21029
e3b3bb522d62
maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
4163 void |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
4164 err_invalid_file_id (int fid, const std::string& who) |
3341 | 4165 { |
4166 if (who.empty ()) | |
4167 ::error ("invalid stream number = %d", fid); | |
4168 else | |
4169 ::error ("%s: invalid stream number = %d", who.c_str (), fid); | |
4170 } | |
4171 | |
3340 | 4172 octave_stream |
3523 | 4173 octave_stream_list::do_lookup (int fid, const std::string& who) const |
2117 | 4174 { |
3340 | 4175 octave_stream retval; |
2117 | 4176 |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4177 if (fid < 0) |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
4178 err_invalid_file_id (fid, who); |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4179 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4180 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
|
4181 retval = lookup_cache->second; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4182 else |
6757 | 4183 { |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4184 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
|
4185 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4186 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
|
4187 err_invalid_file_id (fid, who); |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4188 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4189 retval = iter->second; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4190 lookup_cache = iter; |
6757 | 4191 } |
2117 | 4192 |
4193 return retval; | |
4194 } | |
4195 | |
3340 | 4196 octave_stream |
3341 | 4197 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
|
4198 const std::string& who) const |
2117 | 4199 { |
4200 int i = get_file_number (fid); | |
4201 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4202 return do_lookup (i, who); |
2117 | 4203 } |
4204 | |
4205 int | |
3523 | 4206 octave_stream_list::do_remove (int fid, const std::string& who) |
2117 | 4207 { |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
4208 // 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
|
4209 if (fid < 3) |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
4210 err_invalid_file_id (fid, who); |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4211 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4212 ostrl_map::iterator iter = list.find (fid); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4213 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4214 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
|
4215 err_invalid_file_id (fid, who); |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4216 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4217 octave_stream os = iter->second; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4218 list.erase (iter); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4219 lookup_cache = list.end (); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4220 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4221 // FIXME: is this check redundant? |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4222 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
|
4223 err_invalid_file_id (fid, who); |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4224 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4225 os.close (); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4226 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
4227 return 0; |
2117 | 4228 } |
4229 | |
4230 int | |
3523 | 4231 octave_stream_list::do_remove (const octave_value& fid, const std::string& who) |
2117 | 4232 { |
4233 int retval = -1; | |
4234 | |
6054 | 4235 if (fid.is_string () && fid.string_value () == "all") |
4236 { | |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
4237 do_clear (false); |
6054 | 4238 |
4239 retval = 0; | |
4240 } | |
4241 else | |
4242 { | |
4243 int i = get_file_number (fid); | |
4244 | |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
4245 retval = do_remove (i, who); |
6054 | 4246 } |
2117 | 4247 |
4248 return retval; | |
4249 } | |
4250 | |
4251 void | |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
4252 octave_stream_list::do_clear (bool flush) |
2117 | 4253 { |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
4254 if (flush) |
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
4255 { |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
4256 // Flush stdout and stderr. |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
4257 list[1].flush (); |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
4258 list[2].flush (); |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
4259 } |
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
4260 |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
4261 for (ostrl_map::iterator iter = list.begin (); iter != list.end (); ) |
6757 | 4262 { |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
4263 int fid = iter->first; |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
4264 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
|
4265 { |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
4266 iter++; |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
4267 continue; |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
4268 } |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
4269 |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
4270 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
|
4271 |
7655b399abff
eliminate trailing whitespace in source files we maintain
John W. Eaton <jwe@octave.org>
parents:
20764
diff
changeset
|
4272 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
|
4273 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
|
4274 |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
4275 // 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
|
4276 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
|
4277 { |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
4278 // 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
|
4279 iter++; |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
4280 continue; |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
4281 } |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
4282 |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
4283 // 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
|
4284 if (os.is_valid ()) |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
4285 os.close (); |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
4286 |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
4287 list.erase (iter++); |
6757 | 4288 } |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
4289 |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
4290 lookup_cache = list.end (); |
2117 | 4291 } |
4292 | |
4293 string_vector | |
4294 octave_stream_list::do_get_info (int fid) const | |
4295 { | |
3340 | 4296 octave_stream os = do_lookup (fid); |
2117 | 4297 |
20892 | 4298 if (! os.is_valid ()) |
3341 | 4299 ::error ("invalid file id = %d", fid); |
2117 | 4300 |
20892 | 4301 string_vector retval (3); |
4302 | |
4303 retval(0) = os.name (); | |
4304 retval(1) = octave_stream::mode_as_string (os.mode ()); | |
4305 retval(2) = oct_mach_info::float_format_as_string (os.float_format ()); | |
4306 | |
2117 | 4307 return retval; |
4308 } | |
4309 | |
4310 string_vector | |
4311 octave_stream_list::do_get_info (const octave_value& fid) const | |
4312 { | |
4313 int conv_err = 0; | |
4314 | |
4315 int int_fid = convert_to_valid_int (fid, conv_err); | |
4316 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4317 if (conv_err) |
2915 | 4318 ::error ("file id must be a file object or integer value"); |
2117 | 4319 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4320 return do_get_info (int_fid); |
2117 | 4321 } |
4322 | |
3536 | 4323 std::string |
2117 | 4324 octave_stream_list::do_list_open_files (void) const |
4325 { | |
5765 | 4326 std::ostringstream buf; |
2117 | 4327 |
4328 buf << "\n" | |
4329 << " number mode arch name\n" | |
4330 << " ------ ---- ---- ----\n"; | |
4331 | |
6757 | 4332 for (ostrl_map::const_iterator p = list.begin (); p != list.end (); p++) |
2117 | 4333 { |
6757 | 4334 octave_stream os = p->second; |
2117 | 4335 |
4326 | 4336 buf << " " |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4337 << std::setiosflags (std::ios::right) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4338 << std::setw (4) << p->first << " " |
19123 | 4339 // reset necessary in addition to setiosflags since this is one stmt. |
4340 << std::resetiosflags (std::ios::adjustfield) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4341 << std::setiosflags (std::ios::left) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4342 << std::setw (3) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4343 << octave_stream::mode_as_string (os.mode ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4344 << " " |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4345 << std::setw (9) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4346 << oct_mach_info::float_format_as_string (os.float_format ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4347 << " " |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4348 << os.name () << "\n"; |
2117 | 4349 } |
4350 | |
5765 | 4351 buf << "\n"; |
4352 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4353 return buf.str (); |
2117 | 4354 } |
4355 | |
4356 octave_value | |
4357 octave_stream_list::do_open_file_numbers (void) const | |
4358 { | |
6757 | 4359 Matrix retval (1, list.size (), 0.0); |
2117 | 4360 |
4361 int num_open = 0; | |
4362 | |
6757 | 4363 for (ostrl_map::const_iterator p = list.begin (); p != list.end (); p++) |
2117 | 4364 { |
6757 | 4365 // Skip stdin, stdout, and stderr. |
4366 if (p->first > 2 && p->second) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4367 retval(0,num_open++) = p->first; |
2117 | 4368 } |
4369 | |
4370 retval.resize ((num_open > 0), num_open); | |
4371 | |
4372 return retval; | |
4373 } | |
4374 | |
4375 int | |
2609 | 4376 octave_stream_list::do_get_file_number (const octave_value& fid) const |
2117 | 4377 { |
4378 int retval = -1; | |
4379 | |
4380 if (fid.is_string ()) | |
4381 { | |
3523 | 4382 std::string nm = fid.string_value (); |
2117 | 4383 |
6757 | 4384 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
|
4385 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4386 // stdin, stdout, and stderr are unnamed. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4387 if (p->first > 2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4388 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4389 octave_stream os = p->second; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4390 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4391 if (os && os.name () == nm) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4392 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4393 retval = p->first; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4394 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4395 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4396 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4397 } |
2117 | 4398 } |
4399 else | |
4400 { | |
4401 int conv_err = 0; | |
4402 | |
4403 int int_fid = convert_to_valid_int (fid, conv_err); | |
4404 | |
4405 if (conv_err) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4406 ::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
|
4407 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4408 retval = int_fid; |
2117 | 4409 } |
4410 | |
4411 return retval; | |
4412 } |