wine/win32/findfile.c
Alexandre Julliard 7e6ae4ba5e Release 961208
Sun Dec  8 14:51:57 1996  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [configure.in]
	Added check to see if the compiler supports building a DLL when
	the --with-dll option is used.

	* [controls/listbox.c]
	Don't send LBN_SELCHANGE too often.
	Added WM_CHARTOITEM support.

	* [Make.rules.in] [library/Makefile.in]
	Build winestub.o and link it with Winelib programs.

	* [objects/text.c]
	Added support for '&&' in DrawText().

	* [tools/build.c]
	Added -o option.

Sat Dec 7 12:07:07 1996  Andrew Lewycky <plewycky@oise.utoronto.ca>

	* [win32/thread.c]
	GetCurrentThread(): return -2 (current thread pseudo-handle).
	GetCurrentThreadId(): return GetCurrentTask().

	* [objects/font.c] [if1632/gdi32.spec]
	GetTextExtentPoint32{A,W}Buggy(): for future bug-compatibility.

	* [win32/findfile.c]
	FindClose(): ignore INVALID_HANDLE_VALUE (like Win95).

	* [windows/hook.c] [include/hook.h] [if1632/user.spec]
	  [if1632/user32.spec] [windows/focus.c] [windows/message.c]
	  [windows/nonclient.c] [windows/win.c] [windows/winpos.c]
	Hooks rewritten to support Win32.

	* [misc/winsock.c]
	WINSOCK_select(): need to put sockets with errors into exceptfds.
	WINSOCK_socket(): fix error return.

	* [windows/win.c]
	SetWindowWord(): call SetParent on GWW_HWNDPARENT.

Wed Dec  4 22:03:05 1996  Andrew Taylor <andrew@riscan.com>

	* [files/dos_fs.c]
	Check if buf is NULL before copying string in GetFullPathName32A().

Wed Dec  4 21:40:59 1996  Robert Pouliot <krynos@clic.net>

        * [graphics/wing.c] [if1632/wing.spec]
	Implemented many WinG functions, but some don't seem to
	work correctly (probably due to the one not done).
	
Wed Dec  4 03:38:25 1996  Lee Jaekil <juria@puma.kaitech.re.kr>

	* [misc/main.c]
	Implemented a few more of the SystemParametersInfo() cases.

Sun Dec  1 22:30:00 1996  Alex Korobka <alex@trantor.pharm.sunysb.edu> 

	* [controls/button.c]
	Improved focus rectangle painting.

	* [windows/dialog.c] [windows/defdlg.c]
	Fixed IE3.0 problems with DWL_MSGRESULT.

Sun Dec  1 20:49:32 1996  Albrecht Kleine  <kleine@ak.sax.de>

	* [files/profile.c]
	Changed error handling in PROFILE_SetString().
1996-12-08 19:25:27 +00:00

204 lines
5.4 KiB
C

#include <sys/types.h>
#include <dirent.h>
#include <string.h>
#include <ctype.h>
#include <malloc.h>
#include "xmalloc.h"
#include "windows.h"
#include "winerror.h"
#include "dos_fs.h"
#include "heap.h"
#include "string32.h"
#define PATH_LEN 260
struct FindFileContext32 {
DIR * dir;
char mask[PATH_LEN];
char path[PATH_LEN];
};
typedef struct FindFileContext32 FindFileContext32;
const char *DOSFS_Hash(const char *, int, int);
/* example D:\*.dbs */
static BOOL32 MatchWildCard(LPCSTR file, LPCSTR mask)
{
int len;
/* We should check volume information to see if long filenames possible.
*/
len = strlen(file);
while (*file) {
if (*mask == '*') {
if (*(mask+1)) {
while (*file && (toupper(*file) != *(mask+1))) file++;
if (!*file)
return FALSE;
}
else
break;
}
else {
if (*mask != '?' && *mask != toupper(*file)) {
return FALSE;
}
file++;
}
mask++;
}
return (TRUE);
}
/*************************************************************************
* FindNextFile32A (KERNEL32.126)
*/
BOOL32 FindNextFile32A(HANDLE32 handle, LPWIN32_FIND_DATA32A data)
{
FindFileContext32 *context;
struct dirent *dirent;
char dosname[14];
memset(data, 0, sizeof(WIN32_FIND_DATA32A));
context = (FindFileContext32 *) handle;
while ((dirent = readdir(context->dir)) != NULL) {
if (strcmp(dirent->d_name, "..") == 0 ||
strcmp(dirent->d_name, ".") == 0)
continue;
strcpy(dosname, DOSFS_Hash(dirent->d_name, FALSE, FALSE));
if (MatchWildCard(dirent->d_name, context->mask)) {
/* Full file name - is this a long file name?
* If it is, we should probably use the dirent
* instead of the dos hashed name.
*/
strcpy(data->cFileName, dosname);
/* file name expressed in 8.3 format */
strcpy(data->cAlternateFileName, dosname);
return (TRUE);
}
}
return (FALSE);
}
/*************************************************************************
* FindNextFile32W (KERNEL32.127)
*/
BOOL32 FindNextFile32W(HANDLE32 handle, LPWIN32_FIND_DATA32W data)
{
WIN32_FIND_DATA32A adata;
adata.dwFileAttributes = data->dwFileAttributes;
adata.ftCreationTime = data->ftCreationTime;
adata.ftLastAccessTime = data->ftLastAccessTime;
adata.ftLastWriteTime = data->ftLastWriteTime;
adata.nFileSizeHigh = data->nFileSizeHigh;
adata.nFileSizeLow = data->nFileSizeLow;
adata.dwReserved0 = data->dwReserved0;
adata.dwReserved1 = data->dwReserved1;
STRING32_UniToAnsi(adata.cFileName,data->cFileName);
STRING32_UniToAnsi(adata.cAlternateFileName,data->cAlternateFileName);
return FindNextFile32A(handle,&adata);
}
/*************************************************************************
* FindFirstFile32A (KERNEL32.123)
*/
HANDLE32 FindFirstFile32A(LPCSTR lpfilename,
LPWIN32_FIND_DATA32A lpFindFileData)
{
const char *unixpath;
char *slash, *p;
FindFileContext32 *context;
context = HeapAlloc(SystemHeap, 0, sizeof(FindFileContext32));
if (!context)
return (INVALID_HANDLE_VALUE);
slash = strrchr(lpfilename, '\\');
if (slash) {
lstrcpyn32A(context->path, lpfilename, slash - lpfilename + 1);
context->path[slash - lpfilename + 1] = '\0';
unixpath = DOSFS_GetUnixFileName(context->path, FALSE);
if (!unixpath) {
/* FIXME: SetLastError(??) */
HeapFree(SystemHeap, 0, context);
return INVALID_HANDLE_VALUE;
}
lstrcpy32A(context->mask, slash+1);
}
else {
context->path[0] = '\0';
unixpath = ".";
lstrcpy32A(context->mask, lpfilename);
}
context->dir = opendir(unixpath);
if (!context->dir) {
/* FIXME: SetLastError(??) */
HeapFree(SystemHeap, 0, context);
return INVALID_HANDLE_VALUE;
}
/* uppercase mask in place */
for (p = context->mask ; *p; p++)
*p = toupper(*p);
if (!FindNextFile32A((HANDLE32) context, lpFindFileData))
return (INVALID_HANDLE_VALUE);
return ((HANDLE32) context);
}
/*************************************************************************
* FindFirstFile32W (KERNEL32.124)
*/
HANDLE32 FindFirstFile32W(LPCWSTR filename,LPWIN32_FIND_DATA32W data)
{
WIN32_FIND_DATA32A adata;
LPSTR afn = STRING32_DupUniToAnsi(filename);
HANDLE32 res;
adata.dwFileAttributes = data->dwFileAttributes;
adata.ftCreationTime = data->ftCreationTime;
adata.ftLastAccessTime = data->ftLastAccessTime;
adata.ftLastWriteTime = data->ftLastWriteTime;
adata.nFileSizeHigh = data->nFileSizeHigh;
adata.nFileSizeLow = data->nFileSizeLow;
adata.dwReserved0 = data->dwReserved0;
adata.dwReserved1 = data->dwReserved1;
STRING32_UniToAnsi(adata.cFileName,data->cFileName);
STRING32_UniToAnsi(adata.cAlternateFileName,data->cAlternateFileName);
res=FindFirstFile32A(afn,&adata);
free(afn);
return res;
}
/*************************************************************************
* FindClose32 (KERNEL32.119)
*/
BOOL32 FindClose32(HANDLE32 handle)
{
FindFileContext32 *context;
/* Windows95 ignores an invalid handle. */
if (handle == INVALID_HANDLE_VALUE)
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
context = (FindFileContext32 *) handle;
if (context->dir)
closedir(context->dir);
HeapFree(SystemHeap, 0, context);
return (TRUE);
}