00001 #ifndef __REB_H
00002 #define __REB_H
00003 #include <stdio.h>
00004 #include <zlib.h>
00005 #include <sys/stat.h>
00006 #ifdef USEQPE
00007 #include <qpe/global.h>
00008 #endif
00009 #include <qmap.h>
00010
00011 #include "CExpander.h"
00012 #include <zlib.h>
00013
00014 #ifdef _WINDOWS
00015 #include <winsock.h>
00016 #endif
00017
00018 #include "mytypes.h"
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 class CReb;
00032
00033 class RBPage
00034 {
00035 UInt32 filepos;
00036 UInt32 pageoffset;
00037 UInt32 nochunks, currentchunk, chunkpos, chunklen, chunkoffset;
00038 UInt32 m_pagelen, m_blocksize;
00039 bool m_Compressed;
00040 void readchunk();
00041 UInt32* chunklist;
00042 UInt8* chunk;
00043 FILE* fin;
00044 UInt32 m_pageno;
00045 void initpage(UInt32 pos, size_t _cp, bool _isCompressed, UInt32 _len);
00046 size_t (*m_decompress)(UInt8*, size_t, UInt8*, size_t);
00047 public:
00048 RBPage() : pageoffset(0), nochunks(0), currentchunk(0), chunkpos(0), chunkoffset(0), m_pagelen(0), m_Compressed(false), chunklist(NULL), chunk(NULL) {}
00049 ~RBPage()
00050 {
00051 if (chunk != NULL) delete [] chunk;
00052 if (chunklist != NULL) delete [] chunklist;
00053 }
00054 int getch(CReb*);
00055 unsigned short int getuint(CReb*);
00056 int getint(CReb*);
00057 void startpage(UInt32, UInt32, bool, UInt32);
00058 UInt32 pageno() { return m_pageno; }
00059 UInt32 offset() { return pageoffset+chunkoffset; }
00060 void setoffset(UInt32, size_t, bool, UInt32, UInt32);
00061 void init(FILE* _f, UInt32 _bs, size_t (*_decompress)(UInt8*, size_t, UInt8*, size_t))
00062 {
00063 fin = _f;
00064 m_blocksize = _bs;
00065 chunk = new UInt8[m_blocksize];
00066 m_decompress = _decompress;
00067 }
00068 UInt32 length() { return m_pagelen; }
00069 UInt32 m_startoff, m_endoff;
00070 };
00071
00072 struct Page_detail
00073 {
00074 UInt32 pagestart, len, flags;
00075 Page_detail(UInt32 _ps = 0, UInt32 _l = 0, UInt32 _f = 0)
00076 :
00077 pagestart(_ps), len(_l), flags(_f)
00078 {
00079 }
00080 };
00081
00082 struct ParaRef
00083 {
00084 int pos, tag;
00085 ParaRef(int _pos = 0, int _tag = 0) : pos(_pos), tag(_tag)
00086 {
00087
00088 }
00089 };
00090
00091 class CReb : public CExpander
00092 {
00093
00094 size_t (*m_decompress)(UInt8*, size_t, UInt8*, size_t);
00095 RBPage currentpage;
00096 UInt32 nopages, m_homepage, m_blocksize;
00097
00098 QMap<QString, UInt32> m_index;
00099
00100 size_t file_length, text_length;
00101 UInt32 toc;
00102 FILE* fin;
00103 void home();
00104 void startpage(UInt32);
00105 void startpage(UInt32, bool, UInt32);
00106 void readchunk();
00107 QString tagstring;
00108 UInt32 tagoffset;
00109 UInt32 pagelength(UInt32);
00110 QImage* getPicture(const QString& ref);
00111 UInt32 page2pos(UInt32);
00112
00113 UInt32* m_indexpages;
00114 Page_detail* m_pagedetails;
00115
00116 QMap<QString, int> names;
00117 QString* tags;
00118 ParaRef* paras;
00119 UInt32* joins;
00120 UInt32 nojoins;
00121 UInt32 noparas;
00122 bool m_binary;
00123 void readindex(UInt32);
00124 public:
00125 bool findanchor(const QString& _info);
00126 QString about() { return QString("REB codec (c) Tim Wentford"); }
00127 bool getFile(const QString& href, const QString& nm);
00128 void start2endSection();
00129 void sizes(unsigned long& _file, unsigned long& _text)
00130 {
00131 _file = file_length;
00132 _text = text_length;
00133 }
00134 bool hasrandomaccess() { return true; }
00135 virtual ~CReb();
00136 CReb();
00137 int OpenFile(const char *src);
00138 int getch();
00139 unsigned int locate();
00140 void locate(unsigned int n);
00141 CList<Bkmk>* getbkmklist();
00142 MarkupType PreferredMarkup()
00143 {
00144 return cCHM;
00145 }
00146 #ifdef USEQPE
00147 void suspend();
00148 void unsuspend();
00149 #else
00150 void suspend() {}
00151 void unsuspend() {}
00152 #endif
00153 };
00154
00155 #endif
00156
00157