prepare for WINE UNICODE patch

svn path=/trunk/; revision=16392
This commit is contained in:
Martin Fuchs 2005-07-03 13:49:05 +00:00
parent 5c050fc41f
commit d46e87dfdb
2 changed files with 122 additions and 89 deletions

View file

@ -155,52 +155,6 @@ typedef struct {
#ifdef __WINE__
/* functions in unixcalls.c */
extern void call_getcwd(char* buffer, size_t len);
extern void* call_opendir(const char* path);
extern int call_readdir(void* pdir, char* name, unsigned* pinode);
extern void call_closedir(void* pdir);
extern int call_stat(
const char* path, int* pis_dir,
unsigned long* psize_low, unsigned long* psize_high,
time_t* patime, time_t* pmtime,
unsigned long* plinks
);
/* call vswprintf() in msvcrt.dll */
int swprintf(wchar_t* buffer, const wchar_t* fmt, ...)
{
static int (__cdecl *vswprintf)(wchar_t*, const wchar_t*, va_list);
va_list ap;
int ret;
if (!vswprintf) {
HMODULE hmod = LoadLibraryA("msvcrt");
vswprintf = (int(__cdecl*)(wchar_t*,const wchar_t*,va_list)) GetProcAddress(hmod, "vswprintf");
}
va_start(ap, fmt);
ret = vswprintf(buffer, fmt, ap);
va_end(ap);
return 0;
}
#else
// ugly hack to use alloca() while keeping Wine's developers happy
#define HeapAlloc(h,f,s) alloca(s)
#define HeapFree(h,f,p)
#endif
static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd);
static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd);
static void refresh_child(ChildWnd* child);
@ -278,6 +232,53 @@ static void display_network_error(HWND hwnd)
}
#ifdef __WINE__
#ifdef UNICODE
/* call vswprintf() in msvcrt.dll */
/*TODO: fix swprintf() in non-msvcrt mode, so that this dynamic linking function can be removed */
static int msvcrt_swprintf(WCHAR* buffer, const WCHAR* fmt, ...)
{
static int (__cdecl *pvswprintf)(WCHAR*, const WCHAR*, va_list) = NULL;
va_list ap;
int ret;
if (!pvswprintf) {
HMODULE hModMsvcrt = LoadLibraryA("msvcrt");
pvswprintf = (int(__cdecl*)(WCHAR*,const WCHAR*,va_list)) GetProcAddress(hModMsvcrt, "vswprintf");
}
va_start(ap, fmt);
ret = (*pvswprintf)(buffer, fmt, ap);
va_end(ap);
return ret;
}
static LPCWSTR my_wcsrchr(LPCWSTR str, WCHAR c)
{
LPCWSTR p = str;
while(*p)
++p;
do {
if (--p < str)
return NULL;
} while(*p != c);
return p;
}
#define _tcsrchr my_wcsrchr
#else /* UNICODE */
#define _tcsrchr strrchr
#endif /* UNICODE */
#endif /* __WINE__ */
/* allocate and initialise a directory entry */
static Entry* alloc_entry(void)
{
@ -677,7 +678,6 @@ static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
return dest;
}
static void get_strretA(STRRET* str, const SHITEMID* shiid, LPSTR buffer, int len)
{
switch(str->uType) {
@ -694,6 +694,35 @@ static void get_strretA(STRRET* str, const SHITEMID* shiid, LPSTR buffer, int le
}
}
static HRESULT path_from_pidlA(IShellFolder* folder, LPITEMIDLIST pidl, LPSTR buffer, int len)
{
STRRET str;
/* SHGDN_FORPARSING: get full path of id list */
HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
if (SUCCEEDED(hr)) {
get_strretA(&str, &pidl->mkid, buffer, len);
free_strret(&str);
} else
buffer[0] = '\0';
return hr;
}
#endif
static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
{
LPCWSTR s;
LPWSTR d = dest;
for(s=source; count&&(*d++=*s++); )
count--;
return dest;
}
static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int len)
{
switch(str->uType) {
@ -711,13 +740,6 @@ static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int l
}
static void free_strret(STRRET* str)
{
if (str->uType == STRRET_WSTR)
(*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
}
static HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPTSTR buffer, int len, SHGDNF flags)
{
STRRET str;
@ -734,22 +756,6 @@ static HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPTSTR bu
}
static HRESULT path_from_pidlA(IShellFolder* folder, LPITEMIDLIST pidl, LPSTR buffer, int len)
{
STRRET str;
/* SHGDN_FORPARSING: get full path of id list */
HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
if (SUCCEEDED(hr)) {
get_strretA(&str, &pidl->mkid, buffer, len);
free_strret(&str);
} else
buffer[0] = '\0';
return hr;
}
static HRESULT path_from_pidlW(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len)
{
STRRET str;
@ -2697,12 +2703,12 @@ static BOOL pattern_match(LPCTSTR str, LPCTSTR pattern)
return TRUE;
for(; *str; str++)
if (_totupper(*str)==_totupper(*pattern) && pattern_match(str, pattern))
if (*str==*pattern && pattern_match(str, pattern))
return TRUE;
return FALSE;
}
else if (_totupper(*str)!=_totupper(*pattern) && *pattern!='?')
else if (*str!=*pattern && *pattern!='?')
return FALSE;
}
@ -2713,6 +2719,18 @@ static BOOL pattern_match(LPCTSTR str, LPCTSTR pattern)
return TRUE;
}
static BOOL pattern_match_ncase(LPCTSTR str, LPCTSTR pattern)
{
TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
lstrcpy(b1, str);
lstrcpy(b2, pattern);
CharUpper(b1);
CharUpper(b2);
return pattern_match(b1, b2);
}
enum FILE_TYPE {
FT_OTHER = 0,
@ -2757,7 +2775,7 @@ static int insert_entries(Pane* pane, Entry* dir, LPCTSTR pattern, int filter_fl
/* filter using the file name pattern */
if (pattern)
if (!pattern_match(entry->data.cFileName, pattern))
if (!pattern_match_ncase(entry->data.cFileName, pattern))
continue;
/* filter system and hidden files */
@ -3826,20 +3844,6 @@ static BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow)
return TRUE;
}
#ifdef UNICODE
static BOOL launch_fileA(HWND hwnd, LPSTR cmd, UINT nCmdShow)
{
HINSTANCE hinst = ShellExecuteA(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
if ((int)hinst <= 32) {
display_error(hwnd, GetLastError());
return FALSE;
}
return TRUE;
}
#endif
static BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
{

View file

@ -36,17 +36,20 @@
#ifdef UNICODE
#define _UNICODE
#include <wchar.h>
#endif
#include <tchar.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <locale.h>
#include <time.h>
#ifndef __WINE__
#include <malloc.h> /* for alloca() */
// ugly hack to use alloca() while keeping Wine's developers happy
#define HeapAlloc(h,f,s) alloca(s)
#define HeapFree(h,f,p)
#endif
#include <shellapi.h> /* for ShellExecute() */
@ -145,12 +148,38 @@ typedef struct
extern WINEFILE_GLOBALS Globals;
#ifdef __WINE__
extern void WineLicense(HWND hwnd);
extern void WineWarranty(HWND hwnd);
#ifdef UNICODE
extern void _wsplitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHAR* ext);
#define _tsplitpath _wsplitpath
#define _stprintf msvcrt_swprintf
#else
extern void _splitpath(const CHAR* path, CHAR* drv, CHAR* dir, CHAR* name, CHAR* ext);
#define _tsplitpath _splitpath
#define _stprintf sprintf
#endif
/* functions in unixcalls.c */
extern void call_getcwd(char* buffer, size_t len);
extern void* call_opendir(const char* path);
extern int call_readdir(void* pdir, char* name, unsigned* pinode);
extern void call_closedir(void* pdir);
extern int call_stat(
const char* path, int* pis_dir,
unsigned long* psize_low, unsigned long* psize_high,
time_t* patime, time_t* pmtime,
unsigned long* plinks
);
#else
#include <tchar.h> /* for _tsplitpath() */
#endif