mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +01:00
Rewrite dictionary location code so that it can more effeciently
produce a list of dictionaries. The API has changed slightly, but the new ability isn't used yet.
This commit is contained in:
parent
b26982a3df
commit
6680edebb6
4 changed files with 43 additions and 32 deletions
|
@ -573,18 +573,19 @@ checkIfDictAndLegal( MPFORMAL wchar_t* path, XP_U16 pathLen,
|
||||||
XP_U8* base;
|
XP_U8* base;
|
||||||
wchar_t pathBuf[257];
|
wchar_t pathBuf[257];
|
||||||
|
|
||||||
|
wcscpy( pathBuf, path );
|
||||||
|
pathBuf[pathLen] = 0;
|
||||||
|
wcscat( pathBuf, name );
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
{
|
{
|
||||||
char narrowName[32];
|
char narrowName[257];
|
||||||
int len = wcslen( name );
|
int len = wcslen( pathBuf );
|
||||||
len = WideCharToMultiByte( CP_ACP, 0, name, len + 1,
|
len = WideCharToMultiByte( CP_ACP, 0, pathBuf, len + 1,
|
||||||
narrowName, len + 1, NULL, NULL );
|
narrowName, len + 1, NULL, NULL );
|
||||||
XP_LOGF( "%s ends in .xwd", narrowName );
|
XP_LOGF( "%s ends in .xwd", narrowName );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
wcscpy( pathBuf, path );
|
|
||||||
pathBuf[pathLen] = 0;
|
|
||||||
wcscat( pathBuf, name );
|
|
||||||
|
|
||||||
base = openMappedFile( MPPARM(mpool) pathBuf, &mappedFile,
|
base = openMappedFile( MPPARM(mpool) pathBuf, &mappedFile,
|
||||||
&hFile, NULL );
|
&hFile, NULL );
|
||||||
|
@ -606,8 +607,9 @@ checkIfDictAndLegal( MPFORMAL wchar_t* path, XP_U16 pathLen,
|
||||||
return result;
|
return result;
|
||||||
} /* checkIfDictAndLegal */
|
} /* checkIfDictAndLegal */
|
||||||
|
|
||||||
static XP_Bool
|
static void
|
||||||
locateOneDir( MPFORMAL wchar_t* path, XP_U16* which )
|
locateOneDir( MPFORMAL wchar_t* path, XP_UCHAR** bufs, XP_U16 nSought,
|
||||||
|
XP_U16* nFoundP )
|
||||||
{
|
{
|
||||||
WIN32_FIND_DATA data;
|
WIN32_FIND_DATA data;
|
||||||
HANDLE fileH;
|
HANDLE fileH;
|
||||||
|
@ -637,19 +639,31 @@ locateOneDir( MPFORMAL wchar_t* path, XP_U16* which )
|
||||||
#if defined TARGET_OS_WINCE
|
#if defined TARGET_OS_WINCE
|
||||||
/* We don't do recursive search on Win32!!! */
|
/* We don't do recursive search on Win32!!! */
|
||||||
lstrcpy( path+startLen, data.cFileName );
|
lstrcpy( path+startLen, data.cFileName );
|
||||||
result = locateOneDir( MPPARM(mpool) path, which );
|
locateOneDir( MPPARM(mpool) path, bufs, nSought, nFoundP );
|
||||||
if ( result ) {
|
if ( *nFoundP == nSought ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
path[startLen] = 0;
|
path[startLen] = 0;
|
||||||
#endif
|
#endif
|
||||||
} else if ( checkIfDictAndLegal( MPPARM(mpool) path, startLen,
|
} else if ( checkIfDictAndLegal( MPPARM(mpool) path, startLen,
|
||||||
data.cFileName )
|
data.cFileName ) ) {
|
||||||
&& (*which-- == 0)) {
|
XP_U16 len;
|
||||||
/* we're done! */
|
XP_UCHAR* str;
|
||||||
lstrcpy( path+startLen, data.cFileName );
|
XP_ASSERT( *nFoundP < nSought );
|
||||||
result = XP_TRUE;
|
|
||||||
break;
|
len = startLen + wcslen( data.cFileName ) + 1;
|
||||||
|
str = XP_MALLOC( mpool, len );
|
||||||
|
WideCharToMultiByte( CP_ACP, 0, path, startLen,
|
||||||
|
str, startLen, NULL, NULL );
|
||||||
|
WideCharToMultiByte( CP_ACP, 0, data.cFileName, -1,
|
||||||
|
str + startLen, len - startLen,
|
||||||
|
NULL, NULL );
|
||||||
|
XP_LOGF( "%s: got %s at end\n", __FUNCTION__, str );
|
||||||
|
|
||||||
|
bufs[(*nFoundP)++] = str;
|
||||||
|
if ( *nFoundP == nSought ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !FindNextFile( fileH, &data ) ) {
|
if ( !FindNextFile( fileH, &data ) ) {
|
||||||
|
@ -660,25 +674,18 @@ locateOneDir( MPFORMAL wchar_t* path, XP_U16* which )
|
||||||
|
|
||||||
(void)FindClose( fileH );
|
(void)FindClose( fileH );
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
} /* locateOneDir */
|
} /* locateOneDir */
|
||||||
|
|
||||||
XP_UCHAR*
|
XP_U16
|
||||||
ceLocateNthDict( MPFORMAL XP_U16 which )
|
ceLocateNDicts( MPFORMAL XP_UCHAR** bufs, XP_U16 nSought )
|
||||||
{
|
{
|
||||||
|
XP_U16 nFound = 0;
|
||||||
wchar_t pathBuf[257];
|
wchar_t pathBuf[257];
|
||||||
XP_UCHAR* result = NULL;
|
|
||||||
|
|
||||||
pathBuf[0] = 0;
|
pathBuf[0] = 0;
|
||||||
|
|
||||||
if ( locateOneDir( MPPARM(mpool) pathBuf, &which ) ) {
|
locateOneDir( MPPARM(mpool) pathBuf, bufs, nSought, &nFound );
|
||||||
XP_U16 len = wcslen( pathBuf );
|
return nFound;
|
||||||
result = XP_MALLOC( mpool, len + 1 );
|
|
||||||
len = WideCharToMultiByte( CP_ACP, 0, pathBuf, len + 1,
|
|
||||||
result, len + 1, NULL, NULL );
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
} /* ceLocateNthDict */
|
} /* ceLocateNthDict */
|
||||||
|
|
||||||
static XP_U32
|
static XP_U32
|
||||||
|
|
|
@ -33,7 +33,12 @@ DictionaryCtxt* ce_dictionary_make_empty( CEAppGlobals* globals );
|
||||||
|
|
||||||
XP_Bool ce_pickDictFile( CEAppGlobals* globals, XP_UCHAR* buf, XP_U16 len );
|
XP_Bool ce_pickDictFile( CEAppGlobals* globals, XP_UCHAR* buf, XP_U16 len );
|
||||||
|
|
||||||
XP_UCHAR* ceLocateNthDict( MPFORMAL XP_U16 which );
|
/* ceLocateNDicts: Allocate and store in bufs ptrs to up to nSought paths to
|
||||||
|
* dict files. Return the number actually found. Caller is responsible for
|
||||||
|
* making sure bufs contains nSought slots.
|
||||||
|
*/
|
||||||
|
XP_U16 ceLocateNDicts( MPFORMAL XP_UCHAR** bufs, XP_U16 nSought );
|
||||||
|
|
||||||
|
|
||||||
XP_UCHAR* bname( XP_UCHAR* in );
|
XP_UCHAR* bname( XP_UCHAR* in );
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -109,7 +109,7 @@ loadFromGameInfo( HWND hDlg, CEAppGlobals* globals, GameInfoState* giState )
|
||||||
XP_MEMCPY( giState->newDictName, gi->dictName,
|
XP_MEMCPY( giState->newDictName, gi->dictName,
|
||||||
(XP_U16)XP_STRLEN(gi->dictName)+1 );
|
(XP_U16)XP_STRLEN(gi->dictName)+1 );
|
||||||
|
|
||||||
} else if ( !!(str = ceLocateNthDict( MPPARM(globals->mpool) 0 ) ) ) {
|
} else if ( 1 == ceLocateNDicts( MPPARM(globals->mpool) &str, 1 ) ) {
|
||||||
XP_MEMCPY( giState->newDictName, str, (XP_U16)XP_STRLEN(str)+1 );
|
XP_MEMCPY( giState->newDictName, str, (XP_U16)XP_STRLEN(str)+1 );
|
||||||
XP_FREE( globals->mpool, str );
|
XP_FREE( globals->mpool, str );
|
||||||
str = bname( giState->newDictName );
|
str = bname( giState->newDictName );
|
||||||
|
|
|
@ -967,8 +967,7 @@ InitInstance(HINSTANCE hInstance, int nCmdShow)
|
||||||
|
|
||||||
/* choose one. If none found it's an error. */
|
/* choose one. If none found it's an error. */
|
||||||
#ifndef STUBBED_DICT
|
#ifndef STUBBED_DICT
|
||||||
globals->gameInfo.dictName = ceLocateNthDict( MPPARM(mpool) 0 );
|
result = 1 == ceLocateNDicts(MPPARM(mpool) &globals->gameInfo.dictName, 1);
|
||||||
result = globals->gameInfo.dictName != NULL;
|
|
||||||
if ( !result ) {
|
if ( !result ) {
|
||||||
messageBoxChar( globals, "Please install at least one Crosswords "
|
messageBoxChar( globals, "Please install at least one Crosswords "
|
||||||
"dictionary.", L"Fatal error" );
|
"dictionary.", L"Fatal error" );
|
||||||
|
|
Loading…
Add table
Reference in a new issue