2001-05-24 21:32:00 +02:00
|
|
|
/*
|
|
|
|
* Kernel string functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wine/winbase16.h"
|
|
|
|
|
|
|
|
|
|
|
|
static INT WINAPI (*pLoadStringA)(HINSTANCE, UINT, LPSTR, INT);
|
|
|
|
static INT WINAPI (*pwvsprintfA)(LPSTR, LPCSTR, va_list);
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Helper for k32 family functions
|
|
|
|
*/
|
|
|
|
static void *user32_proc_address(const char *proc_name)
|
|
|
|
{
|
|
|
|
static HMODULE hUser32;
|
|
|
|
|
|
|
|
if(!hUser32) hUser32 = LoadLibraryA("user32.dll");
|
|
|
|
return GetProcAddress(hUser32, proc_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* Reserved5 (KERNEL.87)
|
2001-05-24 21:32:00 +02:00
|
|
|
*/
|
|
|
|
INT16 WINAPI KERNEL_lstrcmp16( LPCSTR str1, LPCSTR str2 )
|
|
|
|
{
|
|
|
|
return (INT16)strcmp( str1, str2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* k32CharToOemBuffA (KERNEL32.11)
|
2001-05-24 21:32:00 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI k32CharToOemBuffA(LPCSTR s, LPSTR d, DWORD len)
|
|
|
|
{
|
|
|
|
WCHAR *bufW;
|
|
|
|
|
|
|
|
if ((bufW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
|
|
|
|
{
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, s, len, bufW, len );
|
|
|
|
WideCharToMultiByte( CP_OEMCP, 0, bufW, len, d, len, NULL, NULL );
|
|
|
|
HeapFree( GetProcessHeap(), 0, bufW );
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* k32CharToOemA (KERNEL32.10)
|
2001-05-24 21:32:00 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI k32CharToOemA(LPCSTR s, LPSTR d)
|
|
|
|
{
|
|
|
|
if (!s || !d) return TRUE;
|
|
|
|
return k32CharToOemBuffA( s, d, strlen(s) + 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* k32OemToCharBuffA (KERNEL32.13)
|
2001-05-24 21:32:00 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI k32OemToCharBuffA(LPCSTR s, LPSTR d, DWORD len)
|
|
|
|
{
|
|
|
|
WCHAR *bufW;
|
|
|
|
|
|
|
|
if ((bufW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
|
|
|
|
{
|
|
|
|
MultiByteToWideChar( CP_OEMCP, 0, s, len, bufW, len );
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, bufW, len, d, len, NULL, NULL );
|
|
|
|
HeapFree( GetProcessHeap(), 0, bufW );
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* k32OemToCharA (KERNEL32.12)
|
2001-05-24 21:32:00 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI k32OemToCharA(LPCSTR s, LPSTR d)
|
|
|
|
{
|
|
|
|
return k32OemToCharBuffA( s, d, strlen(s) + 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* k32LoadStringA (KERNEL32.14)
|
2001-05-24 21:32:00 +02:00
|
|
|
*/
|
|
|
|
INT WINAPI k32LoadStringA(HINSTANCE instance, UINT resource_id,
|
|
|
|
LPSTR buffer, INT buflen)
|
|
|
|
{
|
|
|
|
if(!pLoadStringA) pLoadStringA = user32_proc_address("LoadStringA");
|
|
|
|
return pLoadStringA(instance, resource_id, buffer, buflen);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* k32wvsprintfA (KERNEL32.16)
|
2001-05-24 21:32:00 +02:00
|
|
|
*/
|
|
|
|
INT WINAPI k32wvsprintfA(LPSTR buffer, LPCSTR spec, va_list args)
|
|
|
|
{
|
|
|
|
if(!pwvsprintfA) pwvsprintfA = user32_proc_address("wvsprintfA");
|
|
|
|
return (*pwvsprintfA)(buffer, spec, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* k32wsprintfA (KERNEL32.15)
|
2001-05-24 21:32:00 +02:00
|
|
|
*/
|
|
|
|
INT WINAPIV k32wsprintfA(LPSTR buffer, LPCSTR spec, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
INT res;
|
|
|
|
|
|
|
|
va_start(args, spec);
|
|
|
|
res = k32wvsprintfA(buffer, spec, args);
|
|
|
|
va_end(args);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* Win 2.x string functions now moved to USER
|
|
|
|
*
|
|
|
|
* We rather want to implement them here instead of doing Callouts
|
|
|
|
*/
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* Reserved1 (KERNEL.77)
|
2001-05-24 21:32:00 +02:00
|
|
|
*/
|
|
|
|
SEGPTR WINAPI KERNEL_AnsiNext16(SEGPTR current)
|
|
|
|
{
|
|
|
|
return (*(char *)MapSL(current)) ? current + 1 : current;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* Reserved2(KERNEL.78)
|
2001-05-24 21:32:00 +02:00
|
|
|
*/
|
|
|
|
SEGPTR WINAPI KERNEL_AnsiPrev16( SEGPTR start, SEGPTR current )
|
|
|
|
{
|
|
|
|
return (current==start)?start:current-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* Reserved3 (KERNEL.79)
|
2001-05-24 21:32:00 +02:00
|
|
|
*/
|
|
|
|
SEGPTR WINAPI KERNEL_AnsiUpper16( SEGPTR strOrChar )
|
|
|
|
{
|
|
|
|
/* uppercase only one char if strOrChar < 0x10000 */
|
|
|
|
if (HIWORD(strOrChar))
|
|
|
|
{
|
|
|
|
char *s = MapSL(strOrChar);
|
|
|
|
while (*s)
|
|
|
|
{
|
|
|
|
*s = toupper(*s);
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
return strOrChar;
|
|
|
|
}
|
|
|
|
else return toupper((char)strOrChar);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* Reserved4 (KERNEL.80)
|
2001-05-24 21:32:00 +02:00
|
|
|
*/
|
|
|
|
SEGPTR WINAPI KERNEL_AnsiLower16( SEGPTR strOrChar )
|
|
|
|
{
|
|
|
|
/* lowercase only one char if strOrChar < 0x10000 */
|
|
|
|
if (HIWORD(strOrChar))
|
|
|
|
{
|
|
|
|
char *s = MapSL(strOrChar);
|
|
|
|
while (*s)
|
|
|
|
{
|
|
|
|
*s = tolower(*s);
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
return strOrChar;
|
|
|
|
}
|
|
|
|
else return tolower((char)strOrChar);
|
|
|
|
}
|