annotate libinterp/corefcn/oct-stream.cc @ 21477:4fc04d04dd9c

make printf and scanf format element and list objects private * oct-stream.cc (scanf_format_elt, scanf_format_list, printf_format_elt, printf_format_list): Move class declarations and definitions here. * oct-stream.h: From here.
author John W. Eaton <jwe@octave.org>
date Fri, 18 Mar 2016 13:10:19 -0400
parents 4f3e63d75f33
children 7a19c5678f91
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1 /*
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19346
diff changeset
3 Copyright (C) 1996-2015 John W. Eaton
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6970
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6970
diff changeset
10 option) any later version.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
11
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
15 for more details.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
16
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6970
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6970
diff changeset
19 <http://www.gnu.org/licenses/>.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
20
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
21 */
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
22
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21297
diff changeset
24 # include "config.h"
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
25 #endif
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
26
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
27 #include <cassert>
7709
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
28 #include <cctype>
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
29 #include <cstring>
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
30
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3491
diff changeset
31 #include <iomanip>
9202
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
32 #include <iostream>
3559
12d7ec415f35 [project @ 2000-02-03 05:17:36 by jwe]
jwe
parents: 3553
diff changeset
33 #include <fstream>
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
34 #include <sstream>
3535
c5ebcd5d25a9 [project @ 2000-02-02 11:55:49 by jwe]
jwe
parents: 3534
diff changeset
35 #include <string>
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
36
19269
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 19123
diff changeset
37 #include "Array.h"
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
38 #include "byte-swap.h"
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
39 #include "lo-ieee.h"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
40 #include "lo-mappers.h"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
41 #include "lo-utils.h"
19269
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 19123
diff changeset
42 #include "oct-locbuf.h"
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
43 #include "quit.h"
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
44 #include "singleton-cleanup.h"
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
45 #include "str-vec.h"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
46
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
47 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21040
diff changeset
48 #include "errwarn.h"
3342
d8d3700fb4ab [project @ 1999-11-05 16:55:17 by jwe]
jwe
parents: 3341
diff changeset
49 #include "input.h"
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
50 #include "oct-stdstrm.h"
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
51 #include "oct-stream.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20938
diff changeset
52 #include "ovl.h"
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20747
diff changeset
53 #include "toplev.h"
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
54 #include "utils.h"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
55
20938
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
56 // Programming Note: There are two very different error functions used
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
57 // in the stream code. When invoked with "error (...)" the member
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
58 // function from octave_stream or octave_base_stream is called. This
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
59 // function sets the error state on the stream AND returns control to
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
60 // the caller. The caller must then return a value at the end of the
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
61 // function. When invoked with "::error (...)" the exception-based
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
62 // error function from error.h is used. This function will throw an
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
63 // exception and not return control to the caller. BE CAREFUL and
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
64 // invoke the correct error function!
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
65
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
66 // Possible values for conv_err:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
67 //
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
68 // 1 : not a real scalar
2902
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2877
diff changeset
69 // 2 : value is NaN
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2877
diff changeset
70 // 3 : value is not an integer
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
71
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
72 static int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
73 convert_to_valid_int (const octave_value& tc, int& conv_err)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
74 {
20747
ee2743bd07a8 eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents: 20741
diff changeset
75 conv_err = 0;
ee2743bd07a8 eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents: 20741
diff changeset
76
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
77 int retval = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
78
20747
ee2743bd07a8 eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents: 20741
diff changeset
79 double dval = 0.0;
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
80
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
81 try
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
82 {
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
83 dval = tc.double_value ();
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
84 }
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
85 catch (const octave_execution_exception&)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
86 {
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20747
diff changeset
87 recover_from_exception ();
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20747
diff changeset
88
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
89 conv_err = 1;
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
90 }
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
91
20747
ee2743bd07a8 eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents: 20741
diff changeset
92 if (! conv_err)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
93 {
5389
25c8956d2204 [project @ 2005-06-15 03:45:46 by jwe]
jwe
parents: 5353
diff changeset
94 if (! lo_ieee_isnan (dval))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
95 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
96 int ival = NINT (dval);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
97
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
98 if (ival == dval)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
99 retval = ival;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
100 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
101 conv_err = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
102 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
103 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
104 conv_err = 2;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
105 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
106
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
107 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
108 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
109
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
110 static int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
111 get_size (double d, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
112 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
113 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
114
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
115 if (lo_ieee_isnan (d))
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
116 ::error ("%s: NaN is invalid as size specification", who.c_str ());
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
117
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
118 if (xisinf (d))
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
119 retval = -1;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
120 else
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
121 {
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
122 if (d < 0.0)
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
123 ::error ("%s: negative value invalid as size specification",
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
124 who.c_str ());
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
125
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
126 retval = NINT (d);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
127 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
128
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
129 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
130 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
131
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
132 static void
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
133 get_size (const Array<double>& size, octave_idx_type& nr, octave_idx_type& nc,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
134 bool& one_elt_size_spec, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
135 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
136 nr = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
137 nc = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
138
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
139 one_elt_size_spec = false;
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
140
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
141 double dnr = -1.0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
142 double dnc = -1.0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
143
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20230
diff changeset
144 octave_idx_type sz_len = size.numel ();
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
145
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
146 if (sz_len == 1)
2601
3723512a827a [project @ 1997-01-06 05:43:16 by jwe]
jwe
parents: 2600
diff changeset
147 {
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
148 one_elt_size_spec = true;
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
149
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
150 dnr = size(0);
4293
977f977fb2c3 [project @ 2003-01-06 18:18:14 by jwe]
jwe
parents: 4257
diff changeset
151
977f977fb2c3 [project @ 2003-01-06 18:18:14 by jwe]
jwe
parents: 4257
diff changeset
152 dnc = (dnr == 0.0) ? 0.0 : 1.0;
2601
3723512a827a [project @ 1997-01-06 05:43:16 by jwe]
jwe
parents: 2600
diff changeset
153 }
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
154 else if (sz_len == 2)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
155 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
156 dnr = size(0);
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
157
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
158 if (xisinf (dnr))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
159 ::error ("%s: invalid size specification", who.c_str ());
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
160
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
161 dnc = size(1);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
162 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
163 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
164 ::error ("%s: invalid size specification", who.c_str ());
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
165
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
166 nr = get_size (dnr, who);
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
167
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
168 if (dnc >= 0.0)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
169 nc = get_size (dnc, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
170 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
171
21477
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
172 class
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
173 scanf_format_elt
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
174 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
175 public:
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
176
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
177 enum special_conversion
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
178 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
179 whitespace_conversion = 1,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
180 literal_conversion = 2,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
181 null = 3
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
182 };
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 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
185 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
186 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
187 : 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
188 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
189 { }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
190
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
191 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
192 : 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
193 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
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& 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
197 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
198 if (this != &e)
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 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
201 width = e.width;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
202 discard = e.discard;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
203 type = e.type;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
204 modifier = e.modifier;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
205 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
206 }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
207
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
208 return *this;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
209 }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
210
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
211 ~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
212
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
213 // 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
214 const char *text;
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 // 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
217 int width;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
218
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
219 // 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
220 bool discard;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
221
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
222 // 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
223 // '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
224 char type;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
225
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
226 // 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
227 char modifier;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
228
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
229 // 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
230 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
231 };
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
232
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
233 class
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
234 scanf_format_list
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
235 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
236 public:
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 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
239
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
240 ~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
241
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
242 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
243
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
244 // 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
245 // 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
246 // 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
247 // last conversion.
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 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
250
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
251 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
252 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
253 curr_idx = 0;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
254 return current ();
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
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
257 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
258 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
259 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
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 *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
263 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
264 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
265 (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
266
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
267 curr_idx++;
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 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
270 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
271 if (cycle)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
272 curr_idx = 0;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
273 else
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
274 return &dummy;
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
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
277 return current ();
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
278 }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
279
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
280 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
281
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
282 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
283
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
284 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
285
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
286 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
287
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
288 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
289
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
290 private:
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
291
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
292 // 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
293 // 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
294 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
295
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
296 // 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
297 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
298
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
299 // 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
300 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
301
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
302 // Temporary buffer.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
303 std::ostringstream *buf;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
304
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
305 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
306 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
307
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
308 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
309 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
310 char& modifier);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
311
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
312 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
313 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
314 char modifier);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
315 // No copying!
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 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
318
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
319 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
320 };
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
321
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
322 scanf_format_list::scanf_format_list (const std::string& s)
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
323 : nconv (0), curr_idx (0), fmt_elts (), buf (0)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
324 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
325 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
326
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
327 size_t i = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
328
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
329 int width = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
330 bool discard = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
331 char modifier = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
332 char type = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
333
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
334 bool have_more = true;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
335
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
336 while (i < n)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
337 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
338 have_more = true;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
339
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
340 if (! buf)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
341 buf = new std::ostringstream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
342
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
343 if (s[i] == '%')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
344 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
345 // Process percent-escape conversion type.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
346
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
347 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
348
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
349 have_more = (buf != 0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
350 }
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
351 else if (isspace (s[i]))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
352 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
353 type = scanf_format_elt::whitespace_conversion;
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 width = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
356 discard = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
357 modifier = '\0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
358 *buf << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
359
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
360 while (++i < n && isspace (s[i]))
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
361 ; // skip whitespace
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
362
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
363 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
364
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
365 have_more = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
366 }
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
367 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
368 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
369 type = scanf_format_elt::literal_conversion;
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 width = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
372 discard = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
373 modifier = '\0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
374
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
375 while (i < n && ! isspace (s[i]) && s[i] != '%')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
376 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
377
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
378 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
379
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
380 have_more = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
381 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
382
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
383 if (nconv < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
384 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
385 have_more = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
386 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
387 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
388 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
389
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
390 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
391 add_elt_to_list (width, discard, type, modifier);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
392
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
393 delete buf;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
394 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
395
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
396 scanf_format_list::~scanf_format_list (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
397 {
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
398 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
399
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
400 for (size_t i = 0; i < n; i++)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
401 {
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
402 scanf_format_elt *elt = fmt_elts[i];
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
403 delete elt;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
404 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
405 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
406
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
407 void
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
408 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
409 char modifier,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
410 const std::string& char_class)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
411 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
412 if (buf)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
413 {
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
414 std::string text = buf->str ();
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
415
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
416 if (! text.empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
417 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
418 scanf_format_elt *elt
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
419 = new scanf_format_elt (text.c_str (), width, discard, type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
420 modifier, char_class);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
421
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
422 fmt_elts.push_back (elt);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
423 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
424
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
425 delete buf;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
426 buf = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
427 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
428 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
429
3535
c5ebcd5d25a9 [project @ 2000-02-02 11:55:49 by jwe]
jwe
parents: 3534
diff changeset
430 static std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
431 expand_char_class (const std::string& s)
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
432 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
433 std::string retval;
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
434
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
435 size_t len = s.length ();
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
436
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
437 size_t i = 0;
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
438
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
439 while (i < len)
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
440 {
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
441 unsigned char c = s[i++];
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
442
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
443 if (c == '-' && i > 1 && i < len
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
444 && ( static_cast<unsigned char> (s[i-2])
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
445 <= static_cast<unsigned char> (s[i])))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
446 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
447 // Add all characters from the range except the first (we
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
448 // already added it below).
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
449
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
450 for (c = s[i-2]+1; c < s[i]; c++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
451 retval += c;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
452 }
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
453 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
454 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
455 // Add the character to the class. Only add '-' if it is
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
456 // the last character in the class.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
457
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
458 if (c != '-' || i == len)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
459 retval += c;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
460 }
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
461 }
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
462
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
463 return retval;
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
464 }
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
465
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
466 void
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
467 scanf_format_list::process_conversion (const std::string& s, size_t& i,
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
468 size_t n, int& width, bool& discard,
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
469 char& type, char& modifier)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
470 {
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
471 width = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
472 discard = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
473 modifier = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
474 type = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
475
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
476 *buf << s[i++];
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
477
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
478 bool have_width = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
479
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
480 while (i < n)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
481 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
482 switch (s[i])
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
483 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
484 case '*':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
485 if (discard)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
486 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
487 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
488 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
489 discard = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
490 *buf << s[i++];
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;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
503 *buf << c;
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';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
508 *buf << c;
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.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
536 *buf << 'l';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
537
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
538 goto fini;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
539
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
540 case 'c': case 's': case 'p': case '%': case '[':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
541 if (modifier != '\0')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
542 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
543 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
544 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
545 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
546 goto fini;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
547
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
548 fini:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
549 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
550 if (finish_conversion (s, i, n, width, discard,
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
551 type, modifier) == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
552 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
553 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
554 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
555
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
556 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
557 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
558 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
559 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
560
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
561 if (nconv < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
562 break;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
563 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
564
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
565 nconv = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
566 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
567
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
568 int
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
569 scanf_format_list::finish_conversion (const std::string& s, size_t& i,
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
570 size_t n, int& width, bool discard,
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
571 char& type, char modifier)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
572 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
573 int retval = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
574
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
575 std::string char_class;
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
576
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
577 size_t beg_idx = std::string::npos;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
578 size_t end_idx = std::string::npos;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
579
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
580 if (s[i] == '%')
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
581 {
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
582 type = '%';
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
583 *buf << s[i++];
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
584 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
585 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
586 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
587 type = s[i];
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
588
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
589 if (s[i] == '[')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
590 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
591 *buf << s[i++];
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 = '^';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
600 *buf << s[i++];
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] == ']')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
607 *buf << s[i++];
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] == ']')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
611 *buf << s[i++];
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] != ']')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
615 *buf << s[i++];
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;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
620 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
621 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
622
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
623 if (s[i-1] != ']')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
624 retval = nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
625 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
626 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
627 *buf << s[i++];
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
628
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
629 nconv++;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
630 }
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
631
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
632 if (nconv >= 0)
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
633 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
634 if (beg_idx != std::string::npos && end_idx != std::string::npos)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
635 char_class = expand_char_class (s.substr (beg_idx,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
636 end_idx - beg_idx + 1));
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
637
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
638 add_elt_to_list (width, discard, type, modifier, char_class);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
639 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
640
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
641 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
642 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
643
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
644 void
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
645 scanf_format_list::printme (void) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
646 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
647 size_t n = fmt_elts.size ();
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
648
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
649 for (size_t i = 0; i < n; i++)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
650 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
651 scanf_format_elt *elt = fmt_elts[i];
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
652
3531
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
653 std::cerr
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
654 << "width: " << elt->width << "\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
655 << "discard: " << elt->discard << "\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
656 << "type: ";
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
657
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
658 if (elt->type == scanf_format_elt::literal_conversion)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
659 std::cerr << "literal text\n";
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
660 else if (elt->type == scanf_format_elt::whitespace_conversion)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
661 std::cerr << "whitespace\n";
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
662 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
663 std::cerr << elt->type << "\n";
3531
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
664
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
665 std::cerr
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
666 << "modifier: " << elt->modifier << "\n"
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
667 << "char_class: '" << undo_string_escapes (elt->char_class) << "'\n"
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
668 << "text: '" << undo_string_escapes (elt->text) << "'\n\n";
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
669 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
670 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
671
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
672 bool
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
673 scanf_format_list::all_character_conversions (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
674 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
675 size_t n = fmt_elts.size ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
676
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
677 if (n > 0)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
678 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
679 for (size_t i = 0; i < n; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
680 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
681 scanf_format_elt *elt = fmt_elts[i];
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
682
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
683 switch (elt->type)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
684 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
685 case 'c': case 's': case '%': case '[': case '^':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
686 case scanf_format_elt::literal_conversion:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
687 case scanf_format_elt::whitespace_conversion:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
688 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
689
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
690 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
691 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
692 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
693 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
694 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
695
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
696 return true;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
697 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
698 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
699 return false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
700 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
701
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
702 bool
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
703 scanf_format_list::all_numeric_conversions (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
704 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
705 size_t n = fmt_elts.size ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
706
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
707 if (n > 0)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
708 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
709 for (size_t i = 0; i < n; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
710 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
711 scanf_format_elt *elt = fmt_elts[i];
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
712
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
713 switch (elt->type)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
714 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
715 case 'd': case 'i': case 'o': case 'u': case 'x':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
716 case 'e': case 'f': case 'g':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
717 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
718
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
719 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
720 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
721 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
722 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
723 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
724
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
725 return true;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
726 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
727 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
728 return false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
729 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
730
21477
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
731 class
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
732 printf_format_elt
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
733 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
734 public:
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
735
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
736 printf_format_elt (const char *txt = 0, int n = 0, int w = -1,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
737 int p = -1, const std::string& f = "",
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
738 char typ = '\0', char mod = '\0')
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
739 : text (strsave (txt)), args (n), fw (w), prec (p), flags (f),
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
740 type (typ), modifier (mod)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
741 { }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
742
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
743 printf_format_elt (const printf_format_elt& e)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
744 : text (strsave (e.text)), args (e.args), fw (e.fw), prec (e.prec),
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
745 flags (e.flags), type (e.type), modifier (e.modifier)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
746 { }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
747
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
748 printf_format_elt& operator = (const printf_format_elt& e)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
749 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
750 if (this != &e)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
751 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
752 text = strsave (e.text);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
753 args = e.args;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
754 fw = e.fw;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
755 prec = e.prec;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
756 flags = e.flags;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
757 type = e.type;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
758 modifier = e.modifier;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
759 }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
760
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
761 return *this;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
762 }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
763
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
764 ~printf_format_elt (void) { delete [] text; }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
765
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
766 // The C-style format string.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
767 const char *text;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
768
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
769 // How many args do we expect to consume?
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
770 int args;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
771
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
772 // Field width.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
773 int fw;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
774
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
775 // Precision.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
776 int prec;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
777
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
778 // Flags -- '-', '+', ' ', '0', or '#'.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
779 std::string flags;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
780
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
781 // Type of conversion -- 'd', 'i', 'o', 'x', 'X', 'u', 'c', 's',
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
782 // 'f', 'e', 'E', 'g', 'G', 'p', or '%'
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
783 char type;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
784
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
785 // A length modifier -- 'h', 'l', or 'L'.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
786 char modifier;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
787 };
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
788
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
789 class
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
790 printf_format_list
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
791 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
792 public:
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
793
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
794 printf_format_list (const std::string& fmt = "");
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
795
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
796 ~printf_format_list (void);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
797
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
798 octave_idx_type num_conversions (void) { return nconv; }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
799
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
800 const printf_format_elt *first (void)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
801 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
802 curr_idx = 0;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
803 return current ();
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
804 }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
805
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
806 const printf_format_elt *current (void) const
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
807 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
808 return length () > 0 ? fmt_elts[curr_idx] : 0;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
809 }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
810
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
811 size_t length (void) const { return fmt_elts.size (); }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
812
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
813 const printf_format_elt *next (bool cycle = true)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
814 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
815 curr_idx++;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
816
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
817 if (curr_idx >= length ())
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
818 {
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
819 if (cycle)
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
820 curr_idx = 0;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
821 else
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
822 return 0;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
823 }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
824
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
825 return current ();
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
826 }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
827
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
828 bool last_elt_p (void) { return (curr_idx + 1 == length ()); }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
829
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
830 void printme (void) const;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
831
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
832 bool ok (void) const { return (nconv >= 0); }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
833
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
834 operator bool () const { return ok (); }
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
835
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
836 private:
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
837
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
838 // Number of conversions specified by this format string, or -1 if
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
839 // invalid conversions have been found.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
840 octave_idx_type nconv;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
841
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
842 // Index to current element;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
843 size_t curr_idx;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
844
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
845 // List of format elements.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
846 std::deque<printf_format_elt*> fmt_elts;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
847
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
848 // Temporary buffer.
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
849 std::ostringstream *buf;
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
850
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
851 void add_elt_to_list (int args, const std::string& flags, int fw,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
852 int prec, char type, char modifier);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
853
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
854 void process_conversion (const std::string& s, size_t& i, size_t n,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
855 int& args, std::string& flags, int& fw,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
856 int& prec, char& modifier, char& type);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
857
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
858 void finish_conversion (const std::string& s, size_t& i, int args,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
859 const std::string& flags, int fw, int prec,
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
860 char modifier, char& type);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
861
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
862 // No copying!
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
863
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
864 printf_format_list (const printf_format_list&);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
865
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
866 printf_format_list& operator = (const printf_format_list&);
4fc04d04dd9c make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents: 21475
diff changeset
867 };
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
868
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
869 printf_format_list::printf_format_list (const std::string& s)
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
870 : nconv (0), curr_idx (0), fmt_elts (), buf (0)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
871 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
872 size_t n = s.length ();
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
873
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
874 size_t i = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
875
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
876 int args = 0;
3643
3af6d00b82ed [project @ 2000-03-24 10:53:21 by jwe]
jwe
parents: 3640
diff changeset
877 std::string flags;
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
878 int fw = -1;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
879 int prec = -1;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
880 char modifier = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
881 char type = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
882
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
883 bool have_more = true;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
884 bool empty_buf = true;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
885
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
886 if (n == 0)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
887 {
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
888 printf_format_elt *elt
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
889 = new printf_format_elt ("", args, fw, prec, flags, type, modifier);
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
890
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
891 fmt_elts.push_back (elt);
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
892 }
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
893 else
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
894 {
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
895 while (i < n)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
896 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
897 have_more = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
898
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
899 if (! buf)
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 buf = new std::ostringstream ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
902 empty_buf = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
903 }
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 switch (s[i])
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 case '%':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
908 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
909 if (empty_buf)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
910 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
911 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
912 type, modifier);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
913
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
914 have_more = (buf != 0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
915 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
916 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
917 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
918 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
919 break;
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 default:
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 args = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
924 flags = "";
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
925 fw = -1;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
926 prec = -1;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
927 modifier = '\0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
928 type = '\0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
929 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
930 empty_buf = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
931 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
932 break;
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
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
935 if (nconv < 0)
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 have_more = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
938 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
939 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
940 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
941
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
942 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
943 add_elt_to_list (args, flags, fw, prec, type, modifier);
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
944
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
945 delete buf;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
946 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
947 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
948
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
949 printf_format_list::~printf_format_list (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
950 {
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
951 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
952
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
953 for (size_t i = 0; i < n; i++)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
954 {
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
955 printf_format_elt *elt = fmt_elts[i];
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
956 delete elt;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
957 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
958 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
959
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
960 void
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
961 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
962 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
963 char modifier)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
964 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
965 if (buf)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
966 {
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
967 std::string text = buf->str ();
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
968
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
969 if (! text.empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
970 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
971 printf_format_elt *elt
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
972 = new printf_format_elt (text.c_str (), args, fw, prec, flags,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
973 type, modifier);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
974
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
975 fmt_elts.push_back (elt);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
976 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
977
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
978 delete buf;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
979 buf = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
980 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
981 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
982
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
983 void
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
984 printf_format_list::process_conversion (const std::string& s, size_t& i,
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
985 size_t n, int& args,
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
986 std::string& flags, int& fw,
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
987 int& prec, char& modifier,
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
988 char& type)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
989 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
990 args = 0;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
991 flags = "";
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
992 fw = -1;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
993 prec = -1;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
994 modifier = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
995 type = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
996
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
997 *buf << s[i++];
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
998
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4574
diff changeset
999 bool nxt = false;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1000
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1001 while (i < n)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1002 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1003 switch (s[i])
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1004 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1005 case '-': case '+': case ' ': case '0': case '#':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1006 flags += s[i];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1007 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1008 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1009
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1010 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1011 nxt = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1012 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1013 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1014
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4574
diff changeset
1015 if (nxt)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1016 break;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1017 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1018
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1019 if (i < n)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1020 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1021 if (s[i] == '*')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1022 {
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1023 fw = -2;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1024 args++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1025 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1026 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1027 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1028 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1029 if (isdigit (s[i]))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1030 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1031 int nn = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1032 std::string tmp = s.substr (i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1033 sscanf (tmp.c_str (), "%d%n", &fw, &nn);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1034 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1035
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1036 while (i < n && isdigit (s[i]))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1037 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1038 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1039 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1040
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1041 if (i < n && s[i] == '.')
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1042 {
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1043 // nothing before the . means 0.
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1044 if (fw == -1)
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1045 fw = 0;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1046
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1047 // . followed by nothing is 0.
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1048 prec = 0;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1049
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1050 *buf << s[i++];
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1051
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1052 if (i < n)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1053 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1054 if (s[i] == '*')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1055 {
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1056 prec = -2;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1057 args++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1058 *buf << s[i++];
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]))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1070 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1071 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1072 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1073 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1074
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1075 if (i < n)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1076 {
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
1077 // Accept and record modifier, but don't place it in the format
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
1078 // item text. All integer conversions are handled as 64-bit
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
1079 // integers.
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
1080
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1081 switch (s[i])
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1082 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1083 case 'h': case 'l': case 'L':
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
1084 modifier = s[i++];
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1085 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1086
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1087 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1088 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1089 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1090 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1091
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1092 if (i < n)
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
1093 finish_conversion (s, i, args, flags, fw, prec, modifier, type);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1094 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1095 nconv = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1096 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1097
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1098 void
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1099 printf_format_list::finish_conversion (const std::string& s, size_t& i,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1100 int args, const std::string& flags,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1101 int fw, int prec, char modifier,
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
1102 char& type)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1103 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1104 switch (s[i])
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1105 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1106 case 'd': case 'i': case 'o': case 'x': case 'X':
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1107 case 'u': case 'c':
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1108 if (modifier == 'L')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1109 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1110 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1111 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1112 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1113 goto fini;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1114
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1115 case 'f': case 'e': case 'E': case 'g': case 'G':
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1116 if (modifier == 'h' || modifier == 'l')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1117 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1118 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1119 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1120 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1121 goto fini;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1122
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1123 case 's': case 'p': case '%':
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1124 if (modifier != '\0')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1125 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1126 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1127 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1128 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1129 goto fini;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1130
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1131 fini:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1132
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1133 type = s[i];
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1134
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1135 *buf << s[i++];
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1136
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1137 if (type != '%' || args != 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1138 nconv++;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1139
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1140 if (type != '%')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1141 args++;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1142
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
1143 add_elt_to_list (args, flags, fw, prec, type, modifier);
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1144
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1145 break;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1146
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1147 default:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1148 nconv = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1149 break;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1150 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1151 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1152
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1153 void
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1154 printf_format_list::printme (void) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1155 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
1156 size_t n = fmt_elts.size ();
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
1157
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
1158 for (size_t i = 0; i < n; i++)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1159 {
21475
4f3e63d75f33 use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents: 21354
diff changeset
1160 printf_format_elt *elt = fmt_elts[i];
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1161
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1162 std::cerr
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1163 << "args: " << elt->args << "\n"
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1164 << "flags: '" << elt->flags << "'\n"
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1165 << "width: " << elt->fw << "\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1166 << "prec: " << elt->prec << "\n"
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1167 << "type: '" << elt->type << "'\n"
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1168 << "modifier: '" << elt->modifier << "'\n"
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1169 << "text: '" << undo_string_escapes (elt->text) << "'\n\n";
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1170 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1171 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1172
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1173 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1174 octave_base_stream::error (const std::string& msg)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1175 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1176 fail = true;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1177 errmsg = msg;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1178 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1179
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1180 void
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
1181 octave_base_stream::error (const std::string& who, const std::string& msg)
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
1182 {
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
1183 fail = true;
6296
85eb75190e01 [project @ 2007-02-10 07:10:42 by jwe]
jwe
parents: 6109
diff changeset
1184 errmsg = who + ": " + msg;
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
1185 }
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
1186
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
1187 void
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1188 octave_base_stream::clear (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1189 {
4889
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
1190 fail = false;
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
1191 errmsg = "";
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
1192 }
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
1193
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
1194 void
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
1195 octave_base_stream::clearerr (void)
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
1196 {
4888
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
1197 std::istream *is = input_stream ();
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
1198 std::ostream *os = output_stream ();
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
1199
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
1200 if (is)
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
1201 is->clear ();
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
1202
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
1203 if (os)
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
1204 os->clear ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1205 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1206
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1207 // Functions that are defined for all input streams (input streams
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1208 // are those that define is).
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1209
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
1210 std::string
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1211 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
1212 bool strip_newline, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1213 {
19849
1c9ed5b4c73d input.h: change meaning of interactive and forced_interactive global variables.
Carnë Draug <carandraug@octave.org>
parents: 19739
diff changeset
1214 if (interactive && file_number () == 0)
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20768
diff changeset
1215 ::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
1216 who.c_str ());
8773
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
1217
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1218 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1219
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1220 err = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1221
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1222 std::istream *isp = input_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1223
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1224 if (! isp)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1225 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1226 err = true;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1227 invalid_operation (who, "reading");
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1228 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1229 else
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1230 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1231 std::istream& is = *isp;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1232
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
1233 std::ostringstream buf;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1234
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1235 int c = 0;
3553
c5600b44bef9 [project @ 2000-02-03 03:22:37 by jwe]
jwe
parents: 3552
diff changeset
1236 int char_count = 0;
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
1237
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
1238 if (max_len != 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1239 {
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1240 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
1241 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1242 char_count++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1243
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1244 // Handle CRLF, CR, or LF as line ending.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1245 if (c == '\r')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1246 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1247 if (! strip_newline)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1248 buf << static_cast<char> (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1249
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1250 c = is.get ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1251
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1252 if (c != std::istream::traits_type::eof ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1253 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1254 if (c == '\n')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1255 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1256 char_count++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1257
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1258 if (! strip_newline)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1259 buf << static_cast<char> (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1260 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1261 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1262 is.putback (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1263 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1264
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1265 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1266 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1267 else if (c == '\n')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1268 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1269 if (! strip_newline)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1270 buf << static_cast<char> (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1271
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1272 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1273 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1274 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1275 buf << static_cast<char> (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1276
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1277 if (max_len > 0 && char_count == max_len)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1278 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1279 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1280 }
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
1281
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
1282 if (! is.eof () && char_count > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1283 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1284 // 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
1285 // 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
1286 // corresponding C-library functions do.
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1287 int disgusting_compatibility_hack = is.get ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1288 if (! is.eof ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1289 is.putback (disgusting_compatibility_hack);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1290 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1291
4224
0179e6309248 [project @ 2002-12-18 00:34:29 by jwe]
jwe
parents: 4223
diff changeset
1292 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
1293 retval = buf.str ();
4224
0179e6309248 [project @ 2002-12-18 00:34:29 by jwe]
jwe
parents: 4223
diff changeset
1294 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1295 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1296 err = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1297
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1298 if (is.eof () && char_count == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1299 error (who, "at end of file");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1300 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1301 error (who, "read error");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1302 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1303 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1304
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1305 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1306 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1307
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
1308 std::string
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1309 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
1310 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1311 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
1312 return do_gets (max_len, err, true, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1313 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1314
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
1315 std::string
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1316 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
1317 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1318 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
1319 return do_gets (max_len, err, false, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1320 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1321
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
1322 off_t
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
1323 octave_base_stream::skipl (off_t num, bool& err, const std::string& who)
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1324 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1325 if (interactive && file_number () == 0)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1326 ::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
1327 who.c_str ());
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1328
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
1329 off_t cnt = -1;
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1330
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1331 err = false;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1332
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1333 std::istream *isp = input_stream ();
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1334
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1335 if (! isp)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1336 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1337 err = true;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1338 invalid_operation (who, "reading");
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1339 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1340 else
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1341 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1342 std::istream& is = *isp;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1343
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17787
diff changeset
1344 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
1345 int lastc = -1;
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1346 cnt = 0;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1347
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1348 while (is && (c = is.get ()) != std::istream::traits_type::eof ())
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1349 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1350 // Handle CRLF, CR, or LF as line ending.
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1351 if (c == '\r' || (c == '\n' && lastc != '\r'))
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1352 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1353 if (++cnt == num)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1354 break;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1355 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1356
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1357 lastc = c;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1358 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1359
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1360 // Maybe eat the following \n if \r was just met.
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1361 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
1362 is.get ();
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1363
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1364 if (is.bad ())
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1365 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1366 err = true;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1367 error (who, "read error");
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1368 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1369
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1370 if (err)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1371 cnt = -1;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1372 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1373
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1374 return cnt;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1375 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1376
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1377 template <typename T>
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1378 std::istream&
6767
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1379 octave_scan_1 (std::istream& is, const scanf_format_elt& fmt, T* valptr)
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1380 {
3779
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1381 T& ref = *valptr;
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1382
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1383 switch (fmt.type)
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1384 {
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1385 case 'o':
4926
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
1386 is >> std::oct >> ref >> std::dec;
3779
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1387 break;
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1388
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1389 case 'x':
4926
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
1390 is >> std::hex >> ref >> std::dec;
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
1391 break;
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
1392
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
1393 case 'i':
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
1394 {
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1395 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
1396
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1397 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
1398 && isspace (c1))
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
1399 ; // skip whitespace
14675
757f729fd41d skip leading whitespace for scanf %i format
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1400
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1401 if (c1 != std::istream::traits_type::eof ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1402 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1403 if (c1 == '0')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1404 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1405 int c2 = is.peek ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1406
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1407 if (c2 == 'x' || c2 == 'X')
7709
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
1408 {
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
1409 is.ignore ();
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
1410 if (std::isxdigit (is.peek ()))
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
1411 is >> std::hex >> ref >> std::dec;
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
1412 else
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
1413 ref = 0;
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
1414 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1415 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1416 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1417 if (c2 == '0' || c2 == '1' || c2 == '2'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1418 || c2 == '3' || c2 == '4' || c2 == '5'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1419 || c2 == '6' || c2 == '7')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1420 is >> std::oct >> ref >> std::dec;
21114
47908b818865 oct-stream.cc: Add FIXME note about bug #46493.
Rik <rik@octave.org>
parents: 21102
diff changeset
1421 else if (c2 == '8' || c2 == '9')
47908b818865 oct-stream.cc: Add FIXME note about bug #46493.
Rik <rik@octave.org>
parents: 21102
diff changeset
1422 {
47908b818865 oct-stream.cc: Add FIXME note about bug #46493.
Rik <rik@octave.org>
parents: 21102
diff changeset
1423 // 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
1424 // 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
1425 // error ("internal failure to match octal format");
47908b818865 oct-stream.cc: Add FIXME note about bug #46493.
Rik <rik@octave.org>
parents: 21102
diff changeset
1426 ref = 0;
47908b818865 oct-stream.cc: Add FIXME note about bug #46493.
Rik <rik@octave.org>
parents: 21102
diff changeset
1427 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1428 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1429 ref = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1430 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1431 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1432 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1433 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1434 is.putback (c1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1435
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1436 is >> ref;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1437 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1438 }
4926
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
1439 }
3779
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1440 break;
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1441
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1442 default:
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1443 is >> ref;
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1444 break;
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1445 }
3639
fed1847dfd6c [project @ 2000-03-24 05:12:46 by jwe]
jwe
parents: 3638
diff changeset
1446
3638
a76fa215a476 [project @ 2000-03-24 04:53:45 by jwe]
jwe
parents: 3637
diff changeset
1447 return is;
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1448 }
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1449
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1450 template <typename T>
6767
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1451 std::istream&
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1452 octave_scan (std::istream& is, const scanf_format_elt& fmt, T* valptr)
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1453 {
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1454 if (fmt.width)
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1455 {
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1456 // Limit input to fmt.width characters by reading into a
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1457 // temporary stringstream buffer.
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1458 std::string tmp;
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1459
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1460 is.width (fmt.width);
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1461 is >> tmp;
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1462
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1463 std::istringstream ss (tmp);
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1464
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1465 octave_scan_1 (ss, fmt, valptr);
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1466 }
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1467 else
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1468 octave_scan_1 (is, fmt, valptr);
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1469
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1470 return is;
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1471 }
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1472
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1473 // Note that this specialization is only used for reading characters, not
3779
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1474 // character strings. See BEGIN_S_CONVERSION for details.
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1475
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1476 template <>
3779
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1477 std::istream&
4661
12b6fbd57436 [project @ 2003-11-25 05:41:35 by jwe]
jwe
parents: 4649
diff changeset
1478 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
1479 char* valptr)
3779
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1480 {
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1481 return is >> valptr;
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1482 }
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1483
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1484 template <>
5176
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1485 std::istream&
5403
7bdddf96f028 [project @ 2005-07-07 16:46:23 by jwe]
jwe
parents: 5389
diff changeset
1486 octave_scan<> (std::istream& is, const scanf_format_elt& fmt, double* valptr)
5176
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1487 {
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1488 double& ref = *valptr;
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1489
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1490 switch (fmt.type)
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1491 {
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1492 case 'e':
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1493 case 'f':
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1494 case 'g':
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1495 {
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1496 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
1497
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1498 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
1499 && isspace (c1))
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
1500 ; // skip whitespace
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1501
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1502 if (c1 != std::istream::traits_type::eof ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1503 {
12936
b74cb659e757 accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
1504 is.putback (c1);
b74cb659e757 accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
1505
b74cb659e757 accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
1506 ref = octave_read_value<double> (is);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1507 }
5176
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1508 }
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1509 break;
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1510
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1511 default:
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1512 panic_impossible ();
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1513 break;
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1514 }
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1515
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1516 return is;
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1517 }
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1518
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1519 template <typename T>
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1520 void
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1521 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
1522 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
1523 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
1524 octave_idx_type max_size, bool discard)
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1525 {
21147
95feb42d7a97 * oct-stream.cc (OCTAVE_SCAN): Eliminate trivial macro.
John W. Eaton <jwe@octave.org>
parents: 21139
diff changeset
1526 octave_scan (is, fmt, valptr);
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1527
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1528 if (! is)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1529 return;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1530
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1531 if (idx == max_size && ! discard)
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1532 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1533 max_size *= 2;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1534
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1535 if (nr > 0)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1536 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
1537 else
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1538 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
1539
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1540 data = mval.fortran_vec ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1541 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1542
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1543 if (! discard)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1544 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1545 conversion_count++;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1546 data[idx++] = *(valptr);
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1547 }
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1548 }
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1549
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1550 template void
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1551 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
1552 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
1553 octave_idx_type, octave_idx_type, bool);
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1554
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1555 #define DO_WHITESPACE_CONVERSION() \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1556 do \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1557 { \
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1558 int c = std::istream::traits_type::eof (); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1559 \
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1560 while (is && (c = 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
1561 && isspace (c)) \
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1562 { /* skip whitespace */ } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1563 \
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1564 if (c != std::istream::traits_type::eof ()) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1565 is.putback (c); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1566 } \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1567 while (0)
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1568
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1569 #define DO_LITERAL_CONVERSION() \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1570 do \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1571 { \
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1572 int c = std::istream::traits_type::eof (); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1573 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1574 int n = strlen (fmt); \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1575 int i = 0; \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1576 \
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1577 while (i < n && 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
1578 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1579 if (c == static_cast<unsigned char> (fmt[i])) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1580 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1581 i++; \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1582 continue; \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1583 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1584 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1585 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1586 is.putback (c); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1587 break; \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1588 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1589 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1590 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1591 if (i != n) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1592 is.setstate (std::ios::failbit); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1593 } \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1594 while (0)
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1595
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1596 #define DO_PCT_CONVERSION() \
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1597 do \
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1598 { \
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1599 int c = is.get (); \
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1600 \
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1601 if (c != std::istream::traits_type::eof ()) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1602 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1603 if (c != '%') \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1604 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1605 is.putback (c); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1606 is.setstate (std::ios::failbit); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1607 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1608 } \
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1609 else \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1610 is.setstate (std::ios::failbit); \
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1611 } \
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1612 while (0)
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1613
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1614 #define BEGIN_C_CONVERSION() \
3538
0ff7323dab8b [project @ 2000-02-02 12:36:25 by jwe]
jwe
parents: 3536
diff changeset
1615 is.unsetf (std::ios::skipws); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1616 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1617 int width = elt->width ? elt->width : 1; \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1618 \
9952
7cd2e1b372e5 allow scanf to store ASCII NUL values
John W. Eaton <jwe@octave.org>
parents: 9941
diff changeset
1619 std::string tmp (width, '\0'); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1620 \
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1621 int c = std::istream::traits_type::eof (); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1622 int n = 0; \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1623 \
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1624 while (is && n < width && (c = is.get ()) != std::istream::traits_type::eof ()) \
9952
7cd2e1b372e5 allow scanf to store ASCII NUL values
John W. Eaton <jwe@octave.org>
parents: 9941
diff changeset
1625 tmp[n++] = static_cast<char> (c); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1626 \
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1627 if (n > 0 && c == std::istream::traits_type::eof ()) \
12984
7626f8934466 correctly resize scanf output for %c formats (bug #34037)
John W. Eaton <jwe@octave.org>
parents: 12966
diff changeset
1628 is.clear (); \
7626f8934466 correctly resize scanf output for %c formats (bug #34037)
John W. Eaton <jwe@octave.org>
parents: 12966
diff changeset
1629 \
7626f8934466 correctly resize scanf output for %c formats (bug #34037)
John W. Eaton <jwe@octave.org>
parents: 12966
diff changeset
1630 tmp.resize (n)
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1631
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1632 // For a '%s' format, skip initial whitespace and then read until the
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1633 // next whitespace character or until WIDTH characters have been read.
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1634 #define BEGIN_S_CONVERSION() \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1635 int width = elt->width; \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1636 \
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
1637 std::string tmp; \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1638 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1639 do \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1640 { \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1641 if (width) \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1642 { \
10076
4b270d1540f7 avoid various GCC warnings
John W. Eaton <jwe@octave.org>
parents: 9952
diff changeset
1643 tmp = std::string (width, '\0'); \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1644 \
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1645 int c = std::istream::traits_type::eof (); \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1646 \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1647 int n = 0; \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1648 \
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1649 while (is && (c = is.get ()) != std::istream::traits_type::eof ()) \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1650 { \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1651 if (! isspace (c)) \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1652 { \
9952
7cd2e1b372e5 allow scanf to store ASCII NUL values
John W. Eaton <jwe@octave.org>
parents: 9941
diff changeset
1653 tmp[n++] = static_cast<char> (c); \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1654 break; \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1655 } \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1656 } \
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
1657 \
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1658 while (is && n < width \
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1659 && (c = is.get ()) != std::istream::traits_type::eof ()) \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1660 { \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1661 if (isspace (c)) \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1662 { \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1663 is.putback (c); \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1664 break; \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1665 } \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1666 else \
9952
7cd2e1b372e5 allow scanf to store ASCII NUL values
John W. Eaton <jwe@octave.org>
parents: 9941
diff changeset
1667 tmp[n++] = static_cast<char> (c); \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1668 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1669 \
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1670 if (n > 0 && c == std::istream::traits_type::eof ()) \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1671 is.clear (); \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1672 \
9952
7cd2e1b372e5 allow scanf to store ASCII NUL values
John W. Eaton <jwe@octave.org>
parents: 9941
diff changeset
1673 tmp.resize (n); \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1674 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1675 else \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1676 { \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1677 is >> std::ws >> tmp; \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1678 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1679 } \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1680 while (0)
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1681
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1682 // This format must match a nonempty sequence of characters.
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1683 #define BEGIN_CHAR_CLASS_CONVERSION() \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1684 int width = elt->width; \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1685 \
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
1686 std::string tmp; \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1687 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1688 do \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1689 { \
7426
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1690 if (! width) \
15215
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1691 width = std::numeric_limits<int>::max (); \
7427
65f0a8ced9d2 [project @ 2008-01-28 22:42:18 by jwe]
jwe
parents: 7426
diff changeset
1692 \
7426
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1693 std::ostringstream buf; \
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1694 \
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1695 std::string char_class = elt->char_class; \
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
1696 \
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1697 int c = std::istream::traits_type::eof (); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1698 \
7426
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1699 if (elt->type == '[') \
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1700 { \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1701 int chars_read = 0; \
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1702 while (is && chars_read++ < width \
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1703 && (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
1704 && char_class.find (c) != std::string::npos) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1705 buf << static_cast<char> (c); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1706 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1707 else \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1708 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1709 int chars_read = 0; \
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1710 while (is && chars_read++ < width \
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1711 && (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
1712 && char_class.find (c) == std::string::npos) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1713 buf << static_cast<char> (c); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1714 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1715 \
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1716 if (width == std::numeric_limits<int>::max () \
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1717 && c != std::istream::traits_type::eof ()) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1718 is.putback (c); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1719 \
7426
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1720 tmp = buf.str (); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1721 \
7426
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1722 if (tmp.empty ()) \
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1723 is.setstate (std::ios::failbit); \
21184
3db899f1d54c use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents: 21147
diff changeset
1724 else if (c == std::istream::traits_type::eof ()) \
10969
da355a1a6d44 fix scanf char class conversion bug
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
1725 is.clear (); \
da355a1a6d44 fix scanf char class conversion bug
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
1726 \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1727 } \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1728 while (0)
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1729
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1730 #define FINISH_CHARACTER_CONVERSION() \
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1731 do \
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1732 { \
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
1733 width = tmp.length (); \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1734 \
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1735 if (is) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1736 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1737 int i = 0; \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1738 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1739 if (! discard) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1740 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1741 conversion_count++; \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1742 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1743 while (i < width) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1744 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1745 if (data_index == max_size) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1746 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1747 max_size *= 2; \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1748 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1749 if (all_char_conv) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1750 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1751 if (one_elt_size_spec) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1752 mval.resize (1, max_size, 0.0); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1753 else if (nr > 0) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1754 mval.resize (nr, max_size / nr, 0.0); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1755 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1756 panic_impossible (); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1757 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1758 else if (nr > 0) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1759 mval.resize (nr, max_size / nr, 0.0); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1760 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1761 mval.resize (max_size, 1, 0.0); \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1762 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1763 data = mval.fortran_vec (); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1764 } \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1765 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1766 data[data_index++] = tmp[i++]; \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1767 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1768 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1769 } \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1770 } \
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1771 while (0)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1772
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1773 octave_value
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1774 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
1775 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
1776 bool one_elt_size_spec,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1777 octave_idx_type& conversion_count,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1778 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1779 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1780 if (interactive && file_number () == 0)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1781 ::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
1782 who.c_str ());
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1783
8773
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
1784 octave_value retval = Matrix ();
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
1785
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1786 conversion_count = 0;
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1787
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1788 octave_idx_type nconv = fmt_list.num_conversions ();
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1789
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1790 octave_idx_type data_index = 0;
2121
bc6ecd8f1175 [project @ 1996-05-12 06:45:55 by jwe]
jwe
parents: 2117
diff changeset
1791
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1792 if (nr == 0 || nc == 0)
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1793 {
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1794 if (one_elt_size_spec)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1795 nc = 0;
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1796
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1797 return Matrix (nr, nc, 0.0);
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1798 }
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1799
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1800 std::istream *isp = input_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1801
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1802 bool all_char_conv = fmt_list.all_character_conversions ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1803
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1804 Matrix mval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1805 double *data = 0;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1806 octave_idx_type max_size = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1807 octave_idx_type max_conv = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1808
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1809 octave_idx_type final_nr = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1810 octave_idx_type final_nc = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1811
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1812 if (all_char_conv)
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1813 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1814 // 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
1815 // we may read more than one element for each conversion).
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1816 if (one_elt_size_spec)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1817 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1818 max_size = 512;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1819 mval.resize (1, max_size, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1820
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1821 if (nr > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1822 max_conv = nr;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1823 }
4420
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
1824 else if (nr > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1825 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1826 if (nc > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1827 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1828 mval.resize (nr, nc, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1829 max_size = max_conv = nr * nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1830 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1831 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1832 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1833 mval.resize (nr, 32, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1834 max_size = nr * 32;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1835 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1836 }
4420
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
1837 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1838 panic_impossible ();
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1839 }
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1840 else if (nr > 0)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1841 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1842 if (nc > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1843 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1844 // Will not resize later.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1845 mval.resize (nr, nc, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1846 max_size = nr * nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1847 max_conv = max_size;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1848 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1849 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1850 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1851 // Maybe resize later.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1852 mval.resize (nr, 32, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1853 max_size = nr * 32;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1854 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1855 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1856 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1857 {
4420
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
1858 // Maybe resize later.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1859 mval.resize (32, 1, 0.0);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1860 max_size = 32;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1861 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1862
4420
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
1863 data = mval.fortran_vec ();
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
1864
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1865 if (isp)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1866 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1867 std::istream& is = *isp;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1868
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1869 const scanf_format_elt *elt = fmt_list.first ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1870
3538
0ff7323dab8b [project @ 2000-02-02 12:36:25 by jwe]
jwe
parents: 3536
diff changeset
1871 std::ios::fmtflags flags = is.flags ();
2213
c4a887694274 [project @ 1996-05-16 04:13:28 by jwe]
jwe
parents: 2127
diff changeset
1872
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1873 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
1874
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1875 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
1876
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1877 for (;;)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1878 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1879 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1880
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1881 if (elt)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1882 {
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
1883 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
1884 || (! (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
1885 || 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
1886 || 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
1887 && max_conv > 0 && conversion_count == max_conv))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1888 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
1889 // 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
1890 // 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
1891 // 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
1892 // 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
1893 // Determine final array size and exit.
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1894 if (all_char_conv && one_elt_size_spec)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1895 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1896 final_nr = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1897 final_nc = data_index;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1898 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1899 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1900 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1901 final_nr = nr;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1902 final_nc = (data_index - 1) / nr + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1903 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1904
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1905 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1906 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1907 else if (data_index == max_size)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1908 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1909 max_size *= 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1910
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1911 if (all_char_conv)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1912 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1913 if (one_elt_size_spec)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1914 mval.resize (1, max_size, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1915 else if (nr > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1916 mval.resize (nr, max_size / nr, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1917 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1918 panic_impossible ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1919 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1920 else if (nr > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1921 mval.resize (nr, max_size / nr, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1922 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1923 mval.resize (max_size, 1, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1924
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1925 data = mval.fortran_vec ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1926 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1927
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1928 const char *fmt = elt->text;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1929
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1930 bool discard = elt->discard;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1931
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1932 switch (elt->type)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1933 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1934 case scanf_format_elt::whitespace_conversion:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1935 DO_WHITESPACE_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1936 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1937
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1938 case scanf_format_elt::literal_conversion:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1939 DO_LITERAL_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1940 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1941
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1942 case '%':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1943 DO_PCT_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1944 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1945
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1946 case 'd': case 'i':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1947 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1948 switch (elt->modifier)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1949 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1950 case 'h':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1951 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1952 short int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1953 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1954 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1955 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1956 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1957 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1958
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1959 case 'l':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1960 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1961 long int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1962 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1963 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1964 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1965 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1966 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1967
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1968 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1969 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1970 int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1971 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1972 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1973 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1974 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1975 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1976 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1977 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1978 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1979
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1980 case 'o': case 'u': case 'x':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1981 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1982 switch (elt->modifier)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1983 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1984 case 'h':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1985 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1986 unsigned short int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1987 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1988 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1989 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1990 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1991 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1992
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1993 case 'l':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1994 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1995 unsigned long int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1996 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1997 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1998 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1999 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2000 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2001
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2002 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2003 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2004 unsigned int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2005 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2006 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2007 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2008 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2009 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2010 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2011 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2012 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2013
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2014 case 'e': case 'f': case 'g':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2015 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2016 double tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2017
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2018 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2019 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2020 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2021 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2022 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2023
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2024 case 'c':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2025 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2026 BEGIN_C_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2027
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2028 FINISH_CHARACTER_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2029
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2030 is.setf (flags);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2031 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2032 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2033
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2034 case 's':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2035 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2036 BEGIN_S_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2037
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2038 FINISH_CHARACTER_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2039 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2040 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2041
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2042 case '[': case '^':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2043 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2044 BEGIN_CHAR_CLASS_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2045
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2046 FINISH_CHARACTER_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2047 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2048 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2049
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2050 case 'p':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2051 error ("%s: unsupported format specifier", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2052 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2053
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2054 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2055 error ("%s: internal format error", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2056 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2057 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2058
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2059 if (! ok ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2060 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2061 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2062 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2063 else if (! is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2064 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2065 if (all_char_conv)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2066 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2067 if (one_elt_size_spec)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2068 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2069 final_nr = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2070 final_nc = data_index;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2071 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2072 else if (data_index > nr)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2073 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2074 final_nr = nr;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2075 final_nc = (data_index - 1) / nr + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2076 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2077 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2078 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2079 final_nr = data_index;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2080 final_nc = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2081 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2082 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2083 else if (nr > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2084 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2085 if (data_index > nr)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2086 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2087 final_nr = nr;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2088 final_nc = (data_index - 1) / nr + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2089 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2090 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2091 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2092 final_nr = data_index;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2093 final_nc = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2094 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2095 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2096 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2097 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2098 final_nr = data_index;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2099 final_nc = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2100 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2101
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2102 // 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
2103 // reset the failbit in the stream state.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2104 if (is.rdstate () & std::ios::failbit)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2105 is.clear (is.rdstate () & (~std::ios::failbit));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2106
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2107 // FIXME: is this the right thing to do?
19849
1c9ed5b4c73d input.h: change meaning of interactive and forced_interactive global variables.
Carnë Draug <carandraug@octave.org>
parents: 19739
diff changeset
2108 if (interactive && ! forced_interactive && name () == "stdin")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2109 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2110 is.clear ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2111
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2112 // Skip to end of line.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2113 bool err;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2114 do_gets (-1, err, false, who);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2115 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2116
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2117 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2118 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2119 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2120 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2121 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2122 error ("%s: internal format error", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2123 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2124 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2125
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2126 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
2127 {
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2128 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
2129 {
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2130 final_nr = 1;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2131 final_nc = data_index;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2132 }
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2133 else
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2134 {
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2135 final_nr = nr;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2136 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
2137 }
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2138
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2139 break;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2140 }
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2141 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
2142 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2143 // 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
2144 // 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
2145 // 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
2146 // 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
2147 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
2148 && (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
2149 || 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
2150 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2151 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2152 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2153
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2154 if (ok ())
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2155 {
2121
bc6ecd8f1175 [project @ 1996-05-12 06:45:55 by jwe]
jwe
parents: 2117
diff changeset
2156 mval.resize (final_nr, final_nc, 0.0);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2157
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
2158 retval = mval;
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
2159
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2160 if (all_char_conv)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2161 retval = retval.convert_to_str (false, true);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2162 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2163
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2164 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2165 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2166
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2167 octave_value
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
2168 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
2169 octave_idx_type& conversion_count,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2170 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2171 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2172 octave_value retval = Matrix ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2173
3559
12d7ec415f35 [project @ 2000-02-03 05:17:36 by jwe]
jwe
parents: 3553
diff changeset
2174 conversion_count = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2175
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2176 std::istream *isp = input_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2177
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2178 if (! isp)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2179 invalid_operation (who, "reading");
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2180 else
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2181 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2182 scanf_format_list fmt_list (fmt);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2183
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2184 if (fmt_list.num_conversions () == -1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2185 ::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
2186
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2187 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
2188 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
2189
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2190 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
2191
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2192 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
2193
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2194 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
2195 conversion_count, who);
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2196 }
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2197
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2198 return retval;
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2199 }
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2200
2712
2ff2b536cc9d [project @ 1997-02-21 21:38:21 by jwe]
jwe
parents: 2687
diff changeset
2201 bool
2ff2b536cc9d [project @ 1997-02-21 21:38:21 by jwe]
jwe
parents: 2687
diff changeset
2202 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
2203 octave_value& retval, const std::string& who)
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2204 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2205 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
2206
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2207 if (! isp)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2208 return false;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2209
2712
2ff2b536cc9d [project @ 1997-02-21 21:38:21 by jwe]
jwe
parents: 2687
diff changeset
2210 bool quit = false;
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2211
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2212 std::istream& is = *isp;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2213
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2214 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
2215
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2216 if (elt)
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2217 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2218 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
2219
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2220 bool discard = elt->discard;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2221
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2222 switch (elt->type)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2223 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2224 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
2225 DO_WHITESPACE_CONVERSION ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2226 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2227
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2228 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
2229 DO_LITERAL_CONVERSION ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2230 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2231
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2232 case '%':
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2233 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2234 DO_PCT_CONVERSION ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2235
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2236 if (! is)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2237 quit = true;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2238 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2239 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2240
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2241 case 'd': case 'i':
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2242 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2243 int tmp;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2244
21147
95feb42d7a97 * oct-stream.cc (OCTAVE_SCAN): Eliminate trivial macro.
John W. Eaton <jwe@octave.org>
parents: 21139
diff changeset
2245 if (octave_scan (is, *elt, &tmp))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2246 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2247 if (! discard)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2248 retval = tmp;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2249 }
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2250 else
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2251 quit = true;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2252 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2253 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2254
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2255 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
2256 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2257 long int tmp;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2258
21147
95feb42d7a97 * oct-stream.cc (OCTAVE_SCAN): Eliminate trivial macro.
John W. Eaton <jwe@octave.org>
parents: 21139
diff changeset
2259 if (octave_scan (is, *elt, &tmp))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2260 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2261 if (! discard)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2262 retval = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2263 }
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2264 else
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2265 quit = true;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2266 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2267 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2268
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2269 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
2270 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2271 double tmp;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2272
21147
95feb42d7a97 * oct-stream.cc (OCTAVE_SCAN): Eliminate trivial macro.
John W. Eaton <jwe@octave.org>
parents: 21139
diff changeset
2273 if (octave_scan (is, *elt, &tmp))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2274 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2275 if (! discard)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2276 retval = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2277 }
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2278 else
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2279 quit = true;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2280 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2281 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2282
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2283 case 'c':
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2284 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2285 BEGIN_C_CONVERSION ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2286
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2287 if (! discard)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2288 retval = tmp;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2289
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2290 if (! is)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2291 quit = true;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2292
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2293 is.setf (flags);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2294 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2295 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2296
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2297 case 's':
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2298 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2299 BEGIN_S_CONVERSION ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2300
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2301 if (! discard)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2302 retval = tmp;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2303
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2304 if (! is)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2305 quit = true;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2306 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2307 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2308
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2309 case '[':
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2310 case '^':
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2311 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2312 BEGIN_CHAR_CLASS_CONVERSION ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2313
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2314 if (! discard)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2315 retval = tmp;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2316
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2317 if (! is)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2318 quit = true;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2319 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2320 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2321
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2322 case 'p':
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2323 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
2324 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2325
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2326 default:
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2327 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
2328 break;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2329 }
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2330 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2331
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2332 if (ok () && is.fail ())
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2333 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2334 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
2335
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2336 // 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
2337
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2338 if (interactive && ! forced_interactive && name () == "stdin")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2339 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2340 // 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
2341 bool err;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2342 do_gets (-1, err, false, who);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2343 }
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2344 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2345
2712
2ff2b536cc9d [project @ 1997-02-21 21:38:21 by jwe]
jwe
parents: 2687
diff changeset
2346 return quit;
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2347 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2348
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2349 octave_value_list
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2350 octave_base_stream::oscanf (const std::string& fmt, const std::string& who)
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2351 {
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2352 octave_value_list retval;
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2353
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2354 std::istream *isp = input_stream ();
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2355
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2356 if (! isp)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2357 invalid_operation (who, "reading");
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2358 else
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2359 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2360 std::istream& is = *isp;
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2361
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2362 scanf_format_list fmt_list (fmt);
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2363
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2364 octave_idx_type nconv = fmt_list.num_conversions ();
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2365
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2366 if (nconv == -1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2367 ::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
2368
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2369 is.clear ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2370
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2371 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
2372
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2373 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
2374
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2375 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
2376
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2377 int num_values = 0;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2378
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2379 bool quit = false;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2380
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2381 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
2382 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2383 octave_value tmp;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2384
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2385 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
2386
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2387 if (quit)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2388 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2389 else
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2390 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2391 if (tmp.is_defined ())
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2392 retval(num_values++) = tmp;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2393
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2394 if (! ok ())
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2395 break;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2396
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2397 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
2398 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2399 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2400
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2401 retval(nconv) = num_values;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2402
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2403 int err_num;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2404 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
2405
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2406 if (! quit)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2407 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2408 // 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
2409 if (ok () && len > nconv)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2410 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2411 octave_value tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2412
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2413 elt = fmt_list.next ();
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2414
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2415 do_oscanf (elt, tmp, who);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2416 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2417 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2418 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2419
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2420 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2421 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2422
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2423 // 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
2424 // (output streams are those that define os).
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2425
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2426 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2427 octave_base_stream::flush (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2428 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2429 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2430
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2431 std::ostream *os = output_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2432
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2433 if (! os)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2434 invalid_operation ("fflush", "writing");
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2435 else
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2436 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2437 os->flush ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2438
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2439 if (os->good ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2440 retval = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2441 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2442
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2443 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2444 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2445
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2446 class
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2447 printf_value_cache
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2448 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2449 public:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2450
3653
84b2f30007d5 [project @ 2000-03-31 23:33:25 by jwe]
jwe
parents: 3645
diff changeset
2451 enum state { ok, conversion_error };
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2452
7352
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2453 printf_value_cache (const octave_value_list& args, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2454 : 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
2455 n_vals (values.length ()), n_elts (0), have_data (false),
7352
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2456 curr_state (ok)
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2457 {
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2458 for (octave_idx_type i = 0; i < values.length (); i++)
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2459 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2460 octave_value val = values(i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2461
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2462 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
2463 err_wrong_type_arg (who, val);
7352
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2464 }
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2465 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2466
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2467 ~printf_value_cache (void) { }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2468
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2469 // 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
2470 octave_value get_next_value (char type = 0);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2471
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2472 // Get the current value as an int and advance the internal pointer.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2473 int int_value (void);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2474
3145
0d640dc625c7 [project @ 1998-02-05 08:44:59 by jwe]
jwe
parents: 3013
diff changeset
2475 operator bool () const { return (curr_state == ok); }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2476
3653
84b2f30007d5 [project @ 2000-03-31 23:33:25 by jwe]
jwe
parents: 3645
diff changeset
2477 bool exhausted (void) { return (val_idx >= n_vals); }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2478
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2479 private:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2480
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2481 const octave_value_list values;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2482 int val_idx;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2483 int elt_idx;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2484 int n_vals;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2485 int n_elts;
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2486 bool have_data;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2487 octave_value curr_val;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2488 state curr_state;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2489
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2490 // Must create value cache with values!
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2491
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2492 printf_value_cache (void);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2493
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2494 // No copying!
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2495
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2496 printf_value_cache (const printf_value_cache&);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2497
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2498 printf_value_cache& operator = (const printf_value_cache&);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2499 };
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2500
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2501 octave_value
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2502 printf_value_cache::get_next_value (char type)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2503 {
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2504 octave_value retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2505
3711
60db0e500f10 [project @ 2000-08-03 05:09:39 by jwe]
jwe
parents: 3704
diff changeset
2506 if (exhausted ())
60db0e500f10 [project @ 2000-08-03 05:09:39 by jwe]
jwe
parents: 3704
diff changeset
2507 curr_state = conversion_error;
60db0e500f10 [project @ 2000-08-03 05:09:39 by jwe]
jwe
parents: 3704
diff changeset
2508
60db0e500f10 [project @ 2000-08-03 05:09:39 by jwe]
jwe
parents: 3704
diff changeset
2509 while (! exhausted ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2510 {
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2511 if (! have_data)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2512 {
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2513 curr_val = values (val_idx);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2514
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
2515 elt_idx = 0;
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
2516 n_elts = curr_val.numel ();
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
2517 have_data = true;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2518 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2519
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2520 if (elt_idx < n_elts)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2521 {
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2522 if (type == 's')
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2523 {
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2524 if (curr_val.is_string ())
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2525 {
21296
596e19e7e571 fix printf regression (bug #47192)
John W. Eaton <jwe@octave.org>
parents: 21235
diff changeset
2526 dim_vector dv (1, curr_val.numel ());
596e19e7e571 fix printf regression (bug #47192)
John W. Eaton <jwe@octave.org>
parents: 21235
diff changeset
2527 octave_value tmp = curr_val.reshape (dv);
596e19e7e571 fix printf regression (bug #47192)
John W. Eaton <jwe@octave.org>
parents: 21235
diff changeset
2528
596e19e7e571 fix printf regression (bug #47192)
John W. Eaton <jwe@octave.org>
parents: 21235
diff changeset
2529 std::string sval = tmp.string_value ();
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2530
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2531 retval = sval.substr (elt_idx);
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2532
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2533 // We've consumed the rest of the value.
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2534 elt_idx = n_elts;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2535 }
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2536 else
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2537 {
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2538 // Convert to character string while values are
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2539 // integers in the range [0 : char max]
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2540 const NDArray val = curr_val.array_value ();
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2541
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2542 octave_idx_type idx = elt_idx;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2543
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2544 for (; idx < n_elts; idx++)
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2545 {
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2546 double dval = val(idx);
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2547
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2548 if (D_NINT (dval) != dval || dval < 0 || dval > 255)
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2549 break;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2550 }
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2551
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2552 octave_idx_type n = idx - elt_idx;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2553
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2554 if (n > 0)
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2555 {
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2556 std::string sval (n, '\0');
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2557
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2558 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
2559 sval[i] = val(elt_idx++);
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2560
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2561 retval = sval;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2562 }
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2563 else
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2564 retval = curr_val.fast_elem_extract (elt_idx++);
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2565 }
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2566 }
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2567 else
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2568 {
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2569 retval = curr_val.fast_elem_extract (elt_idx++);
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2570
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2571 if (type == 'c' && ! retval.is_string ())
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2572 {
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2573 double dval = retval.double_value ();
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2574
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2575 if (D_NINT (dval) == dval && dval >= 0 && dval < 256)
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2576 retval = static_cast<char> (dval);
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2577 }
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2578 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2579
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2580 if (elt_idx >= n_elts)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2581 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2582 elt_idx = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2583 val_idx++;
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2584 have_data = false;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2585 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2586
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2587 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2588 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2589 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2590 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2591 val_idx++;
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2592 have_data = false;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2593
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2594 if (n_elts == 0)
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2595 {
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2596 if (elt_idx == 0 && (type == 's' || type == 'c'))
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2597 {
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2598 retval = "";
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2599 break;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2600 }
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2601
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2602 if (exhausted ())
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2603 curr_state = conversion_error;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2604 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2605 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2606 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2607
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2608 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2609 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2610
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2611 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2612 printf_value_cache::int_value (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2613 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2614 int retval = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2615
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2616 octave_value val = get_next_value ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2617
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
2618 double dval = val.double_value (true);
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
2619
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
2620 if (D_NINT (dval) == dval)
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
2621 retval = NINT (dval);
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
2622 else
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
2623 curr_state = conversion_error;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2624
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2625 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2626 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2627
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2628 // Ugh again and again.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2629
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
2630 template <typename T>
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
2631 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2632 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
2633 int sa_2, T arg, const std::string& who)
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2634 {
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
2635 int retval = 0;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
2636
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2637 switch (nsa)
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2638 {
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2639 case 2:
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2640 retval = octave_format (os, fmt, sa_1, sa_2, arg);
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2641 break;
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2642
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2643 case 1:
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2644 retval = octave_format (os, fmt, sa_1, arg);
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2645 break;
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2646
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2647 case 0:
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2648 retval = octave_format (os, fmt, arg);
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2649 break;
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2650
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2651 default:
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2652 ::error ("%s: internal error handling format", who.c_str ());
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2653 break;
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2654 }
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
2655
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
2656 return retval;
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2657 }
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2658
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2659 static size_t
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2660 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
2661 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
2662 const std::string& who)
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2663 {
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2664 if (nsa > 2)
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20768
diff changeset
2665 ::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
2666
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2667 std::string flags = elt->flags;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2668
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2669 bool left = flags.find ('-') != std::string::npos;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2670
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2671 size_t len = arg.length ();
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2672
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2673 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
2674 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
2675
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2676 os << std::setw (fw)
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2677 << (left ? std::left : std::right)
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2678 << (prec < len ? arg.substr (0, prec) : arg);
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2679
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2680 return len > fw ? len : fw;
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2681 }
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2682
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2683 static bool
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2684 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
2685 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2686 octave_value ov_isnan = val.isnan ();
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2687 octave_value ov_isinf = val.isinf ();
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2688
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2689 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
2690 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2691
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2692 static bool
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2693 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
2694 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2695 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
2696
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2697 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
2698 return true;
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2699 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
2700 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2701 if (val.is_uint64_type ())
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2702 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2703 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
2704
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2705 if (ival.value () <= limit)
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2706 return true;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2707 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2708 else
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2709 return true;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2710 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2711 else
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2712 {
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2713 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
2714
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2715 if (dval == xround (dval) && dval <= limit)
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2716 return true;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2717 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2718
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2719 return false;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2720 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2721
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2722 static bool
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2723 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
2724 {
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2725 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
2726 return true;
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2727 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
2728 {
7d0014bb9e4e also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents: 18650
diff changeset
2729 // 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
2730
7d0014bb9e4e also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents: 18650
diff changeset
2731 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
2732 = 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
2733
7d0014bb9e4e also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents: 18650
diff changeset
2734 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
2735 }
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2736 else
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2737 {
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2738 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
2739
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2740 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
2741
18653
7d0014bb9e4e also switch from unsigned integer to real format for negative values
John W. Eaton <jwe@octave.org>
parents: 18650
diff changeset
2742 if (dval == xround (dval) && dval >= 0 && dval <= limit)
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2743 return true;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2744 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2745
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2746 return false;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2747 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2748
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2749 static std::string
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2750 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
2751 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2752 std::string tfmt = elt->text;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2753
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2754 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
2755
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2756 return tfmt;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2757 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2758
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2759 int
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2760 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
2761 const printf_format_elt *elt,
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2762 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
2763 const octave_value& val,
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2764 const std::string& who)
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2765 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2766 int retval = 0;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2767
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2768 const char *fmt = elt->text;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2769
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2770 if (is_nan_or_inf (val))
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2771 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2772 double dval = val.double_value ();
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2773
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2774 std::string tfmt = fmt;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2775 std::string::size_type i1, i2;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2776
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2777 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
2778
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2779 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
2780 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2781 tfmt.erase (i2, i1-i2);
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2782 if (elt->prec == -2)
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2783 nsa--;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2784 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2785
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2786 const char *tval;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2787 if (lo_ieee_isinf (dval))
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2788 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2789 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
2790 tval = (dval < 0 ? "-Inf" : "+Inf");
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2791 else
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2792 tval = (dval < 0 ? "-Inf" : "Inf");
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2793 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2794 else
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2795 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2796 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
2797 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
2798 else
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2799 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
2800 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2801
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2802 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
2803 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2804 else
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2805 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2806 static std::string llmod
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2807 = 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
2808
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2809 char type = elt->type;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2810
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2811 switch (type)
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2812 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2813 case 'd': case 'i': case 'c':
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2814 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
2815 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2816 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
2817
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2818 // Insert "long" modifier.
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2819 std::string tfmt = fmt;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2820 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
2821
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2822 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
2823 tval.value (), who);
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2824 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2825 else
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2826 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2827 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
2828
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2829 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
2830
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
2831 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
2832 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
2833 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2834 break;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2835
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2836 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
2837 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
2838 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2839 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
2840
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2841 // Insert "long" modifier.
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2842 std::string tfmt = fmt;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2843 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
2844
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2845 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
2846 tval.value (), who);
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2847 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2848 else
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2849 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2850 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
2851
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2852 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
2853
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
2854 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
2855 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
2856 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2857 break;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2858
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2859 case 'f': case 'e': case 'E':
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2860 case 'g': case 'G':
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2861 {
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2862 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
2863
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
2864 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
2865 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2866 break;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2867
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2868 default:
20938
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
2869 // 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
2870 // 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
2871 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
2872 return -1;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2873 break;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2874 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2875 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2876
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2877 return retval;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2878 }
6492
bcfdc9f0d267 [project @ 2007-04-05 06:13:30 by jwe]
jwe
parents: 6483
diff changeset
2879
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2880 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2881 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
2882 const octave_value_list& args,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2883 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2884 {
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
2885 int retval = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2886
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2887 octave_idx_type nconv = fmt_list.num_conversions ();
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2888
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2889 std::ostream *osp = output_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2890
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2891 if (! osp)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2892 invalid_operation (who, "writing");
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2893 else
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2894 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2895 std::ostream& os = *osp;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2896
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2897 const printf_format_elt *elt = fmt_list.first ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2898
7352
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2899 printf_value_cache val_cache (args, who);
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2900
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2901 for (;;)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2902 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2903 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2904
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2905 if (! elt)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2906 ::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
2907
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2908 // 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
2909 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
2910
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2911 int sa_1 = 0;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2912 int sa_2 = 0;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2913
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2914 if (nsa > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2915 {
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2916 sa_1 = val_cache.int_value ();
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2917
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2918 if (! val_cache)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2919 break;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2920 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2921 {
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2922 if (nsa > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2923 {
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2924 sa_2 = val_cache.int_value ();
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2925
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2926 if (! val_cache)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2927 break;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2928 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2929 }
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2930 }
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2931
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2932 if (elt->type == '%')
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2933 {
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2934 os << "%";
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2935 retval++;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2936 }
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2937 else if (elt->args == 0 && elt->text)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2938 {
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2939 os << elt->text;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2940 retval += strlen (elt->text);
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2941 }
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2942 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
2943 {
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2944 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
2945
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2946 if (val_cache)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2947 {
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2948 if (val.is_string ())
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2949 {
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2950 std::string sval = val.string_value ();
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2951
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2952 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
2953 sa_2, sval, who);
19729
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
2954 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2955 else
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18620
diff changeset
2956 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
2957 sa_2, val, who);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2958 }
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2959 else
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2960 break;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2961 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2962 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2963 {
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2964 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
2965
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2966 if (val_cache)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2967 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
2968 sa_2, val, who);
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2969 else
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2970 break;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2971 }
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2972
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2973 if (! os)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2974 {
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
2975 error ("%s: write error", who.c_str ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2976 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2977 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2978
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2979 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
2980
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2981 if (! elt || (val_cache.exhausted () && elt->args > 0))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2982 break;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2983 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2984 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2985
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2986 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2987 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2988
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2989 int
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2990 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
2991 const octave_value_list& args,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2992 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2993 {
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2994 printf_format_list fmt_list (fmt);
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2995
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2996 if (fmt_list.num_conversions () == -1)
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2997 ::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
2998
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
2999 return do_printf (fmt_list, args, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3000 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3001
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3002 int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3003 octave_base_stream::puts (const std::string& s, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3004 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3005 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3006
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
3007 std::ostream *osp = output_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3008
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3009 if (! osp)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3010 invalid_operation (who, "writing");
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3011 else
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3012 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
3013 std::ostream& os = *osp;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3014
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3015 os << s;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3016
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3017 if (! os)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3018 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
3019 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3020 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3021 // 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
3022 // Without it, output from a loop like
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3023 //
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3024 // 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
3025 //
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3026 // 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
3027 os.flush ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3028
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3029 if (os)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3030 retval = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3031 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3032 error ("%s: write error", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3033 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3034 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3035
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3036 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3037 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3038
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3039 // Return current error message for this stream.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3040
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
3041 std::string
2435
3be97fe02051 [project @ 1996-10-27 21:31:29 by jwe]
jwe
parents: 2341
diff changeset
3042 octave_base_stream::error (bool clear_err, int& err_num)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3043 {
2435
3be97fe02051 [project @ 1996-10-27 21:31:29 by jwe]
jwe
parents: 2341
diff changeset
3044 err_num = fail ? -1 : 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3045
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
3046 std::string tmp = errmsg;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3047
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3048 if (clear_err)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3049 clear ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3050
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3051 return tmp;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3052 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3053
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3054 void
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3055 octave_base_stream::invalid_operation (const std::string& who, const char *rw)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3056 {
20938
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
3057 // Note: This calls the member fcn error, not ::error from error.h.
6297
a943cb9c8068 [project @ 2007-02-10 08:42:27 by jwe]
jwe
parents: 6296
diff changeset
3058 error (who, std::string ("stream not open for ") + rw);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3059 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3060
3552
41daa489833a [project @ 2000-02-03 03:05:28 by jwe]
jwe
parents: 3548
diff changeset
3061 octave_stream::octave_stream (octave_base_stream *bs)
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3062 : rep (bs)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3063 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3064 if (rep)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3065 rep->count = 1;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3066 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3067
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3068 octave_stream::~octave_stream (void)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3069 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3070 if (rep && --rep->count == 0)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3071 delete rep;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3072 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3073
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3074 octave_stream::octave_stream (const octave_stream& s)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3075 : rep (s.rep)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3076 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3077 if (rep)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3078 rep->count++;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3079 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3080
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3081 octave_stream&
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3082 octave_stream::operator = (const octave_stream& s)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3083 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3084 if (rep != s.rep)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3085 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3086 if (rep && --rep->count == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3087 delete rep;
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3088
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3089 rep = s.rep;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3090
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3091 if (rep)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3092 rep->count++;
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3093 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3094
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3095 return *this;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3096 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3097
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3098 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3099 octave_stream::flush (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3100 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3101 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3102
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3103 if (stream_ok ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3104 retval = rep->flush ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3105
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3106 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3107 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3108
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
3109 std::string
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3110 octave_stream::getl (octave_idx_type max_len, bool& err, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3111 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
3112 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3113
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3114 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3115 retval = rep->getl (max_len, err, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3116
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3117 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3118 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3119
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
3120 std::string
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3121 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
3122 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3123 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3124 err = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3125
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3126 int conv_err = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3127
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
3128 int max_len = -1;
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
3129
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
3130 if (tc_max_len.is_defined ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3131 {
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
3132 max_len = convert_to_valid_int (tc_max_len, conv_err);
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
3133
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
3134 if (conv_err || max_len < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3135 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3136 err = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3137 ::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
3138 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3139 }
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
3140
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3141 return getl (max_len, err, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3142 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3143
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
3144 std::string
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3145 octave_stream::gets (octave_idx_type max_len, bool& err, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3146 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
3147 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3148
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3149 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3150 retval = rep->gets (max_len, err, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3151
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3152 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3153 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3154
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
3155 std::string
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3156 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
3157 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3158 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3159 err = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3160
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3161 int conv_err = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3162
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
3163 int max_len = -1;
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
3164
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
3165 if (tc_max_len.is_defined ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3166 {
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
3167 max_len = convert_to_valid_int (tc_max_len, conv_err);
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
3168
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
3169 if (conv_err || max_len < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3170 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3171 err = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3172 ::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
3173 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3174 }
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
3175
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3176 return gets (max_len, err, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3177 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3178
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
3179 off_t
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
3180 octave_stream::skipl (off_t count, bool& err, const std::string& who)
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3181 {
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
3182 off_t retval = -1;
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3183
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3184 if (stream_ok ())
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3185 retval = rep->skipl (count, err, who);
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3186
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3187 return retval;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3188 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3189
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
3190 off_t
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3191 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
3192 const std::string& who)
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3193 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3194 err = false;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3195
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3196 int conv_err = 0;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3197
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3198 int count = 1;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3199
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3200 if (tc_count.is_defined ())
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3201 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3202 if (tc_count.is_scalar_type () && xisinf (tc_count.scalar_value ()))
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3203 count = -1;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3204 else
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3205 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3206 count = convert_to_valid_int (tc_count, conv_err);
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3207
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3208 if (conv_err || count < 0)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3209 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3210 err = true;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3211 ::error ("%s: invalid number of lines specified", who.c_str ());
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3212 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3213 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3214 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3215
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3216 return skipl (count, err, who);
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3217 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3218
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3219 int
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
3220 octave_stream::seek (off_t offset, int origin)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3221 {
5065
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
3222 int status = -1;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3223
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3224 if (stream_ok ())
4889
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
3225 {
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
3226 clearerr ();
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
3227
12957
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3228 // 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
3229 off_t orig_pos = rep->tell ();
5065
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
3230
12957
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3231 // 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
3232 status = rep->seek (0, SEEK_END);
5065
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
3233
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
3234 if (status == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3235 {
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
3236 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
3237
12943
8372d50de75a improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents: 12936
diff changeset
3238 if (origin == SEEK_CUR)
8372d50de75a improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents: 12936
diff changeset
3239 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3240 // 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
3241 // 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
3242 // location.
12943
8372d50de75a improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents: 12936
diff changeset
3243 rep->seek (orig_pos, SEEK_SET);
8372d50de75a improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents: 12936
diff changeset
3244 }
8372d50de75a improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents: 12936
diff changeset
3245
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3246 // 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
3247 // existing file.
12957
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3248 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
3249
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3250 if (status == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3251 {
12957
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3252 // 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
3253 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
3254
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3255 // 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
3256 // 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
3257 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
3258 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3259 // 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
3260 // 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
3261 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
3262
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3263 status = -1;
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3264 }
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3265 }
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3266 else
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3267 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3268 // 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
3269 // 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
3270 rep->seek (orig_pos, SEEK_SET);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3271
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3272 status = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3273 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3274 }
4889
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
3275 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3276
5065
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
3277 return status;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3278 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3279
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3280 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3281 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
3282 const octave_value& tc_origin)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3283 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3284 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3285
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3286 // 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
3287 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
3288 off_t xoffset = val.value ();
4645
bd2067547b40 [project @ 2003-11-23 08:07:52 by jwe]
jwe
parents: 4643
diff changeset
3289
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3290 int conv_err = 0;
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3291
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3292 int origin = SEEK_SET;
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3293
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3294 if (tc_origin.is_string ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3295 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3296 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
3297
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3298 if (xorigin == "bof")
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3299 origin = SEEK_SET;
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3300 else if (xorigin == "cof")
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3301 origin = SEEK_CUR;
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3302 else if (xorigin == "eof")
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3303 origin = SEEK_END;
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3304 else
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3305 conv_err = -1;
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3306 }
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3307 else
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3308 {
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3309 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
3310
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3311 if (! conv_err)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3312 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3313 if (xorigin == -1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3314 origin = SEEK_SET;
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3315 else if (xorigin == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3316 origin = SEEK_CUR;
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3317 else if (xorigin == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3318 origin = SEEK_END;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3319 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3320 conv_err = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3321 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3322 }
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
3323
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
3324 if (conv_err)
20938
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
3325 ::error ("fseek: invalid value for origin");
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3326
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
3327 retval = seek (xoffset, origin);
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
3328
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
3329 if (retval != 0)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
3330 // 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
3331 error ("fseek: failed to seek to requested position");
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3332
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3333 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3334 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3335
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
3336 off_t
4797
19b8225bdaa2 [project @ 2004-02-23 22:10:31 by jwe]
jwe
parents: 4693
diff changeset
3337 octave_stream::tell (void)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3338 {
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
3339 off_t retval = -1;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3340
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3341 if (stream_ok ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3342 retval = rep->tell ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3343
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3344 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3345 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3346
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3347 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3348 octave_stream::rewind (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3349 {
6296
85eb75190e01 [project @ 2007-02-10 07:10:42 by jwe]
jwe
parents: 6109
diff changeset
3350 return seek (0, SEEK_SET);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3351 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3352
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3353 bool
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3354 octave_stream::is_open (void) const
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3355 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3356 bool retval = false;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3357
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3358 if (stream_ok ())
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3359 retval = rep->is_open ();
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3360
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3361 return retval;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3362 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3363
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3364 void
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3365 octave_stream::close (void)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3366 {
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3367 if (stream_ok ())
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3368 rep->close ();
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3369 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3370
21335
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3371 // 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
3372
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3373 template <typename T>
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3374 static inline bool
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3375 is_old_NA (T)
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3376 {
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3377 return false;
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3378 }
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3379
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3380 template <>
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3381 inline bool
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3382 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
3383 {
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3384 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
3385 }
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3386
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3387 template <typename T>
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3388 static inline T
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3389 replace_old_NA (T val)
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3390 {
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3391 return val;
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3392 }
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3393
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3394 template <>
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3395 inline double
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3396 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
3397 {
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3398 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
3399 }
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3400
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
3401 template <typename SRC_T, typename DST_T>
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3402 static octave_value
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3403 convert_and_copy (std::list<void *>& input_buf_list,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3404 octave_idx_type input_buf_elts,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3405 octave_idx_type elts_read,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3406 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
3407 bool do_float_fmt_conv, bool do_NA_conv,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3408 oct_mach_info::float_format from_flt_fmt)
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3409 {
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3410 typedef typename DST_T::element_type dst_elt_type;
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3411
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3412 DST_T conv (dim_vector (nr, nc));
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3413
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3414 dst_elt_type *conv_data = conv.fortran_vec ();
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3415
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3416 octave_idx_type j = 0;
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3417
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3418 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
3419 it != input_buf_list.end (); it++)
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3420 {
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3421 SRC_T *data = static_cast<SRC_T *> (*it);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3422
17463
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3423 if (swap || do_float_fmt_conv)
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3424 {
21335
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3425 if (do_NA_conv)
17463
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3426 {
21335
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3427 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
3428 i++, j++)
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3429 {
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3430 if (swap)
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3431 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
3432 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
3433 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
3434 1, from_flt_fmt,
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3435 oct_mach_info::native_float_format ());
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3436
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3437 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
3438
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3439 if (is_old_NA (tmp))
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3440 tmp = replace_old_NA (tmp);
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3441
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3442 conv_data[j] = tmp;
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3443 }
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3444 }
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3445 else
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3446 {
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3447 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
3448 i++, j++)
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3449 {
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3450 if (swap)
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3451 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
3452 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
3453 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
3454 1, from_flt_fmt,
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3455 oct_mach_info::native_float_format ());
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3456
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3457 conv_data[j] = data[i];
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3458 }
17463
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3459 }
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3460 }
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3461 else
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3462 {
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3463 if (do_NA_conv)
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3464 {
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3465 for (octave_idx_type i = 0; i < input_buf_elts && j < elts_read;
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3466 i++, j++)
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3467 {
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3468 dst_elt_type tmp (data[i]);
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3469
21335
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3470 if (is_old_NA (tmp))
e078d2208d86 avoid warnings about implicit float to booll conversions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3471 tmp = replace_old_NA (tmp);
17463
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3472
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3473 conv_data[j] = tmp;
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3474 }
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3475 }
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3476 else
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3477 {
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3478 for (octave_idx_type i = 0; i < input_buf_elts && j < elts_read;
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3479 i++, j++)
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3480 conv_data[j] = data[i];
cc13924a4266 snapshot 3.7.7
John W. Eaton <jwe@octave.org>
parents: 17453
diff changeset
3481 }
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3482 }
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3483
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3484 delete [] data;
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3485 }
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3486
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3487 input_buf_list.clear ();
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3488
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3489 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
3490 conv_data[i] = dst_elt_type (0);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3491
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3492 return conv;
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3493 }
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3494
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3495 typedef octave_value (*conv_fptr)
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3496 (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
3497 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
3498 bool swap, bool do_float_fmt_conv, bool do_NA_conv,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3499 oct_mach_info::float_format from_flt_fmt);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3500
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3501 #define TABLE_ELT(T, U, V, W) \
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3502 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
3503
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3504 #define FILL_TABLE_ROW(T, V) \
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3505 TABLE_ELT (T, dt_int8, V, int8NDArray); \
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3506 TABLE_ELT (T, dt_uint8, V, uint8NDArray); \
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3507 TABLE_ELT (T, dt_int16, V, int16NDArray); \
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3508 TABLE_ELT (T, dt_uint16, V, uint16NDArray); \
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3509 TABLE_ELT (T, dt_int32, V, int32NDArray); \
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3510 TABLE_ELT (T, dt_uint32, V, uint32NDArray); \
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3511 TABLE_ELT (T, dt_int64, V, int64NDArray); \
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3512 TABLE_ELT (T, dt_uint64, V, uint64NDArray); \
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3513 TABLE_ELT (T, dt_single, V, FloatNDArray); \
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3514 TABLE_ELT (T, dt_double, V, NDArray); \
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3515 TABLE_ELT (T, dt_char, V, charNDArray); \
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3516 TABLE_ELT (T, dt_schar, V, charNDArray); \
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3517 TABLE_ELT (T, dt_uchar, V, charNDArray); \
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3518 TABLE_ELT (T, dt_logical, V, boolNDArray);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3519
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3520 octave_value
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3521 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
3522 octave_idx_type input_buf_elts,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3523 octave_idx_type elts_read,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3524 octave_idx_type nr, octave_idx_type nc,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3525 oct_data_conv::data_type input_type,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3526 oct_data_conv::data_type output_type,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3527 oct_mach_info::float_format ffmt)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3528 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3529 octave_value retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3530
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3531 static bool initialized = false;
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3532
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3533 // Table function pointers for return types x read types.
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3534
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3535 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
3536
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3537 if (! initialized)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3538 {
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3539 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
3540 for (int j = 0; j < 14; j++)
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3541 conv_fptr_table[i][j] = 0;
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3542
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3543 FILL_TABLE_ROW (dt_int8, int8_t);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3544 FILL_TABLE_ROW (dt_uint8, uint8_t);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3545 FILL_TABLE_ROW (dt_int16, int16_t);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3546 FILL_TABLE_ROW (dt_uint16, uint16_t);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3547 FILL_TABLE_ROW (dt_int32, int32_t);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3548 FILL_TABLE_ROW (dt_uint32, uint32_t);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3549 FILL_TABLE_ROW (dt_int64, int64_t);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3550 FILL_TABLE_ROW (dt_uint64, uint64_t);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3551 FILL_TABLE_ROW (dt_single, float);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3552 FILL_TABLE_ROW (dt_double, double);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3553 FILL_TABLE_ROW (dt_char, char);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3554 FILL_TABLE_ROW (dt_schar, signed char);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3555 FILL_TABLE_ROW (dt_uchar, unsigned char);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3556 FILL_TABLE_ROW (dt_logical, bool);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3557
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3558 initialized = true;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3559 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3560
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3561 bool swap = false;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3562
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3563 if (ffmt == oct_mach_info::flt_fmt_unknown)
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3564 ffmt = float_format ();
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3565
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3566 if (oct_mach_info::words_big_endian ())
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3567 swap = (ffmt == oct_mach_info::flt_fmt_ieee_little_endian);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3568 else
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3569 swap = (ffmt == oct_mach_info::flt_fmt_ieee_big_endian);
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3570
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3571 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
3572 || input_type == oct_data_conv::dt_single)
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3573 && ffmt != float_format ());
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3574
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3575 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
3576
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3577 switch (output_type)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3578 {
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3579 case oct_data_conv::dt_int8:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3580 case oct_data_conv::dt_uint8:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3581 case oct_data_conv::dt_int16:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3582 case oct_data_conv::dt_uint16:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3583 case oct_data_conv::dt_int32:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3584 case oct_data_conv::dt_uint32:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3585 case oct_data_conv::dt_int64:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3586 case oct_data_conv::dt_uint64:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3587 case oct_data_conv::dt_single:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3588 case oct_data_conv::dt_double:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3589 case oct_data_conv::dt_char:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3590 case oct_data_conv::dt_schar:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3591 case oct_data_conv::dt_uchar:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3592 case oct_data_conv::dt_logical:
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3593 {
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3594 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
3595
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3596 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
3597 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
3598 }
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3599 break;
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3600
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3601 default:
20938
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
3602 ::error ("read: invalid type specification");
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3603 }
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3604
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3605 return retval;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3606 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3607
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3608 octave_value
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3609 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
3610 oct_data_conv::data_type input_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3611 oct_data_conv::data_type output_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3612 octave_idx_type skip, oct_mach_info::float_format ffmt,
18210
a0abcf377ec5 return elements read, not bytes in fread second output (bug #41091)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
3613 octave_idx_type& count)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3614 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3615 octave_value retval;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3616
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3617 octave_idx_type nr = -1;
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3618 octave_idx_type nc = -1;
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3619
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3620 bool one_elt_size_spec = false;
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3621
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3622 if (! stream_ok ())
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3623 return retval;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3624
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3625 // 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
3626
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3627 // 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
3628 // 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
3629 // 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
3630
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3631 // 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
3632 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
3633
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3634 count = 0;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3635
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3636 try
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3637 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3638 get_size (size, nr, nc, one_elt_size_spec, "fread");
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3639 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3640 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
3641 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3642 invalid_operation ("fread", "reading");
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3643 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3644
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3645 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
3646
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3647 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
3648 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3649 // 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
3650
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3651 // 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
3652 // number of rows.
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3653
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3654 // 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
3655 // 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
3656
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3657 if (nr == 0)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3658 nr = nc = 0;
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
3659 else
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3660 nc = 1;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3661 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3662 else
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3663 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3664 // 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
3665 // 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
3666
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3667 // 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
3668 // should be.
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3669
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3670 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
3671 nr = nc = 0;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3672 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3673
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3674 // 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
3675 // 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
3676 // 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
3677 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
3678
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3679 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
3680
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3681 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
3682
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3683 if (skip == 0)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3684 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3685 if (read_to_eof)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3686 input_buf_elts = 1024 * 1024;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3687 else
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3688 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
3689 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3690 else
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3691 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
3692
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3693 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
3694 = 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
3695
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3696 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
3697
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3698 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
3699
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3700 // 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
3701 // 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
3702 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
3703
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3704 if (! isp)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3705 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
3706 else
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3707 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3708 std::istream& is = *isp;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3709
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3710 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
3711
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3712 while (is && ! is.eof ()
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3713 && (read_to_eof || count < elts_to_read))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3714 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3715 if (! read_to_eof)
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3716 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3717 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
3718
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3719 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
3720 input_buf_size = remaining_elts * input_elt_size;
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3721 }
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3722
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3723 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
3724
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3725 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
3726
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3727 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
3728
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3729 char_count += gcount;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3730
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3731 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
3732
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3733 count += nel;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3734
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3735 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
3736
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3737 if (is && skip != 0 && nel == block_size)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3738 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3739 // Seek to skip.
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3740 // 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
3741
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3742 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
3743
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3744 seek (0, SEEK_END);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3745
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3746 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
3747
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3748 // 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
3749 // the original position?
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3750 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
3751
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3752 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
3753
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3754 if (remaining < skip)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3755 seek (0, SEEK_END);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3756 else
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3757 seek (skip, SEEK_CUR);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3758
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3759 if (! is)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3760 break;
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3761 }
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3762 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3763
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3764 if (read_to_eof)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3765 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3766 if (nc < 0)
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3767 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3768 nc = count / nr;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3769
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
3770 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
3771 nc++;
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3772 }
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3773 else
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3774 nr = count;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3775 }
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3776 else if (count == 0)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3777 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3778 nr = 0;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3779 nc = 0;
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
3780 }
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3781 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
3782 {
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3783 if (count % nr != 0)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3784 nc = count / nr + 1;
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
3785 else
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3786 nc = count / nr;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3787
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3788 if (count < nr)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3789 nr = count;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3790 }
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3791
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3792 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
3793 nr, nc, input_type, output_type, ffmt);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3794 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3795
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3796 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3797 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3798
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3799 octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3800 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
3801 oct_data_conv::data_type output_type,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3802 octave_idx_type skip, oct_mach_info::float_format flt_fmt)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3803 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3804 octave_idx_type retval = -1;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3805
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3806 if (! stream_ok ())
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3807 invalid_operation ("fwrite", "writing");
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3808 else
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3809 {
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
3810 if (flt_fmt == oct_mach_info::flt_fmt_unknown)
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
3811 flt_fmt = float_format ();
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
3812
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
3813 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
3814 skip, flt_fmt);
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
3815
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
3816 if (status < 0)
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
3817 error ("fwrite: write error");
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3818 else
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20714
diff changeset
3819 retval = status;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3820 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3821
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3822 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3823 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3824
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
3825 template <typename T, typename V>
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3826 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
3827 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
3828 {
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
3829 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
3830
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
3831 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
3832
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
3833 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
3834 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
3835 }
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
3836
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
3837 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
3838 static void
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3839 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
3840 bool swap)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3841 {
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3842 typedef typename V::val_type val_type;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3843
19739
3fa35defe495 Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19729
diff changeset
3844 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
3845
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3846 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
3847 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
3848 // 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
3849 V val (data[i]);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3850
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3851 vt_data[i] = val.value ();
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3852
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3853 if (swap)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3854 swap_bytes<sizeof (val_type)> (&vt_data[i]);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3855 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3856 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3857
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
3858 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
3859 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
3860 {
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
3861 public:
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
3862 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
3863 };
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
3864
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
3865 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
3866 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
3867 {
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
3868 public:
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
3869 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
3870 };
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
3871
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
3872 template <typename T>
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3873 static bool
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3874 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
3875 oct_data_conv::data_type output_type,
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3876 oct_mach_info::float_format flt_fmt)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3877 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3878 bool retval = true;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3879
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3880 bool swap
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3881 = ((oct_mach_info::words_big_endian ()
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3882 && flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3883 || flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3884
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3885 bool do_float_conversion = flt_fmt != oct_mach_info::float_format ();
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3886
18616
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
3887 typedef typename ultimate_element_type<T>::type ult_elt_type;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3888
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3889 switch (output_type)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3890 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3891 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
3892 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
3893 break;
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
3894
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3895 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
3896 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
3897 break;
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
3898
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
3899 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
3900 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
3901 break;
aa861a98d84d fwrite: don't convert to octave_int for char output types
John W. Eaton <jwe@octave.org>
parents: 18518
diff changeset
3902
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3903 case oct_data_conv::dt_int8:
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3904 convert_ints<T, octave_int8> (data, conv_data, n_elts, swap);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3905 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3906
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3907 case oct_data_conv::dt_uint8:
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3908 convert_ints<T, octave_uint8> (data, conv_data, n_elts, swap);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3909 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3910
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3911 case oct_data_conv::dt_int16:
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3912 convert_ints<T, octave_int16> (data, conv_data, n_elts, swap);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3913 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3914
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3915 case oct_data_conv::dt_uint16:
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3916 convert_ints<T, octave_uint16> (data, conv_data, n_elts, swap);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3917 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3918
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3919 case oct_data_conv::dt_int32:
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3920 convert_ints<T, octave_int32> (data, conv_data, n_elts, swap);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3921 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3922
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3923 case oct_data_conv::dt_uint32:
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3924 convert_ints<T, octave_uint32> (data, conv_data, n_elts, swap);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3925 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3926
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3927 case oct_data_conv::dt_int64:
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3928 convert_ints<T, octave_int64> (data, conv_data, n_elts, swap);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3929 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3930
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3931 case oct_data_conv::dt_uint64:
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3932 convert_ints<T, octave_uint64> (data, conv_data, n_elts, swap);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3933 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3934
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3935 case oct_data_conv::dt_single:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3936 {
19739
3fa35defe495 Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19729
diff changeset
3937 float *vt_data = static_cast<float *> (conv_data);
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3938
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3939 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
3940 {
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3941 vt_data[i] = data[i];
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3942
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3943 if (do_float_conversion)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3944 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
3945 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3946 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3947 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3948
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3949 case oct_data_conv::dt_double:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3950 {
19739
3fa35defe495 Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19729
diff changeset
3951 double *vt_data = static_cast<double *> (conv_data);
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3952
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3953 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
3954 {
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3955 vt_data[i] = data[i];
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3956
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3957 if (do_float_conversion)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3958 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
3959 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3960 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3961 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3962
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3963 default:
20938
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
3964 ::error ("write: invalid type specification");
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3965 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3966
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3967 return retval;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3968 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3969
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3970 bool
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3971 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
3972 {
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3973 bool status = false;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3974
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3975 std::ostream *osp = output_stream ();
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3976
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3977 if (osp)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3978 {
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3979 std::ostream& os = *osp;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3980
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3981 if (os)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3982 {
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3983 os.write (static_cast<const char *> (data), nbytes);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3984
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3985 if (os)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3986 status = true;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3987 }
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3988 }
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3989
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3990 return status;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3991 }
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3992
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3993 bool
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3994 octave_stream::skip_bytes (size_t skip)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3995 {
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3996 bool status = false;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3997
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3998 std::ostream *osp = output_stream ();
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
3999
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4000 if (! osp)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4001 return false;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4002
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4003 std::ostream& os = *osp;
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 // 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
4006 // 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
4007 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
4008
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4009 seek (0, SEEK_END);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4010
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4011 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
4012
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4013 // 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
4014 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
4015
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4016 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
4017
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4018 if (remaining < skip)
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4019 {
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4020 seek (0, SEEK_END);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4021
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4022 // 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
4023 unsigned char zero = 0;
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4024 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
4025 os.write (reinterpret_cast<const char *> (&zero), 1);
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4026 }
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4027 else
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4028 seek (skip, SEEK_CUR);
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4029
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4030 if (os)
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4031 status = true;
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4032
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4033 return status;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4034 }
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4035
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
4036 template <typename T>
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
4037 octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
4038 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
4039 oct_data_conv::data_type output_type,
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4040 octave_idx_type skip,
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4041 oct_mach_info::float_format flt_fmt)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
4042 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4043 bool swap = ((oct_mach_info::words_big_endian ()
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4044 && flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4045 || flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4046
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4047 bool do_data_conversion = (swap || ! is_equivalent_type<T> (output_type)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4048 || flt_fmt != oct_mach_info::float_format ());
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4049
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4050 octave_idx_type nel = data.numel ();
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4051
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4052 octave_idx_type chunk_size;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4053
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4054 if (skip != 0)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4055 chunk_size = block_size;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4056 else if (do_data_conversion)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4057 chunk_size = 1024 * 1024;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
4058 else
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4059 chunk_size = nel;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4060
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4061 octave_idx_type i = 0;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4062
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4063 const T *pdata = data.data ();
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4064
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4065 while (i < nel)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
4066 {
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4067 if (skip != 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4068 {
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4069 if (! skip_bytes (skip))
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4070 return -1;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4071 }
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4072
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4073 octave_idx_type remaining_nel = nel - i;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4074
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4075 if (chunk_size > remaining_nel)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4076 chunk_size = remaining_nel;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4077
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4078 bool status = false;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4079
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4080 if (do_data_conversion)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4081 {
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4082 size_t output_size
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4083 = 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
4084
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4085 OCTAVE_LOCAL_BUFFER (unsigned char, conv_data, output_size);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4086
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4087 status = convert_data (&pdata[i], conv_data, chunk_size,
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4088 output_type, flt_fmt);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4089
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4090 if (status)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4091 status = write_bytes (conv_data, output_size);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4092 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
4093 else
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4094 status = write_bytes (pdata, sizeof (T) * chunk_size);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4095
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4096 if (! status)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4097 return -1;
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4098
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4099 i += chunk_size;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
4100 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
4101
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4102 return nel;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
4103 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
4104
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4105 #define INSTANTIATE_WRITE(T) \
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4106 template \
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4107 octave_idx_type \
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4108 octave_stream::write (const Array<T>& data, octave_idx_type block_size, \
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4109 oct_data_conv::data_type output_type, \
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4110 octave_idx_type skip, \
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4111 oct_mach_info::float_format flt_fmt)
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4112
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4113 INSTANTIATE_WRITE (octave_int8);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4114 INSTANTIATE_WRITE (octave_uint8);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4115 INSTANTIATE_WRITE (octave_int16);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4116 INSTANTIATE_WRITE (octave_uint16);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4117 INSTANTIATE_WRITE (octave_int32);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4118 INSTANTIATE_WRITE (octave_uint32);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4119 INSTANTIATE_WRITE (octave_int64);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4120 INSTANTIATE_WRITE (octave_uint64);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4121 INSTANTIATE_WRITE (int8_t);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4122 INSTANTIATE_WRITE (uint8_t);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4123 INSTANTIATE_WRITE (int16_t);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4124 INSTANTIATE_WRITE (uint16_t);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4125 INSTANTIATE_WRITE (int32_t);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4126 INSTANTIATE_WRITE (uint32_t);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4127 INSTANTIATE_WRITE (int64_t);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4128 INSTANTIATE_WRITE (uint64_t);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4129 INSTANTIATE_WRITE (bool);
21354
06d15e4e611a move public data type macros to octave-config.h
John W. Eaton <jwe@octave.org>
parents: 21335
diff changeset
4130 #if defined (OCTAVE_HAVE_OVERLOAD_CHAR_INT8_TYPES)
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4131 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
4132 #endif
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4133 INSTANTIATE_WRITE (float);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 17415
diff changeset
4134 INSTANTIATE_WRITE (double);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
4135
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4136 octave_value
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
4137 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
4138 octave_idx_type& count, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4139 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4140 octave_value retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4141
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
4142 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
4143 retval = rep->scanf (fmt, size, count, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4144
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4145 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4146 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4147
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4148 octave_value
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4149 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
4150 octave_idx_type& count, const std::string& who)
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4151 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4152 octave_value retval = Matrix ();
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4153
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4154 if (fmt.is_string ())
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4155 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4156 std::string sfmt = fmt.string_value ();
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4157
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4158 if (fmt.is_sq_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4159 sfmt = do_string_escapes (sfmt);
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4160
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4161 retval = scanf (sfmt, size, count, who);
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4162 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4163 else
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4164 {
20938
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
4165 // Note: error is member fcn from octave_stream, not ::error.
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4166 error (who + ": format must be a string");
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4167 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4168
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4169 return retval;
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4170 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4171
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
4172 octave_value_list
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
4173 octave_stream::oscanf (const std::string& fmt, const std::string& who)
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
4174 {
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
4175 octave_value_list retval;
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
4176
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
4177 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
4178 retval = rep->oscanf (fmt, who);
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
4179
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
4180 return retval;
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
4181 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
4182
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4183 octave_value_list
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4184 octave_stream::oscanf (const octave_value& fmt, const std::string& who)
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4185 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4186 octave_value_list retval;
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4187
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4188 if (fmt.is_string ())
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4189 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4190 std::string sfmt = fmt.string_value ();
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4191
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4192 if (fmt.is_sq_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4193 sfmt = do_string_escapes (sfmt);
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4194
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4195 retval = oscanf (sfmt, who);
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4196 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4197 else
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4198 {
20938
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
4199 // Note: error is member fcn from octave_stream, not ::error.
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4200 error (who + ": format must be a string");
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4201 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4202
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4203 return retval;
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4204 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4205
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4206 int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
4207 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
4208 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4209 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4210 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4211
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
4212 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
4213 retval = rep->printf (fmt, args, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4214
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4215 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4216 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4217
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4218 int
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4219 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
4220 const std::string& who)
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4221 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4222 int retval = 0;
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4223
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4224 if (fmt.is_string ())
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4225 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4226 std::string sfmt = fmt.string_value ();
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4227
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4228 if (fmt.is_sq_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4229 sfmt = do_string_escapes (sfmt);
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4230
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4231 retval = printf (sfmt, args, who);
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4232 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4233 else
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4234 {
20938
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
4235 // Note: error is member fcn from octave_stream, not ::error.
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4236 error (who + ": format must be a string");
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4237 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4238
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4239 return retval;
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4240 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4241
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4242 int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
4243 octave_stream::puts (const std::string& s, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4244 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4245 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4246
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
4247 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
4248 retval = rep->puts (s, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4249
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4250 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4251 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4252
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4253 // FIXME: maybe this should work for string arrays too.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4254
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4255 int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
4256 octave_stream::puts (const octave_value& tc_s, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4257 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4258 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4259
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4260 if (tc_s.is_string ())
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4261 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4262 std::string s = tc_s.string_value ();
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
4263 retval = puts (s, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4264 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4265 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
4266 {
20938
aac911d8847b choose correct error function in stream classes
John W. Eaton <jwe@octave.org>
parents: 20931
diff changeset
4267 // Note: error is member fcn from octave_stream, not ::error.
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
4268 error (who + ": argument must be a string");
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
4269 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4270
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4271 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4272 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4273
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4274 bool
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4275 octave_stream::eof (void) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4276 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4277 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4278
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
4279 if (stream_ok ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4280 retval = rep->eof ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4281
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4282 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4283 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4284
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
4285 std::string
2435
3be97fe02051 [project @ 1996-10-27 21:31:29 by jwe]
jwe
parents: 2341
diff changeset
4286 octave_stream::error (bool clear, int& err_num)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4287 {
5649
d24b97246b9b [project @ 2006-03-08 20:31:25 by jwe]
jwe
parents: 5581
diff changeset
4288 std::string retval = "invalid stream object";
d24b97246b9b [project @ 2006-03-08 20:31:25 by jwe]
jwe
parents: 5581
diff changeset
4289
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
4290 if (stream_ok (false))
2435
3be97fe02051 [project @ 1996-10-27 21:31:29 by jwe]
jwe
parents: 2341
diff changeset
4291 retval = rep->error (clear, err_num);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4292
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4293 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4294 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4295
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
4296 std::string
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4297 octave_stream::name (void) const
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4298 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4299 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4300
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
4301 if (stream_ok ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4302 retval = rep->name ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4303
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4304 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4305 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4306
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4307 int
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4308 octave_stream::mode (void) const
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4309 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4310 int retval = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4311
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
4312 if (stream_ok ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4313 retval = rep->mode ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4314
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4315 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4316 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4317
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 2305
diff changeset
4318 oct_mach_info::float_format
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4319 octave_stream::float_format (void) const
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4320 {
4574
6cb22b9e3942 [project @ 2003-10-31 05:57:43 by jwe]
jwe
parents: 4468
diff changeset
4321 oct_mach_info::float_format retval = oct_mach_info::flt_fmt_unknown;
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 2305
diff changeset
4322
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
4323 if (stream_ok ())
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 2305
diff changeset
4324 retval = rep->float_format ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4325
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4326 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4327 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4328
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
4329 std::string
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4330 octave_stream::mode_as_string (int mode)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4331 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4332 std::string retval = "???";
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
4333 std::ios::openmode in_mode = static_cast<std::ios::openmode> (mode);
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
4334
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
4335 if (in_mode == std::ios::in)
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
4336 retval = "r";
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4337 else if (in_mode == std::ios::out
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
4338 || in_mode == (std::ios::out | std::ios::trunc))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
4339 retval = "w";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
4340 else if (in_mode == (std::ios::out | std::ios::app))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
4341 retval = "a";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
4342 else if (in_mode == (std::ios::in | std::ios::out))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
4343 retval = "r+";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
4344 else if (in_mode == (std::ios::in | std::ios::out | std::ios::trunc))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
4345 retval = "w+";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
4346 else if (in_mode == (std::ios::in | std::ios::out | std::ios::ate))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
4347 retval = "a+";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
4348 else if (in_mode == (std::ios::in | std::ios::binary))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
4349 retval = "rb";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
4350 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
4351 || in_mode == (std::ios::out | std::ios::trunc | std::ios::binary))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
4352 retval = "wb";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
4353 else if (in_mode == (std::ios::out | std::ios::app | std::ios::binary))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
4354 retval = "ab";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
4355 else if (in_mode == (std::ios::in | std::ios::out | std::ios::binary))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
4356 retval = "r+b";
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4357 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
4358 | std::ios::binary))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
4359 retval = "w+b";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
4360 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
4361 | std::ios::binary))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
4362 retval = "a+b";
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4363
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4364 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4365 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4366
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4367 octave_stream_list *octave_stream_list::instance = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4368
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4369 bool
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4370 octave_stream_list::instance_ok (void)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4371 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4372 bool retval = true;
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4373
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4374 if (! instance)
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
4375 {
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
4376 instance = new octave_stream_list ();
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
4377
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
4378 if (instance)
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
4379 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
4380 }
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4381
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4382 if (! instance)
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20768
diff changeset
4383 ::error ("unable to create stream list object!");
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4384
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4385 return retval;
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4386 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4387
5353
df230b7df93c [project @ 2005-05-18 02:18:24 by jwe]
jwe
parents: 5338
diff changeset
4388 int
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4389 octave_stream_list::insert (octave_stream& os)
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4390 {
5353
df230b7df93c [project @ 2005-05-18 02:18:24 by jwe]
jwe
parents: 5338
diff changeset
4391 return (instance_ok ()) ? instance->do_insert (os) : -1;
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4392 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4393
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4394 octave_stream
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4395 octave_stream_list::lookup (int fid, const std::string& who)
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4396 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4397 return (instance_ok ()) ? instance->do_lookup (fid, who) : octave_stream ();
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4398 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4399
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4400 octave_stream
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4401 octave_stream_list::lookup (const octave_value& fid, const std::string& who)
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4402 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4403 return (instance_ok ()) ? instance->do_lookup (fid, who) : octave_stream ();
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4404 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4405
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4406 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4407 octave_stream_list::remove (int fid, const std::string& who)
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4408 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4409 return (instance_ok ()) ? instance->do_remove (fid, who) : -1;
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4410 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4411
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4412 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4413 octave_stream_list::remove (const octave_value& fid, const std::string& who)
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4414 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4415 return (instance_ok ()) ? instance->do_remove (fid, who) : -1;
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4416 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4417
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4418 void
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4419 octave_stream_list::clear (bool flush)
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4420 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4421 if (instance)
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4422 instance->do_clear (flush);
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4423 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4424
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4425 string_vector
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4426 octave_stream_list::get_info (int fid)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4427 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4428 return (instance_ok ()) ? instance->do_get_info (fid) : string_vector ();
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4429 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4430
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4431 string_vector
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4432 octave_stream_list::get_info (const octave_value& fid)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4433 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4434 return (instance_ok ()) ? instance->do_get_info (fid) : string_vector ();
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4435 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4436
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
4437 std::string
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4438 octave_stream_list::list_open_files (void)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4439 {
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20982
diff changeset
4440 return (instance_ok ()) ? instance->do_list_open_files () : "";
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4441 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4442
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4443 octave_value
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4444 octave_stream_list::open_file_numbers (void)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4445 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4446 return (instance_ok ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4447 ? instance->do_open_file_numbers () : octave_value ();
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4448 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4449
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4450 int
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4451 octave_stream_list::get_file_number (const octave_value& fid)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4452 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4453 return (instance_ok ()) ? instance->do_get_file_number (fid) : -1;
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4454 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4455
5353
df230b7df93c [project @ 2005-05-18 02:18:24 by jwe]
jwe
parents: 5338
diff changeset
4456 int
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4457 octave_stream_list::do_insert (octave_stream& os)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4458 {
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4459 // Insert item with key corresponding to file-descriptor.
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4460
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4461 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
4462
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4463 if (stream_number == -1)
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4464 return stream_number;
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4465
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
4466 // 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
4467 //
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
4468 // (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
4469 // && 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
4470 //
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
4471 // 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
4472 // 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
4473 // 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
4474 // 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
4475 // 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
4476 // 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
4477 // before.
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4478
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4479 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
4480 ::error ("could not create file id");
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4481
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4482 list[stream_number] = os;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4483
5353
df230b7df93c [project @ 2005-05-18 02:18:24 by jwe]
jwe
parents: 5338
diff changeset
4484 return stream_number;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4485 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4486
21040
3e7cfee5f786 maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents: 21029
diff changeset
4487 OCTAVE_NORETURN static
21029
e3b3bb522d62 maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents: 21017
diff changeset
4488 void
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
4489 err_invalid_file_id (int fid, const std::string& who)
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4490 {
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4491 if (who.empty ())
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4492 ::error ("invalid stream number = %d", fid);
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4493 else
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4494 ::error ("%s: invalid stream number = %d", who.c_str (), fid);
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4495 }
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4496
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4497 octave_stream
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4498 octave_stream_list::do_lookup (int fid, const std::string& who) const
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4499 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4500 octave_stream retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4501
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4502 if (fid < 0)
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
4503 err_invalid_file_id (fid, who);
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4504
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4505 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
4506 retval = lookup_cache->second;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4507 else
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4508 {
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4509 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
4510
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4511 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
4512 err_invalid_file_id (fid, who);
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4513
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4514 retval = iter->second;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4515 lookup_cache = iter;
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4516 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4517
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4518 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4519 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4520
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4521 octave_stream
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4522 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
4523 const std::string& who) const
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4524 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4525 int i = get_file_number (fid);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4526
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4527 return do_lookup (i, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4528 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4529
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4530 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4531 octave_stream_list::do_remove (int fid, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4532 {
20764
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
4533 // 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
4534 if (fid < 3)
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
4535 err_invalid_file_id (fid, who);
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4536
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4537 ostrl_map::iterator iter = list.find (fid);
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4538
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4539 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
4540 err_invalid_file_id (fid, who);
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4541
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4542 octave_stream os = iter->second;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4543 list.erase (iter);
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4544 lookup_cache = list.end ();
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4545
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4546 // FIXME: is this check redundant?
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4547 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
4548 err_invalid_file_id (fid, who);
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4549
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4550 os.close ();
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4551
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
4552 return 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4553 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4554
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4555 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4556 octave_stream_list::do_remove (const octave_value& fid, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4557 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4558 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4559
6054
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4560 if (fid.is_string () && fid.string_value () == "all")
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4561 {
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4562 do_clear (false);
6054
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4563
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4564 retval = 0;
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4565 }
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4566 else
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4567 {
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4568 int i = get_file_number (fid);
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4569
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20465
diff changeset
4570 retval = do_remove (i, who);
6054
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4571 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4572
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4573 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4574 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4575
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4576 void
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4577 octave_stream_list::do_clear (bool flush)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4578 {
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4579 if (flush)
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4580 {
20764
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
4581 // Flush stdout and stderr.
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4582 list[1].flush ();
20764
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
4583 list[2].flush ();
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4584 }
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4585
20764
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
4586 for (ostrl_map::iterator iter = list.begin (); iter != list.end (); )
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4587 {
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4588 int fid = iter->first;
20764
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
4589 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
4590 {
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
4591 iter++;
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
4592 continue;
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
4593 }
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
4594
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4595 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
4596
7655b399abff eliminate trailing whitespace in source files we maintain
John W. Eaton <jwe@octave.org>
parents: 20764
diff changeset
4597 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
4598 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
4599
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
4600 // 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
4601 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
4602 {
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
4603 // 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
4604 iter++;
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
4605 continue;
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
4606 }
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
4607
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
4608 // 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
4609 if (os.is_valid ())
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4610 os.close ();
20764
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
4611
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
4612 list.erase (iter++);
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4613 }
20764
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
4614
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4615 lookup_cache = list.end ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4616 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4617
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4618 string_vector
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4619 octave_stream_list::do_get_info (int fid) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4620 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4621 octave_stream os = do_lookup (fid);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4622
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20831
diff changeset
4623 if (! os.is_valid ())
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4624 ::error ("invalid file id = %d", fid);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4625
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20831
diff changeset
4626 string_vector retval (3);
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20831
diff changeset
4627
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20831
diff changeset
4628 retval(0) = os.name ();
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20831
diff changeset
4629 retval(1) = octave_stream::mode_as_string (os.mode ());
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20831
diff changeset
4630 retval(2) = oct_mach_info::float_format_as_string (os.float_format ());
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20831
diff changeset
4631
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4632 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4633 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4634
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4635 string_vector
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4636 octave_stream_list::do_get_info (const octave_value& fid) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4637 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4638 int conv_err = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4639
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4640 int int_fid = convert_to_valid_int (fid, conv_err);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4641
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4642 if (conv_err)
2915
649549662cf6 [project @ 1997-04-30 20:51:40 by jwe]
jwe
parents: 2902
diff changeset
4643 ::error ("file id must be a file object or integer value");
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4644
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4645 return do_get_info (int_fid);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4646 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4647
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
4648 std::string
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4649 octave_stream_list::do_list_open_files (void) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4650 {
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
4651 std::ostringstream buf;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4652
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4653 buf << "\n"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4654 << " number mode arch name\n"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4655 << " ------ ---- ---- ----\n";
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4656
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4657 for (ostrl_map::const_iterator p = list.begin (); p != list.end (); p++)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4658 {
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4659 octave_stream os = p->second;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4660
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4312
diff changeset
4661 buf << " "
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4662 << std::setiosflags (std::ios::right)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4663 << std::setw (4) << p->first << " "
19123
c8f03ccdc9ee Align columns for freport() output.
Rik <rik@octave.org>
parents: 18676
diff changeset
4664 // reset necessary in addition to setiosflags since this is one stmt.
c8f03ccdc9ee Align columns for freport() output.
Rik <rik@octave.org>
parents: 18676
diff changeset
4665 << std::resetiosflags (std::ios::adjustfield)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4666 << std::setiosflags (std::ios::left)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4667 << std::setw (3)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4668 << octave_stream::mode_as_string (os.mode ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4669 << " "
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4670 << std::setw (9)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4671 << oct_mach_info::float_format_as_string (os.float_format ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4672 << " "
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4673 << os.name () << "\n";
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4674 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4675
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
4676 buf << "\n";
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
4677
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4678 return buf.str ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4679 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4680
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4681 octave_value
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4682 octave_stream_list::do_open_file_numbers (void) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4683 {
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4684 Matrix retval (1, list.size (), 0.0);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4685
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4686 int num_open = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4687
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4688 for (ostrl_map::const_iterator p = list.begin (); p != list.end (); p++)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4689 {
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4690 // Skip stdin, stdout, and stderr.
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4691 if (p->first > 2 && p->second)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4692 retval(0,num_open++) = p->first;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4693 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4694
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4695 retval.resize ((num_open > 0), num_open);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4696
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4697 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4698 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4699
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4700 int
2609
12bc9d0a50b5 [project @ 1997-01-18 00:17:36 by jwe]
jwe
parents: 2601
diff changeset
4701 octave_stream_list::do_get_file_number (const octave_value& fid) const
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4702 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4703 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4704
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4705 if (fid.is_string ())
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4706 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4707 std::string nm = fid.string_value ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4708
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4709 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
4710 {
20931
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4711 // stdin, stdout, and stderr are unnamed.
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4712 if (p->first > 2)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4713 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4714 octave_stream os = p->second;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4715
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4716 if (os && os.name () == nm)
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 retval = p->first;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4719 break;
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 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4722 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4723 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4724 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4725 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4726 int conv_err = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4727
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4728 int int_fid = convert_to_valid_int (fid, conv_err);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4729
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4730 if (conv_err)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4731 ::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
4732
69dcb58b9ada Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents: 20917
diff changeset
4733 retval = int_fid;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4734 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4735
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4736 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4737 }