summaryrefslogtreecommitdiff
authorerik <erik>2007-01-24 23:31:45 (UTC)
committer erik <erik>2007-01-24 23:31:45 (UTC)
commit644780047090442429342addb3fa97ec95bdc670 (patch) (side-by-side diff)
tree64032e4e81653501977b95bebdc8ebd69288d6c6
parent0076a11b467dce1233194ce228287a2a127b1f5d (diff)
downloadopie-644780047090442429342addb3fa97ec95bdc670.zip
opie-644780047090442429342addb3fa97ec95bdc670.tar.gz
opie-644780047090442429342addb3fa97ec95bdc670.tar.bz2
There was quite a bit of deadwood in this file. I am removing it to make
the file more readable (and smaller overall).
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/Reb.cpp65
1 files changed, 0 insertions, 65 deletions
diff --git a/noncore/apps/opie-reader/Reb.cpp b/noncore/apps/opie-reader/Reb.cpp
index 2e6c1fc..65de9f6 100644
--- a/noncore/apps/opie-reader/Reb.cpp
+++ b/noncore/apps/opie-reader/Reb.cpp
@@ -1,164 +1,102 @@
#include <stdio.h>
#include <string.h>
#include <qimage.h>
#include "decompress.h"
#include "Reb.h"
#include "my_list.h"
#include "Bkmks.h"
#include "Model.h"
-/*
-#ifdef offsetof
-#define OffsetOf(type, field) ((int) offsetof(type, field))
-#else
-#define OffsetOf(type, field) ((int) ((char *) &((type *) 0)->field))
-#endif
-
-template<class T>
-UInt32 binarychop(T* data, UInt32 n, T val)
-{
- UInt32 jl = 0,jh = n-1,jm = (jl+jh)/2;
- while (jh > jl+1)
- {
- if (data[jm] > val)
- {
- jh = jm;
- }
- else
- {
- jl = jm;
- }
- jm = (jl+jh)/2;
- }
- return jl;
-}
-
-template<class T, class D>
-UInt32 binarychop(D* data, UInt32 n, T val, UInt32 offset)
-{
- UInt32 jl = 0,jh = n-1,jm = (jl+jh)/2;
- while (jh > jl+1)
- {
- T* d = reinterpret_cast<T*>(reinterpret_cast<char*>(data+jm)+offset);
- if (*d > val)
- {
- jh = jm;
- }
- else
- {
- jl = jm;
- }
- jm = (jl+jh)/2;
- }
- return jl;
-}
-*/
CReb::CReb()
:
fin(NULL), m_indexpages(NULL), m_pagedetails(NULL),tagoffset(0),
tags(NULL), paras(NULL), noparas(0), joins(NULL), nojoins(0)
{
}
CReb::~CReb()
{
if (fin != NULL) fclose(fin);
if (m_indexpages != NULL) delete [] m_indexpages;
if (m_pagedetails != NULL) delete [] m_pagedetails;
if (tags != NULL) delete [] tags;
if (paras != NULL) delete [] paras;
if (joins != NULL) delete [] joins;
}
unsigned int CReb::locate()
{
return m_pagedetails[currentpage.pageno()].pagestart+currentpage.offset();
}
void CReb::locate(unsigned int n)
{
- /*
- UInt32 cp = nopages-1;
- for (int i = 0; i < nopages; ++i)
- {
- if (m_pagedetails[i].pagestart > n)
- {
- cp = i-1;
- break;
- }
- }
- qDebug("Requesting %u from page %u [%u]", n, cp, n - m_pagedetails[cp].pagestart);
- */
- //UInt32 jl = binarychop<UInt32, Page_detail>(m_pagedetails, nopages, n, OffsetOf(Page_detail, pagestart));
-
UInt32 jl = 0,jh = nopages-1,jm = (jl+jh)/2;
while (jh > jl+1)
{
if (m_pagedetails[jm].pagestart > n)
{
jh = jm;
}
else
{
jl = jm;
}
jm = (jl+jh)/2;
}
unsuspend();
Page_detail rs = m_pagedetails[jl];
UInt32 val = n - rs.pagestart;
if (jl != currentpage.pageno()) readindex(jl);
currentpage.setoffset(page2pos(jl), jl, ((rs.flags & 8) != 0), rs.len, val);
if (noparas > 0)
{
- //jl = binarychop<int, ParaRef>(paras, noparas, val, OffsetOf(ParaRef, pos));
-
UInt32 jl = 0,jh = noparas-1,jm = (jl+jh)/2;
while (jh > jl+1)
{
if (paras[jm].pos > val)
{
jh = jm;
}
else
{
jl = jm;
}
jm = (jl+jh)/2;
}
qDebug("TAGS:%s", (const char*)tags[paras[jl].tag]);
tagstring = tags[paras[jl].tag]+"<br>"; // Add br to set extra space to 0
tagoffset = 0;
}
unsigned long current = locate();
if (m_currentstart > current || current > m_currentend)
{
start2endSection();
}
if (current != n) qDebug("ERROR:Ended up at %u", current);
}
bool CReb::getFile(const QString& href, const QString& nm)
{
qDebug("File:%s, Name:%s", (const char*)href, (const char*)nm);
QMap<QString, UInt32>::Iterator iter = m_index.find(href);
if (iter != m_index.end())
{
qDebug("REB:BEFORE:%u", locate());
startpage(iter.data());
qDebug("REB:AFTER:%u", locate());
return true;
}
else
{
return false;
}
}
QImage* CReb::getPicture(const QString& ref)
{
QMap<QString, UInt32>::Iterator iter = m_index.find(ref);
if (iter != m_index.end())
{
@@ -713,77 +651,74 @@ void RBPage::readchunk()
}
fseek(fin, chunkpos, SEEK_SET);
chunklen = fread(chunk, 1, chunklen, fin);
chunkpos = ftell(fin);
}
}
void RBPage::setoffset(UInt32 pos, size_t _cp, bool _isCompressed, UInt32 _len, UInt32 _offset)
{
if (m_pageno != _cp)
{
initpage(pos, _cp, _isCompressed, _len);
}
else
{
if (m_Compressed)
{
chunkpos = filepos + sizeof(nochunks) + sizeof(m_pagelen) + 4*nochunks;
}
else
{
chunkpos = filepos;
}
}
currentchunk = _offset/m_blocksize;
pageoffset = m_blocksize*currentchunk;
if (m_Compressed)
{
for (int i = 0; i < currentchunk; ++i)
{
chunkpos += chunklist[i];
}
}
else
{
chunkpos += pageoffset;
}
readchunk();
chunkoffset = _offset - pageoffset;
}
void CReb::start2endSection()
{
if (m_pagedetails != NULL)
{
if (nojoins > 0)
{
- //UInt32 jl = binarychop<UInt32>(joins, nojoins, currentpage.offset());
-
UInt32 jl = 0,jh = nojoins-1,jm = (jl+jh)/2;
while (jh > jl+1)
{
if (joins[jm] > currentpage.offset())
{
jh = jm;
}
else
{
jl = jm;
}
jm = (jl+jh)/2;
}
currentpage.m_startoff = joins[jl];
currentpage.m_endoff = joins[jl+1]-1;
- //currentpage.m_endoff = joins[jh]-1;
}
m_currentstart = m_pagedetails[currentpage.pageno()].pagestart+currentpage.m_startoff;
m_currentend = m_pagedetails[currentpage.pageno()].pagestart+currentpage.m_endoff;
}
else
{
m_currentstart = m_currentend = 0;
}
qDebug("s2e:[%u, %u, %u]", m_currentstart, locate(), m_currentend);
}