ReactOS 0.4.15-dev-8109-gd7be748
wsprintf.c File Reference
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include "windef.h"
#include "winbase.h"
#include "shlwapi.h"
#include "wine/debug.h"
Include dependency graph for wsprintf.c:

Go to the source code of this file.

Classes

struct  WPRINTF_FORMAT
 
union  WPRINTF_DATA
 

Macros

#define NO_SHLWAPI_REG
 
#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) */
 
#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) */
 

Enumerations

enum  WPRINTF_TYPE {
  WPR_UNKNOWN , WPR_CHAR , WPR_WCHAR , WPR_STRING ,
  WPR_WSTRING , WPR_SIGNED , WPR_UNSIGNED , WPR_HEXA
}
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (string)
 
static INT WPRINTF_ParseFormatA (LPCSTR format, WPRINTF_FORMAT *res)
 
static INT WPRINTF_ParseFormatW (LPCWSTR format, WPRINTF_FORMAT *res)
 
static UINT WPRINTF_GetLen (WPRINTF_FORMAT *format, WPRINTF_DATA *arg, LPSTR number, UINT maxlen)
 
INT WINAPI wvnsprintfA (LPSTR buffer, INT maxlen, LPCSTR spec, __ms_va_list args)
 
INT WINAPI wvnsprintfW (LPWSTR buffer, INT maxlen, LPCWSTR spec, __ms_va_list args)
 
int WINAPIV wnsprintfA (LPSTR lpOut, int cchLimitIn, LPCSTR lpFmt,...)
 
int WINAPIV wnsprintfW (LPWSTR lpOut, int cchLimitIn, LPCWSTR lpFmt,...)
 

Variables

static const CHAR null_stringA [] = "(null)"
 
static const WCHAR null_stringW [] = { '(', 'n', 'u', 'l', 'l', ')', 0 }
 

Macro Definition Documentation

◆ NO_SHLWAPI_REG

#define NO_SHLWAPI_REG

Definition at line 31 of file wsprintf.c.

◆ WPRINTF_I64

#define WPRINTF_I64   0x0100 /* 64-bit arg ('I64' prefix) */

Definition at line 47 of file wsprintf.c.

◆ WPRINTF_INTPTR

#define WPRINTF_INTPTR   0x0080 /* Pointer-size arg ('I' prefix) */

Definition at line 46 of file wsprintf.c.

◆ WPRINTF_LEFTALIGN

#define WPRINTF_LEFTALIGN   0x0001 /* Align output on the left ('-' prefix) */

Definition at line 39 of file wsprintf.c.

◆ WPRINTF_LONG

#define WPRINTF_LONG   0x0008 /* Long arg ('l' prefix) */

Definition at line 42 of file wsprintf.c.

◆ WPRINTF_PREFIX_HEX

#define WPRINTF_PREFIX_HEX   0x0002 /* Prefix hex with 0x ('#' prefix) */

Definition at line 40 of file wsprintf.c.

◆ WPRINTF_SHORT

#define WPRINTF_SHORT   0x0010 /* Short arg ('h' prefix) */

Definition at line 43 of file wsprintf.c.

◆ WPRINTF_UPPER_HEX

#define WPRINTF_UPPER_HEX   0x0020 /* Upper-case hex ('X' specifier) */

Definition at line 44 of file wsprintf.c.

◆ WPRINTF_WIDE

#define WPRINTF_WIDE   0x0040 /* Wide arg ('w' prefix) */

Definition at line 45 of file wsprintf.c.

◆ WPRINTF_ZEROPAD

#define WPRINTF_ZEROPAD   0x0004 /* Pad with zeros ('0' prefix) */

Definition at line 41 of file wsprintf.c.

Enumeration Type Documentation

◆ WPRINTF_TYPE

Enumerator
WPR_UNKNOWN 
WPR_CHAR 
WPR_WCHAR 
WPR_STRING 
WPR_WSTRING 
WPR_SIGNED 
WPR_UNSIGNED 
WPR_HEXA 

Definition at line 49 of file wsprintf.c.

50{
WPRINTF_TYPE
Definition: wsprintf.c:50
@ WPR_UNSIGNED
Definition: wsprintf.c:57
@ WPR_STRING
Definition: wsprintf.c:54
@ WPR_WSTRING
Definition: wsprintf.c:55
@ WPR_WCHAR
Definition: wsprintf.c:53
@ WPR_UNKNOWN
Definition: wsprintf.c:51
@ WPR_CHAR
Definition: wsprintf.c:52
@ WPR_SIGNED
Definition: wsprintf.c:56
@ WPR_HEXA
Definition: wsprintf.c:58

Function Documentation

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( string  )

◆ wnsprintfA()

int WINAPIV wnsprintfA ( LPSTR  lpOut,
int  cchLimitIn,
LPCSTR  lpFmt,
  ... 
)

Definition at line 547 of file wsprintf.c.

548{
550 INT res;
551
552 __ms_va_start( valist, lpFmt );
553 res = wvnsprintfA( lpOut, cchLimitIn, lpFmt, valist );
555 return res;
556}
INT WINAPI wvnsprintfA(LPSTR buffer, INT maxlen, LPCSTR spec, __ms_va_list args)
Definition: wsprintf.c:325
GLuint res
Definition: glext.h:9613
static __ms_va_list valist
Definition: printf.c:66
int32_t INT
Definition: typedefs.h:58
#define __ms_va_list
Definition: windef.h:456
#define __ms_va_end(list)
Definition: windef.h:458
#define __ms_va_start(list, arg)
Definition: windef.h:457

◆ wnsprintfW()

int WINAPIV wnsprintfW ( LPWSTR  lpOut,
int  cchLimitIn,
LPCWSTR  lpFmt,
  ... 
)

Definition at line 564 of file wsprintf.c.

565{
567 INT res;
568
569 __ms_va_start( valist, lpFmt );
570 res = wvnsprintfW( lpOut, cchLimitIn, lpFmt, valist );
572 return res;
573}
INT WINAPI wvnsprintfW(LPWSTR buffer, INT maxlen, LPCWSTR spec, __ms_va_list args)
Definition: wsprintf.c:432

Referenced by confirm_delete_list().

◆ WPRINTF_GetLen()

static UINT WPRINTF_GetLen ( WPRINTF_FORMAT format,
WPRINTF_DATA arg,
LPSTR  number,
UINT  maxlen 
)
static

Definition at line 247 of file wsprintf.c.

249{
250 UINT len;
251
252 if (format->flags & WPRINTF_LEFTALIGN) format->flags &= ~WPRINTF_ZEROPAD;
253 if (format->width > maxlen) format->width = maxlen;
254 switch(format->type)
255 {
256 case WPR_CHAR:
257 case WPR_WCHAR:
258 return (format->precision = 1);
259 case WPR_STRING:
260 if (!arg->lpcstr_view) arg->lpcstr_view = null_stringA;
261 for (len = 0; !format->precision || (len < format->precision); len++)
262 if (!*(arg->lpcstr_view + len)) break;
263 if (len > maxlen) len = maxlen;
264 return (format->precision = len);
265 case WPR_WSTRING:
266 if (!arg->lpcwstr_view) arg->lpcwstr_view = null_stringW;
267 for (len = 0; !format->precision || (len < format->precision); len++)
268 if (!*(arg->lpcwstr_view + len)) break;
269 if (len > maxlen) len = maxlen;
270 return (format->precision = len);
271 case WPR_SIGNED:
272 case WPR_UNSIGNED:
273 case WPR_HEXA:
274 {
275 const char *digits = (format->flags & WPRINTF_UPPER_HEX) ? "0123456789ABCDEF" : "0123456789abcdef";
276 ULONGLONG num = arg->int_view;
277 int base = format->type == WPR_HEXA ? 16 : 10;
278 char buffer[20], *p = buffer, *dst = number;
279
280 if (format->type == WPR_SIGNED && arg->int_view < 0)
281 {
282 *dst++ = '-';
283 num = -arg->int_view;
284 }
285 if (format->flags & WPRINTF_INTPTR) num = (UINT_PTR)num;
286 else if (!(format->flags & WPRINTF_I64)) num = (UINT)num;
287
288 do
289 {
290 *p++ = digits[num % base];
291 num /= base;
292 } while (num);
293 while (p > buffer) *dst++ = *(--p);
294 *dst = 0;
295 len = dst - number;
296 break;
297 }
298 default:
299 return 0;
300 }
301 if (len > maxlen) len = maxlen;
302 if (format->precision < len) format->precision = len;
303 if (format->precision > maxlen) format->precision = maxlen;
304 if ((format->flags & WPRINTF_ZEROPAD) && (format->width > format->precision))
305 format->precision = format->width;
306 if (format->flags & WPRINTF_PREFIX_HEX) len += 2;
307 return len;
308}
#define WPRINTF_UPPER_HEX
Definition: wsprintf.c:44
#define WPRINTF_PREFIX_HEX
Definition: wsprintf.c:40
#define WPRINTF_ZEROPAD
Definition: wsprintf.c:41
#define WPRINTF_INTPTR
Definition: wsprintf.c:46
static const WCHAR null_stringW[]
Definition: wsprintf.c:78
#define WPRINTF_LEFTALIGN
Definition: wsprintf.c:39
#define WPRINTF_I64
Definition: wsprintf.c:47
static const CHAR null_stringA[]
Definition: wsprintf.c:77
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLuint buffer
Definition: glext.h:5915
GLenum GLenum dst
Definition: glext.h:6340
GLfloat GLfloat p
Definition: glext.h:8902
GLuint GLuint num
Definition: glext.h:9618
GLenum GLsizei len
Definition: glext.h:6722
static const int digits[]
Definition: decode.c:71
static unsigned int number
Definition: dsound.c:1479
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
unsigned int UINT
Definition: ndis.h:50
uint64_t ULONGLONG
Definition: typedefs.h:67

Referenced by wvnsprintfA(), and wvnsprintfW().

◆ WPRINTF_ParseFormatA()

static INT WPRINTF_ParseFormatA ( LPCSTR  format,
WPRINTF_FORMAT res 
)
static

Definition at line 89 of file wsprintf.c.

90{
91 LPCSTR p = format;
92
93 res->flags = 0;
94 res->width = 0;
95 res->precision = 0;
96 if (*p == '-') { res->flags |= WPRINTF_LEFTALIGN; p++; }
97 if (*p == '#') { res->flags |= WPRINTF_PREFIX_HEX; p++; }
98 if (*p == '0') { res->flags |= WPRINTF_ZEROPAD; p++; }
99 while ((*p >= '0') && (*p <= '9')) /* width field */
100 {
101 res->width = res->width * 10 + *p - '0';
102 p++;
103 }
104 if (*p == '.') /* precision field */
105 {
106 p++;
107 while ((*p >= '0') && (*p <= '9'))
108 {
109 res->precision = res->precision * 10 + *p - '0';
110 p++;
111 }
112 }
113 if (*p == 'l') { res->flags |= WPRINTF_LONG; p++; }
114 else if (*p == 'h') { res->flags |= WPRINTF_SHORT; p++; }
115 else if (*p == 'w') { res->flags |= WPRINTF_WIDE; p++; }
116 else if (*p == 'I')
117 {
118 if (p[1] == '6' && p[2] == '4') { res->flags |= WPRINTF_I64; p += 3; }
119 else if (p[1] == '3' && p[2] == '2') p += 3;
120 else { res->flags |= WPRINTF_INTPTR; p++; }
121 }
122 switch(*p)
123 {
124 case 'c':
125 res->type = (res->flags & WPRINTF_LONG) ? WPR_WCHAR : WPR_CHAR;
126 break;
127 case 'C':
128 res->type = (res->flags & WPRINTF_SHORT) ? WPR_CHAR : WPR_WCHAR;
129 break;
130 case 'd':
131 case 'i':
132 res->type = WPR_SIGNED;
133 break;
134 case 's':
135 res->type = (res->flags & (WPRINTF_LONG |WPRINTF_WIDE)) ? WPR_WSTRING : WPR_STRING;
136 break;
137 case 'S':
138 res->type = (res->flags & (WPRINTF_SHORT|WPRINTF_WIDE)) ? WPR_STRING : WPR_WSTRING;
139 break;
140 case 'u':
141 res->type = WPR_UNSIGNED;
142 break;
143 case 'p':
144 res->width = 2 * sizeof(void *);
146 /* fall through */
147 case 'X':
148 res->flags |= WPRINTF_UPPER_HEX;
149 /* fall through */
150 case 'x':
151 res->type = WPR_HEXA;
152 break;
153 default: /* unknown format char */
154 res->type = WPR_UNKNOWN;
155 p--; /* print format as normal char */
156 break;
157 }
158 return (INT)(p - format) + 1;
159}
#define WPRINTF_LONG
Definition: wsprintf.c:42
#define WPRINTF_SHORT
Definition: wsprintf.c:43
#define WPRINTF_WIDE
Definition: wsprintf.c:45
const char * LPCSTR
Definition: xmlstorage.h:183

Referenced by wvnsprintfA().

◆ WPRINTF_ParseFormatW()

static INT WPRINTF_ParseFormatW ( LPCWSTR  format,
WPRINTF_FORMAT res 
)
static

Definition at line 171 of file wsprintf.c.

172{
173 LPCWSTR p = format;
174
175 res->flags = 0;
176 res->width = 0;
177 res->precision = 0;
178 if (*p == '-') { res->flags |= WPRINTF_LEFTALIGN; p++; }
179 if (*p == '#') { res->flags |= WPRINTF_PREFIX_HEX; p++; }
180 if (*p == '0') { res->flags |= WPRINTF_ZEROPAD; p++; }
181 while ((*p >= '0') && (*p <= '9')) /* width field */
182 {
183 res->width = res->width * 10 + *p - '0';
184 p++;
185 }
186 if (*p == '.') /* precision field */
187 {
188 p++;
189 while ((*p >= '0') && (*p <= '9'))
190 {
191 res->precision = res->precision * 10 + *p - '0';
192 p++;
193 }
194 }
195 if (*p == 'l') { res->flags |= WPRINTF_LONG; p++; }
196 else if (*p == 'h') { res->flags |= WPRINTF_SHORT; p++; }
197 else if (*p == 'w') { res->flags |= WPRINTF_WIDE; p++; }
198 else if (*p == 'I')
199 {
200 if (p[1] == '6' && p[2] == '4') { res->flags |= WPRINTF_I64; p += 3; }
201 else if (p[1] == '3' && p[2] == '2') p += 3;
202 else { res->flags |= WPRINTF_INTPTR; p++; }
203 }
204 switch(*p)
205 {
206 case 'c':
207 res->type = (res->flags & WPRINTF_SHORT) ? WPR_CHAR : WPR_WCHAR;
208 break;
209 case 'C':
210 res->type = (res->flags & WPRINTF_LONG) ? WPR_WCHAR : WPR_CHAR;
211 break;
212 case 'd':
213 case 'i':
214 res->type = WPR_SIGNED;
215 break;
216 case 's':
217 res->type = ((res->flags & WPRINTF_SHORT) && !(res->flags & WPRINTF_WIDE)) ? WPR_STRING : WPR_WSTRING;
218 break;
219 case 'S':
220 res->type = (res->flags & (WPRINTF_LONG|WPRINTF_WIDE)) ? WPR_WSTRING : WPR_STRING;
221 break;
222 case 'u':
223 res->type = WPR_UNSIGNED;
224 break;
225 case 'p':
226 res->width = 2 * sizeof(void *);
228 /* fall through */
229 case 'X':
230 res->flags |= WPRINTF_UPPER_HEX;
231 /* fall through */
232 case 'x':
233 res->type = WPR_HEXA;
234 break;
235 default:
236 res->type = WPR_UNKNOWN;
237 p--; /* print format as normal char */
238 break;
239 }
240 return (INT)(p - format) + 1;
241}
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by wvnsprintfW().

◆ wvnsprintfA()

INT WINAPI wvnsprintfA ( LPSTR  buffer,
INT  maxlen,
LPCSTR  spec,
__ms_va_list  args 
)

Definition at line 325 of file wsprintf.c.

326{
328 LPSTR p = buffer;
329 UINT i, len, sign;
330 CHAR number[21]; /* 64bit number can be 18446744073709551616 which is 20 chars. and a \0 */
331 WPRINTF_DATA argData;
332
333 TRACE("%p %u %s\n", buffer, maxlen, debugstr_a(spec));
334
335 while (*spec && (maxlen > 1))
336 {
337 if (*spec != '%') { *p++ = *spec++; maxlen--; continue; }
338 spec++;
339 if (*spec == '%') { *p++ = *spec++; maxlen--; continue; }
340 spec += WPRINTF_ParseFormatA( spec, &format );
341
342 switch(format.type)
343 {
344 case WPR_WCHAR:
345 argData.wchar_view = (WCHAR)va_arg( args, int );
346 break;
347 case WPR_CHAR:
348 argData.char_view = (CHAR)va_arg( args, int );
349 break;
350 case WPR_STRING:
351 argData.lpcstr_view = va_arg( args, LPCSTR );
352 break;
353 case WPR_WSTRING:
354 argData.lpcwstr_view = va_arg( args, LPCWSTR );
355 break;
356 case WPR_HEXA:
357 case WPR_SIGNED:
358 case WPR_UNSIGNED:
359 if (format.flags & WPRINTF_INTPTR) argData.int_view = va_arg(args, INT_PTR);
360 else if (format.flags & WPRINTF_I64) argData.int_view = va_arg(args, LONGLONG);
361 else argData.int_view = va_arg(args, INT);
362 break;
363 default:
364 argData.wchar_view = 0;
365 break;
366 }
367
368 len = WPRINTF_GetLen( &format, &argData, number, maxlen - 1 );
369 sign = 0;
370 if (!(format.flags & WPRINTF_LEFTALIGN))
371 for (i = format.precision; i < format.width; i++, maxlen--)
372 *p++ = ' ';
373 switch(format.type)
374 {
375 case WPR_WCHAR:
376 *p++ = argData.wchar_view;
377 break;
378 case WPR_CHAR:
379 *p++ = argData.char_view;
380 break;
381 case WPR_STRING:
382 memcpy( p, argData.lpcstr_view, len );
383 p += len;
384 break;
385 case WPR_WSTRING:
386 {
387 LPCWSTR ptr = argData.lpcwstr_view;
388 for (i = 0; i < len; i++) *p++ = (CHAR)*ptr++;
389 }
390 break;
391 case WPR_HEXA:
392 if ((format.flags & WPRINTF_PREFIX_HEX) && (maxlen > 3))
393 {
394 *p++ = '0';
395 *p++ = (format.flags & WPRINTF_UPPER_HEX) ? 'X' : 'x';
396 maxlen -= 2;
397 len -= 2;
398 }
399 /* fall through */
400 case WPR_SIGNED:
401 /* Transfer the sign now, just in case it will be zero-padded*/
402 if (number[0] == '-')
403 {
404 *p++ = '-';
405 sign = 1;
406 }
407 /* fall through */
408 case WPR_UNSIGNED:
409 for (i = len; i < format.precision; i++, maxlen--) *p++ = '0';
410 memcpy( p, number + sign, len - sign );
411 p += len - sign;
412 break;
413 case WPR_UNKNOWN:
414 continue;
415 }
416 if (format.flags & WPRINTF_LEFTALIGN)
417 for (i = format.precision; i < format.width; i++, maxlen--)
418 *p++ = ' ';
419 maxlen -= len;
420 }
421 *p = 0;
422 TRACE("%s\n",debugstr_a(buffer));
423 return (maxlen > 1) ? (INT)(p - buffer) : -1;
424}
#define va_arg(ap, T)
Definition: acmsvcex.h:89
#define CHAR(Char)
static INT WPRINTF_ParseFormatA(LPCSTR format, WPRINTF_FORMAT *res)
Definition: wsprintf.c:89
static UINT WPRINTF_GetLen(WPRINTF_FORMAT *format, WPRINTF_DATA *arg, LPSTR number, UINT maxlen)
Definition: wsprintf.c:247
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define debugstr_a
Definition: kernel32.h:31
#define sign(x)
Definition: mapdesc.cc:613
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static PVOID ptr
Definition: dispmode.c:27
#define INT
Definition: polytest.cpp:20
#define TRACE(s)
Definition: solgame.cpp:4
Definition: match.c:390
int32_t INT_PTR
Definition: typedefs.h:64
int64_t LONGLONG
Definition: typedefs.h:68
WCHAR wchar_view
Definition: wsprintf.c:70
LPCWSTR lpcwstr_view
Definition: wsprintf.c:73
LONGLONG int_view
Definition: wsprintf.c:74
LPCSTR lpcstr_view
Definition: wsprintf.c:72
CHAR char_view
Definition: wsprintf.c:71
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180
char CHAR
Definition: xmlstorage.h:175

Referenced by wnsprintfA().

◆ wvnsprintfW()

INT WINAPI wvnsprintfW ( LPWSTR  buffer,
INT  maxlen,
LPCWSTR  spec,
__ms_va_list  args 
)

Definition at line 432 of file wsprintf.c.

433{
435 LPWSTR p = buffer;
436 UINT i, len, sign;
437 CHAR number[21]; /* 64bit number can be 18446744073709551616 which is 20 chars. and a \0 */
438 WPRINTF_DATA argData;
439
440 TRACE("%p %u %s\n", buffer, maxlen, debugstr_w(spec));
441
442 while (*spec && (maxlen > 1))
443 {
444 if (*spec != '%') { *p++ = *spec++; maxlen--; continue; }
445 spec++;
446 if (*spec == '%') { *p++ = *spec++; maxlen--; continue; }
447 spec += WPRINTF_ParseFormatW( spec, &format );
448
449 switch(format.type)
450 {
451 case WPR_WCHAR:
452 argData.wchar_view = (WCHAR)va_arg( args, int );
453 break;
454 case WPR_CHAR:
455 argData.char_view = (CHAR)va_arg( args, int );
456 break;
457 case WPR_STRING:
458 argData.lpcstr_view = va_arg( args, LPCSTR );
459 break;
460 case WPR_WSTRING:
461 argData.lpcwstr_view = va_arg( args, LPCWSTR );
462 break;
463 case WPR_HEXA:
464 case WPR_SIGNED:
465 case WPR_UNSIGNED:
466 if (format.flags & WPRINTF_INTPTR) argData.int_view = va_arg(args, INT_PTR);
467 else if (format.flags & WPRINTF_I64) argData.int_view = va_arg(args, LONGLONG);
468 else argData.int_view = va_arg(args, INT);
469 break;
470 default:
471 argData.wchar_view = 0;
472 break;
473 }
474
475 len = WPRINTF_GetLen( &format, &argData, number, maxlen - 1 );
476 sign = 0;
477 if (!(format.flags & WPRINTF_LEFTALIGN))
478 for (i = format.precision; i < format.width; i++, maxlen--)
479 *p++ = ' ';
480 switch(format.type)
481 {
482 case WPR_WCHAR:
483 *p++ = argData.wchar_view;
484 break;
485 case WPR_CHAR:
486 *p++ = argData.char_view;
487 break;
488 case WPR_STRING:
489 {
490 LPCSTR ptr = argData.lpcstr_view;
491 for (i = 0; i < len; i++) *p++ = (BYTE)*ptr++;
492 }
493 break;
494 case WPR_WSTRING:
495 if (len) memcpy( p, argData.lpcwstr_view, len * sizeof(WCHAR) );
496 p += len;
497 break;
498 case WPR_HEXA:
499 if ((format.flags & WPRINTF_PREFIX_HEX) && (maxlen > 3))
500 {
501 *p++ = '0';
502 *p++ = (format.flags & WPRINTF_UPPER_HEX) ? 'X' : 'x';
503 maxlen -= 2;
504 len -= 2;
505 }
506 /* fall through */
507 case WPR_SIGNED:
508 /* Transfer the sign now, just in case it will be zero-padded*/
509 if (number[0] == '-')
510 {
511 *p++ = '-';
512 sign = 1;
513 }
514 /* fall through */
515 case WPR_UNSIGNED:
516 for (i = len; i < format.precision; i++, maxlen--) *p++ = '0';
517 for (i = sign; i < len; i++) *p++ = (BYTE)number[i];
518 break;
519 case WPR_UNKNOWN:
520 continue;
521 }
522 if (format.flags & WPRINTF_LEFTALIGN)
523 for (i = format.precision; i < format.width; i++, maxlen--)
524 *p++ = ' ';
525 maxlen -= len;
526 }
527 *p = 0;
528 TRACE("%s\n",debugstr_w(buffer));
529 return (maxlen > 1) ? (INT)(p - buffer) : -1;
530}
static INT WPRINTF_ParseFormatW(LPCWSTR format, WPRINTF_FORMAT *res)
Definition: wsprintf.c:171
#define debugstr_w
Definition: kernel32.h:32
WCHAR * LPWSTR
Definition: xmlstorage.h:184
unsigned char BYTE
Definition: xxhash.c:193

Referenced by wnsprintfW().

Variable Documentation

◆ null_stringA

const CHAR null_stringA[] = "(null)"
static

Definition at line 77 of file wsprintf.c.

Referenced by WPRINTF_GetLen().

◆ null_stringW

const WCHAR null_stringW[] = { '(', 'n', 'u', 'l', 'l', ')', 0 }
static

Definition at line 78 of file wsprintf.c.

Referenced by WPRINTF_GetLen().