+// ============================================================================
+// printf() functions business
+// ============================================================================
+
+// special test mode: define all functions below even if we don't really need
+// them to be able to test them
+#ifdef wxTEST_PRINTF
+ #undef wxFprintf
+ #undef wxPrintf
+ #undef wxSprintf
+ #undef wxVfprintf
+ #undef wxVsprintf
+ #undef wxVprintf
+ #undef wxVsnprintf_
+ #undef wxSnprintf_
+
+ #define wxNEED_WPRINTF
+
+ int wxVfprintf( FILE *stream, const wxChar *format, va_list argptr );
+#endif
+
+// ----------------------------------------------------------------------------
+// implement [v]snprintf() if the system doesn't provide a safe one
+// or if the system's one does not support positional parameters
+// (very useful for i18n purposes)
+// ----------------------------------------------------------------------------
+
+#if !defined(wxVsnprintf_)
+
+// wxUSE_STRUTILS says our wxVsnprintf_ implementation to use or not to
+// use wxStrlen and wxStrncpy functions over one-char processing loops.
+//
+// Some benchmarking revealed that wxUSE_STRUTILS == 1 has the following
+// effects:
+// -> on Windows:
+// when in ANSI mode, this setting does not change almost anything
+// when in Unicode mode, it gives ~ 50% of slowdown !
+// -> on Linux:
+// both in ANSI and Unicode mode it gives ~ 60% of speedup !
+//
+#if defined(WIN32) && wxUSE_UNICODE
+#define wxUSE_STRUTILS 0
+#else
+#define wxUSE_STRUTILS 1
+#endif
+
+// some limits of our implementation
+#define wxMAX_SVNPRINTF_ARGUMENTS 16
+#define wxMAX_SVNPRINTF_FLAGBUFFER_LEN 32
+#define wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN 512
+
+
+// wxVsnprintf() needs to use a *system* implementation of swnprintf()
+// in order to perform some internal tasks.
+// NB: we cannot just use wxSnprintf() because for some systems it maybe
+// implemented later in this file using wxVsnprintf() and that would
+// result in an endless recursion and thus in a stack overflow
+#if wxUSE_UNICODE
+ #if defined(__WINDOWS__) && !defined(HAVE_SWPRINTF)
+ // all compilers under Windows should have swprintf()
+ #define HAVE_SWPRINTF
+ #endif
+
+ // NB: MSVC 6 has only non-standard swprintf() declaration and while MSVC 7
+ // and 7.1 do have the standard one, it's completely broken unless
+ // /Zc:wchar_t is used while the other one works so use it instead, and
+ // only VC8 has a working standard-compliant swprintf()
+ #if defined(__WXWINCE__) || \
+ (defined(__VISUALC__) && __VISUALC__ < 1400) || \
+ defined(__GNUWIN32__) || \
+ defined(__BORLANDC__)
+ #ifndef HAVE_BROKEN_SWPRINTF_DECL
+ #define HAVE_BROKEN_SWPRINTF_DECL
+ #endif
+ #endif
+
+ // problem: on some systems swprintf takes the 'max' argument while on
+ // others it doesn't
+ #if defined(HAVE_BROKEN_SWPRINTF_DECL)
+ // like when using sprintf(), since 'max' is not used, wxVsnprintf()
+ // should always ensure that 'buff' is big enough for all common needs
+ #define system_sprintf(buff, max, flags, data) \
+ ::swprintf(buff, flags, data)
+
+ #define SYSTEM_SPRINTF_IS_UNSAFE
+ #else
+ #if !defined(HAVE_SWPRINTF)
+ #error wxVsnprintf() needs a system swprintf() implementation!
+ #endif
+
+ #define system_sprintf(buff, max, flags, data) \
+ ::swprintf(buff, max, flags, data)
+ #endif
+#else // !wxUSE_UNICODE
+ #if defined(__VISUALC__) || \
+ (defined(__BORLANDC__) && __BORLANDC__ >= 0x540)
+ #define system_sprintf(buff, max, flags, data) \
+ ::_snprintf(buff, max, flags, data)
+ #elif defined(HAVE_SNPRINTF)
+ #define system_sprintf(buff, max, flags, data) \
+ ::snprintf(buff, max, flags, data)
+ #else // NB: at least sprintf() should always be available
+ // since 'max' is not used in this case, wxVsnprintf() should always
+ // ensure that 'buff' is big enough for all common needs
+ // (see wxMAX_SVNPRINTF_FLAGBUFFER_LEN and wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN)
+ #define system_sprintf(buff, max, flags, data) \
+ ::sprintf(buff, flags, data)
+
+ #define SYSTEM_SPRINTF_IS_UNSAFE
+ #endif
+#endif // wxUSE_UNICODE/!wxUSE_UNICODE
+
+
+
+// the conversion specifiers accepted by wxVsnprintf_
+enum wxPrintfArgType {
+ wxPAT_INVALID = -1,
+
+ wxPAT_INT, // %d, %i, %o, %u, %x, %X
+ wxPAT_LONGINT, // %ld, etc
+#if SIZEOF_LONG_LONG
+ wxPAT_LONGLONGINT, // %Ld, etc
+#endif
+ wxPAT_SIZET, // %Zd, etc
+
+ wxPAT_DOUBLE, // %e, %E, %f, %g, %G
+ wxPAT_LONGDOUBLE, // %le, etc
+
+ wxPAT_POINTER, // %p
+
+ wxPAT_CHAR, // %hc (in ANSI mode: %c, too)
+ wxPAT_WCHAR, // %lc (in Unicode mode: %c, too)
+
+ wxPAT_PCHAR, // %s (related to a char *)
+ wxPAT_PWCHAR, // %s (related to a wchar_t *)
+
+ wxPAT_NINT, // %n
+ wxPAT_NSHORTINT, // %hn
+ wxPAT_NLONGINT // %ln
+};
+
+// an argument passed to wxVsnprintf_
+typedef union {
+ int pad_int; // %d, %i, %o, %u, %x, %X
+ long int pad_longint; // %ld, etc
+#if SIZEOF_LONG_LONG
+ long long int pad_longlongint; // %Ld, etc
+#endif
+ size_t pad_sizet; // %Zd, etc
+
+ double pad_double; // %e, %E, %f, %g, %G
+ long double pad_longdouble; // %le, etc
+
+ void *pad_pointer; // %p
+
+ char pad_char; // %hc (in ANSI mode: %c, too)
+ wchar_t pad_wchar; // %lc (in Unicode mode: %c, too)
+
+ char *pad_pchar; // %s (related to a char *)
+ wchar_t *pad_pwchar; // %s (related to a wchar_t *)
+
+ int *pad_nint; // %n
+ short int *pad_nshortint; // %hn
+ long int *pad_nlongint; // %ln
+} wxPrintfArg;
+
+
+// Contains parsed data relative to a conversion specifier given to
+// wxVsnprintf_ and parsed from the format string
+// NOTE: in C++ there is almost no difference between struct & classes thus
+// there is no performance gain by using a struct here...
+class wxPrintfConvSpec