epoc32/include/tools/stlport/stl/_istream.c
branchSymbian3
changeset 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/tools/stlport/stl/_istream.c	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -0,0 +1,1429 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999
     1.6 + * Silicon Graphics Computer Systems, Inc.
     1.7 + *
     1.8 + * Copyright (c) 1999
     1.9 + * Boris Fomitchev
    1.10 + *
    1.11 + * This material is provided "as is", with absolutely no warranty expressed
    1.12 + * or implied. Any use is at your own risk.
    1.13 + *
    1.14 + * Permission to use or copy this software for any purpose is hereby granted
    1.15 + * without fee, provided the above notices are retained on all copies.
    1.16 + * Permission to modify the code and to distribute modified code is granted,
    1.17 + * provided the above notices are retained, and a notice that the code was
    1.18 + * modified is included with the above copyright notice.
    1.19 + *
    1.20 + */
    1.21 +#ifndef _STLP_ISTREAM_C
    1.22 +#define _STLP_ISTREAM_C
    1.23 +
    1.24 +#ifndef _STLP_INTERNAL_ISTREAM
    1.25 +#  include <stl/_istream.h>
    1.26 +#endif
    1.27 +
    1.28 +#ifndef _STLP_INTERNAL_LIMITS
    1.29 +#  include <stl/_limits.h>
    1.30 +#endif
    1.31 +
    1.32 +#ifndef _STLP_INTERNAL_NUM_GET_H
    1.33 +#  include <stl/_num_get.h>
    1.34 +#endif
    1.35 +
    1.36 +#if defined ( _STLP_NESTED_TYPE_PARAM_BUG )
    1.37 +// no wchar_t is supported for this mode
    1.38 +#  define __BIS_int_type__ int
    1.39 +#  define __BIS_pos_type__ streampos
    1.40 +#  define __BIS_off_type__ streamoff
    1.41 +#else
    1.42 +#  define __BIS_int_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::int_type
    1.43 +#  define __BIS_pos_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::pos_type
    1.44 +#  define __BIS_off_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::off_type
    1.45 +#endif
    1.46 +
    1.47 +_STLP_BEGIN_NAMESPACE
    1.48 +
    1.49 +//----------------------------------------------------------------------
    1.50 +// Function object structs used by some member functions.
    1.51 +
    1.52 +_STLP_MOVE_TO_PRIV_NAMESPACE
    1.53 +
    1.54 +template <class _Traits>
    1.55 +struct _Is_not_wspace {
    1.56 +  typedef typename _Traits::char_type argument_type;
    1.57 +  typedef bool                        result_type;
    1.58 +
    1.59 +  const ctype<argument_type>* _M_ctype;
    1.60 +
    1.61 +  _Is_not_wspace(const ctype<argument_type>* __c_type) : _M_ctype(__c_type) {}
    1.62 +  bool operator()(argument_type __c) const
    1.63 +    { return !_M_ctype->is(ctype_base::space, __c); }
    1.64 +};
    1.65 +
    1.66 +template <class _Traits>
    1.67 +struct _Is_wspace_null {
    1.68 +  typedef typename _Traits::char_type argument_type;
    1.69 +  typedef bool                        result_type;
    1.70 +
    1.71 +  const ctype<argument_type>* _M_ctype;
    1.72 +
    1.73 +  _Is_wspace_null(const ctype<argument_type>* __c_type) : _M_ctype(__c_type) {}
    1.74 +  bool operator()(argument_type __c) const {
    1.75 +    return _Traits::eq(__c, argument_type()) ||
    1.76 +           _M_ctype->is(ctype_base::space, __c);
    1.77 +  }
    1.78 +};
    1.79 +
    1.80 +template <class _Traits>
    1.81 +struct _Scan_for_wspace {
    1.82 +  typedef typename _Traits::char_type  char_type;
    1.83 +  typedef char_type*                   first_argument_type;
    1.84 +  typedef char_type*                   second_argument_type;
    1.85 +  typedef char_type*                   result_type;
    1.86 +
    1.87 +  const ctype<char_type>* _M_ctype;
    1.88 +
    1.89 +  _Scan_for_wspace(const ctype<char_type>* __ctype) : _M_ctype(__ctype) {}
    1.90 +  const char_type*
    1.91 +  operator()(const char_type* __first, const char_type* __last) const {
    1.92 +    return _M_ctype->scan_is(ctype_base::space, __first, __last);
    1.93 +  }
    1.94 +};
    1.95 +
    1.96 +template <class _Traits>
    1.97 +struct _Scan_wspace_null {
    1.98 +  typedef typename _Traits::char_type  char_type;
    1.99 +  typedef char_type*                   first_argument_type;
   1.100 +  typedef char_type*                   second_argument_type;
   1.101 +  typedef char_type*                   result_type;
   1.102 +
   1.103 +  const ctype<char_type>* _M_ctype;
   1.104 +
   1.105 +  _Scan_wspace_null(const ctype<char_type>* __c_type) : _M_ctype(__c_type) {}
   1.106 +  const char_type*
   1.107 +  operator()(const char_type* __first, const char_type* __last) const {
   1.108 +    __last = find_if(__first, __last,
   1.109 +                     _Eq_char_bound<_Traits>(char_type()));
   1.110 +    return _M_ctype->scan_is(ctype_base::space, __first, __last);
   1.111 +  }
   1.112 +};
   1.113 +
   1.114 +template <class _Traits>
   1.115 +struct _Scan_for_not_wspace {
   1.116 +  typedef typename _Traits::char_type  char_type;
   1.117 +  typedef char_type*                   first_argument_type;
   1.118 +  typedef char_type*                   second_argument_type;
   1.119 +  typedef char_type*                   result_type;
   1.120 +
   1.121 +  const ctype<char_type>* _M_ctype;
   1.122 +
   1.123 +  _Scan_for_not_wspace(const ctype<char_type>* __c_type) : _M_ctype(__c_type) {}
   1.124 +  const char_type*
   1.125 +  operator()(const char_type* __first, const char_type* __last) const {
   1.126 +    return _M_ctype->scan_not(ctype_base::space, __first, __last);
   1.127 +  }
   1.128 +};
   1.129 +
   1.130 +template <class _Traits>
   1.131 +struct _Scan_for_char_val {
   1.132 +  typedef typename _Traits::char_type char_type;
   1.133 +  typedef char_type*                  first_argument_type;
   1.134 +  typedef char_type*                  second_argument_type;
   1.135 +  typedef char_type*                  result_type;
   1.136 +
   1.137 +  char_type _M_val;
   1.138 +
   1.139 +  _Scan_for_char_val(char_type __val) : _M_val(__val) {}
   1.140 +
   1.141 +  const char_type*
   1.142 +  operator()(const char_type* __first, const char_type* __last) const {
   1.143 +    return find_if(__first, __last, _Eq_char_bound<_Traits>(_M_val));
   1.144 +  }
   1.145 +};
   1.146 +
   1.147 +template <class _Traits>
   1.148 +struct _Scan_for_int_val {
   1.149 +  typedef typename _Traits::char_type char_type;
   1.150 +  typedef typename _Traits::int_type  int_type;
   1.151 +  typedef char_type*                  first_argument_type;
   1.152 +  typedef char_type*                  second_argument_type;
   1.153 +  typedef char_type*                  result_type;
   1.154 +
   1.155 +  int_type _M_val;
   1.156 +
   1.157 +  _Scan_for_int_val(int_type __val) : _M_val(__val) {}
   1.158 +
   1.159 +  const char_type*
   1.160 +  operator()(const char_type* __first, const char_type* __last) const {
   1.161 +    return find_if(__first, __last,
   1.162 +                   _Eq_int_bound<_Traits>(_M_val));
   1.163 +  }
   1.164 +};
   1.165 +
   1.166 +// Helper function: try to push back a character to a streambuf,
   1.167 +// return true if the pushback succeeded.  Does not throw.
   1.168 +
   1.169 +template <class _CharT, class _Traits>
   1.170 +bool _STLP_CALL
   1.171 +__pushback(basic_streambuf<_CharT, _Traits>* __buf, _CharT __c) {
   1.172 +  bool ret;
   1.173 +  _STLP_TRY {
   1.174 +    const typename _Traits::int_type __eof = _Traits::eof();
   1.175 +    ret = !_Traits::eq_int_type(__buf->sputbackc(__c), __eof);
   1.176 +  }
   1.177 +  _STLP_CATCH_ALL {
   1.178 +    ret = false;
   1.179 +  }
   1.180 +  return ret;
   1.181 +}
   1.182 +
   1.183 +//----------------------------------------------------------------------
   1.184 +// Definitions of basic_istream<>'s noninline member functions.
   1.185 +
   1.186 +// Helper function for formatted input of numbers.
   1.187 +template <class _CharT, class _Traits, class _Number>
   1.188 +ios_base::iostate _STLP_CALL
   1.189 +__get_num(basic_istream<_CharT, _Traits>& __that, _Number& __val) {
   1.190 +  typedef typename basic_istream<_CharT, _Traits>::sentry _Sentry;
   1.191 +  ios_base::iostate __err = 0;
   1.192 +  _Sentry __sentry( __that );     // Skip whitespace.
   1.193 +  if (__sentry) {
   1.194 +    typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> > _Num_get;
   1.195 +    _STLP_TRY {
   1.196 +      ((const _Num_get&)use_facet<_Num_get>(__that.getloc())).get(istreambuf_iterator<_CharT, _Traits>(__that.rdbuf()),
   1.197 +                                                                  0, __that, __err, __val);
   1.198 +    }
   1.199 +    _STLP_CATCH_ALL {
   1.200 +      __that._M_handle_exception(ios_base::badbit);
   1.201 +    }
   1.202 +    if (__err) __that.setstate(__err);
   1.203 +  }
   1.204 +  return __err;
   1.205 +}
   1.206 +
   1.207 +_STLP_MOVE_TO_STD_NAMESPACE
   1.208 +
   1.209 +template <class _CharT, class _Traits>
   1.210 +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (short& __val) {
   1.211 +  long __lval;
   1.212 +  _STLP_PRIV __get_num(*this, __lval);
   1.213 +  if ( this->fail() ) {
   1.214 +    return *this;
   1.215 +  }
   1.216 +  short __tmp = __STATIC_CAST(short, __lval);
   1.217 +  unsigned short __uval = __STATIC_CAST(unsigned short, __lval);
   1.218 +  // check if we lose digits
   1.219 +  //    if ((__val != __lval) && ((unsigned short)__val != __lval))
   1.220 +  if ((__tmp != __lval) && ((long)__uval != __lval))
   1.221 +    this->setstate(ios_base::failbit);
   1.222 +  else
   1.223 +    __val = __tmp;
   1.224 +  return *this;
   1.225 +}
   1.226 +
   1.227 +template <class _CharT, class _Traits>
   1.228 +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (int& __val) {
   1.229 +  long __lval;
   1.230 +  _STLP_PRIV __get_num(*this, __lval);
   1.231 +  if ( this->fail() ) {
   1.232 +    return *this;
   1.233 +  }
   1.234 +  int __tmp = __lval;
   1.235 +  unsigned int __uval = __lval;
   1.236 +  // check if we lose digits
   1.237 +  //    if ((__val != __lval) && ((unsigned int)__val != __lval))
   1.238 +  if ((__tmp != __lval) && ((long)__uval != __lval))
   1.239 +    this->setstate(ios_base::failbit);
   1.240 +  else
   1.241 +    __val = __tmp;
   1.242 +  return *this;
   1.243 +}
   1.244 +
   1.245 +template <class _CharT, class _Traits>
   1.246 +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (unsigned short& __val) {
   1.247 +  _STLP_PRIV __get_num(*this, __val);
   1.248 +  return *this;
   1.249 +}
   1.250 +
   1.251 +template <class _CharT, class _Traits>
   1.252 +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (unsigned int& __val) {
   1.253 +  _STLP_PRIV __get_num(*this, __val);
   1.254 +  return *this;
   1.255 +}
   1.256 +
   1.257 +template <class _CharT, class _Traits>
   1.258 +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (long& __val) {
   1.259 +  _STLP_PRIV __get_num(*this, __val);
   1.260 +  return *this;
   1.261 +}
   1.262 +
   1.263 +template <class _CharT, class _Traits>
   1.264 +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (unsigned long& __val) {
   1.265 +  _STLP_PRIV __get_num(*this, __val);
   1.266 +  return *this;
   1.267 +}
   1.268 +
   1.269 +#if defined (_STLP_LONG_LONG)
   1.270 +template <class _CharT, class _Traits>
   1.271 +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (_STLP_LONG_LONG& __val) {
   1.272 +  _STLP_PRIV __get_num(*this, __val);
   1.273 +  return *this;
   1.274 +}
   1.275 +
   1.276 +template <class _CharT, class _Traits>
   1.277 +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (unsigned _STLP_LONG_LONG& __val) {
   1.278 +  _STLP_PRIV __get_num(*this, __val);
   1.279 +  return *this;
   1.280 +}
   1.281 +#endif
   1.282 +template <class _CharT, class _Traits>
   1.283 +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (float& __val) {
   1.284 +  _STLP_PRIV __get_num(*this, __val);
   1.285 +  return *this;
   1.286 +}
   1.287 +template <class _CharT, class _Traits>
   1.288 +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (double& __val) {
   1.289 +  _STLP_PRIV __get_num(*this, __val);
   1.290 +  return *this;
   1.291 +}
   1.292 +#if !defined (_STLP_NO_LONG_DOUBLE)
   1.293 +template <class _CharT, class _Traits>
   1.294 +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (long double& __val) {
   1.295 +  _STLP_PRIV __get_num(*this, __val);
   1.296 +  return *this;
   1.297 +}
   1.298 +#endif
   1.299 +#if !defined (_STLP_NO_BOOL)
   1.300 +template <class _CharT, class _Traits>
   1.301 +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (bool& __val) {
   1.302 +  _STLP_PRIV __get_num(*this, __val);
   1.303 +  return *this;
   1.304 +}
   1.305 +#endif
   1.306 +
   1.307 +template <class _CharT, class _Traits>
   1.308 +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (void*& __val) {
   1.309 +  _STLP_PRIV __get_num(*this, __val);
   1.310 +  return *this;
   1.311 +}
   1.312 +
   1.313 +// Unformatted input
   1.314 +
   1.315 +template <class _CharT, class _Traits>
   1.316 +__BIS_int_type__
   1.317 +basic_istream<_CharT, _Traits>::peek() {
   1.318 +  typename _Traits::int_type __tmp = _Traits::eof();
   1.319 +
   1.320 +  this->_M_gcount = 0;
   1.321 +  sentry __sentry(*this, _No_Skip_WS());
   1.322 +
   1.323 +  if (__sentry) {
   1.324 +    _STLP_TRY {
   1.325 +      __tmp = this->rdbuf()->sgetc();
   1.326 +    }
   1.327 +    _STLP_CATCH_ALL {
   1.328 +      this->_M_handle_exception(ios_base::badbit);
   1.329 +    }
   1.330 +    if (this->_S_eof(__tmp))
   1.331 +      this->setstate(ios_base::eofbit);
   1.332 +  }
   1.333 +
   1.334 +  return __tmp;
   1.335 +}
   1.336 +
   1.337 +
   1.338 +template <class _CharT, class _Traits>
   1.339 +__BIS_int_type__
   1.340 +basic_istream<_CharT, _Traits>::get() {
   1.341 +  typename _Traits::int_type __tmp = _Traits::eof();
   1.342 +  sentry __sentry(*this, _No_Skip_WS());
   1.343 +  this->_M_gcount = 0;
   1.344 +
   1.345 +  if (__sentry) {
   1.346 +    _STLP_TRY {
   1.347 +      __tmp = this->rdbuf()->sbumpc();
   1.348 +    }
   1.349 +    _STLP_CATCH_ALL {
   1.350 +      this->_M_handle_exception(ios_base::badbit);
   1.351 +    }
   1.352 +
   1.353 +    if (!this->_S_eof(__tmp))
   1.354 +      this->_M_gcount = 1;
   1.355 +  }
   1.356 +
   1.357 +  if (_M_gcount == 0)
   1.358 +    this->setstate(ios_base::eofbit | ios_base::failbit);
   1.359 +
   1.360 +  return __tmp;
   1.361 +}
   1.362 +
   1.363 +template <class _CharT, class _Traits>
   1.364 +basic_istream<_CharT, _Traits>&
   1.365 +basic_istream<_CharT, _Traits>::get(_CharT& __c) {
   1.366 +  sentry __sentry(*this, _No_Skip_WS());
   1.367 +  this->_M_gcount = 0;
   1.368 +
   1.369 +  if (__sentry) {
   1.370 +    typename _Traits::int_type __tmp = _Traits::eof();
   1.371 +    _STLP_TRY {
   1.372 +      __tmp = this->rdbuf()->sbumpc();
   1.373 +    }
   1.374 +    _STLP_CATCH_ALL {
   1.375 +      this->_M_handle_exception(ios_base::badbit);
   1.376 +    }
   1.377 +
   1.378 +    if (!this->_S_eof(__tmp)) {
   1.379 +      this->_M_gcount = 1;
   1.380 +      __c = _Traits::to_char_type(__tmp);
   1.381 +    }
   1.382 +  }
   1.383 +
   1.384 +  if (this->_M_gcount == 0)
   1.385 +    this->setstate(ios_base::eofbit | ios_base::failbit);
   1.386 +
   1.387 +  return *this;
   1.388 +}
   1.389 +
   1.390 +
   1.391 +// Read characters and discard them.  The standard specifies a single
   1.392 +// function with two arguments, each with a default.  We instead use
   1.393 +// three overloded functions, because it's possible to implement the
   1.394 +// first two more efficiently than the fully general third version.
   1.395 +template <class _CharT, class _Traits>
   1.396 +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::ignore() {
   1.397 +  sentry __sentry(*this, _No_Skip_WS());
   1.398 +  this->_M_gcount = 0;
   1.399 +
   1.400 +  if (__sentry) {
   1.401 +    int_type __c;
   1.402 +    _STLP_TRY {
   1.403 +      __c = this->rdbuf()->sbumpc();
   1.404 +    }
   1.405 +    _STLP_CATCH_ALL {
   1.406 +      this->_M_handle_exception(ios_base::badbit);
   1.407 +      return *this;
   1.408 +    }
   1.409 +
   1.410 +    if (!this->_S_eof(__c))
   1.411 +      this->_M_gcount = 1;
   1.412 +    else
   1.413 +      this->setstate(ios_base::eofbit);
   1.414 +  }
   1.415 +
   1.416 +  return *this;
   1.417 +}
   1.418 +
   1.419 +// Putback
   1.420 +
   1.421 +template <class _CharT, class _Traits>
   1.422 +basic_istream<_CharT, _Traits>&
   1.423 +basic_istream<_CharT, _Traits>::putback(_CharT __c) {
   1.424 +  this->_M_gcount = 0;
   1.425 +  sentry __sentry(*this, _No_Skip_WS());
   1.426 +
   1.427 +  if (__sentry) {
   1.428 +    typename _Traits::int_type __tmp = _Traits::eof();
   1.429 +    basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
   1.430 +//    if (!__buf || this->_S_eof(__buf->sputbackc(__c)))
   1.431 +    if (__buf) {
   1.432 +      _STLP_TRY {
   1.433 +        __tmp = __buf->sputbackc(__c);
   1.434 +      }
   1.435 +      _STLP_CATCH_ALL {
   1.436 +        this->_M_handle_exception(ios_base::badbit);
   1.437 +      }
   1.438 +    }
   1.439 +    if (this->_S_eof(__tmp))
   1.440 +      this->setstate(ios_base::badbit);
   1.441 +  }
   1.442 +  else
   1.443 +    this->setstate(ios_base::failbit);
   1.444 +
   1.445 +  return *this;
   1.446 +}
   1.447 +
   1.448 +template <class _CharT, class _Traits>
   1.449 +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::unget() {
   1.450 +  this->_M_gcount = 0;
   1.451 +
   1.452 +  sentry __sentry(*this, _No_Skip_WS());
   1.453 +
   1.454 +  if (__sentry) {
   1.455 +    basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
   1.456 +    //     if (!__buf || _Traits::eq_int_type(__buf->sungetc(), _Traits::eof()))
   1.457 +    if (__buf) {
   1.458 +      _STLP_TRY {
   1.459 +        if (this->_S_eof(__buf->sungetc()))
   1.460 +          this->setstate(ios_base::badbit);
   1.461 +      }
   1.462 +      _STLP_CATCH_ALL {
   1.463 +        this->_M_handle_exception(ios_base::badbit);
   1.464 +      }
   1.465 +    } else
   1.466 +      this->setstate(ios_base::badbit);
   1.467 +  }
   1.468 +  else
   1.469 +    this->setstate(ios_base::failbit);
   1.470 +
   1.471 +  return *this;
   1.472 +}
   1.473 +
   1.474 +// Positioning and buffer control.
   1.475 +
   1.476 +template <class _CharT, class _Traits>
   1.477 +int basic_istream<_CharT, _Traits>::sync() {
   1.478 +  sentry __sentry(*this, _No_Skip_WS());
   1.479 +
   1.480 +  basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
   1.481 +  if (__buf) {
   1.482 +    if (__buf->pubsync() == -1) {
   1.483 +      this->setstate(ios_base::badbit);
   1.484 +      return -1;
   1.485 +    }
   1.486 +    else
   1.487 +      return 0;
   1.488 +  }
   1.489 +  else
   1.490 +    return -1;
   1.491 +}
   1.492 +
   1.493 +template <class _CharT, class _Traits>
   1.494 +__BIS_pos_type__
   1.495 +basic_istream<_CharT, _Traits>::tellg() {
   1.496 +  sentry __sentry(*this, _No_Skip_WS());
   1.497 +
   1.498 +  basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
   1.499 +  return (__buf && !this->fail()) ? __buf->pubseekoff(0, ios_base::cur, ios_base::in)
   1.500 +    : pos_type(-1);
   1.501 +}
   1.502 +
   1.503 +template <class _CharT, class _Traits>
   1.504 +basic_istream<_CharT, _Traits>&
   1.505 +basic_istream<_CharT, _Traits>::seekg(pos_type __pos) {
   1.506 +  sentry __sentry(*this, _No_Skip_WS());
   1.507 +
   1.508 +  basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
   1.509 +  if (!this->fail() && __buf) {
   1.510 +    if (__buf->pubseekpos(__pos) == pos_type(-1)) {
   1.511 +      this->setstate(ios_base::failbit);
   1.512 +    }
   1.513 +  }
   1.514 +  return *this;
   1.515 +}
   1.516 +
   1.517 +template <class _CharT, class _Traits>
   1.518 +basic_istream<_CharT, _Traits>&
   1.519 +basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir) {
   1.520 +  sentry __sentry(*this, _No_Skip_WS());
   1.521 +
   1.522 +  basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
   1.523 +  if (!this->fail() && __buf)
   1.524 +    __buf->pubseekoff(__off, __dir);
   1.525 +  return *this;
   1.526 +}
   1.527 +
   1.528 +// Formatted input of characters and character arrays.
   1.529 +
   1.530 +template <class _CharT, class _Traits>
   1.531 +void basic_istream<_CharT, _Traits>::_M_formatted_get(_CharT& __c) {
   1.532 +//  typename _Traits::int_type __tmp = _Traits::eof();
   1.533 +
   1.534 +  sentry __sentry(*this); // Skip whitespace.
   1.535 +
   1.536 +  if (__sentry) {
   1.537 +    typename _Traits::int_type __tmp;// = _Traits::eof();
   1.538 +
   1.539 +    _STLP_TRY {
   1.540 +      __tmp = this->rdbuf()->sbumpc();
   1.541 +    }
   1.542 +    _STLP_CATCH_ALL {
   1.543 +      this->_M_handle_exception(ios_base::badbit);
   1.544 +      return;
   1.545 +    }
   1.546 +
   1.547 +    if (!this->_S_eof(__tmp))
   1.548 +      __c = _Traits::to_char_type(__tmp);
   1.549 +    else
   1.550 +      this->setstate(ios_base::eofbit | ios_base::failbit);
   1.551 +  }
   1.552 +}
   1.553 +
   1.554 +
   1.555 +//---------------------------------------------------------------------------
   1.556 +// istream's helper functions.
   1.557 +
   1.558 +// A generic function for unbuffered input.  We stop when we reach EOF,
   1.559 +// or when we have extracted _Num characters, or when the function object
   1.560 +// __is_delim return true.  In the last case, it extracts the character
   1.561 +// for which __is_delim is true, if and only if __extract_delim is true.
   1.562 +// It appends a null character to the end of the string; this means that
   1.563 +// it may store up to _Num + 1 characters.
   1.564 +//
   1.565 +// __is_getline governs two corner cases: reading _Num characters without
   1.566 +// encountering delim or eof (in which case failbit is set if __is_getline
   1.567 +// is true); and reading _Num characters where the _Num+1'st character is
   1.568 +// eof (in which case eofbit is set if __is_getline is true).
   1.569 +//
   1.570 +// It is assumed that __is_delim never throws.
   1.571 +//
   1.572 +// Return value is the number of characters extracted, including the
   1.573 +// delimiter if it is extracted.  Note that the number of characaters
   1.574 +// extracted isn't necessarily the same as the number stored.
   1.575 +
   1.576 +_STLP_MOVE_TO_PRIV_NAMESPACE
   1.577 +
   1.578 +template < class _CharT, class _Traits, class _Is_Delim>
   1.579 +streamsize _STLP_CALL
   1.580 +__read_unbuffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __buf,
   1.581 +                  streamsize _Num, _CharT* __s,
   1.582 +                  _Is_Delim __is_delim,
   1.583 +                  bool __extract_delim, bool __append_null,
   1.584 +                  bool __is_getline) {
   1.585 +  streamsize __n = 0;
   1.586 +  ios_base::iostate __status = 0;
   1.587 +
   1.588 +  typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
   1.589 +  // The operations that can potentially throw are sbumpc, snextc, and sgetc.
   1.590 +  _STLP_TRY {
   1.591 +    for (;;) {
   1.592 +      int_type __c = __buf->sbumpc(); // sschwarz
   1.593 +
   1.594 +      if (__that->_S_eof(__c)) {
   1.595 +        if (__n < _Num || __is_getline)
   1.596 +          __status |= ios_base::eofbit;
   1.597 +        break;
   1.598 +      }
   1.599 +      else if (__is_delim(_Traits::to_char_type(__c))) {
   1.600 +        if (__extract_delim) { // Extract and discard current character.
   1.601 +          ++__n;
   1.602 +        } else if ( !__pushback(__buf, _Traits::to_char_type(__c)) ) { // leave delimiter
   1.603 +          __status |= ios_base::failbit;
   1.604 +        }
   1.605 +        break;
   1.606 +      }
   1.607 +      else { // regular character
   1.608 +        *__s++ = _Traits::to_char_type(__c);
   1.609 +        ++__n;
   1.610 +      }
   1.611 +
   1.612 +      if (__n == _Num) {
   1.613 +        if (__is_getline) // didn't find delimiter as one of the _Num chars
   1.614 +          __status |= ios_base::failbit;
   1.615 +        break;
   1.616 +      }
   1.617 +    }
   1.618 +  }
   1.619 +  _STLP_CATCH_ALL {
   1.620 +    __that->_M_handle_exception(ios_base::badbit);
   1.621 +    *__s = _STLP_DEFAULT_CONSTRUCTED(_CharT);
   1.622 +    return __n;
   1.623 +  }
   1.624 +
   1.625 +  if (__append_null)
   1.626 +    *__s =  _STLP_DEFAULT_CONSTRUCTED(_CharT);
   1.627 +  if (__status)
   1.628 +    __that->setstate(__status);    // This might throw.
   1.629 +  return __n;
   1.630 +}
   1.631 +
   1.632 +// Much like __read_unbuffered, but with one additional function object:
   1.633 +// __scan_delim(first, last) returns the first pointer p in [first, last)
   1.634 +// such that __is_delim(p) is true.
   1.635 +
   1.636 +template < class _CharT, class _Traits, class _Is_Delim, class _Scan_Delim>
   1.637 +streamsize _STLP_CALL
   1.638 +__read_buffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __buf,
   1.639 +                 streamsize _Num, _CharT* __s,
   1.640 +                 _Is_Delim __is_delim, _Scan_Delim __scan_delim,
   1.641 +                 bool __extract_delim, bool __append_null,
   1.642 +                 bool __is_getline) {
   1.643 +  streamsize __n = 0;
   1.644 +  ios_base::iostate __status = 0;
   1.645 +  bool __done    = false;
   1.646 +
   1.647 +  _STLP_TRY {
   1.648 +    while (__buf->_M_egptr() != __buf->_M_gptr() && !__done) {
   1.649 +      const _CharT* __first = __buf->_M_gptr();
   1.650 +      const _CharT* __last  = __buf->_M_egptr();
   1.651 +      //casting numeric_limits<ptrdiff_t>::max to streamsize only works is ptrdiff_t is signed or streamsize representation
   1.652 +      //is larger than ptrdiff_t one.
   1.653 +      _STLP_STATIC_ASSERT((sizeof(streamsize) > sizeof(ptrdiff_t)) ||
   1.654 +                          (sizeof(streamsize) == sizeof(ptrdiff_t)) && numeric_limits<ptrdiff_t>::is_signed)
   1.655 +      ptrdiff_t __request = __STATIC_CAST(ptrdiff_t, (min) (__STATIC_CAST(streamsize, (numeric_limits<ptrdiff_t>::max)()), _Num - __n));
   1.656 +
   1.657 +      const _CharT* __p  = __scan_delim(__first, __last);
   1.658 +      ptrdiff_t __chunk = (min) (ptrdiff_t(__p - __first), __request);
   1.659 +      _Traits::copy(__s, __first, __chunk);
   1.660 +      __s += __chunk;
   1.661 +      __n += __chunk;
   1.662 +      __buf->_M_gbump((int)__chunk);
   1.663 +
   1.664 +      // We terminated by finding delim.
   1.665 +      if (__p != __last && __p - __first <= __request) {
   1.666 +        if (__extract_delim) {
   1.667 +          __n += 1;
   1.668 +          __buf->_M_gbump(1);
   1.669 +        }
   1.670 +        __done = true;
   1.671 +      }
   1.672 +
   1.673 +      // We terminated by reading all the characters we were asked for.
   1.674 +      else if (__n == _Num) {
   1.675 +
   1.676 +        // Find out if we have reached eof.  This matters for getline.
   1.677 +        if (__is_getline) {
   1.678 +          if (__chunk == __last - __first) {
   1.679 +            if (__that->_S_eof(__buf->sgetc()))
   1.680 +              __status |= ios_base::eofbit;
   1.681 +          }
   1.682 +          else
   1.683 +            __status |= ios_base::failbit;
   1.684 +        }
   1.685 +        __done   = true;
   1.686 +      }
   1.687 +
   1.688 +      // The buffer contained fewer than _Num - __n characters.  Either we're
   1.689 +      // at eof, or we should refill the buffer and try again.
   1.690 +      else {
   1.691 +        if (__that->_S_eof(__buf->sgetc())) {
   1.692 +          __status |= ios_base::eofbit;
   1.693 +          __done = true;
   1.694 +        }
   1.695 +      }
   1.696 +    } // Close the while loop.
   1.697 +  }
   1.698 +  _STLP_CATCH_ALL {
   1.699 +    __that->_M_handle_exception(ios_base::badbit);
   1.700 +    __done = true;
   1.701 +  }
   1.702 +
   1.703 +  if (__done) {
   1.704 +    if (__append_null)
   1.705 +        *__s =  _STLP_DEFAULT_CONSTRUCTED(_CharT);
   1.706 +    if (__status != 0)
   1.707 +      __that->setstate(__status);   // This might throw.
   1.708 +    return __n;
   1.709 +  }
   1.710 +
   1.711 +  // If execution has reached this point, then we have an empty buffer but
   1.712 +  // we have not reached eof.  What that means is that the streambuf has
   1.713 +  // decided to switch from buffered to unbuffered input.  We switch to
   1.714 +  // to __read_unbuffered.
   1.715 +
   1.716 +  return __n + __read_unbuffered(__that,  __buf, _Num - __n, __s, __is_delim,
   1.717 +                                 __extract_delim,__append_null,__is_getline);
   1.718 +}
   1.719 +
   1.720 +_STLP_MOVE_TO_STD_NAMESPACE
   1.721 +
   1.722 +template <class _CharT, class _Traits>
   1.723 +basic_istream<_CharT, _Traits>&
   1.724 +basic_istream<_CharT, _Traits>::get(_CharT* __s, streamsize __n,
   1.725 +                                    _CharT __delim) {
   1.726 +  sentry __sentry(*this, _No_Skip_WS());
   1.727 +  this->_M_gcount = 0;
   1.728 +
   1.729 +  if (__sentry) {
   1.730 +    if (__n > 0) {
   1.731 +      basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
   1.732 +
   1.733 +      if (__buf->egptr() != __buf->gptr())
   1.734 +        this->_M_gcount =
   1.735 +          _STLP_PRIV __read_buffered(this,  __buf, __n - 1, __s,
   1.736 +                                     _STLP_PRIV _Eq_char_bound<_Traits>(__delim),
   1.737 +                                     _STLP_PRIV _Scan_for_char_val<_Traits>(__delim),
   1.738 +                                     false, true, false);
   1.739 +      else
   1.740 +        this->_M_gcount =
   1.741 +          _STLP_PRIV __read_unbuffered(this,  __buf, __n - 1, __s,
   1.742 +                                       _STLP_PRIV _Eq_char_bound<_Traits>(__delim),
   1.743 +                                       false, true, false);
   1.744 +    }
   1.745 +  }
   1.746 +
   1.747 +  if (this->_M_gcount == 0)
   1.748 +    this->setstate(ios_base::failbit);
   1.749 +
   1.750 +  return *this;
   1.751 +}
   1.752 +
   1.753 +// Getline is essentially identical to get, except that it extracts
   1.754 +// the delimiter.
   1.755 +template <class _CharT, class _Traits>
   1.756 +basic_istream<_CharT, _Traits>&
   1.757 +basic_istream<_CharT, _Traits>::getline(_CharT* __s, streamsize __n,
   1.758 +                                        _CharT __delim) {
   1.759 +  sentry __sentry(*this, _No_Skip_WS());
   1.760 +  this->_M_gcount = 0;
   1.761 +
   1.762 +  if (__sentry) {
   1.763 +    if (__n > 0) {
   1.764 +      basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
   1.765 +      this->_M_gcount = __buf->egptr() != __buf->gptr()
   1.766 +        ? _STLP_PRIV __read_buffered(this,  __buf, __n - 1, __s,
   1.767 +                                     _STLP_PRIV _Eq_char_bound<_Traits>(__delim),
   1.768 +                                     _STLP_PRIV _Scan_for_char_val<_Traits>(__delim),
   1.769 +                                     true, true, true)
   1.770 +        : _STLP_PRIV __read_unbuffered(this,  __buf, __n - 1, __s,
   1.771 +                                       _STLP_PRIV _Eq_char_bound<_Traits>(__delim),
   1.772 +                                       true, true, true);
   1.773 +    }
   1.774 +  }
   1.775 +
   1.776 +  if (this->_M_gcount == 0)
   1.777 +    this->setstate(ios_base::failbit);
   1.778 +
   1.779 +  return *this;
   1.780 +}
   1.781 +
   1.782 +// Read n characters.  We don't look for any delimiter, and we don't
   1.783 +// put in a terminating null character.
   1.784 +template <class _CharT, class _Traits>
   1.785 +basic_istream<_CharT, _Traits>&
   1.786 +basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n) {
   1.787 +  sentry __sentry(*this, _No_Skip_WS());
   1.788 +  this->_M_gcount = 0;
   1.789 +
   1.790 +  if (__sentry && !this->eof()) {
   1.791 +    basic_streambuf<_CharT, _Traits>*__buf = this->rdbuf();
   1.792 +    if (__buf->gptr() != __buf->egptr())
   1.793 +      _M_gcount
   1.794 +        = _STLP_PRIV __read_buffered(this,  __buf, __n, __s,
   1.795 +                                     _STLP_PRIV _Constant_unary_fun<bool, int_type>(false),
   1.796 +                                     _STLP_PRIV _Project2nd<const _CharT*, const _CharT*>(),
   1.797 +                                     false, false, false);
   1.798 +    else
   1.799 +      _M_gcount
   1.800 +        = _STLP_PRIV __read_unbuffered(this,  __buf, __n, __s,
   1.801 +                                       _STLP_PRIV _Constant_unary_fun<bool, int_type>(false),
   1.802 +                                       false, false, false);
   1.803 +  }
   1.804 +  else
   1.805 +    this->setstate(ios_base::failbit);
   1.806 +
   1.807 +  if (this->eof())
   1.808 +    this->setstate(ios_base::eofbit | ios_base::failbit);
   1.809 +
   1.810 +  return *this;
   1.811 +}
   1.812 +
   1.813 +
   1.814 +// Read n or fewer characters.  We don't look for any delimiter, and
   1.815 +// we don't put in a terminating null character.
   1.816 +template <class _CharT, class _Traits>
   1.817 +streamsize
   1.818 +basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __nmax) {
   1.819 +  sentry __sentry(*this, _No_Skip_WS());
   1.820 +  this->_M_gcount = 0;
   1.821 +
   1.822 +  if (__sentry && !this->eof() && __nmax >= 0) {
   1.823 +
   1.824 +    basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
   1.825 +    streamsize __avail = __buf->in_avail();
   1.826 +
   1.827 +    // fbp : isn't full-blown setstate required here ?
   1.828 +    if (__avail == -1)
   1.829 +      this->_M_setstate_nothrow(ios_base::eofbit);
   1.830 +
   1.831 +    else if (__avail != 0) {
   1.832 +
   1.833 +      if (__buf->gptr() != __buf->egptr())
   1.834 +        _M_gcount
   1.835 +          = _STLP_PRIV __read_buffered(this,  __buf, (min) (__avail, __nmax), __s,
   1.836 +                                       _STLP_PRIV _Constant_unary_fun<bool, int_type>(false),
   1.837 +                                       _STLP_PRIV _Project2nd<const _CharT*, const _CharT*>(),
   1.838 +                                       false, false, false);
   1.839 +      else
   1.840 +        _M_gcount
   1.841 +          = _STLP_PRIV __read_unbuffered(this,  __buf, (min) (__avail, __nmax), __s,
   1.842 +                                         _STLP_PRIV _Constant_unary_fun<bool, int_type>(false),
   1.843 +                                         false, false, false);
   1.844 +    }
   1.845 +  }
   1.846 +  else {
   1.847 +    // fbp : changed so that failbit is set only there, to pass Dietmar's test
   1.848 +    if (this->eof())
   1.849 +      this->setstate(ios_base::eofbit | ios_base::failbit);
   1.850 +    else
   1.851 +      this->setstate(ios_base::failbit);
   1.852 +  }
   1.853 +
   1.854 +  //  if (this->eof())
   1.855 +  //    this->setstate(ios_base::eofbit | ios_base::failbit);
   1.856 +
   1.857 +  return _M_gcount;
   1.858 +}
   1.859 +
   1.860 +template <class _CharT, class _Traits>
   1.861 +void basic_istream<_CharT, _Traits>::_M_formatted_get(_CharT* __s) {
   1.862 +  sentry __sentry(*this); // Skip whitespace.
   1.863 +
   1.864 +  if (__sentry) {
   1.865 +    basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
   1.866 +    streamsize __nmax = this->width() > 0
   1.867 +      ? this->width() - 1
   1.868 +      : ((numeric_limits<streamsize>::max)() / sizeof(_CharT)) - 1;
   1.869 +
   1.870 +    streamsize __n = __buf->gptr() != __buf->egptr()
   1.871 +      ? _STLP_PRIV __read_buffered(this,  __buf, __nmax, __s,
   1.872 +                                   _STLP_PRIV _Is_wspace_null<_Traits>(__STATIC_CAST(const ctype<_CharT>*, this->_M_ctype_facet())),
   1.873 +                                   _STLP_PRIV _Scan_wspace_null<_Traits>(__STATIC_CAST(const ctype<_CharT>*, this->_M_ctype_facet())),
   1.874 +                                   false, true, false)
   1.875 +      : _STLP_PRIV __read_unbuffered(this,  __buf, __nmax, __s,
   1.876 +                                     _STLP_PRIV _Is_wspace_null<_Traits>(__STATIC_CAST(const ctype<_CharT>*, this->_M_ctype_facet())),
   1.877 +                                     false, true, false);
   1.878 +    if (__n == 0)
   1.879 +      this->setstate(ios_base::failbit);
   1.880 +  }
   1.881 +  this->width(0);
   1.882 +}
   1.883 +
   1.884 +// A generic unbuffered function for ignoring characters.  We stop
   1.885 +// when we reach EOF, or when the function object __is_delim returns
   1.886 +// true.  In the last case, it extracts the character for which
   1.887 +// __is_delim is true, if and only if __extract_delim is true.
   1.888 +
   1.889 +template < class _CharT, class _Traits, class _Is_Delim>
   1.890 +void _STLP_CALL
   1.891 +_M_ignore_unbuffered(basic_istream<_CharT, _Traits>* __that,
   1.892 +                     basic_streambuf<_CharT, _Traits>* __buf,
   1.893 +                     _Is_Delim __is_delim,
   1.894 +                     bool __extract_delim, bool __set_failbit) {
   1.895 +  bool __done = false;
   1.896 +  ios_base::iostate __status = 0;
   1.897 +  typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
   1.898 +
   1.899 +  _STLP_TRY {
   1.900 +    while (!__done) {
   1.901 +      int_type __c = __buf->sbumpc();
   1.902 +
   1.903 +      if (__that->_S_eof(__c)) {
   1.904 +        __done = true;
   1.905 +        __status |= __set_failbit ? ios_base::eofbit | ios_base::failbit
   1.906 +                                  : ios_base::eofbit;
   1.907 +      }
   1.908 +
   1.909 +      else if (__is_delim(_Traits::to_char_type(__c))) {
   1.910 +        __done = true;
   1.911 +        if (!__extract_delim)
   1.912 +          if (__that->_S_eof(__buf->sputbackc(_Traits::to_char_type(__c))))
   1.913 +            __status |= ios_base::failbit;
   1.914 +      }
   1.915 +    }
   1.916 +  }
   1.917 +  _STLP_CATCH_ALL {
   1.918 +    __that->_M_handle_exception(ios_base::badbit);
   1.919 +  }
   1.920 +
   1.921 +  __that->setstate(__status);
   1.922 +}
   1.923 +
   1.924 +// A generic buffered function for ignoring characters.  Much like
   1.925 +// _M_ignore_unbuffered, but with one additional function object:
   1.926 +// __scan_delim(first, last) returns the first pointer p in [first,
   1.927 +// last) such that __is_delim(p) is true.
   1.928 +
   1.929 +template < class _CharT, class _Traits, class _Is_Delim, class _Scan_Delim>
   1.930 +void _STLP_CALL
   1.931 +_M_ignore_buffered(basic_istream<_CharT, _Traits>* __that,
   1.932 +                   basic_streambuf<_CharT, _Traits>* __buf,
   1.933 +                   _Is_Delim __is_delim, _Scan_Delim __scan_delim,
   1.934 +                   bool __extract_delim, bool __set_failbit) {
   1.935 +  bool __at_eof      = false;
   1.936 +  bool __found_delim = false;
   1.937 +
   1.938 +  _STLP_TRY {
   1.939 +    while (__buf->_M_egptr() != __buf->_M_gptr() && !__at_eof && !__found_delim) {
   1.940 +      const _CharT* __p = __scan_delim(__buf->_M_gptr(), __buf->_M_egptr());
   1.941 +      __buf->_M_gbump((int)(__p - __buf->_M_gptr()));
   1.942 +
   1.943 +      if (__p != __buf->_M_egptr()) { // We found delim, so we're done.
   1.944 +        if (__extract_delim)
   1.945 +          __buf->_M_gbump(1);
   1.946 +        __found_delim = true;
   1.947 +      }
   1.948 +
   1.949 +      else                         // No delim.  Try to refil the buffer.
   1.950 +        __at_eof = __that->_S_eof(__buf->sgetc());
   1.951 +    }                              // Close the while loop.
   1.952 +  }
   1.953 +  _STLP_CATCH_ALL {
   1.954 +    __that->_M_handle_exception(ios_base::badbit);
   1.955 +    return;
   1.956 +  }
   1.957 +
   1.958 +  if (__at_eof) {
   1.959 +    __that->setstate(__set_failbit ? ios_base::eofbit | ios_base::failbit
   1.960 +                                   : ios_base::eofbit);
   1.961 +    return;
   1.962 +  }
   1.963 +  if (__found_delim)
   1.964 +    return;
   1.965 +
   1.966 +  // If execution has reached this point, then we have an empty buffer but
   1.967 +  // we have not reached eof.  What that means is that the streambuf has
   1.968 +  // decided to switch from a buffered to an unbuffered mode.  We switch
   1.969 +  // to _M_ignore_unbuffered.
   1.970 +  _M_ignore_unbuffered(__that,  __buf, __is_delim, __extract_delim, __set_failbit);
   1.971 +}
   1.972 +
   1.973 +// Overloaded versions of _M_ignore_unbuffered and _M_ignore_unbuffered
   1.974 +// with an explicit count _Num.  Return value is the number of
   1.975 +// characters extracted.
   1.976 +//
   1.977 +// The function object __max_chars takes two arguments, _Num and __n
   1.978 +// (the latter being the number of characters we have already read),
   1.979 +// and returns the maximum number of characters to read from the buffer.
   1.980 +// We parameterize _M_ignore_buffered so that we can use it for both
   1.981 +// bounded and unbounded input; for the former the function object should
   1.982 +// be minus<>, and for the latter it should return a constant maximum value.
   1.983 +
   1.984 +template < class _CharT, class _Traits, class _Max_Chars, class _Is_Delim>
   1.985 +streamsize _STLP_CALL
   1.986 +_M_ignore_unbuffered(basic_istream<_CharT, _Traits>* __that,
   1.987 +                     basic_streambuf<_CharT, _Traits>* __buf,
   1.988 +                     streamsize _Num, _Max_Chars __max_chars,
   1.989 +                     _Is_Delim __is_delim,
   1.990 +                     bool __extract_delim, bool __set_failbit) {
   1.991 +  streamsize __n = 0;
   1.992 +  ios_base::iostate __status = 0;
   1.993 +  typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
   1.994 +
   1.995 +  _STLP_TRY {
   1.996 +    while (__max_chars(_Num, __n) > 0) {
   1.997 +      int_type __c = __buf->sbumpc();
   1.998 +
   1.999 +      if (__that->_S_eof(__c)) {
  1.1000 +        __status |= __set_failbit ? ios_base::eofbit | ios_base::failbit
  1.1001 +                                  : ios_base::eofbit;
  1.1002 +        break;
  1.1003 +      }
  1.1004 +
  1.1005 +      else if (__is_delim(_Traits::to_char_type(__c))) {
  1.1006 +        if (__extract_delim)
  1.1007 +          ++__n;
  1.1008 +        else if (__that->_S_eof(__buf->sputbackc(_Traits::to_char_type(__c))))
  1.1009 +          __status |= ios_base::failbit;
  1.1010 +
  1.1011 +        break;
  1.1012 +      }
  1.1013 +      // fbp : added counter increment to pass Dietmar's test
  1.1014 +      ++__n;
  1.1015 +    }
  1.1016 +  }
  1.1017 +  _STLP_CATCH_ALL {
  1.1018 +    __that->_M_handle_exception(ios_base::badbit);
  1.1019 +  }
  1.1020 +
  1.1021 +  if (__status)
  1.1022 +    __that->setstate(__status);   // This might throw.
  1.1023 +  return __n;
  1.1024 +}
  1.1025 +
  1.1026 +template < class _CharT, class _Traits, class _Max_Chars, class _Is_Delim, class _Scan_Delim>
  1.1027 +streamsize _STLP_CALL
  1.1028 +_M_ignore_buffered(basic_istream<_CharT, _Traits>* __that,
  1.1029 +                   basic_streambuf<_CharT, _Traits>* __buf,
  1.1030 +                   streamsize _Num,
  1.1031 +                   _Max_Chars __max_chars,
  1.1032 +                   _Is_Delim __is_delim, _Scan_Delim __scan_delim,
  1.1033 +                   bool __extract_delim, bool __set_failbit) {
  1.1034 +  streamsize __n = 0;
  1.1035 +  bool __at_eof = false;
  1.1036 +  bool __done   = false;
  1.1037 +
  1.1038 +  _STLP_TRY {
  1.1039 +    while (__buf->_M_egptr() != __buf->_M_gptr() && !__done) {
  1.1040 +      ptrdiff_t __avail = __buf->_M_egptr() - __buf->_M_gptr();
  1.1041 +      streamsize __m = __max_chars(_Num, __n);
  1.1042 +
  1.1043 +      if (__avail >= __m) {       // We have more characters than we need.
  1.1044 +        const _CharT* __last = __buf->_M_gptr() + __STATIC_CAST(ptrdiff_t, __m);
  1.1045 +        const _CharT* __p = __scan_delim(__buf->_M_gptr(), __last);
  1.1046 +        ptrdiff_t __chunk = __p - __buf->_M_gptr();
  1.1047 +        __n += __chunk;
  1.1048 +        __buf->_M_gbump((int)__chunk);
  1.1049 +
  1.1050 +        if (__extract_delim && __p != __last) {
  1.1051 +          __n += 1;
  1.1052 +          __buf->_M_gbump(1);
  1.1053 +        }
  1.1054 +
  1.1055 +        __done = true;
  1.1056 +      }
  1.1057 +
  1.1058 +      else {
  1.1059 +        const _CharT* __p = __scan_delim(__buf->_M_gptr(), __buf->_M_egptr());
  1.1060 +        ptrdiff_t __chunk = __p - __buf->_M_gptr();
  1.1061 +        __n += __chunk;
  1.1062 +        __buf->_M_gbump((int)__chunk);
  1.1063 +
  1.1064 +        if (__p != __buf->_M_egptr()) { // We found delim.
  1.1065 +          if (__extract_delim) {
  1.1066 +            __n += 1;
  1.1067 +            __buf->_M_gbump(1);
  1.1068 +          }
  1.1069 +
  1.1070 +          __done = true;
  1.1071 +        }
  1.1072 +
  1.1073 +        // We didn't find delim.  Try to refill the buffer.
  1.1074 +        else if (__that->_S_eof(__buf->sgetc())) {
  1.1075 +          __done   = true;
  1.1076 +          __at_eof = true;
  1.1077 +        }
  1.1078 +      }
  1.1079 +    } // Close the while loop.
  1.1080 +  }
  1.1081 +  _STLP_CATCH_ALL {
  1.1082 +    __that->_M_handle_exception(ios_base::badbit);
  1.1083 +    return __n;
  1.1084 +  }
  1.1085 +
  1.1086 +  if (__at_eof)
  1.1087 +    __that->setstate(__set_failbit ? ios_base::eofbit | ios_base::failbit
  1.1088 +                                   : ios_base::eofbit);
  1.1089 +
  1.1090 +  if (__done)
  1.1091 +    return __n;
  1.1092 +
  1.1093 +  // If execution has reached this point, then we have an empty buffer but
  1.1094 +  // we have not reached eof.  What that means is that the streambuf has
  1.1095 +  // decided to switch from buffered to unbuffered input.  We switch to
  1.1096 +  // to _M_ignore_unbuffered.
  1.1097 +
  1.1098 +  return __n + _M_ignore_unbuffered(__that,  __buf, _Num, __max_chars,
  1.1099 +                                    __is_delim, __extract_delim, __set_failbit);
  1.1100 +}
  1.1101 +
  1.1102 +
  1.1103 +template <class _CharT, class _Traits>
  1.1104 +basic_istream<_CharT, _Traits>&
  1.1105 +basic_istream<_CharT, _Traits>::ignore(streamsize __n) {
  1.1106 +  sentry __sentry(*this, _No_Skip_WS());
  1.1107 +  this->_M_gcount = 0;
  1.1108 +
  1.1109 +  if (__sentry) {
  1.1110 +    basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
  1.1111 +    typedef _STLP_PRIV _Constant_unary_fun<bool, int_type> _Const_bool;
  1.1112 +    typedef _STLP_PRIV _Constant_binary_fun<streamsize, streamsize, streamsize> _Const_streamsize;
  1.1113 +    const streamsize __maxss = (numeric_limits<streamsize>::max)();
  1.1114 +
  1.1115 +    if (__n == (numeric_limits<int>::max)()) {
  1.1116 +      if (__buf->gptr() != __buf->egptr())
  1.1117 +        _M_gcount = _M_ignore_buffered(this,  __buf,
  1.1118 +                                       __maxss, _Const_streamsize(__maxss),
  1.1119 +                                       _Const_bool(false),
  1.1120 +                                       _STLP_PRIV _Project2nd<const _CharT*, const _CharT*>(),
  1.1121 +                                       false, false);
  1.1122 +      else
  1.1123 +        _M_gcount = _M_ignore_unbuffered(this,  __buf,
  1.1124 +                                         __maxss, _Const_streamsize(__maxss),
  1.1125 +                                         _Const_bool(false), false, false);
  1.1126 +    }
  1.1127 +    else {
  1.1128 +      if (__buf->gptr() != __buf->egptr())
  1.1129 +        _M_gcount = _M_ignore_buffered(this,  __buf,
  1.1130 +                                       __n, minus<streamsize>(),
  1.1131 +                                       _Const_bool(false),
  1.1132 +                                       _STLP_PRIV _Project2nd<const _CharT*, const _CharT*>(),
  1.1133 +                                       false, false);
  1.1134 +      else
  1.1135 +        _M_gcount = _M_ignore_unbuffered(this,  __buf, __n, minus<streamsize>(),
  1.1136 +                                         _Const_bool(false), false, false);
  1.1137 +    }
  1.1138 +  }
  1.1139 +
  1.1140 +  return *this;
  1.1141 +}
  1.1142 +
  1.1143 +template <class _CharT, class _Traits>
  1.1144 +basic_istream<_CharT, _Traits>&
  1.1145 +basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __delim) {
  1.1146 +  sentry __sentry(*this, _No_Skip_WS());
  1.1147 +  this->_M_gcount = 0;
  1.1148 +
  1.1149 +  if (__sentry) {
  1.1150 +    basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
  1.1151 +    typedef _STLP_PRIV _Constant_unary_fun<bool, int_type> _Const_bool;
  1.1152 +    typedef _STLP_PRIV _Constant_binary_fun<streamsize, streamsize, streamsize>
  1.1153 +      _Const_streamsize;
  1.1154 +    const streamsize __maxss = (numeric_limits<streamsize>::max)();
  1.1155 +
  1.1156 +    if (__n == (numeric_limits<int>::max)()) {
  1.1157 +      if (__buf->gptr() != __buf->egptr())
  1.1158 +        _M_gcount = _M_ignore_buffered(this,  __buf,
  1.1159 +                                       __maxss, _Const_streamsize(__maxss),
  1.1160 +                                       _STLP_PRIV _Eq_int_bound<_Traits>(__delim),
  1.1161 +                                       _STLP_PRIV _Scan_for_int_val<_Traits>(__delim),
  1.1162 +                                       true, false);
  1.1163 +      else
  1.1164 +        _M_gcount = _M_ignore_unbuffered(this,  __buf,
  1.1165 +                                         __maxss, _Const_streamsize(__maxss),
  1.1166 +                                         _STLP_PRIV _Eq_int_bound<_Traits>(__delim),
  1.1167 +                                         true, false);
  1.1168 +    }
  1.1169 +    else {
  1.1170 +      if (__buf->gptr() != __buf->egptr())
  1.1171 +        _M_gcount = _M_ignore_buffered(this,  __buf,
  1.1172 +                                       __n, minus<streamsize>(),
  1.1173 +                                       _STLP_PRIV _Eq_int_bound<_Traits>(__delim),
  1.1174 +                                       _STLP_PRIV _Scan_for_int_val<_Traits>(__delim),
  1.1175 +                                       true, false);
  1.1176 +      else
  1.1177 +        _M_gcount = _M_ignore_unbuffered(this,  __buf, __n, minus<streamsize>(),
  1.1178 +                                         _STLP_PRIV _Eq_int_bound<_Traits>(__delim),
  1.1179 +                                         true, false);
  1.1180 +    }
  1.1181 +  }
  1.1182 +
  1.1183 +  return *this;
  1.1184 +}
  1.1185 +
  1.1186 +// This member function does not construct a sentry object, because
  1.1187 +// it is called from sentry's constructor.
  1.1188 +template <class _CharT, class _Traits>
  1.1189 +void basic_istream<_CharT, _Traits>::_M_skip_whitespace(bool __set_failbit) {
  1.1190 +  basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
  1.1191 +  if (!__buf)
  1.1192 +    this->setstate(ios_base::badbit);
  1.1193 +  else if (__buf->gptr() != __buf->egptr())
  1.1194 +    _M_ignore_buffered(this,  __buf,
  1.1195 +                       _STLP_PRIV _Is_not_wspace<_Traits>(__STATIC_CAST(const ctype<_CharT>*, this->_M_ctype_facet())),
  1.1196 +                       _STLP_PRIV _Scan_for_not_wspace<_Traits>(__STATIC_CAST(const ctype<_CharT>*, this->_M_ctype_facet())),
  1.1197 +                       false, __set_failbit);
  1.1198 +  else
  1.1199 +    _M_ignore_unbuffered(this,  __buf,
  1.1200 +                         _STLP_PRIV _Is_not_wspace<_Traits>(__STATIC_CAST(const ctype<_CharT>*, this->_M_ctype_facet())),
  1.1201 +                         false, __set_failbit);
  1.1202 +}
  1.1203 +
  1.1204 +
  1.1205 +// This is a very simple loop that reads characters from __src and puts
  1.1206 +// them into __dest.  It looks complicated because of the (standard-
  1.1207 +// mandated) exception handling policy.
  1.1208 +//
  1.1209 +// We stop when we get an exception, when we fail to insert into the
  1.1210 +// output streambuf, or when __is_delim is true.
  1.1211 +
  1.1212 +_STLP_MOVE_TO_PRIV_NAMESPACE
  1.1213 +
  1.1214 +template < class _CharT, class _Traits, class _Is_Delim>
  1.1215 +streamsize _STLP_CALL
  1.1216 +__copy_unbuffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __src,
  1.1217 +                  basic_streambuf<_CharT, _Traits>* __dest,
  1.1218 +                  _Is_Delim __is_delim,
  1.1219 +                  bool __extract_delim, bool __rethrow) {
  1.1220 +  streamsize __extracted = 0;
  1.1221 +  ios_base::iostate __status = 0;
  1.1222 +  typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
  1.1223 +  int_type __c;
  1.1224 +
  1.1225 +  _STLP_TRY {
  1.1226 +    for (;;) {
  1.1227 +      // Get a character. If there's an exception, catch and (maybe) rethrow it.
  1.1228 +      __c = __src->sbumpc();
  1.1229 +
  1.1230 +      // If we failed to get a character, then quit.
  1.1231 +      if (__that->_S_eof(__c)) {
  1.1232 +        __status |= ios_base::eofbit;
  1.1233 +        break;
  1.1234 +      }
  1.1235 +      // If it's the delimiter, then quit.
  1.1236 +      else if (__is_delim(_Traits::to_char_type(__c))) {
  1.1237 +        if (!__extract_delim && !__pushback(__src, _Traits::to_char_type(__c)))
  1.1238 +          __status |= ios_base::failbit;
  1.1239 +        break;
  1.1240 +      }
  1.1241 +      else {
  1.1242 +        // Try to put the character in the output streambuf.
  1.1243 +        bool __failed = false;
  1.1244 +        _STLP_TRY {
  1.1245 +          if (!__that->_S_eof(__dest->sputc(_Traits::to_char_type(__c))))
  1.1246 +            ++__extracted;
  1.1247 +          else
  1.1248 +            __failed = true;
  1.1249 +        }
  1.1250 +        _STLP_CATCH_ALL {
  1.1251 +          __failed = true;
  1.1252 +        }
  1.1253 +
  1.1254 +        // If we failed to put the character in the output streambuf, then
  1.1255 +        // try to push it back to the input streambuf.
  1.1256 +        if (__failed && !__pushback(__src, _Traits::to_char_type(__c)))
  1.1257 +          __status |= ios_base::failbit;
  1.1258 +
  1.1259 +        // fbp : avoiding infinite loop in io-27-6-1-2-3.exp
  1.1260 +        if (__failed)
  1.1261 +          break;
  1.1262 +      }
  1.1263 +
  1.1264 +    } /* for (;;) */
  1.1265 +
  1.1266 +  }
  1.1267 +  // fbp : this try/catch moved here in reasonable assumption
  1.1268 +  // __is_delim never throw (__pushback is guaranteed not to)
  1.1269 +  _STLP_CATCH_ALL {
  1.1270 +    // See 27.6.1.2.3, paragraph 13.
  1.1271 +    if (__rethrow && __extracted == 0)
  1.1272 +      __that->_M_handle_exception(ios_base::failbit);
  1.1273 +  }
  1.1274 +  __that->setstate(__status);
  1.1275 +  return __extracted;
  1.1276 +}
  1.1277 +
  1.1278 +// Buffered copying from one streambuf to another.  We copy the characters
  1.1279 +// in chunks, rather than one at a time.  We still have to worry about all
  1.1280 +// of the error conditions we checked in __copy_unbuffered, plus one more:
  1.1281 +// the streambuf might decide to switch from a buffered to an unbuffered mode.
  1.1282 +
  1.1283 +template < class _CharT, class _Traits, class _Is_Delim, class _Scan_Delim>
  1.1284 +streamsize _STLP_CALL
  1.1285 +__copy_buffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __src,
  1.1286 +                basic_streambuf<_CharT, _Traits>* __dest,
  1.1287 +                _Scan_Delim __scan_delim, _Is_Delim __is_delim,
  1.1288 +                bool __extract_delim, bool __rethrow) {
  1.1289 +  streamsize __extracted = 0;
  1.1290 +  ios_base::iostate __status = 0;
  1.1291 +  typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
  1.1292 +  //Borland compiler generates a warning if assignment because value is never used:
  1.1293 +  int_type __c /*= _Traits::eof()*/;
  1.1294 +  _CharT* __first = __src->_M_gptr();
  1.1295 +  ptrdiff_t __avail = __src->_M_egptr() - __first;
  1.1296 +  // fbp : introduced to move catch/try blocks out of the loop
  1.1297 +  bool __do_handle_exceptions = false;
  1.1298 +
  1.1299 +  _STLP_TRY {
  1.1300 +    for (;;) {
  1.1301 +      const _CharT* __last = __scan_delim(__first, __src->_M_egptr());
  1.1302 +
  1.1303 +      // Try to copy the entire input buffer to the output buffer.
  1.1304 +      streamsize __n = __dest->sputn(__first, __extract_delim && __last != __src->_M_egptr()
  1.1305 +                                     ? (__last - __first) + 1
  1.1306 +                                     : (__last - __first));
  1.1307 +      __src->_M_gbump((int)__n);
  1.1308 +      __extracted += __n;
  1.1309 +
  1.1310 +      // from this on, catch() will call _M_handle_exceptions()
  1.1311 +      __do_handle_exceptions = true;
  1.1312 +
  1.1313 +      if (__n < __avail)          // We found the delimiter, or else failed to
  1.1314 +        break;                    // copy some characters.
  1.1315 +
  1.1316 +      __c = __src->sgetc();
  1.1317 +
  1.1318 +      // Three possibilities: we succeeded in refilling the buffer, or
  1.1319 +      // we got EOF, or the streambuf has switched to unbuffered mode.
  1.1320 +      __first = __src->_M_gptr();
  1.1321 +      __avail = __src->_M_egptr() - __first;
  1.1322 +
  1.1323 +      if (__avail > 0)
  1.1324 +        {}  // dwa 1/16/00 -- suppress a Metrowerks warning
  1.1325 +      else if (__that->_S_eof(__c)) {
  1.1326 +        __status |= ios_base::eofbit;
  1.1327 +        break;
  1.1328 +      }
  1.1329 +      else {
  1.1330 +        return __extracted + __copy_unbuffered(__that,  __src, __dest, __is_delim,
  1.1331 +                                                __extract_delim, __rethrow);
  1.1332 +      }
  1.1333 +
  1.1334 +      __do_handle_exceptions = false;
  1.1335 +    }
  1.1336 +  }
  1.1337 +
  1.1338 +  _STLP_CATCH_ALL {
  1.1339 +    // See 27.6.1.2.3, paragraph 13.
  1.1340 +    if (__rethrow && __do_handle_exceptions &&  __extracted == 0)
  1.1341 +      __that->_M_handle_exception(ios_base::failbit);
  1.1342 +  }
  1.1343 +
  1.1344 +  if (__status)
  1.1345 +    __that->setstate(__status);   // This might throw.
  1.1346 +  return __extracted;
  1.1347 +}
  1.1348 +
  1.1349 +_STLP_MOVE_TO_STD_NAMESPACE
  1.1350 +
  1.1351 +template <class _CharT, class _Traits>
  1.1352 +basic_istream<_CharT, _Traits>&
  1.1353 +basic_istream<_CharT, _Traits>
  1.1354 +  ::get(basic_streambuf<_CharT, _Traits>& __dest, _CharT __delim) {
  1.1355 +  sentry __sentry(*this, _No_Skip_WS());
  1.1356 +  this->_M_gcount = 0;
  1.1357 +
  1.1358 +  if (__sentry) {
  1.1359 +    basic_streambuf<_CharT, _Traits>* __src = this->rdbuf();
  1.1360 +
  1.1361 +    if (__src)
  1.1362 +      this->_M_gcount = __src->egptr() != __src->gptr()
  1.1363 +        ? _STLP_PRIV __copy_buffered(this,  __src, &__dest,
  1.1364 +                                     _STLP_PRIV _Scan_for_char_val<_Traits>(__delim),
  1.1365 +                                     _STLP_PRIV _Eq_char_bound<_Traits>(__delim),
  1.1366 +                                     false, false)
  1.1367 +        : _STLP_PRIV __copy_unbuffered(this,  __src, &__dest,
  1.1368 +                                       _STLP_PRIV _Eq_char_bound<_Traits>(__delim),
  1.1369 +                                       false, false);
  1.1370 +  }
  1.1371 +
  1.1372 +  if (this->_M_gcount == 0)
  1.1373 +    this->setstate(ios_base::failbit);
  1.1374 +
  1.1375 +  return *this;
  1.1376 +}
  1.1377 +
  1.1378 +// Copying characters into a streambuf.
  1.1379 +template <class _CharT, class _Traits>
  1.1380 +basic_istream<_CharT, _Traits>&
  1.1381 +basic_istream<_CharT, _Traits>
  1.1382 +  ::operator>>(basic_streambuf<_CharT, _Traits>* __dest) {
  1.1383 +  streamsize __n = 0;
  1.1384 +  typedef typename basic_istream<_CharT, _Traits>::sentry _Sentry;
  1.1385 +  _Sentry __sentry(*this);
  1.1386 +  if (__sentry) {
  1.1387 +    basic_streambuf<_CharT, _Traits>* __src = this->rdbuf();
  1.1388 +    if (__src && __dest)
  1.1389 +      __n = __src->egptr() != __src->gptr()
  1.1390 +        ? _STLP_PRIV __copy_buffered(this,  __src, __dest,
  1.1391 +                                     _STLP_PRIV _Project2nd<const _CharT*, const _CharT*>(),
  1.1392 +                                     _STLP_PRIV _Constant_unary_fun<bool, int_type>(false),
  1.1393 +                                     false, true)
  1.1394 +        : _STLP_PRIV __copy_unbuffered(this,  __src, __dest,
  1.1395 +                                       _STLP_PRIV _Constant_unary_fun<bool, int_type>(false),
  1.1396 +                                       false, true);
  1.1397 +  }
  1.1398 +
  1.1399 +  if (__n == 0)
  1.1400 +    this->setstate(ios_base::failbit);
  1.1401 +
  1.1402 +  return *this;
  1.1403 +}
  1.1404 +
  1.1405 +// ----------------------------------------------------------------
  1.1406 +// basic_iostream<> class
  1.1407 +// ----------------------------------------------------------------
  1.1408 +
  1.1409 +template <class _CharT, class _Traits>
  1.1410 +basic_iostream<_CharT, _Traits>
  1.1411 +  ::basic_iostream(basic_streambuf<_CharT, _Traits>* __buf)
  1.1412 +    : basic_ios<_CharT, _Traits>(),
  1.1413 +      basic_istream<_CharT, _Traits>(__buf),
  1.1414 +      basic_ostream<_CharT, _Traits>(__buf) {
  1.1415 +  this->init(__buf);
  1.1416 +}
  1.1417 +
  1.1418 +template <class _CharT, class _Traits>
  1.1419 +basic_iostream<_CharT, _Traits>::~basic_iostream()
  1.1420 +{}
  1.1421 +
  1.1422 +_STLP_END_NAMESPACE
  1.1423 +
  1.1424 +#undef __BIS_int_type__
  1.1425 +#undef __BIS_pos_type__
  1.1426 +#undef __BIS_off_type__
  1.1427 +
  1.1428 +#endif /* _STLP_ISTREAM_C */
  1.1429 +
  1.1430 +// Local Variables:
  1.1431 +// mode:C++
  1.1432 +// End: