Diffstat (limited to 'noncore/apps/opie-reader/Aportis.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/Aportis.cpp | 105 |
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 | |||
@@ -2,9 +2,55 @@ | |||
2 | #include <string.h> | 2 | #include <string.h> |
3 | #include "Aportis.h" | 3 | #include "Aportis.h" |
4 | #include "my_list.h" | ||
5 | #include "Bkmks.h" | ||
4 | 6 | ||
5 | Aportis::Aportis() { /*printf("constructing:%x\n",fin);*/ } | 7 | Aportis::Aportis() : peanutfile(false) { /*printf("constructing:%x\n",fin);*/ } |
8 | |||
9 | void 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 | ||
7 | CList<Bkmk>* Aportis::getbkmklist() | 19 | 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; |
10 | CList<Bkmk>* t = new CList<Bkmk>; | 56 | CList<Bkmk>* t = new CList<Bkmk>; |
@@ -35,5 +81,5 @@ CList<Bkmk>* Aportis::getbkmklist() | |||
35 | tname[i] = name[i]; | 81 | tname[i] = name[i]; |
36 | } | 82 | } |
37 | t->push_back(Bkmk(tname,lcn)); | 83 | t->push_back(Bkmk(tname, NULL, lcn)); |
38 | #else | 84 | #else |
39 | t->push_back(Bkmk(name,lcn)); | 85 | t->push_back(Bkmk(name,lcn)); |
@@ -47,5 +93,4 @@ CList<Bkmk>* Aportis::getbkmklist() | |||
47 | int Aportis::openfile(const char *src) | 93 | int Aportis::openfile(const char *src) |
48 | { | 94 | { |
49 | |||
50 | // printf("In openfile\n"); | 95 | // printf("In openfile\n"); |
51 | int ret = 0; | 96 | int ret = 0; |
@@ -56,7 +101,40 @@ int Aportis::openfile(const char *src) | |||
56 | || head.type != 0x74584554) // 'tXET') | 101 | || head.type != 0x74584554) // 'tXET') |
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); |
62 | tDocRecord0 hdr0; | 140 | tDocRecord0 hdr0; |
@@ -67,9 +145,4 @@ int Aportis::openfile(const char *src) | |||
67 | bCompressed = 2; | 145 | bCompressed = 2; |
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) |
75 | { | 148 | { |
@@ -91,4 +164,5 @@ int Aportis::openfile(const char *src) | |||
91 | case 2: | 164 | case 2: |
92 | default: | 165 | default: |
166 | nRecs = SwapWord(hdr0.wNumRecs); | ||
93 | dwTLen = SwapLong(hdr0.dwStoryLen); | 167 | dwTLen = SwapLong(hdr0.dwStoryLen); |
94 | BlockSize = SwapWord(hdr0.wRecSize); | 168 | BlockSize = SwapWord(hdr0.wRecSize); |
@@ -99,4 +173,6 @@ int Aportis::openfile(const char *src) | |||
99 | } | 173 | } |
100 | } | 174 | } |
175 | } | ||
176 | |||
101 | 177 | ||
102 | 178 | ||
@@ -107,4 +183,5 @@ int Aportis::openfile(const char *src) | |||
107 | outptr = 0; | 183 | outptr = 0; |
108 | refreshbuffer(); | 184 | refreshbuffer(); |
185 | qDebug("Number of records:[%u,%u]", nRecs, nRecs2); | ||
109 | return ret; | 186 | return ret; |
110 | } | 187 | } |
@@ -118,4 +195,5 @@ int Aportis::getch() | |||
118 | { | 195 | { |
119 | int c = getc(fin); | 196 | int c = getc(fin); |
197 | dePeanut(c); | ||
120 | dwRecLen--; | 198 | dwRecLen--; |
121 | currentpos++; | 199 | currentpos++; |
@@ -130,8 +208,9 @@ int Aportis::getch() | |||
130 | if ((dwRecLen == 0) && !refreshbuffer()) return EOF; | 208 | if ((dwRecLen == 0) && !refreshbuffer()) return EOF; |
131 | currentpos++; | 209 | currentpos++; |
132 | unsigned int c; | 210 | int c; |
133 | 211 | ||
134 | // take a char from the input buffer | 212 | // take a char from the input buffer |
135 | c = getc(fin); | 213 | c = getc(fin); |
214 | dePeanut(c); | ||
136 | dwRecLen--; | 215 | dwRecLen--; |
137 | // separate the char into zones: 0, 1...8, 9...0x7F, 0x80...0xBF, 0xC0...0xFF | 216 | // separate the char into zones: 0, 1...8, 9...0x7F, 0x80...0xBF, 0xC0...0xFF |
@@ -153,5 +232,7 @@ int Aportis::getch() | |||
153 | while(c--) | 232 | while(c--) |
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 | } |
157 | return circbuf[outptr = (outptr+1)%2048]; | 238 | return circbuf[outptr = (outptr+1)%2048]; |
@@ -161,5 +242,7 @@ int Aportis::getch() | |||
161 | int m,n; | 242 | int m,n; |
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--; |
165 | m = (c & 0x3FFF) >> COUNT_BITS; | 248 | m = (c & 0x3FFF) >> COUNT_BITS; |