Changeset 5271 for trunk/src/user32


Ignore:
Timestamp:
Feb 27, 2001, 8:34:47 PM (25 years ago)
Author:
sandervl
Message:

wsprintf wine resync

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 
    31/*
    4  * Win32 misc user32 API functions for OS/2
    52 * wsprintf functions
    63 *
    74 * 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__
    188#include <odin.h>
    199#include <odinwrap.h>
     
    2111#include <os2win.h>
    2212
     13#include <misc.h>
     14
     15#define DBG_LOCALLOG    DBG_wsprintf
     16#include "dbglocal.h"
     17
     18ODINDEBUGCHANNEL(USER32-WSPRINTF)
     19#endif
     20
    2321#include <stdarg.h>
    2422#include <string.h>
     23#include <stdio.h>
     24#include "wine/winbase16.h"
     25#include "windef.h"
     26#include "wingdi.h"
     27#include "winuser.h"
    2528#include "stackframe.h"
    26 #include "module.h"
    27 #include "global.h"
    2829#include "debugtools.h"
    2930
    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  ****************************************************************************/
     31DEFAULT_DEBUG_CHANNEL(string);
     32
    4133
    4234#define WPRINTF_LEFTALIGN   0x0001  /* Align output on the left ('-' prefix) */
     
    7668} WPRINTF_DATA;
    7769
    78 
    79 /****************************************************************************
    80  * Module global variables                                                  *
    81  ****************************************************************************/
    82 
    8370static const CHAR null_stringA[] = "(null)";
    8471static const WCHAR null_stringW[] = { '(', 'n', 'u', 'l', 'l', ')', 0 };
    85 
    8672
    8773/***********************************************************************
     
    134120        break;
    135121    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;
    138123        break;
    139124    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;
    142126        break;
    143127    case 'u':
     
    266250    case WPR_HEXA:
    267251        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);
    274254        break;
    275255    default:
     
    281261    if ((format->flags & WPRINTF_ZEROPAD) && (format->width > format->precision))
    282262        format->precision = format->width;
     263    if (format->flags & WPRINTF_PREFIX_HEX) len += 2;
    283264    return len;
    284265}
    285266
    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 */
     272static INT16 wvsnprintf16( LPSTR buffer, UINT16 maxlen, LPCSTR spec,
     273                           LPCVOID args )
    317274{
    318275    WPRINTF_FORMAT format;
     
    320277    UINT i, len;
    321278    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))
    325283    {
    326284        if (*spec != '%') { *p++ = *spec++; maxlen--; continue; }
     
    328286        if (*spec == '%') { *p++ = *spec++; maxlen--; continue; }
    329287        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 );
    332318        if (!(format.flags & WPRINTF_LEFTALIGN))
    333319            for (i = format.precision; i < format.width; i++, maxlen--)
     
    335321        switch(format.type)
    336322        {
    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;
    339326            if (*p != '\0') p++;
    340327            else if (format.width > 1) *p++ = ' ';
    341328            else len = 0;
    342329            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 */
    349331        case WPR_STRING:
    350             memcpy( p, argData.lpcstr_view, len );
     332            if (len) memcpy( p, cur_arg.lpcstr_view, len );
    351333            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             }
    358334            break;
    359335        case WPR_HEXA:
     
    364340                maxlen -= 2;
    365341                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 */
     367INT 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;
    368443            }
    369444            /* fall through */
     
    373448            memcpy( p, number, len );
    374449            p += len;
    375             /* Go to the next arg */
    376450            break;
    377451        case WPR_UNKNOWN:
     
    384458    }
    385459    *p = 0;
    386     TRACE("%s\n",buffer);
     460    TRACE("%s\n",debugstr_a(buffer));
    387461    return (maxlen > 1) ? (INT)(p - buffer) : -1;
    388462}
     
    390464
    391465/***********************************************************************
    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 */
     468INT WINAPI wvsnprintfW( LPWSTR buffer, UINT maxlen, LPCWSTR spec, va_list args )
    396469{
    397470    WPRINTF_FORMAT format;
     
    399472    UINT i, len;
    400473    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))
    403479    {
    404480        if (*spec != '%') { *p++ = *spec++; maxlen--; continue; }
     
    406482        if (*spec == '%') { *p++ = *spec++; maxlen--; continue; }
    407483        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 );
    409510        if (!(format.flags & WPRINTF_LEFTALIGN))
    410511            for (i = format.precision; i < format.width; i++, maxlen--)
     
    413514        {
    414515        case WPR_WCHAR:
    415             *p = va_arg( args, WCHAR );
     516            *p = argData.wchar_view;
    416517            if (*p != '\0') p++;
    417518            else if (format.width > 1) *p++ = ' ';
     
    419520            break;
    420521        case WPR_CHAR:
    421             *p = (WCHAR)va_arg( args, CHAR );
     522            *p = argData.char_view;
    422523            if (*p != '\0') p++;
    423524            else if (format.width > 1) *p++ = ' ';
     
    426527        case WPR_STRING:
    427528            {
    428                 LPCSTR ptr = va_arg( args, LPCSTR );
     529                LPCSTR ptr = argData.lpcstr_view;
    429530                for (i = 0; i < len; i++) *p++ = (WCHAR)*ptr++;
    430531            }
    431532            break;
    432533        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) );
    434535            p += len;
    435536            break;
     
    441542                maxlen -= 2;
    442543                len -= 2;
    443                 format.precision -= 2;
    444                 format.width -= 2;
    445544            }
    446545            /* fall through */
     
    449548            for (i = len; i < format.precision; i++, maxlen--) *p++ = '0';
    450549            for (i = 0; i < len; i++) *p++ = (WCHAR)number[i];
    451             (void)va_arg( args, INT ); /* Go to the next arg */
    452550            break;
    453551        case WPR_UNKNOWN:
     
    460558    }
    461559    *p = 0;
     560    TRACE("%s\n",debugstr_w(buffer));
    462561    return (maxlen > 1) ? (INT)(p - buffer) : -1;
    463562}
    464563
    465564
    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 */
     569INT16 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 */
     583INT 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 */
     593INT 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 */
     603INT16 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.@)
    492621 */
    493622INT WINAPIV wsprintfA( LPSTR buffer, LPCSTR spec, ... )
     
    496625    INT res;
    497626
    498     TRACE("for %p got:\n",buffer);
    499627    va_start( valist, spec );
    500     res = wvsnprintfA( buffer, 0xffffffff, spec, valist );
     628    res = wvsnprintfA( buffer, 1024, spec, valist );
    501629    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.@)
    508636 */
    509637INT WINAPIV wsprintfW( LPWSTR buffer, LPCWSTR spec, ... )
     
    512640    INT res;
    513641
    514     TRACE("wsprintfW for %p\n",buffer);
    515642    va_start( valist, spec );
    516     res = wvsnprintfW( buffer, 0xffffffff, spec, valist );
     643    res = wvsnprintfW( buffer, 1024, spec, valist );
    517644    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.