Mercurial > hg > octave-thorsten
annotate src/c-file-ptr-stream.cc @ 11586:12df7854fa7c
strip trailing whitespace from source files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 20 Jan 2011 17:24:59 -0500 |
parents | fd0a3ac60b0e |
children | e116dd862879 |
rev | line source |
---|---|
3628 | 1 /* |
2 | |
11523 | 3 Copyright (C) 2000-2011 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 { |
71 int_type c = fgetc (f); | |
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) |
115 return fread (s, 1, n, f); | |
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 { | |
176 return f ? fflush (f) : EOF; | |
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 |
196 c_file_ptr_buf::file_close (FILE *f) | |
197 { | |
198 return gnulib::fclose (f); | |
199 } | |
200 | |
5325 | 201 #ifdef HAVE_ZLIB |
202 | |
203 c_zfile_ptr_buf::~c_zfile_ptr_buf (void) | |
204 { | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
205 buf_close (); |
5325 | 206 } |
207 | |
5775 | 208 // FIXME -- I'm sure there is room for improvement here... |
5325 | 209 |
210 c_zfile_ptr_buf::int_type | |
211 c_zfile_ptr_buf::overflow (int_type c) | |
212 { | |
213 #if defined (CXX_ISO_COMPLIANT_LIBRARY) | |
214 if (f) | |
215 return (c != traits_type::eof ()) ? gzputc (f, c) : flush (); | |
216 else | |
217 return traits_type::not_eof (c); | |
218 #else | |
219 if (f) | |
220 return (c != EOF) ? gzputc (f, c) : flush (); | |
221 else | |
222 return EOF; | |
223 #endif | |
224 } | |
225 | |
226 c_zfile_ptr_buf::int_type | |
227 c_zfile_ptr_buf::underflow_common (bool bump) | |
228 { | |
229 if (f) | |
230 { | |
231 int_type c = gzgetc (f); | |
232 | |
233 if (! bump | |
234 #if defined (CXX_ISO_COMPLIANT_LIBRARY) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
235 && c != traits_type::eof ()) |
5325 | 236 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
237 && c != EOF) |
5325 | 238 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
239 gzungetc (c, f); |
5325 | 240 |
241 return c; | |
242 } | |
243 else | |
244 #if defined (CXX_ISO_COMPLIANT_LIBRARY) | |
245 return traits_type::eof (); | |
246 #else | |
247 return EOF; | |
248 #endif | |
249 } | |
250 | |
251 c_zfile_ptr_buf::int_type | |
252 c_zfile_ptr_buf::pbackfail (int_type c) | |
253 { | |
254 #if defined (CXX_ISO_COMPLIANT_LIBRARY) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
255 return (c != traits_type::eof () && f) ? gzungetc (c, f) : |
5325 | 256 traits_type::not_eof (c); |
257 #else | |
258 return (c != EOF && f) ? gzungetc (c, f) : EOF; | |
259 #endif | |
260 } | |
261 | |
262 std::streamsize | |
263 c_zfile_ptr_buf::xsputn (const char* s, std::streamsize n) | |
264 { | |
265 if (f) | |
266 return gzwrite (f, s, n); | |
267 else | |
268 return 0; | |
269 } | |
270 | |
271 std::streamsize | |
272 c_zfile_ptr_buf::xsgetn (char *s, std::streamsize n) | |
273 { | |
274 if (f) | |
275 return gzread (f, s, n); | |
276 else | |
277 return 0; | |
278 } | |
279 | |
280 std::streampos | |
8802
061780d8da1e
c-file-ptr-stream.cc: avoid unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
281 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
|
282 std::ios::seekdir /* dir */, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
283 std::ios::openmode) |
5325 | 284 { |
5775 | 285 // FIXME |
5325 | 286 #if 0 |
287 if (f) | |
288 { | |
289 gzseek (f, offset, seekdir_to_whence (dir)); | |
290 | |
291 return gztell (f); | |
292 } | |
293 else | |
294 return 0; | |
295 #endif | |
296 return -1; | |
297 } | |
298 | |
299 std::streampos | |
8802
061780d8da1e
c-file-ptr-stream.cc: avoid unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
300 c_zfile_ptr_buf::seekpos (std::streampos /* offset */, std::ios::openmode) |
5325 | 301 { |
5775 | 302 // FIXME |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
303 #if 0 |
5325 | 304 if (f) |
305 { | |
306 gzseek (f, offset, SEEK_SET); | |
307 | |
308 return gztell (f); | |
309 } | |
310 else | |
311 return 0; | |
312 #endif | |
313 return -1; | |
314 } | |
315 | |
316 int | |
317 c_zfile_ptr_buf::sync (void) | |
318 { | |
319 flush (); | |
320 | |
321 return 0; | |
322 } | |
323 | |
324 int | |
325 c_zfile_ptr_buf::flush (void) | |
326 { | |
5775 | 327 // FIXME -- do we need something more complex here, passing |
5325 | 328 // something other than 0 for the second argument to gzflush and |
329 // checking the return value, etc.? | |
330 | |
331 return f ? gzflush (f, 0) : EOF; | |
332 } | |
333 | |
334 int | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
335 c_zfile_ptr_buf::buf_close (void) |
5325 | 336 { |
337 int retval = -1; | |
338 | |
339 flush (); | |
340 | |
341 if (f) | |
342 { | |
343 retval = cf (f); | |
344 f = 0; | |
345 } | |
346 | |
347 return retval; | |
348 } | |
349 | |
350 #endif |