mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-06 20:45:54 +01:00
Turn off STUBBED_DICT -- can now load and execute from an .xwd file
running on WINE.
This commit is contained in:
parent
870af10a63
commit
a79052513e
2 changed files with 66 additions and 21 deletions
|
@ -81,7 +81,6 @@ XW_BOTH_DEFINES = \
|
||||||
-DXWFEATURE_HINT_CONFIG \
|
-DXWFEATURE_HINT_CONFIG \
|
||||||
-DPOINTER_SUPPORT -DKEY_SUPPORT -D__LITTLE_ENDIAN \
|
-DPOINTER_SUPPORT -DKEY_SUPPORT -D__LITTLE_ENDIAN \
|
||||||
-DCEFEATURE_CANSCROLL -DUNICODE \
|
-DCEFEATURE_CANSCROLL -DUNICODE \
|
||||||
-DSTUBBED_DICT \
|
|
||||||
-DCANT_DO_SHELL_THING \
|
-DCANT_DO_SHELL_THING \
|
||||||
$(DEBUG) $(MEM_DEBUG) \
|
$(DEBUG) $(MEM_DEBUG) \
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,10 @@ static XP_Bitmap* ceMakeBitmap( CEDictionaryCtxt* ctxt, XP_U8** ptrp );
|
||||||
|
|
||||||
static XP_U32 n_ptr_tohl( XP_U8** in );
|
static XP_U32 n_ptr_tohl( XP_U8** in );
|
||||||
static XP_U16 n_ptr_tohs( XP_U8** in );
|
static XP_U16 n_ptr_tohs( XP_U8** in );
|
||||||
static XP_U8* openMappedFile( const wchar_t* name, HANDLE* mappedFileP,
|
static XP_U8* openMappedFile( MPFORMAL const wchar_t* name,
|
||||||
HANDLE* hFileP);
|
HANDLE* mappedFileP, HANDLE* hFileP,
|
||||||
|
XP_U32* sizep );
|
||||||
|
static void closeMappedFile( MPFORMAL XP_U8* base, HANDLE mappedFile );
|
||||||
|
|
||||||
#define ALIGN_COUNT 2
|
#define ALIGN_COUNT 2
|
||||||
|
|
||||||
|
@ -54,6 +56,7 @@ ce_dictionary_make( CEAppGlobals* globals, XP_UCHAR* dictName )
|
||||||
wchar_t nameBuf[MAX_PATH+1];
|
wchar_t nameBuf[MAX_PATH+1];
|
||||||
HANDLE hFile;
|
HANDLE hFile;
|
||||||
XP_U8* ptr;
|
XP_U8* ptr;
|
||||||
|
XP_U32 dictLength;
|
||||||
|
|
||||||
XP_ASSERT( !!dictName );
|
XP_ASSERT( !!dictName );
|
||||||
XP_DEBUGF( "looking for dict %s", dictName );
|
XP_DEBUGF( "looking for dict %s", dictName );
|
||||||
|
@ -61,14 +64,14 @@ ce_dictionary_make( CEAppGlobals* globals, XP_UCHAR* dictName )
|
||||||
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, dictName, -1,
|
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, dictName, -1,
|
||||||
nameBuf, sizeof(nameBuf)/sizeof(nameBuf[0]) );
|
nameBuf, sizeof(nameBuf)/sizeof(nameBuf[0]) );
|
||||||
|
|
||||||
ptr = openMappedFile( nameBuf, &mappedFile, &hFile );
|
ptr = openMappedFile( MPPARM(globals->mpool) nameBuf, &mappedFile,
|
||||||
|
&hFile, &dictLength );
|
||||||
|
|
||||||
while( !!ptr ) { /* lets us break.... */
|
while( !!ptr ) { /* lets us break.... */
|
||||||
XP_U32 offset;
|
XP_U32 offset;
|
||||||
XP_U16 numFaces;
|
XP_U16 numFaces;
|
||||||
XP_U16 i;
|
XP_U16 i;
|
||||||
XP_U16 flags;
|
XP_U16 flags;
|
||||||
XP_U32 dictLength;
|
|
||||||
void* mappedBase = (void*)ptr;
|
void* mappedBase = (void*)ptr;
|
||||||
XP_U8 nodeSize;
|
XP_U8 nodeSize;
|
||||||
|
|
||||||
|
@ -130,7 +133,6 @@ ce_dictionary_make( CEAppGlobals* globals, XP_UCHAR* dictName )
|
||||||
|
|
||||||
ceLoadSpecialData( ctxt, &ptr );
|
ceLoadSpecialData( ctxt, &ptr );
|
||||||
|
|
||||||
dictLength = GetFileSize( hFile, NULL );
|
|
||||||
dictLength -= ptr - (XP_U8*)ctxt->mappedBase;
|
dictLength -= ptr - (XP_U8*)ctxt->mappedBase;
|
||||||
if ( dictLength > sizeof(XP_U32) ) {
|
if ( dictLength > sizeof(XP_U32) ) {
|
||||||
offset = n_ptr_tohl( &ptr );
|
offset = n_ptr_tohl( &ptr );
|
||||||
|
@ -398,8 +400,8 @@ ce_dict_destroy( DictionaryCtxt* dict )
|
||||||
|
|
||||||
XP_FREE( ctxt->super.mpool, ctxt->super.faces16 );
|
XP_FREE( ctxt->super.mpool, ctxt->super.faces16 );
|
||||||
|
|
||||||
UnmapViewOfFile( ctxt->mappedBase );
|
closeMappedFile( MPPARM(ctxt->super.mpool) ctxt->mappedBase,
|
||||||
CloseHandle( ctxt->mappedFile );
|
ctxt->mappedFile );
|
||||||
XP_FREE( ctxt->super.mpool, ctxt );
|
XP_FREE( ctxt->super.mpool, ctxt );
|
||||||
} // ce_dict_destroy
|
} // ce_dict_destroy
|
||||||
|
|
||||||
|
@ -451,7 +453,8 @@ ce_pickDictFile( CEAppGlobals* globals, XP_UCHAR* buf, XP_U16 bufLen )
|
||||||
} /* ce_pickDictFile */
|
} /* ce_pickDictFile */
|
||||||
|
|
||||||
static XP_U8*
|
static XP_U8*
|
||||||
openMappedFile( const wchar_t* name, HANDLE* mappedFileP, HANDLE* hFileP )
|
openMappedFile( MPFORMAL const wchar_t* name, HANDLE* mappedFileP,
|
||||||
|
HANDLE* hFileP, XP_U32* sizep )
|
||||||
{
|
{
|
||||||
XP_U8* ptr = NULL;
|
XP_U8* ptr = NULL;
|
||||||
HANDLE mappedFile = NULL;
|
HANDLE mappedFile = NULL;
|
||||||
|
@ -487,6 +490,9 @@ openMappedFile( const wchar_t* name, HANDLE* mappedFileP, HANDLE* hFileP )
|
||||||
ptr = (XP_U8*)mappedBase;
|
ptr = (XP_U8*)mappedBase;
|
||||||
*mappedFileP = mappedFile;
|
*mappedFileP = mappedFile;
|
||||||
*hFileP = hFile;
|
*hFileP = hFile;
|
||||||
|
if ( sizep != NULL ) {
|
||||||
|
*sizep = GetFileSize( hFile, NULL );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#elif defined TARGET_OS_WIN32
|
#elif defined TARGET_OS_WIN32
|
||||||
|
@ -497,14 +503,47 @@ openMappedFile( const wchar_t* name, HANDLE* mappedFileP, HANDLE* hFileP )
|
||||||
OPEN_EXISTING,
|
OPEN_EXISTING,
|
||||||
FILE_FLAG_RANDOM_ACCESS,
|
FILE_FLAG_RANDOM_ACCESS,
|
||||||
NULL );
|
NULL );
|
||||||
*hFileP = hFile;
|
XP_ASSERT( hFile != INVALID_HANDLE_VALUE );
|
||||||
*mappedFileP = NULL;
|
|
||||||
|
DWORD size = GetFileSize( hFile, NULL );
|
||||||
|
XP_LOGF( "file size: %d", size );
|
||||||
|
|
||||||
|
ptr = XP_MALLOC( mpool, size );
|
||||||
|
if ( ptr != NULL ) {
|
||||||
|
DWORD nRead;
|
||||||
|
if ( ReadFile( hFile, ptr, size, &nRead, NULL ) ) {
|
||||||
|
XP_ASSERT( nRead == size );
|
||||||
|
} else {
|
||||||
|
XP_FREE( mpool, ptr );
|
||||||
|
ptr = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseHandle( hFile );
|
||||||
|
|
||||||
|
*hFileP = NULL; /* nothing to close later */
|
||||||
|
if ( sizep != NULL ) {
|
||||||
|
*sizep = GetFileSize( hFile, NULL );
|
||||||
|
}
|
||||||
|
*mappedFileP = (HANDLE)ptr;
|
||||||
#endif
|
#endif
|
||||||
return ptr;
|
return ptr;
|
||||||
} /* openMappedFile */
|
} /* openMappedFile */
|
||||||
|
|
||||||
|
static void
|
||||||
|
closeMappedFile( MPFORMAL XP_U8* base, HANDLE mappedFile )
|
||||||
|
{
|
||||||
|
#if defined TARGET_OS_WINCE
|
||||||
|
UnmapViewOfFile( base );
|
||||||
|
CloseHandle( mappedFile );
|
||||||
|
#elif defined TARGET_OS_WIN32
|
||||||
|
XP_FREE( mpool, base );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static XP_Bool
|
static XP_Bool
|
||||||
checkIfDictAndLegal( wchar_t* path, XP_U16 pathLen, WIN32_FIND_DATA* data )
|
checkIfDictAndLegal( MPFORMAL wchar_t* path, XP_U16 pathLen,
|
||||||
|
WIN32_FIND_DATA* data )
|
||||||
{
|
{
|
||||||
XP_Bool result = XP_FALSE;
|
XP_Bool result = XP_FALSE;
|
||||||
wchar_t* name = data->cFileName;
|
wchar_t* name = data->cFileName;
|
||||||
|
@ -532,15 +571,14 @@ checkIfDictAndLegal( wchar_t* path, XP_U16 pathLen, WIN32_FIND_DATA* data )
|
||||||
pathBuf[pathLen] = 0;
|
pathBuf[pathLen] = 0;
|
||||||
wcscat( pathBuf, name );
|
wcscat( pathBuf, name );
|
||||||
|
|
||||||
base = openMappedFile( pathBuf, &mappedFile, &hFile );
|
base = openMappedFile( MPPARM(mpool) pathBuf, &mappedFile,
|
||||||
|
&hFile, NULL );
|
||||||
if ( !!base ) {
|
if ( !!base ) {
|
||||||
XP_U8* ptr = base;
|
XP_U8* ptr = base;
|
||||||
|
|
||||||
flags = n_ptr_tohs( &ptr );
|
flags = n_ptr_tohs( &ptr );
|
||||||
XP_LOGF( "checkIfDictAndLegal: flags=0x%x", flags );
|
XP_LOGF( "checkIfDictAndLegal: flags=0x%x", flags );
|
||||||
UnmapViewOfFile( base );
|
closeMappedFile( MPPARM(mpool) base, mappedFile );
|
||||||
CloseHandle( mappedFile );
|
|
||||||
|
|
||||||
#ifdef NODE_CAN_4
|
#ifdef NODE_CAN_4
|
||||||
/* are the flags what we expect */
|
/* are the flags what we expect */
|
||||||
result = flags == 0x0002 || flags == 0x0003;
|
result = flags == 0x0002 || flags == 0x0003;
|
||||||
|
@ -554,14 +592,18 @@ checkIfDictAndLegal( wchar_t* path, XP_U16 pathLen, WIN32_FIND_DATA* data )
|
||||||
} /* checkIfDictAndLegal */
|
} /* checkIfDictAndLegal */
|
||||||
|
|
||||||
static XP_Bool
|
static XP_Bool
|
||||||
locateOneDir( wchar_t* path, XP_U16* which )
|
locateOneDir( MPFORMAL wchar_t* path, XP_U16* which )
|
||||||
{
|
{
|
||||||
WIN32_FIND_DATA data;
|
WIN32_FIND_DATA data;
|
||||||
HANDLE fileH;
|
HANDLE fileH;
|
||||||
XP_Bool result = XP_FALSE;
|
XP_Bool result = XP_FALSE;
|
||||||
XP_U16 startLen;
|
XP_U16 startLen;
|
||||||
|
|
||||||
|
#if defined TARGET_OS_WINCE
|
||||||
lstrcat( path, L"\\" );
|
lstrcat( path, L"\\" );
|
||||||
|
#elif defined TARGET_OS_WIN32
|
||||||
|
lstrcat( path, L".\\" );
|
||||||
|
#endif
|
||||||
startLen = wcslen(path); /* record where we were so can back up */
|
startLen = wcslen(path); /* record where we were so can back up */
|
||||||
lstrcat( path, L"*" );
|
lstrcat( path, L"*" );
|
||||||
|
|
||||||
|
@ -576,14 +618,18 @@ locateOneDir( wchar_t* path, XP_U16* which )
|
||||||
if ( fileH != INVALID_HANDLE_VALUE ) {
|
if ( fileH != INVALID_HANDLE_VALUE ) {
|
||||||
for ( ; ; ) {
|
for ( ; ; ) {
|
||||||
|
|
||||||
if ( (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 ) {
|
if ((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0){
|
||||||
|
#if defined TARGET_OS_WINCE
|
||||||
|
/* We don't do recursive search on Win32!!! */
|
||||||
lstrcpy( path+startLen, data.cFileName );
|
lstrcpy( path+startLen, data.cFileName );
|
||||||
result = locateOneDir( path, which );
|
result = locateOneDir( MPPARM(mpool) path, which );
|
||||||
if ( result ) {
|
if ( result ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
path[startLen] = 0;
|
path[startLen] = 0;
|
||||||
} else if ( checkIfDictAndLegal( path, startLen, &data )
|
#endif
|
||||||
|
} else if ( checkIfDictAndLegal( MPPARM(mpool) path, startLen,
|
||||||
|
&data )
|
||||||
&& (*which-- == 0)) {
|
&& (*which-- == 0)) {
|
||||||
/* we're done! */
|
/* we're done! */
|
||||||
lstrcpy( path+startLen, data.cFileName );
|
lstrcpy( path+startLen, data.cFileName );
|
||||||
|
@ -611,7 +657,7 @@ ceLocateNthDict( MPFORMAL XP_U16 which )
|
||||||
|
|
||||||
pathBuf[0] = 0;
|
pathBuf[0] = 0;
|
||||||
|
|
||||||
if ( locateOneDir( pathBuf, &which ) ) {
|
if ( locateOneDir( MPPARM(mpool) pathBuf, &which ) ) {
|
||||||
XP_U16 len = wcslen( pathBuf );
|
XP_U16 len = wcslen( pathBuf );
|
||||||
result = XP_MALLOC( mpool, len + 1 );
|
result = XP_MALLOC( mpool, len + 1 );
|
||||||
len = WideCharToMultiByte( CP_ACP, 0, pathBuf, len + 1,
|
len = WideCharToMultiByte( CP_ACP, 0, pathBuf, len + 1,
|
||||||
|
|
Loading…
Add table
Reference in a new issue