]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/wxcrt.cpp
moving things to private headers
[wxWidgets.git] / src / common / wxcrt.cpp
index 4f92e20a3d96f2ef48a67f2e21ba8c943fdec2d0..c50a880767d011c72845fa1c681c3305131341e6 100644 (file)
@@ -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()
 #include <stdlib.h>
 #include <string.h>
 
+#ifndef __WXPALMOS5__
 #ifndef __WXWINCE__
     #include <time.h>
     #include <locale.h>
 #else
     #include "wx/msw/wince/time.h"
 #endif
+#endif // !__WXPALMOS5__
 
 #ifndef WX_PRECOMP
     #include "wx/string.h"
     #include "wx/log.h"
 #endif
 
+#ifdef HAVE_LANGINFO_H
+    #include <langinfo.h>
+#endif
+
 #ifdef __WXWINCE__
     // there is no errno.h under CE apparently
     #define wxSET_ERRNO(value)
@@ -57,6 +64,13 @@ namespace std {}
 using namespace std ;
 #endif
 
+#if defined(__DARWIN__)
+       #include "wx/mac/corefoundation/cfref.h"
+       #include <CoreFoundation/CFLocale.h>
+       #include "wx/mac/corefoundation/cfstring.h"
+    #include <xlocale.h>
+#endif
+
 #if wxUSE_WCHAR_T
 WXDLLIMPEXP_BASE size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n)
 {
@@ -149,7 +163,36 @@ char* wxSetlocale(int category, const char *locale)
 
     return NULL;
 #else // !__WXWINCE__
+#ifdef __WXMAC__
+    char *rv = NULL ;
+    if ( locale != NULL && locale[0] == 0 )
+    {
+        locale_t lt = newlocale(LC_ALL_MASK, "", NULL);
+        if ( lt )
+        {
+            rv = (char*) querylocale( LC_ALL_MASK, lt );
+            freelocale(lt);
+        }
+        if ( rv == NULL || rv[0] == 0  || strcmp( rv , "C" ) == 0 || strcmp( rv, "POSIX" ) == 0 )
+        {
+            // we have to emulate the behaviour under OS X
+            wxCFRef<CFLocaleRef> 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, rv);
+        }
+    }
+    else
+        rv = setlocale(category, locale);
+#else
     char *rv = setlocale(category, locale);
+#endif
     if ( locale != NULL /* setting locale, not querying */ &&
          rv /* call was successful */ )
     {
@@ -240,14 +283,14 @@ int /* not wint_t */ wxCRT_FputcW(wchar_t wc, FILE *stream)
 #ifdef wxNEED_WPRINTF
 
 // TODO: implement the scanf() functions
-int vwscanf(const wchar_t *format, va_list argptr)
+static int vwscanf(const wchar_t *format, va_list argptr)
 {
     wxFAIL_MSG( _T("TODO") );
 
     return -1;
 }
 
-int vswscanf(const wchar_t *ws, const wchar_t *format, va_list argptr)
+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
@@ -262,7 +305,7 @@ int vswscanf(const wchar_t *ws, const wchar_t *format, va_list argptr)
     return vsscanf(wxConvLibc.cWX2MB(ws), wxConvLibc.cWX2MB(format), argptr);
 }
 
-int vfwscanf(FILE *stream, const wchar_t *format, va_list argptr)
+static int vfwscanf(FILE *stream, const wchar_t *format, va_list argptr)
 {
     wxFAIL_MSG( _T("TODO") );
 
@@ -271,7 +314,7 @@ int vfwscanf(FILE *stream, const wchar_t *format, va_list argptr)
 
 #define vswprintf wxCRT_VsnprintfW
 
-int vfwprintf(FILE *stream, const wchar_t *format, va_list argptr)
+static int vfwprintf(FILE *stream, const wchar_t *format, va_list argptr)
 {
     wxString s;
     int rc = s.PrintfV(format, argptr);
@@ -286,7 +329,7 @@ int vfwprintf(FILE *stream, const wchar_t *format, va_list argptr)
     return rc;
 }
 
-int vwprintf(const wchar_t *format, va_list argptr)
+static int vwprintf(const wchar_t *format, va_list argptr)
 {
     return wxCRT_VfprintfW(stdout, format, argptr);
 }
@@ -625,7 +668,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( _T("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 )
@@ -936,9 +992,9 @@ wxCRT_StrtoullBase(const T* nptr, T** endptr, int base, T* sign)
         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;
@@ -1139,7 +1195,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:
@@ -1243,7 +1299,7 @@ wchar_t *wxFgets(wchar_t *s, int size, FILE *stream)
 // wxScanf() and friends
 // ----------------------------------------------------------------------------
 
-#ifndef __VISUALC__
+#ifndef HAVE_NO_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)
@@ -1260,4 +1316,4 @@ int wxVsscanf(const wxCStrData& str, const char *format, va_list ap)
     { return wxCRT_VsscanfA(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