X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/410390cf09515a64f49fbe3e47a9c111a2a0d0e3..dfbb5eff442e9bcabd494f0340553fbf49739b25:/src/common/wxcrt.cpp diff --git a/src/common/wxcrt.cpp b/src/common/wxcrt.cpp index 3c4c5e0d95..55ad0812a8 100644 --- a/src/common/wxcrt.cpp +++ b/src/common/wxcrt.cpp @@ -21,6 +21,7 @@ #endif #include "wx/crt.h" +#include "wx/strconv.h" // wxMBConv::cWC2MB() #define _ISOC9X_SOURCE 1 // to get vsscanf() #define _BSD_SOURCE 1 // to still get strdup() @@ -28,13 +29,25 @@ #include #include #include +#include +#ifdef __SGI__ + // wide character functions are declared in std namespace under IRIX + using namespace std; + + // and this one is only declared if __c99 is defined which is not the case + // for C++ builds, so declare it ourselves + extern "C" int vswscanf(const wchar_t *, const wchar_t *, va_list); +#endif + +#ifndef __WXPALMOS5__ #ifndef __WXWINCE__ #include #include #else #include "wx/msw/wince/time.h" #endif +#endif // !__WXPALMOS5__ #ifndef WX_PRECOMP #include "wx/string.h" @@ -43,6 +56,10 @@ #include "wx/log.h" #endif +#ifdef HAVE_LANGINFO_H + #include +#endif + #ifdef __WXWINCE__ // there is no errno.h under CE apparently #define wxSET_ERRNO(value) @@ -57,8 +74,14 @@ namespace std {} using namespace std ; #endif -#if wxUSE_WCHAR_T -size_t WXDLLEXPORT wxMB2WC(wchar_t *buf, const char *psz, size_t n) +#if defined(__DARWIN__) + #include "wx/osx/core/cfref.h" + #include + #include "wx/osx/core/cfstring.h" + #include +#endif + +WXDLLIMPEXP_BASE size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n) { // assume that we have mbsrtowcs() too if we have wcsrtombs() #ifdef HAVE_WCSRTOMBS @@ -85,13 +108,13 @@ size_t WXDLLEXPORT wxMB2WC(wchar_t *buf, const char *psz, size_t n) // support it (the only currently known example being Metrowerks, see // wx/crt.h) we don't use its mbstowcs() at all #ifdef HAVE_WCSRTOMBS - return mbsrtowcs((wchar_t *) NULL, &psz, 0, &mbstate); + return mbsrtowcs(NULL, &psz, 0, &mbstate); #else - return wxMbstowcs((wchar_t *) NULL, psz, 0); + return wxMbstowcs(NULL, psz, 0); #endif } -size_t WXDLLEXPORT wxWC2MB(char *buf, const wchar_t *pwz, size_t n) +WXDLLIMPEXP_BASE size_t wxWC2MB(char *buf, const wchar_t *pwz, size_t n) { #ifdef HAVE_WCSRTOMBS mbstate_t mbstate; @@ -112,43 +135,49 @@ size_t WXDLLEXPORT wxWC2MB(char *buf, const wchar_t *pwz, size_t n) } #ifdef HAVE_WCSRTOMBS - return wcsrtombs((char *) NULL, &pwz, 0, &mbstate); + return wcsrtombs(NULL, &pwz, 0, &mbstate); #else - return wxWcstombs((char *) NULL, pwz, 0); -#endif -} -#endif // wxUSE_WCHAR_T - -bool WXDLLEXPORT wxOKlibc() -{ -#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) && - (wxMB2WC(&res, "\xdd\xa5", 1) == 1) && - (res==0x765)) { - // this is UTF-8 allright, check whether that's what we want - char *cur_locale = setlocale(LC_CTYPE, NULL); - if ((strlen(cur_locale) < 4) || - (strcasecmp(cur_locale + strlen(cur_locale) - 4, "utf8")) || - (strcasecmp(cur_locale + strlen(cur_locale) - 5, "utf-8"))) { - // nope, don't use libc conversion - return false; - } - } + return wxWcstombs(NULL, pwz, 0); #endif - return true; } char* wxSetlocale(int category, const char *locale) { +#ifdef __WXWINCE__ + // FIXME-CE: there is no setlocale() in CE CRT, use SetThreadLocale()? + wxUnusedVar(category); + wxUnusedVar(locale); + + return NULL; +#else // !__WXWINCE__ +#ifdef __WXMAC__ + char *rv = NULL ; + if ( locale != NULL && locale[0] == 0 ) + { + // the attempt to use newlocale(LC_ALL_MASK, "", NULL); + // here in order to deduce the language along the environment vars rules + // lead to strange crashes later... + + // we have to emulate the behaviour under OS X + wxCFRef userLocaleRef(CFLocaleCopyCurrent()); + wxCFStringRef str(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleLanguageCode))); + wxString langFull = str.AsString()+"_"; + str.reset(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleCountryCode))); + langFull += str.AsString(); + rv = setlocale(category, langFull.c_str()); + } + else + rv = setlocale(category, locale); +#else char *rv = setlocale(category, locale); +#endif if ( locale != NULL /* setting locale, not querying */ && rv /* call was successful */ ) { wxUpdateLocaleIsUtf8(); } return rv; +#endif // __WXWINCE__/!__WXWINCE__ } // ============================================================================ @@ -234,34 +263,19 @@ int /* not wint_t */ wxCRT_FputcW(wchar_t wc, FILE *stream) // TODO: implement the scanf() functions static int vwscanf(const wchar_t *format, va_list argptr) { - wxFAIL_MSG( _T("TODO") ); + wxFAIL_MSG( wxT("TODO") ); return -1; } -static int vswscanf(const wchar_t *ws, const wchar_t *format, va_list argptr) -{ - // The best we can do without proper Unicode support in glibc is to - // convert the strings into MB representation and run ANSI version - // of the function. This doesn't work with %c and %s because of difference - // in size of char and wchar_t, though. - - wxCHECK_MSG( wxStrstr(format, _T("%s")) == NULL, -1, - _T("incomplete vswscanf implementation doesn't allow %s") ); - wxCHECK_MSG( wxStrstr(format, _T("%c")) == NULL, -1, - _T("incomplete vswscanf implementation doesn't allow %c") ); - - return vsscanf(wxConvLibc.cWX2MB(ws), wxConvLibc.cWX2MB(format), argptr); -} - static int vfwscanf(FILE *stream, const wchar_t *format, va_list argptr) { - wxFAIL_MSG( _T("TODO") ); + wxFAIL_MSG( wxT("TODO") ); return -1; } -#define vswprintf wxCRT_VsnprintfW_ +#define vswprintf wxCRT_VsnprintfW static int vfwprintf(FILE *stream, const wchar_t *format, va_list argptr) { @@ -285,220 +299,21 @@ static int vwprintf(const wchar_t *format, va_list argptr) #endif // wxNEED_WPRINTF -#ifdef wxNEED_PRINTF_CONVERSION - -// ---------------------------------------------------------------------------- -// wxFormatConverter: class doing the "%s" -> "%ls" conversion -// ---------------------------------------------------------------------------- - -/* - Here are the gory details. We want to follow the Windows/MS conventions, - that is to have - - In ANSI mode: - - format specifier results in - ----------------------------------- - %c, %hc, %hC char - %lc, %C, %lC wchar_t - - In Unicode mode: - - format specifier results in - ----------------------------------- - %hc, %C, %hC char - %c, %lc, %lC wchar_t - - - while on POSIX systems we have %C identical to %lc and %c always means char - (in any mode) while %lc always means wchar_t, - - So to use native functions in order to get our semantics we must do the - following translations in Unicode mode (nothing to do in ANSI mode): - - wxWidgets specifier POSIX specifier - ---------------------------------------- - - %hc, %C, %hC %c - %c %lc - - - And, of course, the same should be done for %s as well. -*/ - -class wxFormatConverter -{ -public: - wxFormatConverter(const wchar_t *format); - - // notice that we only translated the string if m_fmtOrig == NULL (as set - // by CopyAllBefore()), otherwise we should simply use the original format - operator const wchar_t *() const - { return m_fmtOrig ? m_fmtOrig : m_fmt.c_str(); } - -private: - // copy another character to the translated format: this function does the - // copy if we are translating but doesn't do anything at all if we don't, - // so we don't create the translated format string at all unless we really - // need to (i.e. InsertFmtChar() is called) - wchar_t CopyFmtChar(wchar_t ch) - { - if ( !m_fmtOrig ) - { - // we're translating, do copy - m_fmt += ch; - } - else - { - // simply increase the count which should be copied by - // CopyAllBefore() later if needed - m_nCopied++; - } - - return ch; - } - - // insert an extra character - void InsertFmtChar(wchar_t ch) - { - if ( m_fmtOrig ) - { - // so far we haven't translated anything yet - CopyAllBefore(); - } - - m_fmt += ch; - } - - void CopyAllBefore() - { - wxASSERT_MSG( m_fmtOrig && m_fmt.empty(), _T("logic error") ); - - m_fmt = wxString(m_fmtOrig, m_nCopied); - - // we won't need it any longer - m_fmtOrig = NULL; - } - - static bool IsFlagChar(wchar_t ch) - { - return ch == _T('-') || ch == _T('+') || - ch == _T('0') || ch == _T(' ') || ch == _T('#'); - } - - void SkipDigits(const wchar_t **ptpc) - { - while ( **ptpc >= _T('0') && **ptpc <= _T('9') ) - CopyFmtChar(*(*ptpc)++); - } - - // the translated format - wxString m_fmt; - - // the original format - const wchar_t *m_fmtOrig; - - // the number of characters already copied - size_t m_nCopied; -}; - -wxFormatConverter::wxFormatConverter(const wchar_t *format) +#ifdef wxNEED_VSWSCANF +static int vswscanf(const wchar_t *ws, const wchar_t *format, va_list argptr) { - m_fmtOrig = format; - m_nCopied = 0; - - while ( *format ) - { - if ( CopyFmtChar(*format++) == _T('%') ) - { - // skip any flags - while ( IsFlagChar(*format) ) - CopyFmtChar(*format++); - - // and possible width - if ( *format == _T('*') ) - CopyFmtChar(*format++); - else - SkipDigits(&format); - - // precision? - if ( *format == _T('.') ) - { - CopyFmtChar(*format++); - if ( *format == _T('*') ) - CopyFmtChar(*format++); - else - SkipDigits(&format); - } - - // next we can have a size modifier - enum - { - Default, - Short, - Long - } size; - - switch ( *format ) - { - case _T('h'): - size = Short; - format++; - break; - - case _T('l'): - // "ll" has a different meaning! - if ( format[1] != _T('l') ) - { - size = Long; - format++; - break; - } - //else: fall through - - default: - size = Default; - } - - // and finally we should have the type - switch ( *format ) - { - case _T('C'): - case _T('S'): - // %C and %hC -> %c and %lC -> %lc - if ( size == Long ) - CopyFmtChar(_T('l')); - - InsertFmtChar(*format++ == _T('C') ? _T('c') : _T('s')); - break; - - case _T('c'): - case _T('s'): - // %c -> %lc but %hc stays %hc and %lc is still %lc - if ( size == Default) - InsertFmtChar(_T('l')); - // fall through - - default: - // nothing special to do - if ( size != Default ) - CopyFmtChar(*(format - 1)); - CopyFmtChar(*format++); - } - } - } -} + // The best we can do without proper Unicode support in glibc is to + // convert the strings into MB representation and run ANSI version + // of the function. This doesn't work with %c and %s because of difference + // in size of char and wchar_t, though. -#else // !wxNEED_PRINTF_CONVERSION - // no conversion necessary - #define wxFormatConverter(x) (x) -#endif // wxNEED_PRINTF_CONVERSION/!wxNEED_PRINTF_CONVERSION + wxCHECK_MSG( wxStrstr(format, wxT("%s")) == NULL, -1, + wxT("incomplete vswscanf implementation doesn't allow %s") ); + wxCHECK_MSG( wxStrstr(format, wxT("%c")) == NULL, -1, + wxT("incomplete vswscanf implementation doesn't allow %c") ); -#ifdef __WXDEBUG__ -// For testing the format converter -wxString wxConvertFormat(const wchar_t *format) -{ - return wxString(wxFormatConverter(format)); + return vsscanf(static_cast(wxConvLibc.cWX2MB(ws)), + wxConvLibc.cWX2MB(format), argptr); } #endif @@ -517,7 +332,7 @@ int wxCRT_PrintfW( const wchar_t *format, ... ) va_list argptr; va_start(argptr, format); - int ret = vwprintf( wxFormatConverter(format), argptr ); + int ret = vwprintf( format, argptr ); va_end(argptr); @@ -531,7 +346,7 @@ int wxCRT_FprintfW( FILE *stream, const wchar_t *format, ... ) va_list argptr; va_start( argptr, format ); - int ret = vfwprintf( stream, wxFormatConverter(format), argptr ); + int ret = vfwprintf( stream, format, argptr ); va_end(argptr); @@ -542,48 +357,22 @@ int wxCRT_FprintfW( FILE *stream, const wchar_t *format, ... ) #ifndef wxCRT_VfprintfW int wxCRT_VfprintfW( FILE *stream, const wchar_t *format, va_list argptr ) { - return vfwprintf( stream, wxFormatConverter(format), argptr ); + return vfwprintf( stream, format, argptr ); } #endif #ifndef wxCRT_VprintfW int wxCRT_VprintfW( const wchar_t *format, va_list argptr ) { - return vwprintf( wxFormatConverter(format), argptr ); + return vwprintf( format, argptr ); } #endif -#ifndef wxCRT_VsnprintfW -int wxCRT_VsnprintfW(wchar_t *str, size_t size, const wchar_t *format, va_list argptr ) -{ - return vswprintf( str, size, wxFormatConverter(format), argptr ); -} -#endif // !wxCRT_VsnprintfW - -// FIXME-UTF8: we only implement widechar version of vsnprintf() in wxprint.cpp, -// so this one has to convert the data for now -#ifndef wxCRT_VsnprintfA -int wxCRT_VsnprintfA(char *buf, size_t len, const char *format, va_list argptr) -{ - wxWCharBuffer wbuf(len); - int rt = wxCRT_VsnprintfW(wbuf.data(), len, - (const wchar_t*)wxConvLibc.cMB2WC(format), - argptr); - if ( rt < 0 || rt >= (int)len ) - return rt; - - if ( wxConvLibc.FromWChar(buf, len, wbuf) == wxCONV_FAILED ) - return -1; - - return rt; -} -#endif // !wxCRT_VsnprintfA - #ifndef wxCRT_VsprintfW int wxCRT_VsprintfW( wchar_t *str, const wchar_t *format, va_list argptr ) { // same as for wxSprintf() - return vswprintf(str, INT_MAX / 4, wxFormatConverter(format), argptr); + return vswprintf(str, INT_MAX / 4, format, argptr); } #endif @@ -595,14 +384,14 @@ int wxCRT_ScanfW(const wchar_t *format, ...) #ifdef __VMS #if (__DECCXX_VER >= 70100000) && !defined(__STD_CFRONT) && !defined( __NONAMESPACE_STD ) - int ret = std::vwscanf(wxFormatConverter(format), argptr); + int ret = std::vwscanf(format, argptr); #else - int ret = vwscanf(wxFormatConverter(format), argptr); + int ret = vwscanf(format, argptr); #endif #else - int ret = vwscanf(wxFormatConverter(format), argptr); + int ret = vwscanf(format, argptr); #endif - + va_end(argptr); return ret; @@ -617,12 +406,12 @@ int wxCRT_SscanfW(const wchar_t *str, const wchar_t *format, ...) #ifdef __VMS #if (__DECCXX_VER >= 70100000) && !defined(__STD_CFRONT) && !defined( __NONAMESPACE_STD ) - int ret = std::vswscanf(str, wxFormatConverter(format), argptr); + int ret = std::vswscanf(str, format, argptr); #else - int ret = vswscanf(str, wxFormatConverter(format), argptr); + int ret = vswscanf(str, format, argptr); #endif #else - int ret = vswscanf(str, wxFormatConverter(format), argptr); + int ret = vswscanf(str, format, argptr); #endif va_end(argptr); @@ -638,12 +427,12 @@ int wxCRT_FscanfW(FILE *stream, const wchar_t *format, ...) va_start(argptr, format); #ifdef __VMS #if (__DECCXX_VER >= 70100000) && !defined(__STD_CFRONT) && !defined( __NONAMESPACE_STD ) - int ret = std::vfwscanf(stream, wxFormatConverter(format), argptr); + int ret = std::vfwscanf(stream, format, argptr); #else - int ret = vfwscanf(stream, wxFormatConverter(format), argptr); + int ret = vfwscanf(stream, format, argptr); #endif #else - int ret = vfwscanf(stream, wxFormatConverter(format), argptr); + int ret = vfwscanf(stream, format, argptr); #endif va_end(argptr); @@ -657,12 +446,12 @@ int wxCRT_VsscanfW(const wchar_t *str, const wchar_t *format, va_list argptr) { #ifdef __VMS #if (__DECCXX_VER >= 70100000) && !defined(__STD_CFRONT) && !defined( __NONAMESPACE_STD ) - return std::vswscanf(str, wxFormatConverter(format), argptr); + return std::vswscanf(str, format, argptr); #else - return vswscanf(str, wxFormatConverter(format), argptr); + return vswscanf(str, format, argptr); #endif #else - return vswscanf(str, wxFormatConverter(format), argptr); + return vswscanf(str, format, argptr); #endif } #endif @@ -791,8 +580,11 @@ int wxDoSnprintfUtf8(wchar_t *str, size_t size, const char *format, ...) #if wxUSE_UNICODE +namespace +{ + #if !wxUSE_UTF8_LOCALE_ONLY -static int ConvertStringToBuf(const wxString& s, char *out, size_t outsize) +int ConvertStringToBuf(const wxString& s, char *out, size_t outsize) { const wxWX2WCbuf buf = s.wc_str(); @@ -805,17 +597,25 @@ static int ConvertStringToBuf(const wxString& s, char *out, size_t outsize) #endif // !wxUSE_UTF8_LOCALE_ONLY #if wxUSE_UNICODE_UTF8 -static int ConvertStringToBuf(const wxString& s, wchar_t *out, size_t outsize) +int ConvertStringToBuf(const wxString& s, wchar_t *out, size_t outsize) { const wxWX2WCbuf buf(s.wc_str()); - size_t len = wxWcslen(buf); + size_t len = s.length(); // same as buf length for wchar_t* if ( outsize > len ) + { memcpy(out, buf, (len+1) * sizeof(wchar_t)); - // else: not enough space + } + else // not enough space + { + memcpy(out, buf, (outsize-1) * sizeof(wchar_t)); + out[outsize-1] = 0; + } return len; } #endif // wxUSE_UNICODE_UTF8 +} // anonymous namespace + template static size_t PrintfViaString(T *out, size_t outsize, const wxString& format, va_list argptr) @@ -830,11 +630,11 @@ static size_t PrintfViaString(T *out, size_t outsize, int wxVsprintf(char *str, const wxString& format, va_list argptr) { #if wxUSE_UTF8_LOCALE_ONLY - return vsprintf(str, format.wx_str(), argptr); + return wxCRT_VsprintfA(str, format.wx_str(), argptr); #else #if wxUSE_UNICODE_UTF8 if ( wxLocaleIsUtf8 ) - return vsprintf(str, format.wx_str(), argptr); + return wxCRT_VsprintfA(str, format.wx_str(), argptr); else #endif #if wxUSE_UNICODE @@ -849,7 +649,20 @@ int wxVsprintf(char *str, const wxString& format, va_list argptr) int wxVsprintf(wchar_t *str, const wxString& format, va_list argptr) { #if wxUSE_UNICODE_WCHAR +#ifdef __DMC__ +/* +This fails with a bug similar to +http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=c++.beta&artnum=680 +in DMC 8.49 and 8.50 +I don't see it being used in the wxWidgets sources at present (oct 2007) CE +*/ +#pragma message ( "warning ::::: wxVsprintf(wchar_t *str, const wxString& format, va_list argptr) not yet implemented" ) + wxFAIL_MSG( wxT("TODO") ); + + return -1; +#else return wxCRT_VsprintfW(str, format.wc_str(), argptr); +#endif //DMC #else // wxUSE_UNICODE_UTF8 #if !wxUSE_UTF8_LOCALE_ONLY if ( !wxLocaleIsUtf8 ) @@ -920,7 +733,6 @@ int wxVsnprintf(wchar_t *str, size_t size, const wxString& format, va_list argpt } #endif // wxUSE_UNICODE -#if wxUSE_WCHAR_T // ---------------------------------------------------------------------------- // ctype.h stuff (currently unused) @@ -928,7 +740,7 @@ int wxVsnprintf(wchar_t *str, size_t size, const wxString& format, va_list argpt #ifdef wxNEED_WX_MBSTOWCS -WXDLLEXPORT size_t wxMbstowcs (wchar_t * out, const char * in, size_t outlen) +WXDLLIMPEXP_BASE size_t wxMbstowcs (wchar_t * out, const char * in, size_t outlen) { if (!out) { @@ -950,7 +762,7 @@ WXDLLEXPORT size_t wxMbstowcs (wchar_t * out, const char * in, size_t outlen) return in - origin; } -WXDLLEXPORT size_t wxWcstombs (char * out, const wchar_t * in, size_t outlen) +WXDLLIMPEXP_BASE size_t wxWcstombs (char * out, const wchar_t * in, size_t outlen) { if (!out) { @@ -975,14 +787,14 @@ WXDLLEXPORT size_t wxWcstombs (char * out, const wchar_t * in, size_t outlen) #endif // wxNEED_WX_MBSTOWCS #ifndef wxCRT_StrdupA -WXDLLEXPORT char *wxCRT_StrdupA(const char *s) +WXDLLIMPEXP_BASE char *wxCRT_StrdupA(const char *s) { return strcpy((char *)malloc(strlen(s) + 1), s); } #endif // wxCRT_StrdupA #ifndef wxCRT_StrdupW -WXDLLEXPORT wchar_t * wxCRT_StrdupW(const wchar_t *pwz) +WXDLLIMPEXP_BASE wchar_t * wxCRT_StrdupW(const wchar_t *pwz) { size_t size = (wxWcslen(pwz) + 1) * sizeof(wchar_t); wchar_t *ret = (wchar_t *) malloc(size); @@ -991,8 +803,44 @@ WXDLLEXPORT wchar_t * wxCRT_StrdupW(const wchar_t *pwz) } #endif // wxCRT_StrdupW +#ifndef wxWCHAR_T_IS_WXCHAR16 +size_t wxStrlen(const wxChar16 *s ) +{ + if (!s) return 0; + size_t i=0; + while (*s!=0) { ++i; ++s; }; + return i; +} + +wxChar16* wxStrdup(const wxChar16* s) +{ + size_t size = (wxStrlen(s) + 1) * sizeof(wxChar16); + wxChar16 *ret = (wxChar16*) malloc(size); + memcpy(ret, s, size); + return ret; +} +#endif + +#ifndef wxWCHAR_T_IS_WXCHAR32 +size_t wxStrlen(const wxChar32 *s ) +{ + if (!s) return 0; + size_t i=0; + while (*s!=0) { ++i; ++s; }; + return i; +} + +wxChar32* wxStrdup(const wxChar32* s) +{ + size_t size = (wxStrlen(s) + 1) * sizeof(wxChar32); + wxChar32 *ret = (wxChar32*) malloc(size); + memcpy(ret, s, size); + return ret; +} +#endif + #ifndef wxCRT_StricmpA -int WXDLLEXPORT wxCRT_StricmpA(const char *psz1, const char *psz2) +WXDLLIMPEXP_BASE int wxCRT_StricmpA(const char *psz1, const char *psz2) { register char c1, c2; do { @@ -1004,7 +852,7 @@ int WXDLLEXPORT wxCRT_StricmpA(const char *psz1, const char *psz2) #endif // !defined(wxCRT_StricmpA) #ifndef wxCRT_StricmpW -int WXDLLEXPORT wxCRT_StricmpW(const wchar_t *psz1, const wchar_t *psz2) +WXDLLIMPEXP_BASE int wxCRT_StricmpW(const wchar_t *psz1, const wchar_t *psz2) { register wchar_t c1, c2; do { @@ -1016,7 +864,7 @@ int WXDLLEXPORT wxCRT_StricmpW(const wchar_t *psz1, const wchar_t *psz2) #endif // !defined(wxCRT_StricmpW) #ifndef wxCRT_StrnicmpA -int WXDLLEXPORT wxCRT_StrnicmpA(const char *s1, const char *s2, size_t n) +WXDLLIMPEXP_BASE int wxCRT_StrnicmpA(const char *s1, const char *s2, size_t n) { // initialize the variables just to suppress stupid gcc warning register char c1 = 0, c2 = 0; @@ -1030,7 +878,7 @@ int WXDLLEXPORT wxCRT_StrnicmpA(const char *s1, const char *s2, size_t n) #endif // !defined(wxCRT_StrnicmpA) #ifndef wxCRT_StrnicmpW -int WXDLLEXPORT wxCRT_StrnicmpW(const wchar_t *s1, const wchar_t *s2, size_t n) +WXDLLIMPEXP_BASE int wxCRT_StrnicmpW(const wchar_t *s1, const wchar_t *s2, size_t n) { // initialize the variables just to suppress stupid gcc warning register wchar_t c1 = 0, c2 = 0; @@ -1050,7 +898,7 @@ int WXDLLEXPORT wxCRT_StrnicmpW(const wchar_t *s1, const wchar_t *s2, size_t n) // this (and wxCRT_StrncmpW below) are extern "C" because they are needed // by regex code, the rest isn't needed, so it's not declared as extern "C" #ifndef wxCRT_StrlenW -extern "C" WXDLLEXPORT size_t wxCRT_StrlenW(const wchar_t *s) +extern "C" WXDLLIMPEXP_BASE size_t wxCRT_StrlenW(const wchar_t *s) { size_t n = 0; while ( *s++ ) @@ -1065,19 +913,19 @@ extern "C" WXDLLEXPORT size_t wxCRT_StrlenW(const wchar_t *s) // ---------------------------------------------------------------------------- #ifndef wxCRT_GetenvW -wchar_t* WXDLLEXPORT wxCRT_GetenvW(const wchar_t *name) +WXDLLIMPEXP_BASE wchar_t* wxCRT_GetenvW(const wchar_t *name) { // NB: buffer returned by getenv() is allowed to be overwritten next // time getenv() is called, so it is OK to use static string // buffer to hold the data. - static wxWCharBuffer value((wchar_t*)NULL); + static wxWCharBuffer value; value = wxConvLibc.cMB2WC(getenv(wxConvLibc.cWC2MB(name))); return value.data(); } #endif // !wxCRT_GetenvW #ifndef wxCRT_StrftimeW -WXDLLEXPORT size_t +WXDLLIMPEXP_BASE size_t wxCRT_StrftimeW(wchar_t *s, size_t maxsize, const wchar_t *fmt, const struct tm *tm) { if ( !maxsize ) @@ -1102,8 +950,7 @@ wxCRT_StrftimeW(wchar_t *s, size_t maxsize, const wchar_t *fmt, const struct tm } #endif // !wxCRT_StrftimeW -#endif // wxUSE_WCHAR_T - +#ifdef wxLongLong_t template static wxULongLong_t wxCRT_StrtoullBase(const T* nptr, T** endptr, int base, T* sign) @@ -1114,7 +961,7 @@ wxCRT_StrtoullBase(const T* nptr, T** endptr, int base, T* sign) wxString::const_iterator end = wxstr.end(); // Skip spaces - while ( i != end && wxIsspace(*i) ) i++; + while ( i != end && wxIsspace(*i) ) ++i; // Starts with sign? *sign = wxT(' '); @@ -1124,20 +971,20 @@ wxCRT_StrtoullBase(const T* nptr, T** endptr, int base, T* sign) if ( c == wxT('+') || c == wxT('-') ) { *sign = c; - i++; + ++i; } } // Starts with 0x? if ( i != end && *i == wxT('0') ) { - i++; + ++i; if ( i != end ) { if ( *i == wxT('x') && (base == 16 || base == 0) ) { base = 16; - i++; + ++i; } else { @@ -1148,20 +995,20 @@ wxCRT_StrtoullBase(const T* nptr, T** endptr, int base, T* sign) } } else - i--; + --i; } if ( base == 0 ) base = 10; - for ( ; i != end; i++ ) + for ( ; i != end; ++i ) { unsigned int n; T c = *i; - if ( c >= wxT('0') ) + if ( c >= '0' ) { - if ( c <= wxT('9') ) + if ( c <= '9' ) n = c - wxT('0'); else n = wxTolower(c) - wxT('a') + 10; @@ -1195,7 +1042,7 @@ template static wxULongLong_t wxCRT_DoStrtoull(const T* nptr, T** endptr, int base) { T sign; - wxULongLong_t uval = wxCRT_StrtoullBase(nptr, endptr, base, &sign); + wxULongLong_t uval = ::wxCRT_StrtoullBase(nptr, endptr, base, &sign); if ( sign == wxT('-') ) { @@ -1210,17 +1057,14 @@ template static wxLongLong_t wxCRT_DoStrtoll(const T* nptr, T** endptr, int base) { T sign; - wxULongLong_t uval = wxCRT_StrtoullBase(nptr, endptr, base, &sign); + wxULongLong_t uval = ::wxCRT_StrtoullBase(nptr, endptr, base, &sign); wxLongLong_t val = 0; if ( sign == wxT('-') ) { - if ( uval <= wxULL(wxINT64_MAX+1) ) + if (uval <= (wxULongLong_t)wxINT64_MAX + 1) { - if ( uval == wxULL(wxINT64_MAX+1)) - val = -((wxLongLong_t)wxINT64_MAX) - 1; - else - val = -((wxLongLong_t)uval); + val = -(wxLongLong_t)uval; } else { @@ -1257,8 +1101,10 @@ wxULongLong_t wxCRT_StrtoullW(const wchar_t* nptr, wchar_t** endptr, int base) { return wxCRT_DoStrtoull(nptr, endptr, base); } #endif +#endif // wxLongLong_t + // ---------------------------------------------------------------------------- -// functions which we may need even if !wxUSE_WCHAR_T +// strtok() functions // ---------------------------------------------------------------------------- template @@ -1274,15 +1120,15 @@ static T *wxCRT_DoStrtok(T *psz, const T *delim, T **save_ptr) psz += wxStrspn(psz, delim); if (!*psz) { - *save_ptr = (T *)NULL; - return (T *)NULL; + *save_ptr = NULL; + return NULL; } T *ret = psz; psz = wxStrpbrk(psz, delim); if (!psz) { - *save_ptr = (T*)NULL; + *save_ptr = NULL; } else { @@ -1328,31 +1174,6 @@ void *calloc( size_t num, size_t size ) #endif // __WXWINCE__ <= 211 -#ifdef __WXWINCE__ -int wxCRT_RemoveW(const wchar_t *path) -{ - return ::DeleteFile(path) == 0; -} -#endif - -#ifndef wxCRT_TmpnamW -wchar_t *wxCRT_TmpnamW(wchar_t *s) -{ - // tmpnam_r() returns NULL if s=NULL, do the same - wxCHECK_MSG( s, NULL, "wxTmpnam must be called with a buffer" ); - -#ifndef L_tmpnam - #define L_tmpnam 1024 -#endif - wxCharBuffer buf(L_tmpnam); - tmpnam(buf.data()); - - wxConvLibc.ToWChar(s, L_tmpnam+1, buf.data()); - return s; -} -#endif // !wxCRT_TmpnamW - - // ============================================================================ // wxLocaleIsUtf8 // ============================================================================ @@ -1385,7 +1206,7 @@ static bool wxIsLocaleUtf8() return true; } } -#endif +#endif // HAVE_LANGINFO_H // check if we're running under the "C" locale: it is 7bit subset // of UTF-8, so it can be safely used with the UTF-8 build: @@ -1406,7 +1227,7 @@ void wxUpdateLocaleIsUtf8() #if wxUSE_UTF8_LOCALE_ONLY if ( !wxIsLocaleUtf8() ) { - wxLogFatalError(_T("This program requires UTF-8 locale to run.")); + wxLogFatalError(wxT("This program requires UTF-8 locale to run.")); } #else // !wxUSE_UTF8_LOCALE_ONLY wxLocaleIsUtf8 = wxIsLocaleUtf8(); @@ -1430,9 +1251,11 @@ void wxUpdateLocaleIsUtf8() int wxPuts(const wxString& s) { + // under IRIX putws() takes a non-const argument so use wchar_str() instead + // of wc_str() CALL_ANSI_OR_UNICODE(return, wxCRT_PutsA(s.mb_str()), - wxCRT_PutsW(s.wc_str())); + wxCRT_PutsW(s.wchar_str())); } int wxFputs(const wxString& s, FILE *stream) @@ -1453,6 +1276,8 @@ int wxFputc(const wxUniChar& c, FILE *stream) #endif } +#ifdef wxCRT_PerrorA + void wxPerror(const wxString& s) { #ifdef wxCRT_PerrorW @@ -1464,6 +1289,8 @@ void wxPerror(const wxString& s) #endif } +#endif // wxCRT_PerrorA + wchar_t *wxFgets(wchar_t *s, int size, FILE *stream) { wxCHECK_MSG( s, NULL, "empty buffer passed to wxFgets()" ); @@ -1485,21 +1312,21 @@ wchar_t *wxFgets(wchar_t *s, int size, FILE *stream) // wxScanf() and friends // ---------------------------------------------------------------------------- -#ifndef __VISUALC__ +#ifdef HAVE_VSSCANF // __VISUALC__ and __DMC__ see wx/crt.h int wxVsscanf(const char *str, const char *format, va_list ap) { return wxCRT_VsscanfA(str, format, ap); } int wxVsscanf(const wchar_t *str, const wchar_t *format, va_list ap) { return wxCRT_VsscanfW(str, format, ap); } int wxVsscanf(const wxCharBuffer& str, const char *format, va_list ap) - { return wxCRT_VsscanfA(str, format, ap); } + { return wxCRT_VsscanfA(static_cast(str), format, ap); } int wxVsscanf(const wxWCharBuffer& str, const wchar_t *format, va_list ap) { return wxCRT_VsscanfW(str, format, ap); } int wxVsscanf(const wxString& str, const char *format, va_list ap) - { return wxCRT_VsscanfA(str.mb_str(), format, ap); } + { return wxCRT_VsscanfA(static_cast(str.mb_str()), format, ap); } int wxVsscanf(const wxString& str, const wchar_t *format, va_list ap) { return wxCRT_VsscanfW(str.wc_str(), format, ap); } int wxVsscanf(const wxCStrData& str, const char *format, va_list ap) - { return wxCRT_VsscanfA(str.AsCharBuf(), format, ap); } + { return wxCRT_VsscanfA(static_cast(str.AsCharBuf()), format, ap); } int wxVsscanf(const wxCStrData& str, const wchar_t *format, va_list ap) { return wxCRT_VsscanfW(str.AsWCharBuf(), format, ap); } -#endif // !__VISUALC__ +#endif // HAVE_NO_VSSCANF