+// ----------------------------------------------------------------------------
+// define wxFoo() function for each standard foo() function whose signature
+// (exceptionally including the return type) includes any mention of char:
+// wxFoo() is going to be a Unicode-friendly version of foo(), i.e. will have
+// the same signature but with char replaced by wxChar which allows us to use
+// it in Unicode build as well
+// ----------------------------------------------------------------------------
+
+#ifdef wxHAVE_TCHAR_SUPPORT
+ // ctype.h functions
+ #define wxIsalnum _istalnum
+ #define wxIsalpha _istalpha
+ #define wxIsctrl _istctrl
+ #define wxIsdigit _istdigit
+ #define wxIsgraph _istgraph
+ #define wxIslower _istlower
+ #define wxIsprint _istprint
+ #define wxIspunct _istpunct
+ #define wxIsspace _istspace
+ #define wxIsupper _istupper
+ #define wxIsxdigit _istxdigit
+ #define wxTolower _totlower
+ #define wxToupper _totupper
+
+ // locale.h functons
+ #define wxSetlocale _tsetlocale
+
+ // string.h functions
+ #define wxStrcat _tcscat
+ #define wxStrchr _tcschr
+ #define wxStrcmp _tcscmp
+ #define wxStrcoll _tcscoll
+ #define wxStrcpy _tcscpy
+ #define wxStrcspn _tcscspn
+ #define wxStrftime _tcsftime
+ #define wxStricmp _tcsicmp
+ #define wxStrnicmp _tcsnicmp
+ #define wxStrlen_ _tcslen // used in wxStrlen inline function
+ #define wxStrncat _tcsncat
+ #define wxStrncmp _tcsncmp
+ #define wxStrncpy _tcsncpy
+ #define wxStrpbrk _tcspbrk
+ #define wxStrrchr _tcsrchr
+ #define wxStrspn _tcsspn
+ #define wxStrstr _tcsstr
+ #define wxStrtod _tcstod
+ #define wxStrtol _tcstol
+ #define wxStrtoul _tcstoul
+ #define wxStrxfrm _tcsxfrm
+
+ // stdio.h functions
+ #define wxFgetc _fgettc
+ #define wxFgetchar _fgettchar
+ #define wxFgets _fgetts
+ #define wxFopen _tfopen
+ #define wxFputc _fputtc
+ #define wxFputchar _fputtchar
+ #define wxFprintf _ftprintf
+ #define wxFputs _fputts
+ #define wxFreopen _tfreopen
+ #define wxFscanf _ftscanf
+ #define wxGetc _gettc
+ #define wxGetchar _gettchar
+ #define wxGets _getts
+ #define wxPerror _tperror
+ #define wxPrintf _tprintf
+ #define wxPutc _puttc
+ #define wxPutchar _puttchar
+ #define wxPuts _putts
+ #define wxScanf _tscanf
+ #define wxSprintf _stprintf
+ #define wxSscanf _stscanf
+ #define wxTmpnam _ttmpnam
+ #define wxUngetc _tungetc
+ #define wxVfprintf _vftprintf
+ #define wxVprintf _vtprintf
+ #define wxVsscanf _vstscanf
+ #define wxVsprintf _vstprintf
+
+ // special case: these functions are missing under Win9x with Unicows so we
+ // have to implement them ourselves
+ #if wxUSE_UNICODE_MSLU
+ #define wxRemove wxMSLU__tremove
+ #define wxRename wxMSLU__trename
+ #else
+ #define wxRemove _tremove
+ #define wxRename _trename
+ #endif
+
+ // stdlib.h functions
+ #define wxAtoi _ttoi
+ #define wxAtol _ttol
+ // #define wxAtof _tttof -- notice that there is no such thing (why?)
+ #define wxGetenv _tgetenv
+ #define wxSystem _tsystem
+
+ // time.h functions
+ #define wxAsctime _tasctime
+ #define wxCtime _tctime
+#else // !TCHAR-aware compilers
+ #if wxUSE_UNICODE
+ #include <wctype.h>
+
+ // this is probably glibc-specific
+ #if defined(__WCHAR_TYPE__)
+ // ctype.h functions (wctype.h)
+ #define wxIsalnum iswalnum
+ #define wxIsalpha iswalpha
+ #define wxIsctrl iswcntrl
+ #define wxIsdigit iswdigit
+ #define wxIsgraph iswgraph
+ #define wxIslower iswlower
+ #define wxIsprint iswprint
+ #define wxIspunct iswpunct
+ #define wxIsspace iswspace
+ #define wxIsupper iswupper
+ #define wxIsxdigit iswxdigit
+
+ #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
+ // /usr/include/wctype.h incorrectly declares translations
+ // tables which provokes tons of compile-time warnings -- try
+ // to correct this
+ #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
+ #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
+ #else // !glibc 2.0
+ #define wxTolower towlower
+ #define wxToupper towupper
+ #endif // gcc/!gcc
+
+ // string.h functions (wchar.h)
+ #define wxStrcat wcscat
+ #define wxStrchr wcschr
+ #define wxStrcmp wcscmp
+ #define wxStrcoll wcscoll
+ #define wxStrcpy wcscpy
+ #define wxStrcspn wcscspn
+ #define wxStrlen_ wcslen // used in wxStrlen inline function
+ #define wxStrncat wcsncat
+ #define wxStrncmp wcsncmp
+ #define wxStrncpy wcsncpy
+ #define wxStrpbrk wcspbrk
+ #define wxStrrchr wcsrchr
+ #define wxStrspn wcsspn
+ #define wxStrstr wcsstr
+ #define wxStrtod wcstod
+ #define wxStrtok wcstok
+ #define wxStrtol wcstol
+ #define wxStrtoul wcstoul
+ #define wxStrxfrm wcsxfrm
+
+ #define wxFgetc fgetwc
+ #define wxFgetchar fgetwchar
+ #define wxFgets fgetws
+ #define wxFputc fputwc
+ #define wxFputchar fputwchar
+ #define wxGetc getwc
+ #define wxGetchar getwchar
+ #define wxGets getws
+ #define wxUngetc ungetwc
+
+ #ifdef HAVE_FPUTWC
+ #define wxPutc wputc
+ #define wxPutchar wputchar
+ #define wxPuts putws
+ #define wxFputs fputws
+ #else
+ #define wxNEED_FPUTWC
+
+ #include <stdio.h>
+
+ int wxFputs(const wxChar *ch, FILE *stream);
+ int wxPutc(wxChar ch, FILE *stream);
+
+ #define wxPuts(ws) wxFputs(ws, stdout)
+ #define wxPutchar(wch) wxPutc(wch, stdout)
+ #endif
+
+ // we need %s to %ls conversion for printf and scanf etc
+ #define wxNEED_PRINTF_CONVERSION
+
+ // glibc doesn't have wide char equivalents of the other stuff so
+ // use our own versions
+ #define wxNEED_WX_STDIO_H
+ #define wxNEED_WX_STDLIB_H
+ #define wxNEED_WX_TIME_H
+ #else // !glibc
+ #error "Please define wide character functions for your environment"
+ #endif
+ #else // ASCII
+ #include <ctype.h>
+ #include <string.h>
+
+ // ctype.h functions
+ #define wxIsalnum isalnum
+ #define wxIsalpha isalpha
+ #define wxIsctrl isctrl
+ #define wxIsdigit isdigit
+ #define wxIsgraph isgraph
+ #define wxIslower islower
+ #define wxIsprint isprint
+ #define wxIspunct ispunct
+ #define wxIsspace isspace
+ #define wxIsupper isupper
+ #define wxIsxdigit isxdigit
+ #define wxTolower tolower
+ #define wxToupper toupper
+
+ // locale.h functons
+ #define wxSetlocale setlocale
+
+ // string.h functions
+ #define wxStrcat strcat
+ #define wxStrchr strchr
+ #define wxStrcmp strcmp
+ #define wxStrcoll strcoll
+ #define wxStrcpy strcpy
+ #define wxStrcspn strcspn
+ #if !defined(__MWERKS__) || !defined(__WXMAC__)
+ #define wxStrdup strdup
+ #endif
+ // wxStricmp and wxStrnicmp are defined below
+ #define wxStrlen_ strlen // used in wxStrlen inline function
+ #define wxStrncat strncat
+ #define wxStrncmp strncmp
+ #define wxStrncpy strncpy
+ #define wxStrpbrk strpbrk
+ #define wxStrrchr strrchr
+ #define wxStrspn strspn
+ #define wxStrstr strstr
+ #define wxStrtod strtod
+ #ifdef HAVE_STRTOK_R
+ #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
+ #else
+ #define wxStrtok(str, sep, last) strtok(str, sep)
+ #endif
+ #define wxStrtol strtol
+ #define wxStrtoul strtoul
+ #define wxStrxfrm strxfrm
+
+ // stdio.h functions
+ #define wxFopen fopen
+ #define wxFreopen freopen
+ #define wxPerror perror
+ #define wxRemove remove
+ #define wxRename rename
+ #define wxTmpnam tmpnam
+
+ #define wxFgetc fgetc
+ #define wxFgetchar fgetchar
+ #define wxFgets fgets
+ #define wxFputc fputc
+ #define wxFputchar fputchar
+ #define wxFprintf fprintf
+ #define wxFscanf fscanf
+ #define wxGetc getc
+ #define wxGetchar getchar
+ #define wxGets gets
+ #define wxPrintf printf
+ #define wxPutc putc
+ #define wxPutchar putchar
+ #define wxPuts puts
+ #define wxScanf scanf
+ #define wxSprintf sprintf
+ #define wxSscanf sscanf
+ #define wxUngetc ungetc
+ #define wxVfprintf vfprintf
+ #define wxVprintf vprintf
+ #define wxVsscanf vsscanf
+ #define wxVsprintf vsprintf
+
+ // stdlib.h functions
+ #define wxAtof atof
+ #define wxAtoi atoi
+ #define wxAtol atol
+ #define wxGetenv getenv
+ #define wxSystem system
+
+ // time.h functions
+ #define wxAsctime asctime
+ #define wxCtime ctime
+ #define wxStrftime strftime
+ #endif // Unicode/ASCII
+#endif // TCHAR-aware compilers/the others
+
+// ----------------------------------------------------------------------------
+// various special cases
+// ----------------------------------------------------------------------------
+
+// define wxStricmp and wxStrnicmp for various compilers
+//
+// note that in Unicode mode we definitely are going to need our own version
+#if !defined(wxStricmp) && !wxUSE_UNICODE
+ #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
+ defined(__SALFORDC__) || defined(__VISAGECPP__) || \
+ defined(__EMX__) || defined(__DJGPP__)
+ #define wxStricmp stricmp
+ #define wxStrnicmp strnicmp
+ #elif defined(__SC__) || defined(__VISUALC__) || \
+ (defined(__MWERKS__) && defined(__INTEL__))
+ #define wxStricmp _stricmp
+ #define wxStrnicmp _strnicmp
+ #elif defined(__UNIX__) || defined(__GNUWIN32__)
+ #define wxStricmp strcasecmp
+ #define wxStrnicmp strncasecmp
+ // #else -- use wxWindows implementation
+ #endif
+#endif // !defined(wxStricmp)
+
+// checks whether the passed in pointer is NULL and if the string is empty
+inline bool wxIsEmpty(const wxChar *p) { return !p || !*p; }
+
+// safe version of strlen() (returns 0 if passed NULL pointer)
+inline size_t wxStrlen(const wxChar *psz) { return psz ? wxStrlen_(psz) : 0; }
+
+// define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as
+// it's used in wx/buffer.h)
+#if wxUSE_WCHAR_T
+ #ifdef HAVE_WCSLEN
+ #define wxWcslen wcslen
+ #else
+ inline size_t wxWcslen(const wchar_t *s)
+ {
+ size_t n = 0;
+ while ( *s++ )
+ n++;
+
+ return n;
+ }
+ #endif
+#endif // wxUSE_WCHAR_T
+
+WXDLLEXPORT bool wxOKlibc(); // for internal use
+
+// ----------------------------------------------------------------------------
+// printf() family saga
+// ----------------------------------------------------------------------------
+
+/*
+ First of all, we always want to define safe snprintf() function to be used
+ instead of sprintf(). Some compilers already have it (or rather vsnprintf()
+ which we really need...), otherwise we implement it using our own printf()
+ code.
+
+ We define function with a trailing underscore here because the real one is a
+ wrapper around it as explained below
+ */
+#ifdef wxHAVE_TCHAR_SUPPORT
+ #define wxVsnprintf_ _vsntprintf
+ #define wxSnprintf_ _sntprintf
+#else // !TCHAR
+ #if wxUSE_UNICODE
+ #if defined(HAVE_VSWPRINTF)
+ #define wxVsnprintf_ vswprintf
+ #endif
+ #else // ASCII
+ // all versions of CodeWarrior supported by wxWindows apparently have
+ // vsnprintf()
+ #if defined(HAVE_VSNPRINTF) || defined(__MWERKS__)
+ // assume we have snprintf() too if we have vsnprintf()
+ #define wxVsnprintf_ vsnprintf
+ #define wxSnprintf_ snprintf
+ #endif
+ #endif
+#endif // TCHAR/!TCHAR
+
+#ifndef wxVsnprintf_
+ // no [v]snprintf(), cook our own
+ WXDLLEXPORT int wxSnprintf_(wxChar *buf, size_t len, const wxChar *format,
+ ...) ATTRIBUTE_PRINTF_3;
+ WXDLLEXPORT int wxVsnprintf_(wxChar *buf, size_t len, const wxChar *format,
+ va_list argptr);