From f8151aa338f0aee73db3c5135c50b6457da879f6 Mon Sep 17 00:00:00 2001 From: Abs62 Date: Wed, 25 Jan 2012 20:35:00 +0400 Subject: [PATCH] XDXF support - some improvements --- dsl_details.cc | 15 ++------------- stardict.cc | 14 +------------- ufile.cc | 11 +++++++++++ ufile.hh | 6 +++++- xdxf.cc | 16 ++-------------- 5 files changed, 21 insertions(+), 41 deletions(-) diff --git a/dsl_details.cc b/dsl_details.cc index ca4951dd..fdd6e4e9 100644 --- a/dsl_details.cc +++ b/dsl_details.cc @@ -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 diff --git a/stardict.cc b/stardict.cc index 602e5b8f..f4c6eac5 100644 --- a/stardict.cc +++ b/stardict.cc @@ -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; diff --git a/ufile.cc b/ufile.cc index 02fd0b6d..71145c84 100644 --- a/ufile.cc +++ b/ufile.cc @@ -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 diff --git a/ufile.hh b/ufile.hh index 7eca9938..36dc12e8 100644 --- a/ufile.hh +++ b/ufile.hh @@ -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 diff --git a/xdxf.cc b/xdxf.cc index 173667b1..85f8ff7f 100644 --- a/xdxf.cc +++ b/xdxf.cc @@ -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