]> git.saurik.com Git - wxWidgets.git/commitdiff
wxSscanf() and friends are now Unicode+ANSI friendly wrappers instead of defines...
authorVáclav Slavík <vslavik@fastmail.fm>
Mon, 4 Jun 2007 12:56:50 +0000 (12:56 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Mon, 4 Jun 2007 12:56:50 +0000 (12:56 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46323 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/wxcrtvararg.h
src/common/wxcrt.cpp

index 99b7df61751800f906969e6dbc005027d63944b4..ab0ca2b12d55f6ca18787756f740fbf57b1ac568 100644 (file)
 #ifdef wxHAVE_TCHAR_SUPPORT
     #define  wxCRT_Fprintf   _ftprintf
     #define  wxCRT_Printf    _tprintf
-    #define  wxCRT_Scanf     _tscanf
-
-    #define  wxCRT_Sscanf    _stscanf
     #define  wxCRT_Vfprintf  _vftprintf
     #define  wxCRT_Vprintf   _vtprintf
-    #define  wxCRT_Vsscanf   _vstscanf
     #define  wxCRT_Vsprintf  _vstprintf
-
+    #define  wxCRT_Vscanf    _vtscanf
+    #define  wxCRT_Vfscanf   _vftscanf
+    #define  wxCRT_Vsscanf   _vstscanf
 #else /* !TCHAR-aware compilers */
 
     #if !wxUSE_UNICODE /* ASCII */
         #define  wxCRT_Fprintf   fprintf
         #define  wxCRT_Fscanf    fscanf
         #define  wxCRT_Printf    printf
-        #define  wxCRT_Scanf     scanf
-        #define  wxCRT_Sscanf    sscanf
         #define  wxCRT_Vfprintf  vfprintf
         #define  wxCRT_Vprintf   vprintf
-        #define  wxCRT_Vsscanf   vsscanf
         #define  wxCRT_Vsprintf  vsprintf
+        #define  wxCRT_Scanf     scanf
+        #define  wxCRT_Sscanf    sscanf
+        #define  wxCRT_Vsscanf   vsscanf
     #endif /* ASCII */
 #endif /* TCHAR-aware compilers/the others */
 
+/* Required for wxScanf() etc. */
+#define wxCRT_VscanfA   vscanf
+#define wxCRT_VsscanfA  vsscanf
+#define wxCRT_VfscanfA  vfscanf
+#define wxCRT_VscanfW   vwscanf
+#define wxCRT_VsscanfW  vswscanf
+#define wxCRT_VfscanfW  vfwscanf
+
 /* printf() family saga */
 
 /*
 
 #if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
     /*
-        we need to implement all wide character printf and scanf functions
-        either because we don't have them at all or because they don't have the
-        semantics we need
+        we need to implement all wide character printf functions either because
+        we don't have them at all or because they don't have the semantics we
+        need
      */
-    int wxCRT_Scanf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
-    int wxCRT_Sscanf( const wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
-    int wxCRT_Fscanf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
-    int wxCRT_Vsscanf( const wxChar *str, const wxChar *format, va_list ap );
     int wxCRT_Printf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
     int wxCRT_Fprintf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
     int wxCRT_Vfprintf( FILE *stream, const wxChar *format, va_list ap );
@@ -379,11 +381,34 @@ wxVsnprintf(wchar_t *str, size_t size, const wxString& format, va_list argptr);
 // vararg-like functions, we just provide both char* and wchar_t* variants
 // of these functions. The type of output variadic arguments for %s must match
 // the type of 'str' and 'format' arguments.
-
-// FIXME-UTF8: actually do it, for now we only have wxChar* variants:
-#define wxScanf   wxCRT_Scanf
-#define wxFscanf  wxCRT_Fscanf
-#define wxSscanf  wxCRT_Sscanf
-#define wxVsscanf wxCRT_Vsscanf
+//
+// For compatibility with earlier wx versions, we also provide wxSscanf()
+// version with the first argument (input string) wxString; for this version,
+// the type of output string values is determined by the type of format string
+// only.
+
+int WXDLLIMPEXP_BASE wxScanf(const char *format, ...);
+int WXDLLIMPEXP_BASE wxScanf(const wchar_t *format, ...);
+
+int WXDLLIMPEXP_BASE wxFscanf(FILE *stream, const char *format, ...);
+int WXDLLIMPEXP_BASE wxFscanf(FILE *stream, const wchar_t *format, ...);
+
+int WXDLLIMPEXP_BASE wxSscanf(const char *str, const char *format, ...);
+int WXDLLIMPEXP_BASE wxSscanf(const wchar_t *str, const wchar_t *format, ...);
+int WXDLLIMPEXP_BASE wxSscanf(const wxCharBuffer& str, const char *format, ...);
+int WXDLLIMPEXP_BASE wxSscanf(const wxWCharBuffer& str, const wchar_t *format, ...);
+int WXDLLIMPEXP_BASE wxSscanf(const wxString& str, const char *format, ...);
+int WXDLLIMPEXP_BASE wxSscanf(const wxString& str, const wchar_t *format, ...);
+int WXDLLIMPEXP_BASE wxSscanf(const wxCStrData& str, const char *format, ...);
+int WXDLLIMPEXP_BASE wxSscanf(const wxCStrData& str, const wchar_t *format, ...);
+
+int WXDLLIMPEXP_BASE wxVsscanf(const char *str, const char *format, va_list ap);
+int WXDLLIMPEXP_BASE wxVsscanf(const wchar_t *str, const wchar_t *format, va_list ap);
+int WXDLLIMPEXP_BASE wxVsscanf(const wxCharBuffer& str, const char *format, va_list ap);
+int WXDLLIMPEXP_BASE wxVsscanf(const wxWCharBuffer& str, const wchar_t *format, va_list ap);
+int WXDLLIMPEXP_BASE wxVsscanf(const wxString& str, const char *format, va_list ap);
+int WXDLLIMPEXP_BASE wxVsscanf(const wxString& str, const wchar_t *format, va_list ap);
+int WXDLLIMPEXP_BASE wxVsscanf(const wxCStrData& str, const char *format, va_list ap);
+int WXDLLIMPEXP_BASE wxVsscanf(const wxCStrData& str, const wchar_t *format, va_list ap);
 
 #endif /* _WX_WXCRTVARARG_H_ */
index a3abc326bf75ea0631364d82ef0793f64f44f10f..f461aa340c7be31056e9be5e3235496b2c289778 100644 (file)
@@ -510,41 +510,6 @@ wxString wxConvertFormat(const wxChar *format)
 
 #if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
 
-int wxCRT_Scanf( const wxChar *format, ... )
-{
-    va_list argptr;
-    va_start(argptr, format);
-
-    int ret = vwscanf(wxFormatConverter(format), argptr );
-
-    va_end(argptr);
-
-    return ret;
-}
-
-int wxCRT_Sscanf( const wxChar *str, const wxChar *format, ... )
-{
-    va_list argptr;
-    va_start(argptr, format);
-
-    int ret = vswscanf( str, wxFormatConverter(format), argptr );
-
-    va_end(argptr);
-
-    return ret;
-}
-
-int wxCRT_Fscanf( FILE *stream, const wxChar *format, ... )
-{
-    va_list argptr;
-    va_start(argptr, format);
-    int ret = vfwscanf(stream, wxFormatConverter(format), argptr);
-
-    va_end(argptr);
-
-    return ret;
-}
-
 int wxCRT_Printf( const wxChar *format, ... )
 {
     va_list argptr;
@@ -569,11 +534,6 @@ int wxCRT_Fprintf( FILE *stream, const wxChar *format, ... )
     return ret;
 }
 
-int wxCRT_Vsscanf( const wxChar *str, const wxChar *format, va_list argptr )
-{
-    return vswscanf( str, wxFormatConverter(format), argptr );
-}
-
 int wxCRT_Vfprintf( FILE *stream, const wxChar *format, va_list argptr )
 {
     return vfwprintf( stream, wxFormatConverter(format), argptr );
@@ -1632,4 +1592,66 @@ void wxUpdateLocaleIsUtf8()
 #endif
 }
 
-#endif // wxUSE_UTF8_LOCALE_ONLY
+#endif // wxUSE_UNICODE_UTF8
+
+// ============================================================================
+// wx wrappers for CRT functions
+// ============================================================================
+
+
+// ----------------------------------------------------------------------------
+// wxScanf() and friends
+// ----------------------------------------------------------------------------
+
+// implement vararg function by calling a vfoo function that takes va_list
+// argument; use "ap" for the va_list argument in "call" expression
+#define IMPL_SCANFUNC(call)         \
+    va_list ap;                     \
+    va_start(ap, format);           \
+    int retval = call;              \
+    va_end(ap);                     \
+    return retval
+
+int wxScanf(const char *format, ...)
+    { IMPL_SCANFUNC( wxCRT_VscanfA(format, ap) ); }
+int wxScanf(const wchar_t *format, ...)
+    { IMPL_SCANFUNC( wxCRT_VscanfW(wxFormatConverter(format), ap) ); }
+
+int wxFscanf(FILE *stream, const char *format, ...)
+    { IMPL_SCANFUNC( wxCRT_VfscanfA(stream, format, ap) ); }
+int wxFscanf(FILE *stream, const wchar_t *format, ...)
+    { IMPL_SCANFUNC( wxCRT_VfscanfW(stream, wxFormatConverter(format), ap) ); }
+
+int wxSscanf(const char *str, const char *format, ...)
+    { IMPL_SCANFUNC( wxCRT_VsscanfA(str, format, ap) ); }
+int wxSscanf(const wchar_t *str, const wchar_t *format, ...)
+    { IMPL_SCANFUNC( wxCRT_VsscanfW(str, wxFormatConverter(format), ap) ); }
+int wxSscanf(const wxCharBuffer& str, const char *format, ...)
+    { IMPL_SCANFUNC( wxCRT_VsscanfA(str, format, ap) ); }
+int wxSscanf(const wxWCharBuffer& str, const wchar_t *format, ...)
+    { IMPL_SCANFUNC( wxCRT_VsscanfW(str, wxFormatConverter(format), ap) ); }
+int wxSscanf(const wxString& str, const char *format, ...)
+    { IMPL_SCANFUNC( wxCRT_VsscanfA(str.mb_str(), format, ap) ); }
+int wxSscanf(const wxString& str, const wchar_t *format, ...)
+    { IMPL_SCANFUNC( wxCRT_VsscanfW(str.wc_str(), wxFormatConverter(format), ap) ); }
+int wxSscanf(const wxCStrData& str, const char *format, ...)
+    { IMPL_SCANFUNC( wxCRT_VsscanfA(str.AsCharBuf(), format, ap) ); }
+int wxSscanf(const wxCStrData& str, const wchar_t *format, ...)
+    { IMPL_SCANFUNC( wxCRT_VsscanfW(str.AsWCharBuf(), wxFormatConverter(format), ap) ); }
+
+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, wxFormatConverter(format), ap); }
+int wxVsscanf(const wxCharBuffer& str, const char *format, va_list ap)
+    { return wxCRT_VsscanfA(str, format, ap); }
+int wxVsscanf(const wxWCharBuffer& str, const wchar_t *format, va_list ap)
+    { return wxCRT_VsscanfW(str, wxFormatConverter(format), ap); }
+int wxVsscanf(const wxString& str, const char *format, va_list ap)
+    { return wxCRT_VsscanfA(str.mb_str(), format, ap); }
+int wxVsscanf(const wxString& str, const wchar_t *format, va_list ap)
+    { return wxCRT_VsscanfW(str.wc_str(), wxFormatConverter(format), ap); }
+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(), wxFormatConverter(format), ap); }