Skip to content

Commit

Permalink
Add support for Aard dictionaries (aar-html)
Browse files Browse the repository at this point in the history
  • Loading branch information
Abs62 committed Feb 9, 2012
1 parent 79d24b8 commit 81ee55a
Show file tree
Hide file tree
Showing 9 changed files with 1,034 additions and 72 deletions.
910 changes: 910 additions & 0 deletions aard.cc

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions aard.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* This file is (c) 2008-2012 Konstantin Isakov <[email protected]>
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */

#ifndef __AARD_HH_INCLUDED__
#define __AARD_HH_INCLUDED__

#include "dictionary.hh"

/// Support for the aard dictionaries.
namespace Aard {

using std::vector;
using std::string;

vector< sptr< Dictionary::Class > > makeDictionaries(
vector< string > const & fileNames,
string const & indicesDir,
Dictionary::Initializing & )
throw( std::exception );

}

#endif
72 changes: 72 additions & 0 deletions decompress.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <stdlib.h>

#include "decompress.hh"
#include "zlib.h"
#include "bzlib.h"

string decompressZlib( char * bufptr, unsigned length )
{
z_stream zs;
char buf[2048];
string str;
int res;
memset( &zs, 0, sizeof(zs) );
zs.next_in = (Bytef *)bufptr;
zs.avail_in = length;
while( 1 )
{
res = inflateInit( &zs );
if( res != Z_OK )
break;
while( res != Z_STREAM_END )
{
memset( buf, 0, sizeof(buf) );
zs.next_out = (Bytef *)buf;
zs.avail_out = 2047;
res = inflate( &zs, Z_SYNC_FLUSH );
str += buf;
if( res != Z_OK && res != Z_STREAM_END )
break;
}
break;
}
inflateEnd( &zs );
if( res != Z_STREAM_END )
str.clear();
return str;
}

string decompressBzip2( char * bufptr, unsigned length )
{
bz_stream zs;
char buf[2048];
string str;
int res;
memset( &zs, 0, sizeof(zs) );
zs.next_in = bufptr;
zs.avail_in = length;
zs.total_in_lo32 = length;
while( 1 )
{
res = BZ2_bzDecompressInit( &zs, 0, 0 );
if( res != BZ_OK )
break;
while( res != BZ_STREAM_END )
{
memset( buf, 0, sizeof(buf) );
zs.next_out = buf;
zs.avail_out = 2047;
zs.total_out_lo32 = length;
res = BZ2_bzDecompress( &zs );
str += buf;
if( res != BZ_OK && res != BZ_STREAM_END )
break;
}
break;
}
BZ2_bzDecompressEnd( &zs );
if( res != BZ_STREAM_END )
str.clear();
return str;
}

12 changes: 12 additions & 0 deletions decompress.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef __DECOMPRESS_HH_INCLUDED__
#define __DECOMPRESS_HH_INCLUDED__

#include <string>

using std::string;

string decompressZlib( char * bufptr, unsigned length );

string decompressBzip2( char * bufptr, unsigned length );

#endif // DECOMPRESS_HH
8 changes: 6 additions & 2 deletions goldendict.pro
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ HEADERS += folding.hh \
gdappstyle.hh \
ufile.hh \
xdxf.hh \
sdict.hh
sdict.hh \
decompress.hh \
aard.hh
FORMS += groups.ui \
dictgroupwidget.ui \
mainwindow.ui \
Expand Down Expand Up @@ -282,7 +284,9 @@ SOURCES += folding.cc \
gdappstyle.cc \
ufile.cc \
xdxf.cc \
sdict.cc
sdict.cc \
decompress.cc \
aard.cc
win32 {
SOURCES += mouseover_win32/ThTypes.c \
wordbyauto.cc \
Expand Down
Binary file added icons/icon32_aard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion loaddictionaries.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "fsencoding.hh"
#include "xdxf.hh"
#include "sdict.hh"
#include "aard.hh"

#include <QMessageBox>
#include <QDir>
Expand All @@ -42,7 +43,7 @@ LoadDictionaries::LoadDictionaries( Config::Class const & cfg ):

nameFilters << "*.bgl" << "*.ifo" << "*.lsa" << "*.dat"
<< "*.dsl" << "*.dsl.dz" << "*.index" << "*.xdxf"
<< "*.xdxf.dz" << "*.dct";
<< "*.xdxf.dz" << "*.dct" << "*.aar";
}

void LoadDictionaries::run()
Expand Down Expand Up @@ -155,6 +156,13 @@ void LoadDictionaries::handlePath( Config::Path const & path )
dictionaries.insert( dictionaries.end(), sdictDictionaries.begin(),
sdictDictionaries.end() );
}
{
vector< sptr< Dictionary::Class > > aardDictionaries =
Aard::makeDictionaries( allFiles, FsEncoding::encode( Config::getIndexDir() ), *this );

dictionaries.insert( dictionaries.end(), aardDictionaries.begin(),
aardDictionaries.end() );
}
}

void LoadDictionaries::indexingDictionary( string const & dictionaryName ) throw()
Expand Down
1 change: 1 addition & 0 deletions resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
<file>icons/error.png</file>
<file>icons/macicon.png</file>
<file>icons/icon32_sdict.png</file>
<file>icons/icon32_aard.png</file>
</qresource>
</RCC>
70 changes: 1 addition & 69 deletions sdict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
#include "langcoder.hh"
#include "dprintf.hh"
#include "fsencoding.hh"
#include "decompress.hh"

#include <zlib.h>
#include <bzlib.h>
#include <map>
#include <set>
#include <string>
#include <stdlib.h>

#ifdef _MSC_VER
#include <stub_msvc.h>
Expand Down Expand Up @@ -124,72 +122,6 @@ bool indexIsOldOrBad( string const & indexFile )
header.formatVersion != CurrentFormatVersion;
}

string decompressZlib( char * bufptr, unsigned length )
{
z_stream zs;
char buf[2048];
string str;
int res;
memset( &zs, 0, sizeof(zs) );
zs.next_in = (Bytef *)bufptr;
zs.avail_in = length;
while( 1 )
{
res = inflateInit( &zs );
if( res != Z_OK )
break;
while( res != Z_STREAM_END )
{
memset( buf, 0, sizeof(buf) );
zs.next_out = (Bytef *)buf;
zs.avail_out = 2047;
res = inflate( &zs, Z_SYNC_FLUSH );
str += buf;
if( res != Z_OK && res != Z_STREAM_END )
break;
}
break;
}
inflateEnd( &zs );
if( res != Z_STREAM_END )
str.clear();
return str;
}

string decompressBzip2( char * bufptr, unsigned length )
{
bz_stream zs;
char buf[2048];
string str;
int res;
memset( &zs, 0, sizeof(zs) );
zs.next_in = bufptr;
zs.avail_in = length;
zs.total_in_lo32 = length;
while( 1 )
{
res = BZ2_bzDecompressInit( &zs, 0, 0 );
if( res != BZ_OK )
break;
while( res != BZ_STREAM_END )
{
memset( buf, 0, sizeof(buf) );
zs.next_out = buf;
zs.avail_out = 2047;
zs.total_out_lo32 = length;
res = BZ2_bzDecompress( &zs );
str += buf;
if( res != BZ_OK && res != BZ_STREAM_END )
break;
}
break;
}
BZ2_bzDecompressEnd( &zs );
if( res != BZ_STREAM_END )
str.clear();
return str;
}

class SdictDictionary: public BtreeIndexing::BtreeDictionary
{
Mutex idxMutex;
Expand Down

0 comments on commit 81ee55a

Please sign in to comment.