Skip to content

Commit 9f8ce14

Browse files
author
tntnet
committed
move zimlib, -reader and -writer into separate modules
0 parents  commit 9f8ce14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+19739
-0
lines changed

include/Makefile.am

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
nobase_include_HEADERS = \
2+
zim/article.h \
3+
zim/articlesearch.h \
4+
zim/bunzip2stream.h \
5+
zim/bzip2.h \
6+
zim/bzip2stream.h \
7+
zim/cache.h \
8+
zim/deflatestream.h \
9+
zim/dirent.h \
10+
zim/endian.h \
11+
zim/error.h \
12+
zim/file.h \
13+
zim/fileheader.h \
14+
zim/fileimpl.h \
15+
zim/fileiterator.h \
16+
zim/files.h \
17+
zim/indexarticle.h \
18+
zim/inflatestream.h \
19+
zim/qunicode.h \
20+
zim/search.h \
21+
zim/stringlessignorecase.h \
22+
zim/unicode.h \
23+
zim/zim.h \
24+
zim/zintstream.h

include/zim/article.h

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*
2+
* Copyright (C) 2006 Tommi Maekitalo
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License as
6+
* published by the Free Software Foundation; either version 2 of the
7+
* License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but
10+
* is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
11+
* warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
12+
* NON-INFRINGEMENT. See the GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
*/
19+
20+
#ifndef ZIM_ARTICLE_H
21+
#define ZIM_ARTICLE_H
22+
23+
#include <string>
24+
#include <zim/zim.h>
25+
#include <zim/dirent.h>
26+
#include <zim/qunicode.h>
27+
#include <zim/file.h>
28+
29+
namespace zim
30+
{
31+
class Article
32+
{
33+
public:
34+
typedef Dirent::CompressionType CompressionType;
35+
typedef Dirent::MimeType MimeType;
36+
37+
private:
38+
Dirent dirent;
39+
std::string data;
40+
mutable std::string uncompressedData;
41+
File file;
42+
size_type idx;
43+
bool dataRead;
44+
45+
void uncompressData() const;
46+
47+
public:
48+
Article() : dataRead(true) { }
49+
Article(size_type idx_, const Dirent& dirent_, const File& file_,
50+
const std::string& data_, bool dummy)
51+
: dirent(dirent_),
52+
data(data_),
53+
file(file_),
54+
idx(idx_),
55+
dataRead(true)
56+
{ }
57+
Article(size_type idx_, const Dirent& dirent_, const File& file_)
58+
: dirent(dirent_),
59+
file(file_),
60+
idx(idx_),
61+
dataRead(false)
62+
{ }
63+
64+
Dirent& getDirent() { return dirent; }
65+
const Dirent& getDirent() const { return dirent; }
66+
void setDirent(const Dirent& d) { dirent = d; }
67+
68+
const std::string&
69+
getParameter() const { return dirent.getParameter(); }
70+
void setParameter(const std::string& p) { dirent.setParameter(p); }
71+
72+
offset_type getDataOffset() const { return dirent.getOffset(); }
73+
void setDataOffset(offset_type o) { dirent.setOffset(o); }
74+
75+
size_type getDataLen() const { return dirent.getSize(); }
76+
77+
CompressionType getCompression() const { return dirent.getCompression(); }
78+
bool isCompressionZip() const { return dirent.isCompressionZip(); }
79+
bool isCompressionBzip2() const { return dirent.isCompressionBzip2(); }
80+
bool isCompressionLzma() const { return dirent.isCompressionLzma(); }
81+
bool isCompressed() const { return isCompressionZip() || isCompressionLzma(); }
82+
83+
QUnicodeString getTitle() const { return QUnicodeString(dirent.getTitle()); }
84+
void setTitle(const QUnicodeString& title) { dirent.setTitle(title.getValue()); }
85+
86+
MimeType getLibraryMimeType() const { return dirent.getMimeType(); }
87+
void setLibraryMimeType(MimeType m) { dirent.setMimeType(m); }
88+
const std::string&
89+
getMimeType() const;
90+
91+
bool getRedirectFlag() const { return dirent.getRedirectFlag(); }
92+
void setRedirectFlag(bool sw = true) { dirent.setRedirectFlag(sw); }
93+
94+
char getNamespace() const { return dirent.getNamespace(); }
95+
void setNamespace(char ns) { dirent.setNamespace(ns); }
96+
97+
size_type getRedirectIndex() const { return dirent.getRedirectIndex(); }
98+
void setRedirectIndex(size_type o) { dirent.setRedirectIndex(o); }
99+
100+
Article getRedirectArticle() const;
101+
102+
size_type getArticleOffset() const { return dirent.getArticleOffset(); }
103+
void setArticleOffset(size_type o) { dirent.setArticleOffset(o); }
104+
105+
size_type getArticleSize() const { return dirent.getArticleSize(); }
106+
void setArticleSize(size_type s) { dirent.setArticleSize(s); }
107+
108+
operator bool() { return getDataOffset() != 0; }
109+
110+
bool operator< (const Article& a) const
111+
{ return getNamespace() < a.getNamespace()
112+
|| getNamespace() == a.getNamespace()
113+
&& getTitle() < a.getTitle(); }
114+
115+
const std::string& getRawData() const;
116+
117+
std::string getData() const;
118+
void setData(const std::string& data_) { data = data_; dataRead = true; }
119+
120+
size_type getUncompressedLen() const
121+
{
122+
uncompressData();
123+
return uncompressedData.size();
124+
}
125+
126+
const File& getFile() const { return file; }
127+
File& getFile() { return file; }
128+
void setFile(const File& f) { file = f; }
129+
130+
size_type getIndex() const { return idx; }
131+
void setIndex(size_type i) { idx = i; }
132+
133+
QUnicodeString getUrl() const { return QUnicodeString(std::string(1, getNamespace()) + '/' + getDirent().getTitle()); }
134+
135+
offset_type getIndexOffset() const { return getFile().getFileheader().getIndexPos() + idx * 4; }
136+
offset_type getDirentOffset() const { return getFile().getDirentOffset(idx); }
137+
};
138+
139+
}
140+
141+
#endif // ZIM_ARTICLE_H
142+

include/zim/articlesearch.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (C) 2007 Tommi Maekitalo
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License as
6+
* published by the Free Software Foundation; either version 2 of the
7+
* License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but
10+
* is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
11+
* warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
12+
* NON-INFRINGEMENT. See the GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
*/
19+
20+
#ifndef ZIM_ARTICLESEARCH_H
21+
#define ZIM_ARTICLESEARCH_H
22+
23+
#include <vector>
24+
#include <zim/file.h>
25+
#include <zim/fileiterator.h>
26+
#include <zim/article.h>
27+
28+
namespace zim
29+
{
30+
class ArticleSearch
31+
{
32+
public:
33+
typedef std::vector<Article> Results;
34+
35+
private:
36+
File articleFile;
37+
std::string titles;
38+
39+
public:
40+
explicit ArticleSearch(const File& articleFile_)
41+
: articleFile(articleFile_)
42+
{ }
43+
44+
Results search(const std::string& expr);
45+
};
46+
}
47+
48+
#endif // ZIM_ARTICLESEARCH_H

include/zim/bunzip2stream.h

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (C) 2008 Tommi Maekitalo
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License as
6+
* published by the Free Software Foundation; either version 2 of the
7+
* License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but
10+
* is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
11+
* warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
12+
* NON-INFRINGEMENT. See the GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
*/
19+
20+
21+
#ifndef ZIM_BUNZIP2STREAM_H
22+
#define ZIM_BUNZIP2STREAM_H
23+
24+
#include <iostream>
25+
#include <stdexcept>
26+
#include <bzlib.h>
27+
#include <zim/bzip2.h>
28+
29+
namespace zim
30+
{
31+
class Bzip2UncompressError : public Bzip2Error
32+
{
33+
public:
34+
Bzip2UncompressError(int zRet_, const std::string& msg)
35+
: Bzip2Error(zRet_, msg)
36+
{ }
37+
};
38+
39+
class Bunzip2StreamBuf : public std::streambuf
40+
{
41+
bz_stream stream;
42+
char_type* iobuffer;
43+
unsigned bufsize;
44+
std::streambuf* sinksource;
45+
46+
char_type* ibuffer() { return iobuffer; }
47+
std::streamsize ibuffer_size() { return bufsize >> 1; }
48+
char_type* obuffer() { return iobuffer + ibuffer_size(); }
49+
std::streamsize obuffer_size() { return bufsize >> 1; }
50+
51+
public:
52+
explicit Bunzip2StreamBuf(std::streambuf* sinksource_, bool small = false, unsigned bufsize = 8192);
53+
~Bunzip2StreamBuf();
54+
55+
/// see std::streambuf
56+
int_type overflow(int_type c);
57+
/// see std::streambuf
58+
int_type underflow();
59+
/// see std::streambuf
60+
int sync();
61+
62+
void setSinksource(std::streambuf* sinksource_) { sinksource = sinksource_; }
63+
};
64+
65+
class Bunzip2Stream : public std::iostream
66+
{
67+
Bunzip2StreamBuf streambuf;
68+
69+
public:
70+
explicit Bunzip2Stream(std::streambuf* sinksource, bool small = false, unsigned bufsize = 8192)
71+
: std::iostream(0),
72+
streambuf(sinksource, small, bufsize)
73+
{ init(&streambuf); }
74+
explicit Bunzip2Stream(std::ios& sinksource, bool small = false, unsigned bufsize = 8192)
75+
: std::iostream(0),
76+
streambuf(sinksource.rdbuf(), small, bufsize)
77+
{ init(&streambuf); }
78+
79+
void setSinksource(std::streambuf* sinksource) { streambuf.setSinksource(sinksource); }
80+
void setSinksource(std::ios& sinksource) { streambuf.setSinksource(sinksource.rdbuf()); }
81+
void setSink(std::ostream& sink) { streambuf.setSinksource(sink.rdbuf()); }
82+
void setSource(std::istream& source) { streambuf.setSinksource(source.rdbuf()); }
83+
};
84+
}
85+
86+
#endif // ZIM_BUNZIP2STREAM_H
87+

include/zim/bzip2.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (C) 2008 Tommi Maekitalo
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License as
6+
* published by the Free Software Foundation; either version 2 of the
7+
* License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but
10+
* is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
11+
* warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
12+
* NON-INFRINGEMENT. See the GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
*/
19+
20+
#ifndef ZIM_BZIP2_H
21+
#define ZIM_BZIP2_H
22+
23+
#include <stdexcept>
24+
25+
namespace zim
26+
{
27+
class Bzip2Error : public std::runtime_error
28+
{
29+
int zRet;
30+
31+
public:
32+
Bzip2Error(int zRet_, const std::string& msg)
33+
: std::runtime_error(msg),
34+
zRet(zRet_)
35+
{ }
36+
37+
int getRet() const { return zRet; }
38+
static const char* getErrorString(int ret);
39+
};
40+
41+
}
42+
43+
#endif // ZIM_BZIP2_H
44+

0 commit comments

Comments
 (0)