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