mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-15 15:41:24 +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
144e7b408b
commit
76c6a56f93
4 changed files with 43 additions and 32 deletions
|
@ -573,18 +573,19 @@ checkIfDictAndLegal( MPFORMAL wchar_t* path, XP_U16 pathLen,
|
|||
XP_U8* base;
|
||||
wchar_t pathBuf[257];
|
||||
|
||||
wcscpy( pathBuf, path );
|
||||
pathBuf[pathLen] = 0;
|
||||
wcscat( pathBuf, name );
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
char narrowName[32];
|
||||
int len = wcslen( name );
|
||||
len = WideCharToMultiByte( CP_ACP, 0, name, len + 1,
|
||||
char narrowName[257];
|
||||
int len = wcslen( pathBuf );
|
||||
len = WideCharToMultiByte( CP_ACP, 0, pathBuf, len + 1,
|
||||
narrowName, len + 1, NULL, NULL );
|
||||
XP_LOGF( "%s ends in .xwd", narrowName );
|
||||
}
|
||||
#endif
|
||||
wcscpy( pathBuf, path );
|
||||
pathBuf[pathLen] = 0;
|
||||
wcscat( pathBuf, name );
|
||||
|
||||
base = openMappedFile( MPPARM(mpool) pathBuf, &mappedFile,
|
||||
&hFile, NULL );
|
||||
|
@ -606,8 +607,9 @@ checkIfDictAndLegal( MPFORMAL wchar_t* path, XP_U16 pathLen,
|
|||
return result;
|
||||
} /* checkIfDictAndLegal */
|
||||
|
||||
static XP_Bool
|
||||
locateOneDir( MPFORMAL wchar_t* path, XP_U16* which )
|
||||
static void
|
||||
locateOneDir( MPFORMAL wchar_t* path, XP_UCHAR** bufs, XP_U16 nSought,
|
||||
XP_U16* nFoundP )
|
||||
{
|
||||
WIN32_FIND_DATA data;
|
||||
HANDLE fileH;
|
||||
|
@ -637,19 +639,31 @@ locateOneDir( MPFORMAL wchar_t* path, XP_U16* which )
|
|||
#if defined TARGET_OS_WINCE
|
||||
/* We don't do recursive search on Win32!!! */
|
||||
lstrcpy( path+startLen, data.cFileName );
|
||||
result = locateOneDir( MPPARM(mpool) path, which );
|
||||
if ( result ) {
|
||||
locateOneDir( MPPARM(mpool) path, bufs, nSought, nFoundP );
|
||||
if ( *nFoundP == nSought ) {
|
||||
break;
|
||||
}
|
||||
path[startLen] = 0;
|
||||
#endif
|
||||
} else if ( checkIfDictAndLegal( MPPARM(mpool) path, startLen,
|
||||
data.cFileName )
|
||||
&& (*which-- == 0)) {
|
||||
/* we're done! */
|
||||
lstrcpy( path+startLen, data.cFileName );
|
||||
result = XP_TRUE;
|
||||
break;
|
||||
data.cFileName ) ) {
|
||||
XP_U16 len;
|
||||
XP_UCHAR* str;
|
||||
XP_ASSERT( *nFoundP < nSought );
|
||||
|
||||
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 ) ) {
|
||||
|
@ -660,25 +674,18 @@ locateOneDir( MPFORMAL wchar_t* path, XP_U16* which )
|
|||
|
||||
(void)FindClose( fileH );
|
||||
}
|
||||
|
||||
return result;
|
||||
} /* locateOneDir */
|
||||
|
||||
XP_UCHAR*
|
||||
ceLocateNthDict( MPFORMAL XP_U16 which )
|
||||
XP_U16
|
||||
ceLocateNDicts( MPFORMAL XP_UCHAR** bufs, XP_U16 nSought )
|
||||
{
|
||||
XP_U16 nFound = 0;
|
||||
wchar_t pathBuf[257];
|
||||
XP_UCHAR* result = NULL;
|
||||
|
||||
pathBuf[0] = 0;
|
||||
|
||||
if ( locateOneDir( MPPARM(mpool) pathBuf, &which ) ) {
|
||||
XP_U16 len = wcslen( pathBuf );
|
||||
result = XP_MALLOC( mpool, len + 1 );
|
||||
len = WideCharToMultiByte( CP_ACP, 0, pathBuf, len + 1,
|
||||
result, len + 1, NULL, NULL );
|
||||
}
|
||||
return result;
|
||||
locateOneDir( MPPARM(mpool) pathBuf, bufs, nSought, &nFound );
|
||||
return nFound;
|
||||
} /* ceLocateNthDict */
|
||||
|
||||
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_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 );
|
||||
#endif
|
||||
|
|
|
@ -109,7 +109,7 @@ loadFromGameInfo( HWND hDlg, CEAppGlobals* globals, GameInfoState* giState )
|
|||
XP_MEMCPY( giState->newDictName, gi->dictName,
|
||||
(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_FREE( globals->mpool, str );
|
||||
str = bname( giState->newDictName );
|
||||
|
|
|
@ -967,8 +967,7 @@ InitInstance(HINSTANCE hInstance, int nCmdShow)
|
|||
|
||||
/* choose one. If none found it's an error. */
|
||||
#ifndef STUBBED_DICT
|
||||
globals->gameInfo.dictName = ceLocateNthDict( MPPARM(mpool) 0 );
|
||||
result = globals->gameInfo.dictName != NULL;
|
||||
result = 1 == ceLocateNDicts(MPPARM(mpool) &globals->gameInfo.dictName, 1);
|
||||
if ( !result ) {
|
||||
messageBoxChar( globals, "Please install at least one Crosswords "
|
||||
"dictionary.", L"Fatal error" );
|
||||
|
|
Loading…
Reference in a new issue