Diffstat (limited to 'noncore/apps/opie-reader/Aportis.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/Aportis.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/noncore/apps/opie-reader/Aportis.cpp b/noncore/apps/opie-reader/Aportis.cpp index 353996c..37dcc99 100644 --- a/noncore/apps/opie-reader/Aportis.cpp +++ b/noncore/apps/opie-reader/Aportis.cpp | |||
@@ -33,48 +33,49 @@ CList<Bkmk>* Aportis::getbkmklist() | |||
33 | fread(name,1,16,fin); | 33 | fread(name,1,16,fin); |
34 | unsigned long lcn; | 34 | unsigned long lcn; |
35 | fread(&lcn,sizeof(lcn),1,fin); | 35 | fread(&lcn,sizeof(lcn),1,fin); |
36 | lcn ^= 0xa5a5a5a5; | 36 | lcn ^= 0xa5a5a5a5; |
37 | lcn = SwapLong(lcn); | 37 | lcn = SwapLong(lcn); |
38 | // qDebug("Bookmark:%s:%u", name,lcn); | 38 | // qDebug("Bookmark:%s:%u", name,lcn); |
39 | tchar tname[17]; | 39 | tchar tname[17]; |
40 | memset(tname, 0, sizeof(tname)); | 40 | memset(tname, 0, sizeof(tname)); |
41 | for (int i = 0; name[i] != 0; i++) | 41 | for (int i = 0; name[i] != 0; i++) |
42 | { | 42 | { |
43 | tname[i] = name[i] ^ 0xa5; | 43 | tname[i] = name[i] ^ 0xa5; |
44 | } | 44 | } |
45 | t->push_back(Bkmk(tname, NULL, lcn)); | 45 | t->push_back(Bkmk(tname, NULL, lcn)); |
46 | } | 46 | } |
47 | return t; | 47 | return t; |
48 | } | 48 | } |
49 | else | 49 | else |
50 | { | 50 | { |
51 | return NULL; | 51 | return NULL; |
52 | } | 52 | } |
53 | } | 53 | } |
54 | */ | 54 | */ |
55 | if (bCompressed != 4) return NULL; | 55 | if (bCompressed != 4) return NULL; |
56 | CList<Bkmk>* t = new CList<Bkmk>; | 56 | CList<Bkmk>* t = new CList<Bkmk>; |
57 | unsuspend(); | ||
57 | size_t cur = ftell(fin); | 58 | size_t cur = ftell(fin); |
58 | for (int i = 0; i < nRecs2; i++) | 59 | for (int i = 0; i < nRecs2; i++) |
59 | { | 60 | { |
60 | DWORD dwPos; | 61 | DWORD dwPos; |
61 | fseek(fin, 0x56 + 8*i, SEEK_SET); | 62 | fseek(fin, 0x56 + 8*i, SEEK_SET); |
62 | fread(&dwPos, 4, 1, fin); | 63 | fread(&dwPos, 4, 1, fin); |
63 | dwPos = SwapLong(dwPos); | 64 | dwPos = SwapLong(dwPos); |
64 | fseek(fin,dwPos,SEEK_SET); | 65 | fseek(fin,dwPos,SEEK_SET); |
65 | unsigned char ch; | 66 | unsigned char ch; |
66 | fread(&ch,1,1,fin); | 67 | fread(&ch,1,1,fin); |
67 | if (ch != 241) | 68 | if (ch != 241) |
68 | { | 69 | { |
69 | char name[17]; | 70 | char name[17]; |
70 | name[16] = '\0'; | 71 | name[16] = '\0'; |
71 | fseek(fin,dwPos,SEEK_SET); | 72 | fseek(fin,dwPos,SEEK_SET); |
72 | fread(name,1,16,fin); | 73 | fread(name,1,16,fin); |
73 | unsigned long lcn; | 74 | unsigned long lcn; |
74 | fread(&lcn,sizeof(lcn),1,fin); | 75 | fread(&lcn,sizeof(lcn),1,fin); |
75 | lcn = SwapLong(lcn); | 76 | lcn = SwapLong(lcn); |
76 | #ifdef _UNICODE | 77 | #ifdef _UNICODE |
77 | tchar tname[17]; | 78 | tchar tname[17]; |
78 | memset(tname, 0, sizeof(tname)); | 79 | memset(tname, 0, sizeof(tname)); |
79 | for (int i = 0; name[i] != 0; i++) | 80 | for (int i = 0; name[i] != 0; i++) |
80 | { | 81 | { |
@@ -225,65 +226,67 @@ int Aportis::OpenFile(const char *src) | |||
225 | } | 226 | } |
226 | currentrec = 0; | 227 | currentrec = 0; |
227 | cbptr = 0; | 228 | cbptr = 0; |
228 | outptr = 0; | 229 | outptr = 0; |
229 | refreshbuffer(); | 230 | refreshbuffer(); |
230 | } | 231 | } |
231 | /* | 232 | /* |
232 | for (int i = 0; i < nRecs2; i++) | 233 | for (int i = 0; i < nRecs2; i++) |
233 | { | 234 | { |
234 | qDebug("Record:%u - %u bytes at position %x", i, recordlength(i), recordpos(i)); | 235 | qDebug("Record:%u - %u bytes at position %x", i, recordlength(i), recordpos(i)); |
235 | } | 236 | } |
236 | */ | 237 | */ |
237 | 238 | ||
238 | qDebug("Number of records:[%u,%u]", nRecs, nRecs2); | 239 | qDebug("Number of records:[%u,%u]", nRecs, nRecs2); |
239 | return ret; | 240 | return ret; |
240 | } | 241 | } |
241 | 242 | ||
242 | int Aportis::getch() | 243 | int Aportis::getch() |
243 | { | 244 | { |
244 | if (bCompressed == 1) | 245 | if (bCompressed == 1) |
245 | { | 246 | { |
246 | if ((dwRecLen == 0) && !refreshbuffer()) return EOF; | 247 | if ((dwRecLen == 0) && !refreshbuffer()) return EOF; |
247 | else | 248 | else |
248 | { | 249 | { |
250 | unsuspend(); | ||
249 | int c = getc(fin); | 251 | int c = getc(fin); |
250 | dePeanut(c); | 252 | dePeanut(c); |
251 | dwRecLen--; | 253 | dwRecLen--; |
252 | currentpos++; | 254 | currentpos++; |
253 | return c; | 255 | return c; |
254 | } | 256 | } |
255 | } | 257 | } |
256 | if (outptr != cbptr) | 258 | if (outptr != cbptr) |
257 | { | 259 | { |
258 | currentpos++; | 260 | currentpos++; |
259 | return (circbuf[outptr = (outptr + 1) % 2048]); | 261 | return (circbuf[outptr = (outptr + 1) % 2048]); |
260 | } | 262 | } |
261 | if ((dwRecLen == 0) && !refreshbuffer()) return EOF; | 263 | if ((dwRecLen == 0) && !refreshbuffer()) return EOF; |
262 | currentpos++; | 264 | currentpos++; |
263 | int c; | 265 | int c; |
264 | 266 | ||
265 | // take a char from the input buffer | 267 | // take a char from the input buffer |
268 | unsuspend(); | ||
266 | c = getc(fin); | 269 | c = getc(fin); |
267 | dePeanut(c); | 270 | dePeanut(c); |
268 | dwRecLen--; | 271 | dwRecLen--; |
269 | // separate the char into zones: 0, 1...8, 9...0x7F, 0x80...0xBF, 0xC0...0xFF | 272 | // separate the char into zones: 0, 1...8, 9...0x7F, 0x80...0xBF, 0xC0...0xFF |
270 | 273 | ||
271 | // codes 1...8 mean copy that many chars; for accented chars & binary | 274 | // codes 1...8 mean copy that many chars; for accented chars & binary |
272 | if (c == 0) | 275 | if (c == 0) |
273 | { | 276 | { |
274 | circbuf[outptr = cbptr = (cbptr+1)%2048] = c; | 277 | circbuf[outptr = cbptr = (cbptr+1)%2048] = c; |
275 | return c; | 278 | return c; |
276 | } | 279 | } |
277 | else if (c >= 0x09 && c <= 0x7F) | 280 | else if (c >= 0x09 && c <= 0x7F) |
278 | { | 281 | { |
279 | circbuf[outptr = cbptr = (cbptr+1)%2048] = c; | 282 | circbuf[outptr = cbptr = (cbptr+1)%2048] = c; |
280 | return c; | 283 | return c; |
281 | } | 284 | } |
282 | else if (c >= 0x01 && c <= 0x08) | 285 | else if (c >= 0x01 && c <= 0x08) |
283 | { | 286 | { |
284 | dwRecLen -= c; | 287 | dwRecLen -= c; |
285 | while(c--) | 288 | while(c--) |
286 | { | 289 | { |
287 | int c = getc(fin); | 290 | int c = getc(fin); |
288 | dePeanut(c); | 291 | dePeanut(c); |
289 | circbuf[cbptr = (cbptr+1)%2048] = c; | 292 | circbuf[cbptr = (cbptr+1)%2048] = c; |
@@ -299,71 +302,72 @@ int Aportis::getch() | |||
299 | c += c1; | 302 | c += c1; |
300 | dwRecLen--; | 303 | dwRecLen--; |
301 | m = (c & 0x3FFF) >> COUNT_BITS; | 304 | m = (c & 0x3FFF) >> COUNT_BITS; |
302 | n = c & ((1<<COUNT_BITS) - 1); | 305 | n = c & ((1<<COUNT_BITS) - 1); |
303 | n += 3; | 306 | n += 3; |
304 | while (n--) | 307 | while (n--) |
305 | { | 308 | { |
306 | cbptr = (cbptr+1)%2048; | 309 | cbptr = (cbptr+1)%2048; |
307 | circbuf[cbptr] = circbuf[(cbptr+2048-m)%2048]; | 310 | circbuf[cbptr] = circbuf[(cbptr+2048-m)%2048]; |
308 | } | 311 | } |
309 | return circbuf[outptr = (outptr+1)%2048]; | 312 | return circbuf[outptr = (outptr+1)%2048]; |
310 | } | 313 | } |
311 | else if (c >= 0xC0 && c <= 0xFF) | 314 | else if (c >= 0xC0 && c <= 0xFF) |
312 | { | 315 | { |
313 | circbuf[cbptr = (cbptr+1)%2048] = ' '; | 316 | circbuf[cbptr = (cbptr+1)%2048] = ' '; |
314 | circbuf[cbptr = (cbptr+1)%2048] = c^0x80; | 317 | circbuf[cbptr = (cbptr+1)%2048] = c^0x80; |
315 | return circbuf[outptr = (outptr+1)%2048]; | 318 | return circbuf[outptr = (outptr+1)%2048]; |
316 | } | 319 | } |
317 | } | 320 | } |
318 | 321 | ||
319 | unsigned int Aportis::GetBS(unsigned int bn) | 322 | unsigned int Aportis::GetBS(unsigned int bn) |
320 | { | 323 | { |
321 | DWORD dwPos; | 324 | DWORD dwPos; |
322 | WORD fs; | 325 | WORD fs; |
323 | 326 | unsuspend(); | |
324 | fseek(fin, 0x56 + 8*bn, SEEK_SET); | 327 | fseek(fin, 0x56 + 8*bn, SEEK_SET); |
325 | fread(&dwPos, 4, 1, fin); | 328 | fread(&dwPos, 4, 1, fin); |
326 | dwPos = SwapLong(dwPos); | 329 | dwPos = SwapLong(dwPos); |
327 | fseek(fin,dwPos,SEEK_SET); | 330 | fseek(fin,dwPos,SEEK_SET); |
328 | 331 | ||
329 | // gotorecordnumber(bn+1); | 332 | // gotorecordnumber(bn+1); |
330 | unsigned char ch; | 333 | unsigned char ch; |
331 | fread(&ch,1,1,fin); | 334 | fread(&ch,1,1,fin); |
332 | if (ch == 241) | 335 | if (ch == 241) |
333 | { | 336 | { |
334 | fread(&fs,sizeof(fs),1,fin); | 337 | fread(&fs,sizeof(fs),1,fin); |
335 | fs = SwapWord(fs); | 338 | fs = SwapWord(fs); |
336 | } | 339 | } |
337 | else | 340 | else |
338 | fs = 0; | 341 | fs = 0; |
339 | return fs; | 342 | return fs; |
340 | } | 343 | } |
341 | 344 | ||
342 | unsigned int Aportis::locate() | 345 | unsigned int Aportis::locate() |
343 | { | 346 | { |
344 | if (bCompressed == 4) | 347 | if (bCompressed == 4) |
345 | { | 348 | { |
349 | unsuspend(); | ||
346 | size_t cur = ftell(fin); | 350 | size_t cur = ftell(fin); |
347 | unsigned int clen = 0; | 351 | unsigned int clen = 0; |
348 | for (unsigned int i = 0; i < currentrec-1; i++) | 352 | for (unsigned int i = 0; i < currentrec-1; i++) |
349 | { | 353 | { |
350 | unsigned int bs = GetBS(i); | 354 | unsigned int bs = GetBS(i); |
351 | if (bs == 0) break; | 355 | if (bs == 0) break; |
352 | clen += bs; | 356 | clen += bs; |
353 | } | 357 | } |
354 | fseek(fin,cur,SEEK_SET); | 358 | fseek(fin,cur,SEEK_SET); |
355 | return clen+currentpos; | 359 | return clen+currentpos; |
356 | } | 360 | } |
357 | else | 361 | else |
358 | return (currentrec-1)*BlockSize+currentpos; | 362 | return (currentrec-1)*BlockSize+currentpos; |
359 | } | 363 | } |
360 | 364 | ||
361 | void Aportis::locate(unsigned int n) | 365 | void Aportis::locate(unsigned int n) |
362 | { | 366 | { |
363 | unsigned int offset; | 367 | unsigned int offset; |
364 | // currentrec = (n >> OFFBITS); | 368 | // currentrec = (n >> OFFBITS); |
365 | switch (bCompressed) | 369 | switch (bCompressed) |
366 | { | 370 | { |
367 | case 4: | 371 | case 4: |
368 | { | 372 | { |
369 | DWORD clen = 0; | 373 | DWORD clen = 0; |
@@ -380,75 +384,77 @@ void Aportis::locate(unsigned int n) | |||
380 | currentrec = i; | 384 | currentrec = i; |
381 | } | 385 | } |
382 | break; | 386 | break; |
383 | case 1: | 387 | case 1: |
384 | case 2: | 388 | case 2: |
385 | default: | 389 | default: |
386 | currentrec = n / BlockSize; | 390 | currentrec = n / BlockSize; |
387 | offset = n % BlockSize; | 391 | offset = n % BlockSize; |
388 | } | 392 | } |
389 | 393 | ||
390 | outptr = cbptr; | 394 | outptr = cbptr; |
391 | refreshbuffer(); | 395 | refreshbuffer(); |
392 | while (currentpos < offset && getch() != EOF); | 396 | while (currentpos < offset && getch() != EOF); |
393 | } | 397 | } |
394 | 398 | ||
395 | bool Aportis::refreshbuffer() | 399 | bool Aportis::refreshbuffer() |
396 | { | 400 | { |
397 | if (currentrec < nRecs) | 401 | if (currentrec < nRecs) |
398 | { | 402 | { |
399 | dwRecLen = recordlength(currentrec+1); | 403 | dwRecLen = recordlength(currentrec+1); |
400 | gotorecordnumber(currentrec+1); | 404 | gotorecordnumber(currentrec+1); |
401 | if (bCompressed == 4) | 405 | if (bCompressed == 4) |
402 | { | 406 | { |
403 | unsigned char t[3]; | 407 | unsigned char t[3]; |
408 | unsuspend(); | ||
404 | fread(t,1,3,fin); | 409 | fread(t,1,3,fin); |
405 | if (t[0] != 241) | 410 | if (t[0] != 241) |
406 | { | 411 | { |
407 | printf("You shouldn't be here!\n"); | 412 | printf("You shouldn't be here!\n"); |
408 | return false; | 413 | return false; |
409 | } | 414 | } |
410 | dwRecLen -= 3; | 415 | dwRecLen -= 3; |
411 | } | 416 | } |
412 | /* | 417 | /* |
413 | int n = fread(t.buf, 1, dwRecLen, fin); | 418 | int n = fread(t.buf, 1, dwRecLen, fin); |
414 | t.len = n; | 419 | t.len = n; |
415 | // if(bCompressed) | 420 | // if(bCompressed) |
416 | t.Decompress(); | 421 | t.Decompress(); |
417 | 422 | ||
418 | t.buf[t.Len()] = '\0'; | 423 | t.buf[t.Len()] = '\0'; |
419 | */ | 424 | */ |
420 | currentpos = 0; | 425 | currentpos = 0; |
421 | currentrec++; | 426 | currentrec++; |
422 | return true; | 427 | return true; |
423 | } | 428 | } |
424 | else { | 429 | else { |
425 | return false; | 430 | return false; |
426 | } | 431 | } |
427 | } | 432 | } |
428 | 433 | ||
429 | #include <qimage.h> | 434 | #include <qimage.h> |
430 | 435 | ||
431 | QImage* Aportis::getPicture(unsigned long tgt) | 436 | QImage* Aportis::getPicture(unsigned long tgt) |
432 | { | 437 | { |
438 | unsuspend(); | ||
433 | unsigned short tgtrec = tgt+mobiimagerec; | 439 | unsigned short tgtrec = tgt+mobiimagerec; |
434 | if (tgtrec > nRecs2) return NULL; | 440 | if (tgtrec > nRecs2) return NULL; |
435 | size_t cur = ftell(fin); | 441 | size_t cur = ftell(fin); |
436 | unsigned short reclen = recordlength(tgtrec); | 442 | unsigned short reclen = recordlength(tgtrec); |
437 | gotorecordnumber(tgtrec); | 443 | gotorecordnumber(tgtrec); |
438 | UInt8* imgbuffer = new UInt8[reclen]; | 444 | UInt8* imgbuffer = new UInt8[reclen]; |
439 | fread(imgbuffer, 1, reclen, fin); | 445 | fread(imgbuffer, 1, reclen, fin); |
440 | QByteArray arr; | 446 | QByteArray arr; |
441 | arr.assign((const char*)imgbuffer, reclen); | 447 | arr.assign((const char*)imgbuffer, reclen); |
442 | 448 | ||
443 | QImage* qimage = new QImage(arr); | 449 | QImage* qimage = new QImage(arr); |
444 | fseek(fin, cur, SEEK_SET); | 450 | fseek(fin, cur, SEEK_SET); |
445 | 451 | ||
446 | return qimage; | 452 | return qimage; |
447 | } | 453 | } |
448 | 454 | ||
449 | #ifndef __STATIC | 455 | #ifndef __STATIC |
450 | extern "C" | 456 | extern "C" |
451 | { | 457 | { |
452 | CExpander* newcodec() { return new Aportis; } | 458 | CExpander* newcodec() { return new Aportis; } |
453 | } | 459 | } |
454 | #endif | 460 | #endif |