2000-08-04 06:21:02 +02:00
|
|
|
/*
|
2000-08-06 04:42:46 +02:00
|
|
|
* USER string functions
|
2000-08-04 06:21:02 +02:00
|
|
|
*
|
|
|
|
* Copyright 1993 Yngvi Sigurjonsson (yngvi@hafro.is)
|
2000-08-06 04:42:46 +02:00
|
|
|
* Copyright 1996 Alexandre Julliard
|
2000-08-04 06:21:02 +02:00
|
|
|
* Copyright 1996 Marcus Meissner
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
|
|
|
|
2001-07-18 23:04:23 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2000-08-06 04:42:46 +02:00
|
|
|
#include <ctype.h>
|
2000-08-04 06:21:02 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2001-01-22 03:17:29 +01:00
|
|
|
#include <string.h>
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2000-08-04 06:21:02 +02:00
|
|
|
#include "winbase.h"
|
2001-04-16 22:27:16 +02:00
|
|
|
#include "winerror.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "ntstatus.h"
|
2001-07-18 23:04:23 +02:00
|
|
|
|
|
|
|
#include "wine/exception.h"
|
|
|
|
#include "wine/unicode.h"
|
2000-08-04 06:21:02 +02:00
|
|
|
#include "wine/winbase16.h"
|
|
|
|
#include "wine/winuser16.h"
|
2001-07-18 23:04:23 +02:00
|
|
|
|
2002-12-13 00:34:01 +01:00
|
|
|
#include "excpt.h"
|
2002-02-25 21:10:35 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(resource);
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2001-04-16 22:27:16 +02:00
|
|
|
/* filter for page-fault exceptions */
|
|
|
|
static WINE_EXCEPTION_FILTER(page_fault)
|
|
|
|
{
|
|
|
|
if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ||
|
|
|
|
GetExceptionCode() == EXCEPTION_PRIV_INSTRUCTION)
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
}
|
|
|
|
|
2000-08-06 04:42:46 +02:00
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* AnsiToOem (KEYBOARD.5)
|
2000-08-06 04:42:46 +02:00
|
|
|
*/
|
|
|
|
INT16 WINAPI AnsiToOem16( LPCSTR s, LPSTR d )
|
|
|
|
{
|
|
|
|
CharToOemA( s, d );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* OemToAnsi (KEYBOARD.6)
|
2000-08-06 04:42:46 +02:00
|
|
|
*/
|
|
|
|
INT16 WINAPI OemToAnsi16( LPCSTR s, LPSTR d )
|
|
|
|
{
|
|
|
|
OemToCharA( s, d );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* AnsiToOemBuff (KEYBOARD.134)
|
2000-08-06 04:42:46 +02:00
|
|
|
*/
|
|
|
|
void WINAPI AnsiToOemBuff16( LPCSTR s, LPSTR d, UINT16 len )
|
|
|
|
{
|
|
|
|
if (len != 0) CharToOemBuffA( s, d, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* OemToAnsiBuff (KEYBOARD.135)
|
2000-08-06 04:42:46 +02:00
|
|
|
*/
|
|
|
|
void WINAPI OemToAnsiBuff16( LPCSTR s, LPSTR d, UINT16 len )
|
|
|
|
{
|
|
|
|
if (len != 0) OemToCharBuffA( s, d, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-26 00:00:06 +02:00
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* lstrcmp (USER.430)
|
2000-08-26 00:00:06 +02:00
|
|
|
*/
|
|
|
|
INT16 WINAPI lstrcmp16( LPCSTR str1, LPCSTR str2 )
|
|
|
|
{
|
|
|
|
return (INT16)strcmp( str1, str2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-06 04:42:46 +02:00
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* AnsiUpper (USER.431)
|
2000-08-06 04:42:46 +02:00
|
|
|
*/
|
|
|
|
SEGPTR WINAPI AnsiUpper16( SEGPTR strOrChar )
|
|
|
|
{
|
|
|
|
/* uppercase only one char if strOrChar < 0x10000 */
|
|
|
|
if (HIWORD(strOrChar))
|
|
|
|
{
|
2000-12-13 21:20:09 +01:00
|
|
|
CharUpperA( MapSL(strOrChar) );
|
2000-08-06 04:42:46 +02:00
|
|
|
return strOrChar;
|
|
|
|
}
|
|
|
|
else return toupper((char)strOrChar);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* AnsiLower (USER.432)
|
2000-08-06 04:42:46 +02:00
|
|
|
*/
|
|
|
|
SEGPTR WINAPI AnsiLower16( SEGPTR strOrChar )
|
|
|
|
{
|
|
|
|
/* lowercase only one char if strOrChar < 0x10000 */
|
|
|
|
if (HIWORD(strOrChar))
|
|
|
|
{
|
2000-12-13 21:20:09 +01:00
|
|
|
CharLowerA( MapSL(strOrChar) );
|
2000-08-06 04:42:46 +02:00
|
|
|
return strOrChar;
|
|
|
|
}
|
|
|
|
else return tolower((char)strOrChar);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* AnsiUpperBuff (USER.437)
|
2000-08-06 04:42:46 +02:00
|
|
|
*/
|
|
|
|
UINT16 WINAPI AnsiUpperBuff16( LPSTR str, UINT16 len )
|
|
|
|
{
|
|
|
|
CharUpperBuffA( str, len ? len : 65536 );
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* AnsiLowerBuff (USER.438)
|
2000-08-06 04:42:46 +02:00
|
|
|
*/
|
|
|
|
UINT16 WINAPI AnsiLowerBuff16( LPSTR str, UINT16 len )
|
|
|
|
{
|
|
|
|
CharLowerBuffA( str, len ? len : 65536 );
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* AnsiNext (USER.472)
|
2000-08-06 04:42:46 +02:00
|
|
|
*/
|
|
|
|
SEGPTR WINAPI AnsiNext16(SEGPTR current)
|
|
|
|
{
|
2000-12-13 21:20:09 +01:00
|
|
|
char *ptr = MapSL(current);
|
2000-08-06 04:42:46 +02:00
|
|
|
return current + (CharNextA(ptr) - ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* AnsiPrev (USER.473)
|
2000-08-06 04:42:46 +02:00
|
|
|
*/
|
|
|
|
SEGPTR WINAPI AnsiPrev16( LPCSTR start, SEGPTR current )
|
|
|
|
{
|
2000-12-13 21:20:09 +01:00
|
|
|
char *ptr = MapSL(current);
|
2000-08-06 04:42:46 +02:00
|
|
|
return current - (ptr - CharPrevA( start, ptr ));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CharNextA (USER32.@)
|
|
|
|
*/
|
|
|
|
LPSTR WINAPI CharNextA( LPCSTR ptr )
|
|
|
|
{
|
|
|
|
if (!*ptr) return (LPSTR)ptr;
|
|
|
|
if (IsDBCSLeadByte( ptr[0] ) && ptr[1]) return (LPSTR)(ptr + 2);
|
|
|
|
return (LPSTR)(ptr + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CharNextExA (USER32.@)
|
|
|
|
*/
|
|
|
|
LPSTR WINAPI CharNextExA( WORD codepage, LPCSTR ptr, DWORD flags )
|
|
|
|
{
|
|
|
|
if (!*ptr) return (LPSTR)ptr;
|
|
|
|
if (IsDBCSLeadByteEx( codepage, ptr[0] ) && ptr[1]) return (LPSTR)(ptr + 2);
|
|
|
|
return (LPSTR)(ptr + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CharNextExW (USER32.@)
|
|
|
|
*/
|
|
|
|
LPWSTR WINAPI CharNextExW( WORD codepage, LPCWSTR ptr, DWORD flags )
|
|
|
|
{
|
|
|
|
/* doesn't make sense, there are no codepages for Unicode */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CharNextW (USER32.@)
|
|
|
|
*/
|
|
|
|
LPWSTR WINAPI CharNextW(LPCWSTR x)
|
|
|
|
{
|
|
|
|
if (*x) x++;
|
2000-08-07 04:33:50 +02:00
|
|
|
|
|
|
|
return (LPWSTR)x;
|
2000-08-06 04:42:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CharPrevA (USER32.@)
|
|
|
|
*/
|
|
|
|
LPSTR WINAPI CharPrevA( LPCSTR start, LPCSTR ptr )
|
|
|
|
{
|
|
|
|
while (*start && (start < ptr))
|
|
|
|
{
|
|
|
|
LPCSTR next = CharNextA( start );
|
|
|
|
if (next >= ptr) break;
|
|
|
|
start = next;
|
|
|
|
}
|
|
|
|
return (LPSTR)start;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CharPrevExA (USER32.@)
|
|
|
|
*/
|
|
|
|
LPSTR WINAPI CharPrevExA( WORD codepage, LPCSTR start, LPCSTR ptr, DWORD flags )
|
|
|
|
{
|
|
|
|
while (*start && (start < ptr))
|
|
|
|
{
|
|
|
|
LPCSTR next = CharNextExA( codepage, start, flags );
|
|
|
|
if (next > ptr) break;
|
|
|
|
start = next;
|
|
|
|
}
|
|
|
|
return (LPSTR)start;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CharPrevExW (USER32.@)
|
|
|
|
*/
|
|
|
|
LPSTR WINAPI CharPrevExW( WORD codepage, LPCWSTR start, LPCWSTR ptr, DWORD flags )
|
|
|
|
{
|
|
|
|
/* doesn't make sense, there are no codepages for Unicode */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CharPrevW (USER32.@)
|
|
|
|
*/
|
|
|
|
LPWSTR WINAPI CharPrevW(LPCWSTR start,LPCWSTR x)
|
|
|
|
{
|
|
|
|
if (x>start) return (LPWSTR)(x-1);
|
|
|
|
else return (LPWSTR)x;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CharToOemA (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CharToOemA( LPCSTR s, LPSTR d )
|
|
|
|
{
|
|
|
|
if ( !s || !d ) return TRUE;
|
|
|
|
return CharToOemBuffA( s, d, strlen( s ) + 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CharToOemBuffA (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CharToOemBuffA( LPCSTR s, LPSTR d, DWORD len )
|
|
|
|
{
|
|
|
|
WCHAR *bufW;
|
|
|
|
|
|
|
|
bufW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
|
|
|
if( bufW )
|
|
|
|
{
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, s, len, bufW, len );
|
|
|
|
WideCharToMultiByte( CP_OEMCP, 0, bufW, len, d, len, NULL, NULL );
|
|
|
|
HeapFree( GetProcessHeap(), 0, bufW );
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CharToOemBuffW (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CharToOemBuffW( LPCWSTR s, LPSTR d, DWORD len )
|
|
|
|
{
|
|
|
|
if ( !s || !d ) return TRUE;
|
|
|
|
WideCharToMultiByte( CP_OEMCP, 0, s, len, d, len, NULL, NULL );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CharToOemW (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CharToOemW( LPCWSTR s, LPSTR d )
|
|
|
|
{
|
|
|
|
return CharToOemBuffW( s, d, strlenW( s ) + 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OemToCharA (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI OemToCharA( LPCSTR s, LPSTR d )
|
|
|
|
{
|
|
|
|
return OemToCharBuffA( s, d, strlen( s ) + 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OemToCharBuffA (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI OemToCharBuffA( LPCSTR s, LPSTR d, DWORD len )
|
|
|
|
{
|
|
|
|
WCHAR *bufW;
|
|
|
|
|
|
|
|
bufW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
|
|
|
if( bufW )
|
|
|
|
{
|
|
|
|
MultiByteToWideChar( CP_OEMCP, 0, s, len, bufW, len );
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, bufW, len, d, len, NULL, NULL );
|
|
|
|
HeapFree( GetProcessHeap(), 0, bufW );
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OemToCharBuffW (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI OemToCharBuffW( LPCSTR s, LPWSTR d, DWORD len )
|
|
|
|
{
|
|
|
|
MultiByteToWideChar( CP_OEMCP, 0, s, len, d, len );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OemToCharW (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI OemToCharW( LPCSTR s, LPWSTR d )
|
|
|
|
{
|
|
|
|
return OemToCharBuffW( s, d, strlen( s ) + 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-14 19:39:15 +02:00
|
|
|
/***********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* CharLowerA (USER32.@)
|
2000-08-14 19:39:15 +02:00
|
|
|
* FIXME: handle current locale
|
|
|
|
*/
|
|
|
|
LPSTR WINAPI CharLowerA(LPSTR x)
|
|
|
|
{
|
2001-04-16 22:27:16 +02:00
|
|
|
if (!HIWORD(x)) return (LPSTR)tolower((char)(int)x);
|
2000-08-14 19:39:15 +02:00
|
|
|
|
2001-04-16 22:27:16 +02:00
|
|
|
__TRY
|
2000-08-14 19:39:15 +02:00
|
|
|
{
|
2001-04-16 22:27:16 +02:00
|
|
|
LPSTR s = x;
|
2000-08-14 19:39:15 +02:00
|
|
|
while (*s)
|
|
|
|
{
|
|
|
|
*s=tolower(*s);
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
}
|
2001-04-16 22:27:16 +02:00
|
|
|
__EXCEPT(page_fault)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
__ENDTRY
|
|
|
|
return x;
|
2000-08-14 19:39:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CharUpperA (USER32.@)
|
|
|
|
* FIXME: handle current locale
|
|
|
|
*/
|
|
|
|
LPSTR WINAPI CharUpperA(LPSTR x)
|
|
|
|
{
|
2001-04-16 22:27:16 +02:00
|
|
|
if (!HIWORD(x)) return (LPSTR)toupper((char)(int)x);
|
|
|
|
|
|
|
|
__TRY
|
2000-08-14 19:39:15 +02:00
|
|
|
{
|
|
|
|
LPSTR s = x;
|
|
|
|
while (*s)
|
|
|
|
{
|
|
|
|
*s=toupper(*s);
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
}
|
2001-04-16 22:27:16 +02:00
|
|
|
__EXCEPT(page_fault)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
__ENDTRY
|
|
|
|
return x;
|
2000-08-14 19:39:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CharLowerW (USER32.@)
|
|
|
|
*/
|
|
|
|
LPWSTR WINAPI CharLowerW(LPWSTR x)
|
|
|
|
{
|
|
|
|
if (HIWORD(x)) return strlwrW(x);
|
|
|
|
else return (LPWSTR)((UINT)tolowerW(LOWORD(x)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CharUpperW (USER32.@)
|
|
|
|
*/
|
|
|
|
LPWSTR WINAPI CharUpperW(LPWSTR x)
|
|
|
|
{
|
|
|
|
if (HIWORD(x)) return struprW(x);
|
|
|
|
else return (LPWSTR)((UINT)toupperW(LOWORD(x)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CharLowerBuffA (USER32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI CharLowerBuffA( LPSTR str, DWORD len )
|
|
|
|
{
|
2001-06-14 21:27:01 +02:00
|
|
|
DWORD lenW;
|
|
|
|
WCHAR *strW;
|
2000-08-14 19:39:15 +02:00
|
|
|
if (!str) return 0; /* YES */
|
2001-06-14 21:27:01 +02:00
|
|
|
|
|
|
|
lenW = MultiByteToWideChar(CP_ACP, 0, str, len, NULL, 0);
|
|
|
|
strW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR));
|
|
|
|
if(strW)
|
|
|
|
{
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, str, len, strW, lenW);
|
|
|
|
CharLowerBuffW(strW, lenW);
|
|
|
|
len = WideCharToMultiByte(CP_ACP, 0, strW, lenW, str, len, NULL, NULL);
|
|
|
|
HeapFree(GetProcessHeap(), 0, strW);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
return 0;
|
2000-08-14 19:39:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CharLowerBuffW (USER32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI CharLowerBuffW( LPWSTR str, DWORD len )
|
|
|
|
{
|
|
|
|
DWORD ret = len;
|
|
|
|
if (!str) return 0; /* YES */
|
|
|
|
for (; len; len--, str++) *str = tolowerW(*str);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CharUpperBuffA (USER32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI CharUpperBuffA( LPSTR str, DWORD len )
|
|
|
|
{
|
2001-06-14 21:27:01 +02:00
|
|
|
DWORD lenW;
|
|
|
|
WCHAR *strW;
|
2000-08-14 19:39:15 +02:00
|
|
|
if (!str) return 0; /* YES */
|
2001-06-14 21:27:01 +02:00
|
|
|
|
|
|
|
lenW = MultiByteToWideChar(CP_ACP, 0, str, len, NULL, 0);
|
|
|
|
strW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR));
|
|
|
|
if(strW)
|
|
|
|
{
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, str, len, strW, lenW);
|
|
|
|
CharUpperBuffW(strW, lenW);
|
|
|
|
len = WideCharToMultiByte(CP_ACP, 0, strW, lenW, str, len, NULL, NULL);
|
|
|
|
HeapFree(GetProcessHeap(), 0, strW);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
return 0;
|
2000-08-14 19:39:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CharUpperBuffW (USER32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI CharUpperBuffW( LPWSTR str, DWORD len )
|
|
|
|
{
|
|
|
|
DWORD ret = len;
|
|
|
|
if (!str) return 0; /* YES */
|
|
|
|
for (; len; len--, str++) *str = toupperW(*str);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-11 22:53:40 +02:00
|
|
|
/***********************************************************************
|
2001-07-11 20:56:41 +02:00
|
|
|
* IsCharLower (USER.436)
|
2001-06-13 22:13:18 +02:00
|
|
|
* IsCharLowerA (USER32.@)
|
2000-08-11 22:53:40 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI IsCharLowerA(CHAR x)
|
|
|
|
{
|
2001-06-14 21:27:01 +02:00
|
|
|
WCHAR wch;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, &x, 1, &wch, 1);
|
|
|
|
return IsCharLowerW(wch);
|
2000-08-11 22:53:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* IsCharLowerW (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI IsCharLowerW(WCHAR x)
|
|
|
|
{
|
2001-06-14 21:27:01 +02:00
|
|
|
return (get_char_typeW(x) & C1_LOWER) != 0;
|
2000-08-11 22:53:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-11 20:56:41 +02:00
|
|
|
* IsCharUpper (USER.435)
|
2001-06-13 22:13:18 +02:00
|
|
|
* IsCharUpperA (USER32.@)
|
2000-08-11 22:53:40 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI IsCharUpperA(CHAR x)
|
|
|
|
{
|
2001-06-14 21:27:01 +02:00
|
|
|
WCHAR wch;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, &x, 1, &wch, 1);
|
|
|
|
return IsCharUpperW(wch);
|
2000-08-11 22:53:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* IsCharUpperW (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI IsCharUpperW(WCHAR x)
|
|
|
|
{
|
2001-06-14 21:27:01 +02:00
|
|
|
return (get_char_typeW(x) & C1_UPPER) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* IsCharAlphaNumeric (USER.434)
|
2001-06-14 21:27:01 +02:00
|
|
|
* IsCharAlphaNumericA (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI IsCharAlphaNumericA(CHAR x)
|
|
|
|
{
|
|
|
|
WCHAR wch;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, &x, 1, &wch, 1);
|
|
|
|
return IsCharAlphaNumericW(wch);
|
2000-08-11 22:53:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* IsCharAlphaNumericW (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI IsCharAlphaNumericW(WCHAR x)
|
|
|
|
{
|
2001-06-14 21:27:01 +02:00
|
|
|
return (get_char_typeW(x) & (C1_ALPHA|C1_DIGIT)) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* IsCharAlpha (USER.433)
|
2001-06-14 21:27:01 +02:00
|
|
|
* IsCharAlphaA (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI IsCharAlphaA(CHAR x)
|
|
|
|
{
|
|
|
|
WCHAR wch;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, &x, 1, &wch, 1);
|
|
|
|
return IsCharAlphaW(wch);
|
2000-08-11 22:53:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* IsCharAlphaW (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI IsCharAlphaW(WCHAR x)
|
|
|
|
{
|
2001-06-14 21:27:01 +02:00
|
|
|
return (get_char_typeW(x) & C1_ALPHA) != 0;
|
2000-08-11 22:53:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* FormatMessage (USER.606)
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI FormatMessage16(
|
|
|
|
DWORD dwFlags,
|
2000-12-02 00:58:28 +01:00
|
|
|
SEGPTR lpSource, /* [in] NOTE: not always a valid pointer */
|
2000-08-04 06:21:02 +02:00
|
|
|
WORD dwMessageId,
|
|
|
|
WORD dwLanguageId,
|
2000-12-02 00:58:28 +01:00
|
|
|
LPSTR lpBuffer, /* [out] NOTE: *((HLOCAL16*)) for FORMAT_MESSAGE_ALLOCATE_BUFFER*/
|
2000-08-04 06:21:02 +02:00
|
|
|
WORD nSize,
|
2000-12-02 00:58:28 +01:00
|
|
|
LPDWORD args /* [in] NOTE: va_list *args */
|
2000-08-04 06:21:02 +02:00
|
|
|
) {
|
|
|
|
#ifdef __i386__
|
2003-07-02 06:37:26 +02:00
|
|
|
/* This implementation is completely dependent on the format of the va_list on x86 CPUs */
|
2000-08-04 06:21:02 +02:00
|
|
|
LPSTR target,t;
|
|
|
|
DWORD talloced;
|
|
|
|
LPSTR from,f;
|
|
|
|
DWORD width = dwFlags & FORMAT_MESSAGE_MAX_WIDTH_MASK;
|
|
|
|
BOOL eos = FALSE;
|
|
|
|
LPSTR allocstring = NULL;
|
|
|
|
|
|
|
|
TRACE("(0x%lx,%lx,%d,0x%x,%p,%d,%p)\n",
|
|
|
|
dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args);
|
|
|
|
if ((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
|
|
|
|
&& (dwFlags & FORMAT_MESSAGE_FROM_HMODULE)) return 0;
|
|
|
|
if ((dwFlags & FORMAT_MESSAGE_FROM_STRING)
|
|
|
|
&&((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
|
|
|
|
|| (dwFlags & FORMAT_MESSAGE_FROM_HMODULE))) return 0;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if (width && width != FORMAT_MESSAGE_MAX_WIDTH_MASK)
|
2000-08-04 06:21:02 +02:00
|
|
|
FIXME("line wrapping (%lu) not supported.\n", width);
|
|
|
|
from = NULL;
|
|
|
|
if (dwFlags & FORMAT_MESSAGE_FROM_STRING)
|
2001-07-24 23:45:22 +02:00
|
|
|
{
|
|
|
|
char *source = MapSL(lpSource);
|
|
|
|
from = HeapAlloc( GetProcessHeap(), 0, strlen(source)+1 );
|
|
|
|
strcpy( from, source );
|
|
|
|
}
|
2000-08-04 06:21:02 +02:00
|
|
|
if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) {
|
|
|
|
from = HeapAlloc( GetProcessHeap(),0,200 );
|
|
|
|
sprintf(from,"Systemmessage, messageid = 0x%08x\n",dwMessageId);
|
|
|
|
}
|
|
|
|
if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) {
|
|
|
|
INT16 bufsize;
|
2002-10-15 23:00:05 +02:00
|
|
|
HINSTANCE16 hinst16 = ((HINSTANCE16)lpSource & 0xffff);
|
2000-08-04 06:21:02 +02:00
|
|
|
|
|
|
|
dwMessageId &= 0xFFFF;
|
|
|
|
bufsize=LoadString16(hinst16,dwMessageId,NULL,0);
|
|
|
|
if (bufsize) {
|
|
|
|
from = HeapAlloc( GetProcessHeap(), 0, bufsize +1);
|
|
|
|
LoadString16(hinst16,dwMessageId,from,bufsize+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
target = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 100);
|
|
|
|
t = target;
|
|
|
|
talloced= 100;
|
|
|
|
|
|
|
|
#define ADD_TO_T(c) \
|
|
|
|
*t++=c;\
|
|
|
|
if (t-target == talloced) {\
|
|
|
|
target = (char*)HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,talloced*2);\
|
|
|
|
t = target+talloced;\
|
|
|
|
talloced*=2;\
|
|
|
|
}
|
|
|
|
|
|
|
|
if (from) {
|
|
|
|
f=from;
|
|
|
|
while (*f && !eos) {
|
|
|
|
if (*f=='%') {
|
|
|
|
int insertnr;
|
|
|
|
char *fmtstr,*x,*lastf;
|
|
|
|
DWORD *argliststart;
|
|
|
|
|
|
|
|
fmtstr = NULL;
|
|
|
|
lastf = f;
|
|
|
|
f++;
|
|
|
|
if (!*f) {
|
|
|
|
ADD_TO_T('%');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (*f) {
|
|
|
|
case '1':case '2':case '3':case '4':case '5':
|
|
|
|
case '6':case '7':case '8':case '9':
|
|
|
|
insertnr=*f-'0';
|
|
|
|
switch (f[1]) {
|
|
|
|
case '0':case '1':case '2':case '3':
|
|
|
|
case '4':case '5':case '6':case '7':
|
|
|
|
case '8':case '9':
|
|
|
|
f++;
|
|
|
|
insertnr=insertnr*10+*f-'0';
|
|
|
|
f++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
f++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*f=='!') {
|
|
|
|
f++;
|
|
|
|
if (NULL!=(x=strchr(f,'!'))) {
|
|
|
|
*x='\0';
|
|
|
|
fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)+2);
|
|
|
|
sprintf(fmtstr,"%%%s",f);
|
|
|
|
f=x+1;
|
|
|
|
} else {
|
|
|
|
fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)+2);
|
|
|
|
sprintf(fmtstr,"%%%s",f);
|
|
|
|
f+=strlen(f); /*at \0*/
|
|
|
|
}
|
2001-07-24 23:45:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(!args) break;
|
|
|
|
fmtstr=HeapAlloc( GetProcessHeap(), 0, 3 );
|
|
|
|
strcpy( fmtstr, "%s" );
|
|
|
|
}
|
2000-08-04 06:21:02 +02:00
|
|
|
if (args) {
|
2001-12-26 20:48:15 +01:00
|
|
|
int ret;
|
2000-08-04 06:21:02 +02:00
|
|
|
int sz;
|
|
|
|
LPSTR b = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sz = 100);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
argliststart=args+insertnr-1;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
/* CMF - This makes a BIG assumption about va_list */
|
2001-12-26 20:48:15 +01:00
|
|
|
while ((ret = vsnprintf(b, sz, fmtstr, (va_list) argliststart) < 0) || (ret >= sz)) {
|
|
|
|
sz = (ret == -1 ? sz + 100 : ret + 1);
|
|
|
|
b = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, b, sz);
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
for (x=b; *x; x++) ADD_TO_T(*x);
|
2002-06-14 01:54:55 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, b);
|
2000-08-04 06:21:02 +02:00
|
|
|
} else {
|
2002-06-01 01:06:46 +02:00
|
|
|
/* NULL args - copy formatstr
|
2000-08-04 06:21:02 +02:00
|
|
|
* (probably wrong)
|
|
|
|
*/
|
|
|
|
while ((lastf<f)&&(*lastf)) {
|
|
|
|
ADD_TO_T(*lastf++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(),0,fmtstr);
|
|
|
|
break;
|
|
|
|
case '0': /* Just stop processing format string */
|
|
|
|
eos = TRUE;
|
|
|
|
f++;
|
|
|
|
break;
|
|
|
|
case 'n': /* 16 bit version just outputs 'n' */
|
|
|
|
default:
|
|
|
|
ADD_TO_T(*f++);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else { /* '\n' or '\r' gets mapped to "\r\n" */
|
|
|
|
if(*f == '\n' || *f == '\r') {
|
|
|
|
if (width == 0) {
|
|
|
|
ADD_TO_T('\r');
|
|
|
|
ADD_TO_T('\n');
|
|
|
|
if(*f++ == '\r' && *f == '\n')
|
|
|
|
f++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ADD_TO_T(*f++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*t='\0';
|
|
|
|
}
|
|
|
|
talloced = strlen(target)+1;
|
|
|
|
if (nSize && talloced<nSize) {
|
|
|
|
target = (char*)HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,nSize);
|
|
|
|
}
|
|
|
|
TRACE("-- %s\n",debugstr_a(target));
|
|
|
|
if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) {
|
|
|
|
/* nSize is the MINIMUM size */
|
|
|
|
HLOCAL16 h = LocalAlloc16(LPTR,talloced);
|
|
|
|
SEGPTR ptr = LocalLock16(h);
|
2000-12-13 21:20:09 +01:00
|
|
|
allocstring = MapSL( ptr );
|
2000-08-04 06:21:02 +02:00
|
|
|
memcpy( allocstring,target,talloced);
|
|
|
|
LocalUnlock16( h );
|
|
|
|
*((HLOCAL16*)lpBuffer) = h;
|
|
|
|
} else
|
|
|
|
lstrcpynA(lpBuffer,target,nSize);
|
|
|
|
HeapFree(GetProcessHeap(),0,target);
|
|
|
|
if (from) HeapFree(GetProcessHeap(),0,from);
|
2002-06-01 01:06:46 +02:00
|
|
|
return (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) ?
|
2000-08-04 06:21:02 +02:00
|
|
|
strlen(allocstring):
|
|
|
|
strlen(lpBuffer);
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif /* __i386__ */
|
|
|
|
}
|
|
|
|
#undef ADD_TO_T
|