From 89b0f3ae6ec09c92643a6f8b0057ebc5647f7fc1 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 29 Mar 2005 13:15:44 +0000 Subject: [PATCH] Moved 16-bit string functions to user16.c and kbd16.c. --- dlls/user/kbd16.c | 33 +++++ dlls/user/lstr.c | 311 +-------------------------------------------- dlls/user/user16.c | 272 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 306 insertions(+), 310 deletions(-) diff --git a/dlls/user/kbd16.c b/dlls/user/kbd16.c index 57f2c35aa50..d010407771a 100644 --- a/dlls/user/kbd16.c +++ b/dlls/user/kbd16.c @@ -85,6 +85,23 @@ VOID WINAPI KEYBOARD_Disable(VOID) pKeyStateTable = NULL; } +/*********************************************************************** + * AnsiToOem (KEYBOARD.5) + */ +INT16 WINAPI AnsiToOem16( LPCSTR s, LPSTR d ) +{ + CharToOemA( s, d ); + return -1; +} + +/*********************************************************************** + * OemToAnsi (KEYBOARD.6) + */ +INT16 WINAPI OemToAnsi16( LPCSTR s, LPSTR d ) +{ + OemToCharA( s, d ); + return -1; +} /********************************************************************** * SetSpeed (KEYBOARD.7) @@ -153,6 +170,22 @@ INT16 WINAPI GetKeyNameText16(LONG lParam, LPSTR lpBuffer, INT16 nSize) return GetKeyNameTextA( lParam, lpBuffer, nSize ); } +/*********************************************************************** + * AnsiToOemBuff (KEYBOARD.134) + */ +void WINAPI AnsiToOemBuff16( LPCSTR s, LPSTR d, UINT16 len ) +{ + if (len != 0) CharToOemBuffA( s, d, len ); +} + +/*********************************************************************** + * OemToAnsiBuff (KEYBOARD.135) + */ +void WINAPI OemToAnsiBuff16( LPCSTR s, LPSTR d, UINT16 len ) +{ + if (len != 0) OemToCharBuffA( s, d, len ); +} + /**************************************************************************** * ToAscii (KEYBOARD.4) * diff --git a/dlls/user/lstr.c b/dlls/user/lstr.c index af83db3a9af..9a3473819c0 100644 --- a/dlls/user/lstr.c +++ b/dlls/user/lstr.c @@ -31,13 +31,11 @@ #include "windef.h" #include "winbase.h" +#include "winuser.h" #include "winerror.h" #include "wine/exception.h" #include "wine/unicode.h" -#include "wine/winbase16.h" -#include "wine/winuser16.h" - #include "excpt.h" #include "wine/debug.h" @@ -53,123 +51,6 @@ static WINE_EXCEPTION_FILTER(page_fault) return EXCEPTION_CONTINUE_SEARCH; } -/*********************************************************************** - * AnsiToOem (KEYBOARD.5) - */ -INT16 WINAPI AnsiToOem16( LPCSTR s, LPSTR d ) -{ - CharToOemA( s, d ); - return -1; -} - - -/*********************************************************************** - * OemToAnsi (KEYBOARD.6) - */ -INT16 WINAPI OemToAnsi16( LPCSTR s, LPSTR d ) -{ - OemToCharA( s, d ); - return -1; -} - - -/*********************************************************************** - * AnsiToOemBuff (KEYBOARD.134) - */ -void WINAPI AnsiToOemBuff16( LPCSTR s, LPSTR d, UINT16 len ) -{ - if (len != 0) CharToOemBuffA( s, d, len ); -} - - -/*********************************************************************** - * OemToAnsiBuff (KEYBOARD.135) - */ -void WINAPI OemToAnsiBuff16( LPCSTR s, LPSTR d, UINT16 len ) -{ - if (len != 0) OemToCharBuffA( s, d, len ); -} - - -/*********************************************************************** - * lstrcmp (USER.430) - */ -INT16 WINAPI lstrcmp16( LPCSTR str1, LPCSTR str2 ) -{ - return (INT16)strcmp( str1, str2 ); -} - - -/*********************************************************************** - * AnsiUpper (USER.431) - */ -SEGPTR WINAPI AnsiUpper16( SEGPTR strOrChar ) -{ - /* uppercase only one char if strOrChar < 0x10000 */ - if (HIWORD(strOrChar)) - { - CharUpperA( MapSL(strOrChar) ); - return strOrChar; - } - else return (SEGPTR)CharUpperA( (LPSTR)strOrChar ); -} - - -/*********************************************************************** - * AnsiLower (USER.432) - */ -SEGPTR WINAPI AnsiLower16( SEGPTR strOrChar ) -{ - /* lowercase only one char if strOrChar < 0x10000 */ - if (HIWORD(strOrChar)) - { - CharLowerA( MapSL(strOrChar) ); - return strOrChar; - } - else return (SEGPTR)CharLowerA( (LPSTR)strOrChar ); -} - - -/*********************************************************************** - * AnsiUpperBuff (USER.437) - */ -UINT16 WINAPI AnsiUpperBuff16( LPSTR str, UINT16 len ) -{ - CharUpperBuffA( str, len ? len : 65536 ); - return len; -} - - -/*********************************************************************** - * AnsiLowerBuff (USER.438) - */ -UINT16 WINAPI AnsiLowerBuff16( LPSTR str, UINT16 len ) -{ - CharLowerBuffA( str, len ? len : 65536 ); - return len; -} - - -/*********************************************************************** - * AnsiNext (USER.472) - */ -SEGPTR WINAPI AnsiNext16(SEGPTR current) -{ - char *ptr = MapSL(current); - return current + (CharNextA(ptr) - ptr); -} - - -/*********************************************************************** - * AnsiPrev (USER.473) - */ -SEGPTR WINAPI AnsiPrev16( LPCSTR start, SEGPTR current ) -{ - char *ptr = MapSL(current); - return current - (ptr - CharPrevA( start, ptr )); -} - - /*********************************************************************** * CharNextA (USER32.@) */ @@ -585,193 +466,3 @@ BOOL WINAPI IsCharAlphaW(WCHAR x) { return (get_char_typeW(x) & C1_ALPHA) != 0; } - - -/*********************************************************************** - * FormatMessage (USER.606) - */ -DWORD WINAPI FormatMessage16( - DWORD dwFlags, - SEGPTR lpSource, /* [in] NOTE: not always a valid pointer */ - WORD dwMessageId, - WORD dwLanguageId, - LPSTR lpBuffer, /* [out] NOTE: *((HLOCAL16*)) for FORMAT_MESSAGE_ALLOCATE_BUFFER*/ - WORD nSize, - LPDWORD args /* [in] NOTE: va_list *args */ -) { -#ifdef __i386__ -/* This implementation is completely dependent on the format of the va_list on x86 CPUs */ - 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; - - if (width && width != FORMAT_MESSAGE_MAX_WIDTH_MASK) - FIXME("line wrapping (%lu) not supported.\n", width); - from = NULL; - if (dwFlags & FORMAT_MESSAGE_FROM_STRING) - { - char *source = MapSL(lpSource); - from = HeapAlloc( GetProcessHeap(), 0, strlen(source)+1 ); - strcpy( from, source ); - } - else if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) { - from = HeapAlloc( GetProcessHeap(),0,200 ); - sprintf(from,"Systemmessage, messageid = 0x%08x\n",dwMessageId); - } - else if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) { - INT16 bufsize; - HINSTANCE16 hinst16 = ((HINSTANCE16)lpSource & 0xffff); - - 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 = 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*/ - } - } - else - { - if(!args) break; - fmtstr=HeapAlloc( GetProcessHeap(), 0, 3 ); - strcpy( fmtstr, "%s" ); - } - if (args) { - int ret; - int sz; - LPSTR b = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sz = 100); - - argliststart=args+insertnr-1; - - /* CMF - This makes a BIG assumption about va_list */ - 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); - } - for (x=b; *x; x++) ADD_TO_T(*x); - HeapFree(GetProcessHeap(), 0, b); - } else { - /* NULL args - copy formatstr - * (probably wrong) - */ - while ((lastf #include +#include +#include + #include "wine/winuser16.h" #include "windef.h" #include "winbase.h" @@ -1167,6 +1170,65 @@ BOOL16 WINAPI SetMenuItemBitmaps16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags, } +/*********************************************************************** + * lstrcmp (USER.430) + */ +INT16 WINAPI lstrcmp16( LPCSTR str1, LPCSTR str2 ) +{ + return strcmp( str1, str2 ); +} + + +/*********************************************************************** + * AnsiUpper (USER.431) + */ +SEGPTR WINAPI AnsiUpper16( SEGPTR strOrChar ) +{ + /* uppercase only one char if strOrChar < 0x10000 */ + if (HIWORD(strOrChar)) + { + CharUpperA( MapSL(strOrChar) ); + return strOrChar; + } + else return (SEGPTR)CharUpperA( (LPSTR)strOrChar ); +} + + +/*********************************************************************** + * AnsiLower (USER.432) + */ +SEGPTR WINAPI AnsiLower16( SEGPTR strOrChar ) +{ + /* lowercase only one char if strOrChar < 0x10000 */ + if (HIWORD(strOrChar)) + { + CharLowerA( MapSL(strOrChar) ); + return strOrChar; + } + else return (SEGPTR)CharLowerA( (LPSTR)strOrChar ); +} + + +/*********************************************************************** + * AnsiUpperBuff (USER.437) + */ +UINT16 WINAPI AnsiUpperBuff16( LPSTR str, UINT16 len ) +{ + CharUpperBuffA( str, len ? len : 65536 ); + return len; +} + + +/*********************************************************************** + * AnsiLowerBuff (USER.438) + */ +UINT16 WINAPI AnsiLowerBuff16( LPSTR str, UINT16 len ) +{ + CharLowerBuffA( str, len ? len : 65536 ); + return len; +} + + /******************************************************************* * InsertMenuItem (USER.441) * @@ -1432,6 +1494,216 @@ void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc ) } +/*********************************************************************** + * AnsiNext (USER.472) + */ +SEGPTR WINAPI AnsiNext16(SEGPTR current) +{ + char *ptr = MapSL(current); + return current + (CharNextA(ptr) - ptr); +} + + +/*********************************************************************** + * AnsiPrev (USER.473) + */ +SEGPTR WINAPI AnsiPrev16( LPCSTR start, SEGPTR current ) +{ + char *ptr = MapSL(current); + return current - (ptr - CharPrevA( start, ptr )); +} + + +/*********************************************************************** + * FormatMessage (USER.606) + */ +DWORD WINAPI FormatMessage16( + DWORD dwFlags, + SEGPTR lpSource, /* [in] NOTE: not always a valid pointer */ + WORD dwMessageId, + WORD dwLanguageId, + LPSTR lpBuffer, /* [out] NOTE: *((HLOCAL16*)) for FORMAT_MESSAGE_ALLOCATE_BUFFER*/ + WORD nSize, + LPDWORD args ) /* [in] NOTE: va_list *args */ +{ +#ifdef __i386__ +/* This implementation is completely dependent on the format of the va_list on x86 CPUs */ + 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; + + if (width && width != FORMAT_MESSAGE_MAX_WIDTH_MASK) + FIXME("line wrapping (%lu) not supported.\n", width); + from = NULL; + if (dwFlags & FORMAT_MESSAGE_FROM_STRING) + { + char *source = MapSL(lpSource); + from = HeapAlloc( GetProcessHeap(), 0, strlen(source)+1 ); + strcpy( from, source ); + } + else if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) { + from = HeapAlloc( GetProcessHeap(),0,200 ); + sprintf(from,"Systemmessage, messageid = 0x%08x\n",dwMessageId); + } + else if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) { + INT16 bufsize; + HINSTANCE16 hinst16 = ((HINSTANCE16)lpSource & 0xffff); + + 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 = 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*/ + } + } + else + { + if(!args) break; + fmtstr=HeapAlloc( GetProcessHeap(), 0, 3 ); + strcpy( fmtstr, "%s" ); + } + if (args) { + int ret; + int sz; + LPSTR b = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sz = 100); + + argliststart=args+insertnr-1; + + /* CMF - This makes a BIG assumption about va_list */ + 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); + } + for (x=b; *x; x++) ADD_TO_T(*x); + HeapFree(GetProcessHeap(), 0, b); + } else { + /* NULL args - copy formatstr + * (probably wrong) + */ + while ((lastf