summaryrefslogtreecommitdiff
Unidiff
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,140 +1,78 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <string.h> 2#include <string.h>
3#include <qimage.h> 3#include <qimage.h>
4#include "decompress.h" 4#include "decompress.h"
5#include "Reb.h" 5#include "Reb.h"
6#include "my_list.h" 6#include "my_list.h"
7#include "Bkmks.h" 7#include "Bkmks.h"
8#include "Model.h" 8#include "Model.h"
9/*
10#ifdef offsetof
11#define OffsetOf(type, field) ((int) offsetof(type, field))
12#else
13#define OffsetOf(type, field) ((int) ((char *) &((type *) 0)->field))
14#endif
15
16template<class T>
17UInt32 binarychop(T* data, UInt32 n, T val)
18{
19 UInt32 jl = 0,jh = n-1,jm = (jl+jh)/2;
20 while (jh > jl+1)
21 {
22 if (data[jm] > val)
23 {
24 jh = jm;
25 }
26 else
27 {
28 jl = jm;
29 }
30 jm = (jl+jh)/2;
31 }
32 return jl;
33}
34
35template<class T, class D>
36UInt32 binarychop(D* data, UInt32 n, T val, UInt32 offset)
37{
38 UInt32 jl = 0,jh = n-1,jm = (jl+jh)/2;
39 while (jh > jl+1)
40 {
41 T* d = reinterpret_cast<T*>(reinterpret_cast<char*>(data+jm)+offset);
42 if (*d > val)
43 {
44 jh = jm;
45 }
46 else
47 {
48 jl = jm;
49 }
50 jm = (jl+jh)/2;
51 }
52 return jl;
53}
54*/
55 9
56CReb::CReb() 10CReb::CReb()
57: 11:
58 fin(NULL), m_indexpages(NULL), m_pagedetails(NULL),tagoffset(0), 12 fin(NULL), m_indexpages(NULL), m_pagedetails(NULL),tagoffset(0),
59 tags(NULL), paras(NULL), noparas(0), joins(NULL), nojoins(0) 13 tags(NULL), paras(NULL), noparas(0), joins(NULL), nojoins(0)
60{ 14{
61} 15}
62 16
63CReb::~CReb() 17CReb::~CReb()
64{ 18{
65 if (fin != NULL) fclose(fin); 19 if (fin != NULL) fclose(fin);
66 if (m_indexpages != NULL) delete [] m_indexpages; 20 if (m_indexpages != NULL) delete [] m_indexpages;
67 if (m_pagedetails != NULL) delete [] m_pagedetails; 21 if (m_pagedetails != NULL) delete [] m_pagedetails;
68 if (tags != NULL) delete [] tags; 22 if (tags != NULL) delete [] tags;
69 if (paras != NULL) delete [] paras; 23 if (paras != NULL) delete [] paras;
70 if (joins != NULL) delete [] joins; 24 if (joins != NULL) delete [] joins;
71} 25}
72 26
73unsigned int CReb::locate() 27unsigned int CReb::locate()
74{ 28{
75 return m_pagedetails[currentpage.pageno()].pagestart+currentpage.offset(); 29 return m_pagedetails[currentpage.pageno()].pagestart+currentpage.offset();
76} 30}
77 31
78void CReb::locate(unsigned int n) 32void CReb::locate(unsigned int n)
79{ 33{
80 /*
81 UInt32 cp = nopages-1;
82 for (int i = 0; i < nopages; ++i)
83 {
84 if (m_pagedetails[i].pagestart > n)
85 {
86 cp = i-1;
87 break;
88 }
89 }
90 qDebug("Requesting %u from page %u [%u]", n, cp, n - m_pagedetails[cp].pagestart);
91 */
92 //UInt32 jl = binarychop<UInt32, Page_detail>(m_pagedetails, nopages, n, OffsetOf(Page_detail, pagestart));
93
94 UInt32 jl = 0,jh = nopages-1,jm = (jl+jh)/2; 34 UInt32 jl = 0,jh = nopages-1,jm = (jl+jh)/2;
95 while (jh > jl+1) 35 while (jh > jl+1)
96 { 36 {
97 if (m_pagedetails[jm].pagestart > n) 37 if (m_pagedetails[jm].pagestart > n)
98 { 38 {
99 jh = jm; 39 jh = jm;
100 } 40 }
101 else 41 else
102 { 42 {
103 jl = jm; 43 jl = jm;
104 } 44 }
105 jm = (jl+jh)/2; 45 jm = (jl+jh)/2;
106 } 46 }
107 47
108 unsuspend(); 48 unsuspend();
109 Page_detail rs = m_pagedetails[jl]; 49 Page_detail rs = m_pagedetails[jl];
110 UInt32 val = n - rs.pagestart; 50 UInt32 val = n - rs.pagestart;
111 if (jl != currentpage.pageno()) readindex(jl); 51 if (jl != currentpage.pageno()) readindex(jl);
112 currentpage.setoffset(page2pos(jl), jl, ((rs.flags & 8) != 0), rs.len, val); 52 currentpage.setoffset(page2pos(jl), jl, ((rs.flags & 8) != 0), rs.len, val);
113 if (noparas > 0) 53 if (noparas > 0)
114 { 54 {
115 //jl = binarychop<int, ParaRef>(paras, noparas, val, OffsetOf(ParaRef, pos));
116
117 UInt32 jl = 0,jh = noparas-1,jm = (jl+jh)/2; 55 UInt32 jl = 0,jh = noparas-1,jm = (jl+jh)/2;
118 while (jh > jl+1) 56 while (jh > jl+1)
119 { 57 {
120 if (paras[jm].pos > val) 58 if (paras[jm].pos > val)
121 { 59 {
122 jh = jm; 60 jh = jm;
123 } 61 }
124 else 62 else
125 { 63 {
126 jl = jm; 64 jl = jm;
127 } 65 }
128 jm = (jl+jh)/2; 66 jm = (jl+jh)/2;
129 } 67 }
130 68
131 qDebug("TAGS:%s", (const char*)tags[paras[jl].tag]); 69 qDebug("TAGS:%s", (const char*)tags[paras[jl].tag]);
132 tagstring = tags[paras[jl].tag]+"<br>"; // Add br to set extra space to 0 70 tagstring = tags[paras[jl].tag]+"<br>"; // Add br to set extra space to 0
133 tagoffset = 0; 71 tagoffset = 0;
134 } 72 }
135 unsigned long current = locate(); 73 unsigned long current = locate();
136 if (m_currentstart > current || current > m_currentend) 74 if (m_currentstart > current || current > m_currentend)
137 { 75 {
138 start2endSection(); 76 start2endSection();
139 } 77 }
140 if (current != n) qDebug("ERROR:Ended up at %u", current); 78 if (current != n) qDebug("ERROR:Ended up at %u", current);
@@ -737,53 +675,50 @@ void RBPage::setoffset(UInt32 pos, size_t _cp, bool _isCompressed, UInt32 _len,
737 675
738 currentchunk = _offset/m_blocksize; 676 currentchunk = _offset/m_blocksize;
739 pageoffset = m_blocksize*currentchunk; 677 pageoffset = m_blocksize*currentchunk;
740 if (m_Compressed) 678 if (m_Compressed)
741 { 679 {
742 for (int i = 0; i < currentchunk; ++i) 680 for (int i = 0; i < currentchunk; ++i)
743 { 681 {
744 chunkpos += chunklist[i]; 682 chunkpos += chunklist[i];
745 } 683 }
746 } 684 }
747 else 685 else
748 { 686 {
749 chunkpos += pageoffset; 687 chunkpos += pageoffset;
750 } 688 }
751 readchunk(); 689 readchunk();
752 chunkoffset = _offset - pageoffset; 690 chunkoffset = _offset - pageoffset;
753} 691}
754 692
755void CReb::start2endSection() 693void CReb::start2endSection()
756{ 694{
757 if (m_pagedetails != NULL) 695 if (m_pagedetails != NULL)
758 { 696 {
759 if (nojoins > 0) 697 if (nojoins > 0)
760 { 698 {
761 //UInt32 jl = binarychop<UInt32>(joins, nojoins, currentpage.offset());
762
763 UInt32 jl = 0,jh = nojoins-1,jm = (jl+jh)/2; 699 UInt32 jl = 0,jh = nojoins-1,jm = (jl+jh)/2;
764 while (jh > jl+1) 700 while (jh > jl+1)
765 { 701 {
766 if (joins[jm] > currentpage.offset()) 702 if (joins[jm] > currentpage.offset())
767 { 703 {
768 jh = jm; 704 jh = jm;
769 } 705 }
770 else 706 else
771 { 707 {
772 jl = jm; 708 jl = jm;
773 } 709 }
774 jm = (jl+jh)/2; 710 jm = (jl+jh)/2;
775 } 711 }
776 712
777 currentpage.m_startoff = joins[jl]; 713 currentpage.m_startoff = joins[jl];
778 currentpage.m_endoff = joins[jl+1]-1; 714 currentpage.m_endoff = joins[jl+1]-1;
779 //currentpage.m_endoff = joins[jh]-1;
780 } 715 }
781 m_currentstart = m_pagedetails[currentpage.pageno()].pagestart+currentpage.m_startoff; 716 m_currentstart = m_pagedetails[currentpage.pageno()].pagestart+currentpage.m_startoff;
782 m_currentend = m_pagedetails[currentpage.pageno()].pagestart+currentpage.m_endoff; 717 m_currentend = m_pagedetails[currentpage.pageno()].pagestart+currentpage.m_endoff;
783 } 718 }
784 else 719 else
785 { 720 {
786 m_currentstart = m_currentend = 0; 721 m_currentstart = m_currentend = 0;
787 } 722 }
788 qDebug("s2e:[%u, %u, %u]", m_currentstart, locate(), m_currentend); 723 qDebug("s2e:[%u, %u, %u]", m_currentstart, locate(), m_currentend);
789} 724}