home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright (C) 1988 Free Software Foundation
- written by Doug Lea (dl@rocky.oswego.edu)
-
- This file is part of GNU CC.
-
- GNU CC is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY. No author or distributor
- accepts responsibility to anyone for the consequences of using it
- or for whether it serves any particular purpose or works at all,
- unless he says so in writing. Refer to the GNU CC General Public
- License for full details.
-
- Everyone is granted permission to copy, modify and redistribute
- GNU CC, but only under the conditions described in the
- GNU CC General Public License. A copy of this license is
- supposed to have been given to you along with GNU CC so you
- can know your rights and responsibilities. It should be in a
- file named COPYING. Among other things, the copyright notice
- and this notice must be preserved on all copies.
- */
-
- #include <stream.h>
- #include <stdarg.h>
- #include <ctype.h>
- #include "libconfig.h"
-
- ostream::ostream() {}
-
- ostream::ostream(const char* filename, io_mode m, access_mode a)
- :(filename, m, a) {}
-
- ostream::ostream(const char* filename, const char* m)
- :(filename, m) {}
-
- ostream::ostream(int filedesc, io_mode m = io_writeonly)
- :(filedesc, m) {}
-
- ostream::ostream(FILE* fileptr)
- :(fileptr) {}
-
- ostream::ostream(int sz, char* buf)
- :(sz, buf, io_writeonly) {}
-
- ostream::~ostream() {}
-
- istream::istream()
- {
- tied_to = 0;
- }
-
- istream::istream(const char* filename, io_mode m, access_mode a)
- :(filename, m, a)
- {
- tied_to = 0;
- }
-
- istream::istream(const char* filename, const char* m)
- :(filename, m)
- {
- tied_to = 0;
- }
-
- istream::istream(int filedesc, io_mode m = io_readonly)
- :(filedesc, m)
- {
- tied_to = 0;
- }
-
- istream::istream(FILE* fileptr)
- :(fileptr)
- {
- tied_to = 0;
- }
-
- istream::istream(int sz, char* buf)
- :(sz, buf, io_readonly)
- {
- tied_to = 0;
- }
-
- istream::~istream() {}
-
-
- ostream* istream::tie(ostream* s)
- {
- ostream* t = tied_to;
- tied_to = s;
- return t;
- }
-
- istream& istream::operator>>(whitespace&)
- {
- _flush();
- char ch;
- while((get(ch)) && isspace(ch));
- if (good())
- unget(ch);
- return *this;
- }
-
- istream& istream::operator>>(char& ch)
- {
- _flush();
- while((get(ch)) && isspace(ch));
- return *this;
- }
-
- istream& istream::scan(const char* fmt ...)
- {
- if (readable())
- {
- _flush();
- va_list args;
- va_start(args, fmt);
- stat = _doscan(fp, fmt, args);
- va_end(args);
- failif(stat <= 0);
- }
- return *this;
- }
-
- istream& istream::operator>>(short& n)
- {
- return scan("%hd", &n);
- }
-
- istream& istream::operator>>(unsigned short& n)
- {
- return scan("%hd", &n);
- }
-
- istream& istream::operator>>(int& n)
- {
- return scan("%d", &n);
- }
-
- istream& istream::operator>>(unsigned int& n)
- {
- return scan("%d", &n);
- }
-
- istream& istream::operator>>(long& n)
- {
- return scan("%ld", &n);
- }
-
- istream& istream::operator>>(unsigned long& n)
- {
- return scan("%ld", &n);
- }
-
- istream& istream::operator>>(float& n)
- {
- return scan("%f", &n);
- }
-
- istream& istream::operator>>(double& n)
- {
- return scan("%lf", &n);
- }
-
- istream& istream::operator>>(char* s)
- {
- return scan("%s", s);
- }
-
- void eatwhite(istream& s)
- {
- s >> WS;
- }
-
-
- ostream& ostream::form(const char* fmt ...)
- {
- va_list args;
- va_start(args, fmt);
- #ifndef HAVE_VPRINTF
- stat = _doprnt(fmt, args, fp);
- #else
- stat = vfprintf(fp, fmt, args);
- #endif
- va_end(args);
- failif(stat < 0);
- return *this;
- }
-
- ostream& ostream::operator<<(const char* s)
- {
- put(s); return *this;
- }
-
- ostream& ostream::operator<<(short n)
- {
- return form("%d",(int)n);
- }
-
- ostream& ostream::operator<<(unsigned short n)
- {
- return form("%u",(unsigned)n);
- }
-
- ostream& ostream::operator<<(int n)
- {
- return form("%d",n);
- }
-
- ostream& ostream::operator<<(unsigned int n)
- {
- return form("%u",n);
- }
-
- ostream& ostream::operator<<(long n)
- {
- return form("%ld",n);
- }
-
- ostream& ostream::operator<<(unsigned long n)
- {
- return form("%lu",n);
- }
-
- ostream& ostream::operator<<(float n)
- {
- return form("%g",(double)n);
- }
-
- ostream& ostream::operator<<(double n)
- {
- return form("%g",n);
- }
-
-
- /*
- * predeclared streams
- */
-
- istream cin(stdin);
- ostream cout(stdout);
- ostream cerr(stderr);
-
- whitespace WS;
-
-