/* Release 3.10 */
/*-------------------------------------------------------------------------*
*                                                                          *
*  IOINLINE.CPP - 2.0 stream class small inline implementations.           *
*                                                                          *
*  COPYRIGHT (C) 1989..1992 Clarion Software Corporation.                  *
*  All Rights Reserved                                                     *
*                                                                          *
*--------------------------------------------------------------------------*/

#undef _SMALL_INLINE
#include <clib.h>
#include <iostream.hpp>

streambuf* ios::rdbuf() {
  return _bp;
}
ostream* ios::tie() {
  return x_tie;
}

char ios::fill() {
  return x_fill;
}

int ios::precision() {
  return x_precision;
}

int ios::rdstate() {
  return state;
}

int ios::eof() {
  return (state&eofbit);
}

int ios::fail() {
  return (state&(failbit|badbit|hardfail));
}

int ios::bad() {
  return (state&(badbit|hardfail));
}

int ios::good() {
  return (state == 0);
}

long ios::flags() {
  return x_flags;
}

int ios::width() {
  return x_width;
}

int ios::width(int _w) {
  int _temp = x_width;
  x_width = _w;
  return _temp;
}

char  ios::fill(char _w) {
  char _temp = x_fill;
  x_fill = _w;
  return _temp;
}

int ios::precision(int _w) {
  int _temp = x_precision;
  x_precision = _w;
  return _temp;
}

ios::operator void* () {
  return (fail()|eof()) ? 0 : this;
}

ios::operator! () {
  return (fail()|eof());
}

char * streambuf::base()  {
  return _base;
}

char * streambuf::pbase() {
  return _pbase;
}

char * streambuf::pptr()  {
  return _pptr;
}

char * streambuf::epptr() {
  return _epptr;
}

char * streambuf::gptr()  {
  return _gptr;
}

char * streambuf::egptr() {
  return _egptr;
}

char * streambuf::eback() {
  return _eback;
}

char * streambuf::ebuf()  {
  return _ebuf;
}

int    streambuf::unbuffered() {
  return _unbuf;
}

int    streambuf::blen() {
  return (int) (_ebuf - _base);
}

void   streambuf::pbump(int _n) {
  _pptr += _n;
}

void   streambuf::gbump(int _n) {
  _gptr += _n;
}

void   streambuf::unbuffered(int _ub) {
  _unbuf = (_ub != 0);
}

int    streambuf::in_avail() {
  return (_egptr > _gptr) ?   (int)(_egptr - _gptr): 0;
}

int    streambuf::out_waiting() {
  return _pptr ? (int)(_pptr - _pbase): 0;
}

int    streambuf::allocate() {
  return((_base || _unbuf) ? 0 : doallocate());
}

int    streambuf::sgetc() {
  return ((_gptr >= _egptr) ? underflow() : (unsigned char) *_gptr);
}

int    streambuf::snextc() {
  return ((++_gptr >= _egptr) ? do_snextc() : (unsigned char) *_gptr);
}

int    streambuf::sbumpc() {
  return ((_gptr >= _egptr) && (underflow() == EOF) ? EOF : (unsigned char) *_gptr++);
}

void   streambuf::stossc() {
  if (_gptr >= _egptr)
    underflow();
  else
    ++_gptr;
}

int    streambuf::sputbackc(char _c) {
  return (_gptr > _eback) ? *--_gptr = _c : pbackfail(_c) ;
}

int    streambuf::sputc(int _c) {
  return (_pptr >= _epptr) ? overflow(_c) : (*_pptr++=_c);
}


int istream::gcount() {
  return _gcount;
}

int istream::ipfx(int _need) {
  if( _need ? (ispecial&~skipping) : ispecial)
    return do_ipfx(_need);
  return 1;
}

int istream::ipfx0() {
  return ispecial ? do_ipfx(0) : 1;
}

int istream::ipfx1() {
  return (ispecial&~skipping) ? do_ipfx(1) : 1;
}

istream& istream::operator>>(unsigned char& _c) {
  if(ipfx0()) {
    if(_bp->in_avail())
      _c = _bp->sbumpc();
    else
      _c = do_get();
  }
  return *this;
}

istream& istream::operator>>(signed char& _c) {
  if(ipfx0()) {
    if(_bp->in_avail())
      _c = _bp->sbumpc();
    else
      _c = do_get();
  }
  return *this;
}

istream& istream::operator>>(char& _c) {
  if(ipfx0()) {
    if(_bp->in_avail())
      _c = _bp->sbumpc();
    else
      _c = do_get();
  }
  return *this;
}

istream& istream::operator>>(unsigned char* _s) {
  return *this>>(signed char *) _s;
}

istream& istream::operator>>(char* _s) {
  return *this>>(signed char *) _s;
}

istream& istream::get(unsigned char* _s, int _l, char _t) {
  return get((signed char *)_s, _l, _t);
}

istream& istream::get(char* _s, int _l, char _t) {
  return get((signed char *)_s, _l, _t);
}

istream& istream::read(unsigned char* _s, int _l) {
  return read((signed char *)_s, _l);
}

istream& istream::read(char* _s, int _l) {
  return read((signed char *)_s, _l);
}

istream& istream::getline(unsigned char* _s, int _l, char _t) {
  return getline((signed char *)_s, _l, _t);
}

istream& istream::getline(char* _s, int _l, char _t) {
  return getline((signed char *)_s, _l, _t);
}

int  istream::sync() {
  return _bp->sync();
}

istream& istream::operator>> (istream& (*_f)(istream&)) {
  return (*_f)(*this);
}

int istream::peek() {
  return ipfx1() ? _bp->sgetc() : EOF;
}

int  ostream::opfx() {
  return ospecial ? do_opfx() : 1;
}

void ostream::osfx() {
  if((x_flags&(stdio|unitbuf)) || (ospecial)) do_osfx();
}

ostream& ostream::operator<<(unsigned char _c) {
  return *this <<(signed char ) _c;
}

ostream& ostream::operator<<(char _c) {
  return *this <<(signed char ) _c;
}

ostream& ostream::operator<<(short _i) {
  return *this<<(long)_i;
}

ostream& ostream::operator<<(unsigned short _i) {
  return *this<<(unsigned long)_i;
}

ostream& ostream::operator<<(int _i) {
  return *this<<(long)_i;
}

ostream& ostream::operator<<(unsigned int _i) {
  return *this<<(unsigned long)_i;
}

ostream& ostream::operator<<(float _f) {
  return *this<<(long double)_f;
}

ostream& ostream::operator<<(double _f) {
  return *this<<(long double)_f;
}

ostream& ostream::operator<<(ostream& (*_f)(ostream&)) {
  return (*_f)(*this);
}

ostream& ostream::write(const signed char *_s, int _n) {
  return write((const char *)_s, _n);
}

ostream& ostream::write(const unsigned char *_s, int _n) {
  return write((const char *)_s, _n);
}

ostream& ostream::put(char _c) {
  if(_bp->sputc(_c) == EOF)
    setstate(badbit);
  return *this;
}

ostream& ostream::operator<<(const signed char *_s) {
  return *this<<(const char *) _s;
}
ostream& ostream::operator<<(const unsigned char *_s) {
  return *this<<(const char *) _s;
}
