Commit 25d7e0b9 authored by Alexandre Julliard's avatar Alexandre Julliard

user32: Move wsprintf16 to user16.c.

parent 77ab4354
......@@ -132,6 +132,98 @@ static void logfont_32_to_16( const LOGFONTA* font32, LPLOGFONT16 font16 )
lstrcpynA( font16->lfFaceName, font32->lfFaceName, LF_FACESIZE );
}
/***********************************************************************
* Helper for wsprintf16
*/
#define WPRINTF_LEFTALIGN 0x0001 /* Align output on the left ('-' prefix) */
#define WPRINTF_PREFIX_HEX 0x0002 /* Prefix hex with 0x ('#' prefix) */
#define WPRINTF_ZEROPAD 0x0004 /* Pad with zeros ('0' prefix) */
#define WPRINTF_LONG 0x0008 /* Long arg ('l' prefix) */
#define WPRINTF_SHORT 0x0010 /* Short arg ('h' prefix) */
#define WPRINTF_UPPER_HEX 0x0020 /* Upper-case hex ('X' specifier) */
typedef enum
{
WPR_UNKNOWN,
WPR_CHAR,
WPR_STRING,
WPR_SIGNED,
WPR_UNSIGNED,
WPR_HEXA
} WPRINTF_TYPE;
typedef struct
{
UINT flags;
UINT width;
UINT precision;
WPRINTF_TYPE type;
} WPRINTF_FORMAT;
static INT parse_format( LPCSTR format, WPRINTF_FORMAT *res )
{
LPCSTR p = format;
res->flags = 0;
res->width = 0;
res->precision = 0;
if (*p == '-') { res->flags |= WPRINTF_LEFTALIGN; p++; }
if (*p == '#') { res->flags |= WPRINTF_PREFIX_HEX; p++; }
if (*p == '0') { res->flags |= WPRINTF_ZEROPAD; p++; }
while ((*p >= '0') && (*p <= '9')) /* width field */
{
res->width = res->width * 10 + *p - '0';
p++;
}
if (*p == '.') /* precision field */
{
p++;
while ((*p >= '0') && (*p <= '9'))
{
res->precision = res->precision * 10 + *p - '0';
p++;
}
}
if (*p == 'l') { res->flags |= WPRINTF_LONG; p++; }
else if (*p == 'h') { res->flags |= WPRINTF_SHORT; p++; }
switch(*p)
{
case 'c':
case 'C': /* no Unicode in Win16 */
res->type = WPR_CHAR;
break;
case 's':
case 'S':
res->type = WPR_STRING;
break;
case 'd':
case 'i':
res->type = WPR_SIGNED;
break;
case 'u':
res->type = WPR_UNSIGNED;
break;
case 'p':
res->width = 8;
res->flags |= WPRINTF_ZEROPAD;
/* fall through */
case 'X':
res->flags |= WPRINTF_UPPER_HEX;
/* fall through */
case 'x':
res->type = WPR_HEXA;
break;
default: /* unknown format char */
res->type = WPR_UNKNOWN;
p--; /* print format as normal char */
break;
}
return (INT)(p - format) + 1;
}
/**********************************************************************
* InitApp (USER.5)
*/
......@@ -1679,6 +1771,122 @@ BOOL16 WINAPI SetMenuItemBitmaps16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags,
/***********************************************************************
* wvsprintf (USER.421)
*/
INT16 WINAPI wvsprintf16( LPSTR buffer, LPCSTR spec, VA_LIST16 args )
{
WPRINTF_FORMAT format;
LPSTR p = buffer;
UINT i, len, sign;
CHAR number[20];
CHAR char_view = 0;
LPCSTR lpcstr_view = NULL;
INT int_view;
SEGPTR seg_str;
while (*spec)
{
if (*spec != '%') { *p++ = *spec++; continue; }
spec++;
if (*spec == '%') { *p++ = *spec++; continue; }
spec += parse_format( spec, &format );
switch(format.type)
{
case WPR_CHAR:
char_view = VA_ARG16( args, CHAR );
len = format.precision = 1;
break;
case WPR_STRING:
seg_str = VA_ARG16( args, SEGPTR );
if (IsBadReadPtr16( seg_str, 1 )) lpcstr_view = "";
else lpcstr_view = MapSL( seg_str );
if (!lpcstr_view) lpcstr_view = "(null)";
for (len = 0; !format.precision || (len < format.precision); len++)
if (!lpcstr_view[len]) break;
format.precision = len;
break;
case WPR_SIGNED:
if (format.flags & WPRINTF_LONG) int_view = VA_ARG16( args, INT );
else int_view = VA_ARG16( args, INT16 );
len = sprintf( number, "%d", int_view );
break;
case WPR_UNSIGNED:
if (format.flags & WPRINTF_LONG) int_view = VA_ARG16( args, UINT );
else int_view = VA_ARG16( args, UINT16 );
len = sprintf( number, "%u", int_view );
break;
case WPR_HEXA:
if (format.flags & WPRINTF_LONG) int_view = VA_ARG16( args, UINT );
else int_view = VA_ARG16( args, UINT16 );
len = sprintf( number, (format.flags & WPRINTF_UPPER_HEX) ? "%X" : "%x", int_view);
break;
case WPR_UNKNOWN:
continue;
}
if (format.precision < len) format.precision = len;
if (format.flags & WPRINTF_LEFTALIGN) format.flags &= ~WPRINTF_ZEROPAD;
if ((format.flags & WPRINTF_ZEROPAD) && (format.width > format.precision))
format.precision = format.width;
if (format.flags & WPRINTF_PREFIX_HEX) len += 2;
sign = 0;
if (!(format.flags & WPRINTF_LEFTALIGN))
for (i = format.precision; i < format.width; i++) *p++ = ' ';
switch(format.type)
{
case WPR_CHAR:
*p = char_view;
/* wsprintf16 ignores null characters */
if (*p != '\0') p++;
else if (format.width > 1) *p++ = ' ';
else len = 0;
break;
case WPR_STRING:
if (len) memcpy( p, lpcstr_view, len );
p += len;
break;
case WPR_HEXA:
if (format.flags & WPRINTF_PREFIX_HEX)
{
*p++ = '0';
*p++ = (format.flags & WPRINTF_UPPER_HEX) ? 'X' : 'x';
len -= 2;
}
/* fall through */
case WPR_SIGNED:
/* Transfer the sign now, just in case it will be zero-padded*/
if (number[0] == '-')
{
*p++ = '-';
sign = 1;
}
/* fall through */
case WPR_UNSIGNED:
for (i = len; i < format.precision; i++) *p++ = '0';
if (len > sign) memcpy( p, number + sign, len - sign );
p += len-sign;
break;
case WPR_UNKNOWN:
continue;
}
if (format.flags & WPRINTF_LEFTALIGN)
for (i = format.precision; i < format.width; i++) *p++ = ' ';
}
*p = 0;
return p - buffer;
}
/***********************************************************************
* _wsprintf (USER.420)
*/
INT16 WINAPIV wsprintf16( LPSTR buffer, LPCSTR spec, VA_LIST16 valist )
{
return wvsprintf16( buffer, spec, valist );
}
/***********************************************************************
* lstrcmp (USER.430)
*/
INT16 WINAPI lstrcmp16( LPCSTR str1, LPCSTR str2 )
......
......@@ -31,8 +31,6 @@
#include "wingdi.h"
#include "winuser.h"
#include "wine/winbase16.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(string);
......@@ -281,108 +279,6 @@ static UINT WPRINTF_GetLen( WPRINTF_FORMAT *format, WPRINTF_DATA *arg,
/***********************************************************************
* wvsnprintf16 (Not a Windows API)
*/
static INT16 wvsnprintf16( LPSTR buffer, UINT16 maxlen, LPCSTR spec, VA_LIST16 args )
{
WPRINTF_FORMAT format;
LPSTR p = buffer;
UINT i, len, sign;
CHAR number[20];
WPRINTF_DATA cur_arg;
SEGPTR seg_str;
while (*spec && (maxlen > 1))
{
if (*spec != '%') { *p++ = *spec++; maxlen--; continue; }
spec++;
if (*spec == '%') { *p++ = *spec++; maxlen--; continue; }
spec += WPRINTF_ParseFormatA( spec, &format );
switch(format.type)
{
case WPR_WCHAR: /* No Unicode in Win16 */
case WPR_CHAR:
cur_arg.char_view = VA_ARG16( args, CHAR );
break;
case WPR_WSTRING: /* No Unicode in Win16 */
case WPR_STRING:
seg_str = VA_ARG16( args, SEGPTR );
if (IsBadReadPtr16(seg_str, 1 )) cur_arg.lpcstr_view = "";
else cur_arg.lpcstr_view = MapSL( seg_str );
break;
case WPR_SIGNED:
if (!(format.flags & WPRINTF_LONG))
{
cur_arg.int_view = VA_ARG16( args, INT16 );
break;
}
/* fall through */
case WPR_HEXA:
case WPR_UNSIGNED:
if (format.flags & WPRINTF_LONG)
cur_arg.int_view = VA_ARG16( args, UINT );
else
cur_arg.int_view = VA_ARG16( args, UINT16 );
break;
case WPR_UNKNOWN:
continue;
}
len = WPRINTF_GetLen( &format, &cur_arg, number, maxlen - 1 );
sign = 0;
if (!(format.flags & WPRINTF_LEFTALIGN))
for (i = format.precision; i < format.width; i++, maxlen--)
*p++ = ' ';
switch(format.type)
{
case WPR_WCHAR: /* No Unicode in Win16 */
case WPR_CHAR:
*p= cur_arg.char_view;
/* wsprintf16 (unlike wsprintf) ignores null characters */
if (*p != '\0') p++;
else if (format.width > 1) *p++ = ' ';
else len = 0;
break;
case WPR_WSTRING: /* No Unicode in Win16 */
case WPR_STRING:
if (len) memcpy( p, cur_arg.lpcstr_view, len );
p += len;
break;
case WPR_HEXA:
if ((format.flags & WPRINTF_PREFIX_HEX) && (maxlen > 3))
{
*p++ = '0';
*p++ = (format.flags & WPRINTF_UPPER_HEX) ? 'X' : 'x';
maxlen -= 2;
len -= 2;
}
/* fall through */
case WPR_SIGNED:
/* Transfer the sign now, just in case it will be zero-padded*/
if (number[0] == '-')
{
*p++ = '-';
sign = 1;
}
/* fall through */
case WPR_UNSIGNED:
for (i = len; i < format.precision; i++, maxlen--) *p++ = '0';
if (len > sign) memcpy( p, number + sign, len - sign );
p += len-sign;
break;
case WPR_UNKNOWN:
continue;
}
if (format.flags & WPRINTF_LEFTALIGN)
for (i = format.precision; i < format.width; i++, maxlen--)
*p++ = ' ';
maxlen -= len;
}
*p = 0;
return (maxlen > 1) ? (INT)(p - buffer) : -1;
}
/***********************************************************************
* wvsnprintfA (internal)
*/
static INT wvsnprintfA( LPSTR buffer, UINT maxlen, LPCSTR spec, __ms_va_list args )
......@@ -588,19 +484,6 @@ static INT wvsnprintfW( LPWSTR buffer, UINT maxlen, LPCWSTR spec, __ms_va_list a
/***********************************************************************
* wvsprintf (USER.421)
*/
INT16 WINAPI wvsprintf16( LPSTR buffer, LPCSTR spec, VA_LIST16 args )
{
INT16 res;
TRACE("for %p got:\n",buffer);
res = wvsnprintf16( buffer, 1024, spec, args );
return ( res == -1 ) ? 1024 : res;
}
/***********************************************************************
* wvsprintfA (USER32.@)
*/
INT WINAPI wvsprintfA( LPSTR buffer, LPCSTR spec, __ms_va_list args )
......@@ -621,18 +504,6 @@ INT WINAPI wvsprintfW( LPWSTR buffer, LPCWSTR spec, __ms_va_list args )
/***********************************************************************
* _wsprintf (USER.420)
*/
INT16 WINAPIV wsprintf16( LPSTR buffer, LPCSTR spec, VA_LIST16 valist )
{
INT16 res;
res = wvsnprintf16( buffer, 1024, spec, valist );
return ( res == -1 ) ? 1024 : res;
}
/***********************************************************************
* wsprintfA (USER32.@)
*/
INT WINAPIV wsprintfA( LPSTR buffer, LPCSTR spec, ... )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment