/*
 * 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 _STLP_CWCHAR
#define _STLP_CWCHAR

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

#ifdef __GNUC__
#  include <cstddef>
#endif

#if !defined(_STLP_WINCE) && !defined(_STLP_WCE_EVC3)

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

#  if !defined(_STLP_NO_CWCHAR) && defined(_STLP_USE_NEW_C_HEADERS)
#    include _STLP_NATIVE_CPP_C_HEADER(cwchar)
#    if defined(__OpenBSD__)
typedef _BSD_WINT_T_ wint_t;
#    endif /* __OpenBSD__ */

#  elif defined (_STLP_NO_WCHAR_T) || defined (__MRC__) || (defined (__SC__) && !defined (__DMC__)) || defined (__BORLANDC__) || \
        defined(__OpenBSD__) || defined(__FreeBSD__) || \
       (defined (__GNUC__) && (defined (__APPLE__) || defined( __Lynx__ )))
#    include _STLP_NATIVE_C_HEADER(stddef.h)
#    if defined (__Lynx__)
#      ifndef _WINT_T
typedef long int wint_t;
#        define _WINT_T
#      endif /* _WINT_T */
#    endif
#    if defined(__OpenBSD__)
typedef _BSD_WINT_T_ wint_t;
#    endif /* __OpenBSD__ */
#  elif defined(__MWERKS__) && defined(N_PLAT_NLM)
#    include <wchar.h>
#  else 
#    include _STLP_NATIVE_C_HEADER(wchar.h)

#    if defined(__sun) && (defined(_XOPEN_SOURCE) || (_XOPEN_VERSION - 0 == 4))
extern wint_t   btowc();
extern int      fwprintf();
extern int      fwscanf();
extern int      fwide();
extern int      mbsinit();
extern size_t   mbrlen();
extern size_t   mbrtowc();
extern size_t   mbsrtowcs();
extern int      swprintf();
extern int      swscanf();
extern int      vfwprintf();
extern int      vwprintf();
extern int      vswprintf();
extern size_t   wcrtomb();
extern size_t   wcsrtombs();
extern wchar_t  *wcsstr();
extern int      wctob();
extern wchar_t  *wmemchr();
extern int      wmemcmp();
extern wchar_t  *wmemcpy();
extern wchar_t  *wmemmove();
extern wchar_t  *wmemset();
extern int      wprintf();
extern int      wscanf();
#    endif
#  endif

#  if defined(__MSL__) && __MSL__ <= 0x51FF	/* dwa 2/28/99 - not yet implemented by MSL  */
#    define _STLP_WCHAR_MSL_EXCLUDE 1
namespace std
{ extern "C" size_t wcsftime(wchar_t * str, size_t max_size, const wchar_t * format_str, const struct tm * timeptr); }
#    define _STLP_NO_MBSTATE_T 1
#  elif defined (__BORLANDC__)
#    ifndef _STLP_USE_NO_IOSTREAMS
#      define _STLP_NO_NATIVE_MBSTATE_T
#    endif
#    define _STLP_WCHAR_BORLAND_EXCLUDE 1
#    if (__BORLANDC__ < 0x540 )
#      define _STLP_NO_MBSTATE_T 1
#      define _STLP_WCHAR_SUNPRO_EXCLUDE
#    endif
#  endif

#  ifndef _STLP_CWCHAR_H
#    include <stl/_cwchar.h>
#  endif

#  ifdef _STLP_IMPORT_VENDOR_CSTD

#    if defined (__SUNPRO_CC) && !defined (_STLP_HAS_NO_NEW_C_HEADERS)
using _STLP_VENDOR_CSTD::wint_t; 
#    endif

_STLP_BEGIN_NAMESPACE
#    ifdef _STLP_NO_WCHAR_T
typedef int wint_t;
#    else
// gcc 3.0 has a glitch : wint_t only sucked into the global namespace if _GLIBCPP_USE_WCHAR_T is defined
// __MWERKS__ has definition in wchar_t.h (MSL C++), but ones differ from definition
// in stdio.h; I prefer settings from last file.
#      if (defined (__GNUC__) && ! defined (_GLIBCPP_USE_WCHAR_T)) // || (defined(__MWERKS__) && defined(N_PLAT_NLM))
using ::wint_t;
#      else
using _STLP_VENDOR_CSTD::wint_t;
#      endif
#    endif

using _STLP_VENDOR_CSTD::size_t;

#    if !defined (_STLP_NO_NATIVE_MBSTATE_T) && ! defined (_STLP_USE_OWN_MBSTATE_T)
using _STLP_VENDOR_MB_NAMESPACE::mbstate_t;

#      if !defined (_STLP_NO_CSTD_FUNCTION_IMPORTS) && !defined(_STLP_WCHAR_BORLAND_EXCLUDE) && \
         (!defined(__MSL__) || __MSL__ > 0x6001)
#        if defined (__MINGW32__) && ((__MINGW32_MAJOR_VERSION > 3) || ((__MINGW32_MAJOR_VERSION == 3) && (__MINGW32_MINOR_VERSION >= 8))) || \
          !(defined (__KCC) || defined (__GNUC__)) && !defined(_STLP_WCE_NET) && !(defined(__MWERKS__) && defined(N_PLAT_NLM))
using _STLP_VENDOR_MB_NAMESPACE::btowc;
#          if (!defined(__MSL__) || __MSL__ > 0x7001)
using _STLP_VENDOR_MB_NAMESPACE::mbsinit;
#          endif
#        endif
#        if defined (__MINGW32__) && ((__MINGW32_MAJOR_VERSION > 3) || ((__MINGW32_MAJOR_VERSION == 3) && (__MINGW32_MINOR_VERSION >= 8))) || \
           !defined (__GNUC__) && !defined(_STLP_WCE_NET) && !(defined(__MWERKS__) && defined(N_PLAT_NLM))
using _STLP_VENDOR_MB_NAMESPACE::mbrlen;
using _STLP_VENDOR_MB_NAMESPACE::mbrtowc;
using _STLP_VENDOR_MB_NAMESPACE::mbsrtowcs;
using _STLP_VENDOR_MB_NAMESPACE::wcrtomb;
using _STLP_VENDOR_MB_NAMESPACE::wcsrtombs;
#        endif
#      endif /* BORLAND && !__MSL__ || __MSL__ > 0x6001 */

#    endif /* _STLP_NO_NATIVE_MBSTATE_T */

#    if !defined (_STLP_NO_NATIVE_WIDE_FUNCTIONS) && ! defined (_STLP_NO_CSTD_FUNCTION_IMPORTS)

#      if !defined (_STLP_WCHAR_BORLAND_EXCLUDE) && ! defined (_STLP_NO_CSTD_FUNCTION_IMPORTS) && !(defined(__MWERKS__) && defined(N_PLAT_NLM))
using _STLP_VENDOR_CSTD::fgetwc;
using _STLP_VENDOR_CSTD::fgetws;
using _STLP_VENDOR_CSTD::fputwc;
using _STLP_VENDOR_CSTD::fputws;
#      endif

#      if !(defined (_STLP_WCHAR_SUNPRO_EXCLUDE) || defined (_STLP_WCHAR_BORLAND_EXCLUDE) || \
          defined(_STLP_WCHAR_HPACC_EXCLUDE) || (defined(__MWERKS__) && defined(N_PLAT_NLM)))
#        ifndef __DECCXX
using _STLP_VENDOR_CSTD::fwide;
#        endif
using _STLP_VENDOR_CSTD::fwprintf;
using _STLP_VENDOR_CSTD::fwscanf;
using _STLP_VENDOR_CSTD::getwchar;
#      endif

#      if !defined(_STLP_WCHAR_BORLAND_EXCLUDE) && !(defined(__MWERKS__) && defined(N_PLAT_NLM))
#        ifndef _STLP_WCE_NET
using _STLP_VENDOR_CSTD::getwc;
#        endif
using _STLP_VENDOR_CSTD::ungetwc;
#        ifndef _STLP_WCE_NET
using _STLP_VENDOR_CSTD::putwc;
#        endif
using _STLP_VENDOR_CSTD::putwchar;
#      endif

#      if !(defined (_STLP_WCHAR_SUNPRO_EXCLUDE) || defined (_STLP_WCHAR_BORLAND_EXCLUDE) || \
          defined(_STLP_WCHAR_HPACC_EXCLUDE) || (defined(__MWERKS__) && defined(N_PLAT_NLM)))
using _STLP_VENDOR_CSTD::swprintf;
using _STLP_VENDOR_CSTD::swscanf;
using _STLP_VENDOR_CSTD::vfwprintf;
using _STLP_VENDOR_CSTD::vwprintf;
using _STLP_VENDOR_CSTD::vswprintf;

#        if (!defined(__MSL__) || __MSL__ > 0x7001 ) && !defined(_STLP_WCE_NET) && \
             !defined(_STLP_USE_UCLIBC) /* at least in uClibc 0.9.26 */

using _STLP_VENDOR_CSTD::wcsftime;
#        endif
using _STLP_VENDOR_CSTD::wcstok;

#      endif

#      if !(defined (__BORLANDC__) && (__BORLANDC__ < 0x540)) && !(defined(__MWERKS__) && defined(N_PLAT_NLM))
#        ifndef _STLP_WCE_NET
using _STLP_VENDOR_CSTD::wcscoll;
using _STLP_VENDOR_CSTD::wcsxfrm;
#        endif
using _STLP_VENDOR_CSTD::wcscat;
using _STLP_VENDOR_CSTD::wcsrchr;
using _STLP_VENDOR_CSTD::wcscmp;

using _STLP_VENDOR_CSTD::wcscpy;
using _STLP_VENDOR_CSTD::wcscspn;

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

using _STLP_VENDOR_CSTD::wcsspn;

#      endif

#      if !defined (_STLP_WCHAR_BORLAND_EXCLUDE) && !(defined(__MWERKS__) && defined(N_PLAT_NLM))
using _STLP_VENDOR_CSTD::wcstod;
using _STLP_VENDOR_CSTD::wcstol;
#      endif

#      if !( defined (_STLP_WCHAR_SUNPRO_EXCLUDE) || defined(_STLP_WCHAR_HPACC_EXCLUDE) || (defined(__MWERKS__) && defined(N_PLAT_NLM)))
using _STLP_VENDOR_CSTD::wcsstr;
using _STLP_VENDOR_CSTD::wmemchr;

#        if !defined (_STLP_WCHAR_BORLAND_EXCLUDE)
#          ifndef __DMC__
#            ifndef _STLP_WCE_NET
using _STLP_VENDOR_CSTD::wctob;
#            endif
using _STLP_VENDOR_CSTD::wmemcmp;
#          endif
using _STLP_VENDOR_CSTD::wmemmove;
using _STLP_VENDOR_CSTD::wprintf;
using _STLP_VENDOR_CSTD::wscanf;
#        endif

using _STLP_VENDOR_CSTD::wmemcpy;
using _STLP_VENDOR_CSTD::wmemset;
#      endif

#    elif defined(__MWERKS__) && defined(N_PLAT_NLM) /* _STLP_NO_NATIVE_WIDE_FUNCTIONS */
using _STLP_VENDOR_CSTD::wcslen;
using _STLP_VENDOR_CSTD::wcscmp;
using _STLP_VENDOR_CSTD::wcscpy;
using _STLP_VENDOR_CSTD::wcsstr;
using _STLP_VENDOR_CSTD::wcschr;
using _STLP_VENDOR_CSTD::wcsrchr;
using _STLP_VENDOR_CSTD::wcspbrk;
#    endif /* _STLP_NO_NATIVE_WIDE_FUNCTIONS */
_STLP_END_NAMESPACE

#  endif /* _STLP_IMPORT_VENDOR_CSTD */

#  undef _STLP_WCHAR_SUNPRO_EXCLUDE
#  undef _STLP_WCHAR_MSL_EXCLUDE

#  endif /* !defined(_STLP_WINCE) && !defined(_STLP_WCE_EVC3) */

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

#endif /* _STLP_CWCHAR */


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