annotate src/oct-stream.cc @ 13741:b0e70a71647b stable release-3-4-3

Version 3.4.3 released. * configure.ac (AC_INIT): Version number is now 3.4.3. (OCTAVE_RELEASE_DATE): Update to 2011-10-10.
author John W. Eaton <jwe@octave.org>
date Mon, 10 Oct 2011 10:23:45 -0400
parents b12e2cffaa2f
children c91bd3f10bec
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
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11004
diff changeset
3 Copyright (C) 1996-2011 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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
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
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
37 #include <Array.h>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
38
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
39 #include "byte-swap.h"
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
40 #include "lo-ieee.h"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
41 #include "lo-mappers.h"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
42 #include "lo-utils.h"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
43 #include "str-vec.h"
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4078
diff changeset
44 #include "quit.h"
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
45
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
46 #include "error.h"
7352
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
47 #include "gripes.h"
3342
d8d3700fb4ab [project @ 1999-11-05 16:55:17 by jwe]
jwe
parents: 3341
diff changeset
48 #include "input.h"
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
49 #include "oct-stdstrm.h"
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
50 #include "oct-stream.h"
2877
5c1b9e545dd1 [project @ 1997-04-24 09:07:39 by jwe]
jwe
parents: 2847
diff changeset
51 #include "oct-obj.h"
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
52 #include "utils.h"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
53
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
54 // Possible values for conv_err:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
55 //
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
56 // 1 : not a real scalar
2902
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2877
diff changeset
57 // 2 : value is NaN
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2877
diff changeset
58 // 3 : value is not an integer
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
59
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
60 static int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
61 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
62 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
63 int retval = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
64
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
65 conv_err = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
66
2902
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2877
diff changeset
67 double dval = tc.double_value ();
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2877
diff changeset
68
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2877
diff changeset
69 if (! error_state)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
70 {
5389
25c8956d2204 [project @ 2005-06-15 03:45:46 by jwe]
jwe
parents: 5353
diff changeset
71 if (! lo_ieee_isnan (dval))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
72 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
73 int ival = NINT (dval);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
74
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
75 if (ival == dval)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
76 retval = ival;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
77 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
78 conv_err = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
79 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
80 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
81 conv_err = 2;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
82 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
83 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
84 conv_err = 1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
85
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
86 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
87 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
88
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
89 static int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
90 get_size (double d, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
91 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
92 int retval = -1;
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 (d))
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
95 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
96 if (! xisinf (d))
10315
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 (d >= 0.0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
99 retval = NINT (d);
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 ::error ("%s: negative value invalid as size specification",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
102 who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
103 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
104 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
105 retval = -1;
2117
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 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
108 ::error ("%s: NaN is invalid as size specification", who.c_str ());
2117
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 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
111 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
112
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
113 static void
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
114 get_size (const Array<double>& size, octave_idx_type& nr, octave_idx_type& nc, bool& one_elt_size_spec,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
115 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
116 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
117 nr = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
118 nc = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
119
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
120 one_elt_size_spec = false;
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
121
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
122 double dnr = -1.0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
123 double dnc = -1.0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
124
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
125 octave_idx_type sz_len = size.length ();
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
126
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
127 if (sz_len == 1)
2601
3723512a827a [project @ 1997-01-06 05:43:16 by jwe]
jwe
parents: 2600
diff changeset
128 {
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
129 one_elt_size_spec = true;
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
130
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
131 dnr = size (0);
4293
977f977fb2c3 [project @ 2003-01-06 18:18:14 by jwe]
jwe
parents: 4257
diff changeset
132
977f977fb2c3 [project @ 2003-01-06 18:18:14 by jwe]
jwe
parents: 4257
diff changeset
133 dnc = (dnr == 0.0) ? 0.0 : 1.0;
2601
3723512a827a [project @ 1997-01-06 05:43:16 by jwe]
jwe
parents: 2600
diff changeset
134 }
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
135 else if (sz_len == 2)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
136 {
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
137 dnr = size (0);
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
138
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
139 if (! xisinf (dnr))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
140 dnc = size (1);
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
141 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
142 ::error ("%s: invalid size specification", who.c_str ());
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
143 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
144 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
145 ::error ("%s: invalid size specification", who.c_str ());
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
146
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
147 if (! error_state)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
148 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
149 nr = get_size (dnr, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
150
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
151 if (! error_state && dnc >= 0.0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
152 nc = get_size (dnc, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
153 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
154 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
155
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
156 scanf_format_list::scanf_format_list (const std::string& s)
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
157 : nconv (0), curr_idx (0), list (dim_vector (16, 1)), buf (0)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
158 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
159 octave_idx_type num_elts = 0;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
160
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
161 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
162
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
163 size_t i = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
164
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
165 int width = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
166 bool discard = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
167 char modifier = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
168 char type = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
169
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
170 bool have_more = true;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
171
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
172 while (i < n)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
173 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
174 have_more = true;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
175
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
176 if (! buf)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
177 buf = new std::ostringstream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
178
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
179 if (s[i] == '%')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
180 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
181 // Process percent-escape conversion type.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
182
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
183 process_conversion (s, i, n, width, discard, type, modifier,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
184 num_elts);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
185
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
186 have_more = (buf != 0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
187 }
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
188 else if (isspace (s[i]))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
189 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
190 type = scanf_format_elt::whitespace_conversion;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
191
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
192 width = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
193 discard = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
194 modifier = '\0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
195 *buf << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
196
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
197 while (++i < n && isspace (s[i]))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
198 /* skip whitespace */;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
199
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
200 add_elt_to_list (width, discard, type, modifier, num_elts);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
201
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
202 have_more = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
203 }
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
204 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
205 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
206 type = scanf_format_elt::literal_conversion;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
207
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
208 width = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
209 discard = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
210 modifier = '\0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
211
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
212 while (i < n && ! isspace (s[i]) && s[i] != '%')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
213 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
214
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
215 add_elt_to_list (width, discard, type, modifier, num_elts);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
216
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
217 have_more = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
218 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
219
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
220 if (nconv < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
221 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
222 have_more = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
223 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
224 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
225 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
226
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
227 if (have_more)
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
228 add_elt_to_list (width, discard, type, modifier, num_elts);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
229
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
230 list.resize (dim_vector (num_elts, 1));
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
231
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
232 delete buf;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
233 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
234
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
235 scanf_format_list::~scanf_format_list (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
236 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
237 octave_idx_type n = list.length ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
238
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
239 for (octave_idx_type i = 0; i < n; i++)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
240 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
241 scanf_format_elt *elt = list(i);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
242 delete elt;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
243 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
244 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
245
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
246 void
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
247 scanf_format_list::add_elt_to_list (int width, bool discard, char type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
248 char modifier, octave_idx_type& num_elts,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
249 const std::string& char_class)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
250 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
251 if (buf)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
252 {
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
253 std::string text = buf->str ();
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
254
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
255 if (! text.empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
256 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
257 scanf_format_elt *elt
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
258 = 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
259 modifier, char_class);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
260
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
261 if (num_elts == list.length ())
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
262 list.resize (dim_vector (2 * num_elts, 1));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
263
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
264 list(num_elts++) = elt;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
265 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
266
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
267 delete buf;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
268 buf = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
269 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
270 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
271
3535
c5ebcd5d25a9 [project @ 2000-02-02 11:55:49 by jwe]
jwe
parents: 3534
diff changeset
272 static std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
273 expand_char_class (const std::string& s)
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
274 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
275 std::string retval;
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
276
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
277 size_t len = s.length ();
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
278
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
279 size_t i = 0;
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
280
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
281 while (i < len)
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
282 {
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
283 unsigned char c = s[i++];
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
284
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
285 if (c == '-' && i > 1 && i < len
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
286 && static_cast<unsigned char> (s[i-2]) <= static_cast<unsigned char> (s[i]))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
287 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
288 // 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
289 // already added it below).
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
290
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
291 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
292 retval += c;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
293 }
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
294 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
295 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
296 // 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
297 // the last character in the class.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
298
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
299 if (c != '-' || i == len)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
300 retval += c;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
301 }
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
302 }
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
303
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
304 return retval;
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
305 }
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
306
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
307 void
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
308 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
309 size_t n, int& width, bool& discard,
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
310 char& type, char& modifier,
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
311 octave_idx_type& num_elts)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
312 {
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
313 width = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
314 discard = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
315 modifier = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
316 type = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
317
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
318 *buf << s[i++];
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
319
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
320 bool have_width = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
321
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
322 while (i < n)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
323 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
324 switch (s[i])
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
325 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
326 case '*':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
327 if (discard)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
328 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
329 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
330 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
331 discard = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
332 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
333 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
334 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
335
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
336 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
337 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
338 if (have_width)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
339 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
340 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
341 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
342 char c = s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
343 width = width * 10 + c - '0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
344 have_width = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
345 *buf << c;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
346 while (i < n && isdigit (s[i]))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
347 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
348 c = s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
349 width = width * 10 + c - '0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
350 *buf << c;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
351 }
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 break;
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 case 'h': case 'l': case 'L':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
356 if (modifier != '\0')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
357 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
358 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
359 modifier = s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
360 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
361
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
362 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
363 if (modifier == 'L')
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 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
366 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
367 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
368 goto fini;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
369
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
370 case 'e': case 'f': case 'g':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
371 if (modifier == 'h')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
372 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
373 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
374 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
375 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
376
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
377 // No float or long double conversions, thanks.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
378 *buf << 'l';
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 goto fini;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
381
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
382 case 'c': case 's': case 'p': case '%': case '[':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
383 if (modifier != '\0')
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 nconv = -1;
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 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
388 goto fini;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
389
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
390 fini:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
391 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
392 if (finish_conversion (s, i, n, width, discard, type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
393 modifier, num_elts) == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
394 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
395 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
396 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
397
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
398 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
399 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
400 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
401 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
402
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
403 if (nconv < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
404 break;
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 nconv = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
408 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
409
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
410 int
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
411 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
412 size_t n, int& width, bool discard,
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
413 char& type, char modifier,
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
414 octave_idx_type& num_elts)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
415 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
416 int retval = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
417
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
418 std::string char_class;
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
419
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
420 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
421 size_t end_idx = std::string::npos;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
422
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
423 if (s[i] == '%')
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
424 {
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
425 type = '%';
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
426 *buf << s[i++];
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
427 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
428 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
429 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
430 type = s[i];
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
431
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
432 if (s[i] == '[')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
433 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
434 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
435
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
436 if (i < n)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
437 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
438 beg_idx = i;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
439
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
440 if (s[i] == '^')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
441 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
442 type = '^';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
443 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
444
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
445 if (i < n)
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 beg_idx = i;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
448
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
449 if (s[i] == ']')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
450 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
451 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
452 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
453 else if (s[i] == ']')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
454 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
455 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
456
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
457 while (i < n && s[i] != ']')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
458 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
459
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
460 if (i < n && s[i] == ']')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
461 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
462 end_idx = i-1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
463 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
464 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
465
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
466 if (s[i-1] != ']')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
467 retval = nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
468 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
469 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
470 *buf << s[i++];
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
471
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
472 nconv++;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
473 }
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
474
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
475 if (nconv >= 0)
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
476 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
477 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
478 char_class = expand_char_class (s.substr (beg_idx,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
479 end_idx - beg_idx + 1));
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
480
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
481 add_elt_to_list (width, discard, type, modifier, num_elts, char_class);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
482 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
483
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
484 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
485 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
486
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
487 void
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
488 scanf_format_list::printme (void) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
489 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
490 octave_idx_type n = list.length ();
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
491
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
492 for (octave_idx_type i = 0; i < n; i++)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
493 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
494 scanf_format_elt *elt = list(i);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
495
3531
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
496 std::cerr
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
497 << "width: " << elt->width << "\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
498 << "discard: " << elt->discard << "\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
499 << "type: ";
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
500
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
501 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
502 std::cerr << "literal text\n";
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
503 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
504 std::cerr << "whitespace\n";
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
505 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
506 std::cerr << elt->type << "\n";
3531
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
507
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
508 std::cerr
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
509 << "modifier: " << elt->modifier << "\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
510 << "char_class: `" << undo_string_escapes (elt->char_class) << "'\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
511 << "text: `" << undo_string_escapes (elt->text) << "'\n\n";
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
512 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
513 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
514
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
515 bool
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
516 scanf_format_list::all_character_conversions (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
517 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
518 octave_idx_type n = list.length ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
519
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
520 if (n > 0)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
521 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
522 for (octave_idx_type i = 0; i < n; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
523 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
524 scanf_format_elt *elt = list(i);
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 switch (elt->type)
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 'c': case 's': case '%': case '[': case '^':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
529 case scanf_format_elt::literal_conversion:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
530 case scanf_format_elt::whitespace_conversion:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
531 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
532
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
533 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
534 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
535 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
536 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
537 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
538
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
539 return true;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
540 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
541 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
542 return false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
543 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
544
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
545 bool
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
546 scanf_format_list::all_numeric_conversions (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
547 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
548 octave_idx_type n = list.length ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
549
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
550 if (n > 0)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
551 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
552 for (octave_idx_type i = 0; i < n; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
553 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
554 scanf_format_elt *elt = list(i);
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 switch (elt->type)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
557 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
558 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
559 case 'e': case 'f': case 'g':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
560 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
561
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
562 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
563 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
564 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
565 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
566 }
2117
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 return true;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
569 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
570 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
571 return false;
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
574 // Ugh again.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
575
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
576 printf_format_list::printf_format_list (const std::string& s)
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
577 : nconv (0), curr_idx (0), list (dim_vector (16, 1)), buf (0)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
578 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
579 octave_idx_type num_elts = 0;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
580
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
581 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
582
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
583 size_t i = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
584
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
585 int args = 0;
3643
3af6d00b82ed [project @ 2000-03-24 10:53:21 by jwe]
jwe
parents: 3640
diff changeset
586 std::string flags;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
587 int fw = 0;
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
588 int prec = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
589 char modifier = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
590 char type = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
591
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
592 bool have_more = true;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
593 bool empty_buf = true;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
594
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
595 if (n == 0)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
596 {
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
597 printf_format_elt *elt
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
598 = 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
599
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
600 list(num_elts++) = elt;
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
601
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
602 list.resize (dim_vector (num_elts, 1));
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
603 }
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
604 else
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
605 {
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
606 while (i < n)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
607 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
608 have_more = true;
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 if (! buf)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
611 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
612 buf = new std::ostringstream ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
613 empty_buf = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
614 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
615
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
616 switch (s[i])
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
617 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
618 case '%':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
619 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
620 if (empty_buf)
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 process_conversion (s, i, n, args, flags, fw, prec,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
623 type, modifier, num_elts);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
624
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
625 have_more = (buf != 0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
626 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
627 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
628 add_elt_to_list (args, flags, fw, prec, type, modifier,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
629 num_elts);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
630 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
631 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
632
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
633 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
634 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
635 args = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
636 flags = "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
637 fw = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
638 prec = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
639 modifier = '\0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
640 type = '\0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
641 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
642 empty_buf = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
643 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
644 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
645 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
646
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
647 if (nconv < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
648 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
649 have_more = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
650 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
651 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
652 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
653
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
654 if (have_more)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
655 add_elt_to_list (args, flags, fw, prec, type, modifier, num_elts);
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
656
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
657 list.resize (dim_vector (num_elts, 1));
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
658
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
659 delete buf;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
660 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
661 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
662
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
663 printf_format_list::~printf_format_list (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
664 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
665 octave_idx_type n = list.length ();
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
666
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
667 for (octave_idx_type i = 0; i < n; i++)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
668 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
669 printf_format_elt *elt = list(i);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
670 delete elt;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
671 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
672 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
673
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
674 void
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
675 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
676 int fw, int prec, char type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
677 char modifier, octave_idx_type& num_elts)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
678 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
679 if (buf)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
680 {
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
681 std::string text = buf->str ();
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
682
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
683 if (! text.empty ())
10315
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 printf_format_elt *elt
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
686 = 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
687 type, modifier);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
688
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
689 if (num_elts == list.length ())
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
690 list.resize (dim_vector (2 * num_elts, 1));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
691
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
692 list(num_elts++) = elt;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
693 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
694
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
695 delete buf;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
696 buf = 0;
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 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
699
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
700 void
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
701 printf_format_list::process_conversion
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
702 (const std::string& s, size_t& i, size_t n, int& args, std::string& flags,
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
703 int& fw, int& prec, char& modifier, char& type, octave_idx_type& num_elts)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
704 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
705 args = 0;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
706 flags = "";
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
707 fw = 0;
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
708 prec = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
709 modifier = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
710 type = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
711
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
712 *buf << s[i++];
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
713
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4574
diff changeset
714 bool nxt = false;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
715
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
716 while (i < n)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
717 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
718 switch (s[i])
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
719 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
720 case '-': case '+': case ' ': case '0': case '#':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
721 flags += s[i];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
722 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
723 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
724
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
725 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
726 nxt = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
727 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
728 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
729
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4574
diff changeset
730 if (nxt)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
731 break;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
732 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
733
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
734 if (i < n)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
735 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
736 if (s[i] == '*')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
737 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
738 fw = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
739 args++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
740 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
741 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
742 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
743 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
744 if (isdigit (s[i]))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
745 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
746 int nn = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
747 std::string tmp = s.substr (i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
748 sscanf (tmp.c_str (), "%d%n", &fw, &nn);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
749 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
750
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
751 while (i < n && isdigit (s[i]))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
752 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
753 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
754 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
755
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
756 if (i < n && s[i] == '.')
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
757 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
758 *buf << s[i++];
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
759
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
760 if (i < n)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
761 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
762 if (s[i] == '*')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
763 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
764 prec = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
765 args++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
766 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
767 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
768 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
769 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
770 if (isdigit (s[i]))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
771 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
772 int nn = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
773 std::string tmp = s.substr (i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
774 sscanf (tmp.c_str (), "%d%n", &prec, &nn);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
775 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
776
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
777 while (i < n && isdigit (s[i]))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
778 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
779 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
780 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
781 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
782
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
783 if (i < n)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
784 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
785 switch (s[i])
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
786 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
787 case 'h': case 'l': case 'L':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
788 modifier = s[i];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
789 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
790 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
791
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
792 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
793 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
794 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
795 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
796
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
797 if (i < n)
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
798 finish_conversion (s, i, args, flags, fw, prec, modifier, type, num_elts);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
799 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
800 nconv = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
801 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
802
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
803 void
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
804 printf_format_list::finish_conversion
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
805 (const std::string& s, size_t& i, int args, const std::string& flags,
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
806 int fw, int prec, char modifier, char& type, octave_idx_type& num_elts)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
807
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
808 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
809 switch (s[i])
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
810 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
811 case 'd': case 'i': case 'o': case 'x': case 'X':
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
812 case 'u': case 'c':
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
813 if (modifier == 'L')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
814 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
815 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
816 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
817 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
818 goto fini;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
819
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
820 case 'f': case 'e': case 'E': case 'g': case 'G':
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
821 if (modifier == 'h' || modifier == 'l')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
822 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
823 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
824 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
825 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
826 goto fini;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
827
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
828 case 's': case 'p': case '%':
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
829 if (modifier != '\0')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
830 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
831 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
832 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
833 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
834 goto fini;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
835
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
836 fini:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
837
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
838 type = s[i];
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
839
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
840 *buf << s[i++];
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
841
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
842 if (type != '%' || args != 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
843 nconv++;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
844
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
845 if (type != '%')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
846 args++;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
847
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
848 add_elt_to_list (args, flags, fw, prec, type, modifier, num_elts);
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
849
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
850 break;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
851
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
852 default:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
853 nconv = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
854 break;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
855 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
856 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
857
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
858 void
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
859 printf_format_list::printme (void) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
860 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
861 int n = list.length ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
862
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
863 for (int i = 0; i < n; i++)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
864 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
865 printf_format_elt *elt = list(i);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
866
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
867 std::cerr
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
868 << "args: " << elt->args << "\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
869 << "flags: `" << elt->flags << "'\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
870 << "width: " << elt->fw << "\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
871 << "prec: " << elt->prec << "\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
872 << "type: `" << elt->type << "'\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
873 << "modifier: `" << elt->modifier << "'\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
874 << "text: `" << undo_string_escapes (elt->text) << "'\n\n";
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 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
877
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
878 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
879 octave_base_stream::error (const std::string& msg)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
880 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
881 fail = true;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
882 errmsg = msg;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
883 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
884
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
885 void
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
886 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
887 {
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
888 fail = true;
6296
85eb75190e01 [project @ 2007-02-10 07:10:42 by jwe]
jwe
parents: 6109
diff changeset
889 errmsg = who + ": " + msg;
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
890 }
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
891
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
892 void
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
893 octave_base_stream::clear (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
894 {
4889
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
895 fail = false;
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
896 errmsg = "";
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
897 }
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
898
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
899 void
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
900 octave_base_stream::clearerr (void)
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
901 {
4888
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
902 std::istream *is = input_stream ();
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
903 std::ostream *os = output_stream ();
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
904
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
905 if (is)
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
906 is->clear ();
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
907
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
908 if (os)
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
909 os->clear ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
910 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
911
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
912 // Functions that are defined for all input streams (input streams
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
913 // are those that define is).
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
914
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
915 std::string
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
916 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
917 bool strip_newline, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
918 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
919 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
920
8773
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
921 if ((interactive || forced_interactive) && file_number () == 0)
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
922 {
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
923 ::error ("%s: unable to read from stdin while running interactively",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
924 who.c_str ());
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
925
8773
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
926 return retval;
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
927 }
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
928
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
929 err = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
930
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
931 std::istream *isp = input_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
932
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
933 if (isp)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
934 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
935 std::istream& is = *isp;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
936
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
937 std::ostringstream buf;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
938
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
939 int c = 0;
3553
c5600b44bef9 [project @ 2000-02-03 03:22:37 by jwe]
jwe
parents: 3552
diff changeset
940 int char_count = 0;
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
941
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
942 if (max_len != 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
943 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
944 while (is && (c = is.get ()) != EOF)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
945 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
946 char_count++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
947
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
948 // Handle CRLF, CR, or LF as line ending.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
949
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
950 if (c == '\r')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
951 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
952 if (! strip_newline)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
953 buf << static_cast<char> (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
954
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
955 c = is.get ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
956
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
957 if (c != EOF)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
958 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
959 if (c == '\n')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
960 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
961 char_count++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
962
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
963 if (! strip_newline)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
964 buf << static_cast<char> (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
965 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
966 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
967 is.putback (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
968 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
969
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
970 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
971 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
972 else if (c == '\n')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
973 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
974 if (! strip_newline)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
975 buf << static_cast<char> (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
976
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
977 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
978 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
979 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
980 buf << static_cast<char> (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
981
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
982 if (max_len > 0 && char_count == max_len)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
983 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
984 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
985 }
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
986
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
987 if (! is.eof () && char_count > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
988 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
989 // GAGME. Matlab seems to check for EOF even if the last
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
990 // character in a file is a newline character. This is NOT
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
991 // what the corresponding C-library functions do.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
992 int disgusting_compatibility_hack = is.get ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
993 if (! is.eof ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
994 is.putback (disgusting_compatibility_hack);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
995 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
996
4224
0179e6309248 [project @ 2002-12-18 00:34:29 by jwe]
jwe
parents: 4223
diff changeset
997 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
998 retval = buf.str ();
4224
0179e6309248 [project @ 2002-12-18 00:34:29 by jwe]
jwe
parents: 4223
diff changeset
999 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1000 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1001 err = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1002
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1003 if (is.eof () && char_count == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1004 error (who, "at end of file");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1005 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1006 error (who, "read error");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1007 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1008 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1009 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1010 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1011 err = true;
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
1012 invalid_operation (who, "reading");
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1013 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1014
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1015 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1016 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1017
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
1018 std::string
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1019 octave_base_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
1020 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
1021 return do_gets (max_len, err, true, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1022 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1023
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
1024 std::string
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1025 octave_base_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
1026 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
1027 return do_gets (max_len, err, false, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1028 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1029
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1030 long
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1031 octave_base_stream::skipl (long num, bool& err, const std::string& who)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1032 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1033 long cnt = -1;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1034
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1035 if ((interactive || forced_interactive) && file_number () == 0)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1036 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1037 ::error ("%s: unable to read from stdin while running interactively",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1038 who.c_str ());
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1039
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1040 return count;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1041 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1042
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1043 err = false;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1044
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1045 std::istream *isp = input_stream ();
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1046
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1047 if (isp)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1048 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1049 std::istream& is = *isp;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1050
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1051 int c = 0, lastc = -1;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1052 cnt = 0;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1053
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1054 while (is && (c = is.get ()) != EOF)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1055 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1056 // Handle CRLF, CR, or LF as line ending.
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1057
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1058 if (c == '\r' || (c == '\n' && lastc != '\r'))
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1059 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1060 if (++cnt == num)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1061 break;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1062 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1063
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1064 lastc = c;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1065 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1066
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1067 // Maybe eat the following \n if \r was just met.
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1068 if (c == '\r' && is.peek () == '\n')
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1069 is.get ();
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1070
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1071 if (is.bad ())
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1072 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1073 err = true;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1074 error (who, "read error");
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1075 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1076
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1077 if (err)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1078 cnt = -1;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1079 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1080 else
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1081 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1082 err = true;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1083 invalid_operation (who, "reading");
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1084 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1085
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1086 return cnt;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1087 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1088
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1089 #define OCTAVE_SCAN(is, fmt, arg) octave_scan (is, fmt, arg)
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1090
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1091 template <class T>
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1092 std::istream&
6767
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1093 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
1094 {
3779
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1095 T& ref = *valptr;
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1096
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1097 switch (fmt.type)
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1098 {
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1099 case 'o':
4926
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
1100 is >> std::oct >> ref >> std::dec;
3779
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1101 break;
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1102
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1103 case 'x':
4926
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
1104 is >> std::hex >> ref >> std::dec;
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
1105 break;
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
1106
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
1107 case 'i':
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
1108 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1109 int c1 = is.get ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1110
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1111 if (! is.eof ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1112 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1113 if (c1 == '0')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1114 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1115 int c2 = is.peek ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1116
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1117 if (c2 == 'x' || c2 == 'X')
7709
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
1118 {
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
1119 is.ignore ();
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
1120 if (std::isxdigit (is.peek ()))
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
1121 is >> std::hex >> ref >> std::dec;
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
1122 else
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
1123 ref = 0;
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
1124 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1125 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1126 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1127 if (c2 == '0' || c2 == '1' || c2 == '2'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1128 || c2 == '3' || c2 == '4' || c2 == '5'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1129 || c2 == '6' || c2 == '7')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1130 is >> std::oct >> ref >> std::dec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1131 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1132 ref = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1133 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1134 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1135 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1136 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1137 is.putback (c1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1138
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1139 is >> ref;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1140 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1141 }
4926
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
1142 }
3779
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1143 break;
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1144
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1145 default:
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1146 is >> ref;
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1147 break;
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1148 }
3639
fed1847dfd6c [project @ 2000-03-24 05:12:46 by jwe]
jwe
parents: 3638
diff changeset
1149
3638
a76fa215a476 [project @ 2000-03-24 04:53:45 by jwe]
jwe
parents: 3637
diff changeset
1150 return is;
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1151 }
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1152
6767
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1153 template <class T>
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1154 std::istream&
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1155 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
1156 {
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1157 if (fmt.width)
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1158 {
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1159 // 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
1160 // temporary stringstream buffer.
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1161
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1162 std::string tmp;
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1163
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1164 is.width (fmt.width);
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1165 is >> tmp;
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1166
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1167 std::istringstream ss (tmp);
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1168
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1169 octave_scan_1 (ss, fmt, valptr);
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1170 }
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1171 else
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1172 octave_scan_1 (is, fmt, valptr);
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1173
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1174 return is;
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1175 }
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1176
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1177 // 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
1178 // character strings. See BEGIN_S_CONVERSION for details.
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1179
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1180 template<>
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1181 std::istream&
4661
12b6fbd57436 [project @ 2003-11-25 05:41:35 by jwe]
jwe
parents: 4649
diff changeset
1182 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
1183 char* valptr)
3779
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1184 {
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1185 return is >> valptr;
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1186 }
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1187
4595
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1188 template std::istream&
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1189 octave_scan (std::istream&, const scanf_format_elt&, int*);
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1190
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1191 template std::istream&
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1192 octave_scan (std::istream&, const scanf_format_elt&, long int*);
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1193
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1194 template std::istream&
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1195 octave_scan (std::istream&, const scanf_format_elt&, short int*);
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1196
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1197 template std::istream&
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1198 octave_scan (std::istream&, const scanf_format_elt&, unsigned int*);
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1199
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1200 template std::istream&
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1201 octave_scan (std::istream&, const scanf_format_elt&, unsigned long int*);
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1202
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1203 template std::istream&
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1204 octave_scan (std::istream&, const scanf_format_elt&, unsigned short int*);
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1205
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1206 #if 0
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1207 template std::istream&
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1208 octave_scan (std::istream&, const scanf_format_elt&, float*);
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1209 #endif
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1210
5403
7bdddf96f028 [project @ 2005-07-07 16:46:23 by jwe]
jwe
parents: 5389
diff changeset
1211 template<>
5176
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1212 std::istream&
5403
7bdddf96f028 [project @ 2005-07-07 16:46:23 by jwe]
jwe
parents: 5389
diff changeset
1213 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
1214 {
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1215 double& ref = *valptr;
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1216
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1217 switch (fmt.type)
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1218 {
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1219 case 'e':
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1220 case 'f':
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1221 case 'g':
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1222 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1223 int c1 = EOF;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1224
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1225 while (is && (c1 = is.get ()) != EOF && isspace (c1))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1226 /* skip whitespace */;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1227
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1228 if (c1 != EOF)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1229 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1230 if (c1 == 'N')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1231 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1232 int c2 = is.get ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1233
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1234 if (c2 != EOF)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1235 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1236 if (c2 == 'A')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1237 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1238 int c3 = is.get ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1239
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1240 if (c3 != EOF)
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 is.putback (c3);
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 if (isspace (c3) || ispunct (c3))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1245 ref = octave_NA;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1246 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1247 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1248 is.putback (c2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1249 is.putback (c1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1250
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1251 is >> ref;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1252 }
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 else
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 is.clear ();
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 ref = octave_NA;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1259 }
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 if (c2 == 'a')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1262 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1263 int c3 = is.get ();
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 if (c3 != EOF)
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 if (c3 == '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 int c4 = is.get ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1270
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1271 if (c4 != EOF)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1272 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1273 is.putback (c4);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1274
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1275 if (isspace (c4) || ispunct (c4))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1276 ref = octave_NaN;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1277 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1278 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1279 is.putback (c3);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1280 is.putback (c2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1281 is.putback (c1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1282
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1283 is >> ref;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1284 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1285 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1286 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1287 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1288 is.clear ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1289
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1290 ref = octave_NaN;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1291 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1292 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1293 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1294 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1295 is.putback (c3);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1296 is.putback (c2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1297 is.putback (c1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1298
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1299 is >> ref;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1300 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1301 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1302 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1303 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1304 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1305 is.putback (c2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1306 is.putback (c1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1307
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1308 is >> ref;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1309 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1310 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1311 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1312 else if (c1 == 'I')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1313 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1314 int c2 = is.get ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1316 if (c2 != EOF)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1317 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1318 if (c2 == 'n')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1319 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1320 int c3 = is.get ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1321
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1322 if (c3 != EOF)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1323 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1324 if (c3 == 'f')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1325 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1326 int c4 = is.get ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1327
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1328 if (c4 != EOF)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1329 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1330 is.putback (c4);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1331
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1332 if (isspace (c4) || ispunct (c4))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1333 ref = octave_Inf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1334 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1335 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1336 is.putback (c3);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1337 is.putback (c2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1338 is.putback (c1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1339
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1340 is >> ref;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1341 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1342 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1343 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1344 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1345 is.clear ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1346
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1347 ref = octave_Inf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1348 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1349 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1350 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1351 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1352 is.putback (c3);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1353 is.putback (c2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1354 is.putback (c1);
12994
b12e2cffaa2f fix scanf problem with reading I (bug #33722)
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 12984
diff changeset
1355
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1356 is >> ref;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1357 }
12994
b12e2cffaa2f fix scanf problem with reading I (bug #33722)
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 12984
diff changeset
1358 }
b12e2cffaa2f fix scanf problem with reading I (bug #33722)
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 12984
diff changeset
1359 else
b12e2cffaa2f fix scanf problem with reading I (bug #33722)
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 12984
diff changeset
1360 {
b12e2cffaa2f fix scanf problem with reading I (bug #33722)
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 12984
diff changeset
1361 is.putback (c2);
b12e2cffaa2f fix scanf problem with reading I (bug #33722)
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 12984
diff changeset
1362 is.putback (c1);
b12e2cffaa2f fix scanf problem with reading I (bug #33722)
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 12984
diff changeset
1363
b12e2cffaa2f fix scanf problem with reading I (bug #33722)
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 12984
diff changeset
1364 is >> ref;
b12e2cffaa2f fix scanf problem with reading I (bug #33722)
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 12984
diff changeset
1365 }
b12e2cffaa2f fix scanf problem with reading I (bug #33722)
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 12984
diff changeset
1366 }
b12e2cffaa2f fix scanf problem with reading I (bug #33722)
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 12984
diff changeset
1367 else
b12e2cffaa2f fix scanf problem with reading I (bug #33722)
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 12984
diff changeset
1368 {
b12e2cffaa2f fix scanf problem with reading I (bug #33722)
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 12984
diff changeset
1369 is.putback (c2);
b12e2cffaa2f fix scanf problem with reading I (bug #33722)
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 12984
diff changeset
1370 is.putback (c1);
b12e2cffaa2f fix scanf problem with reading I (bug #33722)
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 12984
diff changeset
1371
b12e2cffaa2f fix scanf problem with reading I (bug #33722)
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 12984
diff changeset
1372 is >> ref;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1373 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1374 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1375 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1376 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1377 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1378 is.putback (c1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1379
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1380 is >> ref;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1381 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1382 }
5176
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1383 }
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1384 break;
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1385
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1386 default:
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1387 panic_impossible ();
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1388 break;
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1389 }
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1390
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1391 return is;
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1392 }
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1393
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1394 template <class T>
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1395 void
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1396 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
1397 T valptr, Matrix& mval, double *data, octave_idx_type& idx,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1398 octave_idx_type& conversion_count, octave_idx_type nr, octave_idx_type max_size,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1399 bool discard)
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1400 {
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1401 OCTAVE_SCAN (is, fmt, valptr);
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1402
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1403 if (is)
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1404 {
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1405 if (idx == max_size && ! discard)
10315
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 max_size *= 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1408
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1409 if (nr > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1410 mval.resize (nr, max_size / nr, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1411 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1412 mval.resize (max_size, 1, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1413
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1414 data = mval.fortran_vec ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1415 }
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1416
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1417 if (! discard)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1418 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1419 conversion_count++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1420 data[idx++] = *(valptr);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1421 }
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1422 }
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1423 }
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1424
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1425 template void
3878
faeca8a063ae [project @ 2002-03-07 23:28:32 by jwe]
jwe
parents: 3810
diff changeset
1426 do_scanf_conv (std::istream&, const scanf_format_elt&, int*,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1427 Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool);
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1428
3233
98d0ee053ba4 [project @ 1999-01-27 20:23:40 by jwe]
jwe
parents: 3180
diff changeset
1429 template void
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1430 do_scanf_conv (std::istream&, const scanf_format_elt&, long int*,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1431 Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool);
3233
98d0ee053ba4 [project @ 1999-01-27 20:23:40 by jwe]
jwe
parents: 3180
diff changeset
1432
98d0ee053ba4 [project @ 1999-01-27 20:23:40 by jwe]
jwe
parents: 3180
diff changeset
1433 template void
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1434 do_scanf_conv (std::istream&, const scanf_format_elt&, short int*,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1435 Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool);
3233
98d0ee053ba4 [project @ 1999-01-27 20:23:40 by jwe]
jwe
parents: 3180
diff changeset
1436
3878
faeca8a063ae [project @ 2002-03-07 23:28:32 by jwe]
jwe
parents: 3810
diff changeset
1437 template void
faeca8a063ae [project @ 2002-03-07 23:28:32 by jwe]
jwe
parents: 3810
diff changeset
1438 do_scanf_conv (std::istream&, const scanf_format_elt&, unsigned int*,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1439 Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool);
3878
faeca8a063ae [project @ 2002-03-07 23:28:32 by jwe]
jwe
parents: 3810
diff changeset
1440
faeca8a063ae [project @ 2002-03-07 23:28:32 by jwe]
jwe
parents: 3810
diff changeset
1441 template void
faeca8a063ae [project @ 2002-03-07 23:28:32 by jwe]
jwe
parents: 3810
diff changeset
1442 do_scanf_conv (std::istream&, const scanf_format_elt&, unsigned long int*,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1443 Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool);
3878
faeca8a063ae [project @ 2002-03-07 23:28:32 by jwe]
jwe
parents: 3810
diff changeset
1444
faeca8a063ae [project @ 2002-03-07 23:28:32 by jwe]
jwe
parents: 3810
diff changeset
1445 template void
faeca8a063ae [project @ 2002-03-07 23:28:32 by jwe]
jwe
parents: 3810
diff changeset
1446 do_scanf_conv (std::istream&, const scanf_format_elt&, unsigned short int*,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1447 Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool);
3878
faeca8a063ae [project @ 2002-03-07 23:28:32 by jwe]
jwe
parents: 3810
diff changeset
1448
2600
c454cd888ada [project @ 1996-12-19 22:35:54 by jwe]
jwe
parents: 2572
diff changeset
1449 #if 0
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1450 template void
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1451 do_scanf_conv (std::istream&, const scanf_format_elt&, float*,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1452 Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool);
2600
c454cd888ada [project @ 1996-12-19 22:35:54 by jwe]
jwe
parents: 2572
diff changeset
1453 #endif
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1454
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1455 template void
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1456 do_scanf_conv (std::istream&, const scanf_format_elt&, double*,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1457 Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool);
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1458
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1459 #define DO_WHITESPACE_CONVERSION() \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1460 do \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1461 { \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1462 int c = EOF; \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1463 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1464 while (is && (c = is.get ()) != EOF && isspace (c)) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1465 /* skip whitespace */; \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1466 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1467 if (c != EOF) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1468 is.putback (c); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1469 } \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1470 while (0)
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1471
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1472 #define DO_LITERAL_CONVERSION() \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1473 do \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1474 { \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1475 int c = EOF; \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1476 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1477 int n = strlen (fmt); \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1478 int i = 0; \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1479 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1480 while (i < n && is && (c = is.get ()) != EOF) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1481 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1482 if (c == static_cast<unsigned char> (fmt[i])) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1483 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1484 i++; \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1485 continue; \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1486 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1487 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1488 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1489 is.putback (c); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1490 break; \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1491 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1492 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1493 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1494 if (i != n) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1495 is.setstate (std::ios::failbit); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1496 } \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1497 while (0)
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1498
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1499 #define DO_PCT_CONVERSION() \
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1500 do \
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1501 { \
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1502 int c = is.get (); \
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1503 \
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1504 if (c != EOF) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1505 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1506 if (c != '%') \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1507 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1508 is.putback (c); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1509 is.setstate (std::ios::failbit); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1510 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1511 } \
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1512 else \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1513 is.setstate (std::ios::failbit); \
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1514 } \
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1515 while (0)
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1516
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1517 #define BEGIN_C_CONVERSION() \
3538
0ff7323dab8b [project @ 2000-02-02 12:36:25 by jwe]
jwe
parents: 3536
diff changeset
1518 is.unsetf (std::ios::skipws); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1519 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1520 int width = elt->width ? elt->width : 1; \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1521 \
9952
7cd2e1b372e5 allow scanf to store ASCII NUL values
John W. Eaton <jwe@octave.org>
parents: 9941
diff changeset
1522 std::string tmp (width, '\0'); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1523 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1524 int c = EOF; \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1525 int n = 0; \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1526 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1527 while (is && n < width && (c = is.get ()) != EOF) \
9952
7cd2e1b372e5 allow scanf to store ASCII NUL values
John W. Eaton <jwe@octave.org>
parents: 9941
diff changeset
1528 tmp[n++] = static_cast<char> (c); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1529 \
5266
3fe873712e07 [project @ 2005-04-05 15:49:50 by jwe]
jwe
parents: 5259
diff changeset
1530 if (n > 0 && c == EOF) \
12984
7626f8934466 correctly resize scanf output for %c formats (bug #34037)
John W. Eaton <jwe@octave.org>
parents: 12966
diff changeset
1531 is.clear (); \
7626f8934466 correctly resize scanf output for %c formats (bug #34037)
John W. Eaton <jwe@octave.org>
parents: 12966
diff changeset
1532 \
7626f8934466 correctly resize scanf output for %c formats (bug #34037)
John W. Eaton <jwe@octave.org>
parents: 12966
diff changeset
1533 tmp.resize (n)
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1534
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1535 // 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
1536 // 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
1537 #define BEGIN_S_CONVERSION() \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1538 int width = elt->width; \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1539 \
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
1540 std::string tmp; \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1541 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1542 do \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1543 { \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1544 if (width) \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1545 { \
10076
4b270d1540f7 avoid various GCC warnings
John W. Eaton <jwe@octave.org>
parents: 9952
diff changeset
1546 tmp = std::string (width, '\0'); \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1547 \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1548 int c = EOF; \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1549 \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1550 int n = 0; \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1551 \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1552 while (is && (c = is.get ()) != EOF) \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1553 { \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1554 if (! isspace (c)) \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1555 { \
9952
7cd2e1b372e5 allow scanf to store ASCII NUL values
John W. Eaton <jwe@octave.org>
parents: 9941
diff changeset
1556 tmp[n++] = static_cast<char> (c); \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1557 break; \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1558 } \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1559 } \
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
1560 \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1561 while (is && n < width && (c = is.get ()) != EOF) \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1562 { \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1563 if (isspace (c)) \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1564 { \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1565 is.putback (c); \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1566 break; \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1567 } \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1568 else \
9952
7cd2e1b372e5 allow scanf to store ASCII NUL values
John W. Eaton <jwe@octave.org>
parents: 9941
diff changeset
1569 tmp[n++] = static_cast<char> (c); \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1570 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1571 \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1572 if (n > 0 && c == EOF) \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1573 is.clear (); \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1574 \
9952
7cd2e1b372e5 allow scanf to store ASCII NUL values
John W. Eaton <jwe@octave.org>
parents: 9941
diff changeset
1575 tmp.resize (n); \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1576 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1577 else \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1578 { \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1579 is >> std::ws >> tmp; \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1580 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1581 } \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1582 while (0)
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1583
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1584 // This format must match a nonempty sequence of characters.
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1585 #define BEGIN_CHAR_CLASS_CONVERSION() \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1586 int width = elt->width; \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1587 \
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
1588 std::string tmp; \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1589 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1590 do \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1591 { \
7426
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1592 if (! width) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1593 width = INT_MAX; \
7427
65f0a8ced9d2 [project @ 2008-01-28 22:42:18 by jwe]
jwe
parents: 7426
diff changeset
1594 \
7426
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1595 std::ostringstream buf; \
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1596 \
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1597 std::string char_class = elt->char_class; \
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
1598 \
7426
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1599 int c = EOF; \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1600 \
7426
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1601 if (elt->type == '[') \
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1602 { \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1603 int chars_read = 0; \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1604 while (is && chars_read++ < width && (c = is.get ()) != EOF \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1605 && char_class.find (c) != std::string::npos) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1606 buf << static_cast<char> (c); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1607 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1608 else \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1609 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1610 int chars_read = 0; \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1611 while (is && chars_read++ < width && (c = is.get ()) != EOF \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1612 && char_class.find (c) == std::string::npos) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1613 buf << static_cast<char> (c); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1614 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1615 \
7426
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1616 if (width == INT_MAX && c != EOF) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1617 is.putback (c); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1618 \
7426
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1619 tmp = buf.str (); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1620 \
7426
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1621 if (tmp.empty ()) \
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1622 is.setstate (std::ios::failbit); \
10969
da355a1a6d44 fix scanf char class conversion bug
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
1623 else if (c == EOF) \
da355a1a6d44 fix scanf char class conversion bug
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
1624 is.clear (); \
da355a1a6d44 fix scanf char class conversion bug
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
1625 \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1626 } \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1627 while (0)
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1628
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1629 #define FINISH_CHARACTER_CONVERSION() \
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1630 do \
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1631 { \
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
1632 width = tmp.length (); \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1633 \
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1634 if (is) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1635 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1636 int i = 0; \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1637 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1638 if (! discard) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1639 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1640 conversion_count++; \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1641 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1642 while (i < width) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1643 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1644 if (data_index == max_size) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1645 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1646 max_size *= 2; \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1647 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1648 if (all_char_conv) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1649 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1650 if (one_elt_size_spec) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1651 mval.resize (1, max_size, 0.0); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1652 else if (nr > 0) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1653 mval.resize (nr, max_size / nr, 0.0); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1654 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1655 panic_impossible (); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1656 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1657 else if (nr > 0) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1658 mval.resize (nr, max_size / nr, 0.0); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1659 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1660 mval.resize (max_size, 1, 0.0); \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1661 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1662 data = mval.fortran_vec (); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1663 } \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1664 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1665 data[data_index++] = tmp[i++]; \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1666 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1667 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1668 } \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1669 } \
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1670 while (0)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1671
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1672 octave_value
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1673 octave_base_stream::do_scanf (scanf_format_list& fmt_list,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1674 octave_idx_type nr, octave_idx_type nc, bool one_elt_size_spec,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1675 octave_idx_type& conversion_count, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1676 {
8773
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
1677 octave_value retval = Matrix ();
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
1678
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
1679 if ((interactive || forced_interactive) && file_number () == 0)
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
1680 {
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
1681 ::error ("%s: unable to read from stdin while running interactively",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1682 who.c_str ());
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1683
8773
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
1684 return retval;
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
1685 }
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
1686
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1687 conversion_count = 0;
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1688
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1689 octave_idx_type nconv = fmt_list.num_conversions ();
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1690
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1691 octave_idx_type data_index = 0;
2121
bc6ecd8f1175 [project @ 1996-05-12 06:45:55 by jwe]
jwe
parents: 2117
diff changeset
1692
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1693 if (nr == 0 || nc == 0)
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1694 {
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1695 if (one_elt_size_spec)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1696 nc = 0;
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1697
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1698 return Matrix (nr, nc, 0.0);
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1699 }
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1700
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1701 std::istream *isp = input_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1702
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1703 bool all_char_conv = fmt_list.all_character_conversions ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1704
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1705 Matrix mval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1706 double *data = 0;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1707 octave_idx_type max_size = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1708 octave_idx_type max_conv = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1709
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1710 octave_idx_type final_nr = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1711 octave_idx_type final_nc = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1712
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1713 if (all_char_conv)
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1714 {
4420
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
1715 // Any of these could be resized later (if we have %s
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
1716 // conversions, we may read more than one element for each
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
1717 // conversion).
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
1718
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1719 if (one_elt_size_spec)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1720 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1721 max_size = 512;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1722 mval.resize (1, max_size, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1723
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1724 if (nr > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1725 max_conv = nr;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1726 }
4420
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
1727 else if (nr > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1728 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1729 if (nc > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1730 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1731 mval.resize (nr, nc, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1732 max_size = max_conv = nr * nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1733 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1734 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1735 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1736 mval.resize (nr, 32, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1737 max_size = nr * 32;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1738 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1739 }
4420
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
1740 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1741 panic_impossible ();
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1742 }
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1743 else if (nr > 0)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1744 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1745 if (nc > 0)
10315
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 // Will not resize later.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1748 mval.resize (nr, nc, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1749 max_size = nr * nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1750 max_conv = max_size;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1751 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1752 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1753 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1754 // Maybe resize later.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1755 mval.resize (nr, 32, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1756 max_size = nr * 32;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1757 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1758 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1759 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1760 {
4420
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
1761 // Maybe resize later.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1762 mval.resize (32, 1, 0.0);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1763 max_size = 32;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1764 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1765
4420
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
1766 data = mval.fortran_vec ();
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
1767
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1768 if (isp)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1769 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1770 std::istream& is = *isp;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1771
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1772 const scanf_format_elt *elt = fmt_list.first ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1773
3538
0ff7323dab8b [project @ 2000-02-02 12:36:25 by jwe]
jwe
parents: 3536
diff changeset
1774 std::ios::fmtflags flags = is.flags ();
2213
c4a887694274 [project @ 1996-05-16 04:13:28 by jwe]
jwe
parents: 2127
diff changeset
1775
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1776 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
1777
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1778 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
1779
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1780 for (;;)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1781 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1782 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1783
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1784 if (elt)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1785 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1786 if (! (elt->type == scanf_format_elt::whitespace_conversion
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1787 || elt->type == scanf_format_elt::literal_conversion
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1788 || elt->type == '%')
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1789 && max_conv > 0 && conversion_count == max_conv)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1790 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1791 if (all_char_conv && one_elt_size_spec)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1792 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1793 final_nr = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1794 final_nc = data_index;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1795 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1796 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1797 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1798 final_nr = nr;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1799 final_nc = (data_index - 1) / nr + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1800 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1801
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1802 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1803 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1804 else if (data_index == max_size)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1805 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1806 max_size *= 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1807
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1808 if (all_char_conv)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1809 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1810 if (one_elt_size_spec)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1811 mval.resize (1, max_size, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1812 else if (nr > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1813 mval.resize (nr, max_size / nr, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1814 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1815 panic_impossible ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1816 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1817 else if (nr > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1818 mval.resize (nr, max_size / nr, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1819 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1820 mval.resize (max_size, 1, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1821
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1822 data = mval.fortran_vec ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1823 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1824
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1825 const char *fmt = elt->text;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1826
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1827 bool discard = elt->discard;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1828
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1829 switch (elt->type)
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 case scanf_format_elt::whitespace_conversion:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1832 DO_WHITESPACE_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1833 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1834
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1835 case scanf_format_elt::literal_conversion:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1836 DO_LITERAL_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1837 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1838
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1839 case '%':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1840 DO_PCT_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1841 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1842
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1843 case 'd': case 'i':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1844 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1845 switch (elt->modifier)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1846 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1847 case 'h':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1848 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1849 short int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1850 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1851 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1852 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1853 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1854 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1855
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1856 case 'l':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1857 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1858 long int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1859 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1860 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1861 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1862 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1863 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1864
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1865 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1866 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1867 int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1868 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1869 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1870 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1871 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1872 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1873 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1874 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1875 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1876
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1877 case 'o': case 'u': case 'x':
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 switch (elt->modifier)
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 case 'h':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1882 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1883 unsigned short int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1884 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1885 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1886 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1887 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1888 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1889
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1890 case 'l':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1891 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1892 unsigned long int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1893 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1894 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1895 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1896 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1897 break;
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 default:
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 unsigned int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1902 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1903 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1904 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1905 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1906 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1907 }
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 break;
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 case 'e': case 'f': case 'g':
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 double tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1914
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1915 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1916 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1917 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1918 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1919 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1920
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1921 case 'c':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1922 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1923 BEGIN_C_CONVERSION ();
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 FINISH_CHARACTER_CONVERSION ();
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 is.setf (flags);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1928 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1929 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1930
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1931 case 's':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1932 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1933 BEGIN_S_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1934
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1935 FINISH_CHARACTER_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1936 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1937 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1938
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1939 case '[': case '^':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1940 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1941 BEGIN_CHAR_CLASS_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1942
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1943 FINISH_CHARACTER_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1944 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1945 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1946
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1947 case 'p':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1948 error ("%s: unsupported format specifier", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1949 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1950
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1951 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1952 error ("%s: internal format error", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1953 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1954 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1955
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1956 if (! ok ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1957 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1958 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1959 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1960 else if (! is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1961 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1962 if (all_char_conv)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1963 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1964 if (one_elt_size_spec)
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 final_nr = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1967 final_nc = data_index;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1968 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1969 else if (data_index > nr)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1970 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1971 final_nr = nr;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1972 final_nc = (data_index - 1) / nr + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1973 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1974 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1975 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1976 final_nr = data_index;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1977 final_nc = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1978 }
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 else if (nr > 0)
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 if (data_index > nr)
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 final_nr = nr;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1985 final_nc = (data_index - 1) / nr + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1986 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1987 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1988 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1989 final_nr = data_index;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1990 final_nc = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1991 }
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 else
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 final_nr = data_index;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1996 final_nc = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1997 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1998
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1999 // 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
2000 // reset the failbit in the stream state.
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 if (is.rdstate () & std::ios::failbit)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2003 is.clear (is.rdstate () & (~std::ios::failbit));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2004
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2005 // FIXME -- is this the right thing to do?
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2006
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2007 if (interactive && name () == "stdin")
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 is.clear ();
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 // Skip to end of line.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2012
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2013 bool err;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2014 do_gets (-1, err, false, who);
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
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2017 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2018 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2019 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2020 else
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 error ("%s: internal format error", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2023 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2024 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2025
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2026 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
2027 {
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2028 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
2029 {
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2030 final_nr = 1;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2031 final_nc = data_index;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2032 }
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2033 else
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2034 {
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2035 final_nr = nr;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2036 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
2037 }
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2038
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2039 break;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2040 }
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2041 else
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2042 elt = fmt_list.next (nconv > 0);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2043 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2044 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2045
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2046 if (ok ())
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2047 {
2121
bc6ecd8f1175 [project @ 1996-05-12 06:45:55 by jwe]
jwe
parents: 2117
diff changeset
2048 mval.resize (final_nr, final_nc, 0.0);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2049
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
2050 retval = mval;
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
2051
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2052 if (all_char_conv)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2053 retval = retval.convert_to_str (false, true);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2054 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2055
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2056 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2057 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2058
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2059 octave_value
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
2060 octave_base_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
2061 octave_idx_type& conversion_count, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2062 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2063 octave_value retval = Matrix ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2064
3559
12d7ec415f35 [project @ 2000-02-03 05:17:36 by jwe]
jwe
parents: 3553
diff changeset
2065 conversion_count = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2066
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2067 std::istream *isp = input_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2068
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2069 if (isp)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2070 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2071 scanf_format_list fmt_list (fmt);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2072
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2073 if (fmt_list.num_conversions () == -1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2074 ::error ("%s: invalid format specified", who.c_str ());
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2075 else
10315
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 octave_idx_type nr = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2078 octave_idx_type nc = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2079
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2080 bool one_elt_size_spec;
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 get_size (size, nr, nc, one_elt_size_spec, who);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2083
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2084 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2085 retval = do_scanf (fmt_list, nr, nc, one_elt_size_spec,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2086 conversion_count, who);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2087 }
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2088 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2089 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2090 invalid_operation (who, "reading");
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2091
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2092 return retval;
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2093 }
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2094
2712
2ff2b536cc9d [project @ 1997-02-21 21:38:21 by jwe]
jwe
parents: 2687
diff changeset
2095 bool
2ff2b536cc9d [project @ 1997-02-21 21:38:21 by jwe]
jwe
parents: 2687
diff changeset
2096 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
2097 octave_value& retval, const std::string& who)
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2098 {
2712
2ff2b536cc9d [project @ 1997-02-21 21:38:21 by jwe]
jwe
parents: 2687
diff changeset
2099 bool quit = false;
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2100
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2101 std::istream *isp = input_stream ();
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2102
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2103 if (isp)
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2104 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2105 std::istream& is = *isp;
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2106
3538
0ff7323dab8b [project @ 2000-02-02 12:36:25 by jwe]
jwe
parents: 3536
diff changeset
2107 std::ios::fmtflags flags = is.flags ();
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2108
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2109 if (elt)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2110 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2111 const char *fmt = elt->text;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2112
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2113 bool discard = elt->discard;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2114
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2115 switch (elt->type)
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 case scanf_format_elt::whitespace_conversion:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2118 DO_WHITESPACE_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2119 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2120
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2121 case scanf_format_elt::literal_conversion:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2122 DO_LITERAL_CONVERSION ();
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
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2125 case '%':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2126 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2127 DO_PCT_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2128
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2129 if (! is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2130 quit = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2131
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2132 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2133 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2134
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2135 case 'd': case 'i':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2136 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2137 int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2138
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2139 if (OCTAVE_SCAN (is, *elt, &tmp))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2140 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2141 if (! discard)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2142 retval = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2143 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2144 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2145 quit = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2146 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2147 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2148
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2149 case 'o': case 'u': case 'x':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2150 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2151 long int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2152
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2153 if (OCTAVE_SCAN (is, *elt, &tmp))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2154 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2155 if (! discard)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2156 retval = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2157 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2158 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2159 quit = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2160 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2161 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2162
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2163 case 'e': case 'f': case 'g':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2164 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2165 double tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2166
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2167 if (OCTAVE_SCAN (is, *elt, &tmp))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2168 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2169 if (! discard)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2170 retval = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2171 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2172 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2173 quit = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2174 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2175 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2176
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2177 case 'c':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2178 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2179 BEGIN_C_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2180
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2181 if (! discard)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2182 retval = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2183
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2184 if (! is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2185 quit = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2186
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2187 is.setf (flags);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2188 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2189 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2190
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2191 case 's':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2192 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2193 BEGIN_S_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2194
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2195 if (! discard)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2196 retval = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2197
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2198 if (! is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2199 quit = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2200 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2201 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2202
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2203 case '[': case '^':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2204 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2205 BEGIN_CHAR_CLASS_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2206
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2207 if (! discard)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2208 retval = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2209
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2210 if (! is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2211 quit = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2212 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2213 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2214
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2215 case 'p':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2216 error ("%s: unsupported format specifier", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2217 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2218
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2219 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2220 error ("%s: internal format error", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2221 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2222 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2223 }
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2224
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2225 if (ok () && is.fail ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2226 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2227 error ("%s: read error", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2228
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2229 // FIXME -- is this the right thing to do?
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2230
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2231 if (interactive && name () == "stdin")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2232 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2233 // Skip to end of line.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2234
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2235 bool err;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2236 do_gets (-1, err, false, who);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2237 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2238 }
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2239 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2240
2712
2ff2b536cc9d [project @ 1997-02-21 21:38:21 by jwe]
jwe
parents: 2687
diff changeset
2241 return quit;
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2242 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2243
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2244 octave_value_list
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2245 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
2246 {
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2247 octave_value_list retval;
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2248
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2249 std::istream *isp = input_stream ();
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2250
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2251 if (isp)
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2252 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2253 std::istream& is = *isp;
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2254
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2255 scanf_format_list fmt_list (fmt);
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2256
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2257 octave_idx_type nconv = fmt_list.num_conversions ();
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2258
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2259 if (nconv == -1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2260 ::error ("%s: invalid format specified", who.c_str ());
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2261 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2262 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2263 is.clear ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2264
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2265 octave_idx_type len = fmt_list.length ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2266
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2267 retval.resize (nconv+1, Matrix ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2268
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2269 const scanf_format_elt *elt = fmt_list.first ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2270
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2271 int num_values = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2272
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2273 bool quit = false;
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 for (octave_idx_type i = 0; i < len; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2276 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2277 octave_value tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2278
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2279 quit = do_oscanf (elt, tmp, who);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2280
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2281 if (quit)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2282 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2283 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2284 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2285 if (tmp.is_defined ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2286 retval (num_values++) = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2287
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2288 if (! ok ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2289 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2290
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2291 elt = fmt_list.next (nconv > 0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2292 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2293 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2294
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2295 retval(nconv) = num_values;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2296
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2297 if (! quit)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2298 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2299 // Pick up any trailing stuff.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2300 if (ok () && len > nconv)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2301 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2302 octave_value tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2303
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2304 elt = fmt_list.next ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2305
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2306 do_oscanf (elt, tmp, who);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2307 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2308 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2309 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2310 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2311 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2312 invalid_operation (who, "reading");
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2313
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2314 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2315 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2316
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2317 // Functions that are defined for all output streams (output streams
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2318 // are those that define os).
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2319
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2320 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2321 octave_base_stream::flush (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2322 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2323 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2324
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2325 std::ostream *os = output_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2326
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2327 if (os)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2328 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2329 os->flush ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2330
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2331 if (os->good ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2332 retval = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2333 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2334 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2335 invalid_operation ("fflush", "writing");
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2336
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2337 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2338 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2339
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2340 class
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2341 printf_value_cache
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2342 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2343 public:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2344
3653
84b2f30007d5 [project @ 2000-03-31 23:33:25 by jwe]
jwe
parents: 3645
diff changeset
2345 enum state { ok, conversion_error };
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2346
7352
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2347 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
2348 : values (args), val_idx (0), elt_idx (0),
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2349 n_vals (values.length ()), n_elts (0), data (0),
7352
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2350 curr_state (ok)
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2351 {
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2352 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
2353 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2354 octave_value val = values(i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2355
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2356 if (val.is_map () || val.is_cell () || val.is_object ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2357 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2358 gripe_wrong_type_arg (who, val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2359 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2360 }
7352
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2361 }
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2362 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2363
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2364 ~printf_value_cache (void) { }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2365
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2366 // Get the current value as a double and advance the internal pointer.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2367 double double_value (void);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2368
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2369 // 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
2370 int int_value (void);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2371
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2372 // Get the current value as a string and advance the internal pointer.
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2373 std::string string_value (void);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2374
3145
0d640dc625c7 [project @ 1998-02-05 08:44:59 by jwe]
jwe
parents: 3013
diff changeset
2375 operator bool () const { return (curr_state == ok); }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2376
3653
84b2f30007d5 [project @ 2000-03-31 23:33:25 by jwe]
jwe
parents: 3645
diff changeset
2377 bool exhausted (void) { return (val_idx >= n_vals); }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2378
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2379 private:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2380
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2381 const octave_value_list values;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2382 int val_idx;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2383 int elt_idx;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2384 int n_vals;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2385 int n_elts;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2386 const double *data;
4874
c69a6a16932b [project @ 2004-04-22 16:02:25 by jwe]
jwe
parents: 4797
diff changeset
2387 NDArray curr_val;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2388 state curr_state;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2389
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2390 // Must create value cache with values!
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2391
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2392 printf_value_cache (void);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2393
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2394 // No copying!
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2395
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2396 printf_value_cache (const printf_value_cache&);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2397
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2398 printf_value_cache& operator = (const printf_value_cache&);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2399 };
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2400
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2401 double
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2402 printf_value_cache::double_value (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2403 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2404 double retval = 0.0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2405
3711
60db0e500f10 [project @ 2000-08-03 05:09:39 by jwe]
jwe
parents: 3704
diff changeset
2406 if (exhausted ())
60db0e500f10 [project @ 2000-08-03 05:09:39 by jwe]
jwe
parents: 3704
diff changeset
2407 curr_state = conversion_error;
60db0e500f10 [project @ 2000-08-03 05:09:39 by jwe]
jwe
parents: 3704
diff changeset
2408
60db0e500f10 [project @ 2000-08-03 05:09:39 by jwe]
jwe
parents: 3704
diff changeset
2409 while (! exhausted ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2410 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2411 if (! data)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2412 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2413 octave_value tmp_val = values (val_idx);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2414
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2415 // Force string conversion here for compatibility.
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 curr_val = tmp_val.array_value (true);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2418
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2419 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2420 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2421 elt_idx = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2422 n_elts = curr_val.length ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2423 data = curr_val.data ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2424 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2425 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2426 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2427 curr_state = conversion_error;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2428 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2429 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2430 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2431
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2432 if (elt_idx < n_elts)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2433 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2434 retval = data[elt_idx++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2435
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2436 if (elt_idx >= n_elts)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2437 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2438 elt_idx = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2439 val_idx++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2440 data = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2441 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2442
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2443 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2444 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2445 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2446 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2447 val_idx++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2448 data = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2449
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2450 if (n_elts == 0 && exhausted ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2451 curr_state = conversion_error;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2452
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2453 continue;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2454 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2455 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2456
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2457 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2458 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2459
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2460 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2461 printf_value_cache::int_value (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2462 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2463 int retval = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2464
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2465 double dval = double_value ();
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 if (! error_state)
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 if (D_NINT (dval) == dval)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2470 retval = NINT (dval);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2471 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2472 curr_state = conversion_error;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2473 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2474
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2475 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2476 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2477
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
2478 std::string
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2479 printf_value_cache::string_value (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2480 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2481 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2482
4425
82f8aae8cf20 [project @ 2003-06-13 15:08:25 by jwe]
jwe
parents: 4420
diff changeset
2483 if (exhausted ())
82f8aae8cf20 [project @ 2003-06-13 15:08:25 by jwe]
jwe
parents: 4420
diff changeset
2484 curr_state = conversion_error;
4257
e556870ce8f0 [project @ 2003-01-02 03:14:41 by jwe]
jwe
parents: 4254
diff changeset
2485 else
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2486 {
4425
82f8aae8cf20 [project @ 2003-06-13 15:08:25 by jwe]
jwe
parents: 4420
diff changeset
2487 octave_value tval = values (val_idx++);
82f8aae8cf20 [project @ 2003-06-13 15:08:25 by jwe]
jwe
parents: 4420
diff changeset
2488
82f8aae8cf20 [project @ 2003-06-13 15:08:25 by jwe]
jwe
parents: 4420
diff changeset
2489 if (tval.rows () == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2490 retval = tval.string_value ();
4425
82f8aae8cf20 [project @ 2003-06-13 15:08:25 by jwe]
jwe
parents: 4420
diff changeset
2491 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2492 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2493 // In the name of Matlab compatibility.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2494
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2495 charMatrix chm = tval.char_matrix_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2496
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2497 octave_idx_type nr = chm.rows ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2498 octave_idx_type nc = chm.columns ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2499
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2500 int k = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2501
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2502 retval.resize (nr * nc, '\0');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2503
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2504 for (octave_idx_type j = 0; j < nc; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2505 for (octave_idx_type i = 0; i < nr; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2506 retval[k++] = chm(i,j);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2507 }
4425
82f8aae8cf20 [project @ 2003-06-13 15:08:25 by jwe]
jwe
parents: 4420
diff changeset
2508
82f8aae8cf20 [project @ 2003-06-13 15:08:25 by jwe]
jwe
parents: 4420
diff changeset
2509 if (error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2510 curr_state = conversion_error;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2511 }
4257
e556870ce8f0 [project @ 2003-01-02 03:14:41 by jwe]
jwe
parents: 4254
diff changeset
2512
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2513 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2514 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2515
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2516 // Ugh again and again.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2517
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2518 template <class T>
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
2519 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2520 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
2521 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
2522 {
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
2523 int retval = 0;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
2524
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2525 switch (nsa)
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2526 {
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2527 case 2:
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2528 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
2529 break;
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2530
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2531 case 1:
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2532 retval = octave_format (os, fmt, sa_1, arg);
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2533 break;
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2534
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2535 case 0:
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2536 retval = octave_format (os, fmt, arg);
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2537 break;
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2538
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2539 default:
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2540 ::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
2541 break;
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2542 }
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
2543
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
2544 return retval;
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2545 }
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2546
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
2547 template int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2548 do_printf_conv (std::ostream&, const char*, int, int, int, int,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2549 const std::string&);
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2550
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2551 template int
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2552 do_printf_conv (std::ostream&, const char*, int, int, int, long,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2553 const std::string&);
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2554
3878
faeca8a063ae [project @ 2002-03-07 23:28:32 by jwe]
jwe
parents: 3810
diff changeset
2555 template int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2556 do_printf_conv (std::ostream&, const char*, int, int, int, unsigned int,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2557 const std::string&);
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2558
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2559 template int
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2560 do_printf_conv (std::ostream&, const char*, int, int, int, unsigned long,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2561 const std::string&);
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2562
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2563 template int
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2564 do_printf_conv (std::ostream&, const char*, int, int, int, double,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2565 const std::string&);
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2566
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2567 template int
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2568 do_printf_conv (std::ostream&, const char*, int, int, int, const char*,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2569 const std::string&);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2570
6492
bcfdc9f0d267 [project @ 2007-04-05 06:13:30 by jwe]
jwe
parents: 6483
diff changeset
2571 #define DO_DOUBLE_CONV(TQUAL) \
bcfdc9f0d267 [project @ 2007-04-05 06:13:30 by jwe]
jwe
parents: 6483
diff changeset
2572 do \
bcfdc9f0d267 [project @ 2007-04-05 06:13:30 by jwe]
jwe
parents: 6483
diff changeset
2573 { \
7199
cd6ceb8cbf09 [project @ 2007-11-27 03:29:57 by jwe]
jwe
parents: 7017
diff changeset
2574 if (val > std::numeric_limits<TQUAL long>::max () \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2575 || val < std::numeric_limits<TQUAL long>::min ()) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2576 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2577 std::string tfmt = fmt; \
6492
bcfdc9f0d267 [project @ 2007-04-05 06:13:30 by jwe]
jwe
parents: 6483
diff changeset
2578 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2579 tfmt.replace (tfmt.rfind (elt->type), 1, ".f"); \
6492
bcfdc9f0d267 [project @ 2007-04-05 06:13:30 by jwe]
jwe
parents: 6483
diff changeset
2580 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2581 if (elt->modifier == 'l') \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2582 tfmt.replace (tfmt.rfind (elt->modifier), 1, ""); \
7199
cd6ceb8cbf09 [project @ 2007-11-27 03:29:57 by jwe]
jwe
parents: 7017
diff changeset
2583 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2584 retval += do_printf_conv (os, tfmt.c_str (), nsa, sa_1, sa_2, \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2585 val, who); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2586 } \
6492
bcfdc9f0d267 [project @ 2007-04-05 06:13:30 by jwe]
jwe
parents: 6483
diff changeset
2587 else \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2588 retval += do_printf_conv (os, fmt, nsa, sa_1, sa_2, \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2589 static_cast<TQUAL long> (val), who); \
6492
bcfdc9f0d267 [project @ 2007-04-05 06:13:30 by jwe]
jwe
parents: 6483
diff changeset
2590 } \
bcfdc9f0d267 [project @ 2007-04-05 06:13:30 by jwe]
jwe
parents: 6483
diff changeset
2591 while (0)
bcfdc9f0d267 [project @ 2007-04-05 06:13:30 by jwe]
jwe
parents: 6483
diff changeset
2592
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2593 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2594 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
2595 const octave_value_list& args,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2596 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2597 {
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
2598 int retval = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2599
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2600 octave_idx_type nconv = fmt_list.num_conversions ();
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2601
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2602 std::ostream *osp = output_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2603
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2604 if (osp)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2605 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2606 std::ostream& os = *osp;
2117
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 const printf_format_elt *elt = fmt_list.first ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2609
7352
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2610 printf_value_cache val_cache (args, who);
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2611
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2612 if (error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2613 return retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2614
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2615 for (;;)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2616 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2617 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2618
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2619 if (elt)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2620 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2621 // NSA is the number of `star' args to convert.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2622
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2623 int nsa = (elt->fw < 0) + (elt->prec < 0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2624
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2625 int sa_1 = 0;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2626 int sa_2 = 0;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2627
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2628 if (nsa > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2629 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2630 sa_1 = val_cache.int_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2631
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2632 if (! val_cache)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2633 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2634 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2635 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2636 if (nsa > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2637 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2638 sa_2 = val_cache.int_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2639
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2640 if (! val_cache)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2641 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2642 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2643 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2644 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2645
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2646 const char *fmt = elt->text;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2647
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2648 if (elt->type == '%')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2649 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2650 os << "%";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2651 retval++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2652 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2653 else if (elt->args == 0 && elt->text)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2654 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2655 os << elt->text;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2656 retval += strlen (elt->text);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2657 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2658 else if (elt->type == 's')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2659 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2660 std::string val = val_cache.string_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2661
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2662 if (val_cache)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2663 retval += do_printf_conv (os, fmt, nsa, sa_1,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2664 sa_2, val.c_str (), who);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2665 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2666 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2667 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2668 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2669 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2670 double val = val_cache.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2671
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2672 if (val_cache)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2673 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2674 if (lo_ieee_isnan (val) || xisinf (val))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2675 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2676 std::string tfmt = fmt;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2677 std::string::size_type i1, i2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2678
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2679 tfmt.replace ((i1 = tfmt.rfind (elt->type)),
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2680 1, 1, 's');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2681
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2682 if ((i2 = tfmt.rfind ('.')) != std::string::npos && i2 < i1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2683 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2684 tfmt.erase (i2, i1-i2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2685 if (elt->prec < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2686 nsa--;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2687 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2688
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2689 const char *tval = xisinf (val)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2690 ? (val < 0 ? "-Inf" : "Inf")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2691 : (lo_ieee_is_NA (val) ? "NA" : "NaN");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2692
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2693 retval += do_printf_conv (os, tfmt.c_str (),
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2694 nsa, sa_1, sa_2,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2695 tval, who);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2696 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2697 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2698 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2699 char type = elt->type;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2700
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2701 switch (type)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2702 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2703 case 'd': case 'i': case 'c':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2704 DO_DOUBLE_CONV (OCTAVE_EMPTY_CPP_ARG);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2705 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2706
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2707 case 'o': case 'x': case 'X': case 'u':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2708 DO_DOUBLE_CONV (unsigned);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2709 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2710
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2711 case 'f': case 'e': case 'E':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2712 case 'g': case 'G':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2713 retval
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2714 += do_printf_conv (os, fmt, nsa, sa_1, sa_2,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2715 val, who);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2716 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2717
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2718 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2719 error ("%s: invalid format specifier",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2720 who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2721 return -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2722 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2723 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2724 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2725 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2726 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2727 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2728 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2729
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2730 if (! os)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2731 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2732 error ("%s: write error", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2733 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2734 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2735 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2736 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2737 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2738 ::error ("%s: internal error handling format", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2739 retval = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2740 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2741 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2742
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2743 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
2744
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2745 if (! elt || (val_cache.exhausted () && elt->args > 0))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2746 break;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2747 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2748 }
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2749 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2750 invalid_operation (who, "writing");
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2751
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2752 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2753 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2754
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2755 int
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2756 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
2757 const octave_value_list& args,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2758 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2759 {
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2760 int retval = 0;
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2761
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2762 printf_format_list fmt_list (fmt);
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2763
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2764 if (fmt_list.num_conversions () == -1)
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2765 ::error ("%s: invalid format specified", who.c_str ());
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2766 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2767 retval = do_printf (fmt_list, args, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2768
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2769 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2770 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2771
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2772 int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2773 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
2774 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2775 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2776
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2777 std::ostream *osp = output_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2778
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2779 if (osp)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2780 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2781 std::ostream& os = *osp;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2782
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2783 os << s;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2784
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2785 if (os)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2786 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2787 // FIXME -- why does this seem to be necessary?
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2788 // Without it, output from a loop like
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2789 //
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2790 // 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
2791 //
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2792 // 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
2793
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2794 os.flush ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2795
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2796 if (os)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2797 retval = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2798 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2799 error ("%s: write error", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2800 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2801 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2802 error ("%s: write error", who.c_str ());
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2803 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2804 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2805 invalid_operation (who, "writing");
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2806
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2807 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2808 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2809
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2810 // Return current error message for this stream.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2811
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
2812 std::string
2435
3be97fe02051 [project @ 1996-10-27 21:31:29 by jwe]
jwe
parents: 2341
diff changeset
2813 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
2814 {
2435
3be97fe02051 [project @ 1996-10-27 21:31:29 by jwe]
jwe
parents: 2341
diff changeset
2815 err_num = fail ? -1 : 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2816
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2817 std::string tmp = errmsg;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2818
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2819 if (clear_err)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2820 clear ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2821
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2822 return tmp;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2823 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2824
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2825 void
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2826 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
2827 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2828 // Note that this is not ::error () !
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2829
6297
a943cb9c8068 [project @ 2007-02-10 08:42:27 by jwe]
jwe
parents: 6296
diff changeset
2830 error (who, std::string ("stream not open for ") + rw);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2831 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2832
3552
41daa489833a [project @ 2000-02-03 03:05:28 by jwe]
jwe
parents: 3548
diff changeset
2833 octave_stream::octave_stream (octave_base_stream *bs)
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2834 : rep (bs)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2835 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2836 if (rep)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2837 rep->count = 1;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2838 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2839
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2840 octave_stream::~octave_stream (void)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2841 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2842 if (rep && --rep->count == 0)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2843 delete rep;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2844 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2845
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2846 octave_stream::octave_stream (const octave_stream& s)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2847 : rep (s.rep)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2848 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2849 if (rep)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2850 rep->count++;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2851 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2852
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2853 octave_stream&
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2854 octave_stream::operator = (const octave_stream& s)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2855 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2856 if (rep != s.rep)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2857 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2858 if (rep && --rep->count == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2859 delete rep;
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2860
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2861 rep = s.rep;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2862
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2863 if (rep)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2864 rep->count++;
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2865 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2866
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2867 return *this;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2868 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2869
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2870 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2871 octave_stream::flush (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2872 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2873 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2874
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
2875 if (stream_ok ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2876 retval = rep->flush ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2877
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2878 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2879 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2880
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
2881 std::string
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
2882 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
2883 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2884 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2885
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
2886 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2887 retval = rep->getl (max_len, err, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2888
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2889 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2890 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2891
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
2892 std::string
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2893 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
2894 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2895 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2896 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2897
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2898 err = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2899
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2900 int conv_err = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2901
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2902 int max_len = -1;
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2903
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2904 if (tc_max_len.is_defined ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2905 {
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2906 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
2907
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2908 if (conv_err || max_len < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2909 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2910 err = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2911 ::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
2912 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2913 }
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2914
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2915 if (! error_state)
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2916 retval = getl (max_len, err, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2917
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2918 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2919 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2920
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
2921 std::string
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
2922 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
2923 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2924 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2925
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
2926 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2927 retval = rep->gets (max_len, err, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2928
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2929 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2930 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2931
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
2932 std::string
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2933 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
2934 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2935 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2936 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2937
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2938 err = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2939
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2940 int conv_err = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2941
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2942 int max_len = -1;
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2943
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2944 if (tc_max_len.is_defined ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2945 {
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2946 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
2947
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2948 if (conv_err || max_len < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2949 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2950 err = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2951 ::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
2952 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2953 }
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2954
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2955 if (! error_state)
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2956 retval = gets (max_len, err, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2957
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2958 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2959 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2960
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2961 long
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2962 octave_stream::skipl (long count, bool& err, const std::string& who)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2963 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2964 long retval = -1;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2965
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2966 if (stream_ok ())
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2967 retval = rep->skipl (count, err, who);
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2968
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2969 return retval;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2970 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2971
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2972 long
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2973 octave_stream::skipl (const octave_value& tc_count, bool& err, const std::string& who)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2974 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2975 long retval = -1;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2976
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2977 err = false;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2978
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2979 int conv_err = 0;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2980
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2981 int count = 1;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2982
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2983 if (tc_count.is_defined ())
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2984 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2985 if (tc_count.is_scalar_type () && xisinf (tc_count.scalar_value ()))
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2986 count = -1;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2987 else
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2988 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2989 count = convert_to_valid_int (tc_count, conv_err);
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2990
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2991 if (conv_err || count < 0)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2992 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2993 err = true;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2994 ::error ("%s: invalid number of lines specified", who.c_str ());
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2995 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2996 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2997 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2998
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2999 if (! error_state)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3000 retval = skipl (count, err, who);
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3001
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3002 return retval;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3003 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
3004
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3005 int
4797
19b8225bdaa2 [project @ 2004-02-23 22:10:31 by jwe]
jwe
parents: 4693
diff changeset
3006 octave_stream::seek (long offset, int origin)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3007 {
5065
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
3008 int status = -1;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3009
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3010 if (stream_ok ())
4889
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
3011 {
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
3012 clearerr ();
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
3013
5065
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
3014 long orig_pos = rep->tell ();
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
3015
12966
18797a4b6174 undo previous unintended change to oct-stream.cc
John W. Eaton <jwe@octave.org>
parents: 12957
diff changeset
3016 status = rep->seek (offset, origin);
5065
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
3017
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
3018 if (status == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3019 {
12966
18797a4b6174 undo previous unintended change to oct-stream.cc
John W. Eaton <jwe@octave.org>
parents: 12957
diff changeset
3020 long save_pos = rep->tell ();
18797a4b6174 undo previous unintended change to oct-stream.cc
John W. Eaton <jwe@octave.org>
parents: 12957
diff changeset
3021
18797a4b6174 undo previous unintended change to oct-stream.cc
John W. Eaton <jwe@octave.org>
parents: 12957
diff changeset
3022 rep->seek (0, SEEK_END);
18797a4b6174 undo previous unintended change to oct-stream.cc
John W. Eaton <jwe@octave.org>
parents: 12957
diff changeset
3023
18797a4b6174 undo previous unintended change to oct-stream.cc
John W. Eaton <jwe@octave.org>
parents: 12957
diff changeset
3024 long pos_eof = rep->tell ();
18797a4b6174 undo previous unintended change to oct-stream.cc
John W. Eaton <jwe@octave.org>
parents: 12957
diff changeset
3025
18797a4b6174 undo previous unintended change to oct-stream.cc
John W. Eaton <jwe@octave.org>
parents: 12957
diff changeset
3026 // I don't think save_pos can be less than zero, but we'll
18797a4b6174 undo previous unintended change to oct-stream.cc
John W. Eaton <jwe@octave.org>
parents: 12957
diff changeset
3027 // check anyway...
18797a4b6174 undo previous unintended change to oct-stream.cc
John W. Eaton <jwe@octave.org>
parents: 12957
diff changeset
3028
18797a4b6174 undo previous unintended change to oct-stream.cc
John W. Eaton <jwe@octave.org>
parents: 12957
diff changeset
3029 if (save_pos > pos_eof || save_pos < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3030 {
12966
18797a4b6174 undo previous unintended change to oct-stream.cc
John W. Eaton <jwe@octave.org>
parents: 12957
diff changeset
3031 // Seek outside bounds of file. Failure should leave
18797a4b6174 undo previous unintended change to oct-stream.cc
John W. Eaton <jwe@octave.org>
parents: 12957
diff changeset
3032 // position unchanged.
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3033
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3034 rep->seek (orig_pos, SEEK_SET);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3035
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3036 status = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3037 }
12966
18797a4b6174 undo previous unintended change to oct-stream.cc
John W. Eaton <jwe@octave.org>
parents: 12957
diff changeset
3038 else
18797a4b6174 undo previous unintended change to oct-stream.cc
John W. Eaton <jwe@octave.org>
parents: 12957
diff changeset
3039 {
18797a4b6174 undo previous unintended change to oct-stream.cc
John W. Eaton <jwe@octave.org>
parents: 12957
diff changeset
3040 // Is it possible for this to fail? We are just
18797a4b6174 undo previous unintended change to oct-stream.cc
John W. Eaton <jwe@octave.org>
parents: 12957
diff changeset
3041 // returning to a position after the first successful
18797a4b6174 undo previous unintended change to oct-stream.cc
John W. Eaton <jwe@octave.org>
parents: 12957
diff changeset
3042 // seek.
18797a4b6174 undo previous unintended change to oct-stream.cc
John W. Eaton <jwe@octave.org>
parents: 12957
diff changeset
3043
18797a4b6174 undo previous unintended change to oct-stream.cc
John W. Eaton <jwe@octave.org>
parents: 12957
diff changeset
3044 rep->seek (save_pos, SEEK_SET);
18797a4b6174 undo previous unintended change to oct-stream.cc
John W. Eaton <jwe@octave.org>
parents: 12957
diff changeset
3045 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3046 }
4889
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
3047 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3048
5065
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
3049 return status;
2117
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3052 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3053 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
3054 const octave_value& tc_origin)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3055 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3056 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3057
4797
19b8225bdaa2 [project @ 2004-02-23 22:10:31 by jwe]
jwe
parents: 4693
diff changeset
3058 long xoffset = tc_offset.long_value (true);
4645
bd2067547b40 [project @ 2003-11-23 08:07:52 by jwe]
jwe
parents: 4643
diff changeset
3059
bd2067547b40 [project @ 2003-11-23 08:07:52 by jwe]
jwe
parents: 4643
diff changeset
3060 if (! error_state)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3061 {
4645
bd2067547b40 [project @ 2003-11-23 08:07:52 by jwe]
jwe
parents: 4643
diff changeset
3062 int conv_err = 0;
bd2067547b40 [project @ 2003-11-23 08:07:52 by jwe]
jwe
parents: 4643
diff changeset
3063
4797
19b8225bdaa2 [project @ 2004-02-23 22:10:31 by jwe]
jwe
parents: 4693
diff changeset
3064 int origin = SEEK_SET;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3065
2341
6ee55c0f25a9 [project @ 1996-07-24 10:33:09 by jwe]
jwe
parents: 2317
diff changeset
3066 if (tc_origin.is_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3067 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3068 std::string xorigin = tc_origin.string_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3069
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3070 if (xorigin == "bof")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3071 origin = SEEK_SET;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3072 else if (xorigin == "cof")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3073 origin = SEEK_CUR;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3074 else if (xorigin == "eof")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3075 origin = SEEK_END;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3076 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3077 conv_err = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3078 }
2341
6ee55c0f25a9 [project @ 1996-07-24 10:33:09 by jwe]
jwe
parents: 2317
diff changeset
3079 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3080 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3081 int xorigin = convert_to_valid_int (tc_origin, conv_err);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3082
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3083 if (! conv_err)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3084 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3085 if (xorigin == -1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3086 origin = SEEK_SET;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3087 else if (xorigin == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3088 origin = SEEK_CUR;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3089 else if (xorigin == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3090 origin = SEEK_END;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3091 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3092 conv_err = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3093 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3094 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3095
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3096 if (! conv_err)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3097 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3098 retval = seek (xoffset, origin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3099
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3100 if (retval != 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3101 error ("fseek: failed to seek to requested position");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3102 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3103 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3104 error ("fseek: invalid value for origin");
2117
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 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3107 error ("fseek: invalid value for offset");
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3108
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3109 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3110 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3111
4797
19b8225bdaa2 [project @ 2004-02-23 22:10:31 by jwe]
jwe
parents: 4693
diff changeset
3112 long
19b8225bdaa2 [project @ 2004-02-23 22:10:31 by jwe]
jwe
parents: 4693
diff changeset
3113 octave_stream::tell (void)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3114 {
4797
19b8225bdaa2 [project @ 2004-02-23 22:10:31 by jwe]
jwe
parents: 4693
diff changeset
3115 long retval = -1;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3116
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3117 if (stream_ok ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3118 retval = rep->tell ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3119
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3120 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3121 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3122
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3123 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3124 octave_stream::rewind (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3125 {
6296
85eb75190e01 [project @ 2007-02-10 07:10:42 by jwe]
jwe
parents: 6109
diff changeset
3126 return seek (0, SEEK_SET);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3127 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3128
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3129 bool
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3130 octave_stream::is_open (void) const
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3131 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3132 bool retval = false;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3133
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3134 if (stream_ok ())
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3135 retval = rep->is_open ();
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3136
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3137 return retval;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3138 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3139
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3140 void
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3141 octave_stream::close (void)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3142 {
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3143 if (stream_ok ())
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3144 rep->close ();
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3145 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3146
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3147 template <class RET_T, class READ_T>
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3148 octave_value
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3149 do_read (octave_stream& strm, octave_idx_type nr, octave_idx_type nc, octave_idx_type block_size,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3150 octave_idx_type skip, bool do_float_fmt_conv, bool do_NA_conv,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3151 oct_mach_info::float_format from_flt_fmt, octave_idx_type& count)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3152 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3153 octave_value retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3154
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3155 RET_T nda;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3156
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3157 count = 0;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3158
9941
1369f13ae6b2 several fixes by M. Goffioul
Jaroslav Hajek <highegg@gmail.com>
parents: 9701
diff changeset
3159 typedef typename RET_T::element_type ELMT;
1369f13ae6b2 several fixes by M. Goffioul
Jaroslav Hajek <highegg@gmail.com>
parents: 9701
diff changeset
3160 ELMT elt_zero = ELMT ();
1369f13ae6b2 several fixes by M. Goffioul
Jaroslav Hajek <highegg@gmail.com>
parents: 9701
diff changeset
3161
1369f13ae6b2 several fixes by M. Goffioul
Jaroslav Hajek <highegg@gmail.com>
parents: 9701
diff changeset
3162 ELMT *dat = 0;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3163
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3164 octave_idx_type max_size = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3165
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3166 octave_idx_type final_nr = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3167 octave_idx_type final_nc = 1;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3168
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3169 if (nr > 0)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3170 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3171 if (nc > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3172 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3173 nda.resize (dim_vector (nr, nc), elt_zero);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3174 dat = nda.fortran_vec ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3175 max_size = nr * nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3176 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3177 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3178 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3179 nda.resize (dim_vector (nr, 32), elt_zero);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3180 dat = nda.fortran_vec ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3181 max_size = nr * 32;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3182 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3183 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3184 else
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3185 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3186 nda.resize (dim_vector (32, 1), elt_zero);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3187 dat = nda.fortran_vec ();
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3188 max_size = 32;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3189 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3190
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5765
diff changeset
3191 // FIXME -- byte order for Cray?
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3192
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3193 bool swap = false;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3194
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3195 if (oct_mach_info::words_big_endian ())
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3196 swap = (from_flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3197 || from_flt_fmt == oct_mach_info::flt_fmt_vax_g
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3198 || from_flt_fmt == oct_mach_info::flt_fmt_vax_g);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3199 else
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3200 swap = (from_flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3201
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3202 union
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3203 {
9685
e793865ede63 implement builtin_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9202
diff changeset
3204 char buf[sizeof (typename strip_template_param<octave_int, READ_T>::type)];
e793865ede63 implement builtin_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9202
diff changeset
3205 typename strip_template_param<octave_int, READ_T>::type val;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3206 } u;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3207
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3208 std::istream *isp = strm.input_stream ();
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3209
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3210 if (isp)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3211 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3212 std::istream& is = *isp;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3213
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3214 octave_idx_type elts_read = 0;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3215
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3216 for (;;)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3217 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3218 // FIXME -- maybe there should be a special case for
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3219 // skip == 0.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3220
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3221 if (is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3222 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3223 if (nr > 0 && nc > 0 && count == max_size)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3224 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3225 final_nr = nr;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3226 final_nc = nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3227
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3228 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3229 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3230
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3231 is.read (u.buf, sizeof (typename strip_template_param<octave_int, READ_T>::type));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3232
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3233 // We only swap bytes for integer types. For float
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3234 // types, the format conversion will also handle byte
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3235 // swapping.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3236
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3237 if (swap)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3238 swap_bytes<sizeof (typename strip_template_param<octave_int, READ_T>::type)> (u.buf);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3239 else if (do_float_fmt_conv)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3240 do_float_format_conversion
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3241 (u.buf,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3242 sizeof (typename strip_template_param<octave_int, READ_T>::type),
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3243 1, from_flt_fmt, oct_mach_info::float_format ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3244
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3245 typename RET_T::element_type tmp
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3246 = static_cast <typename RET_T::element_type> (u.val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3247
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3248 if (is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3249 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3250 if (count == max_size)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3251 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3252 max_size *= 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3253
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3254 if (nr > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3255 nda.resize (dim_vector (nr, max_size / nr),
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3256 elt_zero);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3257 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3258 nda.resize (dim_vector (max_size, 1), elt_zero);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3259
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3260 dat = nda.fortran_vec ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3261 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3262
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3263 if (do_NA_conv && __lo_ieee_is_old_NA (tmp))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3264 tmp = __lo_ieee_replace_old_NA (tmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3265
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3266 dat[count++] = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3267
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3268 elts_read++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3269 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3270
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3271 int seek_status = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3272
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3273 if (skip != 0 && elts_read == block_size)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3274 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3275 seek_status = strm.seek (skip, SEEK_CUR);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3276 elts_read = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3277 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3278
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3279 if (is.eof () || seek_status < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3280 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3281 if (nr > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3282 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3283 if (count > nr)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3284 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3285 final_nr = nr;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3286 final_nc = (count - 1) / nr + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3287 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3288 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3289 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3290 final_nr = count;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3291 final_nc = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3292 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3293 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3294 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3295 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3296 final_nr = count;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3297 final_nc = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3298 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3299
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3300 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3301 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3302 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3303 else if (is.eof ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3304 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3305 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3306 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3307
5030
160365410ad4 [project @ 2004-09-24 03:22:23 by jwe]
jwe
parents: 4970
diff changeset
3308 nda.resize (dim_vector (final_nr, final_nc), elt_zero);
160365410ad4 [project @ 2004-09-24 03:22:23 by jwe]
jwe
parents: 4970
diff changeset
3309
160365410ad4 [project @ 2004-09-24 03:22:23 by jwe]
jwe
parents: 4970
diff changeset
3310 retval = nda;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3311
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3312 return retval;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3313 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3314
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3315 #define DO_READ_VAL_TEMPLATE(RET_T, READ_T) \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3316 template octave_value \
7995
89dd4531b26a fread: translate NA values
John W. Eaton <jwe@octave.org>
parents: 7789
diff changeset
3317 do_read<RET_T, READ_T> (octave_stream&, octave_idx_type, octave_idx_type, octave_idx_type, octave_idx_type, bool, bool, \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3318 oct_mach_info::float_format, octave_idx_type&)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3319
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5765
diff changeset
3320 // FIXME -- should we only have float if it is a different
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3321 // size from double?
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3322
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3323 #define INSTANTIATE_DO_READ(VAL_T) \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3324 DO_READ_VAL_TEMPLATE (VAL_T, octave_int8); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3325 DO_READ_VAL_TEMPLATE (VAL_T, octave_uint8); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3326 DO_READ_VAL_TEMPLATE (VAL_T, octave_int16); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3327 DO_READ_VAL_TEMPLATE (VAL_T, octave_uint16); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3328 DO_READ_VAL_TEMPLATE (VAL_T, octave_int32); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3329 DO_READ_VAL_TEMPLATE (VAL_T, octave_uint32); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3330 DO_READ_VAL_TEMPLATE (VAL_T, octave_int64); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3331 DO_READ_VAL_TEMPLATE (VAL_T, octave_uint64); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3332 DO_READ_VAL_TEMPLATE (VAL_T, float); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3333 DO_READ_VAL_TEMPLATE (VAL_T, double); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3334 DO_READ_VAL_TEMPLATE (VAL_T, char); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3335 DO_READ_VAL_TEMPLATE (VAL_T, signed char); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3336 DO_READ_VAL_TEMPLATE (VAL_T, unsigned char)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3337
4970
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4946
diff changeset
3338 INSTANTIATE_DO_READ (int8NDArray);
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4946
diff changeset
3339 INSTANTIATE_DO_READ (uint8NDArray);
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4946
diff changeset
3340 INSTANTIATE_DO_READ (int16NDArray);
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4946
diff changeset
3341 INSTANTIATE_DO_READ (uint16NDArray);
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4946
diff changeset
3342 INSTANTIATE_DO_READ (int32NDArray);
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4946
diff changeset
3343 INSTANTIATE_DO_READ (uint32NDArray);
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4946
diff changeset
3344 INSTANTIATE_DO_READ (int64NDArray);
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4946
diff changeset
3345 INSTANTIATE_DO_READ (uint64NDArray);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7724
diff changeset
3346 INSTANTIATE_DO_READ (FloatNDArray);
4970
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4946
diff changeset
3347 INSTANTIATE_DO_READ (NDArray);
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4946
diff changeset
3348 INSTANTIATE_DO_READ (charNDArray);
5780
cbf717bf8150 [project @ 2006-04-27 20:02:30 by jwe]
jwe
parents: 5775
diff changeset
3349 INSTANTIATE_DO_READ (boolNDArray);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3350
7995
89dd4531b26a fread: translate NA values
John W. Eaton <jwe@octave.org>
parents: 7789
diff changeset
3351 typedef octave_value (*read_fptr) (octave_stream&, octave_idx_type, octave_idx_type, octave_idx_type, octave_idx_type, bool, bool,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3352 oct_mach_info::float_format ffmt, octave_idx_type&);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3353
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3354 #define FILL_TABLE_ROW(R, VAL_T) \
9202
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
3355 read_fptr_table[R][oct_data_conv::dt_int8] = do_read<VAL_T, octave_int8>; \
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
3356 read_fptr_table[R][oct_data_conv::dt_uint8] = do_read<VAL_T, octave_uint8>; \
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
3357 read_fptr_table[R][oct_data_conv::dt_int16] = do_read<VAL_T, octave_int16>; \
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
3358 read_fptr_table[R][oct_data_conv::dt_uint16] = do_read<VAL_T, octave_uint16>; \
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
3359 read_fptr_table[R][oct_data_conv::dt_int32] = do_read<VAL_T, octave_int32>; \
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
3360 read_fptr_table[R][oct_data_conv::dt_uint32] = do_read<VAL_T, octave_uint32>; \
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
3361 read_fptr_table[R][oct_data_conv::dt_int64] = do_read<VAL_T, octave_int64>; \
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
3362 read_fptr_table[R][oct_data_conv::dt_uint64] = do_read<VAL_T, octave_uint64>; \
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
3363 read_fptr_table[R][oct_data_conv::dt_single] = do_read<VAL_T, float>; \
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
3364 read_fptr_table[R][oct_data_conv::dt_double] = do_read<VAL_T, double>; \
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
3365 read_fptr_table[R][oct_data_conv::dt_char] = do_read<VAL_T, char>; \
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
3366 read_fptr_table[R][oct_data_conv::dt_schar] = do_read<VAL_T, signed char>; \
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
3367 read_fptr_table[R][oct_data_conv::dt_uchar] = do_read<VAL_T, unsigned char>; \
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
3368 read_fptr_table[R][oct_data_conv::dt_logical] = do_read<VAL_T, unsigned char>
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3369
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3370 octave_value
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3371 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
3372 oct_data_conv::data_type input_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3373 oct_data_conv::data_type output_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3374 octave_idx_type skip, oct_mach_info::float_format ffmt,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3375 octave_idx_type& char_count)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3376 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3377 static bool initialized = false;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3378
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3379 // Table function pointers for return types x read types.
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3380
9202
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
3381 static read_fptr read_fptr_table[oct_data_conv::dt_unknown][14];
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3382
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3383 if (! initialized)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3384 {
9202
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
3385 for (int i = 0; i < oct_data_conv::dt_unknown; i++)
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
3386 for (int j = 0; j < 14; j++)
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
3387 read_fptr_table[i][j] = 0;
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
3388
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3389 FILL_TABLE_ROW (oct_data_conv::dt_int8, int8NDArray);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3390 FILL_TABLE_ROW (oct_data_conv::dt_uint8, uint8NDArray);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3391 FILL_TABLE_ROW (oct_data_conv::dt_int16, int16NDArray);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3392 FILL_TABLE_ROW (oct_data_conv::dt_uint16, uint16NDArray);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3393 FILL_TABLE_ROW (oct_data_conv::dt_int32, int32NDArray);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3394 FILL_TABLE_ROW (oct_data_conv::dt_uint32, uint32NDArray);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3395 FILL_TABLE_ROW (oct_data_conv::dt_int64, int64NDArray);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3396 FILL_TABLE_ROW (oct_data_conv::dt_uint64, uint64NDArray);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7724
diff changeset
3397 FILL_TABLE_ROW (oct_data_conv::dt_single, FloatNDArray);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3398 FILL_TABLE_ROW (oct_data_conv::dt_double, NDArray);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3399 FILL_TABLE_ROW (oct_data_conv::dt_char, charNDArray);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3400 FILL_TABLE_ROW (oct_data_conv::dt_schar, charNDArray);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3401 FILL_TABLE_ROW (oct_data_conv::dt_uchar, charNDArray);
4970
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4946
diff changeset
3402 FILL_TABLE_ROW (oct_data_conv::dt_logical, boolNDArray);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3403
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3404 initialized = true;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3405 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3406
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3407 octave_value retval;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3408
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3409 if (stream_ok ())
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3410 {
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5765
diff changeset
3411 // FIXME -- we may eventually want to make this extensible.
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5765
diff changeset
3412
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5765
diff changeset
3413 // FIXME -- we need a better way to ensure that this
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3414 // numbering stays consistent with the order of the elements in the
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3415 // data_type enum in the oct_data_conv class.
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3416
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3417 char_count = 0;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3418
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3419 octave_idx_type nr = -1;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3420 octave_idx_type nc = -1;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3421
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3422 bool ignore;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3423
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3424 get_size (size, nr, nc, ignore, "fread");
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3425
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3426 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3427 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3428 if (nr == 0 || nc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3429 retval = Matrix (nr, nc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3430 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3431 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3432 if (ffmt == oct_mach_info::flt_fmt_unknown)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3433 ffmt = float_format ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3434
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3435 read_fptr fcn = read_fptr_table[output_type][input_type];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3436
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3437 bool do_float_fmt_conv = ((input_type == oct_data_conv::dt_double
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3438 || input_type == oct_data_conv::dt_single)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3439 && ffmt != float_format ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3440
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3441 bool do_NA_conv = (output_type == oct_data_conv::dt_double);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3442
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3443 if (fcn)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3444 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3445 retval = (*fcn) (*this, nr, nc, block_size, skip,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3446 do_float_fmt_conv, do_NA_conv,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3447 ffmt, char_count);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3448
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3449 // FIXME -- kluge!
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3450
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3451 if (! error_state
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3452 && (output_type == oct_data_conv::dt_char
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3453 || output_type == oct_data_conv::dt_schar
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3454 || output_type == oct_data_conv::dt_uchar))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3455 retval = retval.char_matrix_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3456 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3457 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3458 error ("fread: unable to read and convert requested types");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3459 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3460 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3461 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3462 invalid_operation ("fread", "reading");
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3463 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3464
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3465 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3466 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3467
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3468 octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3469 octave_stream::write (const octave_value& data, octave_idx_type block_size,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3470 oct_data_conv::data_type output_type, octave_idx_type skip,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3471 oct_mach_info::float_format flt_fmt)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3472 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3473 octave_idx_type retval = -1;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3474
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3475 if (stream_ok ())
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3476 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3477 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3478 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3479 if (flt_fmt == oct_mach_info::flt_fmt_unknown)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3480 flt_fmt = float_format ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3481
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3482 octave_idx_type status = data.write (*this, block_size, output_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3483 skip, flt_fmt);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3484
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3485 if (status < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3486 error ("fwrite: write error");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3487 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3488 retval = status;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3489 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3490 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3491 invalid_operation ("fwrite", "writing");
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3492 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3493
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3494 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3495 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3496
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3497 template <class T>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3498 void
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3499 write_int (std::ostream& os, bool swap, const T& val)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3500 {
9685
e793865ede63 implement builtin_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9202
diff changeset
3501 typename T::val_type tmp = val.value ();
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3502
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3503 if (swap)
9685
e793865ede63 implement builtin_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9202
diff changeset
3504 swap_bytes<sizeof (typename T::val_type)> (&tmp);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3505
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3506 os.write (reinterpret_cast<const char *> (&tmp),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3507 sizeof (typename T::val_type));
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3508 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3509
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3510 template void write_int (std::ostream&, bool, const octave_int8&);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3511 template void write_int (std::ostream&, bool, const octave_uint8&);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3512 template void write_int (std::ostream&, bool, const octave_int16&);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3513 template void write_int (std::ostream&, bool, const octave_uint16&);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3514 template void write_int (std::ostream&, bool, const octave_int32&);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3515 template void write_int (std::ostream&, bool, const octave_uint32&);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3516 template void write_int (std::ostream&, bool, const octave_int64&);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3517 template void write_int (std::ostream&, bool, const octave_uint64&);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3518
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3519 template <class T>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3520 static inline bool
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3521 do_write (std::ostream& os, const T& val, oct_data_conv::data_type output_type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3522 oct_mach_info::float_format flt_fmt, bool swap,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3523 bool do_float_conversion)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3524 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3525 bool retval = true;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3526
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3527 // For compatibility, Octave converts to the output type, then
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3528 // writes. This means that truncation happens on the conversion.
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3529 // For example, the following program prints 0:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3530 //
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3531 // x = int8 (-1)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3532 // f = fopen ("foo.dat", "w");
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3533 // fwrite (f, x, "unsigned char");
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3534 // fclose (f);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3535 // f = fopen ("foo.dat", "r");
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3536 // y = fread (f, 1, "unsigned char");
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3537 // printf ("%d\n", y);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3538
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3539 switch (output_type)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3540 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3541 case oct_data_conv::dt_char:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3542 case oct_data_conv::dt_schar:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3543 case oct_data_conv::dt_int8:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3544 write_int (os, swap, octave_int8 (val));
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3545 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3546
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3547 case oct_data_conv::dt_uchar:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3548 case oct_data_conv::dt_uint8:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3549 write_int (os, swap, octave_uint8 (val));
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3550 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3551
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3552 case oct_data_conv::dt_int16:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3553 write_int (os, swap, octave_int16 (val));
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3554 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3555
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3556 case oct_data_conv::dt_uint16:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3557 write_int (os, swap, octave_uint16 (val));
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3558 break;
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 case oct_data_conv::dt_int32:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3561 write_int (os, swap, octave_int32 (val));
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3562 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3563
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3564 case oct_data_conv::dt_uint32:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3565 write_int (os, swap, octave_uint32 (val));
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3566 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3567
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3568 case oct_data_conv::dt_int64:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3569 write_int (os, swap, octave_int64 (val));
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3570 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3571
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3572 case oct_data_conv::dt_uint64:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3573 write_int (os, swap, octave_uint64 (val));
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3574 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3575
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3576 case oct_data_conv::dt_single:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3577 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3578 float f = static_cast<float> (val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3579
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3580 if (do_float_conversion)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3581 do_float_format_conversion (&f, 1, flt_fmt);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3582
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3583 os.write (reinterpret_cast<const char *> (&f), sizeof (float));
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3584 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3585 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3586
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3587 case oct_data_conv::dt_double:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3588 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3589 double d = static_cast<double> (val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3590 if (do_float_conversion)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3591 do_double_format_conversion (&d, 1, flt_fmt);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3592
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3593 os.write (reinterpret_cast<const char *> (&d), sizeof (double));
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3594 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3595 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3596
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3597 default:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3598 retval = false;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3599 (*current_liboctave_error_handler)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3600 ("write: invalid type specification");
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3601 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3602 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3603
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3604 return retval;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3605 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3606
5887
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3607 template bool
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3608 do_write (std::ostream&, const octave_int8&, oct_data_conv::data_type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3609 oct_mach_info::float_format, bool, bool);
5887
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3610
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3611 template bool
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3612 do_write (std::ostream&, const octave_uint8&, oct_data_conv::data_type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3613 oct_mach_info::float_format, bool, bool);
5887
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3614
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3615 template bool
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3616 do_write (std::ostream&, const octave_int16&, oct_data_conv::data_type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3617 oct_mach_info::float_format, bool, bool);
5887
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3618
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3619 template bool
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3620 do_write (std::ostream&, const octave_uint16&, oct_data_conv::data_type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3621 oct_mach_info::float_format, bool, bool);
5887
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3622
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3623 template bool
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3624 do_write (std::ostream&, const octave_int32&, oct_data_conv::data_type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3625 oct_mach_info::float_format, bool, bool);
5887
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3626
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3627 template bool
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3628 do_write (std::ostream&, const octave_uint32&, oct_data_conv::data_type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3629 oct_mach_info::float_format, bool, bool);
5887
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3630
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3631 template bool
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3632 do_write (std::ostream&, const octave_int64&, oct_data_conv::data_type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3633 oct_mach_info::float_format, bool, bool);
5887
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3634
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3635 template bool
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3636 do_write (std::ostream&, const octave_uint64&, oct_data_conv::data_type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3637 oct_mach_info::float_format, bool, bool);
5887
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3638
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3639 template <class T>
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3640 octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3641 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
3642 oct_data_conv::data_type output_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3643 octave_idx_type skip, oct_mach_info::float_format flt_fmt)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3644 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3645 octave_idx_type retval = -1;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3646
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3647 bool status = true;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3648
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3649 octave_idx_type count = 0;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3650
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3651 const T *d = data.data ();
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3652
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3653 octave_idx_type n = data.length ();
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3654
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3655 oct_mach_info::float_format native_flt_fmt
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3656 = oct_mach_info::float_format ();
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3657
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3658 bool do_float_conversion = (flt_fmt != native_flt_fmt);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3659
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5765
diff changeset
3660 // FIXME -- byte order for Cray?
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3661
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3662 bool swap = false;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3663
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3664 if (oct_mach_info::words_big_endian ())
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3665 swap = (flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3666 || flt_fmt == oct_mach_info::flt_fmt_vax_g
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3667 || flt_fmt == oct_mach_info::flt_fmt_vax_g);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3668 else
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3669 swap = (flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3670
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3671 for (octave_idx_type i = 0; i < n; i++)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3672 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3673 std::ostream *osp = output_stream ();
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3674
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3675 if (osp)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3676 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3677 std::ostream& os = *osp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3678
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3679 if (skip != 0 && (i % block_size) == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3680 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3681 // Seek to skip when inside bounds of existing file.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3682 // Otherwise, write NUL to skip.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3683
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3684 long orig_pos = tell ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3685
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3686 seek (0, SEEK_END);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3687
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3688 long eof_pos = tell ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3689
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3690 // Is it possible for this to fail to return us to the
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3691 // original position?
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3692 seek (orig_pos, SEEK_SET);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3693
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3694 long remaining = eof_pos - orig_pos;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3695
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3696 if (remaining < skip)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3697 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3698 seek (0, SEEK_END);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3699
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3700 // FIXME -- probably should try to write larger
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3701 // blocks...
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3702
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3703 unsigned char zero = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3704 for (octave_idx_type j = 0; j < skip - remaining; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3705 os.write (reinterpret_cast<const char *> (&zero), 1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3706 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3707 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3708 seek (skip, SEEK_CUR);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3709 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3710
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3711 if (os)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3712 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3713 status = do_write (os, d[i], output_type, flt_fmt, swap,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3714 do_float_conversion);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3715
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3716 if (os && status)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3717 count++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3718 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3719 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3720 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3721 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3722 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3723 status = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3724 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3725 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3726 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3727 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3728 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3729 status = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3730 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3731 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3732 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3733
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3734 if (status)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3735 retval = count;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3736
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3737 return retval;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3738 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3739
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3740 template octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3741 octave_stream::write (const Array<char>&, octave_idx_type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3742 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3743 octave_idx_type, oct_mach_info::float_format);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3744
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3745 template octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3746 octave_stream::write (const Array<bool>&, octave_idx_type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3747 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3748 octave_idx_type, oct_mach_info::float_format);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3749
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3750 template octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3751 octave_stream::write (const Array<double>&, octave_idx_type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3752 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3753 octave_idx_type, oct_mach_info::float_format);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3754
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3755 template octave_idx_type
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7724
diff changeset
3756 octave_stream::write (const Array<float>&, octave_idx_type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3757 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3758 octave_idx_type, oct_mach_info::float_format);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7724
diff changeset
3759
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7724
diff changeset
3760 template octave_idx_type
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3761 octave_stream::write (const Array<octave_int8>&, octave_idx_type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3762 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3763 octave_idx_type, oct_mach_info::float_format);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3764
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3765 template octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3766 octave_stream::write (const Array<octave_uint8>&, octave_idx_type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3767 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3768 octave_idx_type, oct_mach_info::float_format);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3769
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3770 template octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3771 octave_stream::write (const Array<octave_int16>&, octave_idx_type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3772 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3773 octave_idx_type, oct_mach_info::float_format);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3774
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3775 template octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3776 octave_stream::write (const Array<octave_uint16>&, octave_idx_type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3777 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3778 octave_idx_type, oct_mach_info::float_format);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3779
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3780 template octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3781 octave_stream::write (const Array<octave_int32>&, octave_idx_type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3782 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3783 octave_idx_type, oct_mach_info::float_format);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3784
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3785 template octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3786 octave_stream::write (const Array<octave_uint32>&, octave_idx_type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3787 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3788 octave_idx_type, oct_mach_info::float_format);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3789
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3790 template octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3791 octave_stream::write (const Array<octave_int64>&, octave_idx_type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3792 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3793 octave_idx_type, oct_mach_info::float_format);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3794
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3795 template octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3796 octave_stream::write (const Array<octave_uint64>&, octave_idx_type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3797 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3798 octave_idx_type, oct_mach_info::float_format);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3799
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3800 octave_value
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
3801 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
3802 octave_idx_type& count, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3803 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3804 octave_value retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3805
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3806 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3807 retval = rep->scanf (fmt, size, count, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3808
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3809 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3810 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3811
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3812 octave_value
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3813 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
3814 octave_idx_type& count, const std::string& who)
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3815 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3816 octave_value retval = Matrix ();
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3817
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3818 if (fmt.is_string ())
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3819 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3820 std::string sfmt = fmt.string_value ();
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3821
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3822 if (fmt.is_sq_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3823 sfmt = do_string_escapes (sfmt);
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3824
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3825 retval = scanf (sfmt, size, count, who);
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3826 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3827 else
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3828 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3829 // Note that this is not ::error () !
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3830
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3831 error (who + ": format must be a string");
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3832 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3833
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3834 return retval;
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3835 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3836
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
3837 octave_value_list
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3838 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
3839 {
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
3840 octave_value_list retval;
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
3841
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3842 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3843 retval = rep->oscanf (fmt, who);
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
3844
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
3845 return retval;
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
3846 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
3847
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3848 octave_value_list
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3849 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
3850 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3851 octave_value_list retval;
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3852
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3853 if (fmt.is_string ())
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3854 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3855 std::string sfmt = fmt.string_value ();
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3856
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3857 if (fmt.is_sq_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3858 sfmt = do_string_escapes (sfmt);
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3859
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3860 retval = oscanf (sfmt, who);
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3861 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3862 else
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3863 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3864 // Note that this is not ::error () !
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3865
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3866 error (who + ": format must be a string");
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3867 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3868
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3869 return retval;
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3870 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3871
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3872 int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3873 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
3874 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3875 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3876 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3877
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3878 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3879 retval = rep->printf (fmt, args, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3880
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3881 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3882 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3883
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3884 int
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3885 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
3886 const std::string& who)
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3887 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3888 int retval = 0;
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3889
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3890 if (fmt.is_string ())
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3891 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3892 std::string sfmt = fmt.string_value ();
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3893
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3894 if (fmt.is_sq_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3895 sfmt = do_string_escapes (sfmt);
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3896
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3897 retval = printf (sfmt, args, who);
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3898 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3899 else
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3900 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3901 // Note that this is not ::error () !
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3902
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3903 error (who + ": format must be a string");
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3904 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3905
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3906 return retval;
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3907 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3908
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3909 int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3910 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
3911 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3912 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3913
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3914 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3915 retval = rep->puts (s, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3916
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3917 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3918 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3919
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5765
diff changeset
3920 // FIXME -- maybe this should work for string arrays too.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3921
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3922 int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3923 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
3924 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3925 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3926
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3927 if (tc_s.is_string ())
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3928 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3929 std::string s = tc_s.string_value ();
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3930 retval = puts (s, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3931 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3932 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3933 {
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3934 // Note that this is not ::error () !
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3935
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3936 error (who + ": argument must be a string");
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3937 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3938
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3939 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3940 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3941
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3942 bool
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3943 octave_stream::eof (void) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3944 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3945 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3946
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3947 if (stream_ok ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3948 retval = rep->eof ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3949
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3950 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3951 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3952
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
3953 std::string
2435
3be97fe02051 [project @ 1996-10-27 21:31:29 by jwe]
jwe
parents: 2341
diff changeset
3954 octave_stream::error (bool clear, int& err_num)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3955 {
5649
d24b97246b9b [project @ 2006-03-08 20:31:25 by jwe]
jwe
parents: 5581
diff changeset
3956 std::string retval = "invalid stream object";
d24b97246b9b [project @ 2006-03-08 20:31:25 by jwe]
jwe
parents: 5581
diff changeset
3957
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3958 if (stream_ok (false))
2435
3be97fe02051 [project @ 1996-10-27 21:31:29 by jwe]
jwe
parents: 2341
diff changeset
3959 retval = rep->error (clear, err_num);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3960
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3961 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3962 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3963
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
3964 std::string
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3965 octave_stream::name (void) const
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3966 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
3967 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3968
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3969 if (stream_ok ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3970 retval = rep->name ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3971
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3972 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3973 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3974
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3975 int
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3976 octave_stream::mode (void) const
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3977 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3978 int retval = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3979
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3980 if (stream_ok ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3981 retval = rep->mode ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3982
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3983 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3984 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3985
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 2305
diff changeset
3986 oct_mach_info::float_format
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3987 octave_stream::float_format (void) const
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3988 {
4574
6cb22b9e3942 [project @ 2003-10-31 05:57:43 by jwe]
jwe
parents: 4468
diff changeset
3989 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
3990
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3991 if (stream_ok ())
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 2305
diff changeset
3992 retval = rep->float_format ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3993
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3994 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3995 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3996
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
3997 std::string
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3998 octave_stream::mode_as_string (int mode)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3999 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4000 std::string retval = "???";
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
4001 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
4002
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
4003 if (in_mode == std::ios::in)
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
4004 retval = "r";
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4005 else if (in_mode == std::ios::out
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
4006 || in_mode == (std::ios::out | std::ios::trunc))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
4007 retval = "w";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
4008 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
4009 retval = "a";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
4010 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
4011 retval = "r+";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
4012 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
4013 retval = "w+";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
4014 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
4015 retval = "a+";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
4016 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
4017 retval = "rb";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
4018 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
4019 || 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
4020 retval = "wb";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
4021 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
4022 retval = "ab";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
4023 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
4024 retval = "r+b";
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4025 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
4026 | std::ios::binary))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
4027 retval = "w+b";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
4028 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
4029 | std::ios::binary))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
4030 retval = "a+b";
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4031
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4032 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4033 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4034
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4035 octave_stream_list *octave_stream_list::instance = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4036
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4037 bool
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4038 octave_stream_list::instance_ok (void)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4039 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4040 bool retval = true;
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4041
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4042 if (! instance)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4043 instance = new octave_stream_list ();
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4044
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4045 if (! instance)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4046 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4047 ::error ("unable to create stream list object!");
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4048
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4049 retval = false;
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4050 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4051
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4052 return retval;
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4053 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4054
5353
df230b7df93c [project @ 2005-05-18 02:18:24 by jwe]
jwe
parents: 5338
diff changeset
4055 int
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4056 octave_stream_list::insert (octave_stream& os)
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4057 {
5353
df230b7df93c [project @ 2005-05-18 02:18:24 by jwe]
jwe
parents: 5338
diff changeset
4058 return (instance_ok ()) ? instance->do_insert (os) : -1;
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4059 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4060
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4061 octave_stream
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4062 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
4063 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4064 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
4065 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4066
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4067 octave_stream
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4068 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
4069 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4070 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
4071 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4072
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4073 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4074 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
4075 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4076 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
4077 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4078
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4079 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4080 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
4081 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4082 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
4083 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4084
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4085 void
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4086 octave_stream_list::clear (bool flush)
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4087 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4088 if (instance)
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4089 instance->do_clear (flush);
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4090 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4091
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4092 string_vector
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4093 octave_stream_list::get_info (int fid)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4094 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4095 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
4096 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4097
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4098 string_vector
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4099 octave_stream_list::get_info (const octave_value& fid)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4100 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4101 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
4102 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4103
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
4104 std::string
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4105 octave_stream_list::list_open_files (void)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4106 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4107 return (instance_ok ()) ? instance->do_list_open_files () : std::string ();
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4108 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4109
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4110 octave_value
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4111 octave_stream_list::open_file_numbers (void)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4112 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4113 return (instance_ok ())
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4114 ? instance->do_open_file_numbers () : octave_value ();
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4115 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4116
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4117 int
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4118 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
4119 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4120 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
4121 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4122
5353
df230b7df93c [project @ 2005-05-18 02:18:24 by jwe]
jwe
parents: 5338
diff changeset
4123 int
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4124 octave_stream_list::do_insert (octave_stream& os)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4125 {
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4126 // Insert item with key corresponding to file-descriptor.
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4127
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4128 int stream_number;
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4129
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4130 if ((stream_number = os.file_number ()) == -1)
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4131 return stream_number;
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4132
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4133 // Should we test for "(list.find (stream_number) != list.end ()) &&
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4134 // list[stream_number].is_open ()" and respond with "error
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4135 // ("internal error: ...")"? It should not happen except for some
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4136 // bug or if the user has opened a stream with an interpreted
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4137 // command, but closed it directly with a system call in an
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4138 // oct-file; then the kernel knows the fd is free, but Octave does
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4139 // not know. If it happens, it should not do harm here to simply
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4140 // overwrite this entry, although the wrong entry might have done
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4141 // harm before.
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4142
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4143 if (list.size () < list.max_size ())
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4144 list[stream_number] = os;
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4145 else
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4146 {
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4147 stream_number = -1;
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4148 error ("could not create file id");
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4149 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4150
5353
df230b7df93c [project @ 2005-05-18 02:18:24 by jwe]
jwe
parents: 5338
diff changeset
4151 return stream_number;
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4152
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4153 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4154
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4155 static void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4156 gripe_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
4157 {
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4158 if (who.empty ())
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4159 ::error ("invalid stream number = %d", fid);
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4160 else
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4161 ::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
4162 }
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4163
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4164 octave_stream
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4165 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
4166 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4167 octave_stream retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4168
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4169 if (fid >= 0)
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4170 {
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4171 if (lookup_cache != list.end () && lookup_cache->first == fid)
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4172 retval = lookup_cache->second;
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4173 else
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4174 {
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4175 ostrl_map::const_iterator iter = list.find (fid);
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4176
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4177 if (iter != list.end ())
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4178 {
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4179 retval = iter->second;
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4180 lookup_cache = iter;
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4181 }
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4182 else
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4183 gripe_invalid_file_id (fid, who);
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4184 }
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4185 }
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4186 else
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4187 gripe_invalid_file_id (fid, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4188
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4189 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4190 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4191
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4192 octave_stream
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4193 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
4194 const std::string& who) const
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4195 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4196 octave_stream retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4197
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4198 int i = get_file_number (fid);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4199
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4200 if (! error_state)
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4201 retval = do_lookup (i, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4202
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4203 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4204 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4205
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4206 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4207 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
4208 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4209 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4210
3531
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
4211 // Can't remove stdin (std::cin), stdout (std::cout), or stderr
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
4212 // (std::cerr).
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4213
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4214 if (fid > 2)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4215 {
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4216 ostrl_map::iterator iter = list.find (fid);
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4217
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4218 if (iter != list.end ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4219 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4220 octave_stream os = iter->second;
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4221 list.erase (iter);
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4222 lookup_cache = list.end ();
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4223
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4224 // FIXME: is this check redundant?
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4225 if (os.is_valid ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4226 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4227 os.close ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4228 retval = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4229 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4230 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4231 gripe_invalid_file_id (fid, who);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4232 }
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4233 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4234 gripe_invalid_file_id (fid, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4235 }
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4236 else
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4237 gripe_invalid_file_id (fid, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4238
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4239 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4240 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4241
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4242 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4243 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
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
6054
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4247 if (fid.is_string () && fid.string_value () == "all")
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4248 {
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4249 do_clear (false);
6054
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4250
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4251 retval = 0;
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4252 }
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4253 else
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4254 {
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4255 int i = get_file_number (fid);
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4256
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4257 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4258 retval = do_remove (i, who);
6054
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4259 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4260
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4261 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4262 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4263
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4264 void
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4265 octave_stream_list::do_clear (bool flush)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4266 {
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4267 if (flush)
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4268 {
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4269 // Do flush stdout and stderr.
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4270
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4271 list[0].flush ();
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4272 list[1].flush ();
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4273 }
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4274
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4275 octave_stream saved_os[3];
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4276 // But don't delete them or stdin.
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4277 for (ostrl_map::iterator iter = list.begin (); iter != list.end (); iter++)
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4278 {
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4279 int fid = iter->first;
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4280 octave_stream os = iter->second;
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4281 if (fid < 3)
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4282 saved_os[fid] = os;
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4283 else if (os.is_valid ())
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4284 os.close ();
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4285 }
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4286 list.clear ();
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4287 for (int fid = 0; fid < 3; fid++) list[fid] = saved_os[fid];
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4288 lookup_cache = list.end ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4289 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4290
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4291 string_vector
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4292 octave_stream_list::do_get_info (int fid) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4293 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4294 string_vector retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4295
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4296 octave_stream os = do_lookup (fid);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4297
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4298 if (os.is_valid ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4299 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4300 retval.resize (3);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4301
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4302 retval(0) = os.name ();
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4303 retval(1) = octave_stream::mode_as_string (os.mode ());
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4304 retval(2) = oct_mach_info::float_format_as_string (os.float_format ());
2117
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 else
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4307 ::error ("invalid file id = %d", fid);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4308
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4309 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4310 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4311
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4312 string_vector
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4313 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
4314 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4315 string_vector 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 int conv_err = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4318
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4319 int int_fid = convert_to_valid_int (fid, conv_err);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4320
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4321 if (! conv_err)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4322 retval = do_get_info (int_fid);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4323 else
2915
649549662cf6 [project @ 1997-04-30 20:51:40 by jwe]
jwe
parents: 2902
diff changeset
4324 ::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
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_list::do_list_open_files (void) const
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;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4333
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
4334 std::ostringstream buf;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4335
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4336 buf << "\n"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4337 << " number mode arch name\n"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4338 << " ------ ---- ---- ----\n";
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4339
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4340 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
4341 {
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4342 octave_stream os = p->second;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4343
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4312
diff changeset
4344 buf << " "
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4345 << std::setiosflags (std::ios::right)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4346 << std::setw (4) << p->first << " "
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4347 << std::setiosflags (std::ios::left)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4348 << std::setw (3)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4349 << octave_stream::mode_as_string (os.mode ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4350 << " "
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4351 << std::setw (9)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4352 << 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
4353 << " "
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4354 << os.name () << "\n";
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4355 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4356
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
4357 buf << "\n";
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
4358
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
4359 retval = buf.str ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4360
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4361 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4362 }
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 octave_value
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4365 octave_stream_list::do_open_file_numbers (void) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4366 {
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4367 Matrix retval (1, list.size (), 0.0);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4368
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4369 int num_open = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4370
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4371 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
4372 {
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4373 // Skip stdin, stdout, and stderr.
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4374
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4375 if (p->first > 2 && p->second)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4376 retval(0,num_open++) = p->first;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4377 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4378
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4379 retval.resize ((num_open > 0), num_open);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4380
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4381 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4382 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4383
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4384 int
2609
12bc9d0a50b5 [project @ 1997-01-18 00:17:36 by jwe]
jwe
parents: 2601
diff changeset
4385 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
4386 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4387 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4388
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4389 if (fid.is_string ())
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4390 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4391 std::string nm = fid.string_value ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4392
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4393 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
4394 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4395 // stdin (std::cin), stdout (std::cout), and stderr (std::cerr)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4396 // are unnamed.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4397
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4398 if (p->first > 2)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4399 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4400 octave_stream os = p->second;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4401
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4402 if (os && os.name () == nm)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4403 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4404 retval = p->first;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4405 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4406 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4407 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4408 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4409 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4410 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4411 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4412 int conv_err = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4413
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4414 int int_fid = convert_to_valid_int (fid, conv_err);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4415
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4416 if (conv_err)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4417 ::error ("file id must be a file object, std::string, or integer value");
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4418 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4419 retval = int_fid;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4420 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4421
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4422 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4423 }