Changeset 5271 for trunk/src/user32
- Timestamp:
- Feb 27, 2001, 8:34:47 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/user32/wsprintf.cpp
r3747 r5271 1 /* $Id: wsprintf.cpp,v 1.8 2000-06-23 19:04:13 sandervl Exp $ */2 3 1 /* 4 * Win32 misc user32 API functions for OS/25 2 * wsprintf functions 6 3 * 7 4 * Copyright 1996 Alexandre Julliard 8 * Copyright 1999 Patrick Haller 9 * 10 * Project Odin Software License can be found in LICENSE.TXT 11 */ 12 13 14 /**************************************************************************** 15 * Includes * 16 ****************************************************************************/ 17 5 */ 6 7 #ifdef __WIN32OS2__ 18 8 #include <odin.h> 19 9 #include <odinwrap.h> … … 21 11 #include <os2win.h> 22 12 13 #include <misc.h> 14 15 #define DBG_LOCALLOG DBG_wsprintf 16 #include "dbglocal.h" 17 18 ODINDEBUGCHANNEL(USER32-WSPRINTF) 19 #endif 20 23 21 #include <stdarg.h> 24 22 #include <string.h> 23 #include <stdio.h> 24 #include "wine/winbase16.h" 25 #include "windef.h" 26 #include "wingdi.h" 27 #include "winuser.h" 25 28 #include "stackframe.h" 26 #include "module.h"27 #include "global.h"28 29 #include "debugtools.h" 29 30 30 #include <misc.h> 31 32 #define DBG_LOCALLOG DBG_wsprintf 33 #include "dbglocal.h" 34 35 ODINDEBUGCHANNEL(USER32-WSPRINTF) 36 37 38 /**************************************************************************** 39 * Definitions & Structures * 40 ****************************************************************************/ 31 DEFAULT_DEBUG_CHANNEL(string); 32 41 33 42 34 #define WPRINTF_LEFTALIGN 0x0001 /* Align output on the left ('-' prefix) */ … … 76 68 } WPRINTF_DATA; 77 69 78 79 /****************************************************************************80 * Module global variables *81 ****************************************************************************/82 83 70 static const CHAR null_stringA[] = "(null)"; 84 71 static const WCHAR null_stringW[] = { '(', 'n', 'u', 'l', 'l', ')', 0 }; 85 86 72 87 73 /*********************************************************************** … … 134 120 break; 135 121 case 's': 136 res->type = (res->flags & (WPRINTF_LONG |WPRINTF_WIDE)) 137 ? WPR_WSTRING : WPR_STRING; 122 res->type = (res->flags & (WPRINTF_LONG |WPRINTF_WIDE)) ? WPR_WSTRING : WPR_STRING; 138 123 break; 139 124 case 'S': 140 res->type = (res->flags & (WPRINTF_SHORT|WPRINTF_WIDE)) 141 ? WPR_STRING : WPR_WSTRING; 125 res->type = (res->flags & (WPRINTF_SHORT|WPRINTF_WIDE)) ? WPR_STRING : WPR_WSTRING; 142 126 break; 143 127 case 'u': … … 266 250 case WPR_HEXA: 267 251 len = sprintf( number, 268 (format->flags & WPRINTF_UPPER_HEX) ? "%X" : "%x", 269 (UINT)arg->int_view); 270 if (format->flags & WPRINTF_PREFIX_HEX) { 271 len += 2; 272 format->width += 2; 273 } 252 (format->flags & WPRINTF_UPPER_HEX) ? "%X" : "%x", 253 (UINT)arg->int_view); 274 254 break; 275 255 default: … … 281 261 if ((format->flags & WPRINTF_ZEROPAD) && (format->width > format->precision)) 282 262 format->precision = format->width; 263 if (format->flags & WPRINTF_PREFIX_HEX) len += 2; 283 264 return len; 284 265 } 285 266 286 /*********************************************************************** 287 * WPRINTF_ExtractVAPtr (Not a Windows API) 288 */ 289 static WPRINTF_DATA WPRINTF_ExtractVAPtr( WPRINTF_FORMAT *format, va_list* args ) 290 { 291 WPRINTF_DATA result; 292 switch(format->type) 293 { 294 case WPR_WCHAR: 295 result.wchar_view = va_arg( *args, WCHAR ); break; 296 case WPR_CHAR: 297 result.char_view = va_arg( *args, CHAR ); break; 298 case WPR_STRING: 299 result.lpcstr_view = va_arg( *args, LPCSTR); break; 300 case WPR_WSTRING: 301 result.lpcwstr_view = va_arg( *args, LPCWSTR); break; 302 case WPR_HEXA: 303 case WPR_SIGNED: 304 case WPR_UNSIGNED: 305 result.int_view = va_arg( *args, INT ); break; 306 default: 307 result.wchar_view = 0; break; 308 } 309 return result; 310 } 311 312 /*********************************************************************** 313 * wvsnprintfA (Not a Windows API) 314 */ 315 INT WINAPI wvsnprintfA( LPSTR buffer, UINT maxlen, LPCSTR spec, 316 va_list args ) 267 268 #ifndef __WIN32OS2__ 269 /*********************************************************************** 270 * wvsnprintf16 (Not a Windows API) 271 */ 272 static INT16 wvsnprintf16( LPSTR buffer, UINT16 maxlen, LPCSTR spec, 273 LPCVOID args ) 317 274 { 318 275 WPRINTF_FORMAT format; … … 320 277 UINT i, len; 321 278 CHAR number[20]; 322 WPRINTF_DATA argData; 323 324 while (spec && *spec && (maxlen > 1)) 279 WPRINTF_DATA cur_arg; 280 SEGPTR seg_str; 281 282 while (*spec && (maxlen > 1)) 325 283 { 326 284 if (*spec != '%') { *p++ = *spec++; maxlen--; continue; } … … 328 286 if (*spec == '%') { *p++ = *spec++; maxlen--; continue; } 329 287 spec += WPRINTF_ParseFormatA( spec, &format ); 330 argData = WPRINTF_ExtractVAPtr( &format, &args ); 331 len = WPRINTF_GetLen( &format, &argData, number, maxlen - 1 ); 288 switch(format.type) 289 { 290 case WPR_WCHAR: /* No Unicode in Win16 */ 291 case WPR_CHAR: 292 cur_arg.char_view = VA_ARG16( args, CHAR ); 293 break; 294 case WPR_WSTRING: /* No Unicode in Win16 */ 295 case WPR_STRING: 296 seg_str = VA_ARG16( args, SEGPTR ); 297 if (IsBadReadPtr16(seg_str, 1 )) cur_arg.lpcstr_view = ""; 298 else cur_arg.lpcstr_view = MapSL( seg_str ); 299 break; 300 case WPR_SIGNED: 301 if (!(format.flags & WPRINTF_LONG)) 302 { 303 cur_arg.int_view = VA_ARG16( args, INT16 ); 304 break; 305 } 306 /* fall through */ 307 case WPR_HEXA: 308 case WPR_UNSIGNED: 309 if (format.flags & WPRINTF_LONG) 310 cur_arg.int_view = VA_ARG16( args, UINT ); 311 else 312 cur_arg.int_view = VA_ARG16( args, UINT16 ); 313 break; 314 case WPR_UNKNOWN: 315 continue; 316 } 317 len = WPRINTF_GetLen( &format, &cur_arg, number, maxlen - 1 ); 332 318 if (!(format.flags & WPRINTF_LEFTALIGN)) 333 319 for (i = format.precision; i < format.width; i++, maxlen--) … … 335 321 switch(format.type) 336 322 { 337 case WPR_WCHAR: 338 *p = argData.wchar_view; 323 case WPR_WCHAR: /* No Unicode in Win16 */ 324 case WPR_CHAR: 325 *p= cur_arg.char_view; 339 326 if (*p != '\0') p++; 340 327 else if (format.width > 1) *p++ = ' '; 341 328 else len = 0; 342 329 break; 343 case WPR_CHAR: 344 *p = argData.char_view; 345 if (*p != '\0') p++; 346 else if (format.width > 1) *p++ = ' '; 347 else len = 0; 348 break; 330 case WPR_WSTRING: /* No Unicode in Win16 */ 349 331 case WPR_STRING: 350 memcpy( p, argData.lpcstr_view, len );332 if (len) memcpy( p, cur_arg.lpcstr_view, len ); 351 333 p += len; 352 break;353 case WPR_WSTRING:354 {355 LPCWSTR ptr = argData.lpcwstr_view;356 for (i = 0; i < len; i++) *p++ = (CHAR)*ptr++;357 }358 334 break; 359 335 case WPR_HEXA: … … 364 340 maxlen -= 2; 365 341 len -= 2; 366 format.precision -= 2; 367 format.width -= 2; 342 } 343 /* fall through */ 344 case WPR_SIGNED: 345 case WPR_UNSIGNED: 346 for (i = len; i < format.precision; i++, maxlen--) *p++ = '0'; 347 if (len) memcpy( p, number, len ); 348 p += len; 349 break; 350 case WPR_UNKNOWN: 351 continue; 352 } 353 if (format.flags & WPRINTF_LEFTALIGN) 354 for (i = format.precision; i < format.width; i++, maxlen--) 355 *p++ = ' '; 356 maxlen -= len; 357 } 358 *p = 0; 359 return (maxlen > 1) ? (INT)(p - buffer) : -1; 360 } 361 #endif //!__WIN32OS2__ 362 363 364 /*********************************************************************** 365 * wvsnprintfA (USER32.@) (Not a Windows API, but we export it from USER32 anyway) 366 */ 367 INT WINAPI wvsnprintfA( LPSTR buffer, UINT maxlen, LPCSTR spec, va_list args ) 368 { 369 WPRINTF_FORMAT format; 370 LPSTR p = buffer; 371 UINT i, len; 372 CHAR number[20]; 373 WPRINTF_DATA argData; 374 375 TRACE("%p %u %s\n", buffer, maxlen, debugstr_a(spec)); 376 377 while (*spec && (maxlen > 1)) 378 { 379 if (*spec != '%') { *p++ = *spec++; maxlen--; continue; } 380 spec++; 381 if (*spec == '%') { *p++ = *spec++; maxlen--; continue; } 382 spec += WPRINTF_ParseFormatA( spec, &format ); 383 384 switch(format.type) 385 { 386 case WPR_WCHAR: 387 argData.wchar_view = (WCHAR)va_arg( args, int ); 388 break; 389 case WPR_CHAR: 390 argData.char_view = (CHAR)va_arg( args, int ); 391 break; 392 case WPR_STRING: 393 argData.lpcstr_view = va_arg( args, LPCSTR ); 394 break; 395 case WPR_WSTRING: 396 argData.lpcwstr_view = va_arg( args, LPCWSTR ); 397 break; 398 case WPR_HEXA: 399 case WPR_SIGNED: 400 case WPR_UNSIGNED: 401 argData.int_view = va_arg( args, INT ); 402 break; 403 default: 404 argData.wchar_view = 0; 405 break; 406 } 407 408 len = WPRINTF_GetLen( &format, &argData, number, maxlen - 1 ); 409 if (!(format.flags & WPRINTF_LEFTALIGN)) 410 for (i = format.precision; i < format.width; i++, maxlen--) 411 *p++ = ' '; 412 switch(format.type) 413 { 414 case WPR_WCHAR: 415 *p = argData.wchar_view; 416 if (*p != '\0') p++; 417 else if (format.width > 1) *p++ = ' '; 418 else len = 0; 419 break; 420 case WPR_CHAR: 421 *p = argData.char_view; 422 if (*p != '\0') p++; 423 else if (format.width > 1) *p++ = ' '; 424 else len = 0; 425 break; 426 case WPR_STRING: 427 memcpy( p, argData.lpcstr_view, len ); 428 p += len; 429 break; 430 case WPR_WSTRING: 431 { 432 LPCWSTR ptr = argData.lpcwstr_view; 433 for (i = 0; i < len; i++) *p++ = (CHAR)*ptr++; 434 } 435 break; 436 case WPR_HEXA: 437 if ((format.flags & WPRINTF_PREFIX_HEX) && (maxlen > 3)) 438 { 439 *p++ = '0'; 440 *p++ = (format.flags & WPRINTF_UPPER_HEX) ? 'X' : 'x'; 441 maxlen -= 2; 442 len -= 2; 368 443 } 369 444 /* fall through */ … … 373 448 memcpy( p, number, len ); 374 449 p += len; 375 /* Go to the next arg */376 450 break; 377 451 case WPR_UNKNOWN: … … 384 458 } 385 459 *p = 0; 386 TRACE("%s\n", buffer);460 TRACE("%s\n",debugstr_a(buffer)); 387 461 return (maxlen > 1) ? (INT)(p - buffer) : -1; 388 462 } … … 390 464 391 465 /*********************************************************************** 392 * wvsnprintfW (Not a Windows API) 393 */ 394 INT WINAPI wvsnprintfW( LPWSTR buffer, UINT maxlen, LPCWSTR spec, 395 va_list args ) 466 * wvsnprintfW (USER32.@) (Not a Windows API, but we export it from USER32 anyway) 467 */ 468 INT WINAPI wvsnprintfW( LPWSTR buffer, UINT maxlen, LPCWSTR spec, va_list args ) 396 469 { 397 470 WPRINTF_FORMAT format; … … 399 472 UINT i, len; 400 473 CHAR number[20]; 401 402 while (spec && *spec && (maxlen > 1)) 474 WPRINTF_DATA argData; 475 476 TRACE("%p %u %s\n", buffer, maxlen, debugstr_w(spec)); 477 478 while (*spec && (maxlen > 1)) 403 479 { 404 480 if (*spec != '%') { *p++ = *spec++; maxlen--; continue; } … … 406 482 if (*spec == '%') { *p++ = *spec++; maxlen--; continue; } 407 483 spec += WPRINTF_ParseFormatW( spec, &format ); 408 len = WPRINTF_GetLen( &format, (WPRINTF_DATA*)args, number, maxlen - 1 ); 484 485 switch(format.type) 486 { 487 case WPR_WCHAR: 488 argData.wchar_view = (WCHAR)va_arg( args, int ); 489 break; 490 case WPR_CHAR: 491 argData.char_view = (CHAR)va_arg( args, int ); 492 break; 493 case WPR_STRING: 494 argData.lpcstr_view = va_arg( args, LPCSTR ); 495 break; 496 case WPR_WSTRING: 497 argData.lpcwstr_view = va_arg( args, LPCWSTR ); 498 break; 499 case WPR_HEXA: 500 case WPR_SIGNED: 501 case WPR_UNSIGNED: 502 argData.int_view = va_arg( args, INT ); 503 break; 504 default: 505 argData.wchar_view = 0; 506 break; 507 } 508 509 len = WPRINTF_GetLen( &format, &argData, number, maxlen - 1 ); 409 510 if (!(format.flags & WPRINTF_LEFTALIGN)) 410 511 for (i = format.precision; i < format.width; i++, maxlen--) … … 413 514 { 414 515 case WPR_WCHAR: 415 *p = va_arg( args, WCHAR );516 *p = argData.wchar_view; 416 517 if (*p != '\0') p++; 417 518 else if (format.width > 1) *p++ = ' '; … … 419 520 break; 420 521 case WPR_CHAR: 421 *p = (WCHAR)va_arg( args, CHAR );522 *p = argData.char_view; 422 523 if (*p != '\0') p++; 423 524 else if (format.width > 1) *p++ = ' '; … … 426 527 case WPR_STRING: 427 528 { 428 LPCSTR ptr = va_arg( args, LPCSTR );529 LPCSTR ptr = argData.lpcstr_view; 429 530 for (i = 0; i < len; i++) *p++ = (WCHAR)*ptr++; 430 531 } 431 532 break; 432 533 case WPR_WSTRING: 433 if (len) memcpy( p, va_arg( args, LPCWSTR ), len * sizeof(WCHAR) );534 if (len) memcpy( p, argData.lpcwstr_view, len * sizeof(WCHAR) ); 434 535 p += len; 435 536 break; … … 441 542 maxlen -= 2; 442 543 len -= 2; 443 format.precision -= 2;444 format.width -= 2;445 544 } 446 545 /* fall through */ … … 449 548 for (i = len; i < format.precision; i++, maxlen--) *p++ = '0'; 450 549 for (i = 0; i < len; i++) *p++ = (WCHAR)number[i]; 451 (void)va_arg( args, INT ); /* Go to the next arg */452 550 break; 453 551 case WPR_UNKNOWN: … … 460 558 } 461 559 *p = 0; 560 TRACE("%s\n",debugstr_w(buffer)); 462 561 return (maxlen > 1) ? (INT)(p - buffer) : -1; 463 562 } 464 563 465 564 466 /*********************************************************************** 467 * wvsprintfA (USER32.587) 468 */ 469 ODINFUNCTION3(INT, wvsprintfA, 470 LPSTR, buffer, 471 LPCSTR, spec, 472 va_list,args ) 473 { 474 return wvsnprintfA( buffer, 0xffffffff, spec, args ); 475 } 476 477 478 /*********************************************************************** 479 * wvsprintfW (USER32.588) 480 */ 481 ODINFUNCTION3(INT, wvsprintfW, 482 LPWSTR, buffer, 483 LPCWSTR, spec, 484 va_list, args ) 485 { 486 return wvsnprintfW( buffer, 0xffffffff, spec, args ); 487 } 488 489 490 /*********************************************************************** 491 * wsprintfA (USER32.585) 565 #ifndef __WIN32OS2__ 566 /*********************************************************************** 567 * wvsprintf16 (USER.421) 568 */ 569 INT16 WINAPI wvsprintf16( LPSTR buffer, LPCSTR spec, LPCVOID args ) 570 { 571 INT16 res; 572 573 TRACE("for %p got:\n",buffer); 574 res = wvsnprintf16( buffer, 1024, spec, args ); 575 return ( res == -1 ) ? 1024 : res; 576 } 577 #endif //!__WIN32OS2__ 578 579 580 /*********************************************************************** 581 * wvsprintfA (USER32.@) 582 */ 583 INT WINAPI wvsprintfA( LPSTR buffer, LPCSTR spec, va_list args ) 584 { 585 INT res = wvsnprintfA( buffer, 1024, spec, args ); 586 return ( res == -1 ) ? 1024 : res; 587 } 588 589 590 /*********************************************************************** 591 * wvsprintfW (USER32.@) 592 */ 593 INT WINAPI wvsprintfW( LPWSTR buffer, LPCWSTR spec, va_list args ) 594 { 595 INT res = wvsnprintfW( buffer, 1024, spec, args ); 596 return ( res == -1 ) ? 1024 : res; 597 } 598 599 #ifndef __WIN32OS2__ 600 /*********************************************************************** 601 * wsprintf16 (USER.420) 602 */ 603 INT16 WINAPIV wsprintf16(void) 604 { 605 VA_LIST16 valist; 606 INT16 res; 607 SEGPTR buffer, spec; 608 609 VA_START16( valist ); 610 buffer = VA_ARG16( valist, SEGPTR ); 611 spec = VA_ARG16( valist, SEGPTR ); 612 res = wvsnprintf16( MapSL(buffer), 1024, MapSL(spec), valist ); 613 VA_END16( valist ); 614 return ( res == -1 ) ? 1024 : res; 615 } 616 #endif //!__WIN32OS2__ 617 618 619 /*********************************************************************** 620 * wsprintfA (USER32.@) 492 621 */ 493 622 INT WINAPIV wsprintfA( LPSTR buffer, LPCSTR spec, ... ) … … 496 625 INT res; 497 626 498 TRACE("for %p got:\n",buffer);499 627 va_start( valist, spec ); 500 res = wvsnprintfA( buffer, 0xffffffff, spec, valist );628 res = wvsnprintfA( buffer, 1024, spec, valist ); 501 629 va_end( valist ); 502 return res;503 } 504 505 506 /*********************************************************************** 507 * wsprintfW (USER32. 586)630 return ( res == -1 ) ? 1024 : res; 631 } 632 633 634 /*********************************************************************** 635 * wsprintfW (USER32.@) 508 636 */ 509 637 INT WINAPIV wsprintfW( LPWSTR buffer, LPCWSTR spec, ... ) … … 512 640 INT res; 513 641 514 TRACE("wsprintfW for %p\n",buffer);515 642 va_start( valist, spec ); 516 res = wvsnprintfW( buffer, 0xffffffff, spec, valist );643 res = wvsnprintfW( buffer, 1024, spec, valist ); 517 644 va_end( valist ); 518 return res; 519 } 520 521 522 /*********************************************************************** 523 * wsnprintfA (Not a Windows API) 524 */ 525 INT WINAPIV wsnprintfA( LPSTR buffer, UINT maxlen, LPCSTR spec, ... ) 526 { 527 va_list valist; 528 INT res; 529 530 va_start( valist, spec ); 531 res = wvsnprintfA( buffer, maxlen, spec, valist ); 532 va_end( valist ); 533 return res; 534 } 535 536 537 /*********************************************************************** 538 * wsnprintfW (Not a Windows API) 539 */ 540 INT WINAPIV wsnprintfW( LPWSTR buffer, UINT maxlen, LPCWSTR spec, ... ) 541 { 542 va_list valist; 543 INT res; 544 545 va_start( valist, spec ); 546 res = wvsnprintfW( buffer, maxlen, spec, valist ); 547 va_end( valist ); 548 return res; 549 } 550 551 552 553 554 645 return ( res == -1 ) ? 1024 : res; 646 }
Note:
See TracChangeset
for help on using the changeset viewer.