-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 @@ -163,274 +163,275 @@ char* CPlucker_base::geturl(UInt16 tgt) ptr += strlen(ptr)+1; rn++; } delete [] urls; } } } else { pRet = NULL; } return pRet; } CPlucker_base::~CPlucker_base() { if (expandedtextbuffer != NULL) delete [] expandedtextbuffer; if (compressedtextbuffer != NULL) delete [] compressedtextbuffer; #ifdef LOCALPICTURES if (m_viewer != NULL) delete m_viewer; #endif } int CPlucker_base::getch() { return getch(false); } void CPlucker_base::getch(tchar& ch, CStyle& sty, unsigned long& pos) { pos = locate(); ch = getch(false); sty = mystyle; } unsigned int CPlucker_base::locate() { return currentpos; /* UInt16 thisrec = 1; unsigned long locpos = 0; gotorecordnumber(thisrec); UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size; UInt8 thishdr_type, thishdr_reserved; while (thisrec < bufferrec) { GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); if (thishdr_type < 2) locpos += thishdr_size; thisrec++; gotorecordnumber(thisrec); } return locpos+bufferpos; */ } void CPlucker_base::locate(unsigned int n) { // clock_t start = clock(); if (n >= currentpos-bufferpos && n < currentpos - bufferpos + buffercontent) { currentpos -= bufferpos; expand(bufferrec); while (currentpos < n && bufferpos < buffercontent) getch_base(true); return; } /* UInt32 textlength = currentpos - bufferpos; UInt16 recptr = bufferrec; if (n < textlength/2) { textlength = 0; UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size = buffercontent; UInt8 thishdr_type, thishdr_reserved; for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) { gotorecordnumber(recptr); GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); if (thishdr_type < 2) { textlength += thishdr_size; if (textlength > n) { textlength -= thishdr_size; break; } } } } else if (n < textlength) { UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size; UInt8 thishdr_type, thishdr_reserved; while (n < textlength && recptr > 1) { recptr--; gotorecordnumber(recptr); //qDebug("recptr:%u", recptr); GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); if (thishdr_type < 2) { textlength -= thishdr_size; } } } else { UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size = buffercontent; UInt8 thishdr_type, thishdr_reserved; while (n > textlength + thishdr_size && recptr < ntohs(head.recordList.numRecords)-1) { textlength += thishdr_size; recptr++; gotorecordnumber(recptr); GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); if (!(thishdr_type < 2)) { thishdr_size = 0; } } } */ UInt16 thisrec = 0; unsigned long locpos = 0; unsigned long bs = 0; + unsigned int np1 = n+1; UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size; UInt8 thishdr_type, thishdr_reserved; do { thisrec++; locpos += bs; gotorecordnumber(thisrec); GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); if (thishdr_type < 2) { bs = thishdr_size; } else { bs = 0; } - } while (locpos + bs < n); + } while (locpos + bs < np1); // qDebug("Time(2): %u", clock()-start); /* if (recptr != thisrec) { qDebug("Disaster:recptr:%u thisrec:%u", recptr, thisrec); UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size = buffercontent; UInt8 thishdr_type, thishdr_reserved; for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) { gotorecordnumber(recptr); GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); // 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); } // QApplication::exit ( 100 ); } */ currentpos = locpos; expand(thisrec); while (currentpos < n && bufferpos < buffercontent) getch_base(true); /* // This is faster but the alignment attribute doesn't get set 8^( bufferpos = n-locpos; currentpos = n; while (bufferpos >= m_nextPara && m_nextPara >= 0) { UInt16 attr = m_ParaAttrs[m_nextParaIndex]; m_nextParaIndex++; if (m_nextParaIndex == m_nParas) { m_nextPara = -1; } else { m_nextPara += m_ParaOffsets[m_nextParaIndex]; } } */ } bool CPlucker_base::expand(int thisrec) { mystyle.unset(); if (bufferrec != thisrec) { size_t reclen = recordlength(thisrec); gotorecordnumber(thisrec); UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size; UInt8 thishdr_type, thishdr_reserved; while (1) { GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); //qDebug("This (%d) type is %d, uid is %u", thisrec, thishdr_type, thishdr_uid); if (thishdr_type < 2) break; //qDebug("Skipping paragraph of type %d", thishdr_type); if (++thisrec >= ntohs(head.recordList.numRecords) - 1) return false; reclen = recordlength(thisrec); gotorecordnumber(thisrec); } m_nParas = thishdr_nParagraphs; m_bufferisreserved = (thishdr_reserved != 0); //qDebug("It has %u paragraphs and is %u bytes", thishdr_nParagraphs, thishdr_size); uid = thishdr_uid; // gotorecordnumber(thisrec); // fread(expandedtextbuffer,1,10,fin); for (int i = 0; i < m_nParas; i++) { UInt16 ubytes, attrs; fread(&ubytes, 1, sizeof(ubytes), fin); fread(&attrs, 1, sizeof(attrs), fin); m_ParaOffsets[i] = ntohs(ubytes); m_ParaAttrs[i] = ntohs(attrs); // //qDebug("Bytes %u, Attr %x", ntohs(ubytes), ntohs(attrs)); } reclen -= HeaderSize()+4*m_nParas; buffercontent = thishdr_size; if (thishdr_size > buffersize) { delete [] expandedtextbuffer; buffersize = thishdr_size; expandedtextbuffer = new UInt8[buffersize]; } Expand(reclen, thishdr_type, expandedtextbuffer, buffercontent); bufferrec = thisrec; } if (m_nParas > 0) { m_nextPara = m_ParaOffsets[0]; //qDebug("First offset = %u", m_nextPara); m_nextParaIndex = 0; } else { m_nextPara = -1; } bufferpos = 0; //qDebug("BC:%u, HS:%u", buffercontent, thishdr_size); return true; } /* void CPlucker_base::UnZip(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize) { z_stream zstream; memset(&zstream,sizeof(zstream),0); zstream.next_in = compressedbuffer; zstream.next_out = tgtbuffer; zstream.avail_out = bsize; zstream.avail_in = reclen; int keylen = 0; zstream.zalloc = Z_NULL; zstream.zfree = Z_NULL; zstream.opaque = Z_NULL; // printf("Initialising\n"); inflateInit(&zstream); int err = 0; do { if ( zstream.avail_in == 0 && 0 < keylen ) { |