summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/Aportis.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/Aportis.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-reader/Aportis.cpp105
1 files changed, 94 insertions, 11 deletions
diff --git a/noncore/apps/opie-reader/Aportis.cpp b/noncore/apps/opie-reader/Aportis.cpp
index 595b385..1327ff8 100644
--- a/noncore/apps/opie-reader/Aportis.cpp
+++ b/noncore/apps/opie-reader/Aportis.cpp
@@ -3,4 +3,16 @@
3#include "Aportis.h" 3#include "Aportis.h"
4#include "my_list.h"
5#include "Bkmks.h"
4 6
5Aportis::Aportis() { /*printf("constructing:%x\n",fin);*/ } 7Aportis::Aportis() : peanutfile(false) { /*printf("constructing:%x\n",fin);*/ }
8
9void Aportis::dePeanut(int& ch)
10{
11 if (peanutfile && ch != EOF)
12 {
13 unsigned char c = ch;
14 if (peanutfile) c ^= 0xa5;
15 ch = c;
16 }
17}
6 18
@@ -8,2 +20,36 @@ CList<Bkmk>* Aportis::getbkmklist()
8{ 20{
21/*
22 if (peanutfile)
23 {
24 if (nRecs2 > nRecs)
25 {
26 CList<Bkmk>* t = new CList<Bkmk>;
27 for (int i = nRecs; i < nRecs2; i++)
28 {
29 char name[17];
30 name[16] = '\0';
31 qDebug("Record:%d, Length:%u",i,recordlength(i));
32 gotorecordnumber(i);
33 fread(name,1,16,fin);
34 unsigned long lcn;
35 fread(&lcn,sizeof(lcn),1,fin);
36 lcn ^= 0xa5a5a5a5;
37 lcn = SwapLong(lcn);
38 qDebug("Bookmark:%s:%u", name,lcn);
39 tchar tname[17];
40 memset(tname, 0, sizeof(tname));
41 for (int i = 0; name[i] != 0; i++)
42 {
43 tname[i] = name[i] ^ 0xa5;
44 }
45 t->push_back(Bkmk(tname, NULL, lcn));
46 }
47 return t;
48 }
49 else
50 {
51 return NULL;
52 }
53 }
54*/
9 if (bCompressed != 4) return NULL; 55 if (bCompressed != 4) return NULL;
@@ -36,3 +82,3 @@ CList<Bkmk>* Aportis::getbkmklist()
36 } 82 }
37 t->push_back(Bkmk(tname,lcn)); 83 t->push_back(Bkmk(tname, NULL, lcn));
38#else 84#else
@@ -48,3 +94,2 @@ int Aportis::openfile(const char *src)
48{ 94{
49
50 // printf("In openfile\n"); 95 // printf("In openfile\n");
@@ -57,5 +102,38 @@ int Aportis::openfile(const char *src)
57 { 102 {
103
104 if (memcmp(&head.creator, "PPrs", 4) == 0 && memcmp(&head.type, "PNRd", 4) == 0)
105 {
106 peanutfile = true;
107 }
108 else
109 {
58 return -2; 110 return -2;
59 } 111 }
112 }
113
114 nRecs2 = nRecs = SwapWord(head.recordList.numRecords) - 1;
115 fseek(fin,0,SEEK_END);
116 dwLen = ftell(fin);
117
118 if (peanutfile)
119 {
60 120
121 PeanutHeader hdr0;
122 gotorecordnumber(0);
123 fread(&hdr0, sizeof(hdr0), 1, fin);
124 qDebug("Version:%x", ntohs(hdr0.Version));
125 if (hdr0.Version && 0x0200)
126 {
127 bCompressed = 2;
128 }
129 else
130 {
131 bCompressed = 1;
132 }
133 BlockSize = 4096;
134 nRecs = SwapWord(hdr0.Records)-1;
135 dwTLen = nRecs*BlockSize;
136 }
137 else
138 {
61 gotorecordnumber(0); 139 gotorecordnumber(0);
@@ -68,7 +146,2 @@ int Aportis::openfile(const char *src)
68 } 146 }
69
70 fseek(fin,0,SEEK_END);
71 dwLen = ftell(fin);
72 nRecs2 = nRecs = SwapWord(head.recordList.numRecords) - 1;
73
74 switch (bCompressed) 147 switch (bCompressed)
@@ -92,2 +165,3 @@ int Aportis::openfile(const char *src)
92 default: 165 default:
166 nRecs = SwapWord(hdr0.wNumRecs);
93 dwTLen = SwapLong(hdr0.dwStoryLen); 167 dwTLen = SwapLong(hdr0.dwStoryLen);
@@ -100,2 +174,4 @@ int Aportis::openfile(const char *src)
100 } 174 }
175 }
176
101 177
@@ -108,2 +184,3 @@ int Aportis::openfile(const char *src)
108 refreshbuffer(); 184 refreshbuffer();
185 qDebug("Number of records:[%u,%u]", nRecs, nRecs2);
109 return ret; 186 return ret;
@@ -119,2 +196,3 @@ int Aportis::getch()
119 int c = getc(fin); 196 int c = getc(fin);
197 dePeanut(c);
120 dwRecLen--; 198 dwRecLen--;
@@ -131,3 +209,3 @@ int Aportis::getch()
131 currentpos++; 209 currentpos++;
132 unsigned int c; 210 int c;
133 211
@@ -135,2 +213,3 @@ int Aportis::getch()
135 c = getc(fin); 213 c = getc(fin);
214 dePeanut(c);
136 dwRecLen--; 215 dwRecLen--;
@@ -154,3 +233,5 @@ int Aportis::getch()
154 { 233 {
155 circbuf[cbptr = (cbptr+1)%2048] = getc(fin); 234 int c = getc(fin);
235 dePeanut(c);
236 circbuf[cbptr = (cbptr+1)%2048] = c;
156 } 237 }
@@ -162,3 +243,5 @@ int Aportis::getch()
162 c <<= 8; 243 c <<= 8;
163 c += getc(fin); 244 int c1 = getc(fin);
245 dePeanut(c1);
246 c += c1;
164 dwRecLen--; 247 dwRecLen--;