Changeset 6375 for trunk/src/kernel32


Ignore:
Timestamp:
Jul 20, 2001, 5:42:38 PM (24 years ago)
Author:
sandervl
Message:

initterm update

Location:
trunk/src/kernel32
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/KERNEL32.DEF

    r6263 r6375  
    1 ; $Id: KERNEL32.DEF,v 1.114 2001-07-09 07:58:12 sandervl Exp $
     1; $Id: KERNEL32.DEF,v 1.115 2001-07-20 15:33:28 sandervl Exp $
    22
    33;Basis is Windows95 KERNEL32
     
    11641164    _Odin32GetBuildNumber@0                                       @1293 NONAME
    11651165
    1166 ;Export for MSACM32
    1167     _wsnprintfA                                                   @2000 NONAME
    1168 
    11691166    IsExeStarted__Fv                                              @2001 NONAME
    11701167    CheckCurFS                                                    @2002 NONAME
  • trunk/src/kernel32/dbglocal.cpp

    r5587 r6375  
    1 /* $Id: dbglocal.cpp,v 1.15 2001-04-26 13:22:43 sandervl Exp $ */
     1/* $Id: dbglocal.cpp,v 1.16 2001-07-20 15:33:29 sandervl Exp $ */
    22
    33/*
     
    1616#ifdef DEBUG
    1717
    18 USHORT DbgEnabled[DBG_MAXFILES] = {0};
    19 USHORT DbgEnabledLvl2[DBG_MAXFILES] = {0};
     18USHORT DbgEnabledKERNEL32[DBG_MAXFILES] = {0};
     19USHORT DbgEnabledLvl2KERNEL32[DBG_MAXFILES] = {0};
    2020
    21 char  *DbgFileNames[DBG_MAXFILES] =
     21static char  *DbgFileNames[DBG_MAXFILES] =
    2222{
    2323"kernel32",
     
    128128//******************************************************************************
    129129//******************************************************************************
    130 void ParseLogStatus()
     130void ParseLogStatusKERNEL32()
    131131{
    132132 char *envvar = getenv(DBG_ENVNAME);
     
    136136
    137137    for(i=0;i<DBG_MAXFILES;i++) {
    138         DbgEnabled[i] = 1;
     138        DbgEnabledKERNEL32[i] = 1;
    139139    }
    140140
     
    144144                if(*(dbgvar-1) == '-') {
    145145                    for(i=0;i<DBG_MAXFILES;i++) {
    146                         DbgEnabled[i] = 0;
     146                        DbgEnabledKERNEL32[i] = 0;
    147147                    }
    148148                }
     
    152152                if(dbgvar) {
    153153                    if(*(dbgvar-1) == '-') {
    154                             DbgEnabled[i] = 0;
     154                            DbgEnabledKERNEL32[i] = 0;
    155155                    }
    156156                    else   
    157157                    if(*(dbgvar-1) == '+') {
    158                         DbgEnabled[i] = 1;
     158                        DbgEnabledKERNEL32[i] = 1;
    159159                    }
    160160                }
     
    166166                if(*(dbgvar-1) == '+') {
    167167                    for(i=0;i<DBG_MAXFILES;i++) {
    168                         DbgEnabledLvl2[i] = 1;
     168                        DbgEnabledLvl2KERNEL32[i] = 1;
    169169                    }
    170170                }
     
    174174                if(dbgvar) {
    175175                    if(*(dbgvar-1) == '-') {
    176                             DbgEnabledLvl2[i] = 0;
     176                            DbgEnabledLvl2KERNEL32[i] = 0;
    177177                    }
    178178                    else   
    179179                    if(*(dbgvar-1) == '+') {
    180                         DbgEnabledLvl2[i] = 1;
     180                        DbgEnabledLvl2KERNEL32[i] = 1;
    181181                    }
    182182                }
  • trunk/src/kernel32/dbglocal.h

    r5587 r6375  
    1313#ifdef DEBUG
    1414//Parses environment variable for selective enabling/disabling of logging
    15 void ParseLogStatus();
     15void ParseLogStatusKERNEL32();
    1616
    1717#define DBG_ENVNAME        "dbg_kernel32"
     
    124124#define DBG_MAXFILES       104
    125125
    126 extern USHORT DbgEnabled[DBG_MAXFILES];
    127 extern USHORT DbgEnabledLvl2[DBG_MAXFILES];
     126extern USHORT DbgEnabledKERNEL32[DBG_MAXFILES];
     127extern USHORT DbgEnabledLvl2KERNEL32[DBG_MAXFILES];
    128128
    129129#ifdef dprintf
     
    131131#endif
    132132
    133 #define dprintf(a)      if(DbgEnabled[DBG_LOCALLOG] == 1) WriteLog a
     133#define dprintf(a)      if(DbgEnabledKERNEL32[DBG_LOCALLOG] == 1) WriteLog a
    134134
    135135#ifdef dprintf2
     
    137137#endif
    138138
    139 #define dprintf2(a)     if(DbgEnabledLvl2[DBG_LOCALLOG] == 1) WriteLog a
     139#define dprintf2(a)     if(DbgEnabledLvl2KERNEL32[DBG_LOCALLOG] == 1) WriteLog a
    140140
    141141#else
    142142
    143 #define ParseLogStatus()
     143#define ParseLogStatusKERNEL32()
    144144
    145145#endif //DEBUG
  • trunk/src/kernel32/exceptstackdump.cpp

    r4555 r6375  
    1 /* $Id: exceptstackdump.cpp,v 1.3 2000-11-05 13:40:45 sandervl Exp $ */
     1/* $Id: exceptstackdump.cpp,v 1.4 2001-07-20 15:33:29 sandervl Exp $ */
    22/*
    33 * Stack dump code
     
    3030
    3131#undef dprintf
    32 #define dprintf(a)     if(DbgEnabled[DBG_LOCALLOG] == 1) WriteLogNoEOL a
     32#define dprintf(a)     if(DbgEnabledKERNEL32[DBG_LOCALLOG] == 1) WriteLogNoEOL a
    3333
    3434/* ******************************************************************
  • trunk/src/kernel32/exceptutil.asm

    r6133 r6375  
    1 ; $Id: exceptutil.asm,v 1.17 2001-06-27 19:09:35 sandervl Exp $
     1; $Id: exceptutil.asm,v 1.18 2001-07-20 15:33:29 sandervl Exp $
    22
    33;/*
     
    160160getEAX  endp
    161161
     162public  getEDX
     163getEDX  proc    near
     164        mov     EAX, EDX
     165        ret
     166endp
     167
    162168getEBX  proc near
    163169        mov  eax, ebx
     
    292298        EXTRN _GetThreadTEB@0:PROC
    293299IFDEF DEBUG
    294         EXTRN DbgEnabled:DWORD
     300        EXTRN DbgEnabledKERNEL32:DWORD
    295301ENDIF
    296302
     
    375381; 299     dprintf(("KERNEL32: Calling handler at %p code=%lx flags=%lx\n",
    376382IFDEF DEBUG
    377         cmp     word ptr  DbgEnabled+020h,01h
     383        cmp     word ptr  DbgEnabledKERNEL32+020h,01h
    378384        jne     @BLBL20
    379385        mov     eax,[ebp+08h];  record
     
    400406IFDEF DEBUG
    401407; 302     dprintf(("KERNEL32: Handler returned %lx\n", ret));
    402         cmp     word ptr  DbgEnabled+020h,01h
     408        cmp     word ptr  DbgEnabledKERNEL32+020h,01h
    403409        jne     @BLBL21
    404410        push    dword ptr [ebp-010h];   ret
  • trunk/src/kernel32/initterm.cpp

    r6340 r6375  
    5858#include "dbglocal.h"
    5959
    60 PVOID   SYSTEM _O32_GetEnvironmentStrings( VOID );
    6160BOOL  fVersionWarp3 = FALSE;
    6261
     
    6867/*-------------------------------------------------------------------*/
    6968static void APIENTRY cleanup(ULONG reason);
    70 
    71 extern "C" {
    72  //Win32 resource table (produced by wrc)
    73  extern DWORD _Resource_PEResTab;
    74 }
    75 
    76 //Global DLL Data
    77 #pragma data_seg(_GLOBALDATA)
    78 int globLoadNr = 0;
    79 #pragma data_seg()
    80 
    81 /* Tue 03.03.1998: knut */
    82 ULONG flAllocMem = 0;    /* flag to optimize DosAllocMem to use all the memory on SMP machines */
    83 ULONG ulMaxAddr = 0x20000000; /* end of user address space. */
    84 int   loadNr = 0;
    85 char  kernel32Path[CCHMAXPATH] = "";
    86 static HMODULE dllHandle = 0;
    8769
    8870/****************************************************************************/
     
    11092        case 0 :
    11193        {
    112             ParseLogStatus();
    113 
    114             /*
    115              * Init the win32k library.
    116              * We will also need to tell win32k where the Odin32 environment is
    117              * located. Currently that is within Open32. I'm quite sure that it's
    118              * not relocated during run, so we're pretty well off.
    119              */
    120             if (!libWin32kInit())
    121             {
    122                 rc = libWin32kSetEnvironment((PSZ)_O32_GetEnvironmentStrings(), 0, 0);
    123                 if (rc)
    124                 {
    125                     dprintf(("KERNEL32: initterm: libWin32kSetEnvironment failed with rc=%d\n", rc));
    126                 }
    127             }
    128 
    129             loadNr = globLoadNr++;
    130 
    131             strcpy(kernel32Path, OSLibGetDllName(hModule));
    132             char *endofpath = strrchr(kernel32Path, '\\');
    133             *(endofpath+1) = 0;
    134             dprintf(("kernel32 init %s %s (%x) Win32k - %s", __DATE__, __TIME__, DLLENTRYPOINT_NAME,
    135                      libWin32kInstalled() ? "Installed" : "Not Installed"));
    13694            ctordtorInit();
    13795
    13896            CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed  98-03-18 05:28:48*/
    139 
    140             OpenPrivateLogFiles();
    141 
    142             if (InitializeSharedHeap() == FALSE)
    143                 return 0UL;
    144 
    145             if (InitializeCodeHeap() == FALSE)
    146                 return 0UL;
    147 
    148             PROFILE_LoadOdinIni();
    149             dllHandle = RegisterLxDll(hModule, 0, (PVOID)&_Resource_PEResTab);
    150             if (dllHandle == 0)
    151                 return 0UL;
    152 
    153             //SvL: Kernel32 is a special case; pe.exe loads it, so increase
    154             //     the reference count here
    155             Win32DllBase *module = Win32DllBase::findModule(dllHandle);
    156             if (module)
    157             {
    158                 module->AddRef();
    159                 module->DisableUnload();
    160             }
    16197
    16298            /*******************************************************************/
     
    169105                return 0UL;
    170106
    171             /* knut: check for high memory support */
    172             rc = DosQuerySysInfo(QSV_VIRTUALADDRESSLIMIT, QSV_VIRTUALADDRESSLIMIT, &ulSysinfo, sizeof(ulSysinfo));
    173             if (rc == 0 && ulSysinfo > 512)   //VirtualAddresslimit is in MB
    174             {
    175                 flAllocMem = PAG_ANY;      // high memory support. Let's use it!
    176                 ulMaxAddr = ulSysinfo * (1024*1024);
    177                 OSLibInitWSeBFileIO();
    178             if (PROFILE_GetOdinIniInt(ODINSYSTEM_SECTION, HIGHMEM_KEY, 1) == 0) {
    179                     dprintf(("WARNING: OS/2 kernel supports high memory, but support is DISABLED because of HIGHMEM odin.ini key"));
    180                     flAllocMem = 0;
    181                 }
    182             }
    183             else
    184                 flAllocMem = 0;        // no high memory support
    185 
    186             OSLibDosSetInitialMaxFileHandles(ODIN_DEFAULT_MAX_FILEHANDLES);
    187 
    188             //SvL: Do it here instead of during the exe object creation
    189             //(std handles can be used in win32 dll initialization routines
    190             HMInitialize();             /* store standard handles within HandleManager */
    191             InitDirectories();      //Must be done before InitializeTIB (which loads NTDLL -> USER32)
    192             InitializeTIB(TRUE);        //Must be done after HMInitialize!
    193             RegisterDevices();
    194             Win32DllBase::setDefaultRenaming();
    195             rc = DosQuerySysInfo(QSV_NUMPROCESSORS, QSV_NUMPROCESSORS, &ulSysinfo, sizeof(ulSysinfo));
    196             if (rc != 0)
    197                 ulSysinfo = 1;
    198 
    199107            rc = DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_MINOR, version, sizeof(version));
    200108            if(rc == 0){
     
    203111                }
    204112            }
    205 
    206             /* Setup codepage info */
    207             CODEPAGE_Init();
    208 
    209             InitSystemInfo(ulSysinfo);
    210             //Set up environment as found in NT
    211             InitEnvironment(ulSysinfo);
    212 
    213             //InitDynamicRegistry creates/changes keys that may change (i.e. odin.ini
    214             //keys that affect windows version)
    215             InitDynamicRegistry();
     113           
     114            rc = inittermKernel32(hModule, ulFlag);
    216115            break;
    217116        }
    218117
    219118        case 1 :
    220             if (dllHandle)
    221             {
    222                 UnregisterLxDll(dllHandle);
    223             }
     119            rc = inittermKernel32(hModule, ulFlag);
    224120            break;
    225121
     
    237133static void APIENTRY cleanup(ULONG ulReason)
    238134{
    239     dprintf(("kernel32 exit %d\n", ulReason));
    240     //Flush and delete all open memory mapped files
    241     Win32MemMap::deleteAll();
    242     WinExe = NULL;
     135    cleanupKernel32(ulReason);
    243136
    244     WriteOutProfiles();
    245     DestroyTIB();
    246     DestroySharedHeap();
    247     DestroyCodeHeap();
    248137    ctordtorTerm();
    249 
    250     //NOTE: Must be done after DestroyTIB
    251     ClosePrivateLogFiles();
    252     CloseLogFile();
    253 
    254     /*
    255      * Terminate win32k library.
    256      */
    257     libWin32kSetEnvironment(NULL, 0, 0);
    258     libWin32kTerm();
    259138
    260139    DosExitList(EXLST_EXIT, cleanup);
  • trunk/src/kernel32/kernel32.mak

    r6060 r6375  
    1 # $Id: kernel32.mak,v 1.7 2001-06-21 21:07:54 sandervl Exp $
     1# $Id: kernel32.mak,v 1.8 2001-07-20 15:33:30 sandervl Exp $
    22
    33#
     
    2020# Overrides.
    2121#
    22 ##CDEFINES    = $(CDEFINES) -DUSE_OS2SEMAPHORES
     22##CDEFINES    = $(CDEFINES) -DTEST_BUILTIN
    2323
    2424
     
    6666$(OBJDIR)\vsemaphore.obj \
    6767$(OBJDIR)\initterm.obj \
     68$(OBJDIR)\initkernel32.obj \
    6869$(OBJDIR)\handlemanager.obj \
    6970$(OBJDIR)\environ.obj \
     
    138139LIBS = \
    139140$(ODIN32_LIB)/$(ODINCRT).lib \
     141##$(ODIN32_LIB)\wgss.lib \
    140142$(ODIN32_LIB)\PMWINX.LIB \
    141143$(ODIN32_LIB)\LIBULS.LIB \
  • trunk/src/kernel32/time.cpp

    r5818 r6375  
    1 /* $Id: time.cpp,v 1.15 2001-05-28 14:47:49 phaller Exp $ */
     1/* $Id: time.cpp,v 1.16 2001-07-20 15:33:30 sandervl Exp $ */
    22
    33/*
     
    191191  return O32_SetSystemTime(arg1);
    192192}
    193 
    194 /***********************************************************************
    195  *           WPRINTF_ParseFormatA
    196  *
    197  * Parse a format specification. A format specification has the form:
    198  *
    199  * [-][#][0][width][.precision]type
    200  *
    201  * Return value is the length of the format specification in characters.
    202  */
    203 static INT WPRINTF_ParseFormatA( LPCSTR format, WPRINTF_FORMAT *res )
    204 {
    205     LPCSTR p = format;
    206 
    207     res->flags = 0;
    208     res->width = 0;
    209     res->precision = 0;
    210     if (*p == '-') { res->flags |= WPRINTF_LEFTALIGN; p++; }
    211     if (*p == '#') { res->flags |= WPRINTF_PREFIX_HEX; p++; }
    212     if (*p == '0') { res->flags |= WPRINTF_ZEROPAD; p++; }
    213     while ((*p >= '0') && (*p <= '9'))  /* width field */
    214     {
    215         res->width = res->width * 10 + *p - '0';
    216         p++;
    217     }
    218     if (*p == '.')  /* precision field */
    219     {
    220         p++;
    221         while ((*p >= '0') && (*p <= '9'))
    222         {
    223             res->precision = res->precision * 10 + *p - '0';
    224             p++;
    225         }
    226     }
    227     if (*p == 'l') { res->flags |= WPRINTF_LONG; p++; }
    228     else if (*p == 'h') { res->flags |= WPRINTF_SHORT; p++; }
    229     else if (*p == 'w') { res->flags |= WPRINTF_WIDE; p++; }
    230     switch(*p)
    231     {
    232     case 'c':
    233         res->type = (res->flags & WPRINTF_LONG) ? WPR_WCHAR : WPR_CHAR;
    234         break;
    235     case 'C':
    236         res->type = (res->flags & WPRINTF_SHORT) ? WPR_CHAR : WPR_WCHAR;
    237         break;
    238     case 'd':
    239     case 'i':
    240         res->type = WPR_SIGNED;
    241         break;
    242     case 's':
    243         res->type = (res->flags & (WPRINTF_LONG |WPRINTF_WIDE))
    244                     ? WPR_WSTRING : WPR_STRING;
    245         break;
    246     case 'S':
    247         res->type = (res->flags & (WPRINTF_SHORT|WPRINTF_WIDE))
    248                     ? WPR_STRING : WPR_WSTRING;
    249         break;
    250     case 'u':
    251         res->type = WPR_UNSIGNED;
    252         break;
    253     case 'X':
    254         res->flags |= WPRINTF_UPPER_HEX;
    255         /* fall through */
    256     case 'x':
    257         res->type = WPR_HEXA;
    258         break;
    259     default: /* unknown format char */
    260         res->type = WPR_UNKNOWN;
    261         p--;  /* print format as normal char */
    262         break;
    263     }
    264     return (INT)(p - format) + 1;
    265 }
    266 
    267 
    268 /***********************************************************************
    269  *           WPRINTF_ParseFormatW
    270  *
    271  * Parse a format specification. A format specification has the form:
    272  *
    273  * [-][#][0][width][.precision]type
    274  *
    275  * Return value is the length of the format specification in characters.
    276  */
    277 static INT WPRINTF_ParseFormatW( LPCWSTR format, WPRINTF_FORMAT *res )
    278 {
    279     LPCWSTR p = format;
    280 
    281     res->flags = 0;
    282     res->width = 0;
    283     res->precision = 0;
    284     if (*p == '-') { res->flags |= WPRINTF_LEFTALIGN; p++; }
    285     if (*p == '#') { res->flags |= WPRINTF_PREFIX_HEX; p++; }
    286     if (*p == '0') { res->flags |= WPRINTF_ZEROPAD; p++; }
    287     while ((*p >= '0') && (*p <= '9'))  /* width field */
    288     {
    289         res->width = res->width * 10 + *p - '0';
    290         p++;
    291     }
    292     if (*p == '.')  /* precision field */
    293     {
    294         p++;
    295         while ((*p >= '0') && (*p <= '9'))
    296         {
    297             res->precision = res->precision * 10 + *p - '0';
    298             p++;
    299         }
    300     }
    301     if (*p == 'l') { res->flags |= WPRINTF_LONG; p++; }
    302     else if (*p == 'h') { res->flags |= WPRINTF_SHORT; p++; }
    303     else if (*p == 'w') { res->flags |= WPRINTF_WIDE; p++; }
    304     switch((CHAR)*p)
    305     {
    306     case 'c':
    307         res->type = (res->flags & WPRINTF_SHORT) ? WPR_CHAR : WPR_WCHAR;
    308         break;
    309     case 'C':
    310         res->type = (res->flags & WPRINTF_LONG) ? WPR_WCHAR : WPR_CHAR;
    311         break;
    312     case 'd':
    313     case 'i':
    314         res->type = WPR_SIGNED;
    315         break;
    316     case 's':
    317         res->type = ((res->flags & WPRINTF_SHORT) && !(res->flags & WPRINTF_WIDE)) ? WPR_STRING : WPR_WSTRING;
    318         break;
    319     case 'S':
    320         res->type = (res->flags & (WPRINTF_LONG|WPRINTF_WIDE)) ? WPR_WSTRING : WPR_STRING;
    321         break;
    322     case 'u':
    323         res->type = WPR_UNSIGNED;
    324         break;
    325     case 'X':
    326         res->flags |= WPRINTF_UPPER_HEX;
    327         /* fall through */
    328     case 'x':
    329         res->type = WPR_HEXA;
    330         break;
    331     default:
    332         res->type = WPR_UNKNOWN;
    333         p--;  /* print format as normal char */
    334         break;
    335     }
    336     return (INT)(p - format) + 1;
    337 }
    338 
    339 
    340 /***********************************************************************
    341  *           WPRINTF_GetLen
    342  */
    343 static UINT WPRINTF_GetLen( WPRINTF_FORMAT *format, WPRINTF_DATA *arg,
    344                               LPSTR number, UINT maxlen )
    345 {
    346     UINT len;
    347 
    348     if (format->flags & WPRINTF_LEFTALIGN) format->flags &= ~WPRINTF_ZEROPAD;
    349     if (format->width > maxlen) format->width = maxlen;
    350     switch(format->type)
    351     {
    352     case WPR_CHAR:
    353     case WPR_WCHAR:
    354         return (format->precision = 1);
    355     case WPR_STRING:
    356         if (!arg->lpcstr_view) arg->lpcstr_view = null_stringA;
    357         for (len = 0; !format->precision || (len < format->precision); len++)
    358             if (!*(arg->lpcstr_view + len)) break;
    359         if (len > maxlen) len = maxlen;
    360         return (format->precision = len);
    361     case WPR_WSTRING:
    362         if (!arg->lpcwstr_view) arg->lpcwstr_view = null_stringW;
    363         for (len = 0; !format->precision || (len < format->precision); len++)
    364             if (!*(arg->lpcwstr_view + len)) break;
    365         if (len > maxlen) len = maxlen;
    366         return (format->precision = len);
    367     case WPR_SIGNED:
    368         len = sprintf( number, "%d", arg->int_view );
    369         break;
    370     case WPR_UNSIGNED:
    371         len = sprintf( number, "%u", (UINT)arg->int_view );
    372         break;
    373     case WPR_HEXA:
    374         len = sprintf( number,
    375                         (format->flags & WPRINTF_UPPER_HEX) ? "%X" : "%x",
    376                         (UINT)arg->int_view);
    377         if (format->flags & WPRINTF_PREFIX_HEX) len += 2;
    378         break;
    379     default:
    380         return 0;
    381     }
    382     if (len > maxlen) len = maxlen;
    383     if (format->precision < len) format->precision = len;
    384     if (format->precision > maxlen) format->precision = maxlen;
    385     if ((format->flags & WPRINTF_ZEROPAD) && (format->width > format->precision))
    386         format->precision = format->width;
    387     return len;
    388 }
    389 
    390 /***********************************************************************
    391  *           WPRINTF_ExtractVAPtr (Not a Windows API)
    392  */
    393 static WPRINTF_DATA WPRINTF_ExtractVAPtr( WPRINTF_FORMAT *format, va_list* args )
    394 {
    395     WPRINTF_DATA result;
    396     switch(format->type)
    397     {
    398         case WPR_WCHAR:
    399             result.wchar_view = va_arg( *args, WCHAR );     break;
    400         case WPR_CHAR:
    401             result.char_view = va_arg( *args, CHAR );       break;
    402         case WPR_STRING:
    403             result.lpcstr_view = va_arg( *args, LPCSTR);    break;
    404         case WPR_WSTRING:
    405             result.lpcwstr_view = va_arg( *args, LPCWSTR);  break;
    406         case WPR_HEXA:
    407         case WPR_SIGNED:
    408         case WPR_UNSIGNED:
    409             result.int_view = va_arg( *args, INT );         break;
    410         default:
    411             result.wchar_view = 0;                          break;
    412     }
    413     return result;
    414 }
    415 
    416 /***********************************************************************
    417  *           wvsnprintfA   (Not a Windows API)
    418  */
    419 INT WINAPI wvsnprintfA( LPSTR buffer, UINT maxlen, LPCSTR spec,
    420                             va_list args )
    421 {
    422     WPRINTF_FORMAT format;
    423     LPSTR p = buffer;
    424     UINT i, len;
    425     CHAR number[20];
    426     WPRINTF_DATA argData;
    427 
    428     while (*spec && (maxlen > 1))
    429     {
    430         if (*spec != '%') { *p++ = *spec++; maxlen--; continue; }
    431         spec++;
    432         if (*spec == '%') { *p++ = *spec++; maxlen--; continue; }
    433         spec += WPRINTF_ParseFormatA( spec, &format );
    434         argData = WPRINTF_ExtractVAPtr( &format, &args );
    435         len = WPRINTF_GetLen( &format, &argData, number, maxlen - 1 );
    436         if (!(format.flags & WPRINTF_LEFTALIGN))
    437             for (i = format.precision; i < format.width; i++, maxlen--)
    438                 *p++ = ' ';
    439         switch(format.type)
    440         {
    441         case WPR_WCHAR:
    442             *p = argData.wchar_view;
    443             if (*p != '\0') p++;
    444             else if (format.width > 1) *p++ = ' ';
    445             else len = 0;
    446             break;
    447         case WPR_CHAR:
    448             *p = argData.char_view;
    449             if (*p != '\0') p++;
    450             else if (format.width > 1) *p++ = ' ';
    451             else len = 0;
    452             break;
    453         case WPR_STRING:
    454             memcpy( p, argData.lpcstr_view, len );
    455             p += len;
    456             break;
    457         case WPR_WSTRING:
    458             {
    459                 LPCWSTR ptr = argData.lpcwstr_view;
    460                 for (i = 0; i < len; i++) *p++ = (CHAR)*ptr++;
    461             }
    462             break;
    463         case WPR_HEXA:
    464             if ((format.flags & WPRINTF_PREFIX_HEX) && (maxlen > 3))
    465             {
    466                 *p++ = '0';
    467                 *p++ = (format.flags & WPRINTF_UPPER_HEX) ? 'X' : 'x';
    468                 maxlen -= 2;
    469                 len -= 2;
    470                 format.precision -= 2;
    471                 format.width -= 2;
    472             }
    473             /* fall through */
    474         case WPR_SIGNED:
    475         case WPR_UNSIGNED:
    476             for (i = len; i < format.precision; i++, maxlen--) *p++ = '0';
    477             memcpy( p, number, len );
    478             p += len;
    479             /* Go to the next arg */
    480             break;
    481         case WPR_UNKNOWN:
    482             continue;
    483         }
    484         if (format.flags & WPRINTF_LEFTALIGN)
    485             for (i = format.precision; i < format.width; i++, maxlen--)
    486                 *p++ = ' ';
    487         maxlen -= len;
    488     }
    489     *p = 0;
    490     //TRACE("%s\n",buffer);
    491     return (maxlen > 1) ? (INT)(p - buffer) : -1;
    492 }
    493 
    494 
    495 /***********************************************************************
    496  *           wvsnprintfW   (Not a Windows API)
    497  */
    498 INT WINAPI wvsnprintfW( LPWSTR buffer, UINT maxlen, LPCWSTR spec,
    499                             va_list args )
    500 {
    501     WPRINTF_FORMAT format;
    502     LPWSTR p = buffer;
    503     UINT i, len;
    504     CHAR number[20];
    505 
    506     while (*spec && (maxlen > 1))
    507     {
    508         if (*spec != '%') { *p++ = *spec++; maxlen--; continue; }
    509         spec++;
    510         if (*spec == '%') { *p++ = *spec++; maxlen--; continue; }
    511         spec += WPRINTF_ParseFormatW( spec, &format );
    512         len = WPRINTF_GetLen( &format, (WPRINTF_DATA*)args, number, maxlen - 1 );
    513         if (!(format.flags & WPRINTF_LEFTALIGN))
    514             for (i = format.precision; i < format.width; i++, maxlen--)
    515                 *p++ = ' ';
    516         switch(format.type)
    517         {
    518         case WPR_WCHAR:
    519             *p = va_arg( args, WCHAR );
    520             if (*p != '\0') p++;
    521             else if (format.width > 1) *p++ = ' ';
    522             else len = 0;
    523             break;
    524         case WPR_CHAR:
    525             *p = (WCHAR)va_arg( args, CHAR );
    526             if (*p != '\0') p++;
    527             else if (format.width > 1) *p++ = ' ';
    528             else len = 0;
    529             break;
    530         case WPR_STRING:
    531             {
    532                 LPCSTR ptr = va_arg( args, LPCSTR );
    533                 for (i = 0; i < len; i++) *p++ = (WCHAR)*ptr++;
    534             }
    535             break;
    536         case WPR_WSTRING:
    537             if (len) memcpy( p, va_arg( args, LPCWSTR ), len * sizeof(WCHAR) );
    538             p += len;
    539             break;
    540         case WPR_HEXA:
    541             if ((format.flags & WPRINTF_PREFIX_HEX) && (maxlen > 3))
    542             {
    543                 *p++ = '0';
    544                 *p++ = (format.flags & WPRINTF_UPPER_HEX) ? 'X' : 'x';
    545                 maxlen -= 2;
    546                 len -= 2;
    547                 format.precision -= 2;
    548                 format.width -= 2;
    549             }
    550             /* fall through */
    551         case WPR_SIGNED:
    552         case WPR_UNSIGNED:
    553             for (i = len; i < format.precision; i++, maxlen--) *p++ = '0';
    554             for (i = 0; i < len; i++) *p++ = (WCHAR)number[i];
    555             (void)va_arg( args, INT ); /* Go to the next arg */
    556             break;
    557         case WPR_UNKNOWN:
    558             continue;
    559         }
    560         if (format.flags & WPRINTF_LEFTALIGN)
    561             for (i = format.precision; i < format.width; i++, maxlen--)
    562                 *p++ = ' ';
    563         maxlen -= len;
    564     }
    565     *p = 0;
    566     return (maxlen > 1) ? (INT)(p - buffer) : -1;
    567 }
    568 
    569 /***********************************************************************
    570  *           wsnprintfA   (Not a Windows API)
    571  */
    572 INT WINAPIV wsnprintfA( LPSTR buffer, UINT maxlen, LPCSTR spec, ... )
    573 {
    574     va_list valist;
    575     INT res;
    576 
    577     va_start( valist, spec );
    578     res = wvsnprintfA( buffer, maxlen, spec, valist );
    579     va_end( valist );
    580     return res;
    581 }
    582 
    583 /***********************************************************************
    584  *           wsnprintfW   (Not a Windows API)
    585  */
    586 INT WINAPIV wsnprintfW( LPWSTR buffer, UINT maxlen, LPCWSTR spec, ... )
    587 {
    588     va_list valist;
    589     INT res;
    590 
    591     va_start( valist, spec );
    592     res = wvsnprintfW( buffer, maxlen, spec, valist );
    593     va_end( valist );
    594     return res;
    595 }
    596 
    597 
    598193/*****************************************************************************
    599194 * Name      : DWORD GetSystemTimeAsFileTime
Note: See TracChangeset for help on using the changeset viewer.