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 // Since .dz is backwards-compatible with .gz, we use gz- functions to
// read it -- they are much nicer than the dict_data- ones. // read it -- they are much nicer than the dict_data- ones.
#ifdef __WIN32
int id = gd_open( fileName.c_str() ); f = gd_gzopen( 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");
if ( !f ) if ( !f )
throw exCantOpen( fileName ); throw exCantOpen( fileName );
#endif
// Now try guessing the encoding by reading the first two bytes // 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, vector< uint32_t > * articleOffsets,
bool isSynFile ) bool isSynFile )
{ {
#ifdef __WIN32 gzFile stardictIdx = gd_gzopen( fileName.c_str() );
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" );
if ( !stardictIdx ) if ( !stardictIdx )
throw exCantReadFile( fileName ); throw exCantReadFile( fileName );
#endif
vector< char > image; vector< char > image;

View file

@ -26,4 +26,15 @@ int gd_open( const char *filename)
return _wopen( wname, _O_RDONLY | _O_BINARY ); 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 #endif

View file

@ -3,6 +3,8 @@
#ifdef __WIN32 #ifdef __WIN32
#include "zlib.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
@ -10,6 +12,7 @@ extern "C"
FILE *gd_fopen( const char *filename, const char *mode ); 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 #ifdef __cplusplus
} /* end extern "C" */ } /* end extern "C" */
@ -17,6 +20,7 @@ int gd_open( const char *filename);
#else #else
#define gd_fopen fopen #define gd_fopen fopen
#define gd_gzopen( filename ) gzopen( filename, "rb" )
#endif #endif
#endif // UFILE_HH #endif // UFILE_HH

16
xdxf.cc
View file

@ -575,21 +575,9 @@ protected:
GzippedFile::GzippedFile( char const * fileName ) throw( exCantReadFile ) GzippedFile::GzippedFile( char const * fileName ) throw( exCantReadFile )
{ {
#ifdef __WIN32 gz = gd_gzopen( fileName );
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" );
if ( !gz ) if ( !gz )
throw exCantReadFile( fileName ); throw exCantReadFile( fileName );
#endif
dz = dict_data_open( fileName, 0 ); dz = dict_data_open( fileName, 0 );
@ -763,7 +751,7 @@ void indexArticle( GzippedFile & gzFile,
chunks.addToBlock( &offs, sizeof( offs ) ); chunks.addToBlock( &offs, sizeof( offs ) );
chunks.addToBlock( &size, sizeof( size ) ); 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 // Add words to index