annotate src/c-file-ptr-stream.cc @ 3629:34458e90c576

[project @ 2000-03-23 07:35:32 by jwe]
author jwe
date Thu, 23 Mar 2000 07:37:34 +0000
parents 168c4d71dc63
children 3843aa0767c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3628
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
1 /*
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
2
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
3 Copyright (C) 2000 John W. Eaton
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
4
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
6
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
10 later version.
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
11
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
15 for more details.
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
16
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, write to the Free
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
20
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
21 */
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
22
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
23 #if defined (__GNUG__)
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
24 #pragma implementation
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
25 #endif
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
26
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
27 #ifdef HAVE_CONFIG_H
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
28 #include <config.h>
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
29 #endif
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
30
3629
34458e90c576 [project @ 2000-03-23 07:35:32 by jwe]
jwe
parents: 3628
diff changeset
31 #include "c-file-ptr-stream.h"
3628
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
32
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
33 #ifndef SEEK_SET
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
34 #define SEEK_SET 0
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
35 #endif
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
36
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
37 #ifndef SEEK_CUR
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
38 #define SEEK_CUR 1
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
39 #endif
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
40
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
41 #ifndef SEEK_END
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
42 #define SEEK_END 2
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
43 #endif
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
44
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
45 c_file_ptr_buf::~c_file_ptr_buf (void) { fflush (f); }
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
46
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
47 // XXX FIXME XXX -- I'm sure there is room for improvement here...
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
48
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
49 int
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
50 c_file_ptr_buf::overflow (int c)
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
51 {
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
52 return (c != EOF) ? fputc (c, f) : fflush (f);
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
53 }
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
54
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
55 int
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
56 c_file_ptr_buf::underflow (void)
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
57 {
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
58 return fgetc (f);
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
59 }
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
60
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
61 int
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
62 c_file_ptr_buf::uflow (void)
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
63 {
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
64 return underflow ();
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
65 }
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
66
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
67 int
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
68 c_file_ptr_buf::pbackfail (int c)
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
69 {
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
70 return (c != EOF) ? ungetc (c, f) : EOF;
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
71 }
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
72
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
73 std::streamsize
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
74 c_file_ptr_buf::xsputn (const char* s, std::streamsize n)
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
75 {
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
76 return fwrite (s, 1, n, f);
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
77 }
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
78
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
79 std::streamsize
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
80 c_file_ptr_buf::xsgetn (char *s, std::streamsize n)
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
81 {
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
82 return fread (s, 1, n, f);
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
83 }
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
84
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
85 static inline int
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
86 seekdir_to_whence (std::ios::seekdir dir)
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
87 {
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
88 return ((dir == std::ios::beg) ? SEEK_SET :
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
89 (dir == std::ios::cur) ? SEEK_CUR :
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
90 (dir == std::ios::end) ? SEEK_END :
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
91 dir);
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
92 }
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
93
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
94 std::streampos
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
95 c_file_ptr_buf::seekoff (std::streamoff offset, std::ios::seekdir dir,
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
96 std::ios::openmode)
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
97 {
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
98 // XXX FIXME XXX -- is this the right thing to do?
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
99
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
100 fseek (f, offset, seekdir_to_whence (dir));
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
101
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
102 return ftell (f);
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
103 }
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
104
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
105 std::streampos
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
106 c_file_ptr_buf::seekpos (std::streampos offset, std::ios::openmode)
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
107 {
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
108 // XXX FIXME XXX -- is this the right thing to do?
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
109
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
110 fseek (f, offset, SEEK_SET);
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
111
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
112 return ftell (f);
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
113 }
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
114
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
115 int
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
116 c_file_ptr_buf::sync (void)
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
117 {
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
118 return 0;
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
119 }
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
120
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
121 /*
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
122 ;;; Local Variables: ***
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
123 ;;; mode: C++ ***
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
124 ;;; End: ***
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
125 */
168c4d71dc63 [project @ 2000-03-23 07:34:54 by jwe]
jwe
parents:
diff changeset
126