mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
XDXF support - some improvements
This commit is contained in:
parent
af53018709
commit
f8151aa338
|
@ -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
|
||||||
|
|
||||||
|
|
14
stardict.cc
14
stardict.cc
|
@ -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;
|
||||||
|
|
||||||
|
|
11
ufile.cc
11
ufile.cc
|
@ -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
|
||||||
|
|
4
ufile.hh
4
ufile.hh
|
@ -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
16
xdxf.cc
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue