+ }
+ else if (ilen == 3) {
+ size_t val = va_arg(argptr, size_t);
+ ::sprintf(s_szScratch, s_szFlags, val);
+ }
+ *this += wxString(s_szScratch);
+ done = TRUE;
+ break;
+ case T('e'):
+ case T('E'):
+ case T('f'):
+ case T('g'):
+ case T('G'):
+ CHECK_PREC
+ s_szFlags[flagofs++] = pszFormat[n];
+ s_szFlags[flagofs] = '\0';
+ if (ilen == 2) {
+ long double val = va_arg(argptr, long double);
+ ::sprintf(s_szScratch, s_szFlags, val);
+ } else {
+ double val = va_arg(argptr, double);
+ ::sprintf(s_szScratch, s_szFlags, val);
+ }
+ *this += wxString(s_szScratch);
+ done = TRUE;
+ break;
+ case T('p'):
+ {
+ void *val = va_arg(argptr, void *);
+ CHECK_PREC
+ s_szFlags[flagofs++] = pszFormat[n];
+ s_szFlags[flagofs] = '\0';
+ ::sprintf(s_szScratch, s_szFlags, val);
+ *this += wxString(s_szScratch);
+ done = TRUE;
+ }
+ break;
+ case T('c'):
+ {
+ wxChar val = va_arg(argptr, int);
+ // we don't need to honor padding here, do we?
+ *this += val;
+ done = TRUE;
+ }
+ break;
+ case T('s'):
+ if (ilen == -1) {
+ // wx extension: we'll let %hs mean non-Unicode strings
+ char *val = va_arg(argptr, char *);
+#if wxUSE_UNICODE
+ // ASCII->Unicode constructor handles max_width right
+ wxString s(val, wxConvLibc, max_width);
+#else
+ size_t len = wxSTRING_MAXLEN;
+ if (val) {
+ for (len = 0; val[len] && (len<max_width); len++);
+ } else val = T("(null)");
+ wxString s(val, len);
+#endif
+ if (s.Len() < min_width)
+ s.Pad(min_width - s.Len(), T(' '), adj_left);
+ *this += s;
+ } else {
+ wxChar *val = va_arg(argptr, wxChar *);
+ size_t len = wxSTRING_MAXLEN;
+ if (val) {
+ for (len = 0; val[len] && (len<max_width); len++);
+ } else val = T("(null)");
+ wxString s(val, len);
+ if (s.Len() < min_width)
+ s.Pad(min_width - s.Len(), T(' '), adj_left);
+ *this += s;
+ }
+ done = TRUE;
+ break;
+ case T('n'):
+ if (ilen == 0) {
+ int *val = va_arg(argptr, int *);
+ *val = Len();
+ }
+ else if (ilen == -1) {
+ short int *val = va_arg(argptr, short int *);
+ *val = Len();
+ }
+ else if (ilen >= 1) {
+ long int *val = va_arg(argptr, long int *);
+ *val = Len();
+ }
+ done = TRUE;
+ break;
+ default:
+ if (wxIsalpha(pszFormat[n]))
+ // probably some flag not taken care of here yet
+ s_szFlags[flagofs++] = pszFormat[n];
+ else {
+ // bad format
+ *this += T('%'); // just to pass the glibc tst-printf.c
+ n--;
+ done = TRUE;
+ }
+ break;
+ }
+#undef CHECK_PREC
+ } while (!done);
+ } else *this += pszFormat[n];
+
+#else
+ // NB: wxVsnprintf() may return either less than the buffer size or -1 if there
+ // is not enough place depending on implementation
+ int iLen = wxVsnprintf(s_szScratch, WXSIZEOF(s_szScratch), pszFormat, argptr);
+ char *buffer;
+ if ( iLen < (int)WXSIZEOF(s_szScratch) ) {
+ buffer = s_szScratch;
+ }
+ else {
+ int size = WXSIZEOF(s_szScratch) * 2;
+ buffer = (char *)malloc(size);
+ while ( buffer != NULL ) {
+ iLen = wxVsnprintf(buffer, WXSIZEOF(s_szScratch), pszFormat, argptr);
+ if ( iLen < size ) {
+ // ok, there was enough space
+ break;
+ }
+
+ // still not enough, double it again
+ buffer = (char *)realloc(buffer, size *= 2);
+ }
+
+ if ( !buffer ) {
+ // out of memory
+ return -1;
+ }
+ }
+
+ wxString s(buffer);
+ *this = s;
+
+ if ( buffer != s_szScratch )
+ free(buffer);