annotate src/oct-stream.cc @ 14844:5bc9b9cb4362

maint: Use Octave coding conventions for cuddled parenthesis in retval assignments. * hello.cc, Array-util.cc, CNDArray.cc, CSparse.cc, Sparse.cc, dNDArray.cc, dSparse.cc, fCNDArray.cc, fNDArray.cc, lo-specfun.cc, list_primes.m, rectangle_lw.m, sinetone.m, amd.cc, bsxfun.cc, ccolamd.cc, eigs.cc, lu.cc, qz.cc, spparms.cc, oct-stream.cc: Use Octave coding conventions for cuddled parenthesis in retval assignments.
author Rik <octave@nomad.inbox5.com>
date Fri, 06 Jul 2012 14:00:25 -0700
parents 757f729fd41d
children
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
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 14022
diff changeset
3 Copyright (C) 1996-2012 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"
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
43 #include "quit.h"
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
44 #include "singleton-cleanup.h"
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
45 #include "str-vec.h"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
46
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
47 #include "error.h"
7352
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
48 #include "gripes.h"
3342
d8d3700fb4ab [project @ 1999-11-05 16:55:17 by jwe]
jwe
parents: 3341
diff changeset
49 #include "input.h"
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
50 #include "oct-stdstrm.h"
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
51 #include "oct-stream.h"
2877
5c1b9e545dd1 [project @ 1997-04-24 09:07:39 by jwe]
jwe
parents: 2847
diff changeset
52 #include "oct-obj.h"
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
53 #include "utils.h"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
54
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
55 // Possible values for conv_err:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
56 //
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
57 // 1 : not a real scalar
2902
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2877
diff changeset
58 // 2 : value is NaN
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2877
diff changeset
59 // 3 : value is not an integer
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
60
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
61 static int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
62 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
63 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
64 int retval = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
65
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
66 conv_err = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
67
2902
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2877
diff changeset
68 double dval = tc.double_value ();
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2877
diff changeset
69
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2877
diff changeset
70 if (! error_state)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
71 {
5389
25c8956d2204 [project @ 2005-06-15 03:45:46 by jwe]
jwe
parents: 5353
diff changeset
72 if (! lo_ieee_isnan (dval))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
73 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
74 int ival = NINT (dval);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
75
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
76 if (ival == dval)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
77 retval = ival;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
78 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
79 conv_err = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
80 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
81 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
82 conv_err = 2;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
83 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
84 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
85 conv_err = 1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
86
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
87 return retval;
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
90 static int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
91 get_size (double d, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
92 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
93 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
94
5389
25c8956d2204 [project @ 2005-06-15 03:45:46 by jwe]
jwe
parents: 5353
diff changeset
95 if (! lo_ieee_isnan (d))
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
96 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
97 if (! xisinf (d))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
98 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
99 if (d >= 0.0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
100 retval = NINT (d);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
101 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
102 ::error ("%s: negative value invalid as size specification",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
103 who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
104 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
105 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
106 retval = -1;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
107 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
108 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
109 ::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
110
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
111 return retval;
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
114 static void
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
115 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
116 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
117 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
118 nr = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
119 nc = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
120
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
121 one_elt_size_spec = false;
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
122
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
123 double dnr = -1.0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
124 double dnc = -1.0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
125
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
126 octave_idx_type sz_len = size.length ();
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
127
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
128 if (sz_len == 1)
2601
3723512a827a [project @ 1997-01-06 05:43:16 by jwe]
jwe
parents: 2600
diff changeset
129 {
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
130 one_elt_size_spec = true;
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
131
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
132 dnr = size (0);
4293
977f977fb2c3 [project @ 2003-01-06 18:18:14 by jwe]
jwe
parents: 4257
diff changeset
133
977f977fb2c3 [project @ 2003-01-06 18:18:14 by jwe]
jwe
parents: 4257
diff changeset
134 dnc = (dnr == 0.0) ? 0.0 : 1.0;
2601
3723512a827a [project @ 1997-01-06 05:43:16 by jwe]
jwe
parents: 2600
diff changeset
135 }
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
136 else if (sz_len == 2)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
137 {
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
138 dnr = size (0);
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
139
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
140 if (! xisinf (dnr))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
141 dnc = size (1);
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
142 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
143 ::error ("%s: invalid size specification", who.c_str ());
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
144 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
145 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
146 ::error ("%s: invalid size specification", who.c_str ());
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
147
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
148 if (! error_state)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
149 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
150 nr = get_size (dnr, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
151
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
152 if (! error_state && dnc >= 0.0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
153 nc = get_size (dnc, who);
2117
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 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
156
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
157 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
158 : 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
159 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
160 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
161
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
162 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
163
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
164 size_t i = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
165
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
166 int width = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
167 bool discard = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
168 char modifier = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
169 char type = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
170
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
171 bool have_more = true;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
172
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
173 while (i < n)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
174 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
175 have_more = true;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
176
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
177 if (! buf)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
178 buf = new std::ostringstream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
179
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
180 if (s[i] == '%')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
181 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
182 // Process percent-escape conversion type.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
183
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
184 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
185 num_elts);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
186
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
187 have_more = (buf != 0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
188 }
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
189 else if (isspace (s[i]))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
190 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
191 type = scanf_format_elt::whitespace_conversion;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
192
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
193 width = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
194 discard = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
195 modifier = '\0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
196 *buf << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
197
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
198 while (++i < n && isspace (s[i]))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
199 /* skip whitespace */;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
200
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
201 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
202
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
203 have_more = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
204 }
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
205 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
206 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
207 type = scanf_format_elt::literal_conversion;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
208
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
209 width = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
210 discard = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
211 modifier = '\0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
212
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
213 while (i < n && ! isspace (s[i]) && s[i] != '%')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
214 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
215
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
216 add_elt_to_list (width, discard, type, modifier, num_elts);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
217
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
218 have_more = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
219 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
220
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
221 if (nconv < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
222 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
223 have_more = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
224 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
225 }
2117
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
228 if (have_more)
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
229 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
230
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
231 list.resize (dim_vector (num_elts, 1));
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
232
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
233 delete buf;
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
236 scanf_format_list::~scanf_format_list (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
237 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
238 octave_idx_type n = list.length ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
239
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
240 for (octave_idx_type i = 0; i < n; i++)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
241 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
242 scanf_format_elt *elt = list(i);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
243 delete elt;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
244 }
2117
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
247 void
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
248 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
249 char modifier, octave_idx_type& num_elts,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
250 const std::string& char_class)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
251 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
252 if (buf)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
253 {
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
254 std::string text = buf->str ();
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
255
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
256 if (! text.empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
257 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
258 scanf_format_elt *elt
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
259 = 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
260 modifier, char_class);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
261
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
262 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
263 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
264
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
265 list(num_elts++) = elt;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
266 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
267
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
268 delete buf;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
269 buf = 0;
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 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
272
3535
c5ebcd5d25a9 [project @ 2000-02-02 11:55:49 by jwe]
jwe
parents: 3534
diff changeset
273 static std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
274 expand_char_class (const std::string& s)
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
275 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
276 std::string retval;
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
277
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
278 size_t len = s.length ();
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
279
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
280 size_t i = 0;
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
281
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
282 while (i < len)
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
283 {
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
284 unsigned char c = s[i++];
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
285
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
286 if (c == '-' && i > 1 && i < len
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
287 && 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
288 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
289 // 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
290 // already added it below).
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
291
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
292 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
293 retval += c;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
294 }
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
295 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
296 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
297 // 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
298 // the last character in the class.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
299
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
300 if (c != '-' || i == len)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
301 retval += c;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
302 }
3483
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
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
305 return retval;
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
306 }
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
307
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
308 void
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
309 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
310 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
311 char& type, char& modifier,
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
312 octave_idx_type& num_elts)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
313 {
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
314 width = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
315 discard = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
316 modifier = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
317 type = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
318
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
319 *buf << s[i++];
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
320
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
321 bool have_width = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
322
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
323 while (i < n)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
324 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
325 switch (s[i])
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
326 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
327 case '*':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
328 if (discard)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
329 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
330 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
331 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
332 discard = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
333 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
334 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
335 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
336
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
337 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
338 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
339 if (have_width)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
340 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
341 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
342 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
343 char c = s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
344 width = width * 10 + c - '0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
345 have_width = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
346 *buf << c;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
347 while (i < n && isdigit (s[i]))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
348 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
349 c = s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
350 width = width * 10 + c - '0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
351 *buf << c;
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 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
354 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
355
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
356 case 'h': case 'l': case 'L':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
357 if (modifier != '\0')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
358 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
359 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
360 modifier = s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
361 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
362
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
363 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
364 if (modifier == 'L')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
365 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
366 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
367 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
368 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
369 goto fini;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
370
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
371 case 'e': case 'f': case 'g':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
372 if (modifier == 'h')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
373 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
374 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
375 break;
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
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
378 // No float or long double conversions, thanks.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
379 *buf << 'l';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
380
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
381 goto fini;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
382
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
383 case 'c': case 's': case 'p': case '%': case '[':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
384 if (modifier != '\0')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
385 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
386 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
387 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
388 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
389 goto fini;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
390
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
391 fini:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
392 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
393 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
394 modifier, num_elts) == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
395 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
396 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
397 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
398
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
399 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
400 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
401 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
402 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
403
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
404 if (nconv < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
405 break;
2117
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
408 nconv = -1;
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
411 int
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
412 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
413 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
414 char& type, char modifier,
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
415 octave_idx_type& num_elts)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
416 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
417 int retval = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
418
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
419 std::string char_class;
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
420
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
421 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
422 size_t end_idx = std::string::npos;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
423
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
424 if (s[i] == '%')
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
425 {
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
426 type = '%';
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
427 *buf << s[i++];
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
428 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
429 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
430 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
431 type = s[i];
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
432
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
433 if (s[i] == '[')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
434 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
435 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
436
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
437 if (i < n)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
438 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
439 beg_idx = i;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
440
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
441 if (s[i] == '^')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
442 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
443 type = '^';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
444 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
445
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
446 if (i < n)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
447 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
448 beg_idx = i;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
449
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
450 if (s[i] == ']')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
451 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
452 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
453 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
454 else if (s[i] == ']')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
455 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
456 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
457
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
458 while (i < n && s[i] != ']')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
459 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
460
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
461 if (i < n && s[i] == ']')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
462 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
463 end_idx = i-1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
464 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
465 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
466
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
467 if (s[i-1] != ']')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
468 retval = nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
469 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
470 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
471 *buf << s[i++];
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
472
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
473 nconv++;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
474 }
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
475
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
476 if (nconv >= 0)
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
477 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
478 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
479 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
480 end_idx - beg_idx + 1));
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
481
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
482 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
483 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
484
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
485 return retval;
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
488 void
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
489 scanf_format_list::printme (void) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
490 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
491 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
492
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
493 for (octave_idx_type i = 0; i < n; i++)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
494 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
495 scanf_format_elt *elt = list(i);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
496
3531
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
497 std::cerr
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
498 << "width: " << elt->width << "\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
499 << "discard: " << elt->discard << "\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
500 << "type: ";
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
501
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
502 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
503 std::cerr << "literal text\n";
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
504 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
505 std::cerr << "whitespace\n";
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
506 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
507 std::cerr << elt->type << "\n";
3531
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
508
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
509 std::cerr
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
510 << "modifier: " << elt->modifier << "\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
511 << "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
512 << "text: `" << undo_string_escapes (elt->text) << "'\n\n";
2117
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
516 bool
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
517 scanf_format_list::all_character_conversions (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
518 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
519 octave_idx_type n = list.length ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
520
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
521 if (n > 0)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
522 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
523 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
524 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
525 scanf_format_elt *elt = list(i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
526
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
527 switch (elt->type)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
528 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
529 case 'c': case 's': case '%': case '[': case '^':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
530 case scanf_format_elt::literal_conversion:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
531 case scanf_format_elt::whitespace_conversion:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
532 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
533
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
534 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
535 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
536 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
537 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
538 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
539
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
540 return true;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
541 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
542 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
543 return false;
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
546 bool
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
547 scanf_format_list::all_numeric_conversions (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
548 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
549 octave_idx_type n = list.length ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
550
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
551 if (n > 0)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
552 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
553 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
554 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
555 scanf_format_elt *elt = list(i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
556
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
557 switch (elt->type)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
558 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
559 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
560 case 'e': case 'f': case 'g':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
561 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
562
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
563 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
564 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
565 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
566 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
567 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
568
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
569 return true;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
570 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
571 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
572 return false;
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
575 // Ugh again.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
576
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
577 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
578 : 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
579 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
580 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
581
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
582 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
583
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
584 size_t i = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
585
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
586 int args = 0;
3643
3af6d00b82ed [project @ 2000-03-24 10:53:21 by jwe]
jwe
parents: 3640
diff changeset
587 std::string flags;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
588 int fw = 0;
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
589 int prec = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
590 char modifier = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
591 char type = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
592
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
593 bool have_more = true;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
594 bool empty_buf = true;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
595
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
596 if (n == 0)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
597 {
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
598 printf_format_elt *elt
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
599 = 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
600
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
601 list(num_elts++) = elt;
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
602
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
603 list.resize (dim_vector (num_elts, 1));
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
604 }
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
605 else
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
606 {
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
607 while (i < n)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
608 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
609 have_more = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
610
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
611 if (! buf)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
612 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
613 buf = new std::ostringstream ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
614 empty_buf = true;
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
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
617 switch (s[i])
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
618 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
619 case '%':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
620 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
621 if (empty_buf)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
622 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
623 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
624 type, modifier, num_elts);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
625
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
626 have_more = (buf != 0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
627 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
628 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
629 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
630 num_elts);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
631 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
632 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
633
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
634 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
635 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
636 args = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
637 flags = "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
638 fw = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
639 prec = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
640 modifier = '\0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
641 type = '\0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
642 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
643 empty_buf = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
644 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
645 break;
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
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
648 if (nconv < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
649 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
650 have_more = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
651 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
652 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
653 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
654
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
655 if (have_more)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
656 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
657
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
658 list.resize (dim_vector (num_elts, 1));
4223
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
659
5ebaf7eee36e [project @ 2002-12-17 23:54:34 by jwe]
jwe
parents: 4153
diff changeset
660 delete buf;
2117
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
664 printf_format_list::~printf_format_list (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
665 {
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
666 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
667
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
668 for (octave_idx_type i = 0; i < n; i++)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
669 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
670 printf_format_elt *elt = list(i);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
671 delete elt;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
672 }
2117
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
675 void
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
676 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
677 int fw, int prec, char type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
678 char modifier, octave_idx_type& num_elts)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
679 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
680 if (buf)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
681 {
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
682 std::string text = buf->str ();
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
683
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
684 if (! text.empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
685 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
686 printf_format_elt *elt
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
687 = 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
688 type, modifier);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
689
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
690 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
691 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
692
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
693 list(num_elts++) = elt;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
694 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
695
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
696 delete buf;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
697 buf = 0;
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
701 void
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
702 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
703 (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
704 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
705 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
706 args = 0;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
707 flags = "";
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
708 fw = 0;
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
709 prec = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
710 modifier = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
711 type = '\0';
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
712
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
713 *buf << s[i++];
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
714
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4574
diff changeset
715 bool nxt = false;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
716
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
717 while (i < n)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
718 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
719 switch (s[i])
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
720 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
721 case '-': case '+': case ' ': case '0': case '#':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
722 flags += s[i];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
723 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
724 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
725
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
726 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
727 nxt = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
728 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
729 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
730
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4574
diff changeset
731 if (nxt)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
732 break;
2117
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
735 if (i < n)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
736 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
737 if (s[i] == '*')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
738 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
739 fw = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
740 args++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
741 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
742 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
743 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
744 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
745 if (isdigit (s[i]))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
746 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
747 int nn = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
748 std::string tmp = s.substr (i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
749 sscanf (tmp.c_str (), "%d%n", &fw, &nn);
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
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
752 while (i < n && isdigit (s[i]))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
753 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
754 }
2117
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
757 if (i < n && s[i] == '.')
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
758 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
759 *buf << s[i++];
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
760
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
761 if (i < n)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
762 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
763 if (s[i] == '*')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
764 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
765 prec = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
766 args++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
767 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
768 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
769 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
770 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
771 if (isdigit (s[i]))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
772 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
773 int nn = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
774 std::string tmp = s.substr (i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
775 sscanf (tmp.c_str (), "%d%n", &prec, &nn);
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
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
778 while (i < n && isdigit (s[i]))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
779 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
780 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
781 }
2117
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
784 if (i < n)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
785 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
786 switch (s[i])
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
787 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
788 case 'h': case 'l': case 'L':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
789 modifier = s[i];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
790 *buf << s[i++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
791 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
792
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
793 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
794 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
795 }
2117
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
798 if (i < n)
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
799 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
800 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
801 nconv = -1;
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
804 void
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
805 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
806 (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
807 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
808
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
809 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
810 switch (s[i])
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
811 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
812 case 'd': case 'i': case 'o': case 'x': case 'X':
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
813 case 'u': case 'c':
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
814 if (modifier == 'L')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
815 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
816 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
817 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
818 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
819 goto fini;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
820
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
821 case 'f': case 'e': case 'E': case 'g': case 'G':
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
822 if (modifier == 'h' || modifier == 'l')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
823 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
824 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
825 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
826 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
827 goto fini;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
828
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
829 case 's': case 'p': case '%':
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
830 if (modifier != '\0')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
831 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
832 nconv = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
833 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
834 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
835 goto fini;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
836
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
837 fini:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
838
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
839 type = s[i];
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
840
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
841 *buf << s[i++];
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
842
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
843 if (type != '%' || args != 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
844 nconv++;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
845
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
846 if (type != '%')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
847 args++;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
848
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
849 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
850
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
851 break;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
852
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
853 default:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
854 nconv = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
855 break;
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
859 void
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
860 printf_format_list::printme (void) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
861 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
862 int n = list.length ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
863
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
864 for (int i = 0; i < n; i++)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
865 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
866 printf_format_elt *elt = list(i);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
867
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
868 std::cerr
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
869 << "args: " << elt->args << "\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
870 << "flags: `" << elt->flags << "'\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
871 << "width: " << elt->fw << "\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
872 << "prec: " << elt->prec << "\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
873 << "type: `" << elt->type << "'\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
874 << "modifier: `" << elt->modifier << "'\n"
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
875 << "text: `" << undo_string_escapes (elt->text) << "'\n\n";
2117
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
879 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
880 octave_base_stream::error (const std::string& msg)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
881 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
882 fail = true;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
883 errmsg = msg;
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
886 void
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
887 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
888 {
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
889 fail = true;
6296
85eb75190e01 [project @ 2007-02-10 07:10:42 by jwe]
jwe
parents: 6109
diff changeset
890 errmsg = who + ": " + msg;
4468
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
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
893 void
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
894 octave_base_stream::clear (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
895 {
4889
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
896 fail = false;
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
897 errmsg = "";
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
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
900 void
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
901 octave_base_stream::clearerr (void)
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
902 {
4888
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
903 std::istream *is = input_stream ();
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
904 std::ostream *os = output_stream ();
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
905
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
906 if (is)
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
907 is->clear ();
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
908
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
909 if (os)
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4874
diff changeset
910 os->clear ();
2117
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
913 // Functions that are defined for all input streams (input streams
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
914 // are those that define is).
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
915
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
916 std::string
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
917 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
918 bool strip_newline, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
919 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
920 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
921
8773
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
922 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
923 {
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
924 ::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
925 who.c_str ());
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
926
8773
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
927 return retval;
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
928 }
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
929
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
930 err = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
931
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
932 std::istream *isp = input_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
933
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
934 if (isp)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
935 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
936 std::istream& is = *isp;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
937
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
938 std::ostringstream buf;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
939
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
940 int c = 0;
3553
c5600b44bef9 [project @ 2000-02-03 03:22:37 by jwe]
jwe
parents: 3552
diff changeset
941 int char_count = 0;
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
942
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
943 if (max_len != 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
944 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
945 while (is && (c = is.get ()) != EOF)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
946 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
947 char_count++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
948
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
949 // Handle CRLF, CR, or LF as line ending.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
950
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
951 if (c == '\r')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
952 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
953 if (! strip_newline)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
954 buf << static_cast<char> (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
955
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
956 c = is.get ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
957
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
958 if (c != EOF)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
959 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
960 if (c == '\n')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
961 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
962 char_count++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
963
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
964 if (! strip_newline)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
965 buf << static_cast<char> (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
966 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
967 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
968 is.putback (c);
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
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
971 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
972 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
973 else if (c == '\n')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
974 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
975 if (! strip_newline)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
976 buf << static_cast<char> (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
977
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
978 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
979 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
980 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
981 buf << static_cast<char> (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
982
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
983 if (max_len > 0 && char_count == max_len)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
984 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
985 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
986 }
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
987
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
988 if (! is.eof () && char_count > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
989 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
990 // 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
991 // 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
992 // what the corresponding C-library functions do.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
993 int disgusting_compatibility_hack = is.get ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
994 if (! is.eof ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
995 is.putback (disgusting_compatibility_hack);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
996 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
997
4224
0179e6309248 [project @ 2002-12-18 00:34:29 by jwe]
jwe
parents: 4223
diff changeset
998 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
999 retval = buf.str ();
4224
0179e6309248 [project @ 2002-12-18 00:34:29 by jwe]
jwe
parents: 4223
diff changeset
1000 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1001 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1002 err = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1003
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1004 if (is.eof () && char_count == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1005 error (who, "at end of file");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1006 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1007 error (who, "read error");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1008 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1009 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1010 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1011 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1012 err = true;
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
1013 invalid_operation (who, "reading");
2117
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1016 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1017 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1018
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
1019 std::string
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1020 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
1021 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
1022 return do_gets (max_len, err, true, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1023 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1024
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
1025 std::string
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1026 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
1027 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
1028 return do_gets (max_len, err, false, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1029 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1030
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1031 long
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1032 octave_base_stream::skipl (long num, bool& err, const std::string& who)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1033 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1034 long cnt = -1;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1035
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1036 if ((interactive || forced_interactive) && file_number () == 0)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1037 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1038 ::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
1039 who.c_str ());
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1040
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1041 return count;
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
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1044 err = false;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1045
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1046 std::istream *isp = input_stream ();
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1047
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1048 if (isp)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1049 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1050 std::istream& is = *isp;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1051
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1052 int c = 0, lastc = -1;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1053 cnt = 0;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1054
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1055 while (is && (c = is.get ()) != EOF)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1056 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1057 // Handle CRLF, CR, or LF as line ending.
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1058
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1059 if (c == '\r' || (c == '\n' && lastc != '\r'))
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1060 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1061 if (++cnt == num)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1062 break;
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
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1065 lastc = c;
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
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1068 // Maybe eat the following \n if \r was just met.
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1069 if (c == '\r' && is.peek () == '\n')
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1070 is.get ();
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1071
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1072 if (is.bad ())
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1073 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1074 err = true;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1075 error (who, "read error");
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
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1078 if (err)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1079 cnt = -1;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1080 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1081 else
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1082 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1083 err = true;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1084 invalid_operation (who, "reading");
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
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1087 return cnt;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1088 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
1089
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1090 #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
1091
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1092 template <class T>
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1093 std::istream&
6767
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1094 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
1095 {
3779
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1096 T& ref = *valptr;
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1097
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1098 switch (fmt.type)
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1099 {
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1100 case 'o':
4926
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
1101 is >> std::oct >> ref >> std::dec;
3779
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1102 break;
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1103
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1104 case 'x':
4926
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
1105 is >> std::hex >> ref >> std::dec;
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
1106 break;
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
1107
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
1108 case 'i':
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
1109 {
14675
757f729fd41d skip leading whitespace for scanf %i format
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1110 int c1 = EOF;
757f729fd41d skip leading whitespace for scanf %i format
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1111
757f729fd41d skip leading whitespace for scanf %i format
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1112 while (is && (c1 = is.get ()) != EOF && isspace (c1))
757f729fd41d skip leading whitespace for scanf %i format
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1113 /* skip whitespace */;
757f729fd41d skip leading whitespace for scanf %i format
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1114
757f729fd41d skip leading whitespace for scanf %i format
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1115 if (c1 != EOF)
10315
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 (c1 == '0')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1118 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1119 int c2 = is.peek ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1120
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1121 if (c2 == 'x' || c2 == 'X')
7709
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
1122 {
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
1123 is.ignore ();
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
1124 if (std::isxdigit (is.peek ()))
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
1125 is >> std::hex >> ref >> std::dec;
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
1126 else
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
1127 ref = 0;
fa41af732801 octave_scan_1: fix reading of hex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 7538
diff changeset
1128 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1129 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1130 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1131 if (c2 == '0' || c2 == '1' || c2 == '2'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1132 || c2 == '3' || c2 == '4' || c2 == '5'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1133 || c2 == '6' || c2 == '7')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1134 is >> std::oct >> ref >> std::dec;
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 ref = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1137 }
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 else
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 is.putback (c1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1142
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1143 is >> ref;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1144 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1145 }
4926
e80587ad9503 [project @ 2004-08-02 23:48:40 by jwe]
jwe
parents: 4889
diff changeset
1146 }
3779
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
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1149 default:
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1150 is >> ref;
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1151 break;
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1152 }
3639
fed1847dfd6c [project @ 2000-03-24 05:12:46 by jwe]
jwe
parents: 3638
diff changeset
1153
3638
a76fa215a476 [project @ 2000-03-24 04:53:45 by jwe]
jwe
parents: 3637
diff changeset
1154 return is;
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1155 }
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1156
6767
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1157 template <class T>
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1158 std::istream&
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1159 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
1160 {
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1161 if (fmt.width)
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1162 {
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1163 // 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
1164 // temporary stringstream buffer.
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1165
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1166 std::string tmp;
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1167
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1168 is.width (fmt.width);
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1169 is >> tmp;
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 std::istringstream ss (tmp);
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1172
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1173 octave_scan_1 (ss, fmt, valptr);
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1174 }
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1175 else
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1176 octave_scan_1 (is, fmt, valptr);
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1177
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1178 return is;
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1179 }
a6c8000f113e [project @ 2007-06-28 19:42:42 by jwe]
jwe
parents: 6757
diff changeset
1180
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1181 // 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
1182 // character strings. See BEGIN_S_CONVERSION for details.
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1183
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1184 template<>
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1185 std::istream&
4661
12b6fbd57436 [project @ 2003-11-25 05:41:35 by jwe]
jwe
parents: 4649
diff changeset
1186 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
1187 char* valptr)
3779
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1188 {
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1189 return is >> valptr;
3001e15555e9 [project @ 2001-02-07 04:47:51 by jwe]
jwe
parents: 3775
diff changeset
1190 }
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1191
4595
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1192 template std::istream&
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1193 octave_scan (std::istream&, const scanf_format_elt&, int*);
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1194
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1195 template std::istream&
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1196 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
1197
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1198 template std::istream&
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1199 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
1200
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1201 template std::istream&
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1202 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
1203
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1204 template std::istream&
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1205 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
1206
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&, unsigned short int*);
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1209
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1210 #if 0
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1211 template std::istream&
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1212 octave_scan (std::istream&, const scanf_format_elt&, float*);
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1213 #endif
331f6de7102b [project @ 2003-11-12 02:40:14 by jwe]
jwe
parents: 4587
diff changeset
1214
5403
7bdddf96f028 [project @ 2005-07-07 16:46:23 by jwe]
jwe
parents: 5389
diff changeset
1215 template<>
5176
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1216 std::istream&
5403
7bdddf96f028 [project @ 2005-07-07 16:46:23 by jwe]
jwe
parents: 5389
diff changeset
1217 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
1218 {
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1219 double& ref = *valptr;
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1220
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1221 switch (fmt.type)
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1222 {
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1223 case 'e':
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1224 case 'f':
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1225 case 'g':
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1226 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1227 int c1 = EOF;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1228
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1229 while (is && (c1 = is.get ()) != EOF && isspace (c1))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1230 /* skip whitespace */;
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 if (c1 != EOF)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1233 {
12936
b74cb659e757 accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
1234 is.putback (c1);
b74cb659e757 accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
1235
b74cb659e757 accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
1236 ref = octave_read_value<double> (is);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1237 }
5176
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1238 }
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1239 break;
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1240
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1241 default:
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1242 panic_impossible ();
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1243 break;
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1244 }
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1245
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1246 return is;
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1247 }
10172b519695 [project @ 2005-03-02 19:14:13 by jwe]
jwe
parents: 5065
diff changeset
1248
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1249 template <class T>
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1250 void
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1251 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
1252 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
1253 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
1254 bool discard)
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1255 {
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1256 OCTAVE_SCAN (is, fmt, valptr);
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1257
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1258 if (is)
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1259 {
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1260 if (idx == max_size && ! discard)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1261 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1262 max_size *= 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1263
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1264 if (nr > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1265 mval.resize (nr, max_size / nr, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1266 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1267 mval.resize (max_size, 1, 0.0);
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 data = mval.fortran_vec ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1270 }
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1271
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1272 if (! discard)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1273 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1274 conversion_count++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1275 data[idx++] = *(valptr);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1276 }
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1277 }
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1278 }
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1279
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1280 template void
3878
faeca8a063ae [project @ 2002-03-07 23:28:32 by jwe]
jwe
parents: 3810
diff changeset
1281 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
1282 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
1283
3233
98d0ee053ba4 [project @ 1999-01-27 20:23:40 by jwe]
jwe
parents: 3180
diff changeset
1284 template void
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1285 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
1286 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
1287
98d0ee053ba4 [project @ 1999-01-27 20:23:40 by jwe]
jwe
parents: 3180
diff changeset
1288 template void
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1289 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
1290 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
1291
3878
faeca8a063ae [project @ 2002-03-07 23:28:32 by jwe]
jwe
parents: 3810
diff changeset
1292 template void
faeca8a063ae [project @ 2002-03-07 23:28:32 by jwe]
jwe
parents: 3810
diff changeset
1293 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
1294 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
1295
faeca8a063ae [project @ 2002-03-07 23:28:32 by jwe]
jwe
parents: 3810
diff changeset
1296 template void
faeca8a063ae [project @ 2002-03-07 23:28:32 by jwe]
jwe
parents: 3810
diff changeset
1297 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
1298 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
1299
faeca8a063ae [project @ 2002-03-07 23:28:32 by jwe]
jwe
parents: 3810
diff changeset
1300 template void
faeca8a063ae [project @ 2002-03-07 23:28:32 by jwe]
jwe
parents: 3810
diff changeset
1301 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
1302 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
1303
2600
c454cd888ada [project @ 1996-12-19 22:35:54 by jwe]
jwe
parents: 2572
diff changeset
1304 #if 0
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1305 template void
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1306 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
1307 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
1308 #endif
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1309
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1310 template void
3636
0aeae5fe4ab7 [project @ 2000-03-24 04:27:23 by jwe]
jwe
parents: 3635
diff changeset
1311 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
1312 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
1313
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1314 #define DO_WHITESPACE_CONVERSION() \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1315 do \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1316 { \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1317 int c = EOF; \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1318 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1319 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
1320 /* skip whitespace */; \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1321 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1322 if (c != EOF) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1323 is.putback (c); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1324 } \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1325 while (0)
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1326
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1327 #define DO_LITERAL_CONVERSION() \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1328 do \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1329 { \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1330 int c = EOF; \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1331 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1332 int n = strlen (fmt); \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1333 int i = 0; \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1334 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1335 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
1336 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1337 if (c == static_cast<unsigned char> (fmt[i])) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1338 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1339 i++; \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1340 continue; \
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 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1343 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1344 is.putback (c); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1345 break; \
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 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1348 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1349 if (i != n) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1350 is.setstate (std::ios::failbit); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1351 } \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1352 while (0)
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1353
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1354 #define DO_PCT_CONVERSION() \
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1355 do \
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1356 { \
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1357 int c = is.get (); \
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1358 \
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1359 if (c != EOF) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1360 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1361 if (c != '%') \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1362 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1363 is.putback (c); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1364 is.setstate (std::ios::failbit); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1365 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1366 } \
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1367 else \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1368 is.setstate (std::ios::failbit); \
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1369 } \
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1370 while (0)
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1371
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1372 #define BEGIN_C_CONVERSION() \
3538
0ff7323dab8b [project @ 2000-02-02 12:36:25 by jwe]
jwe
parents: 3536
diff changeset
1373 is.unsetf (std::ios::skipws); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1374 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1375 int width = elt->width ? elt->width : 1; \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1376 \
9952
7cd2e1b372e5 allow scanf to store ASCII NUL values
John W. Eaton <jwe@octave.org>
parents: 9941
diff changeset
1377 std::string tmp (width, '\0'); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1378 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1379 int c = EOF; \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1380 int n = 0; \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1381 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1382 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
1383 tmp[n++] = static_cast<char> (c); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1384 \
5266
3fe873712e07 [project @ 2005-04-05 15:49:50 by jwe]
jwe
parents: 5259
diff changeset
1385 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
1386 is.clear (); \
7626f8934466 correctly resize scanf output for %c formats (bug #34037)
John W. Eaton <jwe@octave.org>
parents: 12966
diff changeset
1387 \
7626f8934466 correctly resize scanf output for %c formats (bug #34037)
John W. Eaton <jwe@octave.org>
parents: 12966
diff changeset
1388 tmp.resize (n)
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1389
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1390 // 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
1391 // 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
1392 #define BEGIN_S_CONVERSION() \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1393 int width = elt->width; \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1394 \
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
1395 std::string tmp; \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1396 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1397 do \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1398 { \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1399 if (width) \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1400 { \
10076
4b270d1540f7 avoid various GCC warnings
John W. Eaton <jwe@octave.org>
parents: 9952
diff changeset
1401 tmp = std::string (width, '\0'); \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1402 \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1403 int c = EOF; \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1404 \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1405 int n = 0; \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1406 \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1407 while (is && (c = is.get ()) != EOF) \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1408 { \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1409 if (! isspace (c)) \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1410 { \
9952
7cd2e1b372e5 allow scanf to store ASCII NUL values
John W. Eaton <jwe@octave.org>
parents: 9941
diff changeset
1411 tmp[n++] = static_cast<char> (c); \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1412 break; \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1413 } \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1414 } \
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
1415 \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1416 while (is && n < width && (c = is.get ()) != EOF) \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1417 { \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1418 if (isspace (c)) \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1419 { \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1420 is.putback (c); \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1421 break; \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1422 } \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1423 else \
9952
7cd2e1b372e5 allow scanf to store ASCII NUL values
John W. Eaton <jwe@octave.org>
parents: 9941
diff changeset
1424 tmp[n++] = static_cast<char> (c); \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1425 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1426 \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1427 if (n > 0 && c == EOF) \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1428 is.clear (); \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1429 \
9952
7cd2e1b372e5 allow scanf to store ASCII NUL values
John W. Eaton <jwe@octave.org>
parents: 9941
diff changeset
1430 tmp.resize (n); \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1431 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1432 else \
5338
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1433 { \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1434 is >> std::ws >> tmp; \
c4b55d47122e [project @ 2005-05-05 17:28:51 by jwe]
jwe
parents: 5326
diff changeset
1435 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1436 } \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1437 while (0)
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1438
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1439 // This format must match a nonempty sequence of characters.
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1440 #define BEGIN_CHAR_CLASS_CONVERSION() \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1441 int width = elt->width; \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1442 \
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
1443 std::string tmp; \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1444 \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1445 do \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1446 { \
7426
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1447 if (! width) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1448 width = INT_MAX; \
7427
65f0a8ced9d2 [project @ 2008-01-28 22:42:18 by jwe]
jwe
parents: 7426
diff changeset
1449 \
7426
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1450 std::ostringstream buf; \
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1451 \
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1452 std::string char_class = elt->char_class; \
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
1453 \
7426
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1454 int c = EOF; \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1455 \
7426
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1456 if (elt->type == '[') \
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1457 { \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1458 int chars_read = 0; \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1459 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
1460 && char_class.find (c) != std::string::npos) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1461 buf << static_cast<char> (c); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1462 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1463 else \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1464 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1465 int chars_read = 0; \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1466 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
1467 && char_class.find (c) == std::string::npos) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1468 buf << static_cast<char> (c); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1469 } \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1470 \
7426
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1471 if (width == INT_MAX && c != EOF) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1472 is.putback (c); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1473 \
7426
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1474 tmp = buf.str (); \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1475 \
7426
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1476 if (tmp.empty ()) \
b9df9abdffbb [project @ 2008-01-28 21:07:58 by jwe]
jwe
parents: 7352
diff changeset
1477 is.setstate (std::ios::failbit); \
10969
da355a1a6d44 fix scanf char class conversion bug
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
1478 else if (c == EOF) \
da355a1a6d44 fix scanf char class conversion bug
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
1479 is.clear (); \
da355a1a6d44 fix scanf char class conversion bug
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
1480 \
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1481 } \
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1482 while (0)
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3410
diff changeset
1483
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1484 #define FINISH_CHARACTER_CONVERSION() \
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1485 do \
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1486 { \
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3969
diff changeset
1487 width = tmp.length (); \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1488 \
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1489 if (is) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1490 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1491 int i = 0; \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1492 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1493 if (! discard) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1494 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1495 conversion_count++; \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1496 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1497 while (i < width) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1498 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1499 if (data_index == max_size) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1500 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1501 max_size *= 2; \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1502 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1503 if (all_char_conv) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1504 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1505 if (one_elt_size_spec) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1506 mval.resize (1, max_size, 0.0); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1507 else if (nr > 0) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1508 mval.resize (nr, max_size / nr, 0.0); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1509 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1510 panic_impossible (); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1511 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1512 else if (nr > 0) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1513 mval.resize (nr, max_size / nr, 0.0); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1514 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1515 mval.resize (max_size, 1, 0.0); \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1516 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1517 data = mval.fortran_vec (); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1518 } \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1519 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1520 data[data_index++] = tmp[i++]; \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1521 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1522 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1523 } \
3410
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1524 } \
ee5f222025c3 [project @ 2000-01-07 04:19:05 by jwe]
jwe
parents: 3342
diff changeset
1525 while (0)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1526
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1527 octave_value
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1528 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
1529 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
1530 octave_idx_type& conversion_count, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1531 {
8773
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
1532 octave_value retval = Matrix ();
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
1533
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
1534 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
1535 {
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
1536 ::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
1537 who.c_str ());
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1538
8773
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
1539 return retval;
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
1540 }
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8739
diff changeset
1541
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1542 conversion_count = 0;
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1543
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1544 octave_idx_type nconv = fmt_list.num_conversions ();
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1545
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1546 octave_idx_type data_index = 0;
2121
bc6ecd8f1175 [project @ 1996-05-12 06:45:55 by jwe]
jwe
parents: 2117
diff changeset
1547
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1548 if (nr == 0 || nc == 0)
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1549 {
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1550 if (one_elt_size_spec)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1551 nc = 0;
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1552
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1553 return Matrix (nr, nc, 0.0);
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1554 }
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1555
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1556 std::istream *isp = input_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1557
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1558 bool all_char_conv = fmt_list.all_character_conversions ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1559
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1560 Matrix mval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1561 double *data = 0;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1562 octave_idx_type max_size = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1563 octave_idx_type max_conv = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1564
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1565 octave_idx_type final_nr = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
1566 octave_idx_type final_nc = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1567
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1568 if (all_char_conv)
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1569 {
4420
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
1570 // 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
1571 // 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
1572 // conversion).
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
1573
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1574 if (one_elt_size_spec)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1575 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1576 max_size = 512;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1577 mval.resize (1, max_size, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1578
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1579 if (nr > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1580 max_conv = nr;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1581 }
4420
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
1582 else if (nr > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1583 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1584 if (nc > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1585 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1586 mval.resize (nr, nc, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1587 max_size = max_conv = nr * nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1588 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1589 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1590 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1591 mval.resize (nr, 32, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1592 max_size = nr * 32;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1593 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1594 }
4420
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
1595 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1596 panic_impossible ();
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1597 }
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1598 else if (nr > 0)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1599 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1600 if (nc > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1601 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1602 // Will not resize later.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1603 mval.resize (nr, nc, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1604 max_size = nr * nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1605 max_conv = max_size;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1606 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1607 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1608 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1609 // Maybe resize later.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1610 mval.resize (nr, 32, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1611 max_size = nr * 32;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1612 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1613 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1614 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1615 {
4420
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
1616 // Maybe resize later.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1617 mval.resize (32, 1, 0.0);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1618 max_size = 32;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1619 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1620
4420
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
1621 data = mval.fortran_vec ();
3dfdbcaf4582 [project @ 2003-05-28 18:24:42 by jwe]
jwe
parents: 4326
diff changeset
1622
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1623 if (isp)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1624 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1625 std::istream& is = *isp;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1626
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1627 const scanf_format_elt *elt = fmt_list.first ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1628
3538
0ff7323dab8b [project @ 2000-02-02 12:36:25 by jwe]
jwe
parents: 3536
diff changeset
1629 std::ios::fmtflags flags = is.flags ();
2213
c4a887694274 [project @ 1996-05-16 04:13:28 by jwe]
jwe
parents: 2127
diff changeset
1630
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1631 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
1632
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1633 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
1634
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1635 for (;;)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1636 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1637 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1638
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1639 if (elt)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1640 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1641 if (! (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
1642 || 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
1643 || elt->type == '%')
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1644 && max_conv > 0 && conversion_count == max_conv)
10315
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 if (all_char_conv && one_elt_size_spec)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1647 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1648 final_nr = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1649 final_nc = data_index;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1650 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1651 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1652 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1653 final_nr = nr;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1654 final_nc = (data_index - 1) / nr + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1655 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1656
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1657 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1658 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1659 else if (data_index == max_size)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1660 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1661 max_size *= 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1662
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1663 if (all_char_conv)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1664 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1665 if (one_elt_size_spec)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1666 mval.resize (1, max_size, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1667 else if (nr > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1668 mval.resize (nr, max_size / nr, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1669 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1670 panic_impossible ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1671 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1672 else if (nr > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1673 mval.resize (nr, max_size / nr, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1674 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1675 mval.resize (max_size, 1, 0.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1676
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1677 data = mval.fortran_vec ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1678 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1679
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1680 const char *fmt = elt->text;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1681
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1682 bool discard = elt->discard;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1683
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1684 switch (elt->type)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1685 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1686 case scanf_format_elt::whitespace_conversion:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1687 DO_WHITESPACE_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1688 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1689
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1690 case scanf_format_elt::literal_conversion:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1691 DO_LITERAL_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1692 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1693
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1694 case '%':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1695 DO_PCT_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1696 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1697
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1698 case 'd': case 'i':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1699 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1700 switch (elt->modifier)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1701 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1702 case 'h':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1703 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1704 short int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1705 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1706 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1707 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1708 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1709 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1710
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1711 case 'l':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1712 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1713 long int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1714 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1715 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1716 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1717 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1718 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1719
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1720 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1721 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1722 int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1723 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1724 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1725 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1726 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1727 break;
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 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1730 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1731
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1732 case 'o': case 'u': case 'x':
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 switch (elt->modifier)
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 case 'h':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1737 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1738 unsigned short int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1739 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1740 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1741 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1742 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1743 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1744
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1745 case 'l':
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 unsigned long int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1748 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1749 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1750 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1751 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1752 break;
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 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1755 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1756 unsigned int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1757 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1758 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1759 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1760 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1761 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1762 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1763 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1764 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1765
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1766 case 'e': case 'f': case 'g':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1767 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1768 double tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1769
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1770 do_scanf_conv (is, *elt, &tmp, mval, data,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1771 data_index, conversion_count,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1772 nr, max_size, discard);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1773 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1774 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1775
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1776 case 'c':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1777 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1778 BEGIN_C_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1779
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1780 FINISH_CHARACTER_CONVERSION ();
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 is.setf (flags);
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 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1785
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1786 case 's':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1787 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1788 BEGIN_S_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1789
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1790 FINISH_CHARACTER_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1791 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1792 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1793
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1794 case '[': case '^':
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 BEGIN_CHAR_CLASS_CONVERSION ();
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 FINISH_CHARACTER_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1799 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1800 break;
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 case 'p':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1803 error ("%s: unsupported format specifier", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1804 break;
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 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1807 error ("%s: internal format error", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1808 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1809 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1810
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1811 if (! ok ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1812 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1813 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1814 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1815 else if (! is)
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 if (all_char_conv)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1818 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1819 if (one_elt_size_spec)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1820 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1821 final_nr = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1822 final_nc = data_index;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1823 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1824 else if (data_index > nr)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1825 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1826 final_nr = nr;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1827 final_nc = (data_index - 1) / nr + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1828 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1829 else
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 final_nr = data_index;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1832 final_nc = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1833 }
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 else if (nr > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1836 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1837 if (data_index > nr)
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 final_nr = nr;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1840 final_nc = (data_index - 1) / nr + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1841 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1842 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1843 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1844 final_nr = data_index;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1845 final_nc = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1846 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1847 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1848 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1849 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1850 final_nr = data_index;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1851 final_nc = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1852 }
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 // 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
1855 // reset the failbit in the stream state.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1856
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1857 if (is.rdstate () & std::ios::failbit)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1858 is.clear (is.rdstate () & (~std::ios::failbit));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1859
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1860 // FIXME -- is this the right thing to do?
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1861
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1862 if (interactive && name () == "stdin")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1863 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1864 is.clear ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1865
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1866 // Skip to end of line.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1867
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1868 bool err;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1869 do_gets (-1, err, false, who);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1870 }
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 else
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 error ("%s: internal format error", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1878 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1879 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1880
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1881 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
1882 {
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1883 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
1884 {
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1885 final_nr = 1;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1886 final_nc = data_index;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1887 }
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1888 else
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1889 {
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1890 final_nr = nr;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1891 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
1892 }
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1893
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1894 break;
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1895 }
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1896 else
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1897 elt = fmt_list.next (nconv > 0);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1898 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1899 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1900
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1901 if (ok ())
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1902 {
2121
bc6ecd8f1175 [project @ 1996-05-12 06:45:55 by jwe]
jwe
parents: 2117
diff changeset
1903 mval.resize (final_nr, final_nc, 0.0);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1904
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1905 retval = mval;
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3267
diff changeset
1906
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1907 if (all_char_conv)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1908 retval = retval.convert_to_str (false, true);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1909 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1910
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1911 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1912 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1913
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1914 octave_value
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
1915 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
1916 octave_idx_type& conversion_count, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1917 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1918 octave_value retval = Matrix ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1919
3559
12d7ec415f35 [project @ 2000-02-03 05:17:36 by jwe]
jwe
parents: 3553
diff changeset
1920 conversion_count = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1921
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1922 std::istream *isp = input_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1923
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1924 if (isp)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1925 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1926 scanf_format_list fmt_list (fmt);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1927
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1928 if (fmt_list.num_conversions () == -1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1929 ::error ("%s: invalid format specified", who.c_str ());
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
1930 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1931 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1932 octave_idx_type nr = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1933 octave_idx_type nc = -1;
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 bool one_elt_size_spec;
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 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
1938
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1939 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1940 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
1941 conversion_count, who);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1942 }
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
1943 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
1944 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
1945 invalid_operation (who, "reading");
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1946
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1947 return retval;
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1948 }
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1949
2712
2ff2b536cc9d [project @ 1997-02-21 21:38:21 by jwe]
jwe
parents: 2687
diff changeset
1950 bool
2ff2b536cc9d [project @ 1997-02-21 21:38:21 by jwe]
jwe
parents: 2687
diff changeset
1951 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
1952 octave_value& retval, const std::string& who)
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
1953 {
2712
2ff2b536cc9d [project @ 1997-02-21 21:38:21 by jwe]
jwe
parents: 2687
diff changeset
1954 bool quit = false;
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
1955
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1956 std::istream *isp = input_stream ();
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
1957
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
1958 if (isp)
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
1959 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1960 std::istream& is = *isp;
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
1961
3538
0ff7323dab8b [project @ 2000-02-02 12:36:25 by jwe]
jwe
parents: 3536
diff changeset
1962 std::ios::fmtflags flags = is.flags ();
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
1963
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
1964 if (elt)
10315
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 const char *fmt = elt->text;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1967
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1968 bool discard = elt->discard;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1969
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1970 switch (elt->type)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1971 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1972 case scanf_format_elt::whitespace_conversion:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1973 DO_WHITESPACE_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1974 break;
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 case scanf_format_elt::literal_conversion:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1977 DO_LITERAL_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1978 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1979
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1980 case '%':
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 DO_PCT_CONVERSION ();
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 if (! is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1985 quit = true;
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 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1988 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1989
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1990 case 'd': case 'i':
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 int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1993
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1994 if (OCTAVE_SCAN (is, *elt, &tmp))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1995 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1996 if (! discard)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
1997 retval = tmp;
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 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2000 quit = true;
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 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2003
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2004 case 'o': case 'u': case 'x':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2005 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2006 long int tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2007
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2008 if (OCTAVE_SCAN (is, *elt, &tmp))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2009 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2010 if (! discard)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2011 retval = tmp;
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 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2014 quit = true;
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 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2017
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2018 case 'e': case 'f': case 'g':
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 double tmp;
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 if (OCTAVE_SCAN (is, *elt, &tmp))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2023 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2024 if (! discard)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2025 retval = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2026 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2027 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2028 quit = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2029 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2030 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2031
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2032 case 'c':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2033 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2034 BEGIN_C_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2035
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2036 if (! discard)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2037 retval = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2038
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2039 if (! is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2040 quit = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2041
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2042 is.setf (flags);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2043 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2044 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2045
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2046 case 's':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2047 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2048 BEGIN_S_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2049
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2050 if (! discard)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2051 retval = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2052
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2053 if (! is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2054 quit = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2055 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2056 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2057
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2058 case '[': case '^':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2059 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2060 BEGIN_CHAR_CLASS_CONVERSION ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2061
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2062 if (! discard)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2063 retval = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2064
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2065 if (! is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2066 quit = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2067 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2068 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2069
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2070 case 'p':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2071 error ("%s: unsupported format specifier", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2072 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2073
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2074 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2075 error ("%s: internal format error", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2076 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2077 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2078 }
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2079
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2080 if (ok () && is.fail ())
10315
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 error ("%s: read error", who.c_str ());
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 // FIXME -- is this the right thing to do?
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2085
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2086 if (interactive && name () == "stdin")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2087 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2088 // Skip to end of line.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2089
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2090 bool err;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2091 do_gets (-1, err, false, who);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2092 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2093 }
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2094 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2095
2712
2ff2b536cc9d [project @ 1997-02-21 21:38:21 by jwe]
jwe
parents: 2687
diff changeset
2096 return quit;
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2097 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2098
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2099 octave_value_list
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2100 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
2101 {
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2102 octave_value_list retval;
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2103
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2104 std::istream *isp = input_stream ();
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2105
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2106 if (isp)
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2107 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2108 std::istream& is = *isp;
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2109
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2110 scanf_format_list fmt_list (fmt);
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2111
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2112 octave_idx_type nconv = fmt_list.num_conversions ();
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
2113
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2114 if (nconv == -1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2115 ::error ("%s: invalid format specified", who.c_str ());
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2116 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2117 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2118 is.clear ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2119
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2120 octave_idx_type len = fmt_list.length ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2121
13271
fba2cc36b762 return stream error message in scanf functions and document behavior
John W. Eaton <jwe@octave.org>
parents: 12998
diff changeset
2122 retval.resize (nconv+2, Matrix ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2123
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2124 const scanf_format_elt *elt = fmt_list.first ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2125
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2126 int num_values = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2127
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2128 bool quit = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2129
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2130 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
2131 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2132 octave_value tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2133
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2134 quit = do_oscanf (elt, tmp, who);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2135
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2136 if (quit)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2137 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2138 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2139 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2140 if (tmp.is_defined ())
14844
5bc9b9cb4362 maint: Use Octave coding conventions for cuddled parenthesis in retval assignments.
Rik <octave@nomad.inbox5.com>
parents: 14675
diff changeset
2141 retval(num_values++) = tmp;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2142
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2143 if (! ok ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2144 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2145
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2146 elt = fmt_list.next (nconv > 0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2147 }
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
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2150 retval(nconv) = num_values;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2151
13271
fba2cc36b762 return stream error message in scanf functions and document behavior
John W. Eaton <jwe@octave.org>
parents: 12998
diff changeset
2152 int err_num;
fba2cc36b762 return stream error message in scanf functions and document behavior
John W. Eaton <jwe@octave.org>
parents: 12998
diff changeset
2153 retval(nconv+1) = error (false, err_num);
fba2cc36b762 return stream error message in scanf functions and document behavior
John W. Eaton <jwe@octave.org>
parents: 12998
diff changeset
2154
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2155 if (! quit)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2156 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2157 // Pick up any trailing stuff.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2158 if (ok () && len > nconv)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2159 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2160 octave_value tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2161
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2162 elt = fmt_list.next ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2163
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2164 do_oscanf (elt, tmp, who);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2165 }
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 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2168 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2169 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2170 invalid_operation (who, "reading");
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2171
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2172 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2173 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2174
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2175 // Functions that are defined for all output streams (output streams
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2176 // are those that define os).
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2177
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2178 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2179 octave_base_stream::flush (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2180 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2181 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2182
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2183 std::ostream *os = output_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2184
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2185 if (os)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2186 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2187 os->flush ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2188
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2189 if (os->good ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2190 retval = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2191 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2192 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2193 invalid_operation ("fflush", "writing");
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2194
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2195 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2196 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2197
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2198 class
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2199 printf_value_cache
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2200 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2201 public:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2202
3653
84b2f30007d5 [project @ 2000-03-31 23:33:25 by jwe]
jwe
parents: 3645
diff changeset
2203 enum state { ok, conversion_error };
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2204
7352
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2205 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
2206 : values (args), val_idx (0), elt_idx (0),
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2207 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
2208 curr_state (ok)
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2209 {
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2210 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
2211 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2212 octave_value val = values(i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2213
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2214 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
2215 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2216 gripe_wrong_type_arg (who, val);
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 }
7352
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2219 }
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2220 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2221
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2222 ~printf_value_cache (void) { }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2223
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2224 // 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
2225 double double_value (void);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2226
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2227 // 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
2228 int int_value (void);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2229
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2230 // 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
2231 std::string string_value (void);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2232
3145
0d640dc625c7 [project @ 1998-02-05 08:44:59 by jwe]
jwe
parents: 3013
diff changeset
2233 operator bool () const { return (curr_state == ok); }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2234
3653
84b2f30007d5 [project @ 2000-03-31 23:33:25 by jwe]
jwe
parents: 3645
diff changeset
2235 bool exhausted (void) { return (val_idx >= n_vals); }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2236
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2237 private:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2238
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2239 const octave_value_list values;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2240 int val_idx;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2241 int elt_idx;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2242 int n_vals;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2243 int n_elts;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2244 const double *data;
4874
c69a6a16932b [project @ 2004-04-22 16:02:25 by jwe]
jwe
parents: 4797
diff changeset
2245 NDArray curr_val;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2246 state curr_state;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2247
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2248 // Must create value cache with values!
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2249
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2250 printf_value_cache (void);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2251
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2252 // No copying!
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2253
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2254 printf_value_cache (const printf_value_cache&);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2255
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2256 printf_value_cache& operator = (const printf_value_cache&);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2257 };
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2258
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2259 double
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2260 printf_value_cache::double_value (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2261 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2262 double retval = 0.0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2263
3711
60db0e500f10 [project @ 2000-08-03 05:09:39 by jwe]
jwe
parents: 3704
diff changeset
2264 if (exhausted ())
60db0e500f10 [project @ 2000-08-03 05:09:39 by jwe]
jwe
parents: 3704
diff changeset
2265 curr_state = conversion_error;
60db0e500f10 [project @ 2000-08-03 05:09:39 by jwe]
jwe
parents: 3704
diff changeset
2266
60db0e500f10 [project @ 2000-08-03 05:09:39 by jwe]
jwe
parents: 3704
diff changeset
2267 while (! exhausted ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2268 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2269 if (! data)
10315
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 octave_value tmp_val = values (val_idx);
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 // Force string conversion here for compatibility.
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 curr_val = tmp_val.array_value (true);
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 if (! error_state)
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 elt_idx = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2280 n_elts = curr_val.length ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2281 data = curr_val.data ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2282 }
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 curr_state = conversion_error;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2286 break;
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 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2289
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2290 if (elt_idx < n_elts)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2291 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2292 retval = data[elt_idx++];
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 if (elt_idx >= n_elts)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2295 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2296 elt_idx = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2297 val_idx++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2298 data = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2299 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2300
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2301 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2302 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2303 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2304 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2305 val_idx++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2306 data = 0;
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 if (n_elts == 0 && exhausted ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2309 curr_state = conversion_error;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2310
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2311 continue;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2312 }
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2315 return retval;
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2318 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2319 printf_value_cache::int_value (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2320 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2321 int retval = 0;
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 double dval = double_value ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2324
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2325 if (! error_state)
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 (D_NINT (dval) == dval)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2328 retval = NINT (dval);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2329 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2330 curr_state = conversion_error;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2331 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2332
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2333 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2334 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2335
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
2336 std::string
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2337 printf_value_cache::string_value (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2338 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2339 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2340
4425
82f8aae8cf20 [project @ 2003-06-13 15:08:25 by jwe]
jwe
parents: 4420
diff changeset
2341 if (exhausted ())
82f8aae8cf20 [project @ 2003-06-13 15:08:25 by jwe]
jwe
parents: 4420
diff changeset
2342 curr_state = conversion_error;
4257
e556870ce8f0 [project @ 2003-01-02 03:14:41 by jwe]
jwe
parents: 4254
diff changeset
2343 else
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2344 {
4425
82f8aae8cf20 [project @ 2003-06-13 15:08:25 by jwe]
jwe
parents: 4420
diff changeset
2345 octave_value tval = values (val_idx++);
82f8aae8cf20 [project @ 2003-06-13 15:08:25 by jwe]
jwe
parents: 4420
diff changeset
2346
82f8aae8cf20 [project @ 2003-06-13 15:08:25 by jwe]
jwe
parents: 4420
diff changeset
2347 if (tval.rows () == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2348 retval = tval.string_value ();
4425
82f8aae8cf20 [project @ 2003-06-13 15:08:25 by jwe]
jwe
parents: 4420
diff changeset
2349 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2350 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2351 // In the name of Matlab compatibility.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2352
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2353 charMatrix chm = tval.char_matrix_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2354
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2355 octave_idx_type nr = chm.rows ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2356 octave_idx_type nc = chm.columns ();
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 int k = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2359
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2360 retval.resize (nr * nc, '\0');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2361
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2362 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
2363 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
2364 retval[k++] = chm(i,j);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2365 }
4425
82f8aae8cf20 [project @ 2003-06-13 15:08:25 by jwe]
jwe
parents: 4420
diff changeset
2366
82f8aae8cf20 [project @ 2003-06-13 15:08:25 by jwe]
jwe
parents: 4420
diff changeset
2367 if (error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2368 curr_state = conversion_error;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2369 }
4257
e556870ce8f0 [project @ 2003-01-02 03:14:41 by jwe]
jwe
parents: 4254
diff changeset
2370
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2371 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2372 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2373
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2374 // Ugh again and again.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2375
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2376 template <class T>
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
2377 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2378 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
2379 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
2380 {
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
2381 int retval = 0;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
2382
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2383 switch (nsa)
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2384 {
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2385 case 2:
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2386 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
2387 break;
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2388
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2389 case 1:
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2390 retval = octave_format (os, fmt, sa_1, arg);
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2391 break;
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2392
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2393 case 0:
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2394 retval = octave_format (os, fmt, arg);
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2395 break;
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2396
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2397 default:
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2398 ::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
2399 break;
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2400 }
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
2401
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
2402 return retval;
2572
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2403 }
5c2be7c820ed [project @ 1996-12-08 04:02:46 by jwe]
jwe
parents: 2435
diff changeset
2404
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
2405 template int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2406 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
2407 const std::string&);
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2408
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2409 template int
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2410 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
2411 const std::string&);
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2412
3878
faeca8a063ae [project @ 2002-03-07 23:28:32 by jwe]
jwe
parents: 3810
diff changeset
2413 template int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2414 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
2415 const std::string&);
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2416
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2417 template int
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2418 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
2419 const std::string&);
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2420
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2421 template int
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2422 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
2423 const std::string&);
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2424
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2425 template int
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2426 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
2427 const std::string&);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2428
6492
bcfdc9f0d267 [project @ 2007-04-05 06:13:30 by jwe]
jwe
parents: 6483
diff changeset
2429 #define DO_DOUBLE_CONV(TQUAL) \
bcfdc9f0d267 [project @ 2007-04-05 06:13:30 by jwe]
jwe
parents: 6483
diff changeset
2430 do \
bcfdc9f0d267 [project @ 2007-04-05 06:13:30 by jwe]
jwe
parents: 6483
diff changeset
2431 { \
7199
cd6ceb8cbf09 [project @ 2007-11-27 03:29:57 by jwe]
jwe
parents: 7017
diff changeset
2432 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
2433 || val < std::numeric_limits<TQUAL long>::min ()) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2434 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2435 std::string tfmt = fmt; \
6492
bcfdc9f0d267 [project @ 2007-04-05 06:13:30 by jwe]
jwe
parents: 6483
diff changeset
2436 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2437 tfmt.replace (tfmt.rfind (elt->type), 1, ".f"); \
6492
bcfdc9f0d267 [project @ 2007-04-05 06:13:30 by jwe]
jwe
parents: 6483
diff changeset
2438 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2439 if (elt->modifier == 'l') \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2440 tfmt.replace (tfmt.rfind (elt->modifier), 1, ""); \
7199
cd6ceb8cbf09 [project @ 2007-11-27 03:29:57 by jwe]
jwe
parents: 7017
diff changeset
2441 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2442 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
2443 val, who); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2444 } \
6492
bcfdc9f0d267 [project @ 2007-04-05 06:13:30 by jwe]
jwe
parents: 6483
diff changeset
2445 else \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2446 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
2447 static_cast<TQUAL long> (val), who); \
6492
bcfdc9f0d267 [project @ 2007-04-05 06:13:30 by jwe]
jwe
parents: 6483
diff changeset
2448 } \
bcfdc9f0d267 [project @ 2007-04-05 06:13:30 by jwe]
jwe
parents: 6483
diff changeset
2449 while (0)
bcfdc9f0d267 [project @ 2007-04-05 06:13:30 by jwe]
jwe
parents: 6483
diff changeset
2450
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2451 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2452 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
2453 const octave_value_list& args,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2454 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2455 {
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3559
diff changeset
2456 int retval = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2457
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2458 octave_idx_type nconv = fmt_list.num_conversions ();
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2459
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2460 std::ostream *osp = output_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2461
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2462 if (osp)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2463 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2464 std::ostream& os = *osp;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2465
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2466 const printf_format_elt *elt = fmt_list.first ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2467
7352
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2468 printf_value_cache val_cache (args, who);
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2469
fab9bc33b949 [project @ 2008-01-07 18:54:45 by jwe]
jwe
parents: 7227
diff changeset
2470 if (error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2471 return retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2472
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2473 for (;;)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2474 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2475 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2476
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2477 if (elt)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2478 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2479 // 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
2480
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2481 int nsa = (elt->fw < 0) + (elt->prec < 0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2482
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2483 int sa_1 = 0;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2484 int sa_2 = 0;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2485
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2486 if (nsa > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2487 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2488 sa_1 = val_cache.int_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2489
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2490 if (! val_cache)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2491 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2492 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2493 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2494 if (nsa > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2495 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2496 sa_2 = val_cache.int_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2497
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2498 if (! val_cache)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2499 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2500 }
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 }
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 const char *fmt = elt->text;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2505
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2506 if (elt->type == '%')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2507 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2508 os << "%";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2509 retval++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2510 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2511 else if (elt->args == 0 && elt->text)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2512 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2513 os << elt->text;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2514 retval += strlen (elt->text);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2515 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2516 else if (elt->type == 's')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2517 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2518 std::string val = val_cache.string_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2519
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2520 if (val_cache)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2521 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
2522 sa_2, val.c_str (), who);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2523 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2524 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2525 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2526 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2527 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2528 double val = val_cache.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2529
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2530 if (val_cache)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2531 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2532 if (lo_ieee_isnan (val) || xisinf (val))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2533 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2534 std::string tfmt = fmt;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2535 std::string::size_type i1, i2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2536
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2537 tfmt.replace ((i1 = tfmt.rfind (elt->type)),
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2538 1, 1, 's');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2539
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2540 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
2541 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2542 tfmt.erase (i2, i1-i2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2543 if (elt->prec < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2544 nsa--;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2545 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2546
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2547 const char *tval = xisinf (val)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2548 ? (val < 0 ? "-Inf" : "Inf")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2549 : (lo_ieee_is_NA (val) ? "NA" : "NaN");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2550
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2551 retval += do_printf_conv (os, tfmt.c_str (),
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2552 nsa, sa_1, sa_2,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2553 tval, who);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2554 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2555 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2556 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2557 char type = elt->type;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2558
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2559 switch (type)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2560 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2561 case 'd': case 'i': case 'c':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2562 DO_DOUBLE_CONV (OCTAVE_EMPTY_CPP_ARG);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2563 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2564
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2565 case 'o': case 'x': case 'X': case 'u':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2566 DO_DOUBLE_CONV (unsigned);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2567 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2568
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2569 case 'f': case 'e': case 'E':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2570 case 'g': case 'G':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2571 retval
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2572 += 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
2573 val, who);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2574 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2575
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2576 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2577 error ("%s: invalid format specifier",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2578 who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2579 return -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2580 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2581 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2582 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2583 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2584 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2585 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2586 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2587
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2588 if (! os)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2589 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2590 error ("%s: write error", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2591 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2592 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2593 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2594 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2595 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2596 ::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
2597 retval = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2598 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2599 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2600
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2601 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
2602
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2603 if (! elt || (val_cache.exhausted () && elt->args > 0))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2604 break;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2605 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2606 }
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2607 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2608 invalid_operation (who, "writing");
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2609
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2610 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2611 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2612
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2613 int
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2614 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
2615 const octave_value_list& args,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2616 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2617 {
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2618 int retval = 0;
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2619
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2620 printf_format_list fmt_list (fmt);
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2621
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3639
diff changeset
2622 if (fmt_list.num_conversions () == -1)
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2623 ::error ("%s: invalid format specified", who.c_str ());
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2624 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2625 retval = do_printf (fmt_list, args, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2626
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2627 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2628 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2629
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2630 int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2631 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
2632 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2633 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2634
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2635 std::ostream *osp = output_stream ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2636
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2637 if (osp)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2638 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2639 std::ostream& os = *osp;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2640
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2641 os << s;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2642
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2643 if (os)
10315
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 // FIXME -- why does this seem to be necessary?
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2646 // Without it, output from a loop like
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 // 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
2649 //
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2650 // 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
2651
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2652 os.flush ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2653
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2654 if (os)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2655 retval = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2656 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2657 error ("%s: write error", who.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2658 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2659 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2660 error ("%s: write error", who.c_str ());
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2661 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2662 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2663 invalid_operation (who, "writing");
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2664
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2665 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2666 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2667
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2668 // Return current error message for this stream.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2669
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
2670 std::string
2435
3be97fe02051 [project @ 1996-10-27 21:31:29 by jwe]
jwe
parents: 2341
diff changeset
2671 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
2672 {
2435
3be97fe02051 [project @ 1996-10-27 21:31:29 by jwe]
jwe
parents: 2341
diff changeset
2673 err_num = fail ? -1 : 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2674
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2675 std::string tmp = errmsg;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2676
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2677 if (clear_err)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2678 clear ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2679
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2680 return tmp;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2681 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2682
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2683 void
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2684 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
2685 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2686 // Note that this is not ::error () !
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2687
6297
a943cb9c8068 [project @ 2007-02-10 08:42:27 by jwe]
jwe
parents: 6296
diff changeset
2688 error (who, std::string ("stream not open for ") + rw);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2689 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2690
3552
41daa489833a [project @ 2000-02-03 03:05:28 by jwe]
jwe
parents: 3548
diff changeset
2691 octave_stream::octave_stream (octave_base_stream *bs)
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2692 : rep (bs)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2693 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2694 if (rep)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2695 rep->count = 1;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2696 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2697
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2698 octave_stream::~octave_stream (void)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2699 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2700 if (rep && --rep->count == 0)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2701 delete rep;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2702 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2703
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2704 octave_stream::octave_stream (const octave_stream& s)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2705 : rep (s.rep)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2706 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2707 if (rep)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2708 rep->count++;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2709 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2710
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2711 octave_stream&
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2712 octave_stream::operator = (const octave_stream& s)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2713 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2714 if (rep != s.rep)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2715 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2716 if (rep && --rep->count == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2717 delete rep;
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2718
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2719 rep = s.rep;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2720
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2721 if (rep)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2722 rep->count++;
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2723 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2724
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2725 return *this;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2726 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
2727
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2728 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2729 octave_stream::flush (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2730 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2731 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2732
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
2733 if (stream_ok ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2734 retval = rep->flush ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2735
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2736 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2737 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2738
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
2739 std::string
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
2740 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
2741 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2742 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2743
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
2744 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2745 retval = rep->getl (max_len, err, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2746
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2747 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2748 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2749
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
2750 std::string
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2751 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
2752 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2753 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2754 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2755
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2756 err = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2757
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2758 int conv_err = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2759
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2760 int max_len = -1;
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2761
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2762 if (tc_max_len.is_defined ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2763 {
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2764 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
2765
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2766 if (conv_err || max_len < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2767 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2768 err = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2769 ::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
2770 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2771 }
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2772
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2773 if (! error_state)
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2774 retval = getl (max_len, err, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2775
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2776 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2777 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2778
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
2779 std::string
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
2780 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
2781 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2782 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2783
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
2784 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2785 retval = rep->gets (max_len, err, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2786
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2787 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2788 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2789
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
2790 std::string
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2791 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
2792 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2793 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2794 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2795
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2796 err = false;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2797
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2798 int conv_err = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2799
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2800 int max_len = -1;
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2801
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2802 if (tc_max_len.is_defined ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2803 {
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2804 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
2805
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2806 if (conv_err || max_len < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2807 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2808 err = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2809 ::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
2810 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2811 }
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2812
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6297
diff changeset
2813 if (! error_state)
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
2814 retval = gets (max_len, err, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2815
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2816 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2817 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2818
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2819 long
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2820 octave_stream::skipl (long count, bool& err, const std::string& who)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2821 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2822 long retval = -1;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2823
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2824 if (stream_ok ())
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2825 retval = rep->skipl (count, err, who);
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2826
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2827 return retval;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2828 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2829
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2830 long
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2831 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
2832 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2833 long retval = -1;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2834
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2835 err = false;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2836
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2837 int conv_err = 0;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2838
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2839 int count = 1;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2840
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2841 if (tc_count.is_defined ())
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2842 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2843 if (tc_count.is_scalar_type () && xisinf (tc_count.scalar_value ()))
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2844 count = -1;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2845 else
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2846 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2847 count = convert_to_valid_int (tc_count, conv_err);
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2848
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2849 if (conv_err || count < 0)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2850 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2851 err = true;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2852 ::error ("%s: invalid number of lines specified", who.c_str ());
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2853 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2854 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2855 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2856
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2857 if (! error_state)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2858 retval = skipl (count, err, who);
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2859
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2860 return retval;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2861 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2862
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2863 int
4797
19b8225bdaa2 [project @ 2004-02-23 22:10:31 by jwe]
jwe
parents: 4693
diff changeset
2864 octave_stream::seek (long offset, int origin)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2865 {
5065
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
2866 int status = -1;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2867
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
2868 if (stream_ok ())
4889
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
2869 {
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
2870 clearerr ();
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
2871
12957
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2872 // Find current position so we can return to it if needed.
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2873
5065
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
2874 long orig_pos = rep->tell ();
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
2875
12957
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2876 // Move to end of file. If successful, find the offset of the end.
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2877
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2878 status = rep->seek (0, SEEK_END);
5065
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
2879
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
2880 if (status == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2881 {
12957
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2882 long eof_pos = rep->tell ();
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2883
12943
8372d50de75a improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents: 12936
diff changeset
2884 if (origin == SEEK_CUR)
8372d50de75a improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents: 12936
diff changeset
2885 {
8372d50de75a improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents: 12936
diff changeset
2886 // Move back to original position, otherwise we will be
8372d50de75a improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents: 12936
diff changeset
2887 // seeking from the end of file which is probably not the
8372d50de75a improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents: 12936
diff changeset
2888 // original location.
8372d50de75a improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents: 12936
diff changeset
2889
8372d50de75a improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents: 12936
diff changeset
2890 rep->seek (orig_pos, SEEK_SET);
8372d50de75a improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents: 12936
diff changeset
2891 }
8372d50de75a improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents: 12936
diff changeset
2892
12957
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2893 // Attempt to move to desired position; may be outside bounds
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2894 // of existing file.
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2895
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2896 status = rep->seek (offset, origin);
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2897
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2898 if (status == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2899 {
12957
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2900 // Where are we after moving to desired position?
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2901
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2902 long desired_pos = rep->tell ();
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2903
12943
8372d50de75a improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents: 12936
diff changeset
2904 // I don't think save_pos can be less than zero, but we'll
8372d50de75a improve logic of octave_stream::seek funtion
John W. Eaton <jwe@octave.org>
parents: 12936
diff changeset
2905 // check anyway...
12957
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2906
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2907 if (desired_pos > eof_pos || desired_pos < 0)
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2908 {
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2909 // Seek outside bounds of file. Failure should leave
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2910 // position unchanged.
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2911
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2912 rep->seek (orig_pos, SEEK_SET);
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2913
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2914 status = -1;
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2915 }
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2916 }
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2917 else
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2918 {
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2919 // Seeking to the desired position failed. Move back to
fb69561e5901 maint: fix missing line continuation in src/Makefile.am
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
2920 // original position and return failure status.
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2921
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2922 rep->seek (orig_pos, SEEK_SET);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2923
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2924 status = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2925 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2926 }
4889
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4888
diff changeset
2927 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2928
5065
1312d3af9eb0 [project @ 2004-11-04 20:12:00 by jwe]
jwe
parents: 5030
diff changeset
2929 return status;
2117
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2932 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2933 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
2934 const octave_value& tc_origin)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2935 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2936 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2937
4797
19b8225bdaa2 [project @ 2004-02-23 22:10:31 by jwe]
jwe
parents: 4693
diff changeset
2938 long xoffset = tc_offset.long_value (true);
4645
bd2067547b40 [project @ 2003-11-23 08:07:52 by jwe]
jwe
parents: 4643
diff changeset
2939
bd2067547b40 [project @ 2003-11-23 08:07:52 by jwe]
jwe
parents: 4643
diff changeset
2940 if (! error_state)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2941 {
4645
bd2067547b40 [project @ 2003-11-23 08:07:52 by jwe]
jwe
parents: 4643
diff changeset
2942 int conv_err = 0;
bd2067547b40 [project @ 2003-11-23 08:07:52 by jwe]
jwe
parents: 4643
diff changeset
2943
4797
19b8225bdaa2 [project @ 2004-02-23 22:10:31 by jwe]
jwe
parents: 4693
diff changeset
2944 int origin = SEEK_SET;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2945
2341
6ee55c0f25a9 [project @ 1996-07-24 10:33:09 by jwe]
jwe
parents: 2317
diff changeset
2946 if (tc_origin.is_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2947 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2948 std::string xorigin = tc_origin.string_value ();
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 if (xorigin == "bof")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2951 origin = SEEK_SET;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2952 else if (xorigin == "cof")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2953 origin = SEEK_CUR;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2954 else if (xorigin == "eof")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2955 origin = SEEK_END;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2956 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2957 conv_err = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2958 }
2341
6ee55c0f25a9 [project @ 1996-07-24 10:33:09 by jwe]
jwe
parents: 2317
diff changeset
2959 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2960 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2961 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
2962
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2963 if (! conv_err)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2964 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2965 if (xorigin == -1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2966 origin = SEEK_SET;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2967 else if (xorigin == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2968 origin = SEEK_CUR;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2969 else if (xorigin == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2970 origin = SEEK_END;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2971 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2972 conv_err = -1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2973 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2974 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2975
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2976 if (! conv_err)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2977 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2978 retval = seek (xoffset, origin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2979
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2980 if (retval != 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2981 error ("fseek: failed to seek to requested position");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2982 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2983 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
2984 error ("fseek: invalid value for origin");
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2985 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2986 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2987 error ("fseek: invalid value for offset");
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2988
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2989 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2990 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2991
4797
19b8225bdaa2 [project @ 2004-02-23 22:10:31 by jwe]
jwe
parents: 4693
diff changeset
2992 long
19b8225bdaa2 [project @ 2004-02-23 22:10:31 by jwe]
jwe
parents: 4693
diff changeset
2993 octave_stream::tell (void)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2994 {
4797
19b8225bdaa2 [project @ 2004-02-23 22:10:31 by jwe]
jwe
parents: 4693
diff changeset
2995 long retval = -1;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2996
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
2997 if (stream_ok ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2998 retval = rep->tell ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2999
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3000 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3001 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3002
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3003 int
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3004 octave_stream::rewind (void)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3005 {
6296
85eb75190e01 [project @ 2007-02-10 07:10:42 by jwe]
jwe
parents: 6109
diff changeset
3006 return seek (0, SEEK_SET);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3007 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3008
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3009 bool
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3010 octave_stream::is_open (void) const
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3011 {
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3012 bool retval = false;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3013
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3014 if (stream_ok ())
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3015 retval = rep->is_open ();
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3016
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3017 return retval;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3018 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3019
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3020 void
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3021 octave_stream::close (void)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3022 {
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3023 if (stream_ok ())
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3024 rep->close ();
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3025 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3026
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3027 template <class RET_T, class READ_T>
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3028 octave_value
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3029 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
3030 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
3031 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
3032 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3033 octave_value retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3034
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3035 RET_T nda;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3036
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3037 count = 0;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3038
9941
1369f13ae6b2 several fixes by M. Goffioul
Jaroslav Hajek <highegg@gmail.com>
parents: 9701
diff changeset
3039 typedef typename RET_T::element_type ELMT;
1369f13ae6b2 several fixes by M. Goffioul
Jaroslav Hajek <highegg@gmail.com>
parents: 9701
diff changeset
3040 ELMT elt_zero = ELMT ();
1369f13ae6b2 several fixes by M. Goffioul
Jaroslav Hajek <highegg@gmail.com>
parents: 9701
diff changeset
3041
1369f13ae6b2 several fixes by M. Goffioul
Jaroslav Hajek <highegg@gmail.com>
parents: 9701
diff changeset
3042 ELMT *dat = 0;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3043
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3044 octave_idx_type max_size = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3045
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3046 octave_idx_type final_nr = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3047 octave_idx_type final_nc = 1;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3048
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3049 if (nr > 0)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3050 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3051 if (nc > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3052 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3053 nda.resize (dim_vector (nr, nc), elt_zero);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3054 dat = nda.fortran_vec ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3055 max_size = nr * nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3056 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3057 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3058 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3059 nda.resize (dim_vector (nr, 32), elt_zero);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3060 dat = nda.fortran_vec ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3061 max_size = nr * 32;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3062 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3063 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3064 else
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3065 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3066 nda.resize (dim_vector (32, 1), elt_zero);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3067 dat = nda.fortran_vec ();
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3068 max_size = 32;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3069 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3070
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5765
diff changeset
3071 // FIXME -- byte order for Cray?
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3072
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3073 bool swap = false;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3074
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3075 if (oct_mach_info::words_big_endian ())
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3076 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
3077 || 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
3078 || 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
3079 else
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3080 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
3081
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3082 union
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3083 {
9685
e793865ede63 implement builtin_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9202
diff changeset
3084 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
3085 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
3086 } u;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3087
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3088 std::istream *isp = strm.input_stream ();
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3089
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3090 if (isp)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3091 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3092 std::istream& is = *isp;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3093
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3094 octave_idx_type elts_read = 0;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3095
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3096 for (;;)
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 // 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
3099 // skip == 0.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3100
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3101 if (is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3102 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3103 if (nr > 0 && nc > 0 && count == max_size)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3104 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3105 final_nr = nr;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3106 final_nc = nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3107
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3108 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3109 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3110
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3111 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
3112
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3113 // 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
3114 // types, the format conversion will also handle byte
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3115 // swapping.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3116
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3117 if (swap)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3118 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
3119 else if (do_float_fmt_conv)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3120 do_float_format_conversion
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3121 (u.buf,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3122 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
3123 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
3124
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3125 typename RET_T::element_type tmp
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3126 = 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
3127
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3128 if (is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3129 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3130 if (count == max_size)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3131 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3132 max_size *= 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3133
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3134 if (nr > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3135 nda.resize (dim_vector (nr, max_size / nr),
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3136 elt_zero);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3137 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3138 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
3139
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3140 dat = nda.fortran_vec ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3141 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3142
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3143 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
3144 tmp = __lo_ieee_replace_old_NA (tmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3145
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3146 dat[count++] = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3147
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3148 elts_read++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3149 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3150
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3151 int seek_status = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3152
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3153 if (skip != 0 && elts_read == block_size)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3154 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3155 seek_status = strm.seek (skip, SEEK_CUR);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3156 elts_read = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3157 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3158
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3159 if (is.eof () || seek_status < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3160 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3161 if (nr > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3162 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3163 if (count > nr)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3164 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3165 final_nr = nr;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3166 final_nc = (count - 1) / nr + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3167 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3168 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3169 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3170 final_nr = count;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3171 final_nc = 1;
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 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3174 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3175 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3176 final_nr = count;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3177 final_nc = 1;
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
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3180 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3181 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3182 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3183 else if (is.eof ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3184 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3185 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3186 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3187
5030
160365410ad4 [project @ 2004-09-24 03:22:23 by jwe]
jwe
parents: 4970
diff changeset
3188 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
3189
160365410ad4 [project @ 2004-09-24 03:22:23 by jwe]
jwe
parents: 4970
diff changeset
3190 retval = nda;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3191
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3192 return retval;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3193 }
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 #define DO_READ_VAL_TEMPLATE(RET_T, READ_T) \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3196 template octave_value \
7995
89dd4531b26a fread: translate NA values
John W. Eaton <jwe@octave.org>
parents: 7789
diff changeset
3197 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
3198 oct_mach_info::float_format, octave_idx_type&)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3199
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5765
diff changeset
3200 // 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
3201 // size from double?
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3202
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3203 #define INSTANTIATE_DO_READ(VAL_T) \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3204 DO_READ_VAL_TEMPLATE (VAL_T, octave_int8); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3205 DO_READ_VAL_TEMPLATE (VAL_T, octave_uint8); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3206 DO_READ_VAL_TEMPLATE (VAL_T, octave_int16); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3207 DO_READ_VAL_TEMPLATE (VAL_T, octave_uint16); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3208 DO_READ_VAL_TEMPLATE (VAL_T, octave_int32); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3209 DO_READ_VAL_TEMPLATE (VAL_T, octave_uint32); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3210 DO_READ_VAL_TEMPLATE (VAL_T, octave_int64); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3211 DO_READ_VAL_TEMPLATE (VAL_T, octave_uint64); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3212 DO_READ_VAL_TEMPLATE (VAL_T, float); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3213 DO_READ_VAL_TEMPLATE (VAL_T, double); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3214 DO_READ_VAL_TEMPLATE (VAL_T, char); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3215 DO_READ_VAL_TEMPLATE (VAL_T, signed char); \
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3216 DO_READ_VAL_TEMPLATE (VAL_T, unsigned char)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3217
4970
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4946
diff changeset
3218 INSTANTIATE_DO_READ (int8NDArray);
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4946
diff changeset
3219 INSTANTIATE_DO_READ (uint8NDArray);
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4946
diff changeset
3220 INSTANTIATE_DO_READ (int16NDArray);
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4946
diff changeset
3221 INSTANTIATE_DO_READ (uint16NDArray);
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4946
diff changeset
3222 INSTANTIATE_DO_READ (int32NDArray);
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4946
diff changeset
3223 INSTANTIATE_DO_READ (uint32NDArray);
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4946
diff changeset
3224 INSTANTIATE_DO_READ (int64NDArray);
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4946
diff changeset
3225 INSTANTIATE_DO_READ (uint64NDArray);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7724
diff changeset
3226 INSTANTIATE_DO_READ (FloatNDArray);
4970
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4946
diff changeset
3227 INSTANTIATE_DO_READ (NDArray);
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4946
diff changeset
3228 INSTANTIATE_DO_READ (charNDArray);
5780
cbf717bf8150 [project @ 2006-04-27 20:02:30 by jwe]
jwe
parents: 5775
diff changeset
3229 INSTANTIATE_DO_READ (boolNDArray);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3230
7995
89dd4531b26a fread: translate NA values
John W. Eaton <jwe@octave.org>
parents: 7789
diff changeset
3231 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
3232 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
3233
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3234 #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
3235 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
3236 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
3237 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
3238 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
3239 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
3240 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
3241 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
3242 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
3243 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
3244 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
3245 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
3246 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
3247 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
3248 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
3249
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3250 octave_value
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3251 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
3252 oct_data_conv::data_type input_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3253 oct_data_conv::data_type output_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3254 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
3255 octave_idx_type& char_count)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3256 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3257 static bool initialized = false;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3258
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3259 // Table function pointers for return types x read types.
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3260
9202
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
3261 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
3262
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3263 if (! initialized)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3264 {
9202
4b2147b25e8d clean up Array instantiation mess in oct-stream.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9017
diff changeset
3265 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
3266 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
3267 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
3268
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3269 FILL_TABLE_ROW (oct_data_conv::dt_int8, int8NDArray);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3270 FILL_TABLE_ROW (oct_data_conv::dt_uint8, uint8NDArray);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3271 FILL_TABLE_ROW (oct_data_conv::dt_int16, int16NDArray);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3272 FILL_TABLE_ROW (oct_data_conv::dt_uint16, uint16NDArray);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3273 FILL_TABLE_ROW (oct_data_conv::dt_int32, int32NDArray);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3274 FILL_TABLE_ROW (oct_data_conv::dt_uint32, uint32NDArray);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3275 FILL_TABLE_ROW (oct_data_conv::dt_int64, int64NDArray);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3276 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
3277 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
3278 FILL_TABLE_ROW (oct_data_conv::dt_double, NDArray);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3279 FILL_TABLE_ROW (oct_data_conv::dt_char, charNDArray);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3280 FILL_TABLE_ROW (oct_data_conv::dt_schar, charNDArray);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3281 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
3282 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
3283
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3284 initialized = true;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3285 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3286
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3287 octave_value retval;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3288
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3289 if (stream_ok ())
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3290 {
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5765
diff changeset
3291 // FIXME -- we may eventually want to make this extensible.
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5765
diff changeset
3292
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5765
diff changeset
3293 // 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
3294 // 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
3295 // data_type enum in the oct_data_conv class.
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3296
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3297 char_count = 0;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3298
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3299 octave_idx_type nr = -1;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3300 octave_idx_type nc = -1;
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3301
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3302 bool ignore;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3303
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3304 get_size (size, nr, nc, ignore, "fread");
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3305
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3306 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3307 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3308 if (nr == 0 || nc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3309 retval = Matrix (nr, nc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3310 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3311 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3312 if (ffmt == oct_mach_info::flt_fmt_unknown)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3313 ffmt = float_format ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3314
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3315 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
3316
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3317 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
3318 || input_type == oct_data_conv::dt_single)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3319 && ffmt != float_format ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3320
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3321 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
3322
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3323 if (fcn)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3324 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3325 retval = (*fcn) (*this, nr, nc, block_size, skip,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3326 do_float_fmt_conv, do_NA_conv,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3327 ffmt, char_count);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3328
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3329 // FIXME -- kluge!
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3330
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3331 if (! error_state
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3332 && (output_type == oct_data_conv::dt_char
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3333 || output_type == oct_data_conv::dt_schar
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3334 || output_type == oct_data_conv::dt_uchar))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3335 retval = retval.char_matrix_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3336 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3337 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3338 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
3339 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3340 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3341 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3342 invalid_operation ("fread", "reading");
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3343 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3344
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3345 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3346 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3347
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3348 octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3349 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
3350 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
3351 oct_mach_info::float_format flt_fmt)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3352 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3353 octave_idx_type retval = -1;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3354
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3355 if (stream_ok ())
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3356 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3357 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3358 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3359 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
3360 flt_fmt = float_format ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3361
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3362 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
3363 skip, flt_fmt);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3364
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3365 if (status < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3366 error ("fwrite: write error");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3367 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3368 retval = status;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3369 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3370 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3371 invalid_operation ("fwrite", "writing");
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3372 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3373
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3374 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3375 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3376
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3377 template <class T>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3378 void
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3379 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
3380 {
9685
e793865ede63 implement builtin_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9202
diff changeset
3381 typename T::val_type tmp = val.value ();
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 (swap)
9685
e793865ede63 implement builtin_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9202
diff changeset
3384 swap_bytes<sizeof (typename T::val_type)> (&tmp);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3385
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3386 os.write (reinterpret_cast<const char *> (&tmp),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3387 sizeof (typename T::val_type));
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3388 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3389
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3390 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
3391 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
3392 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
3393 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
3394 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
3395 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
3396 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
3397 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
3398
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3399 template <class T>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3400 static inline bool
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3401 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
3402 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
3403 bool do_float_conversion)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3404 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3405 bool retval = true;
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 // For compatibility, Octave converts to the output type, then
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3408 // writes. This means that truncation happens on the conversion.
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3409 // For example, the following program prints 0:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3410 //
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3411 // x = int8 (-1)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3412 // f = fopen ("foo.dat", "w");
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3413 // fwrite (f, x, "unsigned char");
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3414 // fclose (f);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3415 // f = fopen ("foo.dat", "r");
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3416 // y = fread (f, 1, "unsigned char");
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3417 // printf ("%d\n", y);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3418
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3419 switch (output_type)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3420 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3421 case oct_data_conv::dt_char:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3422 case oct_data_conv::dt_schar:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3423 case oct_data_conv::dt_int8:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3424 write_int (os, swap, octave_int8 (val));
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3425 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3426
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3427 case oct_data_conv::dt_uchar:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3428 case oct_data_conv::dt_uint8:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3429 write_int (os, swap, octave_uint8 (val));
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3430 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3431
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3432 case oct_data_conv::dt_int16:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3433 write_int (os, swap, octave_int16 (val));
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3434 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3435
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3436 case oct_data_conv::dt_uint16:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3437 write_int (os, swap, octave_uint16 (val));
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3438 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3439
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3440 case oct_data_conv::dt_int32:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3441 write_int (os, swap, octave_int32 (val));
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3442 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3443
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3444 case oct_data_conv::dt_uint32:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3445 write_int (os, swap, octave_uint32 (val));
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3446 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3447
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3448 case oct_data_conv::dt_int64:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3449 write_int (os, swap, octave_int64 (val));
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3450 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3451
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3452 case oct_data_conv::dt_uint64:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3453 write_int (os, swap, octave_uint64 (val));
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3454 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3455
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3456 case oct_data_conv::dt_single:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3457 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3458 float f = static_cast<float> (val);
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 if (do_float_conversion)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3461 do_float_format_conversion (&f, 1, flt_fmt);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3462
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3463 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
3464 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3465 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3466
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3467 case oct_data_conv::dt_double:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3468 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3469 double d = static_cast<double> (val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3470 if (do_float_conversion)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3471 do_double_format_conversion (&d, 1, flt_fmt);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3472
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3473 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
3474 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3475 break;
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 default:
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3478 retval = false;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3479 (*current_liboctave_error_handler)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3480 ("write: invalid type specification");
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3481 break;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3482 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3483
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3484 return retval;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3485 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3486
5887
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3487 template bool
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3488 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
3489 oct_mach_info::float_format, bool, bool);
5887
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3490
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3491 template bool
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3492 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
3493 oct_mach_info::float_format, bool, bool);
5887
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3494
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3495 template bool
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3496 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
3497 oct_mach_info::float_format, bool, bool);
5887
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3498
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3499 template bool
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3500 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
3501 oct_mach_info::float_format, bool, bool);
5887
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3502
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3503 template bool
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3504 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
3505 oct_mach_info::float_format, bool, bool);
5887
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3506
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3507 template bool
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3508 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
3509 oct_mach_info::float_format, bool, bool);
5887
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3510
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3511 template bool
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3512 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
3513 oct_mach_info::float_format, bool, bool);
5887
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3514
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3515 template bool
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3516 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
3517 oct_mach_info::float_format, bool, bool);
5887
39cbf6a484bb [project @ 2006-07-14 21:02:33 by jwe]
jwe
parents: 5780
diff changeset
3518
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3519 template <class T>
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3520 octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3521 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
3522 oct_data_conv::data_type output_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3523 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
3524 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3525 octave_idx_type retval = -1;
4944
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 bool status = true;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3528
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3529 octave_idx_type count = 0;
4944
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 const T *d = data.data ();
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3532
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3533 octave_idx_type n = data.length ();
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3534
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3535 oct_mach_info::float_format native_flt_fmt
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3536 = oct_mach_info::float_format ();
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3537
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3538 bool do_float_conversion = (flt_fmt != native_flt_fmt);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3539
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5765
diff changeset
3540 // FIXME -- byte order for Cray?
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3541
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3542 bool swap = false;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3543
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3544 if (oct_mach_info::words_big_endian ())
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3545 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
3546 || 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
3547 || 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
3548 else
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3549 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
3550
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3551 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
3552 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3553 std::ostream *osp = output_stream ();
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3554
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3555 if (osp)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3556 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3557 std::ostream& os = *osp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3558
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3559 if (skip != 0 && (i % block_size) == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3560 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3561 // 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
3562 // Otherwise, write NUL to skip.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3563
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3564 long orig_pos = tell ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3565
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3566 seek (0, SEEK_END);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3567
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3568 long eof_pos = tell ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3569
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3570 // 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
3571 // original position?
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3572 seek (orig_pos, SEEK_SET);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3573
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3574 long remaining = eof_pos - orig_pos;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3575
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3576 if (remaining < skip)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3577 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3578 seek (0, SEEK_END);
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 // FIXME -- probably should try to write larger
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3581 // blocks...
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 unsigned char zero = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3584 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
3585 os.write (reinterpret_cast<const char *> (&zero), 1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3586 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3587 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3588 seek (skip, SEEK_CUR);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3589 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3590
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3591 if (os)
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 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
3594 do_float_conversion);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3595
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3596 if (os && status)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3597 count++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3598 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3599 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3600 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3601 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3602 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3603 status = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3604 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3605 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3606 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3607 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3608 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3609 status = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3610 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3611 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3612 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3613
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3614 if (status)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3615 retval = count;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3616
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3617 return retval;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3618 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3619
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3620 template octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3621 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
3622 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3623 octave_idx_type, oct_mach_info::float_format);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3624
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3625 template octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3626 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
3627 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3628 octave_idx_type, oct_mach_info::float_format);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3629
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3630 template octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3631 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
3632 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3633 octave_idx_type, oct_mach_info::float_format);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3634
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3635 template octave_idx_type
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7724
diff changeset
3636 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
3637 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3638 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
3639
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7724
diff changeset
3640 template octave_idx_type
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3641 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
3642 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3643 octave_idx_type, oct_mach_info::float_format);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3644
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3645 template octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3646 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
3647 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3648 octave_idx_type, oct_mach_info::float_format);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3649
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3650 template octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3651 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
3652 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3653 octave_idx_type, oct_mach_info::float_format);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3654
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3655 template octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3656 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
3657 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3658 octave_idx_type, oct_mach_info::float_format);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3659
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3660 template octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3661 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
3662 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3663 octave_idx_type, oct_mach_info::float_format);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3664
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3665 template octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3666 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
3667 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3668 octave_idx_type, oct_mach_info::float_format);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3669
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3670 template octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3671 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
3672 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3673 octave_idx_type, oct_mach_info::float_format);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3674
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3675 template octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5266
diff changeset
3676 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
3677 oct_data_conv::data_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3678 octave_idx_type, oct_mach_info::float_format);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4927
diff changeset
3679
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3680 octave_value
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3779
diff changeset
3681 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
3682 octave_idx_type& count, const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3683 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3684 octave_value retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3685
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3686 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3687 retval = rep->scanf (fmt, size, count, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3688
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3689 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3690 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3691
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3692 octave_value
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3693 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
3694 octave_idx_type& count, const std::string& who)
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3695 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3696 octave_value retval = Matrix ();
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3697
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3698 if (fmt.is_string ())
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3699 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3700 std::string sfmt = fmt.string_value ();
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3701
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3702 if (fmt.is_sq_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3703 sfmt = do_string_escapes (sfmt);
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3704
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3705 retval = scanf (sfmt, size, count, who);
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3706 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3707 else
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3708 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3709 // Note that this is not ::error () !
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3710
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3711 error (who + ": format must be a string");
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3712 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3713
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3714 return retval;
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3715 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3716
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
3717 octave_value_list
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3718 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
3719 {
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
3720 octave_value_list retval;
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
3721
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3722 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3723 retval = rep->oscanf (fmt, who);
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
3724
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
3725 return retval;
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
3726 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2213
diff changeset
3727
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3728 octave_value_list
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3729 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
3730 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3731 octave_value_list retval;
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3732
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3733 if (fmt.is_string ())
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3734 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3735 std::string sfmt = fmt.string_value ();
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3736
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3737 if (fmt.is_sq_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3738 sfmt = do_string_escapes (sfmt);
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3739
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3740 retval = oscanf (sfmt, who);
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3741 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3742 else
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3743 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3744 // Note that this is not ::error () !
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3745
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3746 error (who + ": format must be a string");
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3747 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3748
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3749 return retval;
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3750 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3751
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3752 int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3753 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
3754 const std::string& who)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3755 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3756 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3757
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3758 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3759 retval = rep->printf (fmt, args, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3760
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3761 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3762 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3763
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3764 int
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3765 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
3766 const std::string& who)
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3767 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3768 int retval = 0;
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3769
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3770 if (fmt.is_string ())
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3771 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3772 std::string sfmt = fmt.string_value ();
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3773
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3774 if (fmt.is_sq_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
3775 sfmt = do_string_escapes (sfmt);
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3776
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3777 retval = printf (sfmt, args, who);
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3778 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3779 else
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3780 {
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3781 // Note that this is not ::error () !
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3782
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3783 error (who + ": format must be a string");
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3784 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3785
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3786 return retval;
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3787 }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3788
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3789 int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3790 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
3791 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3792 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3793
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3794 if (stream_ok ())
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3795 retval = rep->puts (s, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3796
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3797 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3798 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3799
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5765
diff changeset
3800 // FIXME -- maybe this should work for string arrays too.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3801
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3802 int
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3803 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
3804 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3805 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3806
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3807 if (tc_s.is_string ())
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3808 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3809 std::string s = tc_s.string_value ();
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
3810 retval = puts (s, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3811 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3812 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3813 {
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3814 // Note that this is not ::error () !
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3815
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3816 error (who + ": argument must be a string");
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4425
diff changeset
3817 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3818
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3819 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3820 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3821
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3822 bool
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3823 octave_stream::eof (void) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3824 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3825 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3826
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3827 if (stream_ok ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3828 retval = rep->eof ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3829
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3830 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3831 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3832
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
3833 std::string
2435
3be97fe02051 [project @ 1996-10-27 21:31:29 by jwe]
jwe
parents: 2341
diff changeset
3834 octave_stream::error (bool clear, int& err_num)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3835 {
5649
d24b97246b9b [project @ 2006-03-08 20:31:25 by jwe]
jwe
parents: 5581
diff changeset
3836 std::string retval = "invalid stream object";
d24b97246b9b [project @ 2006-03-08 20:31:25 by jwe]
jwe
parents: 5581
diff changeset
3837
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3838 if (stream_ok (false))
2435
3be97fe02051 [project @ 1996-10-27 21:31:29 by jwe]
jwe
parents: 2341
diff changeset
3839 retval = rep->error (clear, err_num);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3840
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3841 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3842 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3843
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
3844 std::string
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3845 octave_stream::name (void) const
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3846 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
3847 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3848
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3849 if (stream_ok ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3850 retval = rep->name ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3851
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3852 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3853 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3854
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3855 int
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3856 octave_stream::mode (void) const
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3857 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3858 int retval = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3859
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3860 if (stream_ok ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3861 retval = rep->mode ();
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3862
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3863 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3864 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3865
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 2305
diff changeset
3866 oct_mach_info::float_format
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3867 octave_stream::float_format (void) const
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3868 {
4574
6cb22b9e3942 [project @ 2003-10-31 05:57:43 by jwe]
jwe
parents: 4468
diff changeset
3869 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
3870
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
3871 if (stream_ok ())
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 2305
diff changeset
3872 retval = rep->float_format ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3873
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3874 return retval;
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
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
3877 std::string
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3878 octave_stream::mode_as_string (int mode)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3879 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
3880 std::string retval = "???";
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
3881 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
3882
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
3883 if (in_mode == std::ios::in)
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
3884 retval = "r";
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3885 else if (in_mode == std::ios::out
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
3886 || in_mode == (std::ios::out | std::ios::trunc))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
3887 retval = "w";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
3888 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
3889 retval = "a";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
3890 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
3891 retval = "r+";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
3892 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
3893 retval = "w+";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
3894 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
3895 retval = "a+";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
3896 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
3897 retval = "rb";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
3898 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
3899 || 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
3900 retval = "wb";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
3901 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
3902 retval = "ab";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
3903 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
3904 retval = "r+b";
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3905 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
3906 | std::ios::binary))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
3907 retval = "w+b";
4078
bd51df637cb3 [project @ 2002-09-27 23:23:20 by jwe]
jwe
parents: 4070
diff changeset
3908 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
3909 | std::ios::binary))
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3716
diff changeset
3910 retval = "a+b";
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 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3913 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3914
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3915 octave_stream_list *octave_stream_list::instance = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
3916
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3917 bool
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3918 octave_stream_list::instance_ok (void)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3919 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3920 bool retval = true;
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3921
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3922 if (! instance)
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
3923 {
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
3924 instance = new octave_stream_list ();
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
3925
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
3926 if (instance)
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
3927 singleton_cleanup_list::add (cleanup_instance);
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 13271
diff changeset
3928 }
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3929
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3930 if (! instance)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3931 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3932 ::error ("unable to create stream list object!");
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3933
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3934 retval = false;
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3935 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3936
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3937 return retval;
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3938 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3939
5353
df230b7df93c [project @ 2005-05-18 02:18:24 by jwe]
jwe
parents: 5338
diff changeset
3940 int
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
3941 octave_stream_list::insert (octave_stream& os)
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3942 {
5353
df230b7df93c [project @ 2005-05-18 02:18:24 by jwe]
jwe
parents: 5338
diff changeset
3943 return (instance_ok ()) ? instance->do_insert (os) : -1;
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3944 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3945
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3946 octave_stream
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
3947 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
3948 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
3949 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
3950 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3951
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
3952 octave_stream
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
3953 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
3954 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
3955 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
3956 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3957
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3958 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
3959 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
3960 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
3961 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
3962 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3963
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3964 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
3965 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
3966 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
3967 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
3968 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3969
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3970 void
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
3971 octave_stream_list::clear (bool flush)
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3972 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3973 if (instance)
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
3974 instance->do_clear (flush);
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3975 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3976
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3977 string_vector
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3978 octave_stream_list::get_info (int fid)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3979 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3980 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
3981 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3982
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3983 string_vector
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3984 octave_stream_list::get_info (const octave_value& fid)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3985 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3986 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
3987 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3988
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
3989 std::string
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3990 octave_stream_list::list_open_files (void)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3991 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
3992 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
3993 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3994
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3995 octave_value
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3996 octave_stream_list::open_file_numbers (void)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3997 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3998 return (instance_ok ())
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
3999 ? instance->do_open_file_numbers () : octave_value ();
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4000 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4001
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4002 int
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4003 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
4004 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4005 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
4006 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
4007
5353
df230b7df93c [project @ 2005-05-18 02:18:24 by jwe]
jwe
parents: 5338
diff changeset
4008 int
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4009 octave_stream_list::do_insert (octave_stream& os)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4010 {
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4011 // Insert item with key corresponding to file-descriptor.
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4012
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4013 int stream_number;
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4014
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4015 if ((stream_number = os.file_number ()) == -1)
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4016 return stream_number;
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4017
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4018 // 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
4019 // list[stream_number].is_open ()" and respond with "error
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4020 // ("internal error: ...")"? It should not happen except for some
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4021 // 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
4022 // 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
4023 // 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
4024 // 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
4025 // 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
4026 // harm before.
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4027
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4028 if (list.size () < list.max_size ())
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4029 list[stream_number] = os;
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4030 else
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4031 {
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4032 stream_number = -1;
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4033 error ("could not create file id");
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4034 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4035
5353
df230b7df93c [project @ 2005-05-18 02:18:24 by jwe]
jwe
parents: 5338
diff changeset
4036 return stream_number;
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4037
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4038 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4039
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4040 static void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4041 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
4042 {
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4043 if (who.empty ())
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4044 ::error ("invalid stream number = %d", fid);
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4045 else
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4046 ::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
4047 }
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4048
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4049 octave_stream
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4050 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
4051 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4052 octave_stream retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4053
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4054 if (fid >= 0)
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4055 {
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4056 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
4057 retval = lookup_cache->second;
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4058 else
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4059 {
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4060 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
4061
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4062 if (iter != list.end ())
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4063 {
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4064 retval = iter->second;
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4065 lookup_cache = iter;
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4066 }
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4067 else
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4068 gripe_invalid_file_id (fid, who);
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4069 }
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4070 }
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4071 else
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4072 gripe_invalid_file_id (fid, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4073
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4074 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4075 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4076
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4077 octave_stream
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4078 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
4079 const std::string& who) const
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4080 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4081 octave_stream retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4082
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4083 int i = get_file_number (fid);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4084
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4085 if (! error_state)
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4086 retval = do_lookup (i, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4087
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4088 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4089 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4090
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4091 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4092 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
4093 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4094 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4095
3531
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
4096 // 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
4097 // (std::cerr).
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4098
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4099 if (fid > 2)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4100 {
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4101 ostrl_map::iterator iter = list.find (fid);
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4102
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4103 if (iter != list.end ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4104 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4105 octave_stream os = iter->second;
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4106 list.erase (iter);
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4107 lookup_cache = list.end ();
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4108
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4109 // FIXME: is this check redundant?
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4110 if (os.is_valid ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4111 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4112 os.close ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4113 retval = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4114 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4115 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4116 gripe_invalid_file_id (fid, who);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4117 }
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4118 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4119 gripe_invalid_file_id (fid, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4120 }
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4121 else
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4122 gripe_invalid_file_id (fid, who);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4123
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4124 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4125 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4126
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4127 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4128 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
4129 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4130 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4131
6054
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4132 if (fid.is_string () && fid.string_value () == "all")
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4133 {
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4134 do_clear (false);
6054
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4135
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4136 retval = 0;
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4137 }
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4138 else
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4139 {
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4140 int i = get_file_number (fid);
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4141
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4142 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4143 retval = do_remove (i, who);
6054
769b203ede37 [project @ 2006-10-16 17:53:53 by jwe]
jwe
parents: 5887
diff changeset
4144 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4145
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4146 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4147 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4148
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4149 void
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4150 octave_stream_list::do_clear (bool flush)
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4151 {
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4152 if (flush)
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4153 {
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4154 // Do flush stdout and stderr.
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4155
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4156 list[0].flush ();
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4157 list[1].flush ();
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4158 }
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4159
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4160 octave_stream saved_os[3];
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4161 // 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
4162 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
4163 {
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4164 int fid = iter->first;
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4165 octave_stream os = iter->second;
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4166 if (fid < 3)
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4167 saved_os[fid] = os;
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4168 else if (os.is_valid ())
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4169 os.close ();
6757
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 list.clear ();
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8773
diff changeset
4172 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
4173 lookup_cache = list.end ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4174 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4175
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4176 string_vector
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4177 octave_stream_list::do_get_info (int fid) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4178 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4179 string_vector retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4180
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4181 octave_stream os = do_lookup (fid);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4182
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4183 if (os.is_valid ())
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4184 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4185 retval.resize (3);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4186
14022
de90542b7afc Return retval(1) before retval(0) to avoid re-sizing call on retval.
Rik <octave@nomad.inbox5.com>
parents: 13983
diff changeset
4187 retval(2) = oct_mach_info::float_format_as_string (os.float_format ());
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3337
diff changeset
4188 retval(1) = octave_stream::mode_as_string (os.mode ());
14022
de90542b7afc Return retval(1) before retval(0) to avoid re-sizing call on retval.
Rik <octave@nomad.inbox5.com>
parents: 13983
diff changeset
4189 retval(0) = os.name ();
2117
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 else
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
4192 ::error ("invalid file id = %d", fid);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4193
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4194 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4195 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4196
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4197 string_vector
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4198 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
4199 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4200 string_vector retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4201
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4202 int conv_err = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4203
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4204 int int_fid = convert_to_valid_int (fid, conv_err);
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 if (! conv_err)
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4207 retval = do_get_info (int_fid);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4208 else
2915
649549662cf6 [project @ 1997-04-30 20:51:40 by jwe]
jwe
parents: 2902
diff changeset
4209 ::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
4210
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4211 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4212 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4213
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3535
diff changeset
4214 std::string
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4215 octave_stream_list::do_list_open_files (void) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4216 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4217 std::string retval;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4218
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
4219 std::ostringstream buf;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4220
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4221 buf << "\n"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4222 << " number mode arch name\n"
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4223 << " ------ ---- ---- ----\n";
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4224
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4225 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
4226 {
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4227 octave_stream os = p->second;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4228
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4312
diff changeset
4229 buf << " "
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4230 << std::setiosflags (std::ios::right)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4231 << std::setw (4) << p->first << " "
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4232 << std::setiosflags (std::ios::left)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4233 << std::setw (3)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4234 << octave_stream::mode_as_string (os.mode ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4235 << " "
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4236 << std::setw (9)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4237 << 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
4238 << " "
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4239 << os.name () << "\n";
2117
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
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
4242 buf << "\n";
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
4243
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
4244 retval = buf.str ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4245
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4246 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4247 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4248
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4249 octave_value
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4250 octave_stream_list::do_open_file_numbers (void) const
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4251 {
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4252 Matrix retval (1, list.size (), 0.0);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4253
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4254 int num_open = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4255
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4256 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
4257 {
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4258 // Skip stdin, stdout, and stderr.
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4259
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4260 if (p->first > 2 && p->second)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4261 retval(0,num_open++) = p->first;
2117
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 retval.resize ((num_open > 0), num_open);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4265
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4266 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4267 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4268
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4269 int
2609
12bc9d0a50b5 [project @ 1997-01-18 00:17:36 by jwe]
jwe
parents: 2601
diff changeset
4270 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
4271 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4272 int retval = -1;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4273
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4274 if (fid.is_string ())
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4275 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
4276 std::string nm = fid.string_value ();
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4277
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6708
diff changeset
4278 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
4279 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4280 // 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
4281 // are unnamed.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4282
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4283 if (p->first > 2)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4284 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4285 octave_stream os = p->second;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4286
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4287 if (os && os.name () == nm)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4288 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4289 retval = p->first;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4290 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4291 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4292 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4293 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4294 }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4295 else
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4296 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4297 int conv_err = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4298
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4299 int int_fid = convert_to_valid_int (fid, conv_err);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4300
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4301 if (conv_err)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4302 ::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
4303 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
4304 retval = int_fid;
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
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4307 return retval;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4308 }