diff --git a/wince/cedict.c b/wince/cedict.c index fa39c0abd..0227c5831 100755 --- a/wince/cedict.c +++ b/wince/cedict.c @@ -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 diff --git a/wince/cedict.h b/wince/cedict.h index 50f05cf9c..8b4490ea8 100755 --- a/wince/cedict.h +++ b/wince/cedict.h @@ -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 diff --git a/wince/ceginfo.c b/wince/ceginfo.c index 509b87ec3..2eb040e67 100755 --- a/wince/ceginfo.c +++ b/wince/ceginfo.c @@ -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 ); diff --git a/wince/cemain.c b/wince/cemain.c index a1e865890..5c030dc6b 100755 --- a/wince/cemain.c +++ b/wince/cemain.c @@ -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" );