Mercurial > hg > octave-nkf
annotate src/c-file-ptr-stream.cc @ 15536:2e8eb9ac43a5 stable rc-3-6-4-0
3.6.4-rc0 release candidate
* configure.ac (AC_INIT): Version is now 3.6.2-rc0.
(OCTAVE_RELEASE_DATE): Now 2012-05-11.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 17 Oct 2012 10:05:44 -0400 |
parents | 72c96de7a403 |
children |
rev | line source |
---|---|
3628 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12941
diff
changeset
|
3 Copyright (C) 2000-2012 John W. Eaton |
3628 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
3628 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
3628 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
27 #include <iostream> |
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
28 |
3629 | 29 #include "c-file-ptr-stream.h" |
3628 | 30 |
31 #ifndef SEEK_SET | |
32 #define SEEK_SET 0 | |
33 #endif | |
34 | |
35 #ifndef SEEK_CUR | |
36 #define SEEK_CUR 1 | |
37 #endif | |
38 | |
39 #ifndef SEEK_END | |
40 #define SEEK_END 2 | |
41 #endif | |
42 | |
3642 | 43 c_file_ptr_buf::~c_file_ptr_buf (void) |
44 { | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
45 buf_close (); |
3642 | 46 } |
3628 | 47 |
5775 | 48 // FIXME -- I'm sure there is room for improvement here... |
3628 | 49 |
3775 | 50 c_file_ptr_buf::int_type |
51 c_file_ptr_buf::overflow (int_type c) | |
3628 | 52 { |
3775 | 53 #if defined (CXX_ISO_COMPLIANT_LIBRARY) |
54 if (f) | |
10411 | 55 return (c != traits_type::eof ()) ? gnulib::fputc (c, f) : flush (); |
3775 | 56 else |
57 return traits_type::not_eof (c); | |
58 #else | |
3644 | 59 if (f) |
10411 | 60 return (c != EOF) ? gnulib::fputc (c, f) : flush (); |
3644 | 61 else |
62 return EOF; | |
3775 | 63 #endif |
3628 | 64 } |
65 | |
3775 | 66 c_file_ptr_buf::int_type |
4310 | 67 c_file_ptr_buf::underflow_common (bool bump) |
3628 | 68 { |
3644 | 69 if (f) |
4310 | 70 { |
12912
e116dd862879
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
71 int_type c = gnulib::fgetc (f); |
4310 | 72 |
73 if (! bump | |
74 #if defined (CXX_ISO_COMPLIANT_LIBRARY) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
75 && c != traits_type::eof ()) |
4310 | 76 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
77 && c != EOF) |
4310 | 78 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
79 ungetc (c, f); |
4310 | 80 |
81 return c; | |
82 } | |
3644 | 83 else |
3775 | 84 #if defined (CXX_ISO_COMPLIANT_LIBRARY) |
85 return traits_type::eof (); | |
86 #else | |
3644 | 87 return EOF; |
3775 | 88 #endif |
3628 | 89 } |
90 | |
3775 | 91 c_file_ptr_buf::int_type |
92 c_file_ptr_buf::pbackfail (int_type c) | |
3628 | 93 { |
3775 | 94 #if defined (CXX_ISO_COMPLIANT_LIBRARY) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
95 return (c != traits_type::eof () && f) ? ungetc (c, f) : |
3775 | 96 traits_type::not_eof (c); |
97 #else | |
3644 | 98 return (c != EOF && f) ? ungetc (c, f) : EOF; |
3775 | 99 #endif |
3628 | 100 } |
101 | |
102 std::streamsize | |
103 c_file_ptr_buf::xsputn (const char* s, std::streamsize n) | |
104 { | |
3644 | 105 if (f) |
10411 | 106 return gnulib::fwrite (s, 1, n, f); |
3644 | 107 else |
108 return 0; | |
3628 | 109 } |
110 | |
111 std::streamsize | |
112 c_file_ptr_buf::xsgetn (char *s, std::streamsize n) | |
113 { | |
3644 | 114 if (f) |
12912
e116dd862879
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
115 return gnulib::fread (s, 1, n, f); |
3644 | 116 else |
117 return 0; | |
3628 | 118 } |
119 | |
120 static inline int | |
121 seekdir_to_whence (std::ios::seekdir dir) | |
122 { | |
123 return ((dir == std::ios::beg) ? SEEK_SET : | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
124 (dir == std::ios::cur) ? SEEK_CUR : |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
125 (dir == std::ios::end) ? SEEK_END : |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
126 dir); |
3628 | 127 } |
128 | |
129 std::streampos | |
8802
061780d8da1e
c-file-ptr-stream.cc: avoid unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
130 c_file_ptr_buf::seekoff (std::streamoff /* offset */, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
131 std::ios::seekdir /* dir */, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
132 std::ios::openmode) |
3628 | 133 { |
5775 | 134 // FIXME |
4643 | 135 #if 0 |
3644 | 136 if (f) |
137 { | |
138 fseek (f, offset, seekdir_to_whence (dir)); | |
3628 | 139 |
3644 | 140 return ftell (f); |
141 } | |
142 else | |
143 return 0; | |
4643 | 144 #endif |
145 return -1; | |
3628 | 146 } |
147 | |
148 std::streampos | |
8802
061780d8da1e
c-file-ptr-stream.cc: avoid unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
149 c_file_ptr_buf::seekpos (std::streampos /* offset */, std::ios::openmode) |
3628 | 150 { |
5775 | 151 // FIXME |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
152 #if 0 |
3644 | 153 if (f) |
154 { | |
155 fseek (f, offset, SEEK_SET); | |
3628 | 156 |
3644 | 157 return ftell (f); |
158 } | |
159 else | |
160 return 0; | |
4643 | 161 #endif |
162 return -1; | |
3628 | 163 } |
164 | |
165 int | |
166 c_file_ptr_buf::sync (void) | |
167 { | |
3652 | 168 flush (); |
169 | |
3628 | 170 return 0; |
171 } | |
172 | |
3652 | 173 int |
174 c_file_ptr_buf::flush (void) | |
175 { | |
12912
e116dd862879
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
176 return f ? gnulib::fflush (f) : EOF; |
3652 | 177 } |
178 | |
179 int | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
180 c_file_ptr_buf::buf_close (void) |
3652 | 181 { |
3693 | 182 int retval = -1; |
183 | |
3716 | 184 flush (); |
185 | |
3652 | 186 if (f) |
3693 | 187 { |
3716 | 188 retval = cf (f); |
3693 | 189 f = 0; |
190 } | |
191 | |
192 return retval; | |
3652 | 193 } |
194 | |
10411 | 195 int |
12927
f9c1f7c1ead0
maint: undo part of previous gnulib changes
John W. Eaton <jwe@octave.org>
parents:
12912
diff
changeset
|
196 c_file_ptr_buf::seek (long offset, int origin) |
f9c1f7c1ead0
maint: undo part of previous gnulib changes
John W. Eaton <jwe@octave.org>
parents:
12912
diff
changeset
|
197 { |
12941
9a498efac5f1
use gnulib::fseek and gnulib::fopen
John W. Eaton <jwe@octave.org>
parents:
12927
diff
changeset
|
198 return f ? gnulib::fseek (f, offset, origin) : -1; |
12927
f9c1f7c1ead0
maint: undo part of previous gnulib changes
John W. Eaton <jwe@octave.org>
parents:
12912
diff
changeset
|
199 } |
f9c1f7c1ead0
maint: undo part of previous gnulib changes
John W. Eaton <jwe@octave.org>
parents:
12912
diff
changeset
|
200 |
f9c1f7c1ead0
maint: undo part of previous gnulib changes
John W. Eaton <jwe@octave.org>
parents:
12912
diff
changeset
|
201 long |
f9c1f7c1ead0
maint: undo part of previous gnulib changes
John W. Eaton <jwe@octave.org>
parents:
12912
diff
changeset
|
202 c_file_ptr_buf::tell (void) |
f9c1f7c1ead0
maint: undo part of previous gnulib changes
John W. Eaton <jwe@octave.org>
parents:
12912
diff
changeset
|
203 { |
f9c1f7c1ead0
maint: undo part of previous gnulib changes
John W. Eaton <jwe@octave.org>
parents:
12912
diff
changeset
|
204 return f ? gnulib::ftell (f) : -1; |
f9c1f7c1ead0
maint: undo part of previous gnulib changes
John W. Eaton <jwe@octave.org>
parents:
12912
diff
changeset
|
205 } |
f9c1f7c1ead0
maint: undo part of previous gnulib changes
John W. Eaton <jwe@octave.org>
parents:
12912
diff
changeset
|
206 |
f9c1f7c1ead0
maint: undo part of previous gnulib changes
John W. Eaton <jwe@octave.org>
parents:
12912
diff
changeset
|
207 int |
10411 | 208 c_file_ptr_buf::file_close (FILE *f) |
209 { | |
210 return gnulib::fclose (f); | |
211 } | |
212 | |
5325 | 213 #ifdef HAVE_ZLIB |
214 | |
215 c_zfile_ptr_buf::~c_zfile_ptr_buf (void) | |
216 { | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
217 buf_close (); |
5325 | 218 } |
219 | |
5775 | 220 // FIXME -- I'm sure there is room for improvement here... |
5325 | 221 |
222 c_zfile_ptr_buf::int_type | |
223 c_zfile_ptr_buf::overflow (int_type c) | |
224 { | |
225 #if defined (CXX_ISO_COMPLIANT_LIBRARY) | |
226 if (f) | |
227 return (c != traits_type::eof ()) ? gzputc (f, c) : flush (); | |
228 else | |
229 return traits_type::not_eof (c); | |
230 #else | |
231 if (f) | |
232 return (c != EOF) ? gzputc (f, c) : flush (); | |
233 else | |
234 return EOF; | |
235 #endif | |
236 } | |
237 | |
238 c_zfile_ptr_buf::int_type | |
239 c_zfile_ptr_buf::underflow_common (bool bump) | |
240 { | |
241 if (f) | |
242 { | |
243 int_type c = gzgetc (f); | |
244 | |
245 if (! bump | |
246 #if defined (CXX_ISO_COMPLIANT_LIBRARY) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
247 && c != traits_type::eof ()) |
5325 | 248 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
249 && c != EOF) |
5325 | 250 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
251 gzungetc (c, f); |
5325 | 252 |
253 return c; | |
254 } | |
255 else | |
256 #if defined (CXX_ISO_COMPLIANT_LIBRARY) | |
257 return traits_type::eof (); | |
258 #else | |
259 return EOF; | |
260 #endif | |
261 } | |
262 | |
263 c_zfile_ptr_buf::int_type | |
264 c_zfile_ptr_buf::pbackfail (int_type c) | |
265 { | |
266 #if defined (CXX_ISO_COMPLIANT_LIBRARY) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
267 return (c != traits_type::eof () && f) ? gzungetc (c, f) : |
5325 | 268 traits_type::not_eof (c); |
269 #else | |
270 return (c != EOF && f) ? gzungetc (c, f) : EOF; | |
271 #endif | |
272 } | |
273 | |
274 std::streamsize | |
275 c_zfile_ptr_buf::xsputn (const char* s, std::streamsize n) | |
276 { | |
277 if (f) | |
278 return gzwrite (f, s, n); | |
279 else | |
280 return 0; | |
281 } | |
282 | |
283 std::streamsize | |
284 c_zfile_ptr_buf::xsgetn (char *s, std::streamsize n) | |
285 { | |
286 if (f) | |
287 return gzread (f, s, n); | |
288 else | |
289 return 0; | |
290 } | |
291 | |
292 std::streampos | |
8802
061780d8da1e
c-file-ptr-stream.cc: avoid unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
293 c_zfile_ptr_buf::seekoff (std::streamoff /* offset */, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
294 std::ios::seekdir /* dir */, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
295 std::ios::openmode) |
5325 | 296 { |
5775 | 297 // FIXME |
5325 | 298 #if 0 |
299 if (f) | |
300 { | |
301 gzseek (f, offset, seekdir_to_whence (dir)); | |
302 | |
303 return gztell (f); | |
304 } | |
305 else | |
306 return 0; | |
307 #endif | |
308 return -1; | |
309 } | |
310 | |
311 std::streampos | |
8802
061780d8da1e
c-file-ptr-stream.cc: avoid unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
312 c_zfile_ptr_buf::seekpos (std::streampos /* offset */, std::ios::openmode) |
5325 | 313 { |
5775 | 314 // FIXME |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
315 #if 0 |
5325 | 316 if (f) |
317 { | |
318 gzseek (f, offset, SEEK_SET); | |
319 | |
320 return gztell (f); | |
321 } | |
322 else | |
323 return 0; | |
324 #endif | |
325 return -1; | |
326 } | |
327 | |
328 int | |
329 c_zfile_ptr_buf::sync (void) | |
330 { | |
331 flush (); | |
332 | |
333 return 0; | |
334 } | |
335 | |
336 int | |
337 c_zfile_ptr_buf::flush (void) | |
338 { | |
5775 | 339 // FIXME -- do we need something more complex here, passing |
5325 | 340 // something other than 0 for the second argument to gzflush and |
341 // checking the return value, etc.? | |
342 | |
343 return f ? gzflush (f, 0) : EOF; | |
344 } | |
345 | |
346 int | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
347 c_zfile_ptr_buf::buf_close (void) |
5325 | 348 { |
349 int retval = -1; | |
350 | |
351 flush (); | |
352 | |
353 if (f) | |
354 { | |
355 retval = cf (f); | |
356 f = 0; | |
357 } | |
358 | |
359 return retval; | |
360 } | |
361 | |
362 #endif |