/*
 * Copyright (c) 1999 
 * Boris Fomitchev
 *
 * This material is provided "as is", with absolutely no warranty expressed
 * or implied. Any use is at your own risk.
 *
 * Permission to use or copy this software for any purpose is hereby granted 
 * without fee, provided the above notices are retained on all copies.
 * Permission to modify the code and to distribute modified code is granted,
 * provided the above notices are retained, and a notice that the code was
 * modified is included with the above copyright notice.
 *
 */

#ifndef __STLPORT_CWCHAR
# define __STLPORT_CWCHAR

# ifndef __STL_OUTERMOST_HEADER_ID
#  define __STL_OUTERMOST_HEADER_ID 0x120
#  include <stl/_prolog.h>
# endif

# ifdef __GNUC__
# include <cstddef> 
# endif

# if ! defined (__STL_WINCE)

# if defined (__BORLANDC__) &&  (__BORLANDC__ >= 0x530 ) && ! defined (__SGI_STL_OWN_IOSTREAMS)
// Borland defines this stuff here
#   include <iosfwd>
# endif

# if defined  (__STL_USE_NEW_C_HEADERS) && ! defined (__HP_aCC)
#  include __STL_NATIVE_CPP_C_HEADER(cwchar)
# elif defined (__MRC__) || defined (__SC__) || defined (__BORLANDC__)
#  include __STL_NATIVE_C_HEADER(stddef.h)
# else
#  include __STL_NATIVE_C_HEADER(wchar.h)
# endif

// this stuff is varying a lot between platforms
#if defined(__MSL__) && __MSL__ <= 0x51FF	// dwa 2/28/99 - not yet implemented by MSL 
#   define __STL_WCHAR_MSL_EXCLUDE 1
// dwa 2/28/99 - Fix an MSL bug. We expect this to be fixed in the next release.
namespace std
{ 
  extern "C" size_t wcsftime(wchar_t * str, size_t max_size, const wchar_t * format_str, const struct tm * timeptr);
}
#  define __STL_NO_MBSTATE_T 1
#elif defined(__sun) && defined (__SVR4) && !defined (_MBSTATE_T) && !defined (_STD_MBSTATE_T) \
 	&& (defined(__SunOS_5_5_1) || defined(__SunOS_5_6) || ! defined (_WCHAR_ISO_SUNWCC_H))
# ifndef __STL_NO_NATIVE_MBSTATE_T
#  define __STL_NO_NATIVE_MBSTATE_T 1
# endif
# define __STL_WCHAR_SUNPRO_EXCLUDE 1
# if defined ( __SGI_STL_OWN_IOSTREAMS )
#  define _MBSTATE_T
#  define _STD_MBSTATE_T
# else
#  define __STL_NO_MBSTATE_T 1
# endif
#elif defined (__BORLANDC__)
#  ifdef __SGI_STL_OWN_IOSTREAMS
#   define __STL_NO_NATIVE_MBSTATE_T
#  endif
#  define __STL_WCHAR_BORLAND_EXCLUDE 1
#  if (__BORLANDC__ < 0x540 )
#   define __STL_NO_MBSTATE_T 1
#   define __STL_WCHAR_SUNPRO_EXCLUDE
#  endif
#endif

# if defined ( __SGI_STL_OWN_IOSTREAMS ) \
     && defined (__STL_NO_NATIVE_MBSTATE_T) && ! defined (__STL_NO_MBSTATE_T)
#  define __STL_USE_OWN_MBSTATE_T
# endif

# ifdef __STL_USE_OWN_MBSTATE_T

__STL_BEGIN_NAMESPACE

struct __stl_mbstate_t { 
  __stl_mbstate_t( long __st = 0 ) : _M_state(__st) {}
  __stl_mbstate_t& operator=(const long __st) {
    _M_state= __st;              
    return *this;
  } 
  // default ones
  __stl_mbstate_t(const __stl_mbstate_t& __x) : _M_state(__x._M_state) {}         
  __stl_mbstate_t& operator=(const __stl_mbstate_t& __x) {
    _M_state= __x._M_state;              
    return *this;
  }       
  long _M_state;
  //  friend inline bool operator==(const __stl_mbstate_t& __x, const __stl_mbstate_t& __y);
  //  friend inline bool operator!=(const __stl_mbstate_t& __x, const __stl_mbstate_t& __y);    
};          

inline bool operator==(const __stl_mbstate_t& __x, const __stl_mbstate_t& __y) {
  return ( __x._M_state == __y._M_state );
}

inline bool operator!=(const __stl_mbstate_t& __x, const __stl_mbstate_t& __y) {
  return ( __x._M_state == __y._M_state );
}

typedef __stl_mbstate_t mbstate_t;

__STL_END_NAMESPACE

# endif


#  if defined (__STL_NO_MBSTATE_T) && !defined (__STL_NO_NATIVE_MBSTATE_T)
#   define __STL_NO_NATIVE_MBSTATE_T 1
#  endif


# ifdef __STL_IMPORT_VENDOR_CSTD
__STL_BEGIN_NAMESPACE
using __STL_VENDOR_CSTD::wint_t;
using __STL_VENDOR_CSTD::size_t;

#  if !defined (__STL_NO_NATIVE_MBSTATE_T)
using __STL_VENDOR_MB_NAMESPACE::mbstate_t;

# if !defined (__STL_NO_CSTD_FUNCTION_IMPORTS) && !defined(__STL_WCHAR_BORLAND_EXCLUDE) \
  && (!defined(__MSL__) || __MSL__ > 0x6001)
using __STL_VENDOR_MB_NAMESPACE::btowc;
using __STL_VENDOR_MB_NAMESPACE::mbrlen;
using __STL_VENDOR_MB_NAMESPACE::mbrtowc;
using __STL_VENDOR_MB_NAMESPACE::mbsinit;
using __STL_VENDOR_MB_NAMESPACE::mbsrtowcs;
using __STL_VENDOR_MB_NAMESPACE::wcrtomb;
using __STL_VENDOR_MB_NAMESPACE::wcsrtombs;
#    endif /* BORLAND && !__MSL__ || __MSL__ > 0x6001 */

#  endif /* __STL_NO_NATIVE_MBSTATE_T */

# if !defined (__STL_NO_NATIVE_WIDE_FUNCTIONS) && ! defined (__STL_NO_CSTD_FUNCTION_IMPORTS)

# if !defined (__STL_WCHAR_BORLAND_EXCLUDE) && ! defined (__STL_NO_CSTD_FUNCTION_IMPORTS)
using __STL_VENDOR_CSTD::fgetwc;
using __STL_VENDOR_CSTD::fgetws;
using __STL_VENDOR_CSTD::fputwc;
using __STL_VENDOR_CSTD::fputws;
# endif

#  if !( defined (__STL_WCHAR_SUNPRO_EXCLUDE) || defined (__STL_WCHAR_BORLAND_EXCLUDE) \
      || defined(__STL_WCHAR_HPACC_EXCLUDE) ) 
# ifndef __DECCXX
using __STL_VENDOR_CSTD::fwide;
# endif
using __STL_VENDOR_CSTD::fwprintf;
using __STL_VENDOR_CSTD::fwscanf;
using __STL_VENDOR_CSTD::getwchar;
#  endif

# ifndef __STL_WCHAR_BORLAND_EXCLUDE
using __STL_VENDOR_CSTD::getwc;
using __STL_VENDOR_CSTD::ungetwc;

using __STL_VENDOR_CSTD::putwc;
using __STL_VENDOR_CSTD::putwchar;
# endif

#  if !( defined (__STL_WCHAR_SUNPRO_EXCLUDE) || defined (__STL_WCHAR_BORLAND_EXCLUDE)\
      || defined(__STL_WCHAR_HPACC_EXCLUDE) ) 
using __STL_VENDOR_CSTD::swprintf;
using __STL_VENDOR_CSTD::swscanf;
using __STL_VENDOR_CSTD::vfwprintf;
using __STL_VENDOR_CSTD::vwprintf;
using __STL_VENDOR_CSTD::vswprintf;

#   if !defined(__MSL__) || __MSL__ > 0x6001
using __STL_VENDOR_CSTD::wcsftime;
#   endif
using __STL_VENDOR_CSTD::wcstok;

#  endif

# if !(defined (__BORLANDC__) && (__BORLANDC__ < 0x540))
using __STL_VENDOR_CSTD::wcscat;
using __STL_VENDOR_CSTD::wcsrchr;
using __STL_VENDOR_CSTD::wcscmp;
using __STL_VENDOR_CSTD::wcscoll;

using __STL_VENDOR_CSTD::wcscpy;
using __STL_VENDOR_CSTD::wcscspn;

using __STL_VENDOR_CSTD::wcslen;
using __STL_VENDOR_CSTD::wcsncat;
using __STL_VENDOR_CSTD::wcsncmp;
using __STL_VENDOR_CSTD::wcsncpy;
using __STL_VENDOR_CSTD::wcspbrk;
using __STL_VENDOR_CSTD::wcschr;

using __STL_VENDOR_CSTD::wcsspn;
using __STL_VENDOR_CSTD::wcsxfrm;

# endif

#  if !defined (__STL_WCHAR_BORLAND_EXCLUDE)

using __STL_VENDOR_CSTD::wcstod;
using __STL_VENDOR_CSTD::wcstol;

# endif

#  if !( defined (__STL_WCHAR_SUNPRO_EXCLUDE) || defined(__STL_WCHAR_HPACC_EXCLUDE) )

using __STL_VENDOR_CSTD::wcsstr;
using __STL_VENDOR_CSTD::wmemchr;

#  if !defined (__STL_WCHAR_BORLAND_EXCLUDE)

using __STL_VENDOR_CSTD::wctob;
using __STL_VENDOR_CSTD::wmemcmp;
using __STL_VENDOR_CSTD::wmemmove;
using __STL_VENDOR_CSTD::wprintf;
using __STL_VENDOR_CSTD::wscanf;

#  endif

using __STL_VENDOR_CSTD::wmemcpy;
using __STL_VENDOR_CSTD::wmemset;
#  endif

# endif /* __STL_NO_NATIVE_WIDE_FUNCTIONS */
__STL_END_NAMESPACE
# endif /* __STL_IMPORT_VENDOR_CSTD */

# undef __STL_WCHAR_SUNPRO_EXCLUDE
# undef __STL_WCHAR_MSL_EXCLUDE

# endif /* WINCE */




#if !defined (__STL_NO_WCHAR_T)
# ifndef WCHAR_MIN
#  define WCHAR_MIN 0
// SUNpro has some bugs with casts. wchar_t is size of int there anyway.
#  ifdef __SUNPRO_CC
#   define WCHAR_MAX (~0)
#  else
#   define WCHAR_MAX ((wchar_t)~0)
#  endif
# endif
#endif

# if (__STL_OUTERMOST_HEADER_ID == 0x120)
#  include <stl/_epilog.h>
#  undef __STL_OUTERMOST_HEADER_ID
# endif

#endif /* __STLPORT_CWCHAR */

// Local Variables:
// mode:C++
// End:

