-rw-r--r-- | noncore/apps/opie-reader/Reb.cpp | 65 |
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,62 +1,16 @@ | |||
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 | |||
16 | template<class T> | ||
17 | UInt32 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 | |||
35 | template<class T, class D> | ||
36 | UInt32 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 | ||
56 | CReb::CReb() | 10 | CReb::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 | ||
@@ -72,30 +26,16 @@ CReb::~CReb() | |||
72 | 26 | ||
73 | unsigned int CReb::locate() | 27 | unsigned 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 | ||
78 | void CReb::locate(unsigned int n) | 32 | void 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 |
@@ -107,18 +47,16 @@ void CReb::locate(unsigned int n) | |||
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 |
@@ -753,35 +691,32 @@ void RBPage::setoffset(UInt32 pos, size_t _cp, bool _isCompressed, UInt32 _len, | |||
753 | } | 691 | } |
754 | 692 | ||
755 | void CReb::start2endSection() | 693 | void 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 | } |