winefile
Martin Fuchs
martin-fuchs at gmx.net
Wed Jul 6 14:28:37 CDT 2005
>> Hi Alexandre,
>>
>> please take a look at my latest winefile patch. It no more uses
>> <tchar.h>, and it no more needs special rules for 'unixcalls.c' in
>> the Makefile. There is only left one single call into
>> 'msvcrt.dll'. It may even be possible to remove this somedays in the
>> future, if swprintf() is extended to handle %i64 format strings.
>
>Yes it looks better; I was wondering why you are still using a
>unixcalls.c at all, now that all the code is built with the Unix
>headers anyway.
next version of the path, now without unixcalls.c ...
Changelog:
- 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
Index: Makefile.in
===================================================================
RCS file: /home/wine/wine/programs/winefile/Makefile.in,v
retrieving revision 1.12
diff -u -p -d -r1.12 Makefile.in
--- Makefile.in 6 Jun 2005 10:02:43 -0000 1.12
+++ Makefile.in 6 Jul 2005 19:40:33 -0000
@@ -1,4 +1,4 @@
-EXTRADEFS = -D__WINE__
+EXTRADEFS = -D__WINE__ -DUNICODE
TOPSRCDIR = @top_srcdir@
TOPOBJDIR = ../..
SRCDIR = @srcdir@
Index: winefile.c
===================================================================
RCS file: /home/wine/wine/programs/winefile/winefile.c,v
retrieving revision 1.56
diff -u -p -d -r1.56 winefile.c
--- winefile.c 17 Jun 2005 10:11:37 -0000 1.56
+++ winefile.c 6 Jul 2005 19:40:35 -0000
@@ -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 h
}
+#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)
{
@@ -463,16 +505,24 @@ static void read_directory_unix(Entry* d
Entry* entry;
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
+
+ DIR* 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 +538,16 @@ static void read_directory_unix(Entry* d
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 +649,27 @@ static Entry* read_tree_unix(Root* root,
#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 +677,6 @@ static LPWSTR wcscpyn(LPWSTR dest, LPCWS
return dest;
}
-
static void get_strretA(STRRET* str, const SHITEMID* shiid, LPSTR buffer, int len)
{
switch(str->uType) {
@@ -644,6 +693,35 @@ static void get_strretA(STRRET* str, con
}
}
+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 +739,6 @@ static void get_strretW(STRRET* str, con
}
-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 +755,6 @@ static HRESULT name_from_pidl(IShellFold
}
-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 +1436,7 @@ static ChildWnd* alloc_child_window(LPCT
_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 +1905,7 @@ static INT_PTR CALLBACK PropertiesDialog
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 +2337,20 @@ static LRESULT CALLBACK FrameWndProc(HWN
#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 +2698,12 @@ static BOOL pattern_match(LPCTSTR str, L
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 +2714,18 @@ static BOOL pattern_match(LPCTSTR str, L
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 +2770,7 @@ static int insert_entries(Pane* pane, En
/* 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 +2819,11 @@ static void format_bytes(LPTSTR buffer,
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 +2836,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 +2899,7 @@ static void format_date(const FILETIME*
return;
if (!FileTimeToLocalFileTime(ft, &lft))
- {err: _tcscpy(buffer,sQMarks); return;}
+ {err: lstrcpy(buffer,sQMarks); return;}
if (!FileTimeToSystemTime(&lft, &systime))
goto err;
@@ -2957,7 +3032,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 +3220,6 @@ static void draw_item(Pane* pane, LPDRAW
cx = pane->widths[col];
if (cx && img!=IMG_NONE) {
-
if (cx > IMAGE_WIDTH)
cx = IMAGE_WIDTH;
@@ -3245,7 +3319,7 @@ static void draw_item(Pane* pane, LPDRAW
}
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 +3336,10 @@ static void draw_item(Pane* pane, LPDRAW
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 +3381,7 @@ static void draw_item(Pane* pane, LPDRAW
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 +3688,9 @@ static void set_curdir(ChildWnd* child,
{
TCHAR path[MAX_PATH];
+ if (!entry)
+ return;
+
path[0] = '\0';
child->left.cur = entry;
@@ -3757,20 +3834,6 @@ static BOOL launch_file(HWND hwnd, LPCTS
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 +4377,11 @@ static LRESULT CALLBACK ChildWndProc(HWN
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);
}
Index: winefile.h
===================================================================
RCS file: /home/wine/wine/programs/winefile/winefile.h,v
retrieving revision 1.15
diff -u -p -d -r1.15 winefile.h
--- winefile.h 20 Jun 2005 11:45:39 -0000 1.15
+++ winefile.h 6 Jul 2005 19:40:35 -0000
@@ -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
More information about the wine-patches
mailing list