wsprintf.c 17.2 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3 4
/*
 * wsprintf functions
 *
 * Copyright 1996 Alexandre Julliard
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21 22
 *
 * NOTE:
 * This code is duplicated in shlwapi. If you change something here make sure
 * to change it in shlwapi too.
Alexandre Julliard's avatar
Alexandre Julliard committed
23 24 25 26
 */

#include <stdarg.h>
#include <string.h>
27
#include <stdio.h>
28

29
#include "windef.h"
30
#include "winbase.h"
31
#include "wingdi.h"
32
#include "winuser.h"
33

34
#include "wine/debug.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
35

36
WINE_DEFAULT_DEBUG_CHANNEL(string);
37

Alexandre Julliard's avatar
Alexandre Julliard committed
38 39 40 41 42 43 44

#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) */
Alexandre Julliard's avatar
Alexandre Julliard committed
45
#define WPRINTF_WIDE        0x0040  /* Wide arg ('w' prefix) */
46 47
#define WPRINTF_INTPTR      0x0080  /* Pointer-size arg ('I' prefix) */
#define WPRINTF_I64         0x0100  /* 64-bit arg ('I64' prefix) */
Alexandre Julliard's avatar
Alexandre Julliard committed
48 49 50

typedef enum
{
Alexandre Julliard's avatar
Alexandre Julliard committed
51
    WPR_UNKNOWN,
Alexandre Julliard's avatar
Alexandre Julliard committed
52 53 54 55 56 57 58 59 60 61 62
    WPR_CHAR,
    WPR_WCHAR,
    WPR_STRING,
    WPR_WSTRING,
    WPR_SIGNED,
    WPR_UNSIGNED,
    WPR_HEXA
} WPRINTF_TYPE;

typedef struct
{
63 64 65
    UINT         flags;
    UINT         width;
    UINT         precision;
Alexandre Julliard's avatar
Alexandre Julliard committed
66 67 68
    WPRINTF_TYPE   type;
} WPRINTF_FORMAT;

69
typedef union {
70 71 72 73 74
    WCHAR    wchar_view;
    CHAR     char_view;
    LPCSTR   lpcstr_view;
    LPCWSTR  lpcwstr_view;
    LONGLONG int_view;
75 76
} WPRINTF_DATA;

Alexandre Julliard's avatar
Alexandre Julliard committed
77 78
static const CHAR null_stringA[] = "(null)";
static const WCHAR null_stringW[] = { '(', 'n', 'u', 'l', 'l', ')', 0 };
Alexandre Julliard's avatar
Alexandre Julliard committed
79 80 81 82 83 84 85 86 87 88

/***********************************************************************
 *           WPRINTF_ParseFormatA
 *
 * Parse a format specification. A format specification has the form:
 *
 * [-][#][0][width][.precision]type
 *
 * Return value is the length of the format specification in characters.
 */
89
static INT WPRINTF_ParseFormatA( LPCSTR format, WPRINTF_FORMAT *res )
Alexandre Julliard's avatar
Alexandre Julliard committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
{
    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++; }
Alexandre Julliard's avatar
Alexandre Julliard committed
115
    else if (*p == 'w') { res->flags |= WPRINTF_WIDE; p++; }
116 117 118 119 120 121
    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++; }
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
122 123 124 125 126 127 128 129 130 131 132 133 134
    switch(*p)
    {
    case 'c':
        res->type = (res->flags & WPRINTF_LONG) ? WPR_WCHAR : WPR_CHAR;
        break;
    case 'C':
        res->type = (res->flags & WPRINTF_SHORT) ? WPR_CHAR : WPR_WCHAR;
        break;
    case 'd':
    case 'i':
        res->type = WPR_SIGNED;
        break;
    case 's':
135
        res->type = (res->flags & (WPRINTF_LONG |WPRINTF_WIDE)) ? WPR_WSTRING : WPR_STRING;
Alexandre Julliard's avatar
Alexandre Julliard committed
136 137
        break;
    case 'S':
138
        res->type = (res->flags & (WPRINTF_SHORT|WPRINTF_WIDE)) ? WPR_STRING : WPR_WSTRING;
Alexandre Julliard's avatar
Alexandre Julliard committed
139 140 141 142
        break;
    case 'u':
        res->type = WPR_UNSIGNED;
        break;
143
    case 'p':
144 145
        res->width = 2 * sizeof(void *);
        res->flags |= WPRINTF_ZEROPAD | WPRINTF_INTPTR;
146
        /* fall through */
Alexandre Julliard's avatar
Alexandre Julliard committed
147 148 149 150 151 152
    case 'X':
        res->flags |= WPRINTF_UPPER_HEX;
        /* fall through */
    case 'x':
        res->type = WPR_HEXA;
        break;
Alexandre Julliard's avatar
Alexandre Julliard committed
153 154 155
    default: /* unknown format char */
        res->type = WPR_UNKNOWN;
        p--;  /* print format as normal char */
Alexandre Julliard's avatar
Alexandre Julliard committed
156 157
        break;
    }
158
    return (INT)(p - format) + 1;
Alexandre Julliard's avatar
Alexandre Julliard committed
159 160 161 162 163 164 165 166 167 168 169 170
}


/***********************************************************************
 *           WPRINTF_ParseFormatW
 *
 * Parse a format specification. A format specification has the form:
 *
 * [-][#][0][width][.precision]type
 *
 * Return value is the length of the format specification in characters.
 */
171
static INT WPRINTF_ParseFormatW( LPCWSTR format, WPRINTF_FORMAT *res )
Alexandre Julliard's avatar
Alexandre Julliard committed
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
{
    LPCWSTR 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++; }
Alexandre Julliard's avatar
Alexandre Julliard committed
197
    else if (*p == 'w') { res->flags |= WPRINTF_WIDE; p++; }
198 199 200 201 202 203 204
    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)
Alexandre Julliard's avatar
Alexandre Julliard committed
205 206 207 208 209 210 211 212 213 214 215 216
    {
    case 'c':
        res->type = (res->flags & WPRINTF_SHORT) ? WPR_CHAR : WPR_WCHAR;
        break;
    case 'C':
        res->type = (res->flags & WPRINTF_LONG) ? WPR_WCHAR : WPR_CHAR;
        break;
    case 'd':
    case 'i':
        res->type = WPR_SIGNED;
        break;
    case 's':
Alexandre Julliard's avatar
Alexandre Julliard committed
217
        res->type = ((res->flags & WPRINTF_SHORT) && !(res->flags & WPRINTF_WIDE)) ? WPR_STRING : WPR_WSTRING;
Alexandre Julliard's avatar
Alexandre Julliard committed
218 219
        break;
    case 'S':
Alexandre Julliard's avatar
Alexandre Julliard committed
220
        res->type = (res->flags & (WPRINTF_LONG|WPRINTF_WIDE)) ? WPR_WSTRING : WPR_STRING;
Alexandre Julliard's avatar
Alexandre Julliard committed
221 222 223 224
        break;
    case 'u':
        res->type = WPR_UNSIGNED;
        break;
225
    case 'p':
226 227
        res->width = 2 * sizeof(void *);
        res->flags |= WPRINTF_ZEROPAD | WPRINTF_INTPTR;
228
        /* fall through */
Alexandre Julliard's avatar
Alexandre Julliard committed
229 230 231 232 233 234 235
    case 'X':
        res->flags |= WPRINTF_UPPER_HEX;
        /* fall through */
    case 'x':
        res->type = WPR_HEXA;
        break;
    default:
Alexandre Julliard's avatar
Alexandre Julliard committed
236 237
        res->type = WPR_UNKNOWN;
        p--;  /* print format as normal char */
Alexandre Julliard's avatar
Alexandre Julliard committed
238 239
        break;
    }
240
    return (INT)(p - format) + 1;
Alexandre Julliard's avatar
Alexandre Julliard committed
241 242 243 244 245 246
}


/***********************************************************************
 *           WPRINTF_GetLen
 */
247
static UINT WPRINTF_GetLen( WPRINTF_FORMAT *format, WPRINTF_DATA *arg,
248
                              LPSTR number, UINT maxlen )
Alexandre Julliard's avatar
Alexandre Julliard committed
249
{
250
    UINT len;
Alexandre Julliard's avatar
Alexandre Julliard committed
251 252 253 254 255 256 257 258 259

    if (format->flags & WPRINTF_LEFTALIGN) format->flags &= ~WPRINTF_ZEROPAD;
    if (format->width > maxlen) format->width = maxlen;
    switch(format->type)
    {
    case WPR_CHAR:
    case WPR_WCHAR:
        return (format->precision = 1);
    case WPR_STRING:
260
        if (!arg->lpcstr_view) arg->lpcstr_view = null_stringA;
Alexandre Julliard's avatar
Alexandre Julliard committed
261
        for (len = 0; !format->precision || (len < format->precision); len++)
Eric Pouech's avatar
Eric Pouech committed
262
            if (!*(arg->lpcstr_view + len)) break;
Alexandre Julliard's avatar
Alexandre Julliard committed
263 264 265
        if (len > maxlen) len = maxlen;
        return (format->precision = len);
    case WPR_WSTRING:
266
        if (!arg->lpcwstr_view) arg->lpcwstr_view = null_stringW;
Alexandre Julliard's avatar
Alexandre Julliard committed
267
        for (len = 0; !format->precision || (len < format->precision); len++)
268
            if (!*(arg->lpcwstr_view + len)) break;
Alexandre Julliard's avatar
Alexandre Julliard committed
269 270 271 272 273
        if (len > maxlen) len = maxlen;
        return (format->precision = len);
    case WPR_SIGNED:
    case WPR_UNSIGNED:
    case WPR_HEXA:
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
    {
        const char *digits = (format->flags & WPRINTF_UPPER_HEX) ? "0123456789ABCDEF" : "0123456789abcdef";
        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;
Alexandre Julliard's avatar
Alexandre Julliard committed
296
        break;
297
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
298 299 300 301 302 303 304 305
    default:
        return 0;
    }
    if (len > maxlen) len = maxlen;
    if (format->precision < len) format->precision = len;
    if (format->precision > maxlen) format->precision = maxlen;
    if ((format->flags & WPRINTF_ZEROPAD) && (format->width > format->precision))
        format->precision = format->width;
306
    if (format->flags & WPRINTF_PREFIX_HEX) len += 2;
Alexandre Julliard's avatar
Alexandre Julliard committed
307 308 309 310 311
    return len;
}


/***********************************************************************
312
 *           wvsnprintfA   (internal)
Alexandre Julliard's avatar
Alexandre Julliard committed
313
 */
314
static INT wvsnprintfA( LPSTR buffer, UINT maxlen, LPCSTR spec, __ms_va_list args )
Alexandre Julliard's avatar
Alexandre Julliard committed
315 316 317
{
    WPRINTF_FORMAT format;
    LPSTR p = buffer;
318
    UINT i, len, sign;
319
    CHAR number[21]; /* 64bit number can be 18446744073709551616 which is 20 chars. and a \0 */
Patrik Stridvall's avatar
Patrik Stridvall committed
320
    WPRINTF_DATA argData;
Alexandre Julliard's avatar
Alexandre Julliard committed
321

322 323
    TRACE("%p %u %s\n", buffer, maxlen, debugstr_a(spec));

Alexandre Julliard's avatar
Alexandre Julliard committed
324 325 326 327 328 329
    while (*spec && (maxlen > 1))
    {
        if (*spec != '%') { *p++ = *spec++; maxlen--; continue; }
        spec++;
        if (*spec == '%') { *p++ = *spec++; maxlen--; continue; }
        spec += WPRINTF_ParseFormatA( spec, &format );
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347

        switch(format.type)
        {
        case WPR_WCHAR:
            argData.wchar_view = (WCHAR)va_arg( args, int );
            break;
        case WPR_CHAR:
            argData.char_view = (CHAR)va_arg( args, int );
            break;
        case WPR_STRING:
            argData.lpcstr_view = va_arg( args, LPCSTR );
            break;
        case WPR_WSTRING:
            argData.lpcwstr_view = va_arg( args, LPCWSTR );
            break;
        case WPR_HEXA:
        case WPR_SIGNED:
        case WPR_UNSIGNED:
348 349 350
            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);
351 352 353 354 355 356
            break;
        default:
            argData.wchar_view = 0;
            break;
        }

357
        len = WPRINTF_GetLen( &format, &argData, number, maxlen - 1 );
358
        sign = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
359 360 361 362 363 364
        if (!(format.flags & WPRINTF_LEFTALIGN))
            for (i = format.precision; i < format.width; i++, maxlen--)
                *p++ = ' ';
        switch(format.type)
        {
        case WPR_WCHAR:
365
            *p++ = argData.wchar_view;
Alexandre Julliard's avatar
Alexandre Julliard committed
366 367
            break;
        case WPR_CHAR:
368
            *p++ = argData.char_view;
Alexandre Julliard's avatar
Alexandre Julliard committed
369 370
            break;
        case WPR_STRING:
371
            memcpy( p, argData.lpcstr_view, len );
Alexandre Julliard's avatar
Alexandre Julliard committed
372 373 374
            p += len;
            break;
        case WPR_WSTRING:
Alexandre Julliard's avatar
Alexandre Julliard committed
375
            {
376
                LPCWSTR ptr = argData.lpcwstr_view;
Alexandre Julliard's avatar
Alexandre Julliard committed
377 378
                for (i = 0; i < len; i++) *p++ = (CHAR)*ptr++;
            }
Alexandre Julliard's avatar
Alexandre Julliard committed
379 380 381 382 383 384 385 386 387 388 389
            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:
390 391 392 393 394 395 396
            /* Transfer the sign now, just in case it will be zero-padded*/
            if (number[0] == '-')
            {
                *p++ = '-';
                sign = 1;
            }
            /* fall through */
Alexandre Julliard's avatar
Alexandre Julliard committed
397 398
        case WPR_UNSIGNED:
            for (i = len; i < format.precision; i++, maxlen--) *p++ = '0';
399 400
            memcpy( p, number + sign, len - sign  );
            p += len - sign;
Alexandre Julliard's avatar
Alexandre Julliard committed
401
            break;
Alexandre Julliard's avatar
Alexandre Julliard committed
402 403
        case WPR_UNKNOWN:
            continue;
Alexandre Julliard's avatar
Alexandre Julliard committed
404 405 406 407 408 409 410
        }
        if (format.flags & WPRINTF_LEFTALIGN)
            for (i = format.precision; i < format.width; i++, maxlen--)
                *p++ = ' ';
        maxlen -= len;
    }
    *p = 0;
411
    TRACE("%s\n",debugstr_a(buffer));
412
    return (maxlen > 1) ? (INT)(p - buffer) : -1;
Alexandre Julliard's avatar
Alexandre Julliard committed
413 414 415 416
}


/***********************************************************************
417
 *           wvsnprintfW   (internal)
Alexandre Julliard's avatar
Alexandre Julliard committed
418
 */
419
static INT wvsnprintfW( LPWSTR buffer, UINT maxlen, LPCWSTR spec, __ms_va_list args )
Alexandre Julliard's avatar
Alexandre Julliard committed
420 421 422
{
    WPRINTF_FORMAT format;
    LPWSTR p = buffer;
423
    UINT i, len, sign;
424
    CHAR number[21]; /* 64bit number can be 18446744073709551616 which is 20 chars. and a \0 */
Patrik Stridvall's avatar
Patrik Stridvall committed
425
    WPRINTF_DATA argData;
Alexandre Julliard's avatar
Alexandre Julliard committed
426

Juergen Schmied's avatar
Juergen Schmied committed
427 428
    TRACE("%p %u %s\n", buffer, maxlen, debugstr_w(spec));

Alexandre Julliard's avatar
Alexandre Julliard committed
429 430 431 432 433 434
    while (*spec && (maxlen > 1))
    {
        if (*spec != '%') { *p++ = *spec++; maxlen--; continue; }
        spec++;
        if (*spec == '%') { *p++ = *spec++; maxlen--; continue; }
        spec += WPRINTF_ParseFormatW( spec, &format );
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452

        switch(format.type)
        {
        case WPR_WCHAR:
            argData.wchar_view = (WCHAR)va_arg( args, int );
            break;
        case WPR_CHAR:
            argData.char_view = (CHAR)va_arg( args, int );
            break;
        case WPR_STRING:
            argData.lpcstr_view = va_arg( args, LPCSTR );
            break;
        case WPR_WSTRING:
            argData.lpcwstr_view = va_arg( args, LPCWSTR );
            break;
        case WPR_HEXA:
        case WPR_SIGNED:
        case WPR_UNSIGNED:
453 454 455
            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);
456 457 458 459 460 461
            break;
        default:
            argData.wchar_view = 0;
            break;
        }

Patrik Stridvall's avatar
Patrik Stridvall committed
462
        len = WPRINTF_GetLen( &format, &argData, number, maxlen - 1 );
463
        sign = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
464 465 466 467 468 469
        if (!(format.flags & WPRINTF_LEFTALIGN))
            for (i = format.precision; i < format.width; i++, maxlen--)
                *p++ = ' ';
        switch(format.type)
        {
        case WPR_WCHAR:
470
            *p++ = argData.wchar_view;
Alexandre Julliard's avatar
Alexandre Julliard committed
471 472
            break;
        case WPR_CHAR:
473
            *p++ = argData.char_view;
Alexandre Julliard's avatar
Alexandre Julliard committed
474 475
            break;
        case WPR_STRING:
Alexandre Julliard's avatar
Alexandre Julliard committed
476
            {
Juergen Schmied's avatar
Juergen Schmied committed
477
                LPCSTR ptr = argData.lpcstr_view;
478
                for (i = 0; i < len; i++) *p++ = (BYTE)*ptr++;
Alexandre Julliard's avatar
Alexandre Julliard committed
479
            }
Alexandre Julliard's avatar
Alexandre Julliard committed
480 481
            break;
        case WPR_WSTRING:
Juergen Schmied's avatar
Juergen Schmied committed
482
            if (len) memcpy( p, argData.lpcwstr_view, len * sizeof(WCHAR) );
Alexandre Julliard's avatar
Alexandre Julliard committed
483 484 485 486 487 488 489 490 491 492 493 494
            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:
495 496 497 498 499 500 501
            /* Transfer the sign now, just in case it will be zero-padded*/
            if (number[0] == '-')
            {
                *p++ = '-';
                sign = 1;
            }
            /* fall through */
Alexandre Julliard's avatar
Alexandre Julliard committed
502 503
        case WPR_UNSIGNED:
            for (i = len; i < format.precision; i++, maxlen--) *p++ = '0';
504
            for (i = sign; i < len; i++) *p++ = (BYTE)number[i];
Alexandre Julliard's avatar
Alexandre Julliard committed
505
            break;
Alexandre Julliard's avatar
Alexandre Julliard committed
506 507
        case WPR_UNKNOWN:
            continue;
Alexandre Julliard's avatar
Alexandre Julliard committed
508 509 510 511 512 513 514
        }
        if (format.flags & WPRINTF_LEFTALIGN)
            for (i = format.precision; i < format.width; i++, maxlen--)
                *p++ = ' ';
        maxlen -= len;
    }
    *p = 0;
515
    TRACE("%s\n",debugstr_w(buffer));
516
    return (maxlen > 1) ? (INT)(p - buffer) : -1;
Alexandre Julliard's avatar
Alexandre Julliard committed
517 518 519 520
}


/***********************************************************************
521
 *           wvsprintfA   (USER32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
522
 */
523
INT WINAPI wvsprintfA( LPSTR buffer, LPCSTR spec, __ms_va_list args )
Alexandre Julliard's avatar
Alexandre Julliard committed
524
{
525
    INT res = wvsnprintfA( buffer, 1024, spec, args );
526
    return ( res == -1 ) ? 1024 : res;
Alexandre Julliard's avatar
Alexandre Julliard committed
527 528 529 530
}


/***********************************************************************
531
 *           wvsprintfW   (USER32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
532
 */
533
INT WINAPI wvsprintfW( LPWSTR buffer, LPCWSTR spec, __ms_va_list args )
Alexandre Julliard's avatar
Alexandre Julliard committed
534
{
535
    INT res = wvsnprintfW( buffer, 1024, spec, args );
536
    return ( res == -1 ) ? 1024 : res;
Alexandre Julliard's avatar
Alexandre Julliard committed
537 538 539 540
}


/***********************************************************************
541
 *           wsprintfA   (USER32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
542
 */
543
INT WINAPIV wsprintfA( LPSTR buffer, LPCSTR spec, ... )
Alexandre Julliard's avatar
Alexandre Julliard committed
544
{
545
    __ms_va_list valist;
546
    INT res;
Alexandre Julliard's avatar
Alexandre Julliard committed
547

548
    __ms_va_start( valist, spec );
549
    res = wvsnprintfA( buffer, 1024, spec, valist );
550
    __ms_va_end( valist );
551
    return ( res == -1 ) ? 1024 : res;
Alexandre Julliard's avatar
Alexandre Julliard committed
552 553
}

Alexandre Julliard's avatar
Alexandre Julliard committed
554 555

/***********************************************************************
556
 *           wsprintfW   (USER32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
557
 */
558
INT WINAPIV wsprintfW( LPWSTR buffer, LPCWSTR spec, ... )
Alexandre Julliard's avatar
Alexandre Julliard committed
559
{
560
    __ms_va_list valist;
561
    INT res;
Alexandre Julliard's avatar
Alexandre Julliard committed
562

563
    __ms_va_start( valist, spec );
564
    res = wvsnprintfW( buffer, 1024, spec, valist );
565
    __ms_va_end( valist );
566
    return ( res == -1 ) ? 1024 : res;
Alexandre Julliard's avatar
Alexandre Julliard committed
567
}