Changeset 1838 for trunk/src


Ignore:
Timestamp:
Nov 25, 1999, 8:19:57 PM (26 years ago)
Author:
sandervl
Message:

EB's unicode changes + removal of advapi32 dependency

Location:
trunk/src/kernel32
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/cpu.cpp

    r1820 r1838  
    1 /* $Id: cpu.cpp,v 1.2 1999-11-23 20:01:17 sandervl Exp $ */
     1/* $Id: cpu.cpp,v 1.3 1999-11-25 19:19:57 sandervl Exp $ */
    22/*
    33 * Odin win32 CPU apis
     
    2626static BYTE PF[64] = {0,};
    2727static nrCPUs = 1;
     28static HINSTANCE hInstance = 0;
     29
     30LONG (WINAPI *ADVAPI32_RegCloseKey)(HKEY) = 0;
     31LONG (WINAPI *ADVAPI32_RegCreateKeyA)(HKEY,LPCSTR,LPHKEY) = 0;
     32LONG (WINAPI *ADVAPI32_RegSetValueExA)(HKEY,LPSTR,DWORD,DWORD,LPBYTE,DWORD) = 0;
     33
    2834//******************************************************************************
    2935//******************************************************************************
     
    3137{
    3238  SYSTEM_INFO si;
     39
     40   hInstance = LoadLibraryA("ADVAPI32.DLL");
     41   if(hInstance) {
     42        *(VOID **)&ADVAPI32_RegCloseKey=(void*)GetProcAddress(hInstance, (LPCSTR)"RegCloseKey");
     43        *(VOID **)&ADVAPI32_RegCreateKeyA=(void*)GetProcAddress(hInstance, (LPCSTR)"RegCreateKeyA");
     44        *(VOID **)&ADVAPI32_RegSetValueExA=(void*)GetProcAddress(hInstance, (LPCSTR)"RegSetValueExA");
     45   }
    3346
    3447   nrCPUs = nrcpus;
     
    97110
    98111        /* Create this registry key for all systems */
    99         if (RegCreateKeyA(HKEY_LOCAL_MACHINE,"HARDWARE\\DESCRIPTION\\System\\CentralProcessor",&hkey)!=ERROR_SUCCESS) {
     112        if (ADVAPI32_RegCreateKeyA(HKEY_LOCAL_MACHINE,"HARDWARE\\DESCRIPTION\\System\\CentralProcessor",&hkey)!=ERROR_SUCCESS) {
    100113            dprintf(("Unable to register CPU information\n"));
    101114        }
     
    108121                sprintf(buf,"%d",i);
    109122                if (xhkey)
    110                         RegCloseKey(xhkey);
    111                 RegCreateKeyA(hkey,buf,&xhkey);
     123                        ADVAPI32_RegCloseKey(xhkey);
     124                ADVAPI32_RegCreateKeyA(hkey,buf,&xhkey);
    112125
    113126                signature = GetCPUSignature();
     
    132145                sprintf(buf,"CPU %ld",cachedsi.dwProcessorType);
    133146                if (xhkey) {
    134                         RegSetValueExA(xhkey,"Identifier",0,REG_SZ,(LPBYTE)buf,strlen(buf));
     147                        ADVAPI32_RegSetValueExA(xhkey,"Identifier",0,REG_SZ,(LPBYTE)buf,strlen(buf));
    135148                        memset(buf, 0, sizeof(buf));
    136149                        GetCPUVendorString(buf);
    137                         RegSetValueExA(xhkey,"VendorIdentifier",0,REG_SZ,(LPBYTE)buf,strlen(buf));
     150                        ADVAPI32_RegSetValueExA(xhkey,"VendorIdentifier",0,REG_SZ,(LPBYTE)buf,strlen(buf));
    138151                }
    139152                cachedsi.wProcessorRevision = signature & 0xf;
     
    157170                if (features & CPUID_FPU_PRESENT) {
    158171                        if (i == 0) {
    159                                 if(RegCreateKeyA(HKEY_LOCAL_MACHINE,"HARDWARE\\DESCRIPTION\\System\\FloatingPointProcessor",&fpukey)!=ERROR_SUCCESS)
     172                                if(ADVAPI32_RegCreateKeyA(HKEY_LOCAL_MACHINE,"HARDWARE\\DESCRIPTION\\System\\FloatingPointProcessor",&fpukey)!=ERROR_SUCCESS)
    160173                                        dprintf(("Unable to register FPU information\n"));
    161174                        }
     
    163176                        if(fpukey) {
    164177                                sprintf(buf,"%d",i);
    165                                 RegCreateKeyA(fpukey,buf,&xhfpukey);
     178                                ADVAPI32_RegCreateKeyA(fpukey,buf,&xhfpukey);
    166179                        }
    167180                }
     
    172185
    173186        if (xhkey)
    174                 RegCloseKey(xhkey);
     187                ADVAPI32_RegCloseKey(xhkey);
    175188        if (hkey)
    176                 RegCloseKey(hkey);
     189                ADVAPI32_RegCloseKey(hkey);
    177190        if (xhfpukey)
    178                 RegCloseKey(xhfpukey);
     191                ADVAPI32_RegCloseKey(xhfpukey);
    179192        if (fpukey)
    180                 RegCloseKey(fpukey);
     193                ADVAPI32_RegCloseKey(fpukey);
    181194
    182195}
  • trunk/src/kernel32/makefile

    r1833 r1838  
    1 # $Id: makefile,v 1.61 1999-11-24 19:31:23 sandervl Exp $
     1# $Id: makefile,v 1.62 1999-11-25 19:19:57 sandervl Exp $
    22
    33#
     
    7474$(PDWIN32_LIB)\LIBCONV.LIB
    7575$(PDWIN32_LIB)\odincrt.lib
    76 $(PDWIN32_LIB)\advapi32.lib
    7776OS2386.LIB
    7877$(RTLLIB_O)
  • trunk/src/kernel32/unicode.cpp

    r917 r1838  
    1 /* $Id: unicode.cpp,v 1.14 1999-09-13 09:06:05 sandervl Exp $ */
     1/* $Id: unicode.cpp,v 1.15 1999-11-25 19:19:57 sandervl Exp $ */
    22
    33/*
     
    4141}
    4242
    43 //******************************************************************************
    44 //Not identical, but close enough
    45 //******************************************************************************
    46 int WIN32API MultiByteToWideChar(UINT uCodePage, DWORD dwFlags, LPCSTR lpMultiByteStr,
    47                                    int  cchMultiByte, LPWSTR lpWideCharStr, int cchWideChar)
    48 {
    49  int i, len;
    50 
    51 //  dprintf(("MultiByteToWideChar %s\n", lpMultiByteStr));
    52 
    53   if((int)lpMultiByteStr == (int)lpWideCharStr) {//not allowed
    54         SetLastError(ERROR_INVALID_PARAMETER);
    55         return(FALSE);
    56   }
    57   if(cchWideChar == 0) {//return space required for conversion
    58         if(cchMultiByte == -1)
    59             cchMultiByte = strlen(lpMultiByteStr) + 1;
    60         return(cchMultiByte);   //return length in wide chars
    61   }
    62   if(cchMultiByte == -1)
    63         cchMultiByte = strlen(lpMultiByteStr) + 1;
    64 
    65   len = min(cchWideChar, cchMultiByte);
    66   for(i=0;i<=len;i++) { //including 0 terminator
    67         lpWideCharStr[i] = lpMultiByteStr[i];
    68   }
    69   return(len);
    70 }
    71 //******************************************************************************
    72 //******************************************************************************
    73 //Not identical, close enough
    74 //Forget about characters that can't be mapped; just do it
    75 //******************************************************************************
    76 int WIN32API WideCharToMultiByte(UINT uCodePage, DWORD dwFlags, LPCWSTR lpWideCharStr,
    77                                    int cchWideChar, LPSTR lpMultiByteStr,
    78                                    int cchMultiByte, LPCSTR lpDefaultChar,
    79                                    LPBOOL lpfUsedDefaultChar)
    80 {
    81  int i, len;
    82 
    83 //  dprintf(("WideCharToMultiByte\n"));
    84 
    85   if((int)lpMultiByteStr == (int)lpWideCharStr) {//not allowed
    86         SetLastError(ERROR_INVALID_PARAMETER);
    87         return(FALSE);
    88   }
    89   if(cchMultiByte == 0) {//return space required for conversion
    90         if(cchWideChar == -1)   cchWideChar = UniStrlen((UniChar *)lpWideCharStr);
    91         return(cchWideChar);
    92   }
    93   if(cchWideChar == -1)
    94         cchWideChar = UniStrlen((UniChar*)lpWideCharStr);
    95 
    96   len = min(cchWideChar, cchMultiByte);
    97   for(i=0;i<=len;i++) { //including 0 terminator
    98         lpMultiByteStr[i] = (UCHAR)lpWideCharStr[i];
    99   }
    100   return(len);
     43/***********************************************************************
     44 *              MultiByteToWideChar                (KERNEL32.534)
     45 *
     46 * PARAMS
     47 *   page [in]   Codepage character set to convert from
     48 *   flags [in]  Character mapping flags
     49 *   src [in]     Source string buffer
     50 *   srclen [in]  Length of source string buffer
     51 *   dst [in]     Destination buffer
     52 *   dstlen [in]  Length of destination buffer
     53 *
     54 * NOTES
     55 *   The returned length includes the null terminator character.
     56 *
     57 * RETURNS
     58 *   Success: If dstlen > 0, number of characters written to destination
     59 *            buffer.  If dstlen == 0, number of characters needed to do
     60 *            conversion.
     61 *   Failure: 0. Occurs if not enough space is available.
     62 *
     63 * ERRORS
     64 *   ERROR_INSUFFICIENT_BUFFER
     65 *   ERROR_INVALID_FLAGS (not yet implemented)
     66 *   ERROR_INVALID_PARAMETER (not yet implemented)
     67 *
     68 * BUGS
     69 *   Does not properly handle codepage conversions.
     70 *   Does not properly handle flags.
     71 *
     72 */
     73INT WINAPI MultiByteToWideChar(UINT page, DWORD flags,
     74                                 LPCSTR src, INT srclen,
     75                                 LPWSTR dst, INT dstlen)
     76{
     77    int ret;
     78
     79    if (srclen == -1)
     80        srclen = lstrlenA(src)+1;
     81    if (!dstlen || !dst)
     82        return srclen;
     83
     84    ret = srclen;
     85    while (srclen && dstlen) {
     86        *dst = (WCHAR)(unsigned char)*src;
     87        dst++;    src++;
     88        dstlen--; srclen--;
     89    }
     90    if (!dstlen && srclen) {
     91        SetLastError(ERROR_INSUFFICIENT_BUFFER);
     92        return 0;
     93    }
     94    return ret;
     95}
     96
     97/***********************************************************************
     98 *              WideCharToMultiByte                (KERNEL32.727)
     99 *
     100 * PARAMS
     101 *   page [in]    Codepage character set to convert to
     102 *   flags [in]   Character mapping flags
     103 *   src [in]     Source string buffer
     104 *   srclen [in]  Length of source string buffer
     105 *   dst [in]     Destination buffer
     106 *   dstlen [in]  Length of destination buffer
     107 *   defchar [in] Default character to use for conversion if no exact
     108 *                  conversion can be made
     109 *   used [out]   Set if default character was used in the conversion
     110 *
     111 * NOTES
     112 *   The returned length includes the null terminator character.
     113 *
     114 * RETURNS
     115 *   Success: If dstlen > 0, number of characters written to destination
     116 *            buffer.  If dstlen == 0, number of characters needed to do
     117 *            conversion.
     118 *   Failure: 0. Occurs if not enough space is available.
     119 *
     120 * ERRORS
     121 *   ERROR_INSUFFICIENT_BUFFER
     122 *   ERROR_INVALID_FLAGS (not yet implemented)
     123 *
     124 * BUGS
     125 *   Does not properly handle codepage conversions.
     126 *   Does not properly handle flags.
     127 *
     128 */
     129INT WIN32API WideCharToMultiByte(UINT page, DWORD flags, LPCWSTR src,
     130                                 INT srclen,LPSTR dst, INT dstlen,
     131                                 LPCSTR defchar, BOOL *used)
     132{
     133    int count = 0;
     134    int eos = 0;
     135    int care_for_eos=0;
     136    int dont_copy= (dstlen==0);
     137
     138    if ((!src) || ((!dst) && (!dont_copy)) )
     139    {   SetLastError(ERROR_INVALID_PARAMETER);
     140        return 0;
     141    }
     142   
     143    if (page!=GetACP() && page!=CP_OEMCP && page!=CP_ACP)
     144        dprintf(("WideCharToMultiByte, Conversion in CP %d not supported\n",page));
     145#if 0
     146    if (flags)
     147        dprintf(("WideCharToMultiByte, flags %lx not supported\n",flags));
     148#endif
     149    if(used)
     150        *used=0;
     151    if (srclen == -1)
     152      {
     153        srclen = lstrlenW(src)+1;
     154         care_for_eos=1;
     155      }
     156    while(srclen && (dont_copy || dstlen))
     157    {
     158        if(!dont_copy){
     159            if(*src<256)
     160                *dst = *src;
     161            else
     162            {
     163                /* ??? The WC_DEFAULTCHAR flag only gets used in
     164                 * combination with the WC_COMPOSITECHECK flag or at
     165                 * least this is what it seems from using the function
     166                 * on NT4.0 in combination with reading the documentation.
     167                 */
     168                *dst = defchar ? *defchar : '?';
     169                if(used)*used=1;
     170            }
     171            dstlen--;
     172            dst++;
     173        }
     174        count++;
     175        srclen--;
     176        if((!*src) && care_for_eos) {
     177            eos = 1;
     178            break;
     179        }
     180        src++;
     181    }
     182    if (dont_copy)
     183        return count;
     184
     185    if (!eos && srclen > 0) {
     186        SetLastError(ERROR_INSUFFICIENT_BUFFER);
     187        return 0;
     188    }
     189    return count;
    101190}
    102191//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.