X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/70f2e88c6b16abd31645049db8d6d76540fcd3de..1d73f41603de8103218a8460792f244230c6a7b1:/src/common/wxchar.cpp?ds=sidebyside diff --git a/src/common/wxchar.cpp b/src/common/wxchar.cpp index bca67b1228..d8772fce24 100644 --- a/src/common/wxchar.cpp +++ b/src/common/wxchar.cpp @@ -6,10 +6,10 @@ // Created: 09/04/99 // RCS-ID: $Id$ // Copyright: (c) wxWindows copyright -// Licence: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "wxchar.h" #endif @@ -30,8 +30,13 @@ #include #include #include -#include + +#ifndef __WXWINCE__ #include +#include +#else +#include "wx/msw/wince/time.h" +#endif #ifndef WX_PRECOMP #include "wx/defs.h" @@ -47,49 +52,73 @@ #include #endif +#if defined(__MWERKS__) && __MSL__ >= 0x6000 +using namespace std ; +#endif + +#ifdef __WXMAC__ + #include "wx/mac/private.h" +#endif + #if wxUSE_WCHAR_T size_t WXDLLEXPORT wxMB2WC(wchar_t *buf, const char *psz, size_t n) { + // assume that we have mbsrtowcs() too if we have wcsrtombs() +#if HAVE_WCSRTOMBS + mbstate_t mbstate; + memset(&mbstate, 0, sizeof(mbstate_t)); +#endif + if (buf) { if (!n || !*psz) { if (n) *buf = wxT('\0'); return 0; } +#ifdef HAVE_WCSRTOMBS + return mbsrtowcs(buf, &psz, n, &mbstate); +#else return mbstowcs(buf, psz, n); +#endif } - // assume that we have mbsrtowcs() too if we have wcsrtombs() #ifdef HAVE_WCSRTOMBS - mbstate_t mbstate; return mbsrtowcs((wchar_t *) NULL, &psz, 0, &mbstate); -#else // !GNU libc +#else return mbstowcs((wchar_t *) NULL, psz, 0); -#endif // GNU +#endif } size_t WXDLLEXPORT wxWC2MB(char *buf, const wchar_t *pwz, size_t n) { +#if HAVE_WCSRTOMBS + mbstate_t mbstate; + memset(&mbstate, 0, sizeof(mbstate_t)); +#endif + if (buf) { if (!n || !*pwz) { // glibc2.1 chokes on null input if (n) *buf = '\0'; return 0; } +#if HAVE_WCSRTOMBS + return wcsrtombs(buf, &pwz, n, &mbstate); +#else return wcstombs(buf, pwz, n); +#endif } #if HAVE_WCSRTOMBS - mbstate_t mbstate; return wcsrtombs((char *) NULL, &pwz, 0, &mbstate); -#else // !GNU libc +#else return wcstombs((char *) NULL, pwz, 0); -#endif // GNU +#endif } #endif // wxUSE_WCHAR_T bool WXDLLEXPORT wxOKlibc() { -#if wxUSE_WCHAR_T && defined(__UNIX__) && defined(__GLIBC__) +#if wxUSE_WCHAR_T && defined(__UNIX__) && defined(__GLIBC__) && !defined(__WINE__) // glibc 2.0 uses UTF-8 even when it shouldn't wchar_t res = 0; if ((MB_CUR_MAX == 2) && @@ -832,7 +861,6 @@ int wxFscanf( FILE *stream, const wxChar *format, ... ) { va_list argptr; va_start(argptr, format); - int ret = vfwscanf(stream, wxFormatConverter(format), argptr); va_end(argptr); @@ -921,6 +949,8 @@ int wxVsprintf( wxChar *str, const wxChar *format, va_list argptr ) #endif // wxNEED_PRINTF_CONVERSION +#if wxUSE_WCHAR_T + // ---------------------------------------------------------------------------- // ctype.h stuff (currently unused) // ---------------------------------------------------------------------------- @@ -948,15 +978,26 @@ WXDLLEXPORT int wxTolower(wxChar ch) { return (wxChar)CharLower((LPTSTR)(ch)); } WXDLLEXPORT int wxToupper(wxChar ch) { return (wxChar)CharUpper((LPTSTR)(ch)); } #endif -#ifndef wxStrdup -WXDLLEXPORT wxChar * wxStrdup(const wxChar *psz) +#ifndef wxStrdupA + +WXDLLEXPORT char *wxStrdupA(const char *s) +{ + return strcpy((char *)malloc(strlen(s) + 1), s); +} + +#endif // wxStrdupA + +#ifndef wxStrdupW + +WXDLLEXPORT wchar_t * wxStrdupW(const wchar_t *pwz) { - size_t size = (wxStrlen(psz) + 1) * sizeof(wxChar); - wxChar *ret = (wxChar *) malloc(size); - memcpy(ret, psz, size); + size_t size = (wxWcslen(pwz) + 1) * sizeof(wchar_t); + wchar_t *ret = (wchar_t *) malloc(size); + memcpy(ret, pwz, size); return ret; } -#endif + +#endif // wxStrdupW #ifndef wxStricmp int WXDLLEXPORT wxStricmp(const wxChar *psz1, const wxChar *psz2) @@ -973,7 +1014,8 @@ int WXDLLEXPORT wxStricmp(const wxChar *psz1, const wxChar *psz2) #ifndef wxStricmp int WXDLLEXPORT wxStrnicmp(const wxChar *s1, const wxChar *s2, size_t n) { - register wxChar c1, c2; + // initialize the variables just to suppress stupid gcc warning + register wxChar c1 = 0, c2 = 0; while (n && ((c1 = wxTolower(*s1)) == (c2 = wxTolower(*s2)) ) && c1) n--, s1++, s2++; if (n) { if (c1 < c2) return -1; @@ -983,39 +1025,6 @@ int WXDLLEXPORT wxStrnicmp(const wxChar *s1, const wxChar *s2, size_t n) } #endif -#ifndef wxStrtok -WXDLLEXPORT wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr) -{ - if (!psz) - { - psz = *save_ptr; - if ( !psz ) - return NULL; - } - - psz += wxStrspn(psz, delim); - if (!*psz) - { - *save_ptr = (wxChar *)NULL; - return (wxChar *)NULL; - } - - wxChar *ret = psz; - psz = wxStrpbrk(psz, delim); - if (!psz) - { - *save_ptr = (wxChar*)NULL; - } - else - { - *psz = wxT('\0'); - *save_ptr = psz + 1; - } - - return ret; -} -#endif // wxStrtok - #ifndef wxSetlocale WXDLLEXPORT wxWCharBuffer wxSetlocale(int category, const wxChar *locale) { @@ -1196,6 +1205,28 @@ WXDLLEXPORT long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base) } #endif // wxNEED_WX_STRING_H +#if defined(__WXMAC__) && !defined(__DARWIN__) && !defined(wxUSE_UNICODE) +WXDLLEXPORT FILE * wxFopen(const wxChar *path, const wxChar *mode) +{ + return fopen( wxMacStringToCString(path), mode ); +} + +WXDLLEXPORT FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream) +{ + return freopen( wxMacStringToCString(path), mode, stream ); +} + +WXDLLEXPORT int wxRemove(const wxChar *path) +{ + return remove( wxMacStringToCString(path) ); +} + +WXDLLEXPORT int wxRename(const wxChar *oldpath, const wxChar *newpath) +{ + return rename( wxMacStringToCString(oldpath), wxMacStringToCString(newpath) ); +} +#endif + #ifdef wxNEED_WX_STDIO_H WXDLLEXPORT FILE * wxFopen(const wxChar *path, const wxChar *mode) { @@ -1229,7 +1260,16 @@ WXDLLEXPORT int wxRename(const wxChar *oldpath, const wxChar *newpath) #ifndef wxAtof double WXDLLEXPORT wxAtof(const wxChar *psz) { - return atof(wxConvLocal.cWX2MB(psz)); +#ifdef __WXWINCE__ + double d; + wxString str(psz); + if (str.ToDouble(& d)) + return d; + else + return 0.0; +#else + return atof(wxConvLocal.cWX2MB(psz)); +#endif } #endif @@ -1283,7 +1323,7 @@ int WXDLLEXPORT wxSystem(const wxChar *psz) return system(wxConvLocal.cWX2MB(psz)); } -#endif +#endif // wxNEED_WX_STDLIB_H #ifdef wxNEED_WX_TIME_H WXDLLEXPORT size_t wxStrftime(wxChar *s, size_t max, const wxChar *fmt, const struct tm *tm) @@ -1305,4 +1345,85 @@ WXDLLEXPORT size_t wxStrftime(wxChar *s, size_t max, const wxChar *fmt, const return 0; } } +#endif // wxNEED_WX_TIME_H + +#endif // wxUSE_WCHAR_T + +// ---------------------------------------------------------------------------- +// functions which we may need even if !wxUSE_WCHAR_T +// ---------------------------------------------------------------------------- + +#ifndef wxStrtok + +WXDLLEXPORT wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr) +{ + if (!psz) + { + psz = *save_ptr; + if ( !psz ) + return NULL; + } + + psz += wxStrspn(psz, delim); + if (!*psz) + { + *save_ptr = (wxChar *)NULL; + return (wxChar *)NULL; + } + + wxChar *ret = psz; + psz = wxStrpbrk(psz, delim); + if (!psz) + { + *save_ptr = (wxChar*)NULL; + } + else + { + *psz = wxT('\0'); + *save_ptr = psz + 1; + } + + return ret; +} + +#endif // wxStrtok + +// ---------------------------------------------------------------------------- +// missing C RTL functions +// ---------------------------------------------------------------------------- + +#if (defined(__MWERKS__) && !defined(__MACH__) && (__MSL__ < 0x00008000)) || \ + defined(__WXWINCE__) +char *strdup(const char *s) +{ + char *dest = (char*) malloc( strlen( s ) + 1 ) ; + if ( dest ) + strcpy( dest , s ) ; + return dest ; +} +#endif + +#if (defined(__MWERKS__) && !defined(__MACH__)) || (defined(__WXWINCE__) && _WIN32_WCE <= 211) + +int isascii( int c ) +{ + return ( c >= 0 && c < 128 ); +} +#endif + +#if defined(__WXWINCE__) +void *calloc( size_t num, size_t size ) +{ + void** ptr = (void **)malloc(num * size); + memset( ptr, 0, num * size); + return ptr; +} + +#if (_WIN32_WCE <= 211) +int isspace(int c) +{ + return (c == ' '); +} +#endif + #endif