XDXF support - some improvements

This commit is contained in:
Abs62 2012-01-25 20:35:00 +04:00
parent af53018709
commit f8151aa338
5 changed files with 21 additions and 41 deletions

View file

@ -500,21 +500,10 @@ DslScanner::DslScanner( string const & fileName ) throw( Ex, Iconv::Ex ):
{
// Since .dz is backwards-compatible with .gz, we use gz- functions to
// read it -- they are much nicer than the dict_data- ones.
#ifdef __WIN32
int id = gd_open( fileName.c_str() );
if( id == -1 )
throw exCantOpen( fileName );
f = gzdopen( id, "rb");
if ( !f )
{
_close( id );
throw exCantOpen( fileName );
}
#else
f = gzopen( fileName.c_str(), "rb");
f = gd_gzopen( fileName.c_str() );
if ( !f )
throw exCantOpen( fileName );
#endif
// Now try guessing the encoding by reading the first two bytes

View file

@ -887,21 +887,9 @@ static void handleIdxSynFile( string const & fileName,
vector< uint32_t > * articleOffsets,
bool isSynFile )
{
#ifdef __WIN32
int id = gd_open( fileName.c_str() );
if( id == -1 )
throw exCantReadFile( fileName );
gzFile stardictIdx = gzdopen( id, "rb");
if ( !stardictIdx )
{
_close( id );
throw exCantReadFile( fileName );
}
#else
gzFile stardictIdx = gzopen( fileName.c_str(), "rb" );
gzFile stardictIdx = gd_gzopen( fileName.c_str() );
if ( !stardictIdx )
throw exCantReadFile( fileName );
#endif
vector< char > image;

View file

@ -26,4 +26,15 @@ int gd_open( const char *filename)
return _wopen( wname, _O_RDONLY | _O_BINARY );
}
gzFile gd_gzopen( const char *filename )
{
int id = gd_open( filename );
if( id == -1 )
return NULL;
gzFile f = gzdopen( id, "rb");
if( f == NULL )
_close( id );
return f;
}
#endif

View file

@ -3,13 +3,16 @@
#ifdef __WIN32
#include "zlib.h"
#ifdef __cplusplus
extern "C"
{
#endif
FILE *gd_fopen( const char *filename, const char *mode );
int gd_open( const char *filename);
int gd_open( const char *filename );
gzFile gd_gzopen( const char *filename );
#ifdef __cplusplus
} /* end extern "C" */
@ -17,6 +20,7 @@ int gd_open( const char *filename);
#else
#define gd_fopen fopen
#define gd_gzopen( filename ) gzopen( filename, "rb" )
#endif
#endif // UFILE_HH

16
xdxf.cc
View file

@ -575,21 +575,9 @@ protected:
GzippedFile::GzippedFile( char const * fileName ) throw( exCantReadFile )
{
#ifdef __WIN32
int id = gd_open( fileName );
if( id == -1 )
throw exCantReadFile( fileName );
gz = gzdopen( id, "rb");
if ( !gz )
{
_close( id );
throw exCantReadFile( fileName );
}
#else
gz = gzopen( fileName, "rb" );
gz = gd_gzopen( fileName );
if ( !gz )
throw exCantReadFile( fileName );
#endif
dz = dict_data_open( fileName, 0 );
@ -763,7 +751,7 @@ void indexArticle( GzippedFile & gzFile,
chunks.addToBlock( &offs, sizeof( offs ) );
chunks.addToBlock( &size, sizeof( size ) );
DPRINTF( "%x: %s\n", articleOffset, words.begin()->toUtf8().data() );
// DPRINTF( "%x: %s\n", articleOffset, words.begin()->toUtf8().data() );
// Add words to index