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 | |||
@@ -1,14 +1,60 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
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>; |
11 | size_t cur = ftell(fin); | 57 | size_t cur = ftell(fin); |
12 | for (int i = 0; i < nRecs2; i++) | 58 | for (int i = 0; i < nRecs2; i++) |
13 | { | 59 | { |
14 | DWORD dwPos; | 60 | DWORD dwPos; |
@@ -31,49 +77,76 @@ CList<Bkmk>* Aportis::getbkmklist() | |||
31 | tchar tname[17]; | 77 | tchar tname[17]; |
32 | memset(tname, 0, sizeof(tname)); | 78 | memset(tname, 0, sizeof(tname)); |
33 | for (int i = 0; name[i] != 0; i++) | 79 | for (int i = 0; name[i] != 0; i++) |
34 | { | 80 | { |
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)); |
40 | #endif | 86 | #endif |
41 | } | 87 | } |
42 | } | 88 | } |
43 | fseek(fin, cur, SEEK_SET); | 89 | fseek(fin, cur, SEEK_SET); |
44 | return t; | 90 | return t; |
45 | } | 91 | } |
46 | 92 | ||
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; |
52 | 97 | ||
53 | if (!Cpdb::openfile(src)) return -1; | 98 | if (!Cpdb::openfile(src)) return -1; |
54 | 99 | ||
55 | if (head.creator != 0x64414552 // 'dAER' | 100 | if (head.creator != 0x64414552 // 'dAER' |
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; |
63 | fread(&hdr0, sizeof(hdr0), 1, fin); | 141 | fread(&hdr0, sizeof(hdr0), 1, fin); |
64 | bCompressed = SwapWord(hdr0.wVersion); | 142 | bCompressed = SwapWord(hdr0.wVersion); |
65 | if (bCompressed!=1 && bCompressed!=2 && bCompressed != 4) { | 143 | if (bCompressed!=1 && bCompressed!=2 && bCompressed != 4) { |
66 | ret = bCompressed; | 144 | ret = bCompressed; |
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 | { |
76 | case 4: | 149 | case 4: |
77 | { | 150 | { |
78 | dwTLen = 0; | 151 | dwTLen = 0; |
79 | int i; | 152 | int i; |
@@ -87,55 +160,61 @@ int Aportis::openfile(const char *src) | |||
87 | BlockSize = 0; | 160 | BlockSize = 0; |
88 | } | 161 | } |
89 | break; | 162 | break; |
90 | case 1: | 163 | case 1: |
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); |
95 | if (BlockSize == 0) | 169 | if (BlockSize == 0) |
96 | { | 170 | { |
97 | BlockSize = 4096; | 171 | BlockSize = 4096; |
98 | printf("WARNING: Blocksize not set in source file\n"); | 172 | printf("WARNING: Blocksize not set in source file\n"); |
99 | } | 173 | } |
100 | } | 174 | } |
175 | } | ||
176 | |||
101 | 177 | ||
102 | 178 | ||
103 | // this is the main record buffer | 179 | // this is the main record buffer |
104 | // it knows how to stretch to accomodate the decompress | 180 | // it knows how to stretch to accomodate the decompress |
105 | currentrec = 0; | 181 | currentrec = 0; |
106 | cbptr = 0; | 182 | cbptr = 0; |
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 | } |
111 | 188 | ||
112 | int Aportis::getch() | 189 | int Aportis::getch() |
113 | { | 190 | { |
114 | if (bCompressed == 1) | 191 | if (bCompressed == 1) |
115 | { | 192 | { |
116 | if ((dwRecLen == 0) && !refreshbuffer()) return EOF; | 193 | if ((dwRecLen == 0) && !refreshbuffer()) return EOF; |
117 | else | 194 | else |
118 | { | 195 | { |
119 | int c = getc(fin); | 196 | int c = getc(fin); |
197 | dePeanut(c); | ||
120 | dwRecLen--; | 198 | dwRecLen--; |
121 | currentpos++; | 199 | currentpos++; |
122 | return c; | 200 | return c; |
123 | } | 201 | } |
124 | } | 202 | } |
125 | if (outptr != cbptr) | 203 | if (outptr != cbptr) |
126 | { | 204 | { |
127 | currentpos++; | 205 | currentpos++; |
128 | return (circbuf[outptr = (outptr + 1) % 2048]); | 206 | return (circbuf[outptr = (outptr + 1) % 2048]); |
129 | } | 207 | } |
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 |
138 | 217 | ||
139 | // codes 1...8 mean copy that many chars; for accented chars & binary | 218 | // codes 1...8 mean copy that many chars; for accented chars & binary |
140 | if (c == 0) | 219 | if (c == 0) |
141 | { | 220 | { |
@@ -149,21 +228,25 @@ int Aportis::getch() | |||
149 | } | 228 | } |
150 | else if (c >= 0x01 && c <= 0x08) | 229 | else if (c >= 0x01 && c <= 0x08) |
151 | { | 230 | { |
152 | dwRecLen -= c; | 231 | dwRecLen -= c; |
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]; |
158 | } | 239 | } |
159 | else if (c >= 0x80 && c <= 0xBF) | 240 | else if (c >= 0x80 && c <= 0xBF) |
160 | { | 241 | { |
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; |
166 | n = c & ((1<<COUNT_BITS) - 1); | 249 | n = c & ((1<<COUNT_BITS) - 1); |
167 | n += 3; | 250 | n += 3; |
168 | while (n--) | 251 | while (n--) |
169 | { | 252 | { |