Commit 62dbe211 authored by Martin Fuchs's avatar Martin Fuchs Committed by Alexandre Julliard

- remove <tchar.h> and <wchar.h> header usage by switching to WIN32

API string manipulation functions as far as possible - switch to UNICODE compilaton - remove launch_fileA() and tcscpyn - don't crash in set_curdir() for NULL in the 'entry' pointer
parent f278f124
EXTRADEFS = -D__WINE__
EXTRADEFS = -D__WINE__ -DUNICODE
TOPSRCDIR = @top_srcdir@
TOPOBJDIR = ../..
SRCDIR = @srcdir@
......
......@@ -21,21 +21,16 @@
#ifdef __WINE__
#include "config.h"
#include "wine/port.h"
/* for unix filesystem function calls */
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#endif
#include "winefile.h"
#include "resource.h"
/* for read_directory_unix() */
#if !defined(_NO_EXTENSIONS) && defined(__WINE__)
#include <dirent.h>
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <time.h>
#endif
#ifdef _NO_EXTENSIONS
#undef _LEFT_FILES
#endif
......@@ -239,6 +234,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)
{
......@@ -461,18 +503,27 @@ static void read_directory_unix(Entry* dir, LPCTSTR path)
Entry* first_entry = NULL;
Entry* last = NULL;
Entry* entry;
DIR* pdir;
int level = dir->level + 1;
#ifdef UNICODE
char cpath[MAX_PATH];
DIR* pdir = opendir(path);
WideCharToMultiByte(CP_UNIXCP, 0, path, -1, cpath, MAX_PATH, NULL, NULL);
#else
const char* cpath = path;
#endif
pdir = opendir(cpath);
if (pdir) {
struct stat st;
struct dirent* ent;
TCHAR buffer[MAX_PATH], *p;
char buffer[MAX_PATH], *p;
const char* s;
for(p=buffer; *path; )
*p++ = *path++;
for(p=buffer,s=cpath; *s; )
*p++ = *s++;
if (p==buffer || p[-1]!='/')
*p++ = '/';
......@@ -488,12 +539,16 @@ static void read_directory_unix(Entry* dir, LPCTSTR path)
entry->etype = ET_UNIX;
lstrcpy(entry->data.cFileName, ent->d_name);
entry->data.dwFileAttributes = ent->d_name[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0;
strcpy(p, ent->d_name);
#ifdef UNICODE
MultiByteToWideChar(CP_UNIXCP, 0, p, -1, entry->data.cFileName, MAX_PATH);
#else
lstrcpy(entry->data.cFileName, p);
#endif
if (!stat(buffer, &st)) {
entry->data.dwFileAttributes = p[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0;
if (S_ISDIR(st.st_mode))
entry->data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
......@@ -595,31 +650,27 @@ static Entry* read_tree_unix(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWN
#ifdef _SHELL_FOLDERS
#ifdef UNICODE
#define tcscpyn strcpyn
#define get_strret get_strretW
#define path_from_pidl path_from_pidlW
#else
#define tcscpyn wcscpyn
#define get_strret get_strretA
#define path_from_pidl path_from_pidlA
#endif
static LPSTR strcpyn(LPSTR dest, LPCSTR source, size_t count)
static void free_strret(STRRET* str)
{
LPCSTR s;
LPSTR d = dest;
if (str->uType == STRRET_WSTR)
(*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
}
for(s=source; count&&(*d++=*s++); )
count--;
return dest;
}
#ifndef UNICODE
static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
static LPSTR strcpyn(LPSTR dest, LPCSTR source, size_t count)
{
LPCWSTR s;
LPWSTR d = dest;
LPCSTR s;
LPSTR d = dest;
for(s=source; count&&(*d++=*s++); )
count--;
......@@ -627,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) {
......@@ -644,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) {
......@@ -661,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;
......@@ -684,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;
......@@ -1381,7 +1437,7 @@ static ChildWnd* alloc_child_window(LPCTSTR path, LPITEMIDLIST pidl, HWND hwnd)
_tsplitpath(path, drv, dir, name, ext);
}
_tcscpy(child->filter_pattern, sAsterics);
lstrcpy(child->filter_pattern, sAsterics);
child->filter_flags = TF_ALL;
root->entry.level = 0;
......@@ -1850,7 +1906,7 @@ static INT_PTR CALLBACK PropertiesDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wpa
size = ((ULONGLONG)pWFD->nFileSizeHigh << 32) | pWFD->nFileSizeLow;
_stprintf(b1, sLongNumFmt, size);
_stprintf(b2, sByteFmt, b1);
wsprintf(b2, sByteFmt, b1);
SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_SIZE), b2);
SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_FILENAME), pWFD->cFileName);
......@@ -2282,12 +2338,20 @@ static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM
#ifdef __WINE__
case ID_DRIVE_UNIX_FS: {
TCHAR path[MAX_PATH];
#ifdef UNICODE
char cpath[MAX_PATH];
#endif
ChildWnd* child;
if (activate_fs_window(RS(b1,IDS_UNIXFS)))
break;
#ifdef UNICODE
getcwd(cpath, MAX_PATH);
MultiByteToWideChar(CP_UNIXCP, 0, cpath, -1, path, MAX_PATH);
#else
getcwd(path, MAX_PATH);
#endif
child = alloc_child_window(path, NULL, hwnd);
if (!create_child_window(child))
......@@ -2635,12 +2699,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;
}
......@@ -2651,6 +2715,18 @@ static BOOL pattern_match(LPCTSTR str, LPCTSTR pattern)
return TRUE;
}
static BOOL pattern_imatch(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,
......@@ -2695,7 +2771,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_imatch(entry->data.cFileName, pattern))
continue;
/* filter system and hidden files */
......@@ -2744,11 +2820,11 @@ static void format_bytes(LPTSTR buffer, LONGLONG bytes)
float fBytes = (float)bytes;
if (bytes >= 1073741824) /* 1 GB */
_stprintf(buffer, sFmtGB, fBytes/1073741824.f+.5f);
wsprintf(buffer, sFmtGB, fBytes/1073741824.f+.5f);
else if (bytes >= 1048576) /* 1 MB */
_stprintf(buffer, sFmtMB, fBytes/1048576.f+.5f);
wsprintf(buffer, sFmtMB, fBytes/1048576.f+.5f);
else if (bytes >= 1024) /* 1 kB */
_stprintf(buffer, sFmtkB, fBytes/1024.f+.5f);
wsprintf(buffer, sFmtkB, fBytes/1024.f+.5f);
else
_stprintf(buffer, sLongNumFmt, bytes);
}
......@@ -2761,9 +2837,9 @@ static void set_space_status(void)
if (GetDiskFreeSpaceEx(NULL, &ulFreeBytesToCaller, &ulTotalBytes, &ulFreeBytes)) {
format_bytes(b1, ulFreeBytesToCaller.QuadPart);
format_bytes(b2, ulTotalBytes.QuadPart);
_stprintf(buffer, RS(fmt,IDS_FREE_SPACE_FMT), b1, b2);
wsprintf(buffer, RS(fmt,IDS_FREE_SPACE_FMT), b1, b2);
} else
_tcscpy(buffer, sQMarks);
lstrcpy(buffer, sQMarks);
SendMessage(Globals.hstatusbar, SB_SETTEXT, 0, (LPARAM)buffer);
}
......@@ -2824,7 +2900,7 @@ static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols)
return;
if (!FileTimeToLocalFileTime(ft, &lft))
{err: _tcscpy(buffer,sQMarks); return;}
{err: lstrcpy(buffer,sQMarks); return;}
if (!FileTimeToSystemTime(&lft, &systime))
goto err;
......@@ -2957,7 +3033,7 @@ static BOOL is_exe_file(LPCTSTR ext)
d++;
for(p=executable_extensions; (*p)[0]; p++)
if (!_tcsicmp(ext_buffer, *p))
if (!lstrcmpi(ext_buffer, *p))
return TRUE;
return FALSE;
......@@ -3145,7 +3221,6 @@ static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWi
cx = pane->widths[col];
if (cx && img!=IMG_NONE) {
if (cx > IMAGE_WIDTH)
cx = IMAGE_WIDTH;
......@@ -3245,7 +3320,7 @@ static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWi
}
if (visible_cols & COL_LINKS) {
_stprintf(buffer, sNumFmt, entry->bhfi.nNumberOfLinks);
wsprintf(buffer, sNumFmt, entry->bhfi.nNumberOfLinks);
if (calcWidthCol == -1)
output_text(pane, dis, col, buffer, DT_CENTER);
......@@ -3262,10 +3337,10 @@ static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWi
if (visible_cols & COL_ATTRIBUTES) {
#ifdef _NO_EXTENSIONS
const static TCHAR s4Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
_tcscpy(buffer, s4Tabs);
lstrcpy(buffer, s4Tabs);
#else
const static TCHAR s11Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
_tcscpy(buffer, s11Tabs);
lstrcpy(buffer, s11Tabs);
#endif
if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
......@@ -3307,7 +3382,7 @@ static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWi
DWORD rights = get_access_mask();
tcscpy(buffer, sSecTabs);
lstrcpy(buffer, sSecTabs);
if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
......@@ -3614,6 +3689,9 @@ static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
{
TCHAR path[MAX_PATH];
if (!entry)
return;
path[0] = '\0';
child->left.cur = entry;
......@@ -3757,20 +3835,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)
{
......@@ -4314,11 +4378,11 @@ static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM
struct FilterDialog dlg;
memset(&dlg, 0, sizeof(struct FilterDialog));
_tcscpy(dlg.pattern, child->filter_pattern);
lstrcpy(dlg.pattern, child->filter_pattern);
dlg.flags = child->filter_flags;
if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE), hwnd, FilterDialogDlgProc, (LPARAM)&dlg) == IDOK) {
_tcscpy(child->filter_pattern, dlg.pattern);
lstrcpy(child->filter_pattern, dlg.pattern);
child->filter_flags = dlg.flags;
refresh_right_pane(child);
}
......
......@@ -36,14 +36,13 @@
#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() */
......@@ -145,12 +144,23 @@ 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
#else
#include <tchar.h> /* for _tsplitpath() */
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment