Mercurial > octave
annotate libinterp/corefcn/oct-stream.cc @ 22197:e43d83253e28
refill multi-line macro definitions
Use the Emacs C++ mode style for line continuation markers in
multi-line macro definitions.
* make_int.cc, __dsearchn__.cc, __magick_read__.cc, besselj.cc,
bitfcns.cc, bsxfun.cc, cellfun.cc, data.cc, defun-dld.h, defun-int.h,
defun.h, det.cc, error.h, find.cc, gcd.cc, graphics.cc, interpreter.h,
jit-ir.h, jit-typeinfo.h, lookup.cc, ls-mat5.cc, max.cc, mexproto.h,
mxarray.in.h, oct-stream.cc, ordschur.cc, pr-output.cc, profiler.h,
psi.cc, regexp.cc, sparse-xdiv.cc, sparse-xpow.cc, tril.cc, txt-eng.h,
utils.cc, variables.cc, variables.h, xdiv.cc, xpow.cc, __glpk__.cc,
ov-base.cc, ov-base.h, ov-cell.cc, ov-ch-mat.cc, ov-classdef.cc,
ov-complex.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-float.cc, ov-float.h,
ov-flt-complex.cc, ov-flt-cx-mat.cc, ov-flt-re-mat.cc,
ov-int-traits.h, ov-lazy-idx.h, ov-perm.cc, ov-re-mat.cc,
ov-re-sparse.cc, ov-scalar.cc, ov-scalar.h, ov-str-mat.cc,
ov-type-conv.h, ov.cc, ov.h, op-class.cc, op-int-conv.cc, op-int.h,
op-str-str.cc, ops.h, lex.ll, Array.cc, CMatrix.cc, CSparse.cc,
MArray.cc, MArray.h, MDiagArray2.cc, MDiagArray2.h, MSparse.h,
Sparse.cc, dMatrix.cc, dSparse.cc, fCMatrix.cc, fMatrix.cc,
idx-vector.cc, f77-fcn.h, quit.h, bsxfun-decl.h, bsxfun-defs.cc,
lo-specfun.cc, oct-convn.cc, oct-convn.h, oct-norm.cc, oct-norm.h,
oct-rand.cc, Sparse-op-decls.h, Sparse-op-defs.h, mx-inlines.cc,
mx-op-decl.h, mx-op-defs.h, mach-info.cc, oct-group.cc, oct-passwd.cc,
oct-syscalls.cc, oct-time.cc, data-conv.cc, kpse.cc, lo-ieee.h,
lo-macros.h, oct-cmplx.h, oct-glob.cc, oct-inttypes.cc,
oct-inttypes.h, oct-locbuf.h, oct-sparse.h, url-transfer.cc,
oct-conf-post.in.h, shared-fcns.h: Refill macro definitions.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 01 Aug 2016 12:40:18 -0400 |
parents | 9203833cab7d |
children | bac0d6f07a3e |
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 |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
4 Copyright (C) 2015-2016 Lachlan Andrew, Monash University |
2117 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2117 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2117 | 21 |
22 */ | |
23 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21723
diff
changeset
|
24 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21297
diff
changeset
|
25 # include "config.h" |
2117 | 26 #endif |
27 | |
3268 | 28 #include <cassert> |
7709
fa41af732801
octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents:
7538
diff
changeset
|
29 #include <cctype> |
2215 | 30 #include <cstring> |
31 | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
32 #include <deque> |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
33 #include <fstream> |
3503 | 34 #include <iomanip> |
9202
4b2147b25e8d
clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9017
diff
changeset
|
35 #include <iostream> |
5765 | 36 #include <sstream> |
3535 | 37 #include <string> |
2117 | 38 |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
19123
diff
changeset
|
39 #include "Array.h" |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
40 #include "Cell.h" |
4944 | 41 #include "byte-swap.h" |
2117 | 42 #include "lo-ieee.h" |
43 #include "lo-mappers.h" | |
44 #include "lo-utils.h" | |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
19123
diff
changeset
|
45 #include "oct-locbuf.h" |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13271
diff
changeset
|
46 #include "quit.h" |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13271
diff
changeset
|
47 #include "singleton-cleanup.h" |
2117 | 48 #include "str-vec.h" |
49 | |
50 #include "error.h" | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21040
diff
changeset
|
51 #include "errwarn.h" |
3342 | 52 #include "input.h" |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
22089
diff
changeset
|
53 #include "interpreter.h" |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
54 #include "octave.h" |
3775 | 55 #include "oct-stdstrm.h" |
2117 | 56 #include "oct-stream.h" |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
57 #include "ov.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20938
diff
changeset
|
58 #include "ovl.h" |
2117 | 59 #include "utils.h" |
60 | |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
61 // Programming Note: There are two very different error functions used |
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
62 // in the stream code. When invoked with "error (...)" the member |
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
63 // function from octave_stream or octave_base_stream is called. This |
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
64 // function sets the error state on the stream AND returns control to |
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
65 // the caller. The caller must then return a value at the end of the |
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
66 // function. When invoked with "::error (...)" the exception-based |
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
67 // error function from error.h is used. This function will throw an |
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
68 // exception and not return control to the caller. BE CAREFUL and |
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
69 // invoke the correct error function! |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
70 |
2117 | 71 // Possible values for conv_err: |
72 // | |
73 // 1 : not a real scalar | |
2902 | 74 // 2 : value is NaN |
75 // 3 : value is not an integer | |
2117 | 76 |
77 static int | |
78 convert_to_valid_int (const octave_value& tc, int& conv_err) | |
79 { | |
20747
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
80 conv_err = 0; |
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
81 |
2117 | 82 int retval = 0; |
83 | |
20747
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
84 double dval = 0.0; |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
85 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
86 try |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
87 { |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
88 dval = tc.double_value (); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
89 } |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
90 catch (const octave_execution_exception&) |
2117 | 91 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
92 recover_from_exception (); |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
93 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
94 conv_err = 1; |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
95 } |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
96 |
20747
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
97 if (! conv_err) |
2117 | 98 { |
5389 | 99 if (! lo_ieee_isnan (dval)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
100 { |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21777
diff
changeset
|
101 int ival = octave::math::nint (dval); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
102 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
103 if (ival == dval) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
104 retval = ival; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
105 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
106 conv_err = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
107 } |
2117 | 108 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
109 conv_err = 2; |
2117 | 110 } |
111 | |
112 return retval; | |
113 } | |
114 | |
115 static int | |
4468 | 116 get_size (double d, const std::string& who) |
2117 | 117 { |
118 int retval = -1; | |
119 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
120 if (lo_ieee_isnan (d)) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
121 ::error ("%s: NaN is invalid as size specification", who.c_str ()); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
122 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21777
diff
changeset
|
123 if (octave::math::isinf (d)) |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
124 retval = -1; |
2117 | 125 else |
126 { | |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
127 if (d < 0.0) |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
128 ::error ("%s: negative value invalid as size specification", |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
129 who.c_str ()); |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
130 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21777
diff
changeset
|
131 retval = octave::math::nint (d); |
2117 | 132 } |
133 | |
134 return retval; | |
135 } | |
136 | |
137 static void | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
138 get_size (const Array<double>& size, octave_idx_type& nr, octave_idx_type& nc, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
139 bool& one_elt_size_spec, const std::string& who) |
2117 | 140 { |
141 nr = -1; | |
142 nc = -1; | |
143 | |
3268 | 144 one_elt_size_spec = false; |
145 | |
2117 | 146 double dnr = -1.0; |
147 double dnc = -1.0; | |
148 | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20230
diff
changeset
|
149 octave_idx_type sz_len = size.numel (); |
3810 | 150 |
151 if (sz_len == 1) | |
2601 | 152 { |
3268 | 153 one_elt_size_spec = true; |
154 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
155 dnr = size(0); |
4293 | 156 |
157 dnc = (dnr == 0.0) ? 0.0 : 1.0; | |
2601 | 158 } |
3810 | 159 else if (sz_len == 2) |
2117 | 160 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
161 dnr = size(0); |
3810 | 162 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21777
diff
changeset
|
163 if (octave::math::isinf (dnr)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
164 ::error ("%s: invalid size specification", who.c_str ()); |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
165 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
166 dnc = size(1); |
2117 | 167 } |
168 else | |
4468 | 169 ::error ("%s: invalid size specification", who.c_str ()); |
2117 | 170 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
171 nr = get_size (dnr, who); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
172 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
173 if (dnc >= 0.0) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
174 nc = get_size (dnc, who); |
2117 | 175 } |
176 | |
21477
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
177 class |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
178 scanf_format_elt |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
179 { |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
180 public: |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
181 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
182 enum special_conversion |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
183 { |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
184 whitespace_conversion = 1, |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
185 literal_conversion = 2, |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
186 null = 3 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
187 }; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
188 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
189 scanf_format_elt (const char *txt = 0, int w = 0, bool d = false, |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
190 char typ = '\0', char mod = '\0', |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
191 const std::string& ch_class = "") |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
192 : text (strsave (txt)), width (w), discard (d), type (typ), |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
193 modifier (mod), char_class (ch_class) |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
194 { } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
195 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
196 scanf_format_elt (const scanf_format_elt& e) |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
197 : text (strsave (e.text)), width (e.width), discard (e.discard), |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
198 type (e.type), modifier (e.modifier), char_class (e.char_class) |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
199 { } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
200 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
201 scanf_format_elt& operator = (const scanf_format_elt& e) |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
202 { |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
203 if (this != &e) |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
204 { |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
205 text = strsave (e.text); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
206 width = e.width; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
207 discard = e.discard; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
208 type = e.type; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
209 modifier = e.modifier; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
210 char_class = e.char_class; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
211 } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
212 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
213 return *this; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
214 } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
215 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
216 ~scanf_format_elt (void) { delete [] text; } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
217 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
218 // The C-style format string. |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
219 const char *text; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
220 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
221 // The maximum field width. |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
222 int width; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
223 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
224 // TRUE if we are not storing the result of this conversion. |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
225 bool discard; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
226 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
227 // Type of conversion -- 'd', 'i', 'o', 'u', 'x', 'e', 'f', 'g', |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
228 // 'c', 's', 'p', '%', or '['. |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
229 char type; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
230 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
231 // A length modifier -- 'h', 'l', or 'L'. |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
232 char modifier; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
233 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
234 // The class of characters in a '[' format. |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
235 std::string char_class; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
236 }; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
237 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
238 class |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
239 scanf_format_list |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
240 { |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
241 public: |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
242 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
243 scanf_format_list (const std::string& fmt = ""); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
244 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
245 ~scanf_format_list (void); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
246 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
247 octave_idx_type num_conversions (void) { return nconv; } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
248 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
249 // The length can be different than the number of conversions. |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
250 // For example, "x %d y %d z" has 2 conversions but the length of |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
251 // the list is 3 because of the characters that appear after the |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
252 // last conversion. |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
253 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
254 size_t length (void) const { return fmt_elts.size (); } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
255 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
256 const scanf_format_elt *first (void) |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
257 { |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
258 curr_idx = 0; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
259 return current (); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
260 } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
261 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
262 const scanf_format_elt *current (void) const |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
263 { |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
264 return length () > 0 ? fmt_elts[curr_idx] : 0; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
265 } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
266 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
267 const scanf_format_elt *next (bool cycle = true) |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
268 { |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
269 static scanf_format_elt dummy |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
270 (0, 0, false, scanf_format_elt::null, '\0', ""); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
271 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
272 curr_idx++; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
273 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
274 if (curr_idx >= length ()) |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
275 { |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
276 if (cycle) |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
277 curr_idx = 0; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
278 else |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
279 return &dummy; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
280 } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
281 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
282 return current (); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
283 } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
284 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
285 void printme (void) const; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
286 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
287 bool ok (void) const { return (nconv >= 0); } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
288 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
289 operator bool () const { return ok (); } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
290 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
291 bool all_character_conversions (void); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
292 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
293 bool all_numeric_conversions (void); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
294 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
295 private: |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
296 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
297 // Number of conversions specified by this format string, or -1 if |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
298 // invalid conversions have been found. |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
299 octave_idx_type nconv; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
300 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
301 // Index to current element; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
302 size_t curr_idx; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
303 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
304 // List of format elements. |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
305 std::deque<scanf_format_elt*> fmt_elts; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
306 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
307 // Temporary buffer. |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
308 std::ostringstream buf; |
21477
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
309 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
310 void add_elt_to_list (int width, bool discard, char type, char modifier, |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
311 const std::string& char_class = ""); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
312 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
313 void process_conversion (const std::string& s, size_t& i, size_t n, |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
314 int& width, bool& discard, char& type, |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
315 char& modifier); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
316 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
317 int finish_conversion (const std::string& s, size_t& i, size_t n, |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
318 int& width, bool discard, char& type, |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
319 char modifier); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
320 // No copying! |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
321 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
322 scanf_format_list (const scanf_format_list&); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
323 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
324 scanf_format_list& operator = (const scanf_format_list&); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
325 }; |
2117 | 326 |
3523 | 327 scanf_format_list::scanf_format_list (const std::string& s) |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
328 : nconv (0), curr_idx (0), fmt_elts (), buf () |
2117 | 329 { |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
330 size_t n = s.length (); |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
331 |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
332 size_t i = 0; |
2117 | 333 |
2215 | 334 int width = 0; |
2117 | 335 bool discard = false; |
336 char modifier = '\0'; | |
337 char type = '\0'; | |
338 | |
339 bool have_more = true; | |
340 | |
341 while (i < n) | |
342 { | |
343 have_more = true; | |
344 | |
345 if (s[i] == '%') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
346 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
347 // Process percent-escape conversion type. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
348 |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
349 process_conversion (s, i, n, width, discard, type, modifier); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
350 |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
351 have_more = (buf.tellp () != 0); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
352 } |
3483 | 353 else if (isspace (s[i])) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
354 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
355 type = scanf_format_elt::whitespace_conversion; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
356 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
357 width = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
358 discard = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
359 modifier = '\0'; |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
360 buf << " "; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
361 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
362 while (++i < n && isspace (s[i])) |
20946 | 363 ; // skip whitespace |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
364 |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
365 add_elt_to_list (width, discard, type, modifier); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
366 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
367 have_more = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
368 } |
3483 | 369 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
370 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
371 type = scanf_format_elt::literal_conversion; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
372 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
373 width = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
374 discard = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
375 modifier = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
376 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
377 while (i < n && ! isspace (s[i]) && s[i] != '%') |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
378 buf << s[i++]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
379 |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
380 add_elt_to_list (width, discard, type, modifier); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
381 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
382 have_more = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
383 } |
2117 | 384 |
385 if (nconv < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
386 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
387 have_more = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
388 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
389 } |
2117 | 390 } |
391 | |
392 if (have_more) | |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
393 add_elt_to_list (width, discard, type, modifier); |
2117 | 394 |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
395 buf.clear (); |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
396 buf.str (""); |
2117 | 397 } |
398 | |
399 scanf_format_list::~scanf_format_list (void) | |
400 { | |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
401 size_t n = fmt_elts.size (); |
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
402 |
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
403 for (size_t i = 0; i < n; i++) |
2117 | 404 { |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
405 scanf_format_elt *elt = fmt_elts[i]; |
2117 | 406 delete elt; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
407 } |
2117 | 408 } |
409 | |
410 void | |
2215 | 411 scanf_format_list::add_elt_to_list (int width, bool discard, char type, |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
412 char modifier, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
413 const std::string& char_class) |
2117 | 414 { |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
415 std::string text = buf.str (); |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
416 |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
417 if (! text.empty ()) |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
418 { |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
419 scanf_format_elt *elt |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
420 = new scanf_format_elt (text.c_str (), width, discard, type, |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
421 modifier, char_class); |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
422 |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
423 fmt_elts.push_back (elt); |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
424 } |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
425 |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
426 buf.clear (); |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
427 buf.str (""); |
2117 | 428 } |
429 | |
3535 | 430 static std::string |
3523 | 431 expand_char_class (const std::string& s) |
3483 | 432 { |
3523 | 433 std::string retval; |
3483 | 434 |
435 size_t len = s.length (); | |
436 | |
437 size_t i = 0; | |
438 | |
439 while (i < len) | |
440 { | |
441 unsigned char c = s[i++]; | |
442 | |
443 if (c == '-' && i > 1 && i < len | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
444 && ( static_cast<unsigned char> (s[i-2]) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
445 <= static_cast<unsigned char> (s[i]))) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
446 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
447 // Add all characters from the range except the first (we |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
448 // already added it below). |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
449 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
450 for (c = s[i-2]+1; c < s[i]; c++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
451 retval += c; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
452 } |
3483 | 453 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
454 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
455 // Add the character to the class. Only add '-' if it is |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
456 // the last character in the class. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
457 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
458 if (c != '-' || i == len) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
459 retval += c; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
460 } |
3483 | 461 } |
462 | |
463 return retval; | |
464 } | |
465 | |
2117 | 466 void |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
467 scanf_format_list::process_conversion (const std::string& s, size_t& i, |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
468 size_t n, int& width, bool& discard, |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
469 char& type, char& modifier) |
2117 | 470 { |
2215 | 471 width = 0; |
2117 | 472 discard = false; |
473 modifier = '\0'; | |
474 type = '\0'; | |
475 | |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
476 buf << s[i++]; |
2117 | 477 |
478 bool have_width = false; | |
479 | |
480 while (i < n) | |
481 { | |
482 switch (s[i]) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
483 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
484 case '*': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
485 if (discard) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
486 nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
487 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
488 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
489 discard = true; |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
490 buf << s[i++]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
491 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
492 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
493 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
494 case '0': case '1': case '2': case '3': case '4': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
495 case '5': case '6': case '7': case '8': case '9': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
496 if (have_width) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
497 nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
498 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
499 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
500 char c = s[i++]; |
20230
e914b5399c67
Use in-place operators in C++ code where possible.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
501 width = 10 * width + c - '0'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
502 have_width = true; |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
503 buf << c; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
504 while (i < n && isdigit (s[i])) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
505 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
506 c = s[i++]; |
20230
e914b5399c67
Use in-place operators in C++ code where possible.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
507 width = 10 * width + c - '0'; |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
508 buf << c; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
509 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
510 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
511 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
512 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
513 case 'h': case 'l': case 'L': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
514 if (modifier != '\0') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
515 nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
516 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
517 modifier = s[i++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
518 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
519 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
520 case 'd': case 'i': case 'o': case 'u': case 'x': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
521 if (modifier == 'L') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
522 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
523 nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
524 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
525 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
526 goto fini; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
527 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
528 case 'e': case 'f': case 'g': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
529 if (modifier == 'h') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
530 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
531 nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
532 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
533 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
534 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
535 // No float or long double conversions, thanks. |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
536 buf << 'l'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
537 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
538 goto fini; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
539 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
540 case 'c': case 's': case 'p': case '%': case '[': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
541 if (modifier != '\0') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
542 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
543 nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
544 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
545 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
546 goto fini; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
547 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
548 fini: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
549 { |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
550 if (finish_conversion (s, i, n, width, discard, |
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
551 type, modifier) == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
552 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
553 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
554 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
555 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
556 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
557 nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
558 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
559 } |
2117 | 560 |
561 if (nconv < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
562 break; |
2117 | 563 } |
564 | |
565 nconv = -1; | |
566 } | |
567 | |
568 int | |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
569 scanf_format_list::finish_conversion (const std::string& s, size_t& i, |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
570 size_t n, int& width, bool discard, |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
571 char& type, char modifier) |
2117 | 572 { |
573 int retval = 0; | |
574 | |
3523 | 575 std::string char_class; |
3483 | 576 |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
577 size_t beg_idx = std::string::npos; |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
578 size_t end_idx = std::string::npos; |
3640 | 579 |
2117 | 580 if (s[i] == '%') |
3640 | 581 { |
582 type = '%'; | |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
583 buf << s[i++]; |
3640 | 584 } |
2117 | 585 else |
586 { | |
587 type = s[i]; | |
588 | |
589 if (s[i] == '[') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
590 { |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
591 buf << s[i++]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
592 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
593 if (i < n) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
594 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
595 beg_idx = i; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
596 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
597 if (s[i] == '^') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
598 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
599 type = '^'; |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
600 buf << s[i++]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
601 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
602 if (i < n) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
603 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
604 beg_idx = i; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
605 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
606 if (s[i] == ']') |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
607 buf << s[i++]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
608 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
609 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
610 else if (s[i] == ']') |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
611 buf << s[i++]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
612 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
613 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
614 while (i < n && s[i] != ']') |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
615 buf << s[i++]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
616 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
617 if (i < n && s[i] == ']') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
618 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
619 end_idx = i-1; |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
620 buf << s[i++]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
621 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
622 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
623 if (s[i-1] != ']') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
624 retval = nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
625 } |
2117 | 626 else |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
627 buf << s[i++]; |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
628 |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
629 nconv++; |
3640 | 630 } |
631 | |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
632 if (nconv >= 0) |
3640 | 633 { |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
634 if (beg_idx != std::string::npos && end_idx != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
635 char_class = expand_char_class (s.substr (beg_idx, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
636 end_idx - beg_idx + 1)); |
3640 | 637 |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
638 add_elt_to_list (width, discard, type, modifier, char_class); |
2117 | 639 } |
640 | |
641 return retval; | |
642 } | |
643 | |
644 void | |
645 scanf_format_list::printme (void) const | |
646 { | |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
647 size_t n = fmt_elts.size (); |
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
648 |
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
649 for (size_t i = 0; i < n; i++) |
2117 | 650 { |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
651 scanf_format_elt *elt = fmt_elts[i]; |
2117 | 652 |
3531 | 653 std::cerr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
654 << "width: " << elt->width << "\n" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
655 << "discard: " << elt->discard << "\n" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
656 << "type: "; |
3483 | 657 |
658 if (elt->type == scanf_format_elt::literal_conversion) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
659 std::cerr << "literal text\n"; |
3483 | 660 else if (elt->type == scanf_format_elt::whitespace_conversion) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
661 std::cerr << "whitespace\n"; |
3483 | 662 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
663 std::cerr << elt->type << "\n"; |
3531 | 664 |
665 std::cerr | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
666 << "modifier: " << elt->modifier << "\n" |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
667 << "char_class: '" << undo_string_escapes (elt->char_class) << "'\n" |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
668 << "text: '" << undo_string_escapes (elt->text) << "'\n\n"; |
2117 | 669 } |
670 } | |
671 | |
672 bool | |
673 scanf_format_list::all_character_conversions (void) | |
674 { | |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
675 size_t n = fmt_elts.size (); |
2117 | 676 |
677 if (n > 0) | |
678 { | |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
679 for (size_t i = 0; i < n; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
680 { |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
681 scanf_format_elt *elt = fmt_elts[i]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
682 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
683 switch (elt->type) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
684 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
685 case 'c': case 's': case '%': case '[': case '^': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
686 case scanf_format_elt::literal_conversion: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
687 case scanf_format_elt::whitespace_conversion: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
688 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
689 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
690 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
691 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
692 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
693 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
694 } |
2117 | 695 |
696 return true; | |
697 } | |
698 else | |
699 return false; | |
700 } | |
701 | |
702 bool | |
703 scanf_format_list::all_numeric_conversions (void) | |
704 { | |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
705 size_t n = fmt_elts.size (); |
2117 | 706 |
707 if (n > 0) | |
708 { | |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
709 for (size_t i = 0; i < n; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
710 { |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
711 scanf_format_elt *elt = fmt_elts[i]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
712 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
713 switch (elt->type) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
714 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
715 case 'd': case 'i': case 'o': case 'u': case 'x': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
716 case 'e': case 'f': case 'g': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
717 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
718 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
719 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
720 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
721 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
722 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
723 } |
2117 | 724 |
725 return true; | |
726 } | |
727 else | |
728 return false; | |
729 } | |
730 | |
21477
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
731 class |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
732 printf_format_elt |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
733 { |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
734 public: |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
735 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
736 printf_format_elt (const char *txt = 0, int n = 0, int w = -1, |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
737 int p = -1, const std::string& f = "", |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
738 char typ = '\0', char mod = '\0') |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
739 : text (strsave (txt)), args (n), fw (w), prec (p), flags (f), |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
740 type (typ), modifier (mod) |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
741 { } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
742 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
743 printf_format_elt (const printf_format_elt& e) |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
744 : text (strsave (e.text)), args (e.args), fw (e.fw), prec (e.prec), |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
745 flags (e.flags), type (e.type), modifier (e.modifier) |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
746 { } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
747 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
748 printf_format_elt& operator = (const printf_format_elt& e) |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
749 { |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
750 if (this != &e) |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
751 { |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
752 text = strsave (e.text); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
753 args = e.args; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
754 fw = e.fw; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
755 prec = e.prec; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
756 flags = e.flags; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
757 type = e.type; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
758 modifier = e.modifier; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
759 } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
760 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
761 return *this; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
762 } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
763 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
764 ~printf_format_elt (void) { delete [] text; } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
765 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
766 // The C-style format string. |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
767 const char *text; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
768 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
769 // How many args do we expect to consume? |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
770 int args; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
771 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
772 // Field width. |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
773 int fw; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
774 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
775 // Precision. |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
776 int prec; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
777 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
778 // Flags -- '-', '+', ' ', '0', or '#'. |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
779 std::string flags; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
780 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
781 // Type of conversion -- 'd', 'i', 'o', 'x', 'X', 'u', 'c', 's', |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
782 // 'f', 'e', 'E', 'g', 'G', 'p', or '%' |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
783 char type; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
784 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
785 // A length modifier -- 'h', 'l', or 'L'. |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
786 char modifier; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
787 }; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
788 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
789 class |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
790 printf_format_list |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
791 { |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
792 public: |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
793 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
794 printf_format_list (const std::string& fmt = ""); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
795 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
796 ~printf_format_list (void); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
797 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
798 octave_idx_type num_conversions (void) { return nconv; } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
799 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
800 const printf_format_elt *first (void) |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
801 { |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
802 curr_idx = 0; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
803 return current (); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
804 } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
805 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
806 const printf_format_elt *current (void) const |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
807 { |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
808 return length () > 0 ? fmt_elts[curr_idx] : 0; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
809 } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
810 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
811 size_t length (void) const { return fmt_elts.size (); } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
812 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
813 const printf_format_elt *next (bool cycle = true) |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
814 { |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
815 curr_idx++; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
816 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
817 if (curr_idx >= length ()) |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
818 { |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
819 if (cycle) |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
820 curr_idx = 0; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
821 else |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
822 return 0; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
823 } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
824 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
825 return current (); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
826 } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
827 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
828 bool last_elt_p (void) { return (curr_idx + 1 == length ()); } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
829 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
830 void printme (void) const; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
831 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
832 bool ok (void) const { return (nconv >= 0); } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
833 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
834 operator bool () const { return ok (); } |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
835 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
836 private: |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
837 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
838 // Number of conversions specified by this format string, or -1 if |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
839 // invalid conversions have been found. |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
840 octave_idx_type nconv; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
841 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
842 // Index to current element; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
843 size_t curr_idx; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
844 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
845 // List of format elements. |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
846 std::deque<printf_format_elt*> fmt_elts; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
847 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
848 // Temporary buffer. |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
849 std::ostringstream buf; |
21477
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
850 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
851 void add_elt_to_list (int args, const std::string& flags, int fw, |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
852 int prec, char type, char modifier); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
853 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
854 void process_conversion (const std::string& s, size_t& i, size_t n, |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
855 int& args, std::string& flags, int& fw, |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
856 int& prec, char& modifier, char& type); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
857 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
858 void finish_conversion (const std::string& s, size_t& i, int args, |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
859 const std::string& flags, int fw, int prec, |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
860 char modifier, char& type); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
861 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
862 // No copying! |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
863 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
864 printf_format_list (const printf_format_list&); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
865 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
866 printf_format_list& operator = (const printf_format_list&); |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
867 }; |
2117 | 868 |
3523 | 869 printf_format_list::printf_format_list (const std::string& s) |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
870 : nconv (0), curr_idx (0), fmt_elts (), buf () |
2117 | 871 { |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
872 size_t n = s.length (); |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
873 |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
874 size_t i = 0; |
2117 | 875 |
876 int args = 0; | |
3643 | 877 std::string flags; |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
878 int fw = -1; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
879 int prec = -1; |
2117 | 880 char modifier = '\0'; |
881 char type = '\0'; | |
882 | |
883 bool have_more = true; | |
3640 | 884 bool empty_buf = true; |
2117 | 885 |
4223 | 886 if (n == 0) |
2117 | 887 { |
4223 | 888 printf_format_elt *elt |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
889 = new printf_format_elt ("", args, fw, prec, flags, type, modifier); |
4223 | 890 |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
891 fmt_elts.push_back (elt); |
4223 | 892 } |
893 else | |
894 { | |
895 while (i < n) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
896 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
897 have_more = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
898 |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
899 empty_buf = (buf.tellp () == 0); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
900 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
901 switch (s[i]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
902 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
903 case '%': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
904 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
905 if (empty_buf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
906 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
907 process_conversion (s, i, n, args, flags, fw, prec, |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
908 type, modifier); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
909 |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
910 // If there is nothing in the buffer, then |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
911 // add_elt_to_list must have just been called, so we |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
912 // are already done with the current element and we |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
913 // don't need to call add_elt_to_list if this is our |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
914 // last trip through the loop. |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
915 |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
916 have_more = (buf.tellp () != 0); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
917 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
918 else |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
919 add_elt_to_list (args, flags, fw, prec, type, modifier); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
920 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
921 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
922 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
923 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
924 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
925 args = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
926 flags = ""; |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
927 fw = -1; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
928 prec = -1; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
929 modifier = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
930 type = '\0'; |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
931 buf << s[i++]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
932 empty_buf = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
933 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
934 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
935 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
936 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
937 if (nconv < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
938 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
939 have_more = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
940 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
941 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
942 } |
2117 | 943 |
4223 | 944 if (have_more) |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
945 add_elt_to_list (args, flags, fw, prec, type, modifier); |
4223 | 946 |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
947 buf.clear (); |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
948 buf.str (""); |
2117 | 949 } |
950 } | |
951 | |
952 printf_format_list::~printf_format_list (void) | |
953 { | |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
954 size_t n = fmt_elts.size (); |
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
955 |
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
956 for (size_t i = 0; i < n; i++) |
2117 | 957 { |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
958 printf_format_elt *elt = fmt_elts[i]; |
2117 | 959 delete elt; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
960 } |
2117 | 961 } |
962 | |
963 void | |
3640 | 964 printf_format_list::add_elt_to_list (int args, const std::string& flags, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
965 int fw, int prec, char type, |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
966 char modifier) |
2117 | 967 { |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
968 std::string text = buf.str (); |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
969 |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
970 if (! text.empty ()) |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
971 { |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
972 printf_format_elt *elt |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
973 = new printf_format_elt (text.c_str (), args, fw, prec, flags, |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
974 type, modifier); |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
975 |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
976 fmt_elts.push_back (elt); |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
977 } |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
978 |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
979 buf.clear (); |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
980 buf.str (""); |
2117 | 981 } |
982 | |
983 void | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
984 printf_format_list::process_conversion (const std::string& s, size_t& i, |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
985 size_t n, int& args, |
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
986 std::string& flags, int& fw, |
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
987 int& prec, char& modifier, |
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
988 char& type) |
2117 | 989 { |
990 args = 0; | |
3640 | 991 flags = ""; |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
992 fw = -1; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
993 prec = -1; |
2117 | 994 modifier = '\0'; |
995 type = '\0'; | |
996 | |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
997 buf << s[i++]; |
2117 | 998 |
4587 | 999 bool nxt = false; |
2117 | 1000 |
1001 while (i < n) | |
1002 { | |
1003 switch (s[i]) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1004 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1005 case '-': case '+': case ' ': case '0': case '#': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1006 flags += s[i]; |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1007 buf << s[i++]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1008 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1009 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1010 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1011 nxt = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1012 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1013 } |
2117 | 1014 |
4587 | 1015 if (nxt) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1016 break; |
2117 | 1017 } |
1018 | |
1019 if (i < n) | |
1020 { | |
1021 if (s[i] == '*') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1022 { |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1023 fw = -2; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1024 args++; |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1025 buf << s[i++]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1026 } |
2117 | 1027 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1028 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1029 if (isdigit (s[i])) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1030 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1031 int nn = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1032 std::string tmp = s.substr (i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1033 sscanf (tmp.c_str (), "%d%n", &fw, &nn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1034 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1035 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1036 while (i < n && isdigit (s[i])) |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1037 buf << s[i++]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1038 } |
2117 | 1039 } |
1040 | |
1041 if (i < n && s[i] == '.') | |
1042 { | |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1043 // nothing before the . means 0. |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1044 if (fw == -1) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1045 fw = 0; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1046 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1047 // . followed by nothing is 0. |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1048 prec = 0; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1049 |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1050 buf << s[i++]; |
2117 | 1051 |
1052 if (i < n) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1053 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1054 if (s[i] == '*') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1055 { |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1056 prec = -2; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1057 args++; |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1058 buf << s[i++]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1059 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1060 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1061 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1062 if (isdigit (s[i])) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1063 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1064 int nn = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1065 std::string tmp = s.substr (i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1066 sscanf (tmp.c_str (), "%d%n", &prec, &nn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1067 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1068 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1069 while (i < n && isdigit (s[i])) |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1070 buf << s[i++]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1071 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1072 } |
2117 | 1073 } |
1074 | |
1075 if (i < n) | |
1076 { | |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
1077 // Accept and record modifier, but don't place it in the format |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
1078 // item text. All integer conversions are handled as 64-bit |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
1079 // integers. |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
1080 |
2117 | 1081 switch (s[i]) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1082 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1083 case 'h': case 'l': case 'L': |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
1084 modifier = s[i++]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1085 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1086 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1087 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1088 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1089 } |
2117 | 1090 } |
1091 | |
1092 if (i < n) | |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
1093 finish_conversion (s, i, args, flags, fw, prec, modifier, type); |
2117 | 1094 else |
1095 nconv = -1; | |
1096 } | |
1097 | |
1098 void | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1099 printf_format_list::finish_conversion (const std::string& s, size_t& i, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1100 int args, const std::string& flags, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1101 int fw, int prec, char modifier, |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
1102 char& type) |
2117 | 1103 { |
1104 switch (s[i]) | |
1105 { | |
1106 case 'd': case 'i': case 'o': case 'x': case 'X': | |
1107 case 'u': case 'c': | |
1108 if (modifier == 'L') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1109 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1110 nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1111 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1112 } |
2117 | 1113 goto fini; |
1114 | |
1115 case 'f': case 'e': case 'E': case 'g': case 'G': | |
1116 if (modifier == 'h' || modifier == 'l') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1117 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1118 nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1119 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1120 } |
2117 | 1121 goto fini; |
1122 | |
1123 case 's': case 'p': case '%': | |
1124 if (modifier != '\0') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1125 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1126 nconv = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1127 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1128 } |
2117 | 1129 goto fini; |
1130 | |
1131 fini: | |
1132 | |
3640 | 1133 type = s[i]; |
1134 | |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1135 buf << s[i++]; |
3640 | 1136 |
1137 if (type != '%' || args != 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1138 nconv++; |
3640 | 1139 |
1140 if (type != '%') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1141 args++; |
3640 | 1142 |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
1143 add_elt_to_list (args, flags, fw, prec, type, modifier); |
3640 | 1144 |
2117 | 1145 break; |
1146 | |
1147 default: | |
1148 nconv = -1; | |
1149 break; | |
1150 } | |
1151 } | |
1152 | |
1153 void | |
1154 printf_format_list::printme (void) const | |
1155 { | |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
1156 size_t n = fmt_elts.size (); |
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
1157 |
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
1158 for (size_t i = 0; i < n; i++) |
2117 | 1159 { |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21354
diff
changeset
|
1160 printf_format_elt *elt = fmt_elts[i]; |
2117 | 1161 |
3640 | 1162 std::cerr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1163 << "args: " << elt->args << "\n" |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1164 << "flags: '" << elt->flags << "'\n" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1165 << "width: " << elt->fw << "\n" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
1166 << "prec: " << elt->prec << "\n" |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1167 << "type: '" << elt->type << "'\n" |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1168 << "modifier: '" << elt->modifier << "'\n" |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1169 << "text: '" << undo_string_escapes (elt->text) << "'\n\n"; |
2117 | 1170 } |
1171 } | |
1172 | |
21567
3d25f9f4a62b
maint: Eliminate Britishicisms in the code.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
1173 // Delimited stream, optimized to read strings of characters separated |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1174 // by single-character delimiters. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1175 // |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1176 // The reason behind this class is that octstream doesn't provide |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1177 // seek/tell, but the opportunity has been taken to optimise for the |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1178 // textscan workload. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1179 // |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1180 // The function reads chunks into a 4kiB buffer, and marks where the |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1181 // last delimiter occurs. Reads up to this delimiter can be fast. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1182 // After that last delimiter, the remaining text is moved to the front |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1183 // of the buffer and the buffer is refilled. This also allows cheap |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1184 // seek and tell operations within a "fast read" block. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1185 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1186 class |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1187 delimited_stream |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1188 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1189 public: |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1190 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1191 delimited_stream (std::istream& is, const std::string& delimiters, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1192 int longest_lookahead, octave_idx_type bsize = 4096); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1193 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1194 delimited_stream (std::istream& is, const delimited_stream& ds); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1195 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1196 ~delimited_stream (void); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1197 |
21567
3d25f9f4a62b
maint: Eliminate Britishicisms in the code.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
1198 // Called when optimized sequence of get is finished. Ensures that |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1199 // there is a remaining delimiter in buf, or loads more data in. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1200 void field_done (void) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1201 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1202 if (idx >= last) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1203 refresh_buf (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1204 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1205 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1206 // Load new data into buffer, and set eob, last, idx. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1207 // Return EOF at end of file, 0 otherwise. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1208 int refresh_buf (void); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1209 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1210 // Get a character, relying on caller to call field_done if |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1211 // a delimiter has been reached. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1212 int get (void) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1213 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1214 if (delimited) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1215 return eof () ? std::istream::traits_type::eof () : *idx++; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1216 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1217 return get_undelim (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1218 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1219 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1220 // Get a character, checking for underrun of the buffer. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1221 int get_undelim (void); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1222 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1223 // Read character that will be got by the next get. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1224 int peek (void) { return eof () ? std::istream::traits_type::eof () : *idx; } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1225 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1226 // Read character that will be got by the next get. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1227 int peek_undelim (void); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1228 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1229 // Undo a 'get' or 'get_undelim'. It is the caller's responsibility |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1230 // to avoid overflow by calling putbacks only for a character got by |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1231 // get() or get_undelim(), with no intervening |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1232 // get, get_delim, field_done, refresh_buf, getline, read or seekg. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1233 void putback (char /*ch*/ = 0) { if (! eof ()) --idx; } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1234 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1235 int getline (std::string& dest, char delim); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1236 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1237 // int skipline (char delim); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1238 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1239 char *read (char *buffer, int size, char* &new_start); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1240 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1241 // Return a position suitable to "seekg", valid only within this |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1242 // block between calls to field_done. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1243 char *tellg (void) { return idx; } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1244 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1245 void seekg (char *old_idx) { idx = old_idx; } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1246 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1247 bool eof (void) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1248 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1249 return (eob == buf && i_stream.eof ()) || (flags & std::ios_base::eofbit); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1250 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1251 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1252 operator const void* (void) { return (! eof () && ! flags) ? this : 0; } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1253 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1254 bool fail (void) { return flags & std::ios_base::failbit; } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1255 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1256 std::ios_base::iostate rdstate (void) { return flags; } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1257 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1258 void setstate (std::ios_base::iostate m) { flags = flags | m; } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1259 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1260 void clear (std::ios_base::iostate m |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1261 = (std::ios_base::eofbit & ~std::ios_base::eofbit)) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1262 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1263 flags = flags & m; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1264 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1265 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1266 // Report if any characters have been consumed. |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21739
diff
changeset
|
1267 // (get, read, etc. not cancelled by putback or seekg) |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1268 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1269 void progress_benchmark (void) { progress_marker = idx; } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1270 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1271 bool no_progress (void) { return progress_marker == idx; } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1272 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1273 private: |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1274 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1275 // Number of characters to read from the file at once. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1276 int bufsize; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1277 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1278 // Stream to read from. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1279 std::istream& i_stream; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1280 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1281 // Temporary storage for a "chunk" of data. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1282 char *buf; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1283 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1284 // Current read pointer. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1285 char *idx; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1286 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1287 // Location of last delimiter in the buffer at buf (undefined if |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1288 // delimited is false). |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1289 char *last; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1290 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1291 // Position after last character in buffer. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1292 char *eob; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1293 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1294 // True if there is delimiter in the bufer after idx. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1295 bool delimited; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1296 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1297 // Longest lookahead required. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1298 int longest; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1299 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1300 // Sequence of single-character delimiters. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1301 const std::string delims; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1302 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1303 // Position of start of buf in original stream. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1304 std::streampos buf_in_file; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1305 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1306 // Marker to see if a read consumes any characters. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1307 char *progress_marker; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1308 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1309 std::ios_base::iostate flags; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1310 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1311 // No copying! |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1312 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1313 delimited_stream (const delimited_stream&); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1314 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1315 delimited_stream& operator = (const delimited_stream&); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1316 }; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1317 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1318 // Create a delimited stream, reading from is, with delimiters delims, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1319 // and allowing reading of up to tellg + longest_lookeahead. When is |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1320 // is at EOF, lookahead may be padded by ASCII nuls. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1321 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1322 delimited_stream::delimited_stream (std::istream& is, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1323 const std::string& delimiters, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1324 int longest_lookahead, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1325 octave_idx_type bsize) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1326 : bufsize (bsize), i_stream (is), longest (longest_lookahead), |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1327 delims (delimiters), |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1328 flags (std::ios::failbit & ~std::ios::failbit) // can't cast 0 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1329 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1330 buf = new char[bufsize]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1331 eob = buf + bufsize; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1332 idx = eob; // refresh_buf shouldn't try to copy old data |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1333 progress_marker = idx; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1334 refresh_buf (); // load the first batch of data |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1335 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1336 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1337 // Used to create a stream from a strstream from data read from a dstr. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1338 // FIXME: Find a more efficient approach. Perhaps derived dstr |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1339 delimited_stream::delimited_stream (std::istream& is, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1340 const delimited_stream& ds) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1341 : bufsize (ds.bufsize), i_stream (is), longest (ds.longest), |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1342 delims (ds.delims), |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1343 flags (std::ios::failbit & ~std::ios::failbit) // can't cast 0 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1344 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1345 buf = new char[bufsize]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1346 eob = buf + bufsize; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1347 idx = eob; // refresh_buf shouldn't try to copy old data |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1348 progress_marker = idx; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1349 refresh_buf (); // load the first batch of data |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1350 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1351 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1352 delimited_stream::~delimited_stream (void) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1353 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1354 // Seek to the correct position in i_stream. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1355 if (! eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1356 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1357 i_stream.clear (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1358 i_stream.seekg (buf_in_file); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1359 i_stream.read (buf, idx - buf); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1360 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1361 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1362 delete [] buf; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1363 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1364 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1365 // Read a character from the buffer, refilling the buffer from the file |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1366 // if necessary. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1367 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1368 int |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1369 delimited_stream::get_undelim (void) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1370 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1371 int retval; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1372 if (eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1373 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1374 setstate (std::ios_base::failbit); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1375 return std::istream::traits_type::eof (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1376 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1377 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1378 if (idx < eob) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1379 retval = *idx++; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1380 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1381 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1382 refresh_buf (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1383 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1384 if (eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1385 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1386 setstate (std::ios_base::eofbit); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1387 retval = std::istream::traits_type::eof (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1388 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1389 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1390 retval = *idx++; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1391 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1392 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1393 if (idx >= last) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1394 delimited = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1395 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1396 return retval; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1397 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1398 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1399 // Return the next character to be read without incrementing the |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1400 // pointer, refilling the buffer from the file if necessary. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1401 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1402 int |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1403 delimited_stream::peek_undelim (void) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1404 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1405 int retval = get_undelim (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1406 putback (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1407 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1408 return retval; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1409 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1410 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1411 // Copy remaining unprocessed data to the start of the buffer and load |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1412 // new data to fill it. Return EOF if the file is at EOF before |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1413 // reading any data and all of the data that has been read has been |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1414 // processed. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1415 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1416 int |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1417 delimited_stream::refresh_buf (void) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1418 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1419 if (eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1420 return std::istream::traits_type::eof (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1421 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1422 int retval; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1423 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1424 if (eob < idx) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1425 idx = eob; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1426 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1427 size_t old_remaining = eob - idx; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1428 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1429 octave_quit (); // allow ctrl-C |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1430 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1431 if (old_remaining > 0) |
21621
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21578
diff
changeset
|
1432 { |
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21578
diff
changeset
|
1433 buf_in_file += (idx - buf); |
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21578
diff
changeset
|
1434 memmove (buf, idx, old_remaining); |
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21578
diff
changeset
|
1435 } |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1436 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1437 progress_marker -= idx - buf; // where original idx would have been |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1438 idx = buf; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1439 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1440 int gcount; // chars read |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1441 if (! i_stream.eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1442 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1443 buf_in_file = i_stream.tellg (); // record for destructor |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1444 i_stream.read (buf + old_remaining, bufsize - old_remaining); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1445 gcount = i_stream.gcount (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1446 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1447 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1448 gcount = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1449 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1450 eob = buf + old_remaining + gcount; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1451 last = eob; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1452 if (gcount == 0) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1453 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1454 delimited = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1455 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1456 if (eob != buf) // no more data in file, but still some to go |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1457 retval = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1458 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1459 // file and buffer are both done. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1460 retval = std::istream::traits_type::eof (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1461 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1462 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1463 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1464 delimited = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1465 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1466 for (last = eob - longest; last - buf >= 0; last--) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1467 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1468 if (delims.find (*last) != std::string::npos) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1469 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1470 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1471 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1472 if (last < buf) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1473 delimited = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1474 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1475 retval = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1476 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1477 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1478 // Ensure fast peek doesn't give valid char |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1479 if (retval == std::istream::traits_type::eof ()) |
21578
683a1beee538
maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
1480 *idx = '\0'; // FIXME: check that no TreatAsEmpty etc starts w. \0? |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1481 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1482 return retval; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1483 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1484 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1485 // Return a pointer to a block of data of size size, assuming that a |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1486 // sufficiently large buffer is available in buffer, if required. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1487 // If called when delimited == true, and size is no greater than |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1488 // longest_lookahead then this will not call refresh_buf, so seekg |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1489 // still works. Otherwise, seekg may be invalidated. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1490 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1491 char * |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1492 delimited_stream::read (char *buffer, int size, char* &prior_tell) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1493 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1494 char *retval; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1495 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1496 if (eob - idx > size) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1497 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1498 retval = idx; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1499 idx += size; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1500 if (idx > last) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1501 delimited = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1502 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1503 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1504 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1505 // If there was a tellg pointing to an earlier point than the current |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1506 // read position, try to keep it in the active buffer. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1507 // In the current code, prior_tell==idx for each call, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1508 // so this is not necessary, just a precaution. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1509 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1510 if (eob - prior_tell + size < bufsize) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1511 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1512 octave_idx_type gap = idx - prior_tell; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1513 idx = prior_tell; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1514 refresh_buf (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1515 idx += gap; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1516 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1517 else // can't keep the tellg in range. May skip some data. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1518 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1519 refresh_buf (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1520 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1521 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1522 prior_tell = buf; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1523 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1524 if (eob - idx > size) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1525 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1526 retval = idx; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1527 idx += size; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1528 if (idx > last) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1529 delimited = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1530 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1531 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1532 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1533 if (size <= bufsize) // small read, but reached EOF |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1534 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1535 retval = idx; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1536 memset (eob, 0, size + (idx - buf)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1537 idx += size; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1538 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1539 else // Reading more than the whole buf; return it in buffer |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1540 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1541 retval = buffer; |
21578
683a1beee538
maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
1542 // FIXME: read bufsize at a time |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1543 int i; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1544 for (i = 0; i < size && ! eof (); i++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1545 *buffer++ = get_undelim (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1546 if (eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1547 memset (buffer, 0, size - i); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1548 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1549 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1550 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1551 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1552 return retval; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1553 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1554 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1555 // Return in OUT an entire line, terminated by delim. On input, OUT |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1556 // must have length at least 1. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1557 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1558 int |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1559 delimited_stream::getline (std::string& out, char delim) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1560 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1561 int len = out.length (), used = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1562 int ch; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1563 while ((ch = get_undelim ()) != delim |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1564 && ch != std::istream::traits_type::eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1565 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1566 out[used++] = ch; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1567 if (used == len) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1568 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1569 len <<= 1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1570 out.resize (len); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1571 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1572 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1573 out.resize (used); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1574 field_done (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1575 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1576 return ch; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1577 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1578 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1579 // A single conversion specifier, such as %f or %c. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1580 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1581 class |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1582 textscan_format_elt |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1583 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1584 public: |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1585 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1586 enum special_conversion |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1587 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1588 whitespace_conversion = 1, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1589 literal_conversion = 2 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1590 }; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1591 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1592 textscan_format_elt (const std::string& txt, int w = 0, int p = -1, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1593 int bw = 0, bool dis = false, char typ = '\0', |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1594 const std::string& ch_class = std::string ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1595 : text (txt), width (w), prec (p), bitwidth (bw), |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1596 char_class (ch_class), type (typ), discard (dis), |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1597 numeric (typ == 'd' || typ == 'u' || type == 'f' || type == 'n') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1598 { } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1599 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1600 textscan_format_elt (const textscan_format_elt& e) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1601 : text (e.text), width (e.width), prec (e.prec), |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1602 bitwidth (e.bitwidth), char_class (e.char_class), type (e.type), |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1603 discard (e.discard), numeric (e.numeric) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1604 { } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1605 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1606 textscan_format_elt& operator = (const textscan_format_elt& e) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1607 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1608 if (this != &e) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1609 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1610 text = e.text; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1611 width = e.width; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1612 prec = e.prec; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1613 bitwidth = e.bitwidth; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1614 discard = e.discard; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1615 type = e.type; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1616 numeric = e.numeric; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1617 char_class = e.char_class; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1618 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1619 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1620 return *this; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1621 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1622 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1623 // The C-style format string. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1624 std::string text; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1625 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1626 // The maximum field width. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1627 unsigned int width; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1628 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1629 // The maximum number of digits to read after the decimal in a |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1630 // floating point conversion. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1631 int prec; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1632 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1633 // The size of the result. For integers, bitwidth may be 8, 16, 34, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1634 // or 64. For floating point values, bitwidth may be 32 or 64. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1635 int bitwidth; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1636 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1637 // The class of characters in a `[' or `^' format. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1638 std::string char_class; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1639 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1640 // Type of conversion |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1641 // -- `d', `u', `f', `n', `s', `q', `c', `%', `C', `D', `[' or `^'. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1642 char type; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1643 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1644 // TRUE if we are not storing the result of this conversion. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1645 bool discard; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1646 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1647 // TRUE if the type is 'd', 'u', 'f', 'n' |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1648 bool numeric; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1649 }; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1650 |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1651 // The (parsed) sequence of format specifiers. |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1652 |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1653 class textscan; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1654 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1655 class |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1656 textscan_format_list |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1657 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1658 public: |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1659 |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1660 textscan_format_list (const std::string& fmt = std::string (), |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1661 const std::string& who = "textscan"); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1662 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1663 ~textscan_format_list (void); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1664 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1665 octave_idx_type num_conversions (void) const { return nconv; } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1666 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1667 // The length can be different than the number of conversions. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1668 // For example, "x %d y %d z" has 2 conversions but the length of |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1669 // the list is 3 because of the characters that appear after the |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1670 // last conversion. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1671 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1672 size_t numel (void) const { return fmt_elts.size (); } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1673 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1674 const textscan_format_elt *first (void) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1675 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1676 curr_idx = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1677 return current (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1678 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1679 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1680 const textscan_format_elt *current (void) const |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1681 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1682 return numel () > 0 ? fmt_elts[curr_idx] : 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1683 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1684 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1685 const textscan_format_elt *next (bool cycle = true) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1686 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1687 curr_idx++; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1688 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1689 if (curr_idx >= numel ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1690 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1691 if (cycle) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1692 curr_idx = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1693 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1694 return 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1695 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1696 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1697 return current (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1698 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1699 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1700 void printme (void) const; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1701 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1702 bool ok (void) const { return (nconv >= 0); } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1703 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1704 operator const void* (void) const { return ok () ? this : 0; } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1705 |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1706 // What function name should be shown when reporting errors. |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1707 std::string who; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1708 |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1709 // True if number of %f to be set from data file. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1710 bool set_from_first; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1711 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1712 // At least one conversion specifier is s,q,c, or [...]. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1713 bool has_string; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1714 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1715 int read_first_row (delimited_stream& is, textscan& ts); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1716 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1717 std::list<octave_value> out_buf (void) const { return (output_container); } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1718 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1719 private: |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1720 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1721 // Number of conversions specified by this format string, or -1 if |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1722 // invalid conversions have been found. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1723 octave_idx_type nconv; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1724 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1725 // Index to current element; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1726 size_t curr_idx; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1727 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1728 // List of format elements. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1729 std::deque<textscan_format_elt*> fmt_elts; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1730 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1731 // list holding column arrays of types specified by conversions |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1732 std::list<octave_value> output_container; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1733 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1734 // Temporary buffer. |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1735 std::ostringstream buf; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1736 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1737 void add_elt_to_list (unsigned int width, int prec, int bitwidth, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1738 octave_value val_type, bool discard, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1739 char type, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1740 const std::string& char_class = std::string ()); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1741 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1742 void process_conversion (const std::string& s, size_t& i, size_t n); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1743 |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1744 std::string parse_char_class (const std::string& pattern) const; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1745 |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1746 int finish_conversion (const std::string& s, size_t& i, size_t n, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1747 unsigned int& width, int& prec, int& bitwidth, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1748 octave_value& val_type, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1749 bool discard, char& type); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1750 // No copying! |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1751 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1752 textscan_format_list (const textscan_format_list&); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1753 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1754 textscan_format_list& operator = (const textscan_format_list&); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1755 }; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1756 |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1757 // Main class to implement textscan. Read data and parse it |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1758 // according to a format. |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1759 // |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1760 // The calling sequence is |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1761 // |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1762 // textscan scanner (); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1763 // scanner.scan (...); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1764 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1765 class |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1766 OCTINTERP_API |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1767 textscan |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1768 { |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1769 public: |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1770 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1771 textscan (const std::string& who_arg = "textscan"); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1772 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1773 ~textscan (void) { } |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1774 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1775 octave_value scan (std::istream& isp, const std::string& fmt, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1776 octave_idx_type ntimes, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1777 const octave_value_list& options, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1778 octave_idx_type& read_count); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1779 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1780 private: |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1781 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1782 friend class textscan_format_list; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1783 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1784 // What function name should be shown when reporting errors. |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1785 std::string who; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1786 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1787 std::string buf; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1788 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1789 // Three cases for delim_table and delim_list |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1790 // 1. delim_table empty, delim_list empty: whitespace delimiters |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1791 // 2. delim_table = look-up table of delim chars, delim_list empty. |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1792 // 3. delim_table non-empty, delim_list = Cell array of delim strings |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1793 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1794 std::string whitespace_table; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1795 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1796 // delim_table[i] == '\0' if i is not a delimiter. |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1797 std::string delim_table; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1798 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1799 // String of delimiter characters. |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1800 std::string delims; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1801 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1802 Cell comment_style; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1803 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1804 // How far ahead to look to detect an open comment. |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1805 int comment_len; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1806 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1807 // First character of open comment. |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1808 int comment_char; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1809 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1810 octave_idx_type buffer_size; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1811 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1812 std::string date_locale; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1813 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1814 // 'inf' and 'nan' for formatted_double. |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1815 Cell inf_nan; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1816 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1817 // Array of strings of delimiters. |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1818 Cell delim_list; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1819 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1820 // Longest delimiter. |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1821 int delim_len; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1822 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1823 octave_value empty_value; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1824 std::string exp_chars; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1825 int header_lines; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1826 Cell treat_as_empty; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1827 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1828 // Longest string to treat as "N/A". |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1829 int treat_as_empty_len; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1830 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1831 std::string whitespace; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1832 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1833 short eol1; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1834 short eol2; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1835 short return_on_error; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1836 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1837 bool collect_output; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1838 bool multiple_delims_as_one; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1839 bool default_exp; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1840 bool numeric_delim; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1841 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1842 octave_idx_type lines; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1843 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1844 octave_value do_scan (std::istream& isp, textscan_format_list& fmt_list, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1845 octave_idx_type ntimes); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1846 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1847 void parse_options (const octave_value_list& args, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1848 textscan_format_list& fmt_list); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1849 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1850 int read_format_once (delimited_stream& isp, textscan_format_list& fmt_list, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1851 std::list<octave_value>& retval, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1852 Array<octave_idx_type> row, int& done_after); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1853 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1854 void scan_one (delimited_stream& is, const textscan_format_elt& fmt, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1855 octave_value& ov, Array<octave_idx_type> row); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1856 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1857 // Methods to process a particular conversion specifier. |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1858 double read_double (delimited_stream& is, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1859 const textscan_format_elt& fmt) const; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1860 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1861 void scan_complex (delimited_stream& is, const textscan_format_elt& fmt, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1862 Complex& val) const; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1863 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1864 int scan_bracket (delimited_stream& is, const std::string& pattern, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1865 std::string& val) const; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1866 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1867 int scan_caret (delimited_stream& is, const std::string& pattern, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1868 std::string& val) const; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1869 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1870 void scan_string (delimited_stream& is, const textscan_format_elt& fmt, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1871 std::string& val) const; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1872 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1873 void scan_cstring (delimited_stream& is, const textscan_format_elt& fmt, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1874 std::string& val) const; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1875 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1876 void scan_qstring (delimited_stream& is, const textscan_format_elt& fmt, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1877 std::string& val); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1878 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1879 // Helper methods. |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1880 std::string read_until (delimited_stream& is, const Cell& delimiters, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1881 const std::string& ends) const; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1882 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1883 int lookahead (delimited_stream& is, const Cell& targets, int max_len, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1884 bool case_sensitive = true) const; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1885 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1886 bool match_literal (delimited_stream& isp, const textscan_format_elt& elem); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1887 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1888 int skip_whitespace (delimited_stream& is, bool EOLstop = false); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1889 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1890 int skip_delim (delimited_stream& is); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1891 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1892 bool is_delim (unsigned char ch) const |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1893 { |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1894 return ((delim_table.empty () && (isspace (ch) || ch == eol1 || ch == eol2)) |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1895 || delim_table[ch] != '\0'); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1896 } |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1897 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1898 bool isspace (unsigned int ch) const { return whitespace_table[ch & 0xff]; } |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1899 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1900 // True if the only delimiter is whitespace. |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1901 bool whitespace_delim (void) const { return delim_table.empty (); } |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1902 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1903 // No copying! |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1904 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1905 textscan (const textscan&); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1906 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1907 textscan& operator = (const textscan&); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1908 }; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1909 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1910 textscan_format_list::textscan_format_list (const std::string& s, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1911 const std::string& who_arg) |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
1912 : who (who_arg), set_from_first (false), has_string (false), |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1913 nconv (0), curr_idx (0), fmt_elts (), buf () |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1914 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1915 size_t n = s.length (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1916 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1917 size_t i = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1918 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1919 unsigned int width = -1; // Unspecified width = max (except %c) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1920 int prec = -1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1921 int bitwidth = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1922 bool discard = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1923 char type = '\0'; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1924 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1925 bool have_more = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1926 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1927 if (s.empty ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1928 { |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1929 buf.clear (); |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1930 buf.str (""); |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1931 |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1932 buf << "%f"; |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1933 |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1934 bitwidth = 64; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1935 type = 'f'; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1936 add_elt_to_list (width, prec, bitwidth, octave_value (NDArray ()), |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1937 discard, type); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1938 have_more = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1939 set_from_first = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1940 nconv = 1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1941 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1942 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1943 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1944 set_from_first = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1945 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1946 while (i < n) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1947 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1948 have_more = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1949 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1950 if (s[i] == '%' && (i+1 == n || s[i+1] != '%')) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1951 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1952 // Process percent-escape conversion type. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1953 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1954 process_conversion (s, i, n); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1955 |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1956 // If there is nothing in the buffer, then add_elt_to_list |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1957 // must have just been called, so we are already done with |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1958 // the current element and we don't need to call |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1959 // add_elt_to_list if this is our last trip through the |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1960 // loop. |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1961 |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1962 have_more = (buf.tellp () != 0); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1963 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1964 else if (isspace (s[i])) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1965 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1966 while (++i < n && isspace (s[i])) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1967 /* skip whitespace */; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1968 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1969 have_more = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1970 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1971 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1972 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1973 type = textscan_format_elt::literal_conversion; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1974 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1975 width = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1976 prec = -1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1977 bitwidth = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1978 discard = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1979 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1980 while (i < n && ! isspace (s[i]) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1981 && (s[i] != '%' || (i+1 < n && s[i+1] == '%'))) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1982 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1983 if (s[i] == '%') // if double %, skip one |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1984 i++; |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
1985 buf << s[i++]; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1986 width++; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1987 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1988 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1989 add_elt_to_list (width, prec, bitwidth, octave_value (), |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1990 discard, type); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1991 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1992 have_more = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1993 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1994 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1995 if (nconv < 0) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1996 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1997 have_more = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1998 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
1999 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2000 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2001 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2002 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2003 if (have_more) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2004 add_elt_to_list (width, prec, bitwidth, octave_value (), discard, type); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2005 |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2006 buf.clear (); |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2007 buf.str (""); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2008 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2009 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2010 textscan_format_list::~textscan_format_list (void) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2011 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2012 size_t n = numel (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2013 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2014 for (size_t i = 0; i < n; i++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2015 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2016 textscan_format_elt *elt = fmt_elts[i]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2017 delete elt; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2018 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2019 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2020 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2021 void |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2022 textscan_format_list::add_elt_to_list (unsigned int width, int prec, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2023 int bitwidth, octave_value val_type, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2024 bool discard, char type, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2025 const std::string& char_class) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2026 { |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2027 std::string text = buf.str (); |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2028 |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2029 if (! text.empty ()) |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2030 { |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2031 textscan_format_elt *elt |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2032 = new textscan_format_elt (text, width, prec, bitwidth, discard, type, char_class); |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2033 |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2034 if (! discard) |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2035 output_container.push_back (val_type); |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2036 |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2037 fmt_elts.push_back (elt); |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2038 } |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2039 |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2040 buf.clear (); |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2041 buf.str (""); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2042 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2043 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2044 void |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2045 textscan_format_list::process_conversion (const std::string& s, size_t& i, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2046 size_t n) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2047 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2048 unsigned width = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2049 int prec = -1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2050 int bitwidth = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2051 bool discard = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2052 octave_value val_type; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2053 char type = '\0'; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2054 |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2055 buf << s[i++]; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2056 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2057 bool have_width = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2058 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2059 while (i < n) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2060 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2061 switch (s[i]) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2062 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2063 case '*': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2064 if (discard) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2065 nconv = -1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2066 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2067 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2068 discard = true; |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2069 buf << s[i++]; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2070 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2071 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2072 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2073 case '0': case '1': case '2': case '3': case '4': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2074 case '5': case '6': case '7': case '8': case '9': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2075 if (have_width) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2076 nconv = -1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2077 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2078 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2079 char c = s[i++]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2080 width = width * 10 + c - '0'; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2081 have_width = true; |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2082 buf << c; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2083 while (i < n && isdigit (s[i])) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2084 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2085 c = s[i++]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2086 width = width * 10 + c - '0'; |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2087 buf << c; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2088 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2089 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2090 if (i < n && s[i] == '.') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2091 { |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2092 buf << s[i++]; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2093 prec = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2094 while (i < n && isdigit (s[i])) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2095 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2096 c = s[i++]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2097 prec = prec * 10 + c - '0'; |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2098 buf << c; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2099 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2100 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2101 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2102 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2103 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2104 case 'd': case 'u': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2105 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2106 bool done = true; |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2107 buf << (type = s[i++]); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2108 if (i < n) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2109 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2110 if (s[i] == '8') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2111 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2112 bitwidth = 8; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2113 if (type == 'd') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2114 val_type = octave_value (int8NDArray ()); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2115 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2116 val_type = octave_value (uint8NDArray ()); |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2117 buf << s[i++]; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2118 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2119 else if (s[i] == '1' && i+1 < n && s[i+1] == '6') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2120 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2121 bitwidth = 16; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2122 if (type == 'd') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2123 val_type = octave_value (int16NDArray ()); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2124 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2125 val_type = octave_value (uint16NDArray ()); |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2126 buf << s[i++]; |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2127 buf << s[i++]; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2128 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2129 else if (s[i] == '3' && i+1 < n && s[i+1] == '2') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2130 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2131 done = false; // use default size below |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2132 buf << s[i++]; |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2133 buf << s[i++]; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2134 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2135 else if (s[i] == '6' && i+1 < n && s[i+1] == '4') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2136 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2137 bitwidth = 64; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2138 if (type == 'd') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2139 val_type = octave_value (int64NDArray ()); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2140 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2141 val_type = octave_value (uint64NDArray ()); |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2142 buf << s[i++]; |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2143 buf << s[i++]; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2144 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2145 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2146 done = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2147 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2148 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2149 done = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2150 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2151 if (! done) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2152 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2153 bitwidth = 32; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2154 if (type == 'd') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2155 val_type = octave_value (int32NDArray ()); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2156 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2157 val_type = octave_value (uint32NDArray ()); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2158 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2159 goto fini; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2160 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2161 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2162 case 'f': |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2163 buf << (type = s[i++]); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2164 bitwidth = 64; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2165 if (i < n) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2166 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2167 if (s[i] == '3' && i+1 < n && s[i+1] == '2') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2168 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2169 bitwidth = 32; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2170 val_type = octave_value (FloatNDArray ()); |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2171 buf << s[i++]; |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2172 buf << s[i++]; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2173 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2174 else if (s[i] == '6' && i+1 < n && s[i+1] == '4') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2175 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2176 val_type = octave_value (NDArray ()); |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2177 buf << s[i++]; |
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2178 buf << s[i++]; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2179 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2180 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2181 val_type = octave_value (NDArray ()); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2182 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2183 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2184 val_type = octave_value (NDArray ()); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2185 goto fini; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2186 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2187 case 'n': |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2188 buf << (type = s[i++]); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2189 bitwidth = 64; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2190 val_type = octave_value (NDArray ()); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2191 goto fini; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2192 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2193 case 's': case 'q': case '[': case 'c': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2194 if (! discard) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2195 val_type = octave_value (Cell ()); |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2196 buf << (type = s[i++]); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2197 has_string = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2198 goto fini; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2199 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2200 fini: |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2201 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2202 if (! have_width) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2203 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2204 if (type == 'c') // %c defaults to one character |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2205 width = 1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2206 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2207 width = static_cast<unsigned int> (-1); // others: unlimited |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2208 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2209 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2210 if (finish_conversion (s, i, n, width, prec, bitwidth, val_type, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2211 discard, type) == 0) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2212 return; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2213 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2214 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2215 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2216 default: |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2217 error ("%s: '%%%c' is not a valid format specifier", |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2218 who.c_str (), s[i]); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2219 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2220 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2221 if (nconv < 0) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2222 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2223 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2224 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2225 nconv = -1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2226 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2227 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2228 // Parse [...] and [^...] |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2229 // |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2230 // Matlab does not expand expressions like A-Z, but they are useful, and |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2231 // so we parse them "carefully". We treat '-' as a usual character |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2232 // unless both start and end characters are from the same class (upper |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2233 // case, lower case, numeric), or this is not the first '-' in the |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2234 // pattern. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2235 // |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2236 // Keep both a running list of characters and a mask of which chars have |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2237 // occurred. The first is efficient for patterns with few characters. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2238 // The latter is efficient for [^...] patterns. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2239 |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2240 std::string |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2241 textscan_format_list::parse_char_class (const std::string& pattern) const |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2242 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2243 int len = pattern.length (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2244 if (len == 0) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2245 return ""; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2246 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2247 std::string retval (256, '\0'); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2248 std::string mask (256, '\0'); // number of times chr has been seen |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2249 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2250 int in = 0, out = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2251 unsigned char ch, prev = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2252 bool flip = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2253 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2254 ch = pattern[in]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2255 if (ch == '^') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2256 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2257 in++; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2258 flip = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2259 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2260 mask[pattern[in]] = '\1'; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2261 retval[out++] = pattern[in++]; // even copy ']' if it is first |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2262 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2263 bool prev_was_range = false; // disallow "a-m-z" as a pattern |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2264 bool prev_prev_was_range = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2265 for (; in < len; in++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2266 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2267 bool was_range = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2268 ch = pattern[in]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2269 if (ch == ']') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2270 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2271 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2272 if (prev == '-' && in > 1 && isalnum (ch) && ! prev_prev_was_range) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2273 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2274 unsigned char start_of_range = pattern[in-2]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2275 if (start_of_range < ch |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2276 && ((isupper (ch) && isupper (start_of_range)) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2277 || (islower (ch) && islower (start_of_range)) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2278 || (isdigit (ch) && isdigit (start_of_range)) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2279 || mask['-'] > 1)) // not the first '-' |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2280 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2281 was_range = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2282 out--; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2283 mask['-']--; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2284 for (int i = start_of_range; i <= ch; i++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2285 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2286 if (mask[i] == '\0') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2287 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2288 mask[i] = '\1'; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2289 retval[out++] = i; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2290 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2291 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2292 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2293 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2294 if (! was_range) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2295 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2296 if (mask[ch]++ == 0) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2297 retval[out++] = ch; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2298 else if (ch != '-') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2299 warning_with_id ("octave:textscan-pattern", |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2300 "%s: [...] contains two '%c's", |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2301 who.c_str (), ch); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2302 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2303 if (prev == '-' && mask['-'] >= 2) |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2304 warning_with_id |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2305 ("octave:textscan-pattern", |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2306 "%s: [...] contains two '-'s outside range expressions", |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2307 who.c_str ()); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2308 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2309 prev = ch; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2310 prev_prev_was_range = prev_was_range; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2311 prev_was_range = was_range; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2312 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2313 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2314 if (flip) // [^...] |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2315 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2316 out = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2317 for (int i = 0; i < 256; i++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2318 if (! mask[i]) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2319 retval[out++] = i; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2320 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2321 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2322 retval.resize (out); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2323 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2324 return retval; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2325 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2326 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2327 int |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2328 textscan_format_list::finish_conversion (const std::string& s, size_t& i, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2329 size_t n, unsigned int& width, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2330 int& prec, int& bitwidth, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2331 octave_value& val_type, bool discard, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2332 char& type) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2333 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2334 int retval = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2335 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2336 std::string char_class; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2337 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2338 size_t beg_idx = std::string::npos; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2339 size_t end_idx = std::string::npos; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2340 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2341 if (type != '%') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2342 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2343 nconv++; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2344 if (type == '[') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2345 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2346 if (i < n) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2347 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2348 beg_idx = i; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2349 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2350 if (s[i] == '^') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2351 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2352 type = '^'; |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2353 buf << s[i++]; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2354 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2355 if (i < n) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2356 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2357 beg_idx = i; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2358 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2359 if (s[i] == ']') |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2360 buf << s[i++]; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2361 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2362 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2363 else if (s[i] == ']') |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2364 buf << s[i++]; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2365 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2366 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2367 while (i < n && s[i] != ']') |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2368 buf << s[i++]; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2369 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2370 if (i < n && s[i] == ']') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2371 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2372 end_idx = i-1; |
21517
e626d8a3427e
avoid possible memory leak related to ostringstream objects
John W. Eaton <jwe@octave.org>
parents:
21503
diff
changeset
|
2373 buf << s[i++]; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2374 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2375 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2376 if (s[i-1] != ']') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2377 retval = nconv = -1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2378 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2379 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2380 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2381 if (nconv >= 0) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2382 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2383 if (beg_idx != std::string::npos && end_idx != std::string::npos) |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2384 char_class = parse_char_class (s.substr (beg_idx, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2385 end_idx - beg_idx + 1)); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2386 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2387 add_elt_to_list (width, prec, bitwidth, val_type, discard, type, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2388 char_class); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2389 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2390 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2391 return retval; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2392 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2393 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2394 void |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2395 textscan_format_list::printme (void) const |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2396 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2397 size_t n = numel (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2398 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2399 for (size_t i = 0; i < n; i++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2400 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2401 textscan_format_elt *elt = fmt_elts[i]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2402 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2403 std::cerr |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2404 << "width: " << elt->width << "\n" |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2405 << "digits " << elt->prec << "\n" |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2406 << "bitwidth: " << elt->bitwidth << "\n" |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2407 << "discard: " << elt->discard << "\n" |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2408 << "type: "; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2409 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2410 if (elt->type == textscan_format_elt::literal_conversion) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2411 std::cerr << "literal text\n"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2412 else if (elt->type == textscan_format_elt::whitespace_conversion) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2413 std::cerr << "whitespace\n"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2414 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2415 std::cerr << elt->type << "\n"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2416 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2417 std::cerr |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2418 << "char_class: `" << undo_string_escapes (elt->char_class) << "'\n" |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2419 << "text: `" << undo_string_escapes (elt->text) << "'\n\n"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2420 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2421 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2422 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2423 // If FORMAT is explicitly "", it is assumed to be "%f" repeated enough |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2424 // times to read the first row of the file. Set it now. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2425 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2426 int |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2427 textscan_format_list::read_first_row (delimited_stream& is, textscan& ts) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2428 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2429 // Read first line and strip end-of-line, which may be two characters |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2430 std::string first_line (20, ' '); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2431 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2432 is.getline (first_line, static_cast<char> (ts.eol2)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2433 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2434 if (! first_line.empty () |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2435 && first_line[first_line.length () - 1] == ts.eol1) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2436 first_line.resize (first_line.length () - 1); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2437 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2438 std::istringstream strstr (first_line); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2439 delimited_stream ds (strstr, is); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2440 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2441 dim_vector dv (1,1); // initial size of each output_container |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2442 Complex val; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2443 octave_value val_type; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2444 nconv = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2445 int max_empty = 1000; // failsafe, if ds fails but not with eof |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2446 int retval = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2447 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2448 // read line, creating output_container as we go |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2449 while (! ds.eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2450 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2451 bool already_skipped_delim = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2452 ts.skip_whitespace (ds); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2453 ds.progress_benchmark (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2454 bool progress = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2455 ts.scan_complex (ds, *fmt_elts[0], val); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2456 if (ds.fail ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2457 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2458 ds.clear (ds.rdstate () & ~std::ios::failbit); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2459 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2460 if (ds.eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2461 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2462 |
21622
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
2463 // Unless this was a missing value (i.e., followed by a delimiter), |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2464 // return with an error status. |
21622
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
2465 ts.skip_delim (ds); |
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
2466 if (ds.no_progress ()) |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2467 { |
21622
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
2468 retval = 4; |
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
2469 break; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2470 } |
21622
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
2471 already_skipped_delim = true; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2472 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2473 val = ts.empty_value.scalar_value (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2474 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2475 if (! --max_empty) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2476 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2477 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2478 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2479 if (val.imag () == 0) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2480 val_type = octave_value (NDArray (dv, val.real ())); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2481 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2482 val_type = octave_value (ComplexNDArray (dv, val)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2483 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2484 output_container.push_back (val_type); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2485 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2486 if (! already_skipped_delim) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2487 ts.skip_delim (ds); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2488 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2489 if (! progress && ds.no_progress ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2490 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2491 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2492 nconv++; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2493 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2494 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2495 output_container.pop_front (); // discard empty element from constructor |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2496 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2497 // Create fmt_list now that the size is known |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2498 for (octave_idx_type i = 1; i < nconv; i++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2499 fmt_elts.push_back (new textscan_format_elt (*fmt_elts[0])); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2500 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2501 return retval; // May have returned 4 above. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2502 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2503 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2504 static Cell |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2505 init_inf_nan (void) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2506 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2507 Cell retval (dim_vector (1, 2)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2508 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2509 retval(0) = Cell (octave_value ("inf")); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2510 retval(1) = Cell (octave_value ("nan")); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2511 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2512 return retval; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2513 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2514 |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2515 textscan::textscan (const std::string& who_arg) |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2516 : who (who_arg), buf (), whitespace_table (), delim_table (), |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2517 delims (), comment_style (), comment_len (0), comment_char (-2), |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2518 buffer_size (0), date_locale (), inf_nan (init_inf_nan ()), |
21723
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
2519 empty_value (octave::numeric_limits<double>::NaN ()), exp_chars ("edED"), |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2520 header_lines (0), treat_as_empty (), treat_as_empty_len (0), |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2521 whitespace (" \b\t"), eol1 ('\r'), eol2 ('\n'), |
21622
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
2522 return_on_error (1), collect_output (false), |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2523 multiple_delims_as_one (false), default_exp (true), |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2524 numeric_delim (false), lines (0) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2525 { } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2526 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2527 octave_value |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2528 textscan::scan (std::istream& isp, const std::string& fmt, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2529 octave_idx_type ntimes, const octave_value_list& options, |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2530 octave_idx_type& count) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2531 { |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2532 textscan_format_list fmt_list (fmt); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2533 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2534 parse_options (options, fmt_list); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2535 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2536 octave_value result = do_scan (isp, fmt_list, ntimes); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2537 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2538 // FIXME: this is probably not the best way to get count. The |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2539 // position could easily be larger than octave_idx_type when using |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2540 // 32-bit indexing. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2541 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2542 std::ios::iostate state = isp.rdstate (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2543 isp.clear (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2544 count = static_cast<octave_idx_type> (isp.tellg ()); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2545 isp.setstate (state); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2546 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2547 return result; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2548 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2549 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2550 octave_value |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2551 textscan::do_scan (std::istream& isp, textscan_format_list& fmt_list, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2552 octave_idx_type ntimes) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2553 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2554 octave_value retval; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2555 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2556 if (fmt_list.num_conversions () == -1) |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2557 error ("%s: invalid format specified", who.c_str ()); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2558 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2559 if (fmt_list.num_conversions () == 0) |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2560 error ("%s: no valid format conversion specifiers", who.c_str ()); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2561 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2562 // skip the first header_lines |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2563 std::string dummy; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2564 for (int i = 0; i < header_lines && isp; i++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2565 getline (isp, dummy, static_cast<char> (eol2)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2566 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2567 // Create our own buffered stream, for fast get/putback/tell/seek. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2568 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2569 // First, see how far ahead it should let us look. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2570 int max_lookahead = std::max (std::max (comment_len, treat_as_empty_len), |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2571 std::max (delim_len, 3)); // 3 for NaN and Inf |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2572 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2573 // Next, choose a buffer size to avoid reading too much, or too often. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2574 octave_idx_type buf_size = 4096; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2575 if (buffer_size) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2576 buf_size = buffer_size; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2577 else if (ntimes > 0) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2578 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2579 // Avoid overflow of 80*ntimes... |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2580 buf_size = std::min (buf_size, std::max (ntimes, 80 * ntimes)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2581 buf_size = std::max (buf_size, ntimes); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2582 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2583 // Finally, create the stream. |
21552
102b33b53ea4
textscan: Use correct delimiters for file buffering (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21551
diff
changeset
|
2584 delimited_stream is (isp, |
102b33b53ea4
textscan: Use correct delimiters for file buffering (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21551
diff
changeset
|
2585 (delim_table.empty () ? whitespace + "\r\n" : delims), |
102b33b53ea4
textscan: Use correct delimiters for file buffering (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21551
diff
changeset
|
2586 max_lookahead, buf_size); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2587 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2588 // Grow retval dynamically. "size" is half the initial size |
21578
683a1beee538
maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
2589 // (FIXME: Should we start smaller if ntimes is large?) |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2590 octave_idx_type size = ((ntimes < 8 && ntimes >= 0) ? ntimes : 1); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2591 Array<octave_idx_type> row_idx (dim_vector (1,2)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2592 row_idx(1) = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2593 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2594 int err = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2595 octave_idx_type row = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2596 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2597 if (multiple_delims_as_one) // bug #44750? |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2598 skip_delim (is); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2599 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2600 int done_after; // Number of columns read when EOF seen. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2601 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2602 // If FORMAT explicitly "", read first line and see how many "%f" match |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2603 if (fmt_list.set_from_first) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2604 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2605 err = fmt_list.read_first_row (is, *this); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2606 lines = 1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2607 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2608 done_after = fmt_list.numel () + 1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2609 if (! err) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2610 row = 1; // the above puts the first line into fmt_list.out_buf () |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2611 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2612 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2613 done_after = fmt_list.out_buf ().size () + 1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2614 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2615 std::list<octave_value> out = fmt_list.out_buf (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2616 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2617 // We will later merge adjacent columns of the same type. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2618 // Check now which columns to merge. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2619 // Reals may become complex, and so we can't trust types |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2620 // after reading in data. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2621 // If the format was "", that conversion may already have happened, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2622 // so force all to be merged (as all are %f). |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2623 bool merge_with_prev[fmt_list.numel ()]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2624 int conv = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2625 if (collect_output) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2626 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2627 int prev_type = -1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2628 for (std::list<octave_value>::iterator col = out.begin (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2629 col != out.end (); col++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2630 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2631 if (col->type_id () == prev_type |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2632 || (fmt_list.set_from_first && prev_type != -1)) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2633 merge_with_prev [conv++] = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2634 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2635 merge_with_prev [conv++] = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2636 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2637 prev_type = col->type_id (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2638 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2639 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2640 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2641 // This should be caught by earlier code, but this avoids a possible |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2642 // infinite loop below. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2643 if (fmt_list.num_conversions () == 0) |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2644 error ("%s: No conversions specified", who.c_str ()); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2645 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2646 // Read the data. This is the main loop. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2647 if (! err) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2648 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2649 for (/* row set ~30 lines above */; row < ntimes || ntimes == -1; row++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2650 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2651 if (row == 0 || row >= size) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2652 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2653 size += size+1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2654 for (std::list<octave_value>::iterator col = out.begin (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2655 col != out.end (); col++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2656 *col = (*col).resize (dim_vector (size, 1), 0); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2657 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2658 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2659 row_idx(0) = row; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2660 err = read_format_once (is, fmt_list, out, row_idx, done_after); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2661 |
21622
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
2662 if ((err & ~1) > 0 || ! is || (lines >= ntimes && ntimes > -1)) |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2663 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2664 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2665 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2666 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2667 if ((err & 4) && ! return_on_error) |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
2668 error ("%s: Read error in field %d of row %d", who.c_str (), |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2669 done_after + 1, row + 1); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2670 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2671 // If file does not end in EOL, do not pad columns with NaN. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2672 bool uneven_columns = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2673 if (err & 4) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2674 uneven_columns = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2675 else if (isp.eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2676 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2677 isp.clear (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2678 isp.seekg (-1, std::ios_base::end); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2679 int last_char = isp.get (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2680 isp.setstate (isp.eofbit); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2681 uneven_columns = (last_char != eol1 && last_char != eol2); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2682 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2683 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2684 // convert return value to Cell array |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2685 Array<octave_idx_type> ra_idx (dim_vector (1,2)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2686 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2687 // (err & 1) means "error, and no columns read this row |
21578
683a1beee538
maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
2688 // FIXME: This may redundant now that done_after=0 says the same |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2689 if (err & 1) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2690 done_after = out.size () + 1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2691 |
21532
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21517
diff
changeset
|
2692 int valid_rows = (row == ntimes) ? ntimes |
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21517
diff
changeset
|
2693 : (((err & 1) && (err & 8)) ? row : row+1); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2694 dim_vector dv (valid_rows, 1); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2695 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2696 ra_idx(0) = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2697 int i = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2698 if (! collect_output) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2699 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2700 retval = Cell (dim_vector (1, out.size ())); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2701 for (std::list<octave_value>::iterator col = out.begin (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2702 col != out.end (); col++, i++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2703 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2704 // trim last columns if that was requested |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2705 if (i == done_after && uneven_columns) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2706 dv = dim_vector (std::max (valid_rows - 1, 0), 1); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2707 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2708 ra_idx(1) = i; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2709 retval = do_cat_op (retval, octave_value (Cell (col->resize (dv,0))), |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2710 ra_idx); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2711 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2712 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2713 else // group adjacent cells of the same type into a single cell |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2714 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2715 octave_value cur; // current cell, accumulating columns |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2716 octave_idx_type group_size = 0; // columns in this cell |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2717 int prev_type = -1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2718 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2719 conv = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2720 retval = Cell (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2721 for (std::list<octave_value>::iterator col = out.begin (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2722 col != out.end (); col++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2723 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2724 if (! merge_with_prev [conv++]) // including first time |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2725 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2726 if (prev_type != -1) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2727 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2728 ra_idx(1) = i++; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2729 retval = do_cat_op (retval, octave_value (Cell (cur)), |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2730 ra_idx); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2731 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2732 cur = octave_value (col->resize (dv,0)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2733 group_size = 1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2734 prev_type = col->type_id (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2735 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2736 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2737 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2738 ra_idx(1) = group_size++; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2739 cur = do_cat_op (cur, octave_value (col->resize (dv,0)), |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2740 ra_idx); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2741 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2742 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2743 ra_idx(1) = i; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2744 retval = do_cat_op (retval, octave_value (Cell (cur)), ra_idx); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2745 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2746 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2747 return retval; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2748 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2749 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2750 // Calculate x^n. Used for ...e+nn so that, for example, 1e2 is |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2751 // exactly 100 and 5e-1 is 1/2 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2752 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2753 static double |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2754 pown (double x, unsigned int n) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2755 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2756 double retval = 1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2757 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2758 for (unsigned int d = n; d; d >>= 1) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2759 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2760 if (d & 1) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2761 retval *= x; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2762 x *= x; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2763 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2764 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2765 return retval; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2766 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2767 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2768 // Read a double considering the "precision" field of FMT and the |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2769 // EXP_CHARS option of OPTIONS. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2770 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2771 double |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2772 textscan::read_double (delimited_stream& is, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2773 const textscan_format_elt& fmt) const |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2774 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2775 int sign = 1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2776 unsigned int width_left = fmt.width; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2777 double retval = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2778 bool valid = false; // syntactically correct double? |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2779 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2780 int ch = is.peek (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2781 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2782 if (ch == '+') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2783 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2784 is.get (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2785 ch = is.peek (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2786 if (width_left) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2787 width_left--; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2788 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2789 else if (ch == '-') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2790 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2791 sign = -1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2792 is.get (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2793 ch = is.peek (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2794 if (width_left) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2795 width_left--; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2796 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2797 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2798 // Read integer part |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2799 if (ch != '.') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2800 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2801 if (ch >= '0' && ch <= '9') // valid if at least one digit |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2802 valid = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2803 while (width_left-- && is && (ch = is.get ()) >= '0' && ch <= '9') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2804 retval = retval * 10 + (ch - '0'); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2805 width_left++; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2806 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2807 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2808 // Read fractional part, up to specified precision |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2809 if (ch == '.' && width_left) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2810 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2811 double multiplier = 1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2812 int precision = fmt.prec; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2813 int i; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2814 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2815 if (width_left) |
21578
683a1beee538
maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
2816 width_left--; // Consider width of '.' |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2817 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2818 if (precision == -1) |
21578
683a1beee538
maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
2819 precision = 1<<30; // FIXME: Should be MAXINT |
683a1beee538
maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
2820 |
683a1beee538
maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
2821 if (! valid) // if there was nothing before '.'... |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2822 is.get (); // ...ch was a "peek", not "get". |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2823 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2824 for (i = 0; i < precision; i++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2825 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2826 if (width_left-- && is && (ch = is.get ()) >= '0' && ch <= '9') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2827 retval += (ch - '0') * (multiplier *= 0.1); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2828 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2829 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2830 width_left++; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2831 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2832 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2833 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2834 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2835 // round up if we truncated and the next digit is >= 5 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2836 if ((i == precision || ! width_left) && (ch = is.get ()) >= '5' |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2837 && ch <= '9') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2838 retval += multiplier; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2839 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2840 if (i > 0) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2841 valid = true; // valid if at least one digit after '.' |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2842 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2843 // skip remainder after '.', to field width, to look for exponent |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2844 if (i == precision) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2845 while (width_left-- && is && (ch = is.get ()) >= '0' && ch <= '9') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2846 ; // discard |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2847 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2848 width_left++; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2849 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2850 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2851 // look for exponent part in, e.g., 6.023E+23 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2852 bool used_exp = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2853 if (valid && width_left > 1 && exp_chars.find (ch) != std::string::npos) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2854 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2855 int ch1 = is.peek (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2856 if (ch1 == '-' || ch1 == '+' || (ch1 >= '0' && ch1 <= '9')) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2857 { // if 1.0e+$ or some such, this will set failbit, as we want |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2858 width_left--; // count "E" |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2859 int exp = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2860 int exp_sign = 1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2861 if (ch1 == '+') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2862 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2863 if (width_left) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2864 width_left--; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2865 is.get (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2866 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2867 else if (ch1 == '-') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2868 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2869 exp_sign = -1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2870 is.get (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2871 if (width_left) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2872 width_left--; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2873 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2874 valid = false; |
21566
02826fb0f261
textscan: Fix bug in exponent parsing
Mike Miller <mtmiller@octave.org>
parents:
21562
diff
changeset
|
2875 while (width_left-- && is && (ch = is.get ()) >= '0' && ch <= '9') |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2876 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2877 exp = exp*10 + ch - '0'; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2878 valid = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2879 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2880 width_left++; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2881 if (ch != std::istream::traits_type::eof () && width_left) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2882 is.putback (ch); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2883 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2884 double multiplier = pown (10, exp); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2885 if (exp_sign > 0) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2886 retval *= multiplier; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2887 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2888 retval /= multiplier; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2889 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2890 used_exp = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2891 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2892 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2893 is.clear (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2894 if (! used_exp && ch != std::istream::traits_type::eof () && width_left) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2895 is.putback (ch); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2896 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2897 // Check for +/- inf and NaN |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2898 if (! valid && width_left >= 3) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2899 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2900 int i = lookahead (is, inf_nan, 3, false); // false -> case insensitive |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2901 if (i == 0) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2902 { |
21723
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
2903 retval = octave::numeric_limits<double>::Inf (); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2904 valid = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2905 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2906 else if (i == 1) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2907 { |
21723
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
2908 retval = octave::numeric_limits<double>::NaN (); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2909 valid = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2910 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2911 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2912 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2913 // Check for +/- inf and NaN |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2914 if (! valid && width_left >= 3) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2915 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2916 int i = lookahead (is, inf_nan, 3, false); // false -> case insensitive |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2917 if (i == 0) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2918 { |
21723
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
2919 retval = octave::numeric_limits<double>::Inf (); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2920 valid = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2921 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2922 else if (i == 1) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2923 { |
21723
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
2924 retval = octave::numeric_limits<double>::NaN (); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2925 valid = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2926 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2927 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2928 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2929 if (! valid) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2930 is.setstate (std::ios::failbit); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2931 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2932 is.setstate (is.rdstate () & ~std::ios::failbit); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2933 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2934 return retval * sign; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2935 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2936 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2937 // Read a single number: real, complex, inf, NaN, possibly with limited |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2938 // precision. Calls to this should be preceded by skip_whitespace. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2939 // Calling that inside scan_complex would violate its const declaration. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2940 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2941 void |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2942 textscan::scan_complex (delimited_stream& is, const textscan_format_elt& fmt, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2943 Complex& val) const |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2944 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2945 double im = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2946 double re = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2947 bool as_empty = false; // did we fail but match a "treat_as_empty" string? |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2948 bool inf = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2949 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2950 int ch = is.peek (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2951 if (ch == '+' || ch == '-') // check for [+-][ij] with no coefficients |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2952 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2953 ch = is.get (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2954 int ch2 = is.peek (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2955 if (ch2 == 'i' || ch2 == 'j') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2956 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2957 double value = 1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2958 is.get (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2959 // Check not -inf |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2960 if (is.peek () == 'n') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2961 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2962 char *pos = is.tellg (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2963 std::ios::iostate state = is.rdstate (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2964 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2965 is.get (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2966 ch2 = is.get (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2967 if (ch2 == 'f') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2968 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2969 inf = true; |
21723
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
2970 re = (ch == '+') ? octave::numeric_limits<double>::Inf () : -octave::numeric_limits<double>::Inf (); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2971 value = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2972 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2973 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2974 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2975 is.clear (state); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2976 is.seekg (pos); // reset to position before look-ahead |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2977 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2978 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2979 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2980 im = (ch == '+') ? value : -value; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2981 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2982 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2983 is.putback (ch); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2984 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2985 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2986 if (! im && ! inf) // if not [+-][ij] or [+-]inf, read real normally |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2987 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2988 char *pos = is.tellg (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2989 std::ios::iostate state = is.rdstate (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2990 //re = octave_read_value<double> (is); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2991 re = read_double (is, fmt); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2992 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2993 // check for "treat as empty" string |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2994 if (treat_as_empty.numel () |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21777
diff
changeset
|
2995 && (is.fail () || octave::math::is_NaN_or_NA (Complex (re)) |
21723
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
2996 || re == octave::numeric_limits<double>::Inf ())) |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2997 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2998 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
2999 for (int i = 0; i < treat_as_empty.numel (); i++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3000 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3001 if (ch == treat_as_empty (i).string_value ()[0]) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3002 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3003 as_empty = true; // first char matches, so read the lot |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3004 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3005 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3006 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3007 if (as_empty) // if first char matched... |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3008 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3009 as_empty = false; // ...look for the whole string |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3010 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3011 is.clear (state); // treat_as_empty "-" causes partial read |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3012 is.seekg (pos); // reset to position before failed read |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3013 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3014 // treat_as_empty strings may be different sizes. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3015 // Read ahead longest, put it all back, then re-read the string |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3016 // that matches. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3017 std::string look_buf (treat_as_empty_len, '\0'); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3018 char *look = is.read (&look_buf[0], look_buf.size (), pos); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3019 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3020 is.clear (state); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3021 is.seekg (pos); // reset to position before look-ahead |
21578
683a1beee538
maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
3022 // FIXME: is.read could invalidate pos |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3023 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3024 for (int i = 0; i < treat_as_empty.numel (); i++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3025 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3026 std::string s = treat_as_empty (i).string_value (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3027 if (! strncmp (s.c_str (), look, s.size ())) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3028 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3029 as_empty = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3030 // read just the right amount |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3031 is.read (&look_buf[0], s.size (), pos); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3032 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3033 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3034 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3035 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3036 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3037 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3038 if (! is.eof () && ! as_empty) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3039 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3040 state = is.rdstate (); // before tellg, since that fails at EOF |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3041 pos = is.tellg (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3042 ch = is.peek (); // ch == EOF if read failed; no need to chk fail |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3043 if (ch == 'i' || ch == 'j') // pure imaginary |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3044 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3045 is.get (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3046 im = re; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3047 re = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3048 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3049 else if (ch == '+' || ch == '-') // see if it is real+imag[ij] |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3050 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3051 // save stream state in case we have to restore it |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3052 pos = is.tellg (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3053 state = is.rdstate (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3054 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3055 //im = octave_read_value<double> (is); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3056 im = read_double (is, fmt); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3057 if (is.fail ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3058 im = 1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3059 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3060 if (is.peek () == 'i' || is.peek () == 'j') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3061 is.get (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3062 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3063 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3064 im = 0; // no valid imaginary part. Restore state |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3065 is.clear (state); // eof shouldn't cause fail. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3066 is.seekg (pos); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3067 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3068 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3069 else if (is.eof ()) // we've read enough to be a "valid" read |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3070 is.clear (state); // failed peek shouldn't cause fail |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3071 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3072 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3073 if (as_empty) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3074 val = empty_value.scalar_value (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3075 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3076 val = Complex (re, im); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3077 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3078 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3079 // Return in VAL the run of characters from IS NOT contained in PATTERN. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3080 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3081 int |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3082 textscan::scan_caret (delimited_stream& is, const std::string& pattern, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3083 std::string& val) const |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3084 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3085 int c1 = std::istream::traits_type::eof (); |
21567
3d25f9f4a62b
maint: Eliminate Britishicisms in the code.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
3086 std::ostringstream obuf; // Is this optimized for growing? |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3087 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3088 while (is && ((c1 = (is && ! is.eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3089 ? is.get_undelim () |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3090 : std::istream::traits_type::eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3091 != std::istream::traits_type::eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3092 && pattern.find (c1) == std::string::npos) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3093 obuf << static_cast<char> (c1); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3094 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3095 val = obuf.str (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3096 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3097 if (c1 != std::istream::traits_type::eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3098 is.putback (c1); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3099 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3100 return c1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3101 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3102 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3103 // Read until one of the strings in DELIMITERS is found. For |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3104 // efficiency, ENDS is a list of the last character of each delimiter. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3105 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3106 std::string |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3107 textscan::read_until (delimited_stream& is, const Cell& delimiters, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3108 const std::string& ends) const |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3109 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3110 std::string retval (""); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3111 bool done = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3112 do |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3113 { // find sequence ending with an ending char |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3114 std::string next; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3115 scan_caret (is, ends.c_str (), next); |
21578
683a1beee538
maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
3116 retval = retval + next; // FIXME: could use repeated doubling of size |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3117 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3118 int last = (! is.eof () |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3119 ? is.get_undelim () : std::istream::traits_type::eof ()); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3120 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3121 if (last != std::istream::traits_type::eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3122 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3123 retval = retval + static_cast<char> (last); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3124 for (int i = 0; i < delimiters.numel (); i++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3125 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3126 std::string delim = delimiters(i).string_value (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3127 size_t start = (retval.length () > delim.length () |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3128 ? retval.length () - delim.length () |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3129 : 0); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3130 std::string may_match = retval.substr (start); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3131 if (may_match == delim) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3132 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3133 done = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3134 retval = retval.substr (0, start); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3135 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3136 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3137 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3138 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3139 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3140 while (! done && is && ! is.eof ()); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3141 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3142 return retval; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3143 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3144 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3145 // Read stream until either fmt.width chars have been read, or |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3146 // options.delimiter has been found. Does *not* rely on fmt being 's'. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3147 // Used by formats like %6f to limit to 6. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3148 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3149 void |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3150 textscan::scan_string (delimited_stream& is, const textscan_format_elt& fmt, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3151 std::string& val) const |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3152 { |
21885
0806871e3e1e
maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents:
21782
diff
changeset
|
3153 if (delim_list.is_empty ()) |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3154 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3155 unsigned int i = 0; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3156 unsigned int width = fmt.width; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3157 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3158 for (i = 0; i < width; i++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3159 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3160 if (i+1 > val.length ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3161 val = val + val + ' '; // grow even if empty |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3162 int ch = is.get (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3163 if (is_delim (ch) || ch == std::istream::traits_type::eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3164 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3165 is.putback (ch); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3166 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3167 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3168 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3169 val[i] = ch; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3170 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3171 val = val.substr (0, i); // trim pre-allocation |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3172 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3173 else // Cell array of multi-character delimiters |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3174 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3175 std::string ends (""); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3176 for (int i = 0; i < delim_list.numel (); i++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3177 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3178 std::string tmp = delim_list(i).string_value (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3179 ends += tmp.substr (tmp.length () - 1); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3180 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3181 val = textscan::read_until (is, delim_list, ends); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3182 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3183 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3184 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3185 // Return in VAL the run of characters from IS contained in PATTERN. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3186 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3187 int |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3188 textscan::scan_bracket (delimited_stream& is, const std::string& pattern, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3189 std::string& val) const |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3190 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3191 int c1 = std::istream::traits_type::eof (); |
21567
3d25f9f4a62b
maint: Eliminate Britishicisms in the code.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
3192 std::ostringstream obuf; // Is this optimized for growing? |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3193 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3194 while (is && pattern.find (c1 = is.get_undelim ()) != std::string::npos) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3195 obuf << static_cast<char> (c1); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3196 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3197 val = obuf.str (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3198 if (c1 != std::istream::traits_type::eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3199 is.putback (c1); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3200 return c1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3201 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3202 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3203 // Return in VAL a string, either delimited by whitespace/delimiters, or |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3204 // enclosed in a pair of double quotes ("..."). Enclosing quotes are |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3205 // removed. A consecutive pair "" is inserted into VAL as a single ". |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3206 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3207 void |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3208 textscan::scan_qstring (delimited_stream& is, const textscan_format_elt& fmt, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3209 std::string& val) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3210 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3211 skip_whitespace (is); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3212 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3213 if (is.peek () != '\"') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3214 scan_string (is, fmt, val); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3215 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3216 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3217 is.get (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3218 scan_caret (is, "\"", val); // read everything until " |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3219 is.get (); // swallow " |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3220 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3221 while (is && is.peek () == '\"') // if double ", insert one in stream, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3222 { // and keep looking for single " |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3223 is.get (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3224 std::string val1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3225 scan_caret (is, "\"", val1); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3226 val = val + "\"" + val1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3227 is.get_undelim (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3228 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3229 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3230 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3231 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3232 // Read from IS into VAL a string of the next fmt.width characters, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3233 // including any whitespace or delimiters. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3234 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3235 void |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3236 textscan::scan_cstring (delimited_stream& is, const textscan_format_elt& fmt, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3237 std::string& val) const |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3238 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3239 val.resize (fmt.width); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3240 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3241 for (unsigned int i = 0; is && i < fmt.width; i++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3242 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3243 int ch = is.get_undelim (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3244 if (ch != std::istream::traits_type::eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3245 val[i] = ch; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3246 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3247 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3248 val.resize (i); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3249 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3250 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3251 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3252 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3253 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3254 // Read a single '%...' conversion and place it in position ROW of OV. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3255 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3256 void |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3257 textscan::scan_one (delimited_stream& is, const textscan_format_elt& fmt, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3258 octave_value& ov, Array<octave_idx_type> row) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3259 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3260 skip_whitespace (is); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3261 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3262 is.clear (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3263 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3264 octave_value val; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3265 if (fmt.numeric) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3266 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3267 if (fmt.type == 'f' || fmt.type == 'n') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3268 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3269 Complex v; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3270 skip_whitespace (is); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3271 scan_complex (is, fmt, v); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3272 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3273 if (! fmt.discard && ! is.fail ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3274 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3275 if (fmt.bitwidth == 64) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3276 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3277 if (ov.is_real_type () && v.imag () == 0) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3278 ov.internal_rep ()->fast_elem_insert (row(0), v.real ()); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3279 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3280 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3281 if (ov.is_real_type ()) // cat does type conversion |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3282 ov = do_cat_op (ov, octave_value (v), row); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3283 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3284 ov.internal_rep ()->fast_elem_insert (row(0), v); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3285 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3286 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3287 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3288 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3289 if (ov.is_real_type () && v.imag () == 0) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3290 ov.internal_rep ()->fast_elem_insert (row(0), |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3291 float (v.real ())); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3292 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3293 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3294 if (ov.is_real_type ()) // cat does type conversion |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3295 ov = do_cat_op (ov, octave_value (v), row); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3296 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3297 ov.internal_rep ()->fast_elem_insert (row(0), |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3298 FloatComplex (v)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3299 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3300 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3301 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3302 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3303 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3304 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3305 double v; // Matlab docs say 1e30 etc should be valid for %d and |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3306 // 1000 as a %d8 should be 127, so read as double. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3307 // Some loss of precision for d64 and u64. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3308 skip_whitespace (is); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3309 v = read_double (is, fmt); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3310 if (! fmt.discard && ! is.fail ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3311 switch (fmt.bitwidth) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3312 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3313 case 64: |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3314 switch (fmt.type) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3315 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3316 case 'd': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3317 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3318 octave_int64 vv = v; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3319 ov.internal_rep ()->fast_elem_insert (row(0), vv); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3320 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3321 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3322 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3323 case 'u': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3324 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3325 octave_uint64 vv = v; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3326 ov.internal_rep ()->fast_elem_insert (row(0), vv); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3327 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3328 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3329 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3330 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3331 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3332 case 32: |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3333 switch (fmt.type) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3334 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3335 case 'd': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3336 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3337 octave_int32 vv = v; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3338 ov.internal_rep ()->fast_elem_insert (row(0), vv); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3339 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3340 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3341 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3342 case 'u': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3343 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3344 octave_uint32 vv = v; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3345 ov.internal_rep ()->fast_elem_insert (row(0), vv); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3346 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3347 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3348 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3349 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3350 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3351 case 16: |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3352 if (fmt.type == 'd') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3353 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3354 octave_int16 vv = v; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3355 ov.internal_rep ()->fast_elem_insert (row(0), vv); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3356 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3357 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3358 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3359 octave_uint16 vv = v; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3360 ov.internal_rep ()->fast_elem_insert (row(0), vv); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3361 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3362 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3363 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3364 case 8: |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3365 if (fmt.type == 'd') |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3366 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3367 octave_int8 vv = v; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3368 ov.internal_rep ()->fast_elem_insert (row(0), vv); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3369 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3370 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3371 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3372 octave_uint8 vv = v; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3373 ov.internal_rep ()->fast_elem_insert (row(0), vv); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3374 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3375 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3376 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3377 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3378 |
21622
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
3379 if (is.fail () & ! fmt.discard) |
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
3380 ov = do_cat_op (ov, empty_value, row); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3381 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3382 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3383 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3384 std::string vv (" "); // initial buffer. Grows as needed |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3385 switch (fmt.type) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3386 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3387 case 's': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3388 scan_string (is, fmt, vv); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3389 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3390 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3391 case 'q': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3392 scan_qstring (is, fmt, vv); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3393 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3394 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3395 case 'c': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3396 scan_cstring (is, fmt, vv); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3397 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3398 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3399 case '[': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3400 scan_bracket (is, fmt.char_class.c_str (), vv); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3401 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3402 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3403 case '^': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3404 scan_caret (is, fmt.char_class.c_str (), vv); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3405 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3406 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3407 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3408 if (! fmt.discard) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3409 ov.internal_rep ()->fast_elem_insert (row (0), |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3410 Cell (octave_value (vv))); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3411 |
21578
683a1beee538
maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
3412 // FIXME: why does failbit get set at EOF, instead of eofbit? |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3413 if (! vv.empty ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3414 is.clear (is.rdstate () & ~std::ios_base::failbit); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3415 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3416 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3417 is.field_done (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3418 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3419 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3420 // Read data corresponding to the entire format string once, placing the |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3421 // values in row ROW of retval. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3422 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3423 int |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3424 textscan::read_format_once (delimited_stream& is, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3425 textscan_format_list& fmt_list, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3426 std::list<octave_value>& retval, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3427 Array<octave_idx_type> row, int& done_after) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3428 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3429 const textscan_format_elt *elem = fmt_list.first (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3430 std::list<octave_value>::iterator out = retval.begin (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3431 bool no_conversions = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3432 bool done = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3433 bool conversion_failed = false; // Record for ReturnOnError |
21532
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21517
diff
changeset
|
3434 bool nothing_worked = true; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3435 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3436 octave_quit (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3437 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3438 for (size_t i = 0; i < fmt_list.numel (); i++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3439 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3440 bool this_conversion_failed = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3441 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3442 // Clear fail of previous numeric conversions. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3443 is.clear (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3444 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3445 switch (elem->type) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3446 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3447 case 'C': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3448 case 'D': |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
3449 warning ("%s: conversion %c not yet implemented", |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
3450 who.c_str (), elem->type); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3451 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3452 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3453 case 'u': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3454 case 'd': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3455 case 'f': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3456 case 'n': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3457 case 's': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3458 case '[': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3459 case '^': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3460 case 'q': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3461 case 'c': |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3462 scan_one (is, *elem, *out, row); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3463 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3464 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3465 case textscan_format_elt::literal_conversion : |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3466 match_literal (is, *elem); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3467 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3468 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3469 default: |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3470 error ("Unknown format element '%c'", elem->type); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3471 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3472 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3473 if (! is.fail ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3474 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3475 if (! elem->discard) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3476 no_conversions = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3477 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3478 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3479 { |
21622
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
3480 is.clear (is.rdstate () & ~std::ios::failbit); |
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
3481 |
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
3482 if (!is.eof () && ~is_delim (is.peek ())) |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3483 this_conversion_failed = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3484 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3485 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3486 if (! elem->discard) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3487 out++; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3488 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3489 elem = fmt_list.next (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3490 char *pos = is.tellg (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3491 |
21578
683a1beee538
maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
3492 // FIXME: these conversions "ignore delimiters". Should they include |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3493 // delimiters at the start of the conversion, or can those be skipped? |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3494 if (elem->type != textscan_format_elt::literal_conversion |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3495 // && elem->type != '[' && elem->type != '^' && elem->type != 'c' |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3496 ) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3497 skip_delim (is); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3498 |
21532
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21517
diff
changeset
|
3499 if (is.eof ()) |
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21517
diff
changeset
|
3500 { |
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21517
diff
changeset
|
3501 if (! done) |
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21517
diff
changeset
|
3502 done_after = i+1; |
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21517
diff
changeset
|
3503 |
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21517
diff
changeset
|
3504 // note EOF, but process others to get empty_val. |
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21517
diff
changeset
|
3505 done = true; |
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21517
diff
changeset
|
3506 } |
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21517
diff
changeset
|
3507 |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3508 if (this_conversion_failed) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3509 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3510 if (is.tellg () == pos && ! conversion_failed) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3511 { // done_after = first failure |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3512 done_after = i; // note fail, but parse others to get empty_val |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3513 conversion_failed = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3514 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3515 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3516 this_conversion_failed = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3517 } |
21532
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21517
diff
changeset
|
3518 else if (! done && !conversion_failed) |
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21517
diff
changeset
|
3519 nothing_worked = false; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3520 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3521 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3522 if (done) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3523 is.setstate (std::ios::eofbit); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3524 |
21532
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21517
diff
changeset
|
3525 return no_conversions + (is.eof () ? 2 : 0) |
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21517
diff
changeset
|
3526 + (conversion_failed ? 4 : 0) |
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21517
diff
changeset
|
3527 + (nothing_worked ? 8 : 0); |
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21517
diff
changeset
|
3528 |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3529 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3530 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3531 void |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3532 textscan::parse_options (const octave_value_list& args, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3533 textscan_format_list& fmt_list) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3534 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3535 int last = args.length (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3536 int n = last; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3537 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3538 if (n & 1) |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
3539 error ("%s: %d parameters given, but only %d values", |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
3540 who.c_str (), n-n/2, n/2); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3541 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3542 delim_len = 1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3543 bool have_delims = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3544 for (int i = 0; i < last; i += 2) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3545 { |
21567
3d25f9f4a62b
maint: Eliminate Britishicisms in the code.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
3546 std::string param = args(i).xstring_value ("%s: Invalid parameter type <%s> for parameter %d", |
21538
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3547 who.c_str (), |
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3548 args(i).type_name ().c_str (), |
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3549 i/2 + 1); |
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3550 std::transform (param.begin (), param.end (), param.begin (), ::tolower); |
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3551 |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3552 if (param == "delimiter") |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3553 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3554 bool invalid = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3555 if (args(i+1).is_string ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3556 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3557 invalid = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3558 have_delims = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3559 delims = args(i+1).string_value (); |
21551
990c6c31a684
Accept escape sequences in single quoted strings for "delimiter" (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21538
diff
changeset
|
3560 if (args(i+1).is_sq_string ()) |
990c6c31a684
Accept escape sequences in single quoted strings for "delimiter" (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21538
diff
changeset
|
3561 delims = do_string_escapes (delims); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3562 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3563 else if (args(i+1).is_cell ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3564 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3565 invalid = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3566 delim_list = args(i+1).cell_value (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3567 delim_table = " "; // non-empty, to flag non-default delim |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3568 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3569 // Check that all elements are strings, and find max length |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3570 for (int j = 0; j < delim_list.numel (); j++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3571 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3572 if (! delim_list(j).is_string ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3573 invalid = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3574 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3575 { |
21551
990c6c31a684
Accept escape sequences in single quoted strings for "delimiter" (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21538
diff
changeset
|
3576 if (delim_list(j).is_sq_string ()) |
990c6c31a684
Accept escape sequences in single quoted strings for "delimiter" (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21538
diff
changeset
|
3577 delim_list(j) = do_string_escapes (delim_list(j) |
990c6c31a684
Accept escape sequences in single quoted strings for "delimiter" (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21538
diff
changeset
|
3578 .string_value ()); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3579 octave_idx_type len = delim_list(j).string_value () |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3580 .length (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3581 delim_len = std::max (static_cast<int> (len), delim_len); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3582 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3583 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3584 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3585 if (invalid) |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
3586 error ("%s: Delimiters must be either a string or cell array of strings", |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
3587 who.c_str ()); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3588 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3589 else if (param == "commentstyle") |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3590 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3591 if (args(i+1).is_string ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3592 { // check here for names like "C++", "C", "shell", ...? |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3593 comment_style = Cell (args(i+1)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3594 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3595 else if (args(i+1).is_cell ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3596 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3597 comment_style = args(i+1).cell_value (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3598 int len = comment_style.numel (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3599 if ((len >= 1 && ! comment_style (0).is_string ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3600 || (len >= 2 && ! comment_style (1).is_string ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3601 || (len >= 3)) |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
3602 error ("%s: CommentStyle must be either a string or cell array of one or two strings", |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
3603 who.c_str ()); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3604 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3605 else |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
3606 error ("%s: CommentStyle must be either a string or cell array of one or two strings", |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
3607 who.c_str ()); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3608 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3609 // How far ahead do we need to look to detect an open comment |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3610 // and which character do we look for? |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3611 if (comment_style.numel () >= 1) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3612 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3613 comment_len = comment_style (0).string_value ().size (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3614 comment_char = comment_style (0).string_value ()[0]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3615 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3616 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3617 else if (param == "treatasempty") |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3618 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3619 bool invalid = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3620 if (args(i+1).is_string ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3621 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3622 treat_as_empty = Cell (args(i+1)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3623 treat_as_empty_len = args(i+1).string_value ().size (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3624 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3625 else if (args(i+1).is_cell ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3626 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3627 treat_as_empty = args(i+1).cell_value (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3628 for (int j = 0; j < treat_as_empty.numel (); j++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3629 if (! treat_as_empty (j).is_string ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3630 invalid = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3631 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3632 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3633 int k = treat_as_empty (j).string_value ().size (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3634 if (k > treat_as_empty_len) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3635 treat_as_empty_len = k; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3636 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3637 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3638 if (invalid) |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
3639 error ("%s: TreatAsEmpty must be either a string or cell array of one or two strings", |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
3640 who.c_str ()); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3641 |
21578
683a1beee538
maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
3642 // FIXME: Ensure none is a prefix of a later one. Sort by length? |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3643 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3644 else if (param == "collectoutput") |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3645 { |
21538
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3646 collect_output = args(i+1).xbool_value ("%s: CollectOutput must be logical or numeric", who.c_str ()); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3647 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3648 else if (param == "emptyvalue") |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3649 { |
21538
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3650 empty_value = args(i+1).xscalar_value ("%s: EmptyValue must be numeric", who.c_str ()); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3651 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3652 else if (param == "headerlines") |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3653 { |
21538
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3654 header_lines = args(i+1).xscalar_value ("%s: HeaderLines must be numeric", who.c_str ()); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3655 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3656 else if (param == "bufsize") |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3657 { |
21538
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3658 buffer_size = args(i+1).xscalar_value ("%s: BufSize must be numeric", who.c_str ()); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3659 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3660 else if (param == "multipledelimsasone") |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3661 { |
21538
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3662 multiple_delims_as_one = args(i+1).xbool_value ("%s: MultipleDelimsAsOne must be logical or numeric", who.c_str ()); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3663 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3664 else if (param == "returnonerror") |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3665 { |
21622
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
3666 return_on_error = args(i+1).xbool_value ("%s: ReturnOnError must be logical or numeric", who.c_str ()); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3667 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3668 else if (param == "whitespace") |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3669 { |
21538
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3670 whitespace = args(i+1).xstring_value ("%s: Whitespace must be a character string", who.c_str ()); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3671 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3672 else if (param == "expchars") |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3673 { |
21538
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3674 exp_chars = args(i+1).xstring_value ("%s: ExpChars must be a character string", who.c_str ()); |
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3675 default_exp = false; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3676 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3677 else if (param == "endofline") |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3678 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3679 bool valid = true; |
21538
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3680 std::string s = args(i+1).xstring_value ("%s: EndOfLine must be at most one character or '\\r\\n'", who.c_str ()); |
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3681 if (args(i+1).is_sq_string ()) |
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3682 s = do_string_escapes (s); |
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3683 int l = s.length (); |
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3684 if (l == 0) |
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3685 eol1 = eol2 = -2; |
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3686 else if (l == 1) |
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3687 eol1 = eol2 = s.c_str ()[0]; |
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3688 else if (l == 2) |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3689 { |
21538
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3690 eol1 = s.c_str ()[0]; |
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3691 eol2 = s.c_str ()[1]; |
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3692 if (eol1 != '\r' || eol2 != '\n') // Why limit it? |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3693 valid = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3694 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3695 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3696 valid = false; |
21538
eb15bc7c5c0b
textscan: Use error-checking value extractors for simpler parameter parsing
Mike Miller <mtmiller@octave.org>
parents:
21532
diff
changeset
|
3697 |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3698 if (! valid) |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
3699 error ("%s: EndOfLine must be at most one character or '\\r\\n'", |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
3700 who.c_str ()); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3701 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3702 else |
21567
3d25f9f4a62b
maint: Eliminate Britishicisms in the code.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
3703 error ("%s: unrecognized option '%s'", who.c_str (), param.c_str ()); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3704 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3705 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3706 whitespace_table = std::string (256, '\0'); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3707 for (unsigned int i = 0; i < whitespace.length (); i++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3708 whitespace_table[whitespace[i]] = '1'; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3709 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3710 // For Matlab compatibility, add 0x20 to whitespace, unless |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3711 // whitespace is explicitly ignored. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3712 if (! (whitespace.empty () && fmt_list.has_string)) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3713 whitespace_table[' '] = '1'; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3714 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3715 // Create look-up table of delimiters, based on 'delimiter' |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3716 delim_table = std::string (256, '\0'); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3717 if (eol1 >= 0 && eol1 < 256) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3718 delim_table[eol1] = '1'; // EOL is always a delimiter |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3719 if (eol2 >= 0 && eol2 < 256) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3720 delim_table[eol2] = '1'; // EOL is always a delimiter |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3721 if (! have_delims) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3722 for (unsigned int i = 0; i < 256; i++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3723 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3724 if (isspace (i)) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3725 delim_table[i] = '1'; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3726 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3727 else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3728 for (unsigned int i = 0; i < delims.length (); i++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3729 delim_table[delims[i]] = '1'; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3730 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3731 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3732 // Skip comments, and characters specified by the "Whitespace" option. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3733 // If EOLstop == true, don't skip end of line. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3734 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3735 int |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3736 textscan::skip_whitespace (delimited_stream& is, bool EOLstop) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3737 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3738 int c1 = std::istream::traits_type::eof (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3739 bool found_comment = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3740 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3741 do |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3742 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3743 found_comment = false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3744 int prev = -1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3745 while (is && (c1 = is.get_undelim ()) != std::istream::traits_type::eof () |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3746 && ( ( (c1 == eol1 || c1 == eol2) && ++lines && ! EOLstop) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3747 || isspace (c1))) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3748 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3749 if (prev == eol1 && eol1 != eol2 && c1 == eol2) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3750 lines--; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3751 prev = c1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3752 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3753 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3754 if (c1 == comment_char) // see if we match an open comment |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3755 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3756 // save stream state in case we have to restore it |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
3757 char *pos = is.tellg (); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3758 std::ios::iostate state = is.rdstate (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3759 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3760 std::string tmp (comment_len, '\0'); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3761 char *look = is.read (&tmp[0], comment_len-1, pos); // already read first char |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3762 if (is && ! strncmp (comment_style(0).string_value ().substr (1) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3763 .c_str (), look, comment_len-1)) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3764 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3765 found_comment = true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3766 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3767 std::string dummy; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3768 if (comment_style.numel () == 1) // skip to end of line |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3769 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3770 std::string eol (3, '\0'); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3771 eol[0] = eol1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3772 eol[1] = eol2; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3773 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3774 scan_caret (is, eol, dummy); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3775 c1 = is.get_undelim (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3776 if (c1 == eol1 && eol1 != eol2 && is.peek_undelim () == eol2) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3777 is.get_undelim (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3778 lines++; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3779 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3780 else // matching pair |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3781 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3782 std::string end_c = comment_style(1).string_value (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3783 // last char of end-comment sequence |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3784 std::string last = end_c.substr (end_c.size () - 1); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3785 std::string may_match (""); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3786 do |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3787 { // find sequence ending with last char |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3788 scan_caret (is, last, dummy); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3789 is.get_undelim (); // (read LAST itself) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3790 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3791 may_match = may_match + dummy + last; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3792 if (may_match.length () > end_c.length ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3793 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3794 size_t start = may_match.length () - end_c.length (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3795 may_match = may_match.substr (start); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3796 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3797 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3798 while (may_match != end_c && is && ! is.eof ()); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3799 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3800 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3801 else // wasn't really a comment; restore state |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3802 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3803 is.clear (state); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3804 is.seekg (pos); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3805 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3806 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3807 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3808 while (found_comment); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3809 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3810 if (c1 != std::istream::traits_type::eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3811 is.putback (c1); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3812 return c1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3813 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3814 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3815 // See if the next few characters match one of the strings in target. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3816 // For efficiency, MAX_LEN is the cached longest length of any target. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3817 // Return -1 if none is found, or the index of the match. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3818 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3819 int |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3820 textscan::lookahead (delimited_stream& is, const Cell& targets, int max_len, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3821 bool case_sensitive) const |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3822 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3823 // target strings may be different sizes. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3824 // Read ahead longest, put it all back, then re-read the string |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3825 // that matches. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3826 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3827 char *pos = is.tellg (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3828 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3829 std::string tmp (max_len, '\0'); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3830 char *look = is.read (&tmp[0], tmp.size (), pos); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3831 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3832 is.clear (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3833 is.seekg (pos); // reset to position before look-ahead |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21552
diff
changeset
|
3834 // FIXME: pos may be corrupted by is.read |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3835 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3836 int i; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3837 int (*compare)(const char *, const char *, size_t); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3838 compare = case_sensitive ? strncmp : strncasecmp; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3839 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3840 for (i = 0; i < targets.numel (); i++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3841 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3842 std::string s = targets (i).string_value (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3843 if (! (*compare) (s.c_str (), look, s.size ())) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3844 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3845 is.read (&tmp[0], s.size (), pos); // read just the right amount |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3846 break; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3847 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3848 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3849 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3850 if (i == targets.numel ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3851 i = -1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3852 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3853 return i; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3854 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3855 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3856 // Skip delimiters -- multiple if MultipleDelimsAsOne specified. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3857 int |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3858 textscan::skip_delim (delimited_stream& is) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3859 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3860 int c1 = skip_whitespace (is, true); // 'true': stop once EOL is read |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3861 if (delim_list.numel () == 0) // single character delimiter |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3862 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3863 if (is_delim (c1) || c1 == eol1 || c1 == eol2) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3864 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3865 is.get (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3866 if (c1 == eol1 && is.peek_undelim () == eol2) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3867 is.get_undelim (); // if \r\n, skip the \n too. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3868 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3869 if (multiple_delims_as_one) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3870 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3871 int prev = -1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3872 // skip multiple delims. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3873 // Increment lines for each end-of-line seen; for \r\n, decrement |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3874 while (is && ((c1 = is.get_undelim ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3875 != std::istream::traits_type::eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3876 && (((c1 == eol1 || c1 == eol2) && ++lines) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3877 || isspace (c1) || is_delim (c1))) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3878 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3879 if (prev == eol1 && eol1 != eol2 && c1 == eol2) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3880 lines--; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3881 prev = c1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3882 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3883 if (c1 != std::istream::traits_type::eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3884 is.putback (c1); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3885 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3886 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3887 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3888 else // multi-character delimiter |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3889 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3890 int first_match; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3891 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3892 if (c1 == eol1 || c1 == eol2 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3893 || (-1 != (first_match = lookahead (is, delim_list, delim_len)))) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3894 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3895 if (c1 == eol1) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3896 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3897 is.get_undelim (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3898 if (is.peek_undelim () == eol2) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3899 is.get_undelim (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3900 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3901 else if (c1 == eol2) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3902 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3903 is.get_undelim (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3904 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3905 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3906 if (multiple_delims_as_one) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3907 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3908 int prev = -1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3909 // skip multiple delims. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3910 // Increment lines for each end-of-line seen; for \r\n, decrement |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3911 while (is && ((c1 = skip_whitespace (is, true)) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3912 != std::istream::traits_type::eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3913 && (((c1 == eol1 || c1 == eol2) && ++lines) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3914 || -1 != lookahead (is, delim_list, delim_len))) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3915 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3916 if (prev == eol1 && eol1 != eol2 && c1 == eol2) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3917 lines--; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3918 prev = c1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3919 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3920 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3921 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3922 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3923 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3924 return c1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3925 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3926 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3927 // Read in as much of the input as coincides with the literal in the |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3928 // format string. Return "true" if the entire literal is matched, else |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3929 // false (and set failbit). |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3930 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3931 bool |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3932 textscan::match_literal (delimited_stream& is, const textscan_format_elt& fmt) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3933 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3934 // "false" -> treat EOL as normal space |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3935 // since a delimiter at the start of a line is a mismatch, not empty field |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3936 skip_whitespace (is, false); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3937 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3938 for (unsigned int i = 0; i < fmt.width; i++) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3939 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3940 int ch = is.get_undelim (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3941 if (ch != fmt.text[i]) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3942 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3943 if (ch != std::istream::traits_type::eof ()) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3944 is.putback (ch); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3945 is.setstate (std::ios::failbit); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3946 return false; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3947 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3948 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3949 return true; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3950 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
3951 |
2117 | 3952 void |
3523 | 3953 octave_base_stream::error (const std::string& msg) |
2117 | 3954 { |
3955 fail = true; | |
3956 errmsg = msg; | |
3957 } | |
3958 | |
3959 void | |
4468 | 3960 octave_base_stream::error (const std::string& who, const std::string& msg) |
3961 { | |
3962 fail = true; | |
6296 | 3963 errmsg = who + ": " + msg; |
4468 | 3964 } |
3965 | |
3966 void | |
2117 | 3967 octave_base_stream::clear (void) |
3968 { | |
4889 | 3969 fail = false; |
3970 errmsg = ""; | |
3971 } | |
3972 | |
3973 void | |
3974 octave_base_stream::clearerr (void) | |
3975 { | |
4888 | 3976 std::istream *is = input_stream (); |
3977 std::ostream *os = output_stream (); | |
3978 | |
3979 if (is) | |
3980 is->clear (); | |
3981 | |
3982 if (os) | |
3983 os->clear (); | |
2117 | 3984 } |
3985 | |
3986 // Functions that are defined for all input streams (input streams | |
3987 // are those that define is). | |
3988 | |
3536 | 3989 std::string |
5275 | 3990 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
|
3991 bool strip_newline, const std::string& who) |
2117 | 3992 { |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3993 if (octave::application::interactive () && file_number () == 0) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20768
diff
changeset
|
3994 ::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
|
3995 who.c_str ()); |
8773
9e3111d203c0
disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents:
8739
diff
changeset
|
3996 |
3523 | 3997 std::string retval; |
2117 | 3998 |
3999 err = false; | |
4000 | |
3523 | 4001 std::istream *isp = input_stream (); |
2117 | 4002 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4003 if (! isp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4004 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4005 err = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4006 invalid_operation (who, "reading"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4007 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4008 else |
2117 | 4009 { |
3523 | 4010 std::istream& is = *isp; |
2117 | 4011 |
5765 | 4012 std::ostringstream buf; |
2117 | 4013 |
4014 int c = 0; | |
3553 | 4015 int char_count = 0; |
6345 | 4016 |
4017 if (max_len != 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4018 { |
21184
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4019 while (is && (c = is.get ()) != std::istream::traits_type::eof ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4020 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4021 char_count++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4022 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4023 // Handle CRLF, CR, or LF as line ending. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4024 if (c == '\r') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4025 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4026 if (! strip_newline) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4027 buf << static_cast<char> (c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4028 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4029 c = is.get (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4030 |
21184
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4031 if (c != std::istream::traits_type::eof ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4032 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4033 if (c == '\n') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4034 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4035 char_count++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4036 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4037 if (! strip_newline) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4038 buf << static_cast<char> (c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4039 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4040 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4041 is.putback (c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4042 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4043 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4044 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4045 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4046 else if (c == '\n') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4047 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4048 if (! strip_newline) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4049 buf << static_cast<char> (c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4050 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4051 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4052 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4053 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4054 buf << static_cast<char> (c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4055 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4056 if (max_len > 0 && char_count == max_len) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4057 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4058 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4059 } |
6345 | 4060 |
4061 if (! is.eof () && char_count > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4062 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4063 // 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
|
4064 // 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
|
4065 // corresponding C-library functions do. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4066 int disgusting_compatibility_hack = is.get (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4067 if (! is.eof ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4068 is.putback (disgusting_compatibility_hack); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4069 } |
2117 | 4070 |
4224 | 4071 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
|
4072 retval = buf.str (); |
4224 | 4073 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4074 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4075 err = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4076 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4077 if (is.eof () && char_count == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4078 error (who, "at end of file"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4079 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4080 error (who, "read error"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4081 } |
2117 | 4082 } |
4083 | |
4084 return retval; | |
4085 } | |
4086 | |
3536 | 4087 std::string |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4088 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
|
4089 const std::string& who) |
2117 | 4090 { |
4468 | 4091 return do_gets (max_len, err, true, who); |
2117 | 4092 } |
4093 | |
3536 | 4094 std::string |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4095 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
|
4096 const std::string& who) |
2117 | 4097 { |
4468 | 4098 return do_gets (max_len, err, false, who); |
2117 | 4099 } |
4100 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
4101 off_t |
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
4102 octave_base_stream::skipl (off_t num, bool& err, const std::string& who) |
9701 | 4103 { |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
4104 if (octave::application::interactive () && file_number () == 0) |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4105 ::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
|
4106 who.c_str ()); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4107 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
4108 off_t cnt = -1; |
9701 | 4109 |
4110 err = false; | |
4111 | |
4112 std::istream *isp = input_stream (); | |
4113 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4114 if (! isp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4115 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4116 err = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4117 invalid_operation (who, "reading"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4118 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4119 else |
9701 | 4120 { |
4121 std::istream& is = *isp; | |
4122 | |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
4123 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
|
4124 int lastc = -1; |
9701 | 4125 cnt = 0; |
4126 | |
21184
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4127 while (is && (c = is.get ()) != std::istream::traits_type::eof ()) |
9701 | 4128 { |
4129 // Handle CRLF, CR, or LF as line ending. | |
4130 if (c == '\r' || (c == '\n' && lastc != '\r')) | |
4131 { | |
4132 if (++cnt == num) | |
4133 break; | |
4134 } | |
4135 | |
4136 lastc = c; | |
4137 } | |
4138 | |
4139 // Maybe eat the following \n if \r was just met. | |
4140 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
|
4141 is.get (); |
9701 | 4142 |
4143 if (is.bad ()) | |
4144 { | |
4145 err = true; | |
4146 error (who, "read error"); | |
4147 } | |
4148 | |
4149 if (err) | |
4150 cnt = -1; | |
4151 } | |
4152 | |
4153 return cnt; | |
4154 } | |
4155 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
4156 template <typename T> |
3636 | 4157 std::istream& |
6767 | 4158 octave_scan_1 (std::istream& is, const scanf_format_elt& fmt, T* valptr) |
3636 | 4159 { |
21687
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4160 T value = T (); |
3779 | 4161 |
4162 switch (fmt.type) | |
4163 { | |
4164 case 'o': | |
21687
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4165 is >> std::oct >> value >> std::dec; |
3779 | 4166 break; |
4167 | |
4168 case 'x': | |
21687
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4169 is >> std::hex >> value >> std::dec; |
4926 | 4170 break; |
4171 | |
4172 case 'i': | |
4173 { | |
21184
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4174 int c1 = std::istream::traits_type::eof (); |
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4175 |
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4176 while (is && (c1 = is.get ()) != std::istream::traits_type::eof () |
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4177 && isspace (c1)) |
20946 | 4178 ; // skip whitespace |
14675
757f729fd41d
skip leading whitespace for scanf %i format
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
4179 |
21184
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4180 if (c1 != std::istream::traits_type::eof ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4181 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4182 if (c1 == '0') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4183 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4184 int c2 = is.peek (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4185 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4186 if (c2 == 'x' || c2 == 'X') |
7709
fa41af732801
octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents:
7538
diff
changeset
|
4187 { |
fa41af732801
octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents:
7538
diff
changeset
|
4188 is.ignore (); |
fa41af732801
octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents:
7538
diff
changeset
|
4189 if (std::isxdigit (is.peek ())) |
21687
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4190 is >> std::hex >> value >> std::dec; |
7709
fa41af732801
octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents:
7538
diff
changeset
|
4191 else |
21687
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4192 value = 0; |
7709
fa41af732801
octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents:
7538
diff
changeset
|
4193 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4194 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4195 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4196 if (c2 == '0' || c2 == '1' || c2 == '2' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4197 || c2 == '3' || c2 == '4' || c2 == '5' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4198 || c2 == '6' || c2 == '7') |
21687
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4199 is >> std::oct >> value >> std::dec; |
21114
47908b818865
oct-stream.cc: Add FIXME note about bug #46493.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
4200 else if (c2 == '8' || c2 == '9') |
47908b818865
oct-stream.cc: Add FIXME note about bug #46493.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
4201 { |
47908b818865
oct-stream.cc: Add FIXME note about bug #46493.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
4202 // 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
|
4203 // 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
|
4204 // error ("internal failure to match octal format"); |
21687
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4205 value = 0; |
21114
47908b818865
oct-stream.cc: Add FIXME note about bug #46493.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
4206 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4207 else |
21687
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4208 value = 0; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4209 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4210 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4211 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4212 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4213 is.putback (c1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4214 |
21687
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4215 is >> value; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4216 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4217 } |
4926 | 4218 } |
3779 | 4219 break; |
4220 | |
4221 default: | |
21687
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4222 is >> value; |
3779 | 4223 break; |
4224 } | |
3639 | 4225 |
21687
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4226 // If conversion produces an integer that overflows, failbit is set but |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21739
diff
changeset
|
4227 // value is non-zero. We want to treat this case as success, so clear |
21687
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4228 // failbit from the stream state to keep going. |
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4229 // FIXME: Maybe set error state on octave stream as above? Matlab does |
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4230 // *not* indicate an error message on overflow. |
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4231 if ((is.rdstate () & std::ios::failbit) && value != T ()) |
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4232 is.clear (is.rdstate () & ~std::ios::failbit); |
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4233 |
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4234 // Only copy the converted value if the stream is in a state where we |
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4235 // want to continue reading. |
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4236 if (! (is.rdstate () & std::ios::failbit)) |
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4237 *valptr = value; |
4418e579cca6
scanf: return maximum/minimum value on integer overflow (bug #47759)
Mike Miller <mtmiller@octave.org>
parents:
21686
diff
changeset
|
4238 |
3638 | 4239 return is; |
3636 | 4240 } |
4241 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
4242 template <typename T> |
6767 | 4243 std::istream& |
4244 octave_scan (std::istream& is, const scanf_format_elt& fmt, T* valptr) | |
4245 { | |
4246 if (fmt.width) | |
4247 { | |
4248 // Limit input to fmt.width characters by reading into a | |
4249 // temporary stringstream buffer. | |
4250 std::string tmp; | |
4251 | |
4252 is.width (fmt.width); | |
4253 is >> tmp; | |
4254 | |
4255 std::istringstream ss (tmp); | |
4256 | |
4257 octave_scan_1 (ss, fmt, valptr); | |
4258 } | |
4259 else | |
4260 octave_scan_1 (is, fmt, valptr); | |
4261 | |
4262 return is; | |
4263 } | |
4264 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
4265 // Note that this specialization is only used for reading characters, not |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21739
diff
changeset
|
4266 // character strings. See BEGIN_S_CONVERSION for details. |
3779 | 4267 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
4268 template <> |
3779 | 4269 std::istream& |
4661 | 4270 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
|
4271 char* valptr) |
3779 | 4272 { |
4273 return is >> valptr; | |
4274 } | |
3636 | 4275 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
4276 template <> |
5176 | 4277 std::istream& |
5403 | 4278 octave_scan<> (std::istream& is, const scanf_format_elt& fmt, double* valptr) |
5176 | 4279 { |
4280 double& ref = *valptr; | |
4281 | |
4282 switch (fmt.type) | |
4283 { | |
4284 case 'e': | |
4285 case 'f': | |
4286 case 'g': | |
4287 { | |
21184
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4288 int c1 = std::istream::traits_type::eof (); |
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4289 |
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4290 while (is && (c1 = is.get ()) != std::istream::traits_type::eof () |
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4291 && isspace (c1)) |
20946 | 4292 ; // skip whitespace |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4293 |
21184
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4294 if (c1 != std::istream::traits_type::eof ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4295 { |
12936
b74cb659e757
accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
4296 is.putback (c1); |
b74cb659e757
accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
4297 |
b74cb659e757
accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
4298 ref = octave_read_value<double> (is); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4299 } |
5176 | 4300 } |
4301 break; | |
4302 | |
4303 default: | |
4304 panic_impossible (); | |
4305 break; | |
4306 } | |
4307 | |
4308 return is; | |
4309 } | |
4310 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
4311 template <typename T> |
2572 | 4312 void |
3636 | 4313 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
|
4314 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
|
4315 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
|
4316 octave_idx_type max_size, bool discard) |
2572 | 4317 { |
21147
95feb42d7a97
* oct-stream.cc (OCTAVE_SCAN): Eliminate trivial macro.
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
4318 octave_scan (is, fmt, valptr); |
2572 | 4319 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4320 if (! is) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4321 return; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4322 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4323 if (idx == max_size && ! discard) |
2572 | 4324 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4325 max_size *= 2; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4326 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4327 if (nr > 0) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4328 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
|
4329 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4330 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
|
4331 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4332 data = mval.fortran_vec (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4333 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4334 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4335 if (! discard) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4336 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4337 conversion_count++; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4338 data[idx++] = *(valptr); |
2572 | 4339 } |
4340 } | |
4341 | |
4342 template void | |
3636 | 4343 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
|
4344 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
|
4345 octave_idx_type, octave_idx_type, bool); |
2572 | 4346 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4347 #define DO_WHITESPACE_CONVERSION() \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4348 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4349 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4350 int c = std::istream::traits_type::eof (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4351 \ |
21184
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4352 while (is && (c = is.get ()) != std::istream::traits_type::eof () \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4353 && isspace (c)) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4354 { /* skip whitespace */ } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4355 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4356 if (c != std::istream::traits_type::eof ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4357 is.putback (c); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4358 } \ |
3483 | 4359 while (0) |
4360 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4361 #define DO_LITERAL_CONVERSION() \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4362 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4363 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4364 int c = std::istream::traits_type::eof (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4365 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4366 int n = strlen (fmt); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4367 int i = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4368 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4369 while (i < n && is && (c = is.get ()) != std::istream::traits_type::eof ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4370 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4371 if (c == static_cast<unsigned char> (fmt[i])) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4372 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4373 i++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4374 continue; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4375 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4376 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4377 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4378 is.putback (c); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4379 break; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4380 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4381 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4382 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4383 if (i != n) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4384 is.setstate (std::ios::failbit); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4385 } \ |
3483 | 4386 while (0) |
4387 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4388 #define DO_PCT_CONVERSION() \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4389 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4390 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4391 int c = is.get (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4392 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4393 if (c != std::istream::traits_type::eof ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4394 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4395 if (c != '%') \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4396 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4397 is.putback (c); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4398 is.setstate (std::ios::failbit); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4399 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4400 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4401 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4402 is.setstate (std::ios::failbit); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4403 } \ |
3640 | 4404 while (0) |
4405 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4406 #define BEGIN_C_CONVERSION() \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4407 is.unsetf (std::ios::skipws); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4408 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4409 int width = elt->width ? elt->width : 1; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4410 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4411 std::string tmp (width, '\0'); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4412 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4413 int c = std::istream::traits_type::eof (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4414 int n = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4415 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4416 while (is && n < width \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4417 && (c = is.get ()) != std::istream::traits_type::eof ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4418 tmp[n++] = static_cast<char> (c); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4419 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4420 if (n > 0 && c == std::istream::traits_type::eof ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4421 is.clear (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4422 \ |
12984
7626f8934466
correctly resize scanf output for %c formats (bug #34037)
John W. Eaton <jwe@octave.org>
parents:
12966
diff
changeset
|
4423 tmp.resize (n) |
3483 | 4424 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
4425 // For a '%s' format, skip initial whitespace and then read until the |
5338 | 4426 // next whitespace character or until WIDTH characters have been read. |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4427 #define BEGIN_S_CONVERSION() \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4428 int width = elt->width; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4429 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4430 std::string tmp; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4431 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4432 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4433 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4434 if (width) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4435 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4436 tmp = std::string (width, '\0'); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4437 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4438 int c = std::istream::traits_type::eof (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4439 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4440 int n = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4441 \ |
21184
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4442 while (is && (c = is.get ()) != std::istream::traits_type::eof ()) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4443 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4444 if (! isspace (c)) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4445 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4446 tmp[n++] = static_cast<char> (c); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4447 break; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4448 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4449 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4450 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4451 while (is && n < width \ |
21184
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21147
diff
changeset
|
4452 && (c = is.get ()) != std::istream::traits_type::eof ()) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4453 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4454 if (isspace (c)) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4455 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4456 is.putback (c); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4457 break; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4458 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4459 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4460 tmp[n++] = static_cast<char> (c); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4461 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4462 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4463 if (n > 0 && c == std::istream::traits_type::eof ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4464 is.clear (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4465 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4466 tmp.resize (n); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4467 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4468 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4469 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4470 is >> std::ws >> tmp; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4471 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4472 } \ |
3483 | 4473 while (0) |
4474 | |
4475 // This format must match a nonempty sequence of characters. | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4476 #define BEGIN_CHAR_CLASS_CONVERSION() \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4477 int width = elt->width; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4478 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4479 std::string tmp; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4480 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4481 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4482 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4483 if (! width) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4484 width = std::numeric_limits<int>::max (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4485 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4486 std::ostringstream buf; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4487 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4488 std::string char_class = elt->char_class; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4489 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4490 int c = std::istream::traits_type::eof (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4491 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4492 if (elt->type == '[') \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4493 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4494 int chars_read = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4495 while (is && chars_read++ < width \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4496 && (c = is.get ()) != std::istream::traits_type::eof () \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4497 && char_class.find (c) != std::string::npos) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4498 buf << static_cast<char> (c); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4499 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4500 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4501 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4502 int chars_read = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4503 while (is && chars_read++ < width \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4504 && (c = is.get ()) != std::istream::traits_type::eof () \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4505 && char_class.find (c) == std::string::npos) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4506 buf << static_cast<char> (c); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4507 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4508 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4509 if (width == std::numeric_limits<int>::max () \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4510 && c != std::istream::traits_type::eof ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4511 is.putback (c); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4512 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4513 tmp = buf.str (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4514 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4515 if (tmp.empty ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4516 is.setstate (std::ios::failbit); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4517 else if (c == std::istream::traits_type::eof ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4518 is.clear (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4519 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4520 } \ |
3483 | 4521 while (0) |
4522 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4523 #define FINISH_CHARACTER_CONVERSION() \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4524 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4525 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4526 width = tmp.length (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4527 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4528 if (is) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4529 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4530 int i = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4531 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4532 if (! discard) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4533 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4534 conversion_count++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4535 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4536 while (i < width) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4537 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4538 if (data_index == max_size) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4539 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4540 max_size *= 2; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4541 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4542 if (all_char_conv) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4543 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4544 if (one_elt_size_spec) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4545 mval.resize (1, max_size, 0.0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4546 else if (nr > 0) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4547 mval.resize (nr, max_size / nr, 0.0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4548 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4549 panic_impossible (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4550 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4551 else if (nr > 0) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4552 mval.resize (nr, max_size / nr, 0.0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4553 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4554 mval.resize (max_size, 1, 0.0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4555 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4556 data = mval.fortran_vec (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4557 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4558 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4559 data[data_index++] = tmp[i++]; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4560 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4561 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4562 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
4563 } \ |
3410 | 4564 while (0) |
2117 | 4565 |
4566 octave_value | |
4567 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
|
4568 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
|
4569 bool one_elt_size_spec, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4570 octave_idx_type& conversion_count, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4571 const std::string& who) |
2117 | 4572 { |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
4573 if (octave::application::interactive () && file_number () == 0) |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4574 ::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
|
4575 who.c_str ()); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4576 |
8773
9e3111d203c0
disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents:
8739
diff
changeset
|
4577 octave_value retval = Matrix (); |
9e3111d203c0
disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents:
8739
diff
changeset
|
4578 |
3268 | 4579 conversion_count = 0; |
4580 | |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4581 octave_idx_type nconv = fmt_list.num_conversions (); |
3640 | 4582 |
5275 | 4583 octave_idx_type data_index = 0; |
2121 | 4584 |
3268 | 4585 if (nr == 0 || nc == 0) |
4586 { | |
4587 if (one_elt_size_spec) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4588 nc = 0; |
3268 | 4589 |
4590 return Matrix (nr, nc, 0.0); | |
4591 } | |
4592 | |
3523 | 4593 std::istream *isp = input_stream (); |
2117 | 4594 |
4595 bool all_char_conv = fmt_list.all_character_conversions (); | |
4596 | |
4597 Matrix mval; | |
4598 double *data = 0; | |
5275 | 4599 octave_idx_type max_size = 0; |
4600 octave_idx_type max_conv = 0; | |
4601 | |
4602 octave_idx_type final_nr = 0; | |
4603 octave_idx_type final_nc = 0; | |
2117 | 4604 |
3268 | 4605 if (all_char_conv) |
4606 { | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4607 // 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
|
4608 // we may read more than one element for each conversion). |
3268 | 4609 if (one_elt_size_spec) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4610 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4611 max_size = 512; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4612 mval.resize (1, max_size, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4613 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4614 if (nr > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4615 max_conv = nr; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4616 } |
4420 | 4617 else if (nr > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4618 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4619 if (nc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4620 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4621 mval.resize (nr, nc, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4622 max_size = max_conv = nr * nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4623 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4624 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4625 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4626 mval.resize (nr, 32, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4627 max_size = nr * 32; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4628 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4629 } |
4420 | 4630 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4631 panic_impossible (); |
3268 | 4632 } |
4633 else if (nr > 0) | |
2117 | 4634 { |
4635 if (nc > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4636 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4637 // Will not resize later. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4638 mval.resize (nr, nc, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4639 max_size = nr * nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4640 max_conv = max_size; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4641 } |
2117 | 4642 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4643 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4644 // Maybe resize later. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4645 mval.resize (nr, 32, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4646 max_size = nr * 32; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4647 } |
2117 | 4648 } |
4649 else | |
4650 { | |
4420 | 4651 // Maybe resize later. |
2117 | 4652 mval.resize (32, 1, 0.0); |
4653 max_size = 32; | |
4654 } | |
4655 | |
4420 | 4656 data = mval.fortran_vec (); |
4657 | |
2117 | 4658 if (isp) |
4659 { | |
3523 | 4660 std::istream& is = *isp; |
2117 | 4661 |
4662 const scanf_format_elt *elt = fmt_list.first (); | |
4663 | |
3538 | 4664 std::ios::fmtflags flags = is.flags (); |
2213 | 4665 |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4666 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
|
4667 |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4668 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
|
4669 |
2117 | 4670 for (;;) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4671 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4672 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4673 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4674 if (elt) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4675 { |
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
|
4676 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
|
4677 || (! (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
|
4678 || 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
|
4679 || 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
|
4680 && max_conv > 0 && conversion_count == max_conv)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4681 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4682 // 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
|
4683 // 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
|
4684 // 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
|
4685 // 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
|
4686 // Determine final array size and exit. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4687 if (all_char_conv && one_elt_size_spec) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4688 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4689 final_nr = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4690 final_nc = data_index; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4691 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4692 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4693 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4694 final_nr = nr; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4695 final_nc = (data_index - 1) / nr + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4696 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4697 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4698 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4699 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4700 else if (data_index == max_size) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4701 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4702 max_size *= 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4703 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4704 if (all_char_conv) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4705 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4706 if (one_elt_size_spec) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4707 mval.resize (1, max_size, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4708 else if (nr > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4709 mval.resize (nr, max_size / nr, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4710 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4711 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4712 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4713 else if (nr > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4714 mval.resize (nr, max_size / nr, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4715 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4716 mval.resize (max_size, 1, 0.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4717 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4718 data = mval.fortran_vec (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4719 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4720 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4721 const char *fmt = elt->text; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4722 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4723 bool discard = elt->discard; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4724 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4725 switch (elt->type) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4726 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4727 case scanf_format_elt::whitespace_conversion: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4728 DO_WHITESPACE_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4729 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4730 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4731 case scanf_format_elt::literal_conversion: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4732 DO_LITERAL_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4733 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4734 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4735 case '%': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4736 DO_PCT_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4737 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4738 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4739 case 'd': case 'i': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4740 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4741 switch (elt->modifier) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4742 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4743 case 'h': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4744 { |
21686
f07d6f579214
scanf: use appropriate sized types for integer conversions (bug #47741)
Mike Miller <mtmiller@octave.org>
parents:
21622
diff
changeset
|
4745 int16_t tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4746 do_scanf_conv (is, *elt, &tmp, mval, data, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4747 data_index, conversion_count, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4748 nr, max_size, discard); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4749 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4750 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4751 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4752 case 'l': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4753 { |
21686
f07d6f579214
scanf: use appropriate sized types for integer conversions (bug #47741)
Mike Miller <mtmiller@octave.org>
parents:
21622
diff
changeset
|
4754 int64_t tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4755 do_scanf_conv (is, *elt, &tmp, mval, data, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4756 data_index, conversion_count, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4757 nr, max_size, discard); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4758 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4759 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4760 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4761 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4762 { |
21686
f07d6f579214
scanf: use appropriate sized types for integer conversions (bug #47741)
Mike Miller <mtmiller@octave.org>
parents:
21622
diff
changeset
|
4763 int32_t tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4764 do_scanf_conv (is, *elt, &tmp, mval, data, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4765 data_index, conversion_count, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4766 nr, max_size, discard); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4767 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4768 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4769 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4770 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4771 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4772 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4773 case 'o': case 'u': case 'x': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4774 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4775 switch (elt->modifier) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4776 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4777 case 'h': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4778 { |
21686
f07d6f579214
scanf: use appropriate sized types for integer conversions (bug #47741)
Mike Miller <mtmiller@octave.org>
parents:
21622
diff
changeset
|
4779 uint16_t tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4780 do_scanf_conv (is, *elt, &tmp, mval, data, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4781 data_index, conversion_count, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4782 nr, max_size, discard); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4783 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4784 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4785 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4786 case 'l': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4787 { |
21686
f07d6f579214
scanf: use appropriate sized types for integer conversions (bug #47741)
Mike Miller <mtmiller@octave.org>
parents:
21622
diff
changeset
|
4788 uint64_t tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4789 do_scanf_conv (is, *elt, &tmp, mval, data, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4790 data_index, conversion_count, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4791 nr, max_size, discard); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4792 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4793 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4794 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4795 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4796 { |
21686
f07d6f579214
scanf: use appropriate sized types for integer conversions (bug #47741)
Mike Miller <mtmiller@octave.org>
parents:
21622
diff
changeset
|
4797 uint32_t tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4798 do_scanf_conv (is, *elt, &tmp, mval, data, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4799 data_index, conversion_count, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4800 nr, max_size, discard); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4801 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4802 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4803 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4804 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4805 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4806 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4807 case 'e': case 'f': case 'g': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4808 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4809 double tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4810 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4811 do_scanf_conv (is, *elt, &tmp, mval, data, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4812 data_index, conversion_count, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4813 nr, max_size, discard); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4814 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4815 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4816 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4817 case 'c': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4818 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4819 BEGIN_C_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4820 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4821 FINISH_CHARACTER_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4822 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4823 is.setf (flags); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4824 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4825 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4826 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4827 case 's': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4828 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4829 BEGIN_S_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4830 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4831 FINISH_CHARACTER_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4832 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4833 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4834 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4835 case '[': case '^': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4836 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4837 BEGIN_CHAR_CLASS_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4838 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4839 FINISH_CHARACTER_CONVERSION (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4840 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4841 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4842 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4843 case 'p': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4844 error ("%s: unsupported format specifier", who.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4845 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4846 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4847 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4848 error ("%s: internal format error", who.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4849 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4850 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4851 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4852 if (! ok ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4853 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4854 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4855 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4856 else if (! is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4857 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4858 if (all_char_conv) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4859 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4860 if (one_elt_size_spec) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4861 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4862 final_nr = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4863 final_nc = data_index; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4864 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4865 else if (data_index > nr) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4866 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4867 final_nr = nr; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4868 final_nc = (data_index - 1) / nr + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4869 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4870 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4871 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4872 final_nr = data_index; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4873 final_nc = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4874 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4875 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4876 else if (nr > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4877 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4878 if (data_index > nr) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4879 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4880 final_nr = nr; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4881 final_nc = (data_index - 1) / nr + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4882 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4883 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4884 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4885 final_nr = data_index; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4886 final_nc = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4887 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4888 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4889 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4890 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4891 final_nr = data_index; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4892 final_nc = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4893 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4894 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4895 // 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
|
4896 // reset the failbit in the stream state. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4897 if (is.rdstate () & std::ios::failbit) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4898 is.clear (is.rdstate () & (~std::ios::failbit)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4899 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4900 // FIXME: is this the right thing to do? |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
4901 if (octave::application::interactive () |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
4902 && ! octave::application::forced_interactive () |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
4903 && name () == "stdin") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4904 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4905 is.clear (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4906 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4907 // Skip to end of line. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4908 bool err; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4909 do_gets (-1, err, false, who); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4910 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4911 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4912 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4913 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4914 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4915 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4916 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4917 error ("%s: internal format error", who.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4918 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4919 } |
2117 | 4920 |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4921 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
|
4922 { |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4923 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
|
4924 { |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4925 final_nr = 1; |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4926 final_nc = data_index; |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4927 } |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4928 else |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4929 { |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4930 final_nr = nr; |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4931 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
|
4932 } |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4933 |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4934 break; |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4935 } |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
4936 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
|
4937 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4938 // 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
|
4939 // 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
|
4940 // 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
|
4941 // 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
|
4942 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
|
4943 && (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
|
4944 || 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
|
4945 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4946 } |
2117 | 4947 } |
4948 | |
4949 if (ok ()) | |
4950 { | |
2121 | 4951 mval.resize (final_nr, final_nc, 0.0); |
2117 | 4952 |
3268 | 4953 retval = mval; |
4954 | |
2117 | 4955 if (all_char_conv) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4956 retval = retval.convert_to_str (false, true); |
2117 | 4957 } |
4958 | |
4959 return retval; | |
4960 } | |
4961 | |
4962 octave_value | |
3810 | 4963 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
|
4964 octave_idx_type& conversion_count, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4965 const std::string& who) |
2117 | 4966 { |
4967 octave_value retval = Matrix (); | |
4968 | |
3559 | 4969 conversion_count = 0; |
2117 | 4970 |
3523 | 4971 std::istream *isp = input_stream (); |
2117 | 4972 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4973 if (! isp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4974 invalid_operation (who, "reading"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4975 else |
2117 | 4976 { |
4977 scanf_format_list fmt_list (fmt); | |
4978 | |
3640 | 4979 if (fmt_list.num_conversions () == -1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
4980 ::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
|
4981 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4982 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
|
4983 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
|
4984 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4985 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
|
4986 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4987 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
|
4988 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
4989 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
|
4990 conversion_count, who); |
2215 | 4991 } |
2572 | 4992 |
4993 return retval; | |
4994 } | |
4995 | |
2712 | 4996 bool |
4997 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
|
4998 octave_value& retval, const std::string& who) |
2572 | 4999 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5000 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
|
5001 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5002 if (! isp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5003 return false; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5004 |
2712 | 5005 bool quit = false; |
2215 | 5006 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5007 std::istream& is = *isp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5008 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5009 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
|
5010 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5011 if (elt) |
2215 | 5012 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5013 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
|
5014 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5015 bool discard = elt->discard; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5016 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5017 switch (elt->type) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5018 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5019 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
|
5020 DO_WHITESPACE_CONVERSION (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5021 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5022 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5023 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
|
5024 DO_LITERAL_CONVERSION (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5025 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5026 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5027 case '%': |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5028 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5029 DO_PCT_CONVERSION (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5030 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5031 if (! is) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5032 quit = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5033 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5034 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5035 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5036 case 'd': case 'i': |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5037 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5038 int tmp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5039 |
21147
95feb42d7a97
* oct-stream.cc (OCTAVE_SCAN): Eliminate trivial macro.
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
5040 if (octave_scan (is, *elt, &tmp)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5041 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5042 if (! discard) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5043 retval = tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5044 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5045 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5046 quit = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5047 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5048 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5049 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5050 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
|
5051 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5052 long int tmp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5053 |
21147
95feb42d7a97
* oct-stream.cc (OCTAVE_SCAN): Eliminate trivial macro.
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
5054 if (octave_scan (is, *elt, &tmp)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5055 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5056 if (! discard) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5057 retval = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5058 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5059 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5060 quit = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5061 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5062 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5063 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5064 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
|
5065 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5066 double tmp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5067 |
21147
95feb42d7a97
* oct-stream.cc (OCTAVE_SCAN): Eliminate trivial macro.
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
5068 if (octave_scan (is, *elt, &tmp)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5069 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5070 if (! discard) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5071 retval = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5072 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5073 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5074 quit = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5075 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5076 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5077 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5078 case 'c': |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5079 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5080 BEGIN_C_CONVERSION (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5081 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5082 if (! discard) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5083 retval = tmp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5084 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5085 if (! is) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5086 quit = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5087 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5088 is.setf (flags); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5089 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5090 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5091 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5092 case 's': |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5093 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5094 BEGIN_S_CONVERSION (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5095 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5096 if (! discard) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5097 retval = tmp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5098 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5099 if (! is) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5100 quit = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5101 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5102 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5103 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5104 case '[': |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5105 case '^': |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5106 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5107 BEGIN_CHAR_CLASS_CONVERSION (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5108 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5109 if (! discard) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5110 retval = tmp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5111 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5112 if (! is) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5113 quit = true; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5114 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5115 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5116 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5117 case 'p': |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5118 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
|
5119 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5120 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5121 default: |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5122 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
|
5123 break; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5124 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5125 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5126 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5127 if (ok () && is.fail ()) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5128 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5129 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
|
5130 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5131 // 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
|
5132 |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
5133 if (octave::application::interactive () |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
5134 && ! octave::application::forced_interactive () |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
5135 && name () == "stdin") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5136 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5137 // 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
|
5138 bool err; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5139 do_gets (-1, err, false, who); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5140 } |
2215 | 5141 } |
5142 | |
2712 | 5143 return quit; |
2215 | 5144 } |
5145 | |
5146 octave_value_list | |
4468 | 5147 octave_base_stream::oscanf (const std::string& fmt, const std::string& who) |
2215 | 5148 { |
5149 octave_value_list retval; | |
5150 | |
3523 | 5151 std::istream *isp = input_stream (); |
2215 | 5152 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5153 if (! isp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5154 invalid_operation (who, "reading"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5155 else |
2215 | 5156 { |
3523 | 5157 std::istream& is = *isp; |
2215 | 5158 |
5159 scanf_format_list fmt_list (fmt); | |
5160 | |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
5161 octave_idx_type nconv = fmt_list.num_conversions (); |
2215 | 5162 |
3640 | 5163 if (nconv == -1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5164 ::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
|
5165 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5166 is.clear (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5167 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5168 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
|
5169 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5170 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
|
5171 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5172 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
|
5173 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5174 int num_values = 0; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5175 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5176 bool quit = false; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5177 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5178 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
|
5179 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5180 octave_value tmp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5181 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5182 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
|
5183 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5184 if (quit) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5185 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5186 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5187 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5188 if (tmp.is_defined ()) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5189 retval(num_values++) = tmp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5190 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5191 if (! ok ()) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5192 break; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5193 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5194 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
|
5195 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5196 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5197 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5198 retval(nconv) = num_values; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5199 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5200 int err_num; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5201 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
|
5202 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5203 if (! quit) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5204 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5205 // 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
|
5206 if (ok () && len > nconv) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5207 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5208 octave_value tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5209 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5210 elt = fmt_list.next (); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5211 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5212 do_oscanf (elt, tmp, who); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5213 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5214 } |
2117 | 5215 } |
5216 | |
5217 return retval; | |
5218 } | |
5219 | |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5220 octave_value |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5221 octave_base_stream::do_textscan (const std::string& fmt, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5222 octave_idx_type ntimes, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5223 const octave_value_list& options, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5224 const std::string& who, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5225 octave_idx_type& read_count) |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5226 { |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
5227 if (octave::application::interactive () && file_number () == 0) |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5228 ::error ("%s: unable to read from stdin while running interactively", |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5229 who.c_str ()); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5230 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5231 octave_value retval = Cell (dim_vector (1, 1), Matrix (0, 1)); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5232 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5233 std::istream *isp = input_stream (); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5234 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5235 if (! isp) |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5236 invalid_operation (who, "reading"); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5237 else |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5238 { |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5239 textscan scanner (who); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5240 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5241 retval = scanner.scan (*isp, fmt, ntimes, options, read_count); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5242 } |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5243 |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5244 return retval; |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5245 } |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
5246 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5247 // 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
|
5248 // (output streams are those that define os). |
2117 | 5249 |
5250 int | |
5251 octave_base_stream::flush (void) | |
5252 { | |
5253 int retval = -1; | |
5254 | |
3523 | 5255 std::ostream *os = output_stream (); |
2117 | 5256 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5257 if (! os) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5258 invalid_operation ("fflush", "writing"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5259 else |
2117 | 5260 { |
5261 os->flush (); | |
5262 | |
5263 if (os->good ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5264 retval = 0; |
2117 | 5265 } |
5266 | |
5267 return retval; | |
5268 } | |
5269 | |
5270 class | |
5271 printf_value_cache | |
5272 { | |
5273 public: | |
5274 | |
3653 | 5275 enum state { ok, conversion_error }; |
2117 | 5276 |
7352 | 5277 printf_value_cache (const octave_value_list& args, const std::string& who) |
2117 | 5278 : 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
|
5279 n_vals (values.length ()), n_elts (0), have_data (false), |
7352 | 5280 curr_state (ok) |
5281 { | |
5282 for (octave_idx_type i = 0; i < values.length (); i++) | |
5283 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5284 octave_value val = values(i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5285 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5286 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
|
5287 err_wrong_type_arg (who, val); |
7352 | 5288 } |
5289 } | |
2117 | 5290 |
5291 ~printf_value_cache (void) { } | |
5292 | |
5293 // 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
|
5294 octave_value get_next_value (char type = 0); |
2117 | 5295 |
5296 // Get the current value as an int and advance the internal pointer. | |
5297 int int_value (void); | |
5298 | |
3145 | 5299 operator bool () const { return (curr_state == ok); } |
2117 | 5300 |
3653 | 5301 bool exhausted (void) { return (val_idx >= n_vals); } |
2117 | 5302 |
5303 private: | |
5304 | |
5305 const octave_value_list values; | |
5306 int val_idx; | |
5307 int elt_idx; | |
5308 int n_vals; | |
5309 int n_elts; | |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5310 bool have_data; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5311 octave_value curr_val; |
2117 | 5312 state curr_state; |
5313 | |
5314 // Must create value cache with values! | |
5315 | |
5316 printf_value_cache (void); | |
5317 | |
5318 // No copying! | |
5319 | |
5320 printf_value_cache (const printf_value_cache&); | |
5321 | |
5322 printf_value_cache& operator = (const printf_value_cache&); | |
5323 }; | |
5324 | |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5325 octave_value |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5326 printf_value_cache::get_next_value (char type) |
2117 | 5327 { |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5328 octave_value retval; |
2117 | 5329 |
3711 | 5330 if (exhausted ()) |
5331 curr_state = conversion_error; | |
5332 | |
5333 while (! exhausted ()) | |
2117 | 5334 { |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5335 if (! have_data) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5336 { |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5337 curr_val = values (val_idx); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5338 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
5339 elt_idx = 0; |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
5340 n_elts = curr_val.numel (); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
5341 have_data = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5342 } |
2117 | 5343 |
5344 if (elt_idx < n_elts) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5345 { |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5346 if (type == 's') |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5347 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5348 if (curr_val.is_string ()) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5349 { |
21296
596e19e7e571
fix printf regression (bug #47192)
John W. Eaton <jwe@octave.org>
parents:
21235
diff
changeset
|
5350 dim_vector dv (1, curr_val.numel ()); |
596e19e7e571
fix printf regression (bug #47192)
John W. Eaton <jwe@octave.org>
parents:
21235
diff
changeset
|
5351 octave_value tmp = curr_val.reshape (dv); |
596e19e7e571
fix printf regression (bug #47192)
John W. Eaton <jwe@octave.org>
parents:
21235
diff
changeset
|
5352 |
596e19e7e571
fix printf regression (bug #47192)
John W. Eaton <jwe@octave.org>
parents:
21235
diff
changeset
|
5353 std::string sval = tmp.string_value (); |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5354 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5355 retval = sval.substr (elt_idx); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5356 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5357 // We've consumed the rest of the value. |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5358 elt_idx = n_elts; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5359 } |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5360 else |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5361 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5362 // Convert to character string while values are |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5363 // integers in the range [0 : char max] |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5364 const NDArray val = curr_val.array_value (); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5365 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5366 octave_idx_type idx = elt_idx; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5367 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5368 for (; idx < n_elts; idx++) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5369 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5370 double dval = val(idx); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5371 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21777
diff
changeset
|
5372 if (octave::math::x_nint (dval) != dval || dval < 0 || dval > 255) |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5373 break; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5374 } |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5375 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5376 octave_idx_type n = idx - elt_idx; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5377 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5378 if (n > 0) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5379 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5380 std::string sval (n, '\0'); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5381 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5382 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
|
5383 sval[i] = val(elt_idx++); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5384 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5385 retval = sval; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5386 } |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5387 else |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5388 retval = curr_val.fast_elem_extract (elt_idx++); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5389 } |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5390 } |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5391 else |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5392 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5393 retval = curr_val.fast_elem_extract (elt_idx++); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5394 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5395 if (type == 'c' && ! retval.is_string ()) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5396 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5397 double dval = retval.double_value (); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5398 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21777
diff
changeset
|
5399 if (octave::math::x_nint (dval) == dval && dval >= 0 && dval < 256) |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5400 retval = static_cast<char> (dval); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5401 } |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5402 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5403 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5404 if (elt_idx >= n_elts) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5405 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5406 elt_idx = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5407 val_idx++; |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5408 have_data = false; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5409 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5410 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5411 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5412 } |
2117 | 5413 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5414 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5415 val_idx++; |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5416 have_data = false; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5417 |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5418 if (n_elts == 0) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5419 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5420 if (elt_idx == 0 && (type == 's' || type == 'c')) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5421 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5422 retval = ""; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5423 break; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5424 } |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5425 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5426 if (exhausted ()) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5427 curr_state = conversion_error; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5428 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5429 } |
2117 | 5430 } |
5431 | |
5432 return retval; | |
5433 } | |
5434 | |
5435 int | |
5436 printf_value_cache::int_value (void) | |
5437 { | |
5438 int retval = 0; | |
5439 | |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5440 octave_value val = get_next_value (); |
2117 | 5441 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
5442 double dval = val.double_value (true); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
5443 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21777
diff
changeset
|
5444 if (octave::math::x_nint (dval) == dval) |
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21777
diff
changeset
|
5445 retval = octave::math::nint (dval); |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
5446 else |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
5447 curr_state = conversion_error; |
2117 | 5448 |
5449 return retval; | |
5450 } | |
5451 | |
5452 // Ugh again and again. | |
5453 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
5454 template <typename T> |
3620 | 5455 int |
3523 | 5456 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
|
5457 int sa_2, T arg, const std::string& who) |
2572 | 5458 { |
3620 | 5459 int retval = 0; |
5460 | |
2572 | 5461 switch (nsa) |
5462 { | |
5463 case 2: | |
3640 | 5464 retval = octave_format (os, fmt, sa_1, sa_2, arg); |
2572 | 5465 break; |
5466 | |
5467 case 1: | |
3640 | 5468 retval = octave_format (os, fmt, sa_1, arg); |
2572 | 5469 break; |
5470 | |
5471 case 0: | |
3640 | 5472 retval = octave_format (os, fmt, arg); |
2572 | 5473 break; |
5474 | |
5475 default: | |
4468 | 5476 ::error ("%s: internal error handling format", who.c_str ()); |
2572 | 5477 break; |
5478 } | |
3620 | 5479 |
5480 return retval; | |
2572 | 5481 } |
5482 | |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5483 static size_t |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5484 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
|
5485 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
|
5486 const std::string& who) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5487 { |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5488 if (nsa > 2) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20768
diff
changeset
|
5489 ::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
|
5490 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5491 std::string flags = elt->flags; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5492 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5493 bool left = flags.find ('-') != std::string::npos; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5494 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5495 size_t len = arg.length (); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5496 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5497 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
|
5498 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
|
5499 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5500 os << std::setw (fw) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5501 << (left ? std::left : std::right) |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5502 << (prec < len ? arg.substr (0, prec) : arg); |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5503 |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5504 return len > fw ? len : fw; |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5505 } |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5506 |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5507 static bool |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5508 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
|
5509 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5510 octave_value ov_isnan = val.isnan (); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5511 octave_value ov_isinf = val.isinf (); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5512 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5513 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
|
5514 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5515 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5516 static bool |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5517 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
|
5518 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5519 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
|
5520 |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5521 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
|
5522 return true; |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5523 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
|
5524 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5525 if (val.is_uint64_type ()) |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5526 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5527 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
|
5528 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5529 if (ival.value () <= limit) |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5530 return true; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5531 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5532 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5533 return true; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5534 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5535 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5536 { |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5537 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
|
5538 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21777
diff
changeset
|
5539 if (dval == octave::math::round (dval) && dval <= limit) |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5540 return true; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5541 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5542 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5543 return false; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5544 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5545 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5546 static bool |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5547 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
|
5548 { |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5549 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
|
5550 return true; |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5551 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
|
5552 { |
7d0014bb9e4e
also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents:
18650
diff
changeset
|
5553 // 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
|
5554 |
7d0014bb9e4e
also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents:
18650
diff
changeset
|
5555 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
|
5556 = 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
|
5557 |
7d0014bb9e4e
also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents:
18650
diff
changeset
|
5558 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
|
5559 } |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5560 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5561 { |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5562 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
|
5563 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5564 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
|
5565 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21777
diff
changeset
|
5566 if (dval == octave::math::round (dval) && dval >= 0 && dval <= limit) |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5567 return true; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5568 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5569 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5570 return false; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5571 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5572 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5573 static std::string |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5574 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
|
5575 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5576 std::string tfmt = elt->text; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5577 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5578 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
|
5579 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5580 return tfmt; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5581 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5582 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5583 int |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5584 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
|
5585 const printf_format_elt *elt, |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5586 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
|
5587 const octave_value& val, |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5588 const std::string& who) |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5589 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5590 int retval = 0; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5591 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5592 const char *fmt = elt->text; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5593 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5594 if (is_nan_or_inf (val)) |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5595 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5596 double dval = val.double_value (); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5597 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5598 std::string tfmt = fmt; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5599 std::string::size_type i1, i2; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5600 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5601 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
|
5602 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5603 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
|
5604 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5605 tfmt.erase (i2, i1-i2); |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5606 if (elt->prec == -2) |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5607 nsa--; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5608 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5609 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5610 const char *tval; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5611 if (lo_ieee_isinf (dval)) |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5612 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5613 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
|
5614 tval = (dval < 0 ? "-Inf" : "+Inf"); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5615 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5616 tval = (dval < 0 ? "-Inf" : "Inf"); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5617 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5618 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5619 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5620 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
|
5621 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
|
5622 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5623 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
|
5624 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5625 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5626 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
|
5627 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5628 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5629 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5630 static std::string llmod |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5631 = 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
|
5632 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5633 char type = elt->type; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5634 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5635 switch (type) |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5636 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5637 case 'd': case 'i': case 'c': |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5638 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
|
5639 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5640 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
|
5641 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5642 // Insert "long" modifier. |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5643 std::string tfmt = fmt; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5644 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
|
5645 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5646 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
|
5647 tval.value (), who); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5648 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5649 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5650 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5651 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
|
5652 |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5653 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
|
5654 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
5655 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
|
5656 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
|
5657 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5658 break; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5659 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5660 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
|
5661 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
|
5662 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5663 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
|
5664 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5665 // Insert "long" modifier. |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5666 std::string tfmt = fmt; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5667 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
|
5668 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5669 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
|
5670 tval.value (), who); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5671 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5672 else |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5673 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5674 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
|
5675 |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5676 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
|
5677 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
5678 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
|
5679 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
|
5680 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5681 break; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5682 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5683 case 'f': case 'e': case 'E': |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5684 case 'g': case 'G': |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5685 { |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5686 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
|
5687 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
5688 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
|
5689 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5690 break; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5691 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5692 default: |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
5693 // 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
|
5694 // 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
|
5695 error ("%s: invalid format specifier", who.c_str ()); |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5696 return -1; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5697 break; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5698 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5699 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5700 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5701 return retval; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5702 } |
6492 | 5703 |
2117 | 5704 int |
5705 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
|
5706 const octave_value_list& args, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5707 const std::string& who) |
2117 | 5708 { |
3620 | 5709 int retval = 0; |
2117 | 5710 |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
5711 octave_idx_type nconv = fmt_list.num_conversions (); |
3640 | 5712 |
3523 | 5713 std::ostream *osp = output_stream (); |
2117 | 5714 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5715 if (! osp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5716 invalid_operation (who, "writing"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5717 else |
2117 | 5718 { |
3523 | 5719 std::ostream& os = *osp; |
2117 | 5720 |
5721 const printf_format_elt *elt = fmt_list.first (); | |
5722 | |
7352 | 5723 printf_value_cache val_cache (args, who); |
5724 | |
2117 | 5725 for (;;) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5726 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5727 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5728 |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5729 if (! elt) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5730 ::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
|
5731 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5732 // 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
|
5733 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
|
5734 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5735 int sa_1 = 0; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5736 int sa_2 = 0; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5737 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5738 if (nsa > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5739 { |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5740 sa_1 = val_cache.int_value (); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5741 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5742 if (! val_cache) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5743 break; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5744 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5745 { |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5746 if (nsa > 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5747 { |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5748 sa_2 = val_cache.int_value (); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5749 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5750 if (! val_cache) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5751 break; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5752 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5753 } |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5754 } |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5755 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5756 if (elt->type == '%') |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5757 { |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5758 os << "%"; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5759 retval++; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5760 } |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5761 else if (elt->args == 0 && elt->text) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5762 { |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5763 os << elt->text; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5764 retval += strlen (elt->text); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5765 } |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5766 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
|
5767 { |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5768 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
|
5769 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5770 if (val_cache) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5771 { |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5772 if (val.is_string ()) |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5773 { |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5774 std::string sval = val.string_value (); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5775 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5776 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
|
5777 sa_2, sval, who); |
19729
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
5778 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5779 else |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18620
diff
changeset
|
5780 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
|
5781 sa_2, val, who); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5782 } |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5783 else |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5784 break; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5785 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5786 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5787 { |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5788 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
|
5789 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5790 if (val_cache) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5791 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
|
5792 sa_2, val, who); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5793 else |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5794 break; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5795 } |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5796 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5797 if (! os) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5798 { |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
5799 error ("%s: write error", who.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5800 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5801 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5802 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5803 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
|
5804 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5805 if (! elt || (val_cache.exhausted () && elt->args > 0)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5806 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
5807 } |
2117 | 5808 } |
5809 | |
5810 return retval; | |
5811 } | |
5812 | |
5813 int | |
3640 | 5814 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
|
5815 const octave_value_list& args, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5816 const std::string& who) |
2117 | 5817 { |
3640 | 5818 printf_format_list fmt_list (fmt); |
5819 | |
5820 if (fmt_list.num_conversions () == -1) | |
4468 | 5821 ::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
|
5822 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5823 return do_printf (fmt_list, args, who); |
2117 | 5824 } |
5825 | |
5826 int | |
4468 | 5827 octave_base_stream::puts (const std::string& s, const std::string& who) |
2117 | 5828 { |
5829 int retval = -1; | |
5830 | |
3523 | 5831 std::ostream *osp = output_stream (); |
2117 | 5832 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5833 if (! osp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5834 invalid_operation (who, "writing"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5835 else |
2117 | 5836 { |
3523 | 5837 std::ostream& os = *osp; |
2117 | 5838 |
5839 os << s; | |
5840 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5841 if (! os) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5842 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
|
5843 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5844 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5845 // 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
|
5846 // Without it, output from a loop like |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5847 // |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5848 // 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
|
5849 // |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5850 // 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
|
5851 os.flush (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5852 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5853 if (os) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5854 retval = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5855 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5856 error ("%s: write error", who.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5857 } |
2117 | 5858 } |
5859 | |
5860 return retval; | |
5861 } | |
5862 | |
5863 // Return current error message for this stream. | |
5864 | |
3536 | 5865 std::string |
2435 | 5866 octave_base_stream::error (bool clear_err, int& err_num) |
2117 | 5867 { |
2435 | 5868 err_num = fail ? -1 : 0; |
2117 | 5869 |
3523 | 5870 std::string tmp = errmsg; |
2117 | 5871 |
5872 if (clear_err) | |
5873 clear (); | |
5874 | |
5875 return tmp; | |
5876 } | |
5877 | |
5878 void | |
4468 | 5879 octave_base_stream::invalid_operation (const std::string& who, const char *rw) |
2117 | 5880 { |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
5881 // Note: This calls the member fcn error, not ::error from error.h. |
6297 | 5882 error (who, std::string ("stream not open for ") + rw); |
2117 | 5883 } |
5884 | |
3552 | 5885 octave_stream::octave_stream (octave_base_stream *bs) |
3340 | 5886 : rep (bs) |
5887 { | |
5888 if (rep) | |
5889 rep->count = 1; | |
5890 } | |
5891 | |
5892 octave_stream::~octave_stream (void) | |
5893 { | |
5894 if (rep && --rep->count == 0) | |
5895 delete rep; | |
5896 } | |
5897 | |
5898 octave_stream::octave_stream (const octave_stream& s) | |
5899 : rep (s.rep) | |
5900 { | |
5901 if (rep) | |
5902 rep->count++; | |
5903 } | |
5904 | |
5905 octave_stream& | |
5906 octave_stream::operator = (const octave_stream& s) | |
5907 { | |
5908 if (rep != s.rep) | |
5909 { | |
5910 if (rep && --rep->count == 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5911 delete rep; |
3340 | 5912 |
5913 rep = s.rep; | |
5914 | |
5915 if (rep) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5916 rep->count++; |
3340 | 5917 } |
5918 | |
5919 return *this; | |
5920 } | |
5921 | |
2117 | 5922 int |
5923 octave_stream::flush (void) | |
5924 { | |
5925 int retval = -1; | |
5926 | |
5659 | 5927 if (stream_ok ()) |
2117 | 5928 retval = rep->flush (); |
5929 | |
5930 return retval; | |
5931 } | |
5932 | |
3536 | 5933 std::string |
5275 | 5934 octave_stream::getl (octave_idx_type max_len, bool& err, const std::string& who) |
2117 | 5935 { |
3523 | 5936 std::string retval; |
2117 | 5937 |
5659 | 5938 if (stream_ok ()) |
4468 | 5939 retval = rep->getl (max_len, err, who); |
2117 | 5940 |
5941 return retval; | |
5942 } | |
5943 | |
3536 | 5944 std::string |
4468 | 5945 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
|
5946 const std::string& who) |
2117 | 5947 { |
5948 err = false; | |
5949 | |
5950 int conv_err = 0; | |
5951 | |
6345 | 5952 int max_len = -1; |
5953 | |
5954 if (tc_max_len.is_defined ()) | |
2117 | 5955 { |
6345 | 5956 max_len = convert_to_valid_int (tc_max_len, conv_err); |
5957 | |
5958 if (conv_err || max_len < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5959 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5960 err = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5961 ::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
|
5962 } |
2117 | 5963 } |
6345 | 5964 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
5965 return getl (max_len, err, who); |
2117 | 5966 } |
5967 | |
3536 | 5968 std::string |
5275 | 5969 octave_stream::gets (octave_idx_type max_len, bool& err, const std::string& who) |
2117 | 5970 { |
3523 | 5971 std::string retval; |
2117 | 5972 |
5659 | 5973 if (stream_ok ()) |
4468 | 5974 retval = rep->gets (max_len, err, who); |
2117 | 5975 |
5976 return retval; | |
5977 } | |
5978 | |
3536 | 5979 std::string |
4468 | 5980 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
|
5981 const std::string& who) |
2117 | 5982 { |
5983 err = false; | |
5984 | |
5985 int conv_err = 0; | |
5986 | |
6345 | 5987 int max_len = -1; |
5988 | |
5989 if (tc_max_len.is_defined ()) | |
2117 | 5990 { |
6345 | 5991 max_len = convert_to_valid_int (tc_max_len, conv_err); |
5992 | |
5993 if (conv_err || max_len < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5994 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5995 err = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
5996 ::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
|
5997 } |
2117 | 5998 } |
6345 | 5999 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6000 return gets (max_len, err, who); |
2117 | 6001 } |
6002 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
6003 off_t |
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
6004 octave_stream::skipl (off_t count, bool& err, const std::string& who) |
9701 | 6005 { |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
6006 off_t retval = -1; |
9701 | 6007 |
6008 if (stream_ok ()) | |
6009 retval = rep->skipl (count, err, who); | |
6010 | |
6011 return retval; | |
6012 } | |
6013 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
6014 off_t |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6015 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
|
6016 const std::string& who) |
9701 | 6017 { |
6018 err = false; | |
6019 | |
6020 int conv_err = 0; | |
6021 | |
6022 int count = 1; | |
6023 | |
6024 if (tc_count.is_defined ()) | |
6025 { | |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21777
diff
changeset
|
6026 if (tc_count.is_scalar_type () && octave::math::isinf (tc_count.scalar_value ())) |
9701 | 6027 count = -1; |
6028 else | |
6029 { | |
6030 count = convert_to_valid_int (tc_count, conv_err); | |
6031 | |
6032 if (conv_err || count < 0) | |
6033 { | |
6034 err = true; | |
6035 ::error ("%s: invalid number of lines specified", who.c_str ()); | |
6036 } | |
6037 } | |
6038 } | |
6039 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6040 return skipl (count, err, who); |
9701 | 6041 } |
6042 | |
2117 | 6043 int |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
6044 octave_stream::seek (off_t offset, int origin) |
2117 | 6045 { |
5065 | 6046 int status = -1; |
2117 | 6047 |
5659 | 6048 if (stream_ok ()) |
4889 | 6049 { |
6050 clearerr (); | |
6051 | |
12957
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
6052 // 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
|
6053 off_t orig_pos = rep->tell (); |
5065 | 6054 |
12957
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
6055 // 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
|
6056 status = rep->seek (0, SEEK_END); |
5065 | 6057 |
6058 if (status == 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6059 { |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
6060 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
|
6061 |
12943
8372d50de75a
improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
6062 if (origin == SEEK_CUR) |
8372d50de75a
improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
6063 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6064 // 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
|
6065 // 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
|
6066 // location. |
12943
8372d50de75a
improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
6067 rep->seek (orig_pos, SEEK_SET); |
8372d50de75a
improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
6068 } |
8372d50de75a
improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
6069 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6070 // 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
|
6071 // existing file. |
12957
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
6072 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
|
6073 |
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
6074 if (status == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6075 { |
12957
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
6076 // 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
|
6077 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
|
6078 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6079 // 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
|
6080 // 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
|
6081 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
|
6082 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6083 // 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
|
6084 // 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
|
6085 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
|
6086 |
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
6087 status = -1; |
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
6088 } |
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
6089 } |
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
6090 else |
fb69561e5901
maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
6091 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6092 // 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
|
6093 // 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
|
6094 rep->seek (orig_pos, SEEK_SET); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6095 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6096 status = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6097 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6098 } |
4889 | 6099 } |
2117 | 6100 |
5065 | 6101 return status; |
2117 | 6102 } |
6103 | |
6104 int | |
6105 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
|
6106 const octave_value& tc_origin) |
2117 | 6107 { |
6108 int retval = -1; | |
6109 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6110 // 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
|
6111 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
|
6112 off_t xoffset = val.value (); |
4645 | 6113 |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6114 int conv_err = 0; |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6115 |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6116 int origin = SEEK_SET; |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6117 |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6118 if (tc_origin.is_string ()) |
2117 | 6119 { |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6120 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
|
6121 |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6122 if (xorigin == "bof") |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6123 origin = SEEK_SET; |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6124 else if (xorigin == "cof") |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6125 origin = SEEK_CUR; |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6126 else if (xorigin == "eof") |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6127 origin = SEEK_END; |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6128 else |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6129 conv_err = -1; |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6130 } |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6131 else |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6132 { |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6133 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
|
6134 |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6135 if (! conv_err) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6136 { |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6137 if (xorigin == -1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6138 origin = SEEK_SET; |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6139 else if (xorigin == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6140 origin = SEEK_CUR; |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6141 else if (xorigin == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6142 origin = SEEK_END; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6143 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6144 conv_err = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6145 } |
2117 | 6146 } |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
6147 |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
6148 if (conv_err) |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
6149 ::error ("fseek: invalid value for origin"); |
2117 | 6150 |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
6151 retval = seek (xoffset, origin); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
6152 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
6153 if (retval != 0) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
6154 // 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
|
6155 error ("fseek: failed to seek to requested position"); |
2117 | 6156 |
6157 return retval; | |
6158 } | |
6159 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
6160 off_t |
4797 | 6161 octave_stream::tell (void) |
2117 | 6162 { |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
6163 off_t retval = -1; |
2117 | 6164 |
5659 | 6165 if (stream_ok ()) |
2117 | 6166 retval = rep->tell (); |
6167 | |
6168 return retval; | |
6169 } | |
6170 | |
6171 int | |
6172 octave_stream::rewind (void) | |
6173 { | |
6296 | 6174 return seek (0, SEEK_SET); |
2117 | 6175 } |
6176 | |
3340 | 6177 bool |
6178 octave_stream::is_open (void) const | |
6179 { | |
6180 bool retval = false; | |
6181 | |
5659 | 6182 if (stream_ok ()) |
3340 | 6183 retval = rep->is_open (); |
6184 | |
6185 return retval; | |
6186 } | |
6187 | |
6188 void | |
6189 octave_stream::close (void) | |
6190 { | |
5659 | 6191 if (stream_ok ()) |
3340 | 6192 rep->close (); |
6193 } | |
6194 | |
21335
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6195 // FIXME: maybe these should be defined in lo-ieee.h? |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6196 |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6197 template <typename T> |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6198 static inline bool |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6199 is_old_NA (T) |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6200 { |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6201 return false; |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6202 } |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6203 |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6204 template <> |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6205 inline bool |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6206 is_old_NA<double> (double val) |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6207 { |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6208 return __lo_ieee_is_old_NA (val); |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6209 } |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6210 |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6211 template <typename T> |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6212 static inline T |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6213 replace_old_NA (T val) |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6214 { |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6215 return val; |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6216 } |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6217 |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6218 template <> |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6219 inline double |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6220 replace_old_NA<double> (double val) |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6221 { |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6222 return __lo_ieee_replace_old_NA (val); |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6223 } |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6224 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
6225 template <typename SRC_T, typename DST_T> |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6226 static octave_value |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6227 convert_and_copy (std::list<void *>& input_buf_list, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6228 octave_idx_type input_buf_elts, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6229 octave_idx_type elts_read, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6230 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
|
6231 bool do_float_fmt_conv, bool do_NA_conv, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6232 octave::mach_info::float_format from_flt_fmt) |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6233 { |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6234 typedef typename DST_T::element_type dst_elt_type; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6235 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6236 DST_T conv (dim_vector (nr, nc)); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6237 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6238 dst_elt_type *conv_data = conv.fortran_vec (); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6239 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6240 octave_idx_type j = 0; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6241 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6242 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
|
6243 it != input_buf_list.end (); it++) |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6244 { |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6245 SRC_T *data = static_cast<SRC_T *> (*it); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6246 |
17463 | 6247 if (swap || do_float_fmt_conv) |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6248 { |
21335
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6249 if (do_NA_conv) |
17463 | 6250 { |
21335
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6251 for (octave_idx_type i = 0; i < input_buf_elts && j < elts_read; |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6252 i++, j++) |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6253 { |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6254 if (swap) |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6255 swap_bytes<sizeof (SRC_T)> (&data[i]); |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6256 else if (do_float_fmt_conv) |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6257 do_float_format_conversion (&data[i], sizeof (SRC_T), |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6258 1, from_flt_fmt, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6259 octave::mach_info::native_float_format ()); |
21335
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6260 |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6261 dst_elt_type tmp (data[i]); |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6262 |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6263 if (is_old_NA (tmp)) |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6264 tmp = replace_old_NA (tmp); |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6265 |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6266 conv_data[j] = tmp; |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6267 } |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6268 } |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6269 else |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6270 { |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6271 for (octave_idx_type i = 0; i < input_buf_elts && j < elts_read; |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6272 i++, j++) |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6273 { |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6274 if (swap) |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6275 swap_bytes<sizeof (SRC_T)> (&data[i]); |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6276 else if (do_float_fmt_conv) |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6277 do_float_format_conversion (&data[i], sizeof (SRC_T), |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6278 1, from_flt_fmt, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6279 octave::mach_info::native_float_format ()); |
21335
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6280 |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6281 conv_data[j] = data[i]; |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6282 } |
17463 | 6283 } |
6284 } | |
6285 else | |
6286 { | |
6287 if (do_NA_conv) | |
6288 { | |
6289 for (octave_idx_type i = 0; i < input_buf_elts && j < elts_read; | |
6290 i++, j++) | |
6291 { | |
6292 dst_elt_type tmp (data[i]); | |
6293 | |
21335
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6294 if (is_old_NA (tmp)) |
e078d2208d86
avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
6295 tmp = replace_old_NA (tmp); |
17463 | 6296 |
6297 conv_data[j] = tmp; | |
6298 } | |
6299 } | |
6300 else | |
6301 { | |
6302 for (octave_idx_type i = 0; i < input_buf_elts && j < elts_read; | |
6303 i++, j++) | |
6304 conv_data[j] = data[i]; | |
6305 } | |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6306 } |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6307 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6308 delete [] data; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6309 } |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6310 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6311 input_buf_list.clear (); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6312 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6313 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
|
6314 conv_data[i] = dst_elt_type (0); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6315 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6316 return conv; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6317 } |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6318 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6319 typedef octave_value (*conv_fptr) |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6320 (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
|
6321 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
|
6322 bool swap, bool do_float_fmt_conv, bool do_NA_conv, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6323 octave::mach_info::float_format from_flt_fmt); |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6324 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6325 #define TABLE_ELT(T, U, V, W) \ |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6326 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
|
6327 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6328 #define FILL_TABLE_ROW(T, V) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6329 TABLE_ELT (T, dt_int8, V, int8NDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6330 TABLE_ELT (T, dt_uint8, V, uint8NDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6331 TABLE_ELT (T, dt_int16, V, int16NDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6332 TABLE_ELT (T, dt_uint16, V, uint16NDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6333 TABLE_ELT (T, dt_int32, V, int32NDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6334 TABLE_ELT (T, dt_uint32, V, uint32NDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6335 TABLE_ELT (T, dt_int64, V, int64NDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6336 TABLE_ELT (T, dt_uint64, V, uint64NDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6337 TABLE_ELT (T, dt_single, V, FloatNDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6338 TABLE_ELT (T, dt_double, V, NDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6339 TABLE_ELT (T, dt_char, V, charNDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6340 TABLE_ELT (T, dt_schar, V, charNDArray); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6341 TABLE_ELT (T, dt_uchar, V, charNDArray); \ |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6342 TABLE_ELT (T, dt_logical, V, boolNDArray); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6343 |
2117 | 6344 octave_value |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6345 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
|
6346 octave_idx_type input_buf_elts, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6347 octave_idx_type elts_read, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6348 octave_idx_type nr, octave_idx_type nc, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6349 oct_data_conv::data_type input_type, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6350 oct_data_conv::data_type output_type, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6351 octave::mach_info::float_format ffmt) |
2117 | 6352 { |
6353 octave_value retval; | |
6354 | |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6355 static bool initialized = false; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6356 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6357 // Table function pointers for return types x read types. |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6358 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6359 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
|
6360 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6361 if (! initialized) |
4944 | 6362 { |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6363 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
|
6364 for (int j = 0; j < 14; j++) |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6365 conv_fptr_table[i][j] = 0; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6366 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6367 FILL_TABLE_ROW (dt_int8, int8_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6368 FILL_TABLE_ROW (dt_uint8, uint8_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6369 FILL_TABLE_ROW (dt_int16, int16_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6370 FILL_TABLE_ROW (dt_uint16, uint16_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6371 FILL_TABLE_ROW (dt_int32, int32_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6372 FILL_TABLE_ROW (dt_uint32, uint32_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6373 FILL_TABLE_ROW (dt_int64, int64_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6374 FILL_TABLE_ROW (dt_uint64, uint64_t); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6375 FILL_TABLE_ROW (dt_single, float); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6376 FILL_TABLE_ROW (dt_double, double); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6377 FILL_TABLE_ROW (dt_char, char); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6378 FILL_TABLE_ROW (dt_schar, signed char); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6379 FILL_TABLE_ROW (dt_uchar, unsigned char); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6380 FILL_TABLE_ROW (dt_logical, bool); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6381 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6382 initialized = true; |
4944 | 6383 } |
6384 | |
6385 bool swap = false; | |
6386 | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6387 if (ffmt == octave::mach_info::flt_fmt_unknown) |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6388 ffmt = float_format (); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6389 |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6390 if (octave::mach_info::words_big_endian ()) |
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6391 swap = (ffmt == octave::mach_info::flt_fmt_ieee_little_endian); |
4944 | 6392 else |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6393 swap = (ffmt == octave::mach_info::flt_fmt_ieee_big_endian); |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6394 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6395 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
|
6396 || input_type == oct_data_conv::dt_single) |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6397 && ffmt != float_format ()); |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6398 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6399 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
|
6400 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6401 switch (output_type) |
4944 | 6402 { |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6403 case oct_data_conv::dt_int8: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6404 case oct_data_conv::dt_uint8: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6405 case oct_data_conv::dt_int16: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6406 case oct_data_conv::dt_uint16: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6407 case oct_data_conv::dt_int32: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6408 case oct_data_conv::dt_uint32: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6409 case oct_data_conv::dt_int64: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6410 case oct_data_conv::dt_uint64: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6411 case oct_data_conv::dt_single: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6412 case oct_data_conv::dt_double: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6413 case oct_data_conv::dt_char: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6414 case oct_data_conv::dt_schar: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6415 case oct_data_conv::dt_uchar: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6416 case oct_data_conv::dt_logical: |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6417 { |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6418 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
|
6419 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6420 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
|
6421 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
|
6422 } |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6423 break; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6424 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6425 default: |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
6426 ::error ("read: invalid type specification"); |
4944 | 6427 } |
6428 | |
6429 return retval; | |
6430 } | |
6431 | |
6432 octave_value | |
5275 | 6433 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
|
6434 oct_data_conv::data_type input_type, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6435 oct_data_conv::data_type output_type, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6436 octave_idx_type skip, octave::mach_info::float_format ffmt, |
18210
a0abcf377ec5
return elements read, not bytes in fread second output (bug #41091)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
6437 octave_idx_type& count) |
4944 | 6438 { |
6439 octave_value retval; | |
6440 | |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6441 octave_idx_type nr = -1; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6442 octave_idx_type nc = -1; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6443 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6444 bool one_elt_size_spec = false; |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6445 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6446 if (! stream_ok ()) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6447 return retval; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6448 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6449 // 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
|
6450 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6451 // 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
|
6452 // 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
|
6453 // 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
|
6454 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6455 // 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
|
6456 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
|
6457 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6458 count = 0; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6459 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6460 try |
4944 | 6461 { |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6462 get_size (size, nr, nc, one_elt_size_spec, "fread"); |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6463 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6464 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
|
6465 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6466 invalid_operation ("fread", "reading"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6467 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6468 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6469 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
|
6470 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6471 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
|
6472 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6473 // 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
|
6474 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6475 // 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
|
6476 // number of rows. |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6477 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6478 // If NR < 0, 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
|
6479 // 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
|
6480 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6481 if (nr == 0) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6482 nr = nc = 0; |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
6483 else |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6484 nc = 1; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6485 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6486 else |
4944 | 6487 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6488 // 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
|
6489 // 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
|
6490 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6491 // 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
|
6492 // should be. |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6493 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6494 if (nr == 0 || nc == 0) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6495 nr = nc = 0; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6496 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6497 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6498 // 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
|
6499 // 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
|
6500 // 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
|
6501 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
|
6502 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6503 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
|
6504 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6505 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
|
6506 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6507 if (skip == 0) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6508 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6509 if (read_to_eof) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6510 input_buf_elts = 1024 * 1024; |
4944 | 6511 else |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6512 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
|
6513 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6514 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6515 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
|
6516 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6517 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
|
6518 = 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
|
6519 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6520 octave_idx_type input_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
|
6521 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6522 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
|
6523 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6524 // 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
|
6525 // 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
|
6526 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
|
6527 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6528 if (! isp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6529 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
|
6530 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6531 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6532 std::istream& is = *isp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6533 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6534 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
|
6535 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6536 while (is && ! is.eof () |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6537 && (read_to_eof || count < elts_to_read)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6538 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6539 if (! read_to_eof) |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6540 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6541 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
|
6542 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6543 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
|
6544 input_buf_size = remaining_elts * input_elt_size; |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6545 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6546 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6547 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
|
6548 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6549 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
|
6550 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6551 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
|
6552 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6553 char_count += gcount; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6554 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6555 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
|
6556 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6557 count += nel; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6558 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6559 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
|
6560 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6561 if (is && skip != 0 && nel == block_size) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6562 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6563 // Seek to skip. |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6564 // 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
|
6565 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6566 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
|
6567 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6568 seek (0, SEEK_END); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6569 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6570 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
|
6571 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6572 // 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
|
6573 // the original position? |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6574 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
|
6575 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6576 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
|
6577 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6578 if (remaining < skip) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6579 seek (0, SEEK_END); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6580 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6581 seek (skip, SEEK_CUR); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6582 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6583 if (! is) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6584 break; |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6585 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6586 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6587 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6588 if (read_to_eof) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6589 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6590 if (nc < 0) |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6591 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6592 nc = count / nr; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6593 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
6594 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
|
6595 nc++; |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6596 } |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6597 else |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6598 nr = count; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6599 } |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6600 else if (count == 0) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6601 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6602 nr = 0; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6603 nc = 0; |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
6604 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6605 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
|
6606 { |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6607 if (count % nr != 0) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6608 nc = count / nr + 1; |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
6609 else |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6610 nc = count / nr; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6611 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6612 if (count < nr) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6613 nr = count; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6614 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6615 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6616 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
|
6617 nr, nc, input_type, output_type, ffmt); |
4944 | 6618 } |
2117 | 6619 |
6620 return retval; | |
6621 } | |
6622 | |
5275 | 6623 octave_idx_type |
6624 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
|
6625 oct_data_conv::data_type output_type, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6626 octave_idx_type skip, octave::mach_info::float_format flt_fmt) |
2117 | 6627 { |
5275 | 6628 octave_idx_type retval = -1; |
2117 | 6629 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6630 if (! stream_ok ()) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6631 invalid_operation ("fwrite", "writing"); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6632 else |
4944 | 6633 { |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6634 if (flt_fmt == octave::mach_info::flt_fmt_unknown) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
6635 flt_fmt = float_format (); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
6636 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
6637 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
|
6638 skip, flt_fmt); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
6639 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
6640 if (status < 0) |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
6641 error ("fwrite: write error"); |
4944 | 6642 else |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20714
diff
changeset
|
6643 retval = status; |
4944 | 6644 } |
2117 | 6645 |
6646 return retval; | |
6647 } | |
6648 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
6649 template <typename T, typename V> |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6650 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
|
6651 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
|
6652 { |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6653 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
|
6654 |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6655 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
|
6656 |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6657 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
|
6658 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
|
6659 } |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6660 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
6661 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
|
6662 static void |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6663 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
|
6664 bool swap) |
4944 | 6665 { |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6666 typedef typename V::val_type val_type; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6667 |
19739
3fa35defe495
Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19729
diff
changeset
|
6668 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
|
6669 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6670 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
|
6671 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6672 // 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
|
6673 V val (data[i]); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6674 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6675 vt_data[i] = val.value (); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6676 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6677 if (swap) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6678 swap_bytes<sizeof (val_type)> (&vt_data[i]); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6679 } |
4944 | 6680 } |
6681 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
6682 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
|
6683 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
|
6684 { |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6685 public: |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6686 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
|
6687 }; |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6688 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
6689 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
|
6690 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
|
6691 { |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6692 public: |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6693 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
|
6694 }; |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6695 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
6696 template <typename T> |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6697 static bool |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6698 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
|
6699 oct_data_conv::data_type output_type, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6700 octave::mach_info::float_format flt_fmt) |
4944 | 6701 { |
6702 bool retval = true; | |
6703 | |
21776
1e81dd035639
Write integers with correct byte order on big-endian systems (bug #47434)
Mike Miller <mtmiller@octave.org>
parents:
21296
diff
changeset
|
6704 bool swap = false; |
1e81dd035639
Write integers with correct byte order on big-endian systems (bug #47434)
Mike Miller <mtmiller@octave.org>
parents:
21296
diff
changeset
|
6705 |
21777
d6826b38b29c
maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
diff
changeset
|
6706 if (octave::mach_info::words_big_endian ()) |
d6826b38b29c
maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
diff
changeset
|
6707 swap = (flt_fmt == octave::mach_info::flt_fmt_ieee_little_endian); |
21776
1e81dd035639
Write integers with correct byte order on big-endian systems (bug #47434)
Mike Miller <mtmiller@octave.org>
parents:
21296
diff
changeset
|
6708 else |
21777
d6826b38b29c
maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
diff
changeset
|
6709 swap = (flt_fmt == octave::mach_info::flt_fmt_ieee_big_endian); |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6710 |
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6711 bool do_float_conversion = flt_fmt != octave::mach_info::float_format (); |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6712 |
18616
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6713 typedef typename ultimate_element_type<T>::type ult_elt_type; |
4944 | 6714 |
6715 switch (output_type) | |
6716 { | |
6717 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
|
6718 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
|
6719 break; |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6720 |
4944 | 6721 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
|
6722 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
|
6723 break; |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6724 |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6725 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
|
6726 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
|
6727 break; |
aa861a98d84d
fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents:
18518
diff
changeset
|
6728 |
4944 | 6729 case oct_data_conv::dt_int8: |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6730 convert_ints<T, octave_int8> (data, conv_data, n_elts, swap); |
4944 | 6731 break; |
6732 | |
6733 case oct_data_conv::dt_uint8: | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6734 convert_ints<T, octave_uint8> (data, conv_data, n_elts, swap); |
4944 | 6735 break; |
6736 | |
6737 case oct_data_conv::dt_int16: | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6738 convert_ints<T, octave_int16> (data, conv_data, n_elts, swap); |
4944 | 6739 break; |
6740 | |
6741 case oct_data_conv::dt_uint16: | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6742 convert_ints<T, octave_uint16> (data, conv_data, n_elts, swap); |
4944 | 6743 break; |
6744 | |
6745 case oct_data_conv::dt_int32: | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6746 convert_ints<T, octave_int32> (data, conv_data, n_elts, swap); |
4944 | 6747 break; |
6748 | |
6749 case oct_data_conv::dt_uint32: | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6750 convert_ints<T, octave_uint32> (data, conv_data, n_elts, swap); |
4944 | 6751 break; |
6752 | |
6753 case oct_data_conv::dt_int64: | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6754 convert_ints<T, octave_int64> (data, conv_data, n_elts, swap); |
4944 | 6755 break; |
6756 | |
6757 case oct_data_conv::dt_uint64: | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6758 convert_ints<T, octave_uint64> (data, conv_data, n_elts, swap); |
4944 | 6759 break; |
6760 | |
6761 case oct_data_conv::dt_single: | |
6762 { | |
19739
3fa35defe495
Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19729
diff
changeset
|
6763 float *vt_data = static_cast<float *> (conv_data); |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6764 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6765 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
|
6766 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6767 vt_data[i] = data[i]; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6768 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6769 if (do_float_conversion) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6770 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
|
6771 } |
4944 | 6772 } |
6773 break; | |
6774 | |
6775 case oct_data_conv::dt_double: | |
6776 { | |
19739
3fa35defe495
Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19729
diff
changeset
|
6777 double *vt_data = static_cast<double *> (conv_data); |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6778 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6779 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
|
6780 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6781 vt_data[i] = data[i]; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6782 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6783 if (do_float_conversion) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6784 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
|
6785 } |
4944 | 6786 } |
6787 break; | |
6788 | |
6789 default: | |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
6790 ::error ("write: invalid type specification"); |
4944 | 6791 } |
6792 | |
6793 return retval; | |
6794 } | |
6795 | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6796 bool |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6797 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
|
6798 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6799 bool status = false; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6800 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6801 std::ostream *osp = output_stream (); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6802 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6803 if (osp) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6804 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6805 std::ostream& os = *osp; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6806 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6807 if (os) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6808 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6809 os.write (static_cast<const char *> (data), nbytes); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6810 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6811 if (os) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6812 status = true; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6813 } |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6814 } |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6815 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6816 return status; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6817 } |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6818 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6819 bool |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6820 octave_stream::skip_bytes (size_t skip) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6821 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6822 bool status = false; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6823 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6824 std::ostream *osp = output_stream (); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6825 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6826 if (! osp) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6827 return false; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6828 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6829 std::ostream& os = *osp; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6830 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6831 // 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
|
6832 // 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
|
6833 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
|
6834 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6835 seek (0, SEEK_END); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6836 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6837 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
|
6838 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6839 // 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
|
6840 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
|
6841 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6842 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
|
6843 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6844 if (remaining < skip) |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6845 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6846 seek (0, SEEK_END); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6847 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6848 // 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
|
6849 unsigned char zero = 0; |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6850 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
|
6851 os.write (reinterpret_cast<const char *> (&zero), 1); |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6852 } |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6853 else |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6854 seek (skip, SEEK_CUR); |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6855 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6856 if (os) |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
6857 status = true; |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6858 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6859 return status; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6860 } |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6861 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
6862 template <typename T> |
5275 | 6863 octave_idx_type |
6864 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
|
6865 oct_data_conv::data_type output_type, |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6866 octave_idx_type skip, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6867 octave::mach_info::float_format flt_fmt) |
4944 | 6868 { |
21776
1e81dd035639
Write integers with correct byte order on big-endian systems (bug #47434)
Mike Miller <mtmiller@octave.org>
parents:
21296
diff
changeset
|
6869 bool swap = false; |
1e81dd035639
Write integers with correct byte order on big-endian systems (bug #47434)
Mike Miller <mtmiller@octave.org>
parents:
21296
diff
changeset
|
6870 |
21777
d6826b38b29c
maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
diff
changeset
|
6871 if (octave::mach_info::words_big_endian ()) |
d6826b38b29c
maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
diff
changeset
|
6872 swap = (flt_fmt == octave::mach_info::flt_fmt_ieee_little_endian); |
21776
1e81dd035639
Write integers with correct byte order on big-endian systems (bug #47434)
Mike Miller <mtmiller@octave.org>
parents:
21296
diff
changeset
|
6873 else |
21777
d6826b38b29c
maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
diff
changeset
|
6874 swap = (flt_fmt == octave::mach_info::flt_fmt_ieee_big_endian); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6875 |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6876 bool do_data_conversion = (swap || ! is_equivalent_type<T> (output_type) |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6877 || flt_fmt != octave::mach_info::float_format ()); |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6878 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6879 octave_idx_type nel = data.numel (); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6880 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6881 octave_idx_type chunk_size; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6882 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6883 if (skip != 0) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6884 chunk_size = block_size; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6885 else if (do_data_conversion) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6886 chunk_size = 1024 * 1024; |
4944 | 6887 else |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6888 chunk_size = nel; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6889 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6890 octave_idx_type i = 0; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6891 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6892 const T *pdata = data.data (); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6893 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6894 while (i < nel) |
4944 | 6895 { |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6896 if (skip != 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6897 { |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6898 if (! skip_bytes (skip)) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6899 return -1; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6900 } |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6901 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6902 octave_idx_type remaining_nel = nel - i; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6903 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6904 if (chunk_size > remaining_nel) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6905 chunk_size = remaining_nel; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6906 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6907 bool status = false; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6908 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6909 if (do_data_conversion) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6910 { |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6911 size_t output_size |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6912 = 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
|
6913 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6914 OCTAVE_LOCAL_BUFFER (unsigned char, conv_data, output_size); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6915 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6916 status = convert_data (&pdata[i], conv_data, chunk_size, |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6917 output_type, flt_fmt); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6918 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6919 if (status) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6920 status = write_bytes (conv_data, output_size); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6921 } |
4944 | 6922 else |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6923 status = write_bytes (pdata, sizeof (T) * chunk_size); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6924 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6925 if (! status) |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6926 return -1; |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6927 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6928 i += chunk_size; |
4944 | 6929 } |
6930 | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6931 return nel; |
4944 | 6932 } |
6933 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6934 #define INSTANTIATE_WRITE(T) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6935 template \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6936 octave_idx_type \ |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6937 octave_stream::write (const Array<T>& data, octave_idx_type block_size, \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6938 oct_data_conv::data_type output_type, \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
6939 octave_idx_type skip, \ |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
6940 octave::mach_info::float_format flt_fmt) |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6941 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6942 INSTANTIATE_WRITE (octave_int8); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6943 INSTANTIATE_WRITE (octave_uint8); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6944 INSTANTIATE_WRITE (octave_int16); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6945 INSTANTIATE_WRITE (octave_uint16); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6946 INSTANTIATE_WRITE (octave_int32); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6947 INSTANTIATE_WRITE (octave_uint32); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6948 INSTANTIATE_WRITE (octave_int64); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6949 INSTANTIATE_WRITE (octave_uint64); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6950 INSTANTIATE_WRITE (int8_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6951 INSTANTIATE_WRITE (uint8_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6952 INSTANTIATE_WRITE (int16_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6953 INSTANTIATE_WRITE (uint16_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6954 INSTANTIATE_WRITE (int32_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6955 INSTANTIATE_WRITE (uint32_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6956 INSTANTIATE_WRITE (int64_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6957 INSTANTIATE_WRITE (uint64_t); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6958 INSTANTIATE_WRITE (bool); |
21354
06d15e4e611a
move public data type macros to octave-config.h
John W. Eaton <jwe@octave.org>
parents:
21335
diff
changeset
|
6959 #if defined (OCTAVE_HAVE_OVERLOAD_CHAR_INT8_TYPES) |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6960 INSTANTIATE_WRITE (char); |
21235
b48d65c5df5b
Disable char/int8_t function overloads where not permitted (bug #45411)
Mike Miller <mtmiller@octave.org>
parents:
20252
diff
changeset
|
6961 #endif |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6962 INSTANTIATE_WRITE (float); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
6963 INSTANTIATE_WRITE (double); |
4944 | 6964 |
2117 | 6965 octave_value |
3810 | 6966 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
|
6967 octave_idx_type& count, const std::string& who) |
2117 | 6968 { |
6969 octave_value retval; | |
6970 | |
5659 | 6971 if (stream_ok ()) |
4468 | 6972 retval = rep->scanf (fmt, size, count, who); |
2117 | 6973 |
6974 return retval; | |
6975 } | |
6976 | |
5279 | 6977 octave_value |
6978 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
|
6979 octave_idx_type& count, const std::string& who) |
5279 | 6980 { |
6981 octave_value retval = Matrix (); | |
6982 | |
6983 if (fmt.is_string ()) | |
6984 { | |
6985 std::string sfmt = fmt.string_value (); | |
6986 | |
6987 if (fmt.is_sq_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
6988 sfmt = do_string_escapes (sfmt); |
5279 | 6989 |
6990 retval = scanf (sfmt, size, count, who); | |
6991 } | |
6992 else | |
6993 { | |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
6994 // Note: error is member fcn from octave_stream, not ::error. |
5279 | 6995 error (who + ": format must be a string"); |
6996 } | |
6997 | |
6998 return retval; | |
6999 } | |
7000 | |
2215 | 7001 octave_value_list |
4468 | 7002 octave_stream::oscanf (const std::string& fmt, const std::string& who) |
2215 | 7003 { |
7004 octave_value_list retval; | |
7005 | |
5659 | 7006 if (stream_ok ()) |
4468 | 7007 retval = rep->oscanf (fmt, who); |
2215 | 7008 |
7009 return retval; | |
7010 } | |
7011 | |
5279 | 7012 octave_value_list |
7013 octave_stream::oscanf (const octave_value& fmt, const std::string& who) | |
7014 { | |
7015 octave_value_list retval; | |
7016 | |
7017 if (fmt.is_string ()) | |
7018 { | |
7019 std::string sfmt = fmt.string_value (); | |
7020 | |
7021 if (fmt.is_sq_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7022 sfmt = do_string_escapes (sfmt); |
5279 | 7023 |
7024 retval = oscanf (sfmt, who); | |
7025 } | |
7026 else | |
7027 { | |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
7028 // Note: error is member fcn from octave_stream, not ::error. |
5279 | 7029 error (who + ": format must be a string"); |
7030 } | |
7031 | |
7032 return retval; | |
7033 } | |
7034 | |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
7035 octave_value |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
7036 octave_stream::textscan (const std::string& fmt, octave_idx_type ntimes, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
7037 const octave_value_list& options, |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
7038 const std::string& who, octave_idx_type& count) |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
7039 { |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
7040 return (stream_ok () |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
7041 ? rep->do_textscan (fmt, ntimes, options, who, count) |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
7042 : octave_value ()); |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
7043 } |
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
7044 |
2117 | 7045 int |
4468 | 7046 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
|
7047 const std::string& who) |
2117 | 7048 { |
7049 int retval = -1; | |
7050 | |
5659 | 7051 if (stream_ok ()) |
4468 | 7052 retval = rep->printf (fmt, args, who); |
2117 | 7053 |
7054 return retval; | |
7055 } | |
7056 | |
7057 int | |
5279 | 7058 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
|
7059 const std::string& who) |
5279 | 7060 { |
7061 int retval = 0; | |
7062 | |
7063 if (fmt.is_string ()) | |
7064 { | |
7065 std::string sfmt = fmt.string_value (); | |
7066 | |
7067 if (fmt.is_sq_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7068 sfmt = do_string_escapes (sfmt); |
5279 | 7069 |
7070 retval = printf (sfmt, args, who); | |
7071 } | |
7072 else | |
7073 { | |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
7074 // Note: error is member fcn from octave_stream, not ::error. |
5279 | 7075 error (who + ": format must be a string"); |
7076 } | |
7077 | |
7078 return retval; | |
7079 } | |
7080 | |
7081 int | |
4468 | 7082 octave_stream::puts (const std::string& s, const std::string& who) |
2117 | 7083 { |
7084 int retval = -1; | |
7085 | |
5659 | 7086 if (stream_ok ()) |
4468 | 7087 retval = rep->puts (s, who); |
2117 | 7088 |
7089 return retval; | |
7090 } | |
7091 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7092 // FIXME: maybe this should work for string arrays too. |
2117 | 7093 |
7094 int | |
4468 | 7095 octave_stream::puts (const octave_value& tc_s, const std::string& who) |
2117 | 7096 { |
7097 int retval = -1; | |
7098 | |
7099 if (tc_s.is_string ()) | |
7100 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
7101 std::string s = tc_s.string_value (); |
5279 | 7102 retval = puts (s, who); |
2117 | 7103 } |
7104 else | |
4468 | 7105 { |
20938
aac911d8847b
choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents:
20931
diff
changeset
|
7106 // Note: error is member fcn from octave_stream, not ::error. |
4468 | 7107 error (who + ": argument must be a string"); |
7108 } | |
2117 | 7109 |
7110 return retval; | |
7111 } | |
7112 | |
7113 bool | |
7114 octave_stream::eof (void) const | |
7115 { | |
7116 int retval = -1; | |
7117 | |
5659 | 7118 if (stream_ok ()) |
2117 | 7119 retval = rep->eof (); |
7120 | |
7121 return retval; | |
7122 } | |
7123 | |
3536 | 7124 std::string |
2435 | 7125 octave_stream::error (bool clear, int& err_num) |
2117 | 7126 { |
5649 | 7127 std::string retval = "invalid stream object"; |
7128 | |
5659 | 7129 if (stream_ok (false)) |
2435 | 7130 retval = rep->error (clear, err_num); |
2117 | 7131 |
7132 return retval; | |
7133 } | |
7134 | |
3536 | 7135 std::string |
3340 | 7136 octave_stream::name (void) const |
2117 | 7137 { |
3523 | 7138 std::string retval; |
2117 | 7139 |
5659 | 7140 if (stream_ok ()) |
2117 | 7141 retval = rep->name (); |
7142 | |
7143 return retval; | |
7144 } | |
7145 | |
7146 int | |
3340 | 7147 octave_stream::mode (void) const |
2117 | 7148 { |
7149 int retval = 0; | |
7150 | |
5659 | 7151 if (stream_ok ()) |
2117 | 7152 retval = rep->mode (); |
7153 | |
7154 return retval; | |
7155 } | |
7156 | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
7157 octave::mach_info::float_format |
3340 | 7158 octave_stream::float_format (void) const |
2117 | 7159 { |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
7160 octave::mach_info::float_format retval = octave::mach_info::flt_fmt_unknown; |
2317 | 7161 |
5659 | 7162 if (stream_ok ()) |
2317 | 7163 retval = rep->float_format (); |
2117 | 7164 |
7165 return retval; | |
7166 } | |
7167 | |
3536 | 7168 std::string |
2117 | 7169 octave_stream::mode_as_string (int mode) |
7170 { | |
3523 | 7171 std::string retval = "???"; |
3775 | 7172 std::ios::openmode in_mode = static_cast<std::ios::openmode> (mode); |
7173 | |
7174 if (in_mode == std::ios::in) | |
7175 retval = "r"; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
7176 else if (in_mode == std::ios::out |
4078 | 7177 || in_mode == (std::ios::out | std::ios::trunc)) |
3775 | 7178 retval = "w"; |
4078 | 7179 else if (in_mode == (std::ios::out | std::ios::app)) |
3775 | 7180 retval = "a"; |
4078 | 7181 else if (in_mode == (std::ios::in | std::ios::out)) |
3775 | 7182 retval = "r+"; |
4078 | 7183 else if (in_mode == (std::ios::in | std::ios::out | std::ios::trunc)) |
3775 | 7184 retval = "w+"; |
4078 | 7185 else if (in_mode == (std::ios::in | std::ios::out | std::ios::ate)) |
3775 | 7186 retval = "a+"; |
4078 | 7187 else if (in_mode == (std::ios::in | std::ios::binary)) |
3775 | 7188 retval = "rb"; |
4078 | 7189 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
|
7190 || in_mode == (std::ios::out | std::ios::trunc | std::ios::binary)) |
3775 | 7191 retval = "wb"; |
4078 | 7192 else if (in_mode == (std::ios::out | std::ios::app | std::ios::binary)) |
3775 | 7193 retval = "ab"; |
4078 | 7194 else if (in_mode == (std::ios::in | std::ios::out | std::ios::binary)) |
3775 | 7195 retval = "r+b"; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
7196 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
|
7197 | std::ios::binary)) |
3775 | 7198 retval = "w+b"; |
4078 | 7199 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
|
7200 | std::ios::binary)) |
3775 | 7201 retval = "a+b"; |
2117 | 7202 |
7203 return retval; | |
7204 } | |
7205 | |
7206 octave_stream_list *octave_stream_list::instance = 0; | |
7207 | |
2926 | 7208 bool |
7209 octave_stream_list::instance_ok (void) | |
7210 { | |
7211 bool retval = true; | |
7212 | |
7213 if (! instance) | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13271
diff
changeset
|
7214 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13271
diff
changeset
|
7215 instance = new octave_stream_list (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13271
diff
changeset
|
7216 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13271
diff
changeset
|
7217 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13271
diff
changeset
|
7218 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
|
7219 } |
2926 | 7220 |
7221 if (! instance) | |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20768
diff
changeset
|
7222 ::error ("unable to create stream list object!"); |
2926 | 7223 |
7224 return retval; | |
7225 } | |
7226 | |
5353 | 7227 int |
6757 | 7228 octave_stream_list::insert (octave_stream& os) |
2926 | 7229 { |
5353 | 7230 return (instance_ok ()) ? instance->do_insert (os) : -1; |
2926 | 7231 } |
7232 | |
3340 | 7233 octave_stream |
3523 | 7234 octave_stream_list::lookup (int fid, const std::string& who) |
2926 | 7235 { |
3341 | 7236 return (instance_ok ()) ? instance->do_lookup (fid, who) : octave_stream (); |
2926 | 7237 } |
7238 | |
3340 | 7239 octave_stream |
3523 | 7240 octave_stream_list::lookup (const octave_value& fid, const std::string& who) |
2926 | 7241 { |
3341 | 7242 return (instance_ok ()) ? instance->do_lookup (fid, who) : octave_stream (); |
2926 | 7243 } |
7244 | |
7245 int | |
3523 | 7246 octave_stream_list::remove (int fid, const std::string& who) |
2926 | 7247 { |
3341 | 7248 return (instance_ok ()) ? instance->do_remove (fid, who) : -1; |
2926 | 7249 } |
7250 | |
7251 int | |
3523 | 7252 octave_stream_list::remove (const octave_value& fid, const std::string& who) |
2926 | 7253 { |
3341 | 7254 return (instance_ok ()) ? instance->do_remove (fid, who) : -1; |
2926 | 7255 } |
7256 | |
7257 void | |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7258 octave_stream_list::clear (bool flush) |
2926 | 7259 { |
7260 if (instance) | |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7261 instance->do_clear (flush); |
2926 | 7262 } |
7263 | |
7264 string_vector | |
7265 octave_stream_list::get_info (int fid) | |
7266 { | |
7267 return (instance_ok ()) ? instance->do_get_info (fid) : string_vector (); | |
7268 } | |
7269 | |
7270 string_vector | |
7271 octave_stream_list::get_info (const octave_value& fid) | |
7272 { | |
7273 return (instance_ok ()) ? instance->do_get_info (fid) : string_vector (); | |
7274 } | |
7275 | |
3536 | 7276 std::string |
2926 | 7277 octave_stream_list::list_open_files (void) |
7278 { | |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20982
diff
changeset
|
7279 return (instance_ok ()) ? instance->do_list_open_files () : ""; |
2926 | 7280 } |
7281 | |
7282 octave_value | |
7283 octave_stream_list::open_file_numbers (void) | |
7284 { | |
7285 return (instance_ok ()) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7286 ? instance->do_open_file_numbers () : octave_value (); |
2926 | 7287 } |
7288 | |
7289 int | |
7290 octave_stream_list::get_file_number (const octave_value& fid) | |
7291 { | |
7292 return (instance_ok ()) ? instance->do_get_file_number (fid) : -1; | |
7293 } | |
7294 | |
5353 | 7295 int |
6757 | 7296 octave_stream_list::do_insert (octave_stream& os) |
2117 | 7297 { |
6757 | 7298 // Insert item with key corresponding to file-descriptor. |
7299 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
7300 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
|
7301 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
7302 if (stream_number == -1) |
6757 | 7303 return stream_number; |
7304 | |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
7305 // 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
|
7306 // |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
7307 // (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
|
7308 // && 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
|
7309 // |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
7310 // 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
|
7311 // 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
|
7312 // 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
|
7313 // 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
|
7314 // 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
|
7315 // 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
|
7316 // before. |
6757 | 7317 |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7318 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
|
7319 ::error ("could not create file id"); |
2117 | 7320 |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7321 list[stream_number] = os; |
2117 | 7322 |
5353 | 7323 return stream_number; |
2117 | 7324 } |
7325 | |
21040
3e7cfee5f786
maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents:
21029
diff
changeset
|
7326 OCTAVE_NORETURN static |
21029
e3b3bb522d62
maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
7327 void |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
7328 err_invalid_file_id (int fid, const std::string& who) |
3341 | 7329 { |
7330 if (who.empty ()) | |
7331 ::error ("invalid stream number = %d", fid); | |
7332 else | |
7333 ::error ("%s: invalid stream number = %d", who.c_str (), fid); | |
7334 } | |
7335 | |
3340 | 7336 octave_stream |
3523 | 7337 octave_stream_list::do_lookup (int fid, const std::string& who) const |
2117 | 7338 { |
3340 | 7339 octave_stream retval; |
2117 | 7340 |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7341 if (fid < 0) |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
7342 err_invalid_file_id (fid, who); |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7343 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7344 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
|
7345 retval = lookup_cache->second; |
3341 | 7346 else |
6757 | 7347 { |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7348 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
|
7349 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7350 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
|
7351 err_invalid_file_id (fid, who); |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7352 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7353 retval = iter->second; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7354 lookup_cache = iter; |
6757 | 7355 } |
2117 | 7356 |
7357 return retval; | |
7358 } | |
7359 | |
3340 | 7360 octave_stream |
3341 | 7361 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
|
7362 const std::string& who) const |
2117 | 7363 { |
7364 int i = get_file_number (fid); | |
7365 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
7366 return do_lookup (i, who); |
2117 | 7367 } |
7368 | |
7369 int | |
3523 | 7370 octave_stream_list::do_remove (int fid, const std::string& who) |
2117 | 7371 { |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7372 // 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
|
7373 if (fid < 3) |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
7374 err_invalid_file_id (fid, who); |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7375 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7376 ostrl_map::iterator iter = list.find (fid); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7377 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7378 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
|
7379 err_invalid_file_id (fid, who); |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7380 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7381 octave_stream os = iter->second; |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7382 list.erase (iter); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7383 lookup_cache = list.end (); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7384 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7385 // FIXME: is this check redundant? |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7386 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
|
7387 err_invalid_file_id (fid, who); |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7388 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7389 os.close (); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7390 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
7391 return 0; |
2117 | 7392 } |
7393 | |
7394 int | |
3523 | 7395 octave_stream_list::do_remove (const octave_value& fid, const std::string& who) |
2117 | 7396 { |
7397 int retval = -1; | |
7398 | |
6054 | 7399 if (fid.is_string () && fid.string_value () == "all") |
7400 { | |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7401 do_clear (false); |
6054 | 7402 |
7403 retval = 0; | |
7404 } | |
7405 else | |
7406 { | |
7407 int i = get_file_number (fid); | |
7408 | |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20465
diff
changeset
|
7409 retval = do_remove (i, who); |
6054 | 7410 } |
2117 | 7411 |
7412 return retval; | |
7413 } | |
7414 | |
7415 void | |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7416 octave_stream_list::do_clear (bool flush) |
2117 | 7417 { |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7418 if (flush) |
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7419 { |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7420 // Flush stdout and stderr. |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7421 list[1].flush (); |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7422 list[2].flush (); |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7423 } |
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7424 |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7425 for (ostrl_map::iterator iter = list.begin (); iter != list.end (); ) |
6757 | 7426 { |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7427 int fid = iter->first; |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7428 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
|
7429 { |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7430 iter++; |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7431 continue; |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7432 } |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7433 |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7434 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
|
7435 |
7655b399abff
eliminate trailing whitespace in source files we maintain
John W. Eaton <jwe@octave.org>
parents:
20764
diff
changeset
|
7436 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
|
7437 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
|
7438 |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7439 // 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
|
7440 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
|
7441 { |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7442 // 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
|
7443 iter++; |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7444 continue; |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7445 } |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7446 |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7447 // 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
|
7448 if (os.is_valid ()) |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7449 os.close (); |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7450 |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7451 list.erase (iter++); |
6757 | 7452 } |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
7453 |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8773
diff
changeset
|
7454 lookup_cache = list.end (); |
2117 | 7455 } |
7456 | |
7457 string_vector | |
7458 octave_stream_list::do_get_info (int fid) const | |
7459 { | |
3340 | 7460 octave_stream os = do_lookup (fid); |
2117 | 7461 |
20892 | 7462 if (! os.is_valid ()) |
3341 | 7463 ::error ("invalid file id = %d", fid); |
2117 | 7464 |
20892 | 7465 string_vector retval (3); |
7466 | |
7467 retval(0) = os.name (); | |
7468 retval(1) = octave_stream::mode_as_string (os.mode ()); | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
7469 retval(2) = octave::mach_info::float_format_as_string (os.float_format ()); |
20892 | 7470 |
2117 | 7471 return retval; |
7472 } | |
7473 | |
7474 string_vector | |
7475 octave_stream_list::do_get_info (const octave_value& fid) const | |
7476 { | |
7477 int conv_err = 0; | |
7478 | |
7479 int int_fid = convert_to_valid_int (fid, conv_err); | |
7480 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
7481 if (conv_err) |
2915 | 7482 ::error ("file id must be a file object or integer value"); |
2117 | 7483 |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
7484 return do_get_info (int_fid); |
2117 | 7485 } |
7486 | |
3536 | 7487 std::string |
2117 | 7488 octave_stream_list::do_list_open_files (void) const |
7489 { | |
5765 | 7490 std::ostringstream buf; |
2117 | 7491 |
7492 buf << "\n" | |
7493 << " number mode arch name\n" | |
7494 << " ------ ---- ---- ----\n"; | |
7495 | |
6757 | 7496 for (ostrl_map::const_iterator p = list.begin (); p != list.end (); p++) |
2117 | 7497 { |
6757 | 7498 octave_stream os = p->second; |
2117 | 7499 |
4326 | 7500 buf << " " |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7501 << std::setiosflags (std::ios::right) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7502 << std::setw (4) << p->first << " " |
19123 | 7503 // reset necessary in addition to setiosflags since this is one stmt. |
7504 << std::resetiosflags (std::ios::adjustfield) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7505 << std::setiosflags (std::ios::left) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7506 << std::setw (3) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7507 << octave_stream::mode_as_string (os.mode ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7508 << " " |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7509 << std::setw (9) |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
7510 << octave::mach_info::float_format_as_string (os.float_format ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7511 << " " |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7512 << os.name () << "\n"; |
2117 | 7513 } |
7514 | |
5765 | 7515 buf << "\n"; |
7516 | |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
7517 return buf.str (); |
2117 | 7518 } |
7519 | |
7520 octave_value | |
7521 octave_stream_list::do_open_file_numbers (void) const | |
7522 { | |
6757 | 7523 Matrix retval (1, list.size (), 0.0); |
2117 | 7524 |
7525 int num_open = 0; | |
7526 | |
6757 | 7527 for (ostrl_map::const_iterator p = list.begin (); p != list.end (); p++) |
2117 | 7528 { |
6757 | 7529 // Skip stdin, stdout, and stderr. |
7530 if (p->first > 2 && p->second) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7531 retval(0,num_open++) = p->first; |
2117 | 7532 } |
7533 | |
7534 retval.resize ((num_open > 0), num_open); | |
7535 | |
7536 return retval; | |
7537 } | |
7538 | |
7539 int | |
2609 | 7540 octave_stream_list::do_get_file_number (const octave_value& fid) const |
2117 | 7541 { |
7542 int retval = -1; | |
7543 | |
7544 if (fid.is_string ()) | |
7545 { | |
3523 | 7546 std::string nm = fid.string_value (); |
2117 | 7547 |
6757 | 7548 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
|
7549 { |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
7550 // stdin, stdout, and stderr are unnamed. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7551 if (p->first > 2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7552 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7553 octave_stream os = p->second; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7554 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7555 if (os && os.name () == nm) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7556 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7557 retval = p->first; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7558 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7559 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7560 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7561 } |
2117 | 7562 } |
7563 else | |
7564 { | |
7565 int conv_err = 0; | |
7566 | |
7567 int int_fid = convert_to_valid_int (fid, conv_err); | |
7568 | |
7569 if (conv_err) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
7570 ::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
|
7571 |
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
7572 retval = int_fid; |
2117 | 7573 } |
7574 | |
7575 return retval; | |
7576 } |