Added better support for Unicode:

Added support for 16-bit wchar_t
Added support for rewriting 4-byte Unicode literals to 16bit Unicode
This commit is contained in:
François Gouget 2000-12-19 04:50:49 +00:00 committed by Alexandre Julliard
parent 975914003b
commit 5051020e9f
4 changed files with 75 additions and 13 deletions

View File

@ -245,10 +245,11 @@ char *CRTDLL__strrev(char *string);
#define _vsntprintf WINE_tchar_routine(_vsnprintf, _vsnprintf, _vsnwprintf) #define _vsntprintf WINE_tchar_routine(_vsnprintf, _vsnprintf, _vsnwprintf)
#define _vstprintf WINE_tchar_routine(vsprintf, vsprintf, vswprintf) #define _vstprintf WINE_tchar_routine(vsprintf, vsprintf, vswprintf)
#define _vtprintf WINE_tchar_routine(vprintf, vprintf, vwprintf) #define _vtprintf WINE_tchar_routine(vprintf, vprintf, vwprintf)
#define _TEOF WINE_tchar_routine(EOF, EOF, WEOF)
#define __T(x) __TEXT(x)
#define _T(x) __T(x) #define _T(x) __T(x)
#define _TEXT(x) __T(x) #define _TEXT(x) __T(x)
#define __T(x) x
typedef CHAR _TCHARA; typedef CHAR _TCHARA;
typedef WCHAR _TCHARW; typedef WCHAR _TCHARW;

View File

@ -12,6 +12,7 @@
#ifndef RC_INVOKED #ifndef RC_INVOKED
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
#include <stddef.h>
#endif #endif
@ -227,11 +228,16 @@ typedef double DATE;
typedef VOID *PVOID, *LPVOID; typedef VOID *PVOID, *LPVOID;
typedef BYTE BOOLEAN, *PBOOLEAN; typedef BYTE BOOLEAN, *PBOOLEAN;
typedef char CHAR, *PCHAR; typedef char CHAR, *PCHAR;
/* Some systems might have wchar_t, but we really need 16 bit characters */
typedef unsigned short WCHAR, *PWCHAR;
typedef short SHORT, *PSHORT; typedef short SHORT, *PSHORT;
typedef long LONG, *PLONG, *LPLONG; typedef long LONG, *PLONG, *LPLONG;
/* Some systems might have wchar_t, but we really need 16 bit characters */
#ifdef WINE_UNICODE_NATIVE
typedef wchar_t WCHAR, *PWCHAR;
#else
typedef unsigned short WCHAR, *PWCHAR;
#endif
/* 'Extended/Wide' numerical types */ /* 'Extended/Wide' numerical types */
#ifndef _ULONGLONG_ #ifndef _ULONGLONG_
#define _ULONGLONG_ #define _ULONGLONG_
@ -257,24 +263,46 @@ typedef WCHAR *PWSTR, *LPWSTR;
typedef const WCHAR *PCWSTR, *LPCWSTR; typedef const WCHAR *PCWSTR, *LPCWSTR;
/* Neutral character and string types */ /* Neutral character and string types */
/* These are only defined for WineLib, i.e. _not_ defined for /* These are only defined for Winelib, i.e. _not_ defined for
* the emulator. The reason is they depend on the UNICODE * the emulator. The reason is they depend on the UNICODE
* macro which only exists in the user's code. * macro which only exists in the user's code.
*/ */
#ifndef __WINE__ #ifndef __WINE__
# ifdef WINE_UNICODE_REWRITE
EXTERN_C unsigned short* wine_rewrite_s4tos2(const wchar_t* str4);
# ifdef __cplusplus
inline WCHAR* wine_unicode_text(const wchar_t* str4)
{
return (WCHAR*)wine_rewrite_s4tos2(str4);
}
inline WCHAR wine_unicode_text(wchar_t chr4)
{
return (WCHAR)chr4;
}
# define WINE_UNICODE_TEXT(x) wine_unicode_text(L##x)
# else /* __cplusplus */
# define WINE_UNICODE_TEXT(x) ((sizeof(x)==1) || (sizeof(L##x)>4) ? \
(WCHAR*)wine_rewrite_s4tos2(L##x) : \
((WCHAR)L##x))
# endif /* __cplusplus */
# else /* WINE_UNICODE_REWRITE */
/* WINE_UNICODE_NATIVE or nothing at all */
# define WINE_UNICODE_TEXT(string) L##string
# endif /* WINE_UNICODE_REWRITE */
# ifdef UNICODE # ifdef UNICODE
typedef WCHAR TCHAR, *PTCHAR; typedef WCHAR TCHAR, *PTCHAR;
typedef LPWSTR PTSTR, LPTSTR; typedef LPWSTR PTSTR, LPTSTR;
typedef LPCWSTR PCTSTR, LPCTSTR; typedef LPCWSTR PCTSTR, LPCTSTR;
# define __TEXT(string) L##string /*probably wrong */ # define __TEXT(string) WINE_UNICODE_TEXT(string)
# else /* UNICODE */ # else /* UNICODE */
typedef CHAR TCHAR, *PTCHAR; typedef CHAR TCHAR, *PTCHAR;
typedef LPSTR PTSTR, LPTSTR; typedef LPSTR PTSTR, LPTSTR;
typedef LPCSTR PCTSTR, LPCTSTR; typedef LPCSTR PCTSTR, LPCTSTR;
# define __TEXT(string) string # define __TEXT(string) string
# endif /* UNICODE */ # endif /* UNICODE */
# define TEXT(quote) __TEXT(quote)
#endif /* __WINE__ */ #endif /* __WINE__ */
#define TEXT(quote) __TEXT(quote)
/* Misc common WIN32 types */ /* Misc common WIN32 types */
typedef LONG HRESULT; typedef LONG HRESULT;

View File

@ -20,11 +20,14 @@ typedef OLECHAR16 *BSTR16;
typedef BSTR16 *LPBSTR16; typedef BSTR16 *LPBSTR16;
#define OLESTR16(x) x #define OLESTR16(x) x
typedef WCHAR OLECHAR; typedef WCHAR OLECHAR;
typedef LPWSTR LPOLESTR; typedef LPWSTR LPOLESTR;
typedef LPCWSTR LPCOLESTR; typedef LPCWSTR LPCOLESTR;
typedef OLECHAR *BSTR; typedef OLECHAR *BSTR;
typedef BSTR *LPBSTR; typedef BSTR *LPBSTR;
#ifndef __WINE__
#define OLESTR(str) WINE_UNICODE_TEXT(str)
#endif
#ifndef _DWORDLONG_ #ifndef _DWORDLONG_
#define _DWORDLONG_ #define _DWORDLONG_
@ -37,8 +40,6 @@ typedef __int64 LONGLONG, *PLONGLONG;
typedef __uint64 ULONGLONG, *PULONGLONG; typedef __uint64 ULONGLONG, *PULONGLONG;
#endif #endif
#define OLESTR(x) L##x
typedef enum tagDVASPECT typedef enum tagDVASPECT
{ {
DVASPECT_CONTENT = 1, DVASPECT_CONTENT = 1,

View File

@ -23,6 +23,7 @@
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <termios.h> #include <termios.h>
#include <wchar.h>
#ifdef HAVE_SYS_MMAN_H #ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h> #include <sys/mman.h>
#endif #endif
@ -526,3 +527,34 @@ int wine_dlclose( void *handle, char *error, int errorsize )
return 1; return 1;
#endif #endif
} }
/***********************************************************************
* wine_rewrite_s4tos2
*
* Convert 4 byte Unicode strings to 2 byte Unicode strings in-place.
* This is only practical if literal strings are writable.
*/
unsigned short* wine_rewrite_s4tos2(const wchar_t* str4 )
{
unsigned short *str2,*s2;
if (str4==NULL)
return NULL;
if ((*str4 & 0xffff0000) != 0) {
/* This string has already been converted. Return it as is */
return (unsigned short*)str4;
}
/* Note that we can also end up here if the string has a single
* character. In such a case we will convert the string over and
* over again. But this is harmless.
*/
str2=s2=(unsigned short*)str4;
do {
*s2=(unsigned short)*str4;
s2++;
} while (*str4++ != L'\0');
return str2;
}