mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
Fixed #237: Proper dictionary title (DICT format)
This commit is contained in:
parent
b4b348546c
commit
97ef5aa995
|
@ -47,7 +47,7 @@ DEF_EX( exInvalidBase64, "Invalid base64 sequence encountered", Dictionary::Ex )
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
Signature = 0x58444344, // DCDX on little-endian, XDCD on big-endian
|
Signature = 0x58444344, // DCDX on little-endian, XDCD on big-endian
|
||||||
CurrentFormatVersion = 3 + BtreeIndexing::FormatVersion + Folding::Version
|
CurrentFormatVersion = 4 + BtreeIndexing::FormatVersion + Folding::Version
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IdxHeader
|
struct IdxHeader
|
||||||
|
@ -82,6 +82,7 @@ class DictdDictionary: public BtreeIndexing::BtreeDictionary
|
||||||
File::Class idx, indexFile; // The later is .index file
|
File::Class idx, indexFile; // The later is .index file
|
||||||
IdxHeader idxHeader;
|
IdxHeader idxHeader;
|
||||||
dictData * dz;
|
dictData * dz;
|
||||||
|
string dictionaryName;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -90,7 +91,8 @@ public:
|
||||||
|
|
||||||
~DictdDictionary();
|
~DictdDictionary();
|
||||||
|
|
||||||
virtual string getName() throw();
|
virtual string getName() throw()
|
||||||
|
{ return dictionaryName; }
|
||||||
|
|
||||||
virtual map< Dictionary::Property, string > getProperties() throw()
|
virtual map< Dictionary::Property, string > getProperties() throw()
|
||||||
{ return map< Dictionary::Property, string >(); }
|
{ return map< Dictionary::Property, string >(); }
|
||||||
|
@ -123,6 +125,14 @@ DictdDictionary::DictdDictionary( string const & id,
|
||||||
indexFile( dictionaryFiles[ 0 ], "rb" ),
|
indexFile( dictionaryFiles[ 0 ], "rb" ),
|
||||||
idxHeader( idx.read< IdxHeader >() )
|
idxHeader( idx.read< IdxHeader >() )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Read the dictionary name
|
||||||
|
idx.seek( sizeof( idxHeader ) );
|
||||||
|
|
||||||
|
vector< char > dName( idx.read< uint32_t >() );
|
||||||
|
idx.read( &dName.front(), dName.size() );
|
||||||
|
dictionaryName = string( &dName.front(), dName.size() );
|
||||||
|
|
||||||
// Open the .dict file
|
// Open the .dict file
|
||||||
|
|
||||||
dz = dict_data_open( dictionaryFiles[ 1 ].c_str(), 0 );
|
dz = dict_data_open( dictionaryFiles[ 1 ].c_str(), 0 );
|
||||||
|
@ -181,11 +191,6 @@ void DictdDictionary::loadIcon() throw()
|
||||||
dictionaryIconLoaded = true;
|
dictionaryIconLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
string DictdDictionary::getName() throw()
|
|
||||||
{
|
|
||||||
return nameFromFileName( getDictionaryFilenames()[ 0 ] );
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t decodeBase64( string const & str )
|
uint32_t decodeBase64( string const & str )
|
||||||
{
|
{
|
||||||
static char const digits[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
static char const digits[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||||
|
@ -362,7 +367,8 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
|
||||||
indexIsOldOrBad( indexFile ) )
|
indexIsOldOrBad( indexFile ) )
|
||||||
{
|
{
|
||||||
// Building the index
|
// Building the index
|
||||||
initializing.indexingDictionary( nameFromFileName( dictFiles[ 0 ] ) );
|
string dictionaryName = nameFromFileName( dictFiles[ 0 ] );
|
||||||
|
initializing.indexingDictionary( dictionaryName );
|
||||||
|
|
||||||
File::Class idx( indexFile, "wb" );
|
File::Class idx( indexFile, "wb" );
|
||||||
|
|
||||||
|
@ -400,12 +406,57 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !strncmp( buf, "00databaseshort", 15 ) ) // Check for proper dictionary name
|
||||||
|
{
|
||||||
|
char * tab1 = strchr( buf, '\t' );
|
||||||
|
if ( tab1 )
|
||||||
|
{
|
||||||
|
char * tab2 = strchr( tab1 + 1, '\t' );
|
||||||
|
if ( tab2 )
|
||||||
|
{
|
||||||
|
// After tab1 should be article offset, after tab2 -- article size
|
||||||
|
uint32_t articleOffset = decodeBase64( string( tab1 + 1, tab2 - tab1 - 1 ) );
|
||||||
|
uint32_t articleSize = decodeBase64( tab2 + 1 );
|
||||||
|
|
||||||
|
dictData * dz = dict_data_open( dictFiles[ 1 ].c_str(), 0 );
|
||||||
|
|
||||||
|
if ( dz )
|
||||||
|
{
|
||||||
|
char * articleBody = dict_data_read_( dz, articleOffset, articleSize, 0, 0 );
|
||||||
|
if ( articleBody )
|
||||||
|
{
|
||||||
|
char * eol = strchr( articleBody, '\n' ); // skip the first line (headword itself)
|
||||||
|
if ( eol )
|
||||||
|
{
|
||||||
|
while( *eol && isspace( *eol ) ) ++eol; // skip spaces
|
||||||
|
|
||||||
|
// use only the single line for the dictionary title
|
||||||
|
char * endEol = strchr( eol, '\n' );
|
||||||
|
if ( endEol )
|
||||||
|
*endEol = 0;
|
||||||
|
|
||||||
|
DPRINTF( "DICT NAME: '%s'\n", eol );
|
||||||
|
dictionaryName = eol;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dict_data_close( dz );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
indexedWords.addWord( Utf8::decode( string( buf, strchr( buf, '\t' ) - buf ) ), curOffset );
|
indexedWords.addWord( Utf8::decode( string( buf, strchr( buf, '\t' ) - buf ) ), curOffset );
|
||||||
|
|
||||||
++idxHeader.wordCount;
|
++idxHeader.wordCount;
|
||||||
|
|
||||||
} while( !indexFile.eof() );
|
} while( !indexFile.eof() );
|
||||||
|
|
||||||
|
|
||||||
|
// Write dictionary name
|
||||||
|
|
||||||
|
idx.write( (uint32_t) dictionaryName.size() );
|
||||||
|
idx.write( dictionaryName.data(), dictionaryName.size() );
|
||||||
|
|
||||||
// Build index
|
// Build index
|
||||||
|
|
||||||
IndexInfo idxInfo = BtreeIndexing::buildIndex( indexedWords, idx );
|
IndexInfo idxInfo = BtreeIndexing::buildIndex( indexedWords, idx );
|
||||||
|
|
Loading…
Reference in a new issue