annotate src/oct-fstrm.cc @ 3775:13905c3a24af

[project @ 2001-02-06 01:56:59 by jwe]
author jwe
date Tue, 06 Feb 2001 01:57:06 +0000
parents 25e84fcef38a
children 7b957b442818
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2081
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
1 /*
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
2
2847
8b262e771614 [project @ 1997-03-27 16:18:26 by jwe]
jwe
parents: 2800
diff changeset
3 Copyright (C) 1996, 1997 John W. Eaton
2081
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
4
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
6
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
10 later version.
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
11
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
15 for more details.
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
16
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, write to the Free
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
20
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
21 */
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
22
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
25 #endif
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
26
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
27 #include <cerrno>
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
28 #include <cstring>
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
29
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
30 #include "error.h"
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
31 #include "oct-fstrm.h"
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
32
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 2847
diff changeset
33 octave_stream
3570
f74d9dfec96f [project @ 2000-02-03 11:27:10 by jwe]
jwe
parents: 3560
diff changeset
34 octave_fstream::create (const std::string& nm_arg, std::ios::openmode arg_md,
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 2847
diff changeset
35 oct_mach_info::float_format flt_fmt)
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 2847
diff changeset
36 {
3570
f74d9dfec96f [project @ 2000-02-03 11:27:10 by jwe]
jwe
parents: 3560
diff changeset
37 return octave_stream (new octave_fstream (nm_arg, arg_md, flt_fmt));
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 2847
diff changeset
38 }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 2847
diff changeset
39
3552
41daa489833a [project @ 2000-02-03 03:05:28 by jwe]
jwe
parents: 3546
diff changeset
40 octave_fstream::octave_fstream (const std::string& nm_arg,
3570
f74d9dfec96f [project @ 2000-02-03 11:27:10 by jwe]
jwe
parents: 3560
diff changeset
41 std::ios::openmode arg_md,
3552
41daa489833a [project @ 2000-02-03 03:05:28 by jwe]
jwe
parents: 3546
diff changeset
42 oct_mach_info::float_format flt_fmt)
3570
f74d9dfec96f [project @ 2000-02-03 11:27:10 by jwe]
jwe
parents: 3560
diff changeset
43 : octave_base_stream (arg_md, flt_fmt), nm (nm_arg)
2081
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
44 {
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3652
diff changeset
45
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3652
diff changeset
46 #if CXX_ISO_COMPLIANT_LIBRARY
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3652
diff changeset
47
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3652
diff changeset
48 fs.open (nm.c_str (), arg_md);
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3652
diff changeset
49
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3652
diff changeset
50 #else
2081
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
51 // Override default protection of 0664 so that umask will appear to
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
52 // do the right thing.
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
53
3570
f74d9dfec96f [project @ 2000-02-03 11:27:10 by jwe]
jwe
parents: 3560
diff changeset
54 fs.open (nm.c_str (), arg_md, 0666);
2081
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
55
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3652
diff changeset
56 #endif
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3652
diff changeset
57
2081
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
58 if (! fs)
3531
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
59 {
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
60 using namespace std;
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
61
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
62 error (strerror (errno));
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
63 }
2081
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
64 }
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
65
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
66 // Position a stream at OFFSET relative to ORIGIN.
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
67
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
68 int
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3652
diff changeset
69 octave_fstream::seek (std::streamoff offset, std::ios::seekdir origin)
2081
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
70 {
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
71 int retval = -1;
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
72
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
73 if (! fs.bad ())
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
74 {
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
75 fs.clear ();
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
76
3560
e3e8cfe73935 [project @ 2000-02-03 05:28:16 by jwe]
jwe
parents: 3552
diff changeset
77 std::filebuf *fb = fs.rdbuf ();
2081
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
78
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
79 if (fb)
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
80 {
3570
f74d9dfec96f [project @ 2000-02-03 11:27:10 by jwe]
jwe
parents: 3560
diff changeset
81 fb->pubseekoff (offset, origin);
2081
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
82 retval = fs.bad () ? -1 : 0;
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
83 }
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
84 }
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
85
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
86 return retval;
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
87 }
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
88
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
89 // Return current stream position.
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
90
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
91 long
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
92 octave_fstream::tell (void) const
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
93 {
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
94 long retval = -1;
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
95
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
96 if (fs)
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
97 {
3560
e3e8cfe73935 [project @ 2000-02-03 05:28:16 by jwe]
jwe
parents: 3552
diff changeset
98 std::filebuf *fb = fs.rdbuf ();
3570
f74d9dfec96f [project @ 2000-02-03 11:27:10 by jwe]
jwe
parents: 3560
diff changeset
99 retval = static_cast<long> (fb->pubseekoff (0, std::ios::cur));
2081
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
100 }
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
101
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
102 return retval;
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
103 }
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
104
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
105 // Return non-zero if EOF has been reached on this stream.
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
106
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
107 bool
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
108 octave_fstream::eof (void) const
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
109 {
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
110 return fs.eof ();
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
111 }
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
112
3652
25e84fcef38a [project @ 2000-03-31 08:50:48 by jwe]
jwe
parents: 3570
diff changeset
113 void
25e84fcef38a [project @ 2000-03-31 08:50:48 by jwe]
jwe
parents: 3570
diff changeset
114 octave_fstream::do_close (void)
25e84fcef38a [project @ 2000-03-31 08:50:48 by jwe]
jwe
parents: 3570
diff changeset
115 {
25e84fcef38a [project @ 2000-03-31 08:50:48 by jwe]
jwe
parents: 3570
diff changeset
116 fs.close ();
25e84fcef38a [project @ 2000-03-31 08:50:48 by jwe]
jwe
parents: 3570
diff changeset
117 }
25e84fcef38a [project @ 2000-03-31 08:50:48 by jwe]
jwe
parents: 3570
diff changeset
118
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3340
diff changeset
119 std::istream *
2081
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
120 octave_fstream::input_stream (void)
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
121 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3340
diff changeset
122 std::istream *retval = 0;
2081
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
123
3544
71bd2d124119 [project @ 2000-02-02 21:02:31 by jwe]
jwe
parents: 3531
diff changeset
124 if (mode () & std::ios::in)
2081
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
125 retval = &fs;
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
126
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
127 return retval;
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
128 }
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
129
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3340
diff changeset
130 std::ostream *
2081
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
131 octave_fstream::output_stream (void)
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
132 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3340
diff changeset
133 std::ostream *retval = 0;
2081
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
134
3544
71bd2d124119 [project @ 2000-02-02 21:02:31 by jwe]
jwe
parents: 3531
diff changeset
135 if (mode () & std::ios::out)
2081
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
136 retval = &fs;
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
137
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
138 return retval;
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
139 }
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
140
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
141 /*
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
142 ;;; Local Variables: ***
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
143 ;;; mode: C++ ***
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
144 ;;; End: ***
e9ec222a53e1 [project @ 1996-04-25 03:17:36 by jwe]
jwe
parents:
diff changeset
145 */