user32: Add support for 64-bit formats in wsprintf.
This commit is contained in:
parent
c63d085d1f
commit
4ec27a632d
|
@ -23,39 +23,93 @@
|
||||||
#include "windef.h"
|
#include "windef.h"
|
||||||
#include "winbase.h"
|
#include "winbase.h"
|
||||||
#include "winuser.h"
|
#include "winuser.h"
|
||||||
|
#include "winnls.h"
|
||||||
|
|
||||||
|
static const struct
|
||||||
|
{
|
||||||
|
const char *fmt;
|
||||||
|
ULONGLONG value;
|
||||||
|
const char *res;
|
||||||
|
} i64_formats[] =
|
||||||
|
{
|
||||||
|
{ "%I64X", ((ULONGLONG)0x12345 << 32) | 0x67890a, "123450067890A" },
|
||||||
|
{ "%I32X", ((ULONGLONG)0x12345 << 32) | 0x67890a, "67890A" },
|
||||||
|
{ "%I64d", (ULONGLONG)543210 * 1000000, "543210000000" },
|
||||||
|
{ "%I64X", (LONGLONG)-0x12345, "FFFFFFFFFFFEDCBB" },
|
||||||
|
{ "%I32x", (LONGLONG)-0x12345, "fffedcbb" },
|
||||||
|
{ "%I64u", (LONGLONG)-123, "18446744073709551493" },
|
||||||
|
{ "%Id", (LONGLONG)-12345, "-12345" },
|
||||||
|
#ifdef _WIN64
|
||||||
|
{ "%Ix", ((ULONGLONG)0x12345 << 32) | 0x67890a, "123450067890a" },
|
||||||
|
{ "%Ix", (LONGLONG)-0x12345, "fffffffffffedcbb" },
|
||||||
|
{ "%p", (LONGLONG)-0x12345, "FFFFFFFFFFFEDCBB" },
|
||||||
|
#else
|
||||||
|
{ "%Ix", ((ULONGLONG)0x12345 << 32) | 0x67890a, "67890a" },
|
||||||
|
{ "%Ix", (LONGLONG)-0x12345, "fffedcbb" },
|
||||||
|
{ "%p", (LONGLONG)-0x12345, "FFFEDCBB" },
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
static void wsprintfATest(void)
|
static void wsprintfATest(void)
|
||||||
{
|
{
|
||||||
char buf[25];
|
char buf[25];
|
||||||
|
unsigned int i;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc=wsprintfA(buf, "%010ld", -1);
|
rc=wsprintfA(buf, "%010ld", -1);
|
||||||
ok(rc == 10, "wsPrintfA length failure: rc=%d error=%d\n",rc,GetLastError());
|
ok(rc == 10, "wsprintfA length failure: rc=%d error=%d\n",rc,GetLastError());
|
||||||
ok((lstrcmpA(buf, "-000000001") == 0),
|
ok((lstrcmpA(buf, "-000000001") == 0),
|
||||||
"wsprintfA zero padded negative value failure: buf=[%s]\n",buf);
|
"wsprintfA zero padded negative value failure: buf=[%s]\n",buf);
|
||||||
|
rc = wsprintfA(buf, "%I64X", (ULONGLONG)0);
|
||||||
|
if (rc == 4 && !lstrcmpA(buf, "I64X"))
|
||||||
|
{
|
||||||
|
win_skip( "I64 formats not supported\n" );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (i = 0; i < sizeof(i64_formats)/sizeof(i64_formats[0]); i++)
|
||||||
|
{
|
||||||
|
rc = wsprintfA(buf, i64_formats[i].fmt, i64_formats[i].value);
|
||||||
|
ok(rc == strlen(i64_formats[i].res), "%u: wsprintfA length failure: rc=%d\n", i, rc);
|
||||||
|
ok(!strcmp(buf, i64_formats[i].res), "%u: wrong result [%s]\n", i, buf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wsprintfWTest(void)
|
static void wsprintfWTest(void)
|
||||||
{
|
{
|
||||||
static const WCHAR fmt[] = {'%','0','1','0','l','d','\0'};
|
static const WCHAR fmt_010ld[] = {'%','0','1','0','l','d','\0'};
|
||||||
static const WCHAR target[] = {'-','0','0','0','0','0','0','0','0','1', '\0'};
|
static const WCHAR res_010ld[] = {'-','0','0','0','0','0','0','0','0','1', '\0'};
|
||||||
WCHAR buf[25];
|
static const WCHAR fmt_I64x[] = {'%','I','6','4','x',0};
|
||||||
|
WCHAR buf[25], fmt[25], res[25];
|
||||||
|
unsigned int i;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc=wsprintfW(buf, fmt, -1);
|
rc=wsprintfW(buf, fmt_010ld, -1);
|
||||||
if (rc==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
|
if (rc==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
|
||||||
{
|
{
|
||||||
win_skip("wsprintfW is not implemented\n");
|
win_skip("wsprintfW is not implemented\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ok(rc == 10, "wsPrintfW length failure: rc=%d error=%d\n",rc,GetLastError());
|
ok(rc == 10, "wsPrintfW length failure: rc=%d error=%d\n",rc,GetLastError());
|
||||||
ok((lstrcmpW(buf, target) == 0),
|
ok((lstrcmpW(buf, res_010ld) == 0),
|
||||||
"wsprintfW zero padded negative value failure\n");
|
"wsprintfW zero padded negative value failure\n");
|
||||||
|
rc = wsprintfW(buf, fmt_I64x, (ULONGLONG)0 );
|
||||||
|
if (rc == 4 && !lstrcmpW(buf, fmt_I64x + 1))
|
||||||
|
{
|
||||||
|
win_skip( "I64 formats not supported\n" );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (i = 0; i < sizeof(i64_formats)/sizeof(i64_formats[0]); i++)
|
||||||
|
{
|
||||||
|
MultiByteToWideChar( CP_ACP, 0, i64_formats[i].fmt, -1, fmt, sizeof(fmt)/sizeof(WCHAR) );
|
||||||
|
MultiByteToWideChar( CP_ACP, 0, i64_formats[i].res, -1, res, sizeof(res)/sizeof(WCHAR) );
|
||||||
|
rc = wsprintfW(buf, fmt, i64_formats[i].value);
|
||||||
|
ok(rc == lstrlenW(res), "%u: wsprintfW length failure: rc=%d\n", i, rc);
|
||||||
|
ok(!lstrcmpW(buf, res), "%u: wrong result [%s]\n", i, wine_dbgstr_w(buf));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test if the CharUpper / CharLower functions return true 16 bit results,
|
/* Test if the CharUpper / CharLower functions return true 16 bit results,
|
||||||
if the input is a 16 bit input value. Up to Wine 11-2003 the input value
|
if the input is a 16 bit input value. */
|
||||||
0xff returns 0xffffffff. */
|
|
||||||
|
|
||||||
static void CharUpperTest(void)
|
static void CharUpperTest(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,6 +43,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(string);
|
||||||
#define WPRINTF_SHORT 0x0010 /* Short arg ('h' prefix) */
|
#define WPRINTF_SHORT 0x0010 /* Short arg ('h' prefix) */
|
||||||
#define WPRINTF_UPPER_HEX 0x0020 /* Upper-case hex ('X' specifier) */
|
#define WPRINTF_UPPER_HEX 0x0020 /* Upper-case hex ('X' specifier) */
|
||||||
#define WPRINTF_WIDE 0x0040 /* Wide arg ('w' prefix) */
|
#define WPRINTF_WIDE 0x0040 /* Wide arg ('w' prefix) */
|
||||||
|
#define WPRINTF_INTPTR 0x0080 /* Pointer-size arg ('I' prefix) */
|
||||||
|
#define WPRINTF_I64 0x0100 /* 64-bit arg ('I64' prefix) */
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
@ -65,11 +67,11 @@ typedef struct
|
||||||
} WPRINTF_FORMAT;
|
} WPRINTF_FORMAT;
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
WCHAR wchar_view;
|
WCHAR wchar_view;
|
||||||
CHAR char_view;
|
CHAR char_view;
|
||||||
LPCSTR lpcstr_view;
|
LPCSTR lpcstr_view;
|
||||||
LPCWSTR lpcwstr_view;
|
LPCWSTR lpcwstr_view;
|
||||||
INT int_view;
|
LONGLONG int_view;
|
||||||
} WPRINTF_DATA;
|
} WPRINTF_DATA;
|
||||||
|
|
||||||
static const CHAR null_stringA[] = "(null)";
|
static const CHAR null_stringA[] = "(null)";
|
||||||
|
@ -111,6 +113,12 @@ static INT WPRINTF_ParseFormatA( LPCSTR format, WPRINTF_FORMAT *res )
|
||||||
if (*p == 'l') { res->flags |= WPRINTF_LONG; p++; }
|
if (*p == 'l') { res->flags |= WPRINTF_LONG; p++; }
|
||||||
else if (*p == 'h') { res->flags |= WPRINTF_SHORT; p++; }
|
else if (*p == 'h') { res->flags |= WPRINTF_SHORT; p++; }
|
||||||
else if (*p == 'w') { res->flags |= WPRINTF_WIDE; p++; }
|
else if (*p == 'w') { res->flags |= WPRINTF_WIDE; p++; }
|
||||||
|
else if (*p == 'I')
|
||||||
|
{
|
||||||
|
if (p[1] == '6' && p[2] == '4') { res->flags |= WPRINTF_I64; p += 3; }
|
||||||
|
else if (p[1] == '3' && p[2] == '2') p += 3;
|
||||||
|
else { res->flags |= WPRINTF_INTPTR; p++; }
|
||||||
|
}
|
||||||
switch(*p)
|
switch(*p)
|
||||||
{
|
{
|
||||||
case 'c':
|
case 'c':
|
||||||
|
@ -133,8 +141,8 @@ static INT WPRINTF_ParseFormatA( LPCSTR format, WPRINTF_FORMAT *res )
|
||||||
res->type = WPR_UNSIGNED;
|
res->type = WPR_UNSIGNED;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
res->width = 8;
|
res->width = 2 * sizeof(void *);
|
||||||
res->flags |= WPRINTF_ZEROPAD;
|
res->flags |= WPRINTF_ZEROPAD | WPRINTF_INTPTR;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case 'X':
|
case 'X':
|
||||||
res->flags |= WPRINTF_UPPER_HEX;
|
res->flags |= WPRINTF_UPPER_HEX;
|
||||||
|
@ -187,7 +195,13 @@ static INT WPRINTF_ParseFormatW( LPCWSTR format, WPRINTF_FORMAT *res )
|
||||||
if (*p == 'l') { res->flags |= WPRINTF_LONG; p++; }
|
if (*p == 'l') { res->flags |= WPRINTF_LONG; p++; }
|
||||||
else if (*p == 'h') { res->flags |= WPRINTF_SHORT; p++; }
|
else if (*p == 'h') { res->flags |= WPRINTF_SHORT; p++; }
|
||||||
else if (*p == 'w') { res->flags |= WPRINTF_WIDE; p++; }
|
else if (*p == 'w') { res->flags |= WPRINTF_WIDE; p++; }
|
||||||
switch((CHAR)*p)
|
else if (*p == 'I')
|
||||||
|
{
|
||||||
|
if (p[1] == '6' && p[2] == '4') { res->flags |= WPRINTF_I64; p += 3; }
|
||||||
|
else if (p[1] == '3' && p[2] == '2') p += 3;
|
||||||
|
else { res->flags |= WPRINTF_INTPTR; p++; }
|
||||||
|
}
|
||||||
|
switch(*p)
|
||||||
{
|
{
|
||||||
case 'c':
|
case 'c':
|
||||||
res->type = (res->flags & WPRINTF_SHORT) ? WPR_CHAR : WPR_WCHAR;
|
res->type = (res->flags & WPRINTF_SHORT) ? WPR_CHAR : WPR_WCHAR;
|
||||||
|
@ -209,8 +223,8 @@ static INT WPRINTF_ParseFormatW( LPCWSTR format, WPRINTF_FORMAT *res )
|
||||||
res->type = WPR_UNSIGNED;
|
res->type = WPR_UNSIGNED;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
res->width = 8;
|
res->width = 2 * sizeof(void *);
|
||||||
res->flags |= WPRINTF_ZEROPAD;
|
res->flags |= WPRINTF_ZEROPAD | WPRINTF_INTPTR;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case 'X':
|
case 'X':
|
||||||
res->flags |= WPRINTF_UPPER_HEX;
|
res->flags |= WPRINTF_UPPER_HEX;
|
||||||
|
@ -255,16 +269,32 @@ static UINT WPRINTF_GetLen( WPRINTF_FORMAT *format, WPRINTF_DATA *arg,
|
||||||
if (len > maxlen) len = maxlen;
|
if (len > maxlen) len = maxlen;
|
||||||
return (format->precision = len);
|
return (format->precision = len);
|
||||||
case WPR_SIGNED:
|
case WPR_SIGNED:
|
||||||
len = sprintf( number, "%d", arg->int_view );
|
|
||||||
break;
|
|
||||||
case WPR_UNSIGNED:
|
case WPR_UNSIGNED:
|
||||||
len = sprintf( number, "%u", (UINT)arg->int_view );
|
|
||||||
break;
|
|
||||||
case WPR_HEXA:
|
case WPR_HEXA:
|
||||||
len = sprintf( number,
|
{
|
||||||
(format->flags & WPRINTF_UPPER_HEX) ? "%X" : "%x",
|
const char *digits = (format->flags & WPRINTF_UPPER_HEX) ? "0123456789ABCDEF" : "0123456789abcdef";
|
||||||
(UINT)arg->int_view);
|
ULONGLONG num = arg->int_view;
|
||||||
|
int base = format->type == WPR_HEXA ? 16 : 10;
|
||||||
|
char buffer[20], *p = buffer, *dst = number;
|
||||||
|
|
||||||
|
if (format->type == WPR_SIGNED && arg->int_view < 0)
|
||||||
|
{
|
||||||
|
*dst++ = '-';
|
||||||
|
num = -arg->int_view;
|
||||||
|
}
|
||||||
|
if (format->flags & WPRINTF_INTPTR) num = (UINT_PTR)num;
|
||||||
|
else if (!(format->flags & WPRINTF_I64)) num = (UINT)num;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
*p++ = digits[num % base];
|
||||||
|
num /= base;
|
||||||
|
} while (num);
|
||||||
|
while (p > buffer) *dst++ = *(--p);
|
||||||
|
*dst = 0;
|
||||||
|
len = dst - number;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -315,7 +345,9 @@ static INT wvsnprintfA( LPSTR buffer, UINT maxlen, LPCSTR spec, __ms_va_list arg
|
||||||
case WPR_HEXA:
|
case WPR_HEXA:
|
||||||
case WPR_SIGNED:
|
case WPR_SIGNED:
|
||||||
case WPR_UNSIGNED:
|
case WPR_UNSIGNED:
|
||||||
argData.int_view = va_arg( args, INT );
|
if (format.flags & WPRINTF_INTPTR) argData.int_view = va_arg(args, INT_PTR);
|
||||||
|
else if (format.flags & WPRINTF_I64) argData.int_view = va_arg(args, LONGLONG);
|
||||||
|
else argData.int_view = va_arg(args, INT);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
argData.wchar_view = 0;
|
argData.wchar_view = 0;
|
||||||
|
@ -418,7 +450,9 @@ static INT wvsnprintfW( LPWSTR buffer, UINT maxlen, LPCWSTR spec, __ms_va_list a
|
||||||
case WPR_HEXA:
|
case WPR_HEXA:
|
||||||
case WPR_SIGNED:
|
case WPR_SIGNED:
|
||||||
case WPR_UNSIGNED:
|
case WPR_UNSIGNED:
|
||||||
argData.int_view = va_arg( args, INT );
|
if (format.flags & WPRINTF_INTPTR) argData.int_view = va_arg(args, INT_PTR);
|
||||||
|
else if (format.flags & WPRINTF_I64) argData.int_view = va_arg(args, LONGLONG);
|
||||||
|
else argData.int_view = va_arg(args, INT);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
argData.wchar_view = 0;
|
argData.wchar_view = 0;
|
||||||
|
|
Loading…
Reference in New Issue