Import (slightly modified) ru.koi8-r.win.kbd:1.1 from FreeBSD (fjoe):
[dragonfly.git] / contrib / libio / iostream.h
1 /*  This is part of libio/iostream, providing -*- C++ -*- input/output.
2 Copyright (C) 1993 Free Software Foundation
3
4 This file is part of the GNU IO Library.  This library is free
5 software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this library; see the file COPYING.  If not, write to the Free
17 Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 As a special exception, if you link this library with files
20 compiled with a GNU compiler to produce an executable, this does not cause
21 the resulting executable to be covered by the GNU General Public License.
22 This exception does not however invalidate any other reasons why
23 the executable file might be covered by the GNU General Public License. */
24
25 #ifndef _IOSTREAM_H
26 #ifdef __GNUG__
27 #pragma interface
28 #endif
29 #define _IOSTREAM_H
30
31 #include <streambuf.h>
32
33 extern "C++" {
34 class istream; class ostream;
35 typedef ios& (*__manip)(ios&);
36 typedef istream& (*__imanip)(istream&);
37 typedef ostream& (*__omanip)(ostream&);
38
39 extern istream& ws(istream& ins);
40 extern ostream& flush(ostream& outs);
41 extern ostream& endl(ostream& outs);
42 extern ostream& ends(ostream& outs);
43
44 class ostream : virtual public ios
45 {
46     // NOTE: If fields are changed, you must fix _fake_ostream in stdstreams.C!
47     void do_osfx();
48   public:
49     ostream() { }
50     ostream(streambuf* sb, ostream* tied=NULL);
51     int opfx() {
52         if (!good()) return 0;
53         else { if (_tie) _tie->flush(); _IO_flockfile(_strbuf); return 1;} }
54     void osfx() { _IO_funlockfile(_strbuf);
55                   if (flags() & (ios::unitbuf|ios::stdio))
56                       do_osfx(); }
57     ostream& flush();
58     ostream& put(char c) { _strbuf->sputc(c); return *this; }
59 #ifdef _STREAM_COMPAT
60     /* Temporary binary compatibility.  REMOVE IN NEXT RELEASE. */
61     ostream& put(unsigned char c) { return put((char)c); }
62     ostream& put(signed char c) { return put((char)c); }
63 #endif
64     ostream& write(const char *s, streamsize n);
65     ostream& write(const unsigned char *s, streamsize n)
66       { return write((const char*)s, n);}
67     ostream& write(const signed char *s, streamsize n)
68       { return write((const char*)s, n);}
69     ostream& write(const void *s, streamsize n)
70       { return write((const char*)s, n);}
71     ostream& seekp(streampos);
72     ostream& seekp(streamoff, _seek_dir);
73     streampos tellp();
74     ostream& form(const char *format ...);
75     ostream& vform(const char *format, _IO_va_list args);
76
77     ostream& operator<<(char c);
78     ostream& operator<<(unsigned char c) { return (*this) << (char)c; }
79     ostream& operator<<(signed char c) { return (*this) << (char)c; }
80     ostream& operator<<(const char *s);
81     ostream& operator<<(const unsigned char *s)
82         { return (*this) << (const char*)s; }
83     ostream& operator<<(const signed char *s)
84         { return (*this) << (const char*)s; }
85     ostream& operator<<(const void *p);
86     ostream& operator<<(int n);
87     ostream& operator<<(unsigned int n);
88     ostream& operator<<(long n);
89     ostream& operator<<(unsigned long n);
90 #if defined(__GNUC__)
91     __extension__ ostream& operator<<(long long n);
92     __extension__ ostream& operator<<(unsigned long long n);
93 #endif
94     ostream& operator<<(short n) {return operator<<((int)n);}
95     ostream& operator<<(unsigned short n) {return operator<<((unsigned int)n);}
96 #if _G_HAVE_BOOL
97     ostream& operator<<(bool b) { return operator<<((int)b); }
98 #endif
99     ostream& operator<<(double n);
100     ostream& operator<<(float n) { return operator<<((double)n); }
101 #if _G_HAVE_LONG_DOUBLE_IO
102     ostream& operator<<(long double n);
103 #else
104     ostream& operator<<(long double n) { return operator<<((double)n); }
105 #endif
106     ostream& operator<<(__omanip func) { return (*func)(*this); }
107     ostream& operator<<(__manip func) {(*func)(*this); return *this;}
108     ostream& operator<<(streambuf*);
109 #ifdef _STREAM_COMPAT
110     streambuf* ostreambuf() const { return _strbuf; }
111 #endif
112 };
113
114 class istream : virtual public ios
115 {
116     // NOTE: If fields are changed, you must fix _fake_istream in stdstreams.C!
117 protected:
118     _IO_size_t _gcount;
119
120     int _skip_ws();
121   public:
122     istream(): _gcount (0) { }
123     istream(streambuf* sb, ostream*tied=NULL);
124     istream& get(char* ptr, int len, char delim = '\n');
125     istream& get(unsigned char* ptr, int len, char delim = '\n')
126         { return get((char*)ptr, len, delim); }
127     istream& get(char& c);
128     istream& get(unsigned char& c) { return get((char&)c); }
129     istream& getline(char* ptr, int len, char delim = '\n');
130     istream& getline(unsigned char* ptr, int len, char delim = '\n')
131         { return getline((char*)ptr, len, delim); }
132     istream& get(signed char& c)  { return get((char&)c); }
133     istream& get(signed char* ptr, int len, char delim = '\n')
134         { return get((char*)ptr, len, delim); }
135     istream& getline(signed char* ptr, int len, char delim = '\n')
136         { return getline((char*)ptr, len, delim); }
137     istream& read(char *ptr, streamsize n);
138     istream& read(unsigned char *ptr, streamsize n)
139       { return read((char*)ptr, n); }
140     istream& read(signed char *ptr, streamsize n)
141       { return read((char*)ptr, n); }
142     istream& read(void *ptr, streamsize n)
143       { return read((char*)ptr, n); }
144     istream& get(streambuf& sb, char delim = '\n');
145     istream& gets(char **s, char delim = '\n');
146     int ipfx(int need = 0) {
147         if (!good()) { set(ios::failbit); return 0; }
148         else {
149           _IO_flockfile(_strbuf);
150           if (_tie && (need == 0 || rdbuf()->in_avail() < need)) _tie->flush();
151           if (!need && (flags() & ios::skipws)) return _skip_ws();
152           else return 1;
153         }
154     }
155     int ipfx0() { // Optimized version of ipfx(0).
156         if (!good()) { set(ios::failbit); return 0; }
157         else {
158           _IO_flockfile(_strbuf);
159           if (_tie) _tie->flush();
160           if (flags() & ios::skipws) return _skip_ws();
161           else return 1;
162         }
163     }
164     int ipfx1() { // Optimized version of ipfx(1).
165         if (!good()) { set(ios::failbit); return 0; }
166         else {
167           _IO_flockfile(_strbuf);
168           if (_tie && rdbuf()->in_avail() == 0) _tie->flush();
169           return 1;
170         }
171     }
172     void isfx() { _IO_funlockfile(_strbuf); }
173     int get() { if (!ipfx1()) return EOF;
174                 else { int ch = _strbuf->sbumpc();
175                        if (ch == EOF) set(ios::eofbit);
176                        isfx();
177                        return ch;
178                      } }
179     int peek();
180     _IO_size_t gcount() { return _gcount; }
181     istream& ignore(int n=1, int delim = EOF);
182     int sync ();
183     istream& seekg(streampos);
184     istream& seekg(streamoff, _seek_dir);
185     streampos tellg();
186     istream& putback(char ch) {
187         if (good() && _strbuf->sputbackc(ch) == EOF) clear(ios::badbit);
188         return *this;}
189     istream& unget() {
190         if (good() && _strbuf->sungetc() == EOF) clear(ios::badbit);
191         return *this;}
192     istream& scan(const char *format ...);
193     istream& vscan(const char *format, _IO_va_list args);
194 #ifdef _STREAM_COMPAT
195     istream& unget(char ch) { return putback(ch); }
196     int skip(int i);
197     streambuf* istreambuf() const { return _strbuf; }
198 #endif
199
200     istream& operator>>(char*);
201     istream& operator>>(unsigned char* p) { return operator>>((char*)p); }
202     istream& operator>>(signed char*p) { return operator>>((char*)p); }
203     istream& operator>>(char& c);
204     istream& operator>>(unsigned char& c) {return operator>>((char&)c);}
205     istream& operator>>(signed char& c) {return operator>>((char&)c);}
206     istream& operator>>(int&);
207     istream& operator>>(long&);
208 #if defined(__GNUC__)
209     __extension__ istream& operator>>(long long&);
210     __extension__ istream& operator>>(unsigned long long&);
211 #endif
212     istream& operator>>(short&);
213     istream& operator>>(unsigned int&);
214     istream& operator>>(unsigned long&);
215     istream& operator>>(unsigned short&);
216 #if _G_HAVE_BOOL
217     istream& operator>>(bool&);
218 #endif
219     istream& operator>>(float&);
220     istream& operator>>(double&);
221     istream& operator>>(long double&);
222     istream& operator>>( __manip func) {(*func)(*this); return *this;}
223     istream& operator>>(__imanip func) { return (*func)(*this); }
224     istream& operator>>(streambuf*);
225 };
226
227 class iostream : public istream, public ostream
228 {
229   public:
230     iostream() { }
231     iostream(streambuf* sb, ostream*tied=NULL);
232 };
233
234 class _IO_istream_withassign : public istream {
235 public:
236   _IO_istream_withassign& operator=(istream&);
237   _IO_istream_withassign& operator=(_IO_istream_withassign& rhs)
238     { return operator= (static_cast<istream&> (rhs)); }
239 };
240
241 class _IO_ostream_withassign : public ostream {
242 public:
243   _IO_ostream_withassign& operator=(ostream&);
244   _IO_ostream_withassign& operator=(_IO_ostream_withassign& rhs)
245     { return operator= (static_cast<ostream&> (rhs)); }
246 };
247
248 extern _IO_istream_withassign cin;
249 // clog->rdbuf() == cerr->rdbuf()
250 extern _IO_ostream_withassign cout, cerr;
251
252 extern _IO_ostream_withassign clog
253 #if _G_CLOG_CONFLICT
254 __asm__ ("__IO_clog")
255 #endif
256 ;
257
258 extern istream& lock(istream& ins);
259 extern istream& unlock(istream& ins);
260 extern ostream& lock(ostream& outs);
261 extern ostream& unlock(ostream& outs);
262
263 struct Iostream_init { } ;  // Compatibility hack for AT&T library.
264
265 inline ios& dec(ios& i)
266 { i.setf(ios::dec, ios::dec|ios::hex|ios::oct); return i; }
267 inline ios& hex(ios& i)
268 { i.setf(ios::hex, ios::dec|ios::hex|ios::oct); return i; }
269 inline ios& oct(ios& i)
270 { i.setf(ios::oct, ios::dec|ios::hex|ios::oct); return i; }
271 } // extern "C++"
272
273 #endif /*!_IOSTREAM_H*/