-rw-r--r-- | noncore/apps/opie-reader/plucker_base.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/noncore/apps/opie-reader/plucker_base.cpp b/noncore/apps/opie-reader/plucker_base.cpp index 51c7fa7..81614f5 100644 --- a/noncore/apps/opie-reader/plucker_base.cpp +++ b/noncore/apps/opie-reader/plucker_base.cpp | |||
@@ -35,530 +35,531 @@ CPlucker_base::CPlucker_base() : | |||
35 | compressedtextbuffer(NULL), | 35 | compressedtextbuffer(NULL), |
36 | bufferrec(-1), | 36 | bufferrec(-1), |
37 | m_offset(0) | 37 | m_offset(0) |
38 | //, urls(NULL) | 38 | //, urls(NULL) |
39 | { /*printf("constructing:%x\n",fin);*/ } | 39 | { /*printf("constructing:%x\n",fin);*/ } |
40 | 40 | ||
41 | 41 | ||
42 | void CPlucker_base::Expand(UInt32 reclen, UInt8 type, UInt8* buffer, UInt32 buffersize) | 42 | void CPlucker_base::Expand(UInt32 reclen, UInt8 type, UInt8* buffer, UInt32 buffersize) |
43 | { | 43 | { |
44 | unsuspend(); | 44 | unsuspend(); |
45 | if ((type%2 == 0) && (type != 14)) | 45 | if ((type%2 == 0) && (type != 14)) |
46 | { | 46 | { |
47 | fread(buffer, reclen, sizeof(char), fin); | 47 | fread(buffer, reclen, sizeof(char), fin); |
48 | } | 48 | } |
49 | else | 49 | else |
50 | { | 50 | { |
51 | UInt8* readbuffer = NULL; | 51 | UInt8* readbuffer = NULL; |
52 | if (reclen > compressedbuffersize) | 52 | if (reclen > compressedbuffersize) |
53 | { | 53 | { |
54 | readbuffer = new UInt8[reclen]; | 54 | readbuffer = new UInt8[reclen]; |
55 | } | 55 | } |
56 | else | 56 | else |
57 | { | 57 | { |
58 | readbuffer = compressedtextbuffer; | 58 | readbuffer = compressedtextbuffer; |
59 | } | 59 | } |
60 | if (readbuffer != NULL) | 60 | if (readbuffer != NULL) |
61 | { | 61 | { |
62 | fread(readbuffer, reclen, sizeof(char), fin); | 62 | fread(readbuffer, reclen, sizeof(char), fin); |
63 | (*m_decompress)(readbuffer, reclen, buffer, buffersize); | 63 | (*m_decompress)(readbuffer, reclen, buffer, buffersize); |
64 | if (reclen > compressedbuffersize) | 64 | if (reclen > compressedbuffersize) |
65 | { | 65 | { |
66 | delete [] readbuffer; | 66 | delete [] readbuffer; |
67 | } | 67 | } |
68 | } | 68 | } |
69 | } | 69 | } |
70 | } | 70 | } |
71 | 71 | ||
72 | void CPlucker_base::sizes(unsigned long& _file, unsigned long& _text) | 72 | void CPlucker_base::sizes(unsigned long& _file, unsigned long& _text) |
73 | { | 73 | { |
74 | _file = file_length; | 74 | _file = file_length; |
75 | if (textlength == 0) | 75 | if (textlength == 0) |
76 | { | 76 | { |
77 | for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) | 77 | for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) |
78 | { | 78 | { |
79 | gotorecordnumber(recptr); | 79 | gotorecordnumber(recptr); |
80 | UInt16 thishdr_uid, thishdr_nParagraphs; | 80 | UInt16 thishdr_uid, thishdr_nParagraphs; |
81 | UInt32 thishdr_size; | 81 | UInt32 thishdr_size; |
82 | UInt8 thishdr_type, thishdr_reserved; | 82 | UInt8 thishdr_type, thishdr_reserved; |
83 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 83 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
84 | if (thishdr_type < 2) textlength += thishdr_size; | 84 | if (thishdr_type < 2) textlength += thishdr_size; |
85 | } | 85 | } |
86 | } | 86 | } |
87 | _text = textlength; | 87 | _text = textlength; |
88 | //ntohl(hdr0.size); | 88 | //ntohl(hdr0.size); |
89 | } | 89 | } |
90 | 90 | ||
91 | char* CPlucker_base::geturl(UInt16 tgt) | 91 | char* CPlucker_base::geturl(UInt16 tgt) |
92 | { | 92 | { |
93 | char * pRet = NULL; | 93 | char * pRet = NULL; |
94 | gotorecordnumber(0); | 94 | gotorecordnumber(0); |
95 | fread(&hdr0, 1, 6, fin); | 95 | fread(&hdr0, 1, 6, fin); |
96 | unsigned int nrecs = ntohs(hdr0.nRecords); | 96 | unsigned int nrecs = ntohs(hdr0.nRecords); |
97 | //qDebug("Version %u, no. recs %u", ntohs(hdr0.version), nrecs); | 97 | //qDebug("Version %u, no. recs %u", ntohs(hdr0.version), nrecs); |
98 | UInt16 urlid = 0; | 98 | UInt16 urlid = 0; |
99 | bool urlsfound = false; | 99 | bool urlsfound = false; |
100 | char* urls = NULL; | 100 | char* urls = NULL; |
101 | size_t urlsize = 0; | 101 | size_t urlsize = 0; |
102 | for (unsigned int i = 0; i < nrecs; i++) | 102 | for (unsigned int i = 0; i < nrecs; i++) |
103 | { | 103 | { |
104 | UInt16 id, name; | 104 | UInt16 id, name; |
105 | fread(&name, 1, sizeof(name), fin); | 105 | fread(&name, 1, sizeof(name), fin); |
106 | fread(&id, 1, sizeof(id), fin); | 106 | fread(&id, 1, sizeof(id), fin); |
107 | //qDebug("N:%d, I:%d", ntohs(name), ntohs(id)); | 107 | //qDebug("N:%d, I:%d", ntohs(name), ntohs(id)); |
108 | if (ntohs(name) == 2) | 108 | if (ntohs(name) == 2) |
109 | { | 109 | { |
110 | urlsfound = true; | 110 | urlsfound = true; |
111 | urlid = id; | 111 | urlid = id; |
112 | //qDebug("Found url index:%d", ntohs(urlid)); | 112 | //qDebug("Found url index:%d", ntohs(urlid)); |
113 | } | 113 | } |
114 | ////qDebug("%x", id); | 114 | ////qDebug("%x", id); |
115 | } | 115 | } |
116 | if (urlsfound) | 116 | if (urlsfound) |
117 | { | 117 | { |
118 | unsigned short recptr = finduid(ntohs(urlid)); | 118 | unsigned short recptr = finduid(ntohs(urlid)); |
119 | if (recptr != 0) | 119 | if (recptr != 0) |
120 | { | 120 | { |
121 | gotorecordnumber(recptr); | 121 | gotorecordnumber(recptr); |
122 | UInt16 thishdr_uid, thishdr_nParagraphs; | 122 | UInt16 thishdr_uid, thishdr_nParagraphs; |
123 | UInt32 thishdr_size; | 123 | UInt32 thishdr_size; |
124 | UInt8 thishdr_type, thishdr_reserved; | 124 | UInt8 thishdr_type, thishdr_reserved; |
125 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 125 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
126 | UInt16 urlctr = 0; | 126 | UInt16 urlctr = 0; |
127 | while (1) | 127 | while (1) |
128 | { | 128 | { |
129 | UInt16 tctr; | 129 | UInt16 tctr; |
130 | fread(&tctr, 1, sizeof(tctr), fin); | 130 | fread(&tctr, 1, sizeof(tctr), fin); |
131 | fread(&urlid, 1, sizeof(urlid), fin); | 131 | fread(&urlid, 1, sizeof(urlid), fin); |
132 | tctr = ntohs(tctr); | 132 | tctr = ntohs(tctr); |
133 | //qDebug("tgt:%u urlctr:%u tctr:%u", tgt, urlctr, tctr); | 133 | //qDebug("tgt:%u urlctr:%u tctr:%u", tgt, urlctr, tctr); |
134 | if (tctr >= tgt) | 134 | if (tctr >= tgt) |
135 | { | 135 | { |
136 | break; | 136 | break; |
137 | } | 137 | } |
138 | urlctr = tctr; | 138 | urlctr = tctr; |
139 | } | 139 | } |
140 | //qDebug("urls are in %d", ntohs(urlid)); | 140 | //qDebug("urls are in %d", ntohs(urlid)); |
141 | recptr = finduid(ntohs(urlid)); | 141 | recptr = finduid(ntohs(urlid)); |
142 | if (recptr != 0) | 142 | if (recptr != 0) |
143 | { | 143 | { |
144 | UInt32 reclen = recordlength(recptr) - HeaderSize(); | 144 | UInt32 reclen = recordlength(recptr) - HeaderSize(); |
145 | gotorecordnumber(recptr); | 145 | gotorecordnumber(recptr); |
146 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 146 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
147 | //qDebug("Found urls:%x",thishdr_type); | 147 | //qDebug("Found urls:%x",thishdr_type); |
148 | urlsize = thishdr_size; | 148 | urlsize = thishdr_size; |
149 | urls = new char[urlsize]; | 149 | urls = new char[urlsize]; |
150 | Expand(reclen, thishdr_type, (UInt8*)urls, urlsize); | 150 | Expand(reclen, thishdr_type, (UInt8*)urls, urlsize); |
151 | char* ptr = urls; | 151 | char* ptr = urls; |
152 | int rn = urlctr+1; | 152 | int rn = urlctr+1; |
153 | while (ptr - urls < urlsize) | 153 | while (ptr - urls < urlsize) |
154 | { | 154 | { |
155 | if (rn == tgt) | 155 | if (rn == tgt) |
156 | { | 156 | { |
157 | //qDebug("URL:%s", ptr); | 157 | //qDebug("URL:%s", ptr); |
158 | int len = strlen(ptr)+1; | 158 | int len = strlen(ptr)+1; |
159 | pRet = new char[len]; | 159 | pRet = new char[len]; |
160 | memcpy(pRet, ptr, len); | 160 | memcpy(pRet, ptr, len); |
161 | break; | 161 | break; |
162 | } | 162 | } |
163 | ptr += strlen(ptr)+1; | 163 | ptr += strlen(ptr)+1; |
164 | rn++; | 164 | rn++; |
165 | } | 165 | } |
166 | delete [] urls; | 166 | delete [] urls; |
167 | } | 167 | } |
168 | } | 168 | } |
169 | } | 169 | } |
170 | else | 170 | else |
171 | { | 171 | { |
172 | pRet = NULL; | 172 | pRet = NULL; |
173 | } | 173 | } |
174 | return pRet; | 174 | return pRet; |
175 | } | 175 | } |
176 | 176 | ||
177 | CPlucker_base::~CPlucker_base() | 177 | CPlucker_base::~CPlucker_base() |
178 | { | 178 | { |
179 | if (expandedtextbuffer != NULL) delete [] expandedtextbuffer; | 179 | if (expandedtextbuffer != NULL) delete [] expandedtextbuffer; |
180 | if (compressedtextbuffer != NULL) delete [] compressedtextbuffer; | 180 | if (compressedtextbuffer != NULL) delete [] compressedtextbuffer; |
181 | #ifdef LOCALPICTURES | 181 | #ifdef LOCALPICTURES |
182 | if (m_viewer != NULL) delete m_viewer; | 182 | if (m_viewer != NULL) delete m_viewer; |
183 | #endif | 183 | #endif |
184 | } | 184 | } |
185 | 185 | ||
186 | int CPlucker_base::getch() { return getch(false); } | 186 | int CPlucker_base::getch() { return getch(false); } |
187 | 187 | ||
188 | void CPlucker_base::getch(tchar& ch, CStyle& sty, unsigned long& pos) | 188 | void CPlucker_base::getch(tchar& ch, CStyle& sty, unsigned long& pos) |
189 | { | 189 | { |
190 | pos = locate(); | 190 | pos = locate(); |
191 | ch = getch(false); | 191 | ch = getch(false); |
192 | sty = mystyle; | 192 | sty = mystyle; |
193 | } | 193 | } |
194 | 194 | ||
195 | unsigned int CPlucker_base::locate() | 195 | unsigned int CPlucker_base::locate() |
196 | { | 196 | { |
197 | return currentpos; | 197 | return currentpos; |
198 | /* | 198 | /* |
199 | UInt16 thisrec = 1; | 199 | UInt16 thisrec = 1; |
200 | unsigned long locpos = 0; | 200 | unsigned long locpos = 0; |
201 | gotorecordnumber(thisrec); | 201 | gotorecordnumber(thisrec); |
202 | UInt16 thishdr_uid, thishdr_nParagraphs; | 202 | UInt16 thishdr_uid, thishdr_nParagraphs; |
203 | UInt32 thishdr_size; | 203 | UInt32 thishdr_size; |
204 | UInt8 thishdr_type, thishdr_reserved; | 204 | UInt8 thishdr_type, thishdr_reserved; |
205 | while (thisrec < bufferrec) | 205 | while (thisrec < bufferrec) |
206 | { | 206 | { |
207 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 207 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
208 | if (thishdr_type < 2) locpos += thishdr_size; | 208 | if (thishdr_type < 2) locpos += thishdr_size; |
209 | thisrec++; | 209 | thisrec++; |
210 | gotorecordnumber(thisrec); | 210 | gotorecordnumber(thisrec); |
211 | } | 211 | } |
212 | return locpos+bufferpos; | 212 | return locpos+bufferpos; |
213 | */ | 213 | */ |
214 | } | 214 | } |
215 | 215 | ||
216 | void CPlucker_base::locate(unsigned int n) | 216 | void CPlucker_base::locate(unsigned int n) |
217 | { | 217 | { |
218 | 218 | ||
219 | // clock_t start = clock(); | 219 | // clock_t start = clock(); |
220 | if (n >= currentpos-bufferpos && n < currentpos - bufferpos + buffercontent) | 220 | if (n >= currentpos-bufferpos && n < currentpos - bufferpos + buffercontent) |
221 | { | 221 | { |
222 | currentpos -= bufferpos; | 222 | currentpos -= bufferpos; |
223 | expand(bufferrec); | 223 | expand(bufferrec); |
224 | while (currentpos < n && bufferpos < buffercontent) getch_base(true); | 224 | while (currentpos < n && bufferpos < buffercontent) getch_base(true); |
225 | return; | 225 | return; |
226 | } | 226 | } |
227 | /* | 227 | /* |
228 | 228 | ||
229 | UInt32 textlength = currentpos - bufferpos; | 229 | UInt32 textlength = currentpos - bufferpos; |
230 | UInt16 recptr = bufferrec; | 230 | UInt16 recptr = bufferrec; |
231 | if (n < textlength/2) | 231 | if (n < textlength/2) |
232 | { | 232 | { |
233 | textlength = 0; | 233 | textlength = 0; |
234 | UInt16 thishdr_uid, thishdr_nParagraphs; | 234 | UInt16 thishdr_uid, thishdr_nParagraphs; |
235 | UInt32 thishdr_size = buffercontent; | 235 | UInt32 thishdr_size = buffercontent; |
236 | UInt8 thishdr_type, thishdr_reserved; | 236 | UInt8 thishdr_type, thishdr_reserved; |
237 | for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) | 237 | for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) |
238 | { | 238 | { |
239 | gotorecordnumber(recptr); | 239 | gotorecordnumber(recptr); |
240 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 240 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
241 | if (thishdr_type < 2) | 241 | if (thishdr_type < 2) |
242 | { | 242 | { |
243 | textlength += thishdr_size; | 243 | textlength += thishdr_size; |
244 | if (textlength > n) | 244 | if (textlength > n) |
245 | { | 245 | { |
246 | textlength -= thishdr_size; | 246 | textlength -= thishdr_size; |
247 | break; | 247 | break; |
248 | } | 248 | } |
249 | } | 249 | } |
250 | } | 250 | } |
251 | } | 251 | } |
252 | else if (n < textlength) | 252 | else if (n < textlength) |
253 | { | 253 | { |
254 | UInt16 thishdr_uid, thishdr_nParagraphs; | 254 | UInt16 thishdr_uid, thishdr_nParagraphs; |
255 | UInt32 thishdr_size; | 255 | UInt32 thishdr_size; |
256 | UInt8 thishdr_type, thishdr_reserved; | 256 | UInt8 thishdr_type, thishdr_reserved; |
257 | while (n < textlength && recptr > 1) | 257 | while (n < textlength && recptr > 1) |
258 | { | 258 | { |
259 | recptr--; | 259 | recptr--; |
260 | gotorecordnumber(recptr); | 260 | gotorecordnumber(recptr); |
261 | //qDebug("recptr:%u", recptr); | 261 | //qDebug("recptr:%u", recptr); |
262 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 262 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
263 | if (thishdr_type < 2) | 263 | if (thishdr_type < 2) |
264 | { | 264 | { |
265 | textlength -= thishdr_size; | 265 | textlength -= thishdr_size; |
266 | } | 266 | } |
267 | } | 267 | } |
268 | } | 268 | } |
269 | else | 269 | else |
270 | { | 270 | { |
271 | UInt16 thishdr_uid, thishdr_nParagraphs; | 271 | UInt16 thishdr_uid, thishdr_nParagraphs; |
272 | UInt32 thishdr_size = buffercontent; | 272 | UInt32 thishdr_size = buffercontent; |
273 | UInt8 thishdr_type, thishdr_reserved; | 273 | UInt8 thishdr_type, thishdr_reserved; |
274 | while (n > textlength + thishdr_size && recptr < ntohs(head.recordList.numRecords)-1) | 274 | while (n > textlength + thishdr_size && recptr < ntohs(head.recordList.numRecords)-1) |
275 | { | 275 | { |
276 | textlength += thishdr_size; | 276 | textlength += thishdr_size; |
277 | recptr++; | 277 | recptr++; |
278 | gotorecordnumber(recptr); | 278 | gotorecordnumber(recptr); |
279 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 279 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
280 | if (!(thishdr_type < 2)) | 280 | if (!(thishdr_type < 2)) |
281 | { | 281 | { |
282 | thishdr_size = 0; | 282 | thishdr_size = 0; |
283 | } | 283 | } |
284 | } | 284 | } |
285 | } | 285 | } |
286 | 286 | ||
287 | */ | 287 | */ |
288 | UInt16 thisrec = 0; | 288 | UInt16 thisrec = 0; |
289 | unsigned long locpos = 0; | 289 | unsigned long locpos = 0; |
290 | unsigned long bs = 0; | 290 | unsigned long bs = 0; |
291 | unsigned int np1 = n+1; | ||
291 | UInt16 thishdr_uid, thishdr_nParagraphs; | 292 | UInt16 thishdr_uid, thishdr_nParagraphs; |
292 | UInt32 thishdr_size; | 293 | UInt32 thishdr_size; |
293 | UInt8 thishdr_type, thishdr_reserved; | 294 | UInt8 thishdr_type, thishdr_reserved; |
294 | do | 295 | do |
295 | { | 296 | { |
296 | thisrec++; | 297 | thisrec++; |
297 | locpos += bs; | 298 | locpos += bs; |
298 | gotorecordnumber(thisrec); | 299 | gotorecordnumber(thisrec); |
299 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 300 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
300 | if (thishdr_type < 2) | 301 | if (thishdr_type < 2) |
301 | { | 302 | { |
302 | bs = thishdr_size; | 303 | bs = thishdr_size; |
303 | } | 304 | } |
304 | else | 305 | else |
305 | { | 306 | { |
306 | bs = 0; | 307 | bs = 0; |
307 | } | 308 | } |
308 | } while (locpos + bs < n); | 309 | } while (locpos + bs < np1); |
309 | 310 | ||
310 | // qDebug("Time(2): %u", clock()-start); | 311 | // qDebug("Time(2): %u", clock()-start); |
311 | /* | 312 | /* |
312 | if (recptr != thisrec) | 313 | if (recptr != thisrec) |
313 | { | 314 | { |
314 | qDebug("Disaster:recptr:%u thisrec:%u", recptr, thisrec); | 315 | qDebug("Disaster:recptr:%u thisrec:%u", recptr, thisrec); |
315 | UInt16 thishdr_uid, thishdr_nParagraphs; | 316 | UInt16 thishdr_uid, thishdr_nParagraphs; |
316 | UInt32 thishdr_size = buffercontent; | 317 | UInt32 thishdr_size = buffercontent; |
317 | UInt8 thishdr_type, thishdr_reserved; | 318 | UInt8 thishdr_type, thishdr_reserved; |
318 | for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) | 319 | for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) |
319 | { | 320 | { |
320 | gotorecordnumber(recptr); | 321 | gotorecordnumber(recptr); |
321 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 322 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
322 | // qDebug("UID:%u Paras:%u Size:%u Type:%u Reserved:%u", thishdr_uid, thishdr_nParagraphs, thishdr_size, (unsigned int)thishdr_type, (unsigned int)thishdr_reserved); | 323 | // qDebug("UID:%u Paras:%u Size:%u Type:%u Reserved:%u", thishdr_uid, thishdr_nParagraphs, thishdr_size, (unsigned int)thishdr_type, (unsigned int)thishdr_reserved); |
323 | } | 324 | } |
324 | //QApplication::exit ( 100 ); | 325 | //QApplication::exit ( 100 ); |
325 | } | 326 | } |
326 | */ | 327 | */ |
327 | currentpos = locpos; | 328 | currentpos = locpos; |
328 | expand(thisrec); | 329 | expand(thisrec); |
329 | while (currentpos < n && bufferpos < buffercontent) getch_base(true); | 330 | while (currentpos < n && bufferpos < buffercontent) getch_base(true); |
330 | 331 | ||
331 | /* // This is faster but the alignment attribute doesn't get set 8^( | 332 | /* // This is faster but the alignment attribute doesn't get set 8^( |
332 | bufferpos = n-locpos; | 333 | bufferpos = n-locpos; |
333 | currentpos = n; | 334 | currentpos = n; |
334 | while (bufferpos >= m_nextPara && m_nextPara >= 0) | 335 | while (bufferpos >= m_nextPara && m_nextPara >= 0) |
335 | { | 336 | { |
336 | UInt16 attr = m_ParaAttrs[m_nextParaIndex]; | 337 | UInt16 attr = m_ParaAttrs[m_nextParaIndex]; |
337 | m_nextParaIndex++; | 338 | m_nextParaIndex++; |
338 | if (m_nextParaIndex == m_nParas) | 339 | if (m_nextParaIndex == m_nParas) |
339 | { | 340 | { |
340 | m_nextPara = -1; | 341 | m_nextPara = -1; |
341 | } | 342 | } |
342 | else | 343 | else |
343 | { | 344 | { |
344 | m_nextPara += m_ParaOffsets[m_nextParaIndex]; | 345 | m_nextPara += m_ParaOffsets[m_nextParaIndex]; |
345 | } | 346 | } |
346 | } | 347 | } |
347 | */ | 348 | */ |
348 | } | 349 | } |
349 | 350 | ||
350 | bool CPlucker_base::expand(int thisrec) | 351 | bool CPlucker_base::expand(int thisrec) |
351 | { | 352 | { |
352 | mystyle.unset(); | 353 | mystyle.unset(); |
353 | if (bufferrec != thisrec) | 354 | if (bufferrec != thisrec) |
354 | { | 355 | { |
355 | size_t reclen = recordlength(thisrec); | 356 | size_t reclen = recordlength(thisrec); |
356 | gotorecordnumber(thisrec); | 357 | gotorecordnumber(thisrec); |
357 | UInt16 thishdr_uid, thishdr_nParagraphs; | 358 | UInt16 thishdr_uid, thishdr_nParagraphs; |
358 | UInt32 thishdr_size; | 359 | UInt32 thishdr_size; |
359 | UInt8 thishdr_type, thishdr_reserved; | 360 | UInt8 thishdr_type, thishdr_reserved; |
360 | while (1) | 361 | while (1) |
361 | { | 362 | { |
362 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 363 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
363 | //qDebug("This (%d) type is %d, uid is %u", thisrec, thishdr_type, thishdr_uid); | 364 | //qDebug("This (%d) type is %d, uid is %u", thisrec, thishdr_type, thishdr_uid); |
364 | if (thishdr_type < 2) break; | 365 | if (thishdr_type < 2) break; |
365 | //qDebug("Skipping paragraph of type %d", thishdr_type); | 366 | //qDebug("Skipping paragraph of type %d", thishdr_type); |
366 | if (++thisrec >= ntohs(head.recordList.numRecords) - 1) return false; | 367 | if (++thisrec >= ntohs(head.recordList.numRecords) - 1) return false; |
367 | reclen = recordlength(thisrec); | 368 | reclen = recordlength(thisrec); |
368 | gotorecordnumber(thisrec); | 369 | gotorecordnumber(thisrec); |
369 | } | 370 | } |
370 | m_nParas = thishdr_nParagraphs; | 371 | m_nParas = thishdr_nParagraphs; |
371 | m_bufferisreserved = (thishdr_reserved != 0); | 372 | m_bufferisreserved = (thishdr_reserved != 0); |
372 | //qDebug("It has %u paragraphs and is %u bytes", thishdr_nParagraphs, thishdr_size); | 373 | //qDebug("It has %u paragraphs and is %u bytes", thishdr_nParagraphs, thishdr_size); |
373 | uid = thishdr_uid; | 374 | uid = thishdr_uid; |
374 | // gotorecordnumber(thisrec); | 375 | // gotorecordnumber(thisrec); |
375 | // fread(expandedtextbuffer,1,10,fin); | 376 | // fread(expandedtextbuffer,1,10,fin); |
376 | for (int i = 0; i < m_nParas; i++) | 377 | for (int i = 0; i < m_nParas; i++) |
377 | { | 378 | { |
378 | UInt16 ubytes, attrs; | 379 | UInt16 ubytes, attrs; |
379 | fread(&ubytes, 1, sizeof(ubytes), fin); | 380 | fread(&ubytes, 1, sizeof(ubytes), fin); |
380 | fread(&attrs, 1, sizeof(attrs), fin); | 381 | fread(&attrs, 1, sizeof(attrs), fin); |
381 | m_ParaOffsets[i] = ntohs(ubytes); | 382 | m_ParaOffsets[i] = ntohs(ubytes); |
382 | m_ParaAttrs[i] = ntohs(attrs); | 383 | m_ParaAttrs[i] = ntohs(attrs); |
383 | ////qDebug("Bytes %u, Attr %x", ntohs(ubytes), ntohs(attrs)); | 384 | ////qDebug("Bytes %u, Attr %x", ntohs(ubytes), ntohs(attrs)); |
384 | } | 385 | } |
385 | 386 | ||
386 | reclen -= HeaderSize()+4*m_nParas; | 387 | reclen -= HeaderSize()+4*m_nParas; |
387 | 388 | ||
388 | buffercontent = thishdr_size; | 389 | buffercontent = thishdr_size; |
389 | 390 | ||
390 | if (thishdr_size > buffersize) | 391 | if (thishdr_size > buffersize) |
391 | { | 392 | { |
392 | delete [] expandedtextbuffer; | 393 | delete [] expandedtextbuffer; |
393 | buffersize = thishdr_size; | 394 | buffersize = thishdr_size; |
394 | expandedtextbuffer = new UInt8[buffersize]; | 395 | expandedtextbuffer = new UInt8[buffersize]; |
395 | } | 396 | } |
396 | Expand(reclen, thishdr_type, expandedtextbuffer, buffercontent); | 397 | Expand(reclen, thishdr_type, expandedtextbuffer, buffercontent); |
397 | bufferrec = thisrec; | 398 | bufferrec = thisrec; |
398 | } | 399 | } |
399 | 400 | ||
400 | 401 | ||
401 | if (m_nParas > 0) | 402 | if (m_nParas > 0) |
402 | { | 403 | { |
403 | m_nextPara = m_ParaOffsets[0]; | 404 | m_nextPara = m_ParaOffsets[0]; |
404 | //qDebug("First offset = %u", m_nextPara); | 405 | //qDebug("First offset = %u", m_nextPara); |
405 | m_nextParaIndex = 0; | 406 | m_nextParaIndex = 0; |
406 | } | 407 | } |
407 | else | 408 | else |
408 | { | 409 | { |
409 | m_nextPara = -1; | 410 | m_nextPara = -1; |
410 | } | 411 | } |
411 | bufferpos = 0; | 412 | bufferpos = 0; |
412 | //qDebug("BC:%u, HS:%u", buffercontent, thishdr_size); | 413 | //qDebug("BC:%u, HS:%u", buffercontent, thishdr_size); |
413 | return true; | 414 | return true; |
414 | } | 415 | } |
415 | /* | 416 | /* |
416 | void CPlucker_base::UnZip(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize) | 417 | void CPlucker_base::UnZip(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize) |
417 | { | 418 | { |
418 | z_stream zstream; | 419 | z_stream zstream; |
419 | memset(&zstream,sizeof(zstream),0); | 420 | memset(&zstream,sizeof(zstream),0); |
420 | zstream.next_in = compressedbuffer; | 421 | zstream.next_in = compressedbuffer; |
421 | zstream.next_out = tgtbuffer; | 422 | zstream.next_out = tgtbuffer; |
422 | zstream.avail_out = bsize; | 423 | zstream.avail_out = bsize; |
423 | zstream.avail_in = reclen; | 424 | zstream.avail_in = reclen; |
424 | 425 | ||
425 | int keylen = 0; | 426 | int keylen = 0; |
426 | 427 | ||
427 | zstream.zalloc = Z_NULL; | 428 | zstream.zalloc = Z_NULL; |
428 | zstream.zfree = Z_NULL; | 429 | zstream.zfree = Z_NULL; |
429 | zstream.opaque = Z_NULL; | 430 | zstream.opaque = Z_NULL; |
430 | 431 | ||
431 | // printf("Initialising\n"); | 432 | // printf("Initialising\n"); |
432 | 433 | ||
433 | inflateInit(&zstream); | 434 | inflateInit(&zstream); |
434 | int err = 0; | 435 | int err = 0; |
435 | do { | 436 | do { |
436 | if ( zstream.avail_in == 0 && 0 < keylen ) { | 437 | if ( zstream.avail_in == 0 && 0 < keylen ) { |
437 | zstream.next_in = compressedbuffer + keylen; | 438 | zstream.next_in = compressedbuffer + keylen; |
438 | zstream.avail_in = reclen - keylen; | 439 | zstream.avail_in = reclen - keylen; |
439 | keylen = 0; | 440 | keylen = 0; |
440 | } | 441 | } |
441 | zstream.next_out = tgtbuffer; | 442 | zstream.next_out = tgtbuffer; |
442 | zstream.avail_out = bsize; | 443 | zstream.avail_out = bsize; |
443 | 444 | ||
444 | err = inflate( &zstream, Z_SYNC_FLUSH ); | 445 | err = inflate( &zstream, Z_SYNC_FLUSH ); |
445 | 446 | ||
446 | ////qDebug("err:%d - %u", err, zstream.avail_in); | 447 | ////qDebug("err:%d - %u", err, zstream.avail_in); |
447 | 448 | ||
448 | } while ( err == Z_OK ); | 449 | } while ( err == Z_OK ); |
449 | 450 | ||
450 | inflateEnd(&zstream); | 451 | inflateEnd(&zstream); |
451 | } | 452 | } |
452 | */ | 453 | */ |
453 | size_t CPlucker_base::UnDoc(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize) | 454 | size_t CPlucker_base::UnDoc(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize) |
454 | { | 455 | { |
455 | // UInt16 headerSize; | 456 | // UInt16 headerSize; |
456 | UInt16 docSize; | 457 | UInt16 docSize; |
457 | UInt16 i; | 458 | UInt16 i; |
458 | UInt16 j; | 459 | UInt16 j; |
459 | UInt16 k; | 460 | UInt16 k; |
460 | 461 | ||
461 | UInt8 *inBuf = compressedbuffer; | 462 | UInt8 *inBuf = compressedbuffer; |
462 | UInt8 *outBuf = tgtbuffer; | 463 | UInt8 *outBuf = tgtbuffer; |
463 | 464 | ||
464 | // headerSize = sizeof( Header ) + record->paragraphs * sizeof( Paragraph ); | 465 | // headerSize = sizeof( Header ) + record->paragraphs * sizeof( Paragraph ); |
465 | docSize = reclen; | 466 | docSize = reclen; |
466 | 467 | ||
467 | j = 0; | 468 | j = 0; |
468 | k = 0; | 469 | k = 0; |
469 | while ( j < docSize ) { | 470 | while ( j < docSize ) { |
470 | i = 0; | 471 | i = 0; |
471 | while ( i < bsize && j < docSize ) { | 472 | while ( i < bsize && j < docSize ) { |
472 | UInt16 c; | 473 | UInt16 c; |
473 | 474 | ||
474 | c = (UInt16) inBuf[ j++ ]; | 475 | c = (UInt16) inBuf[ j++ ]; |
475 | if ( 0 < c && c < 9 ) { | 476 | if ( 0 < c && c < 9 ) { |
476 | while ( 0 < c-- ) | 477 | while ( 0 < c-- ) |
477 | outBuf[ i++ ] = inBuf[ j++ ]; | 478 | outBuf[ i++ ] = inBuf[ j++ ]; |
478 | } | 479 | } |
479 | else if ( c < 0x80 ) | 480 | else if ( c < 0x80 ) |
480 | outBuf[ i++ ] = c; | 481 | outBuf[ i++ ] = c; |
481 | else if ( 0xc0 <= c ) { | 482 | else if ( 0xc0 <= c ) { |
482 | outBuf[ i++ ] = ' '; | 483 | outBuf[ i++ ] = ' '; |
483 | outBuf[ i++ ] = c ^ 0x80; | 484 | outBuf[ i++ ] = c ^ 0x80; |
484 | } | 485 | } |
485 | else { | 486 | else { |
486 | Int16 m; | 487 | Int16 m; |
487 | Int16 n; | 488 | Int16 n; |
488 | 489 | ||
489 | c <<= 8; | 490 | c <<= 8; |
490 | c += inBuf[ j++ ]; | 491 | c += inBuf[ j++ ]; |
491 | 492 | ||
492 | m = ( c & 0x3fff ) >> COUNT_BITS; | 493 | m = ( c & 0x3fff ) >> COUNT_BITS; |
493 | n = c & ( ( 1 << COUNT_BITS ) - 1 ); | 494 | n = c & ( ( 1 << COUNT_BITS ) - 1 ); |
494 | n += 2; | 495 | n += 2; |
495 | 496 | ||
496 | do { | 497 | do { |
497 | outBuf[ i ] = outBuf[ i - m ]; | 498 | outBuf[ i ] = outBuf[ i - m ]; |
498 | i++; | 499 | i++; |
499 | } while ( 0 < n-- ); | 500 | } while ( 0 < n-- ); |
500 | } | 501 | } |
501 | } | 502 | } |
502 | k += bsize; | 503 | k += bsize; |
503 | } | 504 | } |
504 | return i; | 505 | return i; |
505 | } | 506 | } |
506 | 507 | ||
507 | void CPlucker_base::home() | 508 | void CPlucker_base::home() |
508 | { | 509 | { |
509 | currentpos = 0; | 510 | currentpos = 0; |
510 | expand(1); | 511 | expand(1); |
511 | } | 512 | } |
512 | 513 | ||
513 | CList<Bkmk>* CPlucker_base::getbkmklist() | 514 | CList<Bkmk>* CPlucker_base::getbkmklist() |
514 | { | 515 | { |
515 | /* | 516 | /* |
516 | UInt16 thishdr_uid, thishdr_nParagraphs; | 517 | UInt16 thishdr_uid, thishdr_nParagraphs; |
517 | UInt32 thishdr_size; | 518 | UInt32 thishdr_size; |
518 | UInt8 thishdr_type, thishdr_reserved; | 519 | UInt8 thishdr_type, thishdr_reserved; |
519 | 520 | ||
520 | for (int i = 1; i < ntohs(head.recordList.numRecords); i++) | 521 | for (int i = 1; i < ntohs(head.recordList.numRecords); i++) |
521 | { | 522 | { |
522 | gotorecordnumber(i); | 523 | gotorecordnumber(i); |
523 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 524 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
524 | if (thishdr_type == 8) | 525 | if (thishdr_type == 8) |
525 | { | 526 | { |
526 | UInt16 n; | 527 | UInt16 n; |
527 | fread(&n, 1, sizeof(n), fin); | 528 | fread(&n, 1, sizeof(n), fin); |
528 | n = ntohs(n); | 529 | n = ntohs(n); |
529 | //qDebug("Found %u bookmarks", n); | 530 | //qDebug("Found %u bookmarks", n); |
530 | } | 531 | } |
531 | //qDebug("Found:%d, %u", i , thishdr_type); | 532 | //qDebug("Found:%d, %u", i , thishdr_type); |
532 | } | 533 | } |
533 | */ | 534 | */ |
534 | return NULL; | 535 | return NULL; |
535 | } | 536 | } |
536 | 537 | ||
537 | #include <qnamespace.h> | 538 | #include <qnamespace.h> |
538 | 539 | ||
539 | QImage* CPlucker_base::expandimg(UInt16 tgt, bool border) | 540 | QImage* CPlucker_base::expandimg(UInt16 tgt, bool border) |
540 | { | 541 | { |
541 | QImage* qimage = getimg(tgt); | 542 | QImage* qimage = getimg(tgt); |
542 | QImage* ret; | 543 | QImage* ret; |
543 | if (qimage == NULL) return NULL; | 544 | if (qimage == NULL) return NULL; |
544 | if (border) | 545 | if (border) |
545 | { | 546 | { |
546 | QPixmap* image = new QPixmap(0,0); | 547 | QPixmap* image = new QPixmap(0,0); |
547 | image->convertFromImage(*qimage); | 548 | image->convertFromImage(*qimage); |
548 | delete qimage; | 549 | delete qimage; |
549 | QPixmap* pret = new QPixmap(image->width()+4, image->height()+4); | 550 | QPixmap* pret = new QPixmap(image->width()+4, image->height()+4); |
550 | pret->fill(Qt::red); | 551 | pret->fill(Qt::red); |
551 | bitBlt(pret, 2, 2, image, 0, 0, -1, -1);//, Qt::RasterOp::CopyROP); | 552 | bitBlt(pret, 2, 2, image, 0, 0, -1, -1);//, Qt::RasterOp::CopyROP); |
552 | delete image; | 553 | delete image; |
553 | ret = new QImage(pret->convertToImage()); | 554 | ret = new QImage(pret->convertToImage()); |
554 | } | 555 | } |
555 | else | 556 | else |
556 | { | 557 | { |
557 | ret = qimage; | 558 | ret = qimage; |
558 | } | 559 | } |
559 | return ret; | 560 | return ret; |
560 | } | 561 | } |
561 | 562 | ||
562 | #ifdef _BUFFERPICS | 563 | #ifdef _BUFFERPICS |
563 | #include <qmap.h> | 564 | #include <qmap.h> |
564 | #endif | 565 | #endif |