home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wxos2240.zip / wxWindows-2.4.0 / include / wx / wxchar.h < prev    next >
C/C++ Source or Header  |  2002-11-17  |  31KB  |  823 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name:        wx/wxchar.h
  3. // Purpose:     Declarations common to wx char/wchar_t usage (wide chars)
  4. // Author:      Joel Farley, Ove Kσven
  5. // Modified by: Vadim Zeitlin, Robert Roebling
  6. // Created:     1998/06/12
  7. // RCS-ID:      $Id: wxchar.h,v 1.100.2.4 2002/11/17 10:06:08 MBN Exp $
  8. // Copyright:   (c) 1998-2002 wxWindows dev team
  9. // Licence:     wxWindows licence
  10. /////////////////////////////////////////////////////////////////////////////
  11.  
  12. #ifndef _WX_WXCHAR_H_
  13. #define _WX_WXCHAR_H_
  14.  
  15. #if defined(__GNUG__) && !defined(__APPLE__)
  16.     #pragma interface "wxchar.h"
  17. #endif
  18.  
  19. // ----------------------------------------------------------------------------
  20. // first deal with Unicode setting: wxUSE_UNICODE should be defined as 0 or 1
  21. // and is used by wxWindows, _UNICODE and/or UNICODE may be defined or used by
  22. // the system headers so bring these settings in sync
  23. // ----------------------------------------------------------------------------
  24.  
  25. // set wxUSE_UNICODE to 1 if UNICODE or _UNICODE is defined
  26. #if defined(_UNICODE) || defined(UNICODE)
  27.     #undef wxUSE_UNICODE
  28.     #define wxUSE_UNICODE 1
  29. #else
  30.     #ifndef wxUSE_UNICODE
  31.         #define wxUSE_UNICODE 0
  32.     #endif
  33. #endif // Unicode
  34.  
  35. // and vice versa: define UNICODE and _UNICODE if wxUSE_UNICODE is 1...
  36. #if wxUSE_UNICODE
  37.     #ifndef _UNICODE
  38.         #define _UNICODE
  39.     #endif
  40.     #ifndef UNICODE
  41.         #define UNICODE
  42.     #endif
  43. #endif // Unicode
  44.  
  45. // check whether we have wchar_t
  46. #if !defined(wxUSE_WCHAR_T)
  47.     #if defined(__WIN16__)
  48.         // no wchar_t under Win16 regadrless of compiler used
  49.         #define wxUSE_WCHAR_T 0
  50.     #elif defined(__UNIX__)
  51.         #if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__) || defined(__DARWIN__)
  52.             #define wxUSE_WCHAR_T 1
  53.         #else
  54.             #define wxUSE_WCHAR_T 0
  55.         #endif
  56.     #elif defined(__GNUWIN32__) && !defined(__MINGW32__)
  57.         #define wxUSE_WCHAR_T 0
  58.     #elif defined(__WATCOMC__)
  59.         #define wxUSE_WCHAR_T 0
  60.     #elif defined(__VISAGECPP__) && (__IBMCPP__ < 400)
  61.         #define wxUSE_WCHAR_T 0
  62.     #else
  63.         // add additional compiler checks if this fails
  64.         #define wxUSE_WCHAR_T 1
  65.     #endif
  66. #endif // !defined(wxUSE_WCHAR_T)
  67.  
  68. // Unicode support requires wchar_t
  69. #if wxUSE_UNICODE && !wxUSE_WCHAR_T
  70.     #error "wchar_t must be available in Unicode build"
  71. #endif // Unicode
  72.  
  73. // ----------------------------------------------------------------------------
  74. // standard headers we need here
  75. //
  76. // NB: don't include any wxWindows headers here because almost of them include
  77. //     this one!
  78. // ----------------------------------------------------------------------------
  79.  
  80. // Required for wxPrintf() etc
  81. #include <stdarg.h>
  82.  
  83. // non Unix compilers which do have wchar.h (but not tchar.h which is included
  84. // below and which includes wchar.h anyhow).
  85. // Actually MinGW has tchar.h, but it does not include wchar.h
  86. #if defined(__MWERKS__) || defined(__VISAGECPP__) || defined(__MINGW32__)
  87.     #ifndef HAVE_WCHAR_H
  88.         #define HAVE_WCHAR_H
  89.     #endif
  90. #endif
  91.  
  92. #if wxUSE_WCHAR_T
  93.     #ifdef HAVE_WCHAR_H
  94.         // the current (as of Nov 2002) version of cygwin has a bug in its
  95.         // wchar.h -- there is no extern "C" around the declarations in it and
  96.         // this results in linking errors later; also, at least on some
  97.         // Cygwin versions, wchar.h requires sys/types.h
  98.         #ifdef __CYGWIN__
  99.             #include <sys/types.h>
  100.             extern "C" {
  101.         #endif // Cygwin
  102.                 #include <wchar.h>
  103.         #ifdef __CYGWIN__
  104.             }
  105.         #endif // Cygwin
  106.     #elif defined(HAVE_WCSTR_H)
  107.         // old compilers have relevant declarations here
  108.         #include <wcstr.h>
  109.     #elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__)
  110.         // include stdlib.h for wchar_t
  111.         #include <stdlib.h>
  112.     #endif // HAVE_WCHAR_H
  113. #endif // wxUSE_WCHAR_T
  114.  
  115. // ----------------------------------------------------------------------------
  116. // define wxHAVE_TCHAR_SUPPORT for the compilers which support the TCHAR type
  117. // mapped to either char or wchar_t depending on the ASCII/Unicode mode and have
  118. // the function mapping _tfoo() -> foo() or wfoo()
  119. // ----------------------------------------------------------------------------
  120.  
  121. // VC++ and BC++ starting with 5.2 have TCHAR support
  122. #ifdef __VISUALC__
  123.     #define wxHAVE_TCHAR_SUPPORT
  124. #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
  125.     #define wxHAVE_TCHAR_SUPPORT
  126.     #include <ctype.h>
  127. #elif defined(__MINGW32__) && wxCHECK_W32API_VERSION( 1, 0 )
  128.     #define wxHAVE_TCHAR_SUPPORT
  129.     #include <stddef.h>
  130.     #include <string.h>
  131.     #include <ctype.h>
  132. #elif 0 && defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
  133.     // VZ: the old VisualAge definitions were completely wrong and had no
  134.     //     chance at all to work in Unicode build anyhow so let's pretend that
  135.     //     VisualAge does _not_ support TCHAR for the moment (as indicated by
  136.     //     "0 &&" above) until someone really has time to delve into Unicode
  137.     //     issues under OS/2
  138.  
  139.     // VisualAge 4.0+ supports TCHAR
  140.     #define wxHAVE_TCHAR_SUPPORT
  141. #endif // compilers with (good) TCHAR support
  142.  
  143. #ifdef wxHAVE_TCHAR_SUPPORT
  144.     // get TCHAR definition if we've got it
  145.     #include <tchar.h>
  146.  
  147.     // we surely do have wchar_t if we have TCHAR
  148.     #ifndef wxUSE_WCHAR_T
  149.         #define wxUSE_WCHAR_T 1
  150.     #endif // !defined(wxUSE_WCHAR_T)
  151.  
  152.     // and we also do have wcslen()
  153.     #ifndef HAVE_WCSLEN
  154.         #define HAVE_WCSLEN
  155.     #endif
  156. #endif // wxHAVE_TCHAR_SUPPORT
  157.  
  158. // ----------------------------------------------------------------------------
  159. // define wxChar type
  160. // ----------------------------------------------------------------------------
  161.  
  162. // TODO: define wxCharInt to be equal to either int or wint_t?
  163.  
  164. #if !wxUSE_UNICODE
  165.     typedef char wxChar;
  166.     typedef signed char wxSChar;
  167.     typedef unsigned char wxUChar;
  168. #else // Unicode
  169.     // VZ: note that VC++ defines _T[SU]CHAR simply as wchar_t and not as
  170.     //     signed/unsigned version of it which (a) makes sense to me (unlike
  171.     //     char wchar_t is always unsigned) and (b) was how the previous
  172.     //     definitions worked so keep it like this
  173.  
  174.     // GNU libc has __WCHAR_TYPE__ which requires special treatment, see
  175.     // comment below
  176.     #if !defined(__WCHAR_TYPE__) || \
  177.         (!defined(__GNUC__) || wxCHECK_GCC_VERSION(2, 96))
  178.         // standard case
  179.         typedef wchar_t wxChar;
  180.         typedef wchar_t wxSChar;
  181.         typedef wchar_t wxUChar;
  182.     #else // __WCHAR_TYPE__ and gcc < 2.96
  183.         // VS: wxWindows used to define wxChar as __WCHAR_TYPE__ here. However,
  184.         //     this doesn't work with new GCC 3.x compilers because wchar_t is
  185.         //     C++'s builtin type in the new standard. OTOH, old compilers (GCC
  186.         //     2.x) won't accept new definition of wx{S,U}Char, therefore we
  187.         //     have to define wxChar conditionally depending on detected
  188.         //     compiler & compiler version.
  189.         //     with old definition of wxChar.
  190.         typedef __WCHAR_TYPE__ wxChar;
  191.         typedef __WCHAR_TYPE__ wxSChar;
  192.         typedef __WCHAR_TYPE__ wxUChar;
  193.     #endif // __WCHAR_TYPE__
  194. #endif // ASCII/Unicode
  195.  
  196. // ----------------------------------------------------------------------------
  197. // define _T() and related macros
  198. // ----------------------------------------------------------------------------
  199.  
  200. // BSD systems define _T() to be something different in ctype.h, override it
  201. #if defined(__FreeBSD__) || defined(__DARWIN__)
  202.     #include <ctype.h>
  203.     #undef _T
  204. #endif
  205.  
  206. // could already be defined by tchar.h (it's quasi standard)
  207. #ifndef _T
  208.     #if !wxUSE_UNICODE
  209.         #define _T(x) x
  210.     #else // Unicode
  211.         #define _T(x) L ## x
  212.     #endif // ASCII/Unicode
  213. #endif // !defined(_T)
  214.  
  215. // although global macros with such names are normally bad, we want to have
  216. // another name for _T() which should be used to avoid confusion between _T()
  217. // and _() in wxWindows sources
  218. #define wxT(x)       _T(x)
  219.  
  220. // Unicode-friendly __FILE__, __DATE__ and __TIME__ analogs
  221. #ifndef __TFILE__
  222.     #define __XFILE__(x) wxT(x)
  223.     #define __TFILE__ __XFILE__(__FILE__)
  224. #endif
  225.  
  226. #ifndef __TDATE__
  227.     #define __XDATE__(x) wxT(x)
  228.     #define __TDATE__ __XDATE__(__DATE__)
  229. #endif
  230.  
  231. #ifndef __TTIME__
  232.     #define __XTIME__(x) wxT(x)
  233.     #define __TTIME__ __XTIME__(__TIME__)
  234. #endif
  235.  
  236. // ----------------------------------------------------------------------------
  237. // define wxFoo() function for each standard foo() function whose signature
  238. // (exceptionally including the return type) includes any mention of char:
  239. // wxFoo() is going to be a Unicode-friendly version of foo(), i.e. will have
  240. // the same signature but with char replaced by wxChar which allows us to use
  241. // it in Unicode build as well
  242. // ----------------------------------------------------------------------------
  243.  
  244. #ifdef wxHAVE_TCHAR_SUPPORT
  245.     #include <ctype.h>
  246.  
  247.     // ctype.h functions
  248.     #define  wxIsalnum   _istalnum
  249.     #define  wxIsalpha   _istalpha
  250.     #define  wxIsctrl    _istctrl
  251.     #define  wxIsdigit   _istdigit
  252.     #define  wxIsgraph   _istgraph
  253.     #define  wxIslower   _istlower
  254.     #define  wxIsprint   _istprint
  255.     #define  wxIspunct   _istpunct
  256.     #define  wxIsspace   _istspace
  257.     #define  wxIsupper   _istupper
  258.     #define  wxIsxdigit  _istxdigit
  259.     #define  wxTolower   _totlower
  260.     #define  wxToupper   _totupper
  261.  
  262.     // locale.h functons
  263.     #define  wxSetlocale _tsetlocale
  264.  
  265.     // string.h functions
  266.     #define  wxStrcat    _tcscat
  267.     #define  wxStrchr    _tcschr
  268.     #define  wxStrcmp    _tcscmp
  269.     #define  wxStrcoll   _tcscoll
  270.     #define  wxStrcpy    _tcscpy
  271.     #define  wxStrcspn   _tcscspn
  272.     #define  wxStrdup    _tcsdup
  273.     #define  wxStrftime  _tcsftime
  274.     #define  wxStricmp   _tcsicmp
  275.     #define  wxStrnicmp  _tcsnicmp
  276.     #define  wxStrlen_   _tcslen        // used in wxStrlen inline function
  277.     #define  wxStrncat   _tcsncat
  278.     #define  wxStrncmp   _tcsncmp
  279.     #define  wxStrncpy   _tcsncpy
  280.     #define  wxStrpbrk   _tcspbrk
  281.     #define  wxStrrchr   _tcsrchr
  282.     #define  wxStrspn    _tcsspn
  283.     #define  wxStrstr    _tcsstr
  284.     #define  wxStrtod    _tcstod
  285.     #define  wxStrtol    _tcstol
  286.     #define  wxStrtoul   _tcstoul
  287.     #define  wxStrxfrm   _tcsxfrm
  288.  
  289.     // stdio.h functions
  290.     #define  wxFgetc     _fgettc
  291.     #define  wxFgetchar  _fgettchar
  292.     #define  wxFgets     _fgetts
  293.     #define  wxFopen     _tfopen
  294.     #define  wxFputc     _fputtc
  295.     #define  wxFputchar  _fputtchar
  296.     #define  wxFprintf   _ftprintf
  297.     #define  wxFputs     _fputts
  298.     #define  wxFreopen   _tfreopen
  299.     #define  wxFscanf    _ftscanf
  300.     #define  wxGetc      _gettc
  301.     #define  wxGetchar   _gettchar
  302.     #define  wxGets      _getts
  303.     #define  wxPerror    _tperror
  304.     #define  wxPrintf    _tprintf
  305.     #define  wxPutc      _puttc
  306.     #define  wxPutchar   _puttchar
  307.     #define  wxPuts      _putts
  308.     #define  wxScanf     _tscanf
  309.     #define  wxSprintf   _stprintf
  310.     #define  wxSscanf    _stscanf
  311.     #define  wxTmpnam    _ttmpnam
  312.     #define  wxUngetc    _tungetc
  313.     #define  wxVfprintf  _vftprintf
  314.     #define  wxVprintf   _vtprintf
  315.     #define  wxVsscanf   _vstscanf
  316.     #define  wxVsprintf  _vstprintf
  317.  
  318.     // special case: not all TCHAR-aware compilers have those
  319.     #if defined(__VISUALC__) || \
  320.             (defined(__BORLANDC__) && __BORLANDC__ >= 0x540)
  321.         #define wxVsnprintf_    _vsntprintf
  322.         #define wxSnprintf_     _sntprintf
  323.     #endif
  324.  
  325.     // special case: these functions are missing under Win9x with Unicows so we
  326.     // have to implement them ourselves
  327.     #if wxUSE_UNICODE_MSLU
  328.         #define  wxRemove    wxMSLU__tremove
  329.         #define  wxRename    wxMSLU__trename
  330.     #else
  331.         #define  wxRemove    _tremove
  332.         #define  wxRename    _trename
  333.     #endif
  334.  
  335.     // stdlib.h functions
  336.     #define  wxAtoi      _ttoi
  337.     #define  wxAtol      _ttol
  338.     // #define  wxAtof   _tttof -- notice that there is no such thing (why?)
  339.     #define  wxGetenv    _tgetenv
  340.     #define  wxSystem    _tsystem
  341.  
  342.     // time.h functions
  343.     #define  wxAsctime   _tasctime
  344.     #define  wxCtime     _tctime
  345. #else // !TCHAR-aware compilers
  346.     #if wxUSE_UNICODE
  347.         #include <wctype.h>
  348.  
  349.         // this is probably glibc-specific
  350.         #if defined(__WCHAR_TYPE__)
  351.             // ctype.h functions (wctype.h)
  352.             #define  wxIsalnum   iswalnum
  353.             #define  wxIsalpha   iswalpha
  354.             #define  wxIsctrl    iswcntrl
  355.             #define  wxIsdigit   iswdigit
  356.             #define  wxIsgraph   iswgraph
  357.             #define  wxIslower   iswlower
  358.             #define  wxIsprint   iswprint
  359.             #define  wxIspunct   iswpunct
  360.             #define  wxIsspace   iswspace
  361.             #define  wxIsupper   iswupper
  362.             #define  wxIsxdigit  iswxdigit
  363.  
  364.             #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
  365.                 // /usr/include/wctype.h incorrectly declares translations
  366.                 // tables which provokes tons of compile-time warnings -- try
  367.                 // to correct this
  368.                 #define  wxTolower(wc)   towctrans((wc), (wctrans_t)__ctype_tolower)
  369.                 #define  wxToupper(wc)   towctrans((wc), (wctrans_t)__ctype_toupper)
  370.             #else // !glibc 2.0
  371.                 #define  wxTolower   towlower
  372.                 #define  wxToupper   towupper
  373.             #endif // gcc/!gcc
  374.  
  375.             // string.h functions (wchar.h)
  376.             #define  wxStrcat    wcscat
  377.             #define  wxStrchr    wcschr
  378.             #define  wxStrcmp    wcscmp
  379.             #define  wxStrcoll   wcscoll
  380.             #define  wxStrcpy    wcscpy
  381.             #define  wxStrcspn   wcscspn
  382.             #define  wxStrlen_   wxWcslen // wxStrlen_() is used in wxStrlen()
  383.             #define  wxStrncat   wcsncat
  384.             #define  wxStrncmp   wcsncmp
  385.             #define  wxStrncpy   wcsncpy
  386.             #define  wxStrpbrk   wcspbrk
  387.             #define  wxStrrchr   wcsrchr
  388.             #define  wxStrspn    wcsspn
  389.             #define  wxStrstr    wcsstr
  390.             #define  wxStrtod    wcstod
  391.             #define  wxStrtol    wcstol
  392.             #define  wxStrtoul   wcstoul
  393.             #define  wxStrxfrm   wcsxfrm
  394.  
  395.             #define  wxFgetc     fgetwc
  396.             #define  wxFgetchar  fgetwchar
  397.             #define  wxFgets     fgetws
  398.             #define  wxFputc     fputwc
  399.             #define  wxFputchar  fputwchar
  400.             #define  wxGetc      getwc
  401.             #define  wxGetchar   getwchar
  402.             #define  wxGets      getws
  403.             #define  wxUngetc    ungetwc
  404.  
  405.             #ifdef HAVE_FPUTWC
  406.                 #define  wxPutc      wputc
  407.                 #define  wxPutchar   wputchar
  408.                 #define  wxPuts      putws
  409.                 #define  wxFputs     fputws
  410.             #else
  411.                 #define wxNEED_FPUTWC
  412.  
  413.                 #include <stdio.h>
  414.  
  415.                 int wxFputs(const wxChar *ch, FILE *stream);
  416.                 int wxPutc(wxChar ch, FILE *stream);
  417.  
  418.                 #define wxPuts(ws) wxFputs(ws, stdout)
  419.                 #define wxPutchar(wch) wxPutc(wch, stdout)
  420.             #endif
  421.  
  422.             // we need %s to %ls conversion for printf and scanf etc
  423.             #define wxNEED_PRINTF_CONVERSION
  424.  
  425.             // glibc doesn't have wide char equivalents of the other stuff so
  426.             // use our own versions
  427.             #define wxNEED_WX_STDIO_H
  428.             #define wxNEED_WX_STDLIB_H
  429.             #define wxNEED_WX_TIME_H
  430.         #else // !glibc
  431.             #error  "Please define wide character functions for your environment"
  432.         #endif
  433.     #else // ASCII
  434.         #include <ctype.h>
  435.         #include <string.h>
  436.  
  437.         // ctype.h functions
  438.         #define  wxIsalnum   isalnum
  439.         #define  wxIsalpha   isalpha
  440.         #define  wxIsctrl    isctrl
  441.         #define  wxIsdigit   isdigit
  442.         #define  wxIsgraph   isgraph
  443.         #define  wxIslower   islower
  444.         #define  wxIsprint   isprint
  445.         #define  wxIspunct   ispunct
  446.         #define  wxIsspace   isspace
  447.         #define  wxIsupper   isupper
  448.         #define  wxIsxdigit  isxdigit
  449.         #define  wxTolower   tolower
  450.         #define  wxToupper   toupper
  451.  
  452.          // locale.h functons
  453.         #define  wxSetlocale setlocale
  454.  
  455.          // string.h functions
  456.         #define  wxStrcat    strcat
  457.         #define  wxStrchr    strchr
  458.         #define  wxStrcmp    strcmp
  459.         #define  wxStrcoll   strcoll
  460.         #define  wxStrcpy    strcpy
  461.         #define  wxStrcspn   strcspn
  462.         #if !defined(__MWERKS__) || !defined(__WXMAC__)
  463.             #define  wxStrdup    strdup
  464.         #endif
  465.         // wxStricmp and wxStrnicmp are defined below
  466.         #define  wxStrlen_   strlen // used in wxStrlen inline function
  467.         #define  wxStrncat   strncat
  468.         #define  wxStrncmp   strncmp
  469.         #define  wxStrncpy   strncpy
  470.         #define  wxStrpbrk   strpbrk
  471.         #define  wxStrrchr   strrchr
  472.         #define  wxStrspn    strspn
  473.         #define  wxStrstr    strstr
  474.         #define  wxStrtod    strtod
  475.         #ifdef HAVE_STRTOK_R
  476.             #define  wxStrtok(str, sep, last)    strtok_r(str, sep, last)
  477.         #endif
  478.         #define  wxStrtol    strtol
  479.         #define  wxStrtoul   strtoul
  480.         #define  wxStrxfrm   strxfrm
  481.  
  482.         // stdio.h functions
  483.         #define  wxFopen     fopen
  484.         #define  wxFreopen   freopen
  485.         #define  wxPerror    perror
  486.         #define  wxRemove    remove
  487.         #define  wxRename    rename
  488.         #define  wxTmpnam    tmpnam
  489.  
  490.         #define  wxFgetc     fgetc
  491.         #define  wxFgetchar  fgetchar
  492.         #define  wxFgets     fgets
  493.         #define  wxFputc     fputc
  494.         #define  wxFputchar  fputchar
  495.         #define  wxFprintf   fprintf
  496.         #define  wxFscanf    fscanf
  497.         #define  wxGetc      getc
  498.         #define  wxGetchar   getchar
  499.         #define  wxGets      gets
  500.         #define  wxPrintf    printf
  501.         #define  wxPutc      putc
  502.         #define  wxPutchar   putchar
  503.         #define  wxPuts      puts
  504.         #define  wxScanf     scanf
  505.         #define  wxSprintf   sprintf
  506.         #define  wxSscanf    sscanf
  507.         #define  wxUngetc    ungetc
  508.         #define  wxVfprintf  vfprintf
  509.         #define  wxVprintf   vprintf
  510.         #define  wxVsscanf   vsscanf
  511.         #define  wxVsprintf  vsprintf
  512.  
  513.         // stdlib.h functions
  514.         #define  wxAtof      atof
  515.         #define  wxAtoi      atoi
  516.         #define  wxAtol      atol
  517.         #define  wxGetenv    getenv
  518.         #define  wxSystem    system
  519.  
  520.         // time.h functions
  521.         #define  wxAsctime   asctime
  522.         #define  wxCtime     ctime
  523.         #define  wxStrftime  strftime
  524.     #endif // Unicode/ASCII
  525. #endif // TCHAR-aware compilers/the others
  526.  
  527. // ----------------------------------------------------------------------------
  528. // various special cases
  529. // ----------------------------------------------------------------------------
  530.  
  531. // define wxStricmp and wxStrnicmp for various compilers
  532. //
  533. // note that in Unicode mode we definitely are going to need our own version
  534. #if !defined(wxStricmp) && !wxUSE_UNICODE
  535.     #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
  536.             defined(__SALFORDC__) || defined(__VISAGECPP__) || \
  537.             defined(__EMX__) || defined(__DJGPP__)
  538.         #define wxStricmp stricmp
  539.         #define wxStrnicmp strnicmp
  540.     #elif defined(__SC__) || defined(__VISUALC__) || \
  541.             (defined(__MWERKS__) && defined(__INTEL__))
  542.         #define wxStricmp _stricmp
  543.         #define wxStrnicmp _strnicmp
  544.     #elif defined(__UNIX__) || defined(__GNUWIN32__)
  545.         #define wxStricmp strcasecmp
  546.         #define wxStrnicmp strncasecmp
  547.     // #else -- use wxWindows implementation
  548.     #endif
  549. #endif // !defined(wxStricmp)
  550.  
  551. // define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as
  552. // it's used in wx/buffer.h -- and also might be used just below by wxStrlen()
  553. // when wxStrlen_() is #define'd as wxWcslen so do it before defining wxStrlen)
  554. #if wxUSE_WCHAR_T
  555.     #ifdef HAVE_WCSLEN
  556.         #define wxWcslen wcslen
  557.     #else
  558.         inline size_t wxWcslen(const wchar_t *s)
  559.         {
  560.             size_t n = 0;
  561.             while ( *s++ )
  562.                 n++;
  563.  
  564.             return n;
  565.         }
  566.     #endif
  567. #endif // wxUSE_WCHAR_T
  568.  
  569. // checks whether the passed in pointer is NULL and if the string is empty
  570. inline bool wxIsEmpty(const wxChar *p) { return !p || !*p; }
  571.  
  572. // safe version of strlen() (returns 0 if passed NULL pointer)
  573. inline size_t wxStrlen(const wxChar *psz) { return psz ? wxStrlen_(psz) : 0; }
  574.  
  575. WXDLLEXPORT bool wxOKlibc(); // for internal use
  576.  
  577. // ----------------------------------------------------------------------------
  578. // printf() family saga
  579. // ----------------------------------------------------------------------------
  580.  
  581. /*
  582.    First of all, we always want to define safe snprintf() function to be used
  583.    instead of sprintf(). Some compilers already have it (or rather vsnprintf()
  584.    which we really need...), otherwise we implement it using our own printf()
  585.    code.
  586.  
  587.    We define function with a trailing underscore here because the real one is a
  588.    wrapper around it as explained below
  589.  */
  590. #ifndef wxVsnprintf_
  591.     #if wxUSE_UNICODE
  592.         #if defined(HAVE__VSNWPRINTF)
  593.             #define wxVsnprintf_    _vsnwprintf
  594.         /* MinGW?MSVCRT has the wrong vswprintf */
  595.         #elif defined(HAVE_VSWPRINTF) && !defined(__MINGW32__)
  596.             #define wxVsnprintf_    vswprintf
  597.         #endif
  598.     #else // ASCII
  599.         // all versions of CodeWarrior supported by wxWindows apparently have
  600.         // vsnprintf()
  601.         #if defined(HAVE_VSNPRINTF) || defined(__MWERKS__)
  602.             // assume we have snprintf() too if we have vsnprintf()
  603.             #define wxVsnprintf_    vsnprintf
  604.             #define wxSnprintf_     snprintf
  605.         #endif
  606.     #endif
  607. #endif // wxVsnprintf_ not defined yet
  608.  
  609. #ifndef wxSnprintf_
  610.     // no [v]snprintf(), cook our own
  611.     WXDLLEXPORT int wxSnprintf_(wxChar *buf, size_t len, const wxChar *format,
  612.                                 ...) ATTRIBUTE_PRINTF_3;
  613. #endif
  614. #ifndef wxVsnprintf_
  615.     WXDLLEXPORT int wxVsnprintf_(wxChar *buf, size_t len, const wxChar *format,
  616.                                  va_list argptr);
  617. #endif
  618.  
  619. /*
  620.    In Unicode mode we need to have all standard functions such as wprintf() and
  621.    so on but not all systems have them so use our own implementations in this
  622.    case.
  623.  */
  624. #if wxUSE_UNICODE && !defined(wxHAVE_TCHAR_SUPPORT) && !defined(HAVE_WPRINTF)
  625.     #define wxNEED_WPRINTF
  626. #endif
  627.  
  628. /*
  629.    More Unicode complications: although both ANSI C and C++ define a number of
  630.    wide character functions such as wprintf(), not all environments have them.
  631.    Worse, those which do have different behaviours: under Windows, %s format
  632.    specifier changes its meaning in Unicode build and expects a Unicode string
  633.    while under Unix/POSIX it still means an ASCII string even for wprintf() and
  634.    %ls has to be used for wide strings.
  635.  
  636.    We choose to always emulate Windows behaviour as more useful for us so even
  637.    if we have wprintf() we still must wrap it in a non trivial wxPrintf().
  638.  
  639.    However, if we don't have any vswprintf() at all we don't need to redefine
  640.    anything as our own wxVsnprintf_() already behaves as needed.
  641. */
  642. #ifndef wxVsnprintf_
  643.     #undef wxNEED_PRINTF_CONVERSION
  644. #endif
  645.  
  646. #if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
  647.     // we need to implement all wide character printf and scanf functions
  648.     // either because we don't have them at all or because they don't have the
  649.     // semantics we need
  650.  
  651.     #include <stdio.h>  // for FILE
  652.  
  653.     int wxScanf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
  654.     int wxSscanf( const wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
  655.     int wxFscanf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
  656.     int wxVsscanf( const wxChar *str, const wxChar *format, va_list ap );
  657.     int wxPrintf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
  658.     int wxSprintf( wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
  659.     int wxFprintf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
  660.     int wxVfprintf( FILE *stream, const wxChar *format, va_list ap );
  661.     int wxVprintf( const wxChar *format, va_list ap );
  662.     int wxVsprintf( wxChar *str, const wxChar *format, va_list ap );
  663. #endif // wxNEED_PRINTF_CONVERSION
  664.  
  665. // these 2 can be simply mapped to the versions with underscore at the end
  666. // if we don't have to do the conversion
  667. #ifdef wxNEED_PRINTF_CONVERSION
  668.     int wxSnprintf( wxChar *str, size_t size, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3;
  669.     int wxVsnprintf( wxChar *str, size_t size, const wxChar *format, va_list ap );
  670. #else
  671.     #define wxSnprintf wxSnprintf_
  672.     #define wxVsnprintf wxVsnprintf_
  673. #endif
  674.  
  675. // ----------------------------------------------------------------------------
  676. // various functions which might not be available in libc and for which we
  677. // provide our own replacements in wxchar.cpp
  678. // ----------------------------------------------------------------------------
  679.  
  680. // ctype.h functions
  681. //
  682. // VZ: note that this is never defined currently
  683. #ifdef wxNEED_WX_CTYPE_H
  684.     WXDLLEXPORT int wxIsalnum(wxChar ch);
  685.     WXDLLEXPORT int wxIsalpha(wxChar ch);
  686.     WXDLLEXPORT int wxIsctrl(wxChar ch);
  687.     WXDLLEXPORT int wxIsdigit(wxChar ch);
  688.     WXDLLEXPORT int wxIsgraph(wxChar ch);
  689.     WXDLLEXPORT int wxIslower(wxChar ch);
  690.     WXDLLEXPORT int wxIsprint(wxChar ch);
  691.     WXDLLEXPORT int wxIspunct(wxChar ch);
  692.     WXDLLEXPORT int wxIsspace(wxChar ch);
  693.     WXDLLEXPORT int wxIsupper(wxChar ch);
  694.     WXDLLEXPORT int wxIsxdigit(wxChar ch);
  695.     WXDLLEXPORT int wxTolower(wxChar ch);
  696.     WXDLLEXPORT int wxToupper(wxChar ch);
  697. #endif // wxNEED_WX_CTYPE_H
  698.  
  699. // under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks
  700. // the file parsing -- this may be true for 5.0 as well, update #ifdef then
  701. #if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
  702.     #undef wxIsspace
  703.     #define wxIsspace(c) ((((unsigned)c) < 128) && isspace(c))
  704. #endif // VC++
  705.  
  706.  
  707. // string.h functions
  708. //
  709. // VZ: this is never defined neither currently
  710. #ifdef wxNEED_WX_STRING_H
  711.     WXDLLEXPORT wxChar * wxStrcat(wxChar *dest, const wxChar *src);
  712.     WXDLLEXPORT const wxChar * wxStrchr(const wxChar *s, wxChar c);
  713.     WXDLLEXPORT wxChar * wxStrchr(wxChar *s, wxChar c)
  714.         { return (wxChar *)wxStrchr((const wxChar *)s, c); }
  715.     WXDLLEXPORT int      wxStrcmp(const wxChar *s1, const wxChar *s2);
  716.     WXDLLEXPORT int      wxStrcoll(const wxChar *s1, const wxChar *s2);
  717.     WXDLLEXPORT wxChar * wxStrcpy(wxChar *dest, const wxChar *src);
  718.     WXDLLEXPORT size_t   wxStrcspn(const wxChar *s, const wxChar *reject);
  719.     WXDLLEXPORT size_t   wxStrlen(const wxChar *s);
  720.     WXDLLEXPORT wxChar * wxStrncat(wxChar *dest, const wxChar *src, size_t n);
  721.     WXDLLEXPORT int      wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n);
  722.     WXDLLEXPORT wxChar * wxStrncpy(wxChar *dest, const wxChar *src, size_t n);
  723.     WXDLLEXPORT const wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept);
  724.     WXDLLEXPORT wxChar * wxStrpbrk(wxChar *s, const wxChar *accept)
  725.         { return (wxChar *)wxStrpbrk((const wxChar *)s, accept); }
  726.     WXDLLEXPORT const wxChar * wxStrrchr(const wxChar *s, wxChar c);
  727.     WXDLLEXPORT wxChar * wxStrrchr(wxChar *s, wxChar c)
  728.         { return (wxChar *)wxStrrchr((const wxChar *)s, c); }
  729.     WXDLLEXPORT size_t   wxStrspn(const wxChar *s, const wxChar *accept);
  730.     WXDLLEXPORT const wxChar * wxStrstr(const wxChar *haystack, const wxChar *needle);
  731.     WXDLLEXPORT wxChar *wxStrstr(wxChar *haystack, const wxChar *needle)
  732.         { return (wxChar *)wxStrstr((const wxChar *)haystack, needle); }
  733.     WXDLLEXPORT double   wxStrtod(const wxChar *nptr, wxChar **endptr);
  734.     WXDLLEXPORT long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base);
  735.     WXDLLEXPORT unsigned long int wxStrtoul(const wxChar *nptr, wxChar **endptr, int base);
  736.     WXDLLEXPORT size_t   wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
  737. #endif // wxNEED_WX_STRING_H
  738.  
  739. #ifndef wxStrdup
  740. WXDLLEXPORT wxChar * wxStrdup(const wxChar *psz);
  741. #endif
  742.  
  743. #ifndef wxStricmp
  744. WXDLLEXPORT int wxStricmp(const wxChar *psz1, const wxChar *psz2);
  745. #endif
  746.  
  747. #ifndef wxStrnicmp
  748. WXDLLEXPORT int wxStrnicmp(const wxChar *psz1, const wxChar *psz2, size_t len);
  749. #endif
  750.  
  751. #ifndef wxStrtok
  752. WXDLLEXPORT wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
  753. #endif
  754.  
  755. #ifndef wxSetlocale
  756. class WXDLLEXPORT wxWCharBuffer;
  757. WXDLLEXPORT wxWCharBuffer wxSetlocale(int category, const wxChar *locale);
  758. #endif
  759.  
  760. // stdio.h functions
  761. #ifdef wxNEED_WX_STDIO_H
  762.     #include <stdio.h>
  763.     WXDLLEXPORT FILE *   wxFopen(const wxChar *path, const wxChar *mode);
  764.     WXDLLEXPORT FILE *   wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream);
  765.     WXDLLEXPORT int      wxRemove(const wxChar *path);
  766.     WXDLLEXPORT int      wxRename(const wxChar *oldpath, const wxChar *newpath);
  767.  
  768.     // *printf() family is handled separately
  769. #endif // wxNEED_WX_STDIO_H
  770.  
  771.  
  772. // stdlib.h functions
  773. #ifndef wxAtof
  774. WXDLLEXPORT double   wxAtof(const wxChar *psz);
  775. #endif
  776.  
  777. #ifdef wxNEED_WX_STDLIB_H
  778. WXDLLEXPORT int      wxAtoi(const wxChar *psz);
  779. WXDLLEXPORT long     wxAtol(const wxChar *psz);
  780. WXDLLEXPORT wxChar * wxGetenv(const wxChar *name);
  781. WXDLLEXPORT int      wxSystem(const wxChar *psz);
  782. #endif
  783.  
  784.  
  785. // time.h functions
  786. #ifdef wxNEED_WX_TIME_H
  787.     WXDLLEXPORT size_t wxStrftime(wxChar *s, size_t max,
  788.                                   const wxChar *fmt, const struct tm *tm);
  789. #endif // wxNEED_WX_TIME_H
  790.  
  791. // ----------------------------------------------------------------------------
  792. // multibyte to wide char conversion functions and macros
  793. // ----------------------------------------------------------------------------
  794.  
  795. #if wxUSE_WCHAR_T
  796.     // multibyte<->widechar conversion
  797.     WXDLLEXPORT size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n);
  798.     WXDLLEXPORT size_t wxWC2MB(char *buf, const wchar_t *psz, size_t n);
  799.  
  800.     #if wxUSE_UNICODE
  801.         #define wxMB2WX wxMB2WC
  802.         #define wxWX2MB wxWC2MB
  803.         #define wxWC2WX wxStrncpy
  804.         #define wxWX2WC wxStrncpy
  805.     #else
  806.         #define wxMB2WX wxStrncpy
  807.         #define wxWX2MB wxStrncpy
  808.         #define wxWC2WX wxWC2MB
  809.         #define wxWX2WC wxMB2WC
  810.     #endif
  811. #else // !wxUSE_UNICODE
  812.     // No wxUSE_WCHAR_T: we have to do something (JACS)
  813.     #define wxMB2WC wxStrncpy
  814.     #define wxWC2MB wxStrncpy
  815.     #define wxMB2WX wxStrncpy
  816.     #define wxWX2MB wxStrncpy
  817.     #define wxWC2WX wxWC2MB
  818.     #define wxWX2WC wxMB2WC
  819. #endif
  820.  
  821. #endif //_WX_WXCHAR_H_
  822.  
  823.