From 5051020e9fd316d737bb68ceaa93611db039d35b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Gouget?= Date: Tue, 19 Dec 2000 04:50:49 +0000 Subject: [PATCH] Added better support for Unicode: Added support for 16-bit wchar_t Added support for rewriting 4-byte Unicode literals to 16bit Unicode --- include/tchar.h | 3 ++- include/winnt.h | 38 +++++++++++++++++++++++++++++++++----- include/wtypes.h | 15 ++++++++------- library/port.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 13 deletions(-) diff --git a/include/tchar.h b/include/tchar.h index 488548b89ed..4bd28265c28 100644 --- a/include/tchar.h +++ b/include/tchar.h @@ -245,10 +245,11 @@ char *CRTDLL__strrev(char *string); #define _vsntprintf WINE_tchar_routine(_vsnprintf, _vsnprintf, _vsnwprintf) #define _vstprintf WINE_tchar_routine(vsprintf, vsprintf, vswprintf) #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 _TEXT(x) __T(x) -#define __T(x) x typedef CHAR _TCHARA; typedef WCHAR _TCHARW; diff --git a/include/winnt.h b/include/winnt.h index e72f4392b97..1bc504d42a4 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -12,6 +12,7 @@ #ifndef RC_INVOKED #include #include +#include #endif @@ -227,11 +228,16 @@ typedef double DATE; typedef VOID *PVOID, *LPVOID; typedef BYTE BOOLEAN, *PBOOLEAN; 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 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 */ #ifndef _ULONGLONG_ #define _ULONGLONG_ @@ -257,24 +263,46 @@ typedef WCHAR *PWSTR, *LPWSTR; typedef const WCHAR *PCWSTR, *LPCWSTR; /* 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 * macro which only exists in the user's code. */ #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 typedef WCHAR TCHAR, *PTCHAR; typedef LPWSTR PTSTR, LPTSTR; typedef LPCWSTR PCTSTR, LPCTSTR; -# define __TEXT(string) L##string /*probably wrong */ +# define __TEXT(string) WINE_UNICODE_TEXT(string) # else /* UNICODE */ typedef CHAR TCHAR, *PTCHAR; typedef LPSTR PTSTR, LPTSTR; typedef LPCSTR PCTSTR, LPCTSTR; # define __TEXT(string) string # endif /* UNICODE */ +# define TEXT(quote) __TEXT(quote) #endif /* __WINE__ */ -#define TEXT(quote) __TEXT(quote) /* Misc common WIN32 types */ typedef LONG HRESULT; diff --git a/include/wtypes.h b/include/wtypes.h index 71c0631c490..c7428e15121 100644 --- a/include/wtypes.h +++ b/include/wtypes.h @@ -20,11 +20,14 @@ typedef OLECHAR16 *BSTR16; typedef BSTR16 *LPBSTR16; #define OLESTR16(x) x -typedef WCHAR OLECHAR; -typedef LPWSTR LPOLESTR; -typedef LPCWSTR LPCOLESTR; -typedef OLECHAR *BSTR; -typedef BSTR *LPBSTR; +typedef WCHAR OLECHAR; +typedef LPWSTR LPOLESTR; +typedef LPCWSTR LPCOLESTR; +typedef OLECHAR *BSTR; +typedef BSTR *LPBSTR; +#ifndef __WINE__ +#define OLESTR(str) WINE_UNICODE_TEXT(str) +#endif #ifndef _DWORDLONG_ #define _DWORDLONG_ @@ -37,8 +40,6 @@ typedef __int64 LONGLONG, *PLONGLONG; typedef __uint64 ULONGLONG, *PULONGLONG; #endif -#define OLESTR(x) L##x - typedef enum tagDVASPECT { DVASPECT_CONTENT = 1, diff --git a/library/port.c b/library/port.c index cc41a2e9dce..bf41085a21e 100644 --- a/library/port.c +++ b/library/port.c @@ -23,6 +23,7 @@ #include #include #include +#include #ifdef HAVE_SYS_MMAN_H #include #endif @@ -526,3 +527,34 @@ int wine_dlclose( void *handle, char *error, int errorsize ) return 1; #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; +}